Commit 9f920d60 authored by Rodrigo Moya's avatar Rodrigo Moya Committed by Rodrigo Moya
Browse files

2005-09-07 Rodrigo Moya <rodrigo@novell.com>

	* gnome/panel/eggtrayicon.[ch]:
	* examples/python/systray/eggtrayicon.[ch]: updated code from libegg.


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@950 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
parent ad61bd69
2005-09-07 Rodrigo Moya <rodrigo@novell.com>
* gnome/panel/eggtrayicon.[ch]:
* examples/python/systray/eggtrayicon.[ch]: updated code from libegg.
2005-09-07 Dan Williams <dcbw@redhat.com>
Patch from Bill Moss <bmoss@clemson.edu>
......
......@@ -24,11 +24,23 @@
#include "eggtrayicon.h"
#include <gdkconfig.h>
#if defined (GDK_WINDOWING_X11)
#include <gdk/gdkx.h>
#include <X11/Xatom.h>
#elif defined (GDK_WINDOWING_WIN32)
#include <gdk/gdkwin32.h>
#endif
#ifndef EGG_COMPILATION
#ifndef _
#define _(x) dgettext (GETTEXT_PACKAGE, x)
#define N_(x) x
#endif
#else
#define _(x) x
#define N_(x) x
#endif
#define SYSTEM_TRAY_REQUEST_DOCK 0
#define SYSTEM_TRAY_BEGIN_MESSAGE 1
......@@ -55,7 +67,11 @@ static void egg_tray_icon_get_property (GObject *object,
static void egg_tray_icon_realize (GtkWidget *widget);
static void egg_tray_icon_unrealize (GtkWidget *widget);
static void egg_tray_icon_update_manager_window (EggTrayIcon *icon);
#ifdef GDK_WINDOWING_X11
static void egg_tray_icon_update_manager_window (EggTrayIcon *icon,
gboolean dock_if_realized);
static void egg_tray_icon_manager_window_destroyed (EggTrayIcon *icon);
#endif
GType
egg_tray_icon_get_type (void)
......@@ -113,6 +129,14 @@ egg_tray_icon_class_init (EggTrayIconClass *klass)
GTK_TYPE_ORIENTATION,
GTK_ORIENTATION_HORIZONTAL,
G_PARAM_READABLE));
#if defined (GDK_WINDOWING_X11)
/* Nothing */
#elif defined (GDK_WINDOWING_WIN32)
g_warning ("Port eggtrayicon to Win32");
#else
g_warning ("Port eggtrayicon to this GTK+ backend");
#endif
}
static void
......@@ -134,6 +158,8 @@ egg_tray_icon_get_property (GObject *object,
}
}
#ifdef GDK_WINDOWING_X11
static void
egg_tray_icon_get_orientation_property (EggTrayIcon *icon)
{
......@@ -196,7 +222,7 @@ egg_tray_icon_manager_filter (GdkXEvent *xevent, GdkEvent *event, gpointer user_
xev->xclient.message_type == icon->manager_atom &&
xev->xclient.data.l[1] == icon->selection_atom)
{
egg_tray_icon_update_manager_window (icon);
egg_tray_icon_update_manager_window (icon, TRUE);
}
else if (xev->xany.window == icon->manager_window)
{
......@@ -207,16 +233,18 @@ egg_tray_icon_manager_filter (GdkXEvent *xevent, GdkEvent *event, gpointer user_
}
if (xev->xany.type == DestroyNotify)
{
egg_tray_icon_update_manager_window (icon);
egg_tray_icon_manager_window_destroyed (icon);
}
}
return GDK_FILTER_CONTINUE;
}
#endif
static void
egg_tray_icon_unrealize (GtkWidget *widget)
{
#ifdef GDK_WINDOWING_X11
EggTrayIcon *icon = EGG_TRAY_ICON (widget);
GdkWindow *root_window;
......@@ -236,8 +264,11 @@ egg_tray_icon_unrealize (GtkWidget *widget)
if (GTK_WIDGET_CLASS (parent_class)->unrealize)
(* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
#endif
}
#ifdef GDK_WINDOWING_X11
static void
egg_tray_icon_send_manager_message (EggTrayIcon *icon,
long message,
......@@ -279,21 +310,15 @@ egg_tray_icon_send_dock_request (EggTrayIcon *icon)
}
static void
egg_tray_icon_update_manager_window (EggTrayIcon *icon)
egg_tray_icon_update_manager_window (EggTrayIcon *icon,
gboolean dock_if_realized)
{
Display *xdisplay;
xdisplay = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon)));
if (icon->manager_window != None)
{
GdkWindow *gdkwin;
return;
gdkwin = gdk_window_lookup_for_display (gtk_widget_get_display (GTK_WIDGET (icon)),
icon->manager_window);
gdk_window_remove_filter (gdkwin, egg_tray_icon_manager_filter, icon);
}
xdisplay = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon)));
XGrabServer (xdisplay);
......@@ -316,16 +341,36 @@ egg_tray_icon_update_manager_window (EggTrayIcon *icon)
gdk_window_add_filter (gdkwin, egg_tray_icon_manager_filter, icon);
/* Send a request that we'd like to dock */
egg_tray_icon_send_dock_request (icon);
if (dock_if_realized && GTK_WIDGET_REALIZED (icon))
egg_tray_icon_send_dock_request (icon);
egg_tray_icon_get_orientation_property (icon);
}
}
static void
egg_tray_icon_manager_window_destroyed (EggTrayIcon *icon)
{
GdkWindow *gdkwin;
g_return_if_fail (icon->manager_window != None);
gdkwin = gdk_window_lookup_for_display (gtk_widget_get_display (GTK_WIDGET (icon)),
icon->manager_window);
gdk_window_remove_filter (gdkwin, egg_tray_icon_manager_filter, icon);
icon->manager_window = None;
egg_tray_icon_update_manager_window (icon, TRUE);
}
#endif
static void
egg_tray_icon_realize (GtkWidget *widget)
{
#ifdef GDK_WINDOWING_X11
EggTrayIcon *icon = EGG_TRAY_ICON (widget);
GdkScreen *screen;
GdkDisplay *display;
......@@ -357,25 +402,15 @@ egg_tray_icon_realize (GtkWidget *widget)
"_NET_SYSTEM_TRAY_ORIENTATION",
False);
egg_tray_icon_update_manager_window (icon);
egg_tray_icon_update_manager_window (icon, FALSE);
egg_tray_icon_send_dock_request (icon);
root_window = gdk_screen_get_root_window (screen);
/* Add a root window filter so that we get changes on MANAGER */
gdk_window_add_filter (root_window,
egg_tray_icon_manager_filter, icon);
}
EggTrayIcon *
egg_tray_icon_new_for_xscreen (Screen *xscreen, const char *name)
{
GdkDisplay *display;
GdkScreen *screen;
display = gdk_x11_lookup_xdisplay (DisplayOfScreen (xscreen));
screen = gdk_display_get_screen (display, XScreenNumberOfScreen (xscreen));
return egg_tray_icon_new_for_screen (screen, name);
#endif
}
EggTrayIcon *
......@@ -404,14 +439,17 @@ egg_tray_icon_send_message (EggTrayIcon *icon,
g_return_val_if_fail (timeout >= 0, 0);
g_return_val_if_fail (message != NULL, 0);
#ifdef GDK_WINDOWING_X11
if (icon->manager_window == None)
return 0;
#endif
if (len < 0)
len = strlen (message);
stamp = icon->stamp++;
#ifdef GDK_WINDOWING_X11
/* Get ready to send the message */
egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_BEGIN_MESSAGE,
(Window)gtk_plug_get_id (GTK_PLUG (icon)),
......@@ -448,6 +486,7 @@ egg_tray_icon_send_message (EggTrayIcon *icon,
XSync (xdisplay, False);
}
gdk_error_trap_pop ();
#endif
return stamp;
}
......@@ -458,10 +497,11 @@ egg_tray_icon_cancel_message (EggTrayIcon *icon,
{
g_return_if_fail (EGG_IS_TRAY_ICON (icon));
g_return_if_fail (id > 0);
#ifdef GDK_WINDOWING_X11
egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_CANCEL_MESSAGE,
(Window)gtk_plug_get_id (GTK_PLUG (icon)),
id, 0, 0);
#endif
}
GtkOrientation
......
......@@ -22,7 +22,9 @@
#define __EGG_TRAY_ICON_H__
#include <gtk/gtkplug.h>
#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
#endif
G_BEGIN_DECLS
......@@ -42,12 +44,13 @@ struct _EggTrayIcon
guint stamp;
#ifdef GDK_WINDOWING_X11
Atom selection_atom;
Atom manager_atom;
Atom system_tray_opcode_atom;
Atom orientation_atom;
Window manager_window;
#endif
GtkOrientation orientation;
};
......
......@@ -24,8 +24,13 @@
#include "eggtrayicon.h"
#include <gdkconfig.h>
#if defined (GDK_WINDOWING_X11)
#include <gdk/gdkx.h>
#include <X11/Xatom.h>
#elif defined (GDK_WINDOWING_WIN32)
#include <gdk/gdkwin32.h>
#endif
#ifndef EGG_COMPILATION
#ifndef _
......@@ -62,7 +67,11 @@ static void egg_tray_icon_get_property (GObject *object,
static void egg_tray_icon_realize (GtkWidget *widget);
static void egg_tray_icon_unrealize (GtkWidget *widget);
static void egg_tray_icon_update_manager_window (EggTrayIcon *icon);
#ifdef GDK_WINDOWING_X11
static void egg_tray_icon_update_manager_window (EggTrayIcon *icon,
gboolean dock_if_realized);
static void egg_tray_icon_manager_window_destroyed (EggTrayIcon *icon);
#endif
GType
egg_tray_icon_get_type (void)
......@@ -120,6 +129,14 @@ egg_tray_icon_class_init (EggTrayIconClass *klass)
GTK_TYPE_ORIENTATION,
GTK_ORIENTATION_HORIZONTAL,
G_PARAM_READABLE));
#if defined (GDK_WINDOWING_X11)
/* Nothing */
#elif defined (GDK_WINDOWING_WIN32)
g_warning ("Port eggtrayicon to Win32");
#else
g_warning ("Port eggtrayicon to this GTK+ backend");
#endif
}
static void
......@@ -141,6 +158,8 @@ egg_tray_icon_get_property (GObject *object,
}
}
#ifdef GDK_WINDOWING_X11
static void
egg_tray_icon_get_orientation_property (EggTrayIcon *icon)
{
......@@ -203,7 +222,7 @@ egg_tray_icon_manager_filter (GdkXEvent *xevent, GdkEvent *event, gpointer user_
xev->xclient.message_type == icon->manager_atom &&
xev->xclient.data.l[1] == icon->selection_atom)
{
egg_tray_icon_update_manager_window (icon);
egg_tray_icon_update_manager_window (icon, TRUE);
}
else if (xev->xany.window == icon->manager_window)
{
......@@ -214,16 +233,18 @@ egg_tray_icon_manager_filter (GdkXEvent *xevent, GdkEvent *event, gpointer user_
}
if (xev->xany.type == DestroyNotify)
{
egg_tray_icon_update_manager_window (icon);
egg_tray_icon_manager_window_destroyed (icon);
}
}
return GDK_FILTER_CONTINUE;
}
#endif
static void
egg_tray_icon_unrealize (GtkWidget *widget)
{
#ifdef GDK_WINDOWING_X11
EggTrayIcon *icon = EGG_TRAY_ICON (widget);
GdkWindow *root_window;
......@@ -243,8 +264,11 @@ egg_tray_icon_unrealize (GtkWidget *widget)
if (GTK_WIDGET_CLASS (parent_class)->unrealize)
(* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
#endif
}
#ifdef GDK_WINDOWING_X11
static void
egg_tray_icon_send_manager_message (EggTrayIcon *icon,
long message,
......@@ -286,21 +310,15 @@ egg_tray_icon_send_dock_request (EggTrayIcon *icon)
}
static void
egg_tray_icon_update_manager_window (EggTrayIcon *icon)
egg_tray_icon_update_manager_window (EggTrayIcon *icon,
gboolean dock_if_realized)
{
Display *xdisplay;
xdisplay = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon)));
if (icon->manager_window != None)
{
GdkWindow *gdkwin;
return;
gdkwin = gdk_window_lookup_for_display (gtk_widget_get_display (GTK_WIDGET (icon)),
icon->manager_window);
gdk_window_remove_filter (gdkwin, egg_tray_icon_manager_filter, icon);
}
xdisplay = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon)));
XGrabServer (xdisplay);
......@@ -323,16 +341,36 @@ egg_tray_icon_update_manager_window (EggTrayIcon *icon)
gdk_window_add_filter (gdkwin, egg_tray_icon_manager_filter, icon);
/* Send a request that we'd like to dock */
egg_tray_icon_send_dock_request (icon);
if (dock_if_realized && GTK_WIDGET_REALIZED (icon))
egg_tray_icon_send_dock_request (icon);
egg_tray_icon_get_orientation_property (icon);
}
}
static void
egg_tray_icon_manager_window_destroyed (EggTrayIcon *icon)
{
GdkWindow *gdkwin;
g_return_if_fail (icon->manager_window != None);
gdkwin = gdk_window_lookup_for_display (gtk_widget_get_display (GTK_WIDGET (icon)),
icon->manager_window);
gdk_window_remove_filter (gdkwin, egg_tray_icon_manager_filter, icon);
icon->manager_window = None;
egg_tray_icon_update_manager_window (icon, TRUE);
}
#endif
static void
egg_tray_icon_realize (GtkWidget *widget)
{
#ifdef GDK_WINDOWING_X11
EggTrayIcon *icon = EGG_TRAY_ICON (widget);
GdkScreen *screen;
GdkDisplay *display;
......@@ -364,13 +402,15 @@ egg_tray_icon_realize (GtkWidget *widget)
"_NET_SYSTEM_TRAY_ORIENTATION",
False);
egg_tray_icon_update_manager_window (icon);
egg_tray_icon_update_manager_window (icon, FALSE);
egg_tray_icon_send_dock_request (icon);
root_window = gdk_screen_get_root_window (screen);
/* Add a root window filter so that we get changes on MANAGER */
gdk_window_add_filter (root_window,
egg_tray_icon_manager_filter, icon);
#endif
}
EggTrayIcon *
......@@ -399,14 +439,17 @@ egg_tray_icon_send_message (EggTrayIcon *icon,
g_return_val_if_fail (timeout >= 0, 0);
g_return_val_if_fail (message != NULL, 0);
#ifdef GDK_WINDOWING_X11
if (icon->manager_window == None)
return 0;
#endif
if (len < 0)
len = strlen (message);
stamp = icon->stamp++;
#ifdef GDK_WINDOWING_X11
/* Get ready to send the message */
egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_BEGIN_MESSAGE,
(Window)gtk_plug_get_id (GTK_PLUG (icon)),
......@@ -443,6 +486,7 @@ egg_tray_icon_send_message (EggTrayIcon *icon,
XSync (xdisplay, False);
}
gdk_error_trap_pop ();
#endif
return stamp;
}
......@@ -453,10 +497,11 @@ egg_tray_icon_cancel_message (EggTrayIcon *icon,
{
g_return_if_fail (EGG_IS_TRAY_ICON (icon));
g_return_if_fail (id > 0);
#ifdef GDK_WINDOWING_X11
egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_CANCEL_MESSAGE,
(Window)gtk_plug_get_id (GTK_PLUG (icon)),
id, 0, 0);
#endif
}
GtkOrientation
......
......@@ -22,7 +22,9 @@
#define __EGG_TRAY_ICON_H__
#include <gtk/gtkplug.h>
#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
#endif
G_BEGIN_DECLS
......@@ -42,12 +44,13 @@ struct _EggTrayIcon
guint stamp;
#ifdef GDK_WINDOWING_X11
Atom selection_atom;
Atom manager_atom;
Atom system_tray_opcode_atom;
Atom orientation_atom;
Window manager_window;
#endif
GtkOrientation orientation;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment