*/
#include "all.h"
+#include <xkbcommon/xkbcommon.h>
+
pid_t command_error_nagbar_pid = -1;
/*
*
*/
Binding *configure_binding(const char *bindtype, const char *modifiers, const char *input_code,
- const char *release, const char *command, const char *modename) {
+ const char *release, const char *command, const char *modename) {
Binding *new_binding = scalloc(sizeof(Binding));
DLOG("bindtype %s, modifiers %s, input code %s, release %s\n", bindtype, modifiers, input_code, release);
new_binding->release = (release != NULL ? B_UPON_KEYRELEASE : B_UPON_KEYPRESS);
if (strcmp(bindtype, "bindsym") == 0) {
new_binding->input_type = (strncasecmp(input_code, "button", (sizeof("button") - 1)) == 0
- ? B_MOUSE
- : B_KEYBOARD);
+ ? B_MOUSE
+ : B_KEYBOARD);
new_binding->symbol = sstrdup(input_code);
} else {
return;
DLOG("Grabbing %d with modifiers %d (with mod_mask_lock %d)\n", keycode, bind->mods, bind->mods | XCB_MOD_MASK_LOCK);
- /* Grab the key in all combinations */
- #define GRAB_KEY(modifier) \
- do { \
- xcb_grab_key(conn, 0, root, modifier, keycode, \
- XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC); \
- } while (0)
+/* Grab the key in all combinations */
+#define GRAB_KEY(modifier) \
+ do { \
+ xcb_grab_key(conn, 0, root, modifier, keycode, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC); \
+ } while (0)
int mods = bind->mods;
if ((bind->mods & BIND_MODE_SWITCH) != 0) {
mods &= ~BIND_MODE_SWITCH;
GRAB_KEY(mods | xcb_numlock_mask | XCB_MOD_MASK_LOCK);
}
-
/*
* Grab the bound keys (tell X to send us keypress events for those keycodes)
*
Binding *bind;
TAILQ_FOREACH(bind, bindings, bindings) {
if (bind->input_type != B_KEYBOARD ||
- (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) ||
+ (!bind_mode_switch && (bind->mods & BIND_MODE_SWITCH) != 0))
continue;
/* The easy case: the user specified a keycode directly. */
*
*/
Binding *get_binding_from_xcb_event(xcb_generic_event_t *event) {
- bool is_release = (event->response_type == XCB_KEY_RELEASE
- || event->response_type == XCB_BUTTON_RELEASE);
+ bool is_release = (event->response_type == XCB_KEY_RELEASE || event->response_type == XCB_BUTTON_RELEASE);
- input_type_t input_type = ((event->response_type == XCB_BUTTON_RELEASE
- || event->response_type == XCB_BUTTON_PRESS)
- ? B_MOUSE
- : B_KEYBOARD);
+ input_type_t input_type = ((event->response_type == XCB_BUTTON_RELEASE || event->response_type == XCB_BUTTON_PRESS)
+ ? B_MOUSE
+ : B_KEYBOARD);
uint16_t event_state = ((xcb_key_press_event_t *)event)->state;
uint16_t event_detail = ((xcb_key_press_event_t *)event)->detail;
continue;
/* We need to translate the symbol to a keycode */
- keysym = XStringToKeysym(bind->symbol);
- if (keysym == NoSymbol) {
+ keysym = xkb_keysym_from_name(bind->symbol, XKB_KEYSYM_NO_FLAGS);
+ if (keysym == XKB_KEY_NoSymbol) {
ELOG("Could not translate string to key symbol: \"%s\"\n",
bind->symbol);
continue;
for (i = min_keycode; i && i <= max_keycode; i++) {
if ((xcb_key_symbols_get_keysym(keysyms, i, col) != keysym) &&
- (xcb_key_symbols_get_keysym(keysyms, i, col+1) != keysym))
+ (xcb_key_symbols_get_keysym(keysyms, i, col + 1) != keysym))
continue;
bind->number_keycodes++;
bind->translated_to = srealloc(bind->translated_to,
(sizeof(xcb_keycode_t) *
bind->number_keycodes));
- bind->translated_to[bind->number_keycodes-1] = i;
+ bind->translated_to[bind->number_keycodes - 1] = i;
}
DLOG("Translated symbol \"%s\" to %d keycode\n", bind->symbol,
}
/*
- * Runs the given binding and handles parse errors. Returns a CommandResult for
- * running the binding's command. Caller should render tree if
- * needs_tree_render is true. Free with command_result_free().
+ * Runs the given binding and handles parse errors. If con is passed, it will
+ * execute the command binding with that container selected by criteria.
+ * Returns a CommandResult for running the binding's command. Caller should
+ * render tree if needs_tree_render is true. Free with command_result_free().
*
*/
-CommandResult *run_binding(Binding *bind) {
+CommandResult *run_binding(Binding *bind, Con *con) {
+ char *command;
+
/* We need to copy the command since “reload” may be part of the command,
* and then the memory that bind->command points to may not contain the
* same data anymore. */
- char *command_copy = sstrdup(bind->command);
- CommandResult *result = parse_command(command_copy, NULL);
- free(command_copy);
+ if (con == NULL)
+ command = sstrdup(bind->command);
+ else
+ sasprintf(&command, "[con_id=\"%d\"] %s", con, bind->command);
+
+ CommandResult *result = parse_command(command, NULL);
+ free(command);
if (result->needs_tree_render)
tree_render();
"-b",
"show errors",
pageraction,
- NULL
- };
+ NULL};
start_nagbar(&command_error_nagbar_pid, argv);
free(pageraction);
}