unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#16761: 24.3.50; focus-in-hook not running accurately when frame switches to terminal
@ 2014-02-15 12:14 Steven Edwards
  2014-02-15 14:31 ` Eli Zaretskii
  2021-12-04  3:27 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 7+ messages in thread
From: Steven Edwards @ 2014-02-15 12:14 UTC (permalink / raw)
  To: 16761

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@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@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@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@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)





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#16761: 24.3.50; focus-in-hook not running accurately when frame switches to terminal
  2014-02-15 12:14 bug#16761: 24.3.50; focus-in-hook not running accurately when frame switches to terminal Steven Edwards
@ 2014-02-15 14:31 ` Eli Zaretskii
  2014-02-15 17:04   ` Steven Edwards
  2021-12-04  3:27 ` Lars Ingebrigtsen
  1 sibling, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2014-02-15 14:31 UTC (permalink / raw)
  To: Steven Edwards; +Cc: 16761

> Date: Sat, 15 Feb 2014 07:14:22 -0500
> From: Steven Edwards <cureadvocate@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@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@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@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@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?





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#16761: 24.3.50; focus-in-hook not running accurately when frame switches to terminal
  2014-02-15 14:31 ` Eli Zaretskii
@ 2014-02-15 17:04   ` Steven Edwards
  2014-02-15 17:14     ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Steven Edwards @ 2014-02-15 17:04 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 16761

> 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





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#16761: 24.3.50; focus-in-hook not running accurately when frame switches to terminal
  2014-02-15 17:04   ` Steven Edwards
@ 2014-02-15 17:14     ` Eli Zaretskii
  2014-02-15 17:23       ` Steven Edwards
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2014-02-15 17:14 UTC (permalink / raw)
  To: Steven Edwards; +Cc: 16761

> Date: Sat, 15 Feb 2014 12:04:52 -0500
> From: Steven Edwards <cureadvocate@gmail.com>
> Cc: 16761@debbugs.gnu.org, Jan Djärv <jan.h.d@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?





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#16761: 24.3.50; focus-in-hook not running accurately when frame switches to terminal
  2014-02-15 17:14     ` Eli Zaretskii
@ 2014-02-15 17:23       ` Steven Edwards
  2014-02-15 20:39         ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Steven Edwards @ 2014-02-15 17:23 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 16761

On 2/15/14, Eli Zaretskii <eliz@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.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#16761: 24.3.50; focus-in-hook not running accurately when frame switches to terminal
  2014-02-15 17:23       ` Steven Edwards
@ 2014-02-15 20:39         ` Eli Zaretskii
  0 siblings, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2014-02-15 20:39 UTC (permalink / raw)
  To: Steven Edwards; +Cc: 16761

> Date: Sat, 15 Feb 2014 12:23:56 -0500
> From: Steven Edwards <cureadvocate@gmail.com>
> Cc: 16761@debbugs.gnu.org, jan.h.d@swipnet.se
> 
> On 2/15/14, Eli Zaretskii <eliz@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.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#16761: 24.3.50; focus-in-hook not running accurately when frame switches to terminal
  2014-02-15 12:14 bug#16761: 24.3.50; focus-in-hook not running accurately when frame switches to terminal Steven Edwards
  2014-02-15 14:31 ` Eli Zaretskii
@ 2021-12-04  3:27 ` Lars Ingebrigtsen
  1 sibling, 0 replies; 7+ messages in thread
From: Lars Ingebrigtsen @ 2021-12-04  3:27 UTC (permalink / raw)
  To: Steven Edwards; +Cc: 16761

Steven Edwards <cureadvocate@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





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-12-04  3:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-15 12:14 bug#16761: 24.3.50; focus-in-hook not running accurately when frame switches to terminal Steven Edwards
2014-02-15 14:31 ` Eli Zaretskii
2014-02-15 17:04   ` Steven Edwards
2014-02-15 17:14     ` Eli Zaretskii
2014-02-15 17:23       ` Steven Edwards
2014-02-15 20:39         ` Eli Zaretskii
2021-12-04  3:27 ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).