summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@blame.services>2021-09-20 19:57:12 +0200
committerDave Davenport <qball@blame.services>2021-09-20 19:57:12 +0200
commit4face975a988a9118da6b5b86f0d944c81b2a4af (patch)
tree911696af8a9dbe826cdfcc4f51517ab55d998d44
parentabe4d2d85e890e9cf7b3e53fa5f109651e97b5b0 (diff)
[Theme] Print known colors as color name.
When printing look if the set color has a known color name, print this.
-rw-r--r--Makefile.am8
-rw-r--r--lexer/theme-lexer.l1
-rw-r--r--meson.build11
-rw-r--r--source/theme.c35
4 files changed, 42 insertions, 13 deletions
diff --git a/Makefile.am b/Makefile.am
index 0a4359cc..9b6aadc3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -348,6 +348,7 @@ helper_pidfile_SOURCES=\
include/mode-private.h\
source/helper.c\
source/theme.c\
+ source/css-colors.c\
source/rofi-types.c\
include/rofi-types.h\
include/helper.h\
@@ -468,6 +469,7 @@ helper_test_SOURCES=\
include/xrmoptions.h\
source/xrmoptions.c\
source/theme.c\
+ source/css-colors.c\
source/rofi-types.c\
include/rofi-types.h\
test/helper-test.c
@@ -505,6 +507,7 @@ helper_expand_SOURCES=\
include/mode-private.h\
source/helper.c\
source/theme.c\
+ source/css-colors.c\
include/helper.h\
include/helper-theme.h\
include/xrmoptions.h\
@@ -527,6 +530,7 @@ helper_config_cmdline_parser_SOURCES=\
include/mode-private.h\
source/helper.c\
source/theme.c\
+ source/css-colors.c\
source/rofi-types.c\
include/rofi-types.h\
include/helper.h\
@@ -544,7 +548,8 @@ mode_test_SOURCES=\
source/dialogs/help-keys.c\
source/helper.c\
source/theme.c\
- source/mode.c\
+ source/css-colors.c\
+ source/mode.c\
source/rofi-types.c\
include/rofi-types.h\
source/xrmoptions.c\
@@ -560,6 +565,7 @@ helper_tokenize_SOURCES=\
include/mode-private.h\
source/helper.c\
source/theme.c\
+ source/css-colors.c\
source/rofi-types.c\
include/rofi-types.h\
include/helper.h\
diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l
index de7e9d26..c2071d41 100644
--- a/lexer/theme-lexer.l
+++ b/lexer/theme-lexer.l
@@ -86,7 +86,6 @@ typedef struct _ParseObject {
} ParseObject;
-GList *prev_imported_files = NULL;
GQueue *file_queue = NULL;
GQueue *queue = NULL;
diff --git a/meson.build b/meson.build
index 8406e5f8..71615d83 100644
--- a/meson.build
+++ b/meson.build
@@ -299,6 +299,7 @@ test('helper_pidfile test', executable('helper_pidfile.test', [
objects: rofi.extract_objects([
'config/config.c',
'source/theme.c',
+ 'source/css-colors.c',
'source/helper.c',
'source/xrmoptions.c',
'source/rofi-types.c',
@@ -317,6 +318,7 @@ test('widget test', executable('widget.test', [
'source/widgets/widget.c',
'source/widgets/textbox.c',
'source/theme.c',
+ 'source/css-colors.c',
'source/rofi-types.c',
'source/css-colors.c',
'source/helper.c',
@@ -335,6 +337,7 @@ test('box test', executable('box.test', [
'source/widgets/widget.c',
'source/widgets/box.c',
'source/theme.c',
+ 'source/css-colors.c',
'source/rofi-types.c',
'source/css-colors.c',
'config/config.c',
@@ -352,6 +355,7 @@ test('scrollbar test', executable('scrollbar.test', [
'source/widgets/widget.c',
'source/widgets/scrollbar.c',
'source/theme.c',
+ 'source/css-colors.c',
'source/rofi-types.c',
'source/css-colors.c',
'config/config.c',
@@ -369,6 +373,7 @@ test('textbox test', executable('textbox.test', [
'source/widgets/widget.c',
'source/widgets/textbox.c',
'source/theme.c',
+ 'source/css-colors.c',
'source/rofi-types.c',
'source/css-colors.c',
'source/helper.c',
@@ -383,6 +388,7 @@ test('helper test', executable('helper.test', [
objects: rofi.extract_objects([
'config/config.c',
'source/theme.c',
+ 'source/css-colors.c',
'source/helper.c',
'source/xrmoptions.c',
'source/rofi-types.c',
@@ -396,6 +402,7 @@ test('helper_expand test', executable('helper_expand.test', [
objects: rofi.extract_objects([
'config/config.c',
'source/theme.c',
+ 'source/css-colors.c',
'source/helper.c',
'source/xrmoptions.c',
'source/rofi-types.c',
@@ -409,6 +416,7 @@ test('helper_config_cmdline_parser test', executable('helper_config_cmdline_pars
objects: rofi.extract_objects([
'config/config.c',
'source/theme.c',
+ 'source/css-colors.c',
'source/helper.c',
'source/xrmoptions.c',
'source/rofi-types.c',
@@ -430,6 +438,7 @@ if check.found()
'source/helper.c',
'source/xrmoptions.c',
'source/theme.c',
+ 'source/css-colors.c',
'source/rofi-types.c',
'source/css-colors.c',
]),
@@ -444,6 +453,7 @@ if check.found()
'source/dialogs/help-keys.c',
'source/helper.c',
'source/theme.c',
+ 'source/css-colors.c',
'source/mode.c',
'source/xrmoptions.c',
'source/rofi-types.c',
@@ -459,6 +469,7 @@ if check.found()
'config/config.c',
'source/helper.c',
'source/theme.c',
+ 'source/css-colors.c',
'source/xrmoptions.c',
'source/rofi-types.c',
]),
diff --git a/source/theme.c b/source/theme.c
index 66da7bb9..0cf668a3 100644
--- a/source/theme.c
+++ b/source/theme.c
@@ -293,6 +293,27 @@ static void rofi_theme_print_distance_unit(RofiDistanceUnit *unit) {
}
}
+static void rofi_theme_print_color(ThemeColor color) {
+ uint8_t r, g, b;
+ g = 255 * color.green;
+ r = 255 * color.red;
+ b = 255 * color.blue;
+ if (color.alpha < 0.00001) {
+ printf("transparent");
+ return;
+ }
+ for (uint32_t x = 0; x < num_CSSColors; x++) {
+ if (CSSColors[x].r == r && CSSColors[x].g == g && CSSColors[x].b == b) {
+ printf("%s", CSSColors[x].name);
+ if (color.alpha < 1) {
+ printf("/%.0f%%", color.alpha * 100.0);
+ }
+ return;
+ }
+ }
+ printf("rgba ( %.0f, %.0f, %.0f, %.0f %% )", (color.red * 255.0),
+ (color.green * 255.0), (color.blue * 255.0), (color.alpha * 100.0));
+}
static void rofi_theme_print_distance(RofiDistance d) {
if (d.base.modtype == ROFI_DISTANCE_MODIFIER_GROUP) {
fputs("calc( ", stdout);
@@ -345,11 +366,7 @@ static void int_rofi_theme_print_property(Property *p) {
printf("italic ");
}
if (p->value.highlight.style & ROFI_HL_COLOR) {
- printf("rgba ( %.0f, %.0f, %.0f, %.0f %% )",
- (p->value.highlight.color.red * 255.0),
- (p->value.highlight.color.green * 255.0),
- (p->value.highlight.color.blue * 255.0),
- (p->value.highlight.color.alpha * 100.0));
+ rofi_theme_print_color(p->value.highlight.color);
}
break;
case P_POSITION: {
@@ -401,9 +418,7 @@ static void int_rofi_theme_print_property(Property *p) {
printf("%s", p->value.b ? "true" : "false");
break;
case P_COLOR:
- printf("rgba ( %.0f, %.0f, %.0f, %.0f %% )", (p->value.color.red * 255.0),
- (p->value.color.green * 255.0), (p->value.color.blue * 255.0),
- (p->value.color.alpha * 100.0));
+ rofi_theme_print_color(p->value.color);
break;
case P_IMAGE: {
if (p->value.image.type == ROFI_IMAGE_URL) {
@@ -415,9 +430,7 @@ static void int_rofi_theme_print_property(Property *p) {
for (GList *l = g_list_first(p->value.image.colors); l != NULL;
l = g_list_next(l)) {
ThemeColor *color = (ThemeColor *)l->data;
- printf("rgba ( %.0f, %.0f, %.0f, %.0f %% )", (color->red * 255.0),
- (color->green * 255.0), (color->blue * 255.0),
- (color->alpha * 100.0));
+ rofi_theme_print_color(*color);
index++;
if (index < length) {
printf(", ");