From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Robert Weiner Newsgroups: gmane.emacs.bugs Subject: bug#28620: Interact directly on Emacs bug#28620: mouse drag event records wrong release window Date: Wed, 11 Oct 2017 14:49:45 -0400 Message-ID: References: <83wp4e3nvx.fsf@gnu.org> <8360bx340d.fsf@gnu.org> <8360bw19es.fsf@gnu.org> <83vajwytja.fsf@gnu.org> <83poa4yqyq.fsf@gnu.org> <83376qouoj.fsf@gnu.org> Reply-To: rswgnu@gmail.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="94eb2c0e6e320355b2055b49e551" X-Trace: blaine.gmane.org 1507747882 2120 195.159.176.226 (11 Oct 2017 18:51:22 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 11 Oct 2017 18:51:22 +0000 (UTC) To: Eli Zaretskii , martin rudalics , Alan Third , 28620@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Oct 11 20:51:17 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 1e2M5w-00072K-Mx for geb-bug-gnu-emacs@m.gmane.org; Wed, 11 Oct 2017 20:51:05 +0200 Original-Received: from localhost ([::1]:42221 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2M64-0006G4-6e for geb-bug-gnu-emacs@m.gmane.org; Wed, 11 Oct 2017 14:51:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49969) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2M5x-0006Fy-KD for bug-gnu-emacs@gnu.org; Wed, 11 Oct 2017 14:51:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2M5u-0000ZS-Dm for bug-gnu-emacs@gnu.org; Wed, 11 Oct 2017 14:51:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:54009) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e2M5u-0000Yy-AH for bug-gnu-emacs@gnu.org; Wed, 11 Oct 2017 14:51:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1e2M5t-0004ay-Vl for bug-gnu-emacs@gnu.org; Wed, 11 Oct 2017 14:51:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Robert Weiner Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 11 Oct 2017 18:51:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 28620 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 28620-submit@debbugs.gnu.org id=B28620.150774782817613 (code B ref 28620); Wed, 11 Oct 2017 18:51:01 +0000 Original-Received: (at 28620) by debbugs.gnu.org; 11 Oct 2017 18:50:28 +0000 Original-Received: from localhost ([127.0.0.1]:34457 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2M5M-0004a1-7M for submit@debbugs.gnu.org; Wed, 11 Oct 2017 14:50:28 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:58818) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2M5K-0004Zn-Bg for 28620@debbugs.gnu.org; Wed, 11 Oct 2017 14:50:26 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2M5B-00005k-Sn for 28620@debbugs.gnu.org; Wed, 11 Oct 2017 14:50:21 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:56514) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2M5B-00005P-Jb for 28620@debbugs.gnu.org; Wed, 11 Oct 2017 14:50:17 -0400 Original-Received: from mail-qt0-f178.google.com ([209.85.216.178]:56301) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1e2M5B-0004XK-3d for 28620@debbugs.gnu.org; Wed, 11 Oct 2017 14:50:17 -0400 Original-Received: by mail-qt0-f178.google.com with SMTP id x54so8173834qth.12 for <28620@debbugs.gnu.org>; Wed, 11 Oct 2017 11:50:16 -0700 (PDT) X-Gm-Message-State: AMCzsaXl2Vof+XAN06wxQGSi8ObQXsxaU3zSbzzp5V3F/I7DtuxPU1E1 2ez+IQ9tMSoLfdSWYKRgQIIysodHM7Jrm2ujbOo= X-Google-Smtp-Source: AOwi7QC5n5oqbLxy6Lw/DYibWjJQspkcUbhmDMHkQwhVptCyHNLm85s1AuWNIOdklMDKFFZ8yqIclSNVLQqeM/jvEMs= X-Received: by 10.237.59.249 with SMTP id s54mr1059338qte.34.1507747816493; Wed, 11 Oct 2017 11:50:16 -0700 (PDT) Original-Received: by 10.237.34.225 with HTTP; Wed, 11 Oct 2017 11:49:45 -0700 (PDT) In-Reply-To: X-Gmail-Original-Message-ID: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] 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:138224 Archived-At: --94eb2c0e6e320355b2055b49e551 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Oct 11, 2017 at 1:16 PM, Robert Weiner wrote: > > =E2=80=8BMartin wrote:=E2=80=8B > >> Take the position of the event-end (if it's a frame) and translate it >> into absolute screen coordinates (the Elisp manual should give you >> enough clues to do that). Or, try =E2=80=98mouse-absolute-pixel-positio= n=E2=80=99 - it >> should give you the screen position of the mouse at that time so you can >> ignore the event completely. >> >> Then walk all your windows and compare that position with whatever >> =E2=80=98window-absolute-pixel-edges=E2=80=99 returns for that window. = If you have two >> or more positives, run =E2=80=98frame-list-z-order=E2=80=99 and compare = the result >> against those windows' frames. No hands, IMHO. >> =E2=80=8B=E2=80=8B >> > =E2=80=8B=E2=80=8B =E2=80=8B Eli wrote: =E2=80=8B=E2=80=8B Why cannot you compute the frame at button release using the a =E2=80=8B=E2=80=8B lgorithm proposed by Martin, given the mouse position at button release?=E2= =80=8B > >> =E2=80=8B=E2=80=8B >> > I w > =E2=80=8B=E2=80=8B > rote: > =E2=80=8B > =E2=80=8B=E2=80=8B > frame-list-z-order is Emacs 26 only; I need something that works with > older versions.=E2=80=8B > =E2=80=8B=E2=80=8B > =E2=80=8B=E2=80=8B > I'll see if I can make this work under Emacs 26 and then we can > contemplate a solution that would apply to earlier versions. > =E2=80=8B=E2=80=8B > Thanks for the reminder. It does still seem to me that there should be a > function that takes a mouse position and returns > =E2=80=8B=E2=80=8B > the top-most Emacs window that the position is in or nil. I'll work on i= t. > =E2=80=8B=E2=80=8B =E2=80=8B=E2=80=8B=E2=80=8BAnd now there is such a function. It was easier= than I expected thanks to Martin's pointers. Now how can we make this work (replacing frame-list-z-order) for Emacs versions prior to 26? -- Bob (defun window-at-absolute-pixel-position (&optional position) "Return the top-most Emacs window at optional POSITION ((X . Y) in pixels) or mouse position. If POSITION is not in a window, return nil. Considers all windows on the the same terminal display as the selected frame." (interactive) (setq position (or position (mouse-absolute-pixel-position))) (let* ((top-to-bottom-frames (frame-list-z-order)) (pos-x (car position)) (pos-y (cdr position)) edges left top right bottom frame in-frame window) ;; First find top-most frame containing position. (while (and (not in-frame) top-to-bottom-frames) (setq frame (car top-to-bottom-frames) top-to-bottom-frames (cdr top-to-bottom-frames)) ;; Check that in-frame is valid with frame-live-p since under macOS ;; when position is outside a frame, in-frame could be invalid and ;; frame-visible-p would trigger an error in that case. (when (and (frame-live-p frame) (frame-visible-p frame)) (setq edges (frame-edges frame) left (nth 0 edges) top (nth 1 edges) right (nth 2 edges) bottom (nth 3 edges)) (when (and (>=3D pos-x left) (<=3D pos-x right) (>=3D pos-y top) (<=3D pos-y bottom)) (setq in-frame frame)))) ;; If in-frame is found, find which of its windows contains ;; position and return that. The window-at call below requires ;; character coordinates relative to in-frame, so compute them. (setq pos-x (/ (- pos-x left) (frame-char-width in-frame)) pos-y (/ (- pos-y top) (frame-char-height in-frame)) window (window-at pos-x pos-y in-frame)) (if (called-interactively-p 'interactive) (message "%s at absolute pixel position %s" (or window "No Emacs window") position)) window)) --94eb2c0e6e320355b2055b49e551 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Wed, Oct 11, 2= 017 at 1:16 PM, Robert Weiner <rsw= @gnu.org> wrote:=

