diff options
| author | Jason Smith <jason.smith@canonical.com> | 2012-02-08 23:14:31 -0500 |
|---|---|---|
| committer | Jason Smith <jason.smith@canonical.com> | 2012-02-08 23:14:31 -0500 |
| commit | 16ebda4e57d0e08f89fe4c740e41e8746879ad51 (patch) | |
| tree | 51dfc0271c427c81fafe789d54af75bc0423bdf9 | |
| parent | be016f6f6155c603f200a7aa2acfd4251166ecb9 (diff) | |
lazy load quicklist and tooltips when they are needed
(bzr r1937.1.1)
| -rw-r--r-- | plugins/unityshell/src/LauncherIcon.cpp | 61 | ||||
| -rw-r--r-- | plugins/unityshell/src/LauncherIcon.h | 9 |
2 files changed, 46 insertions, 24 deletions
diff --git a/plugins/unityshell/src/LauncherIcon.cpp b/plugins/unityshell/src/LauncherIcon.cpp index 119342ad1..94cb7ec6f 100644 --- a/plugins/unityshell/src/LauncherIcon.cpp +++ b/plugins/unityshell/src/LauncherIcon.cpp @@ -70,7 +70,6 @@ GtkIconTheme* LauncherIcon::_unity_theme = NULL; LauncherIcon::LauncherIcon() : _menuclient_dynamic_quicklist(nullptr) - , _quicklist_is_initialized(false) , _remote_urgent(false) , _present_urgency(0) , _progress(0) @@ -96,20 +95,12 @@ LauncherIcon::LauncherIcon() _quirk_times[i].tv_nsec = 0; } - _tooltip = new Tooltip(); - tooltip_text.SetSetterFunction(sigc::mem_fun(this, &LauncherIcon::SetTooltipText)); tooltip_text = "blank"; - _quicklist = new QuicklistView(); - // FIXME: the abstraction is already broken, should be fixed for O // right now, hooking the dynamic quicklist the less ugly possible way - QuicklistManager::Default()->RegisterQuicklist(_quicklist.GetPointer()); - - // Add to introspection - AddChild(_quicklist.GetPointer()); - AddChild(_tooltip.GetPointer()); + mouse_enter.connect(sigc::mem_fun(this, &LauncherIcon::RecvMouseEnter)); mouse_leave.connect(sigc::mem_fun(this, &LauncherIcon::RecvMouseLeave)); @@ -123,8 +114,11 @@ LauncherIcon::~LauncherIcon() SetQuirk(QUIRK_URGENT, false); // Remove from introspection - RemoveChild(_quicklist.GetPointer()); - RemoveChild(_tooltip.GetPointer()); + + if (_quicklist) + RemoveChild(_quicklist.GetPointer()); + if (_tooltip) + RemoveChild(_tooltip.GetPointer()); if (_present_time_handle) g_source_remove(_present_time_handle); @@ -158,6 +152,22 @@ LauncherIcon::~LauncherIcon() } } +void LauncherIcon::LoadTooltip() +{ + _tooltip = new Tooltip(); + AddChild(_tooltip.GetPointer()); + + _tooltip->SetText(nux::NString(tooltip_text().c_str())); +} + +void LauncherIcon::LoadQuicklist() +{ + _quicklist = new QuicklistView(); + AddChild(_quicklist.GetPointer()); + + QuicklistManager::Default()->RegisterQuicklist(_quicklist.GetPointer()); +} + const bool LauncherIcon::WindowVisibleOnMonitor(int monitor) { @@ -451,7 +461,8 @@ bool LauncherIcon::SetTooltipText(std::string& target, std::string const& value) if (escaped != target) { target = escaped; - _tooltip->SetText(nux::NString(target.c_str())); + if (_tooltip) + _tooltip->SetText(nux::NString(target.c_str())); result = true; } @@ -476,7 +487,7 @@ LauncherIcon::GetShortcut() void LauncherIcon::ShowTooltip() { - if (_quicklist->IsVisible()) + if (_quicklist && _quicklist->IsVisible()) return; int tip_x = 100; @@ -488,6 +499,8 @@ LauncherIcon::ShowTooltip() tip_y = geo.y + _center[_last_monitor].y; } + if (!_tooltip) + LoadTooltip(); _tooltip->ShowTooltipWithTipAt(tip_x, tip_y); _tooltip->ShowWindow(!tooltip_text().empty()); } @@ -509,17 +522,22 @@ void LauncherIcon::RecvMouseLeave(int monitor) { _last_monitor = -1; - _tooltip->ShowWindow(false); + if (_tooltip) + _tooltip->ShowWindow(false); } bool LauncherIcon::OpenQuicklist(bool default_to_first_item, int monitor) { std::list<DbusmenuMenuitem*> menus = Menus(); + if (!_quicklist) + LoadQuicklist(); + if (menus.empty()) return false; - _tooltip->ShowWindow(false); + if (_tooltip) + _tooltip->ShowWindow(false); _quicklist->RemoveAllMenuItem(); for (auto menu_item : menus) @@ -601,7 +619,7 @@ void LauncherIcon::RecvMouseUp(int button, int monitor) { if (button == 3) { - if (_quicklist->IsVisible()) + if (_quicklist && _quicklist->IsVisible()) _quicklist->CaptureMouseDownAnyWhereElse(true); } } @@ -619,7 +637,8 @@ void LauncherIcon::RecvMouseClick(int button, int monitor) void LauncherIcon::HideTooltip() { - _tooltip->ShowWindow(false); + if (_tooltip) + _tooltip->ShowWindow(false); } gboolean @@ -649,9 +668,9 @@ LauncherIcon::SetCenter(nux::Point3 center, int monitor, nux::Geometry geo) tip_x = geo.x + geo.width - 4 * geo.width / 48; tip_y = geo.y + _center[monitor].y; - if (_quicklist->IsVisible()) + if (_quicklist && _quicklist->IsVisible()) QuicklistManager::Default()->ShowQuicklist(_quicklist.GetPointer(), tip_x, tip_y); - else if (_tooltip->IsVisible()) + else if (_tooltip && _tooltip->IsVisible()) _tooltip->ShowTooltipWithTipAt(tip_x, tip_y); } @@ -742,7 +761,7 @@ LauncherIcon::Unpresent() void LauncherIcon::Remove() { - if (_quicklist->IsVisible()) + if (_quicklist && _quicklist->IsVisible()) _quicklist->Hide(); SetQuirk(QUIRK_VISIBLE, false); diff --git a/plugins/unityshell/src/LauncherIcon.h b/plugins/unityshell/src/LauncherIcon.h index 0155f2325..6d45c8d39 100644 --- a/plugins/unityshell/src/LauncherIcon.h +++ b/plugins/unityshell/src/LauncherIcon.h @@ -263,8 +263,6 @@ protected: void OnRemoteProgressVisibleChanged(LauncherEntryRemote* remote); - nux::ObjectPtr<Tooltip> _tooltip; - nux::ObjectPtr<QuicklistView> _quicklist; // This looks like a case for boost::logical::tribool static int _current_theme_is_mono; @@ -278,6 +276,9 @@ private: Quirk quirk; } DelayedUpdateArg; + nux::ObjectPtr<Tooltip> _tooltip; + nux::ObjectPtr<QuicklistView> _quicklist; + static void ChildRealized(DbusmenuMenuitem* newitem, QuicklistView* quicklist); static void RootChanged(DbusmenuClient* client, DbusmenuMenuitem* newroot, QuicklistView* quicklist); static gboolean OnPresentTimeout(gpointer data); @@ -286,8 +287,10 @@ private: void ColorForIcon(GdkPixbuf* pixbuf, nux::Color& background, nux::Color& glow); + void LoadTooltip(); + void LoadQuicklist(); + std::vector<bool> _has_visible_window; - bool _quicklist_is_initialized; bool _remote_urgent; float _present_urgency; float _progress; |
