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
=== modified file 'UnityCore/DesktopUtilities.cpp'
--- UnityCore/DesktopUtilities.cpp 2012-11-06 18:19:09 +0000
+++ UnityCore/DesktopUtilities.cpp 2014-04-16 22:18:11 +0000
@@ -23,12 +23,17 @@
2323
24#include <glib.h>24#include <glib.h>
25#include <gio/gdesktopappinfo.h>25#include <gio/gdesktopappinfo.h>
26#include <NuxCore/Logger.h>
2627
27#include "DesktopUtilities.h"28#include "DesktopUtilities.h"
28#include "GLibWrapper.h"29#include "GLibWrapper.h"
2930
30namespace unity31namespace unity
31{32{
33namespace
34{
35DECLARE_LOGGER(logger, "unity.desktop.utilities");
36}
3237
33std::string DesktopUtilities::GetUserDataDirectory()38std::string DesktopUtilities::GetUserDataDirectory()
34{39{
@@ -49,6 +54,30 @@
49 return "";54 return "";
50}55}
5156
57std::string DesktopUtilities::GetUserCacheDirectory()
58{
59 const char *cache_dir = g_get_user_cache_dir();
60 auto unity_cache = glib::gchar_to_string(cache_dir).append(G_DIR_SEPARATOR_S "unity" G_DIR_SEPARATOR_S);
61
62 if (g_mkdir_with_parents(unity_cache.c_str(), 0700) >= 0)
63 return unity_cache;
64
65 LOG_ERROR(logger) << "Impossible to create unity cache folder '"<< unity_cache <<"' !";
66 return "";
67}
68
69std::string DesktopUtilities::GetUserRuntimeDirectory()
70{
71 const char *runtime_dir = g_get_user_runtime_dir();
72 auto unity_runtime = glib::gchar_to_string(runtime_dir).append(G_DIR_SEPARATOR_S "unity" G_DIR_SEPARATOR_S);
73
74 if (g_mkdir_with_parents(unity_runtime.c_str(), 0700) >= 0)
75 return unity_runtime;
76
77 LOG_ERROR(logger) << "Impossible to create unity runtime folder '"<< unity_runtime <<"' !";
78 return "";
79}
80
52std::vector<std::string> DesktopUtilities::GetSystemDataDirectories()81std::vector<std::string> DesktopUtilities::GetSystemDataDirectories()
53{82{
54 const char* const* system_dirs = g_get_system_data_dirs();83 const char* const* system_dirs = g_get_system_data_dirs();
5584
=== modified file 'UnityCore/DesktopUtilities.h'
--- UnityCore/DesktopUtilities.h 2012-09-07 14:32:44 +0000
+++ UnityCore/DesktopUtilities.h 2014-04-16 22:18:11 +0000
@@ -30,6 +30,8 @@
30{30{
31public:31public:
32 static std::string GetUserDataDirectory();32 static std::string GetUserDataDirectory();
33 static std::string GetUserCacheDirectory();
34 static std::string GetUserRuntimeDirectory();
33 static std::vector<std::string> GetSystemDataDirectories();35 static std::vector<std::string> GetSystemDataDirectories();
34 static std::vector<std::string> GetDataDirectories();36 static std::vector<std::string> GetDataDirectories();
3537
3638
=== modified file 'plugins/unityshell/src/unityshell.cpp'
--- plugins/unityshell/src/unityshell.cpp 2014-04-14 14:21:46 +0000
+++ plugins/unityshell/src/unityshell.cpp 2014-04-16 22:18:11 +0000
@@ -1,6 +1,6 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/* Compiz unity plugin2/* Compiz unity plugin
3 * unity.cpp 3 * unityshell.cpp
4 *4 *
5 * Copyright (c) 2010-11 Canonical Ltd.5 * Copyright (c) 2010-11 Canonical Ltd.
6 *6 *
@@ -26,6 +26,7 @@
26#include <Nux/WindowCompositor.h>26#include <Nux/WindowCompositor.h>
2727
28#include <UnityCore/DBusIndicators.h>28#include <UnityCore/DBusIndicators.h>
29#include <UnityCore/DesktopUtilities.h>
29#include <UnityCore/GnomeSessionManager.h>30#include <UnityCore/GnomeSessionManager.h>
30#include <UnityCore/ScopeProxyInterface.h>31#include <UnityCore/ScopeProxyInterface.h>
3132
@@ -58,6 +59,7 @@
58#include "decorations/DecorationsManager.h"59#include "decorations/DecorationsManager.h"
5960
60#include <glib/gi18n-lib.h>61#include <glib/gi18n-lib.h>
62#include <glib/gstdio.h>
61#include <gtk/gtk.h>63#include <gtk/gtk.h>
62#include <gdk/gdk.h>64#include <gdk/gdk.h>
63#include <gdk/gdkx.h>65#include <gdk/gdkx.h>
@@ -142,6 +144,7 @@
142const RawPixel SCALE_SPACING = 20_em;144const RawPixel SCALE_SPACING = 20_em;
143const std::string RELAYOUT_TIMEOUT = "relayout-timeout";145const std::string RELAYOUT_TIMEOUT = "relayout-timeout";
144const std::string FIRST_RUN_STAMP = "first_run.stamp";146const std::string FIRST_RUN_STAMP = "first_run.stamp";
147const std::string LOCKED_STAMP = "locked.stamp";
145} // namespace local148} // namespace local
146} // anon namespace149} // anon namespace
147150
@@ -466,6 +469,7 @@
466 unity_a11y_finalize();469 unity_a11y_finalize();
467 QuicklistManager::Destroy();470 QuicklistManager::Destroy();
468 decoration::DataPool::Reset();471 decoration::DataPool::Reset();
472 SaveLockStamp(false);
469473
470 reset_glib_logging();474 reset_glib_logging();
471}475}
@@ -3727,7 +3731,7 @@
3727 RaiseOSK();3731 RaiseOSK();
3728}3732}
37293733
3730void UnityScreen::LockscreenRequested()3734void UnityScreen::OnLockScreenRequested()
3731{3735{
3732 if (switcher_controller_->Visible())3736 if (switcher_controller_->Visible())
3733 {3737 {
@@ -3748,6 +3752,32 @@
3748 RaiseOSK();3752 RaiseOSK();
3749}3753}
37503754
3755void UnityScreen::SaveLockStamp(bool save)
3756{
3757 auto const& cache_dir = DesktopUtilities::GetUserRuntimeDirectory();
3758
3759 if (cache_dir.empty())
3760 return;
3761
3762 if (save)
3763 {
3764 glib::Error error;
3765 g_file_set_contents((cache_dir+local::LOCKED_STAMP).c_str(), "", 0, &error);
3766
3767 if (error)
3768 {
3769 LOG_ERROR(logger) << "Impossible to save the unity locked stamp file: " << error;
3770 }
3771 }
3772 else
3773 {
3774 if (g_unlink((cache_dir+local::LOCKED_STAMP).c_str()) < 0)
3775 {
3776 LOG_ERROR(logger) << "Impossible to delete the unity locked stamp file";
3777 }
3778 }
3779}
3780
3751void UnityScreen::RaiseOSK()3781void UnityScreen::RaiseOSK()
3752{3782{
3753 /* stack any windows named "onboard" above us */3783 /* stack any windows named "onboard" above us */
@@ -3813,7 +3843,9 @@
38133843
3814 // Setup Session Controller3844 // Setup Session Controller
3815 auto manager = std::make_shared<session::GnomeManager>();3845 auto manager = std::make_shared<session::GnomeManager>();
3816 manager->lock_requested.connect(sigc::mem_fun(this, &UnityScreen::LockscreenRequested));3846 manager->lock_requested.connect(sigc::mem_fun(this, &UnityScreen::OnLockScreenRequested));
3847 manager->locked.connect(sigc::bind(sigc::mem_fun(this, &UnityScreen::SaveLockStamp), true));
3848 manager->unlocked.connect(sigc::bind(sigc::mem_fun(this, &UnityScreen::SaveLockStamp), false));
3817 session_dbus_manager_ = std::make_shared<session::DBusManager>(manager);3849 session_dbus_manager_ = std::make_shared<session::DBusManager>(manager);
3818 session_controller_ = std::make_shared<session::Controller>(manager);3850 session_controller_ = std::make_shared<session::Controller>(manager);
3819 AddChild(session_controller_.get());3851 AddChild(session_controller_.get());
@@ -3823,6 +3855,9 @@
3823 lockscreen_controller_ = std::make_shared<lockscreen::Controller>(screensaver_dbus_manager_, manager);3855 lockscreen_controller_ = std::make_shared<lockscreen::Controller>(screensaver_dbus_manager_, manager);
3824 UpdateActivateIndicatorsKey();3856 UpdateActivateIndicatorsKey();
38253857
3858 if (g_file_test((DesktopUtilities::GetUserRuntimeDirectory()+local::LOCKED_STAMP).c_str(), G_FILE_TEST_EXISTS))
3859 manager->PromptLockScreen();
3860
3826 auto on_launcher_size_changed = [this] (nux::Area* area, int w, int h) {3861 auto on_launcher_size_changed = [this] (nux::Area* area, int w, int h) {
3827 /* The launcher geometry includes 1px used to draw the right margin3862 /* The launcher geometry includes 1px used to draw the right margin
3828 * that must not be considered when drawing an overlay */3863 * that must not be considered when drawing an overlay */
@@ -3907,8 +3942,8 @@
3907void UnityScreen::ShowFirstRunHints()3942void UnityScreen::ShowFirstRunHints()
3908{3943{
3909 sources_.AddTimeoutSeconds(1, [this] {3944 sources_.AddTimeoutSeconds(1, [this] {
3910 auto const& cache_dir = glib::gchar_to_string(g_get_user_cache_dir())+"/unity/";3945 auto const& cache_dir = DesktopUtilities::GetUserCacheDirectory();
3911 if (!g_file_test((cache_dir+local::FIRST_RUN_STAMP).c_str(), G_FILE_TEST_EXISTS))3946 if (!cache_dir.empty() && !g_file_test((cache_dir+local::FIRST_RUN_STAMP).c_str(), G_FILE_TEST_EXISTS))
3912 {3947 {
3913 // We focus the panel, so the shortcut hint will be hidden at first user input3948 // We focus the panel, so the shortcut hint will be hidden at first user input
3914 auto const& panels = panel_controller_->panels();3949 auto const& panels = panel_controller_->panels();
@@ -3920,19 +3955,12 @@
3920 shortcut_controller_->first_run = true;3955 shortcut_controller_->first_run = true;
3921 shortcut_controller_->Show();3956 shortcut_controller_->Show();
39223957
3923 if (g_mkdir_with_parents(cache_dir.c_str(), 0700) >= 0)3958 glib::Error error;
3924 {3959 g_file_set_contents((cache_dir+local::FIRST_RUN_STAMP).c_str(), "", 0, &error);
3925 glib::Error error;
3926 g_file_set_contents((cache_dir+local::FIRST_RUN_STAMP).c_str(), "", 0, &error);
39273960
3928 if (error)3961 if (error)
3929 {
3930 LOG_ERROR(logger) << "Impossible to save the unity stamp file: " << error;
3931 }
3932 }
3933 else
3934 {3962 {
3935 LOG_ERROR(logger) << "Impossible to create unity cache folder!";3963 LOG_ERROR(logger) << "Impossible to save the unity stamp file: " << error;
3936 }3964 }
3937 }3965 }
3938 return false;3966 return false;
39393967
=== modified file 'plugins/unityshell/src/unityshell.h'
--- plugins/unityshell/src/unityshell.h 2014-04-12 16:26:38 +0000
+++ plugins/unityshell/src/unityshell.h 2014-04-16 22:18:11 +0000
@@ -232,7 +232,8 @@
232232
233 void OnMinimizeDurationChanged();233 void OnMinimizeDurationChanged();
234234
235 void LockscreenRequested();235 void OnLockScreenRequested();
236 void SaveLockStamp(bool);
236237
237 switcher::Controller::Ptr switcher_controller();238 switcher::Controller::Ptr switcher_controller();
238 launcher::Controller::Ptr launcher_controller();239 launcher::Controller::Ptr launcher_controller();