Merge lp:~brandontschaefer/unity/switcher-alt+f4-disabled-SRU into lp:unity/5.0

Proposed by Brandon Schaefer
Status: Merged
Approved by: Brandon Schaefer
Approved revision: no longer in the source branch.
Merged at revision: 2374
Proposed branch: lp:~brandontschaefer/unity/switcher-alt+f4-disabled-SRU
Merge into: lp:unity/5.0
Diff against target: 199 lines (+69/-5)
6 files modified
plugins/unityshell/src/SwitcherController.cpp (+17/-4)
plugins/unityshell/src/SwitcherController.h (+2/-0)
plugins/unityshell/src/UBusMessages.h (+3/-1)
plugins/unityshell/src/unityshell.cpp (+27/-0)
plugins/unityshell/src/unityshell.h (+5/-0)
tests/autopilot/autopilot/tests/test_switcher.py (+15/-0)
To merge this branch: bzr merge lp:~brandontschaefer/unity/switcher-alt+f4-disabled-SRU
Reviewer Review Type Date Requested Status
Thomi Richards (community) quality Approve
Review via email: mp+111966@code.launchpad.net

Commit message

The switcher now focuses it's own window, instead of leaving it to the current one. Now Alt+F4 does not work while the switcher is active.

Description of the change

=== Problem ===
When the switcher starts it does not take the focus from the current window. This means if you press Alt+F4 it will close that program, but when you exit from the switcher it will restart that application.

=== Fix ===
The fix is to take the switchers view window and give it focus. If the switcher is cancled then restore focus to the previous window. Else, do what the switcher normally does.

=== Test ===
AP test included.

To post a comment you must log in.
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) :
review: Approve (quality)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/SwitcherController.cpp'
2--- plugins/unityshell/src/SwitcherController.cpp 2012-06-05 14:17:55 +0000
3+++ plugins/unityshell/src/SwitcherController.cpp 2012-06-25 23:29:18 +0000
4@@ -95,7 +95,7 @@
5 {
6 std::sort(results.begin(), results.end(), CompareSwitcherItemsPriority);
7 }
8-
9+
10 model_.reset(new SwitcherModel(results));
11 AddChild(model_.get());
12 model_->selection_changed.connect(sigc::mem_fun(this, &Controller::OnModelSelectionChanged));
13@@ -187,11 +187,14 @@
14 {
15 if (!visible_)
16 return;
17-
18+
19 ConstructView();
20
21+ ubus_manager_.SendMessage(UBUS_SWITCHER_START);
22+
23 if (view_window_) {
24 view_window_->ShowWindow(true);
25+ view_window_->PushToFront();
26 view_window_->SetOpacity(1.0f);
27 }
28 }
29@@ -215,6 +218,7 @@
30 view_window_->SetLayout(main_layout_);
31 view_window_->SetBackgroundColor(nux::Color(0x00000000));
32 view_window_->SetGeometry(workarea_);
33+ view_window_->EnableInputWindow(true, "Switcher", false, false);
34 }
35 }
36
37@@ -280,6 +284,8 @@
38 }
39 }
40
41+ ubus_manager_.SendMessage(UBUS_SWITCHER_END, g_variant_new_boolean(!accept_state));
42+
43 if (view_idle_timer_)
44 {
45 g_source_remove(view_idle_timer_);
46@@ -296,6 +302,8 @@
47 {
48 view_window_->SetOpacity(0.0f);
49 view_window_->ShowWindow(false);
50+ view_window_->PushToBack();
51+ view_window_->EnableInputWindow(false);
52 }
53
54 if (show_timer_)
55@@ -435,15 +443,20 @@
56 return view_->ExternalTargets();
57 }
58
59+guint Controller::GetSwitcherInputWindowId() const
60+{
61+ return view_window_->GetInputWindowId();
62+}
63+
64 bool Controller::CompareSwitcherItemsPriority(AbstractLauncherIcon::Ptr first,
65 AbstractLauncherIcon::Ptr second)
66 {
67 if (first->GetIconType() == second->GetIconType())
68 return first->SwitcherPriority() > second->SwitcherPriority();
69-
70+
71 if (first->GetIconType() == AbstractLauncherIcon::IconType::TYPE_DESKTOP)
72 return true;
73-
74+
75 if (second->GetIconType() == AbstractLauncherIcon::IconType::TYPE_DESKTOP)
76 return false;
77 return first->GetIconType() < second->GetIconType();
78
79=== modified file 'plugins/unityshell/src/SwitcherController.h'
80--- plugins/unityshell/src/SwitcherController.h 2012-04-14 18:15:54 +0000
81+++ plugins/unityshell/src/SwitcherController.h 2012-06-25 23:29:18 +0000
82@@ -95,6 +95,8 @@
83
84 ui::LayoutWindowList ExternalRenderTargets ();
85
86+ guint GetSwitcherInputWindowId() const;
87+
88 protected:
89 // Introspectable methods
90 std::string GetName() const;
91
92=== modified file 'plugins/unityshell/src/UBusMessages.h'
93--- plugins/unityshell/src/UBusMessages.h 2012-04-17 22:09:41 +0000
94+++ plugins/unityshell/src/UBusMessages.h 2012-06-25 23:29:18 +0000
95@@ -35,7 +35,7 @@
96 #define UBUS_DASH_ABOUT_TO_SHOW "DASH_ABOUT_TO_SHOW"
97
98 // Signal sent when an overlay interface is shown, includes a gvariant
99-// gvariant format is (sb), (interface-name, can_maximize?)
100+// gvariant format is (sb), (interface-name, can_maximize?)
101 #define UBUS_OVERLAY_FORMAT_STRING "(sbi)"
102 #define UBUS_OVERLAY_HIDDEN "OVERLAY_HIDDEN"
103 #define UBUS_OVERLAY_SHOWN "OVERLAY_SHOWN"
104@@ -88,6 +88,8 @@
105
106 // Signals sent when the switcher is shown, hidden or changes selection
107 #define UBUS_SWITCHER_SHOWN "SWITCHER_SHOWN"
108+#define UBUS_SWITCHER_START "SWITCHER_START"
109+#define UBUS_SWITCHER_END "SWITCHER_END"
110 #define UBUS_SWITCHER_SELECTION_CHANGED "SWITCHER_SELECTION_CHANGED"
111
112 #endif // UBUS_MESSAGES_H
113
114=== modified file 'plugins/unityshell/src/unityshell.cpp'
115--- plugins/unityshell/src/unityshell.cpp 2012-05-23 13:43:03 +0000
116+++ plugins/unityshell/src/unityshell.cpp 2012-06-25 23:29:18 +0000
117@@ -350,6 +350,12 @@
118 ubus_manager_.RegisterInterest(UBUS_LAUNCHER_END_KEY_SWTICHER,
119 sigc::mem_fun(this, &UnityScreen::OnLauncherEndKeyNav));
120
121+ ubus_manager_.RegisterInterest(UBUS_SWITCHER_START,
122+ sigc::mem_fun(this, &UnityScreen::OnSwitcherStart));
123+
124+ ubus_manager_.RegisterInterest(UBUS_SWITCHER_END,
125+ sigc::mem_fun(this, &UnityScreen::OnSwitcherEnd));
126+
127 g_idle_add_full (G_PRIORITY_DEFAULT, &UnityScreen::initPluginActions, this, NULL);
128 super_keypressed_ = false;
129
130@@ -1931,6 +1937,27 @@
131
132 void UnityScreen::OnLauncherEndKeyNav(GVariant* data)
133 {
134+ RestoreWindow(data);
135+}
136+
137+void UnityScreen::OnSwitcherStart(GVariant* data)
138+{
139+ newFocusedWindow = screen->findWindow(switcher_controller_->GetSwitcherInputWindowId());
140+
141+ if (switcher_controller_->GetSwitcherInputWindowId() != screen->activeWindow())
142+ PluginAdapter::Default()->saveInputFocus();
143+
144+ if (newFocusedWindow)
145+ newFocusedWindow->moveInputFocusTo();
146+}
147+
148+void UnityScreen::OnSwitcherEnd(GVariant* data)
149+{
150+ RestoreWindow(data);
151+}
152+
153+void UnityScreen::RestoreWindow(GVariant* data)
154+{
155 bool preserve_focus = false;
156
157 if (data)
158
159=== modified file 'plugins/unityshell/src/unityshell.h'
160--- plugins/unityshell/src/unityshell.h 2012-04-24 21:26:55 +0000
161+++ plugins/unityshell/src/unityshell.h 2012-06-25 23:29:18 +0000
162@@ -229,6 +229,11 @@
163 void OnLauncherStartKeyNav(GVariant* data);
164 void OnLauncherEndKeyNav(GVariant* data);
165
166+ void OnSwitcherStart(GVariant* data);
167+ void OnSwitcherEnd(GVariant* data);
168+
169+ void RestoreWindow(GVariant* data);
170+
171 void InitHints();
172
173 void OnPanelStyleChanged();
174
175=== modified file 'tests/autopilot/autopilot/tests/test_switcher.py'
176--- tests/autopilot/autopilot/tests/test_switcher.py 2012-04-16 01:03:10 +0000
177+++ tests/autopilot/autopilot/tests/test_switcher.py 2012-06-25 23:29:18 +0000
178@@ -210,6 +210,21 @@
179 self.assertThat(self.switcher.get_monitor(), Equals(monitor))
180 self.switcher.terminate()
181
182+ def test_switcher_alt_f4_is_disabled(self):
183+ """Tests that alt+f4 does not work while switcher is active."""
184+
185+ app = self.start_app("Text Editor")
186+ sleep(1)
187+ self.switcher.initiate()
188+
189+ self.keyboard.press_and_release("Alt+F4")
190+ [win] = [w for w in app.get_windows()]
191+ self.switcher.terminate()
192+
193+ # Need the sleep to allow the window time to close, for jenkins!
194+ sleep(10)
195+ self.assertThat(win.is_valid, Equals(True))
196+
197
198 class SwitcherWindowsManagementTests(AutopilotTestCase):
199 """Test the switcher window management."""

Subscribers

People subscribed via source and target branches

to all changes: