From 95837cc844210a35b3374bbe707cb82920b80a9b Mon Sep 17 00:00:00 2001 From: Mavridis Philippe Date: Sun, 9 Jun 2024 22:22:02 +0300 Subject: Add support for assigning global shortcuts for suspend actions The corresponding shortcuts have been added as part of the KDesktop shortucts, to complement similar options (logout, shutdown, reboot). The shortcuts are only shown for the options that KSMServer reports via DCOP as valid. In order to do be able to make a DCOP call from kdesktopbindings.cpp, the include had to be added to several files of the shortcuts TDECM. Signed-off-by: Mavridis Philippe --- kcontrol/keys/main.cpp | 1 + kcontrol/keys/shortcuts.cpp | 1 + kdesktop/desktop.cpp | 28 ++++++++++++++++++++++++++-- kdesktop/desktop.h | 4 ++++ kdesktop/kdesktopbindings.cpp | 21 +++++++++++++++++++++ 5 files changed, 53 insertions(+), 2 deletions(-) diff --git a/kcontrol/keys/main.cpp b/kcontrol/keys/main.cpp index bba777adb..db7416c28 100644 --- a/kcontrol/keys/main.cpp +++ b/kcontrol/keys/main.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "commandShortcuts.h" #include "main.h" diff --git a/kcontrol/keys/shortcuts.cpp b/kcontrol/keys/shortcuts.cpp index 18f6803ab..4fb58a9b5 100644 --- a/kcontrol/keys/shortcuts.cpp +++ b/kcontrol/keys/shortcuts.cpp @@ -41,6 +41,7 @@ #include #include #include +#include ShortcutsModule::ShortcutsModule( TQWidget *parent, const char *name ) : TQWidget( parent, name ) diff --git a/kdesktop/desktop.cpp b/kdesktop/desktop.cpp index e7681b1f2..fac03a185 100644 --- a/kdesktop/desktop.cpp +++ b/kdesktop/desktop.cpp @@ -113,7 +113,7 @@ bool KRootWidget::eventFilter ( TQObject *, TQEvent * e ) else if ( e->type() == TQEvent::Drop ) { TQDropEvent* de = static_cast( e ); - if ( KColorDrag::canDecode( de ) ) + if ( KColorDrag::canDecode( de ) ) emit colorDropEvent( de ); else if ( TQImageDrag::canDecode( de ) ) emit imageDropEvent( de ); @@ -215,7 +215,7 @@ KDesktop::initRoot() Display *dpy = tqt_xdisplay(); Window root = RootWindow(dpy, kdesktop_screen_number); XDefineCursor(dpy, root, cursor().handle()); - + m_bDesktopEnabled = KDesktopSettings::desktopEnabled(); if ( !m_bDesktopEnabled && !m_pRootWidget ) { @@ -1064,6 +1064,30 @@ void KDesktop::slotRebootNoCnf() TDEApplication::ShutdownTypeReboot ); } +void KDesktop::slotFreeze() +{ + DCOPRef r("ksmserver", "ksmserver"); + r.send("suspend", 1); +} + +void KDesktop::slotSuspend() +{ + DCOPRef r("ksmserver", "ksmserver"); + r.send("suspend", 3); +} + +void KDesktop::slotHibernate() +{ + DCOPRef r("ksmserver", "ksmserver"); + r.send("suspend", 4); +} + +void KDesktop::slotHybridSuspend() +{ + DCOPRef r("ksmserver", "ksmserver"); + r.send("suspend", 5); +} + void KDesktop::setVRoot( bool enable ) { if ( enable == set_vroot ) diff --git a/kdesktop/desktop.h b/kdesktop/desktop.h index c85e8b577..ca1eefc61 100644 --- a/kdesktop/desktop.h +++ b/kdesktop/desktop.h @@ -135,6 +135,10 @@ private slots: void slotLogoutNoCnf(); void slotHaltNoCnf(); void slotRebootNoCnf(); + void slotFreeze(); + void slotSuspend(); + void slotHibernate(); + void slotHybridSuspend(); /** Connected to KSycoca */ void slotDatabaseChanged(); diff --git a/kdesktop/kdesktopbindings.cpp b/kdesktop/kdesktopbindings.cpp index 17b27fc65..5f4fb24cd 100644 --- a/kdesktop/kdesktopbindings.cpp +++ b/kdesktop/kdesktopbindings.cpp @@ -49,6 +49,27 @@ } #endif + // Only add these options if supported by ksmserver + DCOPRef ksmref("ksmserver", "ksmserver"); + DCOPReply reply = ksmref.call("suspendOptions"); + + TQStringList suspendOptions; + if (reply.isValid()) { + reply.get(suspendOptions); + } + + if (suspendOptions.contains("freeze")) + DEF( I18N_NOOP("Freeze"), TDEShortcut(), TDEShortcut(), slotFreeze() ); + + if (suspendOptions.contains("suspend")) + DEF( I18N_NOOP("Suspend"), TDEShortcut(TQString("XF86Sleep")), TDEShortcut(TQString("XF86Sleep")), slotSuspend() ); + + if (suspendOptions.contains("hibernate")) + DEF( I18N_NOOP("Hibernate"), TDEShortcut(), TDEShortcut(), slotHibernate() ); + + if (suspendOptions.contains("hybridSuspend")) + DEF( I18N_NOOP("Hybrid Suspend"), TDEShortcut(), TDEShortcut(), slotHybridSuspend() ); + #undef DEF #undef DEF2 #undef WIN -- cgit v1.2.1