~cairo-dock-team/ubuntu/oneiric/cairo-dock-plug-ins/2.4.0-0beta2

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Matthieu Baerts (matttbe)
  • Date: 2011-04-20 20:46:51 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20110420204651-ftnpzesj6uc7qeul
Tags: 2.3.0~1-0ubuntu1
* New Upstream Version (LP: #723995)
* Upstream short ChangeLog (since 2.3.0~0rc1):
 - Updated translations
 - Updated the integration of the new versions of kwin and compiz
    (Switcher, ShowDesktop, etc.)
 - Removed a lot of useless g_print
 - Updated a few plug-ins to fit with the new version of the API (gldit)
 - Fixed a few bugs
 - Updated MeMenu, MessagingMenu and Status-Notifier to works
    with the latest version of dbusmenu, etc.
* Switch to dpkg-source 3.0 (quilt) format
* debian/cairo-dock-plug-ins.install:
 - Added new files (interfaces for python, ruby, vala and mono)
* debian/control:
 - Added new dependences for new applets (sensors and zeitgeist)
    and new interfaces (python, valac, ruby and mono)
 - Updated the version of cairo-dock build-dependences
* debian/rules:
 - Added a new CMake flag to install python interface in debian/tmp
* Updated debian/watch

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
 
40
40
static void _cd_switcher_get_best_agencement (int iNbViewports, int *iBestNbLines, int *iBestNbColumns)
41
41
{
 
42
        *iBestNbLines = 0;
 
43
        *iBestNbColumns = 0;
42
44
        g_return_if_fail (iNbViewports != 0);
43
45
        //g_print ("%s (%d)\n", __func__, iNbViewports);
 
46
        
 
47
        int w, h;
 
48
        cairo_dock_get_icon_extent (myIcon, myContainer, &w, &h);
 
49
        if (w == 0 || h == 0)  // may happen in desklet mode on startup, until the desklet's window reaches its definite size.
 
50
                return;
 
51
        cd_debug ("%d; %dx%d", iNbViewports, w, h);
 
52
        
44
53
        double fZoomX, fZoomY;
45
54
        int iNbLines, iNbDesktopByLine;
46
 
        int Nx, Ny;
47
 
        
48
 
        ///if (myConfig.bPreserveScreenRatio)  // on va chercher a minimiser la deformation de l'image de fond d'ecran.
 
55
        double fZoom, fZoomMax=0.;
 
56
        for (iNbLines = 1; iNbLines <= iNbViewports; iNbLines ++)
49
57
        {
50
 
                int w, h;
51
 
                cairo_dock_get_icon_extent (myIcon, myContainer, &w, &h);
52
 
                double fRatio, fMinRatio=9999;
53
 
                for (iNbLines = 1; iNbLines <= iNbViewports; iNbLines ++)
54
 
                {
55
 
                        ///if (iNbViewports % iNbLines != 0)
56
 
                        ///     continue;
57
 
                        iNbDesktopByLine = iNbViewports / iNbLines;
58
 
                        fZoomX = (double)w / (iNbDesktopByLine * g_desktopGeometry.iXScreenWidth[CAIRO_DOCK_HORIZONTAL]);
59
 
                        fZoomY = (double)h / (iNbLines * g_desktopGeometry.iXScreenHeight[CAIRO_DOCK_HORIZONTAL]);
60
 
                        fRatio = (fZoomX > fZoomY ? fZoomX / fZoomY : fZoomY / fZoomX);  // ratio ramene dans [1, inf].
61
 
                        //cd_debug ("%d lignes => fRatio: %.2f", iNbLines, fRatio);
62
 
                        if (fRatio < fMinRatio)
 
58
                iNbDesktopByLine = ceil ((double)iNbViewports / iNbLines);
 
59
                
 
60
                fZoomX = (double)w / (iNbDesktopByLine * g_desktopGeometry.iXScreenWidth[CAIRO_DOCK_HORIZONTAL]);
 
61
                fZoomY = (double)h / (iNbLines * g_desktopGeometry.iXScreenHeight[CAIRO_DOCK_HORIZONTAL]);
 
62
                fZoom = MIN (fZoomX, fZoomY);  // on preserve le ratio
 
63
                cd_debug ("%d lignes => iNbDesktopByLine: %d, zooms: %.3f,%.3f", iNbLines, iNbDesktopByLine, fZoomX, fZoomY);
 
64
                if (fZoom > fZoomMax)
 
65
                {
 
66
                        fZoomMax = fZoom;
 
67
                        *iBestNbColumns = iNbDesktopByLine;
 
68
                        *iBestNbLines = iNbLines;
 
69
                }
 
70
                else if (fabs (fZoom - fZoomMax) < 1e-4)  // same zoom, the solution which minimizes the number of squares is better.
 
71
                {
 
72
                        if (iNbLines * iNbDesktopByLine < *iBestNbColumns * *iBestNbLines)
63
73
                        {
64
 
                                fMinRatio = fRatio;
65
74
                                *iBestNbColumns = iNbDesktopByLine;
66
 
                                *iBestNbLines = iNbLines;
 
75
                                *iBestNbLines = iNbLines;       
67
76
                        }
68
77
                }
69
78
        }
70
 
        /**else  // on va chercher a repartir au mieux les bureaux sur l'icone.
71
 
        {
72
 
                if (myIcon->fWidth >= myIcon->fHeight)
73
 
                {
74
 
                        *iBestNbColumns = (int) ceil (sqrt (iNbViewports));
75
 
                        *iBestNbLines = (int) ceil ((double)iNbViewports / (*iBestNbColumns));
76
 
                }
77
 
                else
78
 
                {
79
 
                        *iBestNbLines = (int) ceil (sqrt (iNbViewports));
80
 
                        *iBestNbColumns = (int) ceil ((double)iNbViewports / (*iBestNbLines));
81
 
                }
82
 
        }*/
83
 
        
84
79
}
85
80
void cd_switcher_compute_nb_lines_and_columns (void)
86
81
{
114
109
 
115
110
void cd_switcher_compute_desktop_coordinates (int iNumDesktop, int iNumViewportX, int iNumViewportY, int *iNumLine, int *iNumColumn)
116
111
{
117
 
        g_return_if_fail (myData.switcher.iNbColumns != 0);
 
112
        if (myData.switcher.iNbColumns == 0)  // may happen in desklet mode with a cube desktop, when the desklet is still 0x0.
 
113
        {
 
114
                *iNumLine = 0;
 
115
                *iNumColumn = 0;
 
116
                return;
 
117
        }
118
118
        //cd_debug ("%s (%d;%d)", __func__, iNumViewportX, iNumViewportY);
119
119
        if (g_desktopGeometry.iNbDesktops > 1)  // plusieurs bureaux simples (Metacity) ou etendus (Compiz avec 2 cubes).
120
120
        {
181
181
 
182
182
int cd_switcher_compute_index (int iNumDesktop, int iNumViewportX, int iNumViewportY)
183
183
{
184
 
        return iNumDesktop * g_desktopGeometry.iNbViewportX * g_desktopGeometry.iNbViewportY + iNumViewportX * g_desktopGeometry.iNbViewportY + iNumViewportY;
 
184
        return iNumDesktop * g_desktopGeometry.iNbViewportX * g_desktopGeometry.iNbViewportY + iNumViewportX + iNumViewportY * g_desktopGeometry.iNbViewportX;
185
185
}
186
186
 
187
187
void cd_switcher_compute_viewports_from_index (int iIndex, int *iNumDesktop, int *iNumViewportX, int *iNumViewportY)
194
194
        
195
195
        *iNumDesktop = iIndex / (g_desktopGeometry.iNbViewportX * g_desktopGeometry.iNbViewportY);
196
196
        int index2 = iIndex % (g_desktopGeometry.iNbViewportX * g_desktopGeometry.iNbViewportY);
197
 
        *iNumViewportX = index2 / g_desktopGeometry.iNbViewportY;
198
 
        *iNumViewportY = index2 % g_desktopGeometry.iNbViewportY;
199
 
        //g_print (" -> %d;%d;%d\n", *iNumDesktop, *iNumViewportX, *iNumViewportY);
 
197
        *iNumViewportX = index2 % g_desktopGeometry.iNbViewportX;
 
198
        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