Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

highlight active window

455 views
Skip to first unread message

Renaud Pons

unread,
Mar 6, 2001, 6:15:17 AM3/6/01
to
Hello

I am looking for a piece of code to highlight active window, that is
the window where the cursor is. I use to have a single large frame
with many windows and I often switch from one window to another and
sometimes I have to search in which window is the cursor ! So I would
like to have e.g. a white background for the active window and a light
grey one for other windows.

Thanks for any suggestion.
--
Renaud

Amit Patel

unread,
Mar 12, 2001, 11:13:18 AM3/12/01
to
Renaud Pons <rp...@laas.fr> writes:

I've been experimenting with this but I haven't gotten it completely
working yet. :(

(defvar modeline-last-window nil)
(defvar modeline-off-color "gray50")
(defvar modeline-on-color "red3")
(defun update-modeline-color (&rest args)
(interactive)
(let ((current-window (and (not blink-cursor-lost-focus) (frame-selected-windo
w (selected-frame)))))
(unless (eq current-window modeline-last-window)
(when modeline-last-window
(add-spec-to-specifier (face-property 'modeline 'background)
modeline-off-color modeline-last-window))
(when current-window
(add-spec-to-specifier (face-property 'modeline 'background)
modeline-on-color current-window))
(setq modeline-last-window current-window)
(redraw-frame)
))
t)
(setq hack-modeline-color-timer
(start-itimer "change modeline colors"
'update-modeline-color 1 1 t))
(defadvice other-window (after update-modeline)
(update-modeline-color))
(add-hook 'mouse-track-cleanup-hook 'update-modeline-color)
(add-hook 'deselect-frame-hook 'update-modeline-color)
(add-hook 'select-frame-hook 'update-modeline-color)
(add-hook 'mouse-enter-frame-hook 'update-modeline-color)
(add-hook 'mouse-leave-frame-hook 'update-modeline-color)

This changes the modeline color instead of the frame background color,
but the goal is similar -- I want to know which buffer is active! :)

The code may work better for you than it does for me. I have multiple
frames AND multiple buffers in each one, and I haven't gotten the code
working smoothly with that setup. Alas, if enter-window-hook and
leave-window-hook worked, this would be so much easier.


- Amit

--
Amit J Patel, Computer Science Department, Stanford University
http://www-cs-students.stanford.edu/~amitp/
``Parkinson's Other Law: Perfection is achieved only
at the point of collapse.''

Renaud Pons

unread,
Mar 13, 2001, 11:32:16 AM3/13/01
to
>>>>> "Amit" == Amit Patel <am...@theory.stanford.edu> writes:

Amit> I've been experimenting with this but I haven't gotten it
Amit> completely working yet. :(
Amit> [some code]

Finally I simply wrote:

(defun my-other-window ()
(interactive)
(set-face-property 'default 'background "lightgrey" (selected-window))
(other-window 1)
(set-face-property 'default 'background "floral white" (selected-window)))

(global-set-key '[(control tab)] 'my-other-window)

which is sufficient for me but your code works effectively quite fine
for me. Thanks for your answer.

Amit> Alas, if enter-window-hook and leave-window-hook worked,
Amit> this would be so much easier.

Wait and see :)
--
Renaud

Eric Holbrook

unread,
Mar 14, 2001, 11:32:46 AM3/14/01
to
this is so _incredibly_ useful. i'm amazed it isn't part of xemacs by
default. thanks, all.

Eric

--
Eric Holbrook er...@agere.com (512)502-3268

Colin Marquardt

unread,
Mar 14, 2001, 8:37:05 PM3/14/01
to
Eric Holbrook <er...@agere.com> writes:

> this is so _incredibly_ useful. i'm amazed it isn't part of xemacs by
> default. thanks, all.

Me too, really great. I use Amit's solution, but I would like to have
some slight improvements:

the text of the non-active modeline should become greyed out while
the active one has the full color. For this, you'd have to store and
change the faces of modeline, modeline-buffer-id, modeline-mousable
and modeline-mousable-minor-mode, then set them all to be grey.

I tried that with doing the following:

(defvar modeline-bg-off-color "bisque2")
(defvar modeline-fg-off-color "grey50")
(defvar modeline-bg-on-color "grey90")
(defvar modeline-fg-on-color "steelblue4")


(defun update-modeline-color (&rest args)
(interactive)
(let ((current-window
;; (and (not blink-cursor-lost-focus)
(frame-selected-window (selected-frame))))
;; )
(unless (eq current-window modeline-last-window)
(when modeline-last-window
(add-spec-to-specifier (face-property 'modeline 'background)

modeline-bg-off-color modeline-last-window)
(add-spec-to-specifier (face-property 'modeline 'foreground)
modeline-fg-off-color modeline-last-window)
;; !!! this doesn't work !!!:
(add-spec-to-specifier (face-property 'modeline-buffer-id 'foreground)
modeline-fg-off-color modeline-last-window)


)
(when current-window
(add-spec-to-specifier (face-property 'modeline 'background)

modeline-bg-on-color current-window)
(add-spec-to-specifier (face-property 'modeline 'foreground)
modeline-fg-on-color current-window)
;; need to recover the old value here, hardcode it for now:
(add-spec-to-specifier (face-property 'modeline-buffer-id 'foreground)
"blue4" modeline-last-window)


)
(setq modeline-last-window current-window)
(redraw-frame)
))
t)

[...]

Somehow though, the part marked with !!! doesn't work, it just
doesn't grey out.

Also, I don't know how to copy the old value to a temporary
variable/symbol/face/whatever to recover it. Is it copy-face?

If somebody sees the problem, I'd be happy to hear it, otherwise I'll
probably devote some time to that in the future.

TIA,
Colin

bw...@xs4all.nl

unread,
Mar 17, 2001, 1:28:52 AM3/17/01
to
Colin Marquardt wrote:

> Replying to myself:


>
> Colin Marquardt <colin.m...@usa.alcatel.com> writes:
>
> > ;; !!! this doesn't work !!!:
> > (add-spec-to-specifier (face-property 'modeline-buffer-id 'foreground)
> > modeline-fg-off-color modeline-last-window)
> > )
> > (when current-window
> > (add-spec-to-specifier (face-property 'modeline 'background)
> > modeline-bg-on-color current-window)
> > (add-spec-to-specifier (face-property 'modeline 'foreground)
> > modeline-fg-on-color current-window)
> > ;; need to recover the old value here, hardcode it for now:
> > (add-spec-to-specifier (face-property 'modeline-buffer-id 'foreground)
> > "blue4" modeline-last-window)

> -----------------------------------------^^^^^^^^^^^^^^^^^^^^
>
> should be current-window, of course.


>
> > Somehow though, the part marked with !!! doesn't work, it just
> > doesn't grey out.
>

> The wonders of copy'n'paste... how embarassing.
>
> Cheers,
> Colin

Would you mind reposting the full correct code once again? I am confused.


Bertwim

Colin Marquardt

unread,
Mar 15, 2001, 3:02:38 PM3/15/01
to
Replying to myself:

Colin Marquardt <colin.m...@usa.alcatel.com> writes:

> ;; !!! this doesn't work !!!:
> (add-spec-to-specifier (face-property 'modeline-buffer-id 'foreground)
> modeline-fg-off-color modeline-last-window)
> )
> (when current-window
> (add-spec-to-specifier (face-property 'modeline 'background)
> modeline-bg-on-color current-window)
> (add-spec-to-specifier (face-property 'modeline 'foreground)
> modeline-fg-on-color current-window)
> ;; need to recover the old value here, hardcode it for now:
> (add-spec-to-specifier (face-property 'modeline-buffer-id 'foreground)
> "blue4" modeline-last-window)

-----------------------------------------^^^^^^^^^^^^^^^^^^^^

should be current-window, of course.

> Somehow though, the part marked with !!! doesn't work, it just
> doesn't grey out.

The wonders of copy'n'paste... how embarassing.

Cheers,
Colin

Colin Marquardt

unread,
Mar 20, 2001, 10:36:14 PM3/20/01
to
bw...@xs4all.nl writes:

[tweaked code from Amit Patel to highlight the active window]


> Would you mind reposting the full correct code once again? I am confused.

Sorry for the late answer, here it is:

;;; From: Amit Patel <am...@theory.stanford.edu>
;;; Subject: Re: highlight active window
;;; Newsgroups: comp.emacs.xemacs
;;; Date: 12 Mar 2001 08:13:18 -0800
;;; X-Sent: 2 hours, 58 minutes, 33 seconds ago
;;; X-Newsreader: Gnus v5.5/XEmacs 20.4 - "Emerald"
;;;

;;; Renaud Pons <rp...@laas.fr> writes:
;;;
;;; > Hello
;;; >
;;; > I am looking for a piece of code to highlight active window, that is
;;; > the window where the cursor is. I use to have a single large frame
;;; > with many windows and I often switch from one window to another and

;;; > sometimes I have to search in which window is the cursor ! So I would
;;; > like to have e.g. a white background for the active window and a light


;;; > grey one for other windows.

;;;
;;; I've been experimenting with this but I haven't gotten it completely
;;; working yet. :(

;;; [tweaked a bit by Colin Marquardt]
(defvar modeline-last-window nil)
(defvar modeline-bg-off-color "bisque2")
(defvar modeline-fg-off-color "bisque4")
(defvar modeline-bg-on-color "bisque2")


;(defvar modeline-bg-on-color "grey90")
(defvar modeline-fg-on-color "steelblue4")
(defun update-modeline-color (&rest args)
(interactive)
(let ((current-window
;; (and (not blink-cursor-lost-focus)
(frame-selected-window (selected-frame))))
;; )
(unless (eq current-window modeline-last-window)
(when modeline-last-window
(add-spec-to-specifier (face-property 'modeline 'background)
modeline-bg-off-color modeline-last-window)
(add-spec-to-specifier (face-property 'modeline 'foreground)
modeline-fg-off-color modeline-last-window)

(add-spec-to-specifier (face-property 'modeline-buffer-id 'foreground)
modeline-fg-off-color modeline-last-window)

(add-spec-to-specifier (face-property 'modeline-mousable 'foreground)
modeline-fg-off-color modeline-last-window)
(add-spec-to-specifier (face-property 'modeline-mousable-minor-mode 'foreground)

modeline-fg-off-color modeline-last-window)
)
(when current-window
(add-spec-to-specifier (face-property 'modeline 'background)
modeline-bg-on-color current-window)
(add-spec-to-specifier (face-property 'modeline 'foreground)
modeline-fg-on-color current-window)

(add-spec-to-specifier (face-property 'modeline-buffer-id 'foreground)
"blue4" current-window)
(add-spec-to-specifier (face-property 'modeline-mousable 'foreground)
"firebrick" current-window)
(add-spec-to-specifier (face-property 'modeline-mousable-minor-mode 'foreground)
"green4" current-window)


)
(setq modeline-last-window current-window)
(redraw-frame)
))
t)

0 new messages