[gnome-panel] notification applet: support fixed-sized icons



commit 06033bd75e83051fa92bf6fed601c0f6e7c8eb29
Author: Ryan Lortie <desrt desrt ca>
Date:   Tue Mar 29 23:41:17 2011 +0530

    notification applet: support fixed-sized icons
    
    Add a new _NET_SYSTEM_TRAY_ICON_SIZE property that is set to the value
    of the "icon-size" style property.  The result is that all icons in the
    tray will be hinted to draw themselves with exactly this pixel size
    (16x16, for example).
    
    Bug #645232

 applets/notification_area/main.c            |   13 +++++++-
 applets/notification_area/na-tray-manager.c |   44 +++++++++++++++++++++++++++
 applets/notification_area/na-tray-manager.h |    3 ++
 applets/notification_area/na-tray.c         |   10 ++++++
 applets/notification_area/na-tray.h         |    2 +
 5 files changed, 71 insertions(+), 1 deletions(-)
---
diff --git a/applets/notification_area/main.c b/applets/notification_area/main.c
index b515672..5fc4d1d 100644
--- a/applets/notification_area/main.c
+++ b/applets/notification_area/main.c
@@ -122,6 +122,7 @@ na_tray_applet_style_updated (GtkWidget *widget)
   GdkColor         warning;
   GdkColor         success;
   gint             padding;
+  gint             icon_size;
 
   GTK_WIDGET_CLASS (na_tray_applet_parent_class)->style_updated (widget);
 
@@ -145,8 +146,10 @@ na_tray_applet_style_updated (GtkWidget *widget)
   na_tray_set_colors (applet->priv->tray, &fg, &error, &warning, &success);
 
   gtk_widget_style_get (widget, "icon-padding", &padding, NULL);
-
   na_tray_set_padding (applet->priv->tray, padding);
+
+  gtk_widget_style_get (widget, "icon-size", &icon_size, NULL);
+  na_tray_set_icon_size (applet->priv->tray, icon_size);
 }
 
 static void
@@ -212,6 +215,14 @@ na_tray_applet_class_init (NaTrayAppletClass *class)
                             0, G_MAXINT, 0,
                             G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 
+  gtk_widget_class_install_style_property (
+          widget_class,
+          g_param_spec_int ("icon-size",
+                            "Icon size",
+                            "If non-zero, hardcodes the size of the icons in pixels",
+                            0, G_MAXINT, 0,
+                            G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
   g_type_class_add_private (class, sizeof (NaTrayAppletPrivate));
 }
 
diff --git a/applets/notification_area/na-tray-manager.c b/applets/notification_area/na-tray-manager.c
index 3c25db5..da98f00 100644
--- a/applets/notification_area/na-tray-manager.c
+++ b/applets/notification_area/na-tray-manager.c
@@ -98,6 +98,7 @@ na_tray_manager_init (NaTrayManager *manager)
   manager->socket_table = g_hash_table_new (NULL, NULL);
 
   manager->padding = 0;
+  manager->icon_size = 0;
 
   manager->fg.red = 0;
   manager->fg.green = 0;
@@ -681,6 +682,34 @@ na_tray_manager_set_padding_property (NaTrayManager *manager)
 }
 
 static void
