Skip to content

Commit

Permalink
Add experimental support for multiple screens
Browse files Browse the repository at this point in the history
  • Loading branch information
janten committed Mar 15, 2017
1 parent ecf1a27 commit ef413e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
26 changes: 15 additions & 11 deletions keypad-layout/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,18 @@ CGEventRef hotkeyCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef ev
}

- (NSRect)rectForCoordinateX:(CGFloat)x Y:(CGFloat)y {
NSScreen *primaryScreen = [NSScreen screens][0];
NSScreen *screen = [NSScreen mainScreen];
NSRect workingRect = screen.visibleFrame;
workingRect.origin.y = (screen.frame.size.height - screen.visibleFrame.size.height) - screen.visibleFrame.origin.y;
CGFloat w = workingRect.size.width/3.0;
CGFloat h = workingRect.size.height/3.0;
CGFloat a = workingRect.origin.x;
CGFloat b = workingRect.origin.y;
NSRect rect = NSMakeRect(a + x * w, b + y * h, w, h);
CGFloat statusBarHeight = [[[NSApplication sharedApplication] mainMenu] menuBarHeight];
CGFloat dockHeight = (screen.frame.size.height - screen.visibleFrame.size.height) - statusBarHeight;
NSRect rect = screen.frame;
rect.origin.y = -screen.frame.origin.y + (primaryScreen.frame.size.height - screen.frame.size.height) ;
rect.origin.y += statusBarHeight;
rect.size.height -= statusBarHeight + dockHeight;
rect.size.width = rect.size.width / 3.0;
rect.size.height = rect.size.height / 3.0;
rect.origin.x += x * rect.size.width;
rect.origin.y += y * rect.size.height;
rect = NSInsetRect(rect, 1, 1);
return rect;
}
Expand Down Expand Up @@ -153,15 +157,15 @@ - (void)setFrontmostWindowFrame:(CGRect)frame {
CFRelease(appElem);
return;
}

AXValueRef positionValue = AXValueCreate(kAXValueTypeCGPoint, &frame.origin);
AXUIElementSetAttributeValue(window, kAXPositionAttribute, positionValue);
CFRelease(positionValue);

AXValueRef sizeValue = AXValueCreate(kAXValueTypeCGSize, &frame.size);
AXUIElementSetAttributeValue(window, kAXSizeAttribute, sizeValue);
CFRelease(sizeValue);

AXValueRef positionValue = AXValueCreate(kAXValueTypeCGPoint, &frame.origin);
AXUIElementSetAttributeValue(window, kAXPositionAttribute, positionValue);
CFRelease(positionValue);

CFRelease(window);
CFRelease(appElem);
}
Expand Down
4 changes: 2 additions & 2 deletions keypad-layout/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>1.1</string>
<key>CFBundleVersion</key>
<string>2</string>
<string>5</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.productivity</string>
<key>LSMinimumSystemVersion</key>
Expand Down

0 comments on commit ef413e4

Please sign in to comment.