Merge lp:~3v1n0/unity/relocks-on-crashes into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Brandon Schaefer
Approved revision: no longer in the source branch.
Merged at revision: 3786
Proposed branch: lp:~3v1n0/unity/relocks-on-crashes
Merge into: lp:unity
Diff against target: 221 lines (+77/-17)
4 files modified
UnityCore/DesktopUtilities.cpp (+29/-0)
UnityCore/DesktopUtilities.h (+2/-0)
plugins/unityshell/src/unityshell.cpp (+44/-16)
plugins/unityshell/src/unityshell.h (+2/-1)
To merge this branch: bzr merge lp:~3v1n0/unity/relocks-on-crashes
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Brandon Schaefer (community) Approve
Review via email: mp+216221@code.launchpad.net

Commit message

UnityScreen: save a locked.stamp file when locking/unlocking, to relock on startup

This makes unity to relocks if it was locked before crashing...

To post a comment you must log in.
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Sweeet. Confirmed fixes the issue, and no double lock on a reboot!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Robert Ancell (robert-ancell) wrote :

Given the late arrival of this branch I would prefer if the patch only contained the minimum number of changes required. This fixes up some existing code as well.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'UnityCore/DesktopUtilities.cpp'
2--- UnityCore/DesktopUtilities.cpp 2012-11-06 18:19:09 +0000
3+++ UnityCore/DesktopUtilities.cpp 2014-04-16 22:18:11 +0000
4@@ -23,12 +23,17 @@
5
6 #include <glib.h>
7 #include <gio/gdesktopappinfo.h>
8+#include <NuxCore/Logger.h>
9
10 #include "DesktopUtilities.h"
11 #include "GLibWrapper.h"
12
13 namespace unity
14 {
15+namespace
16+{
17+DECLARE_LOGGER(logger, "unity.desktop.utilities");
18+}
19
20 std::string DesktopUtilities::GetUserDataDirectory()
21 {
22@@ -49,6 +54,30 @@
23 return "";
24 }
25
26+std::string DesktopUtilities::GetUserCacheDirectory()
27+{
28+ const char *cache_dir = g_get_user_cache_dir();
29+ auto unity_cache = glib::gchar_to_string(cache_dir).append(G_DIR_SEPARATOR_S "unity" G_DIR_SEPARATOR_S);
30+
31+ if (g_mkdir_with_parents(unity_cache.c_str(), 0700) >= 0)
32+ return unity_cache;
33+
34+ LOG_ERROR(logger) << "Impossible to create unity cache folder '"<< unity_cache <<"' !";
35+ return "";
36+}
37+
38+std::string DesktopUtilities::GetUserRuntimeDirectory()
39+{
40+ const char *runtime_dir = g_get_user_runtime_dir();
41+ auto unity_runtime = glib::gchar_to_string(runtime_dir).append(G_DIR_SEPARATOR_S "unity" G_DIR_SEPARATOR_S);
42+
43+ if (g_mkdir_with_parents(unity_runtime.c_str(), 0700) >= 0)
44+ return unity_runtime;
45+
46+ LOG_ERROR(logger) << "Impossible to create unity runtime folder '"<< unity_runtime <<"' !";
47+ return "";
48+}
49+
50 std::vector<std::string> DesktopUtilities::GetSystemDataDirectories()
51 {
52 const char* const* system_dirs = g_get_system_data_dirs();
53
54=== modified file 'UnityCore/DesktopUtilities.h'
55--- UnityCore/DesktopUtilities.h 2012-09-07 14:32:44 +0000
56+++ UnityCore/DesktopUtilities.h 2014-04-16 22:18:11 +0000
57@@ -30,6 +30,8 @@
58 {
59 public:
60 static std::string GetUserDataDirectory();
61+ static std::string GetUserCacheDirectory();
62+ static std::string GetUserRuntimeDirectory();
63 static std::vector<std::string> GetSystemDataDirectories();
64 static std::vector<std::string> GetDataDirectories();
65
66
67=== modified file 'plugins/unityshell/src/unityshell.cpp'
68--- plugins/unityshell/src/unityshell.cpp 2014-04-14 14:21:46 +0000
69+++ plugins/unityshell/src/unityshell.cpp 2014-04-16 22:18:11 +0000
70@@ -1,6 +1,6 @@
71 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
72 /* Compiz unity plugin
73- * unity.cpp
74+ * unityshell.cpp
75 *
76 * Copyright (c) 2010-11 Canonical Ltd.
77 *
78@@ -26,6 +26,7 @@
79 #include <Nux/WindowCompositor.h>
80
81 #include <UnityCore/DBusIndicators.h>
82+#include <UnityCore/DesktopUtilities.h>
83 #include <UnityCore/GnomeSessionManager.h>
84 #include <UnityCore/ScopeProxyInterface.h>
85
86@@ -58,6 +59,7 @@
87 #include "decorations/DecorationsManager.h"
88
89 #include <glib/gi18n-lib.h>
90+#include <glib/gstdio.h>
91 #include <gtk/gtk.h>
92 #include <gdk/gdk.h>
93 #include <gdk/gdkx.h>
94@@ -142,6 +144,7 @@
95 const RawPixel SCALE_SPACING = 20_em;
96 const std::string RELAYOUT_TIMEOUT = "relayout-timeout";
97 const std::string FIRST_RUN_STAMP = "first_run.stamp";
98+const std::string LOCKED_STAMP = "locked.stamp";
99 } // namespace local
100 } // anon namespace
101
102@@ -466,6 +469,7 @@
103 unity_a11y_finalize();
104 QuicklistManager::Destroy();
105 decoration::DataPool::Reset();
106+ SaveLockStamp(false);
107
108 reset_glib_logging();
109 }
110@@ -3727,7 +3731,7 @@
111 RaiseOSK();
112 }
113
114-void UnityScreen::LockscreenRequested()
115+void UnityScreen::OnLockScreenRequested()
116 {
117 if (switcher_controller_->Visible())
118 {
119@@ -3748,6 +3752,32 @@
120 RaiseOSK();
121 }
122
123+void UnityScreen::SaveLockStamp(bool save)
124+{
125+ auto const& cache_dir = DesktopUtilities::GetUserRuntimeDirectory();
126+
127+ if (cache_dir.empty())
128+ return;
129+
130+ if (save)
131+ {
132+ glib::Error error;
133+ g_file_set_contents((cache_dir+local::LOCKED_STAMP).c_str(), "", 0, &error);
134+
135+ if (error)
136+ {
137+ LOG_ERROR(logger) << "Impossible to save the unity locked stamp file: " << error;
138+ }
139+ }
140+ else
141+ {
142+ if (g_unlink((cache_dir+local::LOCKED_STAMP).c_str()) < 0)
143+ {
144+ LOG_ERROR(logger) << "Impossible to delete the unity locked stamp file";
145+ }
146+ }
147+}
148+
149 void UnityScreen::RaiseOSK()
150 {
151 /* stack any windows named "onboard" above us */
152@@ -3813,7 +3843,9 @@
153
154 // Setup Session Controller
155 auto manager = std::make_shared<session::GnomeManager>();
156- manager->lock_requested.connect(sigc::mem_fun(this, &UnityScreen::LockscreenRequested));
157+ manager->lock_requested.connect(sigc::mem_fun(this, &UnityScreen::OnLockScreenRequested));
158+ manager->locked.connect(sigc::bind(sigc::mem_fun(this, &UnityScreen::SaveLockStamp), true));
159+ manager->unlocked.connect(sigc::bind(sigc::mem_fun(this, &UnityScreen::SaveLockStamp), false));
160 session_dbus_manager_ = std::make_shared<session::DBusManager>(manager);
161 session_controller_ = std::make_shared<session::Controller>(manager);
162 AddChild(session_controller_.get());
163@@ -3823,6 +3855,9 @@
164 lockscreen_controller_ = std::make_shared<lockscreen::Controller>(screensaver_dbus_manager_, manager);
165 UpdateActivateIndicatorsKey();
166
167+ if (g_file_test((DesktopUtilities::GetUserRuntimeDirectory()+local::LOCKED_STAMP).c_str(), G_FILE_TEST_EXISTS))
168+ manager->PromptLockScreen();
169+
170 auto on_launcher_size_changed = [this] (nux::Area* area, int w, int h) {
171 /* The launcher geometry includes 1px used to draw the right margin
172 * that must not be considered when drawing an overlay */
173@@ -3907,8 +3942,8 @@
174 void UnityScreen::ShowFirstRunHints()
175 {
176 sources_.AddTimeoutSeconds(1, [this] {
177- auto const& cache_dir = glib::gchar_to_string(g_get_user_cache_dir())+"/unity/";
178- if (!g_file_test((cache_dir+local::FIRST_RUN_STAMP).c_str(), G_FILE_TEST_EXISTS))
179+ auto const& cache_dir = DesktopUtilities::GetUserCacheDirectory();
180+ if (!cache_dir.empty() && !g_file_test((cache_dir+local::FIRST_RUN_STAMP).c_str(), G_FILE_TEST_EXISTS))
181 {
182 // We focus the panel, so the shortcut hint will be hidden at first user input
183 auto const& panels = panel_controller_->panels();
184@@ -3920,19 +3955,12 @@
185 shortcut_controller_->first_run = true;
186 shortcut_controller_->Show();
187
188- if (g_mkdir_with_parents(cache_dir.c_str(), 0700) >= 0)
189- {
190- glib::Error error;
191- g_file_set_contents((cache_dir+local::FIRST_RUN_STAMP).c_str(), "", 0, &error);
192+ glib::Error error;
193+ g_file_set_contents((cache_dir+local::FIRST_RUN_STAMP).c_str(), "", 0, &error);
194
195- if (error)
196- {
197- LOG_ERROR(logger) << "Impossible to save the unity stamp file: " << error;
198- }
199- }
200- else
201+ if (error)
202 {
203- LOG_ERROR(logger) << "Impossible to create unity cache folder!";
204+ LOG_ERROR(logger) << "Impossible to save the unity stamp file: " << error;
205 }
206 }
207 return false;
208
209=== modified file 'plugins/unityshell/src/unityshell.h'
210--- plugins/unityshell/src/unityshell.h 2014-04-12 16:26:38 +0000
211+++ plugins/unityshell/src/unityshell.h 2014-04-16 22:18:11 +0000
212@@ -232,7 +232,8 @@
213
214 void OnMinimizeDurationChanged();
215
216- void LockscreenRequested();
217+ void OnLockScreenRequested();
218+ void SaveLockStamp(bool);
219
220 switcher::Controller::Ptr switcher_controller();
221 launcher::Controller::Ptr launcher_controller();