How to programmatically zoom in on a screen using private logging methods (how to find function arguments)

as you may know that Mac OS X has pretty nice screen scaling functionality that can be included in System Preferences => Accessibility.

Now I'm trying to programmatically zoom in on this screen. I can do this by sending keyboard shortcuts, but it's not as hard as it could be. So I did some research on how the system does this.

There seem to be some private graphical methods that can do what I want, but I cannot find what arguments they take.

These are the functions that I found:

  • CGSZoomPoint
  • CGSUnzoomPoint
  • CGSGetZoomParameters
  • CGSSetZoomParameters
  • CGSIsZoomed

Some people already discard some private methods of the main graphics environment and create headers for them. (see, for example, http://pwproject.googlecode.com/svn/trunk/Mac%20OS%20X/Vector%20Grab/ ) Unfortunately, the methods that seem to me are missing. (CGSIsZoomed, actually enabled

CG_EXTERN CGError CGSIsZoomed(CGSConnectionID cid, bool *outIsZoomed); 

)

I also found an application that seems to be able to zoom in on the screen, and this seems to be appropriate disassembly, but I don't know much about assembler, so I can't read it ;-(

 0000000100015c21 callq 0x10002c212 ; symbol stub for: _CGEventCreate 0000000100015c26 movq %rax,%rbx 0000000100015c29 movq %rbx,%rdi 0000000100015c2c callq 0x10002c22a ; symbol stub for: _CGEventGetLocation 0000000100015c31 movsd %xmm0,0xffffff48(%rbp) 0000000100015c39 movsd %xmm1,0xffffff58(%rbp) 0000000100015c41 movsd %xmm0,0xa8(%rbp) 0000000100015c46 movsd %xmm1,0xb0(%rbp) 0000000100015c4b movq %rbx,%rdi 0000000100015c4e callq 0x10002c362 ; symbol stub for: _CFRelease 0000000100015c5a jle 0x100015d01 0000000100015c60 movq 0x00098a71(%rip),%rax 0000000100015c67 movq 0x18(%rax),%rcx 0000000100015c6b movq %rcx,0x18(%rsp) 0000000100015c70 movq 0x10(%rax),%rcx 0000000100015c74 movq %rcx,0x10(%rsp) 0000000100015c79 movq (%rax),%rcx 0000000100015c7c movq 0x08(%rax),%rax 0000000100015c80 movq %rax,0x08(%rsp) 0000000100015c85 movq %rcx,(%rsp) 0000000100015c89 movsd 0xffffff48(%rbp),%xmm0 0000000100015c91 movsd 0xffffff58(%rbp),%xmm1 0000000100015c99 callq 0x10002c266 ; symbol stub for: _CGRectContainsPoint 0000000100015c9e cmpl $0x02,0x00098a43(%rip) 0000000100015ca5 jl 0x100015d01 0000000100015ca7 movl $0x 00000001,%r15d 0000000100015cad movl $0x00000020,%ebx 0000000100015cb2 movsd 0xa8(%rbp),%xmm0 0000000100015cb7 movsd 0xb0(%rbp),%xmm1 0000000100015cbc movq 0x00098a15(%rip),%rax 0000000100015cc3 movq 0x18(%rax,%rbx),%rcx 0000000100015cc8 movq %rcx,0x18(%rsp) 0000000100015ccd movq 0x10(%rax,%rbx),%rcx 0000000100015cd2 movq %rcx,0x10(%rsp) 0000000100015cd7 movq (%rax,%rbx),%rcx 0000000100015cdb movq 0x08(%rax,%rbx),%rax 0000000100015ce0 movq %rax,0x08(%rsp) 0000000100015ce5 movq %rcx,(%rsp) 0000000100015ce9 callq 0x10002c266 ; symbol stub for: _CGRectContainsPoint 0000000100015cee addq $0x20,%rbx 0000000100015cf2 incq %r15 0000000100015cf5 movslq 0x000989ec(%rip),%rax 0000000100015cfc cmpq %rax,%r15 0000000100015cff jl 0x100015cb2 0000000100015d01 movsd 0xc0(%rbp),%xmm0 0000000100015d06 movsd %xmm0,0xffffff58(%rbp) 0000000100015d0e leaq 0xa8(%rbp),%rsi 0000000100015d12 leaq 0x98(%rbp),%rdx 0000000100015d16 movl %r14d,%edi 0000000100015d19 callq 0x10002c296 ; symbol stub for: _CGSZoomPoint 0000000100015d1e movsd 0xffffff58(%rbp),%xmm2 0000000100015d26 testl %eax,%eax 0000000100015d28 jne 0x100015d99 0000000100015d2a movapd %xmm2,%xmm0 0000000100015d2e mulsd 0xffffff60(%rbp),%xmm0 0000000100015d36 addsd 0x98(%rbp),%xmm0 0000000100015d3b movsd 0x00017255(%rip),%xmm1 0000000100015d43 ucomisd %xmm0,%xmm1 0000000100015d47 ja 0x100015d78 0000000100015d49 ucomisd 0x0001749f(%rip),%xmm0 0000000100015d51 ja 0x100015d78 0000000100015d53 mulsd 0xffffff50(%rbp),%xmm2 0000000100015d5b addsd 0xa0(%rbp),%xmm2 0000000100015d60 movsd 0x00017230(%rip),%xmm0 0000000100015d68 ucomisd %xmm2,%xmm0 0000000100015d6c ja 0x100015d78 0000000100015d6e ucomisd 0x00017482(%rip),%xmm2 0000000100015d76 jbe 0x100015d99 0000000100015d78 movzbl 0xbf(%rbp),%edx 0000000100015d7c andl $0x01,%edx 0000000100015d7f movsd 0xc0(%rbp),%xmm0 0000000100015d84 leaq 0xc8(%rbp),%rsi 0000000100015d88 movl %r14d,%edi 0000000100015d8b movl $0x 00000001,%ecx 0000000100015d90 xorpd %xmm1,%xmm1 0000000100015d94 callq 0x10002c290 ; symbol stub for: _CGSSetZoomParameters 0000000100015d99 movsd 0xffffff70(%rbp),%xmm1 0000000100015da1 addsd 0xffffff50(%rbp),%xmm1 0000000100015da9 movsd 0xffffff68(%rbp),%xmm0 0000000100015db1 addsd 0xffffff60(%rbp),%xmm0 0000000100015db9 movb 0x000988f1(%rip),%al 0000000100015dbf xorl %edi,%edi 0000000100015dc1 cmpb $0x01,%al 0000000100015dc3 jne 0x100015dde 0000000100015dc5 movl $0x 00000006,%esi 0000000100015dca xorl %edx,%edx 

If anyone knows how to use those private functions that you would have done in my week :-)

Best, Thomas

+4
source share
1 answer

It’s good that this question went unanswered, but I understood how to use CGSGetZoomParameters and CGSSetZoomParameters for my own work, and both of them can be used to control and get information about the increased state of the screen. Function Definitions:

 CG_EXTERN CGError CGSGetZoomParameters(CGSConnectionID cid, CGPoint *origin, double * zoomFactor, int8_t *smoothed); CG_EXTERN CGError CGSSetZoomParameters(CGSConnectionID cid, CGPoint *origin, double zoomFactor, int8_t smoothed); 

where origin determines which portion of the screen is scaled using the following method:

To increase the area as much as possible, set origin.x to: desktopWidth / zoomFactor

To scale the area as much as possible, set origin.x to: desktopWidth - (desktopWidth / zoomFactor)

To scale the area as far as possible, set origin.x to: desktopHeight / zoomFactor

To scale the area as far as possible, set origin.x to: desktopHeight - (desktopHeight / zoomFactor)

For desktopWidth and desktopHeight , the total width / height of the bounding box of the current desktop, including all displays in their current layout. Therefore, if you have two 1080p displays arranged exactly horizontally, the total width and height of the desktop is 3840x1080.

To scale the intermediate region, use the value of origin , which is somewhere between two extrema. Mathematics works so that the number of integer points between them exactly matches the number of positions that the enlarged screen can have for any given zoomFactor .

These features are low and will interfere with the standard MacOS availability scaling features. For example, if your screen is not jagged, you will increase its use with CGSSetZoomParameters , and then use one of the accessibility functions, such as holding the control and scrolling the mouse wheel to zoom, they will work as if the screen was unzoomed. In addition, when you zoom in on the screen, it cannot be started with the mouse, regardless of how accessibility scaling functions are configured, so be careful! You can make the screen zoom in and leave the user without a good way to zoom out.

I'm not sure how CGSZoomPoint or CGSUnzoomPoint are CGSUnzoomPoint - I could not get them to have any effect. But, as said, a low level of control of screen scaling can be performed using two other functions.

0
source

Source: https://habr.com/ru/post/1442482/


All Articles