powerline icon indicating copy to clipboard operation
powerline copied to clipboard

powerline does not detect the "active" modeline correctly

Open laynor opened this issue 12 years ago • 20 comments

The modeline colors are not changed correctly when I switch windows, at least for me and my colleagues. The predicate powerline-selected-window-active always returns the same value for active and inactive window. Only the parts that have the face property 'nil switch color. I solved this issue in my config long time ago but forgot to share, here is my (brute force) solution:

(add-hook 'post-command-hook (lambda ()
                               (when (not (minibuffer-selected-window))
                                 (setq powerline-selected-window (selected-window)))))

my modeline-format is looks like this:

'("%e"
  (:eval
   (let* ((active (eq powerline-selected-window (selected-window)))

This way, active actually holds the correct value.

laynor avatar Jun 05 '13 21:06 laynor

what system?

On Wed, Jun 5, 2013 at 2:16 PM, Alessandro Piras [email protected]:

The modeline colors are not changed correctly when I switch windows, at least for me and my colleagues. The predicate powerline-selected-window-active always returns the same value for active and inactive window. Only the parts that have the face property 'nil switch color. I solved this issue in my config long time ago but forgot to share, here is my (brute force) solution:

(add-hook 'post-command-hook (lambda () (setq powerline-selected-window (selected-window))))

my modeline-format is looks like this:

'("%e" (:eval (let* ((active (eq powerline-selected-window (selected-window)))

This way, active actually holds the correct value.

— Reply to this email directly or view it on GitHubhttps://github.com/milkypostman/powerline/issues/37 .

milkypostman avatar Jun 07 '13 23:06 milkypostman

Arch linux 64, emacs compiled from source from AUR, bzr version info:

revision-id: [email protected]                   
date: 2013-06-01 20:35:14 +0800
build-date: 2013-06-08 11:13:25 +0200
revno: 112809
branch-nick: trunk

laynor avatar Jun 08 '13 09:06 laynor

ok, installing bzr version now to test.

milkypostman avatar Jun 09 '13 17:06 milkypostman

I had a same problem with emacs compiled from sources. The described fix worked for me. Thanks.

tahti avatar Jul 03 '13 16:07 tahti

The suggested fix worked for me as well. Thanks!

mads-hartmann avatar Jan 30 '14 22:01 mads-hartmann

This bug is still present, the culprit is indeed powerline-selected-window-active which seems very broken.

(defun powerline-selected-window-active ()
  "Return whether the current window is active."
  (or (eq (frame-selected-window)
          (selected-window))
      (and (minibuffer-window-active-p
            (frame-selected-window))
           (eq (pl/minibuffer-selected-window)
               (selected-window)))))

The first part of the or is always t and the second part is always nil. Besides, I don't understand how each window could be checked when they're not given as parameter.

@milkypostman could you please explain your intent with this function?

Also, for anyone unaware, the suggested fix runs its lambda every time you press a key/command. It is far from ideal.

LouisKottmann avatar Feb 11 '14 14:02 LouisKottmann

When I wrote the function emacs would select each window as it updated each mode line. So (selected-window) would be the window whose mode line was being updated and (frame-selected-window) would be three truly selected window.

What version of emacs is this? Likely something has changed but I don't think the proposed solution is the correct one. Because post-command-hook seems too often.

Or frame selected window is misbehaving. I will install on 24.3 and see if I can reproduce. I'm also curious if there is another extension causing this problem. On Feb 11, 2014 6:36 AM, "Baboon" [email protected] wrote:

This bug is still present, the culprit is indeed powerline-selected-window-active which seems very broken.

(defun powerline-selected-window-active () "Return whether the current window is active." (or (eq (frame-selected-window) (selected-window)) (and (minibuffer-window-active-p (frame-selected-window)) (eq (pl/minibuffer-selected-window) (selected-window)))))

The first part of the or is always t and the second part is always nil. Besides, I don't understand how each window could be checked when they're not given as parameters.

@milkypostman https://github.com/milkypostman could you please explain your intent with this function?

— Reply to this email directly or view it on GitHubhttps://github.com/milkypostman/powerline/issues/37#issuecomment-34759602 .

milkypostman avatar Feb 11 '14 15:02 milkypostman

That's the kind of voodoo I was fearing, my emacs version is:

GNU Emacs 24.3.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.8.6) of 2014-01-02 on alphard, modified by Debian

I got it from ppa:cassou/emacs

LouisKottmann avatar Feb 11 '14 15:02 LouisKottmann

This fix should be lighter:

(defun baboon-set-powerline-selected-window ()
  "sets the variable `powerline-selected-window` appropriately"
  (when (not (minibuffer-window-active-p (frame-selected-window)))
      (setq powerline-selected-window (frame-selected-window))))

(add-hook 'window-configuration-change-hook 'baboon-set-powerline-selected-window)
(add-hook 'focus-in-hook 'baboon-set-powerline-selected-window)
(add-hook 'focus-out-hook 'baboon-set-powerline-selected-window)

(defadvice select-window (after baboon-select-window activate)
  "makes powerline aware of window changes"
  (baboon-set-powerline-selected-window))

And in the modeline:

'("%e"
  (:eval
   (let* ((active (eq powerline-selected-window (selected-window)))
           ;; ...

I've had good results with it today, even across frames

@milkypostman if you find no better way, I can make a it a pull request

LouisKottmann avatar Feb 11 '14 16:02 LouisKottmann

Cool, will take a look. I am talking to jonathanchu about his port and seeing if maybe we will deprecate my version and move to his.

On Tue Feb 11 2014 at 8:39:32 AM, Baboon [email protected] wrote:

This fix should be lighter:

(defun baboon-set-powerline-selected-window () "sets the variable powerline-selected-window" (when (not (minibuffer-window-active-p (frame-selected-window))) (setq powerline-selected-window (frame-selected-window)))) (add-hook 'window-configuration-change-hook 'baboon-set-powerline-selected-window)(add-hook 'focus-in-hook 'baboon-set-powerline-selected-window)(add-hook 'focus-out-hook 'baboon-set-powerline-selected-window) (defadvice select-window (after baboon-select-window activate) "makes powerline aware of window changes" (baboon-set-powerline-selected-window))

And in the modeline:

'("%e" (:eval (let* ((active (eq powerline-selected-window (selected-window)))

       ;; ...

I've had good results with it today, even across frames

— Reply to this email directly or view it on GitHubhttps://github.com/milkypostman/powerline/issues/37#issuecomment-34772940 .

milkypostman avatar Feb 11 '14 19:02 milkypostman

I confirm the problem on emacs-snapshot. Works well in emacs 24.3.

DamienCassou avatar Feb 24 '14 08:02 DamienCassou

Sounds to me like this should be a bug we file w/ gnu emacs instead of here? I mean, it's a regression in how the active window is being processed.

On Mon, Feb 24, 2014 at 12:57 AM, Damien Cassou [email protected]:

I confirm the problem on emacs-snapshot. Works well in emacs 24.3.

— Reply to this email directly or view it on GitHubhttps://github.com/milkypostman/powerline/issues/37#issuecomment-35867593 .

milkypostman avatar Feb 24 '14 19:02 milkypostman

Sounds to me like this should be a bug we file w/ gnu emacs instead of here?

done: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16874

DamienCassou avatar Feb 25 '14 09:02 DamienCassou

Can you link to the bug here? On Feb 25, 2014 1:07 AM, "Damien Cassou" [email protected] wrote:

Sounds to me like this should be a bug we file w/ gnu emacs instead of here?

done

— Reply to this email directly or view it on GitHubhttps://github.com/milkypostman/powerline/issues/37#issuecomment-35987968 .

milkypostman avatar Feb 25 '14 15:02 milkypostman

I don't understand. The 2 issues are cross-linked.

DamienCassou avatar Feb 25 '14 15:02 DamienCassou

Hrm, Github email didn't show the link! On Feb 25, 2014 7:05 AM, "Damien Cassou" [email protected] wrote:

I don't understand. The 2 issues are cross-linked.

— Reply to this email directly or view it on GitHubhttps://github.com/milkypostman/powerline/issues/37#issuecomment-36016370 .

milkypostman avatar Feb 25 '14 15:02 milkypostman

@milkypostman Could you please answer the questions on the emacs mailing list?

DamienCassou avatar Feb 26 '14 15:02 DamienCassou

does anyone want to volunteer to add in @LouisKottmann 's in a patch?

milkypostman avatar Mar 07 '14 06:03 milkypostman

@milkypostman I'll make a pull request today

LouisKottmann avatar Mar 07 '14 10:03 LouisKottmann

I managed to workaround this issue with https://github.com/yewton/.emacs.d/commit/574d30a7367b35466190250a2c0dccd5fdfd1147 .

It seems to work reasonably in Emacs 27.1 on macOS Mojave built with https://github.com/d12frosted/homebrew-emacs-plus .

yewton avatar Aug 15 '20 20:08 yewton