mirror of
https://github.com/swaywm/sway.git
synced 2025-11-17 06:59:48 -05:00
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.
This commit is contained in:
parent
bcc61e5147
commit
2f1fd80726
8 changed files with 66 additions and 7 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue