mina86 / auto-dim-other-buffers.el

Visually makes non-selected windows less prominent
GNU General Public License v3.0
93 stars 13 forks source link

mouse clicks select a window but don't autodim others #12

Closed djstauffer closed 7 years ago

djstauffer commented 7 years ago

I noticed that when I click on a window with the mouse in emacs (when auto-dim-other-buffers is turned on), that the window gets focus, but the other buffers are not set to the auto-dimmed face (they still have the normal face that they do when they have focus).

I almost never use the mouse in emacs, but sometimes I do click on the emacs window to give it focus when returning from using another application (particularly if that app is fairly mouse-centric). So this problem was irritating to me.

I was able to correct this by putting code like the following in my init:

(defun zq/mouse-click-autodim ( &rest args ) (adob--post-command-hook))

(add-function :after (symbol-function 'select-window) #'zq/mouse-click-autodim)

That works pretty well. Now there only a couple of cases I can think of when I see multiple windows all having the non-dimmed face, and that is when I click in an emacs window which is not the current window with either the 2nd or 3rd mouse buttons.

For some reason, the emacs select-window function never gets called on these mouse click events, even though the window does indeed get input focus.

I suspect that there is a better or alternative function I could advise to handle this scenario also, but so far I have not found one (admittedly, I haven't tried for terribly long yet).

djstauffer commented 7 years ago

Actually there is another scenario where the 'normal' undimmed face will appear in two windows -- and that is when two windows are displaying the same buffer.

My workaround for this is that I have custom keybindings that I use to switch to the next/previous buffer in an emacs window, and in the functions those keybindings are bound to, I skip past any buffer that is already being displayed in a window.

I can still display the same buffer in two windows using C-x b or C-x C-b, and in that case I will see both windows having the non-dimmed face, but I just hardly ever do that.

mina86 commented 7 years ago

There is a reason this is called ‘auto-dim-other-buffers’. ;) The mechanism the library is using operates on buffers so it’s unable to dim individual windows. Emacs sadly does not provide a way to dim a window.

For the first issue, I think using ‘buffer-list-update-hook’ instead of ‘post-command-hook’ might be a solution. I’ll test it for several days and push the change if it works.

djstauffer commented 7 years ago

"Emacs sadly does not provide a way to dim a window".

^^ Yeah, stock emacs does not. I've tried a number of different things in an attempt to work around this.

For a long time I used the bgex patch to allow me to define a per-window custom background image, and I modified it to use a different background depending on whether the window was the "current window".

That worked OK, but the problem is, with my current setup the flicker in emacs was very hard on the eyes, since it was redrawing the display every time I switched windows. I also frequently use emacs under VNC on a different computer, and the flickering is even more noticeable there I think. I believe the bgex patch made this worse, but even without it it was noticeable.

So to fix the flicker, I compiled and set up Daniel Colascione's "buttery smooth emacs" patch, which implements double buffering to reduce flicker (https://www.facebook.com/notes/daniel-colascione/buttery-smooth-emacs/10155313440066102/ ), and that made a huge difference. Actually, that is the reason I found auto-dim-other-buffers in the first place. I considered trying to port the bgex patch to the version of emacs with Daniel's patch applied, but with the little knowledge of emacs' display code that I have, I suspected I'd have difficulty successfully combining the two patches. The bgex patch is fairly involved, and Daniel's patch is considerably more extensive (and it is on a development branch as well -- the version shows emacs 26-something).

So I looked for other solutions to change the background of non-current windows, and thus I found auto-dim-other-buffers.

I'll keep an eye on this issue and if you do make a change I'll try to test it out once you've pushed it.

Thanks for looking into it.