Merge lp:~osomon/unity-2d/offscreenQuicklists into lp:unity-2d/3.0

Proposed by Olivier Tilloy
Status: Merged
Approved by: Aurélien Gâteau
Approved revision: 426
Merged at revision: 424
Proposed branch: lp:~osomon/unity-2d/offscreenQuicklists
Merge into: lp:unity-2d/3.0
Diff against target: 164 lines (+61/-8)
3 files modified
launcher/UnityApplications/launchermenu.cpp (+49/-6)
launcher/UnityApplications/launchermenu.h (+10/-0)
launcher/launchermenu.css (+2/-2)
To merge this branch: bzr merge lp:~osomon/unity-2d/offscreenQuicklists
Reviewer Review Type Date Requested Status
Aurélien Gâteau (community) Approve
Review via email: mp+52064@code.launchpad.net

Commit message

[launcher] Adjust the position of quicklists so that they never get offscreen.

Description of the change

Note to the reviewer: when testing quicklists, there are two different code paths to test: compositing enabled and compositing disabled. With metacity, it’s simply a matter of changing the value of the GConf key at /apps/metacity/general/compositing_manager.

Also note that the launcher is not aware of live changes (it doesn’t get notified if the window manager suddenly decides to support compositing, this is a known issue documented in the code), so it needs to be restarted to test those two code paths.

To post a comment you must log in.
Revision history for this message
Aurélien Gâteau (agateau) wrote :

# Functional

Works well, except for a tiny bug in composited mode: the arrow and the tooltip seems to overlap. This screenshot should make it clearer.

http://wstaw.org/m/2011/03/03/unity-2d-launcher-tooltip_.png

I think this can be fixed by calling painter.setCompositionMode(QPainter::Source) before painting the arrow.

# Code

You can make m_arrow a QPixmap instead of a QPixmap*. It is not QObject-based and is implicitly shared so it is more common to use QPixmaps as values.

Instead of adding the m_maskNeedsUpdate, would it be possible to simply call updateMask() in setFolded()? That would simplify the code a bit.

review: Needs Fixing
424. By Olivier Tilloy

Paint the arrow over the quicklist, don’t blend pixels.

425. By Olivier Tilloy

Make m_arrow a QPixmap instead of a QPixmap*.

426. By Olivier Tilloy

Directly update the mask when the menu has moved.

Revision history for this message
Olivier Tilloy (osomon) wrote :

Thanks for the review, the very valid points you raised and the suggestions.
They were all addressed/applied.

Revision history for this message
Aurélien Gâteau (agateau) wrote :

Looks good now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'launcher/UnityApplications/launchermenu.cpp'
2--- launcher/UnityApplications/launchermenu.cpp 2011-02-09 16:41:19 +0000
3+++ launcher/UnityApplications/launchermenu.cpp 2011-03-03 15:21:31 +0000
4@@ -27,6 +27,8 @@
5 #include <QResizeEvent>
6 #include <QBitmap>
7 #include <QX11Info>
8+#include <QDesktopWidget>
9+#include <QPainter>
10
11 LauncherContextualMenu::LauncherContextualMenu():
12 QMenu(0), m_folded(true), m_launcherItem(NULL), m_titleAction(NULL)
13@@ -54,6 +56,14 @@
14 /* Custom appearance. */
15 loadCSS();
16
17+ /* Load the pixmap for the arrow. It is drawn separately as its position
18+ may vary depending on the position of the menu on the screen. */
19+ if (transparencyAvailable()) {
20+ m_arrow.load("artwork:tooltip/arrow.png");
21+ } else {
22+ m_arrow.load("artwork:tooltip/arrow_no_transparency.png");
23+ }
24+
25 /* First action used to display the title of the item */
26 m_titleAction = new QAction(this);
27 m_titleAction->setEnabled(false);
28@@ -95,17 +105,22 @@
29 }
30
31 void
32+LauncherContextualMenu::updateMask()
33+{
34+ QPixmap pixmap(size());
35+ render(&pixmap, QPoint(), QRegion(),
36+ QWidget::DrawWindowBackground | QWidget::DrawChildren | QWidget::IgnoreMask);
37+ setMask(pixmap.createMaskFromColor("red"));
38+}
39+
40+void
41 LauncherContextualMenu::resizeEvent(QResizeEvent* event)
42 {
43+ QMenu::resizeEvent(event);
44 /* If transparent windows are not available use the XShape extension */
45 if (!transparencyAvailable()) {
46- QPixmap pixmap(event->size());
47- render(&pixmap, QPoint(), QRegion(),
48- QWidget::DrawWindowBackground | QWidget::DrawChildren | QWidget::IgnoreMask);
49- setMask(pixmap.createMaskFromColor("red"));
50+ updateMask();
51 }
52-
53- QMenu::resizeEvent(event);
54 }
55
56 bool
57@@ -138,6 +153,7 @@
58 if (isVisible())
59 return;
60
61+ m_arrowY = 6;
62 move(x, y - minimumSize().height() / 2);
63 QMenu::show();
64 }
65@@ -183,6 +199,22 @@
66 } else {
67 addSeparator();
68 m_launcherItem->createMenuActions();
69+
70+ QRect screenGeometry = QApplication::desktop()->screenGeometry(this);
71+ if (height() <= screenGeometry.height()) {
72+ /* Adjust the position of the menu only if it fits entirely on the screen. */
73+ int menuBottomEdge = y() + height();
74+ int screenBottomEdge = screenGeometry.y() + screenGeometry.height();
75+ if (menuBottomEdge > screenBottomEdge) {
76+ /* The menu goes offscreen, shift it upwards. */
77+ m_arrowY += menuBottomEdge - screenBottomEdge;
78+ move(x(), screenBottomEdge - height());
79+ if (!transparencyAvailable()) {
80+ /* The arrow has moved relatively to the menu. */
81+ updateMask();
82+ }
83+ }
84+ }
85 }
86
87 m_folded = folded;
88@@ -190,6 +222,17 @@
89 emit foldedChanged(m_folded);
90 }
91
92+void
93+LauncherContextualMenu::paintEvent(QPaintEvent* event)
94+{
95+ QMenu::paintEvent(event);
96+
97+ /* Draw the arrow. */
98+ QPainter painter(this);
99+ painter.setCompositionMode(QPainter::CompositionMode_Source);
100+ painter.drawPixmap(0, m_arrowY, m_arrow);
101+}
102+
103 LauncherItem*
104 LauncherContextualMenu::launcherItem() const
105 {
106
107=== modified file 'launcher/UnityApplications/launchermenu.h'
108--- launcher/UnityApplications/launchermenu.h 2010-12-01 13:10:57 +0000
109+++ launcher/UnityApplications/launchermenu.h 2011-03-03 15:21:31 +0000
110@@ -22,6 +22,7 @@
111
112 #include <QMenu>
113 #include <QTimer>
114+#include <QPixmap>
115
116 class LauncherItem;
117
118@@ -59,6 +60,9 @@
119 void foldedChanged(bool);
120 void titleChanged(QString);
121
122+protected:
123+ void paintEvent(QPaintEvent* event);
124+
125 private:
126 void loadCSS();
127 QTimer m_hidingDelayTimer;
128@@ -66,6 +70,12 @@
129 LauncherItem* m_launcherItem;
130 QString m_title;
131 QAction* m_titleAction;
132+
133+ QPixmap m_arrow;
134+ int m_arrowY;
135+
136+private Q_SLOTS:
137+ void updateMask();
138 };
139
140 #endif // LAUNCHERMENU_H
141
142=== added file 'launcher/artwork/tooltip/arrow.png'
143Binary files launcher/artwork/tooltip/arrow.png 1970-01-01 00:00:00 +0000 and launcher/artwork/tooltip/arrow.png 2011-03-03 15:21:31 +0000 differ
144=== added file 'launcher/artwork/tooltip/arrow_no_transparency.png'
145Binary files launcher/artwork/tooltip/arrow_no_transparency.png 1970-01-01 00:00:00 +0000 and launcher/artwork/tooltip/arrow_no_transparency.png 2011-03-03 15:21:31 +0000 differ
146=== modified file 'launcher/artwork/tooltip/background.png'
147Binary files launcher/artwork/tooltip/background.png 2010-11-29 02:42:22 +0000 and launcher/artwork/tooltip/background.png 2011-03-03 15:21:31 +0000 differ
148=== modified file 'launcher/artwork/tooltip/background_no_transparency.png'
149Binary files launcher/artwork/tooltip/background_no_transparency.png 2010-11-29 02:42:22 +0000 and launcher/artwork/tooltip/background_no_transparency.png 2011-03-03 15:21:31 +0000 differ
150=== modified file 'launcher/launchermenu.css'
151--- launcher/launchermenu.css 2010-11-29 04:36:02 +0000
152+++ launcher/launchermenu.css 2011-03-03 15:21:31 +0000
153@@ -26,11 +26,11 @@
154 }
155
156 QMenu[transparencyAvailable=true] {
157- border-image: url(artwork:tooltip/background.png) 24px 5px 4px 15px Repeat Repeat;
158+ border-image: url(artwork:tooltip/background.png) 5px 5px 4px 15px Repeat Repeat;
159 }
160
161 QMenu[transparencyAvailable=false] {
162- border-image: url(artwork:tooltip/background_no_transparency.png) 24px 5px 4px 15px Repeat Repeat;
163+ border-image: url(artwork:tooltip/background_no_transparency.png) 5px 5px 4px 15px Repeat Repeat;
164 }
165
166

Subscribers

People subscribed via source and target branches