[gnome-applets/wip/segeiger/window-picker/task-title: 5/5] windowpicker: implement theme support



commit e528413ed08d3c2174de0db617b3b0a3ec2dc887
Author: Sebastian Geiger <sbastig gmx net>
Date:   Mon Feb 8 15:41:33 2016 +0100

    windowpicker: implement theme support

 configure.ac                                       |    3 +
 windowpicker/data/Makefile.am                      |    6 ++
 windowpicker/data/theme/Adwaita/Makefile.am        |    7 ++
 windowpicker/data/theme/Adwaita/windowpicker.css   |    3 +
 windowpicker/data/theme/HighContrast/Makefile.am   |    7 ++
 .../data/theme/HighContrast/windowpicker.css       |    3 +
 windowpicker/data/theme/Makefile.am                |    8 ++
 windowpicker/src/wp-applet.c                       |   71 +++++++++++++++++---
 windowpicker/src/wp-resources.gresource.xml        |    4 +
 9 files changed, 102 insertions(+), 10 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 123c685..c02c140 100644
--- a/configure.ac
+++ b/configure.ac
@@ -741,6 +741,9 @@ AC_CONFIG_FILES([
 
   windowpicker/Makefile
   windowpicker/data/Makefile
+  windowpicker/data/theme/Makefile
+  windowpicker/data/theme/Adwaita/Makefile
+  windowpicker/data/theme/HighContrast/Makefile
   windowpicker/src/Makefile
 ])
 
diff --git a/windowpicker/data/Makefile.am b/windowpicker/data/Makefile.am
index fea57fa..4b66f91 100644
--- a/windowpicker/data/Makefile.am
+++ b/windowpicker/data/Makefile.am
@@ -1,3 +1,9 @@
+NULL =
+
+SUBDIRS = \
+       theme \
+       $(NULL)
+
 appletdir       = $(LIBPANEL_APPLET_DIR)
 applet_in_files = org.gnome.applets.WindowPicker.panel-applet.in
 applet_DATA     = $(applet_in_files:.panel-applet.in=.panel-applet)
diff --git a/windowpicker/data/theme/Adwaita/Makefile.am b/windowpicker/data/theme/Adwaita/Makefile.am
new file mode 100644
index 0000000..d4aad01
--- /dev/null
+++ b/windowpicker/data/theme/Adwaita/Makefile.am
@@ -0,0 +1,7 @@
+NULL =
+
+EXTRA_DIST = \
+       windowpicker.css \
+       $(NULL)
+
+-include $(top_srcdir)/git.mk
diff --git a/windowpicker/data/theme/Adwaita/windowpicker.css 
b/windowpicker/data/theme/Adwaita/windowpicker.css
new file mode 100644
index 0000000..64376cd
--- /dev/null
+++ b/windowpicker/data/theme/Adwaita/windowpicker.css
@@ -0,0 +1,3 @@
+WpTaskTitle GtkLabel {
+    color: #000;
+}
diff --git a/windowpicker/data/theme/HighContrast/Makefile.am 
b/windowpicker/data/theme/HighContrast/Makefile.am
new file mode 100644
index 0000000..d4aad01
--- /dev/null
+++ b/windowpicker/data/theme/HighContrast/Makefile.am
@@ -0,0 +1,7 @@
+NULL =
+
+EXTRA_DIST = \
+       windowpicker.css \
+       $(NULL)
+
+-include $(top_srcdir)/git.mk
diff --git a/windowpicker/data/theme/HighContrast/windowpicker.css 
b/windowpicker/data/theme/HighContrast/windowpicker.css
new file mode 100644
index 0000000..64376cd
--- /dev/null
+++ b/windowpicker/data/theme/HighContrast/windowpicker.css
@@ -0,0 +1,3 @@
+WpTaskTitle GtkLabel {
+    color: #000;
+}
diff --git a/windowpicker/data/theme/Makefile.am b/windowpicker/data/theme/Makefile.am
new file mode 100644
index 0000000..9765ab1
--- /dev/null
+++ b/windowpicker/data/theme/Makefile.am
@@ -0,0 +1,8 @@
+NULL =
+
+SUBDIRS = \
+       Adwaita \
+       HighContrast \
+       $(NULL)
+
+-include $(top_srcdir)/git.mk
diff --git a/windowpicker/src/wp-applet.c b/windowpicker/src/wp-applet.c
index 8b6133c..9f20b8a 100644
--- a/windowpicker/src/wp-applet.c
+++ b/windowpicker/src/wp-applet.c
@@ -38,25 +38,27 @@
 
 #define SETTINGS_SCHEMA "org.gnome.gnome-applets.window-picker-applet"
 #define GRESOURCE "/org/gnome/gnome-applets/window-picker/"
