Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
feat(player): center back and next when shuffle and repeat are hidden (#162) (#174)
My-Name-Is-Jefffc64dc74cf1b
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex 6b95cedc..4f01114b 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -566,7 +566,8 @@ Redesigned:cover plays at 2x until the finger lifts (PlayerArtwork.x), an octave higher while Pitch followsspeed is on. Hide on the player's Shuffle and Repeat (spotifyglass.redesign.player.hideShuffle,.hideRepeat, read at launch) take those buttons off the controls by alpha in their slots, as the- Music app keeps them off its own (PlayerControls.x). A Free account gets it too: Spotify's Reinvented Free player mode, whose units none of+ Music app keeps them off its own (PlayerControls.x); with both off, previous and next are translated+ out to a quarter of the row either side of play, the Music app's spacing (issue #162). A Free account gets it too: Spotify's Reinvented Free player mode, whose units none ofthe hooks reach, declines while the redesign runs, so the track falls to Spotify's other Free mode,built from the units the redesign styles (PlayerFree.x, read from the binary, not yet seen on a Freeaccount). Animated artwork (PlayerMotion.x)diff --git a/tweak/Sources/Redesigned/Player/Player.h b/tweak/Sources/Redesigned/Player/Player.hindex 0801d2e5..d49a895d 100644--- a/tweak/Sources/Redesigned/Player/Player.h+++ b/tweak/Sources/Redesigned/Player/Player.h@@ -132,7 +132,8 @@ void SGRPlayerPaintCover(UIView *stack);// Shuffle and repeat left out of the controls (PlayerControls.x), each on its own switch under Hide on the player, the// way the Music app keeps them off its main controls. Off until switched on, read at launch. The buttons go by alpha-// and keep their slots, so previous, play and next stay where they are, centered.+// and keep their slots. With one gone, previous, play and next stay where they are, centered; with both gone,+// previous and next move out a quarter of the row either side of play, as the Music app spaces them (issue #162).#define SGRKeyPlayerHideShuffle @"spotifyglass.redesign.player.hideShuffle"#define SGRKeyPlayerHideRepeat @"spotifyglass.redesign.player.hideRepeat"@@ -212,6 +213,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);+// Translates `arranged`, a view a stack arranges, so that `point` of `view` inside it lands at `x` in `host`: a transform+// survives the stack laying it out again, and the arranged view takes its touches along. Measured where the stack put+// it, its own transform left out, which is returned (-1 for no `arranged`). The footer's glyphs (PlayerFooter.x) and+// previous and next with shuffle and repeat both hidden (PlayerControls.x) move by it.+CGFloat SGRPlayerTranslateArranged(UIView *arranged, UIView *view, CGPoint point, UIView *host, CGFloat x);// 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; nildiff --git a/tweak/Sources/Redesigned/Player/PlayerControls.x b/tweak/Sources/Redesigned/Player/PlayerControls.xindex 9dbb0e8b..27cdf287 100644--- a/tweak/Sources/Redesigned/Player/PlayerControls.x+++ b/tweak/Sources/Redesigned/Player/PlayerControls.x@@ -99,8 +99,9 @@ static void skipGlyph(UIView *host, NSString *identifier, const void *findKey, N#pragma mark - shuffle and repeat// Each switched on under Hide on the player (SGRKeyPlayerHideShuffle, SGRKeyPlayerHideRepeat), read at launch. By-// alpha in their slots: the row is Spotify's stack of five, and setting `hidden` in an Encore stack crashes. Kept by-// SGRSuppress, since Spotify's state render sets a button's alpha back to 1 when shuffle or repeat changes.+// alpha in their slots (with both gone, previous and next spread over them: spreadControls): the row is Spotify's+// stack of five, and setting `hidden` in an Encore stack crashes. Kept by SGRSuppress, since Spotify's state render+// sets a button's alpha back to 1 when shuffle or repeat changes.static BOOL sg_hideShuffle, sg_hideRepeat;// The ordinary player's controls, apart from sg_controlsHost, which the DJ's set too.static __weak UIView *sg_buttonsHost;@@ -137,12 +138,94 @@ static void suppressButton(UIView *button) {%init(SGRPlayerButtonArrival, SGRPlayerButton = button.class);}+// Issue #162: with both gone, previous and next spread out over the room the two left, the way the Music app sets+// its three controls: a quarter of the row's span either side of play, which stays in the middle. The row is+// Spotify's stack of five, so they move by a translation of the arranged view that holds each, as the footer's+// glyphs do (SGRPlayerTranslateArranged): a transform survives the stack laying them out again, and the holder+// takes its touches along. With only one of the two gone they stay in their slots, so play stays centered between+// them. The spread follows the switches and the row's shape, not the buttons in it at that moment: Spotify swaps+// repeat for a new one after the controls lay out (SGRPlayerButtonArrival), and a pass that missed the button would+// put previous and next back with no later pass to spread them again. A row of another shape (a podcast's) gets+// its holders back where the stack puts them.+static char kQuietKey, kMovedKey;+// The ends of the row shuffle and repeat were last found in.+static __weak UIView *sg_shuffleSlot;+static __weak UIView *sg_repeatSlot;++// Whether `slot`, an end of the row, is the hidden button's: it holds the button now, or it is the one the button+// was last found in, for the moment Spotify has taken the button out and not yet put the new one in.+static BOOL hiddenSlot(UIView *slot, UIView *button, UIView *__weak *remembered) {+ if (!slot) return NO;+ if (button) *remembered = slot;+ return slot == *remembered;+}++// Marked, so a row that stops spreading puts back only the holders moved here.+static void moveHolder(UIView *holder, UIView *row, CGFloat x) {+ SGRPlayerTranslateArranged(holder, holder, CGPointMake(CGRectGetMidX(holder.bounds), CGRectGetMidY(holder.bounds)), row, x);+ if (!objc_getAssociatedObject(holder, &kMovedKey)) objc_setAssociatedObject(holder, &kMovedKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);+}++// The holder of a hidden button stays where the stack put it and stops taking touches, or one over the moved+// next (the last of the row is on top) would keep them from it. Given its touches back once the row no longer+// spreads, since Spotify may reuse it for another button (a podcast's).+static void quietHolder(UIView *holder, BOOL quiet) {+ BOOL quieted = objc_getAssociatedObject(holder, &kQuietKey) != nil;+ if (quiet == quieted) return;+ holder.userInteractionEnabled = !quiet;+ objc_setAssociatedObject(holder, &kQuietKey, quiet ? @YES : nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);+}++// With both switched on. `arranged` is the row's arranged views, `shuffle` and `repeat` the buttons found in its ends+// this pass, if any.+static void spreadControls(UIView *host, UIStackView *row, NSArray<UIView *> *arranged, UIView *shuffle, UIView *repeat) {+ // Five holders: shuffle's and repeat's at the ends, play's in the middle, previous's and next's either side of it,+ // in either order (a right-to-left layout). The three were found this pass already, for their glyphs.+ UIView *before = nil, *after = nil;+ BOOL apart = NO;+ if (arranged.count == 5 && hiddenSlot(arranged[0], shuffle, &sg_shuffleSlot) && hiddenSlot(arranged[4], repeat, &sg_repeatSlot)) {+ UIView *previous = SGRFindByIdentifier(host, @"SPTNowPlayingPreviousTrackButton", &kPreviousKey);+ UIView *next = SGRFindByIdentifier(host, @"SPTNowPlayingNextTrackButton", &kNextKey);+ UIView *play = SGRFindByIdentifier(host, @"SPTNowPlayingPlayButton", &kPlayKey);+ BOOL inOrder = [previous isDescendantOfView:arranged[1]];+ before = arranged[inOrder ? 1 : 3];+ after = arranged[inOrder ? 3 : 1];+ apart = previous && next && [play isDescendantOfView:arranged[2]] && [previous isDescendantOfView:before] && [next isDescendantOfView:after];+ }+ if (!apart) {+ for (UIView *holder in arranged) {+ if (objc_getAssociatedObject(holder, &kMovedKey)) {+ holder.transform = CGAffineTransformIdentity;+ objc_setAssociatedObject(holder, &kMovedKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ }+ quietHolder(holder, NO);+ }+ return;+ }+ UIView *first = arranged[0], *last = arranged[4];+ // Centers and bounds are where the stack put the holders, untouched by their transforms.+ CGFloat start = first.center.x - CGRectGetWidth(first.bounds) / 2, end = last.center.x + CGRectGetWidth(last.bounds) / 2;+ CGFloat middle = arranged[2].center.x, reach = (end - start) / 4;+ // The side previous is on (the right in a right-to-left layout); next goes to the other.+ CGFloat side = before.center.x < middle ? -1 : 1;+ moveHolder(before, row, middle + side * reach);+ moveHolder(after, row, middle - side * reach);+ quietHolder(first, YES);+ quietHolder(last, YES);+ static dispatch_once_t once;+ dispatch_once(&once, ^{ SGLog(@"redesign player: shuffle and repeat hidden, previous and next %.0fpt either side of play", reach); });+}+// Each is looked for only in its own end of the row, so a row without it (a podcast's) costs a walk of one// element, not the unit.static void hideShuffleAndRepeat(UIView *host, UIStackView *row) {sg_buttonsHost = host;- if (sg_hideShuffle) suppressButton(SGRFindByIdentifier(row.arrangedSubviews.firstObject, kShuffleID, &kShuffleKey));- if (sg_hideRepeat) suppressButton(SGRFindByIdentifier(row.arrangedSubviews.lastObject, kRepeatID, &kRepeatKey));+ NSArray<UIView *> *arranged = row.arrangedSubviews;+ UIView *shuffle = sg_hideShuffle ? SGRFindByIdentifier(arranged.firstObject, kShuffleID, &kShuffleKey) : nil;+ UIView *repeat = sg_hideRepeat ? SGRFindByIdentifier(arranged.lastObject, kRepeatID, &kRepeatKey) : nil;+ suppressButton(shuffle);+ suppressButton(repeat);+ if (sg_hideShuffle && sg_hideRepeat) spreadControls(host, row, arranged, shuffle, repeat);}#pragma mark - playdiff --git a/tweak/Sources/Redesigned/Player/PlayerFooter.x b/tweak/Sources/Redesigned/Player/PlayerFooter.xindex 10e76de2..0df84303 100644--- a/tweak/Sources/Redesigned/Player/PlayerFooter.x+++ b/tweak/Sources/Redesigned/Player/PlayerFooter.x@@ -77,7 +77,7 @@ static CGFloat untransformedX(UIView *arranged, UIView *view, CGPoint point, UIVreturn [arranged.superview convertPoint:inRow toView:host].x;}-static CGFloat moveTo(UIView *arranged, UIView *view, CGPoint point, UIView *host, CGFloat x) {+CGFloat SGRPlayerTranslateArranged(UIView *arranged, UIView *view, CGPoint point, UIView *host, CGFloat x) {if (!arranged) return -1;CGFloat from = untransformedX(arranged, view, point, host);CGAffineTransform transform = CGAffineTransformMakeTranslation(round(x - from), 0);@@ -476,11 +476,11 @@ void SGRPlayerLowerRow(UIView *row) {UIView *connect = SGRFindByIdentifier(host, @"Components.ConnectButtonOutputSwitcher", &kConnectKey);UIView *glyph = SGRPlayerConnectGlyphIn(host, connect);- CGFloat connectFrom = glyph ? moveTo(arrangedAround(connect, host), glyph, CGPointMake(CGRectGetMidX(glyph.bounds), CGRectGetMidY(glyph.bounds)), host, round(width * kMiddle)) : -1;+ CGFloat connectFrom = glyph ? SGRPlayerTranslateArranged(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)));+ CGFloat queueFrom = SGRPlayerTranslateArranged(arrangedAround(queue, host), queue, CGPointMake(CGRectGetMidX(queue.bounds), CGRectGetMidY(queue.bounds)), host, round(width * (rtl ? kLeading : kTrailing)));SGRPlayerLowerRow(host);SGRPlayerCoverConnect(arrangedAround(connect, host), glyph);