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/>.
20
/************************************************************************************
22
This file is a part of the cairo-dock program,
23
released under the terms of the GNU General Public License.
25
Written by Cchumi & Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
27
************************************************************************************/
29
#include <glib/gstdio.h>
32
#include "applet-struct.h"
33
#include "applet-load-icons.h"
34
#include "applet-draw.h"
36
gboolean my_bRotateIconsOnEllipse = TRUE;
39
static void _cd_switcher_draw_windows_on_viewport (Icon *pIcon, gint *data)
41
if (pIcon == NULL || pIcon->fPersonnalScale > 0)
43
if (pIcon->bIsHidden && ! myConfig.bDisplayHiddenWindows)
45
int iNumDesktop = data[0];
46
int iNumViewportX = data[1];
47
int iNumViewportY = data[2];
48
int iOneViewportWidth = data[3];
49
int iOneViewportHeight = data[4];
50
cairo_t *pCairoContext = GINT_TO_POINTER (data[5]);
52
// On calcule les coordonnees en repere absolu.
53
int x = pIcon->windowGeometry.x; // par rapport au viewport courant.
54
x += myData.switcher.iCurrentViewportX * g_iXScreenWidth[CAIRO_DOCK_HORIZONTAL]; // repere absolu
56
x += g_iNbViewportX * g_iXScreenWidth[CAIRO_DOCK_HORIZONTAL];
57
int y = pIcon->windowGeometry.y;
58
y += myData.switcher.iCurrentViewportY * g_iXScreenHeight[CAIRO_DOCK_HORIZONTAL];
60
y += g_iNbViewportY * g_iXScreenHeight[CAIRO_DOCK_HORIZONTAL];
61
int w = pIcon->windowGeometry.width, h = pIcon->windowGeometry.height;
63
// test d'intersection avec le viewport donne.
64
//g_print (" %s : (%d;%d) %dx%d\n", pIcon->acName, x, y, w, h);
65
if ((pIcon->iNumDesktop != -1 && pIcon->iNumDesktop != iNumDesktop) ||
66
x + w <= iNumViewportX * g_iXScreenWidth[CAIRO_DOCK_HORIZONTAL] ||
67
x >= (iNumViewportX + 1) * g_iXScreenWidth[CAIRO_DOCK_HORIZONTAL] ||
68
y + h <= iNumViewportY * g_iXScreenHeight[CAIRO_DOCK_HORIZONTAL] ||
69
y >= (iNumViewportY + 1) * g_iXScreenHeight[CAIRO_DOCK_HORIZONTAL])
71
//g_print (" > on la dessine (%x)\n", pIcon->pIconBuffer);
73
// on dessine ses traits.
74
cairo_save (pCairoContext);
76
cairo_set_source_rgba (pCairoContext, myConfig.RGBWLineColors[0], myConfig.RGBWLineColors[1], myConfig.RGBWLineColors[2], myConfig.RGBWLineColors[3]);
77
cairo_rectangle (pCairoContext,
78
(1.*x/g_iXScreenWidth[CAIRO_DOCK_HORIZONTAL] - iNumViewportX)*iOneViewportWidth,
79
(1.*y/g_iXScreenHeight[CAIRO_DOCK_HORIZONTAL] - iNumViewportY)*iOneViewportHeight,
80
1.*w/g_iXScreenWidth[CAIRO_DOCK_HORIZONTAL]*iOneViewportWidth,
81
1.*h/g_iXScreenHeight[CAIRO_DOCK_HORIZONTAL]*iOneViewportHeight);
82
if (pIcon->Xid == cairo_dock_get_current_active_window ())
84
//g_print (" %s est la fenetre active\n", pIcon->acName);
85
cairo_fill (pCairoContext);
89
cairo_stroke (pCairoContext);
92
if (pIcon->pIconBuffer != NULL)
94
CairoDock *pParentDock = NULL;
95
pParentDock = cairo_dock_search_dock_from_name (pIcon->cParentDockName);
96
if (pParentDock == NULL)
97
pParentDock = g_pMainDock;
99
cairo_dock_get_icon_extent (pIcon, pParentDock, &iWidth, &iHeight);
100
double fZoomX = (double) w/g_iXScreenWidth[CAIRO_DOCK_HORIZONTAL]*iOneViewportWidth / iWidth;
101
double fZoomY = (double) h/g_iXScreenHeight[CAIRO_DOCK_HORIZONTAL]*iOneViewportHeight / iHeight;
102
double fZoom = MIN (fZoomX, fZoomY); // on garde le ratio.
104
cairo_translate (pCairoContext,
105
(1.*x/g_iXScreenWidth[CAIRO_DOCK_HORIZONTAL] - iNumViewportX)*iOneViewportWidth + (fZoomX - fZoom) * iWidth/2,
106
(1.*y/g_iXScreenHeight[CAIRO_DOCK_HORIZONTAL] - iNumViewportY)*iOneViewportHeight + (fZoomY - fZoom) * iHeight/2);
107
cairo_scale (pCairoContext,
110
cairo_set_source_surface (pCairoContext,
114
cairo_paint (pCairoContext);
117
cairo_restore (pCairoContext);
121
static int _compare_icons_stack_order (Icon *icon1, Icon *icon2)
123
if (icon1 == NULL) // les icones nulles vont a la fin.
127
if (icon1->iStackOrder < icon2->iStackOrder) // ordre petit => dessus => dessinee en dernier.
132
void cd_switcher_draw_main_icon_compact_mode (void)
134
//cd_debug ("%s (%d;%d)", __func__, myData.switcher.iCurrentLine, myData.switcher.iCurrentColumn);
135
// On efface l'icone.
136
cairo_dock_erase_cairo_context (myDrawContext);
138
// definition des parametres de dessin.
139
//double fRatio = (myDock ? myDock->fRatio : 1.);
140
//double fMaxScale = cairo_dock_get_max_scale (myContainer); //coefficient Max icone Width
142
CD_APPLET_GET_MY_ICON_EXTENT (&iWidth, &iHeight);
143
myData.switcher.fOneViewportHeight = (iHeight - 2 * myConfig.iLineSize - (myData.switcher.iNbLines - 1) * myConfig.iInLineSize) / myData.switcher.iNbLines; //hauteur d'un bureau/viewport sans compter les lignes exterieures et interieures.
144
myData.switcher.fOneViewportWidth = (iWidth - 2 * myConfig.iLineSize - (myData.switcher.iNbColumns - 1) * myConfig.iInLineSize) / myData.switcher.iNbColumns; //largeur d'un bureau/viewport sans compter les lignes exterieures et interieures.
146
cairo_surface_t *pSurface = NULL;
147
double fZoomX, fZoomY;
148
if (myConfig.bMapWallpaper)
150
pSurface = cairo_dock_get_desktop_bg_surface ();
151
fZoomX = (double) myData.switcher.fOneViewportWidth / g_iXScreenWidth[CAIRO_DOCK_HORIZONTAL];
152
fZoomY= (double) myData.switcher.fOneViewportHeight / g_iXScreenHeight[CAIRO_DOCK_HORIZONTAL];
154
if (pSurface == NULL)
156
pSurface = myData.pDefaultMapSurface;
157
fZoomX = (double) myData.switcher.fOneViewportWidth / iWidth;
158
fZoomY = (double) myData.switcher.fOneViewportHeight / iHeight;
162
cairo_set_line_width (myDrawContext,myConfig.iLineSize);
163
cairo_set_source_rgba(myDrawContext,myConfig.RGBLineColors[0],myConfig.RGBLineColors[1],myConfig.RGBLineColors[2],myConfig.RGBLineColors[3]);
164
cairo_rectangle(myDrawContext,
165
.5*myConfig.iLineSize,
166
.5*myConfig.iLineSize,
167
iWidth - myConfig.iLineSize,
168
iHeight - myConfig.iLineSize);
170
cairo_stroke (myDrawContext);
172
// lignes interieures.
173
cairo_set_line_width (myDrawContext,myConfig.iInLineSize);
174
cairo_set_source_rgba(myDrawContext,myConfig.RGBInLineColors[0],myConfig.RGBInLineColors[1],myConfig.RGBInLineColors[2],myConfig.RGBInLineColors[3]);
177
for (i = 1; i <myData.switcher.iNbColumns; i ++) // lignes verticales.
179
xi = myConfig.iLineSize + i * (myData.switcher.fOneViewportWidth + myConfig.iInLineSize) - .5*myConfig.iInLineSize;
180
cairo_move_to (myDrawContext, xi, myConfig.iLineSize);
181
cairo_rel_line_to (myDrawContext, 0, iHeight - 2*myConfig.iLineSize);
182
cairo_stroke (myDrawContext);
184
for (j = 1; j < myData.switcher.iNbLines; j ++) // lignes horizontales.
186
yj = myConfig.iLineSize + j * (myData.switcher.fOneViewportHeight + myConfig.iInLineSize) - .5*myConfig.iInLineSize;
187
cairo_move_to (myDrawContext, myConfig.iLineSize, yj);
188
cairo_rel_line_to (myDrawContext, iWidth - 2*myConfig.iLineSize, 0);
189
cairo_stroke (myDrawContext);
192
GList *pWindowList = NULL;
193
if (myConfig.bDrawWindows)
195
pWindowList = cairo_dock_get_current_applis_list ();
196
pWindowList = g_list_sort (pWindowList, (GCompareFunc) _compare_icons_stack_order);
199
// chaque bureau/viewport.
200
int iNumDesktop=0, iNumViewportX=0, iNumViewportY=0;
201
for (j = 0; j < myData.switcher.iNbLines; j ++)
203
for (i = 0; i < myData.switcher.iNbColumns; i ++)
205
cairo_save (myDrawContext);
207
xi = myConfig.iLineSize + i * (myData.switcher.fOneViewportWidth + myConfig.iInLineSize);
208
yj = myConfig.iLineSize + j * (myData.switcher.fOneViewportHeight + myConfig.iInLineSize);
210
cairo_translate (myDrawContext,
214
cairo_scale (myDrawContext,
217
cairo_set_source_surface (myDrawContext,
221
cairo_paint(myDrawContext);
223
cairo_restore (myDrawContext);
225
if (myConfig.iDrawCurrentDesktopMode == SWICTHER_FILL_INVERTED && (i != myData.switcher.iCurrentColumn || j != myData.switcher.iCurrentLine))
227
cairo_save (myDrawContext);
229
cairo_set_source_rgba (myDrawContext, myConfig.RGBIndColors[0], myConfig.RGBIndColors[1], myConfig.RGBIndColors[2], myConfig.RGBIndColors[3]);
230
cairo_rectangle(myDrawContext,
231
xi - .5*myConfig.iLineSize,
232
yj - .5*myConfig.iLineSize,
233
myData.switcher.fOneViewportWidth + myConfig.iLineSize,
234
myData.switcher.fOneViewportHeight + myConfig.iLineSize);
235
cairo_fill (myDrawContext);
237
cairo_restore (myDrawContext);
240
if (myConfig.bDrawWindows)
242
cairo_save (myDrawContext);
244
cairo_translate (myDrawContext,
247
cairo_set_line_width (myDrawContext, 1.);
248
cairo_rectangle (myDrawContext,
251
myData.switcher.fOneViewportWidth,
252
myData.switcher.fOneViewportHeight);
253
cairo_clip (myDrawContext);
255
//g_print (" dessin des fenetres du bureau (%d;%d;%d) ...\n", iNumDesktop, iNumViewportX, iNumViewportY);
256
gint data[6] = {iNumDesktop, iNumViewportX, iNumViewportY, (int) myData.switcher.fOneViewportWidth, (int) myData.switcher.fOneViewportHeight, GPOINTER_TO_INT (myDrawContext)};
257
g_list_foreach (pWindowList, (GFunc) _cd_switcher_draw_windows_on_viewport, data);
259
cairo_restore (myDrawContext);
263
if (iNumViewportX == g_iNbViewportX)
266
if (iNumViewportY == g_iNbViewportY)
272
// dessin de l'indicateur sur le bureau courant (on le fait maintenant car dans le cas ou la ligne interieure est plus petite que la ligne de l'indicateur, les surfaces suivantes recouvreraient en partie la ligne.
273
if (myConfig.iDrawCurrentDesktopMode != SWICTHER_FILL_INVERTED)
275
i = myData.switcher.iCurrentColumn;
276
j = myData.switcher.iCurrentLine;
277
xi = myConfig.iLineSize + i * (myData.switcher.fOneViewportWidth + myConfig.iInLineSize);
278
yj = myConfig.iLineSize + j * (myData.switcher.fOneViewportHeight + myConfig.iInLineSize);
280
cairo_set_line_width (myDrawContext,myConfig.iLineSize);
281
cairo_set_source_rgba (myDrawContext,myConfig.RGBIndColors[0],myConfig.RGBIndColors[1],myConfig.RGBIndColors[2],myConfig.RGBIndColors[3]);
282
cairo_rectangle(myDrawContext,
283
xi - .5*myConfig.iLineSize,
284
yj - .5*myConfig.iLineSize,
285
myData.switcher.fOneViewportWidth + myConfig.iLineSize,
286
myData.switcher.fOneViewportHeight + myConfig.iLineSize);
288
if (myConfig.iDrawCurrentDesktopMode == SWICTHER_FILL)
289
cairo_fill (myDrawContext);
291
cairo_stroke(myDrawContext);
294
g_list_free (pWindowList); // le contenu appartient a la hash table, mais pas la liste.
296
if (CD_APPLET_MY_CONTAINER_IS_OPENGL)
297
cairo_dock_update_icon_texture (myIcon);
299
CD_APPLET_UPDATE_REFLECT_ON_MY_ICON;
303
void cd_switcher_draw_main_icon_expanded_mode (void)
305
// definition des parametres de dessin.
307
CD_APPLET_GET_MY_ICON_EXTENT (&iWidth, &iHeight);
308
//double fRatio = (myDock ? myDock->fRatio : 1.);
309
//double fMaxScale = cairo_dock_get_max_scale (myContainer); //coefficient Max icone Width
310
myData.switcher.fOneViewportHeight = (iHeight - 2 * myConfig.iLineSize - (myData.switcher.iNbLines - 1) * myConfig.iInLineSize) / myData.switcher.iNbLines; //hauteur d'un bureau/viewport sans compter les lignes exterieures et interieures.
311
myData.switcher.fOneViewportWidth = (iWidth - 2 * myConfig.iLineSize - (myData.switcher.iNbColumns - 1) * myConfig.iInLineSize) / myData.switcher.iNbColumns; //largeur d'un bureau/viewport sans compter les lignes exterieures et interieures.
313
cairo_surface_t *pSurface = NULL;
314
double fZoomX, fZoomY;
315
if (myConfig.bMapWallpaper)
317
cairo_dock_erase_cairo_context (myDrawContext);
319
pSurface = cairo_dock_get_desktop_bg_surface ();
320
fZoomX = 1. * iWidth / g_iXScreenWidth[CAIRO_DOCK_HORIZONTAL];
321
fZoomY= 1. * iHeight / g_iXScreenHeight[CAIRO_DOCK_HORIZONTAL];
322
cairo_translate (myDrawContext,
326
cairo_save (myDrawContext);
327
cairo_scale (myDrawContext,
330
cairo_set_source_surface (myDrawContext,
334
cairo_paint(myDrawContext);
335
cairo_restore (myDrawContext);
337
if (CD_APPLET_MY_CONTAINER_IS_OPENGL)
338
cairo_dock_update_icon_texture (myIcon);
340
CD_APPLET_UPDATE_REFLECT_ON_MY_ICON;
344
CD_APPLET_SET_LOCAL_IMAGE_ON_MY_ICON (MY_APPLET_ICON_FILE);
347
if (myConfig.bDrawWindows)
349
GList *pWindowList = cairo_dock_get_current_applis_list ();
350
pWindowList = g_list_sort (pWindowList, (GCompareFunc) _compare_icons_stack_order);
352
//fMaxScale = (myIcon->pSubDock != NULL ? cairo_dock_get_max_scale (myIcon->pSubDock) : 1);
353
//fRatio = (myIcon->pSubDock != NULL ? myIcon->pSubDock->fRatio : 1);
355
int iNumDesktop=0, iNumViewportX=0, iNumViewportY=0;
356
cairo_t *pCairoContext;
358
CairoContainer *pContainer = CD_APPLET_MY_ICONS_LIST_CONTAINER;
359
GList *pIconsList = CD_APPLET_MY_ICONS_LIST;
361
for (ic = pIconsList; ic != NULL; ic = ic->next)
364
cairo_dock_get_icon_extent (pIcon, pContainer, &iWidth, &iHeight);
366
data[0] = iNumDesktop;
367
data[1] = iNumViewportX;
368
data[2] = iNumViewportY;
371
pCairoContext = cairo_create (pIcon->pIconBuffer);
372
data[5] = GPOINTER_TO_INT (pCairoContext);
373
cairo_set_line_width (pCairoContext, 1.);
374
cairo_set_source_rgba (pCairoContext, myConfig.RGBWLineColors[0], myConfig.RGBWLineColors[1], myConfig.RGBWLineColors[2], myConfig.RGBWLineColors[3]);
376
g_list_foreach (pWindowList, (GFunc) _cd_switcher_draw_windows_on_viewport, data);
379
if (iNumViewportX == g_iNbViewportX)
382
if (iNumViewportY == g_iNbViewportY)
385
cairo_destroy (pCairoContext);
387
g_list_free (pWindowList); // le contenu appartient a la hash table, mais pas la liste.
391
/*Fonction de base pour toutes les autres*/
392
void cd_switcher_draw_main_icon (void)
394
cd_message ("%s (%d)", __func__, myConfig.bCompactView);
395
if (myConfig.bCompactView)
397
cd_switcher_draw_main_icon_compact_mode ();
401
cd_switcher_draw_main_icon_expanded_mode ();
404
CD_APPLET_REDRAW_MY_ICON;