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

« back to all changes in this revision

Viewing changes to plugins/showdesktop/showdesktop.c

  • Committer: Bazaar Package Importer
  • Author(s): Yves-Alexis Perez
  • Date: 2008-05-19 08:08:22 UTC
  • mfrom: (1.1.16 upstream)
  • Revision ID: james.westby@ubuntu.com-20080519080822-c8ptdv1s8o9r4ou0
Tags: 4.4.2-6
* switch to triggers:
  - debian/postinst: remove xfce-mcs-manager refresh.
  - debian/prerm dropped.
  - debian/control: conflicts against non-triggers-enable xfce4-mcs-manager.
* debian/control: remove useless Conflicts/Replaces against Sarge stuff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* vim: set expandtab ts=8 sw=4: */
 
2
/*  $Id: showdesktop.c 24221 2006-12-30 14:08:01Z jasper $
 
3
 *
 
4
 *  Copyright © 2005 Jasper Huijsmans <jasper@xfce.org>
 
5
 *  Copyright © 2006 Jani Monoses <jani@ubuntu.com> 
 
6
 *
 
7
 *  This program is free software; you can redistribute it and/or modify
 
8
 *  it under the terms of the GNU General Public License as published by
 
9
 *  the Free Software Foundation; either version 2 of the License, or
 
10
 *  (at your option) any later version.
 
11
 *
 
12
 *  This program is distributed in the hope that it will be useful,
 
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 *  GNU Library General Public License for more details.
 
16
 *
 
17
 *  You should have received a copy of the GNU General Public License
 
18
 *  along with this program; if not, write to the Free Software
 
19
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
20
 */
 
21
 
 
22
#ifdef HAVE_CONFIG_H
 
23
#include <config.h>
 
24
#endif
 
25
 
 
26
#include <gtk/gtk.h>
 
27
#include <libxfcegui4/libxfcegui4.h>
 
28
#include <libxfce4panel/xfce-panel-plugin.h>
 
29
#include <libxfce4panel/xfce-panel-convenience.h>
 
30
 
 
31
#define SHOW_DESKTOP_ICON_NAME  "gnome-fs-desktop"
 
32
#define TIP_ACTIVE              _("Restore hidden windows")
 
33
#define TIP_INACTIVE            _("Hide windows and show desktop")
 
34
 
 
35
typedef struct
 
36
{
 
37
    XfcePanelPlugin *plugin;
 
38
 
 
39
    GtkWidget *button;
 
40
    GtkWidget *image;
 
41
 
 
42
    GtkTooltips *tooltips;
 
43
    NetkScreen *screen;
 
44
    int netk_id;
 
45
    int screen_id;
 
46
    int style_id;
 
47
 
 
48
    guint showing:1;
 
49
    guint updating:1;
 
50
}
 
51
ShowDesktopData;
 
52
 
 
53
/* Panel Plugin Interface */
 
54
 
 
55
static void showdesktop_construct (XfcePanelPlugin * plugin);
 
56
 
 
57
XFCE_PANEL_PLUGIN_REGISTER_INTERNAL (showdesktop_construct);
 
58
 
 
59
 
 
60
/* internal functions */
 
61
 
 
62
static gboolean
 
63
showdesktop_set_size (XfcePanelPlugin *plugin, int size, ShowDesktopData *sdd)
 
64
{
 
65
    GdkPixbuf *pb;
 
66
    int width = size - 2 - 2 * MAX (sdd->button->style->xthickness,
 
67
                                    sdd->button->style->ythickness);
 
68
    
 
69
    pb = xfce_themed_icon_load (SHOW_DESKTOP_ICON_NAME, width);
 
70
    if (pb) 
 
71
    {
 
72
        gtk_image_set_from_pixbuf (GTK_IMAGE (sdd->image), pb);
 
73
        g_object_unref (pb);
 
74
    }
 
75
    gtk_widget_set_size_request (GTK_WIDGET (plugin), size, size);
 
76
 
 
77
    return TRUE;
 
78
}
 
79
 
 
80
static void
 
81
showdesktop_free_data (XfcePanelPlugin * plugin, ShowDesktopData * sdd)
 
82
{
 
83
    if (sdd->netk_id)
 
84
        g_signal_handler_disconnect (sdd->screen, sdd->netk_id);
 
85
    
 
86
    if (sdd->screen_id)
 
87
        g_signal_handler_disconnect (plugin, sdd->screen_id);
 
88
    
 
89
    if (sdd->style_id)
 
90
        g_signal_handler_disconnect (plugin, sdd->style_id);
 
91
    
 
92
    sdd->netk_id = sdd->screen_id = sdd->style_id = 0;
 
93
    gtk_object_sink (GTK_OBJECT (sdd->tooltips));
 
94
    panel_slice_free (ShowDesktopData, sdd);
 
95
}
 
96
 
 
97
static void
 
98
update_button_display (ShowDesktopData * sdd)
 
