~cairo-dock-team/ubuntu/precise/cairo-dock-plug-ins/3.0.0.0rc1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/**
* This file is a part of the Cairo-Dock project
*
* Copyright : (C) see the 'copyright' file.
* E-mail    : see the 'copyright' file.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <string.h>

#include "applet-struct.h"
#include "applet-desktops.h"
#include "applet-draw.h"
#include "applet-load-icons.h"


static void _load_desktop_icon (Icon *pIcon)
{
	int iWidth = pIcon->iImageWidth;
	int iHeight = pIcon->iImageHeight;
	
	pIcon->pIconBuffer = cairo_dock_duplicate_surface (myData.pDesktopBgMapSurface,
		myData.iSurfaceWidth, myData.iSurfaceHeight,
		iWidth, iHeight);
}

static GList * _load_icons (void)
{
	GList *pIconList = NULL;
	int iIndex = cd_switcher_compute_index (myData.switcher.iCurrentDesktop, myData.switcher.iCurrentViewportX, myData.switcher.iCurrentViewportY);
	Icon *pIcon;
	int i;
	for (i = 0; i < myData.switcher.iNbViewportTotal; i ++)
	{
		pIcon = cairo_dock_create_dummy_launcher (NULL,
			(myConfig.bMapWallpaper ? NULL : (myConfig.cDefaultIcon != NULL ? g_strdup (myConfig.cDefaultIcon) : g_strdup (MY_APPLET_SHARE_DATA_DIR"/default.svg"))),
			NULL,
			g_strdup_printf ("%d",i+1),
			i);
		if (i == iIndex)
		{
			pIcon->cName = g_strdup_printf ("%s (%d)", D_("Current"), i+1);
			pIcon->bHasIndicator = TRUE;
			pIcon->fAlpha = .7;
		}
		else
		{
			pIcon->cName = (i < myConfig.iNbNames ? g_strdup (myConfig.cDesktopNames[i]) : g_strdup_printf ("%s %d", D_("Desktop"), i+1));
			pIcon->bHasIndicator = FALSE;
			pIcon->fAlpha = 1.;
		}
		pIcon->cParentDockName = g_strdup (myIcon->cName);
		
		if (myConfig.bMapWallpaper)
		{
			pIcon->iface.load_image = _load_desktop_icon;
		}
		
		pIconList = g_list_append (pIconList, pIcon);
	}
	
	return pIconList;
}



void cd_switcher_load_icons (void)
{
	CD_APPLET_DELETE_MY_ICONS_LIST;
	cairo_surface_destroy (myData.pDesktopBgMapSurface);
	myData.pDesktopBgMapSurface = NULL;
	cairo_surface_destroy (myData.pDefaultMapSurface);
	myData.pDefaultMapSurface = NULL;
	
	if (myConfig.bMapWallpaper)
	{
		cd_switcher_load_desktop_bg_map_surface ();
	}
	if (myData.pDesktopBgMapSurface == NULL)
	{
		cd_switcher_load_default_map_surface ();
	}
	
	if (myConfig.bCompactView)
	{
		if (myIcon->pSubDock != NULL)  // si on est passe de expanded a compact, le sous-dock vide reste.
		{
			cairo_dock_destroy_dock (myIcon->pSubDock, myIcon->cName);
			myIcon->pSubDock = NULL;
		}
		if (myDesklet)
		{
			CD_APPLET_SET_DESKLET_RENDERER ("Simple");
			myDesklet->render_bounding_box = cd_switcher_draw_desktops_bounding_box;  // pour le picking du bureau clique.
		}
	}
	else
	{
		//\_______________________ On cree la liste des icones de prevision.
		GList *pIconList = _load_icons ();
		
		//\_______________________ On charge la nouvelle liste.
		CD_APPLET_LOAD_MY_ICONS_LIST (pIconList, myConfig.cRenderer, "Slide", NULL);
		
		//\_______________________ On peint les icones.
		///cd_switcher_trigger_paint_icons ();
	}
}

/**void cd_switcher_paint_icons (void)
{
	//\_______________________ On applique la surface.
	CairoContainer *pContainer = CD_APPLET_MY_ICONS_LIST_CONTAINER;
	GList *pIconList = CD_APPLET_MY_ICONS_LIST;
	if (pIconList == NULL)
		return ;
	
	cairo_surface_t *pSurface = NULL;
	double fZoomX, fZoomY;
	Icon *pFirstIcon = pIconList->data;
	
	int iWidth, iHeight;
	cairo_dock_get_icon_extent (pFirstIcon, &iWidth, &iHeight);
	int _iWidth, _iHeight;
	CD_APPLET_GET_MY_ICON_EXTENT (&_iWidth, &_iHeight);
	
	if (myConfig.bMapWallpaper)
	{
		cd_switcher_draw_main_icon();
		pSurface = myData.pDesktopBgMapSurface;
		fZoomX = (double)iWidth / _iWidth;
		fZoomY = (double)iHeight / _iHeight;
	
	}
	if (pSurface == NULL)
	{
		pSurface = myData.pDefaultMapSurface;
		fZoomX = (double)iWidth / _iWidth;
		fZoomY = (double)iHeight / _iHeight;
	}
	
	cairo_t *pIconContext;
	GList* ic;
	Icon *icon;
	for (ic = pIconList; ic != NULL; ic = ic->next)
	{
		icon = ic->data;
		//g_print (" (%.2f; %.2f) %.2fx%.2f\n", icon->fDrawX, icon->fDrawY, icon->fWidth, icon->fHeight);
		pIconContext = cairo_create (icon->pIconBuffer);
		cairo_scale (pIconContext,
			fZoomX,
			fZoomY);

		cairo_dock_set_icon_surface_with_reflect (pIconContext, pSurface, icon, pContainer);
		cairo_destroy (pIconContext);
	}
}

static gboolean _paint_icons (gpointer data)
{
	CD_APPLET_ENTER;
	if (! myConfig.bCompactView)
		cd_switcher_paint_icons ();
	myData.iSidPainIcons = 0;
	CD_APPLET_LEAVE (FALSE);
}
void cd_switcher_trigger_paint_icons (void)
{
	if (myData.iSidPainIcons != 0)  // on la lance en idle, car les icones sont chargees en idle.
		g_source_remove (myData.iSidPainIcons);
	myData.iSidPainIcons = g_idle_add ((GSourceFunc)_paint_icons, NULL);
}*/


