2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
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.
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/>.
28
#include <glitz-glx.h>
29
#include <cairo-glitz.h>
32
#include <gtk/gtkgl.h>
33
#include <X11/extensions/Xrender.h>
34
#include <X11/extensions/shape.h>
38
#include <gdk/x11/gdkglx.h>
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"
49
extern CairoDock *g_pMainDock;
51
extern gboolean g_bSticky;
53
extern gboolean g_bUseGlitz;
54
extern gboolean g_bUseOpenGL;
57
static gboolean _cairo_dock_on_delete (GtkWidget *pWidget, GdkEvent *event, gpointer data)
59
g_print ("pas de alt+f4\n");
60
return TRUE; // on empeche les ALT+F4 malheureux.
63
GtkWidget *cairo_dock_create_container_window_full (gboolean bOpenGLWindow)
65
GtkWidget* pWindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
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);
72
cairo_dock_set_colormap_for_window (pWindow);
73
if (g_bUseOpenGL && bOpenGLWindow)
75
cairo_dock_set_gl_capabilities (pWindow);
78
g_signal_connect (G_OBJECT (pWindow),
80
G_CALLBACK (_cairo_dock_on_delete),
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);
90
void cairo_dock_set_colormap_for_window (GtkWidget *pWidget)
92
GdkScreen* pScreen = gtk_widget_get_screen (pWidget);
93
GdkColormap* pColormap = gdk_screen_get_rgba_colormap (pScreen);
95
pColormap = gdk_screen_get_rgb_colormap (pScreen);
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);
101
gtk_widget_set_colormap (pWidget, pColormap);
104
void cairo_dock_set_colormap (CairoContainer *pContainer)
106
GdkColormap* pColormap;
110
glitz_drawable_format_t templ, *format;
111
unsigned long mask = GLITZ_FORMAT_DOUBLEBUFFER_MASK;
112
XVisualInfo *vinfo = NULL;
115
GdkDisplay *gdkdisplay;
118
templ.doublebuffer = 1;
119
gdkdisplay = gtk_widget_get_display (pContainer->pWidget);
120
xdisplay = gdk_x11_display_get_xdisplay (gdkdisplay);
125
format = glitz_glx_find_window_format (xdisplay,
132
vinfo = glitz_glx_get_visual_info_from_format (xdisplay,
135
if (vinfo->depth == 32)
137
pContainer->pDrawFormat = format;
140
else if (!pContainer->pDrawFormat)
142
pContainer->pDrawFormat = format;
147
if (! pContainer->pDrawFormat)
149
cd_warning ("no double buffered GLX visual");
153
vinfo = glitz_glx_get_visual_info_from_format (xdisplay,
155
pContainer->pDrawFormat);
157
visual = gdkx_visual_get (vinfo->visualid);
158
pColormap = gdk_colormap_new (visual, TRUE);
160
gtk_widget_set_colormap (pContainer->pWidget, pColormap);
161
gtk_widget_set_double_buffered (pContainer->pWidget, FALSE);
167
cairo_dock_set_colormap_for_window (pContainer->pWidget);
172
void cairo_dock_redraw_container (CairoContainer *pContainer)
174
g_return_if_fail (pContainer != NULL);
175
GdkRectangle rect = {0, 0, pContainer->iWidth, pContainer->iHeight};
176
if (! pContainer->bIsHorizontal)
178
rect.width = pContainer->iHeight;
179
rect.height = pContainer->iWidth;
181
cairo_dock_redraw_container_area (pContainer, &rect);
184
void cairo_dock_redraw_container_area (CairoContainer *pContainer, GdkRectangle *pArea)
186
g_return_if_fail (pContainer != NULL);
187
if (! GTK_WIDGET_VISIBLE (pContainer->pWidget))
189
if (CAIRO_DOCK_IS_DOCK (pContainer) && cairo_dock_is_hidden (CAIRO_DOCK (pContainer))) // inutile de redessiner.
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);
202
void cairo_dock_redraw_icon (Icon *icon, CairoContainer *pContainer)
204
g_return_if_fail (icon != NULL && pContainer != NULL);
206
cairo_dock_compute_icon_area (icon, pContainer, &rect);
207
cairo_dock_redraw_container_area (pContainer, &rect);
212
static gboolean _cairo_dock_search_icon_in_desklet (CairoDesklet *pDesklet, CairoDockModuleInstance *pInstance, Icon *icon)
214
if (pDesklet->icons != NULL)
218
for (ic = pDesklet->icons; ic != NULL; ic = ic->next)
227
CairoContainer *cairo_dock_search_container_from_icon (Icon *icon)
229
g_return_val_if_fail (icon != NULL, NULL);
230
if (CAIRO_DOCK_IS_APPLET (icon))
232
return icon->pModuleInstance->pContainer;
234
else if (icon->cParentDockName != NULL)
236
return CAIRO_CONTAINER (cairo_dock_search_dock_from_name (icon->cParentDockName));
240
CairoDockModuleInstance *pApplet = cairo_dock_foreach_desklet ((CairoDockForeachDeskletFunc)_cairo_dock_search_icon_in_desklet, icon);
242
return pApplet->pContainer;
247
void cairo_dock_show_hide_container (CairoContainer *pContainer)
249
if (pContainer == NULL)
251
if (! GTK_WIDGET_VISIBLE (pContainer->pWidget))
252
gtk_window_present (GTK_WINDOW (pContainer->pWidget));
254
gtk_widget_hide (pContainer->pWidget);
258
void cairo_dock_allow_widget_to_receive_data (GtkWidget *pWidget, GCallback pCallBack, gpointer data)
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.
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.
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);
282
g_signal_connect (G_OBJECT (pWidget),
283
"drag_data_received",
288
gboolean cairo_dock_string_is_adress (const gchar *cString)
290
gchar *protocole = g_strstr_len (cString, -1, "://");
291
if (protocole == NULL || protocole == cString)
293
if (strncmp (cString, "www", 3) == 0)
297
const gchar *str = cString;
300
while (str < protocole)
302
if (! g_ascii_isalnum (*str) && *str != '-') // x-nautilus-desktop://
310
void cairo_dock_notify_drop_data (gchar *cReceivedData, Icon *pPointedIcon, double fOrder, CairoContainer *pContainer)
312
g_return_if_fail (cReceivedData != NULL);
315
gchar **cStringList = g_strsplit (cReceivedData, "\n", -1);
316
GString *sArg = g_string_new ("");
318
while (cStringList[i] != NULL)
320
g_string_assign (sArg, cStringList[i]);
322
if (! cairo_dock_string_is_adress (cStringList[i]))
325
while (cStringList[j] != NULL)
327
if (cairo_dock_string_is_adress (cStringList[j]))
329
g_string_append_printf (sArg, "\n%s", cStringList[j]);
336
cd_debug (" + adresse");
337
if (sArg->str[sArg->len-1] == '\r')
339
cd_debug ("retour charriot");
340
sArg->str[sArg->len-1] = '\0';
346
cd_debug (" notification de drop '%s'", cData);
347
cairo_dock_notify (CAIRO_DOCK_DROP_DATA, cData, pPointedIcon, fOrder, pContainer);
350
g_strfreev (cStringList);
351
g_string_free (sArg, TRUE);