Sync whitespace with gnome-panel version of NaTray*

Propagate line-wrapping and other white-space changes from gnome-panel
to our copy of NaTrayChild and NaTrayManager.
This commit is contained in:
Owen W. Taylor 2009-04-18 16:34:52 -04:00
parent c8fd1f99d5
commit bb92791bd3
3 changed files with 74 additions and 65 deletions

View File

@ -46,17 +46,18 @@ na_tray_child_realize (GtkWidget *widget)
GTK_WIDGET_CLASS (na_tray_child_parent_class)->realize (widget); GTK_WIDGET_CLASS (na_tray_child_parent_class)->realize (widget);
/* We have alpha if the visual has something other than red, green, and blue */ /* We have alpha if the visual has something other than red, green,
* and blue */
visual_has_alpha = visual->red_prec + visual->blue_prec + visual->green_prec < visual->depth; visual_has_alpha = visual->red_prec + visual->blue_prec + visual->green_prec < visual->depth;
if (visual_has_alpha && gdk_display_supports_composite (gtk_widget_get_display (widget))) if (visual_has_alpha && gdk_display_supports_composite (gtk_widget_get_display (widget)))
{ {
/* We have real transparency with an ARGB visual and the Composite extension. /* We have real transparency with an ARGB visual and the Composite
*/ * extension. */
/* Set a transparent background */ /* Set a transparent background */
GdkColor transparent = { 0, 0, 0, 0 }; /* only pixel=0 matters */ GdkColor transparent = { 0, 0, 0, 0 }; /* only pixel=0 matters */
gdk_window_set_background(widget->window, &transparent); gdk_window_set_background (widget->window, &transparent);
gdk_window_set_composited (widget->window, TRUE); gdk_window_set_composited (widget->window, TRUE);
child->is_composited = TRUE; child->is_composited = TRUE;
@ -64,9 +65,8 @@ na_tray_child_realize (GtkWidget *widget)
} }
else if (visual == gdk_drawable_get_visual (GDK_DRAWABLE (gdk_window_get_parent (widget->window)))) else if (visual == gdk_drawable_get_visual (GDK_DRAWABLE (gdk_window_get_parent (widget->window))))
{ {
/* Otherwise, if the visual matches the visual of the parent window, we can /* Otherwise, if the visual matches the visual of the parent window, we
* use a parent-relative background and fake transparency. * can use a parent-relative background and fake transparency. */
*/
gdk_window_set_back_pixmap (widget->window, NULL, TRUE); gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
child->is_composited = FALSE; child->is_composited = FALSE;
@ -75,41 +75,42 @@ na_tray_child_realize (GtkWidget *widget)
else else
{ {
/* Nothing to do; the icon will sit on top of an ugly gray box */ /* Nothing to do; the icon will sit on top of an ugly gray box */
child->is_composited = FALSE; child->is_composited = FALSE;
child->parent_relative_bg = FALSE; child->parent_relative_bg = FALSE;
} }
gtk_widget_set_app_paintable (GTK_WIDGET (child), gtk_widget_set_app_paintable (GTK_WIDGET (child),
child->parent_relative_bg || child->is_composited); child->parent_relative_bg || child->is_composited);
/* Double-buffering will interfere with the parent-relative-background fake /* Double-buffering will interfere with the parent-relative-background fake
* transparency, since the double-buffer code doesn't know how to fill in the * transparency, since the double-buffer code doesn't know how to fill in the
* background of the double-buffer correctly. * background of the double-buffer correctly.
*/ */
gtk_widget_set_double_buffered (GTK_WIDGET (child), child->parent_relative_bg); gtk_widget_set_double_buffered (GTK_WIDGET (child),
child->parent_relative_bg);
} }
static void static void
na_tray_child_style_set (GtkWidget *widget, na_tray_child_style_set (GtkWidget *widget,
GtkStyle *previous_style) GtkStyle *previous_style)
{ {
/* The default handler resets the background according to the new /* The default handler resets the background according to the new style.
* style. We either use a transparent background or a parent-relative background * We either use a transparent background or a parent-relative background
* and ignore the style background. So, just don't chain up. * and ignore the style background. So, just don't chain up.
*/ */
} }
#if 0 #if 0
/* This is adapted from code that was commented out in na-tray-manager.c; the code /* This is adapted from code that was commented out in na-tray-manager.c; the
* in na-tray-manager.c wouldn't have worked reliably, this will. So maybe it can * code in na-tray-manager.c wouldn't have worked reliably, this will. So maybe
* be reenabled. On other hand, things seem to be working fine without it. * it can be reenabled. On other hand, things seem to be working fine without
* it.
* *
* If reenabling, you need to hook it up in na_tray_child_class_init(). * If reenabling, you need to hook it up in na_tray_child_class_init().
*/ */
static void static void
na_tray_child_size_request (GtkWidget *widget, na_tray_child_size_request (GtkWidget *widget,
GtkRequisition *request) GtkRequisition *request)
{ {
GTK_WIDGET_CLASS (na_tray_child_parent_class)->size_request (widget, request); GTK_WIDGET_CLASS (na_tray_child_parent_class)->size_request (widget, request);
@ -121,7 +122,7 @@ na_tray_child_size_request (GtkWidget *widget,
gint nw = MAX (24, request->width); gint nw = MAX (24, request->width);
gint nh = MAX (24, request->height); gint nh = MAX (24, request->height);
g_warning ("Tray icon has requested a size of (%ix%i), resizing to (%ix%i)", g_warning ("Tray icon has requested a size of (%ix%i), resizing to (%ix%i)",
req.width, req.height, nw, nh); req.width, req.height, nw, nh);
request->width = nw; request->width = nw;
request->height = nh; request->height = nh;
} }
@ -130,39 +131,42 @@ na_tray_child_size_request (GtkWidget *widget,
static void static void
na_tray_child_size_allocate (GtkWidget *widget, na_tray_child_size_allocate (GtkWidget *widget,
GtkAllocation *allocation) GtkAllocation *allocation)
{ {
NaTrayChild *child = NA_TRAY_CHILD (widget); NaTrayChild *child = NA_TRAY_CHILD (widget);
gboolean moved = allocation->x != widget->allocation.x || allocation->y != widget->allocation.y; gboolean moved = allocation->x != widget->allocation.x ||
gboolean resized = allocation->width != widget->allocation.width || allocation->height != widget->allocation.height; allocation->y != widget->allocation.y;
gboolean resized = allocation->width != widget->allocation.width ||
allocation->height != widget->allocation.height;
/* When we are allocating the widget while mapped we need special handling for /* When we are allocating the widget while mapped we need special handling
* both real and fake transparency. * for both real and fake transparency.
* *
* Real transparency: we need to invalidate and trigger a redraw of the old * Real transparency: we need to invalidate and trigger a redraw of the old
* and new areas. (GDK really should handle this for us, but doesn't as of * and new areas. (GDK really should handle this for us, but doesn't as of
* GTK+-2.14) * GTK+-2.14)
* *
* Fake transparency: if the widget moved, we need to force the contents to be * Fake transparency: if the widget moved, we need to force the contents to
* redrawn with the new offset for the parent-relative background. * be redrawn with the new offset for the parent-relative background.
*/ */
if ((moved || resized) && GTK_WIDGET_MAPPED (widget)) if ((moved || resized) && GTK_WIDGET_MAPPED (widget))
{ {
if (na_tray_child_is_composited (child)) if (na_tray_child_is_composited (child))
gdk_window_invalidate_rect (gdk_window_get_parent (widget->window), gdk_window_invalidate_rect (gdk_window_get_parent (widget->window),
&widget->allocation, FALSE); &widget->allocation, FALSE);
} }
GTK_WIDGET_CLASS (na_tray_child_parent_class)->size_allocate (widget, allocation); GTK_WIDGET_CLASS (na_tray_child_parent_class)->size_allocate (widget,
allocation);
if ((moved || resized) && GTK_WIDGET_MAPPED (widget)) if ((moved || resized) && GTK_WIDGET_MAPPED (widget))
{ {
if (na_tray_child_is_composited (NA_TRAY_CHILD (widget))) if (na_tray_child_is_composited (NA_TRAY_CHILD (widget)))
gdk_window_invalidate_rect (gdk_window_get_parent (widget->window), gdk_window_invalidate_rect (gdk_window_get_parent (widget->window),
&widget->allocation, FALSE); &widget->allocation, FALSE);
else if (moved && child->parent_relative_bg) else if (moved && child->parent_relative_bg)
na_tray_child_force_redraw (child); na_tray_child_force_redraw (child);
} }
} }
@ -172,7 +176,7 @@ na_tray_child_size_allocate (GtkWidget *widget,
*/ */
static gboolean static gboolean
na_tray_child_expose_event (GtkWidget *widget, na_tray_child_expose_event (GtkWidget *widget,
GdkEventExpose *event) GdkEventExpose *event)
{ {
NaTrayChild *child = NA_TRAY_CHILD (widget); NaTrayChild *child = NA_TRAY_CHILD (widget);
@ -190,8 +194,8 @@ na_tray_child_expose_event (GtkWidget *widget,
{ {
/* Clear to parent-relative pixmap */ /* Clear to parent-relative pixmap */
gdk_window_clear_area (widget->window, gdk_window_clear_area (widget->window,
event->area.x, event->area.y, event->area.x, event->area.y,
event->area.width, event->area.height); event->area.width, event->area.height);
} }
return FALSE; return FALSE;
@ -220,7 +224,7 @@ na_tray_child_class_init (NaTrayChildClass *klass)
GtkWidget * GtkWidget *
na_tray_child_new (GdkScreen *screen, na_tray_child_new (GdkScreen *screen,
Window icon_window) Window icon_window)
{ {
XWindowAttributes window_attributes; XWindowAttributes window_attributes;
Display *xdisplay; Display *xdisplay;
@ -241,14 +245,14 @@ na_tray_child_new (GdkScreen *screen,
gdk_error_trap_push (); gdk_error_trap_push ();
result = XGetWindowAttributes (xdisplay, icon_window, result = XGetWindowAttributes (xdisplay, icon_window,
&window_attributes); &window_attributes);
gdk_error_trap_pop (); gdk_error_trap_pop ();
if (!result) /* Window already gone */ if (!result) /* Window already gone */
return NULL; return NULL;
visual = gdk_x11_screen_lookup_visual (screen, visual = gdk_x11_screen_lookup_visual (screen,
window_attributes.visual->visualid); window_attributes.visual->visualid);
if (!visual) /* Icon window is on another screen? */ if (!visual) /* Icon window is on another screen? */
return NULL; return NULL;
@ -299,12 +303,12 @@ na_tray_child_get_title (NaTrayChild *child)
gdk_error_trap_push (); gdk_error_trap_push ();
result = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), result = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
child->icon_window, child->icon_window,
atom, atom,
0, G_MAXLONG, 0, G_MAXLONG,
False, utf8_string, False, utf8_string,
&type, &format, &nitems, &type, &format, &nitems,
&bytes_after, (guchar **)&val); &bytes_after, (guchar **)&val);
if (gdk_error_trap_pop () || result != Success) if (gdk_error_trap_pop () || result != Success)
return NULL; return NULL;
@ -314,7 +318,7 @@ na_tray_child_get_title (NaTrayChild *child)
nitems == 0) nitems == 0)
{ {
if (val) if (val)
XFree (val); XFree (val);
return NULL; return NULL;
} }
@ -341,7 +345,7 @@ na_tray_child_is_composited (NaTrayChild *child)
/* If we are faking transparency with a window-relative background, force a /* If we are faking transparency with a window-relative background, force a
* redraw of the icon. This should be called if the background changes or if * redraw of the icon. This should be called if the background changes or if
* the child is shifed with respect to the background. * the child is shifted with respect to the background.
*/ */
void void
na_tray_child_force_redraw (NaTrayChild *child) na_tray_child_force_redraw (NaTrayChild *child)
@ -368,9 +372,9 @@ na_tray_child_force_redraw (NaTrayChild *child)
gdk_error_trap_push (); gdk_error_trap_push ();
XSendEvent (GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (widget)), XSendEvent (GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (widget)),
xev.xexpose.window, xev.xexpose.window,
False, ExposureMask, False, ExposureMask,
&xev); &xev);
/* We have to sync to reliably catch errors from the XSendEvent(), /* We have to sync to reliably catch errors from the XSendEvent(),
* since that is asynchronous. * since that is asynchronous.
*/ */

View File

@ -28,14 +28,14 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define NA_TYPE_TRAY_CHILD (na_tray_child_get_type ()) #define NA_TYPE_TRAY_CHILD (na_tray_child_get_type ())
#define NA_TRAY_CHILD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NA_TYPE_TRAY_CHILD, NaTrayChild)) #define NA_TRAY_CHILD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NA_TYPE_TRAY_CHILD, NaTrayChild))
#define NA_TRAY_CHILD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NA_TYPE_TRAY_CHILD, NaTrayChildClass)) #define NA_TRAY_CHILD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NA_TYPE_TRAY_CHILD, NaTrayChildClass))
#define NA_IS_TRAY_CHILD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NA_TYPE_TRAY_CHILD)) #define NA_IS_TRAY_CHILD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NA_TYPE_TRAY_CHILD))
#define NA_IS_TRAY_CHILD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NA_TYPE_TRAY_CHILD)) #define NA_IS_TRAY_CHILD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NA_TYPE_TRAY_CHILD))
#define NA_TRAY_CHILD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NA_TYPE_TRAY_CHILD, NaTrayChildClass)) #define NA_TRAY_CHILD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NA_TYPE_TRAY_CHILD, NaTrayChildClass))
typedef struct _NaTrayChild NaTrayChild; typedef struct _NaTrayChild NaTrayChild;
typedef struct _NaTrayChildClass NaTrayChildClass; typedef struct _NaTrayChildClass NaTrayChildClass;
typedef struct _NaTrayChildChild NaTrayChildChild; typedef struct _NaTrayChildChild NaTrayChildChild;

View File

@ -254,7 +254,8 @@ na_tray_manager_plug_removed (GtkSocket *socket,
{ {
NaTrayChild *child = NA_TRAY_CHILD (socket); NaTrayChild *child = NA_TRAY_CHILD (socket);
g_hash_table_remove (manager->socket_table, GINT_TO_POINTER (child->icon_window)); g_hash_table_remove (manager->socket_table,
GINT_TO_POINTER (child->icon_window));
g_signal_emit (manager, manager_signals[TRAY_ICON_REMOVED], 0, child); g_signal_emit (manager, manager_signals[TRAY_ICON_REMOVED], 0, child);
/* This destroys the socket. */ /* This destroys the socket. */
@ -268,7 +269,8 @@ na_tray_manager_handle_dock_request (NaTrayManager *manager,
Window icon_window = xevent->data.l[2]; Window icon_window = xevent->data.l[2];
GtkWidget *child; GtkWidget *child;
if (g_hash_table_lookup (manager->socket_table, GINT_TO_POINTER (icon_window))) if (g_hash_table_lookup (manager->socket_table,
GINT_TO_POINTER (icon_window)))
{ {
/* We already got this notification earlier, ignore this one */ /* We already got this notification earlier, ignore this one */
return; return;
@ -302,7 +304,8 @@ na_tray_manager_handle_dock_request (NaTrayManager *manager,
return; return;
} }
g_hash_table_insert (manager->socket_table, GINT_TO_POINTER (icon_window), child); g_hash_table_insert (manager->socket_table,
GINT_TO_POINTER (icon_window), child);
gtk_widget_show (child); gtk_widget_show (child);
} }
@ -631,20 +634,22 @@ na_tray_manager_set_visual_property (NaTrayManager *manager)
{ {
/* We actually want the visual of the tray where the icons will /* We actually want the visual of the tray where the icons will
* be embedded. In almost all cases, this will be the same as the visual * be embedded. In almost all cases, this will be the same as the visual
* of the screen * of the screen.
*/ */
GdkColormap *colormap = gdk_screen_get_default_colormap (manager->screen); GdkColormap *colormap;
colormap = gdk_screen_get_default_colormap (manager->screen);
xvisual = GDK_VISUAL_XVISUAL (gdk_colormap_get_visual (colormap)); xvisual = GDK_VISUAL_XVISUAL (gdk_colormap_get_visual (colormap));
} }
data[0] = XVisualIDFromVisual (xvisual); data[0] = XVisualIDFromVisual (xvisual);
XChangeProperty (GDK_DISPLAY_XDISPLAY (display), XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
GDK_WINDOW_XWINDOW (manager->invisible->window), GDK_WINDOW_XWINDOW (manager->invisible->window),
visual_atom, visual_atom,
XA_VISUALID, 32, XA_VISUALID, 32,
PropModeReplace, PropModeReplace,
(guchar *) &data, 1); (guchar *) &data, 1);
#endif #endif
} }