Merge lp:~brandontschaefer/unity/switcher-alt+f4-fix into lp:unity

Proposed by Brandon Schaefer
Status: Merged
Approved by: Brandon Schaefer
Approved revision: no longer in the source branch.
Merged at revision: 2441
Proposed branch: lp:~brandontschaefer/unity/switcher-alt+f4-fix
Merge into: lp:unity
Diff against target: 202 lines (+69/-4)
7 files modified
launcher/SwitcherController.cpp (+13/-0)
launcher/SwitcherController.h (+2/-0)
launcher/SwitcherModel.cpp (+1/-1)
plugins/unityshell/src/unityshell.cpp (+27/-0)
plugins/unityshell/src/unityshell.h (+5/-0)
tests/autopilot/unity/tests/test_switcher.py (+18/-2)
unity-shared/UBusMessages.h (+3/-1)
To merge this branch: bzr merge lp:~brandontschaefer/unity/switcher-alt+f4-fix
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
Thomi Richards (community) quality Approve
Review via email: mp+111703@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
Brandon Schaefer (brandontschaefer) wrote :

All switcher AP test pass locally.

Ran 24 tests in 185.487s

OK (skipped=1)

Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Hi,

171 + self.keyboard.press_and_release("Alt+F4")
172 + [win] = [w for w in app.get_windows()]
173 +
174 + self.assertThat(win.is_valid, Equals(True))

This will also pass even if the code is broken and we run it on the jenkins machine. It's a bit ugly, but I'd like to see a "sleep(10)" just before the assert, with a comment saying why we need it.

Otherwise looks good to me.

Cheers