void cd_switcher_load_desktop_bg_map_surface (void)
{
	// get the background surface
	CairoDockDesktopBackground *db = cairo_dock_get_desktop_background (FALSE);  // FALSE <=> sans texture.
	cairo_surface_t *pBgSurface = cairo_dock_get_desktop_bg_surface (db);
	
	if (myData.pDesktopBgMapSurface != NULL)
		cairo_surface_destroy (myData.pDesktopBgMapSurface);
	if (pBgSurface == NULL)
	{
		cd_warning ("couldn't get the wallpaper");
		myData.pDesktopBgMapSurface = NULL;
		cairo_dock_destroy_desktop_background (db);
		return ;
	}
	
	// load it at a decent size.
	if (myDock)
	{
		CD_APPLET_GET_MY_ICON_EXTENT (&myData.iSurfaceWidth, &myData.iSurfaceHeight);
	}
	else
	{
		myData.iSurfaceWidth = myContainer->iWidth / myData.switcher.iNbViewportTotal;
		myData.iSurfaceHeight = myContainer->iHeight / myData.switcher.iNbViewportTotal;
	}
	// g_print ("%s (%dx%d)\n", __func__, myData.iSurfaceWidth, myData.iSurfaceHeight);
	
	myData.pDesktopBgMapSurface = cairo_dock_duplicate_surface (pBgSurface,
		g_desktopGeometry.iXScreenWidth[CAIRO_DOCK_HORIZONTAL], g_desktopGeometry.iXScreenHeight[CAIRO_DOCK_HORIZONTAL],
		myData.iSurfaceWidth, myData.iSurfaceHeight);
	
	cairo_dock_destroy_desktop_background (db);
}

void cd_switcher_load_default_map_surface (void)
{
	if (myData.pDefaultMapSurface != NULL)
		cairo_surface_destroy (myData.pDefaultMapSurface);
	if (myDock)
	{
		CD_APPLET_GET_MY_ICON_EXTENT (&myData.iSurfaceWidth, &myData.iSurfaceHeight);
	}
	else
	{
		myData.iSurfaceWidth = myContainer->iWidth / myData.switcher.iNbViewportTotal;
		myData.iSurfaceHeight = myContainer->iHeight / myData.switcher.iNbViewportTotal;
	}
	// g_print ("%s (%dx%d)\n", __func__, myData.iSurfaceWidth, myData.iSurfaceHeight);
	myData.pDefaultMapSurface = cairo_dock_create_surface_from_image_simple (myConfig.cDefaultIcon,
		myData.iSurfaceWidth,
		myData.iSurfaceHeight);
}