Merge lp:~azzar1/unity/fix-double-lock into lp:unity

Proposed by Andrea Azzarone
Status: Superseded
Proposed branch: lp:~azzar1/unity/fix-double-lock
Merge into: lp:unity
Prerequisite: lp:~azzar1/unity/fix-highdpi-force-quit-dialog
Diff against target: 195 lines (+100/-27)
5 files modified
UnityCore/GnomeSessionManager.cpp (+59/-26)
UnityCore/GnomeSessionManagerImpl.h (+2/-0)
UnityCore/Variant.cpp (+30/-0)
UnityCore/Variant.h (+1/-0)
tests/test_gnome_session_manager.cpp (+8/-1)
To merge this branch: bzr merge lp:~azzar1/unity/fix-double-lock
Reviewer Review Type Date Requested Status
Unity Team Pending
Review via email: mp+309859@code.launchpad.net

This proposal supersedes a proposal from 2016-11-02.

Commit message

Retrieve the session id using dbus if env variable XDG_SESSION_ID is not available.

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
=== modified file 'UnityCore/GnomeSessionManager.cpp'
--- UnityCore/GnomeSessionManager.cpp 2016-09-01 17:18:03 +0000
+++ UnityCore/GnomeSessionManager.cpp 2016-11-02 16:39:19 +0000
@@ -101,32 +101,37 @@
101 });101 });
102102
103 {103 {
104 const char* session_id = test_mode_ ? "id0" : g_getenv("XDG_SESSION_ID");104 std::string session_id = test_mode_ ? "id0" : glib::gchar_to_string(g_getenv("XDG_SESSION_ID"));
105105
106 login_proxy_ = std::make_shared<glib::DBusProxy>(test_mode_ ? testing::DBUS_NAME : "org.freedesktop.login1",106 if (!session_id.empty())
107 "/org/freedesktop/login1/session/" + glib::gchar_to_string(session_id),107 {
108 "org.freedesktop.login1.Session",108 CallLogindMethod("GetSession", g_variant_new("(s)", session_id.c_str()), [this, session_id] (GVariant* variant, glib::Error const& err) {
109 test_mode_ ? G_BUS_TYPE_SESSION : G_BUS_TYPE_SYSTEM,109 std::string session_path;
110 G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES);110
111111 if (!err && variant)
112 login_proxy_->Connect("Lock", [this](GVariant*){112 session_path = glib::Variant(variant).GetObjectPath();
113 manager_->PromptLockScreen();113
114 });114 if (session_path.empty())
115115 session_path = "/org/freedesktop/login1/session/" + session_id;
116 login_proxy_->Connect("Unlock", [this](GVariant*){116
117 manager_->unlock_requested.emit();117 SetupLogin1Proxy(session_path);
118 });118 });
119119 }
120 login_proxy_->ConnectProperty("Active", [this] (GVariant* variant) {120 else
121 bool active = glib::Variant(variant).GetBool();121 {
122 manager_->is_session_active.changed.emit(active);122 auto proxy = std::make_shared<glib::DBusProxy>("org.freedesktop.login1",
123 if (active)123 "/org/freedesktop/login1/user/self",
124 manager_->screensaver_requested.emit(false);124 "org.freedesktop.login1.User",
125 });125 G_BUS_TYPE_SYSTEM);
126126
127 manager_->is_session_active.SetGetterFunction([this] {127 proxy->GetProperty("Display", [this, proxy] (GVariant *variant) {
128 return login_proxy_->GetProperty("Active").GetBool();128 if (!variant || g_variant_n_children(variant) < 2)
129 });129 return;
130
131 glib::Variant tmp(g_variant_get_child_value(variant, 1), glib::StealRef());
132 SetupLogin1Proxy(tmp.GetObjectPath());
133 });
134 }
130 }135 }
131136
132 {137 {
@@ -221,6 +226,34 @@
221 ClosedDialog();226 ClosedDialog();
222}227}
223228
229void GnomeManager::Impl::SetupLogin1Proxy(std::string const& session_path)
230{
231 login_proxy_ = std::make_shared<glib::DBusProxy>(test_mode_ ? testing::DBUS_NAME : "org.freedesktop.login1",
232 session_path,
233 "org.freedesktop.login1.Session",
234 test_mode_ ? G_BUS_TYPE_SESSION : G_BUS_TYPE_SYSTEM,
235 G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES);
236
237 login_proxy_->Connect("Lock", [this](GVariant*){
238 manager_->PromptLockScreen();
239 });
240
241 login_proxy_->Connect("Unlock", [this](GVariant*){
242 manager_->unlock_requested.emit();
243 });
244
245 login_proxy_->ConnectProperty("Active", [this] (GVariant* variant) {
246 bool active = glib::Variant(variant).GetBool();
247 manager_->is_session_active.changed.emit(active);
248 if (active)
249 manager_->screensaver_requested.emit(false);
250 });
251
252 manager_->is_session_active.SetGetterFunction([this] {
253 return login_proxy_->GetProperty("Active").GetBool();
254 });
255}
256
224bool GnomeManager::Impl::InteractiveMode()257bool GnomeManager::Impl::InteractiveMode()
225{258{
226 bool schema_found = false;259 bool schema_found = false;
227260
=== modified file 'UnityCore/GnomeSessionManagerImpl.h'
--- UnityCore/GnomeSessionManagerImpl.h 2015-12-03 05:57:00 +0000
+++ UnityCore/GnomeSessionManagerImpl.h 2016-11-02 16:39:19 +0000
@@ -46,6 +46,8 @@
46 Impl(GnomeManager* parent, bool test_mode = false);46 Impl(GnomeManager* parent, bool test_mode = false);
47 ~Impl();47 ~Impl();
4848
49 void SetupLogin1Proxy(std::string const& session_path);
50
49 void ConfirmLogout();51 void ConfirmLogout();
50 void ConfirmReboot();52 void ConfirmReboot();
51 void ConfirmShutdown();53 void ConfirmShutdown();
5254
=== modified file 'UnityCore/Variant.cpp'
--- UnityCore/Variant.cpp 2013-11-19 20:28:13 +0000
+++ UnityCore/Variant.cpp 2016-11-02 16:39:19 +0000
@@ -174,6 +174,36 @@
174 return result ? result : "";174 return result ? result : "";
175}175}
176176
177std::string Variant::GetObjectPath() const
178{
179 const gchar *result = nullptr;
180
181 if (!variant_)
182 return "";
183
184 if (g_variant_is_of_type(variant_, G_VARIANT_TYPE_OBJECT_PATH))
185 {
186 // g_variant_get_string doesn't duplicate the string
187 result = g_variant_get_string(variant_, nullptr);
188 }
189 else if (g_variant_is_of_type(variant_, G_VARIANT_TYPE("(o)")))
190 {
191 // As we're using the '&' prefix we don't need to free the string!
192 g_variant_get(variant_, "(&o)", &result);
193 }
194 else
195 {
196 auto const& variant = get_variant(variant_);
197 if (variant)
198 return variant.GetObjectPath();
199
200 LOG_ERROR(logger) << "You're trying to extract a 'o' from a variant which is of type '"
201 << g_variant_type_peek_string(g_variant_get_type(variant_)) << "'";
202 }
203
204 return result ? result : "";
205}
206
177template <typename TYPE, typename GTYPE>207template <typename TYPE, typename GTYPE>
178TYPE get_numeric_value(GVariant *variant_, const char *type_str, const char *fallback_type_str)208TYPE get_numeric_value(GVariant *variant_, const char *type_str, const char *fallback_type_str)
179{209{
180210
=== modified file 'UnityCore/Variant.h'
--- UnityCore/Variant.h 2013-11-19 20:28:13 +0000
+++ UnityCore/Variant.h 2016-11-02 16:39:19 +0000
@@ -68,6 +68,7 @@
68 ~Variant();68 ~Variant();
6969
70 std::string GetString() const;70 std::string GetString() const;
71 std::string GetObjectPath() const;
71 unsigned char GetByte() const;72 unsigned char GetByte() const;
72 int16_t GetInt16() const;73 int16_t GetInt16() const;
73 uint16_t GetUInt16() const;74 uint16_t GetUInt16() const;
7475
=== modified file 'tests/test_gnome_session_manager.cpp'
--- tests/test_gnome_session_manager.cpp 2016-05-17 02:14:33 +0000
+++ tests/test_gnome_session_manager.cpp 2016-11-02 16:39:19 +0000
@@ -70,6 +70,9 @@
70const std::string LOGIND_MANAGER =70const std::string LOGIND_MANAGER =
71R"(<node>71R"(<node>
72 <interface name="org.freedesktop.login1.Manager">72 <interface name="org.freedesktop.login1.Manager">
73 <method name="GetSession">
74 <arg type="s" name="result" direction="out"/>
75 </method>
73 <method name="CanSuspend">76 <method name="CanSuspend">
74 <arg type="s" name="result" direction="out"/>77 <arg type="s" name="result" direction="out"/>
75 </method>78 </method>
@@ -186,7 +189,11 @@
186 logind_->AddObjects(introspection::LOGIND_MANAGER, LOGIND_MANAGER_PATH);189 logind_->AddObjects(introspection::LOGIND_MANAGER, LOGIND_MANAGER_PATH);
187 logind_->AddObjects(introspection::LOGIND_SESSION, LOGIND_SESSION_PATH);190 logind_->AddObjects(introspection::LOGIND_SESSION, LOGIND_SESSION_PATH);
188 logind_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant*) -> GVariant* {191 logind_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant*) -> GVariant* {
189 if (method == "CanSuspend")192 if (method == "GetSession")
193 {
194 return g_variant_new("(o)", "id0");
195 }
196 else if (method == "CanSuspend")
190 {197 {
191 suspend_called = true;198 suspend_called = true;
192 return g_variant_new("(s)", can_suspend_ ? "yes" : "no");199 return g_variant_new("(s)", can_suspend_ ? "yes" : "no");