diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-10-14 15:13:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-14 15:13:50 +0200 |
commit | 4a05fbf8ab364657763b1d1058bdf9b4c2727b76 (patch) | |
tree | c405121528d191ba74fe329fdb18093810d9b73c /sway | |
parent | abde9d6627483256ccfd20bdeeaa52d7790b0426 (diff) | |
parent | 85dd36e92b2fb3d4b5fefa36927abf8f35f84c5c (diff) | |
download | sway-4a05fbf8ab364657763b1d1058bdf9b4c2727b76.tar.xz |
Merge pull request #2751 from ianyfan/swaybar
Bar mode/hidden_state events
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands/bar/hidden_state.c | 34 | ||||
-rw-r--r-- | sway/commands/bar/mode.c | 34 | ||||
-rw-r--r-- | sway/config/bar.c | 2 | ||||
-rw-r--r-- | sway/input/keyboard.c | 28 | ||||
-rw-r--r-- | sway/ipc-server.c | 18 | ||||
-rw-r--r-- | sway/sway-bar.5.scd | 16 | ||||
-rw-r--r-- | sway/sway.5.scd | 12 |
7 files changed, 100 insertions, 44 deletions
diff --git a/sway/commands/bar/hidden_state.c b/sway/commands/bar/hidden_state.c index 502ce2c4..28adf6c7 100644 --- a/sway/commands/bar/hidden_state.c +++ b/sway/commands/bar/hidden_state.c @@ -32,7 +32,7 @@ static struct cmd_results *bar_set_hidden_state(struct bar_config *bar, } // free old mode free(old_state); - return cmd_results_new(CMD_SUCCESS, NULL, NULL); + return NULL; } struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) { @@ -50,24 +50,20 @@ struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) { const char *state = argv[0]; if (config->reading) { - return bar_set_hidden_state(config->current_bar, state); - } - - const char *id = NULL; - if (argc == 2) { - id = argv[1]; - } - struct bar_config *bar; - for (int i = 0; i < config->bars->length; ++i) { - bar = config->bars->items[i]; - if (id && strcmp(id, bar->id) == 0) { - return bar_set_hidden_state(bar, state); - } - - error = bar_set_hidden_state(bar, state); - if (error) { - return error; + error = bar_set_hidden_state(config->current_bar, state); + } else { + const char *id = argc == 2 ? argv[1] : NULL; + for (int i = 0; i < config->bars->length; ++i) { + struct bar_config *bar = config->bars->items[i]; + if (id) { + if (strcmp(id, bar->id) == 0) { + error = bar_set_hidden_state(bar, state); + break; + } + } else if ((error = bar_set_hidden_state(bar, state))) { + break; + } } } - return cmd_results_new(CMD_SUCCESS, NULL, NULL); + return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/commands/bar/mode.c b/sway/commands/bar/mode.c index 28e2d77b..dbdd3897 100644 --- a/sway/commands/bar/mode.c +++ b/sway/commands/bar/mode.c @@ -33,7 +33,7 @@ static struct cmd_results *bar_set_mode(struct bar_config *bar, const char *mode // free old mode free(old_mode); - return cmd_results_new(CMD_SUCCESS, NULL, NULL); + return NULL; } struct cmd_results *bar_cmd_mode(int argc, char **argv) { @@ -51,24 +51,20 @@ struct cmd_results *bar_cmd_mode(int argc, char **argv) { const char *mode = argv[0]; if (config->reading) { - return bar_set_mode(config->current_bar, mode); - } - - const char *id = NULL; - if (argc == 2) { - id = argv[1]; - } - - struct bar_config *bar; - for (int i = 0; i < config->bars->length; ++i) { - bar = config->bars->items[i]; - if (id && strcmp(id, bar->id) == 0) { - return bar_set_mode(bar, mode); - } - error = bar_set_mode(bar, mode); - if (error) { - return error; + error = bar_set_mode(config->current_bar, mode); + } else { + const char *id = argc == 2 ? argv[1] : NULL; + for (int i = 0; i < config->bars->length; ++i) { + struct bar_config *bar = config->bars->items[i]; + if (id) { + if (strcmp(id, bar->id) == 0) { + error = bar_set_mode(bar, mode); + break; + } + } else if ((error = bar_set_mode(bar, mode))) { + break; + } } } - return cmd_results_new(CMD_SUCCESS, NULL, NULL); + return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL); } 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 @@ #include "stringop.h" #include "list.h" #include "log.h" +#include "util.h" static void terminate_swaybar(pid_t pid) { wlr_log(WLR_DEBUG, "Terminating swaybar %d", pid); @@ -101,6 +102,7 @@ struct bar_config *default_bar_config(void) { bar->binding_mode_indicator = true; bar->verbose = false; bar->pid = 0; + bar->modifier = get_modifier_mask_by_name("Mod4"); if (!(bar->mode = strdup("dock"))) { goto cleanup; } 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; } 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) { json_object_put(json); } +void ipc_event_bar_state_update(struct bar_config *bar) { + if (!ipc_has_event_listeners(IPC_EVENT_BAR_STATE_UPDATE)) { + return; + } + wlr_log(WLR_DEBUG, "Sending bar_state_update event"); + + json_object *json = json_object_new_object(); + json_object_object_add(json, "id", json_object_new_string(bar->id)); + json_object_object_add(json, "visible_by_modifier", + json_object_new_boolean(bar->visible_by_modifier)); + + const char *json_string = json_object_to_json_string(json); + ipc_send_event(json_string, IPC_EVENT_BAR_STATE_UPDATE); + json_object_put(json); +} + void ipc_event_mode(const char *mode, bool pango) { if (!ipc_has_event_listeners(IPC_EVENT_MODE)) { return; @@ -651,6 +667,8 @@ void ipc_client_handle_command(struct ipc_client *client) { client->subscribed_events |= event_mask(IPC_EVENT_WORKSPACE); } else if (strcmp(event_type, "barconfig_update") == 0) { client->subscribed_events |= event_mask(IPC_EVENT_BARCONFIG_UPDATE); + } else if (strcmp(event_type, "bar_state_update") == 0) { + client->subscribed_events |= event_mask(IPC_EVENT_BAR_STATE_UPDATE); } else if (strcmp(event_type, "mode") == 0) { client->subscribed_events |= event_mask(IPC_EVENT_MODE); } else if (strcmp(event_type, "shutdown") == 0) { diff --git a/sway/sway-bar.5.scd b/sway/sway-bar.5.scd index 6729c9ac..873741c0 100644 --- a/sway/sway-bar.5.scd +++ b/sway/sway-bar.5.scd @@ -65,6 +65,22 @@ Sway allows configuring swaybar in the sway configuration file. is given, when mouse button _n_ has been released). To disable the default behavior for a button, use the command _nop_. +*mode* dock|hide|invisible + Specifies the visibility of the bar. In _dock_ mode, it is permanently + visible at one edge of the screen. In _hide_ mode, it is hidden unless the + modifier key is pressed, though this behaviour depends on the hidden state. + In _invisible_ mode, it is permanently hidden. Default is _dock_. + +*hidden\_state* hide|show + Specifies the behaviour of the bar when it is in _hide_ mode. When the + hidden state is _hide_, then it is normally hidden, and only unhidden by + pressing the modifier key or in case of urgency hints. When the hidden + state is _show_, then it is permanently visible, drawn on top of the + currently visible workspace. Default is _hide_. + +*modifier* <Modifier>|none + Specifies the modifier key that shows a hidden bar. Default is _Mod4_. + ## TRAY Swaybar provides a system tray where third-party applications may place icons. diff --git a/sway/sway.5.scd b/sway/sway.5.scd index 2e1d13a8..67cc1cb1 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -614,6 +614,18 @@ match any output by using the output name "\*". *workspace\_layout* default|stacking|tabbed Specifies the initial layout for new workspaces. +# BAR CONTROL + +*bar hidden\_state* hide|show|toggle [<bar\_id>] + Sets the hidden state of the bar (see *sway-bar*(5)), either individually, + by specifying a bar id, or if none is given, for all bar instances. + _toggle_ switches between _hide_ and _show_. + +*bar mode* dock|hide|invisible|toggle [<bar\_id>] + Sets the mode of the bar (see *sway-bar*(5)), either individually, + by specifying a bar id, or if none is given, for all bar instances. + _toggle_ switches between _dock_ and _hide_. + # CRITERIA A criteria is a string in the form of, for example: |