99
{
 
100
    gtk_tooltips_set_tip (sdd->tooltips, sdd->button,
 
101
                          sdd->showing ? TIP_ACTIVE : TIP_INACTIVE, NULL);
 
102
}
 
103
 
 
104
static void
 
105
update_button (ShowDesktopData * sdd)
 
106
{
 
107
    if (sdd->updating)
 
108
        return;
 
109
 
 
110
    sdd->updating = TRUE;
 
111
    
 
112
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sdd->button),
 
113
                                  sdd->showing);
 
114
    update_button_display (sdd);
 
115
    
 
116
    sdd->updating = FALSE;
 
117
}
 
118
 
 
119
/* create widgets and connect to signals */
 
120
static void
 
121
button_toggled (GtkWidget * button, ShowDesktopData * sdd)
 
122
{
 
123
    gboolean active;
 
124
 
 
125
    if (sdd->updating)
 
126
        return;
 
127
 
 
128
    active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
 
129
 
 
130
    netk_screen_toggle_showing_desktop (sdd->screen, active);
 
131
 
 
132
    sdd->showing = active;
 
133
    update_button_display (sdd);
 
134
}
 
135
 
 
136
static void
 
137
showing_desktop_changed (NetkScreen * screen, ShowDesktopData * sdd)
 
138
{
 
139
    sdd->showing = netk_screen_get_showing_desktop (screen);
 
140
    update_button (sdd);
 
141
}
 
142
 
 
143
static void
 
144
showdesktop_screen_changed (XfcePanelPlugin *plugin, GdkScreen *screen,
 
145
                            ShowDesktopData *sdd)
 
146
{
 
147
    if (sdd->netk_id)
 
148
    {
 
149
        g_signal_handler_disconnect (sdd->screen, sdd->netk_id);
 
150
        sdd->netk_id = 0;
 
151
    }
 
152
 
 
153
    screen = gtk_widget_get_screen (GTK_WIDGET (plugin));
 
154
    if (screen)
 
155
    {
 
156
        sdd->screen = netk_screen_get (gdk_screen_get_number (screen));
 
157
        
 
158
        sdd->netk_id = 
 
159
                g_signal_connect (sdd->screen, "showing_desktop_changed",
 
160
                                  G_CALLBACK (showing_desktop_changed), sdd);
 
161
 
 
162
        sdd->showing = netk_screen_get_showing_desktop (sdd->screen);
 
163
        update_button (sdd);
 
164
        showdesktop_set_size (plugin, xfce_panel_plugin_get_size (plugin), sdd);
 
165
    }
 
166
}
 
167
 
 
168
static void
 
169
showdesktop_style_set (XfcePanelPlugin *plugin, gpointer ignored,
 
170
                       ShowDesktopData *sdd)
 
171
{
 
172
    showdesktop_set_size (plugin, xfce_panel_plugin_get_size (plugin), sdd);
 
173
}
 
174
 
 
175
static void
 
176
showdesktop_construct (XfcePanelPlugin * plugin)
 
177
{
 
178
    ShowDesktopData *sdd = panel_slice_new0 (ShowDesktopData);
 
179
 
 
180
    sdd->plugin = plugin;
 
181
 
 
182
    sdd->tooltips = gtk_tooltips_new ();
 
183
 
 
184
    sdd->image = gtk_image_new ();
 
185
 
 
186
    sdd->button = xfce_create_panel_toggle_button ();
 
187
    gtk_container_add (GTK_CONTAINER (sdd->button), GTK_WIDGET (sdd->image));
 
188
 
 
189
    gtk_button_set_relief (GTK_BUTTON (sdd->button), GTK_RELIEF_NONE);
 
190
    gtk_widget_show_all (sdd->button);
 
191
 
 
192
    gtk_container_add (GTK_CONTAINER (plugin), sdd->button);
 
193
    xfce_panel_plugin_add_action_widget (plugin, sdd->button);
 
194
    
 
195
    g_signal_connect (sdd->button, "toggled", 
 
196
                      G_CALLBACK (button_toggled), sdd);
 
197
 
 
198
    g_signal_connect (plugin, "free-data",
 
199
                      G_CALLBACK (showdesktop_free_data), sdd);
 
200
 
 
201
    g_signal_connect (plugin, "size-changed",
 
202
                      G_CALLBACK (showdesktop_set_size), sdd);
 
203
 
 
204
    update_button (sdd);
 
205
 
 
206
    showdesktop_screen_changed (plugin, gtk_widget_get_screen (sdd->button),
 
207
                                sdd);
 
208
 
 
209
    sdd->screen_id = 
 
210
        g_signal_connect (plugin, "screen-changed", 
 
211
                          G_CALLBACK (showdesktop_screen_changed), sdd);
 
212
 
 
213
    sdd->style_id = 
 
214
        g_signal_connect (plugin, "style-set",
 
215
                          G_CALLBACK (showdesktop_style_set), sdd);
 
216
}