[Mac-emacs-devel] set-mouse-position patch for Mac OS X
Brought to you by:
akochoi
From: Steven T. <ste...@ma...> - 2002-07-19 08:32:35
|
After much digging I found a way to move the mouse cursor around programmatically in Mac OS X, despite the documentation of CursorDeviceMoveTo saying you could not. In Quartz 2D, they added the ability to directly modify the screen, including setting the position of the cursor. The documentation can be found in a technote here http://developer.apple.com/technotes/tn/tn2007.html I'm running 10.1.5, so that's all I can vouch for. To try it out you can simple eval (set-mouse-position (selected-frame) 10 10) and it should jump the cursor 10 lines down and 10 characters over. If you remove the call to ObscureCursor in XTread_socket it will be more dramatic. mouse-avoidance-mode is even more clever. Replace the implementation of x_set_mouse_pixel_position in macterm.c (around line 9923 in my version) to be this... void x_set_mouse_pixel_position (f, pix_x, pix_y) struct frame *f; int pix_x, pix_y; { #if MAC_OSX CGPoint point; Point pt; Rect r; GrafPtr savePort; BLOCK_INPUT; GetPort(&savePort); #if TARGET_API_MAC_CARBON SetPort (GetWindowPort (FRAME_MAC_WINDOW (f))); #else SetPort (FRAME_MAC_WINDOW (f)); #endif GetWindowPortBounds (FRAME_MAC_WINDOW (f), &r); SetPt(&pt, r.left, r.top); LocalToGlobal(&pt); SetPort (savePort); /* Use Quartz 2d Direct Display API to move cursor. Not sure if this works on OS X 10.0 */ point = CGPointMake(pt.h+pix_x, pt.v+pix_y); CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, point); UNBLOCK_INPUT; #endif /* MAC_OSX */ } Thanks for reading, -Steven |