summaryrefslogtreecommitdiff
path: root/plugins
diff options
authorMarco Trevisan (TreviƱo) <mail@3v1n0.net>2012-03-12 21:29:14 -0400
committerTarmac <>2012-03-12 21:29:14 -0400
commit5052e4f29cd08532a7d913fafc04ed04b8f452e3 (patch)
tree9e311aa5a82fca648074256399e34bfd62cf616d /plugins
parentab54b55c9292e72770a8057ed9eed2ef3f67b1ce (diff)
parentc9bc9d0abbd339e363c7fabded1fb1bc3bacdd23 (diff)
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. Fixes: https://bugs.launchpad.net/bugs/942634. Approved by Andrea Azzarone. (bzr r2091)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/unityshell/src/SwitcherController.cpp144
-rw-r--r--plugins/unityshell/src/SwitcherController.h16
2 files changed, 107 insertions, 53 deletions
diff --git a/plugins/unityshell/src/SwitcherController.cpp b/plugins/unityshell/src/SwitcherController.cpp
index 21b84f5e9..06bc540f5 100644
--- a/plugins/unityshell/src/SwitcherController.cpp
+++ b/plugins/unityshell/src/SwitcherController.cpp
@@ -22,7 +22,6 @@
#include <Nux/HLayout.h>
#include "UBusMessages.h"
-#include "ubus-server.h"
#include "WindowManager.h"
#include "SwitcherController.h"
@@ -36,41 +35,53 @@ using ui::LayoutWindowList;
namespace switcher
{
-Controller::Controller()
- : view_window_(0)
+Controller::Controller(unsigned int load_timeout)
+ : construct_timeout_(load_timeout)
+ , view_window_(nullptr)
+ , main_layout_(nullptr)
+ , monitor_(0)
, visible_(false)
, show_timer_(0)
, detail_timer_(0)
+ , lazy_timer_(0)
+ , view_idle_timer_(0)
+ , bg_color_(0, 0, 0, 0.5)
{
timeout_length = 75;
detail_on_timeout = true;
detail_timeout_length = 1500;
- monitor_ = 0;
- bg_color_ = nux::Color(0.0, 0.0, 0.0, 0.5);
+ ubus_manager_.RegisterInterest(UBUS_BACKGROUND_COLOR_CHANGED, sigc::mem_fun(this, &Controller::OnBackgroundUpdate));
- UBusServer *ubus = ubus_server_get_default();
- bg_update_handle_ =
- ubus_server_register_interest(ubus, UBUS_BACKGROUND_COLOR_CHANGED,
- (UBusCallback)&Controller::OnBackgroundUpdate,
- this);
+ /* Construct the view after a prefixed timeout, to improve the startup time */
+ lazy_timer_ = g_timeout_add_seconds_full(G_PRIORITY_LOW, construct_timeout_, [] (gpointer data) -> gboolean {
+ auto self = static_cast<Controller*>(data);
+ self->lazy_timer_ = 0;
+ self->ConstructWindow();
+ return FALSE;
+ }, this, nullptr);
}
Controller::~Controller()
{
- ubus_server_unregister_interest(ubus_server_get_default(), bg_update_handle_);
if (view_window_)
view_window_->UnReference();
+
+ if (lazy_timer_)
+ g_source_remove(lazy_timer_);
+
+ if (view_idle_timer_)
+ g_source_remove(view_idle_timer_);
}
-void Controller::OnBackgroundUpdate(GVariant* data, Controller* self)
+void Controller::OnBackgroundUpdate(GVariant* data)
{
gdouble red, green, blue, alpha;
g_variant_get(data, "(dddd)", &red, &green, &blue, &alpha);
- self->bg_color_ = nux::Color(red, green, blue, alpha);
+ bg_color_ = nux::Color(red, green, blue, alpha);
- if (self->view_)
- self->view_->background_color = self->bg_color_;
+ if (view_)
+ view_->background_color = bg_color_;
}
void Controller::Show(ShowMode show, SortMode sort, bool reverse,
@@ -92,13 +103,29 @@ void Controller::Show(ShowMode show, SortMode sort, bool reverse,
if (timeout_length > 0)
{
+ if (view_idle_timer_)
+ g_source_remove(view_idle_timer_);
+
+ view_idle_timer_ = g_idle_add_full(G_PRIORITY_LOW, [] (gpointer data) -> gboolean {
+ auto self = static_cast<Controller*>(data);
+ self->ConstructView();
+ self->view_idle_timer_ = 0;
+ return FALSE;
+ }, this, NULL);
+
if (show_timer_)
g_source_remove (show_timer_);
- show_timer_ = g_timeout_add(timeout_length, &Controller::OnShowTimer, this);
+
+ show_timer_ = g_timeout_add(timeout_length, [] (gpointer data) -> gboolean {
+ auto self = static_cast<Controller*>(data);
+ self->ShowView();
+ self->show_timer_ = 0;
+ return FALSE;
+ }, this);
}
else
{
- ConstructView();
+ ShowView();
}
if (detail_on_timeout)
@@ -108,12 +135,8 @@ void Controller::Show(ShowMode show, SortMode sort, bool reverse,
detail_timer_ = g_timeout_add(detail_timeout_length, &Controller::OnDetailTimer, this);
}
- ubus_server_send_message(ubus_server_get_default(),
- UBUS_PLACE_VIEW_CLOSE_REQUEST,
- NULL);
-
- ubus_server_send_message(ubus_server_get_default(),
- UBUS_SWITCHER_SHOWN, g_variant_new_boolean(true));
+ ubus_manager_.SendMessage(UBUS_PLACE_VIEW_CLOSE_REQUEST);
+ ubus_manager_.SendMessage(UBUS_SWITCHER_SHOWN, g_variant_new_boolean(true));
}
void Controller::Select(int index)
@@ -122,17 +145,6 @@ void Controller::Select(int index)
model_->Select(index);
}
-gboolean Controller::OnShowTimer(gpointer data)
-{
- Controller* self = static_cast<Controller*>(data);
-
- if (self->visible_)
- self->ConstructView();
-
- self->show_timer_ = 0;
- return FALSE;
-}
-
gboolean Controller::OnDetailTimer(gpointer data)
{
Controller* self = static_cast<Controller*>(data);
@@ -157,18 +169,28 @@ void Controller::OnModelSelectionChanged(AbstractLauncherIcon::Ptr icon)
detail_timer_ = g_timeout_add(detail_timeout_length, &Controller::OnDetailTimer, this);
}
- ubus_server_send_message(ubus_server_get_default(),
- UBUS_SWITCHER_SELECTION_CHANGED,
- g_variant_new_string(icon->tooltip_text().c_str()));
+ ubus_manager_.SendMessage(UBUS_SWITCHER_SELECTION_CHANGED,
+ g_variant_new_string(icon->tooltip_text().c_str()));
}
-void Controller::ConstructView()
+void Controller::ShowView()
{
- view_ = SwitcherView::Ptr(new SwitcherView());
- AddChild(view_.GetPointer());
- view_->SetModel(model_);
- view_->background_color = bg_color_;
- view_->monitor = monitor_;
+ if (!visible_)
+ return;
+
+ ConstructView();
+
+ if (view_window_)
+ view_window_->SetOpacity(1.0f);
+}
+
+void Controller::ConstructWindow()
+{
+ if (lazy_timer_)
+ {
+ g_source_remove(lazy_timer_);
+ lazy_timer_ = 0;
+ }
if (!view_window_)
{
@@ -180,12 +202,32 @@ void Controller::ConstructView()
view_window_->SinkReference();
view_window_->SetLayout(main_layout_);
view_window_->SetBackgroundColor(nux::Color(0x00000000));
+ view_window_->SetGeometry(workarea_);
}
+}
- main_layout_->AddView(view_.GetPointer(), 1);
+void Controller::ConstructView()
+{
+ if (view_ || !model_)
+ return;
- view_window_->SetGeometry(workarea_);
+ if (view_idle_timer_)
+ {
+ g_source_remove(view_idle_timer_);
+ view_idle_timer_ = 0;
+ }
+
+ view_ = SwitcherView::Ptr(new SwitcherView());
+ AddChild(view_.GetPointer());
+ view_->SetModel(model_);
+ view_->background_color = bg_color_;
+ view_->monitor = monitor_;
view_->SetupBackground();
+
+ ConstructWindow();
+ main_layout_->AddView(view_.GetPointer(), 1);
+ view_window_->SetGeometry(workarea_);
+ view_window_->SetOpacity(0.0f);
view_window_->ShowWindow(true);
}
@@ -227,6 +269,12 @@ void Controller::Hide(bool accept_state)
}
}
+ if (view_idle_timer_)
+ {
+ g_source_remove(view_idle_timer_);
+ view_idle_timer_ = 0;
+ }
+
model_.reset();
visible_ = false;
@@ -234,7 +282,10 @@ void Controller::Hide(bool accept_state)
main_layout_->RemoveChildObject(view_.GetPointer());
if (view_window_)
+ {
+ view_window_->SetOpacity(0.0f);
view_window_->ShowWindow(false);
+ }
if (show_timer_)
g_source_remove(show_timer_);
@@ -244,8 +295,7 @@ void Controller::Hide(bool accept_state)
g_source_remove(detail_timer_);
detail_timer_ = 0;
- ubus_server_send_message(ubus_server_get_default(),
- UBUS_SWITCHER_SHOWN, g_variant_new_boolean(false));
+ ubus_manager_.SendMessage(UBUS_SWITCHER_SHOWN, g_variant_new_boolean(false));
view_.Release();
}
diff --git a/plugins/unityshell/src/SwitcherController.h b/plugins/unityshell/src/SwitcherController.h
index 75a768e5e..8af38c885 100644
--- a/plugins/unityshell/src/SwitcherController.h
+++ b/plugins/unityshell/src/SwitcherController.h
@@ -27,6 +27,7 @@
#include "SwitcherModel.h"
#include "SwitcherView.h"
+#include "UBusWrapper.h"
#include <boost/shared_ptr.hpp>
#include <sigc++/sigc++.h>
@@ -62,11 +63,10 @@ class Controller : public debug::Introspectable, public sigc::trackable
public:
typedef std::shared_ptr<Controller> Ptr;
- Controller();
+ Controller(unsigned int load_timeout = 20);
virtual ~Controller();
nux::Property<int> timeout_length;
-
nux::Property<bool> detail_on_timeout;
nux::Property<int> detail_timeout_length;
@@ -98,6 +98,8 @@ protected:
std::string GetName() const;
void AddProperties(GVariantBuilder* builder);
+ unsigned int construct_timeout_;
+
private:
enum DetailMode
{
@@ -106,15 +108,17 @@ private:
TAB_NEXT_TILE,
};
+ void ConstructWindow();
void ConstructView();
+ void ShowView();
void OnModelSelectionChanged(launcher::AbstractLauncherIcon::Ptr icon);
-
- static void OnBackgroundUpdate(GVariant* data, Controller* self);
+ void OnBackgroundUpdate(GVariant* data);
SwitcherModel::Ptr model_;
SwitcherView::Ptr view_;
+ UBusManager ubus_manager_;
nux::Geometry workarea_;
nux::BaseWindow* view_window_;
@@ -124,11 +128,11 @@ private:
bool visible_;
guint show_timer_;
guint detail_timer_;
+ guint lazy_timer_;
+ guint view_idle_timer_;
nux::Color bg_color_;
DetailMode detail_mode_;
- guint bg_update_handle_;
- static gboolean OnShowTimer(gpointer data);
static gboolean OnDetailTimer(gpointer data);
static bool CompareSwitcherItemsPriority(launcher::AbstractLauncherIcon::Ptr first, launcher::AbstractLauncherIcon::Ptr second);