Skip to content

Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.

C

feat: the player footer uses the Music app's AirPlay and queue glyphs (#125)

My-Name-Is-Jeff5af61bad64c9
diff --git a/tweak/Sources/Headers/SPTEncoreIconView.h b/tweak/Sources/Headers/SPTEncoreIconView.h
index 2567215e..732a5858 100644
--- a/tweak/Sources/Headers/SPTEncoreIconView.h
+++ b/tweak/Sources/Headers/SPTEncoreIconView.h
@@ -4,8 +4,8 @@
@interface SPTEncoreIconView : UIView
- (instancetype)initWithIcon:(id)icon;
-- (void)setForegroundColor:(UIColor *)color;
-- (void)setActiveForegroundColor:(UIColor *)color;
+@property (nonatomic, strong) UIColor *foregroundColor;
+@property (nonatomic, strong) UIColor *activeForegroundColor;
- (void)setIsActive:(BOOL)active;
- (BOOL)isActive;
@end
diff --git a/tweak/Sources/Redesigned/Player/DJPlayer.x b/tweak/Sources/Redesigned/Player/DJPlayer.x
index ef1661e8..15a5f9f8 100644
--- a/tweak/Sources/Redesigned/Player/DJPlayer.x
+++ b/tweak/Sources/Redesigned/Player/DJPlayer.x
@@ -11,11 +11,10 @@
//
// Footer: DJMFooterUnitView holds the share button, the DJ button, Connect and an empty view, not in a stack.
// Connect and the DJ button stay Spotify's and are only moved, by a transform that survives relayout. Lyrics
-// and Queue are the Kit's glyph buttons; Queue opens spotify:now-playing:queue.
+// and Queue are the Kit's glyph buttons; Queue, the Music app's list.bullet (issue #109), opens spotify:now-playing:queue.
#import "Core/SGCore.h"
#import "Redesigned/Kit/SGRKit.h"
#import "Shared/Navigation/Links.h"
-#import "Shared/Navigation/TabIcons.h"
#import "Player.h"
static const CGFloat kSkipGlyphSize = 32, kFooterGlyphSize = 20;
@@ -24,7 +23,7 @@ static const CGFloat kSlots[4] = {0.2, 0.4, 0.6, 0.8};
// The DJ button's blue disc is 48pt, a good deal more than the glyphs beside it; drawn this much of that.
static const CGFloat kDJButtonScale = 0.88;
static char kPrevKey, kNextKey, kPlayKey, kGlyphKey;
-static char kShareKey, kConnectKey, kDJKey, kQueueKey, kEncoreQueueKey, kEncoreMissKey;
+static char kShareKey, kConnectKey, kDJKey, kQueueKey;
#pragma mark - previous and next
@@ -122,38 +121,6 @@ static SGRGlyphButton *glyphButtonIn(UIView *host, const void *key, NSString *sy
return button;
}
-// Spotify's own queue glyph (SPTEncoreIcon "queue", what the main player's queue button and the Queue tab
-// draw) over the Kit button's list.bullet, which is only what the button is made with. The button keeps its
-// touch and large content viewer; the glyph is its icon's stand-in, so the symbol hides rather than goes. With
-// no Encore (the class gone, or no such glyph) SGTabIconView answers a star symbol, and the bullet list stays.
-// A touch smaller on the iOS < 26 fallback, where the glyph sits among the Kit's own 20pt glyphs and read heavier.
-static CGFloat queueIconSize(void) {
- if (@available(iOS 26.0, *)) return 24;
- return 21;
-}
-
-static void useSpotifyQueueIcon(SGRGlyphButton *button) {
- if (objc_getAssociatedObject(button, &kEncoreMissKey)) return;
- UIView *icon = objc_getAssociatedObject(button, &kEncoreQueueKey);
- if (!icon) {
- UIView *made = SGTabIconView(@"queue", NO, SGRPrimary());
- if (!made || [made isKindOfClass:UIImageView.class]) {
- // No such glyph in this build: not asked again on every layout pass.
- objc_setAssociatedObject(button, &kEncoreMissKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- return;
- }
- icon = made;
- icon.userInteractionEnabled = NO;
- icon.isAccessibilityElement = NO;
- objc_setAssociatedObject(button, &kEncoreQueueKey, icon, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- [button addSubview:icon];
- }
- button.glyph.hidden = YES;
- CGFloat side = queueIconSize();
- icon.bounds = CGRectMake(0, 0, side, side);
- icon.center = CGPointMake(CGRectGetMidX(button.bounds), CGRectGetMidY(button.bounds));
-}
-
#pragma mark the row
static void styleFooter(UIViewController *unit) {
@@ -189,7 +156,6 @@ static void styleFooter(UIViewController *unit) {
});
queue.bounds = CGRectMake(0, 0, 44, 44);
queue.center = CGPointMake(slot(2), middleY);
- useSpotifyQueueIcon(queue);
// The DJ button at the last place. Connect's view reaches a long way to the right of its glyph, so the
// DJ's goes above it in the stack, or Connect would take its touches.
diff --git a/tweak/Sources/Redesigned/Player/Player.h b/tweak/Sources/Redesigned/Player/Player.h
index 820e0c1b..09f1c50e 100644
--- a/tweak/Sources/Redesigned/Player/Player.h
+++ b/tweak/Sources/Redesigned/Player/Player.h
@@ -195,6 +195,11 @@ UIView *SGRPlayerConnectGlyphIn(UIView *host, UIView *connect);
// Connect's touches only in a 44pt square over its glyph: `holder` is the view of the footer that holds Connect, whose
// own view reaches far past the glyph (over Queue and the DJ button once the glyph is moved).
void SGRPlayerCoverConnect(UIView *holder, UIView *glyph);
+// Whether a control is drawn lit: in the accent, judged as Follow the cover judges what it repaints.
+BOOL SGRPlayerAccentLike(UIColor *color);
+// The color an image is drawn in: the average of its opaque pixels, read once at 16 by 16 and kept on the image; nil
+// for one with too few.
+UIColor *SGRPlayerImageInk(UIImage *image);
// The tap to seek around the progress bar (PlayerControls.x), apart for the harness: whether a tap at `point`
// in the duration unit's view seeks, and the share of the song a point on the slider stands for, measured
diff --git a/tweak/Sources/Redesigned/Player/PlayerCoverAccent.x b/tweak/Sources/Redesigned/Player/PlayerCoverAccent.x
index 6d0a4790..493fff75 100644
--- a/tweak/Sources/Redesigned/Player/PlayerCoverAccent.x
+++ b/tweak/Sources/Redesigned/Player/PlayerCoverAccent.x
@@ -14,7 +14,7 @@
static NSInteger sg_cover = -1; // 0xRRGGBB while a cover gives one, else -1
static __weak UIView *sg_stack; // the bottom stack last painted
-static char kOriginalKey, kTintedKey, kTintedCoverKey, kAccentImageKey, kOriginalFillKey, kOriginalStrokeKey;
+static char kOriginalKey, kTintedKey, kTintedCoverKey, kAccentImageKey, kInkKey, kOriginalFillKey, kOriginalStrokeKey;
BOOL SGRPlayerFollowsCover(void) {
static BOOL on;
@@ -72,7 +72,7 @@ static BOOL accentLike(CGFloat r, CGFloat g, CGFloat b) {
return MIN(d, 1 - d) < kHueNear && s > kColorful && v > 0.2;
}
-static BOOL colorAccentLike(UIColor *color) {
+BOOL SGRPlayerAccentLike(UIColor *color) {
CGFloat r, g, b, a;
return color && [color getRed:&r green:&g blue:&b alpha:&a] && a > 0.5 && accentLike(r, g, b);
}
@@ -83,16 +83,15 @@ static BOOL cgAccentLike(CGColorRef color) {
return c[3] > 0.5 && accentLike(c[0], c[1], c[2]);
}
-// Whether an image is drawn in the accent: the average of its opaque pixels, read once at 16 by 16 and kept on it.
-static BOOL imageAccentLike(UIImage *image) {
- NSNumber *known = objc_getAssociatedObject(image, &kAccentImageKey);
- if (known) return known.boolValue;
+UIColor *SGRPlayerImageInk(UIImage *image) {
+ id known = objc_getAssociatedObject(image, &kInkKey);
+ if (known) return known == NSNull.null ? nil : known;
enum { kSide = 16 };
uint8_t pixels[kSide * kSide * 4] = {0};
CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(pixels, kSide, kSide, 8, kSide * 4, space, (CGBitmapInfo)kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(space);
- BOOL accent = NO;
+ UIColor *ink = nil;
if (context && image.CGImage) {
CGContextDrawImage(context, CGRectMake(0, 0, kSide, kSide), image.CGImage);
double r = 0, g = 0, b = 0, n = 0;
@@ -104,9 +103,18 @@ static BOOL imageAccentLike(UIImage *image) {
b += pixels[i * 4 + 2] / (double)alpha;
n++;
}
- accent = n >= 4 && accentLike(r / n, g / n, b / n);
+ if (n >= 4) ink = [UIColor colorWithRed:r / n green:g / n blue:b / n alpha:1];
}
if (context) CGContextRelease(context);
+ objc_setAssociatedObject(image, &kInkKey, ink ?: NSNull.null, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ return ink;
+}
+
+// Whether an image is drawn in the accent, judged once and kept on it.
+static BOOL imageAccentLike(UIImage *image) {
+ NSNumber *known = objc_getAssociatedObject(image, &kAccentImageKey);
+ if (known) return known.boolValue;
+ BOOL accent = SGRPlayerAccentLike(SGRPlayerImageInk(image));
objc_setAssociatedObject(image, &kAccentImageKey, @(accent), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
return accent;
}
@@ -132,7 +140,7 @@ static void paintImageView(UIImageView *view) {
static void paintBackground(UIView *view) {
UIColor *original = objc_getAssociatedObject(view, &kOriginalKey);
UIColor *current = view.backgroundColor;
- if (!original && !colorAccentLike(current)) return;
+ if (!original && !SGRPlayerAccentLike(current)) return;
if (!original) {
original = current;
objc_setAssociatedObject(view, &kOriginalKey, original, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
diff --git a/tweak/Sources/Redesigned/Player/PlayerFooter.x b/tweak/Sources/Redesigned/Player/PlayerFooter.x
index 060d30db..43759c04 100644
--- a/tweak/Sources/Redesigned/Player/PlayerFooter.x
+++ b/tweak/Sources/Redesigned/Player/PlayerFooter.x
@@ -7,6 +7,12 @@
// transform survives the stack view laying them out again, and moving the holder keeps its touches
// inside its own bounds. The device name goes transparent, since the glyph alone sits in the middle, and
// Connect's holder takes touches only in a square over the glyph (SGRPlayerCoverConnect).
+// Both draw the Music app's glyphs, AirPlay audio and a bulleted list (issue #109): a stand-in inside each of
+// Spotify's glyph views, so it is hidden, faded and pulsed with Spotify's own, while Spotify's drawing goes
+// clear at its source. Connect's glyph is an image Spotify draws the color into: each new one is read once for
+// that color, so a device in use still lights it in the accent (or the cover's, PlayerCoverAccent.x), and is
+// swapped for a clear image of its size. The queue's is an SPTEncoreIconView: its foreground colors are kept
+// for the stand-in and Spotify's drawn clear.
// Spotify has no lyrics control down here, so that one is the Kit's glyph button, and it turns the
// lyrics in the player on and off (PlayerLyrics.x): filled while they are up, dimmed and dead for a
// track that has none.
@@ -19,10 +25,11 @@
// ElementView > ConnectButtonOutputSwitcherViewHolder id=Components.ConnectButtonOutputSwitcher 153x36
// (a 19x19 UIImageView glyph and a MarqueeLabel with the device name), a spacer, a hidden media trimmer,
// ElementView > EncoreButton id=ShareButtonNowPlayingView 44x44, ElementView > Queue control
-// id=QueueButtonNowPlaying 47x32.
+// id=QueueButtonNowPlaying 47x32 (an 18x18 SPTEncoreIconView id=Encore.IconView glyph, out/rep/ptree.txt:1228-1279).
#import <substrate.h>
#import "Core/SGCore.h"
#import "Redesigned/Kit/SGRKit.h"
+#import "Headers/SPTEncoreIconView.h"
#import "Player.h"
static const CGFloat kLyricsGlyphSize = 20;
@@ -45,7 +52,10 @@ static const CGFloat kVolumeMargin = 24;
// And the controls go up this much over it, so the gaps above and below the volume row match.
static const CGFloat kVolumeLift = 10;
-static char kConnectKey, kShareKey, kTrimmerKey, kSharedByKey, kQueueKey, kLyricsGlyphKey, kReachKey, kRowKey;
+// "airplayaudio" is the name iOS 16 knows; iOS 18 calls it airplay.audio and keeps this one as its alias.
+static NSString *const kConnectSymbol = @"airplayaudio", *const kQueueSymbol = @"list.bullet";
+
+static char kConnectKey, kShareKey, kTrimmerKey, kSharedByKey, kQueueKey, kQueueIconKey, kLyricsGlyphKey, kReachKey, kRowKey;
static __weak SGRGlyphButton *sg_lyricsGlyph;
// The view the footer's stack view arranges around `view`.
@@ -106,12 +116,132 @@ SGRGlyphButton *SGRPlayerLyricsGlyphIn(UIView *host) {
return glyph;
}
+#pragma mark - the Music app's glyphs
+
+static char kStandInKey, kClearKey, kQueueActiveColorKey;
+
+// The Kit's glyph centered inside `drawn`: it takes `drawn`'s hidden, alpha and animations with it.
+static SGRGlyphView *standIn(UIView *drawn, NSString *symbol) {
+ if (!drawn) return nil;
+ SGRGlyphView *glyph = objc_getAssociatedObject(drawn, &kStandInKey);
+ if (!glyph) {
+ glyph = [[SGRGlyphView alloc] initWithSymbol:symbol pointSize:kLyricsGlyphSize weight:UIImageSymbolWeightRegular];
+ glyph.userInteractionEnabled = NO;
+ glyph.isAccessibilityElement = NO;
+ glyph.tintColor = SGRSecondary(); // at rest, as the Lyrics glyph while it is off
+ // Kept centered when Spotify resizes the view between the footer's passes (a new Connect image of another size).
+ glyph.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin
+ | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
+ objc_setAssociatedObject(drawn, &kStandInKey, glyph, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ }
+ if (glyph.superview != drawn) [drawn addSubview:glyph];
+ CGPoint middle = CGPointMake(CGRectGetMidX(drawn.bounds), CGRectGetMidY(drawn.bounds));
+ if (!CGPointEqualToPoint(glyph.center, middle)) glyph.center = middle;
+ return glyph;
+}
+
+// The color Spotify drew its glyph in (SGRPlayerImageInk, kept on the image, so an image Spotify hands over again costs
+// a lookup). One drawn from the tint answers the tint.
+static UIColor *inkOf(UIImageView *view, UIImage *image) {
+ if (image.isSymbolImage || image.renderingMode == UIImageRenderingModeAlwaysTemplate) return view.tintColor;
+ return SGRPlayerImageInk(image) ?: SGRPrimary();
+}
+
+// A lit glyph as a bitmap in its color, the way Spotify draws its own: Follow the cover finds lit controls by their
+// pixels, and a symbol image has none to read. The symbol's alignment insets are kept, so it sits where it did.
+// Drawn in the glyph's traits (Bold Text, contrast), as its template image is.
+static UIImage *litImage(SGRGlyphView *glyph, UIImage *symbol, UIColor *color) {
+ UIGraphicsImageRendererFormat *format = [UIGraphicsImageRendererFormat formatForTraitCollection:glyph.traitCollection];
+ format.scale = symbol.scale;
+ UIImage *tinted = [symbol imageWithTintColor:color renderingMode:UIImageRenderingModeAlwaysOriginal];
+ __block UIImage *bitmap;
+ [glyph.traitCollection performAsCurrentTraitCollection:^{
+ bitmap = [[[UIGraphicsImageRenderer alloc] initWithSize:symbol.size format:format] imageWithActions:^(UIGraphicsImageRendererContext *context) {
+ [tinted drawAtPoint:CGPointZero];
+ }];
+ }];
+ return [bitmap imageWithAlignmentRectInsets:symbol.alignmentRectInsets];
+}
+
+// Spotify's new Connect glyph: its color onto the stand-in, drawn into the stand-in's image so Follow the cover
+// repaints it the way it did Spotify's, and a clear image of the same size in its place, so nothing moves.
+static void takeConnectImage(UIImageView *drawn) {
+ UIImage *image = drawn.image;
+ UIImage *clear = objc_getAssociatedObject(drawn, &kClearKey);
+ if (!image.CGImage || image == clear) return;
+ SGRGlyphView *glyph = objc_getAssociatedObject(drawn, &kStandInKey);
+ UIImage *symbol = [UIImage systemImageNamed:glyph.symbol withConfiguration:glyph.preferredSymbolConfiguration];
+ UIColor *ink = inkOf(drawn, image);
+ BOOL lit = SGRPlayerAccentLike(ink);
+ glyph.image = lit ? litImage(glyph, symbol, ink) : symbol;
+ // Spotify hands the new image over with no layout pass, so Follow the cover is told here, or a lit glyph keeps the accent.
+ if (lit) SGRPlayerPaintCover(glyph);
+ if (!clear || !CGSizeEqualToSize(clear.size, image.size) || clear.scale != image.scale) {
+ UIGraphicsImageRendererFormat *format = [UIGraphicsImageRendererFormat preferredFormat];
+ format.scale = image.scale;
+ clear = [[[UIGraphicsImageRenderer alloc] initWithSize:image.size format:format] imageWithActions:^(UIGraphicsImageRendererContext *context) {}];
+ objc_setAssociatedObject(drawn, &kClearKey, clear, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ }
+ drawn.image = clear;
+}
+
+// Spotify draws a new glyph when the device changes, with no layout pass of the footer to tell it, so its setImage:
+// tells the stand-in; the clear image set back in reports too, and stops there. Each pass looks too, at the cost of a
+// compare, for a view the image cannot be watched on.
+static void standInForConnect(UIImageView *drawn) {
+ BOOL made = objc_getAssociatedObject(drawn, &kStandInKey) != nil;
+ if (!standIn(drawn, kConnectSymbol)) return;
+ takeConnectImage(drawn);
+ if (!made) SGRObserveImage(drawn, ^(UIImageView *view) { takeConnectImage(view); });
+}
+
+// The queue's state as Spotify sets it, for the stand-in; Spotify's own glyph is drawn in clear.
+static void tintQueueStandIn(SPTEncoreIconView *icon) {
+ SGRGlyphView *glyph = objc_getAssociatedObject(icon, &kStandInKey);
+ // Lit by Spotify's own state, not by a color a cover could make look gray. Lit, it is drawn in the color, as Connect
+ // is, so Follow the cover finds it by its pixels and repaints it.
+ UIColor *active = objc_getAssociatedObject(icon, &kQueueActiveColorKey);
+ UIImage *symbol = [UIImage systemImageNamed:glyph.symbol withConfiguration:glyph.preferredSymbolConfiguration];
+ BOOL lit = icon.isActive && active;
+ glyph.image = lit ? litImage(glyph, symbol, active) : symbol;
+ if (lit) SGRPlayerPaintCover(glyph);
+}
+
+static void standInForQueue(SPTEncoreIconView *icon) {
+ if (![icon isKindOfClass:%c(SPTEncoreIconView)]) return;
+ BOOL made = objc_getAssociatedObject(icon, &kStandInKey) != nil;
+ if (!standIn(icon, kQueueSymbol) || made) return;
+ UIColor *color = icon.foregroundColor, *active = icon.activeForegroundColor;
+ // Through the setters below, which now keep each color and hand Spotify's drawing clear.
+ if (color) icon.foregroundColor = color;
+ if (active) icon.activeForegroundColor = active;
+ tintQueueStandIn(icon);
+}
+
+%hook SPTEncoreIconView
+// The stand-in does not take the color at rest, only the active one.
+- (void)setForegroundColor:(UIColor *)color {
+ %orig(objc_getAssociatedObject(self, &kStandInKey) ? UIColor.clearColor : color);
+}
+- (void)setActiveForegroundColor:(UIColor *)color {
+ BOOL ours = objc_getAssociatedObject(self, &kStandInKey) != nil;
+ if (ours) objc_setAssociatedObject(self, &kQueueActiveColorKey, color, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ %orig(ours ? UIColor.clearColor : color);
+ if (ours) tintQueueStandIn(self);
+}
+- (void)setIsActive:(BOOL)active {
+ %orig;
+ if (objc_getAssociatedObject(self, &kStandInKey)) tintQueueStandIn(self);
+}
+%end
+
#pragma mark - the row
static UIView *connectGlyphIn(UIView *holder) {
__block UIView *glyph = nil;
SGForEachView(holder, ^(UIView *view) {
- if (!glyph && [view isKindOfClass:UIImageView.class] && view.bounds.size.width > 0 && view.bounds.size.width <= kGlyphMaxWidth) glyph = view;
+ if (!glyph && [view isKindOfClass:UIImageView.class] && ![view isKindOfClass:SGRGlyphView.class]
+ && view.bounds.size.width > 0 && view.bounds.size.width <= kGlyphMaxWidth) glyph = view;
});
return glyph;
}
@@ -168,6 +298,7 @@ UIView *SGRPlayerConnectGlyphIn(UIView *host, UIView *connect) {
SGForEachView(connect, ^(UIView *view) {
if ([view isKindOfClass:UILabel.class] || [NSStringFromClass(view.class) containsString:@"MarqueeLabel"]) SGRPlayerVanish(view);
});
+ if (glyph) standInForConnect((UIImageView *)glyph);
return glyph;
}
@@ -301,6 +432,7 @@ void SGRPlayerLowerRow(UIView *row) {
CGFloat connectFrom = glyph ? moveTo(arrangedAround(connect, host), glyph, CGPointMake(CGRectGetMidX(glyph.bounds), CGRectGetMidY(glyph.bounds)), host, round(width * kMiddle)) : -1;
UIView *queue = SGRFindByIdentifier(host, @"QueueButtonNowPlaying", &kQueueKey);
+ standInForQueue((SPTEncoreIconView *)SGRFindByIdentifier(queue, @"Encore.IconView", &kQueueIconKey));
CGFloat queueFrom = moveTo(arrangedAround(queue, host), queue, CGPointMake(CGRectGetMidX(queue.bounds), CGRectGetMidY(queue.bounds)), host, round(width * (rtl ? kLeading : kTrailing)));
SGRPlayerLowerRow(host);
@@ -317,5 +449,5 @@ void SGRPlayerLowerRow(UIView *row) {
%ctor {
if (!SGRedesignedUI()) return;
%init;
- SGRequireClasses(@[@"_TtC20NowPlaying_ModesImpl18FooterElementsUnit"]);
+ SGRequireClasses(@[@"_TtC20NowPlaying_ModesImpl18FooterElementsUnit", @"SPTEncoreIconView"]);
}