Merge pull request #3246 from orestisf1993/bar-modifier-3234

i3bar: make modifier behave like floating_modifier
This commit is contained in:
Ingo Bürk
2018-04-17 13:13:18 +02:00
committed by GitHub
8 changed files with 30 additions and 102 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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);