From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: "Charles A. Roelli" Newsgroups: gmane.emacs.bugs Subject: bug#26816: mouse movement support for OS X Date: Thu, 18 May 2017 21:43:37 +0200 Message-ID: <576caa34-3ec3-3670-c113-23501db35779@aurox.ch> References: <20170507200034.GA661@breton.holly.idiocy.org> <20170509224435.GB8974@breton.holly.idiocy.org> <20170511214342.GA10431@breton.holly.idiocy.org> <3dc0d587-8290-f873-ceef-d059bec0b7f6@aurox.ch> <20170514135910.GA13710@breton.holly.idiocy.org> <83y3tz7bcp.fsf@gnu.org> <76527b19-1f31-0642-ac3a-8e55fd9b0a90@aurox.ch> <20170516225301.GA49449@breton.holly.idiocy.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------CABF158FC5B308C0D90B740E" X-Trace: blaine.gmane.org 1495136660 22901 195.159.176.226 (18 May 2017 19:44:20 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 18 May 2017 19:44:20 +0000 (UTC) User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 Cc: 26816@debbugs.gnu.org To: Andreas Schwab , Alan Third Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu May 18 21:44:14 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dBRLK-0005nf-6H for geb-bug-gnu-emacs@m.gmane.org; Thu, 18 May 2017 21:44:14 +0200 Original-Received: from localhost ([::1]:55270 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBRLP-0006Vt-ML for geb-bug-gnu-emacs@m.gmane.org; Thu, 18 May 2017 15:44:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59865) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBRLD-0006UG-EJ for bug-gnu-emacs@gnu.org; Thu, 18 May 2017 15:44:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBRL8-00029l-GE for bug-gnu-emacs@gnu.org; Thu, 18 May 2017 15:44:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:51157) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dBRL8-00029P-9k for bug-gnu-emacs@gnu.org; Thu, 18 May 2017 15:44:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dBRL8-0003E8-3z for bug-gnu-emacs@gnu.org; Thu, 18 May 2017 15:44:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Charles A. Roelli" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 18 May 2017 19:44:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 26816 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 26816-submit@debbugs.gnu.org id=B26816.149513663112378 (code B ref 26816); Thu, 18 May 2017 19:44:02 +0000 Original-Received: (at 26816) by debbugs.gnu.org; 18 May 2017 19:43:51 +0000 Original-Received: from localhost ([127.0.0.1]:53834 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dBRKw-0003DZ-I7 for submit@debbugs.gnu.org; Thu, 18 May 2017 15:43:50 -0400 Original-Received: from sinyavsky.aurox.ch ([37.35.109.145]:50502) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dBRKv-0003DM-6O for 26816@debbugs.gnu.org; Thu, 18 May 2017 15:43:50 -0400 Original-Received: from sinyavsky.aurox.ch (sinyavsky.aurox.ch [127.0.0.1]) by sinyavsky.aurox.ch (Postfix) with ESMTP id 1CBF622435 for <26816@debbugs.gnu.org>; Thu, 18 May 2017 19:39:21 +0000 (UTC) Authentication-Results: sinyavsky.aurox.ch (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=aurox.ch DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=aurox.ch; h= content-type:content-type:in-reply-to:mime-version:user-agent :date:date:message-id:from:from:references:to:subject:subject; s=dkim; t=1495136358; x=1496000359; bh=3lSAbyc5ageDhDKwdnUkZ1pA 7X1VmZzPOHid6ajJPxs=; b=lEmPmRtNqDEOsarVOX4ZGR736RsIJk2FQvA089mj gVESvDZ/dfxLMCgJTBcs/oBVr9DWRJmnn4w4Db9I9daGfRrJ1wVKwJiGAa49RBLb /IdwakQlJwkl/wEnXS1m/88j+MtDvP43bOL+H46Nof0GskEikxJJxltk45TZ7qIC HyU= X-Virus-Scanned: Debian amavisd-new at test.virtualizor.com Original-Received: from sinyavsky.aurox.ch ([127.0.0.1]) by sinyavsky.aurox.ch (sinyavsky.aurox.ch [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id TJtQg5DnFFGJ for <26816@debbugs.gnu.org>; Thu, 18 May 2017 19:39:18 +0000 (UTC) Original-Received: from [192.168.1.121] (179.133.105.92.dynamic.wline.res.cust.swisscom.ch [92.105.133.179]) by sinyavsky.aurox.ch (Postfix) with ESMTPSA id 767092242E; Thu, 18 May 2017 19:39:17 +0000 (UTC) In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:132606 Archived-At: This is a multi-part message in MIME format. --------------CABF158FC5B308C0D90B740E Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Sorry for the trouble -- I had called M-x untabify on two lines of the patch (bad idea, I think) and I must have messed up the line count at that point too. Second attempt attached. Cheers, Charles On 17/05/2017 10:36, Andreas Schwab wrote: > On Mai 16 2017, Alan Third wrote: > >> On Mon, May 15, 2017 at 08:23:27PM +0200, Charles A. Roelli wrote: >>> Patch is attached, with a commit message. >> For some reason I can’t apply this patch. It looks fine, and I can’t >> see what the problem is at all. > The patch is broken, the hunk for test/lisp/mouse-tests.el has the wrong > line count: > > @@ -47,5 +47,13 @@ > (should-not (mouse--down-1-maybe-follows-link)) > (should (equal unread-command-events '((mouse-2 nil 1)))))) > > +(ert-deftest bug26816-mouse-frame-movement () > + "Mouse moves relative to frame." > + (skip-unless (display-graphic-p)) > + (let ((frame (selected-frame))) > + (set-mouse-position frame 0 0) > + (should (equal (mouse-position) > + (cons frame (cons 0 0)))))) > + > + > ;;; mouse-tests.el ends here --------------CABF158FC5B308C0D90B740E Content-Type: text/x-patch; name="0001-Fix-macOS-mouse-movement.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Fix-macOS-mouse-movement.patch" >From c052ea0a343beefe35c6d7343740724e062a5989 Mon Sep 17 00:00:00 2001 From: Charles A. Roelli Date: Thu, 18 May 2017 21:31:46 +0200 Subject: [PATCH] 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. --- etc/NEWS | 3 +++ lisp/frame.el | 3 +++ src/nsfns.m | 39 +++++++++++++++++++++++++++++++++++++++ src/nsterm.h | 2 +- src/nsterm.m | 14 +++++++------- test/lisp/mouse-tests.el | 9 +++++++++ 6 files changed, 62 insertions(+), 8 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 6851dc9..1faa1db 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1294,6 +1294,9 @@ This is in contrast to the default action on POSIX Systems, where it causes the receiving process to terminate with a core dump if no debugger has been attached to it. +** `set-mouse-position' and `set-mouse-absolute-pixel-position' work +on macOS. + ---------------------------------------------------------------------- This file is part of GNU Emacs. diff --git a/lisp/frame.el b/lisp/frame.el index 05db8cf..02871e0 100644 --- a/lisp/frame.el +++ b/lisp/frame.el @@ -1465,6 +1465,7 @@ mouse-absolute-pixel-position (t (cons 0 0))))) +(declare-function ns-set-mouse-absolute-pixel-position "nsfns.m" (x y)) (declare-function w32-set-mouse-absolute-pixel-position "w32fns.c" (x y)) (declare-function x-set-mouse-absolute-pixel-position "xfns.c" (x y)) @@ -1474,6 +1475,8 @@ set-mouse-absolute-pixel-position position (0, 0) of the selected frame's terminal." (let ((frame-type (framep-on-display))) (cond + ((eq frame-type 'ns) + (ns-set-mouse-absolute-pixel-position x y)) ((eq frame-type 'x) (x-set-mouse-absolute-pixel-position x y)) ((eq frame-type 'w32) diff --git a/src/nsfns.m b/src/nsfns.m index cbe0ffb..f9fb964 100644 --- a/src/nsfns.m +++ b/src/nsfns.m @@ -3053,6 +3053,44 @@ value is a list of the form (LEFT, TOP, RIGHT, BOTTOM). All values are : Qnative_edges)); } +DEFUN ("ns-set-mouse-absolute-pixel-position", + Fns_set_mouse_absolute_pixel_position, + Sns_set_mouse_absolute_pixel_position, 2, 2, 0, + doc: /* Move mouse pointer to absolute pixel position (X, Y). +The coordinates X and Y are interpreted in pixels relative to a position +\(0, 0) of the selected frame's display. */) + (Lisp_Object x, Lisp_Object y) +{ + struct frame *f = SELECTED_FRAME (); + EmacsView *view = FRAME_NS_VIEW (f); + NSScreen *screen = [[view window] screen]; + NSRect screen_frame = [screen frame]; + int mouse_x, mouse_y; + + NSScreen *primary_screen = [[NSScreen screens] objectAtIndex:0]; + NSRect primary_screen_frame = [primary_screen frame]; + CGFloat primary_screen_height = primary_screen_frame.size.height; + + if (FRAME_INITIAL_P (f) || !FRAME_NS_P (f)) + return Qnil; + + CHECK_TYPE_RANGED_INTEGER (int, x); + CHECK_TYPE_RANGED_INTEGER (int, y); + + mouse_x = screen_frame.origin.x + XINT (x); + + if (screen == primary_screen) + mouse_y = screen_frame.origin.y + XINT (y); + else + mouse_y = (primary_screen_height - screen_frame.size.height + - screen_frame.origin.y) + XINT (y); + + CGPoint mouse_pos = CGPointMake(mouse_x, mouse_y); + CGWarpMouseCursorPosition (mouse_pos); + + return Qnil; +} + /* ========================================================================== Class implementations @@ -3241,6 +3279,7 @@ - (NSString *)panel: (id)sender userEnteredFilename: (NSString *)filename defsubr (&Sns_frame_edges); defsubr (&Sns_frame_list_z_order); defsubr (&Sns_frame_restack); + defsubr (&Sns_set_mouse_absolute_pixel_position); defsubr (&Sx_display_mm_width); defsubr (&Sx_display_mm_height); defsubr (&Sx_display_screens); diff --git a/src/nsterm.h b/src/nsterm.h index 9285178..ac339bf 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -1087,7 +1087,7 @@ struct x_output ? ([[FRAME_NS_VIEW (f) window] parentWindow].frame.origin.y \ + [[FRAME_NS_VIEW (f) window] parentWindow].frame.size.height \ - FRAME_NS_TITLEBAR_HEIGHT (FRAME_PARENT_FRAME (f))) \ - : [[[FRAME_NS_VIEW (f) window] screen] frame].size.height) + : [[[NSScreen screens] objectAtIndex: 0] frame].size.height) #define FRAME_NS_FONT_TABLE(f) (FRAME_DISPLAY_INFO (f)->font_table) diff --git a/src/nsterm.m b/src/nsterm.m index c22c5a7..a7ab73b 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -2321,14 +2321,14 @@ so some key presses (TAB) are swallowed by the system. */ -------------------------------------------------------------------------- */ { NSTRACE ("frame_set_mouse_pixel_position"); - ns_raise_frame (f); -#if 0 - /* FIXME: this does not work, and what about GNUstep? */ + + /* FIXME: what about GNUstep? */ #ifdef NS_IMPL_COCOA - [FRAME_NS_VIEW (f) lockFocus]; - PSsetmouse ((float)pix_x, (float)pix_y); - [FRAME_NS_VIEW (f) unlockFocus]; -#endif + CGPoint mouse_pos = + CGPointMake(f->left_pos + pix_x, + f->top_pos + pix_y + + FRAME_NS_TITLEBAR_HEIGHT(f) + FRAME_TOOLBAR_HEIGHT(f)); + CGWarpMouseCursorPosition (mouse_pos); #endif } diff --git a/test/lisp/mouse-tests.el b/test/lisp/mouse-tests.el index fffaa2f..a8eca28 100644 --- a/test/lisp/mouse-tests.el +++ b/test/lisp/mouse-tests.el @@ -47,4 +47,13 @@ (should-not (mouse--down-1-maybe-follows-link)) (should (equal unread-command-events '((mouse-2 nil 1)))))) +(ert-deftest bug26816-mouse-frame-movement () + "Mouse moves relative to frame." + (skip-unless (display-graphic-p)) + (let ((frame (selected-frame))) + (set-mouse-position frame 0 0) + (should (equal (mouse-position) + (cons frame (cons 0 0)))))) + + ;;; mouse-tests.el ends here -- 1.7.4.4 --------------CABF158FC5B308C0D90B740E--