diff options
author | 2018-10-12 21:14:52 +0100 | |
---|---|---|
committer | 2018-10-14 13:33:12 +0100 | |
commit | 2f1fd8072673b1824f37759e14f5388d7a87fb5c (patch) | |
tree | 948b7912a2341c2d0b903258b444173b3fd4d1f3 /sway | |
parent | swaybar: handle mode/hidden_state changes (diff) | |
download | sway-2f1fd8072673b1824f37759e14f5388d7a87fb5c.tar.gz sway-2f1fd8072673b1824f37759e14f5388d7a87fb5c.tar.zst sway-2f1fd8072673b1824f37759e14f5388d7a87fb5c.zip |
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')
-rw-r--r-- | sway/config/bar.c | 2 | ||||
-rw-r--r-- | sway/input/keyboard.c | 28 | ||||
-rw-r--r-- | sway/ipc-server.c | 18 |
3 files changed, 42 insertions, 6 deletions
diff --git a/sway/config/bar.c b/sway/config/bar.c index 5726e95b..8b88642e 100644 --- a/sway/config/bar.c +++ b/sway/config/bar.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include "stringop.h" | 16 | #include "stringop.h" |
17 | #include "list.h" | 17 | #include "list.h" |
18 | #include "log.h" | 18 | #include "log.h" |
19 | #include "util.h" | ||
19 | 20 | ||
20 | static void terminate_swaybar(pid_t pid) { | 21 | static void terminate_swaybar(pid_t pid) { |
21 | wlr_log(WLR_DEBUG, "Terminating swaybar %d", pid); | 22 | wlr_log(WLR_DEBUG, "Terminating swaybar %d", pid); |
@@ -101,6 +102,7 @@ struct bar_config *default_bar_config(void) { | |||
101 | bar->binding_mode_indicator = true; | 102 | bar->binding_mode_indicator = true; |
102 | bar->verbose = false; | 103 | bar->verbose = false; |
103 | bar->pid = 0; | 104 | bar->pid = 0; |
105 | bar->modifier = get_modifier_mask_by_name("Mod4"); | ||
104 | if (!(bar->mode = strdup("dock"))) { | 106 | if (!(bar->mode = strdup("dock"))) { |
105 | goto cleanup; | 107 | goto cleanup; |
106 | } | 108 | } |
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 @@ | |||
9 | #include "sway/input/input-manager.h" | 9 | #include "sway/input/input-manager.h" |
10 | #include "sway/input/keyboard.h" | 10 | #include "sway/input/keyboard.h" |
11 | #include "sway/input/seat.h" | 11 | #include "sway/input/seat.h" |
12 | #include "sway/ipc-server.h" | ||
12 | #include "log.h" | 13 | #include "log.h" |
13 | 14 | ||
14 | /** | 15 | /** |
@@ -66,10 +67,10 @@ static void update_shortcut_state(struct sway_shortcut_state *state, | |||
66 | bool last_key_was_a_modifier = raw_modifiers != state->last_raw_modifiers; | 67 | bool last_key_was_a_modifier = raw_modifiers != state->last_raw_modifiers; |
67 | state->last_raw_modifiers = raw_modifiers; | 68 | state->last_raw_modifiers = raw_modifiers; |
68 | 69 | ||
69 | if (last_key_was_a_modifier && state->last_keycode) { | 70 | if (last_key_was_a_modifier && state->last_keycode) { |
70 | // Last pressed key before this one was a modifier | 71 | // Last pressed key before this one was a modifier |
71 | state_erase_key(state, state->last_keycode); | 72 | state_erase_key(state, state->last_keycode); |
72 | } | 73 | } |
73 | 74 | ||
74 | if (event->state == WLR_KEY_PRESSED) { | 75 | if (event->state == WLR_KEY_PRESSED) { |
75 | // Add current key to set; there may be duplicates | 76 | // Add current key to set; there may be duplicates |
@@ -235,7 +236,6 @@ static void handle_keyboard_key(struct wl_listener *listener, void *data) { | |||
235 | code_modifiers); | 236 | code_modifiers); |
236 | } | 237 | } |
237 | 238 | ||
238 | |||
239 | bool handled = false; | 239 | bool handled = false; |
240 | 240 | ||
241 | // Identify active release binding | 241 | // Identify active release binding |
@@ -337,6 +337,19 @@ static int handle_keyboard_repeat(void *data) { | |||
337 | return 0; | 337 | return 0; |
338 | } | 338 | } |
339 | 339 | ||
340 | static void determine_bar_visibility(uint32_t modifiers) { | ||
341 | for (int i = 0; i < config->bars->length; ++i) { | ||
342 | struct bar_config *bar = config->bars->items[i]; | ||
343 | if (strcmp(bar->mode, bar->hidden_state) == 0) { // both are "hide" | ||
344 | bool should_be_visible = (~modifiers & bar->modifier) == 0; | ||
345 | if (bar->visible_by_modifier != should_be_visible) { | ||
346 | bar->visible_by_modifier = should_be_visible; | ||
347 | ipc_event_bar_state_update(bar); | ||
348 | } | ||
349 | } | ||
350 | } | ||
351 | } | ||
352 | |||
340 | static void handle_keyboard_modifiers(struct wl_listener *listener, | 353 | static void handle_keyboard_modifiers(struct wl_listener *listener, |
341 | void *data) { | 354 | void *data) { |
342 | struct sway_keyboard *keyboard = | 355 | struct sway_keyboard *keyboard = |
@@ -346,6 +359,9 @@ static void handle_keyboard_modifiers(struct wl_listener *listener, | |||
346 | keyboard->seat_device->input_device->wlr_device; | 359 | keyboard->seat_device->input_device->wlr_device; |
347 | wlr_seat_set_keyboard(wlr_seat, wlr_device); | 360 | wlr_seat_set_keyboard(wlr_seat, wlr_device); |
348 | wlr_seat_keyboard_notify_modifiers(wlr_seat, &wlr_device->keyboard->modifiers); | 361 | wlr_seat_keyboard_notify_modifiers(wlr_seat, &wlr_device->keyboard->modifiers); |
362 | |||
363 | uint32_t modifiers = wlr_keyboard_get_modifiers(wlr_device->keyboard); | ||
364 | determine_bar_visibility(modifiers); | ||
349 | } | 365 | } |
350 | 366 | ||
351 | struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat, | 367 | struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat, |
@@ -464,7 +480,7 @@ void sway_keyboard_configure(struct sway_keyboard *keyboard) { | |||
464 | keyboard->keyboard_key.notify = handle_keyboard_key; | 480 | keyboard->keyboard_key.notify = handle_keyboard_key; |
465 | 481 | ||
466 | wl_list_remove(&keyboard->keyboard_modifiers.link); | 482 | wl_list_remove(&keyboard->keyboard_modifiers.link); |
467 | wl_signal_add( &wlr_device->keyboard->events.modifiers, | 483 | wl_signal_add(&wlr_device->keyboard->events.modifiers, |
468 | &keyboard->keyboard_modifiers); | 484 | &keyboard->keyboard_modifiers); |
469 | keyboard->keyboard_modifiers.notify = handle_keyboard_modifiers; | 485 | keyboard->keyboard_modifiers.notify = handle_keyboard_modifiers; |
470 | } | 486 | } |
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 2d915502..63c95503 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -349,6 +349,22 @@ void ipc_event_barconfig_update(struct bar_config *bar) { | |||
349 | json_object_put(json); | 349 | json_object_put(json); |
350 | } | 350 | } |
351 | 351 | ||
352 | void ipc_event_bar_state_update(struct bar_config *bar) { | ||
353 | if (!ipc_has_event_listeners(IPC_EVENT_BAR_STATE_UPDATE)) { | ||
354 | return; | ||
355 | } | ||
356 | wlr_log(WLR_DEBUG, "Sending bar_state_update event"); | ||
357 | |||
358 | json_object *json = json_object_new_object(); | ||
359 | json_object_object_add(json, "id", json_object_new_string(bar->id)); | ||
360 | json_object_object_add(json, "visible_by_modifier", | ||
361 | json_object_new_boolean(bar->visible_by_modifier)); | ||
362 | |||
363 | const char *json_string = json_object_to_json_string(json); | ||
364 | ipc_send_event(json_string, IPC_EVENT_BAR_STATE_UPDATE); | ||
365 | json_object_put(json); | ||
366 | } | ||
367 | |||
352 | void ipc_event_mode(const char *mode, bool pango) { | 368 | void ipc_event_mode(const char *mode, bool pango) { |
353 | if (!ipc_has_event_listeners(IPC_EVENT_MODE)) { | 369 | if (!ipc_has_event_listeners(IPC_EVENT_MODE)) { |
354 | return; | 370 | return; |
@@ -651,6 +667,8 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
651 | client->subscribed_events |= event_mask(IPC_EVENT_WORKSPACE); | 667 | client->subscribed_events |= event_mask(IPC_EVENT_WORKSPACE); |
652 | } else if (strcmp(event_type, "barconfig_update") == 0) { | 668 | } else if (strcmp(event_type, "barconfig_update") == 0) { |
653 | client->subscribed_events |= event_mask(IPC_EVENT_BARCONFIG_UPDATE); | 669 | client->subscribed_events |= event_mask(IPC_EVENT_BARCONFIG_UPDATE); |
670 | } else if (strcmp(event_type, "bar_state_update") == 0) { | ||
671 | client->subscribed_events |= event_mask(IPC_EVENT_BAR_STATE_UPDATE); | ||
654 | } else if (strcmp(event_type, "mode") == 0) { | 672 | } else if (strcmp(event_type, "mode") == 0) { |
655 | client->subscribed_events |= event_mask(IPC_EVENT_MODE); | 673 | client->subscribed_events |= event_mask(IPC_EVENT_MODE); |
656 | } else if (strcmp(event_type, "shutdown") == 0) { | 674 | } else if (strcmp(event_type, "shutdown") == 0) { |