diff options
author | Rodrigo Moya <rodrigo@novell.com> | 2005-09-07 21:41:00 +0000 |
---|---|---|
committer | Rodrigo Moya <rodrigo@gnome-db.org> | 2005-09-07 21:41:00 +0000 |
commit | 9f920d60cc3a723114b5c0aed465f360fa4c87ee (patch) | |
tree | e50f62d31caa7c806c37eff89947f4e2319e9e80 /examples/python | |
parent | ad61bd6964bd838d80953fff02ef8c023619e48a (diff) | |
download | NetworkManager-9f920d60cc3a723114b5c0aed465f360fa4c87ee.tar.gz |
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
Diffstat (limited to 'examples/python')
-rw-r--r-- | examples/python/systray/eggtrayicon.c | 100 | ||||
-rw-r--r-- | examples/python/systray/eggtrayicon.h | 5 |
2 files changed, 74 insertions, 31 deletions
diff --git a/examples/python/systray/eggtrayicon.c b/examples/python/systray/eggtrayicon.c index ddc47d4a33..07ce5dfce0 100644 --- a/examples/python/systray/eggtrayicon.c +++ b/examples/python/systray/eggtrayicon.c @@ -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 diff --git a/examples/python/systray/eggtrayicon.h b/examples/python/systray/eggtrayicon.h index 007f4c18e9..e6664fcb08 100644 --- a/examples/python/systray/eggtrayicon.h +++ b/examples/python/systray/eggtrayicon.h @@ -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; }; |