Implemented auto-hide functionality on Wayland

This commit is contained in:
Aivars Vaivods 2024-11-17 22:18:51 +02:00
parent 3e0083c9f2
commit 3dce815fe3
8 changed files with 54 additions and 9 deletions

View file

@ -177,6 +177,18 @@ set_cursor(struct bar *bar, const char *cursor)
b->backend.iface->set_cursor(bar, cursor);
}
static void
set_visible(struct bar *bar, bool visible)
{
struct private *b = bar->private;
if (b->layer != BAR_LAYER_HIDDEN)
return;
b->visible = visible;
bar->refresh(bar);
}
static const char *
output_name(const struct bar *bar)
{
@ -446,6 +458,7 @@ bar_new(const struct bar_config *config)
struct private *priv = calloc(1, sizeof(*priv));
priv->monitor = config->monitor != NULL ? strdup(config->monitor) : NULL;
priv->layer = config->layer;
priv->visible = false;
priv->location = config->location;
priv->height = config->height;
priv->background = config->background;
@ -488,6 +501,7 @@ bar_new(const struct bar_config *config)
bar->destroy = &destroy;
bar->refresh = &refresh;
bar->set_cursor = &set_cursor;
bar->set_visible = &set_visible;
bar->output_name = &output_name;
for (size_t i = 0; i < priv->left.count; i++)

View file

@ -12,13 +12,14 @@ struct bar {
void (*destroy)(struct bar *bar);
void (*refresh)(const struct bar *bar);
void (*set_visible)(struct bar *bar, bool visible);
void (*set_cursor)(struct bar *bar, const char *cursor);
const char *(*output_name)(const struct bar *bar);
};
enum bar_location { BAR_TOP, BAR_BOTTOM };
enum bar_layer { BAR_LAYER_OVERLAY, BAR_LAYER_TOP, BAR_LAYER_BOTTOM, BAR_LAYER_BACKGROUND };
enum bar_layer { BAR_LAYER_OVERLAY, BAR_LAYER_TOP, BAR_LAYER_BOTTOM, BAR_LAYER_BACKGROUND, BAR_LAYER_HIDDEN };
enum bar_backend { BAR_BACKEND_AUTO, BAR_BACKEND_XCB, BAR_BACKEND_WAYLAND };
struct bar_config {

View file

@ -8,6 +8,7 @@ struct private
/* From bar_config */
char *monitor;
enum bar_layer layer;
bool visible;
enum bar_location location;
int height;
int left_spacing, right_spacing;

View file

@ -651,7 +651,7 @@ handle_global(void *data, struct wl_registry *registry, uint32_t name, const cha
}
else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
const uint32_t required = 1;
const uint32_t required = 2;
if (!verify_iface_version(interface, version, required))
return;
@ -773,6 +773,7 @@ create_surface(struct wayland_backend *backend)
break;
case BAR_LAYER_BOTTOM:
case BAR_LAYER_HIDDEN:
layer = ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM;
break;
@ -1025,10 +1026,12 @@ update_size(struct wayland_backend *backend)
bar->height_with_border = height;
zwlr_layer_surface_v1_set_size(backend->layer_surface, 0, bar->height_with_border / scale);
zwlr_layer_surface_v1_set_exclusive_zone(
backend->layer_surface,
(bar->height_with_border + (bar->location == BAR_TOP ? bar->border.bottom_margin : bar->border.top_margin))
if (bar->layer != BAR_LAYER_HIDDEN) {
zwlr_layer_surface_v1_set_exclusive_zone(
backend->layer_surface,
(bar->height_with_border + (bar->location == BAR_TOP ? bar->border.bottom_margin : bar->border.top_margin))
/ scale);
}
zwlr_layer_surface_v1_set_margin(backend->layer_surface, bar->border.top_margin / scale,
bar->border.right_margin / scale, bar->border.bottom_margin / scale,
@ -1243,8 +1246,14 @@ loop(struct bar *_bar, void (*expose)(const struct bar *bar),
}
LOG_DBG("coalesced %zu expose commands", count);
if (do_expose)
if (bar->layer == BAR_LAYER_HIDDEN) {
zwlr_layer_surface_v1_set_layer(
backend->layer_surface,
(bar->visible) ? ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY : ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM);
}
if (do_expose) {
expose(_bar);
}
}
if (fds[1].revents & POLLIN) {