summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMavridis Philippe <mavridisf@gmail.com>2024-06-09 22:04:25 +0300
committerMavridis Philippe <mavridisf@gmail.com>2024-08-01 13:00:28 +0300
commitd88718ee027e329565d2d97c5cadde4aa1b83166 (patch)
treea4a471e94c5afcf4d5540961c94df707a707bd24
parent352d2ee3da00e402c4d362ab90a031df76d617ad (diff)
downloadtdebase-d88718ee027e329565d2d97c5cadde4aa1b83166.tar.gz
tdebase-d88718ee027e329565d2d97c5cadde4aa1b83166.zip
KSMServer: improve suspend code
1. Some code deduplication. Suspending is now handled via the public method `suspend(int)` which is DCOP-accessible and maps SuspendType values to corresponding TDEHWLib TDESystemPowerState values, and the internal method `suspendInternal(int)` which performs the chosen suspend and optionally locks the screen beforehand. 2. Options are now read from power-managerrc on startup and stored in memory to avoid reading the configuration file every time a suspend is requested. 3. SuspendType is now a member of KSMServer class (instead of KSMShutdownDlg) 4. A new DCOP-accessible method `suspendOptions()` returns a TQStringList of all available suspend options. Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
-rw-r--r--ksmserver/KSMServerInterface.h9
-rw-r--r--ksmserver/server.cpp35
-rw-r--r--ksmserver/server.h26
-rw-r--r--ksmserver/shutdown.cpp96
-rw-r--r--ksmserver/shutdowndlg.cpp6
-rw-r--r--ksmserver/shutdowndlg.h12
6 files changed, 129 insertions, 55 deletions
diff --git a/ksmserver/KSMServerInterface.h b/ksmserver/KSMServerInterface.h
index a628b92ba..3645eb84a 100644
--- a/ksmserver/KSMServerInterface.h
+++ b/ksmserver/KSMServerInterface.h
@@ -10,6 +10,11 @@ class KSMServerInterface : virtual public DCOPObject
k_dcop:
virtual void logout(int, int, int ) = 0;
+ virtual void logoutTimed( int, int, TQString ) = 0;
+ virtual bool suspend(int) = 0;
+
+ virtual TQStringList suspendOptions() = 0;
+
virtual void restoreSessionInternal() = 0;
virtual void restoreSessionDoneInternal() = 0;
virtual TQStringList sessionList() = 0;
@@ -19,11 +24,11 @@ k_dcop:
virtual void saveCurrentSessionAs( TQString ) = 0;
virtual void autoStart2() = 0;
-
+
virtual void suspendStartup( TQCString ) = 0;
virtual void resumeStartup( TQCString ) = 0;
- virtual void logoutTimed( int, int, TQString ) = 0;
+ virtual void reconfigure() = 0;
};
#endif
diff --git a/ksmserver/server.cpp b/ksmserver/server.cpp
index be5ed0bcc..2cfb2e671 100644
--- a/ksmserver/server.cpp
+++ b/ksmserver/server.cpp
@@ -689,6 +689,8 @@ KSMServer::KSMServer( const TQString& windowManager, const TQString& windowManag
connect( &restoreTimer, TQ_SIGNAL( timeout() ), this, TQ_SLOT( tryRestoreNext() ) );
connect( &shutdownTimer, TQ_SIGNAL( timeout() ), this, TQ_SLOT( timeoutQuit() ) );
connect( kapp, TQ_SIGNAL( shutDown() ), this, TQ_SLOT( cleanUp() ) );
+
+ reconfigure();
}
KSMServer::~KSMServer()
@@ -697,6 +699,16 @@ KSMServer::~KSMServer()
cleanUp();
}
+void KSMServer::reconfigure()
+{
+ // respect lock on resume & disable suspend/hibernate settings
+ // from power-manager
+ TDEConfig cfg("power-managerrc");
+ m_disableSuspend = cfg.readBoolEntry("disableSuspend", false);
+ m_disableHibernate = cfg.readBoolEntry("disableHibernate", false);
+ m_lockOnResume = cfg.readBoolEntry("lockOnResume", true);
+}
+
void KSMServer::cleanUp()
{
if (clean) return;
@@ -919,6 +931,27 @@ void KSMServer::storeSession()
config->sync();
}
+TQStringList KSMServer::suspendOptions()
+{
+ TQStringList sopt;
+
+#ifdef WITH_TDEHWLIB
+ TDERootSystemDevice* rootDevice = hwDevices->rootSystemDevice();
+ if (rootDevice->canFreeze() && !m_disableSuspend)
+ sopt << "freeze";
+
+ if (rootDevice->canSuspend() && !m_disableSuspend)
+ sopt << "suspend";
+
+ if (rootDevice->canHibernate() && !m_disableHibernate)
+ sopt << "hibernate";
+
+ if (rootDevice->canHybridSuspend() && !m_disableSuspend && !m_disableHibernate)
+ sopt << "hybridSuspend";
+#endif
+
+ return sopt;
+}
TQStringList KSMServer::sessionList()
{
@@ -995,4 +1028,4 @@ bool KSMServer::defaultSession() const
bool KSMServer::startupCompleted()
{
return m_startupCompleted;
-}
+} \ No newline at end of file
diff --git a/ksmserver/server.h b/ksmserver/server.h
index fdf08cded..511013dc7 100644
--- a/ksmserver/server.h
+++ b/ksmserver/server.h
@@ -37,6 +37,17 @@ class KSMListener;
class KSMConnection;
class KSMClient;
+namespace SuspendType {
+ enum SuspendType {
+ NotSpecified = 0,
+ Freeze,
+ Standby, // not implemented
+ Suspend,
+ Hibernate,
+ HybridSuspend
+ };
+};
+
enum SMType { SM_ERROR, SM_WMCOMMAND, SM_WMSAVEYOURSELF };
struct SMData
{
@@ -103,6 +114,7 @@ public:
public slots:
void cleanUp();
+ void reconfigure();
private slots:
void newConnection( int socket );
@@ -172,6 +184,8 @@ private:
TDEApplication::ShutdownMode sdmode,
TQString bootOption = TQString::null );
+ void suspendInternal(int state);
+
void performLegacySessionSave();
void storeLegacySession( TDEConfig* config );
void restoreLegacySession( TDEConfig* config );
@@ -186,12 +200,14 @@ private:
void resumeStartupInternal();
// public dcop interface
- void logout( int, int, int );
- virtual void logoutTimed( int, int, TQString );
+ void logout(int, int, int);
+ virtual void logoutTimed(int, int, TQString);
+ bool suspend(int);
+ TQStringList suspendOptions();
TQStringList sessionList();
TQString currentSession();
void saveCurrentSession();
- void saveCurrentSessionAs( TQString );
+ void saveCurrentSessionAs(TQString);
TQWidget* startupNotifierIPDlg;
TQWidget* shutdownNotifierIPDlg;
@@ -240,6 +256,10 @@ private:
TDEApplication::ShutdownType pendingShutdown_sdtype;
TDEApplication::ShutdownMode pendingShutdown_sdmode;
+ bool m_disableSuspend;
+ bool m_disableHibernate;
+ bool m_lockOnResume;
+
// ksplash interface
void upAndRunning( const TQString& msg );
void publishProgress( int progress, bool max = false );
diff --git a/ksmserver/shutdown.cpp b/ksmserver/shutdown.cpp
index f62894d72..0b711e53f 100644
--- a/ksmserver/shutdown.cpp
+++ b/ksmserver/shutdown.cpp
@@ -222,45 +222,13 @@ void KSMServer::shutdownInternal( TDEApplication::ShutdownConfirm confirm,
if ( !logoutConfirmed ) {
int selection;
KSMShutdownFeedback::start(); // make the screen gray
- logoutConfirmed =
- KSMShutdownDlg::confirmShutdown( maysd, mayrb, sdtype, bopt, &selection );
+ logoutConfirmed = KSMShutdownDlg::confirmShutdown( maysd, mayrb, sdtype, bopt, &selection );
// ###### We can't make the screen remain gray while talking to the apps,
// because this prevents interaction ("do you want to save", etc.)
// TODO: turn the feedback widget into a list of apps to be closed,
// with an indicator of the current status for each.
KSMShutdownFeedback::stop(); // make the screen become normal again
- if (selection != SuspendType::NotSpecified) {
- // respect lock on resume & disable suspend/hibernate settings
- // from power-manager
- TDEConfig config("power-managerrc");
- bool lockOnResume = config.readBoolEntry("lockOnResume", true);
- if (lockOnResume) {
- TQCString replyType;
- TQByteArray replyData;
- // Block here until lock is complete
- // If this is not done the desktop of the locked session will be shown after suspend/hibernate until the lock fully engages!
- kapp->dcopClient()->call("kdesktop", "KScreensaverIface", "lock()", TQCString(""), replyType, replyData);
- }
-#ifdef WITH_TDEHWLIB
- TDERootSystemDevice* rootDevice = hwDevices->rootSystemDevice();
- if (rootDevice) {
- switch (selection) {
- case SuspendType::Freeze:
- rootDevice->setPowerState(TDESystemPowerState::Freeze);
- break;
- case SuspendType::Suspend:
- rootDevice->setPowerState(TDESystemPowerState::Suspend);
- break;
- case SuspendType::Hibernate:
- rootDevice->setPowerState(TDESystemPowerState::Hibernate);
- break;
- case SuspendType::HybridSuspend:
- rootDevice->setPowerState(TDESystemPowerState::HybridSuspend);
- break;
- }
- }
-#endif
- }
+ suspend(selection);
}
if ( logoutConfirmed ) {
@@ -343,6 +311,66 @@ void KSMServer::shutdown( TDEApplication::ShutdownConfirm confirm,
shutdownInternal( confirm, sdtype, sdmode );
}
+void KSMServer::suspendInternal(int state)
+{
+ if (m_lockOnResume) {
+ TQCString replyType;
+ TQByteArray replyData;
+ // Block here until lock is complete
+ // If this is not done the desktop of the locked session will be shown after suspend/hibernate until the lock fully engages!
+ kapp->dcopClient()->call("kdesktop", "KScreensaverIface", "lock()", TQCString(""), replyType, replyData);
+ }
+
+ TDERootSystemDevice* rootDevice = hwDevices->rootSystemDevice();
+ rootDevice->setPowerState((TDESystemPowerState::TDESystemPowerState)state);
+}
+
+bool KSMServer::suspend(int stype)
+{
+ if (stype == SuspendType::NotSpecified)
+ return false;
+
+#ifdef WITH_TDEHWLIB
+ TDERootSystemDevice* rootDevice = hwDevices->rootSystemDevice();
+ if (rootDevice) {
+ switch (stype) {
+ case SuspendType::Freeze:
+ if (rootDevice->canFreeze() && !m_disableSuspend)
+ {
+ suspendInternal(TDESystemPowerState::Freeze);
+ return true;
+ }
+ break;
+
+ case SuspendType::Suspend:
+ if (rootDevice->canSuspend() && !m_disableSuspend)
+ {
+ suspendInternal(TDESystemPowerState::Suspend);
+ return true;
+ }
+ break;
+
+ case SuspendType::Hibernate:
+ if (rootDevice->canHibernate() && !m_disableHibernate)
+ {
+ suspendInternal(TDESystemPowerState::Hibernate);
+ return true;
+ }
+ break;
+
+ case SuspendType::HybridSuspend:
+ if (rootDevice->canHybridSuspend() && !m_disableSuspend && !m_disableHibernate)
+ {
+ suspendInternal(TDESystemPowerState::HybridSuspend);
+ return true;
+ }
+ break;
+ }
+ }
+#endif
+ return false;
+}
+
#include <tdemessagebox.h>
void KSMServer::logoutTimed( int sdtype, int sdmode, TQString bootOption )
diff --git a/ksmserver/shutdowndlg.cpp b/ksmserver/shutdowndlg.cpp
index 64bf4a407..ed01d30d0 100644
--- a/ksmserver/shutdowndlg.cpp
+++ b/ksmserver/shutdowndlg.cpp
@@ -11,6 +11,7 @@ Copyright (C) 2000 Matthias Ettrich <ettrich@kde.org>
#endif
#include "shutdowndlg.h"
+#include "server.h"
#include <tqapplication.h>
#include <tqlayout.h>
@@ -804,7 +805,6 @@ KSMShutdownDlg::KSMShutdownDlg( TQWidget* parent,
TDEConfig config("power-managerrc");
bool disableSuspend = config.readBoolEntry("disableSuspend", false);
bool disableHibernate = config.readBoolEntry("disableHibernate", false);
- m_lockOnResume = config.readBoolEntry("lockOnResume", true);
bool canFreeze = false;
bool canSuspend = false;
@@ -892,7 +892,7 @@ KSMShutdownDlg::KSMShutdownDlg( TQWidget* parent,
hbuttonbox->addWidget ( btnHybridSuspend );
connect(btnHybridSuspend, TQ_SIGNAL(clicked()), TQ_SLOT(slotHybridSuspend()));
}
-
+
// Separator (within buttonlay)
vbox->addWidget( new KSeparator( frame ) );
@@ -1065,7 +1065,7 @@ KSMShutdownDlg::KSMShutdownDlg( TQWidget* parent,
buttonlay->addWidget( btnHybridSuspend );
connect(btnHybridSuspend, TQ_SIGNAL(clicked()), TQ_SLOT(slotHybridSuspend()));
}
-
+
buttonlay->addStretch( 1 );
// Separator
diff --git a/ksmserver/shutdowndlg.h b/ksmserver/shutdowndlg.h
index 1c3e00e3b..5a9d652f2 100644
--- a/ksmserver/shutdowndlg.h
+++ b/ksmserver/shutdowndlg.h
@@ -34,17 +34,6 @@ class TDEAction;
#include <config.h>
-namespace SuspendType {
-enum SuspendType {
- NotSpecified = 0,
- Freeze,
- Standby,
- Suspend,
- Hibernate,
- HybridSuspend
-};
-};
-
// The (singleton) widget that makes/fades the desktop gray.
class KSMShutdownFeedback : public TQWidget
{
@@ -149,7 +138,6 @@ private:
TQString m_bootOption;
TQPopupMenu *targets;
TQStringList rebootOptions;
- bool m_lockOnResume;
int* m_selection;
};