ch11ng/exwm

EXWM buffers only work with previously defined bindings

Closed this issue · 10 comments

After updating to EXWM 0.24, bindings defined like so

(exwm-input-set-key (kbd "s-n")
                    (lambda () (interactive) (exwm-workspace-switch 0)))

only work in EXWM-buffers (i.e. X windows) if they had been defined before.

(exwm-input-set-key (kbd "s-r")
                    (lambda () (interactive) (exwm-workspace-switch 1)))

would work as expected for example, but s-n does nothing (it works in normal emacs buffers though).

Here is what xev says, when I press s-n (as xev spawn an X-window/EXWM buffer, the hotkeys don't work there either):

KeyPress event, serial 35, synthetic NO, window 0x1800001,
root 0x1a2, subw 0x0, time 1949214, (1913,1008), root:(1913,1008),
state 0x0, keycode 133 (keysym 0xffeb, Super_L), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False

KeyPress event, serial 35, synthetic NO, window 0x1800001,
root 0x1a2, subw 0x0, time 1949496, (1913,1008), root:(1913,1008),
state 0x40, keycode 44 (keysym 0x6e, n), same_screen YES,
XLookupString gives 1 bytes: (6e) "n"
XmbLookupString gives 1 bytes: (6e) "n"
XFilterEvent returns: False

KeyRelease event, serial 35, synthetic NO, window 0x1800001,
root 0x1a2, subw 0x0, time 1949602, (1913,1008), root:(1913,1008),
state 0x40, keycode 44 (keysym 0x6e, n), same_screen YES,
XLookupString gives 1 bytes: (6e) "n"
XFilterEvent returns: False

KeyRelease event, serial 35, synthetic NO, window 0x1800001,
root 0x1a2, subw 0x0, time 1949722, (1913,1008), root:(1913,1008),
state 0x40, keycode 133 (keysym 0xffeb, Super_L), same_screen YES,
XLookupString gives 0 bytes:
XFilterEvent returns: False

Is there anything else I could try to debug this?

My issue seems to be related to
#795
and
#820

timor commented

Could you provide a bit more detail for the steps to reproduce this?

Hey @timor, thanks for responding. I was hoping to have done an obvious mistake with a simple solution, but doesn't seem to be the case..

I use Spacemacs with EXWM on NixOS.

I just noticed that the issue (described in the first post) only starts to appear after my first interaction with any X-window. So here an example action-flow:

  • I start my desktop-manager (exwm) and emacs starts up as expected. With this, a couple of things happen
    • spacemacs loads all layers/packages
    • my init.el runs, which dfines s-n and s-r via exwm-set-input-key
      • a GUI application is started (autostart script)
  • My keybindings all work as expected (e.g. I can switch between the created workspaces using s-n and s-r)
  • Now I press a key on the workspace with my autostarted GUI application and the key is recognized by the GUI application (e.g. arrow down for scrolling the page), then the behavior, as described in the first post, kicks in (irreversibly).
    • To be specific, the s-n does not work anymore and the GUI application acts like I would have pressed 'n' only
    • s-r works, and let's me to change to workspace 0. On that workspace, an ordinary emacs buffer is opened, so all hotkeys work.
  • If I manually bind new keys (exwm-set-input-key) after initialization, they are subject to the same erroneuos behavior

Of note, whether X buffers are in char-mode or line-mode does not make a difference (they are in line-mode by default)

timor commented

I am still not completely sure where in the flow s-n and s-r are bound. Specifically, what do you mean with "having been defined before?"

I updated my description above

timor commented

Does it work if you run (exwm-input--update-global-prefix-keys) after defining the bindings?

Cool, thank you so much @timor, that worked! Can you think of a reason, why most people don't have this issue? Calling (exwm-input--update-global-prefix-keys) doesn't seem to be a requirement for most (e.g. it's not documented int the GH wiki).

Also, the last thing not working are a couple of notebook-hotkeys (like volume up/down, brightness control etc.). These do work in emacs buffer but still not in X windows (presumably because they were not defined using exwm-input-set-key).
Do you have a suggestion how to best fix this? (just redefine all of them using exwm-input-set-key?)

This might also work for you @holtzermann17

timor commented

That's probably not really the solution though, to be honest :). If you check the docstring of exwm-input-set-key:

Set a global key binding.

The new key binding only takes effect in real time when this command is
called interactively, and is lost when this session ends unless it’s
specifically saved in the Customize interface for ‘exwm-input-global-keys’.

In configuration you should customize or set ‘exwm-input-global-keys’
instead.

exwm-input-set-key calls exwm-input--global-prefix-keys iff it is invoked interactively.

Depending on your setup, Spacemacs and Customize don't play well together.

The way I solved it was by introducing a private Spacemacs layer, which defines post-init-exwm. You can use exwm-input-set-key there, because it runs in the same scope as init-exwm (but after that) from the EXWM layer, i.e. before exwm-input--post-init is run (which calls exwm-input--update-global-prefix-keys the first time).

timor commented

Also, the last thing not working are a couple of notebook-hotkeys (like volume up/down, brightness control etc.). These do work in emacs buffer but still not in X windows (presumably because they were not defined using exwm-input-set-key).
Do you have a suggestion how to best fix this? (just redefine all of them using exwm-input-set-key?)

I am using desktop-environment, which has the relevant variable desktop-environment-update-exwm-global-keys. (See here how it is used)

Thank you for all the background info. That really helps!