2018-07-28 15:34:25 +02:00
|
|
|
#include <getopt.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <strings.h>
|
|
|
|
#include "list.h"
|
2019-04-20 04:44:11 +02:00
|
|
|
#include "log.h"
|
2018-07-29 04:56:12 +02:00
|
|
|
#include "swaynag/config.h"
|
2018-07-28 15:34:25 +02:00
|
|
|
#include "swaynag/types.h"
|
|
|
|
#include "util.h"
|
2018-07-30 04:42:03 +02:00
|
|
|
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
|
2018-07-28 15:34:25 +02:00
|
|
|
|
2019-04-20 04:44:11 +02:00
|
|
|
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;
|
2021-03-17 16:55:21 +01:00
|
|
|
type->layer = -1;
|
2019-04-20 04:44:11 +02:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2018-07-29 05:15:12 +02:00
|
|
|
void swaynag_types_add_default(list_t *types) {
|
2019-04-20 04:44:11 +02:00
|
|
|
struct swaynag_type *type_defaults = swaynag_type_new("<defaults>");
|
2022-12-21 11:22:21 +01:00
|
|
|
type_defaults->font_description =
|
2022-12-21 11:19:04 +01:00
|
|
|
pango_font_description_from_string("pango:Monospace 10");
|
2018-07-30 04:42:03 +02:00
|
|
|
type_defaults->anchors = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP
|
|
|
|
| ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
|
|
|
|
| ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
|
2021-03-17 16:55:21 +01:00
|
|
|
type_defaults->layer = ZWLR_LAYER_SHELL_V1_LAYER_TOP;
|
2018-07-30 20:14:16 +02:00
|
|
|
type_defaults->button_background = 0x333333FF;
|
2020-09-09 04:43:35 +02:00
|
|
|
type_defaults->details_background = 0x333333FF;
|
2018-07-30 20:14:16 +02:00
|
|
|
type_defaults->background = 0x323232FF;
|
2018-07-30 19:52:02 +02:00
|
|
|
type_defaults->text = 0xFFFFFFFF;
|
2020-09-02 15:03:48 +02:00
|
|
|
type_defaults->button_text = 0xFFFFFFFF;
|
2018-07-30 20:14:16 +02:00
|
|
|
type_defaults->border = 0x222222FF;
|
|
|
|
type_defaults->border_bottom = 0x444444FF;
|
2018-07-30 04:42:03 +02:00
|
|
|
type_defaults->bar_border_thickness = 2;
|
|
|
|
type_defaults->message_padding = 8;
|
|
|
|
type_defaults->details_border_thickness = 3;
|
|
|
|
type_defaults->button_border_thickness = 3;
|
|
|
|
type_defaults->button_gap = 20;
|
|
|
|
type_defaults->button_gap_close = 15;
|
|
|
|
type_defaults->button_margin_right = 2;
|
|
|
|
type_defaults->button_padding = 3;
|
|
|
|
list_add(types, type_defaults);
|
|
|
|
|
2019-04-20 04:44:11 +02:00
|
|
|
struct swaynag_type *type_error = swaynag_type_new("error");
|
2018-07-30 20:14:16 +02:00
|
|
|
type_error->button_background = 0x680A0AFF;
|
2020-09-09 04:43:35 +02:00
|
|
|
type_error->details_background = 0x680A0AFF;
|
2018-07-30 20:14:16 +02:00
|
|
|
type_error->background = 0x900000FF;
|
|
|
|
type_error->text = 0xFFFFFFFF;
|
2020-09-02 15:03:48 +02:00
|
|
|
type_error->button_text = 0xFFFFFFFF;
|
2018-07-30 20:14:16 +02:00
|
|
|
type_error->border = 0xD92424FF;
|
|
|
|
type_error->border_bottom = 0x470909FF;
|
2018-07-28 15:34:25 +02:00
|
|
|
list_add(types, type_error);
|
|
|
|
|
2019-04-20 04:44:11 +02:00
|
|
|
struct swaynag_type *type_warning = swaynag_type_new("warning");
|
2018-07-28 15:34:25 +02:00
|
|
|
type_warning->button_background = 0xFFC100FF;
|
2020-09-09 04:43:35 +02:00
|
|
|
type_warning->details_background = 0xFFC100FF;
|
2018-07-28 15:34:25 +02:00
|
|
|
type_warning->background = 0xFFA800FF;
|
|
|
|
type_warning->text = 0x000000FF;
|
2020-09-02 15:03:48 +02:00
|
|
|
type_warning->button_text = 0x000000FF;
|
2018-07-28 15:34:25 +02:00
|
|
|
type_warning->border = 0xAB7100FF;
|
|
|
|
type_warning->border_bottom = 0xAB7100FF;
|
|
|
|
list_add(types, type_warning);
|
|
|
|
}
|
|
|
|
|
2018-07-29 05:15:12 +02:00
|
|
|
struct swaynag_type *swaynag_type_get(list_t *types, char *name) {
|
2018-07-28 15:34:25 +02:00
|
|
|
for (int i = 0; i < types->length; i++) {
|
2018-07-29 05:15:12 +02:00
|
|
|
struct swaynag_type *type = types->items[i];
|
2018-07-28 15:34:25 +02:00
|
|
|
if (strcasecmp(type->name, name) == 0) {
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:42:03 +02:00
|
|
|
void swaynag_type_merge(struct swaynag_type *dest, struct swaynag_type *src) {
|
|
|
|
if (!dest || !src) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-21 11:22:21 +01:00
|
|
|
if (src->font_description) {
|
|
|
|
dest->font_description = pango_font_description_copy(src->font_description);
|
|
|
|
}
|
|
|
|
|
2019-04-20 04:44:11 +02:00
|
|
|
if (src->output) {
|
2018-07-30 04:42:03 +02:00
|
|
|
dest->output = strdup(src->output);
|
|
|
|
}
|
|
|
|
|
2019-04-20 04:44:11 +02:00
|
|
|
if (src->anchors > 0) {
|
2018-07-30 04:42:03 +02:00
|
|
|
dest->anchors = src->anchors;
|
|
|
|
}
|
|
|
|
|
2021-03-17 16:55:21 +01:00
|
|
|
if (src->layer >= 0) {
|
|
|
|
dest->layer = src->layer;
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:42:03 +02:00
|
|
|
// Colors
|
2019-04-20 04:44:11 +02:00
|
|
|
if (src->button_background > 0) {
|
2018-07-30 04:42:03 +02:00
|
|
|
dest->button_background = src->button_background;
|
|
|
|
}
|
|
|
|
|
2020-09-09 04:43:35 +02:00
|
|
|
if (src->details_background > 0) {
|
|
|
|
dest->details_background = src->details_background;
|
|
|
|
}
|
|
|
|
|
2019-04-20 04:44:11 +02:00
|
|
|
if (src->background > 0) {
|
2018-07-30 04:42:03 +02:00
|
|
|
dest->background = src->background;
|
|
|
|
}
|
|
|
|
|
2019-04-20 04:44:11 +02:00
|
|
|
if (src->text > 0) {
|
2018-07-30 04:42:03 +02:00
|
|
|
dest->text = src->text;
|
|
|
|
}
|
|
|
|
|
2020-09-02 15:03:48 +02:00
|
|
|
if (src->button_text > 0) {
|
|
|
|
dest->button_text = src->button_text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-20 04:44:11 +02:00
|
|
|
if (src->border > 0) {
|
2018-07-30 04:42:03 +02:00
|
|
|
dest->border = src->border;
|
|
|
|
}
|
|
|
|
|
2019-04-20 04:44:11 +02:00
|
|
|
if (src->border_bottom > 0) {
|
2018-07-30 04:42:03 +02:00
|
|
|
dest->border_bottom = src->border_bottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sizing
|
2019-04-20 04:44:11 +02:00
|
|
|
if (src->bar_border_thickness > -1) {
|
2018-07-30 04:42:03 +02:00
|
|
|
dest->bar_border_thickness = src->bar_border_thickness;
|
|
|
|
}
|
|
|
|
|
2019-04-20 04:44:11 +02:00
|
|
|
if (src->message_padding > -1) {
|
2018-07-30 04:42:03 +02:00
|
|
|
dest->message_padding = src->message_padding;
|
|
|
|
}
|
|
|
|
|
2019-04-20 04:44:11 +02:00
|
|
|
if (src->details_border_thickness > -1) {
|
2018-07-30 04:42:03 +02:00
|
|
|
dest->details_border_thickness = src->details_border_thickness;
|
|
|
|
}
|
|
|
|
|
2019-04-20 04:44:11 +02:00
|
|
|
if (src->button_border_thickness > -1) {
|
2018-07-30 04:42:03 +02:00
|
|
|
dest->button_border_thickness = src->button_border_thickness;
|
|
|
|
}
|
|
|
|
|
2019-04-20 04:44:11 +02:00
|
|
|
if (src->button_gap > -1) {
|
2018-07-30 04:42:03 +02:00
|
|
|
dest->button_gap = src->button_gap;
|
|
|
|
}
|
|
|
|
|
2019-04-20 04:44:11 +02:00
|
|
|
if (src->button_gap_close > -1) {
|
2018-07-30 04:42:03 +02:00
|
|
|
dest->button_gap_close = src->button_gap_close;
|
|
|
|
}
|
|
|
|
|
2019-04-20 04:44:11 +02:00
|
|
|
if (src->button_margin_right > -1) {
|
2018-07-30 04:42:03 +02:00
|
|
|
dest->button_margin_right = src->button_margin_right;
|
|
|
|
}
|
|
|
|
|
2019-04-20 04:44:11 +02:00
|
|
|
if (src->button_padding > -1) {
|
2018-07-30 04:42:03 +02:00
|
|
|
dest->button_padding = src->button_padding;
|
|
|
|
}
|
2018-07-28 15:34:25 +02:00
|
|
|
}
|
|
|
|
|
2018-07-29 05:15:12 +02:00
|
|
|
void swaynag_type_free(struct swaynag_type *type) {
|
2018-07-28 15:34:25 +02:00
|
|
|
free(type->name);
|
2022-12-21 11:22:21 +01:00
|
|
|
pango_font_description_free(type->font_description);
|
2018-07-30 04:42:03 +02:00
|
|
|
free(type->output);
|
2018-07-28 15:34:25 +02:00
|
|
|
free(type);
|
|
|
|
}
|
|
|
|
|
2018-07-29 05:15:12 +02:00
|
|
|
void swaynag_types_free(list_t *types) {
|
2018-12-09 00:55:14 +01:00
|
|
|
for (int i = 0; i < types->length; ++i) {
|
|
|
|
swaynag_type_free(types->items[i]);
|
2018-07-28 15:34:25 +02:00
|
|
|
}
|
|
|
|
list_free(types);
|
|
|
|
}
|