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
1=== modified file 'UnityCore/GnomeSessionManager.cpp'
2--- UnityCore/GnomeSessionManager.cpp 2016-09-01 17:18:03 +0000
3+++ UnityCore/GnomeSessionManager.cpp 2016-11-02 16:39:19 +0000
4@@ -101,32 +101,37 @@
5 });
6
7 {
8- const char* session_id = test_mode_ ? "id0" : g_getenv("XDG_SESSION_ID");
9-
10- login_proxy_ = std::make_shared<glib::DBusProxy>(test_mode_ ? testing::DBUS_NAME : "org.freedesktop.login1",
11- "/org/freedesktop/login1/session/" + glib::gchar_to_string(session_id),
12- "org.freedesktop.login1.Session",
13- test_mode_ ? G_BUS_TYPE_SESSION : G_BUS_TYPE_SYSTEM,
14- G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES);
15-
16- login_proxy_->Connect("Lock", [this](GVariant*){
17- manager_->PromptLockScreen();
18- });
19-
20- login_proxy_->Connect("Unlock", [this](GVariant*){
21- manager_->unlock_requested.emit();
22- });
23-
24- login_proxy_->ConnectProperty("Active", [this] (GVariant* variant) {
25- bool active = glib::Variant(variant).GetBool();
26- manager_->is_session_active.changed.emit(active);
27- if (active)
28- manager_->screensaver_requested.emit(false);
29- });
30-
31- manager_->is_session_active.SetGetterFunction([this] {
32- return login_proxy_->GetProperty("Active").GetBool();
33- });
34+ std::string session_id = test_mode_ ? "id0" : glib::gchar_to_string(g_getenv("XDG_SESSION_ID"));
35+
36+ if (!session_id.empty())
37+ {
38+ CallLogindMethod("GetSession", g_variant_new("(s)", session_id.c_str()), [this, session_id] (GVariant* variant, glib::Error const& err) {
39+ std::string session_path;
40+
41+ if (!err && variant)
42+ session_path = glib::Variant(variant).GetObjectPath();
43+
44+ if (session_path.empty())
45+ session_path = "/org/freedesktop/login1/session/" + session_id;
46+
47+ SetupLogin1Proxy(session_path);
48+ });
49+ }
50+ else
51+ {
52+ auto proxy = std::make_shared<glib::DBusProxy>("org.freedesktop.login1",
53+ "/org/freedesktop/login1/user/self",
54+ "org.freedesktop.login1.User",
55+ G_BUS_TYPE_SYSTEM);
56+
57+ proxy->GetProperty("Display", [this, proxy] (GVariant *variant) {
58+ if (!variant || g_variant_n_children(variant) < 2)
59+ return;
60+
61+ glib::Variant tmp(g_variant_get_child_value(variant, 1), glib::StealRef());
62+ SetupLogin1Proxy(tmp.GetObjectPath());
63+ });
64+ }
65 }
66
67 {
68@@ -221,6 +226,34 @@
69 ClosedDialog();
70 }
71
72+void GnomeManager::Impl::SetupLogin1Proxy(std::string const& session_path)
73+{
74+ login_proxy_ = std::make_shared<glib::DBusProxy>(test_mode_ ? testing::DBUS_NAME : "org.freedesktop.login1",
75+ session_path,
76+ "org.freedesktop.login1.Session",
77+ test_mode_ ? G_BUS_TYPE_SESSION : G_BUS_TYPE_SYSTEM,
78+ G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES);
79+
80+ login_proxy_->Connect("Lock", [this](GVariant*){
81+ manager_->PromptLockScreen();
82+ });
83+
84+ login_proxy_->Connect("Unlock", [this](GVariant*){
85+ manager_->unlock_requested.emit();
86+ });
87+
88+ login_proxy_->ConnectProperty("Active", [this] (GVariant* variant) {
89+ bool active = glib::Variant(variant).GetBool();
90+ manager_->is_session_active.changed.emit(active);
91+ if (active)
92+ manager_->screensaver_requested.emit(false);
93+ });
94+
95+ manager_->is_session_active.SetGetterFunction([this] {
96+ return login_proxy_->GetProperty("Active").GetBool();
97+ });
98+}
99+
100 bool GnomeManager::Impl::InteractiveMode()
101 {
102 bool schema_found = false;
103
104=== modified file 'UnityCore/GnomeSessionManagerImpl.h'
105--- UnityCore/GnomeSessionManagerImpl.h 2015-12-03 05:57:00 +0000
106+++ UnityCore/GnomeSessionManagerImpl.h 2016-11-02 16:39:19 +0000
107@@ -46,6 +46,8 @@
108 Impl(GnomeManager* parent, bool test_mode = false);
109 ~Impl();
110
111+ void SetupLogin1Proxy(std::string const& session_path);
112+
113 void ConfirmLogout();
114 void ConfirmReboot();
115 void ConfirmShutdown();
116
117=== modified file 'UnityCore/Variant.cpp'
118--- UnityCore/Variant.cpp 2013-11-19 20:28:13 +0000
119+++ UnityCore/Variant.cpp 2016-11-02 16:39:19 +0000
120@@ -174,6 +174,36 @@
121 return result ? result : "";
122 }
123
124+std::string Variant::GetObjectPath() const
125+{
126+ const gchar *result = nullptr;
127+
128+ if (!variant_)
129+ return "";
130+
131+ if (g_variant_is_of_type(variant_, G_VARIANT_TYPE_OBJECT_PATH))
132+ {
133+ // g_variant_get_string doesn't duplicate the string
134+ result = g_variant_get_string(variant_, nullptr);
135+ }
136+ else if (g_variant_is_of_type(variant_, G_VARIANT_TYPE("(o)")))
137+ {
138+ // As we're using the '&' prefix we don't need to free the string!
139+ g_variant_get(variant_, "(&o)", &result);
140+ }
141+ else
142+ {
143+ auto const& variant = get_variant(variant_);
144+ if (variant)
145+ return variant.GetObjectPath();
146+
147+ LOG_ERROR(logger) << "You're trying to extract a 'o' from a variant which is of type '"
148+ << g_variant_type_peek_string(g_variant_get_type(variant_)) << "'";
149+ }
150+
151+ return result ? result : "";
152+}
153+
154 template <typename TYPE, typename GTYPE>
155 TYPE get_numeric_value(GVariant *variant_, const char *type_str, const char *fallback_type_str)
156 {
157
158=== modified file 'UnityCore/Variant.h'
159--- UnityCore/Variant.h 2013-11-19 20:28:13 +0000
160+++ UnityCore/Variant.h 2016-11-02 16:39:19 +0000
161@@ -68,6 +68,7 @@
162 ~Variant();
163
164 std::string GetString() const;
165+ std::string GetObjectPath() const;
166 unsigned char GetByte() const;
167 int16_t GetInt16() const;
168 uint16_t GetUInt16() const;
169
170=== modified file 'tests/test_gnome_session_manager.cpp'
171--- tests/test_gnome_session_manager.cpp 2016-05-17 02:14:33 +0000
172+++ tests/test_gnome_session_manager.cpp 2016-11-02 16:39:19 +0000
173@@ -70,6 +70,9 @@
174 const std::string LOGIND_MANAGER =
175 R"(<node>
176 <interface name="org.freedesktop.login1.Manager">
177+ <method name="GetSession">
178+ <arg type="s" name="result" direction="out"/>
179+ </method>
180 <method name="CanSuspend">
181 <arg type="s" name="result" direction="out"/>
182 </method>
183@@ -186,7 +189,11 @@
184 logind_->AddObjects(introspection::LOGIND_MANAGER, LOGIND_MANAGER_PATH);
185 logind_->AddObjects(introspection::LOGIND_SESSION, LOGIND_SESSION_PATH);
186 logind_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant*) -> GVariant* {
187- if (method == "CanSuspend")
188+ if (method == "GetSession")
189+ {
190+ return g_variant_new("(o)", "id0");
191+ }
192+ else if (method == "CanSuspend")
193 {
194 suspend_called = true;
195 return g_variant_new("(s)", can_suspend_ ? "yes" : "no");