~cairo-dock-team/ubuntu/precise/cairo-dock/988102

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2008-11-13 22:04:19 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20081113220419-091g450ognfgm0lo
Tags: 1.6.3.1-0ubuntu1
* New upstream release (LP: #297809).
* debian/cairo-dock-data.install:
 - Update to new upstream installation.
* debian/copyright
 - Update copyright of new files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
#include "cairo-dock-menu.h"
42
42
#include "cairo-dock-dock-factory.h"
43
43
#include "cairo-dock-X-utilities.h"
 
44
#include "cairo-dock-surface-factory.h"
 
45
#include "cairo-dock-renderer-manager.h"
44
46
#include "cairo-dock-desklet.h"
45
47
 
46
48
extern CairoDock *g_pMainDock;
47
49
extern int g_iScreenWidth[2], g_iScreenHeight[2];
48
50
extern gchar *g_cConfFile;
49
51
extern int g_iDockRadius;
50
 
extern double g_fDeskletColor[4];
51
 
extern double g_fDeskletColorInside[4];
52
52
extern gboolean g_bSticky;
 
53
extern gchar *g_cDeskletDecorationsName;
 
54
 
 
55
#define CAIRO_DOCK_DESKLET_BUTTONS_SIZE 16
 
56
static cairo_surface_t *pRotateButtonSurface = NULL;
 
57
static cairo_surface_t *pRetachButtonSurface = NULL;
 
58
 
 
59
void cairo_dock_load_desklet_buttons (cairo_t *pSourceContext)
 
60
{
 
61
        if (pRotateButtonSurface == NULL)
 
62
        {
 
63
                gchar *cRotateButtonPath = g_strdup_printf ("%s/%s", CAIRO_DOCK_SHARE_DATA_DIR, "rotate-desklet.svg");
 
64
                pRotateButtonSurface = cairo_dock_create_surface_for_icon (cRotateButtonPath, pSourceContext, CAIRO_DOCK_DESKLET_BUTTONS_SIZE, CAIRO_DOCK_DESKLET_BUTTONS_SIZE);
 
65
                g_free (cRotateButtonPath);
 
66
        }
 
67
        
 
68
        if (pRetachButtonSurface == NULL)
 
69
        {
 
70
                gchar *cRetachButtonPath = g_strdup_printf ("%s/%s", CAIRO_DOCK_SHARE_DATA_DIR, "retach-desklet.svg");
 
71
                pRetachButtonSurface = cairo_dock_create_surface_for_icon (cRetachButtonPath, pSourceContext, CAIRO_DOCK_DESKLET_BUTTONS_SIZE, CAIRO_DOCK_DESKLET_BUTTONS_SIZE);
 
72
                g_free (cRetachButtonPath);
 
73
        }
 
74
}
53
75
 
54
76
static gboolean on_expose_desklet(GtkWidget *pWidget,
55
77
        GdkEventExpose *pExpose,
62
84
        
63
85
        cairo_t *pCairoContext;
64
86
        //set the color
65
 
        double fColor[4];
 
87
        double fColor[4] = {1., 1., 1., 0.};
66
88
        int i;
67
 
        for (i = 0; i < 4; i ++)
68
 
        {
69
 
                fColor[i] = (g_fDeskletColorInside[i] * pDesklet->iGradationCount + g_fDeskletColor[i] * (CD_NB_ITER_FOR_GRADUATION - pDesklet->iGradationCount)) / CD_NB_ITER_FOR_GRADUATION;
70
 
        }
 
89
        
71
90
        if (gtk_window_is_active (GTK_WINDOW (pDesklet->pWidget)))
72
 
                fColor[3] = MIN (1., fColor[3] * 1.25);
73
 
        
 
91
                fColor[3] = 1.;
 
92
        else
 
93
                fColor[3] = 1.*pDesklet->iGradationCount / CD_NB_ITER_FOR_GRADUATION;
74
94
        
75
95
        gboolean bRenderOptimized = (pExpose->area.x > 0 || pExpose->area.y > 0);
76
96
        if (bRenderOptimized)
77
97
        {
 
98
                g_print ("Using optimized render\n");
78
99
                pCairoContext = cairo_dock_create_drawing_context_on_area (CAIRO_CONTAINER (pDesklet), &pExpose->area, fColor);
79
100
        }
80
101
        else
81
102
        {
 
103
                //cd_debug ("Using normal render");
82
104
                pCairoContext = cairo_dock_create_drawing_context (CAIRO_CONTAINER (pDesklet));
83
105
                
84
106
                if (pDesklet->fZoom != 1)
99
121
                pDesklet->iDesiredWidth = 0;
100
122
                pDesklet->iDesiredHeight = 0;
101
123
                
102
 
                
103
124
                if (fColor[3] != 0)
104
125
                {
105
 
                        cairo_save (pCairoContext);
106
 
                        cairo_set_source_rgba (pCairoContext, fColor[0], fColor[1], fColor[2], fColor[3]);
107
 
                        cairo_set_line_width (pCairoContext, g_iDockRadius);
108
 
                        cairo_set_line_join (pCairoContext, CAIRO_LINE_JOIN_ROUND);
109
 
                        //draw a rounded square
110
 
                        w = pDesklet->iWidth;
111
 
                        h = pDesklet->iHeight;
112
 
                        cairo_move_to (pCairoContext, .5*g_iDockRadius, .5*g_iDockRadius);
113
 
                        cairo_rel_line_to (pCairoContext, w - (g_iDockRadius), 0);
114
 
                        cairo_rel_line_to (pCairoContext, 0, h - (g_iDockRadius));
115
 
                        cairo_rel_line_to (pCairoContext, -(w - (g_iDockRadius)) , 0);
116
 
                        cairo_close_path (pCairoContext);
117
 
                        cairo_stroke (pCairoContext);
118
 
                        
119
 
                        cairo_rectangle(pCairoContext, g_iDockRadius, g_iDockRadius, (w - 2*g_iDockRadius), (h - 2*g_iDockRadius));
120
 
                        cairo_fill(pCairoContext);
121
 
                        cairo_restore (pCairoContext);  // retour au debut.
122
 
                }
 
126
                        cairo_pattern_t *pPattern = cairo_pattern_create_radial (.5*pDesklet->iWidth,
 
127
                                .5*pDesklet->iHeight,
 
128
                                0.,
 
129
                                .5*pDesklet->iWidth,
 
130
                                .5*pDesklet->iHeight,
 
131
                                .5*MIN (pDesklet->iWidth, pDesklet->iHeight));
 
132
                         cairo_pattern_set_extend (pPattern, CAIRO_EXTEND_NONE);
 
133
                        
 
134
                        cairo_pattern_add_color_stop_rgba   (pPattern,
 
135
                                0.,
 
136
                                fColor[0], fColor[1], fColor[2], fColor[3]);
 
137
                        cairo_pattern_add_color_stop_rgba   (pPattern,
 
138
                                1.,
 
139
                                fColor[0], fColor[1], fColor[2], 0.);
 
140
                        cairo_set_source (pCairoContext, pPattern);
 
141
                        cairo_paint (pCairoContext);
 
142
                        cairo_pattern_destroy (pPattern);
 
143
                }
 
144
                
 
145
                cairo_save (pCairoContext);
 
146
                
 
147
                if (pDesklet->fRotation != 0)
 
148
                {
 
149
                        double alpha = atan2 (pDesklet->iHeight, pDesklet->iWidth);
 
150
                        double theta = fabs (pDesklet->fRotation);
 
151
                        if (theta > G_PI/2)
 
152
                                theta -= G_PI/2;
 
153
                        double fZoomX, fZoomY;
 
154
                        double d = .5 * sqrt (pDesklet->iWidth * pDesklet->iWidth + pDesklet->iHeight * pDesklet->iHeight);
 
155
                        fZoomX = fabs (.5 * pDesklet->iWidth / (d * sin (alpha + theta)));
 
156
                        fZoomY = fabs (.5 * pDesklet->iHeight / (d * cos (alpha - theta)));
 
157
                        //g_print ("d = %.2f ; alpha = %.2f ; zoom : %.2fx%.2f\n", d, alpha/G_PI*180., fZoomX, fZoomY);
 
158
                        
 
159
                        cairo_translate (pCairoContext,
 
160
                                .5*pDesklet->iWidth,
 
161
                                .5*pDesklet->iHeight);
 
162
                        
 
163
                        cairo_rotate (pCairoContext, pDesklet->fRotation);
 
164
                        
 
165
                        cairo_translate (pCairoContext,
 
166
                                -.5*pDesklet->iWidth * fZoomX,
 
167
                                -.5*pDesklet->iHeight * fZoomY);
 
168
                        cairo_scale (pCairoContext, fZoomX, fZoomY);
 
169
                }
 
170
        }
 
171
        
 
172
        cairo_save (pCairoContext);
 
173
        if (pDesklet->pBackGroundSurface != NULL && pDesklet->fBackGroundAlpha != 0)
 
174
        {
 
175
                cairo_set_source_surface (pCairoContext,
 
176
                        pDesklet->pBackGroundSurface,
 
177
                        0.,
 
178
                        0.);
 
179
                if (pDesklet->fBackGroundAlpha == 1)
 
180
                        cairo_paint (pCairoContext);
 
181
                else
 
182
                        cairo_paint_with_alpha (pCairoContext, pDesklet->fBackGroundAlpha);
 
183
        }
 
184
        
 
185
        if (pDesklet->iLeftSurfaceOffset != 0 || pDesklet->iTopSurfaceOffset != 0 || pDesklet->iRightSurfaceOffset != 0 || pDesklet->iBottomSurfaceOffset != 0)
 
186
        {
 
187
                cairo_translate (pCairoContext, pDesklet->iLeftSurfaceOffset, pDesklet->iTopSurfaceOffset);
 
188
                cairo_scale (pCairoContext,
 
189
                        1. - 1.*(pDesklet->iLeftSurfaceOffset + pDesklet->iRightSurfaceOffset) / pDesklet->iWidth,
 
190
                        1. - 1.*(pDesklet->iTopSurfaceOffset + pDesklet->iBottomSurfaceOffset) / pDesklet->iHeight);
123
191
        }
124
192
        
125
193
        if (pDesklet->pRenderer != NULL)  // un moteur de rendu specifique a ete fourni.
128
196
                        pDesklet->pRenderer->render (pCairoContext, pDesklet, bRenderOptimized);
129
197
        }
