Merge lp:~3v1n0/unity/input-monitor-decorations into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Andrea Azzarone
Approved revision: no longer in the source branch.
Merged at revision: 4184
Proposed branch: lp:~3v1n0/unity/input-monitor-decorations
Merge into: lp:unity
Prerequisite: lp:~3v1n0/unity/input-monitor-barriers
Diff against target: 134 lines (+33/-39)
2 files modified
decorations/DecorationsMenuLayout.cpp (+31/-37)
decorations/DecorationsMenuLayout.h (+2/-2)
To merge this branch: bzr merge lp:~3v1n0/unity/input-monitor-decorations
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
Review via email: mp+303300@code.launchpad.net

Commit message

DecorationsMenuLayout: use input monitor for menu scrubbing

To post a comment you must log in.
Revision history for this message
Andrea Azzarone (azzar1) wrote :

Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'decorations/DecorationsMenuLayout.cpp'
2--- decorations/DecorationsMenuLayout.cpp 2015-02-03 10:04:17 +0000
3+++ decorations/DecorationsMenuLayout.cpp 2016-08-18 16:07:55 +0000
4@@ -20,6 +20,7 @@
5 #include "DecorationsMenuLayout.h"
6 #include "DecorationsMenuEntry.h"
7 #include "DecorationsMenuDropdown.h"
8+#include "InputMonitor.h"
9
10 namespace unity
11 {
12@@ -33,7 +34,6 @@
13 , show_now(false)
14 , menu_manager_(menu)
15 , win_(win)
16- , last_pointer_(-1, -1)
17 , dropdown_(std::make_shared<MenuDropdown>(menu_manager_->Indicators(), win))
18 {
19 visible = false;
20@@ -117,16 +117,29 @@
21 if (!activated)
22 activated = dropdown_->ActivateChild(target);
23
24- if (activated)
25- {
26- // Since this generally happens on keyboard activation we need to avoid that
27- // the mouse position would interfere with this
28- last_pointer_.set(pointerX, pointerY);
29- }
30-
31 return activated;
32 }
33
34+bool MenuLayout::ActivateMenu(CompPoint const& pos)
35+{
36+ if (!Geometry().contains(pos))
37+ return false;
38+
39+ for (auto const& item : items_)
40+ {
41+ if (!item->visible() || !item->sensitive())
42+ continue;
43+
44+ if (item->Geometry().contains(pos))
45+ {
46+ std::static_pointer_cast<MenuEntry>(item)->ShowMenu(1);
47+ return true;
48+ }
49+ }
50+
51+ return false;
52+}
53+
54 void MenuLayout::OnEntryMouseOwnershipChanged(bool owner)
55 {
56 mouse_owner = owner;
57@@ -154,42 +167,23 @@
58 {
59 active = actived;
60
61- if (active && !pointer_tracker_ && items_.size() > 1)
62+ if (active && items_.size() > 1)
63 {
64- pointer_tracker_.reset(new glib::Timeout(16));
65- pointer_tracker_->Run([this] {
66- Window win;
67- int i, x, y;
68- unsigned int ui;
69-
70- XQueryPointer(screen->dpy(), screen->root(), &win, &win, &x, &y, &i, &i, &ui);
71-
72- if (last_pointer_.x() != x || last_pointer_.y() != y)
73- {
74- last_pointer_.set(x, y);
75-
76- for (auto const& item : items_)
77- {
78- if (!item->visible() || !item->sensitive())
79- continue;
80-
81- if (item->Geometry().contains(last_pointer_))
82- {
83- std::static_pointer_cast<MenuEntry>(item)->ShowMenu(1);
84- break;
85- }
86- }
87- }
88-
89- return true;
90- });
91+ auto const& event_cb = sigc::mem_fun(this, &MenuLayout::OnEntryInputEvent);
92+ input::Monitor::Get().RegisterClient(input::Events::POINTER, event_cb);
93 }
94 else if (!active)
95 {
96- pointer_tracker_.reset();
97+ input::Monitor::Get().UnregisterClient(sigc::mem_fun(this, &MenuLayout::OnEntryInputEvent));
98 }
99 }
100
101+void MenuLayout::OnEntryInputEvent(XEvent const& e)
102+{
103+ if (e.type == MotionNotify)
104+ ActivateMenu(CompPoint(e.xmotion.x_root, e.xmotion.y_root));
105+}
106+
107 void MenuLayout::ChildrenGeometries(EntryLocationMap& map) const
108 {
109 for (auto const& item : items_)
110
111=== modified file 'decorations/DecorationsMenuLayout.h'
112--- decorations/DecorationsMenuLayout.h 2014-02-13 03:01:30 +0000
113+++ decorations/DecorationsMenuLayout.h 2016-08-18 16:07:55 +0000
114@@ -42,6 +42,7 @@
115
116 void Setup();
117 bool ActivateMenu(std::string const& entry_id);
118+ bool ActivateMenu(CompPoint const&);
119 void ChildrenGeometries(indicator::EntryLocationMap&) const;
120
121 protected:
122@@ -52,11 +53,10 @@
123 void OnEntryMouseOwnershipChanged(bool);
124 void OnEntryActiveChanged(bool);
125 void OnEntryShowNowChanged(bool);
126+ void OnEntryInputEvent(XEvent const&);
127
128 menu::Manager::Ptr menu_manager_;
129 CompWindow* win_;
130- CompPoint last_pointer_;
131- glib::Source::UniquePtr pointer_tracker_;
132 glib::Source::UniquePtr show_now_timeout_;
133 std::shared_ptr<MenuDropdown> dropdown_;
134 };