mirror of
https://github.com/swaywm/sway.git
synced 2026-03-21 05:33:56 -04:00
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.
This commit is contained in:
parent
59d9a991b4
commit
9099adbbe6
4 changed files with 59 additions and 51 deletions
|
|
@ -63,9 +63,7 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
if (argc > 1) {
|
||||
struct swaynag_type *type_args;
|
||||
type_args = calloc(1, sizeof(struct swaynag_type));
|
||||
type_args->name = strdup("<args>");
|
||||
struct swaynag_type *type_args = swaynag_type_new("<args>");
|
||||
list_add(types, type_args);
|
||||
|
||||
int result = swaynag_parse_options(argc, argv, &swaynag, types,
|
||||
|
|
@ -86,15 +84,14 @@ int main(int argc, char **argv) {
|
|||
swaynag.type = swaynag_type_get(types, "error");
|
||||
}
|
||||
|
||||
// Construct a new type using the config defaults as base, then merging
|
||||
// config type defaults on top, then merging arguments on top of that, and
|
||||
// finally merging defaults on top.
|
||||
struct swaynag_type *type = calloc(1, sizeof(struct swaynag_type));
|
||||
type->name = strdup(swaynag.type->name);
|
||||
swaynag_type_merge(type, swaynag_type_get(types, "<args>"));
|
||||
swaynag_type_merge(type, swaynag.type);
|
||||
swaynag_type_merge(type, swaynag_type_get(types, "<config>"));
|
||||
// Construct a new type with the defaults as the base, the general config
|
||||
// on top of that, followed by the type config, and finally any command
|
||||
// line arguments
|
||||
struct swaynag_type *type = swaynag_type_new(swaynag.type->name);
|
||||
swaynag_type_merge(type, swaynag_type_get(types, "<defaults>"));
|
||||
swaynag_type_merge(type, swaynag_type_get(types, "<config>"));
|
||||
swaynag_type_merge(type, swaynag.type);
|
||||
swaynag_type_merge(type, swaynag_type_get(types, "<args>"));
|
||||
swaynag.type = type;
|
||||
|
||||
swaynag_types_free(types);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue