diff options
author | Brian Ashworth <[email protected]> | 2019-04-19 22:44:11 -0400 |
---|---|---|
committer | Drew DeVault <[email protected]> | 2019-04-20 09:14:41 -0600 |
commit | 9099adbbe6fffcd7510b31efc8e547da7fa24f65 (patch) | |
tree | 96535c4292d14ca1e5315d387f0282f78cd7167a /swaynag/types.c | |
parent | 59d9a991b425f7cf1ea05a1def7632fa4395c5a7 (diff) |
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/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 @@ #include <string.h> #include <strings.h> #include "list.h" +#include "log.h" #include "swaynag/config.h" #include "swaynag/types.h" #include "util.h" #include "wlr-layer-shell-unstable-v1-client-protocol.h" +struct swaynag_type *swaynag_type_new(const char *name) { + struct swaynag_type *type = calloc(1, sizeof(struct swaynag_type)); + if (!type) { + sway_abort("Failed to allocate type: %s", name); + } + type->name = strdup(name); + type->bar_border_thickness = -1; + type->message_padding = -1; + type->details_border_thickness = -1; + type->button_border_thickness = -1; + type->button_gap = -1; + type->button_gap_close = -1; + type->button_margin_right = -1; + type->button_padding = -1; + return type; +} + void swaynag_types_add_default(list_t *types) { - struct swaynag_type *type_defaults; - type_defaults = calloc(1, sizeof(struct swaynag_type)); - type_defaults->name = strdup("<defaults>"); + struct swaynag_type *type_defaults = swaynag_type_new("<defaults>"); type_defaults->font = strdup("pango:Monospace 10"); type_defaults->anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT @@ -34,19 +50,15 @@ void swaynag_types_add_default(list_t *types) { type_defaults->button_padding = 3; list_add(types, type_defaults); - struct swaynag_type *type_error; - type_error = calloc(1, sizeof(struct swaynag_type)); + struct swaynag_type *type_error = swaynag_type_new("error"); type_error->button_background = 0x680A0AFF; type_error->background = 0x900000FF; type_error->text = 0xFFFFFFFF; type_error->border = 0xD92424FF; type_error->border_bottom = 0x470909FF; - type_error->name = strdup("error"); list_add(types, type_error); - struct swaynag_type *type_warning; - type_warning = calloc(1, sizeof(struct swaynag_type)); - type_warning->name = strdup("warning"); + struct swaynag_type *type_warning = swaynag_type_new("warning"); type_warning->button_background = 0xFFC100FF; type_warning->background = 0xFFA800FF; type_warning->text = 0x000000FF; @@ -70,71 +82,69 @@ void swaynag_type_merge(struct swaynag_type *dest, struct swaynag_type *src) { return; } - if (!dest->font && src->font) { + if (src->font) { dest->font = strdup(src->font); } - if (!dest->output && src->output) { + if (src->output) { dest->output = strdup(src->output); } - if (dest->anchors == 0 && src->anchors > 0) { + if (src->anchors > 0) { dest->anchors = src->anchors; } // Colors - if (dest->button_background == 0 && src->button_background > 0) { + if (src->button_background > 0) { dest->button_background = src->button_background; } - if (dest->background == 0 && src->background > 0) { + if (src->background > 0) { dest->background = src->background; } - if (dest->text == 0 && src->text > 0) { + if (src->text > 0) { dest->text = src->text; } - if (dest->border == 0 && src->border > 0) { + if (src->border > 0) { dest->border = src->border; } - if (dest->border_bottom == 0 && src->border_bottom > 0) { + if (src->border_bottom > 0) { dest->border_bottom = src->border_bottom; } // Sizing - if (dest->bar_border_thickness == 0 && src->bar_border_thickness > 0) { + if (src->bar_border_thickness > -1) { dest->bar_border_thickness = src->bar_border_thickness; } - if (dest->message_padding == 0 && src->message_padding > 0) { + if (src->message_padding > -1) { dest->message_padding = src->message_padding; } - if (dest->details_border_thickness == 0 - && src->details_border_thickness > 0) { + if (src->details_border_thickness > -1) { dest->details_border_thickness = src->details_border_thickness; } - if (dest->button_border_thickness == 0 - && src->button_border_thickness > 0) { + if (src->button_border_thickness > -1) { dest->button_border_thickness = src->button_border_thickness; } - if (dest->button_gap == 0 && src->button_gap > 0) { + if (src->button_gap > -1) { dest->button_gap = src->button_gap; } - if (dest->button_gap_close == 0 && src->button_gap_close > 0) { + if (src->button_gap_close > -1) { dest->button_gap_close = src->button_gap_close; } - if (dest->button_margin_right == 0 && src->button_margin_right > 0) { + if (src->button_margin_right > -1) { dest->button_margin_right = src->button_margin_right; } - if (dest->button_padding == 0 && src->button_padding > 0) { + if (src->button_padding > -1) { dest->button_padding = src->button_padding; } } |