How can I use the focus hooks to attenuate all colours in visible buffers when the Emacs frame loses focus?

I tried using the following code:

(set-frame-parameter (selected-frame) 'alpha '(100 80))

To make the frame become translucent, but it would flicker when I hit Ctrl (apparently that's because I let GNOME highlight the mouse cursor when I hit Ctrl).

Making the frame transparent isn't what I want anyway. Is it possible to desaturate all colours instead?

EDIT: a less ambitious goal is to change/attenuate the colours of the mode line on focus change and restore them to normal when focus returns. With two monitors I often find myself typing into the void when Emacs is displayed but not focussed, so I need some better visual indicator of focus.

  • 3
    While this Emacs feature sounds undeniably cool, I think it would be better to leave such a thing to the compositor you're using, compton for instance can dim inactive windows.
    – wasamasa
    Oct 31 '14 at 17:33
  • Well, I suppose that's one way to do it (and probably the right way to do it), but I don't really want this for any other window/application except for Emacs. I guess I'd be happy with changing the colour of the modeline on focus change.
    – rekado
    Nov 11 '14 at 22:21

See if auto-dim-other-buffers-mode works for you.

Out of the box it dims frames when they lose focus as well as buffers when they lose current-buffer status.

It's available on MELPA. Source here: https://github.com/mina86/auto-dim-other-buffers.el


Sure. See function doremi-increment-color in library doremi-frm.el.

In this case, you want to use a negative INCREMENT argument and specify s (for saturation) as the COMPONENT argument to increment (decrement, in this case).

You would call doremi-increment-color on any color of any UI feature you like (or on all of them), to calculate a less saturated version of the color. See also function hexrgb-increment-saturation in library hexrgb.el.

You can get an interactive idea of applying this across the board by using command doremi-all-faces-bg+ or doremi-all-frames-bg+ (or the same, with fg+ instead of bg+).

More Do Re Mi color-changing described here.

With respect to your request about dynamically desaturating and saturating the mode line: See, for example, function 1on1-color-minibuffer-frame-on-setup in library oneonone.el, which does the same kind of thing for a standalone minibuffer frame. It uses function hexrgb-increment-hue, but you would use hexrgb-increment-saturation instead (or doremi-increment-color).

This is the meat of that function:

(set-background-color (hexrgb-increment-hue ; Change bg hue slightly.
                       (frame-parameter nil 'background-color)

Different answer based on your edit.

If you just want to change the mode line, check out what the Emacs manual has to say about mode-line-inactive face.

Like mode-line, but used for mode lines of the windows other than the selected one (if mode-line-in-non-selected-windows is non-nil). This face inherits from mode-line, so changes in that face affect mode lines in all windows.

You could make mode-line have a bright red background and mode-line-inactive a bland grey background, for instance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.