130
198
        
 
199
        cairo_restore (pCairoContext);
 
200
        if (pDesklet->pForeGroundSurface != NULL && pDesklet->fForeGroundAlpha != 0)
 
201
        {
 
202
                cairo_set_source_surface (pCairoContext,
 
203
                        pDesklet->pForeGroundSurface,
 
204
                        0.,
 
205
                        0.);
 
206
                if (pDesklet->fForeGroundAlpha == 1)
 
207
                        cairo_paint (pCairoContext);
 
208
                else
 
209
                        cairo_paint_with_alpha (pCairoContext, pDesklet->fForeGroundAlpha);
 
210
        }
 
211
        
 
212
        if (pDesklet->bInside || pDesklet->rotating)
 
213
        {
 
214
                if (! pDesklet->rotating)
 
215
                        cairo_restore (pCairoContext);
 
216
                if (pRotateButtonSurface != NULL)
 
217
                {
 
218
                        cairo_set_source_surface (pCairoContext, pRotateButtonSurface, 0., 0.);
 
219
                        cairo_paint (pCairoContext);
 
220
                }
 
221
                if (pRetachButtonSurface != NULL)
 
222
                {
 
223
                        cairo_set_source_surface (pCairoContext, pRetachButtonSurface, pDesklet->iWidth - CAIRO_DOCK_DESKLET_BUTTONS_SIZE, 0.);
 
224
                        cairo_paint (pCairoContext);
 
225
                }
 
226
        }
 
