Merge lp:~3v1n0/unity/input-monitor-menus-scrubbing-triangolation into lp:unity

Proposed by Marco Trevisan (Treviño) on 2016-08-30
Status: Merged
Approved by: Andrea Azzarone on 2016-08-30
Approved revision: no longer in the source branch.
Merged at revision: 4187
Proposed branch: lp:~3v1n0/unity/input-monitor-menus-scrubbing-triangolation
Merge into: lp:unity
Prerequisite: lp:~3v1n0/unity/input-monitor-lockscreen-panel
Diff against target: 1307 lines (+360/-246)
26 files modified
decorations/DecoratedWindow.cpp (+2/-9)
decorations/DecorationsMenuLayout.cpp (+14/-10)
decorations/DecorationsMenuLayout.h (+2/-1)
decorations/DecorationsPriv.h (+0/-1)
lockscreen/KylinLockScreenShield.cpp (+1/-1)
lockscreen/LockScreenBaseShield.cpp (+0/-2)
lockscreen/LockScreenBaseShield.h (+3/-4)
lockscreen/LockScreenController.cpp (+3/-3)
lockscreen/LockScreenController.h (+1/-2)
lockscreen/LockScreenPanel.cpp (+19/-36)
lockscreen/LockScreenPanel.h (+4/-5)
lockscreen/LockScreenShield.cpp (+7/-6)
lockscreen/LockScreenShield.h (+4/-3)
lockscreen/LockScreenShieldFactory.cpp (+2/-2)
lockscreen/LockScreenShieldFactory.h (+3/-3)
panel/PanelIndicatorEntryView.cpp (+10/-0)
panel/PanelMenuView.cpp (+1/-7)
panel/PanelMenuView.h (+0/-2)
panel/PanelView.cpp (+2/-105)
panel/PanelView.h (+2/-9)
tests/test_lockscreen_controller.cpp (+2/-2)
unity-shared/InputMonitor.cpp (+39/-5)
unity-shared/InputMonitor.h (+3/-27)
unity-shared/MenuManager.cpp (+162/-1)
unity-shared/MenuManager.h (+4/-0)
unity-shared/SigcSlotHash.h (+70/-0)
To merge this branch: bzr merge lp:~3v1n0/unity/input-monitor-menus-scrubbing-triangolation
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) 2016-08-30 Approve on 2016-08-30
Review via email: mp+304353@code.launchpad.net

This proposal supersedes a proposal from 2016-08-30.

Commit message

MenuManager: add support for mouse trackers with triangle algorithm support

It allows to register pointer trackers with menu entries selection by using the triangle
technique which prevents menus items from being opened on quick menu scrubbing

Then use use menu::Manager pointer tracker for entries activation in PanelView, LockScreenPanel and DecorationsMenuLayout

To post a comment you must log in.
3827. By Marco Trevisan (Treviño) on 2016-08-30

MenuManager: update active tracker on removal

Andrea Azzarone (azzar1) wrote :

+1

review: Approve
3828. By Marco Trevisan (Treviño) on 2016-08-30

