mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-20 03:35:41 +02:00
Implemented auto-hide functionality on Wayland
This commit is contained in:
parent
3e0083c9f2
commit
3dce815fe3
8 changed files with 54 additions and 9 deletions
14
bar/bar.c
14
bar/bar.c
|
@ -177,6 +177,18 @@ set_cursor(struct bar *bar, const char *cursor)
|
||||||
b->backend.iface->set_cursor(bar, 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 *
|
static const char *
|
||||||
output_name(const struct bar *bar)
|
output_name(const struct bar *bar)
|
||||||
{
|
{
|
||||||
|
@ -446,6 +458,7 @@ bar_new(const struct bar_config *config)
|
||||||
struct private *priv = calloc(1, sizeof(*priv));
|
struct private *priv = calloc(1, sizeof(*priv));
|
||||||
priv->monitor = config->monitor != NULL ? strdup(config->monitor) : NULL;
|
priv->monitor = config->monitor != NULL ? strdup(config->monitor) : NULL;
|
||||||
priv->layer = config->layer;
|
priv->layer = config->layer;
|
||||||
|
priv->visible = false;
|
||||||
priv->location = config->location;
|
priv->location = config->location;
|
||||||
priv->height = config->height;
|
priv->height = config->height;
|
||||||
priv->background = config->background;
|
priv->background = config->background;
|
||||||
|
@ -488,6 +501,7 @@ bar_new(const struct bar_config *config)
|
||||||
bar->destroy = &destroy;
|
bar->destroy = &destroy;
|
||||||
bar->refresh = &refresh;
|
bar->refresh = &refresh;
|
||||||
bar->set_cursor = &set_cursor;
|
bar->set_cursor = &set_cursor;
|
||||||
|
bar->set_visible = &set_visible;
|
||||||
bar->output_name = &output_name;
|
bar->output_name = &output_name;
|
||||||
|
|
||||||
for (size_t i = 0; i < priv->left.count; i++)
|
for (size_t i = 0; i < priv->left.count; i++)
|
||||||
|
|
|
@ -12,13 +12,14 @@ struct bar {
|
||||||
void (*destroy)(struct bar *bar);
|
void (*destroy)(struct bar *bar);
|
||||||
|
|
||||||
void (*refresh)(const 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);
|
void (*set_cursor)(struct bar *bar, const char *cursor);
|
||||||
|
|
||||||
const char *(*output_name)(const struct bar *bar);
|
const char *(*output_name)(const struct bar *bar);
|
||||||
};
|
};
|
||||||
|
|
||||||
enum bar_location { BAR_TOP, BAR_BOTTOM };
|
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 };
|
enum bar_backend { BAR_BACKEND_AUTO, BAR_BACKEND_XCB, BAR_BACKEND_WAYLAND };
|
||||||
|
|
||||||
struct bar_config {
|
struct bar_config {
|
||||||
|
|
|
@ -8,6 +8,7 @@ struct private
|
||||||
/* From bar_config */
|
/* From bar_config */
|
||||||
char *monitor;
|
char *monitor;
|
||||||
enum bar_layer layer;
|
enum bar_layer layer;
|
||||||
|
bool visible;
|
||||||
enum bar_location location;
|
enum bar_location location;
|
||||||
int height;
|
int height;
|
||||||
int left_spacing, right_spacing;
|
int left_spacing, right_spacing;
|
||||||
|
|
|
@ -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) {
|
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))
|
if (!verify_iface_version(interface, version, required))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -773,6 +773,7 @@ create_surface(struct wayland_backend *backend)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BAR_LAYER_BOTTOM:
|
case BAR_LAYER_BOTTOM:
|
||||||
|
case BAR_LAYER_HIDDEN:
|
||||||
layer = ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM;
|
layer = ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1025,10 +1026,12 @@ update_size(struct wayland_backend *backend)
|
||||||
bar->height_with_border = height;
|
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_size(backend->layer_surface, 0, bar->height_with_border / scale);
|
||||||
zwlr_layer_surface_v1_set_exclusive_zone(
|
if (bar->layer != BAR_LAYER_HIDDEN) {
|
||||||
backend->layer_surface,
|
zwlr_layer_surface_v1_set_exclusive_zone(
|
||||||
(bar->height_with_border + (bar->location == BAR_TOP ? bar->border.bottom_margin : bar->border.top_margin))
|
backend->layer_surface,
|
||||||
|
(bar->height_with_border + (bar->location == BAR_TOP ? bar->border.bottom_margin : bar->border.top_margin))
|
||||||
/ scale);
|
/ scale);
|
||||||
|
}
|
||||||
|
|
||||||
zwlr_layer_surface_v1_set_margin(backend->layer_surface, 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,
|
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);
|
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);
|
expose(_bar);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fds[1].revents & POLLIN) {
|
if (fds[1].revents & POLLIN) {
|
||||||
|
|
|
@ -416,7 +416,7 @@ verify_bar_location(keychain_t *chain, const struct yml_node *node)
|
||||||
static bool
|
static bool
|
||||||
verify_bar_layer(keychain_t *chain, const struct yml_node *node)
|
verify_bar_layer(keychain_t *chain, const struct yml_node *node)
|
||||||
{
|
{
|
||||||
return conf_verify_enum(chain, node, (const char *[]){"overlay", "top", "bottom", "background"}, 4);
|
return conf_verify_enum(chain, node, (const char *[]){"overlay", "top", "bottom", "background", "hidden"}, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
2
config.c
2
config.c
|
@ -325,6 +325,8 @@ conf_to_bar(const struct yml_node *bar, enum bar_backend backend)
|
||||||
conf.layer = BAR_LAYER_BOTTOM;
|
conf.layer = BAR_LAYER_BOTTOM;
|
||||||
else if (strcmp(tmp, "background") == 0)
|
else if (strcmp(tmp, "background") == 0)
|
||||||
conf.layer = BAR_LAYER_BACKGROUND;
|
conf.layer = BAR_LAYER_BACKGROUND;
|
||||||
|
else if (strcmp(tmp, "hidden") == 0)
|
||||||
|
conf.layer = BAR_LAYER_HIDDEN;
|
||||||
else
|
else
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,8 +54,9 @@ types that are frequently used:
|
||||||
| layer
|
| layer
|
||||||
: string
|
: string
|
||||||
: no
|
: no
|
||||||
: Layer to put bar on. One of _overlay_, _top_, _bottom_ or
|
: Layer to put bar on. One of _overlay_, _top_, _bottom_, _bottom_ or
|
||||||
_background_. Wayland only. Default: _bottom_.
|
_hidden_. Wayland only. Default: _bottom_. If set to _hidden_, will move
|
||||||
|
between _overlay_ and _bottom_ when receives respectively SIGUSR1 or SIGUSR2.
|
||||||
| left-spacing
|
| left-spacing
|
||||||
: int
|
: int
|
||||||
: no
|
: no
|
||||||
|
|
17
main.c
17
main.c
|
@ -27,6 +27,7 @@
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
static volatile sig_atomic_t aborted = 0;
|
static volatile sig_atomic_t aborted = 0;
|
||||||
|
static volatile sig_atomic_t sigusr = 0;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
signal_handler(int signo)
|
signal_handler(int signo)
|
||||||
|
@ -34,6 +35,12 @@ signal_handler(int signo)
|
||||||
aborted = signo;
|
aborted = signo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sigusr_handler(int signo)
|
||||||
|
{
|
||||||
|
sigusr = signo;
|
||||||
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
get_config_path_user_config(void)
|
get_config_path_user_config(void)
|
||||||
{
|
{
|
||||||
|
@ -295,12 +302,18 @@ main(int argc, char *const *argv)
|
||||||
sigaction(SIGINT, &sa, NULL);
|
sigaction(SIGINT, &sa, NULL);
|
||||||
sigaction(SIGTERM, &sa, NULL);
|
sigaction(SIGTERM, &sa, NULL);
|
||||||
|
|
||||||
|
const struct sigaction sau = {.sa_handler = &sigusr_handler};
|
||||||
|
sigaction(SIGUSR1, &sau, NULL);
|
||||||
|
sigaction(SIGUSR2, &sau, NULL);
|
||||||
|
|
||||||
/* Block SIGINT (this is under the assumption that threads inherit
|
/* Block SIGINT (this is under the assumption that threads inherit
|
||||||
* the signal mask */
|
* the signal mask */
|
||||||
sigset_t signal_mask;
|
sigset_t signal_mask;
|
||||||
sigemptyset(&signal_mask);
|
sigemptyset(&signal_mask);
|
||||||
sigaddset(&signal_mask, SIGINT);
|
sigaddset(&signal_mask, SIGINT);
|
||||||
sigaddset(&signal_mask, SIGTERM);
|
sigaddset(&signal_mask, SIGTERM);
|
||||||
|
sigaddset(&signal_mask, SIGUSR1);
|
||||||
|
sigaddset(&signal_mask, SIGUSR2);
|
||||||
pthread_sigmask(SIG_BLOCK, &signal_mask, NULL);
|
pthread_sigmask(SIG_BLOCK, &signal_mask, NULL);
|
||||||
|
|
||||||
int abort_fd = eventfd(0, EFD_CLOEXEC);
|
int abort_fd = eventfd(0, EFD_CLOEXEC);
|
||||||
|
@ -354,6 +367,10 @@ main(int argc, char *const *argv)
|
||||||
struct pollfd fds[] = {{.fd = abort_fd, .events = POLLIN}};
|
struct pollfd fds[] = {{.fd = abort_fd, .events = POLLIN}};
|
||||||
int r __attribute__((unused)) = poll(fds, sizeof(fds) / sizeof(fds[0]), -1);
|
int r __attribute__((unused)) = poll(fds, sizeof(fds) / sizeof(fds[0]), -1);
|
||||||
|
|
||||||
|
if (sigusr) {
|
||||||
|
bar->set_visible(bar, (sigusr == SIGUSR1));
|
||||||
|
sigusr = 0;
|
||||||
|
}
|
||||||
if (fds[0].revents & (POLLIN | POLLHUP)) {
|
if (fds[0].revents & (POLLIN | POLLHUP)) {
|
||||||
/*
|
/*
|
||||||
* Either the bar aborted (triggering the abort_fd), or user
|
* Either the bar aborted (triggering the abort_fd), or user
|
||||||
|
|
Loading…
Add table
Reference in a new issue