swaybar: add overlay mode (fix #1620)

Overlay mode puts the bar above normal windows and passes through/ignores any
touch/mouse/keyboard events that would be sent to it.
This commit is contained in:
Milkey Mouse 2019-02-23 21:59:36 -08:00 committed by Brian Ashworth
parent 2510e3df38
commit 2f7247e08a
4 changed files with 21 additions and 4 deletions

View file

@ -58,6 +58,7 @@ struct swaybar_output {
struct zxdg_output_v1 *xdg_output; struct zxdg_output_v1 *xdg_output;
struct wl_surface *surface; struct wl_surface *surface;
struct zwlr_layer_surface_v1 *layer_surface; struct zwlr_layer_surface_v1 *layer_surface;
struct wl_region *input_region;
uint32_t wl_name; uint32_t wl_name;
struct wl_list workspaces; // swaybar_workspace::link struct wl_list workspaces; // swaybar_workspace::link

View file

@ -20,6 +20,8 @@ static struct cmd_results *bar_set_mode(struct bar_config *bar, const char *mode
bar->mode = strdup("hide"); bar->mode = strdup("hide");
} else if (strcasecmp("invisible", mode) == 0) { } else if (strcasecmp("invisible", mode) == 0) {
bar->mode = strdup("invisible"); bar->mode = strdup("invisible");
} else if (strcasecmp("overlay", mode) == 0) {
bar->mode = strdup("overlay");
} else { } else {
return cmd_results_new(CMD_INVALID, "Invalid value %s", mode); return cmd_results_new(CMD_INVALID, "Invalid value %s", mode);
} }

View file

@ -84,11 +84,13 @@ Sway allows configuring swaybar in the sway configuration file.
debug-events`. To disable the default behavior for a button, use the debug-events`. To disable the default behavior for a button, use the
command _nop_. command _nop_.
*mode* dock|hide|invisible *mode* dock|hide|invisible|overlay
Specifies the visibility of the bar. In _dock_ mode, it is permanently 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 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. modifier key is pressed, though this behaviour depends on the hidden state.
In _invisible_ mode, it is permanently hidden. Default is _dock_. In _invisible_ mode, it is permanently hidden. In _overlay_ mode, it is
permanently visible on top of other windows. (In _overlay_ mode the bar is
transparent to input events.) Default is _dock_.
*hidden_state* hide|show *hidden_state* hide|show
Specifies the behaviour of the bar when it is in _hide_ mode. When the Specifies the behaviour of the bar when it is in _hide_ mode. When the

View file

@ -51,6 +51,9 @@ static void swaybar_output_free(struct swaybar_output *output) {
if (output->surface != NULL) { if (output->surface != NULL) {
wl_surface_destroy(output->surface); wl_surface_destroy(output->surface);
} }
if (output->input_region != NULL) {
wl_region_destroy(output->input_region);
}
zxdg_output_v1_destroy(output->xdg_output); zxdg_output_v1_destroy(output->xdg_output);
wl_output_destroy(output->output); wl_output_destroy(output->output);
destroy_buffer(&output->buffers[0]); destroy_buffer(&output->buffers[0]);
@ -100,16 +103,25 @@ static void add_layer_surface(struct swaybar_output *output) {
struct swaybar_config *config = bar->config; struct swaybar_config *config = bar->config;
bool hidden = strcmp(config->mode, "hide") == 0; bool hidden = strcmp(config->mode, "hide") == 0;
bool overlay = !hidden && strcmp(config->mode, "overlay") == 0;
output->layer_surface = zwlr_layer_shell_v1_get_layer_surface( output->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
bar->layer_shell, output->surface, output->output, bar->layer_shell, output->surface, output->output,
hidden ? ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY : hidden || overlay ? ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY :
ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM, "panel"); ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM, "panel");
assert(output->layer_surface); assert(output->layer_surface);
zwlr_layer_surface_v1_add_listener(output->layer_surface, zwlr_layer_surface_v1_add_listener(output->layer_surface,
&layer_surface_listener, output); &layer_surface_listener, output);
if (overlay) {
// Empty input region
output->input_region = wl_compositor_create_region(bar->compositor);
assert(output->input_region);
wl_surface_set_input_region(output->surface, output->input_region);
}
zwlr_layer_surface_v1_set_anchor(output->layer_surface, config->position); zwlr_layer_surface_v1_set_anchor(output->layer_surface, config->position);
if (hidden) { if (hidden || overlay) {
zwlr_layer_surface_v1_set_exclusive_zone(output->layer_surface, -1); zwlr_layer_surface_v1_set_exclusive_zone(output->layer_surface, -1);
} }
} }