After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 648709 - provide access to gtk named colors
provide access to gtk named colors
Status: RESOLVED FIXED
Product: mutter
Classification: Core
Component: general
git master
Other All
: Normal normal
: ---
Assigned To: mutter-maint
mutter-maint
Depends on: 645355
Blocks:
 
 
Reported: 2011-04-26 21:58 UTC by Jakub Steiner
Modified: 2011-07-08 20:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
theme: Allow using custom colors from the GTK+ theme (6.57 KB, patch)
2011-05-05 16:09 UTC, Florian Müllner
none Details | Review
Test custom colors (2.06 KB, patch)
2011-05-06 20:34 UTC, Florian Müllner
needs-work Details | Review
theme: Allow using custom colors from the GTK+ theme (6.85 KB, patch)
2011-05-17 21:57 UTC, Florian Müllner
needs-work Details | Review
theme: Allow using custom colors from the GTK+ theme (7.80 KB, patch)
2011-06-16 10:20 UTC, Florian Müllner
accepted-commit_now Details | Review
theme: Allow using custom colors from the GTK+ theme (7.50 KB, patch)
2011-07-08 19:48 UTC, Florian Müllner
committed Details | Review
Proposed interdiff (2.07 KB, patch)
2011-07-08 20:10 UTC, Florian Müllner
accepted-commit_now Details | Review

Description Jakub Steiner 2011-04-26 21:58:32 UTC
It will be extremely useful to mix colors in the gtk theme to pass to mutter as a named color @foobar

