From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Alan Third Newsgroups: gmane.emacs.bugs Subject: bug#4892: [PATCH] Fix mouse-position on macOS (bug#4892) Date: Wed, 4 Dec 2019 12:44:04 +0000 Message-ID: <20191204124404.GA62687@breton.holly.idiocy.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="180661"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.12.0 (2019-05-25) Cc: 4892@debbugs.gnu.org To: David Reitter Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Dec 04 13:49:42 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1icU69-000kqH-SO for geb-bug-gnu-emacs@m.gmane.org; Wed, 04 Dec 2019 13:49:42 +0100 Original-Received: from localhost ([::1]:38332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1icU68-0002NJ-M5 for geb-bug-gnu-emacs@m.gmane.org; Wed, 04 Dec 2019 07:49:40 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54937) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1icU1f-00078W-SD for bug-gnu-emacs@gnu.org; Wed, 04 Dec 2019 07:45:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1icU1e-0003VW-My for bug-gnu-emacs@gnu.org; Wed, 04 Dec 2019 07:45:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35562) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1icU1e-0003Tv-G2 for bug-gnu-emacs@gnu.org; Wed, 04 Dec 2019 07:45:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1icU1e-0008NS-Cl for bug-gnu-emacs@gnu.org; Wed, 04 Dec 2019 07:45:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 04 Dec 2019 12:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 4892 X-GNU-PR-Package: emacs Original-Received: via spool by 4892-submit@debbugs.gnu.org id=B4892.157546345532135 (code B ref 4892); Wed, 04 Dec 2019 12:45:02 +0000 Original-Received: (at 4892) by debbugs.gnu.org; 4 Dec 2019 12:44:15 +0000 Original-Received: from localhost ([127.0.0.1]:41535 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1icU0t-0008ME-2E for submit@debbugs.gnu.org; Wed, 04 Dec 2019 07:44:15 -0500 Original-Received: from mail-wm1-f49.google.com ([209.85.128.49]:37841) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1icU0r-0008M2-3I for 4892@debbugs.gnu.org; Wed, 04 Dec 2019 07:44:13 -0500 Original-Received: by mail-wm1-f49.google.com with SMTP id f129so7790629wmf.2 for <4892@debbugs.gnu.org>; Wed, 04 Dec 2019 04:44:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=5pssJB3Qd9My0EHODX+a/H7IyapNo0V5QYinao+SMcQ=; b=RhvrAD88BC3/qSkIaf4oiiE1Af+sPNwlkA3sEVS0T+pExlSQAEZPFnLbAmOn/KEAEU ZZoz43k8aGOsAdAdOHJCAyFv8CpiUoy2qX3mCc3vI7V0BDTBNQgnVgf6V1y1r4TusR9k miN2wjNVyRo2o5JMuwO/0g9e2P1LlUO6FT2wyw6XfzvORfn8D7wY2+PCWe+IA6GmXo+V LFhuG0WaEK4vnwg+Q1BeBwVzYXPlWwX6EB/5arRp+PBb1y75xdcmzo1OiyKXysE+AdqZ kk4cOhEm8tMB5FdUoQuhZPo/63Z8bzLhj6i8c3knXgXChhjxDHD37oa+ZlvXiHHndHQx vZ0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=5pssJB3Qd9My0EHODX+a/H7IyapNo0V5QYinao+SMcQ=; b=Q2iZJCz7v/aXA6qrJvf6mOurWbBo0b+gbPVbeiLNvOo/wFT+VmU9veV+d5yDE4zr/F 3qUcbSN64j93hKCkFgYsdLwal59RrmKXXh433zpftW0seGAhXs7OP7TB+5mhyrXUKT78 B0oRbKP/ELllEmWkQQ/Y0aLqO88kVsxSq3Lvk0vYrLZ1w8KPYyb2yrVZsEhH7lGrikw3 GOKmPwTX/FEZRniVwJ+Wn5/YRUNpwC0/VL50loIh1gJn/08gcWevezQtjdGwDxzZ13ox IQn7Epl5c8vHwjo5uj59AGpcPk7HXpqXfCQF3aKR2c8RttOCvcehDanjzwyiaWtgeAOr umKg== X-Gm-Message-State: APjAAAVgutHVRtzhm6Yxvv0XbE6WSrqtk8MAvMrDL8Z4z+l6XuNZEKxP me1rW+0sNib+INbAhstkFIA= X-Google-Smtp-Source: APXvYqxTR6Yb4LFp9iwzJPQJPLjiD48sfeMVfwSv9KHYyhufF0Vd/uww3ibX6Ac2aLGNNHSQ8Kif8A== X-Received: by 2002:a1c:c90e:: with SMTP id f14mr14278709wmb.47.1575463446843; Wed, 04 Dec 2019 04:44:06 -0800 (PST) Original-Received: from breton.holly.idiocy.org (ip6-2001-08b0-03f8-8129-d56b-bb71-1482-fd6f.holly.idiocy.org. [2001:8b0:3f8:8129:d56b:bb71:1482:fd6f]) by smtp.gmail.com with ESMTPSA id l204sm6878351wmf.2.2019.12.04.04.44.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Dec 2019 04:44:06 -0800 (PST) Content-Disposition: inline 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: 209.51.188.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:172832 Archived-At: * src/nsterm.m (ns_mouse_position): Implement a search for the frame under the mouse pointer. --- src/nsterm.m | 52 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/src/nsterm.m b/src/nsterm.m index 52a9830be8..71234ac783 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -2475,7 +2475,7 @@ so some key presses (TAB) are swallowed by the system. */ -------------------------------------------------------------------------- */ { id view; - NSPoint position; + NSPoint view_position; Lisp_Object frame, tail; struct frame *f; struct ns_display_info *dpyinfo; @@ -2498,31 +2498,55 @@ so some key presses (TAB) are swallowed by the system. */ XFRAME (frame)->mouse_moved = 0; dpyinfo->last_mouse_scroll_bar = nil; - f = dpyinfo->ns_focus_frame ? dpyinfo->ns_focus_frame : SELECTED_FRAME (); - if (dpyinfo->last_mouse_frame - /* While dropping, use the last mouse frame only if there is no - currently focused frame. */ - && (!EQ (track_mouse, Qdropping) || !f) + +#ifdef NS_IMPL_COCOA + /* Find the uppermost Emacs frame under the mouse pointer. + + This doesn't work on GNUstep, although in recent versions there + is compatibility code that makes it a noop. */ + + NSPoint screen_position = [NSEvent mouseLocation]; + NSInteger window_number = 0; + do + { + NSWindow *w; + + window_number = [NSWindow windowNumberAtPoint:screen_position + belowWindowWithWindowNumber:window_number]; + w = [NSApp windowWithWindowNumber:window_number]; + + if (w && [[w delegate] isKindOfClass:[EmacsView class]]) + f = ((EmacsView *)[w delegate])->emacsframe; + } + while (window_number > 0 && !f); +#endif + + if (!f) + f = dpyinfo->ns_focus_frame ? dpyinfo->ns_focus_frame : SELECTED_FRAME (); + + /* While dropping, use the last mouse frame only if there is no + currently focused frame. */ + if (!f + && EQ (track_mouse, Qdropping) + && dpyinfo->last_mouse_frame && FRAME_LIVE_P (dpyinfo->last_mouse_frame)) f = dpyinfo->last_mouse_frame; - else - f = dpyinfo->ns_focus_frame ? dpyinfo->ns_focus_frame : SELECTED_FRAME (); if (f && FRAME_NS_P (f)) { view = FRAME_NS_VIEW (f); - position = [[view window] mouseLocationOutsideOfEventStream]; - position = [view convertPoint: position fromView: nil]; - remember_mouse_glyph (f, position.x, position.y, + view_position = [[view window] mouseLocationOutsideOfEventStream]; + view_position = [view convertPoint: view_position fromView: nil]; + remember_mouse_glyph (f, view_position.x, view_position.y, &dpyinfo->last_mouse_glyph); - NSTRACE_POINT ("position", position); + NSTRACE_POINT ("view_position", view_position); if (bar_window) *bar_window = Qnil; if (part) *part = scroll_bar_above_handle; - if (x) XSETINT (*x, lrint (position.x)); - if (y) XSETINT (*y, lrint (position.y)); + if (x) XSETINT (*x, lrint (view_position.x)); + if (y) XSETINT (*y, lrint (view_position.y)); if (time) *time = dpyinfo->last_mouse_movement_time; *fp = f; -- 2.21.0 -- Alan Third