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>
(cherry picked from commit d88718ee02)
r14.1.x
Mavridis Philippe 5 months ago
parent 18d7e66404
commit db3f842c54

@ -10,6 +10,11 @@ class KSMServerInterface : virtual public DCOPObject
k_dcop: k_dcop:
virtual void logout(int, int, int ) = 0; 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 restoreSessionInternal() = 0;
virtual void restoreSessionDoneInternal() = 0; virtual void restoreSessionDoneInternal() = 0;
virtual TQStringList sessionList() = 0; virtual TQStringList sessionList() = 0;
@ -19,11 +24,11 @@ k_dcop:
virtual void saveCurrentSessionAs( TQString ) = 0; virtual void saveCurrentSessionAs( TQString ) = 0;
virtual void autoStart2() = 0; virtual void autoStart2() = 0;
virtual void suspendStartup( TQCString ) = 0; virtual void suspendStartup( TQCString ) = 0;
virtual void resumeStartup( TQCString ) = 0; virtual void resumeStartup( TQCString ) = 0;
virtual void logoutTimed( int, int, TQString ) = 0; virtual void reconfigure() = 0;
}; };
#endif #endif

@ -689,6 +689,8 @@ KSMServer::KSMServer( const TQString& windowManager, const TQString& windowManag
connect( &restoreTimer, TQ_SIGNAL( timeout() ), this, TQ_SLOT( tryRestoreNext() ) ); connect( &restoreTimer, TQ_SIGNAL( timeout() ), this, TQ_SLOT( tryRestoreNext() ) );
connect( &shutdownTimer, TQ_SIGNAL( timeout() ), this, TQ_SLOT( timeoutQuit() ) ); connect( &shutdownTimer, TQ_SIGNAL( timeout() ), this, TQ_SLOT( timeoutQuit() ) );
connect( kapp, TQ_SIGNAL( shutDown() ), this, TQ_SLOT( cleanUp() ) ); connect( kapp, TQ_SIGNAL( shutDown() ), this, TQ_SLOT( cleanUp() ) );
reconfigure();
} }
KSMServer::~KSMServer() KSMServer::~KSMServer()
@ -697,6 +699,16 @@ KSMServer::~KSMServer()
cleanUp(); 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() void KSMServer::cleanUp()
{ {
if (clean) return; if (clean) return;
@ -919,6 +931,27 @@ void KSMServer::storeSession()
config->sync(); 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() TQStringList KSMServer::sessionList()
{ {
@ -995,4 +1028,4 @@ bool KSMServer::defaultSession() const
bool KSMServer::startupCompleted() bool KSMServer::startupCompleted()
{ {
return m_startupCompleted; return m_startupCompleted;
} }

@ -37,6 +37,17 @@ class KSMListener;
class KSMConnection; class KSMConnection;
class KSMClient; class KSMClient;
namespace SuspendType {
enum SuspendType {
NotSpecified = 0,
Freeze,
Standby, // not implemented
Suspend,
Hibernate,
HybridSuspend
};
};
enum SMType { SM_ERROR, SM_WMCOMMAND, SM_WMSAVEYOURSELF }; enum SMType { SM_ERROR, SM_WMCOMMAND, SM_WMSAVEYOURSELF };
struct SMData struct SMData
{ {
@ -103,6 +114,7 @@ public:
public slots: public slots:
void cleanUp(); void cleanUp();
void reconfigure();
private slots: private slots:
void newConnection( int socket ); void newConnection( int socket );
@ -172,6 +184,8 @@ private:
TDEApplication::ShutdownMode sdmode, TDEApplication::ShutdownMode sdmode,
TQString bootOption = TQString::null ); TQString bootOption = TQString::null );
void suspendInternal(int state);
void performLegacySessionSave(); void performLegacySessionSave();
void storeLegacySession( TDEConfig* config ); void storeLegacySession( TDEConfig* config );
void restoreLegacySession( TDEConfig* config ); void restoreLegacySession( TDEConfig* config );
@ -186,12 +200,14 @@ private:
void resumeStartupInternal(); void resumeStartupInternal();
// public dcop interface // public dcop interface
void logout( int, int, int ); void logout(int, int, int);
virtual void logoutTimed( int, int, TQString ); virtual void logoutTimed(int, int, TQString);
bool suspend(int);
TQStringList suspendOptions();
TQStringList sessionList(); TQStringList sessionList();
TQString currentSession(); TQString currentSession();
void saveCurrentSession(); void saveCurrentSession();
void saveCurrentSessionAs( TQString ); void saveCurrentSessionAs(TQString);
TQWidget* startupNotifierIPDlg; TQWidget* startupNotifierIPDlg;
TQWidget* shutdownNotifierIPDlg; TQWidget* shutdownNotifierIPDlg;
@ -240,6 +256,10 @@ private:
TDEApplication::ShutdownType pendingShutdown_sdtype; TDEApplication::ShutdownType pendingShutdown_sdtype;
TDEApplication::ShutdownMode pendingShutdown_sdmode; TDEApplication::ShutdownMode pendingShutdown_sdmode;
bool m_disableSuspend;
bool m_disableHibernate;
bool m_lockOnResume;
// ksplash interface // ksplash interface
void upAndRunning( const TQString& msg ); void upAndRunning( const TQString& msg );
void publishProgress( int progress, bool max = false ); void publishProgress( int progress, bool max = false );

@ -222,45 +222,13 @@ void KSMServer::shutdownInternal( TDEApplication::ShutdownConfirm confirm,
if ( !logoutConfirmed ) { if ( !logoutConfirmed ) {
int selection; int selection;
KSMShutdownFeedback::start(); // make the screen gray KSMShutdownFeedback::start(); // make the screen gray
logoutConfirmed = logoutConfirmed = KSMShutdownDlg::confirmShutdown( maysd, mayrb, sdtype, bopt, &selection );
KSMShutdownDlg::confirmShutdown( maysd, mayrb, sdtype, bopt, &selection );
// ###### We can't make the screen remain gray while talking to the apps, // ###### We can't make the screen remain gray while talking to the apps,
// because this prevents interaction ("do you want to save", etc.) // because this prevents interaction ("do you want to save", etc.)
// TODO: turn the feedback widget into a list of apps to be closed, // TODO: turn the feedback widget into a list of apps to be closed,
// with an indicator of the current status for each. // with an indicator of the current status for each.
KSMShutdownFeedback::stop(); // make the screen become normal again KSMShutdownFeedback::stop(); // make the screen become normal again
if (selection != SuspendType::NotSpecified) { suspend(selection);
// 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
}
} }
if ( logoutConfirmed ) { if ( logoutConfirmed ) {
@ -343,6 +311,66 @@ void KSMServer::shutdown( TDEApplication::ShutdownConfirm confirm,
shutdownInternal( confirm, sdtype, sdmode ); 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> #include <tdemessagebox.h>
void KSMServer::logoutTimed( int sdtype, int sdmode, TQString bootOption ) void KSMServer::logoutTimed( int sdtype, int sdmode, TQString bootOption )

@ -11,6 +11,7 @@ Copyright (C) 2000 Matthias Ettrich <ettrich@kde.org>
#endif #endif
#include "shutdowndlg.h" #include "shutdowndlg.h"
#include "server.h"
#include <tqapplication.h> #include <tqapplication.h>
#include <tqlayout.h> #include <tqlayout.h>
@ -804,7 +805,6 @@ KSMShutdownDlg::KSMShutdownDlg( TQWidget* parent,
TDEConfig config("power-managerrc"); TDEConfig config("power-managerrc");
bool disableSuspend = config.readBoolEntry("disableSuspend", false); bool disableSuspend = config.readBoolEntry("disableSuspend", false);
bool disableHibernate = config.readBoolEntry("disableHibernate", false); bool disableHibernate = config.readBoolEntry("disableHibernate", false);
m_lockOnResume = config.readBoolEntry("lockOnResume", true);
bool canFreeze = false; bool canFreeze = false;
bool canSuspend = false; bool canSuspend = false;
@ -892,7 +892,7 @@ KSMShutdownDlg::KSMShutdownDlg( TQWidget* parent,
hbuttonbox->addWidget ( btnHybridSuspend ); hbuttonbox->addWidget ( btnHybridSuspend );
connect(btnHybridSuspend, TQ_SIGNAL(clicked()), TQ_SLOT(slotHybridSuspend())); connect(btnHybridSuspend, TQ_SIGNAL(clicked()), TQ_SLOT(slotHybridSuspend()));
} }
// Separator (within buttonlay) // Separator (within buttonlay)
vbox->addWidget( new KSeparator( frame ) ); vbox->addWidget( new KSeparator( frame ) );
@ -1065,7 +1065,7 @@ KSMShutdownDlg::KSMShutdownDlg( TQWidget* parent,
buttonlay->addWidget( btnHybridSuspend ); buttonlay->addWidget( btnHybridSuspend );
connect(btnHybridSuspend, TQ_SIGNAL(clicked()), TQ_SLOT(slotHybridSuspend())); connect(btnHybridSuspend, TQ_SIGNAL(clicked()), TQ_SLOT(slotHybridSuspend()));
} }
buttonlay->addStretch( 1 ); buttonlay->addStretch( 1 );
// Separator // Separator

@ -34,17 +34,6 @@ class TDEAction;
#include <config.h> #include <config.h>
namespace SuspendType {
enum SuspendType {
NotSpecified = 0,
Freeze,
Standby,
Suspend,
Hibernate,
HybridSuspend
};
};
// The (singleton) widget that makes/fades the desktop gray. // The (singleton) widget that makes/fades the desktop gray.
class KSMShutdownFeedback : public TQWidget class KSMShutdownFeedback : public TQWidget
{ {
@ -149,7 +138,6 @@ private:
TQString m_bootOption; TQString m_bootOption;
TQPopupMenu *targets; TQPopupMenu *targets;
TQStringList rebootOptions; TQStringList rebootOptions;
bool m_lockOnResume;
int* m_selection; int* m_selection;
}; };

Loading…
Cancel
Save