+na_tray_manager_set_icon_size_property (NaTrayManager *manager)
+{
+#ifdef GDK_WINDOWING_X11
+  GdkWindow  *window;
+  GdkDisplay *display;
+  Atom        atom;
+  gulong      data[1];
+
+  g_return_if_fail (manager->invisible != NULL);
+  window = gtk_widget_get_window (manager->invisible);
+  g_return_if_fail (window != NULL);
+
+  display = gtk_widget_get_display (manager->invisible);
+  atom = gdk_x11_get_xatom_by_name_for_display (display,
+                                                "_NET_SYSTEM_TRAY_ICON_SIZE");
+
+  data[0] = manager->icon_size;
+
+  XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
+                   GDK_WINDOW_XID (window),
+                   atom,
+                   XA_CARDINAL, 32,
+                   PropModeReplace,
+                   (guchar *) &data, 1);
+#endif
+}
+
+static void
 na_tray_manager_set_colors_property (NaTrayManager *manager)
 {
 #ifdef GDK_WINDOWING_X11
@@ -765,6 +794,7 @@ na_tray_manager_manage_screen_x11 (NaTrayManager *manager,
   na_tray_manager_set_orientation_property (manager);
   na_tray_manager_set_visual_property (manager);
   na_tray_manager_set_padding_property (manager);
+  na_tray_manager_set_icon_size_property (manager);
   na_tray_manager_set_colors_property (manager);
   
   window = gtk_widget_get_window (invisible);
@@ -915,6 +945,20 @@ na_tray_manager_set_padding (NaTrayManager *manager,
 }
 
 void
+na_tray_manager_set_icon_size (NaTrayManager *manager,
+                               gint           icon_size)
+{
+  g_return_if_fail (NA_IS_TRAY_MANAGER (manager));
+
+  if (manager->icon_size != icon_size)
+    {
+      manager->icon_size = icon_size;
+
+      na_tray_manager_set_icon_size_property (manager);
+    }
+}
+
+void
 na_tray_manager_set_colors (NaTrayManager *manager,
                             GdkColor      *fg,
                             GdkColor      *error,
diff --git a/applets/notification_area/na-tray-manager.h b/applets/notification_area/na-tray-manager.h
index 6273f38..0408959 100644
--- a/applets/notification_area/na-tray-manager.h
+++ b/applets/notification_area/na-tray-manager.h
@@ -57,6 +57,7 @@ struct _NaTrayManager
   GdkScreen *screen;
   GtkOrientation orientation;
   gint padding;
+  gint icon_size;
   GdkColor fg;
   GdkColor error;
   GdkColor warning;
@@ -99,6 +100,8 @@ void            na_tray_manager_set_orientation (NaTrayManager      *manager,
 GtkOrientation  na_tray_manager_get_orientation (NaTrayManager      *manager);
 void            na_tray_manager_set_padding     (NaTrayManager      *manager,
 						 gint                padding);
+void            na_tray_manager_set_icon_size   (NaTrayManager      *manager,
+						 gint                padding);
 void            na_tray_manager_set_colors      (NaTrayManager      *manager,
 						 GdkColor           *fg,
 						 GdkColor           *error,
diff --git a/applets/notification_area/na-tray.c b/applets/notification_area/na-tray.c
index 08f6b50..8fd20e9 100644
--- a/applets/notification_area/na-tray.c
+++ b/applets/notification_area/na-tray.c
@@ -827,6 +827,16 @@ na_tray_set_padding (NaTray *tray,
 }
 
 void
+na_tray_set_icon_size (NaTray *tray,
+                       gint    size)
+{
+  NaTrayPrivate *priv = tray->priv;
+
+  if (get_tray (priv->trays_screen) == tray)
+    na_tray_manager_set_icon_size (priv->trays_screen->tray_manager, size);
+}
+
+void
 na_tray_set_colors (NaTray   *tray,
                     GdkColor *fg,
                     GdkColor *error,
diff --git a/applets/notification_area/na-tray.h b/applets/notification_area/na-tray.h
index 77d3ea3..8fd7db4 100644
--- a/applets/notification_area/na-tray.h
+++ b/applets/notification_area/na-tray.h
@@ -62,6 +62,8 @@ void            na_tray_set_orientation	(NaTray        *tray,
 GtkOrientation  na_tray_get_orientation (NaTray        *tray);
 void            na_tray_set_padding     (NaTray        *tray,
 					 gint           padding);
+void            na_tray_set_icon_size   (NaTray        *tray,
+					 gint           icon_size);
 void            na_tray_set_colors      (NaTray        *tray,
 					 GdkColor      *fg,
 					 GdkColor      *error,



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