diff options
author | Mavridis Philippe <[email protected]> | 2024-06-09 22:04:25 +0300 |
---|---|---|
committer | Mavridis Philippe <[email protected]> | 2024-08-01 13:02:12 +0300 |
commit | db3f842c545ce838e40a50e8025268c833c9fc57 (patch) | |
tree | 2767fd9b56d84928b6c3f946cf8953f44e1159f4 /ksmserver/shutdown.cpp | |
parent | 18d7e66404ccf8c4dcfb1c5f07103e258b576e7e (diff) | |
download | tdebase-db3f842c545ce838e40a50e8025268c833c9fc57.tar.gz tdebase-db3f842c545ce838e40a50e8025268c833c9fc57.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 <[email protected]>
(cherry picked from commit d88718ee027e329565d2d97c5cadde4aa1b83166)
Diffstat (limited to 'ksmserver/shutdown.cpp')
-rw-r--r-- | ksmserver/shutdown.cpp | 96 |
1 files changed, 62 insertions, 34 deletions
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 ) |