diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2018-07-29 22:42:03 -0400 |
---|---|---|
committer | Brian Ashworth <bosrsf04@gmail.com> | 2018-08-01 22:47:54 -0400 |
commit | e01acb6097b583fcf2f6d0e0afe1bd878dd9b683 (patch) | |
tree | cf3e715870bb22d9ef7d5bee9457fdcc70e31ee2 /swaynag/types.c | |
parent | swaynag: add math to meson.build (diff) | |
download | sway-e01acb6097b583fcf2f6d0e0afe1bd878dd9b683.tar.gz sway-e01acb6097b583fcf2f6d0e0afe1bd878dd9b683.tar.zst sway-e01acb6097b583fcf2f6d0e0afe1bd878dd9b683.zip |
swaynag: allow more config options
Diffstat (limited to 'swaynag/types.c')
-rw-r--r-- | swaynag/types.c | 150 |
1 files changed, 92 insertions, 58 deletions
diff --git a/swaynag/types.c b/swaynag/types.c index c92d0e89..f429baf0 100644 --- a/swaynag/types.c +++ b/swaynag/types.c | |||
@@ -9,8 +9,26 @@ | |||
9 | #include "swaynag/config.h" | 9 | #include "swaynag/config.h" |
10 | #include "swaynag/types.h" | 10 | #include "swaynag/types.h" |
11 | #include "util.h" | 11 | #include "util.h" |
12 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" | ||
12 | 13 | ||
13 | void swaynag_types_add_default(list_t *types) { | 14 | void swaynag_types_add_default(list_t *types) { |
15 | struct swaynag_type *type_defaults; | ||
16 | type_defaults = calloc(1, sizeof(struct swaynag_type)); | ||
17 | type_defaults->name = strdup("<defaults>"); | ||
18 | type_defaults->font = strdup("pango:Monospace 10"); | ||
19 | type_defaults->anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ||
20 | | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ||
21 | | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; | ||
22 | type_defaults->bar_border_thickness = 2; | ||
23 | type_defaults->message_padding = 8; | ||
24 | type_defaults->details_border_thickness = 3; | ||
25 | type_defaults->button_border_thickness = 3; | ||
26 | type_defaults->button_gap = 20; | ||
27 | type_defaults->button_gap_close = 15; | ||
28 | type_defaults->button_margin_right = 2; | ||
29 | type_defaults->button_padding = 3; | ||
30 | list_add(types, type_defaults); | ||
31 | |||
14 | struct swaynag_type *type_error; | 32 | struct swaynag_type *type_error; |
15 | type_error = calloc(1, sizeof(struct swaynag_type)); | 33 | type_error = calloc(1, sizeof(struct swaynag_type)); |
16 | type_error->name = strdup("error"); | 34 | type_error->name = strdup("error"); |
@@ -42,20 +60,84 @@ struct swaynag_type *swaynag_type_get(list_t *types, char *name) { | |||
42 | return NULL; | 60 | return NULL; |
43 | } | 61 | } |
44 | 62 | ||
45 | struct swaynag_type *swaynag_type_clone(struct swaynag_type *type) { | 63 | void swaynag_type_merge(struct swaynag_type *dest, struct swaynag_type *src) { |
46 | struct swaynag_type *clone; | 64 | if (!dest || !src) { |
47 | clone = calloc(1, sizeof(struct swaynag_type)); | 65 | return; |
48 | clone->name = strdup(type->name); | 66 | } |
49 | clone->button_background = type->button_background; | 67 | |
50 | clone->background = type->background; | 68 | if (!dest->font && src->font) { |
51 | clone->text = type->text; | 69 | dest->font = strdup(src->font); |
52 | clone->border = type->border; | 70 | } |
53 | clone->border_bottom = type->border_bottom; | 71 | |
54 | return clone; | 72 | if (!dest->output && src->output) { |
73 | dest->output = strdup(src->output); | ||
74 | } | ||
75 | |||
76 | if (dest->anchors == 0 && src->anchors > 0) { | ||
77 | dest->anchors = src->anchors; | ||
78 | } | ||
79 | |||
80 | // Colors | ||
81 | if (dest->button_background == 0 && src->button_background > 0) { | ||
82 | dest->button_background = src->button_background; | ||
83 | } | ||
84 | |||
85 | if (dest->background == 0 && src->background > 0) { | ||
86 | dest->background = src->background; | ||
87 | } | ||
88 | |||
89 | if (dest->text == 0 && src->text > 0) { | ||
90 | dest->text = src->text; | ||
91 | } | ||
92 | |||
93 | if (dest->border == 0 && src->border > 0) { | ||
94 | dest->border = src->border; | ||
95 | } | ||
96 | |||
97 | if (dest->border_bottom == 0 && src->border_bottom > 0) { | ||
98 | dest->border_bottom = src->border_bottom; | ||
99 | } | ||
100 | |||
101 | // Sizing | ||
102 | if (dest->bar_border_thickness == 0 && src->bar_border_thickness > 0) { | ||
103 | dest->bar_border_thickness = src->bar_border_thickness; | ||
104 | } | ||
105 | |||
106 | if (dest->message_padding == 0 && src->message_padding > 0) { | ||
107 | dest->message_padding = src->message_padding; | ||
108 | } | ||
109 | |||
110 | if (dest->details_border_thickness == 0 | ||
111 | && src->details_border_thickness > 0) { | ||
112 | dest->details_border_thickness = src->details_border_thickness; | ||
113 | } | ||
114 | |||
115 | if (dest->button_border_thickness == 0 | ||
116 | && src->button_border_thickness > 0) { | ||
117 | dest->button_border_thickness = src->button_border_thickness; | ||
118 | } | ||
119 | |||
120 | if (dest->button_gap == 0 && src->button_gap > 0) { | ||
121 | dest->button_gap = src->button_gap; | ||
122 | } | ||
123 | |||
124 | if (dest->button_gap_close == 0 && src->button_gap_close > 0) { | ||
125 | dest->button_gap_close = src->button_gap_close; | ||
126 | } | ||
127 | |||
128 | if (dest->button_margin_right == 0 && src->button_margin_right > 0) { | ||
129 | dest->button_margin_right = src->button_margin_right; | ||
130 | } | ||
131 | |||
132 | if (dest->button_padding == 0 && src->button_padding > 0) { | ||
133 | dest->button_padding = src->button_padding; | ||
134 | } | ||
55 | } | 135 | } |
56 | 136 | ||
57 | void swaynag_type_free(struct swaynag_type *type) { | 137 | void swaynag_type_free(struct swaynag_type *type) { |
58 | free(type->name); | 138 | free(type->name); |
139 | free(type->font); | ||
140 | free(type->output); | ||
59 | free(type); | 141 | free(type); |
60 | } | 142 | } |
61 | 143 | ||
@@ -67,51 +149,3 @@ void swaynag_types_free(list_t *types) { | |||
67 | } | 149 | } |
68 | list_free(types); | 150 | list_free(types); |
69 | } | 151 | } |
70 | |||
71 | int swaynag_parse_type(int argc, char **argv, struct swaynag_type *type) { | ||
72 | enum color_option { | ||
73 | COLOR_BACKGROUND, | ||
74 | COLOR_BORDER, | ||
75 | COLOR_BORDER_BOTTOM, | ||
76 | COLOR_BUTTON, | ||
77 | COLOR_TEXT, | ||
78 | }; | ||
79 | |||
80 | static struct option opts[] = { | ||
81 | {"background", required_argument, NULL, COLOR_BACKGROUND}, | ||
82 | {"border", required_argument, NULL, COLOR_BORDER}, | ||
83 | {"border-bottom", required_argument, NULL, COLOR_BORDER_BOTTOM}, | ||
84 | {"button-background", required_argument, NULL, COLOR_BUTTON}, | ||
85 | {"text", required_argument, NULL, COLOR_TEXT}, | ||
86 | {0, 0, 0, 0} | ||
87 | }; | ||
88 | |||
89 | optind = 1; | ||
90 | while (1) { | ||
91 | int c = getopt_long(argc, argv, "", opts, NULL); | ||
92 | if (c == -1) { | ||
93 | break; | ||
94 | } | ||
95 | switch (c) { | ||
96 | case COLOR_BACKGROUND: | ||
97 | type->background = parse_color(optarg); | ||
98 | break; | ||
99 | case COLOR_BORDER: | ||
100 | type->border = parse_color(optarg); | ||
101 | break; | ||
102 | case COLOR_BORDER_BOTTOM: | ||
103 | type->border_bottom = parse_color(optarg); | ||
104 | break; | ||
105 | case COLOR_BUTTON: | ||
106 | type->button_background = parse_color(optarg); | ||
107 | break; | ||
108 | case COLOR_TEXT: | ||
109 | type->text = parse_color(optarg); | ||
110 | break; | ||
111 | default: | ||
112 | break; | ||
113 | } | ||
114 | } | ||
115 | return 0; | ||
116 | } | ||
117 | |||