~ubuntu-branches/ubuntu/maverick/cairo-dock/maverick

« back to all changes in this revision

Viewing changes to src/cairo-dock-container.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthieu Baerts (matttbe)
  • Date: 2010-08-09 23:26:12 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20100809232612-yp4c6ig3jt1bzpdv
Tags: 2.2.0~0beta4-0ubuntu1
* New Upstream Version (LP: #614624)
* Fixed a few bugs on LP:
 - LP: #518453: Dock appears under all windows
                 (Compiz - fullscreen window)
 - LP: #521369: Separator are not removed when closing
                 grouped windows
 - LP: #521762: Some sentences are not correct
 - LP: #526466: Icons of apps with same class shouldn't
                 be stacked by default
 - LP: #535083: Dialogues looks ugly when a lot of them
                 appears at the same time
 - More details on the 'ChangeLog' file
* debian/rules:
 - Autotools has been replaced by CMake
 - Man pages are now included in the source code
* debian/copyright:
 - Updated with the new pathes and new files
* debian/control:
 - Autotools has been replaced by CMake
 - Added libcurl4-gnutls-dev as Build-deps
 - Bump Standard-Version to 3.9.1
* debian/cairo-dock-core.install:
 - Man pages are now included in the source code
 - All sonames are now installed into lib32 or lib64
* debian/cairo-dock-dev.install:
 - pkgconfig is now installed into lib32 or lib64

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
* This file is a part of the Cairo-Dock project
3
 
*
4
 
* Copyright : (C) see the 'copyright' file.
5
 
* E-mail    : see the 'copyright' file.
6
 
*
7
 
* This program is free software; you can redistribute it and/or
8
 
* modify it under the terms of the GNU General Public License
9
 
* as published by the Free Software Foundation; either version 3
10
 
* of the License, or (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 General Public License for more details.
16
 
* You should have received a copy of the GNU General Public License
17
 
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
*/
19
 
 
20
 
#include <stdlib.h>
21
 
 
22
 
#include <gtk/gtk.h>
23
 
#include <gdk/gdkx.h>
24
 
 
25
 
#include <cairo.h>
26
 
 
27
 
#ifdef HAVE_GLITZ
28
 
#include <glitz-glx.h>
29
 
#include <cairo-glitz.h>
30
 
#endif
31
 
 
32
 
#include <gtk/gtkgl.h>
33
 
#include <X11/extensions/Xrender.h>
34
 
#include <X11/extensions/shape.h>
35
 
#include <GL/gl.h> 
36
 
#include <GL/glu.h> 
37
 
#include <GL/glx.h> 
38
 
#include <gdk/x11/gdkglx.h>
39
 
 
40
 
#include "cairo-dock-icons.h"
41
 
#include "cairo-dock-dock-factory.h"
42
 
#include "cairo-dock-dock-facility.h"
43
 
#include "cairo-dock-dock-manager.h"
44
 
#include "cairo-dock-log.h"
45
 
#include "cairo-dock-opengl.h"
46
 
#include "cairo-dock-notifications.h"
47
 
#include "cairo-dock-container.h"
48
 
 
49
 
extern CairoDock *g_pMainDock;
50
 
 
51
 
extern gboolean g_bSticky;
52
 
 
53
 
extern gboolean g_bUseGlitz;
54
 
extern gboolean g_bUseOpenGL;
55
 
 
56
 
 
57
 
static gboolean _cairo_dock_on_delete (GtkWidget *pWidget, GdkEvent *event, gpointer data)
58
 
{
59
 
        g_print ("pas de alt+f4\n");
60
 
        return TRUE;  // on empeche les ALT+F4 malheureux.
61
 
}
62
 
 
63
 
GtkWidget *cairo_dock_create_container_window_full (gboolean bOpenGLWindow)
64
 
{
65
 
        GtkWidget* pWindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
66
 
        
67
 
        if (g_bSticky)
68
 
                gtk_window_stick (GTK_WINDOW (pWindow));
69
 
        gtk_window_set_skip_pager_hint (GTK_WINDOW(pWindow), TRUE);
70
 
        gtk_window_set_skip_taskbar_hint (GTK_WINDOW(pWindow), TRUE);
71
 
        
72
 
        cairo_dock_set_colormap_for_window (pWindow);
73
 
        if (g_bUseOpenGL && bOpenGLWindow)
74
 
        {
75
 
                cairo_dock_set_gl_capabilities (pWindow);
76
 
        }
77
 
        
78
 
        g_signal_connect (G_OBJECT (pWindow),
79
 
                "delete-event",
80
 
                G_CALLBACK (_cairo_dock_on_delete),
81
 
                NULL);
82
 
        
83
 
        gtk_widget_set_app_paintable (pWindow, TRUE);
84
 
        gtk_window_set_decorated (GTK_WINDOW (pWindow), FALSE);
85
 
        gtk_window_set_resizable (GTK_WINDOW (pWindow), TRUE);
86
 
        return pWindow;
87
 
}
88
 
 
89
 
 
90
 
void cairo_dock_set_colormap_for_window (GtkWidget *pWidget)
91
 
{
92
 
        GdkScreen* pScreen = gtk_widget_get_screen (pWidget);
93
 
        GdkColormap* pColormap = gdk_screen_get_rgba_colormap (pScreen);
94
 
        if (!pColormap)
95
 
                pColormap = gdk_screen_get_rgb_colormap (pScreen);
96
 
        
97
 
        /// est-ce que ca vaut le coup de plutot faire ca avec le visual obtenu pour l'openGL ?...
98
 
        //GdkVisual *visual = gdkx_visual_get (pVisInfo->visualid);
99
 
        //pColormap = gdk_colormap_new (visual, TRUE);
100
 
 
101
 
        gtk_widget_set_colormap (pWidget, pColormap);
102
 
}
103
 
 
104
 
void cairo_dock_set_colormap (CairoContainer *pContainer)
105
 
{
106
 
        GdkColormap* pColormap;
107
 
#ifdef HAVE_GLITZ
108
 
        if (g_bUseGlitz)
109
 
        {
110
 
                glitz_drawable_format_t templ, *format;
111
 
                unsigned long       mask = GLITZ_FORMAT_DOUBLEBUFFER_MASK;
112
 
                XVisualInfo                 *vinfo = NULL;
113
 
                int                         screen = 0;
114
 
                GdkVisual                   *visual;
115
 
                GdkDisplay                  *gdkdisplay;
116
 
                Display             *xdisplay;
117
 
 
118
 
                templ.doublebuffer = 1;
119
 
                gdkdisplay = gtk_widget_get_display (pContainer->pWidget);
120
 
                xdisplay   = gdk_x11_display_get_xdisplay (gdkdisplay);
121
 
 
122
 
                int i = 0;
123
 
                do
124
 
                {
125
 
                        format = glitz_glx_find_window_format (xdisplay,
126
 
                                screen,
127
 
                                mask,
128
 
                                &templ,
129
 
                                i++);
130
 
                        if (format)
131
 
                        {
132
 
                                vinfo = glitz_glx_get_visual_info_from_format (xdisplay,
133
 
                                        screen,
134
 
                                        format);
135
 
                                if (vinfo->depth == 32)
136
 
                                {
137
 
                                        pContainer->pDrawFormat = format;
138
 
                                        break;
139
 
                                }
140
 
                                else if (!pContainer->pDrawFormat)
141
 
                                {
142
 
                                        pContainer->pDrawFormat = format;
143
 
                                }
144
 
                        }
145
 
                } while (format);
146
 
 
147
 
                if (! pContainer->pDrawFormat)
148
 
                {
149
 
                        cd_warning ("no double buffered GLX visual");
150
 
                }
151
 
                else
152
 
                {
153
 
                        vinfo = glitz_glx_get_visual_info_from_format (xdisplay,
154
 
                                screen,
155
 
                                pContainer->pDrawFormat);
156
 
 
157
 
                        visual = gdkx_visual_get (vinfo->visualid);
158
 
                        pColormap = gdk_colormap_new (visual, TRUE);
159
 
 
160
 
                        gtk_widget_set_colormap (pContainer->pWidget, pColormap);
161
 
                        gtk_widget_set_double_buffered (pContainer->pWidget, FALSE);
162
 
                        return ;
163
 
                }
164
 
        }
165
 
#endif
166
 
        
167
 
        cairo_dock_set_colormap_for_window (pContainer->pWidget);
168
 
}
169
 
 
170
 
 
171
 
 
172
 
void cairo_dock_redraw_container (CairoContainer *pContainer)
173
 
{
174
 
        g_return_if_fail (pContainer != NULL);
175
 
        GdkRectangle rect = {0, 0, pContainer->iWidth, pContainer->iHeight};
176
 
        if (! pContainer->bIsHorizontal)
177
 
        {
178
 
                rect.width = pContainer->iHeight;
179
 
                rect.height = pContainer->iWidth;
180
 
        }
181
 
        cairo_dock_redraw_container_area (pContainer, &rect);
182
 
}
183
 
 
184
 
void cairo_dock_redraw_container_area (CairoContainer *pContainer, GdkRectangle *pArea)
185
 
{
186
 
        g_return_if_fail (pContainer != NULL);
187
 
        if (! GTK_WIDGET_VISIBLE (pContainer->pWidget))
188
 
                return ;
189
 
        if (CAIRO_DOCK_IS_DOCK (pContainer) && cairo_dock_is_hidden (CAIRO_DOCK (pContainer)))  // inutile de redessiner.
190
 
                return ;
191
 
        if (pArea->y < 0)
192
 
                pArea->y = 0;
193
 
        if (pContainer->bIsHorizontal && pArea->y + pArea->height > pContainer->iHeight)
194
 
                pArea->height = pContainer->iHeight - pArea->y;
195
 
        else if (! pContainer->bIsHorizontal && pArea->x + pArea->width > pContainer->iHeight)
196
 
                pArea->width = pContainer->iHeight - pArea->x;
197
 
        //g_print ("rect (%d;%d) (%dx%d)\n", pArea->x, pArea->y, pArea->width, pArea->height);
198
 
        if (pArea->width > 0 && pArea->height > 0)
199
 
                gdk_window_invalidate_rect (pContainer->pWidget->window, pArea, FALSE);
200
 
}
201
 
 
202
 
void cairo_dock_redraw_icon (Icon *icon, CairoContainer *pContainer)
203
 
{
204
 
        g_return_if_fail (icon != NULL && pContainer != NULL);
205
 
        GdkRectangle rect;
206
 
        cairo_dock_compute_icon_area (icon, pContainer, &rect);
207
 
        cairo_dock_redraw_container_area (pContainer, &rect);
208
 
}
209
 
 
210
 
 
211
 
 
212
 
static gboolean _cairo_dock_search_icon_in_desklet (CairoDesklet *pDesklet, CairoDockModuleInstance *pInstance, Icon *icon)
213
 
{
214
 
        if (pDesklet->icons != NULL)
215
 
        {
216
 
                Icon *pIcon;
217
 
                GList *ic;
218
 
                for (ic = pDesklet->icons; ic != NULL; ic = ic->next)
219
 
                {
220
 
                        pIcon = ic->data;
221
 
                        if (pIcon == icon)
222
 
                                return TRUE;
223
 
                }
224
 
        }
225
 
        return FALSE;
226
 
}
227
 
CairoContainer *cairo_dock_search_container_from_icon (Icon *icon)
228
 
{
229
 
        g_return_val_if_fail (icon != NULL, NULL);
230
 
        if (CAIRO_DOCK_IS_APPLET (icon))
231
 
        {
232
 
                return icon->pModuleInstance->pContainer;
233
 
        }
234
 
        else if (icon->cParentDockName != NULL)
235
 
        {
236
 
                return CAIRO_CONTAINER (cairo_dock_search_dock_from_name (icon->cParentDockName));
237
 
        }
238
 
        else
239
 
        {
240
 
                CairoDockModuleInstance *pApplet = cairo_dock_foreach_desklet ((CairoDockForeachDeskletFunc)_cairo_dock_search_icon_in_desklet, icon);
241
 
                if (pApplet != NULL)
242
 
                        return pApplet->pContainer;
243
 
        }
244
 
}
245
 
 
246
 
 
247
 
void cairo_dock_show_hide_container (CairoContainer *pContainer)
248
 
{
249
 
        if (pContainer == NULL)
250
 
                return;
251
 
        if (! GTK_WIDGET_VISIBLE (pContainer->pWidget))
252
 
                gtk_window_present (GTK_WINDOW (pContainer->pWidget));
253
 
        else
254
 
                gtk_widget_hide (pContainer->pWidget);
255
 
}
256
 
 
257
 
 
258
 
void cairo_dock_allow_widget_to_receive_data (GtkWidget *pWidget, GCallback pCallBack, gpointer data)
259
 
{
260
 
        /*GtkTargetEntry pTargetEntry[6] = {0};
261
 
        pTargetEntry[0].target = (gchar*)"text/*";
262
 
        pTargetEntry[0].flags = (GtkTargetFlags) 0;
263
 
        pTargetEntry[0].info = 0;
264
 
        pTargetEntry[1].target = (gchar*)"text/uri-list";
265
 
        pTargetEntry[2].target = (gchar*)"text/plain";
266
 
        pTargetEntry[3].target = (gchar*)"text/plain;charset=UTF-8";
267
 
        pTargetEntry[4].target = (gchar*)"text/directory";
268
 
        pTargetEntry[5].target = (gchar*)"text/html";
269
 
        gtk_drag_dest_set (pWidget,
270
 
                GTK_DEST_DEFAULT_DROP | GTK_DEST_DEFAULT_MOTION,  // GTK_DEST_DEFAULT_HIGHLIGHT ne rend pas joli je trouve.
271
 
                pTargetEntry,
272
 
                6,
273
 
                GDK_ACTION_COPY | GDK_ACTION_MOVE);  // le 'GDK_ACTION_MOVE' c'est pour KDE.*/
274
 
        gtk_drag_dest_set (pWidget,
275
 
                GTK_DEST_DEFAULT_DROP | GTK_DEST_DEFAULT_MOTION,  // GTK_DEST_DEFAULT_HIGHLIGHT ne rend pas joli je trouve.
276
 
                NULL,
277
 
                0,
278
 
                GDK_ACTION_COPY | GDK_ACTION_MOVE);  // le 'GDK_ACTION_MOVE' c'est pour KDE.
279
 
        gtk_drag_dest_add_text_targets (pWidget);
280
 
        gtk_drag_dest_add_uri_targets (pWidget);
281
 
        
282
 
        g_signal_connect (G_OBJECT (pWidget),
283
 
                "drag_data_received",
284
 
                pCallBack,
285
 
                data);
286
 
}
287
 
 
288
 
gboolean cairo_dock_string_is_adress (const gchar *cString)
289
 
{
290
 
        gchar *protocole = g_strstr_len (cString, -1, "://");
291
 
        if (protocole == NULL || protocole == cString)
292
 
        {
293
 
                if (strncmp (cString, "www", 3) == 0)
294
 
                        return TRUE;
295
 
                return FALSE;
296
 
        }
297
 
        const gchar *str = cString;
298
 
        while (*str == ' ')
299
 
                str ++;
300
 
        while (str < protocole)
301
 
        {
302
 
                if (! g_ascii_isalnum (*str) && *str != '-')  // x-nautilus-desktop://
303
 
                        return FALSE;
304
 
                str ++;
305
 
        }
306
 
        
307
 
        return TRUE;
308
 
}
309
 
 
310
 
void cairo_dock_notify_drop_data (gchar *cReceivedData, Icon *pPointedIcon, double fOrder, CairoContainer *pContainer)
311
 
{
312
 
        g_return_if_fail (cReceivedData != NULL);
313
 
        gchar *cData = NULL;
314
 
        
315
 
        gchar **cStringList = g_strsplit (cReceivedData, "\n", -1);
316
 
        GString *sArg = g_string_new ("");
317
 
        int i=0, j;
318
 
        while (cStringList[i] != NULL)
319
 
        {
320
 
                g_string_assign (sArg, cStringList[i]);
321
 
                
322
 
                if (! cairo_dock_string_is_adress (cStringList[i]))
323
 
                {
324
 
                        j = i + 1;
325
 
                        while (cStringList[j] != NULL)
326
 
                        {
327
 
                                if (cairo_dock_string_is_adress (cStringList[j]))
328
 
                                        break ;
329
 
                                g_string_append_printf (sArg, "\n%s", cStringList[j]);
330
 
                                j ++;
331
 
                        }
332
 
                        i = j;
333
 
                }
334
 
                else
335
 
                {
336
 
                        cd_debug (" + adresse");
337
 
                        if (sArg->str[sArg->len-1] == '\r')
338
 
                        {
339
 
                                cd_debug ("retour charriot");
340
 
                                sArg->str[sArg->len-1] = '\0';
341
 
                        }
342
 
                        i ++;
343
 
                }
344
 
                
345
 
                cData = sArg->str;
346
 
                cd_debug (" notification de drop '%s'", cData);
347
 
                cairo_dock_notify (CAIRO_DOCK_DROP_DATA, cData, pPointedIcon, fOrder, pContainer);
348
 
        }
349
 
        
350
 
        g_strfreev (cStringList);
351
 
        g_string_free (sArg, TRUE);
352
 
}