Merge lp:~brandontschaefer/unity/lp.1101310-window-buttons-fix into lp:unity

Proposed by Brandon Schaefer
Status: Merged
Approved by: Thomi Richards
Approved revision: no longer in the source branch.
Merged at revision: 3081
Proposed branch: lp:~brandontschaefer/unity/lp.1101310-window-buttons-fix
Merge into: lp:unity
Diff against target: 500 lines (+202/-24)
16 files modified
dash/CMakeLists.txt (+1/-1)
dash/DashView.cpp (+17/-9)
dash/DashView.h (+12/-7)
hud/CMakeLists.txt (+1/-1)
hud/HudView.cpp (+6/-0)
hud/HudView.h (+3/-0)
panel/CMakeLists.txt (+0/-1)
panel/PanelMenuView.cpp (+2/-1)
panel/PanelMenuView.h (+1/-1)
panel/PanelView.cpp (+2/-1)
tests/autopilot/unity/tests/test_panel.py (+16/-0)
tests/test_hud_view.cpp (+2/-0)
tests/test_window_buttons.cpp (+2/-2)
unity-shared/CMakeLists.txt (+2/-0)
unity-shared/OverlayWindowButtons.cpp (+81/-0)
unity-shared/OverlayWindowButtons.h (+54/-0)
To merge this branch: bzr merge lp:~brandontschaefer/unity/lp.1101310-window-buttons-fix
Reviewer Review Type Date Requested Status
Thomi Richards (community) quality Approve
Andrea Azzarone (community) Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+145284@code.launchpad.net

Commit message

Created a class OverlayWindowButtons which will sit in the DashView/HudView
  to handle mouse events for the window buttons.
TODO: We need to refactor the PanelMenuView to extract window button logic
  (dealing with overlays).

Description of the change

=== Problem ===

When the launcher icons were resized the dash view would take up that extra space. The problem with this is the panel height is part of the dash view. So part of the window buttons are under the dash view which means no mouse events get to them. Meaning they no longer work :).

=== Fix ===

So to start, we can't fix this by telling the dash view to ignore the panel because the preview needs to draw over them. This means the dash view must be over the panel.

So the new fix, is to have the DashView/HudView hold the OverlayWindowButtons, which can now tell it to the area that is under the mouse. Making the buttons work again (yay!).

=== Test ===

There is an AP test

To post a comment you must log in.
Revision history for this message
Andrea Azzarone (azzar1) wrote :

346 +const int MAIN_LEFT_PADDING = 4;
347 +const int MENUBAR_PADDING = 4;

Put them in an unnamed namespace (or just declare them static, but static is so C :)

387 +nux::Area* OverlayWindowButtons::FindAreaUnderMouse(nux::Point const& mouse_position,
388 + nux::NuxEventType event_type)

Please fix the indentation here.

Revision history for this message
Andrea Azzarone (azzar1) wrote :

LGTM now.

review: Approve
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) :
review: Approve (quality)
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

It's ok for fixing the issue... I'm waiting for the next branch that will cleanup the WindowButtons having an abstract form to share the logic and different implementations for Panel and Overlays ;)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'dash/CMakeLists.txt'
2--- dash/CMakeLists.txt 2012-12-19 20:53:12 +0000
3+++ dash/CMakeLists.txt 2013-01-29 01:28:23 +0000
4@@ -56,4 +56,4 @@
5 # Standalone variant
6 #
7 add_executable (dash StandaloneDash.cpp)
8-target_link_libraries (dash dash-lib unity-shared)
9+target_link_libraries (dash dash-lib unity-shared unity-shared-standalone)
10
11=== modified file 'dash/DashView.cpp'
12--- dash/DashView.cpp 2013-01-15 21:53:55 +0000
13+++ dash/DashView.cpp 2013-01-29 01:28:23 +0000
14@@ -20,6 +20,7 @@
15
16 #include "DashView.h"
17 #include "DashViewPrivate.h"
18+#include "FilterExpanderLabel.h"
19
20 #include <math.h>
21
22@@ -31,13 +32,12 @@
23 #include <UnityCore/GLibWrapper.h>
24 #include <UnityCore/RadioOptionFilter.h>
25
26-#include "FilterExpanderLabel.h"
27 #include "unity-shared/DashStyle.h"
28 #include "unity-shared/KeyboardUtil.h"
29-#include "unity-shared/UnitySettings.h"
30-#include "unity-shared/UBusMessages.h"
31 #include "unity-shared/PreviewStyle.h"
32 #include "unity-shared/PanelStyle.h"
33+#include "unity-shared/UBusMessages.h"
34+#include "unity-shared/UnitySettings.h"
35
36 namespace unity
37 {
38@@ -126,6 +126,7 @@
39 , animate_split_value_(0.0)
40 , animate_preview_container_value_(0.0)
41 , animate_preview_value_(0.0)
42+ , overlay_window_buttons_(new OverlayWindowButtons())
43 {
44 renderer_.SetOwner(this);
45 renderer_.need_redraw.connect([this] () {
46@@ -493,6 +494,8 @@
47 ClosePreview();
48 }
49
50+ overlay_window_buttons_->Show();
51+
52 renderer_.AboutToShow();
53 }
54
55@@ -520,6 +523,8 @@
56 {
57 ClosePreview();
58 }
59+
60+ overlay_window_buttons_->Hide();
61 }
62
63 void DashView::SetupViews()
64@@ -728,6 +733,8 @@
65 nux::GetPainter().PopBackgroundStack();
66 }
67
68+ overlay_window_buttons_->QueueDraw();
69+
70 graphics_engine.PopClippingRectangle();
71
72 renderer_.DrawInnerCleanup(graphics_engine, content_geo_, renderer_geo_abs, renderer_geo);
73@@ -1089,11 +1096,6 @@
74 geo.width += style.GetDashRightTileWidth();
75 geo.height += style.GetDashBottomTileHeight();
76 }
77-
78- if (!geo.IsPointInside(x, y))
79- {
80- ubus_manager_.SendMessage(UBUS_PLACE_VIEW_CLOSE_REQUEST);
81- }
82 }
83
84 void DashView::OnActivateRequest(GVariant* args)
85@@ -1518,6 +1520,7 @@
86 wrapper.add("right-border-width", style.GetDashRightTileWidth());
87 wrapper.add("bottom-border-height", style.GetDashBottomTileHeight());
88 wrapper.add("preview_displaying", preview_displaying_);
89+ wrapper.add("dash_maximized", style.always_maximised());
90 }
91
92 nux::Area* DashView::KeyNavIteration(nux::KeyNavDirection direction)
93@@ -1719,7 +1722,12 @@
94 nux::Area* DashView::FindAreaUnderMouse(const nux::Point& mouse_position, nux::NuxEventType event_type)
95 {
96 nux::Area* view = nullptr;
97- if (preview_displaying_)
98+
99+ if (overlay_window_buttons_->GetGeometry().IsInside(mouse_position))
100+ {
101+ return overlay_window_buttons_->FindAreaUnderMouse(mouse_position, event_type);
102+ }
103+ else if (preview_displaying_)
104 {
105 nux::Point newpos = mouse_position;
106 view = dynamic_cast<nux::Area*>(preview_container_.GetPointer())->FindAreaUnderMouse(newpos, event_type);
107
108=== modified file 'dash/DashView.h'
109--- dash/DashView.h 2012-12-17 09:28:31 +0000
110+++ dash/DashView.h 2013-01-29 01:28:23 +0000
111@@ -28,17 +28,20 @@
112 #include <UnityCore/HomeLens.h>
113 #include <UnityCore/GLibSource.h>
114
115-#include "unity-shared/BackgroundEffectHelper.h"
116-#include "unity-shared/SearchBar.h"
117-#include "unity-shared/Introspectable.h"
118-#include "unity-shared/BGHash.h"
119 #include "LensBar.h"
120 #include "LensView.h"
121-#include "unity-shared/UBusWrapper.h"
122-#include "unity-shared/OverlayRenderer.h"
123-#include "UnityCore/Preview.h"
124 #include "previews/PreviewContainer.h"
125 #include "PreviewStateMachine.h"
126+#include "UnityCore/Preview.h"
127+
128+#include "unity-shared/BackgroundEffectHelper.h"
129+#include "unity-shared/BGHash.h"
130+#include "unity-shared/Introspectable.h"
131+#include "unity-shared/OverlayRenderer.h"
132+#include "unity-shared/SearchBar.h"
133+#include "unity-shared/UBusWrapper.h"
134+#include "unity-shared/OverlayWindowButtons.h"
135+
136
137 namespace na = nux::animation;
138
139@@ -185,6 +188,8 @@
140
141 std::unique_ptr<na::AnimateValue<float>> preview_animation_;
142 float animate_preview_value_;
143+
144+ nux::ObjectPtr<OverlayWindowButtons> overlay_window_buttons_;
145 };
146
147
148
149=== modified file 'hud/CMakeLists.txt'
150--- hud/CMakeLists.txt 2012-12-19 20:53:12 +0000
151+++ hud/CMakeLists.txt 2013-01-29 01:28:23 +0000
152@@ -34,4 +34,4 @@
153 # Standalone variant
154 #
155 add_executable (hud StandaloneHud.cpp)
156-target_link_libraries (hud hud-lib unity-shared)
157+target_link_libraries (hud hud-lib unity-shared unity-shared-standalone)
158
159=== modified file 'hud/HudView.cpp'
160--- hud/HudView.cpp 2013-01-09 13:17:04 +0000
161+++ hud/HudView.cpp 2013-01-29 01:28:23 +0000
162@@ -67,6 +67,7 @@
163 , selected_button_(0)
164 , show_embedded_icon_(true)
165 , keyboard_stole_focus_(false)
166+ , overlay_window_buttons_(new OverlayWindowButtons())
167 {
168 renderer_.SetOwner(this);
169 renderer_.need_redraw.connect([this] () {
170@@ -345,12 +346,14 @@
171 void View::AboutToShow()
172 {
173 visible_ = true;
174+ overlay_window_buttons_->Show();
175 renderer_.AboutToShow();
176 }
177
178 void View::AboutToHide()
179 {
180 visible_ = false;
181+ overlay_window_buttons_->Hide();
182 renderer_.AboutToHide();
183 }
184
185@@ -484,6 +487,9 @@
186 {
187 GetLayout()->ProcessDraw(gfx_context, force_draw);
188 }
189+
190+ overlay_window_buttons_->QueueDraw();
191+
192 gfx_context.PopClippingRectangle();
193
194 renderer_.DrawInnerCleanup(gfx_context, draw_content_geo, GetAbsoluteGeometry(), GetGeometry());
195
196=== modified file 'hud/HudView.h'
197--- hud/HudView.h 2012-11-28 14:23:01 +0000
198+++ hud/HudView.h 2013-01-29 01:28:23 +0000
199@@ -29,6 +29,7 @@
200 #include "HudButton.h"
201 #include "HudAbstractView.h"
202 #include "unity-shared/OverlayRenderer.h"
203+#include "unity-shared/OverlayWindowButtons.h"
204 #include "unity-shared/SearchBar.h"
205 #include "unity-shared/UBusWrapper.h"
206
207@@ -121,6 +122,8 @@
208 bool show_embedded_icon_;
209 bool activated_signal_sent_;
210 bool keyboard_stole_focus_;
211+
212+ nux::ObjectPtr<OverlayWindowButtons> overlay_window_buttons_;
213 };
214
215
216
217=== modified file 'panel/CMakeLists.txt'
218--- panel/CMakeLists.txt 2012-12-19 20:53:12 +0000
219+++ panel/CMakeLists.txt 2013-01-29 01:28:23 +0000
220@@ -24,7 +24,6 @@
221 PanelTitlebarGrabAreaView.cpp
222 PanelTray.cpp
223 PanelView.cpp
224- WindowButtons.cpp
225 )
226
227 add_library (panel-lib STATIC ${PANEL_SOURCES})
228
229=== modified file 'panel/PanelMenuView.cpp'
230--- panel/PanelMenuView.cpp 2013-01-09 14:16:07 +0000
231+++ panel/PanelMenuView.cpp 2013-01-29 01:28:23 +0000
232@@ -356,8 +356,9 @@
233 WindowManager& wm = WindowManager::Default();
234 bool screen_grabbed = (wm.IsExpoActive() || wm.IsScaleActive());
235
236+ // TODO: We need to refactor this code to extract the window button logic
237 if (overlay_showing_)
238- return true;
239+ return false;
240
241 if (we_control_active_ && is_maximized_ && !screen_grabbed &&
242 !launcher_keynav_ && !switcher_showing_)
243
244=== modified file 'panel/PanelMenuView.h'
245--- panel/PanelMenuView.h 2012-12-12 18:07:08 +0000
246+++ panel/PanelMenuView.h 2013-01-29 01:28:23 +0000
247@@ -28,7 +28,7 @@
248
249 #include "PanelIndicatorsView.h"
250 #include "unity-shared/StaticCairoText.h"
251-#include "WindowButtons.h"
252+#include "unity-shared/WindowButtons.h"
253 #include "PanelTitlebarGrabAreaView.h"
254 #include "unity-shared/UBusWrapper.h"
255
256
257=== modified file 'panel/PanelView.cpp'
258--- panel/PanelView.cpp 2012-12-17 19:35:34 +0000
259+++ panel/PanelView.cpp 2013-01-29 01:28:23 +0000
260@@ -636,7 +636,8 @@
261 tracked_pointer_pos_ = {-1, -1};
262 }
263
264- ubus_manager_.SendMessage(UBUS_PLACE_VIEW_CLOSE_REQUEST);
265+ if (overlay_is_open_)
266+ ubus_manager_.SendMessage(UBUS_PLACE_VIEW_CLOSE_REQUEST);
267 }
268
269 void PanelView::OnEntryShowMenu(std::string const& entry_id, unsigned xid,
270
271=== modified file 'tests/autopilot/unity/tests/test_panel.py'
272--- tests/autopilot/unity/tests/test_panel.py 2013-01-25 09:49:47 +0000
273+++ tests/autopilot/unity/tests/test_panel.py 2013-01-29 01:28:23 +0000
274@@ -298,6 +298,22 @@
275 self.assertThat(self.panel.window_buttons_shown, Eventually(Equals(True)))
276 self.assertWinButtonsInOverlayMode(True)
277
278+ def test_window_buttons_work_in_dash_after_launcher_resize(self):
279+ """When the launcher icons are resized, the window
280+ buttons must still work in the dash."""
281+
282+ self.set_unity_option("icon_size", 25)
283+ self.dash.ensure_visible()
284+ self.addCleanup(self.dash.ensure_hidden)
285+
286+ desired_max = not self.dash.view.dash_maximized
287+ if desired_max:
288+ self.panel.window_buttons.maximize.mouse_click()
289+ else:
290+ self.panel.window_buttons.unmaximize.mouse_click()
291+
292+ self.assertThat(self.dash.view.dash_maximized, Eventually(Equals(desired_max)))
293+
294 def test_window_buttons_show_with_hud(self):
295 """Window buttons must be shown when the HUD is open."""
296 self.hud.ensure_visible()
297
298=== modified file 'tests/test_hud_view.cpp'
299--- tests/test_hud_view.cpp 2012-06-04 23:03:32 +0000
300+++ tests/test_hud_view.cpp 2013-01-29 01:28:23 +0000
301@@ -30,6 +30,7 @@
302
303 #include "hud/HudView.h"
304 #include "unity-shared/DashStyle.h"
305+#include "unity-shared/PanelStyle.h"
306 #include "unity-shared/UnitySettings.h"
307 using namespace unity;
308
309@@ -40,6 +41,7 @@
310 {
311 Settings unity_settings;
312 dash::Style dash_style;
313+ panel::Style panel_style;
314 nux::ObjectPtr<hud::View> view(new hud::View());
315
316 hud::Hud::Queries queries;
317
318=== modified file 'tests/test_window_buttons.cpp'
319--- tests/test_window_buttons.cpp 2012-12-14 17:19:44 +0000
320+++ tests/test_window_buttons.cpp 2013-01-29 01:28:23 +0000
321@@ -24,8 +24,8 @@
322 #include "PanelStyle.h"
323 #include "StandaloneWindowManager.h"
324 #include "UnitySettings.h"
325-#include "WindowButtons.h"
326-#include "WindowButtonPriv.h"
327+#include "unity-shared/WindowButtons.h"
328+#include "unity-shared/WindowButtonPriv.h"
329
330 namespace unity
331 {
332
333=== modified file 'unity-shared/CMakeLists.txt'
334--- unity-shared/CMakeLists.txt 2012-12-19 20:53:12 +0000
335+++ unity-shared/CMakeLists.txt 2013-01-29 01:28:23 +0000
336@@ -39,6 +39,7 @@
337 LayoutSystem.cpp
338 LineSeparator.cpp
339 OverlayRenderer.cpp
340+ OverlayWindowButtons.cpp
341 PanelStyle.cpp
342 PlacesVScrollBar.cpp
343 PlacesOverlayVScrollBar.cpp
344@@ -61,6 +62,7 @@
345 UnityWindowView.cpp
346 UserThumbnailProvider.cpp
347 VScrollBarOverlayWindow.cpp
348+ WindowButtons.cpp
349 WindowManager.cpp
350 XPathQueryPart.cpp
351 )
352
353=== added file 'unity-shared/OverlayWindowButtons.cpp'
354--- unity-shared/OverlayWindowButtons.cpp 1970-01-01 00:00:00 +0000
355+++ unity-shared/OverlayWindowButtons.cpp 2013-01-29 01:28:23 +0000
356@@ -0,0 +1,81 @@
357+/*
358+ * Copyright (C) 2013 Canonical Ltd
359+ *
360+ * This program is free software: you can redistribute it and/or modify
361+ * it under the terms of the GNU General Public License version 3 as
362+ * published by the Free Software Foundation.
363+ *
364+ * This program is distributed in the hope that it will be useful,
365+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
366+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
367+ * GNU General Public License for more details.
368+ *
369+ * You should have received a copy of the GNU General Public License
370+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
371+ *
372+ * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com>
373+ *
374+ */
375+
376+#include "OverlayWindowButtons.h"
377+#include "PanelStyle.h"
378+#include "UScreen.h"
379+
380+namespace
381+{
382+ const int MAIN_LEFT_PADDING = 4;
383+ const int MENUBAR_PADDING = 4;
384+}
385+
386+namespace unity
387+{
388+
389+NUX_IMPLEMENT_OBJECT_TYPE(OverlayWindowButtons);
390+
391+OverlayWindowButtons::OverlayWindowButtons()
392+ : nux::BaseWindow("OverlayWindowButtons")
393+ , window_buttons_(new WindowButtons())
394+{
395+ UpdateGeometry();
396+ SetBackgroundColor(nux::color::Transparent);
397+}
398+
399+void OverlayWindowButtons::UpdateGeometry()
400+{
401+ int monitor = unity::UScreen::GetDefault()->GetMonitorWithMouse();
402+ nux::Geometry const& geo = unity::UScreen::GetDefault()->GetMonitorGeometry(monitor);
403+
404+ SetX(geo.x + MAIN_LEFT_PADDING);
405+ SetY(geo.y + MENUBAR_PADDING);
406+ SetHeight(panel::Style::Instance().panel_height);
407+
408+ window_buttons_->monitor = monitor;
409+}
410+
411+void OverlayWindowButtons::Show()
412+{
413+ UpdateGeometry();
414+ ShowWindow(true);
415+ PushToFront();
416+ QueueDraw();
417+}
418+
419+void OverlayWindowButtons::Hide()
420+{
421+ ShowWindow(false);
422+ PushToBack();
423+ QueueDraw();
424+}
425+
426+nux::Area* OverlayWindowButtons::FindAreaUnderMouse(nux::Point const& mouse_position,
427+ nux::NuxEventType event_type)
428+{
429+ return window_buttons_->FindAreaUnderMouse(mouse_position, event_type);
430+}
431+
432+void OverlayWindowButtons::Draw(nux::GraphicsEngine& gfx_context, bool force_draw)
433+{
434+ window_buttons_->ProcessDraw(gfx_context, true);
435+}
436+
437+} // namespace unity
438
439=== added file 'unity-shared/OverlayWindowButtons.h'
440--- unity-shared/OverlayWindowButtons.h 1970-01-01 00:00:00 +0000
441+++ unity-shared/OverlayWindowButtons.h 2013-01-29 01:28:23 +0000
442@@ -0,0 +1,54 @@
443+/*
444+ * Copyright (C) 2013 Canonical Ltd
445+ *
446+ * This program is free software: you can redistribute it and/or modify
447+ * it under the terms of the GNU General Public License version 3 as
448+ * published by the Free Software Foundation.
449+ *
450+ * This program is distributed in the hope that it will be useful,
451+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
452+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
453+ * GNU General Public License for more details.
454+ *
455+ * You should have received a copy of the GNU General Public License
456+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
457+ *
458+ * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com>
459+ *
460+ */
461+
462+#ifndef OVERLAY_WINDOW_BUTTONS
463+#define OVERLAY_WINDOW_BUTTONS
464+
465+#include "Nux/Nux.h"
466+#include "Nux/BaseWindow.h"
467+
468+#include "WindowButtons.h"
469+
470+namespace unity
471+{
472+
473+class OverlayWindowButtons : public nux::BaseWindow
474+{
475+ NUX_DECLARE_OBJECT_TYPE(OverlayWindowButtons, nux::BaseWindow);
476+public:
477+ OverlayWindowButtons();
478+
479+ void Show();
480+ void Hide();
481+
482+ nux::Area* FindAreaUnderMouse(nux::Point const& mouse_position,
483+ nux::NuxEventType event_type);
484+
485+protected:
486+ void Draw(nux::GraphicsEngine& gfx_context, bool force_draw);
487+
488+private:
489+ void UpdateGeometry();
490+
491+ nux::ObjectPtr<WindowButtons> window_buttons_;
492+};
493+
494+} // namespace unity
495+
496+#endif // OVERLAY_WINDOW_BUTTONS
497
498=== renamed file 'panel/WindowButtonPriv.h' => 'unity-shared/WindowButtonPriv.h'
499=== renamed file 'panel/WindowButtons.cpp' => 'unity-shared/WindowButtons.cpp'
500=== renamed file 'panel/WindowButtons.h' => 'unity-shared/WindowButtons.h'