21

To better distinguish between focused window and rest that are not I would love to change this window's fringe color. Discovering customize with fringe keyword I found only how to change its bg color without ability to set different colors for active and not active ones. Is it possible at all? Thx.

6
  • I'm not sure about the fringe, but you can change the mode-line for inactive windows. try M-x customize-face mode-line-inactive.
    – Tyler
    Jul 15, 2016 at 20:55
  • 3
    It appears to be frame-local, so it looks like the answer is no. I tried (face-remap-add-relative 'fringe '((:background "yellow"))) which for other faces is sufficient for buffer-local usage, but it affects all windows in the frame as far as the fringe is concerned. In addition to the suggestion of @Tyler, you can also customize the cursor so that it appears in active windows only -- see the variable cursor-in-non-selected-windows
    – lawlist
    Jul 15, 2016 at 21:09
  • I know about modeline, thx. I just wanted to make it more clear for me.
    – sandric
    Jul 16, 2016 at 13:34
  • Here are a couple of additional ideas to help make the active window attract more visual attention: (1) making the mode-line background of the inactive windows match the buffer color so that the inactive mode-line becomes less noticeable: stackoverflow.com/a/20936397/2112489 and (2) changing the color of certain textual components of the mode-line-format within the active and inactive windows: emacs.stackexchange.com/a/22682/2287
    – lawlist
    Jul 16, 2016 at 15:48

3 Answers 3

16

Since you want "To better distinguish between focused window", you can use other ways to do that instead of just changing the active window's fringe color.

I combine three ways to better distinguish between active and inactive windows.

  1. Use different colors of mode line for the active and inactive windows.
  2. Highlight the current line where the point is in active window.
  3. Use different background colors for the active and inactive windows.

Note that all the chosen colors mentioned above should be working well with your Emacs theme.

Here are all the three ways:

  1. Use different colors of mode line for the active and inactive windows:

    (custom-set-faces
     '(mode-line ((t (:background "dim gray" :foreground "white"))))
     '(mode-line-inactive ((t (:background nil)))))
    
  2. Highlight the current line where the point is in active window:

    (global-hl-line-mode 1)
    ;; underline the current line
    (set-face-attribute hl-line-face nil :underline t)
    
  3. Use different background colors for the active and inactive windows:

    (defun highlight-selected-window ()
      "Highlight selected window with a different background color."
      (walk-windows (lambda (w)
                      (unless (eq w (selected-window))
                        (with-current-buffer (window-buffer w)
                          (buffer-face-set '(:background "#111"))))))
      (buffer-face-set 'default))
    (add-hook 'buffer-list-update-hook 'highlight-selected-window)
    

You can change the colors in the code snippets to work well with your Emacs theme.

This is the final screenshot:

Screenshot of three ways together

And there is another function you can manually use to flash the active window:

(global-set-key (kbd "<f12>") 'flash-active-buffer)
(make-face 'flash-active-buffer-face)
(set-face-attribute 'flash-active-buffer-face nil
                    :background "blue" :foreground nil)
(defun flash-active-buffer ()
  (interactive)
  (run-at-time "100 millisec" nil
               (lambda (remap-cookie)
                 (face-remap-remove-relative remap-cookie))
               (face-remap-add-relative 'default 'flash-active-buffer-face)))

You can change the keybinding in the code snippet, when you want to show the active window, hit the key, the active window will be blue, after you move you point, the color will be gone.

0

I had the same problem. I resorted to using smart line mode and customize it so I get colours that are very distinctive in the active window. Here is a sample frame. The active window is the one with black mode line with gold letters.

enter image description here

Make sure you require smart-mode-line before using this code. I recommend you customize it to the colours you need:

(deftheme smart-mode-line-dmg "dmg theme for smart-mode-line.")
(custom-theme-set-faces
 'smart-mode-line-dmg
                                        ; '(mode-line-inactive ((t :inverse-video nil)))
                                        ; '(mode-line     ((t :inverse-video nil)))
 '(mode-line     ((t :foreground "grey70" :background "black" :inverse-video nil)))
 '(mode-line-inactive  ((t :foreground "black" :background "white" :inverse-video nil)))
 '(sml/global    ((t :inherit font-lock-preprocessor-face)))
 '(sml/filename  ((t :inherit sml/global :foreground "gold" :weight bold)))
 '(sml/prefix    ((t :inherit (font-lock-variable-name-face sml/global))))
 '(sml/read-only ((t :inherit (font-lock-type-face sml/not-modified))))
 '(sml/modes     ((t :foreground nil :inherit sml/filename :weight normal))))

(sml/setup)
-1

You can try doing something like the following to highlight the currently selected window. Beware that this doesn't work if the buffers in multiple windows are the same. This dims all other windows except the selected one.

(defvar dim-window-face
  '((t  (:background "grey40")))
  "Face for a dimmed window in the current frame.")

(defvar current-window-face
  '((t  (:background "black")))
  "Face for a dimmed window in the current frame.")

(defvar window->overlay (make-hash-table)
  "A hash table of window to dimmed overlay.")

(defun dim-windows ()
  "Dim all windows except the `selected-window' in current frame."
  (interactive)
  (walk-windows (lambda (w)
                  ;; Delete existing overlay on window W
                  (when-let ((ol (gethash w window->overlay)))
                    (delete-overlay ol))
                  (let ((ol (make-overlay (window-start w)
                                          (window-end w)
                                          (window-buffer w))))
                    (overlay-put ol 'face (if (eql (selected-window) w)
                                              current-window-face
                                            dim-window-face))
                    (puthash w ol window->overlay)))))
1
  • You never said what hook is needed here and this only changes the background of the text for me...
    – scribe
    May 15, 2023 at 5:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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