~ubuntu-branches/debian/experimental/xfce4-panel/experimental

« back to all changes in this revision

Viewing changes to plugins/systray/xfce-tray-plugin.c

  • Committer: Bazaar Package Importer
  • Author(s): Yves-Alexis Perez, Lionel Le Folgoc, Yves-Alexis Perez
  • Date: 2011-02-06 18:10:07 UTC
  • mfrom: (1.3.13 upstream) (5.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110206181007-vpw5z3xnm3hdvybx
Tags: 4.8.1-1
[ Lionel Le Folgoc ]
* New upstream bugfix release.
* debian/control:
  - refreshed (b-)deps for this new major release
  - add myself to Uploaders
  - bump Standards-Version to 3.9.1.
* debian/NEWS: dropped, unneeded.
* debian/xfce4-panel.shlibs: refreshed, bump to (>= 4.7.2).
* debian/xfce4-panel.lintian-overrides: refreshed, new lib name.
* debian/xfce4-panel.preinst: added, handles removal of old conffiles.
* debian/xfce4-panel.postinst: explicitly set -e.
* debian/*.install: refreshed.
* debian/rules:
  - call dpkg-buildflags
  - dropped rc files mangling as they don't exist anymore
  - updated removal of *.{l,}a files.
  - drop overrides for dh_auto_{configure,clean}, obsolete.
* debian/xfce4-panel.{preinst,postinst,prerm}: use dpkg-maintscript-helper
  to remove pre-xfconf config files.
* Bugs fixed by 4.7.x/4.8.x series:
  - rgba support                                                  lp: #586012
  - disappearing menus                                             lp: #53897
  - xrandr support                               lp: #176174, Closes: #432914
  - Fails to reap children, creating zombies                      lp: #420187
  - DND of desktop-files on the panel to create new launchers Closes: #480380
* Bumped shlibs to >= 4.7.7, abi break for external plugins.

[ Yves-Alexis Perez ]
* New upstream development release
* debian/xfce4-panel.install:
  - install wrapper and migrate tools in xfce4-panel package
  - update plugins paths
* debian/rules:
  - update path when removing .a/.la files for plugins.
  - add hardening flags to {C,LD}FLAGS
* debian/control:
  - add build-dep on hardening-includes
  - update build-dep on garcon to 0.1.4.
* debian/copyright updated for new release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: xfce-tray-plugin.c 29188 2009-01-12 17:08:56Z nick $ */
2
 
/*
3
 
 * Copyright (c) 2007 Nick Schermer <nick@xfce.org>
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or modify it
6
 
 * under the terms of the GNU General Public License as published by the Free
7
 
 * Software Foundation; either version 2 of the License, or (at your option)
8
 
 * any later version.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful, but WITHOUT
11
 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
 
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13
 
 * more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License along with
16
 
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17
 
 * Place, Suite 330, Boston, MA  02111-1307  USA
18
 
 */
19
 
 
20
 
#ifdef HAVE_CONFIG_H
21
 
#include <config.h>
22
 
#endif
23
 
 
24
 
#define SMALL_PANEL_SIZE (26)
25
 
 
26
 
#include <gtk/gtk.h>
27
 
#include <libxfce4util/libxfce4util.h>
28
 
#include <libxfce4panel/xfce-panel-plugin.h>
29
 
#include <libxfce4panel/xfce-panel-macros.h>
30
 
 
31
 
#include "xfce-tray-manager.h"
32
 
#include "xfce-tray-widget.h"
33
 
#include "xfce-tray-plugin.h"
34
 
#include "xfce-tray-dialogs.h"
35
 
 
36
 
 
37
 
 
38
 
/* prototypes */
39
 
static void            xfce_tray_plugin_message                 (GtkMessageType      type,
40
 
                                                                 GdkScreen          *screen,
41
 
                                                                 const gchar        *message);
42
 
static gboolean        xfce_tray_plugin_check                   (GdkScreen          *screen);
43
 
static void            xfce_tray_plugin_update_position         (XfceTrayPlugin     *plugin);
44
 
static XfceTrayPlugin *xfce_tray_plugin_new                     (XfcePanelPlugin    *panel_plugin);
45
 
static void            xfce_tray_plugin_screen_position_changed (XfceTrayPlugin     *plugin,
46
 
                                                                 XfceScreenPosition  position);
47
 
static void            xfce_tray_plugin_orientation_changed     (XfceTrayPlugin     *plugin,
48
 
                                                                 GtkOrientation      orientation);
49
 
static gboolean        xfce_tray_plugin_size_changed            (XfceTrayPlugin     *plugin,
50
 
                                                                 guint               size);
51
 
static void            xfce_tray_plugin_read                    (XfceTrayPlugin     *plugin);
52
 
static void            xfce_tray_plugin_write                   (XfceTrayPlugin     *plugin);
53
 
static void            xfce_tray_plugin_free                    (XfceTrayPlugin     *plugin);
54
 
static void            xfce_tray_plugin_construct               (XfcePanelPlugin    *panel_plugin);
55
 
 
56
 
 
57
 
 
58
 
/* register the plugin */
59
 
XFCE_PANEL_PLUGIN_REGISTER_INTERNAL_WITH_CHECK (xfce_tray_plugin_construct, xfce_tray_plugin_check);
60
 
 
61
 
 
62
 
 
63
 
static void
64
 
xfce_tray_plugin_message (GtkMessageType  type,
65
 
                          GdkScreen      *screen,
66
 
                          const gchar    *message)
67
 
{
68
 
    GtkWidget *dialog;
69
 
 
70
 
    dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, type, GTK_BUTTONS_CLOSE, _("Notification Area"));
71
 
    gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s.", message);
72
 
    gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
73
 
    gtk_window_set_screen (GTK_WINDOW (dialog), screen);
74
 
 
75
 
    /* run the dialog */
76
 
    gtk_dialog_run (GTK_DIALOG (dialog));
77
 
 
78
 
    /* destroy */
79
 
    gtk_widget_destroy (dialog);
80
 
}
81
 
 
82
 
 
83
 
 
84
 
