Merge pull request #3246 from orestisf1993/bar-modifier-3234
i3bar: make modifier behave like floating_modifier
This commit is contained in:
commit
3c66f615e2
|
@ -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;
|
||||
|
|
|
@ -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"))) {
|
||||
|
@ -338,6 +339,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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
if (mod_pressed) {
|
||||
activated_mode = false;
|
||||
unhide_bars();
|
||||
} else if (!activated_mode) {
|
||||
hide_bars();
|
||||
}
|
||||
mod_pressed = modstate;
|
||||
}
|
||||
#undef DLOGMOD
|
||||
}
|
||||
|
||||
free(event);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
27
src/ipc.c
27
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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue