summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorTimm Bäder <mail@baedert.org>2016-10-05 14:26:30 +0200
committerBenjamin Otte <otte@redhat.com>2016-10-16 18:17:21 +0200
commit7377b7e5c2e2f1ffbb3d4f98990878fe4d3d7a58 (patch)
treef7b77c1e418fea201a61457a2d3b52f1a13146ea /examples
parent3c901d6376ffe01c31169679f163e08b18c7e058 (diff)
downloadgtk+-7377b7e5c2e2f1ffbb3d4f98990878fe4d3d7a58.tar.gz
plugman: Stop using gtk_override_color
Diffstat (limited to 'examples')
-rw-r--r--examples/plugman.c50
1 files changed, 34 insertions, 16 deletions
diff --git a/examples/plugman.c b/examples/plugman.c
index 03c633d445..04f0029367 100644
--- a/examples/plugman.c
+++ b/examples/plugman.c
@@ -1,5 +1,17 @@
#include <stdlib.h>
#include <gtk/gtk.h>
+#include <string.h>
+
+
+static const char *red_css =
+"textview>text {"
+" color: red;"
+"}";
+
+static const char *black_css =
+"textview>text {"
+" color: black;"
+"}";
static void
activate_toggle (GSimpleAction *action,
@@ -195,22 +207,28 @@ plugin_action (GAction *action,
GVariant *parameter,
gpointer data)
{
- GApplication *app;
- GList *list;
- GtkWindow *window;
- GtkWidget *text;
- GdkRGBA color;
-
- app = g_application_get_default ();
- list = gtk_application_get_windows (GTK_APPLICATION (app));
- window = GTK_WINDOW (list->data);
- text = g_object_get_data ((GObject*)window, "plugman-text");
-
- gdk_rgba_parse (&color, g_action_get_name (action));
-
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- gtk_widget_override_color (text, 0, &color);
-G_GNUC_END_IGNORE_DEPRECATIONS
+ const char *action_name;
+ const char *css_to_load;
+ GtkCssProvider *css_provider;
+
+ action_name = g_action_get_name (action);
+ if (strcmp (action_name, "red") == 0)
+ css_to_load = red_css;
+ else if (strcmp (action_name, "black") == 0)
+ css_to_load = black_css;
+ else
+ {
+ g_critical ("Unknown action name: %s", action_name);
+ return;
+ }
+
+ g_message ("Color: %s", g_action_get_name (action));
+
+ css_provider = gtk_css_provider_new ();
+ gtk_css_provider_load_from_data (css_provider, css_to_load, -1, NULL);
+ gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
+ GTK_STYLE_PROVIDER (css_provider),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
}
static void