2
* Copyright (C) 2007 Neil Jagdish Patel
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with this library; if not, write to the
16
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
* Boston, MA 02111-1307, USA.
23
#include <X11/Xatom.h>
26
#include <cairo-dock.h>
28
#include "systray-struct.h"
31
//static const guint icon_size_w = 24;
32
//static const guint icon_size_h = 24;
35
tray_icon_added (NaTrayManager *manager,
40
tray_icon_removed (NaTrayManager *manager,
45
tray_icon_message_sent (NaTrayManager *manager,
53
tray_icon_message_cancelled (NaTrayManager *manager,
60
static void tray_resize_container(TrayApplet *applet)
62
/* GtkRequisition req; */
64
/* gtk_widget_size_request(GTK_WIDGET(applet->box), &req); */
65
/* if (systray.dialog && &systray.dialog->pWidget) */
66
/* /\* gtk_widget_set_size_request(GTK_WINDOW(systray.dialog->pWidget), req.width, req.height); *\/ */
67
/* // gtk_window_set_default_size(GTK_WINDOW(systray.dialog->pWidget), req.width, req.height); */
68
/* gtk_window_resize(GTK_WINDOW(systray.dialog->pWidget), req.width, req.height); */
73
static gboolean idle_redraw_cb (TrayApplet *applet)
75
applet->idle_redraw_id = 0;
76
gtk_widget_hide(applet->box);
77
gtk_widget_show(applet->box);
81
static void force_redraw (TrayApplet *applet)
83
/* Force the icons to redraw their backgrounds.
84
* gtk_widget_queue_draw() doesn't work across process boundaries,
85
* so we do this instead.
87
if (applet->idle_redraw_id == 0)
88
applet->idle_redraw_id = g_idle_add ((GSourceFunc) idle_redraw_cb, applet);
93
tray_icon_added (NaTrayManager *manager,
97
applet->icons = g_list_append (applet->icons, icon);
98
gtk_widget_set_colormap(icon, gdk_screen_get_rgb_colormap (gdk_screen_get_default()));
99
gtk_box_pack_start(GTK_BOX(applet->box), icon, TRUE, TRUE, 0);
100
//gtk_widget_set_size_request((applet->box), 52, 28);
101
gtk_widget_set_size_request(icon, myConfig.iIconSize, myConfig.iIconSize);
102
//tray_resize_container(applet);
103
force_redraw(applet);
107
tray_icon_removed (NaTrayManager *manager,
111
applet->icons = g_list_remove (applet->icons, icon);
112
tray_resize_container(applet);
113
gtk_container_remove(GTK_CONTAINER(applet->box), icon);
117
tray_icon_message_sent (NaTrayManager *manager,
124
g_warning ("tray_icon_message_sent : %s\n", text);
125
cairo_dock_show_temporary_dialog(text, myIcon, myContainer, timeout);
128
static void tray_icon_message_cancelled (NaTrayManager *manager,
133
/* FIXME: Er, cancel the message :-/? */
136
static gboolean tray_clean_up(GtkWidget *widget,
140
TrayApplet *tray = (TrayApplet *)user_data;
141
g_warning("free baby\n");
142
g_object_unref (tray->manager);
143
g_object_unref (tray);
147
static gboolean cd_desklet_on_expose(GtkWidget *pWidget,
148
GdkEventExpose *pExpose,
151
cairo_t *pCairoContext = gdk_cairo_create (pWidget->window);
152
if (cairo_status (pCairoContext) != CAIRO_STATUS_SUCCESS, FALSE) {
153
cairo_destroy (pCairoContext);
156
//erase the background
157
cairo_set_source_rgba (pCairoContext, 0., 0., 1., 0.15);
158
cairo_set_operator (pCairoContext, CAIRO_OPERATOR_SOURCE);
159
cairo_paint (pCairoContext);
160
cairo_destroy (pCairoContext);
164
static void tray_create_widget(TrayApplet *applet)
166
applet->manager = na_tray_manager_new();
167
if (!na_tray_manager_manage_screen (applet->manager, applet->screen))
168
g_warning ("The notification area could not manage the screen \n");
169
g_signal_connect (applet->box, "delete-event",
170
G_CALLBACK (tray_clean_up), applet);
172
g_signal_connect (applet->manager, "tray_icon_added",
173
G_CALLBACK (tray_icon_added), applet);
174
g_signal_connect (applet->manager, "tray_icon_removed",
175
G_CALLBACK (tray_icon_removed), applet);
176
g_signal_connect (applet->manager, "message_sent",
177
G_CALLBACK (tray_icon_message_sent), applet);
178
g_signal_connect (applet->manager, "message_cancelled",
179
G_CALLBACK (tray_icon_message_cancelled), applet);
180
g_signal_connect (applet->box, "expose-event",
181
G_CALLBACK (cd_desklet_on_expose), applet->box);
184
GdkColormap* pColormap = gdk_screen_get_rgba_colormap (applet->screen);
185
gtk_widget_set_colormap (applet->box, pColormap);
187
// GdkVisual* pVisual = gdk_rgb_get_visual ();
188
// Visual *vis = GDK_VISUAL_XVISUAL (pVisual);
189
// VisualID visualid = vis->visualid;
191
// Window Xid = GDK_DRAWABLE_XID (applet->box);
192
// Atom aNetVisualID = XInternAtom (cairo_dock_get_Xdisplay (), "_NET_SYSTEM_TRAY_VISUAL", False);
193
// XChangeProperty (cairo_dock_get_Xdisplay (),
196
// XA_VISUALID, 32, PropModeReplace,
197
// (guchar *)&visualid, 1);
199
gtk_container_add (GTK_CONTAINER (applet->widget), applet->box);
202
static void tray_icon_cb_click_steal(GtkWidget *w, TrayApplet* applet)
204
gtk_container_remove(GTK_CONTAINER(applet->widget), w);
205
tray_create_widget(applet);
208
TrayApplet* tray_init (GtkWidget *parent)
210
TrayApplet *applet = g_new0 (TrayApplet, 1);
212
GtkWidget *widget = GTK_WIDGET(parent);
214
//get the real parent
215
while (widget->parent)
216
widget = widget->parent;
217
screen = gtk_widget_get_screen(GTK_WIDGET(widget));
219
applet->box = (myConfig.iIconPacking == 0 ? gtk_hbox_new(TRUE, 0) : gtk_vbox_new(TRUE, 0));
220
gtk_widget_show(applet->box);
221
//gtk_widget_set_size_request(applet->box, icon_size_w*10, icon_size_h + 6);
222
tray_resize_container(applet);
223
applet->icons = NULL;
224
applet->screen = screen;
226
applet->widget = gtk_event_box_new ();
227
//gtk_event_box_set_visible_window(GTK_EVENT_BOX (applet->widget), TRUE); /// utile ?...
228
///gtk_widget_set_colormap(applet->widget, gdk_screen_get_rgb_colormap (screen));
229
//GdkColormap* pColormap = gdk_screen_get_rgba_colormap (screen); /// utile ?...
231
// pColormap = gdk_screen_get_rgb_colormap (screen);
232
//gtk_widget_set_colormap (applet->widget, pColormap);
235
if (na_tray_manager_check_running(screen)) {
236
cd_warning ("There is already another notification area running on this screen");
237
GtkWidget *w = gtk_button_new_with_label("TRY to steal systray icons");
239
gtk_container_add (GTK_CONTAINER (applet->widget), w);
240
g_signal_connect (w, "clicked",
241
G_CALLBACK (tray_icon_cb_click_steal), applet);
245
tray_create_widget(applet);