Merge lp:~3v1n0/unity/lockscreen-shield-ensure-grab into lp:unity

Proposed by Marco Trevisan (Treviño) on 2014-07-30
Status: Merged
Approved by: Marco Trevisan (Treviño) on 2014-07-30
Approved revision: 3848
Merged at revision: 3847
Proposed branch: lp:~3v1n0/unity/lockscreen-shield-ensure-grab
Merge into: lp:unity
Diff against target: 158 lines (+40/-23)
4 files modified
lockscreen/LockScreenController.cpp (+1/-1)
lockscreen/LockScreenShield.cpp (+35/-22)
lockscreen/LockScreenShield.h (+3/-0)
unity-shared/PluginAdapter.cpp (+1/-0)
To merge this branch: bzr merge lp:~3v1n0/unity/lockscreen-shield-ensure-grab
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve on 2014-07-31
Brandon Schaefer (community) 2014-07-30 Approve on 2014-07-30
Review via email: mp+228968@code.launchpad.net

Commit message

LockScreenShield: Add GrabScreen function and retry to make sure we really get grab

It might happen that the grab is not possible because the PluginAdapter::IsScreenGrabbed
request has still not being fully processed, and thus nux is not able to grab the
pointer/keyboard. By doing this we instead try to grab the screen, and if this is
not happening, we wait a little until we don't get the ungrab event.

In this way, if we eventually get the grab, all will work as expected.
Otherwise, we cancel the lock request (very unlikely to happen).

To post a comment you must log in.
Brandon Schaefer (brandontschaefer) wrote :

LGTM

review: Approve
Andrea Azzarone (azzar1) wrote :

LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lockscreen/LockScreenController.cpp'
2--- lockscreen/LockScreenController.cpp 2014-06-19 18:41:29 +0000
3+++ lockscreen/LockScreenController.cpp 2014-07-30 23:50:31 +0000
4@@ -45,9 +45,9 @@
5 bool AcceptKeyNavFocus() override { return true; }
6 bool InspectKeyEvent(unsigned int, unsigned int, const char*) override { return true; };
7 };
8-}
9
10 DECLARE_LOGGER(logger, "unity.lockscreen");
11+}
12
13 Controller::Controller(DBusManager::Ptr const& dbus_manager,
14 session::Manager::Ptr const& session_manager,
15
16=== modified file 'lockscreen/LockScreenShield.cpp'
17--- lockscreen/LockScreenShield.cpp 2014-06-05 19:48:27 +0000
18+++ lockscreen/LockScreenShield.cpp 2014-07-30 23:50:31 +0000
19@@ -19,6 +19,7 @@
20
21 #include "LockScreenShield.h"
22
23+#include <NuxCore/Logger.h>
24 #include <Nux/VLayout.h>
25 #include <Nux/HLayout.h>
26 #include <Nux/PaintLayer.h>
27@@ -35,6 +36,11 @@
28 {
29 namespace lockscreen
30 {
31+namespace
32+{
33+DECLARE_LOGGER(logger, "unity.lockscreen.shield");
34+const unsigned MAX_GRAB_WAIT = 50;
35+}
36
37 Shield::Shield(session::Manager::Ptr const& session_manager, indicator::Indicators::Ptr const& indicators, Accelerators::Ptr const& accelerators, int monitor_num, bool is_primary)
38 : AbstractShield(session_manager, indicators, accelerators, monitor_num, is_primary)
39@@ -56,12 +62,7 @@
40 });
41
42 primary.changed.connect([this] (bool is_primary) {
43- if (!is_primary)
44- {
45- UnGrabPointer();
46- UnGrabKeyboard();
47- }
48-
49+ regrab_conn_->disconnect();
50 is_primary ? ShowPrimaryView() : ShowSecondaryView();
51 if (panel_view_) panel_view_->SetInputEventSensitivity(is_primary);
52 QueueRelayout();
53@@ -86,17 +87,41 @@
54 }
55 }
56
57+void Shield::GrabScreen(bool cancel_on_failure)
58+{
59+ auto& wc = nux::GetWindowCompositor();
60+
61+ if (wc.GrabPointerAdd(this) && wc.GrabKeyboardAdd(this))
62+ {
63+ regrab_conn_->disconnect();
64+ regrab_timeout_.reset();
65+ }
66+ else
67+ {
68+ auto const& retry_cb = sigc::bind(sigc::mem_fun(this, &Shield::GrabScreen), false);
69+ regrab_conn_ = WindowManager::Default().screen_ungrabbed.connect(retry_cb);
70+
71+ if (cancel_on_failure)
72+ {
73+ regrab_timeout_.reset(new glib::Timeout(MAX_GRAB_WAIT, [this] {
74+ LOG_ERROR(logger) << "Impossible to get the grab to lock the screen";
75+ session_manager_->unlock_requested.emit();
76+ return false;
77+ }));
78+ }
79+ }
80+}
81+
82 void Shield::ShowPrimaryView()
83 {
84- GrabPointer();
85- GrabKeyboard();
86-
87 if (primary_layout_)
88 {
89+ GrabScreen(false);
90 SetLayout(primary_layout_.GetPointer());
91 return;
92 }
93
94+ GrabScreen(true);
95 nux::Layout* main_layout = new nux::VLayout();
96 primary_layout_ = main_layout;
97 SetLayout(primary_layout_.GetPointer());
98@@ -149,19 +174,7 @@
99 }
100 else
101 {
102- auto& wc = nux::GetWindowCompositor();
103-
104- if (!wc.GrabPointerAdd(this) || !wc.GrabKeyboardAdd(this))
105- {
106- regrab_conn_ = WindowManager::Default().screen_ungrabbed.connect([this] {
107- if (primary())
108- {
109- GrabPointer();
110- GrabKeyboard();
111- }
112- regrab_conn_->disconnect();
113- });
114- }
115+ GrabScreen(false);
116 }
117 }
118 });
119
120=== modified file 'lockscreen/LockScreenShield.h'
121--- lockscreen/LockScreenShield.h 2014-06-05 19:48:27 +0000
122+++ lockscreen/LockScreenShield.h 2014-07-30 23:50:31 +0000
123@@ -21,6 +21,7 @@
124 #define UNITY_LOCKSCREEN_SHIELD_H
125
126 #include <UnityCore/ConnectionManager.h>
127+#include <UnityCore/GLibSource.h>
128 #include "LockScreenAbstractShield.h"
129
130 namespace unity
131@@ -48,6 +49,7 @@
132
133 private:
134 void UpdateBackgroundTexture();
135+ void GrabScreen(bool cancel_on_failure);
136 void ShowPrimaryView();
137 void ShowSecondaryView();
138 Panel* CreatePanel();
139@@ -59,6 +61,7 @@
140 nux::ObjectPtr<nux::Layout> cof_layout_;
141 connection::Wrapper panel_active_conn_;
142 connection::Wrapper regrab_conn_;
143+ glib::Source::UniquePtr regrab_timeout_;
144 UserPromptView* prompt_view_;
145 Panel* panel_view_;
146 };
147
148=== modified file 'unity-shared/PluginAdapter.cpp'
149--- unity-shared/PluginAdapter.cpp 2014-06-19 18:40:55 +0000
150+++ unity-shared/PluginAdapter.cpp 2014-07-30 23:50:31 +0000
151@@ -1254,6 +1254,7 @@
152 if (ret == GrabSuccess)
153 {
154 XUngrabKeyboard(dpy, CurrentTime);
155+ XFlush(dpy);
156
157 if (CompWindow* w = m_Screen->findWindow(m_Screen->activeWindow()))
158 w->moveInputFocusTo();