exwm icon indicating copy to clipboard operation
exwm copied to clipboard

switch workspace doesn't give focus to xapp

Open ellingtonsantos opened this issue 4 years ago • 23 comments

After update to exwm 0.24, after a workspace switch, I need to click inside X app to get focus. Last version default behavior was give focus to X app under frame.

ellingtonsantos avatar May 27 '20 13:05 ellingtonsantos

This does not happen here, last focused window in the frame gets focused, as usual. Could you try with a blank configuration?

medranocalvo avatar May 28 '20 14:05 medranocalvo

After tests with emacs -Q --eval "(progn (package-initialize) (require 'exwm-config) (exwm-config-default))"

I realized that the problem happens only in chromium. Libreoffice worked.

ellingtonsantos avatar May 28 '20 17:05 ellingtonsantos

Thank you for carrying out the test. I am at a loss, as to what could cause this. (I can't test it myself.)

Could you try enabling debug logging and reproducing again? See https://github.com/ch11ng/exwm/wiki#how-to-report-a-bug for instructions (I just added your emacs -Q line to the instructions).

medranocalvo avatar May 29 '20 05:05 medranocalvo

I did some tests with this command line: emacs -Q --eval "(progn (setq debug-on-error t edebug-all-forms t) (package-initialize) (require 'exwm-config) (exwm-config-default))"

  1. Switching workspace from a normal buffer to a Libreoffice exwm buffer (works):

[00:04:01] exwm-workspace-switch-create: 3 [00:04:01] exwm-workspace-switch: [00:04:01] exwm-workspace--set-active: active=#<frame libreoffice-writer 0x51fe2c0>; frame=t [00:04:01] exwm-workspace--set-fullscreen: frame=#<frame libreoffice-writer 0x51fe2c0> [00:04:01] exwm-workspace--set-fullscreen: x=0; y=0; w=1366; h=768 [00:04:01] exwm--set-geometry: Setting #x60002a to 1366x768+0+0 [00:04:01] exwm--set-geometry: Setting #x40053a to 1366x768+nil+nil [00:04:01] exwm-layout--refresh: frame=#<frame libreoffice-writer 0x51fe2c0> [00:04:01] exwm-layout--refresh-workspace: Refresh workspace #<frame libreoffice-writer 0x51fe2c0> [00:04:01] exwm-layout--show: Show #x1200024 in #<window 9 on libreoffice-writer> [00:04:01] exwm--set-geometry: Setting #x1200024 to 1366x724+0+0 [00:04:01] exwm-layout--set-state: id=#x1200024 [00:04:01] exwm-layout--set-client-list-stacking: [00:04:01] exwm-workspace--set-active: active=#<frame XELB-DEBUG 0x520be00>; frame=nil [00:04:01] exwm--set-geometry: Setting #x600028 to 1x1+nil+nil [00:04:01] exwm-layout--refresh: frame=#<frame XELB-DEBUG 0x520be00> [00:04:01] exwm-layout--refresh-workspace: Refresh workspace #<frame XELB-DEBUG 0x520be00> [00:04:01] exwm-layout--set-client-list-stacking: [00:04:01] exwm-layout--show: Show #x1200024 in #<window 9 on libreoffice-writer> [00:04:01] exwm--set-geometry: Setting #x1200024 to 1366x724+0+0 [00:04:01] exwm-layout--set-state: id=#x1200024 [00:04:01] exwm-input--on-buffer-list-update: current-buffer=# selected-window=#<window 9 on libreoffice-writer> [00:04:01] exwm-input--update-focus: focus-window=#<window 9 on libreoffice-writer> focus-buffer=libreoffice-writer [00:04:01] exwm-input--update-focus: Set focus on #x1200024 [00:04:01] exwm-manage--on-MapNotify: id=#x1200024 [00:04:01] exwm--on-PropertyNotify: atom=WM_STATE(436) [00:04:01] exwm--on-PropertyNotify: Unhandled: WM_STATE(436) [00:04:01] exwm-input--on-PropertyNotify: [00:04:01] exwm--on-PropertyNotify: atom=_NET_WM_STATE(355) [00:04:01] exwm--on-PropertyNotify: Unhandled: _NET_WM_STATE(355) [00:04:01] exwm-input--on-PropertyNotify: [00:04:01] exwm--on-PropertyNotify: atom=WM_STATE(436) [00:04:01] exwm--on-PropertyNotify: Unhandled: WM_STATE(436) [00:04:01] exwm-input--on-PropertyNotify: [00:04:01] exwm--on-PropertyNotify: atom=_NET_WM_STATE(355) [00:04:01] exwm--on-PropertyNotify: Unhandled: _NET_WM_STATE(355) [00:04:01] exwm-input--on-PropertyNotify: [00:04:01] exwm--on-ClientMessage: atom=_NET_ACTIVE_WINDOW(344) [00:04:01] exwm-input--set-focus: #x40053a (corrected) => #x1200024 [00:04:01] exwm-input--update-timestamp: [00:04:01] exwm-input--on-echo-area-dirty: [00:04:01] exwm-input--on-echo-area-dirty: [00:04:01] exwm--on-PropertyNotify: atom=_TIME(498) [00:04:01] exwm-input--on-PropertyNotify: [00:04:01] exwm-input--set-active-window: [00:04:01] exwm-input--on-echo-area-dirty: [00:04:03] exwm-input--on-KeyPress: major-mode=exwm-mode buffer=libreoffice-writer [00:04:03] exwm-input--on-KeyPress-line-mode: (97 . 131) [00:04:03] exwm-input--mimic-read-event: [00:04:03] exwm--on-PropertyNotify: atom=_NET_WM_USER_TIME(378) [00:04:03] exwm-input--on-PropertyNotify: [00:04:03] exwm-input--on-KeyPress: major-mode=exwm-mode buffer=libreoffice-writer [00:04:03] exwm-input--on-KeyPress-line-mode: (97 . 131) [00:04:03] exwm-input--mimic-read-event: [00:04:03] exwm--on-PropertyNotify: atom=_NET_WM_USER_TIME(378) [00:04:03] exwm-input--on-PropertyNotify: [00:04:04] exwm-input--on-KeyPress: major-mode=exwm-mode buffer=libreoffice-writer [00:04:04] exwm-input--on-KeyPress-line-mode: (65515 . 0) [00:04:04] exwm--on-PropertyNotify: atom=_NET_WM_USER_TIME(378) [00:04:04] exwm-input--on-PropertyNotify: [00:04:05] exwm-input--on-KeyPress: major-mode=exwm-mode buffer=libreoffice-writer [00:04:05] exwm-input--on-KeyPress-line-mode: (49 . 129) [00:04:05] exwm-input--mimic-read-event: [00:04:05] exwm-input--cache-event: 8388657 [00:04:05] exwm-workspace-switch-create: 1

  1. Switching workspace from a normal buffer to a Chromium exwm buffer (doesn't work):

[00:04:07] exwm-workspace-switch-create: 2 [00:04:07] exwm-workspace-switch: [00:04:07] exwm-workspace--set-active: active=#<frame Chromium 0x524e810>; frame=t [00:04:07] exwm-workspace--set-fullscreen: frame=#<frame Chromium 0x524e810> [00:04:07] exwm-workspace--set-fullscreen: x=0; y=0; w=1366; h=768 [00:04:07] exwm--set-geometry: Setting #x600029 to 1366x768+0+0 [00:04:07] exwm--set-geometry: Setting #x4003f0 to 1366x768+nil+nil [00:04:07] exwm-layout--refresh: frame=#<frame Chromium 0x524e810> [00:04:07] exwm-layout--refresh-workspace: Refresh workspace #<frame Chromium 0x524e810> [00:04:07] exwm-layout--show: Show #x800001 in #<window 7 on Chromium> [00:04:07] exwm--set-geometry: Setting #x800001 to 1366x724+0+0 [00:04:07] exwm-layout--set-state: id=#x800001 [00:04:07] exwm-layout--set-client-list-stacking: [00:04:07] exwm-workspace--set-active: active=#<frame XELB-DEBUG 0x520be00>; frame=nil [00:04:07] exwm--set-geometry: Setting #x600028 to 1x1+nil+nil [00:04:07] exwm-layout--refresh: frame=#<frame XELB-DEBUG 0x520be00> [00:04:07] exwm-layout--refresh-workspace: Refresh workspace #<frame XELB-DEBUG 0x520be00> [00:04:07] exwm-layout--set-client-list-stacking: [00:04:07] exwm-layout--show: Show #x800001 in #<window 7 on Chromium> [00:04:07] exwm--set-geometry: Setting #x800001 to 1366x724+0+0 [00:04:07] exwm-layout--set-state: id=#x800001 [00:04:07] exwm-input--on-buffer-list-update: current-buffer=#<buffer Chromium> selected-window=#<window 7 on Chromium> [00:04:07] exwm-input--update-focus: focus-window=#<window 7 on Chromium> focus-buffer=Chromium [00:04:07] exwm-input--update-focus: Set focus on #x800001 [00:04:07] exwm-manage--on-MapNotify: id=#x800001 [00:04:07] exwm--on-PropertyNotify: atom=WM_STATE(436) [00:04:07] exwm--on-PropertyNotify: Unhandled: WM_STATE(436) [00:04:07] exwm-input--on-PropertyNotify: [00:04:07] exwm--on-PropertyNotify: atom=_NET_WM_STATE(355) [00:04:07] exwm--on-PropertyNotify: Unhandled: _NET_WM_STATE(355) [00:04:07] exwm-input--on-PropertyNotify: [00:04:07] exwm--on-PropertyNotify: atom=WM_STATE(436) [00:04:07] exwm--on-PropertyNotify: Unhandled: WM_STATE(436) [00:04:07] exwm-input--on-PropertyNotify: [00:04:07] exwm--on-PropertyNotify: atom=_NET_WM_STATE(355) [00:04:07] exwm--on-PropertyNotify: Unhandled: _NET_WM_STATE(355) [00:04:07] exwm-input--on-PropertyNotify: [00:04:07] exwm--on-ClientMessage: atom=_NET_ACTIVE_WINDOW(344) [00:04:07] exwm-input--set-focus: #x4003f0 (corrected) => #x800001 [00:04:07] exwm-input--update-timestamp: [00:04:07] exwm-input--on-echo-area-dirty: [00:04:07] exwm-input--on-echo-area-dirty: [00:04:07] exwm--on-PropertyNotify: atom=_TIME(498) [00:04:07] exwm-input--on-PropertyNotify: [00:04:07] exwm-input--set-active-window: [00:04:07] exwm-input--on-echo-area-dirty: [00:04:11] exwm-input--on-KeyPress: major-mode=exwm-mode buffer=Chromium [00:04:11] exwm-input--on-KeyPress-line-mode: (65515 . 0) [00:04:11] exwm--on-PropertyNotify: atom=_NET_WM_USER_TIME(378) [00:04:11] exwm-input--on-PropertyNotify: [00:04:12] exwm-input--on-KeyPress: major-mode=exwm-mode buffer=Chromium [00:04:12] exwm-input--on-KeyPress-line-mode: (49 . 129) [00:04:12] exwm-input--mimic-read-event: [00:04:12] exwm-input--cache-event: 8388657 [00:04:12] exwm-workspace-switch-create: 1

  1. Switching workspace from a Libreoffice exwm buffer to a Chromium exwm buffer (it works!!!!):

[00:05:28] exwm-workspace-switch-create: 2 [00:05:28] exwm-workspace-switch: [00:05:28] exwm-workspace--set-active: active=#<frame Chromium 0x524e810>; frame=t [00:05:28] exwm-workspace--set-fullscreen: frame=#<frame Chromium 0x524e810> [00:05:28] exwm-workspace--set-fullscreen: x=0; y=0; w=1366; h=768 [00:05:28] exwm--set-geometry: Setting #x600029 to 1366x768+0+0 [00:05:28] exwm--set-geometry: Setting #x4003f0 to 1366x768+nil+nil [00:05:28] exwm-layout--refresh: frame=#<frame Chromium 0x524e810> [00:05:28] exwm-layout--refresh-workspace: Refresh workspace #<frame Chromium 0x524e810> [00:05:28] exwm-layout--show: Show #x800001 in #<window 7 on Chromium> [00:05:28] exwm--set-geometry: Setting #x800001 to 1366x724+0+0 [00:05:28] exwm-layout--set-state: id=#x800001 [00:05:28] exwm-layout--set-client-list-stacking: [00:05:28] exwm-workspace--set-active: active=#<frame libreoffice-writer 0x51fe2c0>; frame=nil [00:05:28] exwm--set-geometry: Setting #x60002a to 1x1+nil+nil [00:05:28] exwm-layout--refresh: frame=#<frame libreoffice-writer 0x51fe2c0> [00:05:28] exwm-layout--refresh-workspace: Refresh workspace #<frame libreoffice-writer 0x51fe2c0> [00:05:28] exwm-layout--hide: Hide #x1200024 [00:05:28] exwm-layout--set-state: id=#x1200024 [00:05:28] exwm-layout--set-client-list-stacking: [00:05:28] exwm-layout--show: Show #x800001 in #<window 7 on Chromium> [00:05:28] exwm--set-geometry: Setting #x800001 to 1366x724+0+0 [00:05:28] exwm-layout--set-state: id=#x800001 [00:05:28] exwm-input--on-buffer-list-update: current-buffer=#<buffer Chromium> selected-window=#<window 7 on Chromium> [00:05:28] exwm-input--on-echo-area-dirty: [00:05:28] exwm-input--update-focus: focus-window=#<window 7 on Chromium> focus-buffer=Chromium [00:05:28] exwm-input--update-focus: Set focus on #x800001 [00:05:28] exwm-manage--on-MapNotify: id=#x800001 [00:05:28] exwm--on-PropertyNotify: atom=WM_STATE(436) [00:05:28] exwm--on-PropertyNotify: Unhandled: WM_STATE(436) [00:05:28] exwm-input--on-PropertyNotify: [00:05:28] exwm--on-PropertyNotify: atom=_NET_WM_STATE(355) [00:05:28] exwm--on-PropertyNotify: Unhandled: _NET_WM_STATE(355) [00:05:28] exwm-input--on-PropertyNotify: [00:05:28] exwm--on-PropertyNotify: atom=WM_STATE(436) [00:05:28] exwm--on-PropertyNotify: Unhandled: WM_STATE(436) [00:05:28] exwm-input--on-PropertyNotify: [00:05:28] exwm--on-PropertyNotify: atom=_NET_WM_STATE(355) [00:05:28] exwm--on-PropertyNotify: Unhandled: _NET_WM_STATE(355) [00:05:28] exwm-input--on-PropertyNotify: [00:05:28] exwm--on-PropertyNotify: atom=WM_STATE(436) [00:05:28] exwm--on-PropertyNotify: Unhandled: WM_STATE(436) [00:05:28] exwm-input--on-PropertyNotify: [00:05:28] exwm--on-PropertyNotify: atom=_NET_WM_STATE(355) [00:05:28] exwm--on-PropertyNotify: Unhandled: _NET_WM_STATE(355) [00:05:28] exwm-input--on-PropertyNotify: [00:05:28] exwm--on-ClientMessage: atom=_NET_ACTIVE_WINDOW(344) [00:05:28] exwm-input--set-focus: #x4003f0 (corrected) => #x800001 [00:05:28] exwm-input--update-timestamp: [00:05:28] exwm-input--on-echo-area-dirty: [00:05:28] exwm--on-PropertyNotify: atom=_TIME(498) [00:05:28] exwm-input--on-PropertyNotify: [00:05:28] exwm-input--set-active-window: [00:05:28] exwm-input--on-echo-area-dirty: [00:05:29] exwm-input--on-KeyPress: major-mode=exwm-mode buffer=Chromium [00:05:29] exwm-input--on-KeyPress-line-mode: (97 . 131) [00:05:29] exwm-input--mimic-read-event: [00:05:29] exwm--on-PropertyNotify: atom=_NET_WM_USER_TIME(378) [00:05:29] exwm-input--on-PropertyNotify: [00:05:29] exwm-input--on-KeyPress: major-mode=exwm-mode buffer=Chromium [00:05:29] exwm-input--on-KeyPress-line-mode: (115 . 131) [00:05:29] exwm-input--mimic-read-event: [00:05:29] exwm--on-PropertyNotify: atom=_NET_WM_USER_TIME(378) [00:05:29] exwm-input--on-PropertyNotify: [00:05:29] exwm-input--on-KeyPress: major-mode=exwm-mode buffer=Chromium [00:05:29] exwm-input--on-KeyPress-line-mode: (100 . 131) [00:05:29] exwm-input--mimic-read-event: [00:05:29] exwm--on-PropertyNotify: atom=_NET_WM_USER_TIME(378) [00:05:29] exwm-input--on-PropertyNotify: [00:05:30] exwm-input--on-KeyPress: major-mode=exwm-mode buffer=Chromium [00:05:30] exwm-input--on-KeyPress-line-mode: (65515 . 0) [00:05:30] exwm--on-PropertyNotify: atom=_NET_WM_USER_TIME(378) [00:05:30] exwm-input--on-PropertyNotify: [00:05:30] exwm-input--on-KeyPress: major-mode=exwm-mode buffer=Chromium [00:05:30] exwm-input--on-KeyPress-line-mode: (49 . 129) [00:05:30] exwm-input--mimic-read-event: [00:05:30] exwm-input--cache-event: 8388657 [00:05:30] exwm-workspace-switch-create: 1

ellingtonsantos avatar May 29 '20 13:05 ellingtonsantos

I am seeing something similar but only with chromium, other X clients are fine. And it's also depends on how I perform the buffer switch. i have a binding to (switch-to-buffer nil) and using that results in lost focus but if I switch with iswitchb-buffer and selecting chromium there then it works. When chromium is in the lost focus state performing a C-x o twice to switch to another window and back restores keyboard focus too.

I noticed this immediately after switching to chromium-83 which has made some changes to input focus handling. Unfortunately I don't have an easy way to revert that so can't verify if that really has anything to do with it, might be a red herring.

On the exwm side I was able to bisect it to 3dbf1b1:

commit 3dbf1b1bed96d9ac3ee2718134ded619f46951bb (refs/bisect/bad)
Author: Chris Feng <[email protected]>
Date:   Sun Mar 29 00:00:00 2020 +0000

    Add support for _NET_WM_STATE_HIDDEN

    * exwm-layout.el (exwm-layout--set-ewmh-state): New function for
    setting _NET_WM_STATE (according to local state).
    * exwm.el (exwm--init-icccm-ewmh): Declare the support for this atom.

imarko avatar Jun 04 '20 14:06 imarko

Also, just commenting out the (cl-pushnew xcb:Atom:_NET_WM_STATE_HIDDEN exwm--ewmh-state) line in exwm-layout--hide makes chromium keyboard focus working correctly with current exwm master.

Perhaps some step is missing in exwm-layout--show when restoring a window to from hidden state that is needed to deal with some quirk in chromium's input handling?

imarko avatar Jun 04 '20 16:06 imarko

@ellingtonsantos I noticed in the debug logs that both applications were in fullscreen mode. Do you experience this issue with them in windowed mode? There are issues with fullscreen mode. Please try the fix (edb930005b0ba83051ca8a59b493e9a3c8ef580a) and report back.

@@imarko I suspect the cause to be that the _NET_WM_STATE_HIDDEN state is removed after Chromium X window is mapped but I'm not able to verify that. Could you try the following patch?

diff --git a/exwm-layout.el b/exwm-layout.el
index 79d0c95bc..c6306f717 100644
--- a/exwm-layout.el
+++ b/exwm-layout.el
@@ -141,11 +141,11 @@
                 width width*
                 height height*)))
       (exwm--set-geometry id x y width height)
