Merge lp:~3v1n0/unity/lockscreen-media-accelerators into lp:unity
- lockscreen-media-accelerators
- Merge into trunk
Proposed by
Marco Trevisan (Treviño)
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Andrea Azzarone | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | 4131 | ||||
Proposed branch: | lp:~3v1n0/unity/lockscreen-media-accelerators | ||||
Merge into: | lp:unity | ||||
Diff against target: |
657 lines (+196/-175) 11 files modified
lockscreen/LockScreenAcceleratorController.cpp (+143/-148) lockscreen/LockScreenAcceleratorController.h (+8/-3) lockscreen/LockScreenAccelerators.cpp (+5/-0) lockscreen/LockScreenAccelerators.h (+3/-1) lockscreen/LockScreenController.cpp (+3/-1) lockscreen/LockScreenController.h (+3/-1) plugins/unityshell/src/unityshell.cpp (+10/-10) tests/test_lockscreen_controller.cpp (+8/-4) unity-shared/GnomeKeyGrabber.cpp (+7/-5) unity-shared/GnomeKeyGrabberImpl.h (+2/-2) unity-shared/KeyGrabber.h (+4/-0) |
||||
To merge this branch: | bzr merge lp:~3v1n0/unity/lockscreen-media-accelerators | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Andrea Azzarone (community) | Approve | ||
PS Jenkins bot | continuous-integration | Pending | |
Review via email: mp+297978@code.launchpad.net |
Commit message
LockScreenAccel
This makes U-S-D to handle key events, without having to add some extra
custom code inside the lockscreen. It's all just about whitelisting the
wanted values.
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'lockscreen/LockScreenAcceleratorController.cpp' |
2 | --- lockscreen/LockScreenAcceleratorController.cpp 2014-05-16 04:51:34 +0000 |
3 | +++ lockscreen/LockScreenAcceleratorController.cpp 2016-06-21 14:42:21 +0000 |
4 | @@ -1,6 +1,6 @@ |
5 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
6 | /* |
7 | - * Copyright (C) 2014 Canonical Ltd |
8 | + * Copyright (C) 2014-2016 Canonical Ltd |
9 | * |
10 | * This program is free software: you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License version 3 as |
12 | @@ -15,10 +15,12 @@ |
13 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
14 | * |
15 | * Authored by: William Hua <william.hua@canonical.com> |
16 | + * Marco Trevisan <marco.trevisan@canonical.com> |
17 | */ |
18 | |
19 | #include "LockScreenAcceleratorController.h" |
20 | |
21 | +#include <NuxCore/Logger.h> |
22 | #include <UnityCore/GLibDBusProxy.h> |
23 | |
24 | namespace unity |
25 | @@ -28,157 +30,150 @@ |
26 | |
27 | namespace |
28 | { |
29 | -const char* const MEDIA_KEYS_SCHEMA = "org.gnome.settings-daemon.plugins.media-keys"; |
30 | -const char* const MEDIA_KEYS_KEY_VOLUME_MUTE = "volume-mute"; |
31 | -const char* const MEDIA_KEYS_KEY_VOLUME_DOWN = "volume-down"; |
32 | -const char* const MEDIA_KEYS_KEY_VOLUME_UP = "volume-up"; |
33 | - |
34 | -const char* const POWER_SCHEMA = "org.gnome.settings-daemon.plugins.power"; |
35 | -const char* const SUSPEND_BUTTON_ACTION_KEY = "button-suspend"; |
36 | -const char* const SLEEP_BUTTON_ACTION_KEY = "button-sleep"; |
37 | -const char* const HIBERNATE_BUTTON_ACTION_KEY = "button-hibernate"; |
38 | -const char* const POWER_BUTTON_ACTION_KEY = "button-power"; |
39 | -const char* const POWER_KEY_SUSPEND = "XF86Suspend"; |
40 | -const char* const POWER_KEY_SLEEP = "XF86Sleep"; |
41 | -const char* const POWER_KEY_HIBERNATE = "XF86Hibernate"; |
42 | -const char* const POWER_KEY_POWEROFF = "XF86PowerOff"; |
43 | - |
44 | -const char* const INPUT_SWITCH_SCHEMA = "org.gnome.desktop.wm.keybindings"; |
45 | -const char* const INPUT_SWITCH_KEY_PREVIOUS_SOURCE = "switch-input-source-backward"; |
46 | -const char* const INPUT_SWITCH_KEY_NEXT_SOURCE = "switch-input-source"; |
47 | - |
48 | -const char* const INDICATOR_INTERFACE_ACTIONS = "org.gtk.Actions"; |
49 | -const char* const INDICATOR_METHOD_ACTIVATE = "Activate"; |
50 | -const char* const INDICATOR_SOUND_BUS_NAME = "com.canonical.indicator.sound"; |
51 | -const char* const INDICATOR_SOUND_OBJECT_PATH = "/com/canonical/indicator/sound"; |
52 | -const char* const INDICATOR_SOUND_ACTION_MUTE = "mute"; |
53 | -const char* const INDICATOR_SOUND_ACTION_SCROLL = "scroll"; |
54 | -const char* const INDICATOR_KEYBOARD_BUS_NAME = "com.canonical.indicator.keyboard"; |
55 | -const char* const INDICATOR_KEYBOARD_OBJECT_PATH = "/com/canonical/indicator/keyboard"; |
56 | -const char* const INDICATOR_KEYBOARD_ACTION_SCROLL = "locked_scroll"; |
57 | - |
58 | -void ActivateIndicator(std::string const& bus_name, |
59 | - std::string const& object_path, |
60 | - std::string const& action_name, |
61 | - glib::Variant const& parameters = glib::Variant()) |
62 | -{ |
63 | - GVariantBuilder builder; |
64 | - |
65 | - g_variant_builder_init(&builder, G_VARIANT_TYPE("(sava{sv})")); |
66 | - g_variant_builder_add(&builder, "s", action_name.c_str()); |
67 | - |
68 | - if (parameters) |
69 | - g_variant_builder_add_parsed(&builder, "[%v]", static_cast<GVariant*>(parameters)); |
70 | - else |
71 | - g_variant_builder_add_parsed(&builder, "@av []"); |
72 | - |
73 | - g_variant_builder_add_parsed(&builder, "@a{sv} []"); |
74 | - |
75 | - auto proxy = std::make_shared<glib::DBusProxy>(bus_name, object_path, INDICATOR_INTERFACE_ACTIONS); |
76 | - proxy->CallBegin(INDICATOR_METHOD_ACTIVATE, g_variant_builder_end(&builder), [proxy] (GVariant*, glib::Error const&) {}); |
77 | -} |
78 | - |
79 | -void MuteIndicatorSound() |
80 | -{ |
81 | - ActivateIndicator(INDICATOR_SOUND_BUS_NAME, |
82 | - INDICATOR_SOUND_OBJECT_PATH, |
83 | - INDICATOR_SOUND_ACTION_MUTE); |
84 | -} |
85 | - |
86 | -void ScrollIndicatorSound(int offset) |
87 | -{ |
88 | - ActivateIndicator(INDICATOR_SOUND_BUS_NAME, |
89 | - INDICATOR_SOUND_OBJECT_PATH, |
90 | - INDICATOR_SOUND_ACTION_SCROLL, |
91 | - g_variant_new_int32(offset)); |
92 | -} |
93 | - |
94 | -void ScrollIndicatorKeyboard(int offset) |
95 | -{ |
96 | - ActivateIndicator(INDICATOR_KEYBOARD_BUS_NAME, |
97 | - INDICATOR_KEYBOARD_OBJECT_PATH, |
98 | - INDICATOR_KEYBOARD_ACTION_SCROLL, |
99 | - g_variant_new_int32(-offset)); |
100 | -} |
101 | - |
102 | -void PowerAction(session::Manager::Ptr const& session, const char *action_key) |
103 | -{ |
104 | - glib::Object<GSettings> settings(g_settings_new(POWER_SCHEMA)); |
105 | - auto const& action = glib::String(g_settings_get_string(settings, action_key)).Str(); |
106 | - |
107 | - if (action == "interactive") |
108 | - session->shutdown_requested.emit(session->HasInhibitors()); |
109 | - else if (action == "shutdown") |
110 | - session->reboot_requested.emit(session->HasInhibitors()); |
111 | - else if (action == "suspend") |
112 | - session->Suspend(); |
113 | - else if (action == "hibernate") |
114 | - session->Hibernate(); |
115 | - else if (action == "blank") |
116 | - session->ScreenSaverActivate(); |
117 | -} |
118 | +DECLARE_LOGGER(logger, "unity.lockscreen.accelerator.controller"); |
119 | + |
120 | +const std::string MEDIA_KEYS_SCHEMA = "org.gnome.settings-daemon.plugins.media-keys"; |
121 | +const std::vector<std::string> ALLOWED_MEDIA_KEYS = { |
122 | + "logout", |
123 | + "magnifier", |
124 | + "on-screen-keyboard", |
125 | + "magnifier-zoom-in", |
126 | + "screenreader", |
127 | + "pause", |
128 | + "stop", |
129 | + "toggle-contrast", |
130 | + "video-out", |
131 | + "volume-down", |
132 | + "volume-mute", |
133 | + "volume-up", |
134 | +}; |
135 | + |
136 | +const std::string WM_KEYS_SCHEMA = "org.gnome.desktop.wm.keybindings"; |
137 | +const std::vector<std::string> ALLOWED_WM_KEYS = { |
138 | + "switch-input-source", |
139 | + "switch-input-source-backward", |
140 | +}; |
141 | + |
142 | +const std::vector<std::string> ALLOWED_XF86_KEYS = { |
143 | + "XF86ScreenSaver", |
144 | + "XF86Sleep", |
145 | + "XF86Standby", |
146 | + "XF86Suspend", |
147 | + "XF86Hibernate", |
148 | + "XF86PowerOff", |
149 | + "XF86MonBrightnessUp", |
150 | + "XF86MonBrightnessDown", |
151 | + "XF86KbdBrightnessUp", |
152 | + "XF86KbdBrightnessDown", |
153 | + "XF86KbdLightOnOff", |
154 | + "XF86AudioMicMute", |
155 | + "XF86Touchpad", |
156 | +}; |
157 | + |
158 | +bool IsKeyBindingAllowed(std::string const& key) |
159 | +{ |
160 | + if (std::find(begin(ALLOWED_XF86_KEYS), end(ALLOWED_XF86_KEYS), key) != end(ALLOWED_XF86_KEYS)) |
161 | + return true; |
162 | + |
163 | + glib::Object<GSettings> media_settings(g_settings_new(MEDIA_KEYS_SCHEMA.c_str())); |
164 | + Accelerator key_accelerator(key); |
165 | + |
166 | + for (auto const& setting : ALLOWED_MEDIA_KEYS) |
167 | + { |
168 | + Accelerator media_key(glib::String(g_settings_get_string(media_settings, setting.c_str())).Str()); |
169 | + if (media_key == key_accelerator) |
170 | + return true; |
171 | + } |
172 | + |
173 | + glib::Object<GSettings> wm_settings(g_settings_new(WM_KEYS_SCHEMA.c_str())); |
174 | + |
175 | + for (auto const& setting : ALLOWED_WM_KEYS) |
176 | + { |
177 | + glib::Variant accels(g_settings_get_value(wm_settings, setting.c_str()), glib::StealRef()); |
178 | + auto children = g_variant_n_children(accels); |
179 | + |
180 | + if (children > 0) |
181 | + { |
182 | + glib::String value; |
183 | + |
184 | + for (auto i = 0u; i < children; ++i) |
185 | + { |
186 | + g_variant_get_child(accels, 0, "s", &value); |
187 | + |
188 | + if (Accelerator(value.Str()) == key_accelerator) |
189 | + return true; |
190 | + } |
191 | + } |
192 | + } |
193 | + |
194 | + return false; |
195 | +} |
196 | + |
197 | } // namespace |
198 | |
199 | -AcceleratorController::AcceleratorController(session::Manager::Ptr const& session) |
200 | +AcceleratorController::AcceleratorController(key::Grabber::Ptr const& key_grabber) |
201 | : accelerators_(new Accelerators) |
202 | { |
203 | - auto settings = glib::Object<GSettings>(g_settings_new(MEDIA_KEYS_SCHEMA)); |
204 | - |
205 | - auto accelerator = std::make_shared<Accelerator>(glib::String(g_settings_get_string(settings, MEDIA_KEYS_KEY_VOLUME_MUTE))); |
206 | - accelerator->activated.connect(std::function<void()>(MuteIndicatorSound)); |
207 | - accelerators_->Add(accelerator); |
208 | - |
209 | - accelerator = std::make_shared<Accelerator>(glib::String(g_settings_get_string(settings, MEDIA_KEYS_KEY_VOLUME_DOWN))); |
210 | - accelerator->activated.connect(std::bind(ScrollIndicatorSound, -1)); |
211 | - accelerators_->Add(accelerator); |
212 | - |
213 | - accelerator = std::make_shared<Accelerator>(glib::String(g_settings_get_string(settings, MEDIA_KEYS_KEY_VOLUME_UP))); |
214 | - accelerator->activated.connect(std::bind(ScrollIndicatorSound, +1)); |
215 | - accelerators_->Add(accelerator); |
216 | - |
217 | - accelerator = std::make_shared<Accelerator>(POWER_KEY_SUSPEND); |
218 | - accelerator->activated.connect(std::bind(PowerAction, session, SUSPEND_BUTTON_ACTION_KEY)); |
219 | - accelerators_->Add(accelerator); |
220 | - |
221 | - accelerator = std::make_shared<Accelerator>(POWER_KEY_SLEEP); |
222 | - accelerator->activated.connect(std::bind(PowerAction, session, SLEEP_BUTTON_ACTION_KEY)); |
223 | - accelerators_->Add(accelerator); |
224 | - |
225 | - accelerator = std::make_shared<Accelerator>(POWER_KEY_HIBERNATE); |
226 | - accelerator->activated.connect(std::bind(PowerAction, session, HIBERNATE_BUTTON_ACTION_KEY)); |
227 | - accelerators_->Add(accelerator); |
228 | - |
229 | - accelerator = std::make_shared<Accelerator>(POWER_KEY_POWEROFF); |
230 | - accelerator->activated.connect(std::bind(PowerAction, session, POWER_BUTTON_ACTION_KEY)); |
231 | - accelerators_->Add(accelerator); |
232 | - |
233 | - settings = glib::Object<GSettings>(g_settings_new(INPUT_SWITCH_SCHEMA)); |
234 | - |
235 | - auto variant = glib::Variant(g_settings_get_value(settings, INPUT_SWITCH_KEY_PREVIOUS_SOURCE), glib::StealRef()); |
236 | - |
237 | - if (g_variant_n_children(variant) > 0) |
238 | - { |
239 | - const gchar* string; |
240 | - |
241 | - g_variant_get_child(variant, 0, "&s", &string); |
242 | - |
243 | - accelerator = std::make_shared<Accelerator>(string); |
244 | - accelerator->activated.connect(std::bind(ScrollIndicatorKeyboard, -1)); |
245 | - accelerators_->Add(accelerator); |
246 | - } |
247 | - |
248 | - variant = glib::Variant(g_settings_get_value(settings, INPUT_SWITCH_KEY_NEXT_SOURCE), glib::StealRef()); |
249 | - |
250 | - if (g_variant_n_children(variant) > 0) |
251 | - { |
252 | - const gchar* string; |
253 | - |
254 | - g_variant_get_child(variant, 0, "&s", &string); |
255 | - |
256 | - accelerator = std::make_shared<Accelerator>(string); |
257 | - accelerator->activated.connect(std::bind(ScrollIndicatorKeyboard, +1)); |
258 | - accelerators_->Add(accelerator); |
259 | - } |
260 | + for (auto const& action : key_grabber->GetActions()) |
261 | + AddAction(action); |
262 | + |
263 | + key_grabber->action_added.connect(sigc::mem_fun(this, &AcceleratorController::AddAction)); |
264 | + key_grabber->action_removed.connect(sigc::mem_fun(this, &AcceleratorController::RemoveAction)); |
265 | +} |
266 | + |
267 | +void AcceleratorController::AddAction(CompAction const& action) |
268 | +{ |
269 | + if (action.type() != CompAction::BindingTypeKey) |
270 | + return; |
271 | + |
272 | + auto const& key = action.keyToString(); |
273 | + |
274 | + if (!IsKeyBindingAllowed(key)) |
275 | + { |
276 | + LOG_DEBUG(logger) << "Action not allowed " << key; |
277 | + return; |
278 | + } |
279 | + |
280 | + auto accelerator = std::make_shared<Accelerator>(key); |
281 | + accelerator->activated.connect(sigc::bind(sigc::mem_fun(this, &AcceleratorController::OnActionActivated), action)); |
282 | + accelerators_->Add(accelerator); |
283 | + actions_accelerators_.push_back({action, accelerator}); |
284 | + |
285 | + LOG_DEBUG(logger) << "Action added " << key; |
286 | +} |
287 | + |
288 | +void AcceleratorController::RemoveAction(CompAction const& action) |
289 | +{ |
290 | + if (action.type() != CompAction::BindingTypeKey) |
291 | + return; |
292 | + |
293 | + LOG_DEBUG(logger) << "Removing action " << action.keyToString(); |
294 | + |
295 | + for (auto it = begin(actions_accelerators_); it != end(actions_accelerators_);) |
296 | + { |
297 | + if (it->first == action) |
298 | + { |
299 | + accelerators_->Remove(it->second); |
300 | + it = actions_accelerators_.erase(it); |
301 | + } |
302 | + else |
303 | + { |
304 | + ++it; |
305 | + } |
306 | + } |
307 | +} |
308 | + |
309 | +void AcceleratorController::OnActionActivated(CompAction& action) |
310 | +{ |
311 | + LOG_DEBUG(logger) << "Activating action " << action.keyToString(); |
312 | + |
313 | + CompOption::Vector options; |
314 | + |
315 | + if (action.state() & CompAction::StateInitKey) |
316 | + action.initiate()(&action, 0, options); |
317 | + |
318 | + if (action.state() & CompAction::StateTermKey) |
319 | + action.terminate()(&action, CompAction::StateTermTapped, options); |
320 | } |
321 | |
322 | Accelerators::Ptr const& AcceleratorController::GetAccelerators() const |
323 | |
324 | === modified file 'lockscreen/LockScreenAcceleratorController.h' |
325 | --- lockscreen/LockScreenAcceleratorController.h 2016-03-31 09:51:33 +0000 |
326 | +++ lockscreen/LockScreenAcceleratorController.h 2016-06-21 14:42:21 +0000 |
327 | @@ -20,7 +20,7 @@ |
328 | #ifndef UNITY_LOCKSCREEN_ACCELERATOR_CONTROLLER |
329 | #define UNITY_LOCKSCREEN_ACCELERATOR_CONTROLLER |
330 | |
331 | -#include "UnityCore/SessionManager.h" |
332 | +#include "unity-shared/KeyGrabber.h" |
333 | #include "LockScreenAccelerators.h" |
334 | |
335 | namespace unity |
336 | @@ -28,16 +28,21 @@ |
337 | namespace lockscreen |
338 | { |
339 | |
340 | -class AcceleratorController |
341 | +class AcceleratorController : public sigc::trackable |
342 | { |
343 | public: |
344 | typedef std::shared_ptr<AcceleratorController> Ptr; |
345 | |
346 | - AcceleratorController(session::Manager::Ptr const&); |
347 | + AcceleratorController(key::Grabber::Ptr const&); |
348 | |
349 | Accelerators::Ptr const& GetAccelerators() const; |
350 | |
351 | private: |
352 | + void AddAction(CompAction const&); |
353 | + void RemoveAction(CompAction const&); |
354 | + void OnActionActivated(CompAction&); |
355 | + |
356 | + std::vector<std::pair<CompAction, Accelerator::Ptr>> actions_accelerators_; |
357 | Accelerators::Ptr accelerators_; |
358 | }; |
359 | |
360 | |
361 | === modified file 'lockscreen/LockScreenAccelerators.cpp' |
362 | --- lockscreen/LockScreenAccelerators.cpp 2014-04-30 04:34:40 +0000 |
363 | +++ lockscreen/LockScreenAccelerators.cpp 2016-06-21 14:42:21 +0000 |
364 | @@ -417,6 +417,11 @@ |
365 | { |
366 | } |
367 | |
368 | +Accelerators::Vector Accelerators::GetAccelerators() const |
369 | +{ |
370 | + return accelerators_; |
371 | +} |
372 | + |
373 | void Accelerators::Clear() |
374 | { |
375 | accelerators_.clear(); |
376 | |
377 | === modified file 'lockscreen/LockScreenAccelerators.h' |
378 | --- lockscreen/LockScreenAccelerators.h 2014-05-12 19:28:48 +0000 |
379 | +++ lockscreen/LockScreenAccelerators.h 2016-06-21 14:42:21 +0000 |
380 | @@ -69,9 +69,11 @@ |
381 | { |
382 | public: |
383 | typedef std::shared_ptr<Accelerators> Ptr; |
384 | + typedef std::vector<Accelerator::Ptr> Vector; |
385 | |
386 | Accelerators(); |
387 | |
388 | + Accelerators::Vector GetAccelerators() const; |
389 | void Clear(); |
390 | |
391 | void Add(Accelerator::Ptr const& accelerator); |
392 | @@ -83,7 +85,7 @@ |
393 | unsigned int modifiers); |
394 | |
395 | private: |
396 | - std::vector<Accelerator::Ptr> accelerators_; |
397 | + Accelerators::Vector accelerators_; |
398 | |
399 | PressedState pressed_state_; |
400 | }; |
401 | |
402 | === modified file 'lockscreen/LockScreenController.cpp' |
403 | --- lockscreen/LockScreenController.cpp 2016-04-15 05:32:41 +0000 |
404 | +++ lockscreen/LockScreenController.cpp 2016-06-21 14:42:21 +0000 |
405 | @@ -54,12 +54,14 @@ |
406 | |
407 | Controller::Controller(DBusManager::Ptr const& dbus_manager, |
408 | session::Manager::Ptr const& session_manager, |
409 | + key::Grabber::Ptr const& key_grabber, |
410 | UpstartWrapper::Ptr const& upstart_wrapper, |
411 | ShieldFactoryInterface::Ptr const& shield_factory, |
412 | bool test_mode) |
413 | : opacity([this] { return fade_animator_.GetCurrentValue(); }) |
414 | , dbus_manager_(dbus_manager) |
415 | , session_manager_(session_manager) |
416 | + , key_grabber_(key_grabber) |
417 | , upstart_wrapper_(upstart_wrapper) |
418 | , shield_factory_(shield_factory) |
419 | , suspend_inhibitor_manager_(std::make_shared<SuspendInhibitorManager>()) |
420 | @@ -459,7 +461,7 @@ |
421 | indicators_ = std::make_shared<indicator::LockScreenDBusIndicators>(); |
422 | upstart_wrapper_->Emit("desktop-lock"); |
423 | |
424 | - accelerator_controller_ = std::make_shared<AcceleratorController>(session_manager_); |
425 | + accelerator_controller_ = std::make_shared<AcceleratorController>(key_grabber_); |
426 | auto activate_key = WindowManager::Default().activate_indicators_key(); |
427 | auto accelerator = std::make_shared<Accelerator>(activate_key.second, 0, activate_key.first); |
428 | accelerator->activated.connect(std::bind(std::mem_fn(&Controller::ActivatePanel), this)); |
429 | |
430 | === modified file 'lockscreen/LockScreenController.h' |
431 | --- lockscreen/LockScreenController.h 2016-03-31 09:59:30 +0000 |
432 | +++ lockscreen/LockScreenController.h 2016-06-21 14:42:21 +0000 |
433 | @@ -30,6 +30,7 @@ |
434 | #include "SuspendInhibitorManager.h" |
435 | #include "ScreenSaverDBusManager.h" |
436 | #include "unity-shared/BackgroundEffectHelper.h" |
437 | +#include "unity-shared/KeyGrabber.h" |
438 | #include "unity-shared/UpstartWrapper.h" |
439 | |
440 | namespace unity |
441 | @@ -44,7 +45,7 @@ |
442 | public: |
443 | typedef std::shared_ptr<Controller> Ptr; |
444 | |
445 | - Controller(DBusManager::Ptr const&, session::Manager::Ptr const&, |
446 | + Controller(DBusManager::Ptr const&, session::Manager::Ptr const&, key::Grabber::Ptr const&, |
447 | UpstartWrapper::Ptr const& upstart_wrapper = std::make_shared<UpstartWrapper>(), |
448 | ShieldFactoryInterface::Ptr const& shield_factory = std::make_shared<ShieldFactory>(), |
449 | bool test_mode = false); |
450 | @@ -84,6 +85,7 @@ |
451 | |
452 | DBusManager::Ptr dbus_manager_; |
453 | session::Manager::Ptr session_manager_; |
454 | + key::Grabber::Ptr key_grabber_; |
455 | indicator::Indicators::Ptr indicators_; |
456 | AcceleratorController::Ptr accelerator_controller_; |
457 | UpstartWrapper::Ptr upstart_wrapper_; |
458 | |
459 | === modified file 'plugins/unityshell/src/unityshell.cpp' |
460 | --- plugins/unityshell/src/unityshell.cpp 2016-06-06 14:28:29 +0000 |
461 | +++ plugins/unityshell/src/unityshell.cpp 2016-06-21 14:42:21 +0000 |
462 | @@ -4081,24 +4081,24 @@ |
463 | ShowFirstRunHints(); |
464 | |
465 | // Setup Session Controller |
466 | - auto manager = std::make_shared<session::GnomeManager>(); |
467 | - manager->lock_requested.connect(sigc::mem_fun(this, &UnityScreen::OnLockScreenRequested)); |
468 | - manager->prompt_lock_requested.connect(sigc::mem_fun(this, &UnityScreen::OnLockScreenRequested)); |
469 | - manager->locked.connect(sigc::mem_fun(this, &UnityScreen::OnScreenLocked)); |
470 | - manager->unlocked.connect(sigc::mem_fun(this, &UnityScreen::OnScreenUnlocked)); |
471 | - session_dbus_manager_ = std::make_shared<session::DBusManager>(manager); |
472 | - session_controller_ = std::make_shared<session::Controller>(manager); |
473 | + auto session = std::make_shared<session::GnomeManager>(); |
474 | + session->lock_requested.connect(sigc::mem_fun(this, &UnityScreen::OnLockScreenRequested)); |
475 | + session->prompt_lock_requested.connect(sigc::mem_fun(this, &UnityScreen::OnLockScreenRequested)); |
476 | + session->locked.connect(sigc::mem_fun(this, &UnityScreen::OnScreenLocked)); |
477 | + session->unlocked.connect(sigc::mem_fun(this, &UnityScreen::OnScreenUnlocked)); |
478 | + session_dbus_manager_ = std::make_shared<session::DBusManager>(session); |
479 | + session_controller_ = std::make_shared<session::Controller>(session); |
480 | LOG_INFO(logger) << "InitUnityComponents-Session " << timer.ElapsedSeconds() << "s"; |
481 | Introspectable::AddChild(session_controller_.get()); |
482 | |
483 | // Setup Lockscreen Controller |
484 | - screensaver_dbus_manager_ = std::make_shared<lockscreen::DBusManager>(manager); |
485 | - lockscreen_controller_ = std::make_shared<lockscreen::Controller>(screensaver_dbus_manager_, manager); |
486 | + screensaver_dbus_manager_ = std::make_shared<lockscreen::DBusManager>(session); |
487 | + lockscreen_controller_ = std::make_shared<lockscreen::Controller>(screensaver_dbus_manager_, session, menus_->KeyGrabber()); |
488 | UpdateActivateIndicatorsKey(); |
489 | LOG_INFO(logger) << "InitUnityComponents-Lockscreen " << timer.ElapsedSeconds() << "s"; |
490 | |
491 | if (g_file_test((DesktopUtilities::GetUserRuntimeDirectory()+local::LOCKED_STAMP).c_str(), G_FILE_TEST_EXISTS)) |
492 | - manager->PromptLockScreen(); |
493 | + session->PromptLockScreen(); |
494 | |
495 | auto on_launcher_size_changed = [this] (nux::Area* area, int w, int h) { |
496 | /* The launcher geometry includes 1px used to draw the right/top margin |
497 | |
498 | === modified file 'tests/test_lockscreen_controller.cpp' |
499 | --- tests/test_lockscreen_controller.cpp 2015-12-05 07:03:25 +0000 |
500 | +++ tests/test_lockscreen_controller.cpp 2016-06-21 14:42:21 +0000 |
501 | @@ -33,6 +33,7 @@ |
502 | #include "unity-shared/DashStyle.h" |
503 | #include "unity-shared/PanelStyle.h" |
504 | #include "unity-shared/UScreen.h" |
505 | +#include "mock_key_grabber.h" |
506 | #include "test_mock_session_manager.h" |
507 | #include "test_uscreen_mock.h" |
508 | #include "test_utils.h" |
509 | @@ -80,19 +81,21 @@ |
510 | TestLockScreenController() |
511 | : animation_controller(tick_source) |
512 | , session_manager(std::make_shared<NiceMock<session::MockManager>>()) |
513 | + , key_grabber(std::make_shared<key::MockGrabber::Nice>()) |
514 | , dbus_manager(std::make_shared<DBusManager>(session_manager)) |
515 | , upstart_wrapper(std::make_shared<UpstartWrapper>()) |
516 | , shield_factory(std::make_shared<ShieldFactoryMock>()) |
517 | - , controller(dbus_manager, session_manager, upstart_wrapper, shield_factory) |
518 | + , controller(dbus_manager, session_manager, key_grabber, upstart_wrapper, shield_factory) |
519 | {} |
520 | |
521 | struct ControllerWrap : Controller |
522 | { |
523 | ControllerWrap(DBusManager::Ptr const& dbus_manager, |
524 | session::Manager::Ptr const& session_manager, |
525 | + key::Grabber::Ptr const& key_grabber, |
526 | UpstartWrapper::Ptr const& upstart_wrapper, |
527 | ShieldFactoryInterface::Ptr const& shield_factory) |
528 | - : Controller(dbus_manager, session_manager, upstart_wrapper, shield_factory, /* test_mode */ true) |
529 | + : Controller(dbus_manager, session_manager, key_grabber, upstart_wrapper, shield_factory, /* test_mode */ true) |
530 | {} |
531 | |
532 | using Controller::shields_; |
533 | @@ -107,6 +110,7 @@ |
534 | unity::panel::Style panel_style; |
535 | unity::lockscreen::Settings lockscreen_settings; |
536 | session::MockManager::Ptr session_manager; |
537 | + key::MockGrabber::Ptr key_grabber; |
538 | DBusManager::Ptr dbus_manager; |
539 | unity::UpstartWrapper::Ptr upstart_wrapper; |
540 | |
541 | @@ -123,7 +127,7 @@ |
542 | { |
543 | size_t before = uscreen.changed.size(); |
544 | { |
545 | - Controller dummy(dbus_manager, session_manager); |
546 | + Controller dummy(dbus_manager, session_manager, key_grabber); |
547 | } |
548 | ASSERT_EQ(before, uscreen.changed.size()); |
549 | |
550 | @@ -135,7 +139,7 @@ |
551 | { |
552 | size_t before = session_manager->unlock_requested.size(); |
553 | { |
554 | - Controller dummy(dbus_manager, session_manager); |
555 | + Controller dummy(dbus_manager, session_manager, key_grabber); |
556 | } |
557 | ASSERT_EQ(before, session_manager->unlock_requested.size()); |
558 | |
559 | |
560 | === modified file 'unity-shared/GnomeKeyGrabber.cpp' |
561 | --- unity-shared/GnomeKeyGrabber.cpp 2016-05-30 16:10:12 +0000 |
562 | +++ unity-shared/GnomeKeyGrabber.cpp 2016-06-21 14:42:21 +0000 |
563 | @@ -70,8 +70,9 @@ |
564 | std::string const DBUS_NAME = "com.canonical.Unity.Test.GnomeKeyGrabber"; |
565 | } |
566 | |
567 | -GnomeGrabber::Impl::Impl(bool test_mode) |
568 | - : screen_(screen) |
569 | +GnomeGrabber::Impl::Impl(Grabber* parent, bool test_mode) |
570 | + : parent_(parent) |
571 | + , screen_(screen) |
572 | , shell_server_(test_mode ? testing::DBUS_NAME : shell::DBUS_NAME) |
573 | , settings_(g_settings_new(SETTINGS_NAME.c_str())) |
574 | , current_action_id_(0) |
575 | @@ -123,6 +124,7 @@ |
576 | actions_ids_.push_back(action_id); |
577 | actions_.push_back(action); |
578 | actions_customers_.push_back(1); |
579 | + parent_->action_added.emit(action); |
580 | return true; |
581 | } |
582 | |
583 | @@ -178,6 +180,7 @@ |
584 | LOG_DEBUG(logger) << "RemoveAction (\"" << action->keyToString() << "\")"; |
585 | |
586 | screen_->removeAction(action); |
587 | + parent_->action_removed.emit(*action); |
588 | actions_.erase(actions_.begin() + index); |
589 | actions_ids_.erase(actions_ids_.begin() + index); |
590 | actions_customers_.erase(actions_customers_.begin() + index); |
591 | @@ -259,7 +262,6 @@ |
592 | action.setState(CompAction::StateInitKey | CompAction::StateTermKey); |
593 | action.setTerminate([this, action_id](CompAction* action, CompAction::State state, CompOption::Vector& options) { |
594 | auto key = action->keyToString(); |
595 | - |
596 | LOG_DEBUG(logger) << "released \"" << key << "\""; |
597 | |
598 | if (state & CompAction::StateTermTapped) |
599 | @@ -353,11 +355,11 @@ |
600 | // Public implementation |
601 | |
602 | GnomeGrabber::GnomeGrabber() |
603 | - : impl_(new Impl()) |
604 | + : impl_(new Impl(this)) |
605 | {} |
606 | |
607 | GnomeGrabber::GnomeGrabber(TestMode const& dummy) |
608 | - : impl_(new Impl(true)) |
609 | + : impl_(new Impl(this, true)) |
610 | {} |
611 | |
612 | GnomeGrabber::~GnomeGrabber() |
613 | |
614 | === modified file 'unity-shared/GnomeKeyGrabberImpl.h' |
615 | --- unity-shared/GnomeKeyGrabberImpl.h 2016-05-30 15:54:34 +0000 |
616 | +++ unity-shared/GnomeKeyGrabberImpl.h 2016-06-21 14:42:21 +0000 |
617 | @@ -37,7 +37,7 @@ |
618 | |
619 | struct GnomeGrabber::Impl |
620 | { |
621 | - Impl(bool test_mode = false); |
622 | + Impl(Grabber*, bool test_mode = false); |
623 | ~Impl(); |
624 | |
625 | uint32_t NextActionID(); |
626 | @@ -55,9 +55,9 @@ |
627 | void ActivateDBusAction(CompAction const& action, uint32_t id, uint32_t device, uint32_t timestamp) const; |
628 | |
629 | bool IsActionPostponed(CompAction const& action) const; |
630 | - |
631 | void UpdateWhitelist(); |
632 | |
633 | + Grabber* parent_; |
634 | CompScreen* screen_; |
635 | |
636 | glib::DBusServer shell_server_; |
637 | |
638 | === modified file 'unity-shared/KeyGrabber.h' |
639 | --- unity-shared/KeyGrabber.h 2015-09-29 13:06:46 +0000 |
640 | +++ unity-shared/KeyGrabber.h 2016-06-21 14:42:21 +0000 |
641 | @@ -21,6 +21,7 @@ |
642 | #define __UNITY_KEY_GRABBER__ |
643 | |
644 | #include <core/core.h> |
645 | +#include <sigc++/signal.h> |
646 | |
647 | namespace unity |
648 | { |
649 | @@ -36,6 +37,9 @@ |
650 | virtual bool RemoveAction(CompAction const&) = 0; |
651 | virtual bool RemoveAction(uint32_t id) = 0; |
652 | |
653 | + sigc::signal<void, CompAction const&> action_added; |
654 | + sigc::signal<void, CompAction const&> action_removed; |
655 | + |
656 | virtual CompAction::Vector& GetActions() = 0; |
657 | }; |
658 |
LGTM.