Merge lp:~3v1n0/unity/lockscreen-power-keys into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Stephen M. Webb
Approved revision: no longer in the source branch.
Merged at revision: 3828
Proposed branch: lp:~3v1n0/unity/lockscreen-power-keys
Merge into: lp:unity
Prerequisite: lp:~brandontschaefer/unity/shutdown-dialog-hi-dpi
Diff against target: 701 lines (+225/-66)
14 files modified
UnityCore/GnomeSessionManager.cpp (+62/-14)
UnityCore/GnomeSessionManager.h (+2/-0)
UnityCore/GnomeSessionManagerImpl.h (+1/-0)
UnityCore/SessionManager.h (+3/-0)
lockscreen/LockScreenAcceleratorController.cpp (+46/-2)
lockscreen/LockScreenAcceleratorController.h (+2/-1)
lockscreen/LockScreenController.cpp (+3/-3)
shutdown/SessionDBusManager.cpp (+23/-9)
shutdown/SessionView.cpp (+49/-30)
shutdown/SessionView.h (+6/-5)
shutdown/StandaloneSession.cpp (+2/-0)
tests/test_mock_session_manager.h (+2/-0)
tests/test_session_controller.cpp (+1/-0)
tests/test_session_view.cpp (+23/-2)
To merge this branch: bzr merge lp:~3v1n0/unity/lockscreen-power-keys
Reviewer Review Type Date Requested Status
Stephen M. Webb (community) Approve
PS Jenkins bot (community) continuous-integration Needs Fixing
Christopher Townsend Approve
Review via email: mp+219778@code.launchpad.net

Commit message

LockScreenAcceleratorController: do ther configured action on power special keys press

We finally can suspend, shutdown, hibernate or start the screensaver when the screen is locked, using
the Suspend, Sleep, Hibernate and PowerOff hardware keys.

Also the Shutdown dialog doesn't allow now to lock the session if it is not allowed by settings.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Christopher Townsend (townsend) wrote :

LGTM

Revision history for this message
Christopher Townsend (townsend) wrote :

Oops, meant to approve

review: Approve
Revision history for this message
Stephen M. Webb (bregma) wrote :

Merge conflicts when attempting to merge to trunk.

Text conflict in lockscreen/LockScreenController.cpp
Text conflict in shutdown/SessionView.cpp
2 conflicts encountered.

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Stephen M. Webb (bregma) wrote :

