Merge lp:~3v1n0/unity/scale-layout-windows into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Christopher Townsend
Approved revision: 3704
Merged at revision: 3714
Proposed branch: lp:~3v1n0/unity/scale-layout-windows
Merge into: lp:unity
Diff against target: 417 lines (+188/-22)
10 files modified
decorations/DecoratedWindow.cpp (+1/-1)
panel/PanelMenuView.cpp (+22/-14)
plugins/unityshell/src/unityshell.cpp (+113/-3)
plugins/unityshell/src/unityshell.h (+6/-0)
shortcuts/ShortcutController.cpp (+5/-1)
shortcuts/ShortcutController.h (+2/-0)
tests/test_layout_system.cpp (+1/-0)
tests/test_shortcut_controller.cpp (+33/-0)
unity-shared/LayoutSystem.cpp (+4/-3)
unity-shared/LayoutSystem.h (+1/-0)
To merge this branch: bzr merge lp:~3v1n0/unity/scale-layout-windows
Reviewer Review Type Date Requested Status
Christopher Townsend Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+210234@code.launchpad.net

Commit message

UnityScreen: use switcher's LayoutSystem to compute the scaled windows geometries

Thanks to this, both the Alt+Tab and Spread will use the same codepath to define the positioning of the scaled windows.

Description of the change

JohnLea approved it.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Christopher Townsend (townsend) wrote :

Looks good

review: Approve
lp:~3v1n0/unity/scale-layout-windows updated
3705. By Marco Trevisan (Treviño) on 2014-03-12

