debian
docs
i3-config-wizard
i3-dump-log
i3-input
i3-msg
i3-nagbar
i3bar
include
libi3
Makefile
README
fake_configure_notify.c
font.c
get_colorpixel.c
get_mod_mask.c
get_socket_path.c
ipc_connect.c
ipc_recv_message.c
ipc_send_message.c
safewrappers.c
strndup.c
ucs2_conversion.c
man
render-tree
src
testcases
tests
yajl-fallback
.gitignore
DEPENDS
GOALS
LICENSE
Makefile
PACKAGE-MAINTAINER
RELEASE-NOTES-4.0
RELEASE-NOTES-4.0.1
RELEASE-NOTES-4.0.2
RELEASE-NOTES-4.1
common.mk
dump-asy.pl
gtk-tree-watch.pl
i3-migrate-config-to-v4
i3-sensible-editor
i3-sensible-pager
i3-sensible-terminal
i3-wsbar
i3.config
i3.config.keycodes
i3.desktop
i3.welcome
logo.svg
pseudo-doc.doxygen
79 lines
2.5 KiB
C
79 lines
2.5 KiB
C
/*
|
|
* vim:ts=4:sw=4:expandtab
|
|
*
|
|
* i3 - an improved dynamic tiling window manager
|
|
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
|
|
*
|
|
*/
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <xcb/xcb.h>
|
|
#include <xcb/xcb_keysyms.h>
|
|
|
|
#include "libi3.h"
|
|
|
|
extern xcb_connection_t *conn;
|
|
|
|
/*
|
|
* All-in-one function which returns the modifier mask (XCB_MOD_MASK_*) for the
|
|
* given keysymbol, for example for XCB_NUM_LOCK (usually configured to mod2).
|
|
*
|
|
* This function initiates one round-trip. Use get_mod_mask_for() directly if
|
|
* you already have the modifier mapping and key symbols.
|
|
*
|
|
*/
|
|
uint32_t aio_get_mod_mask_for(uint32_t keysym, xcb_key_symbols_t *symbols) {
|
|
xcb_get_modifier_mapping_cookie_t cookie;
|
|
xcb_get_modifier_mapping_reply_t *modmap_r;
|
|
|
|
xcb_flush(conn);
|
|
|
|
/* Get the current modifier mapping (this is blocking!) */
|
|
cookie = xcb_get_modifier_mapping(conn);
|
|
if (!(modmap_r = xcb_get_modifier_mapping_reply(conn, cookie, NULL)))
|
|
return 0;
|
|
|
|
uint32_t result = get_mod_mask_for(keysym, symbols, modmap_r);
|
|
free(modmap_r);
|
|
return result;
|
|
}
|
|
|
|
/*
|
|
* Returns the modifier mask (XCB_MOD_MASK_*) for the given keysymbol, for
|
|
* example for XCB_NUM_LOCK (usually configured to mod2).
|
|
*
|
|
* This function does not initiate any round-trips.
|
|
*
|
|
*/
|
|
uint32_t get_mod_mask_for(uint32_t keysym,
|
|
xcb_key_symbols_t *symbols,
|
|
xcb_get_modifier_mapping_reply_t *modmap_reply) {
|
|
xcb_keycode_t *codes, *modmap;
|
|
xcb_keycode_t mod_code;
|
|
|
|
modmap = xcb_get_modifier_mapping_keycodes(modmap_reply);
|
|
|
|
/* Get the list of keycodes for the given symbol */
|
|
if (!(codes = xcb_key_symbols_get_keycode(symbols, keysym)))
|
|
return 0;
|
|
|
|
/* Loop through all modifiers (Mod1-Mod5, Shift, Control, Lock) */
|
|
for (int mod = 0; mod < 8; mod++)
|
|
for (int j = 0; j < modmap_reply->keycodes_per_modifier; j++) {
|
|
/* Store the current keycode (for modifier 'mod') */
|
|
mod_code = modmap[(mod * modmap_reply->keycodes_per_modifier) + j];
|
|
/* Check if that keycode is in the list of previously resolved
|
|
* keycodes for our symbol. If so, return the modifier mask. */
|
|
for (xcb_keycode_t *code = codes; *code; code++) {
|
|
if (*code != mod_code)
|
|
continue;
|
|
|
|
free(codes);
|
|
/* This corresponds to the XCB_MOD_MASK_* constants */
|
|
return (1 << mod);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|