Thanks, Lars. I tried this approach and it's almost perfect. The only thing I noticed is that when I use M-x or C-s, and the focus is on the echo area, the last active buffer (the one I was before pressing M-x or C-s) doesn't use the `mode-line-buffer-id-active` face.

Example: https://0x0.st/oH5O.png - see that the `mode-line-buffer-id` face on the right is raised, and I'm not sure where that's coming from, since I didn't set either to be like that.

```
 '(mode-line ((t (:background "#000000" :foreground "#ffffff"))))
 '(mode-line-buffer-id ((t (:background "white" :foreground "black" :weight normal))))
 '(mode-line-highlight ((t (:background "yellow" :box nil))))
 '(mode-line-id-inactive ((t (:background "gray10" :foreground "dim gray"))))
 '(mode-line-inactive ((t (:inherit nil :background "black" :foreground "dim gray" :inverse-video nil))))
```

Seems the default behavior of emacs is not to change the `mode-line` or `mode-line-buffer-id` on the buffer that M-x or C-s used, so I think that's what's missing from this solution.

@Drew Adams might want to check this too. (not sure if this is the right way to mention people)

On Thu, Feb 3, 2022 at 4:00 PM Lars Ingebrigtsen <larsi@gnus.org> wrote:
Juri Linkov <juri@linkov.net> writes:

> tab-line.el uses such trick:
>
>          (face (if (eq buffer (window-buffer))
>                    (if (eq (selected-window) (old-selected-window))
>                        'tab-line-tab-current
>                      'tab-line-tab)
>                  'tab-line-tab-inactive))

Oh, that's smart.

Then we can get the action requested by something like the following:

(progn
  (defun my-buffer-identification (fmt)
    (list (propertize fmt
                      'face (if (eq (selected-window)
                                    (old-selected-window))
                                'mode-line-buffer-id
                              'error)
                      'mouse-face 'mode-line-highlight
                      'local-map mode-line-buffer-identification-keymap)))
  (setq-default mode-line-buffer-identification
                '(:eval (my-buffer-identification "%12b"))))

(Adjust for the face you want to use.)  Seems to work well for me.

José, does this fix the issue for you, too?

We should probably document this better -- perhaps add some cross
referencing between the selected-window and old-selected-window doc
strings to allow discovery.  And perhaps mention this in the mode line
section, too.

--
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no