Merge lp:~aacid/unity-2d/unity-2d-shell_readd_struts_support into lp:~unity-2d-team/unity-2d/unity-2d-shell

Proposed by Albert Astals Cid
Status: Merged
Approved by: Michał Sawicz
Approved revision: 926
Merged at revision: 928
Proposed branch: lp:~aacid/unity-2d/unity-2d-shell_readd_struts_support
Merge into: lp:~unity-2d-team/unity-2d/unity-2d-shell
Diff against target: 526 lines (+314/-66)
8 files modified
libunity-2d-private/Unity2d/plugin.cpp (+5/-0)
libunity-2d-private/src/CMakeLists.txt (+1/-0)
libunity-2d-private/src/strutmanager.cpp (+191/-0)
libunity-2d-private/src/strutmanager.h (+92/-0)
libunity-2d-private/src/unity2dpanel.cpp (+9/-66)
libunity-2d-private/src/unity2dpanel.h (+1/-0)
shell/Shell.qml (+14/-0)
shell/launcher/LauncherLoader.qml (+1/-0)
To merge this branch: bzr merge lp:~aacid/unity-2d/unity-2d-shell_readd_struts_support
Reviewer Review Type Date Requested Status
Michał Sawicz Approve
Review via email: mp+89690@code.launchpad.net

Description of the change

[launcher] Restore the strut on the left when the launcher is on AlwaysVisibleBehavior mode

To post a comment you must log in.
Revision history for this message
Albert Astals Cid (aacid) wrote :
Revision history for this message
Michał Sawicz (saviq) wrote :

* any reason why you do have an onChanged signal for enabled but not for edge?
* looks to me like we can drop the useStrut property altogether?
* I'm thinking the StrutManager could be moved to Shell.qml? and it's the launcherLoader's height / width is what should be used for the strut height / width

review: Needs Fixing
Revision history for this message
Albert Astals Cid (aacid) wrote :

StrutManager moved to Shell.qml, the other two are a non issue as discussed on IRC

Revision history for this message
Michał Sawicz (saviq) :
review: Approve
Revision history for this message
Michał Sawicz (saviq) wrote :

Attempt to merge into lp:~unity-2d-team/unity-2d/unity-2d-shell failed due to conflicts:

text conflict in libunity-2d-private/src/unity2dpanel.cpp

926. By Albert Astals Cid

merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libunity-2d-private/Unity2d/plugin.cpp'
2--- libunity-2d-private/Unity2d/plugin.cpp 2012-01-20 13:42:51 +0000
3+++ libunity-2d-private/Unity2d/plugin.cpp 2012-01-24 15:19:26 +0000
4@@ -73,6 +73,8 @@
5 #include "inputshapemanager.h"
6 #include "inputshaperectangle.h"
7 #include "inputshapemask.h"
8+#include "unity2dpanel.h"
9+#include "strutmanager.h"
10
11 #include <QtDeclarative/qdeclarative.h>
12 #include <QDeclarativeEngine>
13@@ -171,6 +173,9 @@
14 qmlRegisterType<InputShapeRectangle>(uri, 0, 1, "InputShapeRectangle");
15 qmlRegisterType<InputShapeMask>(uri, 0, 1, "InputShapeMask");
16 qmlRegisterType<Unity2DDeclarativeView>();
17+
18+ qmlRegisterType<Unity2dPanel>(uri, 0, 1, "Unity2dPanel");
19+ qmlRegisterType<StrutManager>(uri, 0, 1, "StrutManager");
20 }
21
22 void Unity2dPlugin::initializeEngine(QDeclarativeEngine *engine, const char *uri)
23
24=== modified file 'libunity-2d-private/src/CMakeLists.txt'
25--- libunity-2d-private/src/CMakeLists.txt 2012-01-24 08:38:24 +0000
26+++ libunity-2d-private/src/CMakeLists.txt 2012-01-24 15:19:26 +0000
27@@ -74,6 +74,7 @@
28 inputshapemanager.cpp
29 inputshaperectangle.cpp
30 inputshapemask.cpp
31+ strutmanager.cpp
32 )
33
34 # Build
35
36=== added file 'libunity-2d-private/src/strutmanager.cpp'
37--- libunity-2d-private/src/strutmanager.cpp 1970-01-01 00:00:00 +0000
38+++ libunity-2d-private/src/strutmanager.cpp 2012-01-24 15:19:26 +0000
39@@ -0,0 +1,191 @@
40+/*
41+ * This file is part of unity-2d
42+ *
43+ * Copyright 2010, 2012 Canonical Ltd.
44+ *
45+ * Authors:
46+ * - Aurélien Gâteau <aurelien.gateau@canonical.com>
47+ * - Albert Astals Cid <albert.astals@canonical.com>
48+ *
49+ * This program is free software; you can redistribute it and/or modify
50+ * it under the terms of the GNU General Public License as published
51+ * by the Free Software Foundation; version 3.
52+ *
53+ * This program is distributed in the hope that it will be useful,
54+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
55+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
56+ * GNU General Public License for more details.
57+ *
58+ * You should have received a copy of the GNU General Public License
59+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
60+ */
61+
62+// Self
63+#include "strutmanager.h"
64+
65+// Qt
66+#include <QApplication>
67+#include <QDesktopWidget>
68+#include <QX11Info>
69+
70+// X
71+#include <X11/Xlib.h>
72+#include <X11/Xatom.h>
73+
74+static void setStrut(ulong* struts, WId effectiveWinId)
75+{
76+ static Atom atom = XInternAtom(QX11Info::display(), "_NET_WM_STRUT_PARTIAL", False);
77+ XChangeProperty(QX11Info::display(), effectiveWinId, atom,
78+ XA_CARDINAL, 32, PropModeReplace,
79+ (unsigned char *) struts, 12);
80+}
81+
82+StrutManager::StrutManager()
83+ : m_enabled(true),
84+ m_widget(NULL),
85+ m_edge(Unity2dPanel::TopEdge),
86+ m_width(-1),
87+ m_height(-1)
88+{
89+}
90+
91+StrutManager::~StrutManager()
92+{
93+ if (m_enabled) {
94+ releaseStrut();
95+ }
96+}
97+
98+bool StrutManager::enabled() const
99+{
100+ return m_enabled;
101+}
102+
103+void StrutManager::setEnabled(bool value)
104+{
105+ if (m_enabled != value) {
106+ if (value) {
107+ reserveStrut();
108+ } else {
109+ releaseStrut();
110+ }
111+ m_enabled = value;
112+ Q_EMIT enabledChanged(value);
113+ }
114+}
115+
116+QObject *StrutManager::widget() const
117+{
118+ return m_widget;
119+}
120+
121+void StrutManager::setWidget(QObject *widget)
122+{
123+ m_widget = qobject_cast<QWidget*>(widget);
124+ Q_ASSERT(m_widget != NULL);
125+}
126+
127+Unity2dPanel::Edge StrutManager::edge() const
128+{
129+ return m_edge;
130+}
131+
132+void StrutManager::setEdge(Unity2dPanel::Edge edge)
133+{
134+ m_edge = edge;
135+ updateStrut();
136+}
137+
138+int StrutManager::width() const
139+{
140+ return m_width;
141+}
142+
143+void StrutManager::setWidth(int width)
144+{
145+ m_width = width;
146+}
147+
148+int StrutManager::realWidth() const
149+{
150+ if (m_widget == NULL)
151+ return m_width;
152+
153+ if (m_width == -1)
154+ return m_widget->width();
155+
156+ return m_width;
157+}
158+
159+int StrutManager::height() const
160+{
161+ return m_height;
162+}
163+
164+void StrutManager::setHeight(int height)
165+{
166+ m_height = height;
167+}
168+
169+int StrutManager::realHeight() const
170+{
171+ if (m_widget == NULL)
172+ return m_height;
173+
174+ if (m_height == -1)
175+ return m_widget->height();
176+
177+ return m_height;
178+}
179+
180+void StrutManager::updateStrut()
181+{
182+ if (m_enabled) {
183+ reserveStrut();
184+ }
185+}
186+
187+
188+void StrutManager::reserveStrut()
189+{
190+ if (m_widget == NULL)
191+ return;
192+
193+ QDesktopWidget* desktop = QApplication::desktop();
194+ const QRect screen = desktop->screenGeometry(m_widget);
195+ const QRect available = desktop->availableGeometry(m_widget);
196+
197+ ulong struts[12] = {};
198+ switch (m_edge) {
199+ case Unity2dPanel::LeftEdge:
200+ if (QApplication::isLeftToRight()) {
201+ struts[0] = realWidth();
202+ struts[4] = available.top();
203+ struts[5] = available.y() + available.height();
204+ } else {
205+ struts[1] = realWidth();
206+ struts[6] = available.top();
207+ struts[7] = available.y() + available.height();
208+ }
209+ break;
210+ case Unity2dPanel::TopEdge:
211+ struts[2] = realHeight();
212+ struts[8] = screen.left();
213+ struts[9] = screen.x() + screen.width();
214+ break;
215+ }
216+
217+ setStrut(struts, m_widget->effectiveWinId());
218+}
219+
220+void StrutManager::releaseStrut()
221+{
222+ if (m_widget == NULL)
223+ return;
224+
225+ ulong struts[12];
226+ memset(struts, 0, sizeof struts);
227+ setStrut(struts, m_widget->effectiveWinId());
228+}
229+
230+#include "strutmanager.moc"
231
232=== added file 'libunity-2d-private/src/strutmanager.h'
233--- libunity-2d-private/src/strutmanager.h 1970-01-01 00:00:00 +0000
234+++ libunity-2d-private/src/strutmanager.h 2012-01-24 15:19:26 +0000
235@@ -0,0 +1,92 @@
236+/*
237+ * This file is part of unity-2d
238+ *
239+ * Copyright 2010, 2012 Canonical Ltd.
240+ *
241+ * Authors:
242+ * - Aurélien Gâteau <aurelien.gateau@canonical.com>
243+ * - Albert Astals Cid <albert.astals@canonical.com>
244+ *
245+ * This program is free software; you can redistribute it and/or modify
246+ * it under the terms of the GNU General Public License as published
247+ * by the Free Software Foundation; version 3.
248+ *
249+ * This program is distributed in the hope that it will be useful,
250+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
251+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
252+ * GNU General Public License for more details.
253+ *
254+ * You should have received a copy of the GNU General Public License
255+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
256+ */
257+
258+#ifndef STRUTMANAGER_H
259+#define STRUTMANAGER_H
260+
261+// Unity 2D
262+#include "unity2dpanel.h"
263+
264+class StrutManager : public QObject
265+{
266+ Q_OBJECT
267+ Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
268+ Q_PROPERTY(QObject* widget READ widget WRITE setWidget)
269+ Q_PROPERTY(Unity2dPanel::Edge edge READ edge WRITE setEdge)
270+ Q_PROPERTY(int width READ width WRITE setWidth)
271+ Q_PROPERTY(int height READ height WRITE setHeight)
272+
273+public:
274+ StrutManager();
275+ ~StrutManager();
276+
277+ bool enabled() const;
278+ void setEnabled(bool value);
279+
280+ // QObject due to QML constraints
281+ QObject *widget() const;
282+ void setWidget(QObject *widget);
283+
284+ Unity2dPanel::Edge edge() const;
285+ void setEdge(Unity2dPanel::Edge edge);
286+
287+ /**
288+ * Returns the width set to the strut manager
289+ * If is -1 (the default value) will use the width of the widget given in setWidget
290+ */
291+ int width() const;
292+ void setWidth(int width);
293+ /**
294+ * Returns the actual width in use by the strut manager
295+ * It is either width() or m_widget->width()
296+ */
297+ int realWidth() const;
298+
299+ /**
300+ * Returns the height set to the strut manager
301+ * If is -1 (the default value) will use the height of the widget given in setWidget
302+ */
303+ int height() const;
304+ void setHeight(int height);
305+ /**
306+ * Returns the actual height in use by the strut manager
307+ * It is either width() or m_widget->width()
308+ */
309+ int realHeight() const;
310+
311+ Q_INVOKABLE void updateStrut();
312+
313+Q_SIGNALS:
314+ void enabledChanged(bool enabled);
315+
316+private:
317+ void reserveStrut();
318+ void releaseStrut();
319+
320+ bool m_enabled;
321+ QWidget *m_widget;
322+ Unity2dPanel::Edge m_edge;
323+ int m_width;
324+ int m_height;
325+};
326+
327+#endif /* STRUTMANAGER_H */
328\ No newline at end of file
329
330=== modified file 'libunity-2d-private/src/unity2dpanel.cpp'
331--- libunity-2d-private/src/unity2dpanel.cpp 2012-01-24 12:58:01 +0000
332+++ libunity-2d-private/src/unity2dpanel.cpp 2012-01-24 15:19:26 +0000
333@@ -21,6 +21,7 @@
334
335 // Self
336 #include "unity2dpanel.h"
337+#include "strutmanager.h"
338 #include <debug_p.h>
339 #include <indicatorsmanager.h>
340
341@@ -32,10 +33,6 @@
342 #include <QHBoxLayout>
343 #include <QX11Info>
344
345-// X
346-#include <X11/Xlib.h>
347-#include <X11/Xatom.h>
348-
349 static const int SLIDE_DURATION = 125;
350
351 struct Unity2dPanelPrivate
352@@ -44,53 +41,9 @@
353 Unity2dPanel::Edge m_edge;
354 mutable IndicatorsManager* m_indicatorsManager;
355 QHBoxLayout* m_layout;
356- bool m_useStrut;
357 int m_delta;
358 bool m_manualSliding;
359-
360- void setStrut(ulong* struts)
361- {
362- static Atom atom = XInternAtom(QX11Info::display(), "_NET_WM_STRUT_PARTIAL", False);
363- XChangeProperty(QX11Info::display(), q->effectiveWinId(), atom,
364- XA_CARDINAL, 32, PropModeReplace,
365- (unsigned char *) struts, 12);
366- }
367-
368- void reserveStrut()
369- {
370- QDesktopWidget* desktop = QApplication::desktop();
371- const QRect screen = desktop->screenGeometry(q);
372- const QRect available = desktop->availableGeometry(q);
373-
374- ulong struts[12] = {};
375- switch (m_edge) {
376- case Unity2dPanel::LeftEdge:
377- if (QApplication::isLeftToRight()) {
378- struts[0] = q->width();
379- struts[4] = available.top();
380- struts[5] = available.y() + available.height();
381- } else {
382- struts[1] = q->width();
383- struts[6] = available.top();
384- struts[7] = available.y() + available.height();
385- }
386- break;
387- case Unity2dPanel::TopEdge:
388- struts[2] = q->height();
389- struts[8] = screen.left();
390- struts[9] = screen.x() + screen.width();
391- break;
392- }
393-
394- setStrut(struts);
395- }
396-
397- void releaseStrut()
398- {
399- ulong struts[12];
400- memset(struts, 0, sizeof struts);
401- setStrut(struts);
402- }
403+ StrutManager m_strutManager;
404
405 void updateGeometry()
406 {
407@@ -134,9 +87,7 @@
408
409 void updateEdge()
410 {
411- if (m_useStrut) {
412- reserveStrut();
413- }
414+ m_strutManager.updateStrut();
415 updateGeometry();
416 updateLayoutDirection();
417 }
418@@ -146,10 +97,11 @@
419 : QWidget(parent)
420 , d(new Unity2dPanelPrivate)
421 {
422+ d->m_strutManager.setWidget(this);
423+ d->m_strutManager.setEdge(Unity2dPanel::TopEdge);
424 d->q = this;
425 d->m_edge = Unity2dPanel::TopEdge;
426 d->m_indicatorsManager = 0;
427- d->m_useStrut = true;
428 d->m_delta = 0;
429 d->m_manualSliding = false;
430 d->m_layout = new QHBoxLayout(this);
431@@ -166,19 +118,18 @@
432 }
433
434 connect(QApplication::desktop(), SIGNAL(workAreaResized(int)), SLOT(slotWorkAreaResized(int)));
435+ connect(&d->m_strutManager, SIGNAL(enabledChanged(bool)), SIGNAL(useStrutChanged(bool)));
436 }
437
438 Unity2dPanel::~Unity2dPanel()
439 {
440- if (d->m_useStrut) {
441- d->releaseStrut();
442- }
443 delete d;
444 }
445
446 void Unity2dPanel::setEdge(Unity2dPanel::Edge edge)
447 {
448 d->m_edge = edge;
449+ d->m_strutManager.setEdge(edge);
450 if (isVisible()) {
451 d->updateEdge();
452 }
453@@ -232,20 +183,12 @@
454
455 bool Unity2dPanel::useStrut() const
456 {
457- return d->m_useStrut;
458+ return d->m_strutManager.enabled();
459 }
460
461 void Unity2dPanel::setUseStrut(bool value)
462 {
463- if (d->m_useStrut != value) {
464- if (value) {
465- d->reserveStrut();
466- } else {
467- d->releaseStrut();
468- }
469- d->m_useStrut = value;
470- Q_EMIT useStrutChanged(value);
471- }
472+ d->m_strutManager.setEnabled(value);
473 }
474
475 int Unity2dPanel::delta() const
476
477=== modified file 'libunity-2d-private/src/unity2dpanel.h'
478--- libunity-2d-private/src/unity2dpanel.h 2012-01-24 12:58:01 +0000
479+++ libunity-2d-private/src/unity2dpanel.h 2012-01-24 15:19:26 +0000
480@@ -45,6 +45,7 @@
481 */
482 Q_PROPERTY(int manualSliding READ manualSliding WRITE setManualSliding NOTIFY manualSlidingChanged)
483 Q_PROPERTY(bool useStrut READ useStrut WRITE setUseStrut NOTIFY useStrutChanged)
484+ Q_ENUMS(Edge)
485
486 public:
487 enum Edge {
488
489=== modified file 'shell/Shell.qml'
490--- shell/Shell.qml 2012-01-19 15:07:09 +0000
491+++ shell/Shell.qml 2012-01-24 15:19:26 +0000
492@@ -19,6 +19,7 @@
493 import QtQuick 1.1
494 import Unity2d 1.0
495 import "launcher"
496+import "common/utils.js" as Utils
497
498 Item {
499 id: shell
500@@ -140,4 +141,17 @@
501 }
502 }
503 }
504+
505+ StrutManager {
506+ id: strutManager
507+ edge: Unity2dPanel.LeftEdge
508+ widget: declarativeView
509+ height: launcherLoader.height
510+ width: launcherLoader.width
511+ enabled: Utils.clamp(launcher2dConfiguration.hideMode, 0, 2) == 0
512+
513+ Component.onCompleted: {
514+ strutManager.updateStrut()
515+ }
516+ }
517 }
518
519=== modified file 'shell/launcher/LauncherLoader.qml'
520--- shell/launcher/LauncherLoader.qml 2012-01-19 08:17:06 +0000
521+++ shell/launcher/LauncherLoader.qml 2012-01-24 15:19:26 +0000
522@@ -1,4 +1,5 @@
523 import QtQuick 1.0
524+import Unity2d 1.0
525 import "../common"
526 import "../common/utils.js" as Utils
527

Subscribers

People subscribed via source and target branches