~ubuntu-branches/ubuntu/oneiric/cairo-dock-plug-ins/oneiric-updates

« back to all changes in this revision

Viewing changes to switcher/src/applet-desktops.c

  • Committer: Kees Cook
  • Date: 2011-08-11 23:17:39 UTC
  • mfrom: (20.1.1 cairo-dock-plug-ins)
  • Revision ID: kees@outflux.net-20110811231739-cteedan51tmdg77v
Tags: 2.4.0~0beta2-0ubuntu1
releasing version 2.4.0~0beta2-0ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
void cd_switcher_get_current_desktop (void)
29
29
{
30
30
        cairo_dock_get_current_desktop_and_viewport (&myData.switcher.iCurrentDesktop, &myData.switcher.iCurrentViewportX, &myData.switcher.iCurrentViewportY);
31
 
        //g_print ("%s () -> %d;%d;%d\n", __func__, myData.switcher.iCurrentDesktop, myData.switcher.iCurrentViewportX, myData.switcher.iCurrentViewportY);
32
31
        
33
32
        myData.switcher.iNbViewportTotal = g_desktopGeometry.iNbDesktops * g_desktopGeometry.iNbViewportX * g_desktopGeometry.iNbViewportY;
34
33
        
35
34
        cd_switcher_compute_desktop_coordinates (myData.switcher.iCurrentDesktop, myData.switcher.iCurrentViewportX, myData.switcher.iCurrentViewportY, &myData.switcher.iCurrentLine, &myData.switcher.iCurrentColumn);
 
35
        
 
36
        cd_debug ("desktop: %d;%d;%d, %dx%d", g_desktopGeometry.iNbDesktops, g_desktopGeometry.iNbViewportX, g_desktopGeometry.iNbViewportY, myData.switcher.iCurrentLine, myData.switcher.iCurrentColumn);
36
37
}
37
38
 
38
39
 
39
 
 
40
40
static void _cd_switcher_get_best_agencement (int iNbViewports, int *iBestNbLines, int *iBestNbColumns)
41
41
{
42
42
        *iBestNbLines = 0;
48
48
        cairo_dock_get_icon_extent (myIcon, myContainer, &w, &h);
49
49
        if (w == 0 || h == 0)  // may happen in desklet mode on startup, until the desklet's window reaches its definite size.
50
50
                return;
51
 
        cd_debug ("%d; %dx%d", iNbViewports, w, h);
 
51
        //cd_debug ("%d; %dx%d", iNbViewports, w, h);
52
52
        
53
53
        double fZoomX, fZoomY;
54
54
        int iNbLines, iNbDesktopByLine;
60
60
                fZoomX = (double)w / (iNbDesktopByLine * g_desktopGeometry.iXScreenWidth[CAIRO_DOCK_HORIZONTAL]);
61
61
                fZoomY = (double)h / (iNbLines * g_desktopGeometry.iXScreenHeight[CAIRO_DOCK_HORIZONTAL]);
62
62
                fZoom = MIN (fZoomX, fZoomY);  // on preserve le ratio
63
 
                cd_debug ("%d lignes => iNbDesktopByLine: %d, zooms: %.3f,%.3f", iNbLines, iNbDesktopByLine, fZoomX, fZoomY);
 
63
                //cd_debug ("%d lignes => iNbDesktopByLine: %d, zooms: %.3f,%.3f", iNbLines, iNbDesktopByLine, fZoomX, fZoomY);
64
64
                if (fZoom > fZoomMax)
65
65
                {
66
66
                        fZoomMax = fZoom;
195
195
        *iNumDesktop = iIndex / (g_desktopGeometry.iNbViewportX * g_desktopGeometry.iNbViewportY);
196
196
        int index2 = iIndex % (g_desktopGeometry.iNbViewportX * g_desktopGeometry.iNbViewportY);
197
197
        *iNumViewportX = index2 % g_desktopGeometry.iNbViewportX;
 
198
        *iNumViewportY = index2 / g_desktopGeometry.iNbViewportX;
198
199
        cd_debug ("[Switcher] New coordinates -> D=%d ; X=%d ; Y=%d ; i1=%d ; i2=%d ; nX=%d ; nY=%d", *iNumDesktop, *iNumViewportX, *iNumViewportY, iIndex, index2, g_desktopGeometry.iNbViewportX, g_desktopGeometry.iNbViewportY);
199
 
        *iNumViewportY = index2 / g_desktopGeometry.iNbViewportX;
200
200
}
201
201
 
202
202
 
226
226
}
227
227
 
228
228
 
229
 
void cd_switcher_update_from_screen_geometry (void)
 
229
static gboolean _update_idle (gpointer data)
230
230
{
231
231
        //\___________________ On calcule la geometrie de l'icone en mode compact.
232
232
        cd_switcher_compute_nb_lines_and_columns ();
239
239
        
240
240
        //\___________________ On dessine l'icone principale.
241
241
        cd_switcher_draw_main_icon ();
242
 
}
243
 
 
244
 
gboolean cd_switcher_refresh_desktop_values (CairoDockModuleInstance *myApplet)
 
242
        
 
243
        //\___________________ draw the current desktop number.
 
244
        if (myConfig.bDisplayNumDesk)
 
245
        {
 
246
                int iIndex = cd_switcher_compute_index (myData.switcher.iCurrentDesktop, myData.switcher.iCurrentViewportX, myData.switcher.iCurrentViewportY);
 
247
                CD_APPLET_SET_QUICK_INFO_ON_MY_ICON_PRINTF ("%d", iIndex+1);
 
248
        }
 
249
        
 
250
        myData.iSidUpdateIdle = 0;
 
251
        return FALSE;
 
252
}
 
253
void cd_switcher_trigger_update_from_screen_geometry (gboolean bNow)
 
254
{
 
255
        if (myData.iSidUpdateIdle == 0)
 
256
        {
 
257
                if (bNow)
 
258
                        myData.iSidUpdateIdle = g_idle_add (_update_idle, NULL);
 
259
                else
 
260
                        myData.iSidUpdateIdle = g_timeout_add_seconds (1, _update_idle, NULL);
 
261
        }
 
262
}
 
263
 
 
264
 
 
265
void cd_switcher_refresh_desktop_values (CairoDockModuleInstance *myApplet)
245
266
{
246
267
        g_desktopGeometry.iNbDesktops = cairo_dock_get_nb_desktops ();
247
268
        cairo_dock_get_nb_viewports (&g_desktopGeometry.iNbViewportX, &g_desktopGeometry.iNbViewportY);
248
269
        cd_debug ("refresh -> %d/%d/%d", g_desktopGeometry.iNbDesktops, g_desktopGeometry.iNbViewportX, g_desktopGeometry.iNbViewportY);
249
 
        cd_switcher_update_from_screen_geometry ();
250
 
        myData.iSidAutoRefresh = 0;
251
 
        return FALSE;
 
270
        cd_switcher_trigger_update_from_screen_geometry (TRUE);
252
271
}
253
272
 
254
273