Bugzilla – Attachment 128758 Details for
Bug 92776
UI: Tab names unreadable in GTK3 in Ubuntu
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
standalone get label text color in a notebook tab
tabcolor.c (text/plain), 4.81 KB, created by
Caolán McNamara
on 2016-11-15 09:30:49 UTC
(
hide
)
Description:
standalone get label text color in a notebook tab
Filename:
MIME Type:
Creator:
Caolán McNamara
Created:
2016-11-15 09:30:49 UTC
Size:
4.81 KB
patch
obsolete
>/* gcc `pkg-config --cflags --libs gtk+-3.0` tabcolor.c -o tabcolor > * > * Ubuntu: 16.10 > * gtk3: 3.20.9 with default Ambiance theme > * > * color is reported as white, which is unexpected, what's wrong > * with this code > */ > >#include <gtk/gtk.h> >#include <string.h> > >static void >append_element (GtkWidgetPath *path, > const char *selector) >{ > static const struct { > const char *name; > GtkStateFlags state_flag; > } pseudo_classes[] = { > { "active", GTK_STATE_FLAG_ACTIVE }, > { "hover", GTK_STATE_FLAG_PRELIGHT }, > { "selected", GTK_STATE_FLAG_SELECTED }, > { "disabled", GTK_STATE_FLAG_INSENSITIVE }, > { "indeterminate", GTK_STATE_FLAG_INCONSISTENT }, > { "focus", GTK_STATE_FLAG_FOCUSED }, > { "backdrop", GTK_STATE_FLAG_BACKDROP }, > { "dir(ltr)", GTK_STATE_FLAG_DIR_LTR }, > { "dir(rtl)", GTK_STATE_FLAG_DIR_RTL }, > { "link", GTK_STATE_FLAG_LINK }, > { "visited", GTK_STATE_FLAG_VISITED }, > { "checked", GTK_STATE_FLAG_CHECKED }, > { "drop(active)", GTK_STATE_FLAG_DROP_ACTIVE } > }; > const char *next; > char *name; > char type; > guint i; > > next = strpbrk (selector, "#.:"); > if (next == NULL) > next = selector + strlen (selector); > > name = g_strndup (selector, next - selector); > if (g_ascii_isupper (selector[0])) > { > GType gtype; > gtype = g_type_from_name (name); > if (gtype == G_TYPE_INVALID) > { > g_critical ("Unknown type name `%s'", name); > g_free (name); > return; > } > gtk_widget_path_append_type (path, gtype); > } > else > { > /* Omit type, we're using name */ > gtk_widget_path_append_type (path, G_TYPE_NONE); > gtk_widget_path_iter_set_object_name (path, -1, name); > } > g_free (name); > > while (*next != '\0') > { > type = *next; > selector = next + 1; > next = strpbrk (selector, "#.:"); > if (next == NULL) > next = selector + strlen (selector); > name = g_strndup (selector, next - selector); > > switch (type) > { > case '#': > gtk_widget_path_iter_set_name (path, -1, name); > break; > > case '.': > gtk_widget_path_iter_add_class (path, -1, name); > break; > > case ':': > for (i = 0; i < G_N_ELEMENTS (pseudo_classes); i++) > { > if (g_str_equal (pseudo_classes[i].name, name)) > { > gtk_widget_path_iter_set_state (path, > -1, > gtk_widget_path_iter_get_state (path, -1) > | pseudo_classes[i].state_flag); > break; > } > } > if (i == G_N_ELEMENTS (pseudo_classes)) > g_critical ("Unknown pseudo-class :%s", name); > break; > > default: > g_assert_not_reached (); > break; > } > > g_free (name); > } >} > >static GtkStyleContext * >create_context_for_path (GtkWidgetPath *path, > GtkStyleContext *parent) >{ > GtkStyleContext *context; > > context = gtk_style_context_new (); > gtk_style_context_set_path (context, path); > gtk_style_context_set_parent (context, parent); > /* Unfortunately, we have to explicitly set the state again here > * for it to take effect > */ > gtk_style_context_set_state (context, gtk_widget_path_iter_get_state (path, -1)); > gtk_widget_path_unref (path); > > return context; >} > >static GtkStyleContext * >get_style (GtkStyleContext *parent, > const char *selector) >{ > GtkWidgetPath *path; > > if (parent) > path = gtk_widget_path_copy (gtk_style_context_get_path (parent)); > else > path = gtk_widget_path_new (); > > append_element (path, selector); > > return create_context_for_path (path, parent); >} > >static void >get_tab_label_color() >{ > GtkStyleContext *notebook_context; > GtkStyleContext *header_context; > GtkStyleContext *tabs_context; > GtkStyleContext *tab_context; > GtkStyleContext *label_context; > GdkRGBA text_color; > > /* This information is taken from the GtkNotebook docs, see "CSS nodes" */ > notebook_context = get_style (NULL, "notebook.frame"); > header_context = get_style (notebook_context, "header.top"); > tabs_context = get_style (header_context, "tabs"); > tab_context = get_style (tabs_context, "tab"); > label_context = get_style (tab_context, "label"); > > gtk_style_context_get_color(label_context, gtk_style_context_get_state(label_context), &text_color); > printf("tab label color is %s\n", gdk_rgba_to_string(&text_color)); > > g_object_unref (label_context); > g_object_unref (tabs_context); > g_object_unref (tab_context); > g_object_unref (header_context); > g_object_unref (notebook_context); >} > >int main (int argc, char *argv[]) >{ > gtk_init (&argc, &argv); > get_tab_label_color(); >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 92776
:
117266
|
127947
|
127948
| 128758