SigcSlotHash: ensure it works with GCC-6

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'decorations/DecoratedWindow.cpp'
--- decorations/DecoratedWindow.cpp 2016-08-06 16:24:45 +0000
+++ decorations/DecoratedWindow.cpp 2016-09-01 22:11:45 +0000
@@ -37,7 +37,6 @@
37{37{
38namespace38namespace
39{39{
40const std::string MENUS_PANEL_NAME = "WindowLIM";
41const int SHADOW_BLUR_MARGIN_FACTOR = 2;40const int SHADOW_BLUR_MARGIN_FACTOR = 2;
42}41}
4342
@@ -55,7 +54,6 @@
55 , deco_elements_(cu::DecorationElement::NONE)54 , deco_elements_(cu::DecorationElement::NONE)
56 , last_mwm_decor_(win_->mwmDecor())55 , last_mwm_decor_(win_->mwmDecor())
57 , last_actions_(win_->actions())56 , last_actions_(win_->actions())
58 , panel_id_(MENUS_PANEL_NAME + std::to_string(win_->id()))
59 , cv_(Settings::Instance().em())57 , cv_(Settings::Instance().em())
60{58{
61 active.changed.connect([this] (bool active) {59 active.changed.connect([this] (bool active) {
@@ -932,18 +930,13 @@
932 sliding_layout->mouse_owner = grab_edge_->mouse_owner();930 sliding_layout->mouse_owner = grab_edge_->mouse_owner();
933}931}
934932
935inline std::string const& Window::Impl::GetMenusPanelID() const
936{
937 return panel_id_;
938}
939
940void Window::Impl::UnsetAppMenu()933void Window::Impl::UnsetAppMenu()
941{934{
942 if (!menus_)935 if (!menus_)
943 return;936 return;
944937
945 auto const& indicators = manager_->impl_->menu_manager_->Indicators();938 auto const& indicators = manager_->impl_->menu_manager_->Indicators();
946 indicators->SyncGeometries(GetMenusPanelID(), indicator::EntryLocationMap());939 indicators->SyncGeometries(menus_->MenubarId(), indicator::EntryLocationMap());
947 sliding_layout_->SetInputItem(nullptr);940 sliding_layout_->SetInputItem(nullptr);
948 grab_mouse_changed_->disconnect();941 grab_mouse_changed_->disconnect();
949}942}
@@ -956,7 +949,7 @@
956 auto const& indicators = manager_->impl_->menu_manager_->Indicators();949 auto const& indicators = manager_->impl_->menu_manager_->Indicators();
957 indicator::EntryLocationMap map;950 indicator::EntryLocationMap map;
958 menus_->ChildrenGeometries(map);951 menus_->ChildrenGeometries(map);
959 indicators->SyncGeometries(GetMenusPanelID(), map);952 indicators->SyncGeometries(menus_->MenubarId(), map);
960}953}
961954
962bool Window::Impl::ActivateMenu(std::string const& entry_id)955bool Window::Impl::ActivateMenu(std::string const& entry_id)
963956
=== modified file 'decorations/DecorationsMenuLayout.cpp'
--- decorations/DecorationsMenuLayout.cpp 2016-09-01 22:11:44 +0000
+++ decorations/DecorationsMenuLayout.cpp 2016-09-01 22:11:45 +0000
@@ -20,12 +20,15 @@
20#include "DecorationsMenuLayout.h"20#include "DecorationsMenuLayout.h"
21#include "DecorationsMenuEntry.h"21#include "DecorationsMenuEntry.h"
22#include "DecorationsMenuDropdown.h"22#include "DecorationsMenuDropdown.h"
23#include "InputMonitor.h"
2423
25namespace unity24namespace unity
26{25{
27namespace decoration26namespace decoration
28{27{
28namespace
29{
30const std::string MENUS_PANEL_NAME = "WindowLIM";
31}
2932
30using namespace indicator;33using namespace indicator;
3134
@@ -35,6 +38,7 @@
35 , menu_manager_(menu)38 , menu_manager_(menu)
36 , win_(win)39 , win_(win)
37 , dropdown_(std::make_shared<MenuDropdown>(menu_manager_->Indicators(), win))40 , dropdown_(std::make_shared<MenuDropdown>(menu_manager_->Indicators(), win))
41 , menubar_id_(MENUS_PANEL_NAME + std::to_string(win_->id()))
38{42{
39 visible = false;43 visible = false;
40}44}
@@ -91,6 +95,11 @@
91 Relayout();95 Relayout();
92}96}
9397
98std::string const& MenuLayout::MenubarId() const
99{
100 return menubar_id_;
101}
102
94bool MenuLayout::ActivateMenu(std::string const& entry_id)103bool MenuLayout::ActivateMenu(std::string const& entry_id)
95{104{
96 MenuEntry::Ptr target;105 MenuEntry::Ptr target;
@@ -169,21 +178,16 @@
169178
170 if (active && items_.size() > 1)179 if (active && items_.size() > 1)
171 {180 {
172 auto const& event_cb = sigc::mem_fun(this, &MenuLayout::OnEntryInputEvent);181 menu_manager_->RegisterTracker(menubar_id_, (sigc::track_obj([this] (int x, int y, double speed) {
173 input::Monitor::Get().RegisterClient(input::Events::POINTER, event_cb);182 ActivateMenu(CompPoint(x, y));
183 }, *this)));
174 }184 }
175 else if (!active)185 else if (!active)
176 {186 {
177 input::Monitor::Get().UnregisterClient(sigc::mem_fun(this, &MenuLayout::OnEntryInputEvent));187 menu_manager_->UnregisterTracker(menubar_id_);
178 }188 }
179}189}
180190
181void MenuLayout::OnEntryInputEvent(XEvent const& e)
182{
183 if (e.type == MotionNotify)
184 ActivateMenu(CompPoint(e.xmotion.x_root, e.xmotion.y_root));
185}
186
187void MenuLayout::ChildrenGeometries(EntryLocationMap& map) const191void MenuLayout::ChildrenGeometries(EntryLocationMap& map) const
188{192{
189 for (auto const& item : items_)193 for (auto const& item : items_)
190194
=== modified file 'decorations/DecorationsMenuLayout.h'
--- decorations/DecorationsMenuLayout.h 2016-09-01 22:11:44 +0000
+++ decorations/DecorationsMenuLayout.h 2016-09-01 22:11:45 +0000
@@ -44,6 +44,7 @@
44 bool ActivateMenu(std::string const& entry_id);44 bool ActivateMenu(std::string const& entry_id);
45 bool ActivateMenu(CompPoint const&);45 bool ActivateMenu(CompPoint const&);
46 void ChildrenGeometries(indicator::EntryLocationMap&) const;46 void ChildrenGeometries(indicator::EntryLocationMap&) const;
47 std::string const& MenubarId() const;
4748
48protected:49protected:
49 void DoRelayout() override;50 void DoRelayout() override;
@@ -53,12 +54,12 @@
53 void OnEntryMouseOwnershipChanged(bool);54 void OnEntryMouseOwnershipChanged(bool);
54 void OnEntryActiveChanged(bool);55 void OnEntryActiveChanged(bool);
55 void OnEntryShowNowChanged(bool);56 void OnEntryShowNowChanged(bool);
56 void OnEntryInputEvent(XEvent const&);
5757
58 menu::Manager::Ptr menu_manager_;58 menu::Manager::Ptr menu_manager_;
59 CompWindow* win_;59 CompWindow* win_;
60 glib::Source::UniquePtr show_now_timeout_;60 glib::Source::UniquePtr show_now_timeout_;
61 std::shared_ptr<MenuDropdown> dropdown_;61 std::shared_ptr<MenuDropdown> dropdown_;
62 std::string menubar_id_;
62};63};
6364
64} // decoration namespace65} // decoration namespace
6566
=== modified file 'decorations/DecorationsPriv.h'
--- decorations/DecorationsPriv.h 2016-08-06 16:24:45 +0000
+++ decorations/DecorationsPriv.h 2016-09-01 22:11:45 +0000
@@ -162,7 +162,6 @@
162 connection::Wrapper dpi_changed_;162 connection::Wrapper dpi_changed_;
163 connection::Wrapper grab_mouse_changed_;163 connection::Wrapper grab_mouse_changed_;
164 std::string last_title_;164 std::string last_title_;
165 std::string panel_id_;
166 std::vector<cu::SimpleTextureQuad> bg_textures_;165 std::vector<cu::SimpleTextureQuad> bg_textures_;
167 cu::PixmapTexture::Ptr shaped_shadow_pixmap_;166 cu::PixmapTexture::Ptr shaped_shadow_pixmap_;
168 std::shared_ptr<ForceQuitDialog> force_quit_;167 std::shared_ptr<ForceQuitDialog> force_quit_;
169168
=== modified file 'lockscreen/KylinLockScreenShield.cpp'
--- lockscreen/KylinLockScreenShield.cpp 2015-12-07 03:09:28 +0000
+++ lockscreen/KylinLockScreenShield.cpp 2016-09-01 22:11:45 +0000
@@ -37,7 +37,7 @@
37 Accelerators::Ptr const& accelerators,37 Accelerators::Ptr const& accelerators,
38 nux::ObjectPtr<AbstractUserPromptView> const& prompt_view,38 nux::ObjectPtr<AbstractUserPromptView> const& prompt_view,
39 int monitor_num, bool is_primary)39 int monitor_num, bool is_primary)
40 : BaseShield(session_manager, nullptr, accelerators, prompt_view, monitor_num, is_primary)40 : BaseShield(session_manager, accelerators, prompt_view, monitor_num, is_primary)
41{41{
42 is_primary ? ShowPrimaryView() : ShowSecondaryView();42 is_primary ? ShowPrimaryView() : ShowSecondaryView();
43 EnableInputWindow(true);43 EnableInputWindow(true);
4444
=== modified file 'lockscreen/LockScreenBaseShield.cpp'
--- lockscreen/LockScreenBaseShield.cpp 2015-12-03 14:13:10 +0000
+++ lockscreen/LockScreenBaseShield.cpp 2016-09-01 22:11:45 +0000
@@ -38,7 +38,6 @@
38}38}
3939
40BaseShield::BaseShield(session::Manager::Ptr const& session,40BaseShield::BaseShield(session::Manager::Ptr const& session,
41 indicator::Indicators::Ptr const& indicators,
42 Accelerators::Ptr const& accelerators,41 Accelerators::Ptr const& accelerators,
43 nux::ObjectPtr<AbstractUserPromptView> const& prompt_view,42 nux::ObjectPtr<AbstractUserPromptView> const& prompt_view,
44 int monitor_num, bool is_primary)43 int monitor_num, bool is_primary)
@@ -47,7 +46,6 @@
47 , monitor(monitor_num)46 , monitor(monitor_num)
48 , scale(1.0)47 , scale(1.0)
49 , session_manager_(session)48 , session_manager_(session)
50 , indicators_(indicators)
51 , accelerators_(accelerators)49 , accelerators_(accelerators)
52 , prompt_view_(prompt_view)50 , prompt_view_(prompt_view)
53 , bg_settings_(std::make_shared<BackgroundSettings>())51 , bg_settings_(std::make_shared<BackgroundSettings>())
5452
=== modified file 'lockscreen/LockScreenBaseShield.h'
--- lockscreen/LockScreenBaseShield.h 2016-03-31 09:51:33 +0000
+++ lockscreen/LockScreenBaseShield.h 2016-09-01 22:11:45 +0000
@@ -21,8 +21,8 @@
21#define UNITY_LOCKSCREEN_BASE_SHIELD_H21#define UNITY_LOCKSCREEN_BASE_SHIELD_H
2222
23#include <NuxCore/Property.h>23#include <NuxCore/Property.h>
24#include "UnityCore/ConnectionManager.h"
24#include "UnityCore/SessionManager.h"25#include "UnityCore/SessionManager.h"
25#include "UnityCore/Indicators.h"
26#include "UnityCore/GLibSource.h"26#include "UnityCore/GLibSource.h"
27#include "unity-shared/MockableBaseWindow.h"27#include "unity-shared/MockableBaseWindow.h"
2828
@@ -39,8 +39,8 @@
39class BaseShield : public MockableBaseWindow39class BaseShield : public MockableBaseWindow
40{40{
41public:41public:
42 BaseShield(session::Manager::Ptr const&, indicator::Indicators::Ptr const&,42 BaseShield(session::Manager::Ptr const&, Accelerators::Ptr const&,
43 Accelerators::Ptr const&, nux::ObjectPtr<AbstractUserPromptView> const&,43 nux::ObjectPtr<AbstractUserPromptView> const&,
44 int monitor_num, bool is_primary);44 int monitor_num, bool is_primary);
4545
46 nux::Property<bool> primary;46 nux::Property<bool> primary;
@@ -69,7 +69,6 @@
69 void UpdateScale();69 void UpdateScale();
7070
71 session::Manager::Ptr session_manager_;71 session::Manager::Ptr session_manager_;
72 indicator::Indicators::Ptr indicators_;
73 Accelerators::Ptr accelerators_;72 Accelerators::Ptr accelerators_;
74 nux::ObjectPtr<AbstractUserPromptView> prompt_view_;73 nux::ObjectPtr<AbstractUserPromptView> prompt_view_;
75 std::shared_ptr<BackgroundSettings> bg_settings_;74 std::shared_ptr<BackgroundSettings> bg_settings_;
7675
=== modified file 'lockscreen/LockScreenController.cpp'
--- lockscreen/LockScreenController.cpp 2016-07-04 12:45:06 +0000
+++ lockscreen/LockScreenController.cpp 2016-09-01 22:11:45 +0000
@@ -130,7 +130,7 @@
130130
131 upstart_wrapper_->Emit("desktop-unlock");131 upstart_wrapper_->Emit("desktop-unlock");
132 accelerator_controller_.reset();132 accelerator_controller_.reset();
133 indicators_.reset();133 menu_manager_.reset();
134 }134 }
135 else if (!prompt_activation_)135 else if (!prompt_activation_)
136 {136 {
@@ -252,7 +252,7 @@
252252
253 if (i >= shields_size)253 if (i >= shields_size)
254 {254 {
255 shield = shield_factory_->CreateShield(session_manager_, indicators_, accelerator_controller_->GetAccelerators(), prompt_view, i, i == primary);255 shield = shield_factory_->CreateShield(session_manager_, menu_manager_, accelerator_controller_->GetAccelerators(), prompt_view, i, i == primary);
256 is_new = true;256 is_new = true;
257 }257 }
258258
@@ -462,7 +462,7 @@
462462
463void Controller::LockScreen()463void Controller::LockScreen()
464{464{
465 indicators_ = std::make_shared<indicator::LockScreenDBusIndicators>();465 menu_manager_ = std::make_shared<menu::Manager>(std::make_shared<indicator::LockScreenDBusIndicators>(), key_grabber_);
466 upstart_wrapper_->Emit("desktop-lock");466 upstart_wrapper_->Emit("desktop-lock");
467467
468 accelerator_controller_ = std::make_shared<AcceleratorController>(key_grabber_);468 accelerator_controller_ = std::make_shared<AcceleratorController>(key_grabber_);
469469
=== modified file 'lockscreen/LockScreenController.h'
--- lockscreen/LockScreenController.h 2016-06-21 01:28:26 +0000
+++ lockscreen/LockScreenController.h 2016-09-01 22:11:45 +0000
@@ -30,7 +30,6 @@
30#include "SuspendInhibitorManager.h"30#include "SuspendInhibitorManager.h"
31#include "ScreenSaverDBusManager.h"31#include "ScreenSaverDBusManager.h"
32#include "unity-shared/BackgroundEffectHelper.h"32#include "unity-shared/BackgroundEffectHelper.h"
33#include "unity-shared/KeyGrabber.h"
34#include "unity-shared/UpstartWrapper.h"33#include "unity-shared/UpstartWrapper.h"
3534
36namespace unity35namespace unity
@@ -85,8 +84,8 @@
8584
86 DBusManager::Ptr dbus_manager_;85 DBusManager::Ptr dbus_manager_;
87 session::Manager::Ptr session_manager_;86 session::Manager::Ptr session_manager_;
87 menu::Manager::Ptr menu_manager_;
88 key::Grabber::Ptr key_grabber_;88 key::Grabber::Ptr key_grabber_;
89 indicator::Indicators::Ptr indicators_;
90 AcceleratorController::Ptr accelerator_controller_;89 AcceleratorController::Ptr accelerator_controller_;
91 UpstartWrapper::Ptr upstart_wrapper_;90 UpstartWrapper::Ptr upstart_wrapper_;
92 ShieldFactoryInterface::Ptr shield_factory_;91 ShieldFactoryInterface::Ptr shield_factory_;
9392
=== modified file 'lockscreen/LockScreenPanel.cpp'
--- lockscreen/LockScreenPanel.cpp 2016-09-01 22:11:44 +0000
+++ lockscreen/LockScreenPanel.cpp 2016-09-01 22:11:45 +0000
@@ -44,11 +44,11 @@
44using namespace indicator;44using namespace indicator;
45using namespace panel;45using namespace panel;
4646
47Panel::Panel(int monitor_, Indicators::Ptr const& indicators, session::Manager::Ptr const& session_manager)47Panel::Panel(int monitor_, menu::Manager::Ptr const& menu_manager, session::Manager::Ptr const& session_manager)
48 : nux::View(NUX_TRACKER_LOCATION)48 : nux::View(NUX_TRACKER_LOCATION)
49 , active(false)49 , active(false)
50 , monitor(monitor_)50 , monitor(monitor_)
51 , indicators_(indicators)51 , menu_manager_(menu_manager)
52 , needs_geo_sync_(true)52 , needs_geo_sync_(true)
53{53{
54 double scale = unity::Settings::Instance().em(monitor)->DPIScale();54 double scale = unity::Settings::Instance().em(monitor)->DPIScale();
@@ -72,14 +72,19 @@
72 indicators_view_->on_indicator_updated.connect(sigc::mem_fun(this, &Panel::OnIndicatorViewUpdated));72 indicators_view_->on_indicator_updated.connect(sigc::mem_fun(this, &Panel::OnIndicatorViewUpdated));
73 layout->AddView(indicators_view_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);73 layout->AddView(indicators_view_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
7474
75 for (auto const& indicator : indicators_->GetIndicators())75 auto indicators = menu_manager_->Indicators();
76 menu_manager_->RegisterTracker(GetPanelName(), (sigc::track_obj([this] (int x, int y, double speed) {
77 indicators_view_->ActivateEntryAt(x, y);
78 }, *this)));
79
80 for (auto const& indicator : indicators->GetIndicators())
76 AddIndicator(indicator);81 AddIndicator(indicator);
7782
78 indicators_->on_object_added.connect(sigc::mem_fun(this, &Panel::AddIndicator));83 indicators->on_object_added.connect(sigc::mem_fun(this, &Panel::AddIndicator));
79 indicators_->on_object_removed.connect(sigc::mem_fun(this, &Panel::RemoveIndicator));84 indicators->on_object_removed.connect(sigc::mem_fun(this, &Panel::RemoveIndicator));
80 indicators_->on_entry_show_menu.connect(sigc::mem_fun(this, &Panel::OnEntryShowMenu));85 indicators->on_entry_show_menu.connect(sigc::mem_fun(this, &Panel::OnEntryShowMenu));
81 indicators_->on_entry_activated.connect(sigc::mem_fun(this, &Panel::OnEntryActivated));86 indicators->on_entry_activated.connect(sigc::mem_fun(this, &Panel::OnEntryActivated));
82 indicators_->on_entry_activate_request.connect(sigc::mem_fun(this, &Panel::OnEntryActivateRequest));87 indicators->on_entry_activate_request.connect(sigc::mem_fun(this, &Panel::OnEntryActivateRequest));
8388
84 monitor.changed.connect([this, hostname] (int monitor) {89 monitor.changed.connect([this, hostname] (int monitor) {
85 double scale = unity::Settings::Instance().em(monitor)->DPIScale();90 double scale = unity::Settings::Instance().em(monitor)->DPIScale();
@@ -159,12 +164,7 @@
159 if (!GetInputEventSensitivity())164 if (!GetInputEventSensitivity())
160 return;165 return;
161166
162 if (!active)167 active = true;
163 {
164 // This is ugly... But Nux fault!
165 WindowManager::Default().UnGrabMousePointer(CurrentTime, button, x, y);
166 active = true;
167 }
168}168}
169169
170void Panel::OnEntryActivateRequest(std::string const& entry_id)170void Panel::OnEntryActivateRequest(std::string const& entry_id)
@@ -178,33 +178,16 @@
178 if (!GetInputEventSensitivity() || (!panel.empty() && panel != GetPanelName()))178 if (!GetInputEventSensitivity() || (!panel.empty() && panel != GetPanelName()))
179 return;179 return;
180180
181 bool active = !entry_id.empty();181 bool valid_entry = !entry_id.empty();
182182
183 if (active && !WindowManager::Default().IsScreenGrabbed())183 if (valid_entry && !WindowManager::Default().IsScreenGrabbed())
184 {184 {
185 // The menu didn't grab the keyboard, let's take it back.185 // The menu didn't grab the keyboard, let's take it back.
186 nux::GetWindowCompositor().GrabKeyboardAdd(static_cast<nux::BaseWindow*>(GetTopLevelViewWindow()));186 nux::GetWindowCompositor().GrabKeyboardAdd(static_cast<nux::BaseWindow*>(GetTopLevelViewWindow()));
187 }187 }
188188
189 auto& im = input::Monitor::Get();189 if (!valid_entry)
190 auto const& event_cb = sigc::mem_fun(this, &Panel::OnEntryEvent);190 active = valid_entry;
191
192 if (active)
193 {
194 if (im.RegisterClient(input::Events::POINTER, event_cb))
195 indicators_view_->ActivateEntry(entry_id);
196 }
197 else
198 {
199 im.UnregisterClient(event_cb);
200 this->active = active;
201 }
202}
203
204void Panel::OnEntryEvent(XEvent const& e)
205{
206 if (e.type == MotionNotify && GetAbsoluteGeometry().IsPointInside(e.xmotion.x, e.xmotion.y))
207 indicators_view_->ActivateEntryAt(e.xmotion.x, e.xmotion.y);
208}191}
209192
210void Panel::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw)193void Panel::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw)
@@ -228,7 +211,7 @@
228 {211 {
229 EntryLocationMap locations;212 EntryLocationMap locations;
230 indicators_view_->GetGeometryForSync(locations);213 indicators_view_->GetGeometryForSync(locations);
231 indicators_->SyncGeometries(GetPanelName(), locations);214 menu_manager_->Indicators()->SyncGeometries(GetPanelName(), locations);
232 needs_geo_sync_ = false;215 needs_geo_sync_ = false;
233 }216 }
234}217}
235218
=== modified file 'lockscreen/LockScreenPanel.h'
--- lockscreen/LockScreenPanel.h 2016-09-01 22:11:44 +0000
+++ lockscreen/LockScreenPanel.h 2016-09-01 22:11:45 +0000
@@ -22,9 +22,9 @@
2222
23#include <Nux/Nux.h>23#include <Nux/Nux.h>
24#include <Nux/View.h>24#include <Nux/View.h>
25#include "UnityCore/Indicators.h"
26#include "UnityCore/GLibSource.h"25#include "UnityCore/GLibSource.h"
27#include "UnityCore/SessionManager.h"26#include "UnityCore/SessionManager.h"
27#include "unity-shared/MenuManager.h"
2828
29namespace unity29namespace unity
30{30{
@@ -39,7 +39,7 @@
39class Panel : public nux::View39class Panel : public nux::View
40{40{
41public:41public:
42 Panel(int monitor, indicator::Indicators::Ptr const&, session::Manager::Ptr const&);42 Panel(int monitor, menu::Manager::Ptr const&, session::Manager::Ptr const&);
4343
44 nux::Property<bool> active;44 nux::Property<bool> active;
45 nux::Property<int> monitor;45 nux::Property<int> monitor;
@@ -55,15 +55,14 @@
55 void AddIndicator(indicator::Indicator::Ptr const&);55 void AddIndicator(indicator::Indicator::Ptr const&);
56 void RemoveIndicator(indicator::Indicator::Ptr const&);56 void RemoveIndicator(indicator::Indicator::Ptr const&);
57 void OnIndicatorViewUpdated();57 void OnIndicatorViewUpdated();
58 void OnEntryActivated(std::string const& panel, std::string const& entry_id, nux::Rect const& geo);58 void OnEntryActivated(std::string const& panel, std::string const& entry_id, nux::Rect const&);
59 void OnEntryShowMenu(std::string const& entry_id, unsigned xid, int x, int y, unsigned button);59 void OnEntryShowMenu(std::string const& entry_id, unsigned xid, int x, int y, unsigned button);
60 void OnEntryActivateRequest(std::string const& entry_id);60 void OnEntryActivateRequest(std::string const& entry_id);
61 void OnEntryEvent(XEvent const&);
6261
63 void UpdateSize();62 void UpdateSize();
64 std::string GetPanelName() const;63 std::string GetPanelName() const;
6564
66 indicator::Indicators::Ptr indicators_;65 menu::Manager::Ptr menu_manager_;
67 panel::PanelIndicatorsView* indicators_view_;66 panel::PanelIndicatorsView* indicators_view_;
68 bool needs_geo_sync_;67 bool needs_geo_sync_;
69};68};
7069
=== modified file 'lockscreen/LockScreenShield.cpp'
--- lockscreen/LockScreenShield.cpp 2015-12-03 14:13:10 +0000
+++ lockscreen/LockScreenShield.cpp 2016-09-01 22:11:45 +0000
@@ -32,11 +32,12 @@
32{32{
3333
34Shield::Shield(session::Manager::Ptr const& session_manager,34Shield::Shield(session::Manager::Ptr const& session_manager,
35 indicator::Indicators::Ptr const& indicators,35 menu::Manager::Ptr const& menu_manager,
36 Accelerators::Ptr const& accelerators,36 Accelerators::Ptr const& accelerators,
37 nux::ObjectPtr<AbstractUserPromptView> const& prompt_view,37 nux::ObjectPtr<AbstractUserPromptView> const& prompt_view,
38 int monitor_num, bool is_primary)38 int monitor_num, bool is_primary)
39 : BaseShield(session_manager, indicators, accelerators, prompt_view, monitor_num, is_primary)39 : BaseShield(session_manager, accelerators, prompt_view, monitor_num, is_primary)
40 , menu_manager_(menu_manager)
40 , panel_view_(nullptr)41 , panel_view_(nullptr)
41{42{
42 is_primary ? ShowPrimaryView() : ShowSecondaryView();43 is_primary ? ShowPrimaryView() : ShowSecondaryView();
@@ -91,11 +92,11 @@
9192
92Panel* Shield::CreatePanel()93Panel* Shield::CreatePanel()
93{94{
94 if (!indicators_ || !session_manager_)95 if (!menu_manager_ || !session_manager_)
95 return nullptr;96 return nullptr;
9697
97 panel_view_ = new Panel(monitor, indicators_, session_manager_);98 panel_view_ = new Panel(monitor, menu_manager_, session_manager_);
98 panel_active_conn_ = panel_view_->active.changed.connect([this] (bool active) {99 panel_view_->active.changed.connect(sigc::track_obj([this] (bool active) {
99 if (primary())100 if (primary())
100 {101 {
101 if (active)102 if (active)
@@ -109,7 +110,7 @@
109 GrabScreen(false);110 GrabScreen(false);
110 }111 }
111 }112 }
112 });113 }, *this));
113114
114 return panel_view_;115 return panel_view_;
115}116}
116117
=== modified file 'lockscreen/LockScreenShield.h'
--- lockscreen/LockScreenShield.h 2015-12-03 14:13:10 +0000
+++ lockscreen/LockScreenShield.h 2016-09-01 22:11:45 +0000
@@ -20,8 +20,9 @@
20#ifndef UNITY_LOCKSCREEN_SHIELD_H20#ifndef UNITY_LOCKSCREEN_SHIELD_H
21#define UNITY_LOCKSCREEN_SHIELD_H21#define UNITY_LOCKSCREEN_SHIELD_H
2222
23#include <UnityCore/ConnectionManager.h>
24#include "LockScreenBaseShield.h"23#include "LockScreenBaseShield.h"
24#include "unity-shared/MenuManager.h"
25
2526
26namespace unity27namespace unity
27{28{
@@ -35,7 +36,7 @@
35{36{
36public:37public:
37 Shield(session::Manager::Ptr const&,38 Shield(session::Manager::Ptr const&,
38 indicator::Indicators::Ptr const&,39 menu::Manager::Ptr const&,
39 Accelerators::Ptr const&,40 Accelerators::Ptr const&,
40 nux::ObjectPtr<AbstractUserPromptView> const&,41 nux::ObjectPtr<AbstractUserPromptView> const&,
41 int monitor, bool is_primary);42 int monitor, bool is_primary);
@@ -50,7 +51,7 @@
50 void ShowPrimaryView() override;51 void ShowPrimaryView() override;
51 Panel* CreatePanel();52 Panel* CreatePanel();
5253
53 connection::Wrapper panel_active_conn_;54 menu::Manager::Ptr menu_manager_;
54 Panel* panel_view_;55 Panel* panel_view_;
55};56};
5657
5758
=== modified file 'lockscreen/LockScreenShieldFactory.cpp'
--- lockscreen/LockScreenShieldFactory.cpp 2015-12-04 08:17:46 +0000
+++ lockscreen/LockScreenShieldFactory.cpp 2016-09-01 22:11:45 +0000
@@ -28,7 +28,7 @@
28{28{
2929
30nux::ObjectPtr<BaseShield> ShieldFactory::CreateShield(session::Manager::Ptr const& session_manager,30nux::ObjectPtr<BaseShield> ShieldFactory::CreateShield(session::Manager::Ptr const& session_manager,
31 indicator::Indicators::Ptr const& indicators,31 menu::Manager::Ptr const& menu_manager,
32 Accelerators::Ptr const& accelerators,32 Accelerators::Ptr const& accelerators,
33 nux::ObjectPtr<AbstractUserPromptView> const& prompt_view,33 nux::ObjectPtr<AbstractUserPromptView> const& prompt_view,
34 int monitor, bool is_primary)34 int monitor, bool is_primary)
@@ -38,7 +38,7 @@
38 if (Settings::Instance().desktop_type() == DesktopType::UBUNTUKYLIN)38 if (Settings::Instance().desktop_type() == DesktopType::UBUNTUKYLIN)
39 shield = new KylinShield(session_manager, accelerators, prompt_view, monitor, is_primary);39 shield = new KylinShield(session_manager, accelerators, prompt_view, monitor, is_primary);
40 else40 else
41 shield = new Shield(session_manager, indicators, accelerators, prompt_view, monitor, is_primary);41 shield = new Shield(session_manager, menu_manager, accelerators, prompt_view, monitor, is_primary);
4242
43 return shield;43 return shield;
44}44}
4545
=== modified file 'lockscreen/LockScreenShieldFactory.h'
--- lockscreen/LockScreenShieldFactory.h 2016-03-31 09:51:33 +0000
+++ lockscreen/LockScreenShieldFactory.h 2016-09-01 22:11:45 +0000
@@ -22,7 +22,7 @@
2222
23#include <NuxCore/NuxCore.h>23#include <NuxCore/NuxCore.h>
24#include "UnityCore/SessionManager.h"24#include "UnityCore/SessionManager.h"
25#include "UnityCore/Indicators.h"25#include "unity-shared/MenuManager.h"
26#include "LockScreenAccelerators.h"26#include "LockScreenAccelerators.h"
2727
28namespace unity28namespace unity
@@ -41,7 +41,7 @@
41 virtual ~ShieldFactoryInterface() = default;41 virtual ~ShieldFactoryInterface() = default;
4242
43 virtual nux::ObjectPtr<BaseShield> CreateShield(session::Manager::Ptr const&,43 virtual nux::ObjectPtr<BaseShield> CreateShield(session::Manager::Ptr const&,
44 indicator::Indicators::Ptr const&,44 menu::Manager::Ptr const&,
45 Accelerators::Ptr const&,45 Accelerators::Ptr const&,
46 nux::ObjectPtr<AbstractUserPromptView> const&,46 nux::ObjectPtr<AbstractUserPromptView> const&,
47 int monitor, bool is_primary) = 0;47 int monitor, bool is_primary) = 0;
@@ -50,7 +50,7 @@
50struct ShieldFactory : ShieldFactoryInterface50struct ShieldFactory : ShieldFactoryInterface
51{51{
52 nux::ObjectPtr<BaseShield> CreateShield(session::Manager::Ptr const&,52 nux::ObjectPtr<BaseShield> CreateShield(session::Manager::Ptr const&,
53 indicator::Indicators::Ptr const&,53 menu::Manager::Ptr const&,
54 Accelerators::Ptr const&,54 Accelerators::Ptr const&,
55 nux::ObjectPtr<AbstractUserPromptView> const&,55 nux::ObjectPtr<AbstractUserPromptView> const&,
56 int monitor, bool is_primary) override;56 int monitor, bool is_primary) override;
5757
=== modified file 'panel/PanelIndicatorEntryView.cpp'
--- panel/PanelIndicatorEntryView.cpp 2016-02-17 13:14:37 +0000
+++ panel/PanelIndicatorEntryView.cpp 2016-09-01 22:11:45 +0000
@@ -33,6 +33,8 @@
33#include "unity-shared/RawPixel.h"33#include "unity-shared/RawPixel.h"
34#include "unity-shared/WindowManager.h"34#include "unity-shared/WindowManager.h"
35#include "unity-shared/ThemeSettings.h"35#include "unity-shared/ThemeSettings.h"
36#include "unity-shared/UBusWrapper.h"
37#include "unity-shared/UBusMessages.h"
36#include "unity-shared/UnitySettings.h"38#include "unity-shared/UnitySettings.h"
3739
38namespace unity40namespace unity
@@ -117,6 +119,9 @@
117 }119 }
118 else120 else
119 {121 {
122 if (overlay_showing_)
123 UBusManager::SendMessage(UBUS_OVERLAY_CLOSE_REQUEST);
124
120 WindowManager& wm = WindowManager::Default();125 WindowManager& wm = WindowManager::Default();
121126
122 if (wm.IsExpoActive())127 if (wm.IsExpoActive())
@@ -140,6 +145,11 @@
140 wm.TerminateScale();145 wm.TerminateScale();
141 }146 }
142147
148 // This is ugly... But Nux fault!
149 auto const& abs_geo = GetAbsoluteGeometry();
150 guint64 timestamp = nux::GetGraphicsDisplay()->GetCurrentEvent().x11_timestamp;
151 WindowManager::Default().UnGrabMousePointer(timestamp, button, abs_geo.x, abs_geo.y);
152
143 Activate(button);153 Activate(button);
144 }154 }
145 }155 }
146156
=== modified file 'panel/PanelMenuView.cpp'
--- panel/PanelMenuView.cpp 2015-12-16 15:12:05 +0000
+++ panel/PanelMenuView.cpp 2016-09-01 22:11:45 +0000
@@ -102,7 +102,6 @@
102 , ignore_menu_visibility_(false)102 , ignore_menu_visibility_(false)
103 , integrated_menus_(menu_manager_->integrated_menus())103 , integrated_menus_(menu_manager_->integrated_menus())
104 , always_show_menus_(menu_manager_->always_show_menus())104 , always_show_menus_(menu_manager_->always_show_menus())
105 , ignore_leave_events_(false)
106 , desktop_name_(get_current_desktop())105 , desktop_name_(get_current_desktop())
107{106{
108 if (ApplicationWindowPtr const& win = ApplicationManager::Default().GetActiveWindow())107 if (ApplicationWindowPtr const& win = ApplicationManager::Default().GetActiveWindow())
@@ -1814,14 +1813,9 @@
1814 }1813 }
1815}1814}
18161815
1817void PanelMenuView::IgnoreLeaveEvents(bool ignore)
1818{
1819 ignore_leave_events_ = ignore;
1820}
1821
1822void PanelMenuView::OnPanelViewMouseLeave(int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state)1816void PanelMenuView::OnPanelViewMouseLeave(int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state)
1823{1817{
1824 if (always_show_menus_ || ignore_leave_events_)1818 if (always_show_menus_)
1825 return;1819 return;
18261820
1827 if (is_inside_)1821 if (is_inside_)
18281822
=== modified file 'panel/PanelMenuView.h'
--- panel/PanelMenuView.h 2015-11-05 14:54:13 +0000
+++ panel/PanelMenuView.h 2016-09-01 22:11:45 +0000
@@ -56,7 +56,6 @@
56 bool HasKeyActivableMenus() const;56 bool HasKeyActivableMenus() const;
5757
58 void NotifyAllMenusClosed();58 void NotifyAllMenusClosed();
59 void IgnoreLeaveEvents(bool);
6059
61 virtual void AddIndicator(indicator::Indicator::Ptr const& indicator);60 virtual void AddIndicator(indicator::Indicator::Ptr const& indicator);
6261
@@ -192,7 +191,6 @@
192 bool ignore_menu_visibility_;191 bool ignore_menu_visibility_;
193 bool integrated_menus_;192 bool integrated_menus_;
194 bool always_show_menus_;193 bool always_show_menus_;
195 bool ignore_leave_events_;
196194
197 nux::Geometry monitor_geo_;195 nux::Geometry monitor_geo_;
198 const std::string desktop_name_;196 const std::string desktop_name_;
199197
=== modified file 'panel/PanelView.cpp'
--- panel/PanelView.cpp 2016-09-01 22:11:44 +0000
+++ panel/PanelView.cpp 2016-09-01 22:11:45 +0000
@@ -23,7 +23,6 @@
2323
24#include <UnityCore/GLibWrapper.h>24#include <UnityCore/GLibWrapper.h>
2525
26#include "unity-shared/InputMonitor.h"
27#include "unity-shared/PanelStyle.h"26#include "unity-shared/PanelStyle.h"
28#include "unity-shared/RawPixel.h"27#include "unity-shared/RawPixel.h"
29#include "unity-shared/TextureCache.h"28#include "unity-shared/TextureCache.h"
@@ -54,7 +53,6 @@
54 : View(NUX_FILE_LINE_PARAM)53 : View(NUX_FILE_LINE_PARAM)
55 , parent_(parent)54 , parent_(parent)
56 , remote_(menus->Indicators())55 , remote_(menus->Indicators())
57 , last_pointer_time_(0)
58 , is_dirty_(true)56 , is_dirty_(true)
59 , opacity_maximized_toggle_(false)57 , opacity_maximized_toggle_(false)
60 , needs_geo_sync_(false)58 , needs_geo_sync_(false)
@@ -116,10 +114,9 @@
116114
117 remote_->on_object_added.connect(sigc::mem_fun(this, &PanelView::OnObjectAdded));115 remote_->on_object_added.connect(sigc::mem_fun(this, &PanelView::OnObjectAdded));
118 remote_->on_object_removed.connect(sigc::mem_fun(this, &PanelView::OnObjectRemoved));116 remote_->on_object_removed.connect(sigc::mem_fun(this, &PanelView::OnObjectRemoved));
119 remote_->on_entry_activated.connect(sigc::mem_fun(this, &PanelView::OnEntryActivated));
120 remote_->on_entry_show_menu.connect(sigc::mem_fun(this, &PanelView::OnEntryShowMenu));
121 menus->key_activate_entry.connect(sigc::mem_fun(this, &PanelView::ActivateEntry));117 menus->key_activate_entry.connect(sigc::mem_fun(this, &PanelView::ActivateEntry));
122 menus->open_first.connect(sigc::mem_fun(this, &PanelView::ActivateFirstSensitive));118 menus->open_first.connect(sigc::mem_fun(this, &PanelView::ActivateFirstSensitive));
119 menus->RegisterTracker(GetPanelName(), sigc::mem_fun(this, &PanelView::OnMenuPointerMoved));
123120
124 ubus_manager_.RegisterInterest(UBUS_OVERLAY_HIDDEN, sigc::mem_fun(this, &PanelView::OnOverlayHidden));121 ubus_manager_.RegisterInterest(UBUS_OVERLAY_HIDDEN, sigc::mem_fun(this, &PanelView::OnOverlayHidden));
125 ubus_manager_.RegisterInterest(UBUS_OVERLAY_SHOWN, sigc::mem_fun(this, &PanelView::OnOverlayShown));122 ubus_manager_.RegisterInterest(UBUS_OVERLAY_SHOWN, sigc::mem_fun(this, &PanelView::OnOverlayShown));
@@ -630,7 +627,7 @@
630 QueueDraw();627 QueueDraw();
631}628}
632629
633void PanelView::OnMenuPointerMoved(int x, int y)630void PanelView::OnMenuPointerMoved(int x, int y, double speed)
634{631{
635 nux::Geometry const& geo = GetAbsoluteGeometry();632 nux::Geometry const& geo = GetAbsoluteGeometry();
636633
@@ -651,106 +648,6 @@
651 }648 }
652}649}
653650
654namespace
655{
656bool PointInTriangle(nux::Point const& p, nux::Point const& t0, nux::Point const& t1, nux::Point const& t2)
657{
658 int s = t0.y * t2.x - t0.x * t2.y + (t2.y - t0.y) * p.x + (t0.x - t2.x) * p.y;
659 int t = t0.x * t1.y - t0.y * t1.x + (t0.y - t1.y) * p.x + (t1.x - t0.x) * p.y;
660
661 if ((s < 0) != (t < 0))
662 return false;
663
664 int A = -t1.y * t2.x + t0.y * (t2.x - t1.x) + t0.x * (t1.y - t2.y) + t1.x * t2.y;
665 if (A < 0)
666 {
667 s = -s;
668 t = -t;
669 A = -A;
670 }
671
672 return s > 0 && t > 0 && (s + t) < A;
673}
674
675double GetMouseVelocity(nux::Point const& p0, nux::Point const& p1, Time time_delta)
676{
677 int dx, dy;
678 double speed;
679
680 if (time_delta == 0)
681 return 1;
682
683 dx = p0.x - p1.x;
684 dy = p0.y - p1.y;
685
686 speed = sqrt(dx * dx + dy * dy) / time_delta;
687
688 return speed;
689}
690} // anonymous namespace
691
692void PanelView::OnActiveEntryEvent(XEvent const& e)
693{
694 if (e.type != MotionNotify)
695 return;
696
697 double scale = Settings::Instance().em(monitor_)->DPIScale();
698 nux::Point mouse(e.xmotion.x_root, e.xmotion.y_root);
699 double speed = GetMouseVelocity(mouse, tracked_pointer_pos_, e.xmotion.time - last_pointer_time_);
700
701 tracked_pointer_pos_ = mouse;
702 last_pointer_time_ = e.xmotion.time;
703
704 if (speed > SCRUB_VELOCITY_THRESHOLD &&
705 PointInTriangle(mouse, {mouse.x, std::max(mouse.y - TRIANGLE_THRESHOLD.CP(scale), 0)},
706 menu_geo_.GetPosition(), {menu_geo_.x + menu_geo_.width, menu_geo_.y}))
707 {
708 return;
709 }
710
711 OnMenuPointerMoved(mouse.x, mouse.y);
712}
713
714void PanelView::OnEntryActivated(std::string const& panel, std::string const& entry_id, nux::Rect const& menu_geo)
715{
716 if (!panel.empty() && panel != GetPanelName())
717 return;
718
719 bool active = !entry_id.empty();
720 auto const& activation_cb = sigc::mem_fun(this, &PanelView::OnActiveEntryEvent);
721 menu_geo_ = menu_geo;
722
723 if (active)
724 {
725 auto& im = input::Monitor::Get();
726 if (im.RegisterClient(input::Events::POINTER, activation_cb))
727 {
728 last_pointer_time_ = 0;
729 ActivateEntry(entry_id);
730 }
731
732 if (overlay_is_open_)
733 ubus_manager_.SendMessage(UBUS_OVERLAY_CLOSE_REQUEST);
734 }
735 else
736 {
737 input::Monitor::Get().UnregisterClient(activation_cb);
738 menu_view_->NotifyAllMenusClosed();
739 }
740}
741
742void PanelView::OnEntryShowMenu(std::string const& entry_id, unsigned xid,
743 int x, int y, unsigned button)
744{
745 if (menu_geo_.IsNull())
746 {
747 // This is ugly... But Nux fault!
748 menu_view_->IgnoreLeaveEvents(true);
749 WindowManager::Default().UnGrabMousePointer(CurrentTime, button, x, y);
750 menu_view_->IgnoreLeaveEvents(false);
751 }
752}
753
754bool PanelView::ActivateFirstSensitive()651bool PanelView::ActivateFirstSensitive()
755{652{
756 if (!IsActive())653 if (!IsActive())
757654
=== modified file 'panel/PanelView.h'
--- panel/PanelView.h 2016-09-01 22:11:44 +0000
+++ panel/PanelView.h 2016-09-01 22:11:45 +0000
@@ -87,8 +87,6 @@
87 void OnObjectAdded(indicator::Indicator::Ptr const& proxy);87 void OnObjectAdded(indicator::Indicator::Ptr const& proxy);
88 void OnObjectRemoved(indicator::Indicator::Ptr const& proxy);88 void OnObjectRemoved(indicator::Indicator::Ptr const& proxy);
89 void OnIndicatorViewUpdated();89 void OnIndicatorViewUpdated();
90 void OnEntryActivated(std::string const& panel, std::string const& entry_id, nux::Rect const& geo);
91 void OnEntryShowMenu(std::string const& entry_id, unsigned xid, int x, int y, unsigned button);
9290
93private:91private:
94 std::string GetPanelName() const;92 std::string GetPanelName() const;
@@ -98,7 +96,7 @@
98 void OnSpreadInitiate();96 void OnSpreadInitiate();
99 void OnSpreadTerminate();97 void OnSpreadTerminate();
100 void OnLowGfxChanged();98 void OnLowGfxChanged();
101 void OnMenuPointerMoved(int x, int y);99 void OnMenuPointerMoved(int x, int y, double speed);
102 void OnActiveEntryEvent(XEvent const&);100 void OnActiveEntryEvent(XEvent const&);
103 void EnableOverlayMode(bool);101 void EnableOverlayMode(bool);
104 void LoadTextures();102 void LoadTextures();
@@ -132,10 +130,6 @@
132 BaseTexturePtr bg_refine_single_column_tex_;130 BaseTexturePtr bg_refine_single_column_tex_;
133 std::unique_ptr<nux::AbstractPaintLayer> bg_refine_single_column_layer_;131 std::unique_ptr<nux::AbstractPaintLayer> bg_refine_single_column_layer_;
134132
135 std::string active_overlay_;
136 nux::Point tracked_pointer_pos_;
137 Time last_pointer_time_;
138
139 bool is_dirty_;133 bool is_dirty_;
140 bool opacity_maximized_toggle_;134 bool opacity_maximized_toggle_;
141 bool needs_geo_sync_;135 bool needs_geo_sync_;
@@ -143,8 +137,7 @@
143 float opacity_;137 float opacity_;
144 int monitor_;138 int monitor_;
145 int stored_dash_width_;139 int stored_dash_width_;
146140 std::string active_overlay_;
147 nux::Geometry menu_geo_;
148141
149 connection::Manager on_indicator_updated_connections_;142 connection::Manager on_indicator_updated_connections_;
150 connection::Manager maximized_opacity_toggle_connections_;143 connection::Manager maximized_opacity_toggle_connections_;
151144
=== modified file 'tests/test_lockscreen_controller.cpp'
--- tests/test_lockscreen_controller.cpp 2016-06-21 14:40:26 +0000
+++ tests/test_lockscreen_controller.cpp 2016-09-01 22:11:45 +0000
@@ -55,7 +55,7 @@
55struct MockShield : BaseShield55struct MockShield : BaseShield
56{56{
57 MockShield()57 MockShield()
58 : BaseShield(nullptr, nullptr, nullptr, nux::ObjectPtr<AbstractUserPromptView>(), 0, false)58 : BaseShield(nullptr, nullptr, nux::ObjectPtr<AbstractUserPromptView>(), 0, false)
59 {}59 {}
6060
61 MOCK_CONST_METHOD0(IsIndicatorOpen, bool());61 MOCK_CONST_METHOD0(IsIndicatorOpen, bool());
@@ -67,7 +67,7 @@
67struct ShieldFactoryMock : ShieldFactoryInterface67struct ShieldFactoryMock : ShieldFactoryInterface
68{68{
69 nux::ObjectPtr<BaseShield> CreateShield(session::Manager::Ptr const&,69 nux::ObjectPtr<BaseShield> CreateShield(session::Manager::Ptr const&,
70 indicator::Indicators::Ptr const&,70 menu::Manager::Ptr const&,
71 Accelerators::Ptr const&,71 Accelerators::Ptr const&,
72 nux::ObjectPtr<AbstractUserPromptView> const&,72 nux::ObjectPtr<AbstractUserPromptView> const&,
73 int, bool) override73 int, bool) override
7474
=== modified file 'unity-shared/InputMonitor.cpp'
--- unity-shared/InputMonitor.cpp 2016-09-01 22:11:44 +0000
+++ unity-shared/InputMonitor.cpp 2016-09-01 22:11:45 +0000
@@ -18,6 +18,7 @@
18 */18 */
1919
20#include "InputMonitor.h"20#include "InputMonitor.h"
21#include "SigcSlotHash.h"
2122
22#include <Nux/Nux.h>23#include <Nux/Nux.h>
23#include <NuxCore/Logger.h>24#include <NuxCore/Logger.h>
@@ -46,6 +47,12 @@
46 return static_cast<ut>(static_cast<ut>(l) & static_cast<ut>(r));47 return static_cast<ut>(static_cast<ut>(l) & static_cast<ut>(r));
47}48}
4849
50Events& operator|=(Events& l, Events r)
51{
52 typedef std::underlying_type<Events>::type ut;
53 return l = static_cast<Events>(static_cast<ut>(l) | static_cast<ut>(r));
54}
55
49template <typename EVENT>56template <typename EVENT>
50void initialize_event_common(EVENT* ev, XIDeviceEvent* xiev)57void initialize_event_common(EVENT* ev, XIDeviceEvent* xiev)
51{58{
@@ -118,6 +125,12 @@
118125
119struct Monitor::Impl126struct Monitor::Impl
120{127{
128#if __GNUC__ < 6
129 using EventCallbackSet = std::unordered_set<EventCallback>;
130#else
131 using EventCallbackSet = std::unordered_set<EventCallback, std::hash<sigc::slot_base>>;
132#endif
133
121 Impl()134 Impl()
122 : xi_opcode_(0)135 : xi_opcode_(0)
123 , event_filter_set_(false)136 , event_filter_set_(false)
@@ -194,6 +207,22 @@
194 return removed;207 return removed;
195 }208 }
196209
210 Events RegisteredEvents(EventCallback const& cb) const
211 {
212 Events events = Events::NONE;
213
214 if (pointer_callbacks_.find(cb) != end(pointer_callbacks_))
215 events |= Events::POINTER;
216
217 if (key_callbacks_.find(cb) != end(key_callbacks_))
218 events |= Events::KEYS;
219
220 if (barrier_callbacks_.find(cb) != end(barrier_callbacks_))
221 events |= Events::BARRIER;
222
223 return events;
224 }
225
197 void UpdateEventMonitor()226 void UpdateEventMonitor()
198 {227 {
199 auto* dpy = nux::GetGraphicsDisplay()->GetX11Display();228 auto* dpy = nux::GetGraphicsDisplay()->GetX11Display();
@@ -276,7 +305,7 @@
276 }305 }
277306
278 template <typename EVENT_TYPE, typename NATIVE_TYPE = XIDeviceEvent>307 template <typename EVENT_TYPE, typename NATIVE_TYPE = XIDeviceEvent>
279 bool InvokeCallbacks(std::unordered_set<EventCallback>& callbacks, XEvent& xiev)308 bool InvokeCallbacks(EventCallbackSet& callbacks, XEvent& xiev)
280 {309 {
281 XGenericEventCookie *cookie = &xiev.xcookie;310 XGenericEventCookie *cookie = &xiev.xcookie;
282311
@@ -332,10 +361,10 @@
332 bool event_filter_set_;361 bool event_filter_set_;
333 bool invoking_callbacks_;362 bool invoking_callbacks_;
334 glib::Source::UniquePtr idle_removal_;363 glib::Source::UniquePtr idle_removal_;
335 std::unordered_set<EventCallback> pointer_callbacks_;364 EventCallbackSet pointer_callbacks_;
336 std::unordered_set<EventCallback> key_callbacks_;365 EventCallbackSet key_callbacks_;
337 std::unordered_set<EventCallback> barrier_callbacks_;366 EventCallbackSet barrier_callbacks_;
338 std::unordered_set<EventCallback> removal_queue_;367 EventCallbackSet removal_queue_;
339};368};
340369
341Monitor::Monitor()370Monitor::Monitor()
@@ -376,5 +405,10 @@
376 return impl_->UnregisterClient(cb);405 return impl_->UnregisterClient(cb);
377}406}
378407
408Events Monitor::RegisteredEvents(EventCallback const& cb) const
409{
410 return impl_->RegisteredEvents(cb);
411}
412
379} // input namespace413} // input namespace
380} // unity namespace414} // unity namespace
381415
=== modified file 'unity-shared/InputMonitor.h'
--- unity-shared/InputMonitor.h 2016-09-01 22:11:44 +0000
+++ unity-shared/InputMonitor.h 2016-09-01 22:11:45 +0000
@@ -30,6 +30,7 @@
30{30{
31enum class Events : unsigned31enum class Events : unsigned
32{32{
33 NONE = 0,
33 POINTER = (1 << 0),34 POINTER = (1 << 0),
34 KEYS = (1 << 1),35 KEYS = (1 << 1),
35 BARRIER = (1 << 2),36 BARRIER = (1 << 2),
@@ -50,6 +51,8 @@
50 bool RegisterClient(Events, EventCallback const&);51 bool RegisterClient(Events, EventCallback const&);
51 bool UnregisterClient(EventCallback const&);52 bool UnregisterClient(EventCallback const&);
5253
54 Events RegisteredEvents(EventCallback const&) const;
55
53private:56private:
54 Monitor(Monitor const&) = delete;57 Monitor(Monitor const&) = delete;
55 Monitor& operator=(Monitor const&) = delete;58 Monitor& operator=(Monitor const&) = delete;
@@ -61,31 +64,4 @@
61} // input namespace64} // input namespace
62} // unity namespace65} // unity namespace
6366
64namespace std
65{
66template<>
67struct hash<unity::input::Monitor::EventCallback>
68{
69 size_t operator()(unity::input::Monitor::EventCallback const& cb) const
70 {
71 if (cb.rep_)
72 return std::hash<size_t>()(reinterpret_cast<size_t>(cb.rep_->call_));
73
74 return std::hash<size_t>()(reinterpret_cast<size_t>(cb.rep_));
75 }
76};
77
78template<>
79struct equal_to<unity::input::Monitor::EventCallback>
80{
81 bool operator()(unity::input::Monitor::EventCallback const& lhs, unity::input::Monitor::EventCallback const& rhs) const
82 {
83 if (!lhs.rep_ || !rhs.rep_)
84 return (lhs.rep_ == rhs.rep_);
85
86 return (lhs.rep_->call_ == rhs.rep_->call_);
87 }
88};
89} // std namespace
90
91#endif // __UNITY_INPUT_MONITOR__67#endif // __UNITY_INPUT_MONITOR__
9268
=== modified file 'unity-shared/MenuManager.cpp'
--- unity-shared/MenuManager.cpp 2015-10-02 14:02:05 +0000
+++ unity-shared/MenuManager.cpp 2016-09-01 22:11:45 +0000
@@ -21,11 +21,17 @@
21#include <gtk/gtk.h>21#include <gtk/gtk.h>
22#include <NuxCore/Logger.h>22#include <NuxCore/Logger.h>
23#include <UnityCore/GLibSignal.h>23#include <UnityCore/GLibSignal.h>
24#include <UnityCore/GLibSource.h>
24#include <UnityCore/GLibWrapper.h>25#include <UnityCore/GLibWrapper.h>
25#include <UnityCore/DBusIndicators.h>26#include <UnityCore/DBusIndicators.h>
26#include <unordered_map>27#include <unordered_map>
2728
28#include "MenuManager.h"29#include "MenuManager.h"
30#include "InputMonitor.h"
31#include "RawPixel.h"
32#include "SigcSlotHash.h"
33#include "UnitySettings.h"
34#include "UScreen.h"
29#include "WindowManager.h"35#include "WindowManager.h"
3036
31namespace unity37namespace unity
@@ -40,6 +46,10 @@
40const std::string LIM_KEY = "integrated-menus";46const std::string LIM_KEY = "integrated-menus";
41const std::string SHOW_MENUS_NOW_DELAY = "show-menus-now-delay";47const std::string SHOW_MENUS_NOW_DELAY = "show-menus-now-delay";
42const std::string ALWAYS_SHOW_MENUS_KEY = "always-show-menus";48const std::string ALWAYS_SHOW_MENUS_KEY = "always-show-menus";
49
50const RawPixel TRIANGLE_THRESHOLD = 5_em;
51const double SCRUB_VELOCITY_THRESHOLD = 0.05;
52const unsigned MENU_OPEN_MOUSE_WAIT = 150;
43}53}
4454
45using namespace indicator;55using namespace indicator;
@@ -51,6 +61,7 @@
51 , indicators_(indicators)61 , indicators_(indicators)
52 , key_grabber_(grabber)62 , key_grabber_(grabber)
53 , show_now_window_(0)63 , show_now_window_(0)
64 , last_pointer_time_(0)
54 , settings_(g_settings_new(SETTINGS_NAME.c_str()))65 , settings_(g_settings_new(SETTINGS_NAME.c_str()))
55 {66 {
56 for (auto const& indicator : indicators_->GetIndicators())67 for (auto const& indicator : indicators_->GetIndicators())
@@ -182,9 +193,15 @@
182 parent_->key_activate_entry.emit(entry_id);193 parent_->key_activate_entry.emit(entry_id);
183 }194 }
184195
185 void EntryActivated(std::string const&, std::string const&, nux::Rect const& geo)196 void EntryActivated(std::string const& menubar, std::string const&, nux::Rect const& geo)
186 {197 {
187 parent_->menu_open = !geo.IsNull();198 parent_->menu_open = !geo.IsNull();
199
200 if (active_menubar_ != menubar)
201 {
202 active_menubar_ = menubar;
203 UpdateActiveTracker();
204 }
188 }205 }
189206
190 void SetShowNowForWindow(Window xid, bool show)207 void SetShowNowForWindow(Window xid, bool show)
@@ -231,15 +248,148 @@
231 gtk_icon_theme_set_search_path(gtk_icon_theme_get_default(), gicon_paths.data(), gicon_paths.size());248 gtk_icon_theme_set_search_path(gtk_icon_theme_get_default(), gicon_paths.data(), gicon_paths.size());
232 }249 }
233250
251 bool PointInTriangle(nux::Point const& p, nux::Point const& t0, nux::Point const& t1, nux::Point const& t2)
252 {
253 int s = t0.y * t2.x - t0.x * t2.y + (t2.y - t0.y) * p.x + (t0.x - t2.x) * p.y;
254 int t = t0.x * t1.y - t0.y * t1.x + (t0.y - t1.y) * p.x + (t1.x - t0.x) * p.y;
255
256 if ((s < 0) != (t < 0))
257 return false;
258
259 int A = -t1.y * t2.x + t0.y * (t2.x - t1.x) + t0.x * (t1.y - t2.y) + t1.x * t2.y;
260 if (A < 0)
261 {
262 s = -s;
263 t = -t;
264 A = -A;
265 }
266
267 return s > 0 && t > 0 && (s + t) < A;
268 }
269
270 double GetMouseVelocity(nux::Point const& p0, nux::Point const& p1, Time time_delta)
271 {
272 int dx, dy;
273 double speed;
274
275 if (time_delta == 0)
276 return 1;
277
278 dx = p0.x - p1.x;
279 dy = p0.y - p1.y;
280
281 speed = sqrt(dx * dx + dy * dy) / time_delta;
282
283 return speed;
284 }
285
286 void OnActiveEntryEvent(XEvent const& e)
287 {
288 if (e.type != MotionNotify)
289 return;
290
291 auto const& active_entry = indicators_->GetActiveEntry();
292
293 if (!active_entry)
294 return;
295
296 nux::Point mouse(e.xmotion.x_root, e.xmotion.y_root);
297 auto monitor = UScreen::GetDefault()->GetMonitorAtPosition(mouse.x, mouse.y);
298 double scale = Settings::Instance().em(monitor)->DPIScale();
299 double speed = GetMouseVelocity(mouse, tracked_pointer_pos_, e.xmotion.time - last_pointer_time_);
300 auto menu_geo = active_entry->geometry();
301
302 tracked_pointer_pos_ = mouse;
303 last_pointer_time_ = e.xmotion.time;
304
305 if (speed > SCRUB_VELOCITY_THRESHOLD &&
306 PointInTriangle(mouse, {mouse.x, std::max(mouse.y - TRIANGLE_THRESHOLD.CP(scale), 0)},
307 menu_geo.GetPosition(), {menu_geo.x + menu_geo.width, menu_geo.y}))
308 {
309 pointer_movement_timeout_ = std::make_shared<glib::Timeout>(MENU_OPEN_MOUSE_WAIT, [this, mouse, speed] {
310 if (active_tracker_)
311 active_tracker_(mouse.x, mouse.y, speed);
312
313 return false;
314 });
315
316 return;
317 }
318
319 if (active_tracker_)
320 {
321 pointer_movement_timeout_.reset();
322 active_tracker_(mouse.x, mouse.y, speed);
323 }
324 }
325
326 bool RegisterTracker(std::string const& menubar, PositionTracker const& cb)
327 {
328 auto it = position_trackers_.find(menubar);
329
330 if (it != end(position_trackers_))
331 return false;
332
333 position_trackers_.insert({menubar, cb});
334
335 if (active_menubar_ == menubar)
336 UpdateActiveTracker();
337
338 return true;
339 }
340
341 bool UnregisterTracker(std::string const& menubar, PositionTracker const& cb)
342 {
343 auto it = position_trackers_.find(menubar);
344
345 if (it == end(position_trackers_))
346 return false;
347
348 if (!cb || (cb && it->second == cb))
349 {
350 position_trackers_.erase(it);
351 UpdateActiveTracker();
352 return true;
353 }
354
355 return false;
356 }
357
358 void UpdateActiveTracker()
359 {
360 auto it = position_trackers_.find(active_menubar_);
361 active_tracker_ = (it != end(position_trackers_)) ? it->second : PositionTracker();
362 pointer_movement_timeout_.reset();
363
364 if (active_tracker_)
365 {
366 if (input::Monitor::Get().RegisterClient(input::Events::POINTER, sigc::mem_fun(this, &Impl::OnActiveEntryEvent)))
367 last_pointer_time_ = 0;
368 }
369 else
370 {
371 input::Monitor::Get().UnregisterClient(sigc::mem_fun(this, &Impl::OnActiveEntryEvent));
372
373 if (it != end(position_trackers_))
374 position_trackers_.erase(it);
375 }
376 }
377
234 Manager* parent_;378 Manager* parent_;
235 Indicators::Ptr indicators_;379 Indicators::Ptr indicators_;
236 AppmenuIndicator::Ptr appmenu_;380 AppmenuIndicator::Ptr appmenu_;
237 key::Grabber::Ptr key_grabber_;381 key::Grabber::Ptr key_grabber_;
238 Window show_now_window_;382 Window show_now_window_;
383 std::string active_menubar_;
384 PositionTracker active_tracker_;
385 nux::Point tracked_pointer_pos_;
386 Time last_pointer_time_;
387 glib::Source::Ptr pointer_movement_timeout_;
239 connection::Manager appmenu_connections_;388 connection::Manager appmenu_connections_;
240 connection::Wrapper active_win_conn_;389 connection::Wrapper active_win_conn_;
241 glib::Object<GSettings> settings_;390 glib::Object<GSettings> settings_;
242 glib::SignalManager signals_;391 glib::SignalManager signals_;
392 std::unordered_map<std::string, PositionTracker> position_trackers_;
243 std::unordered_map<indicator::Entry::Ptr, uint32_t> entry_actions_;393 std::unordered_map<indicator::Entry::Ptr, uint32_t> entry_actions_;
244};394};
245395
@@ -278,5 +428,16 @@
278 return impl_->key_grabber_;428 return impl_->key_grabber_;
279}429}
280430
431bool Manager::RegisterTracker(std::string const& menubar, PositionTracker const& cb)
432{
433 return impl_->RegisterTracker(menubar, cb);
434}
435
436bool Manager::UnregisterTracker(std::string const& menubar, PositionTracker const& cb)
437{
438 return impl_->UnregisterTracker(menubar, cb);
439}
440
441
281} // menu namespace442} // menu namespace
282} // unity namespace443} // unity namespace
283444
=== modified file 'unity-shared/MenuManager.h'
--- unity-shared/MenuManager.h 2015-06-05 14:28:27 +0000
+++ unity-shared/MenuManager.h 2016-09-01 22:11:45 +0000
@@ -67,6 +67,10 @@
6767
68 key::Grabber::Ptr const& KeyGrabber() const;68 key::Grabber::Ptr const& KeyGrabber() const;
6969
70 typedef sigc::slot<void, int /*x*/, int /*y*/, double /*speed*/> PositionTracker;
71 bool RegisterTracker(std::string const& menubar, PositionTracker const&);
72 bool UnregisterTracker(std::string const& menubar, PositionTracker const& = PositionTracker());
73
70 sigc::signal<void> appmenu_added;74 sigc::signal<void> appmenu_added;
71 sigc::signal<void> appmenu_removed;75 sigc::signal<void> appmenu_removed;
72 sigc::signal<bool>::accumulated<any_true> open_first;76 sigc::signal<bool>::accumulated<any_true> open_first;
7377
=== added file 'unity-shared/SigcSlotHash.h'
--- unity-shared/SigcSlotHash.h 1970-01-01 00:00:00 +0000
+++ unity-shared/SigcSlotHash.h 2016-09-01 22:11:45 +0000
@@ -0,0 +1,70 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2016 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Marco Trevisan <marco.trevisan@canonical.com>
18 */
19
20#ifndef __UNITY_SIGC_SLOT_HASHER__
21#define __UNITY_SIGC_SLOT_HASHER__
22
23#include <sigc++/slot.h>
24
25namespace sigc
26{
27inline bool operator==(slot_base const& lhs, slot_base const& rhs)
28{
29 if (!lhs.rep_ || !rhs.rep_)
30 return (lhs.rep_ == rhs.rep_);
31
32 return (lhs.rep_->call_ == rhs.rep_->call_);
33}
34
35inline bool operator!=(slot_base const& lhs, slot_base const& rhs)
36{
37 return !(lhs == rhs);
38}
39} // sigc namespace
40
41namespace std
42{
43
44template<>
45struct hash<sigc::slot_base>
46{
47 size_t operator()(sigc::slot_base const& cb) const
48 {
49 if (cb.rep_)
50 return hash<size_t>()(reinterpret_cast<size_t>(cb.rep_->call_));
51
52 return hash<size_t>()(reinterpret_cast<size_t>(cb.rep_));
53 }
54};
55
56#if __GNUC__ < 6
57template<class T>
58struct hash
59{
60 size_t operator()(T const& cb) const
61 {
62 static_assert(std::is_base_of<sigc::slot_base, T>::value, "Type is not derived from sigc::slot_base");
63 return hash<sigc::slot_base>()(cb);
64 }
65};
66#endif
67
68} // std namespace
69
70#endif // __UNITY_SIGC_SLOT_HASHER__