swaynag: adds option to set wayland shell layer

Uses --layer/-y set to overlay|top|bottom|background
This commit is contained in:
James Edwards-Jones 2021-03-17 15:55:21 +00:00 committed by Simon Ser
parent 75a4122f7a
commit d13090be54
6 changed files with 37 additions and 2 deletions

View File

@ -7,6 +7,7 @@ struct swaynag_type {
char *font;
char *output;
uint32_t anchors;
int32_t layer; // enum zwlr_layer_shell_v1_layer or -1 if unset
// Colors
uint32_t button_text;

View File

@ -59,6 +59,7 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
{"config", required_argument, NULL, 'c'},
{"debug", no_argument, NULL, 'd'},
{"edge", required_argument, NULL, 'e'},
{"layer", required_argument, NULL, 'y'},
{"font", required_argument, NULL, 'f'},
{"help", no_argument, NULL, 'h'},
{"detailed-message", no_argument, NULL, 'l'},
@ -104,6 +105,8 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
" -c, --config <path> Path to config file.\n"
" -d, --debug Enable debugging.\n"
" -e, --edge top|bottom Set the edge to use.\n"
" -y, --layer overlay|top|bottom|background\n"
" Set the layer to use.\n"
" -f, --font <font> Set the font to use.\n"
" -h, --help Show help message and quit.\n"
" -l, --detailed-message Read a detailed message from stdin.\n"
@ -133,7 +136,7 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
optind = 1;
while (1) {
int c = getopt_long(argc, argv, "b:B:z:Z:c:de:f:hlL:m:o:s:t:v", opts, NULL);
int c = getopt_long(argc, argv, "b:B:z:Z:c:de:y:f:hlL:m:o:s:t:v", opts, NULL);
if (c == -1) {
break;
}
@ -184,6 +187,24 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
}
}
break;
case 'y': // Layer
if (type) {
if (strcmp(optarg, "background") == 0) {
type->layer = ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND;
} else if (strcmp(optarg, "bottom") == 0) {
type->layer = ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM;
} else if (strcmp(optarg, "top") == 0) {
type->layer = ZWLR_LAYER_SHELL_V1_LAYER_TOP;
} else if (strcmp(optarg, "overlay") == 0) {
type->layer = ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY;
} else {
fprintf(stderr, "Invalid layer: %s\n"
"Usage: --layer overlay|top|bottom|background\n",
optarg);
return EXIT_FAILURE;
}
}
break;
case 'f': // Font
if (type) {
free(type->font);

View File

@ -48,6 +48,9 @@ _swaynag_ [options...]
*-e, --edge* top|bottom
Set the edge to use.
*-y, --layer* overlay|top|bottom|background
Set the layer to use.
*-f, --font* <font>
Set the font to use.

View File

@ -79,6 +79,9 @@ Additionally, the following options can be assigned a default per-type:
*edge=top|bottom*
Set the edge to use.
*layer=overlay|top|bottom|background*
Set the layer to use.
*font=<font>*
Set the font to use.

View File

@ -476,7 +476,8 @@ void swaynag_setup(struct swaynag *swaynag) {
swaynag->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
swaynag->layer_shell, swaynag->surface,
swaynag->output ? swaynag->output->wl_output : NULL,
ZWLR_LAYER_SHELL_V1_LAYER_TOP, "swaynag");
swaynag->type->layer,
"swaynag");
assert(swaynag->layer_surface);
zwlr_layer_surface_v1_add_listener(swaynag->layer_surface,
&layer_surface_listener, swaynag);

View File

@ -26,6 +26,7 @@ struct swaynag_type *swaynag_type_new(const char *name) {
type->button_gap_close = -1;
type->button_margin_right = -1;
type->button_padding = -1;
type->layer = -1;
return type;
}
@ -35,6 +36,7 @@ void swaynag_types_add_default(list_t *types) {
type_defaults->anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
| ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
| ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
type_defaults->layer = ZWLR_LAYER_SHELL_V1_LAYER_TOP;
type_defaults->button_background = 0x333333FF;
type_defaults->details_background = 0x333333FF;
type_defaults->background = 0x323232FF;
@ -100,6 +102,10 @@ void swaynag_type_merge(struct swaynag_type *dest, struct swaynag_type *src) {
dest->anchors = src->anchors;
}
if (src->layer >= 0) {
dest->layer = src->layer;
}
// Colors
if (src->button_background > 0) {
dest->button_background = src->button_background;