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
=== modified file 'decorations/DecorationsMenuLayout.cpp'
--- decorations/DecorationsMenuLayout.cpp 2015-02-03 10:04:17 +0000
+++ decorations/DecorationsMenuLayout.cpp 2016-08-18 16:07:55 +0000
@@ -20,6 +20,7 @@
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"
2324
24namespace unity25namespace unity
25{26{
@@ -33,7 +34,6 @@
33 , show_now(false)34 , show_now(false)
34 , menu_manager_(menu)35 , menu_manager_(menu)
35 , win_(win)36 , win_(win)
36 , last_pointer_(-1, -1)
37 , dropdown_(std::make_shared<MenuDropdown>(menu_manager_->Indicators(), win))37 , dropdown_(std::make_shared<MenuDropdown>(menu_manager_->Indicators(), win))
38{38{
39 visible = false;39 visible = false;
@@ -117,16 +117,29 @@
117 if (!activated)117 if (!activated)
118 activated = dropdown_->ActivateChild(target);118 activated = dropdown_->ActivateChild(target);
119119
120 if (activated)
121 {
122 // Since this generally happens on keyboard activation we need to avoid that
123 // the mouse position would interfere with this
124 last_pointer_.set(pointerX, pointerY);
125 }
126
127 return activated;120 return activated;
128}121}
129122
123bool MenuLayout::ActivateMenu(CompPoint const& pos)
124{
125 if (!Geometry().contains(pos))
126 return false;
127
128 for (auto const& item : items_)
129 {
130 if (!item->visible() || !item->sensitive())
131 continue;
132
133 if (item->Geometry().contains(pos))
134 {
135 std::static_pointer_cast<MenuEntry>(item)->ShowMenu(1);
136 return true;
137 }
138 }
139
140 return false;
141}
142
130void MenuLayout::OnEntryMouseOwnershipChanged(bool owner)143void MenuLayout::OnEntryMouseOwnershipChanged(bool owner)
131{144{
132 mouse_owner = owner;145 mouse_owner = owner;
@@ -154,42 +167,23 @@
154{167{
155 active = actived;168 active = actived;
156169
157 if (active && !pointer_tracker_ && items_.size() > 1)170 if (active && items_.size() > 1)
158 {171 {
159 pointer_tracker_.reset(new glib::Timeout(16));172 auto const& event_cb = sigc::mem_fun(this, &MenuLayout::OnEntryInputEvent);
160 pointer_tracker_->Run([this] {173 input::Monitor::Get().RegisterClient(input::Events::POINTER, event_cb);
161 Window win;
162 int i, x, y;
163 unsigned int ui;
164
165 XQueryPointer(screen->dpy(), screen->root(), &win, &win, &x, &y, &i, &i, &ui);
166
167 if (last_pointer_.x() != x || last_pointer_.y() != y)
168 {
169 last_pointer_.set(x, y);
170
171 for (auto const& item : items_)
172 {
173 if (!item->visible() || !item->sensitive())
174 continue;
175
176 if (item->Geometry().contains(last_pointer_))
177 {
178 std::static_pointer_cast<MenuEntry>(item)->ShowMenu(1);
179 break;
180 }
181 }
182 }
183
184 return true;
185 });
186 }174 }
187 else if (!active)175 else if (!active)
188 {176 {
189 pointer_tracker_.reset();177 input::Monitor::Get().UnregisterClient(sigc::mem_fun(this, &MenuLayout::OnEntryInputEvent));
190 }178 }
191}179}
192180
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
193void MenuLayout::ChildrenGeometries(EntryLocationMap& map) const187void MenuLayout::ChildrenGeometries(EntryLocationMap& map) const
194{188{
195 for (auto const& item : items_)189 for (auto const& item : items_)
196190
=== modified file 'decorations/DecorationsMenuLayout.h'
--- decorations/DecorationsMenuLayout.h 2014-02-13 03:01:30 +0000
+++ decorations/DecorationsMenuLayout.h 2016-08-18 16:07:55 +0000
@@ -42,6 +42,7 @@
4242
43 void Setup();43 void Setup();
44 bool ActivateMenu(std::string const& entry_id);44 bool ActivateMenu(std::string const& entry_id);
45 bool ActivateMenu(CompPoint const&);
45 void ChildrenGeometries(indicator::EntryLocationMap&) const;46 void ChildrenGeometries(indicator::EntryLocationMap&) const;
4647
47protected:48protected:
@@ -52,11 +53,10 @@
52 void OnEntryMouseOwnershipChanged(bool);53 void OnEntryMouseOwnershipChanged(bool);
53 void OnEntryActiveChanged(bool);54 void OnEntryActiveChanged(bool);
54 void OnEntryShowNowChanged(bool);55 void OnEntryShowNowChanged(bool);
56 void OnEntryInputEvent(XEvent const&);
5557
56 menu::Manager::Ptr menu_manager_;58 menu::Manager::Ptr menu_manager_;
57 CompWindow* win_;59 CompWindow* win_;
58 CompPoint last_pointer_;
59 glib::Source::UniquePtr pointer_tracker_;
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};62};