GNU bug report logs - #16761
24.3.50; focus-in-hook not running accurately when frame switches to terminal

Previous Next

Package: emacs;

Reported by: Steven Edwards <cureadvocate <at> gmail.com>

Date: Sat, 15 Feb 2014 12:15:02 UTC

Severity: normal

Found in version 24.3.50

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 16761 in the body.
You can then email your comments to 16761 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#16761; Package emacs. (Sat, 15 Feb 2014 12:15:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Steven Edwards <cureadvocate <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 15 Feb 2014 12:15:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Steven Edwards <cureadvocate <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.3.50;
 focus-in-hook not running accurately when frame switches to terminal
Date: Sat, 15 Feb 2014 07:14:22 -0500
Starting from emacs -Q:

---
(server-start)
(defun rand/on-focus ()
  (message (concat (prin1-to-string window-system) (prin1-to-string
  (selected-frame)) (format-time-string "%H:%M:%S.%N"))))
(add-hook 'focus-in-hook 'rand/on-focus)
---

Open another graphical frame with C-x 5 2; switch it to *Messages* buffer.

Next open a non-graphical frame with emacsclient -nw.

You should now have three frames open.

Switch frames from one to the next.  (I'm using the awesome window
manager, so Super-J.)

You'll notice that when switching from one graphical frame to the next,
two messages appear, e.g.:

---
x#<frame *unsent mail to bug-gnu-emacs <at> gnu.org* 0xe88e40>06:40:47.325463985
x#<frame *Messages* 0x1123978>06:40:47.384926969
---

...but when cycling from a graphical frame to a terminal frame, nothing new
appears in *Messages*--until you switch to a graphical frame:

---
x#<frame *Messages* 0x1123978>06:44:37.889809270
x#<frame *Messages* 0x1123978>06:44:37.922339020
x#<frame *unsent mail to bug-gnu-emacs <at> gnu.org* 0xe88e40>06:44:37.922801690
---

If you perform any actions on the terminal frame after switching switch
from a graphical frame, *Messages* will receive one message--as if
focus-in-hooks are being called from focus-out-hooks:

---
x#<frame emacs <at> Rand.launchmodem.com 0x352e880>06:56:51.097246751
---

Switching to a raphical frame after performing an action on the terminal
frame will finally send a message containing the terminal frame object,
but only after it loses focus:

---
nil#<frame F2 0x11e90c8>06:56:53.533491550
x#<frame emacs <at> Rand.launchmodem.com 0x352e880>06:56:53.533998714
---

Possibly related, C-x 5 o skips over any terminal frames and C-x 5 1
won't delete terminal frames.

The use case for this is that I'd like to use different themes for X
frames and terminal frames.

I know the use of window-system is deprecated; (framep (selected-frame))
does not work either.

I hope this report helps.

Best,

Steven




In GNU Emacs 24.3.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.20.1)
 of 2014-01-25 on Rand
