Merge lp:~3v1n0/unity/alt+tab-background-load into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 2091
Proposed branch: lp:~3v1n0/unity/alt+tab-background-load
Merge into: lp:unity
Diff against target: 326 lines (+114/-60)
2 files modified
plugins/unityshell/src/SwitcherController.cpp (+104/-54)
plugins/unityshell/src/SwitcherController.h (+10/-6)
To merge this branch: bzr merge lp:~3v1n0/unity/alt+tab-background-load
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
Tim Penhey (community) Needs Fixing
Review via email: mp+94669@code.launchpad.net

Description of the change

Add some background operations to the SwitcherController to make the Alt+Tab to show-up quicker

The switcher controller now when initialized setup a lazy timer (now set to 10s) that on timeout will construct the
switcher view, to make the first time usage quicker.

Also, I've added an idle that will run as soon as the user presses the switcher key combination, that constructs the view in background (and shows an invisible window, since the the ShowWindow operation can take longer than just setting the view visible) to make sure that when the show-timeout occurs everything is already there and it just needs to be shown (setting its opacity).

Tests included into the branch lp:~3v1n0/unity/alt+tab-background-load.tests

To post a comment you must log in.
Revision history for this message
Didier Roche-Tolomelli (didrocks) wrote :

just a note: can you set the timer rather to 20s? (10s is quite short to have everything loaded on the desktop on machines).

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Ok, I thought that 10 seconds were enough, considering that the timeout has low priority, ad so it shouldn't run during boot if there's something else to load, but I'll move that to 20s as you prefer.

Revision history for this message
Tim Penhey (thumper) wrote :

Comments on the test branch.

review: Needs Fixing
Revision history for this message
Andrea Azzarone (azzar1) :
review: Approve
Revision history for this message
Unity Merger (unity-merger) wrote :

The Jenkins job https://jenkins.qa.ubuntu.com/job/automerge-unity/432/console reported an error when processing this lp:~3v1n0/unity/alt+tab-background-load branch.
Not merging it.

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-02-29 02:51:00 +0000
3+++ plugins/unityshell/src/SwitcherController.cpp 2012-03-06 21:11:18 +0000
4@@ -22,7 +22,6 @@
5 #include <Nux/HLayout.h>
6
7 #include "UBusMessages.h"
8-#include "ubus-server.h"
9 #include "WindowManager.h"
10
11 #include "SwitcherController.h"
12@@ -36,41 +35,53 @@
13 namespace switcher
14 {
15
16-Controller::Controller()
17- : view_window_(0)
18+Controller::Controller(unsigned int load_timeout)
19+ : construct_timeout_(load_timeout)
20+ , view_window_(nullptr)
21+ , main_layout_(nullptr)
22+ , monitor_(0)
23 , visible_(false)
24 , show_timer_(0)
25 , detail_timer_(0)
26+ , lazy_timer_(0)
27+ , view_idle_timer_(0)
28+ , bg_color_(0, 0, 0, 0.5)
29 {
30 timeout_length = 75;
31 detail_on_timeout = true;
32 detail_timeout_length = 1500;
33- monitor_ = 0;
34-
35- bg_color_ = nux::Color(0.0, 0.0, 0.0, 0.5);
36-
37- UBusServer *ubus = ubus_server_get_default();
38- bg_update_handle_ =
39- ubus_server_register_interest(ubus, UBUS_BACKGROUND_COLOR_CHANGED,
40- (UBusCallback)&Controller::OnBackgroundUpdate,
41- this);
42+
43+ ubus_manager_.RegisterInterest(UBUS_BACKGROUND_COLOR_CHANGED, sigc::mem_fun(this, &Controller::OnBackgroundUpdate));
44+
45+ /* Construct the view after a prefixed timeout, to improve the startup time */
46+ lazy_timer_ = g_timeout_add_seconds_full(G_PRIORITY_LOW, construct_timeout_, [] (gpointer data) -> gboolean {
47+ auto self = static_cast<Controller*>(data);
48+ self->lazy_timer_ = 0;
49+ self->ConstructWindow();
50+ return FALSE;
51+ }, this, nullptr);
52 }
53
54 Controller::~Controller()
55 {
56- ubus_server_unregister_interest(ubus_server_get_default(), bg_update_handle_);
57 if (view_window_)
58 view_window_->UnReference();
59+
60+ if (lazy_timer_)
61+ g_source_remove(lazy_timer_);
62+
63+ if (view_idle_timer_)
64+ g_source_remove(view_idle_timer_);
65 }
66
67-void Controller::OnBackgroundUpdate(GVariant* data, Controller* self)
68+void Controller::OnBackgroundUpdate(GVariant* data)
69 {
70 gdouble red, green, blue, alpha;
71 g_variant_get(data, "(dddd)", &red, &green, &blue, &alpha);
72- self->bg_color_ = nux::Color(red, green, blue, alpha);
73+ bg_color_ = nux::Color(red, green, blue, alpha);
74
75- if (self->view_)
76- self->view_->background_color = self->bg_color_;
77+ if (view_)
78+ view_->background_color = bg_color_;
79 }
80
81 void Controller::Show(ShowMode show, SortMode sort, bool reverse,
82@@ -92,13 +103,29 @@
83
84 if (timeout_length > 0)
85 {
86+ if (view_idle_timer_)
87+ g_source_remove(view_idle_timer_);
88+
89+ view_idle_timer_ = g_idle_add_full(G_PRIORITY_LOW, [] (gpointer data) -> gboolean {
90+ auto self = static_cast<Controller*>(data);
91+ self->ConstructView();
92+ self->view_idle_timer_ = 0;
93+ return FALSE;
94+ }, this, NULL);
95+
96 if (show_timer_)
97 g_source_remove (show_timer_);
98- show_timer_ = g_timeout_add(timeout_length, &Controller::OnShowTimer, this);
99+
100+ show_timer_ = g_timeout_add(timeout_length, [] (gpointer data) -> gboolean {
101+ auto self = static_cast<Controller*>(data);
102+ self->ShowView();
103+ self->show_timer_ = 0;
104+ return FALSE;
105+ }, this);
106 }
107 else
108 {
109- ConstructView();
110+ ShowView();
111 }
112
113 if (detail_on_timeout)
114@@ -108,12 +135,8 @@
115 detail_timer_ = g_timeout_add(detail_timeout_length, &Controller::OnDetailTimer, this);
116 }
117
118- ubus_server_send_message(ubus_server_get_default(),
119- UBUS_PLACE_VIEW_CLOSE_REQUEST,
120- NULL);
121-
122- ubus_server_send_message(ubus_server_get_default(),
123- UBUS_SWITCHER_SHOWN, g_variant_new_boolean(true));
124+ ubus_manager_.SendMessage(UBUS_PLACE_VIEW_CLOSE_REQUEST);
125+ ubus_manager_.SendMessage(UBUS_SWITCHER_SHOWN, g_variant_new_boolean(true));
126 }
127
128 void Controller::Select(int index)
129@@ -122,17 +145,6 @@
130 model_->Select(index);
131 }
132
133-gboolean Controller::OnShowTimer(gpointer data)
134-{
135- Controller* self = static_cast<Controller*>(data);
136-
137- if (self->visible_)
138- self->ConstructView();
139-
140- self->show_timer_ = 0;
141- return FALSE;
142-}
143-
144 gboolean Controller::OnDetailTimer(gpointer data)
145 {
146 Controller* self = static_cast<Controller*>(data);
147@@ -157,18 +169,28 @@
148 detail_timer_ = g_timeout_add(detail_timeout_length, &Controller::OnDetailTimer, this);
149 }
150
151- ubus_server_send_message(ubus_server_get_default(),
152- UBUS_SWITCHER_SELECTION_CHANGED,
153- g_variant_new_string(icon->tooltip_text().c_str()));
154-}
155-
156-void Controller::ConstructView()
157-{
158- view_ = SwitcherView::Ptr(new SwitcherView());
159- AddChild(view_.GetPointer());
160- view_->SetModel(model_);
161- view_->background_color = bg_color_;
162- view_->monitor = monitor_;
163+ ubus_manager_.SendMessage(UBUS_SWITCHER_SELECTION_CHANGED,
164+ g_variant_new_string(icon->tooltip_text().c_str()));
165+}
166+
167+void Controller::ShowView()
168+{
169+ if (!visible_)
170+ return;
171+
172+ ConstructView();
173+
174+ if (view_window_)
175+ view_window_->SetOpacity(1.0f);
176+}
177+
178+void Controller::ConstructWindow()
179+{
180+ if (lazy_timer_)
181+ {
182+ g_source_remove(lazy_timer_);
183+ lazy_timer_ = 0;
184+ }
185
186 if (!view_window_)
187 {
188@@ -180,12 +202,32 @@
189 view_window_->SinkReference();
190 view_window_->SetLayout(main_layout_);
191 view_window_->SetBackgroundColor(nux::Color(0x00000000));
192- }
193-
194+ view_window_->SetGeometry(workarea_);
195+ }
196+}
197+
198+void Controller::ConstructView()
199+{
200+ if (view_ || !model_)
201+ return;
202+
203+ if (view_idle_timer_)
204+ {
205+ g_source_remove(view_idle_timer_);
206+ view_idle_timer_ = 0;
207+ }
208+
209+ view_ = SwitcherView::Ptr(new SwitcherView());
210+ AddChild(view_.GetPointer());
211+ view_->SetModel(model_);
212+ view_->background_color = bg_color_;
213+ view_->monitor = monitor_;
214+ view_->SetupBackground();
215+
216+ ConstructWindow();
217 main_layout_->AddView(view_.GetPointer(), 1);
218-
219 view_window_->SetGeometry(workarea_);
220- view_->SetupBackground();
221+ view_window_->SetOpacity(0.0f);
222 view_window_->ShowWindow(true);
223 }
224
225@@ -227,6 +269,12 @@
226 }
227 }
228
229+ if (view_idle_timer_)
230+ {
231+ g_source_remove(view_idle_timer_);
232+ view_idle_timer_ = 0;
233+ }
234+
235 model_.reset();
236 visible_ = false;
237
238@@ -234,7 +282,10 @@
239 main_layout_->RemoveChildObject(view_.GetPointer());
240
241 if (view_window_)
242+ {
243+ view_window_->SetOpacity(0.0f);
244 view_window_->ShowWindow(false);
245+ }
246
247 if (show_timer_)
248 g_source_remove(show_timer_);
249@@ -244,8 +295,7 @@
250 g_source_remove(detail_timer_);
251 detail_timer_ = 0;
252
253- ubus_server_send_message(ubus_server_get_default(),
254- UBUS_SWITCHER_SHOWN, g_variant_new_boolean(false));
255+ ubus_manager_.SendMessage(UBUS_SWITCHER_SHOWN, g_variant_new_boolean(false));
256
257 view_.Release();
258 }
259
260=== modified file 'plugins/unityshell/src/SwitcherController.h'
261--- plugins/unityshell/src/SwitcherController.h 2012-02-12 10:43:11 +0000
262+++ plugins/unityshell/src/SwitcherController.h 2012-03-06 21:11:18 +0000
263@@ -27,6 +27,7 @@
264
265 #include "SwitcherModel.h"
266 #include "SwitcherView.h"
267+#include "UBusWrapper.h"
268
269 #include <boost/shared_ptr.hpp>
270 #include <sigc++/sigc++.h>
271@@ -62,11 +63,10 @@
272 public:
273 typedef std::shared_ptr<Controller> Ptr;
274
275- Controller();
276+ Controller(unsigned int load_timeout = 20);
277 virtual ~Controller();
278
279 nux::Property<int> timeout_length;
280-
281 nux::Property<bool> detail_on_timeout;
282 nux::Property<int> detail_timeout_length;
283
284@@ -98,6 +98,8 @@
285 std::string GetName() const;
286 void AddProperties(GVariantBuilder* builder);
287
288+ unsigned int construct_timeout_;
289+
290 private:
291 enum DetailMode
292 {
293@@ -106,15 +108,17 @@
294 TAB_NEXT_TILE,
295 };
296
297+ void ConstructWindow();
298 void ConstructView();
299+ void ShowView();
300
301 void OnModelSelectionChanged(launcher::AbstractLauncherIcon::Ptr icon);
302-
303- static void OnBackgroundUpdate(GVariant* data, Controller* self);
304+ void OnBackgroundUpdate(GVariant* data);
305
306 SwitcherModel::Ptr model_;
307 SwitcherView::Ptr view_;
308
309+ UBusManager ubus_manager_;
310 nux::Geometry workarea_;
311
312 nux::BaseWindow* view_window_;
313@@ -124,11 +128,11 @@
314 bool visible_;
315 guint show_timer_;
316 guint detail_timer_;
317+ guint lazy_timer_;
318+ guint view_idle_timer_;
319 nux::Color bg_color_;
320 DetailMode detail_mode_;
321- guint bg_update_handle_;
322
323- static gboolean OnShowTimer(gpointer data);
324 static gboolean OnDetailTimer(gpointer data);
325
326 static bool CompareSwitcherItemsPriority(launcher::AbstractLauncherIcon::Ptr first, launcher::AbstractLauncherIcon::Ptr second);