aboutsummaryrefslogtreecommitdiff
path: root/sway/input
diff options
context:
space:
mode:
authorIan Fan <ianfan0@gmail.com>2018-10-12 21:14:52 +0100
committerIan Fan <ianfan0@gmail.com>2018-10-14 13:33:12 +0100
commit2f1fd8072673b1824f37759e14f5388d7a87fb5c (patch)
tree948b7912a2341c2d0b903258b444173b3fd4d1f3 /sway/input
parentbcc61e5147fb57a3b4bfb9a2a33065a0cf6da67b (diff)
downloadsway-2f1fd8072673b1824f37759e14f5388d7a87fb5c.tar.xz
swaybar: show hidden bar on key event
Since wayland does not currently allow swaybar to create global keybinds, this is handled within sway and sent to the bar using a custom event, so as not to pollute existing events, called bar_state_update.
Diffstat (limited to 'sway/input')
-rw-r--r--sway/input/keyboard.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c
index fb1fe7b5..2c8b41cd 100644
--- a/sway/input/keyboard.c
+++ b/sway/input/keyboard.c
@@ -9,6 +9,7 @@
#include "sway/input/input-manager.h"
#include "sway/input/keyboard.h"
#include "sway/input/seat.h"
+#include "sway/ipc-server.h"
#include "log.h"
/**
@@ -66,10 +67,10 @@ static void update_shortcut_state(struct sway_shortcut_state *state,
bool last_key_was_a_modifier = raw_modifiers != state->last_raw_modifiers;
state->last_raw_modifiers = raw_modifiers;
- if (last_key_was_a_modifier && state->last_keycode) {
- // Last pressed key before this one was a modifier
- state_erase_key(state, state->last_keycode);
- }
+ if (last_key_was_a_modifier && state->last_keycode) {
+ // Last pressed key before this one was a modifier
+ state_erase_key(state, state->last_keycode);
+ }
if (event->state == WLR_KEY_PRESSED) {
// Add current key to set; there may be duplicates
@@ -235,7 +236,6 @@ static void handle_keyboard_key(struct wl_listener *listener, void *data) {
code_modifiers);
}
-
bool handled = false;
// Identify active release binding
@@ -337,6 +337,19 @@ static int handle_keyboard_repeat(void *data) {
return 0;
}
+static void determine_bar_visibility(uint32_t modifiers) {
+ for (int i = 0; i < config->bars->length; ++i) {
+ struct bar_config *bar = config->bars->items[i];
+ if (strcmp(bar->mode, bar->hidden_state) == 0) { // both are "hide"
+ bool should_be_visible = (~modifiers & bar->modifier) == 0;
+ if (bar->visible_by_modifier != should_be_visible) {
+ bar->visible_by_modifier = should_be_visible;
+ ipc_event_bar_state_update(bar);
+ }
+ }
+ }
+}
+
static void handle_keyboard_modifiers(struct wl_listener *listener,
void *data) {
struct sway_keyboard *keyboard =
@@ -346,6 +359,9 @@ static void handle_keyboard_modifiers(struct wl_listener *listener,
keyboard->seat_device->input_device->wlr_device;
wlr_seat_set_keyboard(wlr_seat, wlr_device);
wlr_seat_keyboard_notify_modifiers(wlr_seat, &wlr_device->keyboard->modifiers);
+
+ uint32_t modifiers = wlr_keyboard_get_modifiers(wlr_device->keyboard);
+ determine_bar_visibility(modifiers);
}
struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat,
@@ -464,7 +480,7 @@ void sway_keyboard_configure(struct sway_keyboard *keyboard) {
keyboard->keyboard_key.notify = handle_keyboard_key;
wl_list_remove(&keyboard->keyboard_modifiers.link);
- wl_signal_add( &wlr_device->keyboard->events.modifiers,
+ wl_signal_add(&wlr_device->keyboard->events.modifiers,
&keyboard->keyboard_modifiers);
keyboard->keyboard_modifiers.notify = handle_keyboard_modifiers;
}