227
 
131
228
        cairo_destroy (pCairoContext);
132
229
        return FALSE;
133
230
}
135
232
 
136
233
static gboolean _cairo_dock_write_desklet_size (CairoDesklet *pDesklet)
137
234
{
 
235
        g_print ("%s (%dx%d ; %dx%d)\n", __func__, pDesklet->iWidth, pDesklet->iHeight, pDesklet->iDesiredWidth, pDesklet->iDesiredHeight);
138
236
        if (pDesklet->pIcon != NULL && pDesklet->pIcon->pModuleInstance != NULL)
139
237
                cairo_dock_update_conf_file (pDesklet->pIcon->pModuleInstance->cConfFilePath,
140
238
                        G_TYPE_INT, "Desklet", "width", pDesklet->iWidth,
141
239
                        G_TYPE_INT, "Desklet", "height", pDesklet->iHeight,
142
240
                        G_TYPE_INVALID);
143
241
        pDesklet->iSidWriteSize = 0;
144
 
        if (pDesklet->pIcon != NULL)
 
242
        pDesklet->iKnownWidth = pDesklet->iWidth;
 
243
        pDesklet->iKnownHeight = pDesklet->iHeight;
 
244
        if (((pDesklet->iDesiredWidth != 0 || pDesklet->iDesiredHeight != 0) && pDesklet->iDesiredWidth == pDesklet->iWidth && pDesklet->iDesiredHeight == pDesklet->iHeight) || (pDesklet->iDesiredWidth == 0 && pDesklet->iDesiredHeight == 0))
145
245
        {
146
 
                pDesklet->iKnownWidth = pDesklet->iWidth;
147
 
                pDesklet->iKnownHeight = pDesklet->iHeight;
148
 
                if (pDesklet->iDesiredWidth == pDesklet->iWidth && pDesklet->iDesiredHeight == pDesklet->iHeight)
 
246
                pDesklet->iDesiredWidth = 0;
 
247
                pDesklet->iDesiredHeight = 0;
 
248
                
 
249
                cairo_t *pCairoContext = cairo_dock_create_context_from_window (CAIRO_CONTAINER (pDesklet));
 
250
                cairo_dock_load_desklet_decorations (pDesklet, pCairoContext);
 
251
                cairo_destroy (pCairoContext);
 
252
                
 
253
                if (pDesklet->pIcon != NULL && pDesklet->pIcon->pModuleInstance != NULL)
149
254
                {
150
 
                        pDesklet->iDesiredWidth = 0;
151
 
                        pDesklet->iDesiredHeight = 0;
 
255
                        cairo_dock_reload_module_instance (pDesklet->pIcon->pModuleInstance, FALSE);
 
256
                        gtk_widget_queue_draw (pDesklet->pWidget);  // sinon on ne redessine que l'interieur.
152
257
                }
153
 
                cairo_dock_reload_module_instance (pDesklet->pIcon->pModuleInstance, FALSE);
154
 
                gtk_widget_queue_draw (pDesklet->pWidget);  // sinon on ne redessine que l'interieur.
155
258
        }
 
259
        
 
260
        //g_print ("iWidth <- %d;iHeight <- %d ; (%dx%d) (%x)\n", pDesklet->iWidth, pDesklet->iHeight, pDesklet->iKnownWidth, pDesklet->iKnownHeight, pDesklet->pIcon);
156
261
        return FALSE;
157
262
}
158
263
static gboolean _cairo_dock_write_desklet_position (CairoDesklet *pDesklet)
165
270
                        G_TYPE_INT, "Desklet", "x position", iRelativePositionX,