This way the light/dark variant of the widget theme can be addressed with a single WM theme.
Comment 1 Florian Müllner 2011-04-26 22:24:55 UTC
(In reply to comment #0)
> It will be extremely useful to mix colors in the gtk theme to pass to mutter as
> a named color @foobar

Unless we tie the mutter theme to the gtk theme, we'll need a fallback when the gtk theme does not contain the custom color. Something like gtk:custom(foobar,#c0102) maybe?
Comment 2 Lapo Calamandrei 2011-04-28 10:46:35 UTC
gtk:custom(foobar,fallback) sounds good to me
Comment 3 Florian Müllner 2011-05-05 16:09:00 UTC
Created attachment 187291 [details] [review]
theme: Allow using custom colors from the GTK+ theme

Add an additional color type to pick up colors defined with
@define-color in the GTK+ theme's CSS:

  gtk:custom/name/fallback

(where "name" refers to the name defined in GTK+'s CSS, and fallback
refers to an alternative color spec which is used when the color
referenced by "name" is not found)

The main intent of the change is to allow designers to improve
Adwaita's dark theme variant without having to compromise on colors
which work in the light variant as well.
Comment 4 Florian Müllner 2011-05-05 16:12:24 UTC
(In reply to comment #2)
> gtk:custom(foobar,fallback) sounds good to me

I went with gtk:custom/foobar/fallback, which is
 - in line with the existing blend/shade functions
 - slightly easier to parse ;-)

Of course, if you insist I can update the patch to use parentheses instead ...
Comment 5 Florian Müllner 2011-05-06 20:34:48 UTC
Created attachment 187386 [details] [review]
Test custom colors

Small patch against gnome-themes-standard for testing.
Comment 6 Florian Müllner 2011-05-06 20:36:36 UTC
Comment on attachment 187386 [details] [review]
Test custom colors

(last patch is not meant for inclusion, so getting it of the review queue)
Comment 7 Owen Taylor 2011-05-17 19:00:43 UTC
Shouldn't you be to mix blend/shade functions and this? isn't there then a problem with the syntax?
Comment 8 Florian Müllner 2011-05-17 21:57:43 UTC
Created attachment 187995 [details] [review]
theme: Allow using custom colors from the GTK+ theme

(In reply to comment #7)
> Shouldn't you be to mix blend/shade functions and this? isn't there then a
> problem with the syntax?

Uhm, yeah ... I tested with blend/shade functions as fallback, but not with gtk:custom as parameter to those. So back to the initial gtk:custom(foo,bar) syntax.
Comment 9 Owen Taylor 2011-06-15 19:09:41 UTC
Review of attachment 187995 [details] [review]:

some concerns about the parsing code (in particular, the first one, the rest are more questions)

::: src/ui/theme.c
@@ +1203,3 @@
+      MetaColorSpec *fallback = NULL;
+
+      color_name_start = strchr (str, '(');

Hmm, I don't think it's good to accept gtk:custom hah hah fooled you(tab-border,color) as a valid color. AFAICT, the theme format doesn't accept whitespace anywhere, so I think you can just demand that the ( is the next character.

@@ +1205,3 @@
+      color_name_start = strchr (str, '(');
+      fallback_str_start = strchr (str, ',');
+      end = strrchr (str, ')');

this means you can't do gtk:custom(color_name,gtk:custom(other_color_name,<last_gasp>)) which might be useful. Not sure if adding code to scan for a matching paren is worth the complexity though.

@@ +1207,3 @@
+      end = strrchr (str, ')');
+
+      if (color_name_start == NULL || fallback_str_start == NULL || end == NULL)

would it make sense to allow fallback not to be specified?

@@ +1225,3 @@
+
+      color_name = g_strndup (color_name_start + 1,
+                              fallback_str_start - color_name_start - 1);

I wonder if validating this to be a valid name would prevent weirdness for syntax errors. A quick look seems to indicate that this has to be a valid param name which has to be

 [A-Za-z][A-Za-z0-9-_]+
Comment 10 Florian Müllner 2011-06-15 19:33:22 UTC
(In reply to comment #9)
> Review of attachment 187995 [details] [review]:
> 
> Hmm, I don't think it's good to accept gtk:custom hah hah fooled
> you(tab-border,color) as a valid color. AFAICT, the theme format doesn't accept
> whitespace anywhere, so I think you can just demand that the ( is the next
> character.

OK.


> @@ +1205,3 @@
> +      color_name_start = strchr (str, '(');
> +      fallback_str_start = strchr (str, ',');
> +      end = strrchr (str, ')');
> 
> this means you can't do
> gtk:custom(color_name,gtk:custom(other_color_name,<last_gasp>)) which might be
> useful. Not sure if adding code to scan for a matching paren is worth the
> complexity though.

No, that case is expected to work - note the use of strrchr instead of strchr for end (now, I only tested with correct syntax, so the primitive parsing might fail very badly on erroneous syntax ...)


> @@ +1207,3 @@
> +      end = strrchr (str, ')');
> +
> +      if (color_name_start == NULL || fallback_str_start == NULL || end ==
> NULL)
> 
> would it make sense to allow fallback not to be specified?


Not sure - meta_color_spec_render() looks like it's supposed to always fill in a color, but I guess we can use a nice shade of pink as hardcoded fallback in case it's omitted in the theme.


> @@ +1225,3 @@
> +
> +      color_name = g_strndup (color_name_start + 1,
> +                              fallback_str_start - color_name_start - 1);
> 
> I wonder if validating this to be a valid name would prevent weirdness for
> syntax errors. A quick look seems to indicate that this has to be a valid param
> name which has to be
> 
>  [A-Za-z][A-Za-z0-9-_]+

Makes sense ...
Comment 11 Florian Müllner 2011-06-16 10:20:54 UTC
Created attachment 190025 [details] [review]
theme: Allow using custom colors from the GTK+ theme

Add some validation to parsing code.

(In reply to comment #9)
> I think you can just demand that the ( is the next character.

Done.


> I wonder if validating this to be a valid name would prevent weirdness for
> syntax errors. A quick look seems to indicate that this has to be a valid param
> name which has to be
> 
>  [A-Za-z][A-Za-z0-9-_]+

Done, but using [A_Za-z0-0-_]+ (which is what GTK+ uses in gtkcssparser.c:_gtk_css_parser_try_name)
Comment 12 Owen Taylor 2011-07-08 18:48:56 UTC
Review of attachment 190025 [details] [review]:

Logic looks right to me; I'll note that there's one stylistic weirdness in the parsing code, but not a blocker - feel to commit without fixing.

::: src/ui/theme.c
@@ +1204,3 @@
+
+      color_name_start = str + 10;
+      if (*color_name_start != '(')

It's weird that color_name_start is one before the start of the color name, and you keep on correcting for that below.

@@ +1241,3 @@
+
+      fallback_str = g_strndup (fallback_str_start + 1,
+                                end - fallback_str_start - 1);

and same for fallback_str_start
Comment 13 Florian Müllner 2011-07-08 19:48:09 UTC
Created attachment 191534 [details] [review]
theme: Allow using custom colors from the GTK+ theme

Updated to master.
Comment 14 Owen Taylor 2011-07-08 19:49:47 UTC
Review of attachment 191534 [details] [review]:

Does this need review?
Comment 15 Florian Müllner 2011-07-08 19:51:32 UTC
(In reply to comment #13)
> Created an attachment (id=191534) [details] [review]
> theme: Allow using custom colors from the GTK+ theme
> 
> Updated to master.

Sorry, missed above review - the attached patch is just a plain rebase, no need to look at it again.
Comment 16 Florian Müllner 2011-07-08 20:10:38 UTC
Created attachment 191535 [details] [review]
Proposed interdiff

(In reply to comment #14)
> Does this need review?

This one does ;-)
Comment 17 Owen Taylor 2011-07-08 20:36:03 UTC
Review of attachment 191535 [details] [review]:

Looks good
Comment 18 Florian Müllner 2011-07-08 20:41:09 UTC
Attachment 191534 [details] pushed as 54b2fab - theme: Allow using custom colors from the GTK+ theme