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-*-keys options (#136) #231

Merged
merged 8 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ The following dependencies will need to be installed for a successful build, dep
### Debian
Run this command to install all dependencies:
```
sudo apt install autoconf gcc make pkg-config libpam0g-dev libcairo2-dev libfontconfig1-dev libxcb-composite0-dev libev-dev libx11-xcb-dev libxcb-xkb-dev libxcb-xinerama0-dev libxcb-randr0-dev libxcb-image0-dev libxcb-util0-dev libxcb-xrm-dev libxkbcommon-dev libxkbcommon-x11-dev libjpeg-dev
sudo apt install autoconf gcc make pkg-config libpam0g-dev libcairo2-dev libfontconfig1-dev libxcb-composite0-dev libev-dev libx11-xcb-dev libxcb-xkb-dev libxcb-xinerama0-dev libxcb-randr0-dev libxcb-image0-dev libxcb-util0-dev libxcb-xrm-dev libxcb-xtest0-dev libxkbcommon-dev libxkbcommon-x11-dev libjpeg-dev
```
If you still see missing packages during build after installing all of these dependencies, try following the steps [here](https://github.com/Raymo111/i3lock-color/issues/211#issuecomment-809891727).

Expand All @@ -95,7 +95,7 @@ sudo dnf install -y autoconf automake cairo-devel fontconfig gcc libev-devel lib
### Ubuntu 18/20.04 LTS
Run this command to install all dependencies:
```
sudo apt install autoconf gcc make pkg-config libpam0g-dev libcairo2-dev libfontconfig1-dev libxcb-composite0-dev libev-dev libx11-xcb-dev libxcb-xkb-dev libxcb-xinerama0-dev libxcb-randr0-dev libxcb-image0-dev libxcb-util-dev libxcb-xrm-dev libxkbcommon-dev libxkbcommon-x11-dev libjpeg-dev
sudo apt install autoconf gcc make pkg-config libpam0g-dev libcairo2-dev libfontconfig1-dev libxcb-composite0-dev libev-dev libx11-xcb-dev libxcb-xkb-dev libxcb-xinerama0-dev libxcb-randr0-dev libxcb-image0-dev libxcb-util-dev libxcb-xrm-dev libxcb-xtest0-dev libxkbcommon-dev libxkbcommon-x11-dev libjpeg-dev
```

## Building i3lock-color
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ AC_SEARCH_LIBS([iconv_open], [iconv], , [AC_MSG_FAILURE([cannot find the require

dnl Each prefix corresponds to a source tarball which users might have
dnl downloaded in a newer version and would like to overwrite.
PKG_CHECK_MODULES([XCB], [xcb xcb-xkb xcb-xinerama xcb-randr xcb-composite])
PKG_CHECK_MODULES([XCB], [xcb xcb-xkb xcb-xinerama xcb-randr xcb-composite xcb-xtest])
PKG_CHECK_MODULES([XCB_IMAGE], [xcb-image])
PKG_CHECK_MODULES([XCB_UTIL], [xcb-event xcb-util xcb-atom])
PKG_CHECK_MODULES([XCB_UTIL_XRM], [xcb-xrm])
Expand Down
31 changes: 27 additions & 4 deletions i3lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
#endif
#include <xcb/xcb_aux.h>
#include <xcb/randr.h>
#include <xcb/xtest.h>
#include <time.h>

#include "i3lock.h"
#include "xcb.h"
Expand Down Expand Up @@ -650,6 +652,27 @@ static bool skip_without_validation(void) {
return false;
}

/*
* Sends key press event to root/wm
* Releases the keyboard, sends the event, and
* grabs the keyboard again
* */
static void send_key_to_root(xcb_key_press_event_t *event, bool twice) {
xcb_ungrab_keyboard(conn, XCB_CURRENT_TIME);
/*xcb_ungrab_key(conn, event->detail, screen->root, XCB_MOD_MASK_ANY);*/
DEBUG("Received: %d at %ld\n", event->detail, time(0));

xcb_test_fake_input(conn, XCB_KEY_PRESS, event->detail, XCB_CURRENT_TIME, screen->root, 0, 0, 0);
xcb_test_fake_input(conn, XCB_KEY_RELEASE, event->detail, XCB_CURRENT_TIME, screen->root, 0, 0, 0);

if (twice) {
xcb_test_fake_input(conn, XCB_KEY_PRESS, event->detail, XCB_CURRENT_TIME, screen->root, 0, 0, 0);
xcb_test_fake_input(conn, XCB_KEY_RELEASE, event->detail, XCB_CURRENT_TIME, screen->root, 0, 0, 0);
}

xcb_grab_keyboard(conn, true, screen->root, XCB_CURRENT_TIME, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
}

/*
* Handle key presses. Fixes state, then looks up the key symbol for the
* given keycode, then looks up the key symbol (as UCS-2), converts it to
Expand Down Expand Up @@ -709,7 +732,7 @@ static void handle_key_press(xcb_key_press_event_t *event) {
case XKB_KEY_XF86AudioMute:
case XKB_KEY_XF86AudioLowerVolume:
case XKB_KEY_XF86AudioRaiseVolume:
xcb_send_event(conn, true, screen->root, XCB_EVENT_MASK_BUTTON_PRESS, (char *)event);
send_key_to_root(event, true);
JezerM marked this conversation as resolved.
Show resolved Hide resolved
return;
}
}
Expand All @@ -719,7 +742,7 @@ static void handle_key_press(xcb_key_press_event_t *event) {
switch(ksym) {
case XKB_KEY_XF86MonBrightnessUp:
case XKB_KEY_XF86MonBrightnessDown:
xcb_send_event(conn, true, screen->root, XCB_EVENT_MASK_BUTTON_PRESS, (char *)event);
send_key_to_root(event, false);
return;
}
}
Expand All @@ -730,7 +753,7 @@ static void handle_key_press(xcb_key_press_event_t *event) {
case XKB_KEY_XF86PowerDown:
case XKB_KEY_XF86PowerOff:
case XKB_KEY_XF86Sleep:
xcb_send_event(conn, true, screen->root, XCB_EVENT_MASK_BUTTON_PRESS, (char *)event);
send_key_to_root(event, false);
return;
}
}
Expand All @@ -741,7 +764,7 @@ static void handle_key_press(xcb_key_press_event_t *event) {
case XKB_KEY_XF86AudioMute:
case XKB_KEY_XF86AudioLowerVolume:
case XKB_KEY_XF86AudioRaiseVolume:
xcb_send_event(conn, true, screen->root, XCB_EVENT_MASK_BUTTON_PRESS, (char *)event);
send_key_to_root(event, true);
return;
}
}
Expand Down