OK, merges cleanly now

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'UnityCore/GnomeSessionManager.cpp'
--- UnityCore/GnomeSessionManager.cpp 2014-04-16 22:03:41 +0000
+++ UnityCore/GnomeSessionManager.cpp 2014-06-18 15:11:36 +0000
@@ -91,6 +91,11 @@
91 shell_object_ = shell_server_.GetObject(shell::DBUS_INTERFACE);91 shell_object_ = shell_server_.GetObject(shell::DBUS_INTERFACE);
92 shell_object_->SetMethodsCallsHandler(sigc::mem_fun(this, &Impl::OnShellMethodCall));92 shell_object_->SetMethodsCallsHandler(sigc::mem_fun(this, &Impl::OnShellMethodCall));
9393
94 manager_->is_locked = false;
95 manager_->is_locked.changed.connect([this] (bool locked) {
96 locked ? manager_->locked.emit() : manager_->unlocked.emit();
97 });
98
94 {99 {
95 const char* session_id = test_mode_ ? "id0" : g_getenv("XDG_SESSION_ID");100 const char* session_id = test_mode_ ? "id0" : g_getenv("XDG_SESSION_ID");
96101
@@ -421,21 +426,13 @@
421{426{
422 EnsureCancelPendingAction();427 EnsureCancelPendingAction();
423428
429 if (!manager_->CanLock())
430 {
431 manager_->ScreenSaverActivate();
432 return;
433 }
434
424 // FIXME (andy) we should ask gnome-session to emit the logind signal435 // FIXME (andy) we should ask gnome-session to emit the logind signal
425 glib::Object<GSettings> lockdown_settings(g_settings_new(GNOME_LOCKDOWN_OPTIONS.c_str()));
426
427 if (g_settings_get_boolean(lockdown_settings, DISABLE_LOCKSCREEN_KEY.c_str()))
428 {
429 manager_->ScreenSaverActivate();
430 return;
431 }
432 else if (manager_->UserName().find("guest-") == 0)
433 {
434 LOG_INFO(logger) << "Impossible to lock a guest session";
435 manager_->ScreenSaverActivate();
436 return;
437 }
438
439 prompt ? manager_->prompt_lock_requested.emit() : manager_->lock_requested.emit();436 prompt ? manager_->prompt_lock_requested.emit() : manager_->lock_requested.emit();
440}437}
441438
@@ -454,6 +451,39 @@
454 });451 });
455}452}
456453
454bool GnomeManager::Impl::HasInhibitors()
455{
456 glib::Error error;
457 glib::Object<GDBusConnection> bus(g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, &error));
458
459 if (error)
460 {
461 LOG_ERROR(logger) << "Impossible to get the session bus, to fetch the inhibitors: " << error;
462 return false;
463 }
464
465 enum class Inhibited : unsigned
466 {
467 LOGOUT = 1,
468 USER_SWITCH = 2,
469 SUSPEND = 4,
470 IDLE_SET = 8
471 };
472
473 glib::Variant inhibitors(g_dbus_connection_call_sync(bus, test_mode_ ? testing::DBUS_NAME.c_str() : "org.gnome.SessionManager",
474 "/org/gnome/SessionManager", "org.gnome.SessionManager",
475 "IsInhibited", g_variant_new("(u)", Inhibited::LOGOUT), nullptr,
476 G_DBUS_CALL_FLAGS_NONE, 500, nullptr, &error));
477
478 if (error)
479 {
480 LOG_ERROR(logger) << "Impossible to get the inhibitors: " << error;
481 return false;
482 }
483
484 return inhibitors.GetBool();
485}
486
457// Public implementation487// Public implementation
458488
459GnomeManager::GnomeManager()489GnomeManager::GnomeManager()
@@ -617,6 +647,19 @@
617 });647 });
618}648}
619649
650bool GnomeManager::CanLock() const
651{
652 glib::Object<GSettings> lockdown_settings(g_settings_new(GNOME_LOCKDOWN_OPTIONS.c_str()));
653
654 if (g_settings_get_boolean(lockdown_settings, DISABLE_LOCKSCREEN_KEY.c_str()) ||
655 UserName().find("guest-") == 0 || is_locked())
656 {
657 return false;
658 }
659
660 return true;
661}
662
620bool GnomeManager::CanShutdown() const663bool GnomeManager::CanShutdown() const
621{664{
622 return impl_->can_shutdown_;665 return impl_->can_shutdown_;
@@ -632,6 +675,11 @@
632 return impl_->can_hibernate_;675 return impl_->can_hibernate_;
633}676}
634677
678bool GnomeManager::HasInhibitors() const
679{
680 return impl_->HasInhibitors();
681}
682
635void GnomeManager::CancelAction()683void GnomeManager::CancelAction()
636{684{
637 impl_->CancelAction();685 impl_->CancelAction();
638686
=== modified file 'UnityCore/GnomeSessionManager.h'
--- UnityCore/GnomeSessionManager.h 2014-04-10 04:47:58 +0000
+++ UnityCore/GnomeSessionManager.h 2014-06-18 15:11:36 +0000
@@ -47,9 +47,11 @@
47 void Suspend();47 void Suspend();
48 void Hibernate();48 void Hibernate();
4949
50 bool CanLock() const;
50 bool CanShutdown() const;51 bool CanShutdown() const;
51 bool CanSuspend() const;52 bool CanSuspend() const;
52 bool CanHibernate() const;53 bool CanHibernate() const;
54 bool HasInhibitors() const;
5355
54 void CancelAction();56 void CancelAction();
5557
5658
=== modified file 'UnityCore/GnomeSessionManagerImpl.h'
--- UnityCore/GnomeSessionManagerImpl.h 2014-04-16 21:51:45 +0000
+++ UnityCore/GnomeSessionManagerImpl.h 2014-06-18 15:11:36 +0000
@@ -51,6 +51,7 @@
51 void ConfirmShutdown();51 void ConfirmShutdown();
52 void CancelAction();52 void CancelAction();
53 void ClosedDialog();53 void ClosedDialog();
54 bool HasInhibitors();
54 void EnsureCancelPendingAction();55 void EnsureCancelPendingAction();
55 void LockScreen(bool prompt);56 void LockScreen(bool prompt);
5657
5758
=== modified file 'UnityCore/SessionManager.h'
--- UnityCore/SessionManager.h 2014-04-16 21:51:45 +0000
+++ UnityCore/SessionManager.h 2014-06-18 15:11:36 +0000
@@ -39,6 +39,7 @@
39 virtual ~Manager() = default;39 virtual ~Manager() = default;
4040
41 nux::ROProperty<bool> have_other_open_sessions;41 nux::ROProperty<bool> have_other_open_sessions;
42 nux::Property<bool> is_locked;
4243
43 virtual std::string RealName() const = 0;44 virtual std::string RealName() const = 0;
44 virtual std::string UserName() const = 0;45 virtual std::string UserName() const = 0;
@@ -54,9 +55,11 @@
54 virtual void Suspend() = 0;55 virtual void Suspend() = 0;
55 virtual void Hibernate() = 0;56 virtual void Hibernate() = 0;
5657
58 virtual bool CanLock() const = 0;
57 virtual bool CanShutdown() const = 0;59 virtual bool CanShutdown() const = 0;
58 virtual bool CanSuspend() const = 0;60 virtual bool CanSuspend() const = 0;
59 virtual bool CanHibernate() const = 0;61 virtual bool CanHibernate() const = 0;
62 virtual bool HasInhibitors() const = 0;
6063
61 virtual void CancelAction() = 0;64 virtual void CancelAction() = 0;
6265
6366
=== modified file 'lockscreen/LockScreenAcceleratorController.cpp'
--- lockscreen/LockScreenAcceleratorController.cpp 2014-04-28 13:09:53 +0000
+++ lockscreen/LockScreenAcceleratorController.cpp 2014-06-18 15:11:36 +0000
@@ -32,6 +32,17 @@
32const char* const MEDIA_KEYS_KEY_VOLUME_MUTE = "volume-mute";32const char* const MEDIA_KEYS_KEY_VOLUME_MUTE = "volume-mute";
33const char* const MEDIA_KEYS_KEY_VOLUME_DOWN = "volume-down";33const char* const MEDIA_KEYS_KEY_VOLUME_DOWN = "volume-down";
34const char* const MEDIA_KEYS_KEY_VOLUME_UP = "volume-up";34const char* const MEDIA_KEYS_KEY_VOLUME_UP = "volume-up";
35
36const char* const POWER_SCHEMA = "org.gnome.settings-daemon.plugins.power";
37const char* const SUSPEND_BUTTON_ACTION_KEY = "button-suspend";
38const char* const SLEEP_BUTTON_ACTION_KEY = "button-sleep";
39const char* const HIBERNATE_BUTTON_ACTION_KEY = "button-hibernate";
40const char* const POWER_BUTTON_ACTION_KEY = "button-power";
41const char* const POWER_KEY_SUSPEND = "XF86Suspend";
42const char* const POWER_KEY_SLEEP = "XF86Sleep";
43const char* const POWER_KEY_HIBERNATE = "XF86Hibernate";
44const char* const POWER_KEY_POWEROFF = "XF86PowerOff";
45
35const char* const INPUT_SWITCH_SCHEMA = "org.gnome.desktop.wm.keybindings";46const char* const INPUT_SWITCH_SCHEMA = "org.gnome.desktop.wm.keybindings";
36const char* const INPUT_SWITCH_KEY_PREVIOUS_SOURCE = "switch-input-source-backward";47const char* const INPUT_SWITCH_KEY_PREVIOUS_SOURCE = "switch-input-source-backward";
37const char* const INPUT_SWITCH_KEY_NEXT_SOURCE = "switch-input-source";48const char* const INPUT_SWITCH_KEY_NEXT_SOURCE = "switch-input-source";
@@ -89,15 +100,32 @@
89 INDICATOR_KEYBOARD_ACTION_SCROLL,100 INDICATOR_KEYBOARD_ACTION_SCROLL,
90 g_variant_new_int32(-offset));101 g_variant_new_int32(-offset));
91}102}
103
104void PowerAction(session::Manager::Ptr const& session, const char *action_key)
105{
106 glib::Object<GSettings> settings(g_settings_new(POWER_SCHEMA));
107 auto const& action = glib::String(g_settings_get_string(settings, action_key)).Str();
108
109 if (action == "interactive")
110 session->shutdown_requested.emit(session->HasInhibitors());
111 else if (action == "shutdown")
112 session->reboot_requested.emit(session->HasInhibitors());
113 else if (action == "suspend")
114 session->Suspend();
115 else if (action == "hibernate")
116 session->Hibernate();
117 else if (action == "blank")
118 session->ScreenSaverActivate();
119}
92} // namespace120} // namespace
93121
94AcceleratorController::AcceleratorController()122AcceleratorController::AcceleratorController(session::Manager::Ptr const& session)
95 : accelerators_(new Accelerators)123 : accelerators_(new Accelerators)
96{124{
97 auto settings = glib::Object<GSettings>(g_settings_new(MEDIA_KEYS_SCHEMA));125 auto settings = glib::Object<GSettings>(g_settings_new(MEDIA_KEYS_SCHEMA));
98126
99 auto accelerator = std::make_shared<Accelerator>(glib::String(g_settings_get_string(settings, MEDIA_KEYS_KEY_VOLUME_MUTE)));127 auto accelerator = std::make_shared<Accelerator>(glib::String(g_settings_get_string(settings, MEDIA_KEYS_KEY_VOLUME_MUTE)));
100 accelerator->activated.connect(std::function<void ()>(MuteIndicatorSound));128 accelerator->activated.connect(std::function<void()>(MuteIndicatorSound));
101 accelerators_->Add(accelerator);129 accelerators_->Add(accelerator);
102130
103 accelerator = std::make_shared<Accelerator>(glib::String(g_settings_get_string(settings, MEDIA_KEYS_KEY_VOLUME_DOWN)));131 accelerator = std::make_shared<Accelerator>(glib::String(g_settings_get_string(settings, MEDIA_KEYS_KEY_VOLUME_DOWN)));
@@ -108,6 +136,22 @@
108 accelerator->activated.connect(std::bind(ScrollIndicatorSound, +1));136 accelerator->activated.connect(std::bind(ScrollIndicatorSound, +1));
109 accelerators_->Add(accelerator);137 accelerators_->Add(accelerator);
110138
139 accelerator = std::make_shared<Accelerator>(POWER_KEY_SUSPEND);
140 accelerator->activated.connect(std::bind(PowerAction, session, SUSPEND_BUTTON_ACTION_KEY));
141 accelerators_->Add(accelerator);
142
143 accelerator = std::make_shared<Accelerator>(POWER_KEY_SLEEP);
144 accelerator->activated.connect(std::bind(PowerAction, session, SLEEP_BUTTON_ACTION_KEY));
145 accelerators_->Add(accelerator);
146
147 accelerator = std::make_shared<Accelerator>(POWER_KEY_HIBERNATE);
148 accelerator->activated.connect(std::bind(PowerAction, session, HIBERNATE_BUTTON_ACTION_KEY));
149 accelerators_->Add(accelerator);
150
151 accelerator = std::make_shared<Accelerator>(POWER_KEY_POWEROFF);
152 accelerator->activated.connect(std::bind(PowerAction, session, POWER_BUTTON_ACTION_KEY));
153 accelerators_->Add(accelerator);
154
111 settings = glib::Object<GSettings>(g_settings_new(INPUT_SWITCH_SCHEMA));155 settings = glib::Object<GSettings>(g_settings_new(INPUT_SWITCH_SCHEMA));
112156
113 auto variant = glib::Variant(g_settings_get_value(settings, INPUT_SWITCH_KEY_PREVIOUS_SOURCE), glib::StealRef());157 auto variant = glib::Variant(g_settings_get_value(settings, INPUT_SWITCH_KEY_PREVIOUS_SOURCE), glib::StealRef());
114158
=== modified file 'lockscreen/LockScreenAcceleratorController.h'
--- lockscreen/LockScreenAcceleratorController.h 2014-04-28 13:09:53 +0000
+++ lockscreen/LockScreenAcceleratorController.h 2014-06-18 15:11:36 +0000
@@ -20,6 +20,7 @@
20#ifndef UNITY_LOCKSCREEN_ACCELERATOR_CONTROLLER20#ifndef UNITY_LOCKSCREEN_ACCELERATOR_CONTROLLER
21#define UNITY_LOCKSCREEN_ACCELERATOR_CONTROLLER21#define UNITY_LOCKSCREEN_ACCELERATOR_CONTROLLER
2222
23#include <UnityCore/SessionManager.h>
23#include "LockScreenAccelerators.h"24#include "LockScreenAccelerators.h"
2425
25namespace unity26namespace unity
@@ -32,7 +33,7 @@
32public:33public:
33 typedef std::shared_ptr<AcceleratorController> Ptr;34 typedef std::shared_ptr<AcceleratorController> Ptr;
3435
35 AcceleratorController();36 AcceleratorController(session::Manager::Ptr const&);
3637
37 Accelerators::Ptr const& GetAccelerators() const;38 Accelerators::Ptr const& GetAccelerators() const;
3839
3940
=== modified file 'lockscreen/LockScreenController.cpp'
--- lockscreen/LockScreenController.cpp 2014-06-07 16:26:59 +0000
+++ lockscreen/LockScreenController.cpp 2014-06-18 15:11:36 +0000
@@ -104,7 +104,7 @@
104 key_connection_->disconnect();104 key_connection_->disconnect();
105 uscreen_connection_->block();105 uscreen_connection_->block();
106 hidden_window_connection_->block();106 hidden_window_connection_->block();
107 session_manager_->unlocked.emit();107 session_manager_->is_locked = false;
108108
109 std::for_each(shields_.begin(), shields_.end(), [](nux::ObjectPtr<Shield> const& shield) {109 std::for_each(shields_.begin(), shields_.end(), [](nux::ObjectPtr<Shield> const& shield) {
110 shield->RemoveLayout();110 shield->RemoveLayout();
@@ -342,7 +342,7 @@
342 HideBlankWindow();342 HideBlankWindow();
343343
344 LockScreen();344 LockScreen();
345 session_manager_->locked.emit();345 session_manager_->is_locked = true;
346346
347 if (prompt_activation_)347 if (prompt_activation_)
348 {348 {
@@ -403,7 +403,7 @@
403 indicators_ = std::make_shared<indicator::LockScreenDBusIndicators>();403 indicators_ = std::make_shared<indicator::LockScreenDBusIndicators>();
404 upstart_wrapper_->Emit("desktop-lock");404 upstart_wrapper_->Emit("desktop-lock");
405405
406 accelerator_controller_ = std::make_shared<AcceleratorController>();406 accelerator_controller_ = std::make_shared<AcceleratorController>(session_manager_);
407 auto activate_key = WindowManager::Default().activate_indicators_key();407 auto activate_key = WindowManager::Default().activate_indicators_key();
408 auto accelerator = std::make_shared<Accelerator>(activate_key.second, 0, activate_key.first);408 auto accelerator = std::make_shared<Accelerator>(activate_key.second, 0, activate_key.first);
409 accelerator->activated.connect(std::bind(std::mem_fn(&Controller::ActivatePanel), this));409 accelerator->activated.connect(std::bind(std::mem_fn(&Controller::ActivatePanel), this));
410410
=== modified file 'shutdown/SessionDBusManager.cpp'
--- shutdown/SessionDBusManager.cpp 2014-04-10 04:47:58 +0000
+++ shutdown/SessionDBusManager.cpp 2014-06-18 15:11:36 +0000
@@ -53,14 +53,20 @@
53 <method name="Suspend" />53 <method name="Suspend" />
54 <method name="Hibernate" />54 <method name="Hibernate" />
55 <method name="CancelAction" />55 <method name="CancelAction" />
56 <method name="IsLocked">
57 <arg type="b" direction="out" name="is_locked" />
58 </method>
59 <method name="CanLock">
60 <arg type="b" direction="out" name="can_lock" />
61 </method>
56 <method name="CanShutdown">62 <method name="CanShutdown">
57 <arg type="b" direction="out" name="canshutdown" />63 <arg type="b" direction="out" name="can_shutdown" />
58 </method>64 </method>
59 <method name="CanSuspend">65 <method name="CanSuspend">
60 <arg type="b" direction="out" name="cansuspend" />66 <arg type="b" direction="out" name="can_suspend" />
61 </method>67 </method>
62 <method name="CanHibernate">68 <method name="CanHibernate">
63 <arg type="b" direction="out" name="canhibernate" />69 <arg type="b" direction="out" name="can_hibernate" />
64 </method>70 </method>
6571
66 <signal name="LockRequested" />72 <signal name="LockRequested" />
@@ -121,7 +127,7 @@
121 }127 }
122 else if (method == "RequestLogout")128 else if (method == "RequestLogout")
123 {129 {
124 session_->logout_requested.emit(false);130 session_->logout_requested.emit(session_->HasInhibitors());
125 }131 }
126 else if (method == "Reboot")132 else if (method == "Reboot")
127 {133 {
@@ -129,7 +135,7 @@
129 }135 }
130 else if (method == "RequestReboot")136 else if (method == "RequestReboot")
131 {137 {
132 session_->reboot_requested.emit(false);138 session_->reboot_requested.emit(session_->HasInhibitors());
133 }139 }
134 else if (method == "Shutdown")140 else if (method == "Shutdown")
135 {141 {
@@ -137,7 +143,7 @@
137 }143 }
138 else if (method == "RequestShutdown")144 else if (method == "RequestShutdown")
139 {145 {
140 session_->shutdown_requested.emit(false);146 session_->shutdown_requested.emit(session_->HasInhibitors());
141 }147 }
142 else if (method == "Suspend")148 else if (method == "Suspend")
143 {149 {
@@ -152,17 +158,25 @@
152 session_->CancelAction();158 session_->CancelAction();
153 session_->cancel_requested.emit();159 session_->cancel_requested.emit();
154 }160 }
161 else if (method == "IsLocked")
162 {
163 return g_variant_new("(b)", session_->is_locked() != false);
164 }
165 else if (method == "CanLock")
166 {
167 return g_variant_new("(b)", session_->CanLock() != false);
168 }
155 else if (method == "CanShutdown")169 else if (method == "CanShutdown")
156 {170 {
157 return g_variant_new("(b)", session_->CanShutdown() != FALSE);171 return g_variant_new("(b)", session_->CanShutdown() != false);
158 }172 }
159 else if (method == "CanSuspend")173 else if (method == "CanSuspend")
160 {174 {
161 return g_variant_new("(b)", session_->CanSuspend() != FALSE);175 return g_variant_new("(b)", session_->CanSuspend() != false);
162 }176 }
163 else if (method == "CanHibernate")177 else if (method == "CanHibernate")
164 {178 {
165 return g_variant_new("(b)", session_->CanHibernate() != FALSE);179 return g_variant_new("(b)", session_->CanHibernate() != false);
166 }180 }
167181
168 return nullptr;182 return nullptr;
169183
=== modified file 'shutdown/SessionView.cpp'
--- shutdown/SessionView.cpp 2014-06-07 16:26:41 +0000
+++ shutdown/SessionView.cpp 2014-06-18 15:11:36 +0000
@@ -91,16 +91,17 @@
91 return false;91 return false;
92 });92 });
9393
94 mode.changed.connect([this] (Mode m) {94 mode.changed.connect(sigc::hide(sigc::mem_fun(this, &View::UpdateContents)));
95 UpdateText();
96 Populate();
97 });
98
99 scale.changed.connect(sigc::hide(sigc::mem_fun(this, &View::UpdateViewSize)));95 scale.changed.connect(sigc::hide(sigc::mem_fun(this, &View::UpdateViewSize)));
96 UpdateContents();
97}
10098
99void View::UpdateContents()
100{
101 SetVisible(true);
102 PopulateButtons();
103 UpdateText();
101 UpdateViewSize();104 UpdateViewSize();
102 UpdateText();
103 Populate();
104}105}
105106
106void View::UpdateViewSize()107void View::UpdateViewSize()
@@ -115,11 +116,17 @@
115 ReloadCloseButtonTexture();116 ReloadCloseButtonTexture();
116117
117 buttons_layout_->SetSpaceBetweenChildren(style::BUTTONS_SPACE.CP(scale()));118 buttons_layout_->SetSpaceBetweenChildren(style::BUTTONS_SPACE.CP(scale()));
118119 auto const& buttons = buttons_layout_->GetChildren();
119 for (auto* area : buttons_layout_->GetChildren())120
121 for (auto* area : buttons)
122 static_cast<Button*>(area)->scale = scale();
123
124 if (buttons.size() == 1)
120 {125 {
121 auto* button = static_cast<Button*>(area);126 auto* button = buttons.front();
122 button->scale = scale();127 button->ComputeContentSize();
128 int padding = button->GetWidth()/2 + style::MAIN_SPACE.CP(scale())/2;
129 buttons_layout_->SetLeftAndRightPadding(padding, padding);
123 }130 }
124}131}
125132
@@ -201,20 +208,26 @@
201 subtitle_->SetText(glib::String(g_strdup_printf(message.c_str(), name.c_str())).Str());208 subtitle_->SetText(glib::String(g_strdup_printf(message.c_str(), name.c_str())).Str());
202}209}
203210
204void View::Populate()211void View::PopulateButtons()
205{212{
206 debug::Introspectable::RemoveAllChildren();213 debug::Introspectable::RemoveAllChildren();
207 buttons_layout_->Clear();214 buttons_layout_->Clear();
215 buttons_layout_->SetLeftAndRightPadding(0, 0);
208 key_focus_area_ = this;216 key_focus_area_ = this;
209217
210 if (mode() == Mode::LOGOUT)218 if (mode() == Mode::LOGOUT)
211 {219 {
212 auto* button = new Button(Button::Action::LOCK, NUX_TRACKER_LOCATION);220 if (manager_->is_locked())
213 button->scale = scale();221 return;
214 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::LockScreen));222
215 AddButton(button);223 if (manager_->CanLock())
216224 {
217 button = new Button(Button::Action::LOGOUT, NUX_TRACKER_LOCATION);225 auto* button = new Button(Button::Action::LOCK, NUX_TRACKER_LOCATION);
226 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::LockScreen));
227 AddButton(button);
228 }
229
230 auto* button = new Button(Button::Action::LOGOUT, NUX_TRACKER_LOCATION);
218 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Logout));231 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Logout));
219 key_focus_area_ = button;232 key_focus_area_ = button;
220 AddButton(button);233 AddButton(button);
@@ -223,23 +236,23 @@
223 {236 {
224 if (mode() == Mode::FULL)237 if (mode() == Mode::FULL)
225 {238 {
226 auto* button = new Button(Button::Action::LOCK, NUX_TRACKER_LOCATION);239 if (manager_->CanLock())
227 button->scale = scale();240 {
228 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::LockScreen));241 auto* button = new Button(Button::Action::LOCK, NUX_TRACKER_LOCATION);
229 AddButton(button);242 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::LockScreen));
243 AddButton(button);
244 }
230245
231 if (manager_->CanSuspend())246 if (manager_->CanSuspend())
232 {247 {
233 button = new Button(Button::Action::SUSPEND, NUX_TRACKER_LOCATION);248 auto* button = new Button(Button::Action::SUSPEND, NUX_TRACKER_LOCATION);
234 button->scale = scale();
235 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Suspend));249 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Suspend));
236 AddButton(button);250 AddButton(button);
237 }251 }
238252
239 if (manager_->CanHibernate())253 if (manager_->CanHibernate())
240 {254 {
241 button = new Button(Button::Action::HIBERNATE, NUX_TRACKER_LOCATION);255 auto* button = new Button(Button::Action::HIBERNATE, NUX_TRACKER_LOCATION);
242 button->scale = scale();
243 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Hibernate));256 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Hibernate));
244 AddButton(button);257 AddButton(button);
245 }258 }
@@ -248,28 +261,34 @@
248 if (manager_->CanShutdown())261 if (manager_->CanShutdown())
249 {262 {
250 auto *button = new Button(Button::Action::REBOOT, NUX_TRACKER_LOCATION);263 auto *button = new Button(Button::Action::REBOOT, NUX_TRACKER_LOCATION);
251 button->scale = scale();
252 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Reboot));264 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Reboot));
253 AddButton(button);265 AddButton(button);
254266
255 button = new Button(Button::Action::SHUTDOWN, NUX_TRACKER_LOCATION);267 button = new Button(Button::Action::SHUTDOWN, NUX_TRACKER_LOCATION);
256 button->scale = scale();
257 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Shutdown));268 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Shutdown));
258 key_focus_area_ = (mode() == Mode::SHUTDOWN) ? button : key_focus_area_;269 key_focus_area_ = (mode() == Mode::SHUTDOWN) ? button : key_focus_area_;
259 AddButton(button);270 AddButton(button);
260 }271 }
261 else if (mode() == Mode::FULL)272 else if (mode() == Mode::FULL && !manager_->is_locked())
262 {273 {
263 auto* button = new Button(Button::Action::LOGOUT, NUX_TRACKER_LOCATION);274 auto* button = new Button(Button::Action::LOGOUT, NUX_TRACKER_LOCATION);
264 button->scale = scale();
265 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Logout));275 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Logout));
266 AddButton(button);276 AddButton(button);
267 }277 }
268 }278 }
279
280 cancel_idle_.reset();
281 if (buttons_layout_->GetChildren().empty())
282 {
283 // There's nothing to show here, let's cancel the action and hide
284 SetVisible(false);
285 cancel_idle_.reset(new glib::Idle([this] { request_close.emit(); return false; }));
286 }
269}287}
270288
271void View::AddButton(Button* button)289void View::AddButton(Button* button)
272{290{
291 button->scale = scale();
273 button->activated.connect([this] {request_hide.emit();});292 button->activated.connect([this] {request_hide.emit();});
274 buttons_layout_->AddView(button);293 buttons_layout_->AddView(button);
275 debug::Introspectable::AddChild(button);294 debug::Introspectable::AddChild(button);
276295
=== modified file 'shutdown/SessionView.h'
--- shutdown/SessionView.h 2014-04-25 18:12:48 +0000
+++ shutdown/SessionView.h 2014-06-18 15:11:36 +0000
@@ -25,10 +25,10 @@
25#include <Nux/VLayout.h>25#include <Nux/VLayout.h>
26#include <Nux/HLayout.h>26#include <Nux/HLayout.h>
2727
28#include "UnityCore/SessionManager.h"28#include <UnityCore/GLibSource.h>
29#include <UnityCore/SessionManager.h>
29#include "unity-shared/EMConverter.h"30#include "unity-shared/EMConverter.h"
30#include "unity-shared/UnityWindowView.h"31#include "unity-shared/UnityWindowView.h"
31#include "UnityCore/SessionManager.h"
3232
33namespace unity33namespace unity
34{34{
@@ -73,10 +73,10 @@
73private:73private:
74 friend class TestSessionView;74 friend class TestSessionView;
7575
76 void PopulateButtons();
77 void UpdateText();
78 void UpdateContents();
76 void UpdateViewSize();79 void UpdateViewSize();
77
78 void UpdateText();
79 void Populate();
80 void AddButton(Button*);80 void AddButton(Button*);
8181
82 Manager::Ptr manager_;82 Manager::Ptr manager_;
@@ -85,6 +85,7 @@
85 nux::VLayout* main_layout_;85 nux::VLayout* main_layout_;
86 nux::HLayout* buttons_layout_;86 nux::HLayout* buttons_layout_;
87 nux::InputArea* key_focus_area_;87 nux::InputArea* key_focus_area_;
88 glib::Source::UniquePtr cancel_idle_;
88};89};
8990
90} // namespace session91} // namespace session
9192
=== modified file 'shutdown/StandaloneSession.cpp'
--- shutdown/StandaloneSession.cpp 2014-04-10 04:47:58 +0000
+++ shutdown/StandaloneSession.cpp 2014-06-18 15:11:36 +0000
@@ -52,9 +52,11 @@
5252
53 void CancelAction() { std::cout << "CancelAction" << std::endl; }53 void CancelAction() { std::cout << "CancelAction" << std::endl; }
5454
55 bool CanLock() const {return true;}
55 bool CanShutdown() const {return true;}56 bool CanShutdown() const {return true;}
56 bool CanSuspend() const {return true;}57 bool CanSuspend() const {return true;}
57 bool CanHibernate() const {return true;}58 bool CanHibernate() const {return true;}
59 bool HasInhibitors() const {return false;}
58};60};
5961
60struct SessionWindow62struct SessionWindow
6163
=== modified file 'tests/test_mock_session_manager.h'
--- tests/test_mock_session_manager.h 2014-04-10 04:47:58 +0000
+++ tests/test_mock_session_manager.h 2014-06-18 15:11:36 +0000
@@ -44,9 +44,11 @@
44 MOCK_METHOD0(Hibernate, void());44 MOCK_METHOD0(Hibernate, void());
45 MOCK_METHOD0(CancelAction, void());45 MOCK_METHOD0(CancelAction, void());
4646
47 MOCK_CONST_METHOD0(CanLock, bool());
47 MOCK_CONST_METHOD0(CanShutdown, bool());48 MOCK_CONST_METHOD0(CanShutdown, bool());
48 MOCK_CONST_METHOD0(CanSuspend, bool());49 MOCK_CONST_METHOD0(CanSuspend, bool());
49 MOCK_CONST_METHOD0(CanHibernate, bool());50 MOCK_CONST_METHOD0(CanHibernate, bool());
51 MOCK_CONST_METHOD0(HasInhibitors, bool());
50};52};
5153
52} // session54} // session
5355
=== modified file 'tests/test_session_controller.cpp'
--- tests/test_session_controller.cpp 2014-04-30 15:33:43 +0000
+++ tests/test_session_controller.cpp 2014-06-18 15:11:36 +0000
@@ -41,6 +41,7 @@
41 , manager(std::make_shared<testing::NiceMock<MockManager>>())41 , manager(std::make_shared<testing::NiceMock<MockManager>>())
42 , controller(manager)42 , controller(manager)
43 {43 {
44 ON_CALL(*manager, CanLock()).WillByDefault(testing::Return(true));
44 ON_CALL(*manager, CanShutdown()).WillByDefault(testing::Return(true));45 ON_CALL(*manager, CanShutdown()).WillByDefault(testing::Return(true));
45 }46 }
4647
4748
=== modified file 'tests/test_session_view.cpp'
--- tests/test_session_view.cpp 2014-03-21 04:40:12 +0000
+++ tests/test_session_view.cpp 2014-06-18 15:11:36 +0000
@@ -137,6 +137,7 @@
137137
138TEST_F(TestSessionView, FullModeButtons)138TEST_F(TestSessionView, FullModeButtons)
139{139{
140 ON_CALL(*manager, CanLock()).WillByDefault(testing::Return(true));
140 ON_CALL(*manager, CanShutdown()).WillByDefault(testing::Return(true));141 ON_CALL(*manager, CanShutdown()).WillByDefault(testing::Return(true));
141 ON_CALL(*manager, CanSuspend()).WillByDefault(testing::Return(true));142 ON_CALL(*manager, CanSuspend()).WillByDefault(testing::Return(true));
142 ON_CALL(*manager, CanHibernate()).WillByDefault(testing::Return(true));143 ON_CALL(*manager, CanHibernate()).WillByDefault(testing::Return(true));
@@ -166,6 +167,11 @@
166 view.mode.changed.emit(View::Mode::FULL);167 view.mode.changed.emit(View::Mode::FULL);
167168
168 EXPECT_EQ(view.GetButtonByAction(Button::Action::HIBERNATE), nullptr);169 EXPECT_EQ(view.GetButtonByAction(Button::Action::HIBERNATE), nullptr);
170
171 ON_CALL(*manager, CanLock()).WillByDefault(testing::Return(false));
172 view.mode.changed.emit(View::Mode::FULL);
173
174 EXPECT_EQ(view.GetButtonByAction(Button::Action::LOCK), nullptr);
169}175}
170176
171TEST_F(TestSessionView, ShutdownModeButtons)177TEST_F(TestSessionView, ShutdownModeButtons)
@@ -181,6 +187,7 @@
181187
182TEST_F(TestSessionView, LogoutModeButtons)188TEST_F(TestSessionView, LogoutModeButtons)
183{189{
190 ON_CALL(*manager, CanLock()).WillByDefault(testing::Return(true));
184 view.mode = View::Mode::LOGOUT;191 view.mode = View::Mode::LOGOUT;
185192
186 EXPECT_EQ(view.GetButtons().size(), 2);193 EXPECT_EQ(view.GetButtons().size(), 2);
@@ -189,6 +196,16 @@
189 EXPECT_EQ(view.key_focus_area(), view.GetButtonByAction(Button::Action::LOGOUT));196 EXPECT_EQ(view.key_focus_area(), view.GetButtonByAction(Button::Action::LOGOUT));
190}197}
191198
199TEST_F(TestSessionView, LogoutLightModeButtons)
200{
201 ON_CALL(*manager, CanLock()).WillByDefault(testing::Return(false));
202 view.mode = View::Mode::LOGOUT;
203
204 EXPECT_EQ(view.GetButtons().size(), 1);
205 EXPECT_EQ(view.GetButtonPosition(Button::Action::LOGOUT), 0);
206 EXPECT_EQ(view.key_focus_area(), view.GetButtonByAction(Button::Action::LOGOUT));
207}
208
192TEST_F(TestSessionView, FullModeTitle)209TEST_F(TestSessionView, FullModeTitle)
193{210{
194 EXPECT_TRUE(view.GetTitle().empty());211 EXPECT_TRUE(view.GetTitle().empty());
@@ -213,8 +230,9 @@
213{230{
214 bool request_hide = false;231 bool request_hide = false;
215 view.request_hide.connect([&request_hide] { request_hide = true; });232 view.request_hide.connect([&request_hide] { request_hide = true; });
233 view.mode = View::Mode::LOGOUT;
216234
217 auto button = view.GetButtonByAction(Button::Action::LOCK);235 auto button = view.GetButtonByAction(Button::Action::LOGOUT);
218 ASSERT_NE(button, nullptr);236 ASSERT_NE(button, nullptr);
219 button->activated.emit();237 button->activated.emit();
220238
@@ -223,7 +241,8 @@
223241
224TEST_F(TestSessionView, ButtonsActivateDeselectButton)242TEST_F(TestSessionView, ButtonsActivateDeselectButton)
225{243{
226 auto button = view.GetButtonByAction(Button::Action::LOCK);244 view.mode = View::Mode::LOGOUT;
245 auto button = view.GetButtonByAction(Button::Action::LOGOUT);
227 ASSERT_NE(button, nullptr);246 ASSERT_NE(button, nullptr);
228 button->highlighted = true;247 button->highlighted = true;
229 button->activated.emit();248 button->activated.emit();
@@ -233,6 +252,8 @@
233252
234TEST_F(TestSessionView, LockButtonActivateLocks)253TEST_F(TestSessionView, LockButtonActivateLocks)
235{254{
255 ON_CALL(*manager, CanLock()).WillByDefault(testing::Return(true));
256 view.mode = View::Mode::LOGOUT;
236 EXPECT_CALL(*manager, LockScreen());257 EXPECT_CALL(*manager, LockScreen());
237 auto button = view.GetButtonByAction(Button::Action::LOCK);258 auto button = view.GetButtonByAction(Button::Action::LOCK);
238 ASSERT_NE(button, nullptr);259 ASSERT_NE(button, nullptr);