Windowing system distributor `The X.Org Foundation', version 11.0.11004000
System Description:	Debian GNU/Linux 6.0.8 (squeeze)

Important settings:
  value of $LC_CTYPE: en_US.UTF-8
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Emacs-Lisp

Minor modes in effect:
  tooltip-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
C-x C-f . e m a c s <return> C-n C-n C-n C-n C-n C-n
C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n
C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-b C-x
C-e C-x b C-g C-x C-f . e m a c s . d / l i TAB c u
s TAB g l TAB <return> C-n C-n C-n C-n C-n C-n C-n
C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n
C-n C-n C-n C-n C-n C-n C-b C-x C-e C-n C-n C-n C-n
C-n C-n C-a C-b C-x C-e C-x 5 2 <switch-frame> M-x
i d o - m o d e <return> <switch-frame> C-x b m e <return>
<switch-frame> <switch-frame> <switch-frame> <switch-frame>
ESC [ > 1 ; 2 4 0 3 ; 0 c <switch-frame> <switch-frame>
<switch-frame> <switch-frame> <switch-frame> <switch-frame>
M-x r e p o r t - e m SPC SPC <return>

Recent messages:
x#<frame custom-global.el 0xe88e40>06:28:40.401223846
x#<frame *Messages* 0x1123978>06:28:40.435829590
x#<frame *Messages* 0x1123978>06:28:58.428023215
x#<frame *Messages* 0x1123978>06:28:58.482460360
x#<frame custom-global.el 0xe88e40>06:28:58.482890190
x#<frame custom-global.el 0xe88e40>06:29:07.640302435
x#<frame *Messages* 0x1123978>06:29:07.675357806
x#<frame *Messages* 0x1123978>06:29:20.079938338
x#<frame *Messages* 0x1123978>06:29:20.136675311
x#<frame custom-global.el 0xe88e40>06:29:20.137121846

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml
easymenu mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util help-fns mail-prsvr mail-utils xterm ido server time-date
tooltip electric uniquify ediff-hook vc-hooks lisp-float-type mwheel
x-win x-dnd tool-bar dnd fontset image regexp-opt fringe tabulated-list
newcomment lisp-mode prog-mode register page menu-bar rfn-eshadow timer
select scroll-bar mouse jit-lock font-lock syntax facemenu font-core
frame cham georgian utf-8-lang misc-lang vietnamese tibetan thai
tai-viet lao korean japanese hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese case-table epa-hook jka-cmpr-hook help
simple abbrev minibuffer nadvice loaddefs button faces cus-face macroexp
files text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote make-network-process
dbusbind gfilenotify dynamic-setting font-render-setting move-toolbar
gtk x-toolkit x multi-tty emacs)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16761; Package emacs. (Sat, 15 Feb 2014 14:32:03 GMT) Full text and rfc822 format available.

Message #8 received at 16761 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Steven Edwards <cureadvocate <at> gmail.com>
Cc: Jan Djärv <jan.h.d <at> swipnet.se>, 16761 <at> debbugs.gnu.org
Subject: Re: bug#16761: 24.3.50;
 focus-in-hook not running accurately when frame switches to terminal
Date: Sat, 15 Feb 2014 16:31:00 +0200
> Date: Sat, 15 Feb 2014 07:14:22 -0500
> From: Steven Edwards <cureadvocate <at> gmail.com>
> 
> Starting from emacs -Q:
> 
> ---
> (server-start)
> (defun rand/on-focus ()
>   (message (concat (prin1-to-string window-system) (prin1-to-string
>   (selected-frame)) (format-time-string "%H:%M:%S.%N"))))
> (add-hook 'focus-in-hook 'rand/on-focus)
> ---
> 
> Open another graphical frame with C-x 5 2; switch it to *Messages* buffer.
> 
> Next open a non-graphical frame with emacsclient -nw.
> 
> You should now have three frames open.
> 
> Switch frames from one to the next.  (I'm using the awesome window
> manager, so Super-J.)
> 
> You'll notice that when switching from one graphical frame to the next,
> two messages appear, e.g.:
> 
> ---
> x#<frame *unsent mail to bug-gnu-emacs <at> gnu.org* 0xe88e40>06:40:47.325463985
> x#<frame *Messages* 0x1123978>06:40:47.384926969
> ---
> 
> ...but when cycling from a graphical frame to a terminal frame, nothing new
> appears in *Messages*--until you switch to a graphical frame:
> 
> ---
> x#<frame *Messages* 0x1123978>06:44:37.889809270
> x#<frame *Messages* 0x1123978>06:44:37.922339020
> x#<frame *unsent mail to bug-gnu-emacs <at> gnu.org* 0xe88e40>06:44:37.922801690
> ---
> 
> If you perform any actions on the terminal frame after switching switch
> from a graphical frame, *Messages* will receive one message--as if
> focus-in-hooks are being called from focus-out-hooks:
> 
> ---
> x#<frame emacs <at> Rand.launchmodem.com 0x352e880>06:56:51.097246751
> ---
> 
> Switching to a raphical frame after performing an action on the terminal
> frame will finally send a message containing the terminal frame object,
> but only after it loses focus:
> 
> ---
> nil#<frame F2 0x11e90c8>06:56:53.533491550
> x#<frame emacs <at> Rand.launchmodem.com 0x352e880>06:56:53.533998714
> ---
> 
> Possibly related, C-x 5 o skips over any terminal frames and C-x 5 1
> won't delete terminal frames.

You don't say what you expect to happen.  Do you expect a focus-in and
focus-out event to be generated for terminal frames?  Or do you expect
(or need) something else?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16761; Package emacs. (Sat, 15 Feb 2014 17:06:01 GMT) Full text and rfc822 format available.

Message #11 received at 16761 <at> debbugs.gnu.org (full text, mbox):

From: Steven Edwards <cureadvocate <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Jan Djärv <jan.h.d <at> swipnet.se>, 16761 <at> debbugs.gnu.org
Subject: Re: bug#16761: 24.3.50; focus-in-hook not running accurately when
 frame switches to terminal
Date: Sat, 15 Feb 2014 12:04:52 -0500
> You don't say what you expect to happen.  Do you expect a focus-in and
> focus-out event to be generated for terminal frames?  Or do you expect
> (or need) something else?

I need a focus-in event to occur when switching to a terminal frame;
the code I provided was simply to demonstrate and focus on the error.

The real code:

---
(defun rand/swap-theme (from to)
  (disable-theme from)
  (enable-theme to))

(defun rand/choose-theme ()
  (cond
    ((memq window-system '(x w32 ns)) (rand/swap-theme 'Custom 'assemblage))
    (t (rand/swap-theme 'assemblage 'Custom))))

(add-hook 'focus-in-hook 'rand/choose-theme)
---

The goal is to switch to a terminal-friendly theme when I'm in tmux
and a GUI friendly theme when I'm in a graphical environment.  The
problem seems to be that the hooks in focus-in-hooks aren't being
executed when I switch to a terminal frame.

Best,

Steven




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16761; Package emacs. (Sat, 15 Feb 2014 17:15:02 GMT) Full text and rfc822 format available.

Message #14 received at 16761 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Steven Edwards <cureadvocate <at> gmail.com>
Cc: jan.h.d <at> swipnet.se, 16761 <at> debbugs.gnu.org
Subject: Re: bug#16761: 24.3.50;
 focus-in-hook not running accurately when frame switches to terminal
Date: Sat, 15 Feb 2014 19:14:43 +0200
> Date: Sat, 15 Feb 2014 12:04:52 -0500
> From: Steven Edwards <cureadvocate <at> gmail.com>
> Cc: 16761 <at> debbugs.gnu.org, Jan Djärv <jan.h.d <at> swipnet.se>
> 
> > You don't say what you expect to happen.  Do you expect a focus-in and
> > focus-out event to be generated for terminal frames?  Or do you expect
> > (or need) something else?
> 
> I need a focus-in event to occur when switching to a terminal frame;

How can Emacs get a focus-in event for the terminal frame, when the
event is sent by X?  Jan, is this possible with X?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16761; Package emacs. (Sat, 15 Feb 2014 17:25:02 GMT) Full text and rfc822 format available.

Message #17 received at 16761 <at> debbugs.gnu.org (full text, mbox):

From: Steven Edwards <cureadvocate <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: jan.h.d <at> swipnet.se, 16761 <at> debbugs.gnu.org
Subject: Re: bug#16761: 24.3.50; focus-in-hook not running accurately when
 frame switches to terminal
Date: Sat, 15 Feb 2014 12:23:56 -0500
On 2/15/14, Eli Zaretskii <eliz <at> gnu.org> wrote:
> How can Emacs get a focus-in event for the terminal frame, when the
> event is sent by X?  Jan, is this possible with X?

Interesting.  I wasn't aware those events were sent by X.

Out of curiosity, then, how does Emacs produce the message indicating
a terminal frame after I return to an X frame?  It seems like it's
blocking somewhere.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16761; Package emacs. (Sat, 15 Feb 2014 20:40:01 GMT) Full text and rfc822 format available.

Message #20 received at 16761 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Steven Edwards <cureadvocate <at> gmail.com>
Cc: jan.h.d <at> swipnet.se, 16761 <at> debbugs.gnu.org
Subject: Re: bug#16761: 24.3.50;
 focus-in-hook not running accurately when frame switches to terminal
Date: Sat, 15 Feb 2014 22:39:12 +0200
> Date: Sat, 15 Feb 2014 12:23:56 -0500
> From: Steven Edwards <cureadvocate <at> gmail.com>
> Cc: 16761 <at> debbugs.gnu.org, jan.h.d <at> swipnet.se
> 
> On 2/15/14, Eli Zaretskii <eliz <at> gnu.org> wrote:
> > How can Emacs get a focus-in event for the terminal frame, when the
> > event is sent by X?  Jan, is this possible with X?
> 
> Interesting.  I wasn't aware those events were sent by X.
> 
> Out of curiosity, then, how does Emacs produce the message indicating
> a terminal frame after I return to an X frame?  It seems like it's
> blocking somewhere.

I think the event is generated by X when you switch to a GUI frame,
and the terminal frame is just indicated as the previous one (since
Emacs does know about its terminal frames).  But I may be mistaken, so
I prefer to hear from Jan on this.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16761; Package emacs. (Sat, 04 Dec 2021 03:29:01 GMT) Full text and rfc822 format available.

Message #23 received at 16761 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Steven Edwards <cureadvocate <at> gmail.com>
Cc: 16761 <at> debbugs.gnu.org
Subject: Re: bug#16761: 24.3.50; focus-in-hook not running accurately when
 frame switches to terminal
Date: Sat, 04 Dec 2021 04:27:56 +0100
Steven Edwards <cureadvocate <at> gmail.com> writes:

> ...but when cycling from a graphical frame to a terminal frame, nothing new
> appears in *Messages*--until you switch to a graphical frame:

(I'm going through old bug reports that unfortunately weren't resolved
at the time.)

focus-in-hook was made obsolete in Emacs 27.1, and
`after-focus-change-function' should be used instead.  And using that, I
see that the change function is called reliably when changing to a
terminal frame, so I think this has been fixed now, and I'm closing this
bug report.

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




bug closed, send any further explanations to 16761 <at> debbugs.gnu.org and Steven Edwards <cureadvocate <at> gmail.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sat, 04 Dec 2021 03:29:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 01 Jan 2022 12:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 77 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.