static gboolean
85
 
xfce_tray_plugin_check (GdkScreen *screen)
86
 
{
87
 
    gboolean   running;
88
 
 
89
 
 
90
 
    /* check if there is already a tray running */
91
 
    running = xfce_tray_manager_check_running (screen);
92
 
 
93
 
    /* message */
94
 
    if (running)
95
 
    {
96
 
        /* TRANSLATORS: This message is shown in an info dialog when the users 
97
 
           add a notification area to a screen with a running systray manager. */
98
 
        xfce_tray_plugin_message (GTK_MESSAGE_INFO, screen, _("There is already a notification area running on this screen"));
99
 
    }
100
 
 
101
 
    return (!running);
102
 
}
103
 
 
104
 
 
105
 
 
106
 
static void
107
 
xfce_tray_plugin_update_position (XfceTrayPlugin *plugin)
108
 
{
109
 
    XfceScreenPosition  position;
110
 
    GdkScreen          *screen;
111
 
    GdkRectangle        geom;
112
 
    gint                mon, x, y;
113
 
    GtkArrowType        arrow_type;
114
 
 
115
 
    _panel_return_if_fail (GTK_WIDGET_REALIZED (plugin->panel_plugin));
116
 
 
117
 
    /* get the plugin position */
118
 
    position = xfce_panel_plugin_get_screen_position (plugin->panel_plugin);
119
 
 
120
 
    /* get the button position */
121
 
    switch (position)
122
 
    {
123
 
        /*    horizontal west */
124
 
        case XFCE_SCREEN_POSITION_NW_H:
125
 
        case XFCE_SCREEN_POSITION_SW_H:
126
 
            arrow_type = GTK_ARROW_RIGHT;
127
 
            break;
128
 
 
129
 
        /* horizontal east */
130
 
        case XFCE_SCREEN_POSITION_N:
131
 
        case XFCE_SCREEN_POSITION_NE_H:
132
 
        case XFCE_SCREEN_POSITION_S:
133
 
        case XFCE_SCREEN_POSITION_SE_H:
134
 
            arrow_type = GTK_ARROW_LEFT;
135
 
            break;
136
 
 
137
 
        /* vertical north */
138
 
        case XFCE_SCREEN_POSITION_NW_V:
139
 
        case XFCE_SCREEN_POSITION_NE_V:
140
 
            arrow_type = GTK_ARROW_DOWN;
141
 
            break;
142
 
 
143
 
        /* vertical south */
144
 
        case XFCE_SCREEN_POSITION_W:
145
 
        case XFCE_SCREEN_POSITION_SW_V:
146
 
        case XFCE_SCREEN_POSITION_E:
147
 
        case XFCE_SCREEN_POSITION_SE_V:
148
 
            arrow_type = GTK_ARROW_UP;
149
 
            break;
150
 
 
151
 
        /* floating */
152
 
        default:
153
 
            /* get the screen information */
154
 
            screen = gtk_widget_get_screen (GTK_WIDGET (plugin->panel_plugin));
155
 
            mon = gdk_screen_get_monitor_at_window (screen, GTK_WIDGET (plugin->panel_plugin)->window);
156
 
            gdk_screen_get_monitor_geometry (screen, mon, &geom);
157
 
            gdk_window_get_root_origin (GTK_WIDGET (plugin->panel_plugin)->window, &x, &y);
158
 
 
159
 
            /* get the position based on the screen position */
160
 
            if (position == XFCE_SCREEN_POSITION_FLOATING_H)
161
 
                arrow_type = ((x < (geom.x + geom.width / 2)) ? GTK_ARROW_RIGHT : GTK_ARROW_LEFT);
162
 
            else
163
 
                arrow_type = ((y < (geom.y + geom.height / 2)) ? GTK_ARROW_DOWN : GTK_ARROW_UP);
164
 
            break;
165
 
    }
166
 
 
167
 
    /* set the arrow type of the tray widget */
168
 
    xfce_tray_widget_set_arrow_type (XFCE_TRAY_WIDGET (plugin->tray), arrow_type);
169
 
 
170
 
    /* update the manager orientation */
171
 
    xfce_tray_manager_set_orientation (plugin->manager, xfce_screen_position_get_orientation (position));
172
 
}
173
 
 
174
 
 
175
 
 
176
 
