Merge lp:~3v1n0/unity/super-arrows-shortcuts 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: 3509
Proposed branch: lp:~3v1n0/unity/super-arrows-shortcuts
Merge into: lp:unity
Diff against target: 595 lines (+318/-20)
10 files modified
plugins/unityshell/src/unityshell.cpp (+23/-0)
plugins/unityshell/src/unityshell.h (+2/-0)
plugins/unityshell/unityshell.xml.in (+12/-0)
shortcuts/CompizShortcutModeller.cpp (+11/-11)
tests/autopilot/unity/tests/test_wm_keybindings.py (+110/-0)
unity-shared/PluginAdapter.cpp (+69/-0)
unity-shared/PluginAdapter.h (+8/-0)
unity-shared/StandaloneWindowManager.cpp (+71/-7)
unity-shared/StandaloneWindowManager.h (+7/-1)
unity-shared/WindowManager.h (+5/-1)
To merge this branch: bzr merge lp:~3v1n0/unity/super-arrows-shortcuts
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Christopher Townsend Approve
Alex Launi Pending
Review via email: mp+185850@code.launchpad.net

This proposal supersedes a proposal from 2012-01-28.

Commit message

UnityScreen: add support for Super+Arrows shortcuts to manage the focused window

Super+Arrows shortcut allows to move and maximize / restore / minimize
the focused window on the screen.

Description of the change

Added the Super+Left/Right arrows shortcuts support to manage the focused window, as defined on bug #751050

This branch requires lp:~3v1n0/autopilot/window-left+right-maximize-keys in order to make the tests pass.
The fixes is also complete when lp:~3v1n0/compiz/unity-wm-shortcuts-0.9.11 merges

To post a comment you must log in.
Revision history for this message
Alex Launi (alexlauni) wrote : Posted in a previous version of this proposal

These tests could be written with autopilot. Please make the necessary adjustments to automate these tests.

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Christopher Townsend (townsend) wrote :

Works great!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugins/unityshell/src/unityshell.cpp'
--- plugins/unityshell/src/unityshell.cpp 2013-09-12 03:12:04 +0000
+++ plugins/unityshell/src/unityshell.cpp 2013-09-16 16:11:09 +0000
@@ -349,6 +349,9 @@
349 optionSetLauncherSwitcherPrevInitiate(boost::bind(&UnityScreen::launcherSwitcherPrevInitiate, this, _1, _2, _3));349 optionSetLauncherSwitcherPrevInitiate(boost::bind(&UnityScreen::launcherSwitcherPrevInitiate, this, _1, _2, _3));
350 optionSetLauncherSwitcherForwardTerminate(boost::bind(&UnityScreen::launcherSwitcherTerminate, this, _1, _2, _3));350 optionSetLauncherSwitcherForwardTerminate(boost::bind(&UnityScreen::launcherSwitcherTerminate, this, _1, _2, _3));
351351
352 optionSetWindowRightMaximizeInitiate(boost::bind(&UnityScreen::rightMaximizeKeyInitiate, this, _1, _2, _3));
353 optionSetWindowLeftMaximizeInitiate(boost::bind(&UnityScreen::leftMaximizeKeyInitiate, this, _1, _2, _3));
354
352 optionSetStopVelocityNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));355 optionSetStopVelocityNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
353 optionSetRevealPressureNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));356 optionSetRevealPressureNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
354 optionSetEdgeResponsivenessNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));357 optionSetEdgeResponsivenessNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
@@ -2136,12 +2139,14 @@
2136 action->setState(action->state() | CompAction::StateTermKey);2139 action->setState(action->state() | CompAction::StateTermKey);
2137 return true;2140 return true;
2138}2141}
2142
2139bool UnityScreen::launcherSwitcherPrevInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options)2143bool UnityScreen::launcherSwitcherPrevInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options)
2140{2144{
2141 launcher_controller_->KeyNavPrevious();2145 launcher_controller_->KeyNavPrevious();
21422146
2143 return true;2147 return true;
2144}2148}
2149
2145bool UnityScreen::launcherSwitcherTerminate(CompAction* action, CompAction::State state, CompOption::Vector& options)2150bool UnityScreen::launcherSwitcherTerminate(CompAction* action, CompAction::State state, CompOption::Vector& options)
2146{2151{
2147 bool accept_state = (state & CompAction::StateCancel) == 0;2152 bool accept_state = (state & CompAction::StateCancel) == 0;
@@ -2164,6 +2169,20 @@
2164 return true;2169 return true;
2165}2170}
21662171
2172bool UnityScreen::rightMaximizeKeyInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options)
2173{
2174 auto& WM = WindowManager::Default();
2175 WM.RightMaximize(WM.GetActiveWindow());
2176 return true;
2177}
2178
2179bool UnityScreen::leftMaximizeKeyInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options)
2180{
2181 auto& WM = WindowManager::Default();
2182 WM.LeftMaximize(WM.GetActiveWindow());
2183 return true;
2184}
2185
2167void UnityScreen::OnLauncherStartKeyNav(GVariant* data)2186void UnityScreen::OnLauncherStartKeyNav(GVariant* data)
2168{2187{
2169 // Put the launcher BaseWindow at the top of the BaseWindow stack. The2188 // Put the launcher BaseWindow at the top of the BaseWindow stack. The
@@ -3554,6 +3573,10 @@
3554 .add("xid", (uint64_t)xid)3573 .add("xid", (uint64_t)xid)
3555 .add("title", wm.GetWindowName(xid))3574 .add("title", wm.GetWindowName(xid))
3556 .add("fake_decorated", uScreen->fake_decorated_windows_.find(this) != uScreen->fake_decorated_windows_.end())3575 .add("fake_decorated", uScreen->fake_decorated_windows_.find(this) != uScreen->fake_decorated_windows_.end())
3576 .add("maximized", wm.IsWindowVerticallyMaximized(xid))
3577 .add("horizontally_maximized", wm.IsWindowHorizontallyMaximized(xid))
3578 .add("vertically_maximized", wm.IsWindowVerticallyMaximized(xid))
3579 .add("minimized", wm.IsWindowMinimized(xid))
3557 .add("scaled", scaled)3580 .add("scaled", scaled)
3558 .add("scaled_close_x", close_button_geo_.x)3581 .add("scaled_close_x", close_button_geo_.x)
3559 .add("scaled_close_y", close_button_geo_.y)3582 .add("scaled_close_y", close_button_geo_.y)
35603583
=== modified file 'plugins/unityshell/src/unityshell.h'
--- plugins/unityshell/src/unityshell.h 2013-08-08 23:04:44 +0000
+++ plugins/unityshell/src/unityshell.h 2013-09-16 16:11:09 +0000
@@ -165,6 +165,8 @@
165 bool launcherSwitcherForwardInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);165 bool launcherSwitcherForwardInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
166 bool launcherSwitcherPrevInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);166 bool launcherSwitcherPrevInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
167 bool launcherSwitcherTerminate(CompAction* action, CompAction::State state, CompOption::Vector& options);167 bool launcherSwitcherTerminate(CompAction* action, CompAction::State state, CompOption::Vector& options);
168 bool rightMaximizeKeyInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
169 bool leftMaximizeKeyInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
168170
169 /* handle option changes and change settings inside of the171 /* handle option changes and change settings inside of the
170 * panel and dock views */172 * panel and dock views */
171173
=== modified file 'plugins/unityshell/unityshell.xml.in'
--- plugins/unityshell/unityshell.xml.in 2013-09-11 19:32:34 +0000
+++ plugins/unityshell/unityshell.xml.in 2013-09-16 16:11:09 +0000
@@ -68,6 +68,18 @@
68 <default>&lt;Alt&gt;F10</default>68 <default>&lt;Alt&gt;F10</default>
69 </option>69 </option>
7070
71 <option name="window_right_maximize" type="key">
72 <_short>Key to vertically maximize the focused window to the right</_short>
73 <_long>Semi-maximize vertically the focused window on the half right width of the screen</_long>
74 <default>&lt;Control&gt;&lt;Super&gt;Right</default>
75 </option>
76
77 <option name="window_left_maximize" type="key">
78 <_short>Key to vertically maximize the focused window to the left</_short>
79 <_long>Semi-maximize vertically the focused window to the half left width of the screen</_long>
80 <default>&lt;Control&gt;&lt;Super&gt;Left</default>
81 </option>
82
71 <option name="panel_opacity" type="float">83 <option name="panel_opacity" type="float">
72 <_short>Panel Opacity</_short>84 <_short>Panel Opacity</_short>
73 <_long>The opacity of the Panel background.</_long>85 <_long>The opacity of the Panel background.</_long>
7486
=== modified file 'shortcuts/CompizShortcutModeller.cpp'
--- shortcuts/CompizShortcutModeller.cpp 2013-07-07 02:46:28 +0000
+++ shortcuts/CompizShortcutModeller.cpp 2013-09-16 16:11:09 +0000
@@ -32,7 +32,6 @@
32 // Compiz' plug-in names32 // Compiz' plug-in names
33 const std::string CORE_PLUGIN_NAME = "core";33 const std::string CORE_PLUGIN_NAME = "core";
34 const std::string EXPO_PLUGIN_NAME = "expo";34 const std::string EXPO_PLUGIN_NAME = "expo";
35 const std::string GRID_PLUGIN_NAME = "grid";
36 const std::string MOVE_PLUGIN_NAME = "move";35 const std::string MOVE_PLUGIN_NAME = "move";
37 const std::string RESIZE_PLUGIN_NAME = "resize";36 const std::string RESIZE_PLUGIN_NAME = "resize";
38 const std::string SCALE_PLUGIN_NAME = "scale";37 const std::string SCALE_PLUGIN_NAME = "scale";
@@ -41,17 +40,14 @@
4140
42 // Compiz Core Options41 // Compiz Core Options
43 const std::string CORE_OPTION_SHOW_DESKTOP_KEY = "show_desktop_key";42 const std::string CORE_OPTION_SHOW_DESKTOP_KEY = "show_desktop_key";
44 const std::string CORE_OPTION_MAXIMIZE_WINDOW_KEY = "maximize_window_key";43 const std::string CORE_OPTION_MAXIMIZE_KEY = "maximize_window_key";
45 const std::string CORE_OPTION_UNMAXIMIZE_OR_MINIMIZE_WINDOW_KEY = "unmaximize_or_minimize_window_key";44 const std::string CORE_OPTION_RESTORE_MINIMIZE_KEY = "unmaximize_or_minimize_window_key";
46 const std::string CORE_OPTION_CLOSE_WINDOW_KEY = "close_window_key";45 const std::string CORE_OPTION_CLOSE_WINDOW_KEY = "close_window_key";
47 const std::string CORE_OPTION_WINDOW_MENU_KEY = "window_menu_key";46 const std::string CORE_OPTION_WINDOW_MENU_KEY = "window_menu_key";
4847
49 // Compiz Expo Options48 // Compiz Expo Options
50 const std::string EXPO_OPTION_EXPO_KEY = "expo_key";49 const std::string EXPO_OPTION_EXPO_KEY = "expo_key";
5150
52 // Compiz Grid Options
53 const std::string GRID_OPTION_PUT_LEFT_KEY = "put_left_key";
54
55 // Compiz Move Options51 // Compiz Move Options
56 const std::string MOVE_OPTION_INITIATE_BUTTON = "initiate_button";52 const std::string MOVE_OPTION_INITIATE_BUTTON = "initiate_button";
5753
@@ -69,6 +65,10 @@
69 const std::string UNITYSHELL_OPTION_PANEL_FIRST_MENU = "panel_first_menu";65 const std::string UNITYSHELL_OPTION_PANEL_FIRST_MENU = "panel_first_menu";
70 const std::string UNITYSHELL_OPTION_ALT_TAB_FORWARD = "alt_tab_forward";66 const std::string UNITYSHELL_OPTION_ALT_TAB_FORWARD = "alt_tab_forward";
71 const std::string UNITYSHELL_OPTION_ALT_TAB_NEXT_WINDOW = "alt_tab_next_window";67 const std::string UNITYSHELL_OPTION_ALT_TAB_NEXT_WINDOW = "alt_tab_next_window";
68 const std::string UNITYSHELL_OPTION_MAXIMIZE = "window_maximize";
69 const std::string UNITYSHELL_OPTION_LEFT_MAXIMIZE = "window_left_maximize";
70 const std::string UNITYSHELL_OPTION_RIGHT_MAXIMIZE = "window_right_maximize";
71 const std::string UNITYSHELL_OPTION_RESTORE_MINIMIZE = "window_restore_minimize";
7272
73 // Compiz Wall Options73 // Compiz Wall Options
74 const std::string WALL_OPTION_LEFT_KEY = "left_key";74 const std::string WALL_OPTION_LEFT_KEY = "left_key";
@@ -304,19 +304,19 @@
304 _("Maximises the current window."),304 _("Maximises the current window."),
305 shortcut::OptionType::COMPIZ_KEY,305 shortcut::OptionType::COMPIZ_KEY,
306 CORE_PLUGIN_NAME,306 CORE_PLUGIN_NAME,
307 CORE_OPTION_MAXIMIZE_WINDOW_KEY));307 CORE_OPTION_MAXIMIZE_KEY));
308308
309 hints.push_back(std::make_shared<shortcut::Hint>(windows, "", "",309 hints.push_back(std::make_shared<shortcut::Hint>(windows, "", "",
310 _("Restores or minimises the current window."),310 _("Restores or minimises the current window."),
311 shortcut::OptionType::COMPIZ_KEY,311 shortcut::OptionType::COMPIZ_KEY,
312 CORE_PLUGIN_NAME,312 CORE_PLUGIN_NAME,
313 CORE_OPTION_UNMAXIMIZE_OR_MINIMIZE_WINDOW_KEY));313 CORE_OPTION_RESTORE_MINIMIZE_KEY));
314314
315 hints.push_back(std::make_shared<shortcut::Hint>(windows, "", _(" or Right"),315 hints.push_back(std::make_shared<shortcut::Hint>(windows, "", _(" or Right"),
316 _("Semi-maximise the current window."),316 _("Semi-maximise the current window."),
317 shortcut::OptionType::COMPIZ_KEY,317 shortcut::OptionType::COMPIZ_KEY,
318 GRID_PLUGIN_NAME,318 UNITYSHELL_PLUGIN_NAME,
319 GRID_OPTION_PUT_LEFT_KEY));319 UNITYSHELL_OPTION_LEFT_MAXIMIZE));
320320
321 hints.push_back(std::make_shared<shortcut::Hint>(windows, "", "",321 hints.push_back(std::make_shared<shortcut::Hint>(windows, "", "",
322 _("Closes the current window."),322 _("Closes the current window."),
@@ -333,7 +333,7 @@
333 hints.push_back(std::make_shared<shortcut::Hint>(windows, "", "",333 hints.push_back(std::make_shared<shortcut::Hint>(windows, "", "",
334 _("Places the window in corresponding position."),334 _("Places the window in corresponding position."),
335 shortcut::OptionType::HARDCODED,335 shortcut::OptionType::HARDCODED,
336 _("Ctrl + Alt + Num")));336 _("Ctrl + Alt + Num (keypad)")));
337337
338 hints.push_back(std::make_shared<shortcut::Hint>(windows, "", _(" Drag"),338 hints.push_back(std::make_shared<shortcut::Hint>(windows, "", _(" Drag"),
339 _("Moves the window."),339 _("Moves the window."),
340340
=== added file 'tests/autopilot/unity/tests/test_wm_keybindings.py'
--- tests/autopilot/unity/tests/test_wm_keybindings.py 1970-01-01 00:00:00 +0000
+++ tests/autopilot/unity/tests/test_wm_keybindings.py 2013-09-16 16:11:09 +0000
@@ -0,0 +1,110 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2# Copyright 2013 Canonical
3# Author: Marco Trevisan (Treviño)
4#
5# This program is free software: you can redistribute it and/or modify it
6# under the terms of the GNU General Public License version 3, as published
7# by the Free Software Foundation.
8
9from __future__ import absolute_import
10
11from autopilot.matchers import Eventually
12from testtools.matchers import Equals, NotEquals
13from unity.tests import UnityTestCase
14
15class WindowManagerKeybindings(UnityTestCase):
16 """Window Manager keybindings tests"""
17
18 scenarios = [('Restored Window', {'start_restored': True}),
19 ('Maximized Window', {'start_restored': False})]
20
21 def setUp(self):
22 super(WindowManagerKeybindings, self).setUp()
23 self.start_test_window()
24
25 def keybinding_if_not_minimized(self, keybinding):
26 if not self.screen_win.minimized:
27 self.keybinding(keybinding)
28
29 def keybinding_if_not_restored(self, keybinding):
30 if self.screen_win.vertically_maximized or self.screen_win.horizontally_maximized:
31 self.keybinding(keybinding)
32
33 def start_test_window(self, app_name="Character Map"):
34 """Start a restored/maximized window of the requested application"""
35 self.process_manager.close_all_app(app_name)
36 self.bamf_win = self.process_manager.start_app_window(app_name)
37 win_fn = lambda: self.unity.screen.window(self.bamf_win.x_id)
38 self.assertThat(win_fn, Eventually(NotEquals(None)))
39 self.screen_win = win_fn()
40
41 if self.start_restored:
42 if self.screen_win.vertically_maximized or self.screen_win.horizontally_maximized:
43 self.addCleanup(self.keybinding_if_not_minimized, "window/maximize")
44 self.keybinding("window/restore")
45 else:
46 if not self.screen_win.vertically_maximized and not self.screen_win.horizontally_maximized:
47 self.addCleanup(self.keybinding_if_not_restored, "window/restore")
48 self.keybinding("window/maximize")
49
50 def get_window_workarea(self):
51 monitor = self.bamf_win.monitor
52 monitor_geo = self.display.get_screen_geometry(monitor)
53 launcher = self.unity.launcher.get_launcher_for_monitor(monitor)
54 launcher_w = 0 if launcher.hidemode else launcher.geometry[2]
55 panel_h = self.unity.panels.get_panel_for_monitor(monitor).geometry[3]
56 return (monitor_geo[0] + launcher_w, monitor_geo[1] + panel_h,
57 monitor_geo[2] - launcher_w, monitor_geo[3] - panel_h)
58
59 def test_maximize_window(self):
60 if self.start_restored:
61 self.addCleanup(self.keybinding, "window/restore")
62 self.keybinding("window/maximize")
63 self.assertThat(self.screen_win.maximized, Eventually(Equals(True)))
64
65 def test_restore_maximized_window(self):
66 if self.start_restored:
67 self.keybinding("window/maximize")
68 self.keybinding("window/restore")
69 self.assertThat(self.screen_win.maximized, Eventually(Equals(False)))
70 self.assertThat(self.screen_win.minimized, Eventually(Equals(False)))
71
72 def test_restore_vertically_maximized_window(self):
73 if not self.start_restored:
74 self.addCleanup(self.keybinding, "window/maximize")
75 self.keybinding("window/restore")
76 self.keyboard.press_and_release("Ctrl+Super+Right")
77 self.keybinding("window/restore")
78 self.assertThat(self.screen_win.vertically_maximized, Eventually(Equals(False)))
79 self.assertThat(self.screen_win.minimized, Eventually(Equals(False)))
80
81 def test_minimize_restored_window(self):
82 if not self.start_restored:
83 self.addCleanup(self.keybinding_if_not_minimized, "window/maximize")
84 self.keybinding("window/restore")
85 self.keybinding("window/restore")
86 self.assertThat(self.screen_win.minimized, Eventually(Equals(True)))
87
88 def test_left_maximize(self):
89 self.addCleanup(self.keybinding, "window/restore" if self.start_restored else "window/maximize")
90 self.keyboard.press_and_release("Ctrl+Super+Left")
91 self.assertThat(self.screen_win.vertically_maximized, Eventually(Equals(True)))
92 self.assertThat(self.screen_win.horizontally_maximized, Eventually(Equals(False)))
93
94 workarea_geo = self.get_window_workarea()
95 self.assertThat(self.screen_win.x, Eventually(Equals(workarea_geo[0])))
96 self.assertThat(self.screen_win.y, Eventually(Equals(workarea_geo[1])))
97 self.assertThat(self.screen_win.width, Eventually(Equals(workarea_geo[2]/2)))
98 self.assertThat(self.screen_win.height, Eventually(Equals(workarea_geo[3])))
99
100 def test_right_maximize(self):
101 self.addCleanup(self.keybinding, "window/restore" if self.start_restored else "window/maximize")
102 self.keyboard.press_and_release("Ctrl+Super+Right")
103 self.assertThat(self.screen_win.vertically_maximized, Eventually(Equals(True)))
104 self.assertThat(self.screen_win.horizontally_maximized, Eventually(Equals(False)))
105
106 workarea_geo = self.get_window_workarea()
107 self.assertThat(self.screen_win.x, Eventually(Equals(workarea_geo[0]+workarea_geo[2]/2)))
108 self.assertThat(self.screen_win.y, Eventually(Equals(workarea_geo[1])))
109 self.assertThat(self.screen_win.width, Eventually(Equals(workarea_geo[2]/2)))
110 self.assertThat(self.screen_win.height, Eventually(Equals(workarea_geo[3])))
0111
=== modified file 'unity-shared/PluginAdapter.cpp'
--- unity-shared/PluginAdapter.cpp 2013-08-08 14:43:50 +0000
+++ unity-shared/PluginAdapter.cpp 2013-09-16 16:11:09 +0000
@@ -461,6 +461,22 @@
461 return false;461 return false;
462}462}
463463
464bool PluginAdapter::IsWindowVerticallyMaximized(Window window_id) const
465{
466 if (CompWindow* window = m_Screen->findWindow(window_id))
467 return (window->state() & CompWindowStateMaximizedVertMask);
468
469 return false;
470}
471
472bool PluginAdapter::IsWindowHorizontallyMaximized(Window window_id) const
473{
474 if (CompWindow* window = m_Screen->findWindow(window_id))
475 return (window->state() & CompWindowStateMaximizedHorzMask);
476
477 return false;
478}
479
464unsigned long PluginAdapter::GetMwnDecorations(Window window_id) const480unsigned long PluginAdapter::GetMwnDecorations(Window window_id) const
465{481{
466 Display* display = m_Screen->dpy();482 Display* display = m_Screen->dpy();
@@ -697,6 +713,59 @@
697 window->maximize(MAXIMIZE_STATE);713 window->maximize(MAXIMIZE_STATE);
698}714}
699715
716void PluginAdapter::VerticallyMaximizeWindowAt(CompWindow* window, nux::Geometry const& geo)
717{
718 if (window && ((window->type() & CompWindowTypeNormalMask) ||
719 ((window->actions() & CompWindowActionMaximizeVertMask) &&
720 window->actions() & CompWindowActionResizeMask)))
721 {
722 /* First we unmaximize the Window */
723 if (window->state() & MAXIMIZE_STATE)
724 window->maximize(0);
725
726 /* Then we vertically maximize the it so it can be unminimized correctly */
727 if (!(window->state() & CompWindowStateMaximizedVertMask))
728 window->maximize(CompWindowStateMaximizedVertMask);
729
730 /* Then we resize and move it on the requested place */
731 MoveResizeWindow(window->id(), geo);
732 }
733}
734
735void PluginAdapter::LeftMaximize(Window window_id)
736{
737 CompWindow* window = m_Screen->findWindow(window_id);
738
739 if (!window)
740 return;
741
742 /* Let's compute the area where the window should stay */
743 CompRect workarea = m_Screen->getWorkareaForOutput(window->outputDevice());
744 nux::Geometry win_geo(workarea.x() + window->border().left,
745 workarea.y() + window->border().top,
746 workarea.width() / 2 - (window->border().left + window->border().right),
747 workarea.height() - (window->border().top + window->border().bottom));
748
749 VerticallyMaximizeWindowAt(window, win_geo);
750}
751
752void PluginAdapter::RightMaximize(Window window_id)
753{
754 CompWindow* window = m_Screen->findWindow(window_id);
755
756 if (!window)
757 return;
758
759 /* Let's compute the area where the window should stay */
760 CompRect workarea = m_Screen->getWorkareaForOutput(window->outputDevice());
761 nux::Geometry win_geo(workarea.x() + workarea.width() / 2 + window->border().left,
762 workarea.y() + window->border().top,
763 workarea.width() / 2 - (window->border().left + window->border().right),
764 workarea.height() - (window->border().top + window->border().bottom));
765
766 VerticallyMaximizeWindowAt(window, win_geo);
767}
768
700void PluginAdapter::Restore(Window window_id)769void PluginAdapter::Restore(Window window_id)
701{770{
702 CompWindow* window = m_Screen->findWindow(window_id);771 CompWindow* window = m_Screen->findWindow(window_id);
703772
=== modified file 'unity-shared/PluginAdapter.h'
--- unity-shared/PluginAdapter.h 2013-08-08 14:43:50 +0000
+++ unity-shared/PluginAdapter.h 2013-09-16 16:11:09 +0000
@@ -130,6 +130,8 @@
130130
131 // WindowManager implementation131 // WindowManager implementation
132 bool IsWindowMaximized(Window window_id) const;132 bool IsWindowMaximized(Window window_id) const;
133 bool IsWindowVerticallyMaximized(Window window_id) const;
134 bool IsWindowHorizontallyMaximized(Window window_id) const;
133 bool IsWindowDecorated(Window window_id) const;135 bool IsWindowDecorated(Window window_id) const;
134 bool IsWindowOnCurrentDesktop(Window window_id) const;136 bool IsWindowOnCurrentDesktop(Window window_id) const;
135 bool IsWindowObscured(Window window_id) const;137 bool IsWindowObscured(Window window_id) const;
@@ -143,6 +145,8 @@
143 bool HasWindowDecorations(Window window_id) const;145 bool HasWindowDecorations(Window window_id) const;
144146
145 void Maximize(Window window_id);147 void Maximize(Window window_id);
148 void LeftMaximize(Window window_id);
149 void RightMaximize(Window window_id);
146 void Restore(Window window_id);150 void Restore(Window window_id);
147 void RestoreAt(Window window_id, int x, int y);151 void RestoreAt(Window window_id, int x, int y);
148 void Minimize(Window window_id);152 void Minimize(Window window_id);
@@ -196,6 +200,8 @@
196200
197 Window GetTopWindowAbove(Window xid) const;201 Window GetTopWindowAbove(Window xid) const;
198202
203 void MoveResizeWindow(guint32 xid, nux::Geometry geometry);
204
199protected:205protected:
200 PluginAdapter(CompScreen* screen);206 PluginAdapter(CompScreen* screen);
201 void AddProperties(GVariantBuilder* builder);207 void AddProperties(GVariantBuilder* builder);
@@ -215,6 +221,8 @@
215 std::string GetUtf8Property(Window xid, Atom atom) const;221 std::string GetUtf8Property(Window xid, Atom atom) const;
216 std::vector<long> GetCardinalProperty(Window xid, Atom atom) const;222 std::vector<long> GetCardinalProperty(Window xid, Atom atom) const;
217223
224 void VerticallyMaximizeWindowAt(CompWindow* window, nux::Geometry const& geo);
225
218 CompScreen* m_Screen;226 CompScreen* m_Screen;
219 MultiActionList m_ExpoActionList;227 MultiActionList m_ExpoActionList;
220 MultiActionList m_ScaleActionList;228 MultiActionList m_ScaleActionList;
221229
=== modified file 'unity-shared/StandaloneWindowManager.cpp'
--- unity-shared/StandaloneWindowManager.cpp 2013-08-08 14:43:50 +0000
+++ unity-shared/StandaloneWindowManager.cpp 2013-09-16 16:11:09 +0000
@@ -43,7 +43,8 @@
43 , active(false)43 , active(false)
44 , mapped(true)44 , mapped(true)
45 , visible(true)45 , visible(true)
46 , maximized(false)46 , v_maximized(false)
47 , h_maximized(false)
47 , minimized(false)48 , minimized(false)
48 , decorated(true)49 , decorated(true)
49 , has_decorations(true)50 , has_decorations(true)
@@ -67,6 +68,20 @@
6768
68 return false;69 return false;
69 });70 });
71
72 maximized.SetGetterFunction([this] { return v_maximized && h_maximized; });
73 maximized.SetSetterFunction([this] (bool value) {
74 if (maximized() == value)
75 return false;
76
77 v_maximized = value;
78 h_maximized = value;
79 decorated = !value;
80 return true;
81 });
82
83 v_maximized.changed.connect([this] (bool value) { maximized.changed.emit(maximized()); });
84 h_maximized.changed.connect([this] (bool value) { maximized.changed.emit(maximized()); });
70}85}
7186
72WindowManagerPtr create_window_manager()87WindowManagerPtr create_window_manager()
@@ -125,6 +140,24 @@
125 return false;140 return false;
126}141}
127142
143bool StandaloneWindowManager::IsWindowVerticallyMaximized(Window window_id) const
144{
145 auto window = GetWindowByXid(window_id);
146 if (window)
147 return window->v_maximized;
148
149 return false;
150}
151
152bool StandaloneWindowManager::IsWindowHorizontallyMaximized(Window window_id) const
153{
154 auto window = GetWindowByXid(window_id);
155 if (window)
156 return window->h_maximized;
157
158 return false;
159}
160
128bool StandaloneWindowManager::IsWindowDecorated(Window window_id) const161bool StandaloneWindowManager::IsWindowDecorated(Window window_id) const
129{162{
130 auto window = GetWindowByXid(window_id);163 auto window = GetWindowByXid(window_id);
@@ -249,20 +282,51 @@
249{282{
250 auto window = GetWindowByXid(window_id);283 auto window = GetWindowByXid(window_id);
251 if (window)284 if (window)
252 {
253 window->maximized = true;285 window->maximized = true;
254 Undecorate(window_id);286}
255 }287
288void StandaloneWindowManager::LeftMaximize(Window window_id)
289{
290 auto window = GetWindowByXid(window_id);
291
292 if (!window)
293 return;
294
295 /* Let's compute the area where the window should be put */
296 auto workarea = GetWorkAreaGeometry(window_id);
297 workarea.width /= 2;
298
299 if (window->maximized)
300 window->maximized = false;
301
302 window->v_maximized = true;
303 MoveResizeWindow(window_id, workarea);
304}
305
306void StandaloneWindowManager::RightMaximize(Window window_id)
307{
308 auto window = GetWindowByXid(window_id);
309
310 if (!window)
311 return;
312
313 /* Let's compute the area where the window should be put */
314 auto workarea = GetWorkAreaGeometry(window_id);
315 workarea.width /= 2;
316 workarea.x += workarea.width;
317
318 if (window->maximized)
319 window->maximized = false;
320
321 window->v_maximized = true;
322 MoveResizeWindow(window_id, workarea);
256}323}
257324
258void StandaloneWindowManager::Restore(Window window_id)325void StandaloneWindowManager::Restore(Window window_id)
259{326{
260 auto window = GetWindowByXid(window_id);327 auto window = GetWindowByXid(window_id);
261 if (window)328 if (window)
262 {
263 window->maximized = false;329 window->maximized = false;
264 Decorate(window_id);
265 }
266}330}
267331
268void StandaloneWindowManager::RestoreAt(Window window_id, int x, int y)332void StandaloneWindowManager::RestoreAt(Window window_id, int x, int y)
269333
=== modified file 'unity-shared/StandaloneWindowManager.h'
--- unity-shared/StandaloneWindowManager.h 2013-08-08 14:43:50 +0000
+++ unity-shared/StandaloneWindowManager.h 2013-09-16 16:11:09 +0000
@@ -48,7 +48,9 @@
48 nux::Property<bool> active;48 nux::Property<bool> active;
49 nux::Property<bool> mapped;49 nux::Property<bool> mapped;
50 nux::Property<bool> visible;50 nux::Property<bool> visible;
51 nux::Property<bool> maximized;51 nux::RWProperty<bool> maximized;
52 nux::Property<bool> v_maximized;
53 nux::Property<bool> h_maximized;
52 nux::Property<bool> minimized;54 nux::Property<bool> minimized;
53 nux::Property<bool> decorated;55 nux::Property<bool> decorated;
54 nux::Property<bool> has_decorations;56 nux::Property<bool> has_decorations;
@@ -70,6 +72,8 @@
70 std::vector<Window> GetWindowsInStackingOrder() const override;72 std::vector<Window> GetWindowsInStackingOrder() const override;
7173
72 virtual bool IsWindowMaximized(Window window_id) const;74 virtual bool IsWindowMaximized(Window window_id) const;
75 virtual bool IsWindowVerticallyMaximized(Window window_id) const;
76 virtual bool IsWindowHorizontallyMaximized(Window window_id) const;
73 virtual bool IsWindowDecorated(Window window_id) const;77 virtual bool IsWindowDecorated(Window window_id) const;
74 virtual bool IsWindowOnCurrentDesktop(Window window_id) const;78 virtual bool IsWindowOnCurrentDesktop(Window window_id) const;
75 virtual bool IsWindowObscured(Window window_id) const;79 virtual bool IsWindowObscured(Window window_id) const;
@@ -86,6 +90,8 @@
86 virtual bool InShowDesktop() const;90 virtual bool InShowDesktop() const;
8791
88 virtual void Maximize(Window window_id);92 virtual void Maximize(Window window_id);
93 virtual void LeftMaximize(Window window_id);
94 virtual void RightMaximize(Window window_id);
89 virtual void Restore(Window window_id);95 virtual void Restore(Window window_id);
90 virtual void RestoreAt(Window window_id, int x, int y);96 virtual void RestoreAt(Window window_id, int x, int y);
91 virtual void Minimize(Window window_id);97 virtual void Minimize(Window window_id);
9298
=== modified file 'unity-shared/WindowManager.h'
--- unity-shared/WindowManager.h 2013-08-08 14:43:50 +0000
+++ unity-shared/WindowManager.h 2013-09-16 16:11:09 +0000
@@ -77,6 +77,9 @@
77 virtual std::vector<Window> GetWindowsInStackingOrder() const = 0;77 virtual std::vector<Window> GetWindowsInStackingOrder() const = 0;
7878
79 virtual bool IsWindowMaximized(Window window_id) const = 0;79 virtual bool IsWindowMaximized(Window window_id) const = 0;
80 virtual bool IsWindowVerticallyMaximized(Window window_id) const = 0;
81 virtual bool IsWindowHorizontallyMaximized(Window window_id) const = 0;
82 virtual bool IsWindowMaximizable(Window window_id) const = 0;
80 virtual bool IsWindowDecorated(Window window_id) const = 0;83 virtual bool IsWindowDecorated(Window window_id) const = 0;
81 virtual bool IsWindowOnCurrentDesktop(Window window_id) const = 0;84 virtual bool IsWindowOnCurrentDesktop(Window window_id) const = 0;
82 virtual bool IsWindowObscured(Window window_id) const = 0;85 virtual bool IsWindowObscured(Window window_id) const = 0;
@@ -86,13 +89,14 @@
86 virtual bool IsWindowClosable(Window window_id) const = 0;89 virtual bool IsWindowClosable(Window window_id) const = 0;
87 virtual bool IsWindowMinimized(Window window_id) const = 0;90 virtual bool IsWindowMinimized(Window window_id) const = 0;
88 virtual bool IsWindowMinimizable(Window window_id) const = 0;91 virtual bool IsWindowMinimizable(Window window_id) const = 0;
89 virtual bool IsWindowMaximizable(Window window_id) const = 0;
90 virtual bool HasWindowDecorations(Window window_id) const = 0;92 virtual bool HasWindowDecorations(Window window_id) const = 0;
9193
92 virtual void ShowDesktop() = 0;94 virtual void ShowDesktop() = 0;
93 virtual bool InShowDesktop() const = 0;95 virtual bool InShowDesktop() const = 0;
9496
95 virtual void Maximize(Window window_id) = 0;97 virtual void Maximize(Window window_id) = 0;
98 virtual void LeftMaximize(Window window_id) = 0;
99 virtual void RightMaximize(Window window_id) = 0;
96 virtual void Restore(Window window_id) = 0;100 virtual void Restore(Window window_id) = 0;
97 virtual void RestoreAt(Window window_id, int x, int y) = 0;101 virtual void RestoreAt(Window window_id, int x, int y) = 0;
98 virtual void Minimize(Window window_id) = 0;102 virtual void Minimize(Window window_id) = 0;