Merge lp:~brandontschaefer/unity/condense-unityshell-function into lp:unity

Proposed by Brandon Schaefer
Status: Merged
Approved by: Brandon Schaefer
Approved revision: no longer in the source branch.
Merged at revision: 2452
Proposed branch: lp:~brandontschaefer/unity/condense-unityshell-function
Merge into: lp:unity
Diff against target: 103 lines (+26/-29)
2 files modified
plugins/unityshell/src/unityshell.cpp (+25/-28)
plugins/unityshell/src/unityshell.h (+1/-1)
To merge this branch: bzr merge lp:~brandontschaefer/unity/condense-unityshell-function
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
Review via email: mp+112213@code.launchpad.net

Commit message

Condensed some code in for saving input focus and focusing a new window in unityshell.cpp

Description of the change

=== Problem ===
Duplicate functions

=== Fix ===
Condense them

To post a comment you must log in.
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

All launcher test pass.

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
1=== modified file 'plugins/unityshell/src/unityshell.cpp'
2--- plugins/unityshell/src/unityshell.cpp 2012-06-26 18:34:03 +0000
3+++ plugins/unityshell/src/unityshell.cpp 2012-06-27 22:26:20 +0000
4@@ -1671,26 +1671,6 @@
5 return true;
6 }
7
8-void UnityScreen::startLauncherKeyNav()
9-{
10- // get CompWindow* of launcher-window
11- newFocusedWindow = screen->findWindow(launcher_controller_->KeyNavLauncherInputWindowId());
12-
13- // check if currently focused window isn't the launcher-window
14- if (newFocusedWindow != screen->findWindow(screen->activeWindow()))
15- PluginAdapter::Default()->saveInputFocus();
16-
17- // set input-focus on launcher-window and start key-nav mode
18- if (newFocusedWindow)
19- {
20- // Put the launcher BaseWindow at the top of the BaseWindow stack. The
21- // input focus coming from the XinputWindow will be processed by the
22- // launcher BaseWindow only. Then the Launcher BaseWindow will decide
23- // which View will get the input focus.
24- launcher_controller_->PushToFront();
25- newFocusedWindow->moveInputFocusTo();
26- }
27-}
28
29 bool UnityScreen::setKeyboardFocusKeyInitiate(CompAction* action,
30 CompAction::State state,
31@@ -1934,7 +1914,12 @@
32
33 void UnityScreen::OnLauncherStartKeyNav(GVariant* data)
34 {
35- startLauncherKeyNav();
36+ // Put the launcher BaseWindow at the top of the BaseWindow stack. The
37+ // input focus coming from the XinputWindow will be processed by the
38+ // launcher BaseWindow only. Then the Launcher BaseWindow will decide
39+ // which View will get the input focus.
40+ if (SaveInputThenFocus(launcher_controller_->KeyNavLauncherInputWindowId()))
41+ launcher_controller_->PushToFront();
42 }
43
44 void UnityScreen::OnLauncherEndKeyNav(GVariant* data)
45@@ -1944,13 +1929,7 @@
46
47 void UnityScreen::OnSwitcherStart(GVariant* data)
48 {
49- newFocusedWindow = screen->findWindow(switcher_controller_->GetSwitcherInputWindowId());
50-
51- if (switcher_controller_->GetSwitcherInputWindowId() != screen->activeWindow())
52- PluginAdapter::Default()->saveInputFocus();
53-
54- if (newFocusedWindow)
55- newFocusedWindow->moveInputFocusTo();
56+ SaveInputThenFocus(switcher_controller_->GetSwitcherInputWindowId());
57 }
58
59 void UnityScreen::OnSwitcherEnd(GVariant* data)
60@@ -1973,6 +1952,24 @@
61 PluginAdapter::Default ()->restoreInputFocus ();
62 }
63
64+bool UnityScreen::SaveInputThenFocus(const guint xid)
65+{
66+ // get CompWindow*
67+ newFocusedWindow = screen->findWindow(xid);
68+
69+ // check if currently focused window isn't it self
70+ if (xid != screen->activeWindow())
71+ PluginAdapter::Default()->saveInputFocus();
72+
73+ // set input-focus on window
74+ if (newFocusedWindow)
75+ {
76+ newFocusedWindow->moveInputFocusTo();
77+ return true;
78+ }
79+ return false;
80+}
81+
82 bool UnityScreen::ShowHud()
83 {
84 if (switcher_controller_->Visible())
85
86=== modified file 'plugins/unityshell/src/unityshell.h'
87--- plugins/unityshell/src/unityshell.h 2012-06-26 17:34:31 +0000
88+++ plugins/unityshell/src/unityshell.h 2012-06-27 22:26:20 +0000
89@@ -220,7 +220,6 @@
90 static void OnStartKeyNav(GVariant* data, void* value);
91 static void OnExitKeyNav(GVariant* data, void* value);
92
93- void startLauncherKeyNav();
94 void restartLauncherKeyNav();
95
96 void OnDashRealized ();
97@@ -232,6 +231,7 @@
98 void OnSwitcherEnd(GVariant* data);
99
100 void RestoreWindow(GVariant* data);
101+ bool SaveInputThenFocus(const guint xid);
102
103 void InitHints();
104