static void
177
 
xfce_tray_plugin_icon_added (XfceTrayManager *manager,
178
 
                             GtkWidget       *icon,
179
 
                             XfceTrayPlugin  *plugin)
180
 
{
181
 
    gchar *name;
182
 
 
183
 
    /* get the application name */
184
 
    name = xfce_tray_manager_get_application_name (icon);
185
 
 
186
 
    /* add the icon to the widget */
187
 
    xfce_tray_widget_add_with_name (XFCE_TRAY_WIDGET (plugin->tray), icon, name);
188
 
 
189
 
    /* cleanup */
190
 
    g_free (name);
191
 
 
192
 
    /* show icon */
193
 
    gtk_widget_show (icon);
194
 
}
195
 
 
196
 
 
197
 
 
198
 
static void
199
 
xfce_tray_plugin_icon_removed (XfceTrayManager *manager,
200
 
                               GtkWidget       *icon,
201
 
                               XfceTrayPlugin  *plugin)
202
 
{
203
 
    /* remove from the tray */
204
 
    gtk_container_remove (GTK_CONTAINER (plugin->tray), icon);
205
 
}
206
 
 
207
 
 
208
 
 
209
 
static void
210
 
xfce_tray_plugin_lost_selection (XfceTrayManager *manager,
211
 
                                 XfceTrayPlugin  *plugin)
212
 
{
213
 
    GdkScreen *screen;
214
 
 
215
 
    /* get screen */
216
 
    screen = gtk_widget_get_screen (GTK_WIDGET (plugin->panel_plugin));
217
 
 
218
 
    /* TRANSLATORS: Bit of a weird text, but this is shown when for some
219
 
       reason another tray takes the ownership of the tray icons and this
220
 
        tray becomes unusable. */
221
 
    xfce_tray_plugin_message (GTK_MESSAGE_WARNING, screen, _("The tray manager lost selection"));
222
 
}
223
 
 
224
 
 
225
 
 
226
 