review: Needs Fixing (quality)
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) :
review: Approve (quality)
Revision history for this message
Andrea Azzarone (azzar1) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'launcher/SwitcherController.cpp'
--- launcher/SwitcherController.cpp 2012-06-15 02:03:31 +0000
+++ launcher/SwitcherController.cpp 2012-06-25 21:40:25 +0000
@@ -159,8 +159,11 @@
159159
160 ConstructView();160 ConstructView();
161161
162 ubus_manager_.SendMessage(UBUS_SWITCHER_START, NULL);
163
162 if (view_window_) {164 if (view_window_) {
163 view_window_->ShowWindow(true);165 view_window_->ShowWindow(true);
166 view_window_->PushToFront();
164 view_window_->SetOpacity(1.0f);167 view_window_->SetOpacity(1.0f);
165 }168 }
166}169}
@@ -179,6 +182,7 @@
179 view_window_->SetLayout(main_layout_);182 view_window_->SetLayout(main_layout_);
180 view_window_->SetBackgroundColor(nux::Color(0x00000000));183 view_window_->SetBackgroundColor(nux::Color(0x00000000));
181 view_window_->SetGeometry(workarea_);184 view_window_->SetGeometry(workarea_);
185 view_window_->EnableInputWindow(true, "Switcher", false, false);
182 }186 }
183}187}
184188
@@ -240,6 +244,8 @@
240 }244 }
241 }245 }
242246
247 ubus_manager_.SendMessage(UBUS_SWITCHER_END, g_variant_new_boolean(!accept_state));
248
243 sources_.Remove(VIEW_CONSTRUCT_IDLE);249 sources_.Remove(VIEW_CONSTRUCT_IDLE);
244 sources_.Remove(SHOW_TIMEOUT);250 sources_.Remove(SHOW_TIMEOUT);
245 sources_.Remove(DETAIL_TIMEOUT);251 sources_.Remove(DETAIL_TIMEOUT);
@@ -254,6 +260,8 @@
254 {260 {
255 view_window_->SetOpacity(0.0f);261 view_window_->SetOpacity(0.0f);
256 view_window_->ShowWindow(false);262 view_window_->ShowWindow(false);
263 view_window_->PushToBack();
264 view_window_->EnableInputWindow(false);
257 }265 }
258266
259 ubus_manager_.SendMessage(UBUS_SWITCHER_SHOWN, g_variant_new("(bi)", false, monitor_));267 ubus_manager_.SendMessage(UBUS_SWITCHER_SHOWN, g_variant_new("(bi)", false, monitor_));
@@ -385,6 +393,11 @@
385 return view_->ExternalTargets();393 return view_->ExternalTargets();
386}394}
387395
396guint Controller::GetSwitcherInputWindowId() const
397{
398 return view_window_->GetInputWindowId();
399}
400
388bool Controller::CompareSwitcherItemsPriority(AbstractLauncherIcon::Ptr first,401bool Controller::CompareSwitcherItemsPriority(AbstractLauncherIcon::Ptr first,
389 AbstractLauncherIcon::Ptr second)402 AbstractLauncherIcon::Ptr second)
390{403{
391404
=== modified file 'launcher/SwitcherController.h'
--- launcher/SwitcherController.h 2012-06-15 02:03:31 +0000
+++ launcher/SwitcherController.h 2012-06-25 21:40:25 +0000
@@ -90,6 +90,8 @@
9090
91 ui::LayoutWindowList ExternalRenderTargets ();91 ui::LayoutWindowList ExternalRenderTargets ();
9292
93 guint GetSwitcherInputWindowId() const;
94
93protected:95protected:
94 // Introspectable methods96 // Introspectable methods
95 std::string GetName() const;97 std::string GetName() const;
9698
=== modified file 'launcher/SwitcherModel.cpp'
--- launcher/SwitcherModel.cpp 2012-06-01 02:38:55 +0000
+++ launcher/SwitcherModel.cpp 2012-06-25 21:40:25 +0000
@@ -171,7 +171,7 @@
171171
172 if (detail_selection_index > DetailXids().size() - 1)172 if (detail_selection_index > DetailXids().size() - 1)
173 return 0;173 return 0;
174 174
175 return DetailXids()[detail_selection_index];175 return DetailXids()[detail_selection_index];
176}176}
177177
178178
=== modified file 'plugins/unityshell/src/unityshell.cpp'
--- plugins/unityshell/src/unityshell.cpp 2012-06-15 02:03:31 +0000
+++ plugins/unityshell/src/unityshell.cpp 2012-06-25 21:40:25 +0000
@@ -353,6 +353,12 @@
353 ubus_manager_.RegisterInterest(UBUS_LAUNCHER_END_KEY_SWTICHER,353 ubus_manager_.RegisterInterest(UBUS_LAUNCHER_END_KEY_SWTICHER,
354 sigc::mem_fun(this, &UnityScreen::OnLauncherEndKeyNav));354 sigc::mem_fun(this, &UnityScreen::OnLauncherEndKeyNav));
355355
356 ubus_manager_.RegisterInterest(UBUS_SWITCHER_START,
357 sigc::mem_fun(this, &UnityScreen::OnSwitcherStart));
358
359 ubus_manager_.RegisterInterest(UBUS_SWITCHER_END,
360 sigc::mem_fun(this, &UnityScreen::OnSwitcherEnd));
361
356 auto init_plugins_cb = sigc::mem_fun(this, &UnityScreen::initPluginActions);362 auto init_plugins_cb = sigc::mem_fun(this, &UnityScreen::initPluginActions);
357 sources_.Add(std::make_shared<glib::Idle>(init_plugins_cb, glib::Source::Priority::DEFAULT));363 sources_.Add(std::make_shared<glib::Idle>(init_plugins_cb, glib::Source::Priority::DEFAULT));
358364
@@ -1909,6 +1915,27 @@
19091915
1910void UnityScreen::OnLauncherEndKeyNav(GVariant* data)1916void UnityScreen::OnLauncherEndKeyNav(GVariant* data)
1911{1917{
1918 RestoreWindow(data);
1919}
1920
1921void UnityScreen::OnSwitcherStart(GVariant* data)
1922{
1923 newFocusedWindow = screen->findWindow(switcher_controller_->GetSwitcherInputWindowId());
1924
1925 if (switcher_controller_->GetSwitcherInputWindowId() != screen->activeWindow())
1926 PluginAdapter::Default()->saveInputFocus();
1927
1928 if (newFocusedWindow)
1929 newFocusedWindow->moveInputFocusTo();
1930}
1931
1932void UnityScreen::OnSwitcherEnd(GVariant* data)
1933{
1934 RestoreWindow(data);
1935}
1936
1937void UnityScreen::RestoreWindow(GVariant* data)
1938{
1912 bool preserve_focus = false;1939 bool preserve_focus = false;
19131940
1914 if (data)1941 if (data)
19151942
=== modified file 'plugins/unityshell/src/unityshell.h'
--- plugins/unityshell/src/unityshell.h 2012-06-15 02:03:31 +0000
+++ plugins/unityshell/src/unityshell.h 2012-06-25 21:40:25 +0000
@@ -228,6 +228,11 @@
228 void OnLauncherStartKeyNav(GVariant* data);228 void OnLauncherStartKeyNav(GVariant* data);
229 void OnLauncherEndKeyNav(GVariant* data);229 void OnLauncherEndKeyNav(GVariant* data);
230230
231 void OnSwitcherStart(GVariant* data);
232 void OnSwitcherEnd(GVariant* data);
233
234 void RestoreWindow(GVariant* data);
235
231 void InitHints();236 void InitHints();
232237
233 void OnPanelStyleChanged();238 void OnPanelStyleChanged();
234239
=== modified file 'tests/autopilot/unity/tests/test_switcher.py'
--- tests/autopilot/unity/tests/test_switcher.py 2012-06-20 21:39:36 +0000
+++ tests/autopilot/unity/tests/test_switcher.py 2012-06-25 21:40:25 +0000
@@ -52,10 +52,10 @@
52 """Starting switcher in details mode must show the focused window title."""52 """Starting switcher in details mode must show the focused window title."""
53 app = self.start_app("Text Editor")53 app = self.start_app("Text Editor")
54 sleep(1)54 sleep(1)
55 self.switcher.initiate(SwitcherMode.DETAIL)
56 self.addCleanup(self.switcher.terminate)
5755
58 [title] = [w.title for w in app.get_windows() if w.is_focused]56 [title] = [w.title for w in app.get_windows() if w.is_focused]
57 self.switcher.initiate(SwitcherMode.DETAIL)
58 self.addCleanup(self.switcher.terminate)
5959
60 self.assertThat(self.switcher.controller.view.label, Eventually(Equals(title)))60 self.assertThat(self.switcher.controller.view.label, Eventually(Equals(title)))
6161
@@ -190,6 +190,22 @@
190 self.addCleanup(self.switcher.terminate)190 self.addCleanup(self.switcher.terminate)
191 self.assertThat(self.switcher.controller.monitor, Eventually(Equals(monitor)))191 self.assertThat(self.switcher.controller.monitor, Eventually(Equals(monitor)))
192192
193 def test_switcher_alt_f4_is_disabled(self):
194 """Tests that alt+f4 does not work while switcher is active."""
195
196 app = self.start_app("Text Editor")
197 sleep(1)
198
199 self.switcher.initiate(SwitcherMode.DETAIL)
200 self.addCleanup(self.switcher.terminate)
201
202 self.keyboard.press_and_release("Alt+F4")
203 [win] = [w for w in app.get_windows()]
204
205 # Need the sleep to allow the window time to close, for jenkins!
206 sleep(10)
207 self.assertThat(win.is_valid, Equals(True))
208
193209
194class SwitcherWindowsManagementTests(SwitcherTestCase):210class SwitcherWindowsManagementTests(SwitcherTestCase):
195 """Test the switcher window management."""211 """Test the switcher window management."""
196212
=== modified file 'unity-shared/UBusMessages.h'
--- unity-shared/UBusMessages.h 2012-05-06 23:48:38 +0000
+++ unity-shared/UBusMessages.h 2012-06-25 21:40:25 +0000
@@ -35,7 +35,7 @@
35#define UBUS_DASH_ABOUT_TO_SHOW "DASH_ABOUT_TO_SHOW"35#define UBUS_DASH_ABOUT_TO_SHOW "DASH_ABOUT_TO_SHOW"
3636
37// Signal sent when an overlay interface is shown, includes a gvariant37// Signal sent when an overlay interface is shown, includes a gvariant
38// gvariant format is (sb), (interface-name, can_maximize?) 38// gvariant format is (sb), (interface-name, can_maximize?)
39#define UBUS_OVERLAY_FORMAT_STRING "(sbi)"39#define UBUS_OVERLAY_FORMAT_STRING "(sbi)"
40#define UBUS_OVERLAY_HIDDEN "OVERLAY_HIDDEN"40#define UBUS_OVERLAY_HIDDEN "OVERLAY_HIDDEN"
41#define UBUS_OVERLAY_SHOWN "OVERLAY_SHOWN"41#define UBUS_OVERLAY_SHOWN "OVERLAY_SHOWN"
@@ -88,6 +88,8 @@
8888
89// Signals sent when the switcher is shown, hidden or changes selection89// Signals sent when the switcher is shown, hidden or changes selection
90#define UBUS_SWITCHER_SHOWN "SWITCHER_SHOWN"90#define UBUS_SWITCHER_SHOWN "SWITCHER_SHOWN"
91#define UBUS_SWITCHER_START "SWITCHER_SHOWN_START"
92#define UBUS_SWITCHER_END "SWITCHER_SHOWN_END"
91#define UBUS_SWITCHER_SELECTION_CHANGED "SWITCHER_SELECTION_CHANGED"93#define UBUS_SWITCHER_SELECTION_CHANGED "SWITCHER_SELECTION_CHANGED"
9294
93#endif // UBUS_MESSAGES_H95#endif // UBUS_MESSAGES_H