6
6
// Copyright 2017 Alex Beals.
7
7
//
8
8
9
- @import AppKit ;
9
+ @import Foundation ;
10
10
#import " ZKSwizzle.h"
11
11
#import < QuartzCore/QuartzCore.h>
12
12
20
20
#define listOfSpacesPlist [@" ~/Library/Containers/com.alexbeals.spacesrenamer/com.alexbeals.spacesrenamer.currentspaces.plist" stringByExpandingTildeInPath ]
21
21
#define spacesPath [@" ~/Library/Preferences/com.apple.spaces.plist" stringByExpandingTildeInPath ]
22
22
23
+ // Maximum online or active displays.
24
+ //
25
+ // SpacesRenamer uses the core graphics API to get online/active
26
+ // displays by calling CGGetActiveDisplayList() and CGGetOnlineDisplayList(),
27
+ // this definition is the count that will be used when calling those functions.
28
+ //
29
+ // If you have more than 12 monitors, this tweak can't help you with organization, good luck.
30
+ #define kMaxDisplays 12
31
+
23
32
int monitorIndex = 0 ;
24
33
25
34
@interface ECMaterialLayer : CALayer
@@ -38,8 +47,9 @@ static void refreshFrames(CALayer *frame) {
38
47
39
48
static void refreshFramesSur (CALayer *frame, CALayer * exception) {
40
49
for (CALayer *layer in frame.sublayers ) {
41
- if (![layer isEqualTo: exception])
42
- [layer setFrame: layer.frame];
50
+ if (![layer isEqualTo: exception]) {
51
+ [layer setFrame: layer.frame];
52
+ }
43
53
refreshFramesSur (layer, exception);
44
54
}
45
55
}
@@ -148,8 +158,8 @@ static double getTextSize(CALayer *view, NSString *string) {
148
158
static int getSelected (NSArray <CALayer *> *views) {
149
159
NSUInteger selectedIndex = [views indexOfObjectPassingTest:
150
160
^(CALayer *layer, NSUInteger idx, BOOL *stop) {
151
- return (BOOL )(layer.sublayers .count > 1 );
152
- }];
161
+ return (BOOL )(layer.sublayers .count > 1 );
162
+ }];
153
163
154
164
return selectedIndex == NSNotFound ? -1 : (int )selectedIndex;
155
165
}
@@ -159,7 +169,7 @@ static int getSelected(NSArray<CALayer *> *views) {
159
169
2. Load the listOfSpacesPlist to get the current list of spaces
160
170
3. Crosslist and return the custom names for each plist, and whether it's selected
161
171
*/
162
- static NSMutableArray *getNamesFromPlist () {
172
+ static NSMutableArray < NSMutableArray < NSMutableDictionary *> *> *getNamesFromPlist () {
163
173
NSDictionary *dictOfNames = [NSDictionary dictionaryWithContentsOfFile: customNamesPlist];
164
174
if (!dictOfNames) {
165
175
return [NSMutableArray arrayWithCapacity: 0 ];
@@ -287,18 +297,22 @@ @implementation _SRECMaterialLayer
287
297
- (void )setFrame : (CGRect)arg1 {
288
298
// Almost surely the desktop switcher
289
299
if ([self probablyDesktopSwitcher: arg1]) {
290
- CALayer *rootLayer = self;
291
- Boolean bigSurOrNewer = false ;
292
300
NSOperatingSystemVersion macOS = NSProcessInfo .processInfo .operatingSystemVersion ;
293
- if (macOS.majorVersion >= 11 || macOS.minorVersion >= 16 ) bigSurOrNewer = true ;
294
- if (bigSurOrNewer) rootLayer = self.superlayer ;
295
-
301
+ bool bigSurOrNewer = (macOS.majorVersion >= 11 || macOS.minorVersion >= 16 );
302
+
303
+ CALayer *rootLayer;
304
+ if (bigSurOrNewer) {
305
+ rootLayer = self.superlayer ;
306
+ } else {
307
+ rootLayer = self;
308
+ }
309
+
296
310
NSArray <CALayer *> *unexpandedViews = rootLayer.sublayers [self .sublayers.count - 1 ].sublayers [0 ].sublayers ;
297
311
NSArray <CALayer *> *expandedViews = rootLayer.sublayers [self .sublayers.count - 1 ].sublayers [1 ].sublayers ;
298
-
312
+
299
313
if (bigSurOrNewer) {
300
- unexpandedViews = rootLayer.sublayers [2 ].sublayers [0 ].sublayers ;
301
- expandedViews = rootLayer.sublayers [2 ].sublayers [1 ].sublayers ;
314
+ unexpandedViews = rootLayer.sublayers [2 ].sublayers [0 ].sublayers ;
315
+ expandedViews = rootLayer.sublayers [2 ].sublayers [1 ].sublayers ;
302
316
}
303
317
304
318
int numMonitors = MAX ((int )unexpandedViews.count , (int )expandedViews.count );
@@ -307,7 +321,7 @@ - (void)setFrame:(CGRect)arg1 {
307
321
int selected = getSelected ((!unexpandedViews || !unexpandedViews.count ) ? expandedViews : unexpandedViews);
308
322
309
323
// Get all of the names
310
- NSMutableArray * names = getNamesFromPlist ();
324
+ NSMutableArray < NSMutableArray < NSMutableDictionary *> *> * names = getNamesFromPlist ();
311
325
312
326
if (names.count == 0 ) {
313
327
ZKOrig (void , arg1);
@@ -318,7 +332,7 @@ - (void)setFrame:(CGRect)arg1 {
318
332
NSMutableArray *possibleMonitors = [[NSMutableArray alloc ] init ];
319
333
for (int i = 0 ; i < names.count ; i++) {
320
334
if (
321
- (( NSArray *) names[i]) .count == numMonitors && // Same number of monitors
335
+ names[i].count == numMonitors && // Same number of monitors
322
336
[names[i][selected][@" selected" ] boolValue ] // Same index is selected
323
337
) {
324
338
[possibleMonitors addObject: [NSNumber numberWithInt: i]];
@@ -368,10 +382,11 @@ - (void)setFrame:(CGRect)arg1 {
368
382
monitorIndex += 1 ;
369
383
370
384
// So that it doesn't change sizes on switching spaces
371
- if (!bigSurOrNewer)
372
- refreshFrames (rootLayer);
373
- else
374
- refreshFramesSur (rootLayer, self);
385
+ if (!bigSurOrNewer) {
386
+ refreshFrames (rootLayer);
387
+ } else {
388
+ refreshFramesSur (rootLayer, self);
389
+ }
375
390
}
376
391
ZKOrig (void , arg1);
377
392
}
@@ -391,16 +406,19 @@ - (BOOL)probablyDesktopSwitcher:(CGRect)rect {
391
406
return false ;
392
407
}
393
408
409
+ // Get all of the monitors
410
+ CGDirectDisplayID displayArray[kMaxDisplays ];
411
+ uint32_t displayCount;
412
+ CGGetActiveDisplayList (kMaxDisplays , displayArray, &displayCount);
413
+
394
414
// Is the width of the full screen (one of them)
395
- NSArray *const screenArray = [NSScreen screens ];
396
- for (int i = 0 ; i < screenArray.count ; i++) {
397
- NSScreen *const screen = [screenArray objectAtIndex: i];
398
- if (screen.visibleFrame .size .width == rect.size .width ) {
415
+ for (int i = 0 ; i < displayCount; i++) {
416
+ if (CGDisplayPixelsWide (displayArray[i]) == rect.size .width ) {
399
417
return true ;
400
418
}
401
419
}
402
420
403
- // Default to NO
421
+ // Default to false
404
422
return false ;
405
423
}
406
424
0 commit comments