166
271
                        G_TYPE_INT, "Desklet", "y position", iRelativePositionY,
167
272
                        G_TYPE_INVALID);
 
273
                
 
274
                /*GdkBitmap* pShapeBitmap = (GdkBitmap*) gdk_pixmap_new (NULL, pDesklet->iWidth, pDesklet->iHeight, 1);
 
275
                cairo_t* pCairoContext = gdk_cairo_create (pShapeBitmap);
 
276
                if (cairo_status (pCairoContext) == CAIRO_STATUS_SUCCESS)
 
277
                {
 
278
                        cairo_set_source_rgb (pCairoContext, 1, 1, 1);
 
279
                        cairo_paint (pCairoContext);
 
280
                        cairo_destroy (pCairoContext);
 
281
                
 
282
                
 
283
                        gtk_widget_input_shape_combine_mask (pDesklet->pWidget,
 
284
                                NULL,
 
285
                                0,
 
286
                                0);
 
287
                        gtk_widget_input_shape_combine_mask (pDesklet->pWidget,
 
288
                                pShapeBitmap,
 
289
                                0,
 
290
                                0);
 
291
                }
 
292
                g_object_unref ((gpointer) pShapeBitmap);*/
168
293
        }
169
294
        pDesklet->iSidWritePosition = 0;
170
295
        return FALSE;
176
301
        //cd_debug ("%s (%dx%d ; %d,%d)", __func__, pEvent->width, pEvent->height, (int) pEvent->x, (int) pEvent->y);
177
302
        if (pDesklet->iWidth != pEvent->width || pDesklet->iHeight != pEvent->height)
178
303
        {
 
304
                if ((pEvent->width < pDesklet->iWidth || pEvent->height < pDesklet->iHeight) && (pDesklet->iDesiredWidth != 0 && pDesklet->iDesiredHeight != 0))
 
305
                {
 
306
                        gdk_window_resize (pDesklet->pWidget->window,
 
307
                                pDesklet->iDesiredWidth,
 
308
                                pDesklet->iDesiredHeight);
 
309
                }
179
310
                pDesklet->iWidth = pEvent->width;
180
311
                pDesklet->iHeight = pEvent->height;
181
312
                
183
314
                {
184
315
                        g_source_remove (pDesklet->iSidWriteSize);
185
316
                }
 
317
                g_print ("on lance l'ecriture differee (%dx%d)\n", pDesklet->iWidth, pDesklet->iHeight);
186
318
                pDesklet->iSidWriteSize = g_timeout_add (500, (GSourceFunc) _cairo_dock_write_desklet_size, (gpointer) pDesklet);
187
319
        }
188
320
 
197
329
                }
198
330
                pDesklet->iSidWritePosition = g_timeout_add (500, (GSourceFunc) _cairo_dock_write_desklet_position, (gpointer) pDesklet);
199
331
        }
 
332
        pDesklet->moving = FALSE;
200
333
 
201
334
        return FALSE;
202
335
}
246
379
        return NULL;
247
380
}
248
381
 
249
 
