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
=== modified file 'plugins/unityshell/src/SwitcherController.cpp'
--- plugins/unityshell/src/SwitcherController.cpp 2012-02-29 02:51:00 +0000
+++ plugins/unityshell/src/SwitcherController.cpp 2012-03-06 21:11:18 +0000
@@ -22,7 +22,6 @@
22#include <Nux/HLayout.h>22#include <Nux/HLayout.h>
2323
24#include "UBusMessages.h"24#include "UBusMessages.h"
25#include "ubus-server.h"
26#include "WindowManager.h"25#include "WindowManager.h"
2726
28#include "SwitcherController.h"27#include "SwitcherController.h"
@@ -36,41 +35,53 @@
36namespace switcher35namespace switcher
37{36{
3837
39Controller::Controller()38Controller::Controller(unsigned int load_timeout)
40 : view_window_(0)39 : construct_timeout_(load_timeout)
40 , view_window_(nullptr)
41 , main_layout_(nullptr)
42 , monitor_(0)
41 , visible_(false)43 , visible_(false)
42 , show_timer_(0)44 , show_timer_(0)
43 , detail_timer_(0)45 , detail_timer_(0)
46 , lazy_timer_(0)
47 , view_idle_timer_(0)
48 , bg_color_(0, 0, 0, 0.5)
44{49{
45 timeout_length = 75;50 timeout_length = 75;
46 detail_on_timeout = true;51 detail_on_timeout = true;
47 detail_timeout_length = 1500;52 detail_timeout_length = 1500;
48 monitor_ = 0;53
4954 ubus_manager_.RegisterInterest(UBUS_BACKGROUND_COLOR_CHANGED, sigc::mem_fun(this, &Controller::OnBackgroundUpdate));
50 bg_color_ = nux::Color(0.0, 0.0, 0.0, 0.5);55
5156 /* Construct the view after a prefixed timeout, to improve the startup time */
52 UBusServer *ubus = ubus_server_get_default();57 lazy_timer_ = g_timeout_add_seconds_full(G_PRIORITY_LOW, construct_timeout_, [] (gpointer data) -> gboolean {
53 bg_update_handle_ =58 auto self = static_cast<Controller*>(data);
54 ubus_server_register_interest(ubus, UBUS_BACKGROUND_COLOR_CHANGED,59 self->lazy_timer_ = 0;
55 (UBusCallback)&Controller::OnBackgroundUpdate,60 self->ConstructWindow();
56 this);61 return FALSE;
62 }, this, nullptr);
57}63}
5864
59Controller::~Controller()65Controller::~Controller()
60{66{
61 ubus_server_unregister_interest(ubus_server_get_default(), bg_update_handle_);
62 if (view_window_)67 if (view_window_)
63 view_window_->UnReference();68 view_window_->UnReference();
69
70 if (lazy_timer_)
71 g_source_remove(lazy_timer_);
72
73 if (view_idle_timer_)
74 g_source_remove(view_idle_timer_);
64}75}
6576
66void Controller::OnBackgroundUpdate(GVariant* data, Controller* self)77void Controller::OnBackgroundUpdate(GVariant* data)
67{78{
68 gdouble red, green, blue, alpha;79 gdouble red, green, blue, alpha;
69 g_variant_get(data, "(dddd)", &red, &green, &blue, &alpha);80 g_variant_get(data, "(dddd)", &red, &green, &blue, &alpha);
70 self->bg_color_ = nux::Color(red, green, blue, alpha);81 bg_color_ = nux::Color(red, green, blue, alpha);
7182
72 if (self->view_)83 if (view_)
73 self->view_->background_color = self->bg_color_;84 view_->background_color = bg_color_;
74}85}
7586
76void Controller::Show(ShowMode show, SortMode sort, bool reverse,87void Controller::Show(ShowMode show, SortMode sort, bool reverse,
@@ -92,13 +103,29 @@
92103
93 if (timeout_length > 0)104 if (timeout_length > 0)
94 {105 {
106 if (view_idle_timer_)
107 g_source_remove(view_idle_timer_);
108
109 view_idle_timer_ = g_idle_add_full(G_PRIORITY_LOW, [] (gpointer data) -> gboolean {
110 auto self = static_cast<Controller*>(data);
111 self->ConstructView();
112 self->view_idle_timer_ = 0;
113 return FALSE;
114 }, this, NULL);
115
95 if (show_timer_)116 if (show_timer_)
96 g_source_remove (show_timer_);117 g_source_remove (show_timer_);
97 show_timer_ = g_timeout_add(timeout_length, &Controller::OnShowTimer, this);118
119 show_timer_ = g_timeout_add(timeout_length, [] (gpointer data) -> gboolean {
120 auto self = static_cast<Controller*>(data);
121 self->ShowView();
122 self->show_timer_ = 0;
123 return FALSE;
124 }, this);
98 }125 }
99 else126 else
100 {127 {
101 ConstructView();128 ShowView();
102 }129 }
103130
104 if (detail_on_timeout)131 if (detail_on_timeout)
@@ -108,12 +135,8 @@
108 detail_timer_ = g_timeout_add(detail_timeout_length, &Controller::OnDetailTimer, this);135 detail_timer_ = g_timeout_add(detail_timeout_length, &Controller::OnDetailTimer, this);
109 }136 }
110137
111 ubus_server_send_message(ubus_server_get_default(),138 ubus_manager_.SendMessage(UBUS_PLACE_VIEW_CLOSE_REQUEST);
112 UBUS_PLACE_VIEW_CLOSE_REQUEST,139 ubus_manager_.SendMessage(UBUS_SWITCHER_SHOWN, g_variant_new_boolean(true));
113 NULL);
114
115 ubus_server_send_message(ubus_server_get_default(),
116 UBUS_SWITCHER_SHOWN, g_variant_new_boolean(true));
117}140}
118141
119void Controller::Select(int index)142void Controller::Select(int index)
@@ -122,17 +145,6 @@
122 model_->Select(index);145 model_->Select(index);
123}146}
124147
125gboolean Controller::OnShowTimer(gpointer data)
126{
127 Controller* self = static_cast<Controller*>(data);
128
129 if (self->visible_)
130 self->ConstructView();
131
132 self->show_timer_ = 0;
133 return FALSE;
134}
135
136gboolean Controller::OnDetailTimer(gpointer data)148gboolean Controller::OnDetailTimer(gpointer data)
137{149{
138 Controller* self = static_cast<Controller*>(data);150 Controller* self = static_cast<Controller*>(data);
@@ -157,18 +169,28 @@
157 detail_timer_ = g_timeout_add(detail_timeout_length, &Controller::OnDetailTimer, this);169 detail_timer_ = g_timeout_add(detail_timeout_length, &Controller::OnDetailTimer, this);
158 }170 }
159171
160 ubus_server_send_message(ubus_server_get_default(),172 ubus_manager_.SendMessage(UBUS_SWITCHER_SELECTION_CHANGED,
161 UBUS_SWITCHER_SELECTION_CHANGED,173 g_variant_new_string(icon->tooltip_text().c_str()));
162 g_variant_new_string(icon->tooltip_text().c_str()));174}
163}175
164176void Controller::ShowView()
165void Controller::ConstructView()177{
166{178 if (!visible_)
167 view_ = SwitcherView::Ptr(new SwitcherView());179 return;
168 AddChild(view_.GetPointer());180
169 view_->SetModel(model_);181 ConstructView();
170 view_->background_color = bg_color_;182
171 view_->monitor = monitor_;183 if (view_window_)
184 view_window_->SetOpacity(1.0f);
185}
186
187void Controller::ConstructWindow()
188{
189 if (lazy_timer_)
190 {
191 g_source_remove(lazy_timer_);
192 lazy_timer_ = 0;
193 }
172194
173 if (!view_window_)195 if (!view_window_)
174 {196 {
@@ -180,12 +202,32 @@
180 view_window_->SinkReference();202 view_window_->SinkReference();
181 view_window_->SetLayout(main_layout_);203 view_window_->SetLayout(main_layout_);
182 view_window_->SetBackgroundColor(nux::Color(0x00000000));204 view_window_->SetBackgroundColor(nux::Color(0x00000000));
183 }205 view_window_->SetGeometry(workarea_);
184206 }
207}
208
209void Controller::ConstructView()
210{
211 if (view_ || !model_)
212 return;
213
214 if (view_idle_timer_)
215 {
216 g_source_remove(view_idle_timer_);
217 view_idle_timer_ = 0;
218 }
219
220 view_ = SwitcherView::Ptr(new SwitcherView());
221 AddChild(view_.GetPointer());
222 view_->SetModel(model_);
223 view_->background_color = bg_color_;
224 view_->monitor = monitor_;
225 view_->SetupBackground();
226
227 ConstructWindow();
185 main_layout_->AddView(view_.GetPointer(), 1);228 main_layout_->AddView(view_.GetPointer(), 1);
186
187 view_window_->SetGeometry(workarea_);229 view_window_->SetGeometry(workarea_);
188 view_->SetupBackground();230 view_window_->SetOpacity(0.0f);
189 view_window_->ShowWindow(true);231 view_window_->ShowWindow(true);
190}232}
191233
@@ -227,6 +269,12 @@
227 }269 }
228 }270 }
229271
272 if (view_idle_timer_)
273 {
274 g_source_remove(view_idle_timer_);
275 view_idle_timer_ = 0;
276 }
277
230 model_.reset();278 model_.reset();
231 visible_ = false;279 visible_ = false;
232280
@@ -234,7 +282,10 @@
234 main_layout_->RemoveChildObject(view_.GetPointer());282 main_layout_->RemoveChildObject(view_.GetPointer());
235283
236 if (view_window_)284 if (view_window_)
285 {
286 view_window_->SetOpacity(0.0f);
237 view_window_->ShowWindow(false);287 view_window_->ShowWindow(false);
288 }
238289
239 if (show_timer_)290 if (show_timer_)
240 g_source_remove(show_timer_);291 g_source_remove(show_timer_);
@@ -244,8 +295,7 @@
244 g_source_remove(detail_timer_);295 g_source_remove(detail_timer_);
245 detail_timer_ = 0;296 detail_timer_ = 0;
246297
247 ubus_server_send_message(ubus_server_get_default(),298 ubus_manager_.SendMessage(UBUS_SWITCHER_SHOWN, g_variant_new_boolean(false));
248 UBUS_SWITCHER_SHOWN, g_variant_new_boolean(false));
249299
250 view_.Release();300 view_.Release();
251}301}
252302
=== modified file 'plugins/unityshell/src/SwitcherController.h'
--- plugins/unityshell/src/SwitcherController.h 2012-02-12 10:43:11 +0000
+++ plugins/unityshell/src/SwitcherController.h 2012-03-06 21:11:18 +0000
@@ -27,6 +27,7 @@
2727
28#include "SwitcherModel.h"28#include "SwitcherModel.h"
29#include "SwitcherView.h"29#include "SwitcherView.h"
30#include "UBusWrapper.h"
3031
31#include <boost/shared_ptr.hpp>32#include <boost/shared_ptr.hpp>
32#include <sigc++/sigc++.h>33#include <sigc++/sigc++.h>
@@ -62,11 +63,10 @@
62public:63public:
63 typedef std::shared_ptr<Controller> Ptr;64 typedef std::shared_ptr<Controller> Ptr;
6465
65 Controller();66 Controller(unsigned int load_timeout = 20);
66 virtual ~Controller();67 virtual ~Controller();
6768
68 nux::Property<int> timeout_length;69 nux::Property<int> timeout_length;
69
70 nux::Property<bool> detail_on_timeout;70 nux::Property<bool> detail_on_timeout;
71 nux::Property<int> detail_timeout_length;71 nux::Property<int> detail_timeout_length;
7272
@@ -98,6 +98,8 @@
98 std::string GetName() const;98 std::string GetName() const;
99 void AddProperties(GVariantBuilder* builder);99 void AddProperties(GVariantBuilder* builder);
100100
101 unsigned int construct_timeout_;
102
101private:103private:
102 enum DetailMode104 enum DetailMode
103 {105 {
@@ -106,15 +108,17 @@
106 TAB_NEXT_TILE,108 TAB_NEXT_TILE,
107 };109 };
108110
111 void ConstructWindow();
109 void ConstructView();112 void ConstructView();
113 void ShowView();
110114
111 void OnModelSelectionChanged(launcher::AbstractLauncherIcon::Ptr icon);115 void OnModelSelectionChanged(launcher::AbstractLauncherIcon::Ptr icon);
112116 void OnBackgroundUpdate(GVariant* data);
113 static void OnBackgroundUpdate(GVariant* data, Controller* self);
114117
115 SwitcherModel::Ptr model_;118 SwitcherModel::Ptr model_;
116 SwitcherView::Ptr view_;119 SwitcherView::Ptr view_;
117120
121 UBusManager ubus_manager_;
118 nux::Geometry workarea_;122 nux::Geometry workarea_;
119123
120 nux::BaseWindow* view_window_;124 nux::BaseWindow* view_window_;
@@ -124,11 +128,11 @@
124 bool visible_;128 bool visible_;
125 guint show_timer_;129 guint show_timer_;
126 guint detail_timer_;130 guint detail_timer_;
131 guint lazy_timer_;
132 guint view_idle_timer_;
127 nux::Color bg_color_;133 nux::Color bg_color_;
128 DetailMode detail_mode_;134 DetailMode detail_mode_;
129 guint bg_update_handle_;
130135
131 static gboolean OnShowTimer(gpointer data);
132 static gboolean OnDetailTimer(gpointer data);136 static gboolean OnDetailTimer(gpointer data);
133137
134 static bool CompareSwitcherItemsPriority(launcher::AbstractLauncherIcon::Ptr first, launcher::AbstractLauncherIcon::Ptr second);138 static bool CompareSwitcherItemsPriority(launcher::AbstractLauncherIcon::Ptr first, launcher::AbstractLauncherIcon::Ptr second);