From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Olaf Rogalsky Newsgroups: gmane.emacs.bugs Subject: bug#69915: 30.0.50; mouse-autoselect-window has no effect in terminal Date: Sun, 24 Mar 2024 20:27:55 +0100 Message-ID: References: <87zfutaram.fsf@t-online.de> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23282"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 69915@debbugs.gnu.org, "eliz@gnu.org" To: Jared Finder Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Mar 24 20:29:39 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1roTXG-0005vy-V6 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 24 Mar 2024 20:29:39 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1roTX5-0002Ot-QC; Sun, 24 Mar 2024 15:29:27 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1roTX1-0002OH-Av for bug-gnu-emacs@gnu.org; Sun, 24 Mar 2024 15:29:23 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1roTWy-0007Fc-Kv for bug-gnu-emacs@gnu.org; Sun, 24 Mar 2024 15:29:22 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1roTXe-0000iG-82 for bug-gnu-emacs@gnu.org; Sun, 24 Mar 2024 15:30:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <87zfutaram.fsf@t-online.de> Resent-From: Olaf Rogalsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 24 Mar 2024 19:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69915 X-GNU-PR-Package: emacs Original-Received: via spool by 69915-submit@debbugs.gnu.org id=B69915.17113086012723 (code B ref 69915); Sun, 24 Mar 2024 19:30:02 +0000 Original-Received: (at 69915) by debbugs.gnu.org; 24 Mar 2024 19:30:01 +0000 Original-Received: from localhost ([127.0.0.1]:47428 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1roTXc-0000hb-KX for submit@debbugs.gnu.org; Sun, 24 Mar 2024 15:30:01 -0400 Original-Received: from mail-pl1-f175.google.com ([209.85.214.175]:58852) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1roTXW-0000hL-CV for 69915@debbugs.gnu.org; Sun, 24 Mar 2024 15:29:59 -0400 Original-Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1def3340682so29764045ad.1 for <69915@debbugs.gnu.org>; Sun, 24 Mar 2024 12:29:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711308486; x=1711913286; darn=debbugs.gnu.org; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=azJunRCKtAwTZPomayKp3Yp65g3Wkn0Nc5AzgQS5OWM=; b=FzRZRgCBMXwXeyd++YdExiNrqSqKPzPIabozuBfq5Be02lurv4kbay9ApwIZoF1TUf f2VhxEVErcaffPMSpELZ3abSzzx06Pu3ZovZrKtdoHNr+3xB1w7TdvC0Vygzz+fPS6WQ fW59VZy0OF8F56hhUA28zYIUQJt560DoOPD2vRlK7Yi0UaH9IjHQLWHBSDbRojS+5nNR 98dcBZBk7IJ0Xryhv3To7D+BX+PJVNI2ffHwvDWXOQ/lwGPRNFbHHxw5TMj23eNKE7T/ 1fwZPVagmQ6SKUWxByG0rqbng0k5dMsYCtqYjrfGipnt53Labykbyn5wIMu6vkucxSBF aRTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711308486; x=1711913286; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=azJunRCKtAwTZPomayKp3Yp65g3Wkn0Nc5AzgQS5OWM=; b=SWvD7X147RGtu0XRBbqPT4H8lKN+4vbLzC0NGslxQlwI67ZPorzP6DWm1sbqmfR/vE kAn3fT4i9UduDIMezZxtFlY+RKk3hmKipIF4+VOHjjNQvFlg0Aj+OEnjRRYvp03mmili /HMziOGeIc3R6WctOMxvO9weTnsjAkzVc7kssfIHaOSFjoXyQAOHhBZhGas55DeWqfZ2 5dghAnVDxinqmoXj16Mi4OznNHZI2aQ4bPGD4yidVIJGc5YHm+ILkMcdG7mO7AHo3q+1 kasK4HVqvXCARQIW1mmfRwb3CE7VcmVKKHvAt/SZVo2hWg/1CdWD053xaXSHc8lrU6vv f1Og== X-Forwarded-Encrypted: i=1; AJvYcCV7Ao/P217YN0O8F/YX09oDvT7UhYtaDgGRLkWgGUpECeoO0msdpUHhqyHjM/Ly+OqqqYVXzXsEAgRZaRDWHCfcwOTwlfU= X-Gm-Message-State: AOJu0Yy1bbnP4NPWokoPh2pzB6GXrQ/7qYzPdX7t1+mcBze44yilXW8Z iH/s9A0iUo4D/qBhPsHYgGBAP9dE9A8Bv/waqjjZHVMhoYMqq9lTfEgi8lIPUJKwQxl5U+5FsGc 8fcJI68EfheHKRbl1zCckBnCkDGU= X-Google-Smtp-Source: AGHT+IGUm7HFGYAqQHFXyqQXmeOHfhGy7SDgrZxn3uYYEDcqPcCp03NXV8/dpl3yd1TQRP8AHV8JCQxd5bHdLMlNVwk= X-Received: by 2002:a17:902:c412:b0:1e0:a7c4:fe61 with SMTP id k18-20020a170902c41200b001e0a7c4fe61mr7138065plk.54.1711308486346; Sun, 24 Mar 2024 12:28:06 -0700 (PDT) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:282032 Archived-At: Hi Jared, thanks for your feedback (answering this from my gmail account and hope this doesn't mess up the debbugs history). > A few other pieces of feedback (you may find it easier to generate the > events in xterm-mouse-translate-1 to address): Yes, I think you are right. I refactored my code accordingly, see the new patch below. > Are you certain you need the change to window.el as well? I'd be very > surprised if it is necessary to change ... > Is your setup is different somehow? No, but I forgot to mention, that the "nil is undefined" error only occurred, iff mouse-autoselect-window had a numeric value. With my new patch, the error disappeared. I don't know why, but a change to window.el isn't necessary anymore. I still think, that the proposed change would be correct. > events shouldn't be generated while the mouse is being > dragged. This probably is reflected in fully by track-mouse, but I'd > suggest looking at the native code that generates the event to confirm. Truly understanding xterm.c unfortunately is beyond my expertise. Nevertheless I tested, the behavior. Dragging the mouse from one window to the next (while passing over the modeline) gives the following sequence of events: ESC [ < 3 5 ; 5 5 ; 4 1 M ESC [ < 0 ; 5 5 ; 4 1 M ;; mouse-drag-region ESC [ < 3 2 ; 5 5 ; 4 2 M ;; anonymous-command ESC [ < 3 2 ; 5 5 ; 4 3 M ;; anonymous-command ESC [ < 3 2 ; 5 5 ; 4 4 M ;; ignore ESC [ < 3 2 ; 5 6 ; 4 4 M ;; anonymous-command ESC [ < 0 ; 5 6 ; 4 4 m ;; anonymous-command ;; mouse-set-region So indeed, no select-window event is generated. As a result, dragging the mouse over the borders of the window results in a scrolling of the window. This matches the behavior of the X11 backend. > If there is a case where two events should be generated (not sure if > this case exists depending on above), we'd want to return both, but you > can only return a single key sequence from the translate function. I > think this case deserves a FIXME note. Can't follow you here. At which occasion two events might be generated and which ones? > Did you try out switching frames? I'm not certain if is > supposed to be generated when the frame is switched. Switching frames is not handled in xt-mouse.el. However, if you change the focus from another X11 window to the title bar of the terminal or wise-versa, no switch-frame event is generated. Instead, xterm-translate-focus-in/xterm-translate-focus-out are called via a binding in xterm-rxvt-function-map. These functions toggle the terminal parameter tty-focus-state between focused and defocused and then call after-focus-change-function, which also does not generate a switch-frame event. As far as I could find out, the X11 backend of emacs doesn't generate switch-frame events, either. > Please name the new internal state variable with prefix "xt-mouse--". I changed it to the terminal parameter xterm-mouse-last-window. Regards, Olaf New patch: diff --git a/lisp/xt-mouse.el b/lisp/xt-mouse.el index 081b8f32456..8b405262168 100644 --- a/lisp/xt-mouse.el +++ b/lisp/xt-mouse.el @@ -60,7 +60,9 @@ xterm-mouse-translate-1 (let* ((event (xterm-mouse-event extension)) (ev-command (nth 0 event)) (ev-data (nth 1 event)) + (ev-window (nth 0 ev-data)) (ev-where (nth 1 ev-data)) + (last-window (terminal-parameter nil 'xterm-mouse-last-window)) (vec (vector event)) (is-move (eq 'mouse-movement ev-command)) (is-down (string-match "down-" (symbol-name ev-command)))) @@ -73,6 +75,9 @@ xterm-mouse-translate-1 'mouse-movement 'mouse-click))) + ;; remember window of current mouse position + (set-terminal-parameter nil 'xterm-mouse-last-window ev-window) + (cond ((null event) nil) ;Unknown/bogus byte sequence! (is-down @@ -84,10 +89,19 @@ xterm-mouse-translate-1 vec) (is-move (xterm-mouse--handle-mouse-movement) - (if track-mouse vec - ;; Mouse movement events are currently supposed to be - ;; suppressed. Return no event. - [])) + (if (and mouse-autoselect-window ; after mouse movement autoselect the mouse window, but ... + (windowp ev-window) ; ignore modeline, tab-bar, menu-bar and so forth ... + ;;(not (posn-area (event-start event))) ; also ignore, if not inside of text area of window ... + (not (eq ev-window last-window)) ; but only, if mouse is over new window ... + (not (eq ev-window (selected-window)))) ; which is different from the selected window + (progn + (put 'select-window 'event-kind 'switch-frame) + (setf (car event) 'select-window) + vec) + (if track-mouse vec + ;; Mouse movement events are currently supposed to be + ;; suppressed. Return no event. + []))) (t (let* ((down (terminal-parameter nil 'xterm-mouse-last-down)) (down-data (nth 1 down))