summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-05-20 18:22:04 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-05-20 18:22:04 -0500
commit193d9afcdb186902317c5bef5d6c769fc8933f1a (patch)
tree7634b1ddfbef08527a9fc55841ccbbdac2de7cae
parent2f2f32d31cb1548defcd7aa84187ac7df6479cce (diff)
downloadtdebase-193d9afcdb186902317c5bef5d6c769fc8933f1a.tar.gz
tdebase-193d9afcdb186902317c5bef5d6c769fc8933f1a.zip
Fix desktop lock not engaging on suspend
This closes Bug 1003
-rw-r--r--kdesktop/lock/main.cc4
-rw-r--r--kdesktop/lockeng.cc46
-rw-r--r--kdesktop/lockeng.h6
-rw-r--r--ksmserver/shutdown.cpp43
-rw-r--r--ksmserver/shutdowndlg.cpp59
-rw-r--r--ksmserver/shutdowndlg.h5
6 files changed, 114 insertions, 49 deletions
diff --git a/kdesktop/lock/main.cc b/kdesktop/lock/main.cc
index a28d88330..7adbd5745 100644
--- a/kdesktop/lock/main.cc
+++ b/kdesktop/lock/main.cc
@@ -331,6 +331,10 @@ int main( int argc, char **argv )
}
else {
pid_t kdesktop_pid = atoi(args->getOption( "internal" ));
+ if (kill(kdesktop_pid, SIGUSR2) < 0) {
+ // The controlling kdesktop process probably died. Commit suicide...
+ return 12;
+ }
app.exec();
if (kill(kdesktop_pid, SIGUSR1) < 0) {
// The controlling kdesktop process probably died. Commit suicide...
diff --git a/kdesktop/lockeng.cc b/kdesktop/lockeng.cc
index f24d02f9f..553f0ce4c 100644
--- a/kdesktop/lockeng.cc
+++ b/kdesktop/lockeng.cc
@@ -37,6 +37,12 @@ static void sigusr1_handler(int)
m_masterSaverEngine->slotLockProcessWaiting();
}
}
+static void sigusr2_handler(int)
+{
+ if (m_masterSaverEngine) {
+ m_masterSaverEngine->slotLockProcessFullyActivated();
+ }
+}
//===========================================================================
//
@@ -61,6 +67,14 @@ SaverEngine::SaverEngine()
act.sa_flags = 0;
sigaction(SIGUSR1, &act, 0L);
+ // handle SIGUSR2
+ m_masterSaverEngine = this;
+ act.sa_handler= sigusr2_handler;
+ sigemptyset(&(act.sa_mask));
+ sigaddset(&(act.sa_mask), SIGUSR2);
+ act.sa_flags = 0;
+ sigaction(SIGUSR2, &act, 0L);
+
// Save X screensaver parameters
XGetScreenSaver(tqt_xdisplay(), &mXTimeout, &mXInterval,
&mXBlanking, &mXExposures);
@@ -118,7 +132,7 @@ SaverEngine::~SaverEngine()
void SaverEngine::lock()
{
bool ok = true;
- if (mState == Waiting)
+ if (mState != Saving)
{
mSAKProcess->kill(SIGTERM);
ok = startLockProcess( ForceLock );
@@ -237,6 +251,27 @@ bool SaverEngine::isBlanked()
return (mState != Waiting);
}
+void SaverEngine::enableExports()
+{
+#ifdef Q_WS_X11
+ kdDebug(270) << k_lineinfo << "activating background exports.\n";
+ DCOPClient *client = kapp->dcopClient();
+ if (!client->isAttached()) {
+ client->attach();
+ }
+ TQByteArray data;
+ TQDataStream args( data, IO_WriteOnly );
+ args << 1;
+
+ TQCString appname( "kdesktop" );
+ int screen_number = DefaultScreen(tqt_xdisplay());
+ if ( screen_number )
+ appname.sprintf("kdesktop-screen-%d", screen_number );
+
+ client->send( appname, "KBackgroundIface", "setExport(int)", data );
+#endif
+}
+
//---------------------------------------------------------------------------
void SaverEngine::handleSecureDialog()
{
@@ -316,9 +351,11 @@ void SaverEngine::setBlankOnly( bool blankOnly )
//
bool SaverEngine::startLockProcess( LockType lock_type )
{
- if (mState != Waiting)
+ if (mState == Saving)
return true;
+ enableExports();
+
kdDebug(1204) << "SaverEngine: starting saver" << endl;
emitDCOPSignal("KDE_start_screensaver()", TQByteArray());
@@ -452,6 +489,11 @@ void SaverEngine::slotLockProcessWaiting()
TQTimer::singleShot(0, this, SLOT(lockProcessWaiting()));
}
+void SaverEngine::slotLockProcessFullyActivated()
+{
+ mState = Saving;
+}
+
void SaverEngine::lockProcessWaiting()
{
kdDebug(1204) << "SaverEngine: lock exited" << endl;
diff --git a/kdesktop/lockeng.h b/kdesktop/lockeng.h
index e42a048bb..d1133aae6 100644
--- a/kdesktop/lockeng.h
+++ b/kdesktop/lockeng.h
@@ -80,6 +80,7 @@ public:
public slots:
void slotLockProcessWaiting();
+ void slotLockProcessFullyActivated();
protected slots:
void idleTimeout();
@@ -90,6 +91,11 @@ private slots:
void handleSecureDialog();
void slotSAKProcessExited();
+ /**
+ * Enable wallpaper exports
+ */
+ void enableExports();
+
protected:
enum LockType { DontLock, DefaultLock, ForceLock, SecureDialog };
bool startLockProcess( LockType lock_type );
diff --git a/ksmserver/shutdown.cpp b/ksmserver/shutdown.cpp
index 09cb2d743..ef0c0c92f 100644
--- a/ksmserver/shutdown.cpp
+++ b/ksmserver/shutdown.cpp
@@ -83,6 +83,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <libkrsync/krsync.h>
+#ifdef WITH_UPOWER
+ #include <tqdbusdata.h>
+ #include <tqdbusmessage.h>
+ #include <tqdbusproxy.h>
+ #include <tqdbusvariant.h>
+#endif
+
#include "server.h"
#include "global.h"
#include "shutdowndlg.h"
@@ -169,14 +176,48 @@ void KSMServer::shutdownInternal( KApplication::ShutdownConfirm confirm,
dialogActive = true;
if ( !logoutConfirmed ) {
+ int selection;
KSMShutdownFeedback::start(); // make the screen gray
logoutConfirmed =
- KSMShutdownDlg::confirmShutdown( maysd, sdtype, bopt );
+ KSMShutdownDlg::confirmShutdown( maysd, 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 != 0) {
+ // respect lock on resume & disable suspend/hibernate settings
+ // from power-manager
+ KConfig config("power-managerrc");
+ bool lockOnResume = config.readBoolEntry("lockOnResume", true);
+ if (lockOnResume) {
+ DCOPRef("kdesktop", "KScreensaverIface").send("lock");
+ }
+#ifdef WITH_UPOWER
+ TQT_DBusConnection dbusConn;
+ dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
+ if (selection == 1) { // Suspend
+ if ( dbusConn.isConnected() ) {
+ TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
+ "org.freedesktop.UPower",
+ "/org/freedesktop/UPower",
+ "org.freedesktop.UPower",
+ "Suspend");
+ dbusConn.sendWithReply(msg);
+ }
+ }
+ if (selection == 2) { // Hibernate
+ if( dbusConn.isConnected() ) {
+ TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
+ "org.freedesktop.UPower",
+ "/org/freedesktop/UPower",
+ "org.freedesktop.UPower",
+ "Hibernate");
+ dbusConn.sendWithReply(msg);
+ }
+ }
+#endif // WITH_UPOWER
+ }
}
if ( logoutConfirmed ) {
diff --git a/ksmserver/shutdowndlg.cpp b/ksmserver/shutdowndlg.cpp
index 35cae6537..3b1e27f68 100644
--- a/ksmserver/shutdowndlg.cpp
+++ b/ksmserver/shutdowndlg.cpp
@@ -674,14 +674,17 @@ void KSMShutdownIPFeedback::slotPaintEffect()
//////
KSMShutdownDlg::KSMShutdownDlg( TQWidget* parent,
- bool maysd, KApplication::ShutdownType sdtype )
- : TQDialog( parent, 0, TRUE, (WFlags)WType_Popup ), targets(0)
+ bool maysd, KApplication::ShutdownType sdtype, int* selection )
+ : TQDialog( parent, 0, TRUE, (WFlags)WType_Popup ), targets(0), m_selection(selection)
// this is a WType_Popup on purpose. Do not change that! Not
// having a popup here has severe side effects.
{
TQVBoxLayout* vbox = new TQVBoxLayout( this );
+ if (m_selection) {
+ *m_selection = 0;
+ }
TQFrame* frame = new TQFrame( this );
frame->setFrameStyle( TQFrame::StyledPanel | TQFrame::Raised );
@@ -1104,27 +1107,12 @@ void KSMShutdownDlg::slotHalt()
void KSMShutdownDlg::slotSuspend()
{
-#ifdef WITH_UPOWER
- if (m_lockOnResume) {
- DCOPRef("kdesktop", "KScreensaverIface").send("lock");
- }
+ *m_selection = 1; // Suspend
- if( m_dbusConn.isConnected() ) {
- TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
- "org.freedesktop.UPower",
- "/org/freedesktop/UPower",
- "org.freedesktop.UPower",
- "Suspend");
- m_dbusConn.sendWithReply(msg);
- }
-
- reject(); // continue on resume
+#ifdef WITH_UPOWER
+ // Handled in shutdown.cpp
#else
#ifdef COMPILE_HALBACKEND
- if (m_lockOnResume) {
- DCOPRef("kdesktop", "KScreensaverIface").send("lock");
- }
-
if (m_dbusConn)
{
DBusMessage *msg = dbus_message_new_method_call(
@@ -1140,35 +1128,19 @@ void KSMShutdownDlg::slotSuspend()
dbus_message_unref(msg);
}
-
- reject(); // continue on resume
#endif
#endif // WITH_UPOWER
+ reject(); // continue on resume
}
void KSMShutdownDlg::slotHibernate()
{
-#ifdef WITH_UPOWER
- if (m_lockOnResume) {
- DCOPRef("kdesktop", "KScreensaverIface").send("lock");
- }
-
- if( m_dbusConn.isConnected() ) {
- TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
- "org.freedesktop.UPower",
- "/org/freedesktop/UPower",
- "org.freedesktop.UPower",
- "Hibernate");
- m_dbusConn.sendWithReply(msg);
- }
+ *m_selection = 2; // Hibernate
- reject(); // continue on resume
+#ifdef WITH_UPOWER
+ // Handled in shutdown.cpp
#else
#ifdef COMPILE_HALBACKEND
- if (m_lockOnResume) {
- DCOPRef("kdesktop", "KScreensaverIface").send("lock");
- }
-
if (m_dbusConn)
{
DBusMessage *msg = dbus_message_new_method_call(
@@ -1181,18 +1153,17 @@ void KSMShutdownDlg::slotHibernate()
dbus_message_unref(msg);
}
-
- reject(); // continue on resume
#endif
#endif // WITH_UPOWER
+ reject(); // continue on resume
}
-bool KSMShutdownDlg::confirmShutdown( bool maysd, KApplication::ShutdownType& sdtype, TQString& bootOption )
+bool KSMShutdownDlg::confirmShutdown( bool maysd, KApplication::ShutdownType& sdtype, TQString& bootOption, int* selection )
{
kapp->enableStyles();
KSMShutdownDlg* l = new KSMShutdownDlg( 0,
//KSMShutdownFeedback::self(),
- maysd, sdtype );
+ maysd, sdtype, selection );
// Show dialog (will save the background in showEvent)
TQSize sh = l->sizeHint();
diff --git a/ksmserver/shutdowndlg.h b/ksmserver/shutdowndlg.h
index 05ca99126..eab4570e1 100644
--- a/ksmserver/shutdowndlg.h
+++ b/ksmserver/shutdowndlg.h
@@ -129,7 +129,7 @@ class KSMShutdownDlg : public TQDialog
Q_OBJECT
public:
- static bool confirmShutdown( bool maysd, KApplication::ShutdownType& sdtype, TQString& bopt );
+ static bool confirmShutdown( bool maysd, KApplication::ShutdownType& sdtype, TQString& bopt, int* selection=0 );
public slots:
void slotLogout();
@@ -143,7 +143,7 @@ protected:
~KSMShutdownDlg();
private:
- KSMShutdownDlg( TQWidget* parent, bool maysd, KApplication::ShutdownType sdtype );
+ KSMShutdownDlg( TQWidget* parent, bool maysd, KApplication::ShutdownType sdtype, int* selection=0 );
KApplication::ShutdownType m_shutdownType;
TQString m_bootOption;
TQPopupMenu *targets;
@@ -157,6 +157,7 @@ private:
#endif
#endif // WITH_UPOWER
bool m_lockOnResume;
+ int* m_selection;
};
// The shutdown-in-progress dialog