aboutsummaryrefslogtreecommitdiffstats
path: root/swaynag
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-04-19 22:44:11 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2019-04-20 09:14:41 -0600
commit9099adbbe6fffcd7510b31efc8e547da7fa24f65 (patch)
tree96535c4292d14ca1e5315d387f0282f78cd7167a /swaynag
parentipc: fix criteria for emitting bar_state_update (diff)
downloadsway-9099adbbe6fffcd7510b31efc8e547da7fa24f65.tar.gz
sway-9099adbbe6fffcd7510b31efc8e547da7fa24f65.tar.zst
sway-9099adbbe6fffcd7510b31efc8e547da7fa24f65.zip
swaynag: revamp type configs
This revamps the type configs for swaynag. All sizing attributes for swaynag are now `ssize_t` instead of `uint32_t` to allow for a default value of `-1`, which allows for `0` to be a valid value. Additionally, the initialization of the type configs has been changed from a simple calloc to use a new function `swaynag_type_new`. `swaynag_type_new` calloc's the memory, checks for an allocation failure, sets the name, and all sizes to -1. The layering order has also been changed to default, general config, type config, and as highest priority command line arguments. Finally, `swaynag_type_merge` has been modified to handle the layering and sizing changes.
Diffstat (limited to 'swaynag')
-rw-r--r--swaynag/config.c7
-rw-r--r--swaynag/main.c19
-rw-r--r--swaynag/types.c64
3 files changed, 47 insertions, 43 deletions
diff --git a/swaynag/config.c b/swaynag/config.c
index fb2aa820..2fa7cb61 100644
--- a/swaynag/config.c
+++ b/swaynag/config.c
@@ -332,9 +332,7 @@ int swaynag_load_config(char *path, struct swaynag *swaynag, list_t *types) {
332 return 0; 332 return 0;
333 } 333 }
334 334
335 struct swaynag_type *type; 335 struct swaynag_type *type = swaynag_type_new("<config>");
336 type = calloc(1, sizeof(struct swaynag_type));
337 type->name = strdup("<config>");
338 list_add(types, type); 336 list_add(types, type);
339 337
340 char *line = NULL; 338 char *line = NULL;
@@ -364,8 +362,7 @@ int swaynag_load_config(char *path, struct swaynag *swaynag, list_t *types) {
364 strncat(name, line + 1, close - line - 1); 362 strncat(name, line + 1, close - line - 1);
365 type = swaynag_type_get(types, name); 363 type = swaynag_type_get(types, name);
366 if (!type) { 364 if (!type) {
367 type = calloc(1, sizeof(struct swaynag_type)); 365 type = swaynag_type_new(name);
368 type->name = strdup(name);
369 list_add(types, type); 366 list_add(types, type);
370 } 367 }
371 free(name); 368 free(name);
diff --git a/swaynag/main.c b/swaynag/main.c
index 4a785f40..542e3472 100644
--- a/swaynag/main.c
+++ b/swaynag/main.c
@@ -63,9 +63,7 @@ int main(int argc, char **argv) {
63 } 63 }
64 64
65 if (argc > 1) { 65 if (argc > 1) {
66 struct swaynag_type *type_args; 66 struct swaynag_type *type_args = swaynag_type_new("<args>");
67 type_args = calloc(1, sizeof(struct swaynag_type));
68 type_args->name = strdup("<args>");
69 list_add(types, type_args); 67 list_add(types, type_args);
70 68
71 int result = swaynag_parse_options(argc, argv, &swaynag, types, 69 int result = swaynag_parse_options(argc, argv, &swaynag, types,
@@ -86,15 +84,14 @@ int main(int argc, char **argv) {
86 swaynag.type = swaynag_type_get(types, "error"); 84 swaynag.type = swaynag_type_get(types, "error");
87 } 85 }
88 86
89 // Construct a new type using the config defaults as base, then merging 87 // Construct a new type with the defaults as the base, the general config
90 // config type defaults on top, then merging arguments on top of that, and 88 // on top of that, followed by the type config, and finally any command
91 // finally merging defaults on top. 89 // line arguments
92 struct swaynag_type *type = calloc(1, sizeof(struct swaynag_type)); 90 struct swaynag_type *type = swaynag_type_new(swaynag.type->name);
93 type->name = strdup(swaynag.type->name);
94 swaynag_type_merge(type, swaynag_type_get(types, "<args>"));
95 swaynag_type_merge(type, swaynag.type);
96 swaynag_type_merge(type, swaynag_type_get(types, "<config>"));
97 swaynag_type_merge(type, swaynag_type_get(types, "<defaults>")); 91 swaynag_type_merge(type, swaynag_type_get(types, "<defaults>"));
92 swaynag_type_merge(type, swaynag_type_get(types, "<config>"));
93 swaynag_type_merge(type, swaynag.type);
94 swaynag_type_merge(type, swaynag_type_get(types, "<args>"));
98 swaynag.type = type; 95 swaynag.type = type;
99 96
100 swaynag_types_free(types); 97 swaynag_types_free(types);
diff --git a/swaynag/types.c b/swaynag/types.c
index bc17bd33..4caaf6f7 100644
--- a/swaynag/types.c
+++ b/swaynag/types.c
@@ -6,15 +6,31 @@
6#include <string.h> 6#include <string.h>
7#include <strings.h> 7#include <strings.h>
8#include "list.h" 8#include "list.h"
9#include "log.h"
9#include "swaynag/config.h" 10#include "swaynag/config.h"
10#include "swaynag/types.h" 11#include "swaynag/types.h"
11#include "util.h" 12#include "util.h"
12#include "wlr-layer-shell-unstable-v1-client-protocol.h" 13#include "wlr-layer-shell-unstable-v1-client-protocol.h"
13 14
15struct swaynag_type *swaynag_type_new(const char *name) {
16 struct swaynag_type *type = calloc(1, sizeof(struct swaynag_type));
17 if (!type) {
18 sway_abort("Failed to allocate type: %s", name);
19 }
20 type->name = strdup(name);
21 type->bar_border_thickness = -1;
22 type->message_padding = -1;
23 type->details_border_thickness = -1;
24 type->button_border_thickness = -1;
25 type->button_gap = -1;
26 type->button_gap_close = -1;
27 type->button_margin_right = -1;
28 type->button_padding = -1;
29 return type;
30}
31
14void swaynag_types_add_default(list_t *types) { 32void swaynag_types_add_default(list_t *types) {
15 struct swaynag_type *type_defaults; 33 struct swaynag_type *type_defaults = swaynag_type_new("<defaults>");
16 type_defaults = calloc(1, sizeof(struct swaynag_type));
17 type_defaults->name = strdup("<defaults>");
18 type_defaults->font = strdup("pango:Monospace 10"); 34 type_defaults->font = strdup("pango:Monospace 10");
19 type_defaults->anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP 35 type_defaults->anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
20 | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT 36 | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
@@ -34,19 +50,15 @@ void swaynag_types_add_default(list_t *types) {
34 type_defaults->button_padding = 3; 50 type_defaults->button_padding = 3;
35 list_add(types, type_defaults); 51 list_add(types, type_defaults);
36 52
37 struct swaynag_type *type_error; 53 struct swaynag_type *type_error = swaynag_type_new("error");
38 type_error = calloc(1, sizeof(struct swaynag_type));
39 type_error->button_background = 0x680A0AFF; 54 type_error->button_background = 0x680A0AFF;
40 type_error->background = 0x900000FF; 55 type_error->background = 0x900000FF;
41 type_error->text = 0xFFFFFFFF; 56 type_error->text = 0xFFFFFFFF;
42 type_error->border = 0xD92424FF; 57 type_error->border = 0xD92424FF;
43 type_error->border_bottom = 0x470909FF; 58 type_error->border_bottom = 0x470909FF;
44 type_error->name = strdup("error");
45 list_add(types, type_error); 59 list_add(types, type_error);
46 60
47 struct swaynag_type *type_warning; 61 struct swaynag_type *type_warning = swaynag_type_new("warning");
48 type_warning = calloc(1, sizeof(struct swaynag_type));
49 type_warning->name = strdup("warning");
50 type_warning->button_background = 0xFFC100FF; 62 type_warning->button_background = 0xFFC100FF;
51 type_warning->background = 0xFFA800FF; 63 type_warning->background = 0xFFA800FF;
52 type_warning->text = 0x000000FF; 64 type_warning->text = 0x000000FF;
@@ -70,71 +82,69 @@ void swaynag_type_merge(struct swaynag_type *dest, struct swaynag_type *src) {
70 return; 82 return;
71 } 83 }
72 84
73 if (!dest->font && src->font) { 85 if (src->font) {
74 dest->font = strdup(src->font); 86 dest->font = strdup(src->font);
75 } 87 }
76 88
77 if (!dest->output && src->output) { 89 if (src->output) {
78 dest->output = strdup(src->output); 90 dest->output = strdup(src->output);
79 } 91 }
80 92
81 if (dest->anchors == 0 && src->anchors > 0) { 93 if (src->anchors > 0) {
82 dest->anchors = src->anchors; 94 dest->anchors = src->anchors;
83 } 95 }
84 96
85 // Colors 97 // Colors
86 if (dest->button_background == 0 && src->button_background > 0) { 98 if (src->button_background > 0) {
87 dest->button_background = src->button_background; 99 dest->button_background = src->button_background;
88 } 100 }
89 101
90 if (dest->background == 0 && src->background > 0) { 102 if (src->background > 0) {
91 dest->background = src->background; 103 dest->background = src->background;
92 } 104 }
93 105
94 if (dest->text == 0 && src->text > 0) { 106 if (src->text > 0) {
95 dest->text = src->text; 107 dest->text = src->text;
96 } 108 }
97 109
98 if (dest->border == 0 && src->border > 0) { 110 if (src->border > 0) {
99 dest->border = src->border; 111 dest->border = src->border;
100 } 112 }
101 113
102 if (dest->border_bottom == 0 && src->border_bottom > 0) { 114 if (src->border_bottom > 0) {
103 dest->border_bottom = src->border_bottom; 115 dest->border_bottom = src->border_bottom;
104 } 116 }
105 117
106 // Sizing 118 // Sizing
107 if (dest->bar_border_thickness == 0 && src->bar_border_thickness > 0) { 119 if (src->bar_border_thickness > -1) {
108 dest->bar_border_thickness = src->bar_border_thickness; 120 dest->bar_border_thickness = src->bar_border_thickness;
109 } 121 }
110 122
111 if (dest->message_padding == 0 && src->message_padding > 0) { 123 if (src->message_padding > -1) {
112 dest->message_padding = src->message_padding; 124 dest->message_padding = src->message_padding;
113 } 125 }
114 126
115 if (dest->details_border_thickness == 0 127 if (src->details_border_thickness > -1) {
116 && src->details_border_thickness > 0) {
117 dest->details_border_thickness = src->details_border_thickness; 128 dest->details_border_thickness = src->details_border_thickness;
118 } 129 }
119 130
120 if (dest->button_border_thickness == 0 131 if (src->button_border_thickness > -1) {
121 && src->button_border_thickness > 0) {
122 dest->button_border_thickness = src->button_border_thickness; 132 dest->button_border_thickness = src->button_border_thickness;
123 } 133 }
124 134
125 if (dest->button_gap == 0 && src->button_gap > 0) { 135 if (src->button_gap > -1) {
126 dest->button_gap = src->button_gap; 136 dest->button_gap = src->button_gap;
127 } 137 }
128 138
129 if (dest->button_gap_close == 0 && src->button_gap_close > 0) { 139 if (src->button_gap_close > -1) {
130 dest->button_gap_close = src->button_gap_close; 140 dest->button_gap_close = src->button_gap_close;
131 } 141 }
132 142
133 if (dest->button_margin_right == 0 && src->button_margin_right > 0) { 143 if (src->button_margin_right > -1) {
134 dest->button_margin_right = src->button_margin_right; 144 dest->button_margin_right = src->button_margin_right;
135 } 145 }
136 146
137 if (dest->button_padding == 0 && src->button_padding > 0) { 147 if (src->button_padding > -1) {
138 dest->button_padding = src->button_padding; 148 dest->button_padding = src->button_padding;
139 } 149 }
140} 150}