static gboolean on_button_press_desklet(GtkWidget *widget,
 
382
static gboolean on_button_press_desklet(GtkWidget *pWidget,
250
383
        GdkEventButton *pButton,
251
384
        CairoDesklet *pDesklet)
252
385
{
257
390
                        pDesklet->diff_x = - pButton->x;  // pour le deplacement manuel.
258
391
                        pDesklet->diff_y = - pButton->y;
259
392
                        cd_debug ("diff : %d;%d", pDesklet->diff_x, pDesklet->diff_y);
 
393
                        
 
394
                        if (pButton->x < CAIRO_DOCK_DESKLET_BUTTONS_SIZE && pButton->y < CAIRO_DOCK_DESKLET_BUTTONS_SIZE)
 
395
                                pDesklet->rotating = TRUE;
 
396
                        else if (pButton->x > pDesklet->iWidth - CAIRO_DOCK_DESKLET_BUTTONS_SIZE && pButton->y < CAIRO_DOCK_DESKLET_BUTTONS_SIZE)
 
397
                        {
 
398
                                pDesklet->retaching = TRUE;
 
399
                        }
 
400
                        else
 
401
                                pDesklet->time = pButton->time;
260
402
                }
261
403
                else if (pButton->type == GDK_BUTTON_RELEASE)
262
404
                {
265
407
                        {
266
408
                                pDesklet->moving = FALSE;
267
409
                        }
 
410
                        else if (pDesklet->rotating)
 
411
                        {
 
412
                                pDesklet->rotating = FALSE;
 
413
                                cairo_dock_update_conf_file (pDesklet->pIcon->pModuleInstance->cConfFilePath,
 
414
                                        G_TYPE_INT, "Desklet", "rotation", (int) (pDesklet->fRotation / G_PI * 180.),
 
415
                                        G_TYPE_INVALID);
 
416
                                gtk_widget_queue_draw (pDesklet->pWidget);
 
417
                        }
 
418
                        else if (pDesklet->retaching)
 
419
                        {
 
420
                                pDesklet->retaching = FALSE;
 
421
                                if (! pDesklet->bPositionLocked && pButton->x > pDesklet->iWidth - CAIRO_DOCK_DESKLET_BUTTONS_SIZE && pButton->y < CAIRO_DOCK_DESKLET_BUTTONS_SIZE)
 
422
                                {
 
423
                                        Icon *icon = pDesklet->pIcon;
 
424
                                        g_return_val_if_fail (CAIRO_DOCK_IS_APPLET (icon), FALSE);
 
425
                                        cairo_dock_update_conf_file (icon->pModuleInstance->cConfFilePath,
 
426
                                                G_TYPE_BOOLEAN, "Desklet", "initially detached", FALSE,
 
427
                                                G_TYPE_INVALID);
 
428
                                        cairo_dock_reload_module_instance (icon->pModuleInstance, TRUE);
 
429
                                        return FALSE;
 
430
                                }
 
431
                        }
268
432
                        else
269
433
                        {
270
434
                                Icon *pClickedIcon = cairo_dock_find_clicked_icon_in_desklet (pDesklet);
274
438
                }
275
439
                else if (pButton->type == GDK_2BUTTON_PRESS)
276
440
                {
277
 
                        Icon *pClickedIcon = cairo_dock_find_clicked_icon_in_desklet (pDesklet);
278
 
                        gpointer data[2] = {pClickedIcon, pDesklet};
279
 
                        cairo_dock_notify (CAIRO_DOCK_DOUBLE_CLICK_ICON, data);
 
441
                        if (pButton->x < CAIRO_DOCK_DESKLET_BUTTONS_SIZE && pButton->y < CAIRO_DOCK_DESKLET_BUTTONS_SIZE)
 
442
                        {
 
443
                                pDesklet->fRotation = 0.;
 
444
                                gtk_widget_queue_draw (pDesklet->pWidget);
 
445
                                cairo_dock_update_conf_file (pDesklet->pIcon->pModuleInstance->cConfFilePath,
 
446
                                        G_TYPE_INT, "Desklet", "rotation", 0,
 
447
                                        G_TYPE_INVALID);
 
448
                        }
 
449
                        else
 
450
                        {
 
451
                                Icon *pClickedIcon = cairo_dock_find_clicked_icon_in_desklet (pDesklet);
 
452
                                gpointer data[2] = {pClickedIcon, pDesklet};
 
453
                                cairo_dock_notify (CAIRO_DOCK_DOUBLE_CLICK_ICON, data);
 
454
                        }
280
455
                }
281
456
        }
282
457
        else if (pButton->button == 3 && pButton->type == GDK_BUTTON_PRESS)  // clique droit.
297
472
        }
298
473
        else if (pButton->button == 2 && pButton->type == GDK_BUTTON_PRESS)  // clique milieu.
299
474
        {
300
 
                gpointer data[2] = {pDesklet->pIcon, pDesklet};
301
 
                cairo_dock_notify (CAIRO_DOCK_MIDDLE_CLICK_ICON, data);
 
475
                if (pButton->x < CAIRO_DOCK_DESKLET_BUTTONS_SIZE && pButton->y < CAIRO_DOCK_DESKLET_BUTTONS_SIZE)
 
476
                {
 
477
                        pDesklet->fRotation = 0.;
 
478
                        gtk_widget_queue_draw (pDesklet->pWidget);
 
479
                        cairo_dock_update_conf_file (pDesklet->pIcon->pModuleInstance->cConfFilePath,
 
480
                                G_TYPE_INT, "Desklet", "rotation", 0,
 
481
                                G_TYPE_INVALID);
 
482
                }
 
483
                else
 
484
                {
 
485
                        gpointer data[2] = {pDesklet->pIcon, pDesklet};
 
486
                        cairo_dock_notify (CAIRO_DOCK_MIDDLE_CLICK_ICON, data);
 
487
                }
302
488
        }
