Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--pass-media-keys, --pass-screen-keys and --pass-power-keys options do not work in DEs #136

Closed
AladW opened this issue Sep 26, 2019 · 32 comments · Fixed by #231 or #256
Closed

--pass-media-keys, --pass-screen-keys and --pass-power-keys options do not work in DEs #136

AladW opened this issue Sep 26, 2019 · 32 comments · Fixed by #231 or #256

Comments

@AladW
Copy link

AladW commented Sep 26, 2019

This issue is a....

[X] Bug
[ ] Other kind of issue (Please describe in detail)

Current Behavior

In XFCE, using i3lock --pass-media-keys does not pass the media keys to the desktop environment. This happens regardless if the XF86 keys are bound in xfce4-settings, or through an external application such as volumeicon. I'm unsure why this happens, as --pass-media-keys works as expected in i3.

Expected Behavior

--pass-media-keys should pass the media keys to the underlying environment, regardless of the used window manager.

Reproduction Instructions

Install XFCE (pacman -S xfce4), bind XF86AudioMute either in keyboard settings or a program like volumeicon, try to mute when the screen is locked with i3lock --pass-media-keys.

Environment

Output of i3lock --version:

i3lock: version aur-2fd6547 (2019-09-20, branch "tags/aur-2fd6547") © 2010 Michael Stapelberg, © 2015 Cassandra Fox

Where'd you get i3lock-color from?

[X] AUR package (which one?)
`i3lock-color-git`
[ ] Built from source yourself
[ ] Other (Please describe in detail)
@PandorasFox
Copy link

PandorasFox commented Sep 27, 2019

Weird. Probably related to #131.

e: wait, it works when run over i3 but not when over xfce?

@AladW
Copy link
Author

AladW commented Sep 28, 2019

e: wait, it works when run over i3 but not when over xfce?

Yes, I never had any issues in i3. Can't say why, though. :/

@PandorasFox
Copy link

Huh, weird. Hopefully I can repro.

@AlonTzarafi
Copy link

I use OpenBox(with volumeicon) and also tried it on KDE-Plasma(with its own volume control) and on both of them the --pass-media-keys doesn't pass the media keys. Tried AUR i3lock-color-git and it still doesn't work

@darkelectron
Copy link

Also in bspwm. It was working on i3.

@Raymo111 Raymo111 changed the title media keys not passed through wtih --pass-media-keys (XFCE) media keys not passed through with --pass-media-keys (XFCE) Mar 8, 2020
@Raymo111
Copy link
Owner

Raymo111 commented Mar 8, 2020

@AladW Is this still an issue for you? I think I'm getting the same issue as well.

@Raymo111 Raymo111 changed the title media keys not passed through with --pass-media-keys (XFCE) --pass-media-keys and --pass-power-keys do not work in DEs Mar 12, 2020
@Raymo111 Raymo111 changed the title --pass-media-keys and --pass-power-keys do not work in DEs --pass-media-keys, --pass-screen-keys and --pass-power-keys options do not work in DEs Mar 12, 2020
@Raymo111
Copy link
Owner

So I've just tested GNOME, Plasma and XFCE. Seems like these options don't work at all. @PandorasFox Did you make the original pass-media-keys option? How exactly does

xcb_send_event(conn, true, screen->root, XCB_EVENT_MASK_BUTTON_PRESS, (char *)event);

work?

@PandorasFox
Copy link

iirc what that bit of code does is, if the flag is specified, it just passes back the specified keypress to the root window (essentially the window manager?). I'm not really sure what would need to be different for different DEs to work.

@Raymo111
Copy link
Owner

@PandorasFox Interesting, thanks.

@subnut
Copy link

subnut commented Jul 1, 2020

I am in bspwm, and the keys are bound to sxhkd. Can confirm the same issue. 😭
But guys, this is like 9 months old. Any updates? This is like a deal-breaker to me. Really.
Please please please do something about it.

@Raymo111
Copy link
Owner

Raymo111 commented Jul 1, 2020

@subnut yeah, unfortunately, I've investigated far and wide, but I have no idea even which window in Plasma/KDE handles these events (for i3 it's simply root window), much less for all DEs. I need serious help on this one.

@moritzhoewer
Copy link

I just switched to i3lock-color for the --pass-media-keys as well, and it's not working for me either. Weird thing is, I am in fact using i3 as a WM.

I am not at all familiar with X11 / linux kernel Keyboard handling, but I noticed that if i run i3lock --pass-media-keys && xev, then I don't get KeyPress events, but instead I get KeymapNotify events for the media keys. If I run i3lock --pass-media-keys && sudo showkey I see all key presses (the ones for the password as well).

The reason I am posting this here is that it could maybe be related to the problems mentioned above.

I hope I can find time in the next days to investigate this further - if I find out anything usefull, I will post it here

@moritzhoewer
Copy link

moritzhoewer commented Aug 3, 2020

I finally found some time to look into this some more. The problem seems to be that allthough I am using i3 as a window manager, I was using xbindkeys to handle volume control. I tried switching that over to i3 directly and now it works. So it seems that only i3 itself can receive key presses through the lock screen, and not any other program.

This only partially solves the issue for me though, since I would still like to pass the actual key presses for Play/Pause/Next/Previous to chromium.

Or to be more general...it would be great if --pass-media-keys and the related option could pass the keys to ANY program and not just the window manager, or is that deliberately not intended?

