diff options
Diffstat (limited to 'swaynag/types.c')
-rw-r--r-- | swaynag/types.c | 64 |
1 files changed, 37 insertions, 27 deletions
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 | ||
15 | struct 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 | |||
14 | void swaynag_types_add_default(list_t *types) { | 32 | void 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 | } |