5

GtkStyle has been deprecated. I want to use GtkStyleContext instead (gtk_style_context_lookup_color) to find theme color.

I replaced successfully:

    color = style->bg [GTK_STATE_SELECTED];

with:

    gtk_style_context_lookup_color (context, "theme_selected_bg_color", &color)

but I do not know what color name to use to replace:

    color = style->dark [GTK_STATE_NORMAL];

I need these colors to transfer them to a vumeter create with cairo:

gdk_cairo_set_source_rgba (cr, &color);
geo
  • 193
  • 1
  • 1
  • 8
  • What do you want to do with the color that you get? I'm not quite sure what you are asking... – andlabs Jan 27 '16 at 19:15
  • 1
    I want to create a vumeter with cairo that respects color scheme of application. – geo Jan 27 '16 at 19:35
  • Possible duplicate of [GTK+3 render rectangle with selection background color](https://stackoverflow.com/questions/43376154/gtk3-render-rectangle-with-selection-background-color) – user877329 Jun 11 '17 at 09:24

2 Answers2

4

as far as I know the list of color names is not part of GTK, but a property of the gtk theme. These are the color names for the default gnome theme, adwaita, for gtk 3.22: https://gitlab.gnome.org/GNOME/gtk/-/blob/gtk-3-22/gtk/theme/Adwaita/_colors-public.scss

I'm copying the names inline:

  • theme_fg_color
  • theme_text_color
  • theme_bg_color
  • theme_base_color
  • theme_selected_bg_color
  • theme_selected_fg_color
  • insensitive_bg_color
  • insensitive_fg_color
  • insensitive_base_color
  • theme_unfocused_fg_color
  • theme_unfocused_text_color
  • theme_unfocused_bg_color
  • theme_unfocused_base_color
  • theme_unfocused_selected_bg_color
  • theme_unfocused_selected_fg_color
  • unfocused_insensitive_color
  • borders
  • unfocused_borders
  • warning_color
  • error_color
  • success_color
Emmanuel Touzery
  • 9,008
  • 3
  • 65
  • 81
0

As I understand it, GTK does not allow you to create custom widgets that respects the current theme, so either

  1. Write custom css for your entire application, ie disabling theming from outside
  2. Use a hack that calls gtk_render_background until you get something useful in a secondary cairo sufrace. See my answer to my own question: https://stackoverflow.com/a/44063175/877329
  3. Choose another toolkit, or stick to Gtk+2 for the sake of being a rebel.
user877329
  • 6,717
  • 8
  • 46
  • 88