303
489
        return FALSE;
304
490
}
324
510
        if (pMotion->state & GDK_BUTTON1_MASK && ! pDesklet->bPositionLocked)
325
511
        {
326
512
                cd_debug ("root : %d;%d", (int) pMotion->x_root, (int) pMotion->y_root);
327
 
                pDesklet->moving = TRUE;
 
513
                /*pDesklet->moving = TRUE;
328
514
                gtk_window_move (GTK_WINDOW (pWidget),
329
515
                        pMotion->x_root + pDesklet->diff_x,
330
 
                        pMotion->y_root + pDesklet->diff_y);
 
516
                        pMotion->y_root + pDesklet->diff_y);*/
331
517
        }
332
518
        else  // le 'press-button' est local au sous-widget clique, alors que le 'motion-notify' est global a la fenetre; c'est donc par lui qu'on peut avoir a coup sur les coordonnees du curseur (juste avant le clic).
333
519
        {
334
520
                pDesklet->diff_x = -pMotion->x;
335
521
                pDesklet->diff_y = -pMotion->y;
336
522
        }
 
523
        
 
524
        if (pDesklet->rotating && ! pDesklet->bPositionLocked)
 
525
        {
 
526
                double alpha = atan2 (pDesklet->iHeight, - pDesklet->iWidth);
 
527
                pDesklet->fRotation = alpha - atan2 (.5*pDesklet->iHeight - pMotion->y, pMotion->x - .5*pDesklet->iWidth);
 
528
                while (pDesklet->fRotation > G_PI)
 
529
                        pDesklet->fRotation -= 2 * G_PI;
 
530
                while (pDesklet->fRotation <= - G_PI)
 
531
                        pDesklet->fRotation += 2 * G_PI;
 
532
                gtk_widget_queue_draw(pDesklet->pWidget);
 
533
        }
 
534
        else if (pMotion->state & GDK_BUTTON1_MASK && ! pDesklet->bPositionLocked && ! pDesklet->moving)
 
535
        {
 
536
                gtk_window_begin_move_drag (GTK_WINDOW (gtk_widget_get_toplevel (pWidget)),
 
537
                        1/*pButton->button*/,
 
538
                        pMotion->x_root/*pButton->x_root*/,
 
539
                        pMotion->y_root/*pButton->y_root*/,
 
540
                        pDesklet->time/*pButton->time*/);
 
541
                pDesklet->moving = TRUE;
 
542
        }
337
543
        gdk_device_get_state (pMotion->device, pMotion->window, NULL, NULL);  // pour recevoir d'autres MotionNotify.
338
544
        return FALSE;
339
545
}
500
706
  return pDesklet;
501
707
}
502
708
 
503
 
void cairo_dock_place_desklet (CairoDesklet *pDesklet, CairoDockMinimalAppletConfig *pMinimalConfig)
 
709
void cairo_dock_configure_desklet (CairoDesklet *pDesklet, CairoDockMinimalAppletConfig *pMinimalConfig)
504
710
{
505
 
        cd_message ("%s (%dx%d ; (%d,%d) ; %d,%d,%d)", __func__, pMinimalConfig->iDeskletWidth, pMinimalConfig->iDeskletHeight, pMinimalConfig->iDeskletPositionX, pMinimalConfig->iDeskletPositionY, pMinimalConfig->bKeepBelow, pMinimalConfig->bKeepAbove, pMinimalConfig->bOnWidgetLayer);
506
 
        if (pMinimalConfig->bDeskletUseSize)
 
711
        g_print ("%s (%dx%d ; (%d,%d) ; %d,%d,%d)\n", __func__, pMinimalConfig->iDeskletWidth, pMinimalConfig->iDeskletHeight, pMinimalConfig->iDeskletPositionX, pMinimalConfig->iDeskletPositionY, pMinimalConfig->bKeepBelow, pMinimalConfig->bKeepAbove, pMinimalConfig->bOnWidgetLayer);
 
712
        if (pMinimalConfig->bDeskletUseSize && (pMinimalConfig->iDeskletWidth != pDesklet->iWidth || pMinimalConfig->iDeskletHeight != pDesklet->iHeight))
507
713
        {
508
714
                pDesklet->iDesiredWidth = pMinimalConfig->iDeskletWidth;
509
715
                pDesklet->iDesiredHeight = pMinimalConfig->iDeskletHeight;
 
716
                g_print ("use size\n");
510
717
                gdk_window_resize (pDesklet->pWidget->window,
511
718
                        pMinimalConfig->iDeskletWidth,
512
719
                        pMinimalConfig->iDeskletHeight);
532
739
                cairo_dock_set_xwindow_type_hint (Xid, "_NET_WM_WINDOW_TYPE_NORMAL");
533
740
        
534
741
        pDesklet->bPositionLocked = pMinimalConfig->bPositionLocked;
 
742
        pDesklet->fRotation = pMinimalConfig->iRotation / 180. * G_PI ;
 
743
        
 
744
        g_free (pDesklet->cDecorationTheme);
 
745
        pDesklet->cDecorationTheme = pMinimalConfig->cDecorationTheme;
 
746
        pMinimalConfig->cDecorationTheme = NULL;
 
747
        cairo_dock_free_desklet_decoration (pDesklet->pUserDecoration);
 
748
        pDesklet->pUserDecoration = pMinimalConfig->pUserDecoration;
 
749
        pMinimalConfig->pUserDecoration = NULL;
 
750
        
 
751
        cd_debug ("%s (%dx%d ; %d)", __func__, pDesklet->iDesiredWidth, pDesklet->iDesiredHeight, pDesklet->iSidWriteSize);
 
752
        if (pDesklet->iDesiredWidth == 0 && pDesklet->iDesiredHeight == 0 && pDesklet->iSidWriteSize == 0)
 
753
        {
 
754
                cairo_t *pCairoContext = cairo_dock_create_context_from_window (CAIRO_CONTAINER (pDesklet));
 
755
                cairo_dock_load_desklet_decorations (pDesklet, pCairoContext);
 
756
                cairo_destroy (pCairoContext);
 
757
        }
535
758
}
536
759
 
537
760
 
578
801
                pDesklet->icons = NULL;
579
802
        }
