Skip to content

Commit

Permalink
Merge pull request #58 from dado3212/DockSupport
Browse files Browse the repository at this point in the history
[v1.7.3] Add in proper support for having Dock on the right
  • Loading branch information
dado3212 authored May 22, 2020
2 parents 75f748b + e905741 commit 43d50d5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 31 deletions.
2 changes: 1 addition & 1 deletion SpacesRenamer/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.7.2</string>
<string>1.7.3</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
Expand Down
Binary file modified build/spaces-renamer.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion spaces-renamer/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.7.2</string>
<string>1.7.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
51 changes: 22 additions & 29 deletions spaces-renamer/spacesRenamer.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
static char OVERRIDDEN_STRING;
static char OVERRIDDEN_WIDTH;
static char OFFSET;
static char MOVED;
static char NEW_X;
static char TYPE;

#define customNamesPlist [@"~/Library/Containers/com.alexbeals.spacesrenamer/com.alexbeals.spacesrenamer.plist" stringByExpandingTildeInPath]
Expand Down Expand Up @@ -186,42 +186,35 @@ static int getSelected(NSArray<CALayer *> *views) {

ZKSwizzleInterface(_SRCALayer, CALayer, CALayer);
@implementation _SRCALayer
- (void)setBounds:(CGRect)arg1 {

return ZKOrig(void, arg1);
}
- (void)setFrame:(CGRect)arg1 {
id possibleWidth = objc_getAssociatedObject(self, &OVERRIDDEN_WIDTH);
if (possibleWidth && [possibleWidth isKindOfClass:[NSNumber class]] && self.class == NSClassFromString(@"CALayer")) {
arg1.size.width = [possibleWidth doubleValue] + 20;
}

id possibleType = objc_getAssociatedObject(self, &TYPE);
if (possibleType == nil) {
return ZKOrig(void, arg1);
}

int textIndex = self.sublayers.lastObject.class == NSClassFromString(@"ECTextLayer")
? (int)self.sublayers.count - 1
: -1;

if (textIndex != -1) {
id possibleWidth = objc_getAssociatedObject(self.sublayers[textIndex], &OVERRIDDEN_WIDTH);
if (possibleWidth && [possibleWidth isKindOfClass:[NSNumber class]]) {
arg1.size.width = [possibleWidth doubleValue];
}

id possibleType = objc_getAssociatedObject(self, &TYPE);
if (possibleType && [possibleType isEqualToString:@"expanded"]) {
// Always just center in the parent view
arg1.origin.x = self.superlayer.frame.size.width / 2 - arg1.size.width / 2;
} else {
id possibleOffset = objc_getAssociatedObject(self.sublayers[textIndex], &OFFSET);
id didMove = objc_getAssociatedObject(self, &MOVED);
// Only change the offsets once
if (possibleOffset && [possibleOffset isKindOfClass:[NSNumber class]] && (!didMove || ![didMove boolValue])) {
arg1.origin.x += [possibleOffset doubleValue];
int textIndex = (int)self.sublayers.count - 1;
possibleWidth = objc_getAssociatedObject(self.sublayers[textIndex], &OVERRIDDEN_WIDTH);
if (possibleWidth && [possibleWidth isKindOfClass:[NSNumber class]]) {
arg1.size.width = [possibleWidth doubleValue];
}

assign(self, &MOVED, [NSNumber numberWithBool:YES]);
}
if ([possibleType isEqualToString:@"expanded"]) {
// Always just center in the parent view
arg1.origin.x = self.superlayer.frame.size.width / 2 - arg1.size.width / 2;
} else if ([possibleType isEqualToString:@"unexpanded"]) {
id possibleOffset = objc_getAssociatedObject(self.sublayers[textIndex], &OFFSET);
id newX = objc_getAssociatedObject(self, &NEW_X);
// Only change the offsets once
if (possibleOffset && [possibleOffset isKindOfClass:[NSNumber class]] && (newX == nil || [newX doubleValue] != arg1.origin.x)) {
arg1.origin.x += [possibleOffset doubleValue];

assign(self, &NEW_X, @(arg1.origin.x));
}


}

return ZKOrig(void, arg1);
Expand Down

0 comments on commit 43d50d5

Please sign in to comment.