[gtk+] Add padding around the status icons



commit a4d4b54a7dab25b7ca894a90f89064400137718b
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon May 10 15:26:44 2010 +0100

    Add padding around the status icons
    
    The amount of padding is determined by reading a _NET_SYSTEM_TRAY_PADDING
    property off the manager window, in the same way that orientation and visual
    are obtained.
    
    Signed-off-by: Richard Hughes <richard hughsie com>

 gtk/gtkstatusicon.c   |   23 +++++++++++++
 gtk/gtktrayicon-x11.c |   85 ++++++++++++++++++++++++++++++++++++++++++++++++-
 gtk/gtktrayicon.h     |    1 +
 3 files changed, 108 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkstatusicon.c b/gtk/gtkstatusicon.c
index e6ec405..8e4ebe6 100644
--- a/gtk/gtkstatusicon.c
+++ b/gtk/gtkstatusicon.c
@@ -170,6 +170,7 @@ static void     gtk_status_icon_screen_changed   (GtkStatusIcon  *status_icon,
 						  GdkScreen      *old_screen);
 static void     gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon);
 static void     gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon);
+static void     gtk_status_icon_padding_changed  (GtkStatusIcon *status_icon);
 static void     gtk_status_icon_fg_changed       (GtkStatusIcon *status_icon);
 static void     gtk_status_icon_color_changed    (GtkTrayIcon   *tray,
                                                   GParamSpec    *pspec,
@@ -854,6 +855,8 @@ gtk_status_icon_init (GtkStatusIcon *status_icon)
 			    G_CALLBACK (gtk_status_icon_embedded_changed), status_icon);
   g_signal_connect_swapped (priv->tray_icon, "notify::orientation",
 			    G_CALLBACK (gtk_status_icon_orientation_changed), status_icon);
+  g_signal_connect_swapped (priv->tray_icon, "notify::padding",
+			    G_CALLBACK (gtk_status_icon_padding_changed), status_icon);
   g_signal_connect_swapped (priv->tray_icon, "notify::fg-color",
                             G_CALLBACK (gtk_status_icon_fg_changed), status_icon);
   g_signal_connect (priv->tray_icon, "notify::error-color",
@@ -987,6 +990,8 @@ gtk_status_icon_finalize (GObject *object)
   g_signal_handlers_disconnect_by_func (priv->tray_icon,
 			                gtk_status_icon_orientation_changed, status_icon);
   g_signal_handlers_disconnect_by_func (priv->tray_icon,
+			                gtk_status_icon_padding_changed, status_icon);
+  g_signal_handlers_disconnect_by_func (priv->tray_icon,
                                         gtk_status_icon_fg_changed, status_icon);
   g_signal_handlers_disconnect_by_func (priv->tray_icon,
                                         gtk_status_icon_color_changed, status_icon);
@@ -1695,14 +1700,32 @@ gtk_status_icon_screen_changed (GtkStatusIcon *status_icon,
 #ifdef GDK_WINDOWING_X11
 
 static void
+gtk_status_icon_padding_changed (GtkStatusIcon *status_icon)
+{
+  GtkStatusIconPrivate *priv = status_icon->priv;
+  GtkOrientation orientation;
+  gint padding;
+
+  orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (priv->tray_icon));
+  padding = _gtk_tray_icon_get_padding (GTK_TRAY_ICON (priv->tray_icon));
+
+  if (orientation == GTK_ORIENTATION_HORIZONTAL)
+    gtk_misc_set_padding (GTK_MISC (priv->image), padding, 0);
+  else
+    gtk_misc_set_padding (GTK_MISC (priv->image), 0, padding);
+}
+
+static void
 gtk_status_icon_embedded_changed (GtkStatusIcon *status_icon)
 {
+  gtk_status_icon_padding_changed (status_icon);
   g_object_notify (G_OBJECT (status_icon), "embedded");
 }
 
 static void
 gtk_status_icon_orientation_changed (GtkStatusIcon *status_icon)
 {
+  gtk_status_icon_padding_changed (status_icon);
   g_object_notify (G_OBJECT (status_icon), "orientation");
 }
 
diff --git a/gtk/gtktrayicon-x11.c b/gtk/gtktrayicon-x11.c
index 4cb1aa7..ae426b3 100644
--- a/gtk/gtktrayicon-x11.c
+++ b/gtk/gtktrayicon-x11.c
@@ -47,7 +47,8 @@ enum {
   PROP_FG_COLOR,
   PROP_ERROR_COLOR,
   PROP_WARNING_COLOR,
-  PROP_SUCCESS_COLOR
+  PROP_SUCCESS_COLOR,
+  PROP_PADDING
 };
 
 struct _GtkTrayIconPrivate
@@ -60,6 +61,7 @@ struct _GtkTrayIconPrivate
   Atom orientation_atom;
   Atom visual_atom;
   Atom colors_atom;
+  Atom padding_atom;
   Window manager_window;
   GdkVisual *manager_visual;
   gboolean manager_visual_rgba;
@@ -69,6 +71,7 @@ struct _GtkTrayIconPrivate
   GdkColor error_color;
   GdkColor warning_color;
   GdkColor success_color;
+  gint padding;
 };
 
 static void gtk_tray_icon_constructed   (GObject     *object);
@@ -154,6 +157,16 @@ gtk_tray_icon_class_init (GtkTrayIconClass *class)
                                                        GDK_TYPE_COLOR,
                                                        GTK_PARAM_READABLE));
 