580
803
        
 
804
        g_free (pDesklet->cDecorationTheme);
 
805
        cairo_dock_free_desklet_decoration (pDesklet->pUserDecoration);
 
806
        
581
807
        g_free(pDesklet);
582
808
}
583
809
 
677
903
        pDesklet->fZoom = 0;
678
904
        pDesklet->iSidGrowUp = g_timeout_add (50, (GSourceFunc) _cairo_dock_grow_up_desklet, (gpointer) pDesklet);
679
905
}
 
906
 
 
907
 
 
908
void cairo_dock_load_desklet_decorations (CairoDesklet *pDesklet, cairo_t *pSourceContext)
 
909
{
 
910
        if (pDesklet->pBackGroundSurface != NULL)
 
911
        {
 
912
                cairo_surface_destroy (pDesklet->pBackGroundSurface);
 
913
                pDesklet->pBackGroundSurface = NULL;
 
914
        }
 
915
        if (pDesklet->pForeGroundSurface != NULL)
 
916
        {
 
917
                cairo_surface_destroy (pDesklet->pForeGroundSurface);
 
918
                pDesklet->pForeGroundSurface = NULL;
 
919
        }
 
920
        
 
921
        CairoDeskletDecoration *pDeskletDecorations;
 
922
        cd_message ("%s (%s)", __func__, pDesklet->cDecorationTheme);
 
923
        if (pDesklet->cDecorationTheme == NULL || strcmp (pDesklet->cDecorationTheme, "personnal") == 0)
 
924
                pDeskletDecorations = pDesklet->pUserDecoration;
 
925
        else if (strcmp (pDesklet->cDecorationTheme, "default") == 0)
 
926
                pDeskletDecorations = cairo_dock_get_desklet_decoration (g_cDeskletDecorationsName);
 
927
        else
 
928
                pDeskletDecorations = cairo_dock_get_desklet_decoration (pDesklet->cDecorationTheme);
 
929
        if (pDeskletDecorations == NULL)  // peut arriver si rendering n'a pas encore charge ses decorations.
 
930
                return ;
 
931
        cd_debug ("pDeskletDecorations : %s (%x)", pDesklet->cDecorationTheme, pDeskletDecorations);
 
932
        
 
933
        double fZoomX = 0., fZoomY = 0.;
 
934
        if  (pDeskletDecorations->cBackGroundImagePath != NULL && pDeskletDecorations->fBackGroundAlpha > 0)
 
935
        {
 
936
                cd_debug ("bg : %s", pDeskletDecorations->cBackGroundImagePath);
 
937
                pDesklet->pBackGroundSurface = cairo_dock_create_surface_from_image (pDeskletDecorations->cBackGroundImagePath,
 
938
                        pSourceContext,
 
939
                        1.,  // cairo_dock_get_max_scale (pDesklet)
 
940
                        pDesklet->iWidth, pDesklet->iHeight,
 
941
                        pDeskletDecorations->iLoadingModifier,
 
942
                        &pDesklet->fImageWidth, &pDesklet->fImageHeight,
 
943
                        &fZoomX, &fZoomY);
 
944
        }
 
945
        if (pDeskletDecorations->cForeGroundImagePath != NULL && pDeskletDecorations->fForeGroundAlpha > 0)
 
946
        {
 
947
                cd_debug ("fg : %s", pDeskletDecorations->cForeGroundImagePath);
 
948
                pDesklet->pForeGroundSurface = cairo_dock_create_surface_from_image (pDeskletDecorations->cForeGroundImagePath,
 
949
                        pSourceContext,
 
950
                        1.,  // cairo_dock_get_max_scale (pDesklet)
 
951
                        pDesklet->iWidth, pDesklet->iHeight,
 
952
                        pDeskletDecorations->iLoadingModifier,
 
953
                        &pDesklet->fImageWidth, &pDesklet->fImageHeight,
 
954
                        &fZoomX, &fZoomY);
 
955
        }
 
956
        cd_debug ("image : %.2fx%.2f ; zoom : %.2fx%.2f", pDesklet->fImageWidth, pDesklet->fImageHeight, fZoomX, fZoomY);
 
957
        pDesklet->iLeftSurfaceOffset = pDeskletDecorations->iLeftMargin * fZoomX;
 
958
        pDesklet->iTopSurfaceOffset = pDeskletDecorations->iTopMargin * fZoomY;
 
959
        pDesklet->iRightSurfaceOffset = pDeskletDecorations->iRightMargin * fZoomX;
 
960
        pDesklet->iBottomSurfaceOffset = pDeskletDecorations->iBottomMargin * fZoomY;
 
961
        pDesklet->fBackGroundAlpha = pDeskletDecorations->fBackGroundAlpha;
 
962
        pDesklet->fForeGroundAlpha = pDeskletDecorations->fForeGroundAlpha;
 
963
        cd_debug ("%d;%d;%d;%d ; %.2f;%.2f", pDesklet->iLeftSurfaceOffset, pDesklet->iTopSurfaceOffset, pDesklet->iRightSurfaceOffset, pDesklet->iBottomSurfaceOffset, pDesklet->fBackGroundAlpha, pDesklet->fForeGroundAlpha);
 
964
}
 
