tray: re-sync from panel, including _NET_SYSTEM_TRAY_COLORS support

https://bugzilla.gnome.org/show_bug.cgi?id=641060
This commit is contained in:
Dan Winship 2011-02-01 12:59:30 -05:00
parent fc313b198a
commit e208c7e3dd
4 changed files with 106 additions and 23 deletions

View File

@ -24,7 +24,6 @@
#include "na-tray-child.h" #include "na-tray-child.h"
#include <glib/gi18n-lib.h>
#include <gdk/gdk.h> #include <gdk/gdk.h>
#include <gdk/gdkx.h> #include <gdk/gdkx.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
@ -173,9 +172,8 @@ na_tray_child_size_allocate (GtkWidget *widget,
} }
/* The plug window should completely occupy the area of the child, so we won't /* The plug window should completely occupy the area of the child, so we won't
* get an expose event. But in case we do (the plug unmaps itself, say), this * get a draw event. But in case we do (the plug unmaps itself, say), this
* draw handler draws with real or fake transparency. * draw handler draws with real or fake transparency.
* Copy-pasted from GtkTrayIcon.
*/ */
static gboolean static gboolean
na_tray_child_draw (GtkWidget *widget, na_tray_child_draw (GtkWidget *widget,
@ -419,7 +417,7 @@ na_tray_child_force_redraw (NaTrayChild *child)
gtk_widget_get_allocation (widget, &allocation); gtk_widget_get_allocation (widget, &allocation);
xev.xexpose.type = Expose; xev.xexpose.type = Expose;
xev.xexpose.window = gdk_x11_window_get_xid (plug_window); xev.xexpose.window = GDK_WINDOW_XID (plug_window);
xev.xexpose.x = 0; xev.xexpose.x = 0;
xev.xexpose.y = 0; xev.xexpose.y = 0;
xev.xexpose.width = allocation.width; xev.xexpose.width = allocation.width;
@ -427,14 +425,10 @@ na_tray_child_force_redraw (NaTrayChild *child)
xev.xexpose.count = 0; xev.xexpose.count = 0;
gdk_error_trap_push (); gdk_error_trap_push ();
XSendEvent (GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (widget)), XSendEvent (xdisplay,
xev.xexpose.window, xev.xexpose.window,
False, ExposureMask, False, ExposureMask,
&xev); &xev);
/* We have to sync to reliably catch errors from the XSendEvent(),
* since that is asynchronous.
*/
XSync (xdisplay, False);
gdk_error_trap_pop_ignored (); gdk_error_trap_pop_ignored ();
#else #else
/* Hiding and showing is the safe way to do it, but can result in more /* Hiding and showing is the safe way to do it, but can result in more

View File

@ -25,7 +25,6 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <gtk/gtkx.h> #include <gtk/gtkx.h>
#include <gdk/gdkx.h>
G_BEGIN_DECLS G_BEGIN_DECLS

View File

@ -26,7 +26,6 @@
#include "na-tray-manager.h" #include "na-tray-manager.h"
#include <glib/gi18n-lib.h>
#if defined (GDK_WINDOWING_X11) #if defined (GDK_WINDOWING_X11)
#include <gdk/gdkx.h> #include <gdk/gdkx.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
@ -97,6 +96,22 @@ na_tray_manager_init (NaTrayManager *manager)
{ {
manager->invisible = NULL; manager->invisible = NULL;
manager->socket_table = g_hash_table_new (NULL, NULL); manager->socket_table = g_hash_table_new (NULL, NULL);
manager->fg.red = 0;
manager->fg.green = 0;
manager->fg.blue = 0;
manager->error.red = 0xffff;
manager->error.green = 0;
manager->error.blue = 0;
manager->warning.red = 0xffff;
manager->warning.green = 0xffff;
manager->warning.blue = 0;
manager->success.red = 0;
manager->success.green = 0xffff;
manager->success.blue = 0;
} }
static void static void
@ -565,11 +580,9 @@ na_tray_manager_set_orientation_property (NaTrayManager *manager)
Atom orientation_atom; Atom orientation_atom;
gulong data[1]; gulong data[1];
if (!manager->invisible) g_return_if_fail (manager->invisible != NULL);
return;
window = gtk_widget_get_window (manager->invisible); window = gtk_widget_get_window (manager->invisible);
if (!window) g_return_if_fail (window != NULL);
return;
display = gtk_widget_get_display (manager->invisible); display = gtk_widget_get_display (manager->invisible);
orientation_atom = gdk_x11_get_xatom_by_name_for_display (display, orientation_atom = gdk_x11_get_xatom_by_name_for_display (display,
@ -580,7 +593,7 @@ na_tray_manager_set_orientation_property (NaTrayManager *manager)
SYSTEM_TRAY_ORIENTATION_VERT; SYSTEM_TRAY_ORIENTATION_VERT;
XChangeProperty (GDK_DISPLAY_XDISPLAY (display), XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
gdk_x11_window_get_xid (window), GDK_WINDOW_XID (window),
orientation_atom, orientation_atom,
XA_CARDINAL, 32, XA_CARDINAL, 32,
PropModeReplace, PropModeReplace,
@ -598,11 +611,9 @@ na_tray_manager_set_visual_property (NaTrayManager *manager)
Atom visual_atom; Atom visual_atom;
gulong data[1]; gulong data[1];
if (!manager->invisible) g_return_if_fail (manager->invisible != NULL);
return;
window = gtk_widget_get_window (manager->invisible); window = gtk_widget_get_window (manager->invisible);
if (!window) g_return_if_fail (window != NULL);
return;
/* The visual property is a hint to the tray icons as to what visual they /* The visual property is a hint to the tray icons as to what visual they
* should use for their windows. If the X server has RGBA colormaps, then * should use for their windows. If the X server has RGBA colormaps, then
@ -620,12 +631,18 @@ na_tray_manager_set_visual_property (NaTrayManager *manager)
gdk_display_supports_composite (display)) gdk_display_supports_composite (display))
xvisual = GDK_VISUAL_XVISUAL (gdk_screen_get_rgba_visual (manager->screen)); xvisual = GDK_VISUAL_XVISUAL (gdk_screen_get_rgba_visual (manager->screen));
else else
{
/* 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
* of the screen.
*/
xvisual = GDK_VISUAL_XVISUAL (gdk_screen_get_system_visual (manager->screen)); xvisual = GDK_VISUAL_XVISUAL (gdk_screen_get_system_visual (manager->screen));
}
data[0] = XVisualIDFromVisual (xvisual); data[0] = XVisualIDFromVisual (xvisual);
XChangeProperty (GDK_DISPLAY_XDISPLAY (display), XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
gdk_x11_window_get_xid (window), GDK_WINDOW_XID (window),
visual_atom, visual_atom,
XA_VISUALID, 32, XA_VISUALID, 32,
PropModeReplace, PropModeReplace,
@ -633,6 +650,45 @@ na_tray_manager_set_visual_property (NaTrayManager *manager)
#endif #endif
} }
static void
na_tray_manager_set_colors_property (NaTrayManager *manager)
{
#ifdef GDK_WINDOWING_X11
GdkWindow *window;
GdkDisplay *display;
Atom atom;
gulong data[12];
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_COLORS");
data[0] = manager->fg.red;
data[1] = manager->fg.green;
data[2] = manager->fg.blue;
data[3] = manager->error.red;
data[4] = manager->error.green;
data[5] = manager->error.blue;
data[6] = manager->warning.red;
data[7] = manager->warning.green;
data[8] = manager->warning.blue;
data[9] = manager->success.red;
data[10] = manager->success.green;
data[11] = manager->success.blue;
XChangeProperty (GDK_DISPLAY_XDISPLAY (display),
GDK_WINDOW_XID (window),
atom,
XA_CARDINAL, 32,
PropModeReplace,
(guchar *) &data, 12);
#endif
}
#ifdef GDK_WINDOWING_X11 #ifdef GDK_WINDOWING_X11
static gboolean static gboolean
@ -678,6 +734,7 @@ na_tray_manager_manage_screen_x11 (NaTrayManager *manager,
na_tray_manager_set_orientation_property (manager); na_tray_manager_set_orientation_property (manager);
na_tray_manager_set_visual_property (manager); na_tray_manager_set_visual_property (manager);
na_tray_manager_set_colors_property (manager);
window = gtk_widget_get_window (invisible); window = gtk_widget_get_window (invisible);
@ -703,7 +760,7 @@ na_tray_manager_manage_screen_x11 (NaTrayManager *manager,
xev.data.l[0] = timestamp; xev.data.l[0] = timestamp;
xev.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, xev.data.l[1] = gdk_x11_atom_to_xatom_for_display (display,
manager->selection_atom); manager->selection_atom);
xev.data.l[2] = gdk_x11_window_get_xid (window); xev.data.l[2] = GDK_WINDOW_XID (window);
xev.data.l[3] = 0; /* manager specific data */ xev.data.l[3] = 0; /* manager specific data */
xev.data.l[4] = 0; /* manager specific data */ xev.data.l[4] = 0; /* manager specific data */
@ -812,6 +869,29 @@ na_tray_manager_set_orientation (NaTrayManager *manager,
} }
} }
void
na_tray_manager_set_colors (NaTrayManager *manager,
GdkColor *fg,
GdkColor *error,
GdkColor *warning,
GdkColor *success)
{
g_return_if_fail (NA_IS_TRAY_MANAGER (manager));
if (!gdk_color_equal (&manager->fg, fg) ||
!gdk_color_equal (&manager->error, error) ||
!gdk_color_equal (&manager->warning, warning) ||
!gdk_color_equal (&manager->success, success))
{
manager->fg = *fg;
manager->error = *error;
manager->warning = *warning;
manager->success = *success;
na_tray_manager_set_colors_property (manager);
}
}
GtkOrientation GtkOrientation
na_tray_manager_get_orientation (NaTrayManager *manager) na_tray_manager_get_orientation (NaTrayManager *manager)
{ {

View File

@ -56,6 +56,10 @@ struct _NaTrayManager
GtkWidget *invisible; GtkWidget *invisible;
GdkScreen *screen; GdkScreen *screen;
GtkOrientation orientation; GtkOrientation orientation;
GdkColor fg;
GdkColor error;
GdkColor warning;
GdkColor success;
GList *messages; GList *messages;
GHashTable *socket_table; GHashTable *socket_table;
@ -92,6 +96,12 @@ gboolean na_tray_manager_manage_screen (NaTrayManager *manager,
void na_tray_manager_set_orientation (NaTrayManager *manager, void na_tray_manager_set_orientation (NaTrayManager *manager,
GtkOrientation orientation); GtkOrientation orientation);
GtkOrientation na_tray_manager_get_orientation (NaTrayManager *manager); GtkOrientation na_tray_manager_get_orientation (NaTrayManager *manager);
void na_tray_manager_set_colors (NaTrayManager *manager,
GdkColor *fg,
GdkColor *error,
GdkColor *warning,
GdkColor *success);
G_END_DECLS G_END_DECLS