-      (xcb:+request exwm--connection (make-instance 'xcb:MapWindow :window id))
       (exwm-layout--set-state id xcb:icccm:WM_STATE:NormalState)
       (setq exwm--ewmh-state
             (delq xcb:Atom:_NET_WM_STATE_HIDDEN exwm--ewmh-state))
       (exwm-layout--set-ewmh-state id)
+      (xcb:+request exwm--connection (make-instance 'xcb:MapWindow :window id))
       (exwm-layout--auto-iconify)))
   (xcb:flush exwm--connection))

Also, @ellingtonsantos were you on Chromium 83 just like @imarko do?

ch11ng avatar Jun 14 '20 09:06 ch11ng

No change with the patch, still seeing the same behavior.

imarko avatar Jun 14 '20 10:06 imarko

I guess we'll have to check what's changed in Chromium before we come up with a fix, if older versions work.

ch11ng avatar Jun 14 '20 14:06 ch11ng

I was able to verify that google-chrome-81.0.4044.138 (from the official google .deb) does work correctly with exwm but 83.0.4103.97 does not.

Also, I checked with stumpwm which I believe also sets/unsets _NET_WM_STATE_HIDDEN in a similar way and that does work with the versions that are broken with exwm. https://github.com/stumpwm/stumpwm/blob/master/window.lisp#L513

imarko avatar Jun 14 '20 20:06 imarko

I can fully reproduce this problem locally now. What I've observed is basically the same with that of @imarko and @ellingtonsantos . The property itself (_NET_WM_STATE_HIDDEN) was correctly set/unset but perhaps at an improper time. I'm still investigating it.

UPDATE: I'm still working on this. Building Chromium is not as straightforward as I thought :(

ch11ng avatar Jul 12 '20 14:07 ch11ng

@ch11ng Having the same issue. Is there a workaround available?

ezemtsov avatar Sep 15 '20 11:09 ezemtsov

@ezemtsov One workaround is to comment out the (cl-pushnew xcb:Atom:_NET_WM_STATE_HIDDEN exwm--ewmh-state) line in exwm-layout.el until this can be fixed.

imarko avatar Sep 15 '20 16:09 imarko

Looks like this is still an issue with electron apps in general, e.g. Discord and Slack. @imarko's workaround seems to work based on a few minutes of experimenting, but that's not exactly ideal of course. I also notice that switching to a different window and then back (e.g. M-: for minibuffer then C-g) fixes the focus.

Is there anything (simple) I can do to help with this issue?

chasecaleb avatar Dec 30 '22 22:12 chasecaleb

I also still face the same problem with google-chrome (not with any other apps I use)

moritzschaefer avatar Jul 08 '23 07:07 moritzschaefer

This happens to me randomly with Chrome, with other apps (and also when switching back to buffers), the focus usually moves but sometimes the cursor doesn't become active. I pull my EXWM from master and this only started appearing after I dragged in the last year or so of updates, if I find the time I'll do a bisect.

tazjin avatar Jul 08 '23 16:07 tazjin

I see this with brave

ecraven avatar Jul 25 '23 16:07 ecraven

I have a similar issue. When clicking in a EXWM buffer, cursor clicks will randomly stop registering. Mouse hovering still registers, as does the keyboard. When I set EXWM to debug mode, it appears as if each cursor clicks focuses the window, but doesn't perform any click. The only way I have solved it is by restarting emacs, or sometimes it will start working again randomly. Interestingly it appears less frequently after I updated to emacs 30, but it still happens once a week or so.

walseb avatar Jul 25 '23 16:07 walseb

@ezemtsov One workaround is to comment out the (cl-pushnew xcb:Atom:_NET_WM_STATE_HIDDEN exwm--ewmh-state) line in exwm-layout.el until this can be fixed.

Any reason not to integrate into the main @ch11ng?

moritzschaefer avatar Oct 05 '23 18:10 moritzschaefer

I'm also facing this issue and will try the workaround. Also, @ch11ng disappeared from the internet like 2 years ago and is no longer the maintainer.

@ezemtsov One workaround is to comment out the (cl-pushnew xcb:Atom:_NET_WM_STATE_HIDDEN exwm--ewmh-state) line in exwm-layout.el until this can be fixed.

Any reason not to integrate into the main @ch11ng?

LemonBreezes avatar Oct 15 '23 02:10 LemonBreezes

@LemonBreezes so whom may I ping to merge this? I can also do the PR

moritzschaefer avatar Oct 15 '23 15:10 moritzschaefer

@LemonBreezes so whom may I ping to merge this? I can also do the PR

@medranocalvo

LemonBreezes avatar Oct 15 '23 15:10 LemonBreezes

Conclusion from #933: The workaround to comment out (cl-pushnew xcb:Atom:_NET_WM_STATE_HIDDEN exwm--ewmh-state) should be a workaround only and not a persistent fix

moritzschaefer avatar Dec 07 '23 19:12 moritzschaefer