swaynag: adds option to separately specify the text color for buttons

This commit is contained in:
oliver-giersch 2020-09-02 15:03:48 +02:00 committed by Simon Ser
parent 08095e99f3
commit a543fa35ff
6 changed files with 50 additions and 27 deletions

View file

@ -9,6 +9,7 @@ struct swaynag_type {
uint32_t anchors; uint32_t anchors;
// Colors // Colors
uint32_t button_text;
uint32_t button_background; uint32_t button_background;
uint32_t background; uint32_t background;
uint32_t text; uint32_t text;

View file

@ -39,6 +39,7 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
TO_COLOR_BORDER_BOTTOM, TO_COLOR_BORDER_BOTTOM,
TO_COLOR_BUTTON, TO_COLOR_BUTTON,
TO_COLOR_TEXT, TO_COLOR_TEXT,
TO_COLOR_BUTTON_TEXT,
TO_THICK_BAR_BORDER, TO_THICK_BAR_BORDER,
TO_PADDING_MESSAGE, TO_PADDING_MESSAGE,
TO_THICK_DET_BORDER, TO_THICK_DET_BORDER,
@ -72,6 +73,7 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
{"border-bottom", required_argument, NULL, TO_COLOR_BORDER_BOTTOM}, {"border-bottom", required_argument, NULL, TO_COLOR_BORDER_BOTTOM},
{"button-background", required_argument, NULL, TO_COLOR_BUTTON}, {"button-background", required_argument, NULL, TO_COLOR_BUTTON},
{"text", required_argument, NULL, TO_COLOR_TEXT}, {"text", required_argument, NULL, TO_COLOR_TEXT},
{"button-text", required_argument, NULL, TO_COLOR_BUTTON_TEXT},
{"border-bottom-size", required_argument, NULL, TO_THICK_BAR_BORDER}, {"border-bottom-size", required_argument, NULL, TO_THICK_BAR_BORDER},
{"message-padding", required_argument, NULL, TO_PADDING_MESSAGE}, {"message-padding", required_argument, NULL, TO_PADDING_MESSAGE},
{"details-border-size", required_argument, NULL, TO_THICK_DET_BORDER}, {"details-border-size", required_argument, NULL, TO_THICK_DET_BORDER},
@ -116,6 +118,7 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
" --border-bottom RRGGBB[AA] Bottom border color.\n" " --border-bottom RRGGBB[AA] Bottom border color.\n"
" --button-background RRGGBB[AA] Button background color.\n" " --button-background RRGGBB[AA] Button background color.\n"
" --text RRGGBB[AA] Text color.\n" " --text RRGGBB[AA] Text color.\n"
" --button-text RRGGBB[AA] Button text color.\n"
" --border-bottom-size size Thickness of the bar border.\n" " --border-bottom-size size Thickness of the bar border.\n"
" --message-padding padding Padding for the message.\n" " --message-padding padding Padding for the message.\n"
" --details-border-size size Thickness for the details border.\n" " --details-border-size size Thickness for the details border.\n"
@ -255,6 +258,11 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag,
fprintf(stderr, "Invalid text color: %s", optarg); fprintf(stderr, "Invalid text color: %s", optarg);
} }
break; break;
case TO_COLOR_BUTTON_TEXT: // Button text color
if (type && !parse_color(optarg, &type->button_text)) {
fprintf(stderr, "Invalid button text color: %s", optarg);
}
break;
case TO_THICK_BAR_BORDER: // Bottom border thickness case TO_THICK_BAR_BORDER: // Bottom border thickness
if (type) { if (type) {
type->bar_border_thickness = strtol(optarg, NULL, 0); type->bar_border_thickness = strtol(optarg, NULL, 0);

View file

@ -47,7 +47,7 @@ static void render_details_scroll_button(cairo_t *cairo,
button->width - (border * 2), button->height - (border * 2)); button->width - (border * 2), button->height - (border * 2));
cairo_fill(cairo); cairo_fill(cairo);
cairo_set_source_u32(cairo, swaynag->type->text); cairo_set_source_u32(cairo, swaynag->type->button_text);
cairo_move_to(cairo, button->x + border + padding, cairo_move_to(cairo, button->x + border + padding,
button->y + border + (button->height - text_height) / 2); button->y + border + (button->height - text_height) / 2);
pango_printf(cairo, swaynag->type->font, swaynag->scale, true, pango_printf(cairo, swaynag->type->font, swaynag->scale, true,
@ -199,7 +199,7 @@ static uint32_t render_button(cairo_t *cairo, struct swaynag *swaynag,
button->width, button->height); button->width, button->height);
cairo_fill(cairo); cairo_fill(cairo);
cairo_set_source_u32(cairo, swaynag->type->text); cairo_set_source_u32(cairo, swaynag->type->button_text);
cairo_move_to(cairo, button->x + padding, button->y + padding); cairo_move_to(cairo, button->x + padding, button->y + padding);
pango_printf(cairo, swaynag->type->font, swaynag->scale, true, pango_printf(cairo, swaynag->type->font, swaynag->scale, true,
"%s", button->text); "%s", button->text);

View file

@ -97,6 +97,9 @@ _swaynag_ [options...]
*--text* <RRGGBB[AA]> *--text* <RRGGBB[AA]>
Set the text color. Set the text color.
*--button-text* <RRGGBB[AA]>
Set the button text color.
*--border-bottom-size* <size> *--border-bottom-size* <size>
Set the thickness of the bottom border. Set the thickness of the bottom border.

View file

@ -42,6 +42,9 @@ colors can be set:
*text=<color>* *text=<color>*
The color of the text. The color of the text.
*button-text=<color>*
The color of the button text.
The following sizing options can also be set: The following sizing options can also be set:
*border-bottom-size=<size>* *border-bottom-size=<size>*

View file

@ -38,6 +38,7 @@ void swaynag_types_add_default(list_t *types) {
type_defaults->button_background = 0x333333FF; type_defaults->button_background = 0x333333FF;
type_defaults->background = 0x323232FF; type_defaults->background = 0x323232FF;
type_defaults->text = 0xFFFFFFFF; type_defaults->text = 0xFFFFFFFF;
type_defaults->button_text = 0xFFFFFFFF;
type_defaults->border = 0x222222FF; type_defaults->border = 0x222222FF;
type_defaults->border_bottom = 0x444444FF; type_defaults->border_bottom = 0x444444FF;
type_defaults->bar_border_thickness = 2; type_defaults->bar_border_thickness = 2;
@ -54,6 +55,7 @@ void swaynag_types_add_default(list_t *types) {
type_error->button_background = 0x680A0AFF; type_error->button_background = 0x680A0AFF;
type_error->background = 0x900000FF; type_error->background = 0x900000FF;
type_error->text = 0xFFFFFFFF; type_error->text = 0xFFFFFFFF;
type_error->button_text = 0xFFFFFFFF;
type_error->border = 0xD92424FF; type_error->border = 0xD92424FF;
type_error->border_bottom = 0x470909FF; type_error->border_bottom = 0x470909FF;
list_add(types, type_error); list_add(types, type_error);
@ -62,6 +64,7 @@ void swaynag_types_add_default(list_t *types) {
type_warning->button_background = 0xFFC100FF; type_warning->button_background = 0xFFC100FF;
type_warning->background = 0xFFA800FF; type_warning->background = 0xFFA800FF;
type_warning->text = 0x000000FF; type_warning->text = 0x000000FF;
type_warning->button_text = 0x000000FF;
type_warning->border = 0xAB7100FF; type_warning->border = 0xAB7100FF;
type_warning->border_bottom = 0xAB7100FF; type_warning->border_bottom = 0xAB7100FF;
list_add(types, type_warning); list_add(types, type_warning);
@ -107,6 +110,11 @@ void swaynag_type_merge(struct swaynag_type *dest, struct swaynag_type *src) {
dest->text = src->text; dest->text = src->text;
} }
if (src->button_text > 0) {
dest->button_text = src->button_text;
}
if (src->border > 0) { if (src->border > 0) {
dest->border = src->border; dest->border = src->border;
} }