=E2=80=8BMartin wrote:=E2=80=8B
Take the position of the event-end (if it's a frame) and tra= nslate it
into absolute screen coordinates (the Elisp manual should give= you
enough clues to do that).=C2=A0 Or, try =E2=80=98mouse-absolute-pix= el-position=E2=80=99 - it
should give you the screen position of th= e mouse at that time so you can
ignore the event completely.

Then= walk all your windows and compare that position with whatever
=E2=80=98= window-absolute-pixel-edges=E2=80=99 returns for that window.=C2=A0 If you = have two
or more positives, run =E2=80=98frame-list-z-order=E2=80=99 and= compare the result
against those windows' frames.=C2=A0 No hands, I= MHO.
=E2=80=8B=E2=80=8B
=E2=80=8B=E2=80=8B
=C2=A0
=E2=80=8B=C2=A0 Eli wrote:
=C2=A0 =C2=A0 =E2=80=8B=E2=80=8B
Why cannot you c= ompute the frame at button release using the a
=E2=80=8B=E2=80=8B=
lgorithm

=C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0proposed by Martin, given the mouse position at button releas= e?=E2=80=8B
=C2=A0
=C2=A0=E2=80=8B=E2=80=8B
I w
=E2=80=8B=E2=80=8B
rote:
= =C2=A0 =E2=80=8B
=E2=80=8B=E2=80=8B
frame-list-z-order is Em= acs 26 only; I need something that works with older versions.=E2=80=8B
=E2=80=8B=E2=80=8B
=E2=80=8B=E2=80=8B
I'll see if I can ma= ke this work under Emacs 26 and then we can contemplate a solution that wou= ld apply to earlier versions.
=E2=80=8B=E2=80=8B
Thanks for the reminder.=C2=A0 It does still see= m to me that there should be a function that takes a mouse position and ret= urns
=E2=80=8B=E2=80=8Bthe top-most Emacs window that the position is in or nil.=C2=A0 I'll = work on it.
=E2=80=8B=E2=80=8B
= =E2=80=8B=E2=80=8B=E2=80=8BAnd now there is such a function.=C2=A0 It was e= asier than I expected thanks to Martin's pointers.=C2=A0 Now how can we= make this work (replacing frame-list-z-order) for Emacs versions prior to = 26?=C2=A0 -- Bob

(def= un window-at-absolute-pixel-position (&optional position)
=C2=A0 "Return the top-most Emacs window at optio= nal POSITION ((X . Y) in pixels) or mouse position.
If POSITION is not in a window, return nil.=C2=A0 Considers all = windows on the the same terminal
display = as the selected frame."
=C2=A0 (inte= ractive)
=C2=A0 (setq position (or positi= on (mouse-absolute-pixel-position)))
=C2= =A0 (let* ((top-to-bottom-frames (frame-list-z-order))
(pos-x (car position= ))
(pos-y (cdr position))
edges left top right bottom
frame
in-frame
<= div class=3D"gmail_default"> window= )
=C2=A0 =C2=A0 ;; First find top-most fr= ame containing position.
=C2=A0 =C2=A0 (w= hile (and (not in-frame) top-to-bottom-frames)
=C2=A0 =C2=A0 =C2=A0 (setq frame (car top-to-bottom-frames)
=C2=A0 =C2= =A0 top-to-bottom-frames (cdr top-to-bottom-frames))
=C2=A0 =C2=A0 =C2=A0 ;; Check that in-frame is valid with frame= -live-p since under macOS
=C2=A0 =C2=A0 = =C2=A0 ;; when position is outside a frame, in-frame could be invalid and
=C2=A0 =C2=A0 =C2=A0 ;; frame-visible-p wo= uld trigger an error in that case.
=C2=A0= =C2=A0 =C2=A0 (when (and (frame-live-p frame) (frame-visible-p frame))
(set= q edges (frame-edges frame)
=C2=A0 =C2=A0 =C2=A0 left=C2=A0 =C2=A0(nth 0 e= dges)
=C2=A0 =C2=A0 =C2=A0 top=C2=A0 =C2=A0 (nth 1 edges)
=C2=A0 =C2=A0 =C2= =A0 right=C2=A0 (nth 2 edges)
=C2=A0 =C2=A0 =C2=A0 bottom (nth 3 edges))
(whe= n (and (>=3D pos-x left) (<=3D pos-x right)
=C2=A0 =C2=A0(>=3D pos= -y top)=C2=A0 (<=3D pos-y bottom))
=C2=A0 (setq in-frame frame))))
<= div class=3D"gmail_default">=C2=A0 =C2=A0 ;; If in-frame is found, find whi= ch of its windows contains
=C2=A0 =C2=A0 = ;; position and return that.=C2=A0 The window-at call below requires
<= div class=3D"gmail_default">=C2=A0 =C2=A0 ;; character coordinates relative= to in-frame, so compute them.
=C2=A0 =C2= =A0 (setq pos-x (/ (- pos-x left) (frame-char-width in-frame))
=C2=A0 pos-y = (/ (- pos-y top) (frame-char-height in-frame))
=C2=A0 window (window-at pos-= x pos-y in-frame))
=C2=A0 =C2=A0 (if (cal= led-interactively-p 'interactive)
=C2=A0 (message "%s at absolute p= ixel position %s"
=C2=A0 =C2=A0(or window "No Emacs window")= position))
=C2=A0 =C2=A0 window))
<= /div>
--94eb2c0e6e320355b2055b49e551--