Merge lp:~3v1n0/unity/input-monitor-lockscreen-panel 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: 4186
Proposed branch: lp:~3v1n0/unity/input-monitor-lockscreen-panel
Merge into: lp:unity
Prerequisite: lp:~3v1n0/unity/input-monitor-panel
Diff against target: 139 lines (+27/-44)
2 files modified
lockscreen/LockScreenPanel.cpp (+25/-39)
lockscreen/LockScreenPanel.h (+2/-5)
To merge this branch: bzr merge lp:~3v1n0/unity/input-monitor-lockscreen-panel
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
Review via email: mp+303554@code.launchpad.net

Commit message

LockScreenPanel: use InputMonitor events instead of mouse polling for menu scrubbing

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

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lockscreen/LockScreenPanel.cpp'
2--- lockscreen/LockScreenPanel.cpp 2015-11-05 14:55:54 +0000
3+++ lockscreen/LockScreenPanel.cpp 2016-08-24 12:32:53 +0000
4@@ -24,7 +24,7 @@
5
6 #include "LockScreenSettings.h"
7 #include "panel/PanelIndicatorsView.h"
8-#include "unity-shared/CairoTexture.h"
9+#include "unity-shared/InputMonitor.h"
10 #include "unity-shared/StaticCairoText.h"
11 #include "unity-shared/PanelStyle.h"
12 #include "unity-shared/RawPixel.h"
13@@ -38,6 +38,7 @@
14 namespace
15 {
16 const RawPixel PADDING = 5_em;
17+const nux::Color BG_COLOR(0.1, 0.1, 0.1, 0.4);
18 }
19
20 using namespace indicator;
21@@ -54,8 +55,7 @@
22 auto* layout = new nux::HLayout();
23 layout->SetLeftAndRightPadding(PADDING.CP(scale), 0);
24 SetLayout(layout);
25-
26- BuildTexture();
27+ UpdateSize();
28
29 // Add setting
30 auto *hostname = new StaticCairoText(session_manager->HostName());
31@@ -86,20 +86,14 @@
32 hostname->SetScale(scale);
33 static_cast<nux::HLayout*>(GetLayout())->SetLeftAndRightPadding(PADDING.CP(scale), 0);
34 indicators_view_->SetMonitor(monitor);
35- BuildTexture();
36+ UpdateSize();
37 QueueRelayout();
38 });
39 }
40
41-void Panel::BuildTexture()
42+void Panel::UpdateSize()
43 {
44 int height = panel::Style::Instance().PanelHeight(monitor);
45- nux::CairoGraphics context(CAIRO_FORMAT_ARGB32, 1, height);
46- auto* cr = context.GetInternalContext();
47- cairo_set_source_rgb(cr, 0.1, 0.1, 0.1);
48- cairo_paint_with_alpha(cr, 0.4);
49- bg_texture_ = texture_ptr_from_cairo_graphics(context);
50-
51 view_layout_->SetMinimumHeight(height);
52 view_layout_->SetMaximumHeight(height);
53 }
54@@ -192,28 +186,25 @@
55 nux::GetWindowCompositor().GrabKeyboardAdd(static_cast<nux::BaseWindow*>(GetTopLevelViewWindow()));
56 }
57
58- if (active && !track_menu_pointer_timeout_)
59- {
60- track_menu_pointer_timeout_.reset(new glib::Timeout(16));
61- track_menu_pointer_timeout_->Run([this] {
62- nux::Point const& mouse = nux::GetGraphicsDisplay()->GetMouseScreenCoord();
63- if (tracked_pointer_pos_ != mouse)
64- {
65- if (GetAbsoluteGeometry().IsPointInside(mouse.x, mouse.y))
66- indicators_view_->ActivateEntryAt(mouse.x, mouse.y);
67-
68- tracked_pointer_pos_ = mouse;
69- }
70-
71- return true;
72- });
73- }
74- else if (!active)
75- {
76- track_menu_pointer_timeout_.reset();
77- tracked_pointer_pos_ = {-1, -1};
78- this->active = false;
79- }
80+ auto& im = input::Monitor::Get();
81+ auto const& event_cb = sigc::mem_fun(this, &Panel::OnEntryEvent);
82+
83+ if (active)
84+ {
85+ if (im.RegisterClient(input::Events::POINTER, event_cb))
86+ indicators_view_->ActivateEntry(entry_id);
87+ }
88+ else
89+ {
90+ im.UnregisterClient(event_cb);
91+ this->active = active;
92+ }
93+}
94+
95+void Panel::OnEntryEvent(XEvent const& e)
96+{
97+ if (e.type == MotionNotify && GetAbsoluteGeometry().IsPointInside(e.xmotion.x, e.xmotion.y))
98+ indicators_view_->ActivateEntryAt(e.xmotion.x, e.xmotion.y);
99 }
100
101 void Panel::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw)
102@@ -227,12 +218,7 @@
103 graphics_engine.PushClippingRectangle(geo);
104 nux::GetPainter().PaintBackground(graphics_engine, geo);
105
106- nux::TexCoordXForm texxform;
107- texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_CLAMP);
108- graphics_engine.QRP_1Tex(geo.x, geo.y, geo.width, geo.height,
109- bg_texture_->GetDeviceTexture(), texxform,
110- nux::color::White);
111-
112+ graphics_engine.QRP_Color(geo.x, geo.y, geo.width, geo.height, BG_COLOR);
113 view_layout_->ProcessDraw(graphics_engine, force_draw);
114
115 graphics_engine.PopClippingRectangle();
116
117=== modified file 'lockscreen/LockScreenPanel.h'
118--- lockscreen/LockScreenPanel.h 2016-03-31 09:51:33 +0000
119+++ lockscreen/LockScreenPanel.h 2016-08-24 12:32:53 +0000
120@@ -58,17 +58,14 @@
121 void OnEntryActivated(std::string const& panel, std::string const& entry_id, nux::Rect const& geo);
122 void OnEntryShowMenu(std::string const& entry_id, unsigned xid, int x, int y, unsigned button);
123 void OnEntryActivateRequest(std::string const& entry_id);
124+ void OnEntryEvent(XEvent const&);
125
126- void BuildTexture();
127+ void UpdateSize();
128 std::string GetPanelName() const;
129
130 indicator::Indicators::Ptr indicators_;
131 panel::PanelIndicatorsView* indicators_view_;
132- nux::ObjectPtr<nux::BaseTexture> bg_texture_;
133-
134 bool needs_geo_sync_;
135- nux::Point tracked_pointer_pos_;
136- glib::Source::UniquePtr track_menu_pointer_timeout_;
137 };
138
139 } // lockscreen namespace