+#define GRESOURCE_THEME "/org/gnome/gnome-applets/theme/%s/windowpicker.css"
 #define TITLE_BUTTON_SPACE 6
 #define CONTAINER_SPACING 10
 
 struct _WpApplet
 {
-  PanelApplet  parent;
+  PanelApplet       parent;
 
-  GSettings   *settings;
+  GSettings        *settings;
 
-  GtkWidget   *about_dialog;
-  GtkWidget   *preferences_dialog;
+  GtkWidget        *about_dialog;
+  GtkWidget        *preferences_dialog;
+  GtkStyleProvider *provider;
 
-  gboolean     show_all_windows;
-  gboolean     icons_greyscale;
-  gboolean     expand_task_list;
+  gboolean          show_all_windows;
+  gboolean          icons_greyscale;
+  gboolean          expand_task_list;
 
-  GtkWidget   *container;
-  GtkWidget   *tasks;
-  GtkWidget   *title;
+  GtkWidget        *container;
+  GtkWidget        *tasks;
+  GtkWidget        *title;
 };
 
 enum
@@ -203,9 +205,51 @@ wp_applet_setup_title (WpApplet *applet)
 }
 
 static void
+theme_changed (GtkSettings *settings,
+               WpApplet    *applet)
+{
+  GdkScreen *screen;
+  gchar *theme_name;
+  guint priority;
+  gchar *resource;
+  GtkCssProvider *css;
+
+  screen = gdk_screen_get_default ();
+
+  if (applet->provider != NULL)
+  {
+    gtk_style_context_remove_provider_for_screen (screen, applet->provider);
+    g_clear_object (&applet->provider);
+  }
+
+  g_object_get (settings, "gtk-theme-name", &theme_name, NULL);
+
+  if (g_strcmp0 (theme_name, "Adwaita") != 0 &&
+      g_strcmp0 (theme_name, "HighContrast") != 0)
+  {
+    g_free (theme_name);
+    return;
+  }
+
+  priority = GTK_STYLE_PROVIDER_PRIORITY_APPLICATION;
+  resource = g_strdup_printf (GRESOURCE_THEME, theme_name);
+
+  css = gtk_css_provider_new ();
+  applet->provider = GTK_STYLE_PROVIDER (css);
+
+  gtk_css_provider_load_from_resource (css, resource);
+  gtk_style_context_add_provider_for_screen (screen, applet->provider,
+                                             priority);
+
+  g_free (theme_name);
+  g_free (resource);
+}
+
+static void
 wp_applet_load (PanelApplet *panel_applet)
 {
   WpApplet *applet;
+  GtkSettings *gtk_settings;
 
   applet = WP_APPLET (panel_applet);
 
@@ -228,6 +272,13 @@ wp_applet_load (PanelApplet *panel_applet)
   g_settings_bind (applet->settings, KEY_EXPAND_TASK_LIST,
                    applet, KEY_EXPAND_TASK_LIST, G_SETTINGS_BIND_GET);
 
+  gtk_settings = gtk_settings_get_default ();
+  g_signal_connect (gtk_settings, "notify::gtk-theme-name",
+                    G_CALLBACK (theme_changed), applet);
+  g_signal_connect (gtk_settings, "notify::gtk-application-prefer-dark-theme",
+                    G_CALLBACK (theme_changed), applet);
+  theme_changed(gtk_settings, applet);
+
   gtk_widget_show_all (GTK_WIDGET (applet));
 }
 
diff --git a/windowpicker/src/wp-resources.gresource.xml b/windowpicker/src/wp-resources.gresource.xml
index f9a065c..c295c23 100644
--- a/windowpicker/src/wp-resources.gresource.xml
+++ b/windowpicker/src/wp-resources.gresource.xml
@@ -1,5 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
+  <gresource prefix="/org/gnome/gnome-applets/theme">
+    <file alias="Adwaita/windowpicker.css">../data/theme/Adwaita/windowpicker.css</file>
+    <file alias="HighContrast/windowpicker.css">../data/theme/HighContrast/windowpicker.css</file>
+  </gresource>
   <gresource prefix="/org/gnome/gnome-applets/window-picker">
     <file compressed="true">wp-about-logo.png</file>
     <file compressed="true">wp-preferences-dialog.ui</file>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]