From fe6b3b74748c711be27459ad61dfe6f1909b4af2 Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Mon, 16 Apr 2018 21:10:10 +0300 Subject: [PATCH] i3bar: make modifier behave like floating_modifier Pressed modifiers are determined like in click.c:handle_button_press. Fixes #3234. --- i3bar/include/configuration.h | 2 +- i3bar/src/config.c | 7 +++++ i3bar/src/xcb.c | 50 ++++++----------------------------- include/config_directives.h | 2 +- include/configuration.h | 11 +------- parser-specs/config.spec | 10 +++++-- src/config_directives.c | 23 +++------------- src/ipc.c | 27 +------------------ 8 files changed, 30 insertions(+), 102 deletions(-) diff --git a/i3bar/include/configuration.h b/i3bar/include/configuration.h index 27fb518f..b86da2e0 100644 --- a/i3bar/include/configuration.h +++ b/i3bar/include/configuration.h @@ -41,7 +41,7 @@ typedef struct tray_output_t { } tray_output_t; typedef struct config_t { - int modifier; + uint32_t modifier; TAILQ_HEAD(bindings_head, binding_t) bindings; diff --git a/i3bar/src/config.c b/i3bar/src/config.c index 59a44aee..5e57e6d9 100644 --- a/i3bar/src/config.c +++ b/i3bar/src/config.c @@ -119,6 +119,7 @@ static int config_string_cb(void *params_, const unsigned char *val, size_t _len return 1; } + /* Kept for backwards compatibility. */ if (!strcmp(cur_key, "modifier")) { DLOG("modifier = %.*s\n", len, val); if (len == strlen("none") && !strncmp((const char *)val, "none", strlen("none"))) { @@ -336,6 +337,12 @@ static int config_integer_cb(void *params_, long long val) { return 1; } + if (!strcmp(cur_key, "modifier")) { + DLOG("modifier = %lld\n", val); + config.modifier = (uint32_t)val; + return 1; + } + return 0; } diff --git a/i3bar/src/xcb.c b/i3bar/src/xcb.c index 8843edbd..7bfeb12e 100644 --- a/i3bar/src/xcb.c +++ b/i3bar/src/xcb.c @@ -79,7 +79,7 @@ int bar_height; /* These are only relevant for XKB, which we only need for grabbing modifiers */ int xkb_base; -int mod_pressed = 0; +bool mod_pressed = 0; /* Event watchers, to interact with the user */ ev_prepare *xcb_prep; @@ -1108,49 +1108,15 @@ void xcb_prep_cb(struct ev_loop *loop, ev_prepare *watcher, int revents) { DLOG("received an xkb event\n"); xcb_xkb_state_notify_event_t *state = (xcb_xkb_state_notify_event_t *)event; + const uint32_t mod = (config.modifier & 0xFFFF); + mod_pressed = (mod != 0 && (state->mods & mod) == mod); if (state->xkbType == XCB_XKB_STATE_NOTIFY && config.modifier != XCB_NONE) { - int modstate = state->mods & config.modifier; - -#define DLOGMOD(modmask, status) \ - do { \ - switch (modmask) { \ - case ShiftMask: \ - DLOG("ShiftMask got " #status "!\n"); \ - break; \ - case ControlMask: \ - DLOG("ControlMask got " #status "!\n"); \ - break; \ - case Mod1Mask: \ - DLOG("Mod1Mask got " #status "!\n"); \ - break; \ - case Mod2Mask: \ - DLOG("Mod2Mask got " #status "!\n"); \ - break; \ - case Mod3Mask: \ - DLOG("Mod3Mask got " #status "!\n"); \ - break; \ - case Mod4Mask: \ - DLOG("Mod4Mask got " #status "!\n"); \ - break; \ - case Mod5Mask: \ - DLOG("Mod5Mask got " #status "!\n"); \ - break; \ - } \ - } while (0) - - if (modstate != mod_pressed) { - if (modstate == 0) { - DLOGMOD(config.modifier, released); - if (!activated_mode) - hide_bars(); - } else { - DLOGMOD(config.modifier, pressed); - activated_mode = false; - unhide_bars(); - } - mod_pressed = modstate; + if (mod_pressed) { + activated_mode = false; + unhide_bars(); + } else if (!activated_mode) { + hide_bars(); } -#undef DLOGMOD } free(event); diff --git a/include/config_directives.h b/include/config_directives.h index 852325ba..f21ad8e1 100644 --- a/include/config_directives.h +++ b/include/config_directives.h @@ -81,7 +81,7 @@ CFGFUN(bar_hidden_state, const char *hidden_state); CFGFUN(bar_id, const char *bar_id); CFGFUN(bar_output, const char *output); CFGFUN(bar_verbose, const char *verbose); -CFGFUN(bar_modifier, const char *modifier); +CFGFUN(bar_modifier, const char *modifiers); CFGFUN(bar_wheel_up_cmd, const char *command); CFGFUN(bar_wheel_down_cmd, const char *command); CFGFUN(bar_bindsym, const char *button, const char *release, const char *command); diff --git a/include/configuration.h b/include/configuration.h index 87897aaf..3eccca4c 100644 --- a/include/configuration.h +++ b/include/configuration.h @@ -289,16 +289,7 @@ struct Barconfig { S_SHOW = 1 } hidden_state; /** Bar modifier (to show bar when in hide mode). */ - enum { - M_NONE = 0, - M_CONTROL = 1, - M_SHIFT = 2, - M_MOD1 = 3, - M_MOD2 = 4, - M_MOD3 = 5, - M_MOD4 = 6, - M_MOD5 = 7 - } modifier; + uint32_t modifier; TAILQ_HEAD(bar_bindings_head, Barbinding) bar_bindings; diff --git a/parser-specs/config.spec b/parser-specs/config.spec index 9cbc782b..c5c4651c 100644 --- a/parser-specs/config.spec +++ b/parser-specs/config.spec @@ -491,8 +491,14 @@ state BAR_ID: -> call cfg_bar_id($bar_id); BAR state BAR_MODIFIER: - modifier = 'Mod1', 'Mod2', 'Mod3', 'Mod4', 'Mod5', 'Control', 'Ctrl', 'Shift', 'none', 'off' - -> call cfg_bar_modifier($modifier); BAR + 'off', 'none' + -> call cfg_bar_modifier(NULL); BAR + modifiers = 'Mod1', 'Mod2', 'Mod3', 'Mod4', 'Mod5', 'Shift', 'Control', 'Ctrl' + -> + '+' + -> + end + -> call cfg_bar_modifier($modifiers); BAR state BAR_WHEEL_UP_CMD: command = string diff --git a/src/config_directives.c b/src/config_directives.c index 491c840a..4a31f79e 100644 --- a/src/config_directives.c +++ b/src/config_directives.c @@ -479,25 +479,8 @@ CFGFUN(bar_verbose, const char *verbose) { current_bar->verbose = eval_boolstr(verbose); } -CFGFUN(bar_modifier, const char *modifier) { - if (strcmp(modifier, "Mod1") == 0) - current_bar->modifier = M_MOD1; - else if (strcmp(modifier, "Mod2") == 0) - current_bar->modifier = M_MOD2; - else if (strcmp(modifier, "Mod3") == 0) - current_bar->modifier = M_MOD3; - else if (strcmp(modifier, "Mod4") == 0) - current_bar->modifier = M_MOD4; - else if (strcmp(modifier, "Mod5") == 0) - current_bar->modifier = M_MOD5; - else if (strcmp(modifier, "Control") == 0 || - strcmp(modifier, "Ctrl") == 0) - current_bar->modifier = M_CONTROL; - else if (strcmp(modifier, "Shift") == 0) - current_bar->modifier = M_SHIFT; - else if (strcmp(modifier, "none") == 0 || - strcmp(modifier, "off") == 0) - current_bar->modifier = M_NONE; +CFGFUN(bar_modifier, const char *modifiers) { + current_bar->modifier = modifiers ? event_state_from_str(modifiers) : XCB_NONE; } static void bar_configure_binding(const char *button, const char *release, const char *command) { @@ -633,7 +616,7 @@ CFGFUN(bar_start) { TAILQ_INIT(&(current_bar->bar_bindings)); TAILQ_INIT(&(current_bar->tray_outputs)); current_bar->tray_padding = 2; - current_bar->modifier = M_MOD4; + current_bar->modifier = XCB_KEY_BUT_MASK_MOD_4; } CFGFUN(bar_finish) { diff --git a/src/ipc.c b/src/ipc.c index 25da1617..eebb576e 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -656,32 +656,7 @@ static void dump_bar_config(yajl_gen gen, Barconfig *config) { } ystr("modifier"); - switch (config->modifier) { - case M_NONE: - ystr("none"); - break; - case M_CONTROL: - ystr("ctrl"); - break; - case M_SHIFT: - ystr("shift"); - break; - case M_MOD1: - ystr("Mod1"); - break; - case M_MOD2: - ystr("Mod2"); - break; - case M_MOD3: - ystr("Mod3"); - break; - case M_MOD5: - ystr("Mod5"); - break; - default: - ystr("Mod4"); - break; - } + y(integer, config->modifier); dump_bar_bindings(gen, config);