开发者

OS X Accessibility API Minimum Width

开发者 https://www.devze.com 2023-03-27 04:32 出处:网络
I found another question and answer explaining how to get the width, height, and position of a window using the Accessibility API. Is there any way to find the minimum size, maximum size, resize incre

I found another question and answer explaining how to get the width, height, and position of a window using the Accessibility API. Is there any way to find the minimum size, maximum size, resize increments, etc?

Edit:

My current approach is to use AXUIElementCopyAttributeValue but I'm not sure that's possible . Looking at the reference you can see there are a lot of properties I can access, but I can't find any mention of the minimum or maximum size of the window. Note it seems position is accessible through this API.

Now I was also looking at some sample code called Son of Grab which is also able to access window size and position but I don't believe that method works for minimum or maximum size eit开发者_如何转开发her.


As far as I can tell, there is no easy way about it. I have found one very crude method of getting the maximum and minimum size of the window.

It involves setting the width and height to a very large number to see how far the window resizes then remembering this size as the maximum, then setting the width and height to a small number and doing the same again. After all this I just reset the width and height to their original values.

The obvious problem with this is the fact that it is very visible to the user that the window has been resized.

As for the resize increments I can't think of (at the moment) any workaround to getting that information.

Anyway here's the code I have for working out the maximum and minimum size:

AXUIElementRef window; // The window

AXValueRef sizeValue = (AXValueRef)[UIElementUtilities valueOfAttribute:@"AXSize" ofUIElement:window];
CGSize windowSize;
AXValueGetValue(sizeValue, kAXValueCGSizeType, &windowSize);

CGFloat windowWidth = windowSize.width;
CGFloat windowHeight = windowSize.height;

// Set it to a very large number
[UIElementUtilities setStringValue:@"w=5000 h=5000" forAttribute:@"AXSize" ofUIElement:window];

AXValueRef maxSizeValue = (AXValueRef)[UIElementUtilities valueOfAttribute:@"AXSize" ofUIElement:window];
CGSize maxWindowSize;
AXValueGetValue(maxSizeValue, kAXValueCGSizeType, &maxWindowSize);

CGFloat maxWindowWidth = maxWindowSize.width;
CGFloat maxWindowHeight = maxWindowSize.height;

NSLog(@"max width = %f. max height = %f.", maxWindowWidth, maxWindowHeight);

// Set it to a very small number
[UIElementUtilities setStringValue:@"w=0 h=0" forAttribute:@"AXSize" ofUIElement:window];

AXValueRef minSizeValue = (AXValueRef)[UIElementUtilities valueOfAttribute:@"AXSize" ofUIElement:window];
CGSize minWindowSize;
AXValueGetValue(minSizeValue, kAXValueCGSizeType, &minWindowSize);

CGFloat minWindowWidth = minWindowSize.width;
CGFloat minWindowHeight = minWindowSize.height;

NSLog(@"min width = %f. min height = %f.", minWindowWidth, minWindowHeight);

// Reset size
[UIElementUtilities setStringValue:[NSString stringWithFormat:@"w=%f h=%f", windowWidth, windowHeight] forAttribute:@"AXSize" ofUIElement:window];

In case you were wondering, UIElementUtilities is a class I've taken from one of the Apple example projects called UIElementInspector.

0

精彩评论

暂无评论...
验证码 换一张
取 消