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

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Christopher Townsend
Approved revision: no longer in the source branch.
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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'decorations/DecoratedWindow.cpp'
--- decorations/DecoratedWindow.cpp 2014-02-27 05:30:25 +0000
+++ decorations/DecoratedWindow.cpp 2014-03-12 23:00:55 +0000
@@ -129,7 +129,7 @@
129 if (win_->hasUnmapReference())129 if (win_->hasUnmapReference())
130 return;130 return;
131131
132 CompWindowExtents empty(0, 0, 0, 0);132 CompWindowExtents empty;
133133
134 if (win_->border() != empty || win_->input() != empty)134 if (win_->border() != empty || win_->input() != empty)
135 win_->setWindowFrameExtents(&empty, &empty);135 win_->setWindowFrameExtents(&empty, &empty);
136136
=== modified file 'panel/PanelMenuView.cpp'
--- panel/PanelMenuView.cpp 2014-03-06 09:26:03 +0000
+++ panel/PanelMenuView.cpp 2014-03-12 23:00:55 +0000
@@ -693,22 +693,30 @@
693 if (BAMF_IS_WINDOW(window))693 if (BAMF_IS_WINDOW(window))
694 {694 {
695 BamfView *view = reinterpret_cast<BamfView*>(window);695 BamfView *view = reinterpret_cast<BamfView*>(window);
696 std::vector<Window> const& our_xids = nux::XInputWindow::NativeHandleList();
697 Window window_xid = bamf_window_get_xid(window);696 Window window_xid = bamf_window_get_xid(window);
698697
699 if (std::find(our_xids.begin(), our_xids.end(), window_xid) != our_xids.end())698 if (bamf_window_get_window_type(window) == BAMF_WINDOW_DOCK)
700 {699 {
701 /* If the active window is an unity window, we need to fallback to the700 auto panel = const_cast<PanelMenuView*>(this)->GetTopLevelViewWindow();
702 * top one, anyway we should always avoid to focus unity internal windows */701 if (static_cast<nux::BaseWindow*>(panel)->GetInputWindowId() == window_xid)
703 BamfWindow* top_win = GetBamfWindowForXid(GetTopWindow());702 return desktop_name_;
704703
705 if (top_win && top_win != window)704 std::vector<Window> const& our_xids = nux::XInputWindow::NativeHandleList();
706 {705
707 window = top_win;706 if (std::find(our_xids.begin(), our_xids.end(), window_xid) != our_xids.end())
708 }707 {
709 else708 /* If the active window is an unity window, we need to fallback to the
710 {709 * top one, anyway we should always avoid to focus unity internal windows */
711 return "";710 BamfWindow* top_win = GetBamfWindowForXid(GetTopWindow());
711
712 if (top_win && top_win != window)
713 {
714 window = top_win;
715 }
716 else
717 {
718 return "";
719 }
712 }720 }
713 }721 }
714722
@@ -718,7 +726,7 @@
718 }726 }
719 else if (!IsValidWindow(window_xid))727 else if (!IsValidWindow(window_xid))
720 {728 {
721 return "";729 return "";
722 }730 }
723731
724 if (WindowManager::Default().IsWindowMaximized(window_xid) && !use_appname)732 if (WindowManager::Default().IsWindowMaximized(window_xid) && !use_appname)
725733
=== modified file 'plugins/unityshell/src/unityshell.cpp'
--- plugins/unityshell/src/unityshell.cpp 2014-03-07 19:18:30 +0000
+++ plugins/unityshell/src/unityshell.cpp 2014-03-12 23:00:55 +0000
@@ -52,6 +52,7 @@
52#include "launcher/XdndStartStopNotifierImp.h"52#include "launcher/XdndStartStopNotifierImp.h"
53#include "CompizShortcutModeller.h"53#include "CompizShortcutModeller.h"
54#include "GnomeKeyGrabber.h"54#include "GnomeKeyGrabber.h"
55#include "RawPixel.h"
5556
56#include "decorations/DecorationsDataPool.h"57#include "decorations/DecorationsDataPool.h"
57#include "decorations/DecorationsManager.h"58#include "decorations/DecorationsManager.h"
@@ -137,7 +138,10 @@
137const unsigned int SCROLL_UP_BUTTON = 7;138const unsigned int SCROLL_UP_BUTTON = 7;
138const int MAX_BUFFER_AGE = 11;139const int MAX_BUFFER_AGE = 11;
139const int FRAMES_TO_REDRAW_ON_RESUME = 10;140const int FRAMES_TO_REDRAW_ON_RESUME = 10;
141const RawPixel SCALE_PADDING = 40_em;
142const RawPixel SCALE_SPACING = 20_em;
140const std::string RELAYOUT_TIMEOUT = "relayout-timeout";143const std::string RELAYOUT_TIMEOUT = "relayout-timeout";
144const std::string FIRST_RUN_STAMP = "first_run.stamp";
141} // namespace local145} // namespace local
142} // anon namespace146} // anon namespace
143147
@@ -267,6 +271,7 @@
267 ScreenInterface::setHandler(screen);271 ScreenInterface::setHandler(screen);
268 CompositeScreenInterface::setHandler(cScreen);272 CompositeScreenInterface::setHandler(cScreen);
269 GLScreenInterface::setHandler(gScreen);273 GLScreenInterface::setHandler(gScreen);
274 ScaleScreenInterface::setHandler(sScreen);
270275
271 PluginAdapter::Initialize(screen);276 PluginAdapter::Initialize(screen);
272 AddChild(&WindowManager::Default());277 AddChild(&WindowManager::Default());
@@ -878,9 +883,8 @@
878 if (CompWindow* window = screen->findWindow(target->xid))883 if (CompWindow* window = screen->findWindow(target->xid))
879 {884 {
880 UnityWindow *unity_window = UnityWindow::get(window);885 UnityWindow *unity_window = UnityWindow::get(window);
881 double scale = target->result.width / static_cast<double>(target->geo.width);
882 double parent_alpha = switcher_controller_->Opacity();886 double parent_alpha = switcher_controller_->Opacity();
883 unity_window->paintThumbnail(target->result, target->alpha, parent_alpha, scale,887 unity_window->paintThumbnail(target->result, target->alpha, parent_alpha, target->scale,
884 target->decoration_height, target->selected);888 target->decoration_height, target->selected);
885 }889 }
886 }890 }
@@ -3603,7 +3607,77 @@
3603 ScheduleRelayout(500);3607 ScheduleRelayout(500);
3604}3608}
36053609
3606void UnityScreen::OnDashRealized ()3610bool UnityScreen::layoutSlotsAndAssignWindows()
3611{
3612 auto const& scaled_windows = sScreen->getWindows();
3613
3614 for (auto const& output : screen->outputDevs())
3615 {
3616 ui::LayoutWindow::Vector layout_windows;
3617 int monitor = UScreen::GetDefault()->GetMonitorAtPosition(output.centerX(), output.centerY());
3618 double monitor_scale = unity_settings_.em(monitor)->DPIScale();
3619
3620 for (ScaleWindow *sw : scaled_windows)
3621 {
3622 if (sw->window->outputDevice() == static_cast<int>(output.id()))
3623 {
3624 UnityWindow::get(sw->window)->deco_win_->scaled = true;
3625 layout_windows.emplace_back(std::make_shared<LayoutWindow>(sw->window->id()));
3626 }
3627 }
3628
3629 auto max_bounds = NuxGeometryFromCompRect(output.workArea());
3630
3631 if (launcher_controller_->options()->hide_mode != LAUNCHER_HIDE_NEVER)
3632 {
3633 int monitor_width = unity_settings_.LauncherWidth(monitor);
3634 max_bounds.x += monitor_width;
3635 max_bounds.width -= monitor_width;
3636 }
3637
3638 nux::Geometry final_bounds;
3639 ui::LayoutSystem layout;
3640 layout.max_row_height = max_bounds.height;
3641 layout.spacing = local::SCALE_SPACING.CP(monitor_scale);
3642 int padding = local::SCALE_PADDING.CP(monitor_scale);
3643 max_bounds.Expand(-padding, -padding);
3644 layout.LayoutWindows(layout_windows, max_bounds, final_bounds);
3645
3646 auto lw_it = layout_windows.begin();
3647 for (auto const& sw : scaled_windows)
3648 {
3649 if (lw_it == layout_windows.end())
3650 break;
3651
3652 LayoutWindow::Ptr const& lw = *lw_it;
3653
3654 if (sw->window->id() != lw->xid)
3655 continue;
3656
3657 ScaleSlot slot(CompRectFromNuxGeo(lw->result));
3658 slot.scale = lw->scale;
3659
3660 float sx = lw->geo.width * slot.scale;
3661 float sy = lw->geo.height * slot.scale;
3662 float cx = (slot.x1() + slot.x2()) / 2;
3663 float cy = (slot.y1() + slot.y2()) / 2;
3664
3665 CompWindow *w = sw->window;
3666 cx += w->input().left * slot.scale;
3667 cy += w->input().top * slot.scale;
3668
3669 slot.setGeometry(cx - sx / 2, cy - sy / 2, sx, sy);
3670 slot.filled = true;
3671
3672 sw->setSlot(slot);
3673 ++lw_it;
3674 }
3675 }
3676
3677 return true;
3678}
3679
3680void UnityScreen::OnDashRealized()
3607{3681{
3608 /* stack any windows named "onboard" above us */3682 /* stack any windows named "onboard" above us */
3609 for (CompWindow *w : screen->windows ())3683 for (CompWindow *w : screen->windows ())
@@ -3663,6 +3737,7 @@
3663 auto shortcuts_modeller = std::make_shared<shortcut::CompizModeller>();3737 auto shortcuts_modeller = std::make_shared<shortcut::CompizModeller>();
3664 shortcut_controller_ = std::make_shared<shortcut::Controller>(base_window_raiser, shortcuts_modeller);3738 shortcut_controller_ = std::make_shared<shortcut::Controller>(base_window_raiser, shortcuts_modeller);
3665 AddChild(shortcut_controller_.get());3739 AddChild(shortcut_controller_.get());
3740 ShowFirstRunHints();
36663741
3667 // Setup Session Controller3742 // Setup Session Controller
3668 auto manager = std::make_shared<session::GnomeManager>();3743 auto manager = std::make_shared<session::GnomeManager>();
@@ -3742,6 +3817,41 @@
3742 return menus_->KeyGrabber()->GetActions();3817 return menus_->KeyGrabber()->GetActions();
3743}3818}
37443819
3820void UnityScreen::ShowFirstRunHints()
3821{
3822 sources_.AddTimeoutSeconds(1, [this] {
3823 auto const& cache_dir = glib::gchar_to_string(g_get_user_cache_dir())+"/unity/";
3824 if (!g_file_test((cache_dir+local::FIRST_RUN_STAMP).c_str(), G_FILE_TEST_EXISTS))
3825 {
3826 // We focus the panel, so the shortcut hint will be hidden at first user input
3827 auto const& panels = panel_controller_->panels();
3828 if (!panels.empty())
3829 {
3830 auto panel_win = static_cast<nux::BaseWindow*>(panels.front()->GetTopLevelViewWindow());
3831 SaveInputThenFocus(panel_win->GetInputWindowId());
3832 }
3833 shortcut_controller_->first_run = true;
3834 shortcut_controller_->Show();
3835
3836 if (g_mkdir_with_parents(cache_dir.c_str(), 0700) >= 0)
3837 {
3838 glib::Error error;
3839 g_file_set_contents((cache_dir+local::FIRST_RUN_STAMP).c_str(), "", 0, &error);
3840
3841 if (error)
3842 {
3843 LOG_ERROR(logger) << "Impossible to save the unity stamp file: " << error;
3844 }
3845 }
3846 else
3847 {
3848 LOG_ERROR(logger) << "Impossible to create unity cache folder!";
3849 }
3850 }
3851 return false;
3852 });
3853}
3854
3745/* Window init */3855/* Window init */
37463856
3747namespace3857namespace
37483858
=== modified file 'plugins/unityshell/src/unityshell.h'
--- plugins/unityshell/src/unityshell.h 2014-03-07 03:37:43 +0000
+++ plugins/unityshell/src/unityshell.h 2014-03-12 23:00:55 +0000
@@ -109,6 +109,7 @@
109 public ScreenInterface,109 public ScreenInterface,
110 public CompositeScreenInterface,110 public CompositeScreenInterface,
111 public GLScreenInterface,111 public GLScreenInterface,
112 public ScaleScreenInterface,
112 public BaseSwitchScreen,113 public BaseSwitchScreen,
113 public PluginClassHandler <UnityScreen, CompScreen>,114 public PluginClassHandler <UnityScreen, CompScreen>,
114 public CompAction::Container,115 public CompAction::Container,
@@ -172,6 +173,9 @@
172 void enterShowDesktopMode ();173 void enterShowDesktopMode ();
173 void leaveShowDesktopMode (CompWindow *w);174 void leaveShowDesktopMode (CompWindow *w);
174175
176 /* window scaling */
177 bool layoutSlotsAndAssignWindows();
178
175 bool showMenuBarInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);179 bool showMenuBarInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
176 bool showMenuBarTerminate(CompAction* action, CompAction::State state, CompOption::Vector& options);180 bool showMenuBarTerminate(CompAction* action, CompAction::State state, CompOption::Vector& options);
177 bool showLauncherKeyInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);181 bool showLauncherKeyInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
@@ -306,6 +310,8 @@
306310
307 void DamageBlurUpdateRegion(nux::Geometry const&);311 void DamageBlurUpdateRegion(nux::Geometry const&);
308312
313 void ShowFirstRunHints();
314
309 std::unique_ptr<na::TickSource> tick_source_;315 std::unique_ptr<na::TickSource> tick_source_;
310 std::unique_ptr<na::AnimationController> animation_controller_;316 std::unique_ptr<na::AnimationController> animation_controller_;
311317
312318
=== modified file 'shortcuts/ShortcutController.cpp'
--- shortcuts/ShortcutController.cpp 2013-11-20 21:39:40 +0000
+++ shortcuts/ShortcutController.cpp 2014-03-12 23:00:55 +0000
@@ -37,7 +37,8 @@
3737
38Controller::Controller(BaseWindowRaiser::Ptr const& base_window_raiser,38Controller::Controller(BaseWindowRaiser::Ptr const& base_window_raiser,
39 AbstractModeller::Ptr const& modeller)39 AbstractModeller::Ptr const& modeller)
40 : modeller_(modeller)40 : first_run(false)
41 , modeller_(modeller)
41 , base_window_raiser_(base_window_raiser)42 , base_window_raiser_(base_window_raiser)
42 , visible_(false)43 , visible_(false)
43 , enabled_(true)44 , enabled_(true)
@@ -155,6 +156,7 @@
155 AddChild(view_.GetPointer());156 AddChild(view_.GetPointer());
156 view_->SetModel(modeller_->GetCurrentModel());157 view_->SetModel(modeller_->GetCurrentModel());
157 view_->background_color = WindowManager::Default().average_color();158 view_->background_color = WindowManager::Default().average_color();
159 view_->closable = first_run();
158160
159 if (!view_window_)161 if (!view_window_)
160 {162 {
@@ -197,6 +199,8 @@
197 if (view_window_ && view_window_->GetOpacity() > 0.0f)199 if (view_window_ && view_window_->GetOpacity() > 0.0f)
198 {200 {
199 view_->live_background = false;201 view_->live_background = false;
202 view_->closable = false;
203 first_run = false;
200 animation::StartOrReverse(fade_animator_, animation::Direction::BACKWARD);204 animation::StartOrReverse(fade_animator_, animation::Direction::BACKWARD);
201 }205 }
202}206}
203207
=== modified file 'shortcuts/ShortcutController.h'
--- shortcuts/ShortcutController.h 2013-11-14 00:17:19 +0000
+++ shortcuts/ShortcutController.h 2014-03-12 23:00:55 +0000
@@ -47,6 +47,8 @@
47 Controller(BaseWindowRaiser::Ptr const& raiser, AbstractModeller::Ptr const& modeller);47 Controller(BaseWindowRaiser::Ptr const& raiser, AbstractModeller::Ptr const& modeller);
48 virtual ~Controller();48 virtual ~Controller();
4949
50 nux::Property<bool> first_run;
51
50 bool Show();52 bool Show();
51 void Hide();53 void Hide();
5254
5355
=== modified file 'tests/test_layout_system.cpp'
--- tests/test_layout_system.cpp 2013-10-14 17:36:51 +0000
+++ tests/test_layout_system.cpp 2014-03-12 23:00:55 +0000
@@ -57,6 +57,7 @@
57 EXPECT_EQ(lwin.geo, fake_window->geo);57 EXPECT_EQ(lwin.geo, fake_window->geo);
58 EXPECT_EQ(lwin.decoration_height, 0);58 EXPECT_EQ(lwin.decoration_height, 0);
59 EXPECT_EQ(lwin.selected, false);59 EXPECT_EQ(lwin.selected, false);
60 EXPECT_FLOAT_EQ(lwin.scale, 1.0f);
60 EXPECT_EQ(lwin.aspect_ratio, fake_window->geo().width / static_cast<float>(fake_window->geo().height));61 EXPECT_EQ(lwin.aspect_ratio, fake_window->geo().width / static_cast<float>(fake_window->geo().height));
61}62}
6263
6364
=== modified file 'tests/test_shortcut_controller.cpp'
--- tests/test_shortcut_controller.cpp 2013-09-25 00:48:03 +0000
+++ tests/test_shortcut_controller.cpp 2014-03-12 23:00:55 +0000
@@ -68,6 +68,7 @@
68 MOCK_METHOD1(SetOpacity, void(double));68 MOCK_METHOD1(SetOpacity, void(double));
69 using Controller::GetOffsetPerMonitor;69 using Controller::GetOffsetPerMonitor;
70 using Controller::ConstructView;70 using Controller::ConstructView;
71 using Controller::OnShowTimer;
71 using Controller::view_;72 using Controller::view_;
7273
73 void RealSetOpacity(double value)74 void RealSetOpacity(double value)
@@ -188,5 +189,37 @@
188 color_property.changed.emit(nux::color::RandomColor());189 color_property.changed.emit(nux::color::RandomColor());
189}190}
190191
192TEST_F(TestShortcutController, FirstRunFalse)
193{
194 ASSERT_FALSE(controller_.first_run());
195
196 controller_.ConstructView();
197 EXPECT_FALSE(controller_.view_->closable());
198}
199
200TEST_F(TestShortcutController, FirstRunTrue)
201{
202 ASSERT_FALSE(controller_.first_run());
203
204 controller_.first_run = true;
205 controller_.ConstructView();
206 EXPECT_TRUE(controller_.view_->closable());
207}
208
209TEST_F(TestShortcutController, UnsetFirstRunOnHide)
210{
211 controller_.first_run = true;
212 controller_.ConstructView();
213
214 ASSERT_TRUE(controller_.view_->closable());
215 controller_.Show();
216 controller_.OnShowTimer();
217 tick_source_.tick(100 * 1000);
218 controller_.Hide();
219
220 EXPECT_FALSE(controller_.first_run());
221 EXPECT_FALSE(controller_.view_->closable());
222}
223
191}224}
192}225}
193226
=== modified file 'unity-shared/LayoutSystem.cpp'
--- unity-shared/LayoutSystem.cpp 2013-09-19 16:44:03 +0000
+++ unity-shared/LayoutSystem.cpp 2014-03-12 23:00:55 +0000
@@ -125,12 +125,12 @@
125 for (LayoutWindow::Ptr const& window : row)125 for (LayoutWindow::Ptr const& window : row)
126 {126 {
127 // we dont allow scaling up127 // we dont allow scaling up
128 float final_scalar = std::min(1.0f, (unpadded_bounds.height / (float)window->geo.height) * global_scalar);128 window->scale = std::min(1.0f, (unpadded_bounds.height / (float)window->geo.height) * global_scalar);
129129
130 window->result.x = x;130 window->result.x = x;
131 window->result.y = y;131 window->result.y = y;
132 window->result.width = window->geo.width * final_scalar;132 window->result.width = window->geo.width * window->scale;
133 window->result.height = window->geo.height * final_scalar;133 window->result.height = window->geo.height * window->scale;
134134
135 x += window->result.width;135 x += window->result.width;
136 }136 }
@@ -275,6 +275,7 @@
275 , decoration_height(0)275 , decoration_height(0)
276 , selected(false)276 , selected(false)
277 , aspect_ratio(geo.width / static_cast<float>(geo.height))277 , aspect_ratio(geo.width / static_cast<float>(geo.height))
278 , scale(1.0f)
278 , alpha(0.0f)279 , alpha(0.0f)
279{280{
280 auto& wm = WindowManager::Default();281 auto& wm = WindowManager::Default();
281282
=== modified file 'unity-shared/LayoutSystem.h'
--- unity-shared/LayoutSystem.h 2013-09-19 16:44:03 +0000
+++ unity-shared/LayoutSystem.h 2014-03-12 23:00:55 +0000
@@ -46,6 +46,7 @@
4646
47 bool selected;47 bool selected;
48 float aspect_ratio;48 float aspect_ratio;
49 float scale;
49 float alpha;50 float alpha;
5051
51protected:52protected: