1
/***************************************************************************
4
* Thu Aug 4 14:57:32 2005
5
* Copyright 2005 Mark Smulders
7
****************************************************************************/
9
* System tray icon for gSTM
11
* Inspired by the Gaim plugin:
12
* Robert McQueen <robot101@debian.org>
13
* Herman Bloggs <hermanator12002@yahoo.com>
14
* Inspired by a similar plugin by:
15
* John (J5) Palmieri <johnp@martianrock.com>
17
* This program is free software; you can redistribute it and/or
18
* modify it under the terms of the GNU General Public License as
19
* published by the Free Software Foundation; either version 2 of the
20
* License, or (at your option) any later version.
22
* This program is distributed in the hope that it will be useful, but
23
* WITHOUT ANY WARRANTY; without even the implied warranty of
24
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25
* General Public License for more details.
27
* You should have received a copy of the GNU General Public License
28
* along with this program; if not, write to the Free Software
29
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
34
#include "eggtrayicon.h"
35
EggTrayIcon *docklet = NULL;
36
static GtkWidget *image = NULL;
37
extern void docklet_clicked(int);
39
static void docklet_x11_destroyed_cb(GtkWidget *widget, void *data);
42
docklet_x11_clicked_cb(GtkWidget *button, GdkEventButton *event, void *data)
44
if (event->type != GDK_BUTTON_PRESS)
47
docklet_clicked(event->button);
53
g_signal_handlers_disconnect_by_func(G_OBJECT(docklet),
54
G_CALLBACK(docklet_x11_destroyed_cb), NULL);
55
gtk_widget_destroy(GTK_WIDGET(docklet));
57
g_object_unref(G_OBJECT(docklet));
65
GdkPixbuf *pb, *pbsmall;
68
/* if this is being called when a tray icon exists, it's because
69
something messed up. try destroying it before we proceed,
70
although docklet_refcount may be all hosed. hopefully won't happen. */
71
docklet_x11_destroy();
74
docklet = egg_tray_icon_new("gSTM");
75
box = GTK_WIDGET(gtk_event_box_new());
76
image = GTK_WIDGET(gtk_image_new());
78
g_signal_connect(G_OBJECT(docklet), "destroy", G_CALLBACK(docklet_x11_destroyed_cb), NULL);
79
g_signal_connect(G_OBJECT(box), "button-press-event", G_CALLBACK(docklet_x11_clicked_cb), NULL);
81
gtk_container_add(GTK_CONTAINER(box), image);
82
gtk_container_add(GTK_CONTAINER(docklet), box);
84
if(!gtk_check_version(2,4,0))
85
g_object_set(G_OBJECT(box), "visible-window", FALSE, NULL);
87
gtk_widget_show_all(GTK_WIDGET(docklet));
89
/* ref the docklet before we bandy it about the place */
90
g_object_ref(G_OBJECT(docklet));
93
pb = GDK_PIXBUF(create_pixbuf("gstm/gSTM.xpm"));
94
/* resize the icon to a more appropriate size */
95
pbsmall = gdk_pixbuf_scale_simple(pb,24,24,GDK_INTERP_BILINEAR); //FIXME? static size
97
gtk_image_set_from_pixbuf(GTK_IMAGE(image),pbsmall);
101
docklet_x11_create_cb()
103
docklet_x11_create();
105
return FALSE; /* for when we're called by the glib idle handler */
109
docklet_x11_destroyed_cb(GtkWidget *widget, void *data)
112
g_object_unref(G_OBJECT(docklet));
115
g_idle_add(docklet_x11_create_cb, NULL);
119
docklet_x11_position_menu(GtkMenu *menu, int *x, int *y, gboolean *push_in,
122
GtkWidget *widget = GTK_WIDGET(docklet);
124
gint menu_xpos, menu_ypos;
126
gtk_widget_size_request(GTK_WIDGET(menu), &req);
127
gdk_window_get_origin(widget->window, &menu_xpos, &menu_ypos);
129
menu_xpos += widget->allocation.x;
130
menu_ypos += widget->allocation.y;
132
if (menu_ypos > gdk_screen_get_height(gtk_widget_get_screen(widget)) / 2)
133
menu_ypos -= req.height;
135
menu_ypos += widget->allocation.height;