965
 
 
966
 
 
967
void cairo_dock_free_minimal_config (CairoDockMinimalAppletConfig *pMinimalConfig)
 
968
{
 
969
        if (pMinimalConfig == NULL)
 
970
                return;
 
971
        g_free (pMinimalConfig->cLabel);
 
972
        g_free (pMinimalConfig->cIconFileName);
 
973
        g_free (pMinimalConfig->cDockName);
 
974
        g_free (pMinimalConfig->cDecorationTheme);
 
975
        cairo_dock_free_desklet_decoration (pMinimalConfig->pUserDecoration);
 
976
        g_free (pMinimalConfig);
 
977
}
 
978
 
 
979
 
 
980
static gboolean _cairo_dock_reload_one_desklet_decorations (CairoDesklet *pDesklet, CairoDockModuleInstance *pInstance, gpointer *data)
 
981
{
 
982
        gboolean bDefaultThemeOnly = GPOINTER_TO_INT (data[0]);
 
983
        cairo_t *pSourceContext = data[1];
 
984
        
 
985
        if (bDefaultThemeOnly)
 
986
        {
 
987
                if (pDesklet->cDecorationTheme == NULL || strcmp (pDesklet->cDecorationTheme, "default") == 0)
 
988
                {
 
989
                        cd_message ("on recharge les decorations de ce desklet");
 
990
                        cairo_dock_load_desklet_decorations (pDesklet, pSourceContext);
 
991
                }
 
992
        }
 
993
        else  // tous ceux qui ne sont pas encore charges et qui ont leur taille definitive.
 
994
        {
 
995
                cd_debug ("pouet %dx%d ; %d ; %x;%x", pDesklet->iDesiredWidth, pDesklet->iDesiredHeight, pDesklet->iSidWriteSize, pDesklet->pBackGroundSurface, pDesklet->pForeGroundSurface);
 
996
                if (pDesklet->iDesiredWidth == 0 && pDesklet->iDesiredHeight == 0 && pDesklet->iSidWriteSize == 0 && pDesklet->pBackGroundSurface == NULL && pDesklet->pForeGroundSurface == NULL)
 
997
                {
 
998
                        cd_message ("ce desklet a saute le chargement de ses deco => on l'aide.");
 
999
                        cairo_dock_load_desklet_decorations (pDesklet, pSourceContext);
 
1000
                }
 
1001
        }
 
1002
        return FALSE;
 
1003
}
 
1004
void cairo_dock_reload_desklets_decorations (gboolean bDefaultThemeOnly, cairo_t *pSourceContext)  // tous ou bien seulement ceux avec "default".
 
1005
{
 
1006
        cd_message ("%s (%d)", __func__, bDefaultThemeOnly);
 
1007
        gpointer data[2] = {GINT_TO_POINTER (bDefaultThemeOnly), pSourceContext};
 
1008
        cairo_dock_foreach_desklet ((CairoDockForeachDeskletFunc)_cairo_dock_reload_one_desklet_decorations, data);
 
1009
}