添加快捷键设置
This commit is contained in:
@@ -297,3 +297,28 @@ void clean_xcb(void) {
|
||||
conn = NULL;
|
||||
screen = NULL;
|
||||
}
|
||||
|
||||
void grab_keybindings(const keybinding_t *keys, const size_t length) {
|
||||
xcb_window_t root = screen->root;
|
||||
xcb_keycode_t key = XCB_GRAB_ANY;
|
||||
xcb_ungrab_key(conn, key, root, XCB_MOD_MASK_ANY);
|
||||
key_symbols = xcb_key_symbols_alloc(conn);
|
||||
|
||||
xcb_grab_mode_t mode = XCB_GRAB_MODE_ASYNC;
|
||||
xcb_keycode_t *keycode = NULL;
|
||||
xcb_mod_mask_t modifiers;
|
||||
xcb_void_cookie_t cookie;
|
||||
xcb_generic_error_t *error = NULL;
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
xcb_keysym_t keysym = keys[i].key_symbol;
|
||||
keycode = xcb_key_symbols_get_keycode(key_symbols, keysym);
|
||||
modifiers = keys[i].modifiers;
|
||||
cookie = xcb_grab_key(conn, key, root, modifiers, *keycode, mode, mode);
|
||||
error = xcb_request_check(conn, cookie);
|
||||
if (error) {
|
||||
clean_xcb();
|
||||
die("%scannot grap key", APP_NAME);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user