re-indent src/config.c
This commit is contained in:
parent
ea842f9686
commit
f44d4ce4b3
124
src/config.c
124
src/config.c
|
@ -26,27 +26,27 @@ struct barconfig_head barconfigs = TAILQ_HEAD_INITIALIZER(barconfigs);
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void ungrab_all_keys(xcb_connection_t *conn) {
|
void ungrab_all_keys(xcb_connection_t *conn) {
|
||||||
DLOG("Ungrabbing all keys\n");
|
DLOG("Ungrabbing all keys\n");
|
||||||
xcb_ungrab_key(conn, XCB_GRAB_ANY, root, XCB_BUTTON_MASK_ANY);
|
xcb_ungrab_key(conn, XCB_GRAB_ANY, root, XCB_BUTTON_MASK_ANY);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void grab_keycode_for_binding(xcb_connection_t *conn, Binding *bind, uint32_t keycode) {
|
static void grab_keycode_for_binding(xcb_connection_t *conn, Binding *bind, uint32_t keycode) {
|
||||||
DLOG("Grabbing %d\n", keycode);
|
DLOG("Grabbing %d\n", keycode);
|
||||||
/* Grab the key in all combinations */
|
/* Grab the key in all combinations */
|
||||||
#define GRAB_KEY(modifier) \
|
#define GRAB_KEY(modifier) \
|
||||||
do { \
|
do { \
|
||||||
xcb_grab_key(conn, 0, root, modifier, keycode, \
|
xcb_grab_key(conn, 0, root, modifier, keycode, \
|
||||||
XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC); \
|
XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC); \
|
||||||
} while (0)
|
} while (0)
|
||||||
int mods = bind->mods;
|
int mods = bind->mods;
|
||||||
if ((bind->mods & BIND_MODE_SWITCH) != 0) {
|
if ((bind->mods & BIND_MODE_SWITCH) != 0) {
|
||||||
mods &= ~BIND_MODE_SWITCH;
|
mods &= ~BIND_MODE_SWITCH;
|
||||||
if (mods == 0)
|
if (mods == 0)
|
||||||
mods = XCB_MOD_MASK_ANY;
|
mods = XCB_MOD_MASK_ANY;
|
||||||
}
|
}
|
||||||
GRAB_KEY(mods);
|
GRAB_KEY(mods);
|
||||||
GRAB_KEY(mods | xcb_numlock_mask);
|
GRAB_KEY(mods | xcb_numlock_mask);
|
||||||
GRAB_KEY(mods | xcb_numlock_mask | XCB_MOD_MASK_LOCK);
|
GRAB_KEY(mods | xcb_numlock_mask | XCB_MOD_MASK_LOCK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -55,28 +55,28 @@ static void grab_keycode_for_binding(xcb_connection_t *conn, Binding *bind, uint
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Binding *get_binding(uint16_t modifiers, xcb_keycode_t keycode) {
|
Binding *get_binding(uint16_t modifiers, xcb_keycode_t keycode) {
|
||||||
Binding *bind;
|
Binding *bind;
|
||||||
|
|
||||||
TAILQ_FOREACH(bind, bindings, bindings) {
|
TAILQ_FOREACH(bind, bindings, bindings) {
|
||||||
/* First compare the modifiers */
|
/* First compare the modifiers */
|
||||||
if (bind->mods != modifiers)
|
if (bind->mods != modifiers)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* If a symbol was specified by the user, we need to look in
|
/* If a symbol was specified by the user, we need to look in
|
||||||
* the array of translated keycodes for the event’s keycode */
|
* the array of translated keycodes for the event’s keycode */
|
||||||
if (bind->symbol != NULL) {
|
if (bind->symbol != NULL) {
|
||||||
if (memmem(bind->translated_to,
|
if (memmem(bind->translated_to,
|
||||||
bind->number_keycodes * sizeof(xcb_keycode_t),
|
bind->number_keycodes * sizeof(xcb_keycode_t),
|
||||||
&keycode, sizeof(xcb_keycode_t)) != NULL)
|
&keycode, sizeof(xcb_keycode_t)) != NULL)
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
/* This case is easier: The user specified a keycode */
|
/* This case is easier: The user specified a keycode */
|
||||||
if (bind->keycode == keycode)
|
if (bind->keycode == keycode)
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (bind == TAILQ_END(bindings) ? NULL : bind);
|
return (bind == TAILQ_END(bindings) ? NULL : bind);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -133,22 +133,22 @@ void translate_keysyms(void) {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void grab_all_keys(xcb_connection_t *conn, bool bind_mode_switch) {
|
void grab_all_keys(xcb_connection_t *conn, bool bind_mode_switch) {
|
||||||
Binding *bind;
|
Binding *bind;
|
||||||
TAILQ_FOREACH(bind, bindings, bindings) {
|
TAILQ_FOREACH(bind, bindings, bindings) {
|
||||||
if ((bind_mode_switch && (bind->mods & BIND_MODE_SWITCH) == 0) ||
|
if ((bind_mode_switch && (bind->mods & BIND_MODE_SWITCH) == 0) ||
|
||||||
(!bind_mode_switch && (bind->mods & BIND_MODE_SWITCH) != 0))
|
(!bind_mode_switch && (bind->mods & BIND_MODE_SWITCH) != 0))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* The easy case: the user specified a keycode directly. */
|
/* The easy case: the user specified a keycode directly. */
|
||||||
if (bind->keycode > 0) {
|
if (bind->keycode > 0) {
|
||||||
grab_keycode_for_binding(conn, bind, bind->keycode);
|
grab_keycode_for_binding(conn, bind, bind->keycode);
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
xcb_keycode_t *walk = bind->translated_to;
|
|
||||||
for (int i = 0; i < bind->number_keycodes; i++)
|
|
||||||
grab_keycode_for_binding(conn, bind, *walk++);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xcb_keycode_t *walk = bind->translated_to;
|
||||||
|
for (int i = 0; i < bind->number_keycodes; i++)
|
||||||
|
grab_keycode_for_binding(conn, bind, *walk++);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -156,22 +156,22 @@ void grab_all_keys(xcb_connection_t *conn, bool bind_mode_switch) {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void switch_mode(const char *new_mode) {
|
void switch_mode(const char *new_mode) {
|
||||||
struct Mode *mode;
|
struct Mode *mode;
|
||||||
|
|
||||||
LOG("Switching to mode %s\n", new_mode);
|
LOG("Switching to mode %s\n", new_mode);
|
||||||
|
|
||||||
SLIST_FOREACH(mode, &modes, modes) {
|
SLIST_FOREACH(mode, &modes, modes) {
|
||||||
if (strcasecmp(mode->name, new_mode) != 0)
|
if (strcasecmp(mode->name, new_mode) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ungrab_all_keys(conn);
|
ungrab_all_keys(conn);
|
||||||
bindings = mode->bindings;
|
bindings = mode->bindings;
|
||||||
translate_keysyms();
|
translate_keysyms();
|
||||||
grab_all_keys(conn, false);
|
grab_all_keys(conn, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ELOG("ERROR: Mode not found\n");
|
ELOG("ERROR: Mode not found\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue