-
-
Notifications
You must be signed in to change notification settings - Fork 137
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-*-keys options (#136) #231
Conversation
What happens if someone spams multiple other keys at the same time? Does ungrabbing the keyboard let those keys go through as well? |
I guess you would need to be really fast to do that, even when pressing them at the same time. I tested it right now and nothing happened, except that spamming slowed down my PC. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not send the keys while the keyboard is grabbed? (i.e. don't ungrab and regrab so we eliminate the chance of any security issue?
No, I think it's not possible. I tried grabbing every key with
And, yeah, it could be a possible security issue, but as I said before, you would need to be faster than the process of ungrabbing, sending, and grabbing, to send any unexpected key to the root window. (even faster than pressing two keys at the same time) |
@JezerM grab_keyboard is fine, what I meant is can we not send the keys using xtest while the keyboard is grabbed? I'm just worried about something like plugging in a runberducky-type device, using media keys to ungrab the keyboard for a split second, and then doing bad things like opening a terminal and killing the lockscreen for example. If we can't send the keys while the keyboard is grabbed, we should leave the existing pass-*-keys as-is and make new "unsafe" versions of the args. |
Sending a key to the root while i3lock is grabbing the root keyboard just makes a infinite loop. So, sadly, it's not possible. |
I've tested some things, with a Python script that tries to grab the keyboard and stops when it is grabbed: from time import sleep
from ewmh import EWMH
from Xlib.ext import xtest
from Xlib.X import GrabModeSync
ewmh = EWMH()
display = ewmh.display
root = display.screen().root
while (root.grab_keyboard(display, False, False, GrabModeSync) == 1):
print("NOPE")
print("YES!")
sleep(2)
display.ungrab_keyboard(0)
display.flush() The same with a c script (if python's "slowness" is a problem): #include <stdbool.h>
#include <stdio.h>
#include <xcb/xcb.h>
#include <unistd.h>
#include <malloc.h>
xcb_connection_t *conn;
xcb_screen_t *screen;
const xcb_setup_t *setup;
xcb_grab_keyboard_cookie_t kcookie;
xcb_grab_keyboard_reply_t *kreply;
int main() {
int screenr;
int done = 0;
conn = xcb_connect(NULL, &screenr);
setup = xcb_get_setup(conn);
screen = xcb_setup_roots_iterator(setup).data;
while (done == 0) {
kcookie = xcb_grab_keyboard(conn, true, screen->root, XCB_CURRENT_TIME, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
if ((kreply = xcb_grab_keyboard_reply(conn, kcookie, NULL)) &&
kreply->status == XCB_GRAB_STATUS_SUCCESS) {
done = 1;
free(kreply);
break;
}
free(kreply);
printf("NOPE\n");
}
printf("YES!\n");
sleep(2);
xcb_ungrab_keyboard(conn, XCB_CURRENT_TIME);
xcb_disconnect(conn);
return 0;
} And then, run ./i3lock --pass-screen-keys --no-verify & \
sleep 2 && python3 ewmh-test.py Or, compile the c script with ./i3lock --pass-screen-keys --no-verify & \
sleep 2 && ./ewmh-test Whenever I press the screen keys, I also tried with a key emitter loop, but no key was received by the root window, except for those permitted and/or pressed (screen and media keys). |
Interesting. Now my only worry is, what happens if the regrab fails? |
I think that couldn't happen. As far as I've seen, |
There was a problem before when an action provoked by the key sets the focus to another window, which could make the regrab to "fail", but setting the focus to i3lock after sending the event solved it. |
Hmm okay. I'd like to keep the current approach to passing keys for WMs though (DEs can use the new function). How about we add a |
That's okay, though this is not a DE only problem, as it also affects some WM (AwesomeWM in my case), so I don't know if calling it |
Oh I see. Maybe like |
Hmm, I have no problem with that, |
Ok. Make sure to add that flag to the manpage as well as your tab completion PR. Also we should test this on all the major target environments just in case. I can handle KDE, XFCE, and i3, if you can take awesomeWM and GNOME? just to make sure pass keys now work on those (sanity check)? |
I tested it before in XFCE, KDE, AwesomeWM and Ubuntu, and I guess everything works well. |
Oh ok, sick. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Closes #136
Description
--pass-media-keys
,--pass-screen-keys
and--pass-power-keys
optionsxtest
library andxcb_test_fake_input
to send keys.Release notes
Notes: Solves
--pass-media-keys
,--pass-screen-keys
and--pass-power-keys
options