+  g_object_class_install_property (gobject_class,
+				   PROP_PADDING,
+				   g_param_spec_int ("padding",
+						     P_("Padding"),
+						     P_("Padding that should be put around icons in the tray"),
+						     0,
+                                                     G_MAXINT,
+                                                     0,
+						     GTK_PARAM_READABLE));
+
   g_type_class_add_private (class, sizeof (GtkTrayIconPrivate));
 }
 
@@ -177,6 +190,7 @@ gtk_tray_icon_init (GtkTrayIcon *icon)
   icon->priv->success_color.red   = 0x4e00;
   icon->priv->success_color.green = 0x9a00;
   icon->priv->success_color.blue  = 0x0600;
+  icon->priv->padding = 0;
 
   gtk_widget_set_app_paintable (GTK_WIDGET (icon), TRUE);
   gtk_widget_add_events (GTK_WIDGET (icon), GDK_PROPERTY_CHANGE_MASK);
@@ -218,6 +232,10 @@ gtk_tray_icon_constructed (GObject *object)
                                          "_NET_SYSTEM_TRAY_COLORS",
                                          False);
 
+  icon->priv->padding_atom = XInternAtom (xdisplay,
+					 "_NET_SYSTEM_TRAY_PADDING",
+					 False);
+
   /* Add a root window filter so that we get changes on MANAGER */
   gdk_window_add_filter (root_window,
 			 gtk_tray_icon_manager_filter, icon);
@@ -281,6 +299,9 @@ gtk_tray_icon_get_property (GObject    *object,
     case PROP_SUCCESS_COLOR:
       g_value_set_boxed (value, &icon->priv->success_color);
       break;
+    case PROP_PADDING:
+      g_value_set_int (value, icon->priv->padding);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -535,6 +556,55 @@ gtk_tray_icon_get_colors_property (GtkTrayIcon *icon)
     XFree (prop.prop);
 }
 
+static void
+gtk_tray_icon_get_padding_property (GtkTrayIcon *icon)
+{
+  GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (icon));
+  GdkDisplay *display = gdk_screen_get_display (screen);
+  Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
+
+  Atom type;
+  int format;
+  union {
+	gulong *prop;
+	guchar *prop_ch;
+  } prop = { NULL };
+  gulong nitems;
+  gulong bytes_after;
+  int error, result;
+
+  g_assert (icon->priv->manager_window != None);
+
+  gdk_error_trap_push ();
+  type = None;
+  result = XGetWindowProperty (xdisplay,
+			       icon->priv->manager_window,
+			       icon->priv->padding_atom,
+			       0, G_MAXLONG, FALSE,
+			       XA_CARDINAL,
+			       &type, &format, &nitems,
+			       &bytes_after, &(prop.prop_ch));
+  error = gdk_error_trap_pop ();
+
+  if (!error && result == Success &&
+      type == XA_CARDINAL && nitems == 1 && format == 32)
+    {
+      gint padding;
+
+      padding = prop.prop[0];
+
+      if (icon->priv->padding != padding)
+	{
+	  icon->priv->padding = padding;
+
+	  g_object_notify (G_OBJECT (icon), "padding");
+	}
+    }
+
+  if (type != None)
+    XFree (prop.prop);
+}
+
 static GdkFilterReturn
 gtk_tray_icon_manager_filter (GdkXEvent *xevent,
 			      GdkEvent  *event,
@@ -570,6 +640,11 @@ gtk_tray_icon_manager_filter (GdkXEvent *xevent,
 
           gtk_tray_icon_get_colors_property (icon);
         }
+      else if (xev->xany.type == PropertyNotify &&
+               xev->xproperty.atom == icon->priv->padding_atom)
+        {
+          gtk_tray_icon_get_padding_property (icon);
+        }
       else if (xev->xany.type == DestroyNotify)
 	{
           GTK_NOTE (PLUGSOCKET,
@@ -676,6 +751,7 @@ gtk_tray_icon_update_manager_window (GtkTrayIcon *icon)
       gtk_tray_icon_get_orientation_property (icon);
       gtk_tray_icon_get_visual_property (icon);
       gtk_tray_icon_get_colors_property (icon);
+      gtk_tray_icon_get_padding_property (icon);
 
       if (gtk_widget_get_realized (GTK_WIDGET (icon)))
 	{
@@ -914,6 +990,13 @@ _gtk_tray_icon_get_orientation (GtkTrayIcon *icon)
   return icon->priv->orientation;
 }
 
+gint
+_gtk_tray_icon_get_padding (GtkTrayIcon *icon)
+{
+  g_return_val_if_fail (GTK_IS_TRAY_ICON (icon), 0);
+
+  return icon->priv->padding;
+}
 
 #define __GTK_TRAY_ICON_X11_C__
 #include "gtkaliasdef.c"
diff --git a/gtk/gtktrayicon.h b/gtk/gtktrayicon.h
index 2b271e8..6dc9852 100644
--- a/gtk/gtktrayicon.h
+++ b/gtk/gtktrayicon.h
@@ -69,6 +69,7 @@ void           _gtk_tray_icon_cancel_message  (GtkTrayIcon *icon,
 					       guint        id);
 
 GtkOrientation _gtk_tray_icon_get_orientation (GtkTrayIcon *icon);
+gint           _gtk_tray_icon_get_padding     (GtkTrayIcon *icon);
 
 G_END_DECLS
 



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