EDIT: If I understand this (https://www.x.org/releases/current/doc/man/man3/xcb_send_event.3.xhtml) documentation correctly, the propagate flag in xcb_send_event only allows the events to propagate up the hierarchy (at least that's how I understand anchestor). Since we are already sending to the root window here, propagate might as well be off. Only the root window actually sees the key anyway. I tried to find a way to do something like an "inverted" propagation (where the event would be propagated to the children and not the parents), but without success so far...

@Raymo111
Copy link
Owner

Raymo111 commented Aug 3, 2020

@moritzhoewer those keys already work in wms like i3 and dwm, that use the root window to control these functions. That's why the keys are passed to the root window. However, when using DEs, it's not the root window that parses these keys, and so it doesn't work; you have to send the keys to some window.

@moritzhoewer
Copy link

I see - and since i3lock has grabbed the entire keyboard, there is no way to just pass the key press through and let whoever would normally have handled that particular key handle it.

That is unfortunate...but I haven't found anything yet that would allow for what I am aiming at here, because that is probably not a use-case the X keyboard system was designed for.

@Rio6
Copy link
Collaborator

Rio6 commented Jan 26, 2021

if --pass-media-keys and the related option could pass the keys to ANY program and not just the window manager

What if we add a param to pass in a window id to pass event to? Then one can use command like xdotool to grab the window id of whoever manages keybind and pass that in.

I don't use a DE though, so not sure how easy it is to get the target window there.

@Raymo111
Copy link
Owner

Raymo111 commented Jan 26, 2021

@Rio6 great suggestion. However, I couldn't find ANY documentation on which KDE (what I use, as an example) window even handles these things. I have a nasty feeling that even if I could find which window I wouldn't be able to use it statically (i.e. window id might change each startx and window might have no name)

@Rio6
Copy link
Collaborator

Rio6 commented Jan 26, 2021

window id is definitely changing, but I'm hoping any of the window class, name, process name might stay the same. This will need some testing on different environments to know if it's actually viable tho.

Hopefully something like this can work.

i3lock --event-window-id $(xdotool search --class some-class-name)

@jclds139
Copy link

If I could make an alternative suggestion,
since the media keys passing doesn't work on other DEs, why not provide an option for setting up custom shortcuts instead? That way you can configure i3lock-color to, for example, send an MPRIS command with dbus-send when it gets an XF86AudioPlay event, or something like that. That seems more flexible, reliable, and secure than sending keystrokes back to the root window that could trigger anything (including, for example, killing i3lock or the X server).

All it needs to function is a syntax for mapping keysyms to commands, like

i3lock --shortcut XF86AudioRaiseVolume "pactl set-sink-volume @DEFAULT_SINK@ +5%"

Thoughts?

@Raymo111
Copy link
Owner

@jclds139 I feel like that would introduce unnecessary security risks (arbitrary command execution isn't really the best idea...)

@Rio6
Copy link
Collaborator

Rio6 commented Feb 24, 2021

I personally don't like to maintain multiple copies of what each key does what :P, although I agree passing things to root window might not be the best solution (that's what this whole issue is about).

Running arbitary commands might not be that bad, considering whoevers running the i3lock command can also run whatever commands separately too (unless someone decides to suid i3lock binary...). But I don't think it's safer than sending events to root window anyways.

@jclds139
Copy link

My thought was it's slightly safer since the root window could do exactly the same thing, but in this case the i3lock binary controls what commands are run, as opposed to the root window that's out of the locker's control. I can see both sides to the argument, though.

@Raymo111
Copy link
Owner

Hmm you guys have fair points. This is starting to look like the best way to handle it.

Reference for KDE volume control: https://askubuntu.com/questions/422078/how-do-i-control-the-volume-in-kde-from-the-command-line

@JezerM
Copy link

JezerM commented Mar 31, 2021

I have the same problem with qtile.
Looking for some solutions, I guess xdotool would be great. If i3lock detects either "special" key, just run xdotool key {key}
xdotool key XF86MonBrightnessDown for example.

@Raymo111
Copy link
Owner

Will xdotool work though? Won't it get intercepted by the lockscreen and infinite loop?

@jclds139
Copy link

jclds139 commented Mar 31, 2021 via email

@JezerM
Copy link

JezerM commented Mar 31, 2021

That's what I don't know. In manpage, if no window parameter is set, it will use the "window stack" (if it exists) and send it to first window %1. Though, it's probably that it would be catched by i3lock.

@jclds139
Copy link

jclds139 commented Mar 31, 2021 via email

@Raymo111
Copy link
Owner

Yeah I think the commands are the way to go.

@JezerM
Copy link

JezerM commented Jul 10, 2021

I guess I've solved this.

When trying on Python, send_event methods didn't work, but fake_input did, so I replaced xcb_send_event with xcb_test_fake_input. The problem is that i3lock is "locking" the root keyboard, so this would create and endless loop, as @Raymo111 commented about xdotool.

Then, ungrab the keyboard, send the event to root, and grab the keyboard again was the solution.

I'm using Awesome WM, and this works to me.

@JezerM
Copy link

JezerM commented Jul 10, 2021

I tested it on Ubuntu... doesn't work... Seems like the volume and brightness UI breaks it.

Edit: Setting focus to i3lock after sending the key solves it.

Raymo111 added a commit that referenced this issue Aug 9, 2021
Raymo111 added a commit that referenced this issue Feb 4, 2022
@Raymo111
Copy link
Owner

Raymo111 commented Feb 4, 2022

Reopening because of #252 and #253.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
10 participants