aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar James Edwards-Jones <git@jamedjo.co.uk>2021-03-17 15:55:21 +0000
committerLibravatar Simon Ser <contact@emersion.fr>2021-06-17 11:47:49 +0200
commitd13090be546d19d487c872f7bc79bb98f8e17873 (patch)
tree60031d8768c0eedf93992c79155b89a208fdb7c8
parentfix typo in sway-output.5.scd (diff)
downloadsway-d13090be546d19d487c872f7bc79bb98f8e17873.tar.gz
sway-d13090be546d19d487c872f7bc79bb98f8e17873.tar.zst
sway-d13090be546d19d487c872f7bc79bb98f8e17873.zip
swaynag: adds option to set wayland shell layer
Uses --layer/-y set to overlay|top|bottom|background
-rw-r--r--include/swaynag/types.h1
-rw-r--r--swaynag/config.c23
-rw-r--r--swaynag/swaynag.1.scd3
-rw-r--r--swaynag/swaynag.5.scd3
-rw-r--r--swaynag/swaynag.c3
-rw-r--r--swaynag/types.c6
6 files changed, 37 insertions, 2 deletions
diff --git a/include/swaynag/types.h b/include/swaynag/types.h
index 24da9418..3c3b2754 100644
--- a/include/swaynag/types.h
+++ b/include/swaynag/types.h
@@ -7,6 +7,7 @@ struct swaynag_type {
7 char *font; 7 char *font;
8 char *output; 8 char *output;
9 uint32_t anchors; 9 uint32_t anchors;
10 int32_t layer; // enum zwlr_layer_shell_v1_layer or -1 if unset
10 11
11 // Colors 12 // Colors
12 uint32_t button_text; 13 uint32_t button_text;
diff --git a/swaynag/config.c b/swaynag/config.c
index c6b4e431..6db7cce5 100644
--- a/swaynag/config.c
+++ b/swaynag/config.c
@@ -59,6 +59,7 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
59 {"config", required_argument, NULL, 'c'}, 59 {"config", required_argument, NULL, 'c'},
60 {"debug", no_argument, NULL, 'd'}, 60 {"debug", no_argument, NULL, 'd'},
61 {"edge", required_argument, NULL, 'e'}, 61 {"edge", required_argument, NULL, 'e'},
62 {"layer", required_argument, NULL, 'y'},
62 {"font", required_argument, NULL, 'f'}, 63 {"font", required_argument, NULL, 'f'},
63 {"help", no_argument, NULL, 'h'}, 64 {"help", no_argument, NULL, 'h'},
64 {"detailed-message", no_argument, NULL, 'l'}, 65 {"detailed-message", no_argument, NULL, 'l'},
@@ -104,6 +105,8 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
104 " -c, --config <path> Path to config file.\n" 105 " -c, --config <path> Path to config file.\n"
105 " -d, --debug Enable debugging.\n" 106 " -d, --debug Enable debugging.\n"
106 " -e, --edge top|bottom Set the edge to use.\n" 107 " -e, --edge top|bottom Set the edge to use.\n"
108 " -y, --layer overlay|top|bottom|background\n"
109 " Set the layer to use.\n"
107 " -f, --font <font> Set the font to use.\n" 110 " -f, --font <font> Set the font to use.\n"
108 " -h, --help Show help message and quit.\n" 111 " -h, --help Show help message and quit.\n"
109 " -l, --detailed-message Read a detailed message from stdin.\n" 112 " -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,
133 136
134 optind = 1; 137 optind = 1;
135 while (1) { 138 while (1) {
136 int c = getopt_long(argc, argv, "b:B:z:Z:c:de:f:hlL:m:o:s:t:v", opts, NULL); 139 int c = getopt_long(argc, argv, "b:B:z:Z:c:de:y:f:hlL:m:o:s:t:v", opts, NULL);
137 if (c == -1) { 140 if (c == -1) {
138 break; 141 break;
139 } 142 }
@@ -184,6 +187,24 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
184 } 187 }
185 } 188 }
186 break; 189 break;
190 case 'y': // Layer
191 if (type) {
192 if (strcmp(optarg, "background") == 0) {
193 type->layer = ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND;
194 } else if (strcmp(optarg, "bottom") == 0) {
195 type->layer = ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM;
196 } else if (strcmp(optarg, "top") == 0) {
197 type->layer = ZWLR_LAYER_SHELL_V1_LAYER_TOP;
198 } else if (strcmp(optarg, "overlay") == 0) {
199 type->layer = ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY;
200 } else {
201 fprintf(stderr, "Invalid layer: %s\n"
202 "Usage: --layer overlay|top|bottom|background\n",
203 optarg);
204 return EXIT_FAILURE;
205 }
206 }
207 break;
187 case 'f': // Font 208 case 'f': // Font
188 if (type) { 209 if (type) {
189 free(type->font); 210 free(type->font);
diff --git a/swaynag/swaynag.1.scd b/swaynag/swaynag.1.scd
index 4a03469e..1cc85db7 100644
--- a/swaynag/swaynag.1.scd
+++ b/swaynag/swaynag.1.scd
@@ -48,6 +48,9 @@ _swaynag_ [options...]
48*-e, --edge* top|bottom 48*-e, --edge* top|bottom
49 Set the edge to use. 49 Set the edge to use.
50 50
51*-y, --layer* overlay|top|bottom|background
52 Set the layer to use.
53
51*-f, --font* <font> 54*-f, --font* <font>
52 Set the font to use. 55 Set the font to use.
53 56
diff --git a/swaynag/swaynag.5.scd b/swaynag/swaynag.5.scd
index 2b583db3..3c367d0f 100644
--- a/swaynag/swaynag.5.scd
+++ b/swaynag/swaynag.5.scd
@@ -79,6 +79,9 @@ Additionally, the following options can be assigned a default per-type:
79*edge=top|bottom* 79*edge=top|bottom*
80 Set the edge to use. 80 Set the edge to use.
81 81
82*layer=overlay|top|bottom|background*
83 Set the layer to use.
84
82*font=<font>* 85*font=<font>*
83 Set the font to use. 86 Set the font to use.
84 87
diff --git a/swaynag/swaynag.c b/swaynag/swaynag.c
index 609e4831..dd17c0b0 100644
--- a/swaynag/swaynag.c
+++ b/swaynag/swaynag.c
@@ -476,7 +476,8 @@ void swaynag_setup(struct swaynag *swaynag) {
476 swaynag->layer_surface = zwlr_layer_shell_v1_get_layer_surface( 476 swaynag->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
477 swaynag->layer_shell, swaynag->surface, 477 swaynag->layer_shell, swaynag->surface,
478 swaynag->output ? swaynag->output->wl_output : NULL, 478 swaynag->output ? swaynag->output->wl_output : NULL,
479 ZWLR_LAYER_SHELL_V1_LAYER_TOP, "swaynag"); 479 swaynag->type->layer,
480 "swaynag");
480 assert(swaynag->layer_surface); 481 assert(swaynag->layer_surface);
481 zwlr_layer_surface_v1_add_listener(swaynag->layer_surface, 482 zwlr_layer_surface_v1_add_listener(swaynag->layer_surface,
482 &layer_surface_listener, swaynag); 483 &layer_surface_listener, swaynag);
diff --git a/swaynag/types.c b/swaynag/types.c
index fa045532..7bef0f87 100644
--- a/swaynag/types.c
+++ b/swaynag/types.c
@@ -26,6 +26,7 @@ struct swaynag_type *swaynag_type_new(const char *name) {
26 type->button_gap_close = -1; 26 type->button_gap_close = -1;
27 type->button_margin_right = -1; 27 type->button_margin_right = -1;
28 type->button_padding = -1; 28 type->button_padding = -1;
29 type->layer = -1;
29 return type; 30 return type;
30} 31}
31 32
@@ -35,6 +36,7 @@ void swaynag_types_add_default(list_t *types) {
35 type_defaults->anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP 36 type_defaults->anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
36 | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT 37 | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
37 | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; 38 | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
39 type_defaults->layer = ZWLR_LAYER_SHELL_V1_LAYER_TOP;
38 type_defaults->button_background = 0x333333FF; 40 type_defaults->button_background = 0x333333FF;
39 type_defaults->details_background = 0x333333FF; 41 type_defaults->details_background = 0x333333FF;
40 type_defaults->background = 0x323232FF; 42 type_defaults->background = 0x323232FF;
@@ -100,6 +102,10 @@ void swaynag_type_merge(struct swaynag_type *dest, struct swaynag_type *src) {
100 dest->anchors = src->anchors; 102 dest->anchors = src->anchors;
101 } 103 }
102 104
105 if (src->layer >= 0) {
106 dest->layer = src->layer;
107 }
108
103 // Colors 109 // Colors
104 if (src->button_background > 0) { 110 if (src->button_background > 0) {
105 dest->button_background = src->button_background; 111 dest->button_background = src->button_background;