Skip to content

Commit 37f7c2f

Browse files
committed
Swap from AppKit to Foundation
1 parent 234f476 commit 37f7c2f

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

spaces-renamer/spacesRenamer.m

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Copyright 2017 Alex Beals.
77
//
88

9-
@import AppKit;
9+
@import Foundation;
1010
#import "ZKSwizzle.h"
1111
#import <QuartzCore/QuartzCore.h>
1212

@@ -20,6 +20,15 @@
2020
#define listOfSpacesPlist [@"~/Library/Containers/com.alexbeals.spacesrenamer/com.alexbeals.spacesrenamer.currentspaces.plist" stringByExpandingTildeInPath]
2121
#define spacesPath [@"~/Library/Preferences/com.apple.spaces.plist" stringByExpandingTildeInPath]
2222

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+
2332
int monitorIndex = 0;
2433

2534
@interface ECMaterialLayer : CALayer
@@ -397,16 +406,19 @@ - (BOOL)probablyDesktopSwitcher:(CGRect)rect {
397406
return false;
398407
}
399408

409+
// Get all of the monitors
410+
CGDirectDisplayID displayArray[kMaxDisplays];
411+
uint32_t displayCount;
412+
CGGetActiveDisplayList(kMaxDisplays, displayArray, &displayCount);
413+
400414
// Is the width of the full screen (one of them)
401-
NSArray *const screenArray = [NSScreen screens];
402-
for (int i = 0; i < screenArray.count; i++) {
403-
NSScreen *const screen = [screenArray objectAtIndex:i];
404-
if (screen.visibleFrame.size.width == rect.size.width) {
415+
for (int i = 0; i < displayCount; i++) {
416+
if (CGDisplayPixelsWide(displayArray[i]) == rect.size.width) {
405417
return true;
406418
}
407419
}
408420

409-
// Default to NO
421+
// Default to false
410422
return false;
411423
}
412424

0 commit comments

Comments
 (0)