Merging with lp:~3v1n0/unity/hints-on-first-run

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'decorations/DecoratedWindow.cpp'
2--- decorations/DecoratedWindow.cpp 2014-02-27 05:30:25 +0000
3+++ decorations/DecoratedWindow.cpp 2014-03-12 23:00:55 +0000
4@@ -129,7 +129,7 @@
5 if (win_->hasUnmapReference())
6 return;
7
8- CompWindowExtents empty(0, 0, 0, 0);
9+ CompWindowExtents empty;
10
11 if (win_->border() != empty || win_->input() != empty)
12 win_->setWindowFrameExtents(&empty, &empty);
13
14=== modified file 'panel/PanelMenuView.cpp'
15--- panel/PanelMenuView.cpp 2014-03-06 09:26:03 +0000
16+++ panel/PanelMenuView.cpp 2014-03-12 23:00:55 +0000
17@@ -693,22 +693,30 @@
18 if (BAMF_IS_WINDOW(window))
19 {
20 BamfView *view = reinterpret_cast<BamfView*>(window);
21- std::vector<Window> const& our_xids = nux::XInputWindow::NativeHandleList();
22 Window window_xid = bamf_window_get_xid(window);
23
24- if (std::find(our_xids.begin(), our_xids.end(), window_xid) != our_xids.end())
25+ if (bamf_window_get_window_type(window) == BAMF_WINDOW_DOCK)
26 {
27- /* If the active window is an unity window, we need to fallback to the
28- * top one, anyway we should always avoid to focus unity internal windows */
29- BamfWindow* top_win = GetBamfWindowForXid(GetTopWindow());
30-
31- if (top_win && top_win != window)
32- {
33- window = top_win;
34- }
35- else
36- {
37- return "";
38+ auto panel = const_cast<PanelMenuView*>(this)->GetTopLevelViewWindow();
39+ if (static_cast<nux::BaseWindow*>(panel)->GetInputWindowId() == window_xid)
40+ return desktop_name_;
41+
42+ std::vector<Window> const& our_xids = nux::XInputWindow::NativeHandleList();
43+
44+ if (std::find(our_xids.begin(), our_xids.end(), window_xid) != our_xids.end())
45+ {
46+ /* If the active window is an unity window, we need to fallback to the
47+ * top one, anyway we should always avoid to focus unity internal windows */
48+ BamfWindow* top_win = GetBamfWindowForXid(GetTopWindow());
49+
50+ if (top_win && top_win != window)
51+ {
52+ window = top_win;
53+ }
54+ else
55+ {
56+ return "";
57+ }
58 }
59 }
60
61@@ -718,7 +726,7 @@
62 }
63 else if (!IsValidWindow(window_xid))
64 {
65- return "";
66+ return "";
67 }
68
69 if (WindowManager::Default().IsWindowMaximized(window_xid) && !use_appname)
70
71=== modified file 'plugins/unityshell/src/unityshell.cpp'
72--- plugins/unityshell/src/unityshell.cpp 2014-03-07 19:18:30 +0000
73+++ plugins/unityshell/src/unityshell.cpp 2014-03-12 23:00:55 +0000
74@@ -52,6 +52,7 @@
75 #include "launcher/XdndStartStopNotifierImp.h"
76 #include "CompizShortcutModeller.h"
77 #include "GnomeKeyGrabber.h"
78+#include "RawPixel.h"
79
80 #include "decorations/DecorationsDataPool.h"
81 #include "decorations/DecorationsManager.h"
82@@ -137,7 +138,10 @@
83 const unsigned int SCROLL_UP_BUTTON = 7;
84 const int MAX_BUFFER_AGE = 11;
85 const int FRAMES_TO_REDRAW_ON_RESUME = 10;
86+const RawPixel SCALE_PADDING = 40_em;
87+const RawPixel SCALE_SPACING = 20_em;
88 const std::string RELAYOUT_TIMEOUT = "relayout-timeout";
89+const std::string FIRST_RUN_STAMP = "first_run.stamp";
90 } // namespace local
91 } // anon namespace
92
93@@ -267,6 +271,7 @@
94 ScreenInterface::setHandler(screen);
95 CompositeScreenInterface::setHandler(cScreen);
96 GLScreenInterface::setHandler(gScreen);
97+ ScaleScreenInterface::setHandler(sScreen);
98
99 PluginAdapter::Initialize(screen);
100 AddChild(&WindowManager::Default());
101@@ -878,9 +883,8 @@
102 if (CompWindow* window = screen->findWindow(target->xid))
103 {
104 UnityWindow *unity_window = UnityWindow::get(window);
105- double scale = target->result.width / static_cast<double>(target->geo.width);
106 double parent_alpha = switcher_controller_->Opacity();
107- unity_window->paintThumbnail(target->result, target->alpha, parent_alpha, scale,
108+ unity_window->paintThumbnail(target->result, target->alpha, parent_alpha, target->scale,
109 target->decoration_height, target->selected);
110 }
111 }
112@@ -3603,7 +3607,77 @@
113 ScheduleRelayout(500);
114 }
115
116-void UnityScreen::OnDashRealized ()
117+bool UnityScreen::layoutSlotsAndAssignWindows()
118+{
119+ auto const& scaled_windows = sScreen->getWindows();
120+
121+ for (auto const& output : screen->outputDevs())
122+ {
123+ ui::LayoutWindow::Vector layout_windows;
124+ int monitor = UScreen::GetDefault()->GetMonitorAtPosition(output.centerX(), output.centerY());
125+ double monitor_scale = unity_settings_.em(monitor)->DPIScale();
126+
127+ for (ScaleWindow *sw : scaled_windows)
128+ {
129+ if (sw->window->outputDevice() == static_cast<int>(output.id()))
130+ {
131+ UnityWindow::get(sw->window)->deco_win_->scaled = true;
132+ layout_windows.emplace_back(std::make_shared<LayoutWindow>(sw->window->id()));
133+ }
134+ }
135+
136+ auto max_bounds = NuxGeometryFromCompRect(output.workArea());
137+
138+ if (launcher_controller_->options()->hide_mode != LAUNCHER_HIDE_NEVER)
139+ {
140+ int monitor_width = unity_settings_.LauncherWidth(monitor);
141+ max_bounds.x += monitor_width;
142+ max_bounds.width -= monitor_width;
143+ }
144+
145+ nux::Geometry final_bounds;
146+ ui::LayoutSystem layout;
147+ layout.max_row_height = max_bounds.height;
148+ layout.spacing = local::SCALE_SPACING.CP(monitor_scale);
149+ int padding = local::SCALE_PADDING.CP(monitor_scale);
150+ max_bounds.Expand(-padding, -padding);
151+ layout.LayoutWindows(layout_windows, max_bounds, final_bounds);
152+
153+ auto lw_it = layout_windows.begin();
154+ for (auto const& sw : scaled_windows)
155+ {
156+ if (lw_it == layout_windows.end())
157+ break;
158+
159+ LayoutWindow::Ptr const& lw = *lw_it;
160+
161+ if (sw->window->id() != lw->xid)
162+ continue;
163+
164+ ScaleSlot slot(CompRectFromNuxGeo(lw->result));
165+ slot.scale = lw->scale;
166+
167+ float sx = lw->geo.width * slot.scale;
168+ float sy = lw->geo.height * slot.scale;
169+ float cx = (slot.x1() + slot.x2()) / 2;
170+ float cy = (slot.y1() + slot.y2()) / 2;
171+
172+ CompWindow *w = sw->window;
173+ cx += w->input().left * slot.scale;
174+ cy += w->input().top * slot.scale;
175+
176+ slot.setGeometry(cx - sx / 2, cy - sy / 2, sx, sy);
177+ slot.filled = true;
178+
179+ sw->setSlot(slot);
180+ ++lw_it;
181+ }
182+ }
183+
184+ return true;
185+}
186+
187+void UnityScreen::OnDashRealized()
188 {
189 /* stack any windows named "onboard" above us */
190 for (CompWindow *w : screen->windows ())
191@@ -3663,6 +3737,7 @@
192 auto shortcuts_modeller = std::make_shared<shortcut::CompizModeller>();
193 shortcut_controller_ = std::make_shared<shortcut::Controller>(base_window_raiser, shortcuts_modeller);
194 AddChild(shortcut_controller_.get());
195+ ShowFirstRunHints();
196
197 // Setup Session Controller
198 auto manager = std::make_shared<session::GnomeManager>();
199@@ -3742,6 +3817,41 @@
200 return menus_->KeyGrabber()->GetActions();
201 }
202
203+void UnityScreen::ShowFirstRunHints()
204+{
205+ sources_.AddTimeoutSeconds(1, [this] {
206+ auto const& cache_dir = glib::gchar_to_string(g_get_user_cache_dir())+"/unity/";
207+ if (!g_file_test((cache_dir+local::FIRST_RUN_STAMP).c_str(), G_FILE_TEST_EXISTS))
208+ {
209+ // We focus the panel, so the shortcut hint will be hidden at first user input
210+ auto const& panels = panel_controller_->panels();
211+ if (!panels.empty())
212+ {
213+ auto panel_win = static_cast<nux::BaseWindow*>(panels.front()->GetTopLevelViewWindow());
214+ SaveInputThenFocus(panel_win->GetInputWindowId());
215+ }
216+ shortcut_controller_->first_run = true;
217+ shortcut_controller_->Show();
218+
219+ if (g_mkdir_with_parents(cache_dir.c_str(), 0700) >= 0)
220+ {
221+ glib::Error error;
222+ g_file_set_contents((cache_dir+local::FIRST_RUN_STAMP).c_str(), "", 0, &error);
223+
224+ if (error)
225+ {
226+ LOG_ERROR(logger) << "Impossible to save the unity stamp file: " << error;
227+ }
228+ }
229+ else
230+ {
231+ LOG_ERROR(logger) << "Impossible to create unity cache folder!";
232+ }
233+ }
234+ return false;
235+ });
236+}
237+
238 /* Window init */
239
240 namespace
241
242=== modified file 'plugins/unityshell/src/unityshell.h'
243--- plugins/unityshell/src/unityshell.h 2014-03-07 03:37:43 +0000
244+++ plugins/unityshell/src/unityshell.h 2014-03-12 23:00:55 +0000
245@@ -109,6 +109,7 @@
246 public ScreenInterface,
247 public CompositeScreenInterface,
248 public GLScreenInterface,
249+ public ScaleScreenInterface,
250 public BaseSwitchScreen,
251 public PluginClassHandler <UnityScreen, CompScreen>,
252 public CompAction::Container,
253@@ -172,6 +173,9 @@
254 void enterShowDesktopMode ();
255 void leaveShowDesktopMode (CompWindow *w);
256
257+ /* window scaling */
258+ bool layoutSlotsAndAssignWindows();
259+
260 bool showMenuBarInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
261 bool showMenuBarTerminate(CompAction* action, CompAction::State state, CompOption::Vector& options);
262 bool showLauncherKeyInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
263@@ -306,6 +310,8 @@
264
265 void DamageBlurUpdateRegion(nux::Geometry const&);
266
267+ void ShowFirstRunHints();
268+
269 std::unique_ptr<na::TickSource> tick_source_;
270 std::unique_ptr<na::AnimationController> animation_controller_;
271
272
273=== modified file 'shortcuts/ShortcutController.cpp'
274--- shortcuts/ShortcutController.cpp 2013-11-20 21:39:40 +0000
275+++ shortcuts/ShortcutController.cpp 2014-03-12 23:00:55 +0000
276@@ -37,7 +37,8 @@
277
278 Controller::Controller(BaseWindowRaiser::Ptr const& base_window_raiser,
279 AbstractModeller::Ptr const& modeller)
280- : modeller_(modeller)
281+ : first_run(false)
282+ , modeller_(modeller)
283 , base_window_raiser_(base_window_raiser)
284 , visible_(false)
285 , enabled_(true)
286@@ -155,6 +156,7 @@
287 AddChild(view_.GetPointer());
288 view_->SetModel(modeller_->GetCurrentModel());
289 view_->background_color = WindowManager::Default().average_color();
290+ view_->closable = first_run();
291
292 if (!view_window_)
293 {
294@@ -197,6 +199,8 @@
295 if (view_window_ && view_window_->GetOpacity() > 0.0f)
296 {
297 view_->live_background = false;
298+ view_->closable = false;
299+ first_run = false;
300 animation::StartOrReverse(fade_animator_, animation::Direction::BACKWARD);
301 }
302 }
303
304=== modified file 'shortcuts/ShortcutController.h'
305--- shortcuts/ShortcutController.h 2013-11-14 00:17:19 +0000
306+++ shortcuts/ShortcutController.h 2014-03-12 23:00:55 +0000
307@@ -47,6 +47,8 @@
308 Controller(BaseWindowRaiser::Ptr const& raiser, AbstractModeller::Ptr const& modeller);
309 virtual ~Controller();
310
311+ nux::Property<bool> first_run;
312+
313 bool Show();
314 void Hide();
315
316
317=== modified file 'tests/test_layout_system.cpp'
318--- tests/test_layout_system.cpp 2013-10-14 17:36:51 +0000
319+++ tests/test_layout_system.cpp 2014-03-12 23:00:55 +0000
320@@ -57,6 +57,7 @@
321 EXPECT_EQ(lwin.geo, fake_window->geo);
322 EXPECT_EQ(lwin.decoration_height, 0);
323 EXPECT_EQ(lwin.selected, false);
324+ EXPECT_FLOAT_EQ(lwin.scale, 1.0f);
325 EXPECT_EQ(lwin.aspect_ratio, fake_window->geo().width / static_cast<float>(fake_window->geo().height));
326 }
327
328
329=== modified file 'tests/test_shortcut_controller.cpp'
330--- tests/test_shortcut_controller.cpp 2013-09-25 00:48:03 +0000
331+++ tests/test_shortcut_controller.cpp 2014-03-12 23:00:55 +0000
332@@ -68,6 +68,7 @@
333 MOCK_METHOD1(SetOpacity, void(double));
334 using Controller::GetOffsetPerMonitor;
335 using Controller::ConstructView;
336+ using Controller::OnShowTimer;
337 using Controller::view_;
338
339 void RealSetOpacity(double value)
340@@ -188,5 +189,37 @@
341 color_property.changed.emit(nux::color::RandomColor());
342 }
343
344+TEST_F(TestShortcutController, FirstRunFalse)
345+{
346+ ASSERT_FALSE(controller_.first_run());
347+
348+ controller_.ConstructView();
349+ EXPECT_FALSE(controller_.view_->closable());
350+}
351+
352+TEST_F(TestShortcutController, FirstRunTrue)
353+{
354+ ASSERT_FALSE(controller_.first_run());
355+
356+ controller_.first_run = true;
357+ controller_.ConstructView();
358+ EXPECT_TRUE(controller_.view_->closable());
359+}
360+
361+TEST_F(TestShortcutController, UnsetFirstRunOnHide)
362+{
363+ controller_.first_run = true;
364+ controller_.ConstructView();
365+
366+ ASSERT_TRUE(controller_.view_->closable());
367+ controller_.Show();
368+ controller_.OnShowTimer();
369+ tick_source_.tick(100 * 1000);
370+ controller_.Hide();
371+
372+ EXPECT_FALSE(controller_.first_run());
373+ EXPECT_FALSE(controller_.view_->closable());
374+}
375+
376 }
377 }
378
379=== modified file 'unity-shared/LayoutSystem.cpp'
380--- unity-shared/LayoutSystem.cpp 2013-09-19 16:44:03 +0000
381+++ unity-shared/LayoutSystem.cpp 2014-03-12 23:00:55 +0000
382@@ -125,12 +125,12 @@
383 for (LayoutWindow::Ptr const& window : row)
384 {
385 // we dont allow scaling up
386- float final_scalar = std::min(1.0f, (unpadded_bounds.height / (float)window->geo.height) * global_scalar);
387+ window->scale = std::min(1.0f, (unpadded_bounds.height / (float)window->geo.height) * global_scalar);
388
389 window->result.x = x;
390 window->result.y = y;
391- window->result.width = window->geo.width * final_scalar;
392- window->result.height = window->geo.height * final_scalar;
393+ window->result.width = window->geo.width * window->scale;
394+ window->result.height = window->geo.height * window->scale;
395
396 x += window->result.width;
397 }
398@@ -275,6 +275,7 @@
399 , decoration_height(0)
400 , selected(false)
401 , aspect_ratio(geo.width / static_cast<float>(geo.height))
402+ , scale(1.0f)
403 , alpha(0.0f)
404 {
405 auto& wm = WindowManager::Default();
406
407=== modified file 'unity-shared/LayoutSystem.h'
408--- unity-shared/LayoutSystem.h 2013-09-19 16:44:03 +0000
409+++ unity-shared/LayoutSystem.h 2014-03-12 23:00:55 +0000
410@@ -46,6 +46,7 @@
411
412 bool selected;
413 float aspect_ratio;
414+ float scale;
415 float alpha;
416
417 protected: