85
85
void WorkspacesInfo::updateWorkspaceGeometry()
90
Orientation orientation;
91
Corner startingCorner;
87
int workspaceCount = 0;
88
Orientation orientation = WorkspacesInfo::OrientationHorizontal;
93
Corner startingCorner = WorkspacesInfo::CornerTopLeft;
94
bool XWorkspaceCountNeedsUpdate = false;
95
bool XLayoutNeedsUpdate = false;
97
XWorkspaceCountNeedsUpdate = !getWorkspaceCountFromX(workspaceCount);
98
XLayoutNeedsUpdate = !getWorkspaceLayoutFromX(orientation, columns, rows, startingCorner);
100
/* If the number of workspaces was not set or set to 0 fallback to a default
101
number of 4 workspaces. */
102
if (workspaceCount == 0) {
104
XWorkspaceCountNeedsUpdate = true;
107
/* Override the number of rows and columns possibly set by an external pager.
108
The number of rows and columns is computed from the number of workspaces
109
to make the layout square.
111
We override external pagers because differentiating an external pager from
112
oneself is hard. Example case where it matters:
113
Starting with 9 workspaces, we decide on 3 rows and 3 columns. When the
114
number of workspaces is then changed dynamically to 4 workspaces, without
115
override, we would layout the 4 workspaces in a 3x3 grid.
117
squareColumns = ceil(sqrt((float)workspaceCount));
118
squareRows = ceil((float) workspaceCount / (float) squareColumns);
120
if (squareColumns != columns || squareRows != rows) {
121
columns = squareColumns;
123
XLayoutNeedsUpdate = true;
126
if (XWorkspaceCountNeedsUpdate) {
127
setWorkspaceCountToX(workspaceCount);
130
if (XLayoutNeedsUpdate) {
131
setWorkspaceLayoutToX(orientation, columns, rows, startingCorner);
134
updateWorkspaceGeometryProperties(workspaceCount, orientation, columns, rows, startingCorner);
137
bool WorkspacesInfo::getWorkspaceCountFromX(int& workspaceCount)
92
139
unsigned long *result;
94
/* First obtain the number of workspaces, that will be needed to
95
also calculate some properties of the layout which could be missing
96
from the property we will retrieve after this one */
97
140
result = getX11IntProperty(_NET_NUMBER_OF_DESKTOPS, 1);
141
if (result != NULL) {
101
142
workspaceCount = result[0];
105
/* Then ask X11 the layout of the workspaces. */
150
bool WorkspacesInfo::getWorkspaceLayoutFromX(Orientation& orientation, int& columns, int& rows, Corner& startingCorner)
152
unsigned long *result;
106
153
result = getX11IntProperty(_NET_DESKTOP_LAYOUT, 4);
107
154
if (result != NULL) {
108
/* If we read the values correctly (some pager or the user set them)
109
then just use them. */
110
155
orientation = (Orientation) result[0];
111
156
columns = result[1];
112
157
rows = result[2];
113
158
startingCorner = (Corner) result[3];
115
/* Perform some sanity checks, since it's possible according to
116
the spec for rows or colums to be zero, and we are supposed to
117
calculate these values ourselves by using the total count
119
if (rows == 0 && columns == 0) {
121
columns = workspaceCount;
124
rows = ceil((float) workspaceCount / (float) columns);
125
} else if (columns == 0) {
126
columns = ceil((float) workspaceCount / (float) rows);
132
/* In this property does not exist (as is the case if you
133
don't login into the regular gnome session before unity-2d),
134
just fallback on reasonable defaults. */
136
columns = ceil((float) workspaceCount / (float) rows);
137
orientation = WorkspacesInfo::OrientationHorizontal;
138
startingCorner = WorkspacesInfo::CornerTopLeft;
141
/* Notify of changes, if any */
166
void WorkspacesInfo::setWorkspaceCountToX(int workspaceCount)
168
unsigned long values[1];
169
values[0] = workspaceCount;
170
setX11IntProperty(_NET_NUMBER_OF_DESKTOPS, (unsigned char*)values, 1);
173
void WorkspacesInfo::setWorkspaceLayoutToX(Orientation orientation, int columns, int rows, Corner startingCorner)
175
unsigned long values[4];
176
values[0] = orientation;
179
values[3] = startingCorner;
180
setX11IntProperty(_NET_DESKTOP_LAYOUT, (unsigned char*)values, 4);
183
void WorkspacesInfo::updateWorkspaceGeometryProperties(int workspaceCount, Orientation orientation, int columns, int rows, Corner startingCorner)
142
185
if (m_count != workspaceCount) {
143
186
m_count = workspaceCount;
144
187
Q_EMIT countChanged(m_count);