static XfceTrayPlugin *
227
 
xfce_tray_plugin_new (XfcePanelPlugin *panel_plugin)
228
 
{
229
 
    XfceTrayPlugin *plugin;
230
 
    gboolean        result;
231
 
    GError         *error = NULL;
232
 
    GdkScreen      *screen;
233
 
 
234
 
    /* create structure */
235
 
    plugin = panel_slice_new0 (XfceTrayPlugin);
236
 
 
237
 
    /* set some data */
238
 
    plugin->panel_plugin = panel_plugin;
239
 
    plugin->manager = NULL;
240
 
    plugin->show_frame = TRUE;
241
 
 
242
 
    /* create the frame */
243
 
    plugin->frame = gtk_frame_new (NULL);
244
 
    gtk_container_add (GTK_CONTAINER (panel_plugin), plugin->frame);
245
 
    gtk_widget_show (plugin->frame);
246
 
 
247
 
    /* create tray widget */
248
 
    plugin->tray = xfce_tray_widget_new ();
249
 
    gtk_container_add (GTK_CONTAINER (plugin->frame), plugin->tray);
250
 
    gtk_widget_show (plugin->tray);
251
 
 
252
 
    /* create a tray manager */
253
 
    plugin->manager = xfce_tray_manager_new ();
254
 
 
255
 
    /* read the plugin settings */
256
 
    xfce_tray_plugin_read (plugin);
257
 
 
258
 
    /* set frame shadow */
259
 
    gtk_frame_set_shadow_type (GTK_FRAME (plugin->frame), plugin->show_frame ? GTK_SHADOW_IN : GTK_SHADOW_NONE);
260
 
 
261
 
    /* get screen */
262
 
    screen = gtk_widget_get_screen (GTK_WIDGET (panel_plugin));
263
 
 
264
 
    /* register the tray */
265
 
    result = xfce_tray_manager_register (plugin->manager, screen, &error);
266
 
 
267
 
    /* check for problems */
268
 
    if (G_LIKELY (result == TRUE))
269
 
    {
270
 
        /* connect signals */
271
 
        g_signal_connect (G_OBJECT (plugin->manager), "tray-icon-added", G_CALLBACK (xfce_tray_plugin_icon_added), plugin);
272
 
        g_signal_connect (G_OBJECT (plugin->manager), "tray-icon-removed", G_CALLBACK (xfce_tray_plugin_icon_removed), plugin);
273
 
        g_signal_connect (G_OBJECT (plugin->manager), "tray-lost-selection", G_CALLBACK (xfce_tray_plugin_lost_selection), plugin);
274
 
 
275
 
        /* update the plugin position */
276
 
        xfce_tray_plugin_update_position (plugin);
277
 
    }
278
 
    else
279
 
    {
280
 
        /* show error */
281
 
        xfce_tray_plugin_message (GTK_MESSAGE_ERROR, screen, error->message);
282
 
 
283
 
        /* free error */
284
 
        g_error_free (error);
285
 
    }
286
 
 
287
 
    return plugin;
288
 
}
289
 
 
290
 
 
291
 
 
292
 
static void
293
 
xfce_tray_plugin_screen_position_changed (XfceTrayPlugin     *plugin,
294
 
                                          XfceScreenPosition  position)
295
 
{
296
 
    /* update the plugin position */
297
 
    xfce_tray_plugin_update_position (plugin);
298
 
}
299
 
 
300
 
 
301
 
 
302
 
static void
303
 
xfce_tray_plugin_orientation_changed (XfceTrayPlugin *plugin,
304
 
                                      GtkOrientation  orientation)
305
 
{
306
 
    /* update the plugin position */
307
 
    xfce_tray_plugin_update_position (plugin);
308
 
}
309
 
 
310
 
 
311
 
 
312
 
static gboolean
313
 
