diff options
| author | Charles A. Roelli | 2017-05-18 21:31:46 +0200 |
|---|---|---|
| committer | Alan Third | 2017-05-21 00:09:41 +0100 |
| commit | 7e5a8cdceb408077df78b1ea810b1f5d4657303d (patch) | |
| tree | 0b8ec76811bc1e66aa3fbfa5ad594a3e6cbb302a /src/nsfns.m | |
| parent | c969b3997168de2bbe781fbcb08b67b15eddc02d (diff) | |
| download | emacs-7e5a8cdceb408077df78b1ea810b1f5d4657303d.tar.gz emacs-7e5a8cdceb408077df78b1ea810b1f5d4657303d.zip | |
Fix macOS mouse movement
* lisp/frame.el (ns-set-mouse-absolute-pixel-position): New
function (Lisp).
(set-mouse-absolute-pixel-position): Change it to call
`ns-set-mouse-absolute-pixel-position' on macOS.
* src/nsfns.m (Fns_set_mouse_absolute_pixel_position): New
function.
* src/nsterm.h (NS_PARENT_WINDOW_TOP_POS): Use the primary
screen's height as a base for calculating global coordinates.
* src/nsterm.m (frame_set_mouse_pixel_position): Fix it in macOS.
* test/lisp/mouse-tests.el (bug26816-mouse-frame-movement): Test
movement of mouse relative to frame.
Diffstat (limited to 'src/nsfns.m')
| -rw-r--r-- | src/nsfns.m | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/nsfns.m b/src/nsfns.m index 04565a99bb7..a815ce656cb 100644 --- a/src/nsfns.m +++ b/src/nsfns.m | |||
| @@ -3066,6 +3066,44 @@ menu bar or tool bar of FRAME. */) | |||
| 3066 | : Qnative_edges)); | 3066 | : Qnative_edges)); |
| 3067 | } | 3067 | } |
| 3068 | 3068 | ||
| 3069 | DEFUN ("ns-set-mouse-absolute-pixel-position", | ||
| 3070 | Fns_set_mouse_absolute_pixel_position, | ||
| 3071 | Sns_set_mouse_absolute_pixel_position, 2, 2, 0, | ||
| 3072 | doc: /* Move mouse pointer to absolute pixel position (X, Y). | ||
| 3073 | The coordinates X and Y are interpreted in pixels relative to a position | ||
| 3074 | \(0, 0) of the selected frame's display. */) | ||
| 3075 | (Lisp_Object x, Lisp_Object y) | ||
| 3076 | { | ||
| 3077 | struct frame *f = SELECTED_FRAME (); | ||
| 3078 | EmacsView *view = FRAME_NS_VIEW (f); | ||
| 3079 | NSScreen *screen = [[view window] screen]; | ||
| 3080 | NSRect screen_frame = [screen frame]; | ||
| 3081 | int mouse_x, mouse_y; | ||
| 3082 | |||
| 3083 | NSScreen *primary_screen = [[NSScreen screens] objectAtIndex:0]; | ||
| 3084 | NSRect primary_screen_frame = [primary_screen frame]; | ||
| 3085 | CGFloat primary_screen_height = primary_screen_frame.size.height; | ||
| 3086 | |||
| 3087 | if (FRAME_INITIAL_P (f) || !FRAME_NS_P (f)) | ||
| 3088 | return Qnil; | ||
| 3089 | |||
| 3090 | CHECK_TYPE_RANGED_INTEGER (int, x); | ||
| 3091 | CHECK_TYPE_RANGED_INTEGER (int, y); | ||
| 3092 | |||
| 3093 | mouse_x = screen_frame.origin.x + XINT (x); | ||
| 3094 | |||
| 3095 | if (screen == primary_screen) | ||
| 3096 | mouse_y = screen_frame.origin.y + XINT (y); | ||
| 3097 | else | ||
| 3098 | mouse_y = (primary_screen_height - screen_frame.size.height | ||
| 3099 | - screen_frame.origin.y) + XINT (y); | ||
| 3100 | |||
| 3101 | CGPoint mouse_pos = CGPointMake(mouse_x, mouse_y); | ||
| 3102 | CGWarpMouseCursorPosition (mouse_pos); | ||
| 3103 | |||
| 3104 | return Qnil; | ||
| 3105 | } | ||
| 3106 | |||
| 3069 | /* ========================================================================== | 3107 | /* ========================================================================== |
| 3070 | 3108 | ||
| 3071 | Class implementations | 3109 | Class implementations |
| @@ -3254,6 +3292,7 @@ be used as the image of the icon representing the frame. */); | |||
| 3254 | defsubr (&Sns_frame_edges); | 3292 | defsubr (&Sns_frame_edges); |
| 3255 | defsubr (&Sns_frame_list_z_order); | 3293 | defsubr (&Sns_frame_list_z_order); |
| 3256 | defsubr (&Sns_frame_restack); | 3294 | defsubr (&Sns_frame_restack); |
| 3295 | defsubr (&Sns_set_mouse_absolute_pixel_position); | ||
| 3257 | defsubr (&Sx_display_mm_width); | 3296 | defsubr (&Sx_display_mm_width); |
| 3258 | defsubr (&Sx_display_mm_height); | 3297 | defsubr (&Sx_display_mm_height); |
| 3259 | defsubr (&Sx_display_screens); | 3298 | defsubr (&Sx_display_screens); |