From bcc61e5147fb57a3b4bfb9a2a33065a0cf6da67b Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Fri, 12 Oct 2018 20:32:48 +0100 Subject: swaybar: handle mode/hidden_state changes As well as adding the hidden_state property to the bar config struct, this commit handles barconfig_update events when the mode or hidden_state changes, and uses a new function determine_bar_visibility to hide or show the bar as required, using, respectively, destroy_layer_surface, which is also newly added, and add_layer_surface, which has been changed to allow dynamically adding the surface. --- include/swaybar/bar.h | 18 ++++++++++++++++++ include/swaybar/config.h | 1 + 2 files changed, 19 insertions(+) (limited to 'include') diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h index 593f4f6d..9ff3fe7b 100644 --- a/include/swaybar/bar.h +++ b/include/swaybar/bar.h @@ -50,6 +50,11 @@ struct swaybar { char *mode; bool mode_pango_markup; + // only relevant when bar is in "hide" mode + bool visible_by_modifier; + bool visible_by_urgency; + bool visible; + struct wl_display *display; struct wl_compositor *compositor; struct zwlr_layer_shell_v1 *layer_shell; @@ -104,6 +109,19 @@ bool bar_setup(struct swaybar *bar, const char *socket_path); void bar_run(struct swaybar *bar); void bar_teardown(struct swaybar *bar); +/* + * Determines whether the bar should be visible and changes it to be so. + * If the current visibility of the bar is the different to what it should be, + * then it adds or destroys the layer surface as required, + * as well as sending the cont or stop signal to the status command. + * If the current visibility of the bar is already what it should be, + * then this function is a no-op, unless moving_layer is true, which occurs + * when the bar changes from "hide" to "dock" mode or vice versa, and the bar + * needs to be destroyed and re-added in order to change its layer. + * + * Returns true if the bar is now visible, otherwise false. + */ +bool determine_bar_visibility(struct swaybar *bar, bool moving_layer); void free_hotspots(struct wl_list *list); void free_workspaces(struct wl_list *list); diff --git a/include/swaybar/config.h b/include/swaybar/config.h index 68ee2087..10904bca 100644 --- a/include/swaybar/config.h +++ b/include/swaybar/config.h @@ -31,6 +31,7 @@ struct swaybar_config { char *font; char *sep_symbol; char *mode; + char *hidden_state; bool strip_workspace_numbers; bool binding_mode_indicator; bool wrap_scroll; -- cgit v1.2.3-54-g00ecf