Merge lp:~3v1n0/unity/panel-grab-offset-fix into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Andrea Azzarone
Approved revision: no longer in the source branch.
Merged at revision: 3084
Proposed branch: lp:~3v1n0/unity/panel-grab-offset-fix
Merge into: lp:unity
Diff against target: 274 lines (+95/-45)
4 files modified
panel/PanelMenuView.cpp (+3/-4)
tests/test_panel_menu_view.cpp (+74/-23)
unity-shared/StandaloneWindowManager.cpp (+11/-13)
unity-shared/StandaloneWindowManager.h (+7/-5)
To merge this branch: bzr merge lp:~3v1n0/unity/panel-grab-offset-fix
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+145304@code.launchpad.net

Commit message

PanelMenuView: restore a grabbed window taking care of the panel offset

Description of the change

Take care of the offset of the panel when defining the new geometry of a restored window by mouse grabbing.

Added tests... (a nice example - considering that this needed lp:~3v1n0/unity/standalone-wm-properties as well - how to generate hundreds of lines of diffs, just for testing an one-line-change ;-) )

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

Fix the problems here. All the tests pass.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'panel/PanelMenuView.cpp'
2--- panel/PanelMenuView.cpp 2013-01-28 23:57:38 +0000
3+++ panel/PanelMenuView.cpp 2013-01-29 14:50:27 +0000
4@@ -155,7 +155,6 @@
5 titlebar_grab_area_->mouse_leave.connect(sigc::mem_fun(this, &PanelMenuView::OnPanelViewMouseLeave));
6
7 ubus_manager_.RegisterInterest(UBUS_SWITCHER_SHOWN, sigc::mem_fun(this, &PanelMenuView::OnSwitcherShown));
8-
9 ubus_manager_.RegisterInterest(UBUS_LAUNCHER_START_KEY_NAV, sigc::mem_fun(this, &PanelMenuView::OnLauncherKeyNavStarted));
10 ubus_manager_.RegisterInterest(UBUS_LAUNCHER_END_KEY_NAV, sigc::mem_fun(this, &PanelMenuView::OnLauncherKeyNavEnded));
11 ubus_manager_.RegisterInterest(UBUS_LAUNCHER_START_KEY_SWITCHER, sigc::mem_fun(this, &PanelMenuView::OnLauncherKeyNavStarted));
12@@ -1414,7 +1413,7 @@
13
14 void PanelMenuView::OnMaximizedGrabMove(int x, int y)
15 {
16- auto panel = static_cast<nux::BaseWindow*>(GetTopLevelViewWindow());
17+ auto panel = GetTopLevelViewWindow();
18
19 if (!panel)
20 return;
21@@ -1429,7 +1428,7 @@
22 *
23 * This is a workaround to avoid that the grid plugin would be fired
24 * showing the window shape preview effect. See bug #838923 */
25- if (maximized != 0 && panel)
26+ if (maximized != 0)
27 {
28 nux::Geometry const& panel_geo = panel->GetAbsoluteGeometry();
29
30@@ -1443,7 +1442,7 @@
31 * pointer position, if it doesn't fit on that area try to keep it into the
32 * current workarea as much as possible, but giving priority to the left border
33 * that shouldn't be never put out of the workarea */
34- int restore_x = x - (restored_geo.width * x / panel_geo.width);
35+ int restore_x = x - (restored_geo.width * (x - panel_geo.x) / panel_geo.width);
36 int restore_y = y;
37
38 if (restore_x + restored_geo.width > workarea_geo.x + workarea_geo.width)
39
40=== modified file 'tests/test_panel_menu_view.cpp'
41--- tests/test_panel_menu_view.cpp 2012-12-14 16:44:58 +0000
42+++ tests/test_panel_menu_view.cpp 2013-01-29 14:50:27 +0000
43@@ -24,6 +24,7 @@
44 #include "UnitySettings.h"
45 #include "UBusMessages.h"
46 #include "StandaloneWindowManager.h"
47+#include "test_uscreen_mock.h"
48 #include "test_utils.h"
49
50 using namespace testing;
51@@ -33,28 +34,45 @@
52
53 struct TestPanelMenuView : public testing::Test
54 {
55- void ProcessUBusMessages()
56- {
57- bool expired = false;
58- glib::Idle idle([&] { expired = true; return false; },
59- glib::Source::Priority::LOW);
60- Utils::WaitUntil(expired);
61- }
62+ TestPanelMenuView()
63+ : WM(dynamic_cast<StandaloneWindowManager*>(&WindowManager::Default()))
64+ {}
65
66 struct MockPanelMenuView : public PanelMenuView
67 {
68 MOCK_METHOD0(QueueDraw, void());
69 MOCK_CONST_METHOD1(GetActiveViewName, std::string(bool));
70
71+ using PanelMenuView::GetCurrentTitle;
72 using PanelMenuView::window_buttons_;
73- using PanelMenuView::GetCurrentTitle;
74+ using PanelMenuView::titlebar_grab_area_;
75 };
76
77+ nux::ObjectPtr<nux::BaseWindow> AddPanelToWindow(int monitor)
78+ {
79+ nux::ObjectPtr<nux::BaseWindow> panel_win(new nux::BaseWindow());
80+ auto const& monitor_geo = uscreen.GetMonitorGeometry(monitor);
81+ panel_win->SetGeometry(monitor_geo);
82+ panel_win->SetMaximumHeight(panelStyle.panel_height());
83+ panel_win->SetLayout(new nux::HLayout(NUX_TRACKER_LOCATION));
84+ panel_win->GetLayout()->AddView(&menu_view, 1);
85+ panel_win->GetLayout()->SetContentDistribution(nux::MAJOR_POSITION_START);
86+ panel_win->GetLayout()->SetVerticalExternalMargin(0);
87+ panel_win->GetLayout()->SetHorizontalExternalMargin(0);
88+ panel_win->ComputeContentSize();
89+
90+ menu_view.SetMonitor(monitor);
91+
92+ return panel_win;
93+ }
94+
95 protected:
96 // The order is important, i.e. menu_view needs
97 // panel::Style that needs Settings
98+ MockUScreen uscreen;
99 Settings settings;
100 panel::Style panelStyle;
101+ StandaloneWindowManager* WM;
102 testing::NiceMock<MockPanelMenuView> menu_view;
103 };
104
105@@ -65,23 +83,16 @@
106 EXPECT_TRUE(menu_view.GetCurrentTitle().empty());
107
108 UBusManager ubus;
109- ubus.SendMessage(UBUS_LAUNCHER_START_KEY_NAV, NULL);
110+ ubus.SendMessage(UBUS_LAUNCHER_START_KEY_NAV);
111 ubus.SendMessage(UBUS_LAUNCHER_SELECTION_CHANGED,
112 g_variant_new_string(escapedText));
113- ProcessUBusMessages();
114-
115- EXPECT_EQ(menu_view.GetCurrentTitle(), escapedText);
116-
117- ubus.SendMessage(UBUS_LAUNCHER_END_KEY_NAV, NULL);
118- ProcessUBusMessages();
119-
120- StandaloneWindowManager *wm = dynamic_cast<StandaloneWindowManager *>(&WindowManager::Default());
121- ASSERT_NE(wm, nullptr);
122- // Change the wm to trick menu_view::RefreshTitle to call GetActiveViewName
123- wm->SetScaleActive(true);
124- wm->SetScaleActiveForGroup(true);
125-
126- EXPECT_EQ(menu_view.GetCurrentTitle(), "&lt;&gt;&apos;");
127+ Utils::WaitUntilMSec([this] {return menu_view.GetCurrentTitle() == escapedText;});
128+
129+
130+ WM->SetScaleActive(true);
131+ WM->SetScaleActiveForGroup(true);
132+ ubus.SendMessage(UBUS_LAUNCHER_END_KEY_NAV);
133+ Utils::WaitUntilMSec([this] {return menu_view.GetCurrentTitle() == "&lt;&gt;&apos;";});
134 }
135
136 TEST_F(TestPanelMenuView, QueuesDrawOnButtonsOpacityChange)
137@@ -90,4 +101,44 @@
138 menu_view.window_buttons_->opacity.changed.emit(0.5f);
139 }
140
141+struct ProgressTester : TestPanelMenuView, WithParamInterface<double> {};
142+INSTANTIATE_TEST_CASE_P(TestPanelMenuView, ProgressTester, Range(0.0, 1.0, 0.1));
143+
144+TEST_P(ProgressTester, RestoreOnGrabInBiggerWorkArea)
145+{
146+ uscreen.SetupFakeMultiMonitor();
147+ unsigned monitor = uscreen.GetMonitors().size() - 1;
148+ auto const& monitor_geo = uscreen.GetMonitorGeometry(monitor);
149+ WM->SetWorkareaGeometry(monitor_geo);
150+
151+ auto panel_win = AddPanelToWindow(monitor);
152+
153+ auto max_window = std::make_shared<StandaloneWindow>(g_random_int());
154+ WM->AddStandaloneWindow(max_window);
155+
156+ max_window->maximized = true;
157+ nux::Geometry win_geo(monitor_geo.x + monitor_geo.width/4, monitor_geo.y + monitor_geo.height/4,
158+ monitor_geo.width/2, monitor_geo.height/2);
159+ max_window->geo = win_geo;
160+
161+ bool restored = false;
162+ bool moved = false;
163+ WM->window_restored.connect([&] (Window xid) {restored = (max_window->Xid() == xid);});
164+ WM->window_moved.connect([&] (Window xid) {moved = (max_window->Xid() == xid);});
165+
166+ // Grab the window outside the panel shape
167+ nux::Point mouse_pos(panel_win->GetX() + panel_win->GetWidth() * GetParam(), panel_win->GetY() + panel_win->GetHeight() + 1);
168+ menu_view.titlebar_grab_area_->grab_move(mouse_pos.x - panel_win->GetX(), mouse_pos.y - panel_win->GetY());
169+
170+ nux::Geometry expected_geo(win_geo);
171+ expected_geo.SetPosition(mouse_pos.x - (win_geo.width * (mouse_pos.x - panel_win->GetX()) / panel_win->GetWidth()), mouse_pos.y);
172+ expected_geo.x = std::max<int>(expected_geo.x, monitor_geo.x);
173+
174+ EXPECT_TRUE(restored);
175+ EXPECT_TRUE(moved);
176+ EXPECT_FALSE(max_window->maximized());
177+ EXPECT_EQ(max_window->geo(), expected_geo);
178+}
179+
180+
181 }
182
183=== modified file 'unity-shared/StandaloneWindowManager.cpp'
184--- unity-shared/StandaloneWindowManager.cpp 2013-01-25 21:06:34 +0000
185+++ unity-shared/StandaloneWindowManager.cpp 2013-01-29 14:50:27 +0000
186@@ -245,8 +245,10 @@
187
188 void StandaloneWindowManager::RestoreAt(Window window_id, int x, int y)
189 {
190+ nux::Geometry new_geo = GetWindowGeometry(window_id);
191+ new_geo.SetPosition(x, y);
192 Restore(window_id);
193- StartMove(window_id, x, y);
194+ MoveResizeWindow(window_id, new_geo);
195 }
196
197 void StandaloneWindowManager::UnMinimize(Window window_id)
198@@ -372,13 +374,8 @@
199
200 void StandaloneWindowManager::StartMove(Window window_id, int x, int y)
201 {
202- auto it = standalone_windows_.find(window_id);
203- if (it != standalone_windows_.end())
204- {
205- nux::Geometry new_geo(it->second->geo());
206- new_geo.SetPosition(x, y);
207- it->second->geo = new_geo;
208- }
209+ // This is called when we ask the WM to start the movement of a window,
210+ // but it does not actually move it.
211 }
212
213 int StandaloneWindowManager::GetWindowMonitor(Window window_id) const
214@@ -415,8 +412,12 @@
215
216 nux::Geometry StandaloneWindowManager::GetWorkAreaGeometry(Window window_id) const
217 {
218- nux::Geometry geo(0, 0, 1, 1);
219- return geo;
220+ return workarea_geo_;
221+}
222+
223+void StandaloneWindowManager::SetWorkareaGeometry(nux::Geometry const& geo)
224+{
225+ workarea_geo_ = geo;
226 }
227
228 nux::Size StandaloneWindowManager::GetWindowDecorationSize(Window window_id, WindowManager::Edge edge) const
229@@ -504,9 +505,6 @@
230 if (!window)
231 return;
232
233- if (standalone_windows_.empty())
234- window->active = true;
235-
236 auto xid = window->Xid();
237 standalone_windows_[xid] = window;
238
239
240=== modified file 'unity-shared/StandaloneWindowManager.h'
241--- unity-shared/StandaloneWindowManager.h 2013-01-25 21:06:34 +0000
242+++ unity-shared/StandaloneWindowManager.h 2013-01-29 14:50:27 +0000
243@@ -143,15 +143,16 @@
244 virtual std::string GetWindowName(Window window_id) const;
245
246 // Mock functions
247+ void AddStandaloneWindow(StandaloneWindow::Ptr const& window);
248+ std::map<Window, StandaloneWindow::Ptr> GetStandaloneWindows() const;
249+
250 void SetScaleActive(bool scale_active);
251 void SetScaleActiveForGroup(bool scale_active_for_group);
252 void SetCurrentDesktop(unsigned desktop_id);
253+
254 void SetViewportSize(unsigned horizontal, unsigned vertical);
255-
256- void AddStandaloneWindow(StandaloneWindow::Ptr const& window);
257- std::map<Window, StandaloneWindow::Ptr> GetStandaloneWindows() const;
258-
259 void SetCurrentViewport(nux::Point const& vp);
260+ void SetWorkareaGeometry(nux::Geometry const& geo);
261
262 protected:
263 virtual void AddProperties(GVariantBuilder* builder);
264@@ -163,8 +164,9 @@
265 bool scale_active_for_group_;
266 unsigned current_desktop_;
267 nux::Size viewport_size_;
268+ nux::Point current_vp_;
269+ nux::Geometry workarea_geo_;
270 std::map<Window, StandaloneWindow::Ptr> standalone_windows_;
271- nux::Point current_vp_;
272 };
273
274 }