xfce_tray_plugin_size_changed (XfceTrayPlugin *plugin,
314
 
                               guint           size)
315
 
{
316
 
    /* set the border sizes */
317
 
    gtk_container_set_border_width (GTK_CONTAINER (plugin->frame), (size > SMALL_PANEL_SIZE && plugin->show_frame) ? 1 : 0);
318
 
    gtk_container_set_border_width (GTK_CONTAINER (plugin->tray),  plugin->show_frame ? 1 : 0);
319
 
 
320
 
    /* we handled the size of the plugin */
321
 
    return TRUE;
322
 
}
323
 
 
324
 
 
325
 
 
326
 
static void
327
 
xfce_tray_plugin_read (XfceTrayPlugin *plugin)
328
 
{
329
 
    gchar     *file;
330
 
    gchar    **names;
331
 
    gboolean   hidden;
332
 
    XfceRc    *rc;
333
 
    guint      i;
334
 
 
335
 
    /* get rc file name */
336
 
    file = xfce_panel_plugin_lookup_rc_file (plugin->panel_plugin);
337
 
 
338
 
    if (G_LIKELY (file))
339
 
    {
340
 
        /* open the file, readonly */
341
 
        rc = xfce_rc_simple_open (file, TRUE);
342
 
 
343
 
        /* cleanup */
344
 
        g_free (file);
345
 
 
346
 
        if (G_LIKELY (rc))
347
 
        {
348
 
            /* save global plugin settings */
349
 
            xfce_rc_set_group (rc, "Global");
350
 
 
351
 
            /* frame setting */
352
 
            plugin->show_frame = xfce_rc_read_bool_entry (rc, "ShowFrame", TRUE);
353
 
 
354
 
            xfce_tray_widget_set_rows (XFCE_TRAY_WIDGET (plugin->tray), xfce_rc_read_int_entry (rc, "Rows", 1));
355
 
 
356
 
            if (G_LIKELY (plugin->manager))
357
 
            {
358
 
                /* list of known applications */
359
 
                names = xfce_rc_get_entries (rc, "Applications");
360
 
 
361
 
                if (G_LIKELY (names))
362
 
                {
363
 
                    /* set the group */
364
 
                    xfce_rc_set_group (rc, "Applications");
365
 
 
366
 
                    /* read their visibility */
367
 
                    for (i = 0; names[i] != NULL; i++)
368
 
                    {
369
 
                        /* whether the application is hidden */
370
 
                        hidden = xfce_rc_read_bool_entry (rc, names[i], FALSE);
371
 
 
372
 
                        /* add the application name */
373
 
                        xfce_tray_widget_name_add (XFCE_TRAY_WIDGET (plugin->tray), names[i], hidden);
374
 
                    }
375
 
 
376
 
                    /* cleanup */
377
 
                    g_strfreev (names);
378
 
                }
379
 
            }
380
 
 
381
 
            /* close the rc file */
382
 
            xfce_rc_close (rc);
383
 
        }
384
 
    }
385
 
}
386
 
 
387
 
 
388
 
 
389
 
static void
390
 
xfce_tray_plugin_write (XfceTrayPlugin *plugin)
391
 
