unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Temporarily select-window, without updating mode-line face and cursor fill?
@ 2021-05-01 18:46 JD Smith
  2021-05-01 19:31 ` Eli Zaretskii
  0 siblings, 1 reply; 22+ messages in thread
From: JD Smith @ 2021-05-01 18:46 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 2308 bytes --]

I’m working on a small “in mode-line” scroll bar, and have implemented mouse events for it, which are working well.  When I interact using the mouse with the mode line of a non-selected window, I need to have that window temporarily selected, so I can calculate its line offsets and move within it.  But (just as for regular scrollbars), I’d like to retain the originally active window afterwards.

Strangely, using `with-selected-window’, which seems like the obvious solution, leaves the mode line face and cursor in a spurious selected state (dark, and filled, respectively).  This is despite the fact that the original window is in fact re-selected after you leave the form.  This leads to two mode lines on the same frame with active mode line face (see below; notice the frame title)!

Wrapping the code in (select-window win)… (select-window old) instead of using `with-selected-window` solves this spurious "double-active" issue, but causes the mode-line to flash “active” while interacting.  Is there a way to select a window but NOT update the window’s mode line face and cursor “active” indicators?

Mouse handler below (attached via keymap text property only to the scroll bar at right).  GNU Emacs 27.2 (build 1, x86_64-apple-darwin18.7.0, Carbon Version 158 AppKit 1671.6) of 2021-03-27.

++++

(defun mlscroll-mouse (start-event)
  "Handle click and drag mouse events on the mode line scroll bar."
  (interactive "e")
  (let* ((start-posn (event-start start-event))
	 (start-win (posn-window start-posn))
	 (lcr (cdr-safe (posn-object start-posn)))
	 (x (car (posn-object-x-y start-posn)))
	 (xstart-abs (car (posn-x-y start-posn)))
	 (mouse-fine-grained-tracking t)
	 (old-selected-window (selected-window))
	 xstart event end xnew)
    (select-window start-win)
    (setq xstart (mlscroll-scroll-to x lcr)) 
    (track-mouse
      (setq track-mouse 'dragging)
      (while (progn (setq event (read-event))
		    (mouse-movement-p event))
	(setq end (event-end event)
	      xnew (+ xstart (- (car (posn-x-y end)) xstart-abs)))
	(when (and
	       (>= xnew 0)
	       (<= xnew (- mlscroll-width mlscroll-border))
	       (eq start-win (posn-window end)))
	  (mlscroll-scroll-to xnew))))
    (select-window old-selected-window)))




[-- Attachment #2.1: Type: text/html, Size: 4650 bytes --]

[-- Attachment #2.2: PastedGraphic-1.png --]
[-- Type: image/png, Size: 139808 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2021-05-06  0:16 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-01 18:46 Temporarily select-window, without updating mode-line face and cursor fill? JD Smith
2021-05-01 19:31 ` Eli Zaretskii
2021-05-01 20:32   ` JD Smith
2021-05-02  6:49     ` Eli Zaretskii
2021-05-03  2:15       ` JD Smith
2021-05-03  7:50         ` martin rudalics
2021-05-03 16:16           ` JD Smith
2021-05-03 17:32             ` martin rudalics
2021-05-02  7:40     ` martin rudalics
2021-05-03  2:23       ` JD Smith
2021-05-01 22:17   ` JD Smith
2021-05-02  6:55     ` Eli Zaretskii
2021-05-03  2:08       ` JD Smith
2021-05-03  2:25         ` Stefan Monnier
2021-05-03  2:49           ` JD Smith
2021-05-04 19:28           ` JD Smith
2021-05-04 19:40             ` Stefan Monnier
2021-05-05  0:49           ` Stefan Kangas
2021-05-05 11:54             ` Eli Zaretskii
2021-05-05 19:32               ` Stefan Kangas
2021-05-05 19:47                 ` Stefan Monnier
2021-05-06  0:16                 ` JD Smith

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).