目标 C 辅助功能 API:最大化 Window
ObjectiveC Accessibility API: UnMaximize Window
我不确定我指的是否正确,但是当我使用“UnMaximize”这个词时,我指的是:
When you click on the green button which is third on the top left of a
Chrome Window, it Maximizes the Window. When I use the word
“UnMaximize” above, I’m referring to the behavior that clicks that
button again so that it is no longer in full screen.
(顺便说一句,在 MacOS 术语中正确的说法是什么?)
我喜欢使用 Easy Move+Resize App. While it can move Windows around, unfortunately, it has no effect on windows that are Maximized. Fortunately, the code is available on Github。
我很好奇是否有人可以告诉我如何使用辅助功能 API
取消最大化 Window
有谁知道 UnMaximize 等同于 kAXCloseButtonAttribute
如果有帮助,我正在使用 MacOs 10.12。
感谢 @Willeke - Willeke 为我指明了正确的方向。
如我的问题所述,我正在查看 Easy Move+Resize App on GitHub 的代码。这个 code/app 的问题是它对当前 Maximized 的 Windows 不起作用,即它试图移动这些 Windows,但它不能,因为它们是固定的。 (注意: 这仅在多显示器设置中有用且相关。) 此应用程序适用于 Windows没有最大化。
在这里,我试图添加代码 UnMaximize a window 以便移动它,然后 Maximize 它被移动后再次出现。显然,下面的代码是在这个应用程序的上下文中,但我相信在其他上下文中对用户有用。
我先加了一个wasMaximized
属性到EMRMoveResize.h
//EMRMoveResize.h
@property bool wasMaximized;
接下来,我移动到 EMRAppDelegate.m 实际事件回调代码所在的位置。应该注意的是,我们只关心移动,即只关心鼠标左键。 (此应用程序使用鼠标右键调整大小,当Window已最大化时不相关。)所以,我们只关心 kCGEventLeftMouseDown
、kCGEventLeftMouseDragged
,最后是 kCGEventLeftMouseUp
。在伪代码中,我做了类似的事情:
If (LeftMouseDown) {
Find out if Window is Maximized
If (Window is Maximized) {
set the wasMaximized property
Click FullScreen Button to UnMaximize the Window in Order to Move it
}
Window 现在 UnMaximized 现在会像 LeftMouseDragged 事件中的其他 windows 一样移动,这我没有做任何改变。最后,
If(LeftMouseUp) {
If(wasMaximized value was set) {
Click FullScreen Button again to Maximize the Window (Since it started out as Maximized)
Reset the wasMaximized property
}
}
现在将代码片段更改为 EMRAppDelegate.m
if (type == kCGEventLeftMouseDown
|| type == kCGEventRightMouseDown) {
//..
//Skipped Unchanged Code
//..
//Find out if Window is Maximized
CFTypeRef TypeRef = nil;
if (AXUIElementCopyAttributeValue((AXUIElementRef)_clickedWindow, CFSTR("AXFullScreen"), &TypeRef)) {
if(Debug) NSLog(@"Could not get wasMaximized Value");
} else {
[moveResize setWasMaximized: CFBooleanGetValue(TypeRef)];
if(Debug) NSLog(CFBooleanGetValue(TypeRef) ? @"Updated Maximized to True" : @"Updated Maximized to False");
}
//Click FullScreen Button to UnMaximize the Window in Order to Move it
if([moveResize wasMaximized]) {
AXUIElementRef buttonRef = nil;
AXUIElementCopyAttributeValue(_clickedWindow, kAXFullScreenButtonAttribute, (CFTypeRef*)&buttonRef);
if(Debug) NSLog(@"buttonRef: %p", buttonRef);
AXUIElementPerformAction(buttonRef, kAXPressAction);
CFRelease(buttonRef);
}
//..
//Skipped Unchanged Code
//..
}
if (type == kCGEventLeftMouseUp
|| type == kCGEventRightMouseUp) {
//..
//Skipped Unchanged Code
//..
//Click FullScreen Button again to Maximize the Window (Since it started out as Maximized)
AXUIElementRef _clickedWindow = [moveResize window];
if([moveResize wasMaximized]) {
AXUIElementRef buttonRef = nil;
AXUIElementCopyAttributeValue(_clickedWindow, kAXFullScreenButtonAttribute, (CFTypeRef*)&buttonRef);
if(Debug) NSLog(@"buttonRef: %p", buttonRef);
AXUIElementPerformAction(buttonRef, kAXPressAction);
CFRelease(buttonRef);
[moveResize setWasMaximized: false];
}
//..
//Skipped Unchanged Code
//..
}
这对我有用。但我不是 Objective C 或 MacOS 方面的专家,所以如果您觉得有什么可以改进的地方,请随时编辑post。
我不确定我指的是否正确,但是当我使用“UnMaximize”这个词时,我指的是:
When you click on the green button which is third on the top left of a Chrome Window, it Maximizes the Window. When I use the word “UnMaximize” above, I’m referring to the behavior that clicks that button again so that it is no longer in full screen.
(顺便说一句,在 MacOS 术语中正确的说法是什么?)
我喜欢使用 Easy Move+Resize App. While it can move Windows around, unfortunately, it has no effect on windows that are Maximized. Fortunately, the code is available on Github。
我很好奇是否有人可以告诉我如何使用辅助功能 API
取消最大化 Window有谁知道 UnMaximize 等同于 kAXCloseButtonAttribute
如果有帮助,我正在使用 MacOs 10.12。
感谢 @Willeke - Willeke 为我指明了正确的方向。
如我的问题所述,我正在查看 Easy Move+Resize App on GitHub 的代码。这个 code/app 的问题是它对当前 Maximized 的 Windows 不起作用,即它试图移动这些 Windows,但它不能,因为它们是固定的。 (注意: 这仅在多显示器设置中有用且相关。) 此应用程序适用于 Windows没有最大化。
在这里,我试图添加代码 UnMaximize a window 以便移动它,然后 Maximize 它被移动后再次出现。显然,下面的代码是在这个应用程序的上下文中,但我相信在其他上下文中对用户有用。
我先加了一个wasMaximized
属性到EMRMoveResize.h
//EMRMoveResize.h
@property bool wasMaximized;
接下来,我移动到 EMRAppDelegate.m 实际事件回调代码所在的位置。应该注意的是,我们只关心移动,即只关心鼠标左键。 (此应用程序使用鼠标右键调整大小,当Window已最大化时不相关。)所以,我们只关心 kCGEventLeftMouseDown
、kCGEventLeftMouseDragged
,最后是 kCGEventLeftMouseUp
。在伪代码中,我做了类似的事情:
If (LeftMouseDown) {
Find out if Window is Maximized
If (Window is Maximized) {
set the wasMaximized property
Click FullScreen Button to UnMaximize the Window in Order to Move it
}
Window 现在 UnMaximized 现在会像 LeftMouseDragged 事件中的其他 windows 一样移动,这我没有做任何改变。最后,
If(LeftMouseUp) {
If(wasMaximized value was set) {
Click FullScreen Button again to Maximize the Window (Since it started out as Maximized)
Reset the wasMaximized property
}
}
现在将代码片段更改为 EMRAppDelegate.m
if (type == kCGEventLeftMouseDown
|| type == kCGEventRightMouseDown) {
//..
//Skipped Unchanged Code
//..
//Find out if Window is Maximized
CFTypeRef TypeRef = nil;
if (AXUIElementCopyAttributeValue((AXUIElementRef)_clickedWindow, CFSTR("AXFullScreen"), &TypeRef)) {
if(Debug) NSLog(@"Could not get wasMaximized Value");
} else {
[moveResize setWasMaximized: CFBooleanGetValue(TypeRef)];
if(Debug) NSLog(CFBooleanGetValue(TypeRef) ? @"Updated Maximized to True" : @"Updated Maximized to False");
}
//Click FullScreen Button to UnMaximize the Window in Order to Move it
if([moveResize wasMaximized]) {
AXUIElementRef buttonRef = nil;
AXUIElementCopyAttributeValue(_clickedWindow, kAXFullScreenButtonAttribute, (CFTypeRef*)&buttonRef);
if(Debug) NSLog(@"buttonRef: %p", buttonRef);
AXUIElementPerformAction(buttonRef, kAXPressAction);
CFRelease(buttonRef);
}
//..
//Skipped Unchanged Code
//..
}
if (type == kCGEventLeftMouseUp
|| type == kCGEventRightMouseUp) {
//..
//Skipped Unchanged Code
//..
//Click FullScreen Button again to Maximize the Window (Since it started out as Maximized)
AXUIElementRef _clickedWindow = [moveResize window];
if([moveResize wasMaximized]) {
AXUIElementRef buttonRef = nil;
AXUIElementCopyAttributeValue(_clickedWindow, kAXFullScreenButtonAttribute, (CFTypeRef*)&buttonRef);
if(Debug) NSLog(@"buttonRef: %p", buttonRef);
AXUIElementPerformAction(buttonRef, kAXPressAction);
CFRelease(buttonRef);
[moveResize setWasMaximized: false];
}
//..
//Skipped Unchanged Code
//..
}
这对我有用。但我不是 Objective C 或 MacOS 方面的专家,所以如果您觉得有什么可以改进的地方,请随时编辑post。