{
392
 
    gchar       *file;
393
 
    GList       *names, *li;
394
 
    XfceRc      *rc;
395
 
    const gchar *name;
396
 
    gboolean     hidden;
397
 
 
398
 
    /* get rc file name, create it if needed */
399
 
    file = xfce_panel_plugin_save_location (plugin->panel_plugin, TRUE);
400
 
 
401
 
    if (G_LIKELY (file))
402
 
    {
403
 
        /* open the file, writable */
404
 
        rc = xfce_rc_simple_open (file, FALSE);
405
 
 
406
 
        /* cleanup */
407
 
        g_free (file);
408
 
 
409
 
        if (G_LIKELY (rc))
410
 
        {
411
 
            /* save global plugin settings */
412
 
            xfce_rc_set_group (rc, "Global");
413
 
 
414
 
            /* write setting */
415
 
            xfce_rc_write_bool_entry (rc, "ShowFrame", plugin->show_frame);
416
 
            xfce_rc_write_int_entry (rc, "Rows", xfce_tray_widget_get_rows (XFCE_TRAY_WIDGET (plugin->tray)));
417
 
 
418
 
            if (G_LIKELY (plugin->manager))
419
 
            {
420
 
                /* get the list of known applications */
421
 
                names = xfce_tray_widget_name_list (XFCE_TRAY_WIDGET (plugin->tray));
422
 
 
423
 
                if (names == NULL)
424
 
                {
425
 
                    /* delete group */
426
 
                    if (xfce_rc_has_group (rc, "Applications"))
427
 
                        xfce_rc_delete_group (rc, "Applications", FALSE);
428
 
                }
429
 
                else
430
 
                {
431
 
                    /* save the list of known applications and their visibility */
432
 
                    xfce_rc_set_group (rc, "Applications");
433
 
 
434
 
                    /* save their state */
435
 
                    for (li = names; li != NULL; li = li->next)
436
 
                    {
437
 
                        /* get name and status */
438
 
                        name = li->data;
439
 
                        hidden = xfce_tray_widget_name_hidden (XFCE_TRAY_WIDGET (plugin->tray), name);
440
 
 
441
 
                        /* write entry */
442
 
                        xfce_rc_write_bool_entry (rc, name, hidden);
443
 
                    }
444
 
 
445
 
                    /* cleanup */
446
 
                    g_list_free (names);
447
 
                }
448
 
            }
449
 
 
450
 
            /* close the rc file */
451
 
            xfce_rc_close (rc);
452
 
        }
453
 
    }
454
 
}
455
 
 
456
 
 
457
 
 
458
 
static void
459
 
xfce_tray_plugin_free (XfceTrayPlugin *plugin)
460
 
{
461
 
    /* unregister manager */
462
 
    xfce_tray_manager_unregister (plugin->manager);
463
 
 
464
 
    /* release */
465
 
    g_object_unref (G_OBJECT (plugin->manager));
466
 
 
467
 
    /* free slice */
468
 
    panel_slice_free (XfceTrayPlugin, plugin);
469
 
}
470
 
 
471
 
 
472
 
 
473
 
static void
474
 
xfce_tray_plugin_construct (XfcePanelPlugin *panel_plugin)
475
 
{
476
 
    XfceTrayPlugin *plugin;
477
 
 
478
 
    /* create the tray panel plugin */
479
 
    plugin = xfce_tray_plugin_new (panel_plugin);
480
 
 
481
 
    /* set the action widgets and show configure */
482
 
    xfce_panel_plugin_add_action_widget (panel_plugin, plugin->frame);
483
 
    xfce_panel_plugin_add_action_widget (panel_plugin, plugin->tray);
484
 
    xfce_panel_plugin_menu_show_configure (panel_plugin);
485
 
 
486
 
    /* connect signals */
487
 
    g_signal_connect_swapped (G_OBJECT (panel_plugin), "screen-position-changed",
488
 
                              G_CALLBACK (xfce_tray_plugin_screen_position_changed), plugin);
489
 
    g_signal_connect_swapped (G_OBJECT (panel_plugin), "orientation-changed",
490
 
                              G_CALLBACK (xfce_tray_plugin_orientation_changed), plugin);
491
 
    g_signal_connect_swapped (G_OBJECT (panel_plugin), "size-changed",
492
 
                              G_CALLBACK (xfce_tray_plugin_size_changed), plugin);
493
 
    g_signal_connect_swapped (G_OBJECT (panel_plugin), "save",
494
 
                              G_CALLBACK (xfce_tray_plugin_write), plugin);
495
 
    g_signal_connect_swapped (G_OBJECT (panel_plugin), "free-data",
496
 
                              G_CALLBACK (xfce_tray_plugin_free), plugin);
497
 
    g_signal_connect_swapped (G_OBJECT (panel_plugin), "configure-plugin",
498
 
                              G_CALLBACK (xfce_tray_dialogs_configure), plugin);
499
 
}