Skip to content

Commit

Permalink
Set frame if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
janten committed Apr 9, 2021
1 parent 678c357 commit 776046e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
8 changes: 4 additions & 4 deletions keypad-layout.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,12 @@
buildSettings = {
CODE_SIGN_IDENTITY = "";
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 20;
CURRENT_PROJECT_VERSION = 21;
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "keypad-layout/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MARKETING_VERSION = 1.8;
MARKETING_VERSION = 1.9;
PRODUCT_BUNDLE_IDENTIFIER = "com.jan-gerd.keypad-layout";
PRODUCT_NAME = "Keypad Layout";
};
Expand All @@ -300,12 +300,12 @@
buildSettings = {
CODE_SIGN_IDENTITY = "";
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 20;
CURRENT_PROJECT_VERSION = 21;
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "keypad-layout/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MARKETING_VERSION = 1.8;
MARKETING_VERSION = 1.9;
PRODUCT_BUNDLE_IDENTIFIER = "com.jan-gerd.keypad-layout";
PRODUCT_NAME = "Keypad Layout";
};
Expand Down
32 changes: 14 additions & 18 deletions keypad-layout/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -219,29 +219,25 @@ - (void)setFrontmostWindowFrame:(CGRect)frame {
return;
}

Boolean canSetFrame = false;
CFStringRef kAXFrameAttribute = CFSTR("AXFrame");
CFArrayRef names = NULL;
AXUIElementCopyAttributeNames(window, &names);
AXUIElementIsAttributeSettable(window, kAXFrameAttribute, &canSetFrame);

if (names) {
CFRange range = CFRangeMake(0, CFArrayGetCount(names));
bool hasFrame = CFArrayContainsValue(names, range, kAXFrameAttribute);

if (hasFrame) {
AXValueRef frameValue = AXValueCreate(kAXValueTypeCGRect, &frame);
AXUIElementSetAttributeValue(window, kAXFrameAttribute, frameValue);
CFRelease(frameValue);
}

CFRelease(names);
if (canSetFrame) {
// Should macOS ever allow us to set origin and size in one call, this should work.
AXValueRef frameValue = AXValueCreate(kAXValueTypeCGRect, &frame);
AXUIElementSetAttributeValue(window, kAXFrameAttribute, frameValue);
CFRelease(frameValue);
} else {
AXValueRef positionValue = AXValueCreate(kAXValueTypeCGPoint, &frame.origin);
AXUIElementSetAttributeValue(window, kAXPositionAttribute, positionValue);
CFRelease(positionValue);

// FIXME: Big Sur starts an animation for the first call and ignores the second one if the animation does not
// finish soon enough.
AXValueRef sizeValue = AXValueCreate(kAXValueTypeCGSize, &frame.size);
AXUIElementSetAttributeValue(window, kAXSizeAttribute, sizeValue);
AXError error = AXUIElementSetAttributeValue(window, kAXSizeAttribute, sizeValue);
CFRelease(sizeValue);

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

CFRelease(window);
Expand Down
Binary file modified keypad-layout/AppIcon.icns
Binary file not shown.
Binary file modified keypad-layout/Icon.psd
Binary file not shown.

0 comments on commit 776046e

Please sign in to comment.