summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmanoil Kotsev <deloptes@gmail.com>2024-09-07 08:17:46 +0000
committerEmanoil Kotsev <deloptes@gmail.com>2024-12-11 22:51:17 +0000
commit1dec40d10689ff9678fb36fec0f3d87439562897 (patch)
treed491842e4a2650dcaacf18f869af99c5606e18c2
parent1c05f36ad14d115b52151b61a06b239d0e6ef27b (diff)
downloadtdebase-1dec40d10689ff9678fb36fec0f3d87439562897.tar.gz
tdebase-1dec40d10689ff9678fb36fec0f3d87439562897.zip
Add DBus screen saver interface to TDE
Signed-off-by: Emanoil Kotsev <deloptes@gmail.com>
-rw-r--r--kdesktop/CMakeLists.txt3
-rw-r--r--kdesktop/ConfigureChecks.cmake3
-rw-r--r--kdesktop/dbus/screensaver/CMakeLists.txt44
-rw-r--r--kdesktop/dbus/screensaver/org.freedesktop.ScreenSaver.xml41
-rw-r--r--kdesktop/dbus/screensaver/org.trinitydesktop.ScreenSaver.xml11
-rw-r--r--kdesktop/dbusscreensaverservice.cpp171
-rw-r--r--kdesktop/dbusscreensaverservice.h126
-rw-r--r--kdesktop/main.cpp87
-rw-r--r--kdesktop/screensaverInterfaceImpl.cpp185
-rw-r--r--kdesktop/screensaverInterfaceImpl.h204
10 files changed, 835 insertions, 40 deletions
diff --git a/kdesktop/CMakeLists.txt b/kdesktop/CMakeLists.txt
index ff0394f4b..041e47355 100644
--- a/kdesktop/CMakeLists.txt
+++ b/kdesktop/CMakeLists.txt
@@ -17,6 +17,7 @@ add_subdirectory( patterns )
add_subdirectory( programs )
add_subdirectory( init )
add_subdirectory( kwebdesktop )
+add_subdirectory( dbus/screensaver )
if( NOT BUILD_LIBKONQ )
@@ -90,6 +91,7 @@ set( ${target}_SRCS
pixmapserver.cpp kcustommenu.cpp startupid.cpp minicli_ui.ui
xautolock_diy.c xautolock_engine.c kshadowengine.cpp
kshadowsettings.cpp kdesktopshadowsettings.cpp
+ dbusscreensaverservice.cpp screensaverInterfaceImpl.cpp
tdefileividesktop.cpp kdesktopapp.cpp
)
@@ -97,6 +99,7 @@ tde_add_tdeinit_executable( ${target} AUTOMOC
SOURCES ${${target}_SRCS}
LINK
pthread kdesktopsettings-static bgnd-static dmctl-static
+ screensaverinterfaces-static
konq-shared tdeutils-shared tdesu-shared ${TDEHW_LIBRARIES}
${XRENDER_LIBRARIES} ${XCURSOR_LIBRARIES} Xext ${DL_LIBRARIES}
${XSS_LIBRARIES} ${DBUS_1_TQT_LIBRARIES}
diff --git a/kdesktop/ConfigureChecks.cmake b/kdesktop/ConfigureChecks.cmake
index bc53ec698..e012b1213 100644
--- a/kdesktop/ConfigureChecks.cmake
+++ b/kdesktop/ConfigureChecks.cmake
@@ -12,3 +12,6 @@
if( WITH_PAM )
set( TDESCREENSAVER_PAM_SERVICE "kde" CACHE INTERNAL "" )
endif( )
+
+# check for dbus
+tde_setup_dbus( dbus-1-tqt )
diff --git a/kdesktop/dbus/screensaver/CMakeLists.txt b/kdesktop/dbus/screensaver/CMakeLists.txt
new file mode 100644
index 000000000..9fb887326
--- /dev/null
+++ b/kdesktop/dbus/screensaver/CMakeLists.txt
@@ -0,0 +1,44 @@
+#################################################
+#
+# (C) 2024 Emanoil Kotsev
+# deloptes (AT) gmail.com
+#
+# Improvements and feedback are welcome
+#
+# This file is released under GPL >= 2
+#
+#################################################
+
+include_directories(
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${TQT_INCLUDE_DIRS}
+ ${DBUS_TQT_INCLUDE_DIRS}
+)
+
+set( INTROSPECTIONPATH ${CMAKE_SOURCE_DIR}/kdesktop/dbus/screensaver )
+
+set( ScreenSaver_HDRS dbusbaseNode.h introspectableInterface.h screensaverInterface.h screensaverNode.h screensaverProxy.h)
+set( ScreenSaver_SRCS dbusbaseNode.cpp introspectableInterface.cpp screensaverInterface.cpp screensaverNode.cpp screensaverProxy.cpp )
+
+##### ScreenSaver #########################
+add_custom_command(
+ OUTPUT ${ScreenSaver_HDRS} ${ScreenSaver_SRCS}
+ COMMAND ${DBUSXML2QT3_EXECUTABLE} ${INTROSPECTIONPATH}/org.freedesktop.ScreenSaver.xml 2>/dev/null
+ DEPENDS ${INTROSPECTIONPATH}/org.freedesktop.ScreenSaver.xml
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+)
+
+tde_add_library( screensaverinterfaces STATIC_PIC AUTOMOC
+ SOURCES ${ScreenSaver_SRCS}
+ LINK ${DBUS_TQT_LIBRARIES}
+)
+
+##### install headers ###################################
+
+install(
+ DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+ DESTINATION ${INCLUDE_INSTALL_DIR}
+ USE_SOURCE_PERMISSIONS
+ FILES_MATCHING PATTERN PATTERN "*.h"
+ PATTERN "CMakeFiles" EXCLUDE
+)
diff --git a/kdesktop/dbus/screensaver/org.freedesktop.ScreenSaver.xml b/kdesktop/dbus/screensaver/org.freedesktop.ScreenSaver.xml
new file mode 100644
index 000000000..1f7b09b28
--- /dev/null
+++ b/kdesktop/dbus/screensaver/org.freedesktop.ScreenSaver.xml
@@ -0,0 +1,41 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node name="/org/freedesktop/screensaver">
+ <interface name="org.freedesktop.ScreenSaver">
+ <signal name="ActiveChanged">
+ <arg type="b"/>
+ </signal>
+ <method name="Lock">
+ </method>
+ <method name="SimulateUserActivity">
+ </method>
+ <method name="GetActive">
+ <arg type="b" direction="out"/>
+ </method>
+ <method name="GetActiveTime">
+ <arg name="seconds" type="u" direction="out"/>
+ </method>
+ <method name="GetSessionIdleTime">
+ <arg name="seconds" type="u" direction="out"/>
+ </method>
+ <method name="SetActive">
+ <arg type="b" direction="out"/>
+ <arg name="e" type="b" direction="in"/>
+ </method>
+ <method name="Inhibit">
+ <arg name="application_name" type="s" direction="in"/>
+ <arg name="reason_for_inhibit" type="s" direction="in"/>
+ <arg name="cookie" type="u" direction="out"/>
+ </method>
+ <method name="UnInhibit">
+ <arg name="cookie" type="u" direction="in"/>
+ </method>
+ <method name="Throttle">
+ <arg name="application_name" type="s" direction="in"/>
+ <arg name="reason_for_inhibit" type="s" direction="in"/>
+ <arg name="cookie" type="u" direction="out"/>
+ </method>
+ <method name="UnThrottle">
+ <arg name="cookie" type="u" direction="in"/>
+ </method>
+ </interface>
+</node> \ No newline at end of file
diff --git a/kdesktop/dbus/screensaver/org.trinitydesktop.ScreenSaver.xml b/kdesktop/dbus/screensaver/org.trinitydesktop.ScreenSaver.xml
new file mode 100644
index 000000000..cac5b2319
--- /dev/null
+++ b/kdesktop/dbus/screensaver/org.trinitydesktop.ScreenSaver.xml
@@ -0,0 +1,11 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+<node name="/org/trinitydesktop/screensaver">
+ <interface name="org.trinitydesktop.screensaver">
+ <!--lock the screen, and show the switch user prompt -->
+ <method name="SwitchUser" />
+ <!-- Re-read configuration -->
+ <method name="configure" />
+ <!-- Emitted just before we start the lock process. Clients should release any X grabs -->
+ <signal name="AboutToLock" />
+ </interface>
+</node> \ No newline at end of file
diff --git a/kdesktop/dbusscreensaverservice.cpp b/kdesktop/dbusscreensaverservice.cpp
new file mode 100644
index 000000000..ba19a970a
--- /dev/null
+++ b/kdesktop/dbusscreensaverservice.cpp
@@ -0,0 +1,171 @@
+/*
+ * dbusscreensaverservice.cpp
+ *
+ * (C) 2024 Emanoil Kotsev
+ * deloptes (AT) gmail.com
+ *
+ * tdebase Copyright (C) 2009 tdebase development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <tdelocale.h>
+#include <tqdbusobjectpath.h>
+
+#include "dbusscreensaverservice.h"
+
+RootNodeService::RootNodeService(TQT_DBusConnection &connection) :
+ DBusBaseNode(), m_connection(connection)
+{
+ addChildNode("org");
+ registerObject(m_connection, "/");
+}
+
+RootNodeService::~RootNodeService()
+{
+}
+
+TQT_DBusObjectBase* RootNodeService::createInterface(const TQString& interfaceName)
+{
+ return (TQT_DBusObjectBase*) m_interfaces[interfaceName];
+}
+
+OrgNodeService::OrgNodeService(TQT_DBusConnection &connection) :
+ DBusBaseNode(), m_connection(connection)
+{
+ addChildNode("freedesktop");
+ registerObject(m_connection, "/org");
+}
+
+OrgNodeService::~OrgNodeService()
+{
+}
+
+TQT_DBusObjectBase* OrgNodeService::createInterface(const TQString& interfaceName)
+{
+ return (TQT_DBusObjectBase*) m_interfaces[interfaceName];
+}
+
+FreeDekstopNodeService::FreeDekstopNodeService(TQT_DBusConnection &connection) :
+ DBusBaseNode(), m_connection(connection)
+{
+ addChildNode("ScreenSaver");
+ registerObject(m_connection, "/org/freedesktop");
+}
+
+FreeDekstopNodeService::~FreeDekstopNodeService()
+{
+}
+
+TQT_DBusObjectBase* FreeDekstopNodeService::createInterface(const TQString& interfaceName)
+{
+ return (TQT_DBusObjectBase*) m_interfaces[interfaceName];
+}
+
+ScreenSaverService::ScreenSaverService(TQT_DBusConnection &conn) :
+ org::freedesktop::screensaverNode(),
+ m_connection(conn),
+ screenSaverInterface(new ScreenSaverInterfaceImpl(conn))
+{
+ m_interfaces.insert("org.freedesktop.DBus.Introspectable", this);
+ m_interfaces.insert("org.freedesktop.ScreenSaver", screenSaverInterface);
+ registerObject(m_connection, DBUS_SCREENSAVER_SERVICE_PATH);
+}
+
+ScreenSaverService::~ScreenSaverService()
+{
+ stopService();
+ if(screenSaverInterface)
+ delete screenSaverInterface;
+}
+
+void ScreenSaverService::stopService()
+{
+ screenSaverInterface->restoreState();
+}
+
+TQT_DBusObjectBase* ScreenSaverService::createInterface(const TQString& interfaceName)
+{
+ return (TQT_DBusObjectBase*) m_interfaces[interfaceName];
+}
+
+
+
+TDEDbusScreenSaver::TDEDbusScreenSaver()
+{
+ // open connection to DBus and configure the service
+ if (!configureService())
+ {
+ tqDebug("Failed to configure the screen saver service");
+ }
+}
+
+TDEDbusScreenSaver::~TDEDbusScreenSaver()
+{
+ // unconfigure the DBus service and close connection
+ if (!unconfigureService())
+ {
+ tqDebug("Failed to properly close the screen saver service");
+ }
+
+ delete screenSaverService;
+ delete freeDekstopNodeService;
+ delete orgService;
+ delete rootService;
+}
+
+bool TDEDbusScreenSaver::isConnectedToDBUS()
+{
+ return m_connection.isConnected();
+}
+
+bool TDEDbusScreenSaver::configureService()
+{
+ m_connection = TQT_DBusConnection::addConnection(TQT_DBusConnection::SessionBus, DBUS_SCREENSAVER_SERVICE);
+
+ if (!m_connection.isConnected())
+ {
+ tqDebug(i18n("Failed to open connection to system message bus: %1").arg(m_connection.lastError().message()));
+ return false;
+ }
+
+ // try to get a specific service name
+ if (!m_connection.requestName(DBUS_SCREENSAVER_SERVICE_NAME))
+ {
+ tqWarning(i18n("Requesting name %1 failed. "
+ "The object will only be addressable through unique name '%2'").arg(
+ DBUS_SCREENSAVER_SERVICE_NAME).arg(m_connection.uniqueName()));
+ return false;
+ }
+
+ rootService = new RootNodeService(m_connection);
+ orgService = new OrgNodeService(m_connection);
+ freeDekstopNodeService = new FreeDekstopNodeService(m_connection);
+ screenSaverService = new ScreenSaverService(m_connection);
+ return true;
+}
+
+bool TDEDbusScreenSaver::unconfigureService()
+{
+ screenSaverService->stopService(); // will restore the original state
+
+ screenSaverService=0;
+ freeDekstopNodeService=0;
+ orgService=0;
+ rootService=0;
+ // close D-Bus connection
+ m_connection.closeConnection(DBUS_SCREENSAVER_SERVICE);
+
+ return true;
+}
diff --git a/kdesktop/dbusscreensaverservice.h b/kdesktop/dbusscreensaverservice.h
new file mode 100644
index 000000000..d556f201d
--- /dev/null
+++ b/kdesktop/dbusscreensaverservice.h
@@ -0,0 +1,126 @@
+/*
+ * dbusscreensaverservice.h
+ *
+ * (C) 2024 Emanoil Kotsev
+ * deloptes (AT) gmail.com
+ *
+ * tdebase Copyright (C) 2009 tdebase development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifndef KDESKTOP_LOCK_DBUS_SCREENSAVER_DBUSSCREENSAVERSERVICE_H_
+#define KDESKTOP_LOCK_DBUS_SCREENSAVER_DBUSSCREENSAVERSERVICE_H_
+
+#include <tqdbusconnection.h>
+#include <tqmap.h>
+
+#include "dbus/screensaver/screensaverNode.h"
+#include "dbus/screensaver/dbusbaseNode.h"
+#include "screensaverInterfaceImpl.h"
+
+class ScreenSaverService: public org::freedesktop::screensaverNode
+{
+public:
+ ScreenSaverService(TQT_DBusConnection&);
+ virtual ~ScreenSaverService();
+ void stopService();
+
+protected:
+ virtual TQT_DBusObjectBase* createInterface(const TQString&);
+
+private:
+ TQMap<TQString, TQT_DBusObjectBase*> m_interfaces;
+ TQT_DBusConnection m_connection;
+ ScreenSaverInterfaceImpl *screenSaverInterface;
+};
+
+class RootNodeService: public DBusBaseNode
+{
+public:
+ RootNodeService(TQT_DBusConnection&);
+ virtual ~RootNodeService();
+protected:
+ virtual TQT_DBusObjectBase* createInterface(const TQString&);
+private:
+ TQMap<TQString, TQT_DBusObjectBase*> m_interfaces;
+ TQT_DBusConnection m_connection;
+};
+
+class OrgNodeService: public DBusBaseNode
+{
+public:
+ OrgNodeService(TQT_DBusConnection&);
+ virtual ~OrgNodeService();
+protected:
+ virtual TQT_DBusObjectBase* createInterface(const TQString&);
+private:
+ TQMap<TQString, TQT_DBusObjectBase*> m_interfaces;
+ TQT_DBusConnection m_connection;
+};
+
+class FreeDekstopNodeService: public DBusBaseNode
+{
+public:
+ FreeDekstopNodeService(TQT_DBusConnection&);
+ virtual ~FreeDekstopNodeService();
+protected:
+ virtual TQT_DBusObjectBase* createInterface(const TQString&);
+private:
+ TQMap<TQString, TQT_DBusObjectBase*> m_interfaces;
+ TQT_DBusConnection m_connection;
+};
+
+class TDEDbusScreenSaver
+{
+
+public:
+ TDEDbusScreenSaver();
+ virtual ~TDEDbusScreenSaver();
+
+ /*!
+ * This function return information about connection status to the DBUS daemon.
+ * \return boolean with the state of the connection to D-Bus
+ * \retval true if connected
+ * \retval false if disconnected
+ */
+ bool isConnectedToDBUS();
+
+private:
+ /*!
+ * This function initialize the connection to the D-Bus daemon.
+ * \return boolean with the result of the operation
+ * \retval true if successfully configured D-Bus connection
+ * \retval false if unsuccessful
+ */
+ bool configureService();
+
+ /*!
+ * This function is to close the connection to D-Bus
+ * \return boolean with the result of the operation
+ * \retval true if successfully unset D-Bus connection
+ * \retval false if unsuccessful
+ */
+ bool unconfigureService();
+
+private:
+ TQT_DBusConnection m_connection;
+
+ RootNodeService *rootService;
+ OrgNodeService *orgService;
+ FreeDekstopNodeService *freeDekstopNodeService;
+ ScreenSaverService *screenSaverService;
+
+};
+
+#endif /* KDESKTOP_LOCK_DBUS_SCREENSAVER_DBUSSCREENSAVERSERVICE_H_ */
diff --git a/kdesktop/main.cpp b/kdesktop/main.cpp
index 5df394478..75038d0c9 100644
--- a/kdesktop/main.cpp
+++ b/kdesktop/main.cpp
@@ -37,6 +37,7 @@
#include "krootwm.h"
#include "kdesktopsettings.h"
#include "kdesktopapp.h"
+#include "dbusscreensaverservice.h"
#include <signal.h>
#include <unistd.h>
@@ -115,45 +116,45 @@ extern "C" TDE_EXPORT int kdemain( int argc, char **argv )
if (TDEGlobalSettings::isMultiHead())
{
Display *dpy = XOpenDisplay(NULL);
- if (! dpy) {
- fprintf(stderr,
- "%s: FATAL ERROR: couldn't open display '%s'\n",
- argv[0], XDisplayName(NULL));
- exit(1);
- }
-
- int number_of_screens = ScreenCount(dpy);
- kdesktop_screen_number = DefaultScreen(dpy);
- int pos;
- TQCString display_name = XDisplayString(dpy);
- XCloseDisplay(dpy);
- dpy = 0;
-
- if ((pos = display_name.findRev('.')) != -1)
- display_name.remove(pos, 10);
-
- TQCString env;
- if (number_of_screens != 1) {
- for (int i = 0; i < number_of_screens; i++) {
- if (i != kdesktop_screen_number && fork() == 0) {
- kdesktop_screen_number = i;
- // break here because we are the child process, we don't
- // want to fork() anymore
- break;
- }
- }
-
- env.sprintf("DISPLAY=%s.%d", display_name.data(),
- kdesktop_screen_number);
-
- if (putenv(strdup(env.data()))) {
- fprintf(stderr,
- "%s: WARNING: unable to set DISPLAY environment variable\n",
- argv[0]);
- perror("putenv()");
- }
- }
- }
+ if (! dpy) {
+ fprintf(stderr,
+ "%s: FATAL ERROR: couldn't open display '%s'\n",
+ argv[0], XDisplayName(NULL));
+ exit(1);
+ }
+
+ int number_of_screens = ScreenCount(dpy);
+ kdesktop_screen_number = DefaultScreen(dpy);
+ int pos;
+ TQCString display_name = XDisplayString(dpy);
+ XCloseDisplay(dpy);
+ dpy = 0;
+
+ if ((pos = display_name.findRev('.')) != -1)
+ display_name.remove(pos, 10);
+
+ TQCString env;
+ if (number_of_screens != 1) {
+ for (int i = 0; i < number_of_screens; i++) {
+ if (i != kdesktop_screen_number && fork() == 0) {
+ kdesktop_screen_number = i;
+ // break here because we are the child process, we don't
+ // want to fork() anymore
+ break;
+ }
+ }
+
+ env.sprintf("DISPLAY=%s.%d", display_name.data(),
+ kdesktop_screen_number);
+
+ if (putenv(strdup(env.data()))) {
+ fprintf(stderr,
+ "%s: WARNING: unable to set DISPLAY environment variable\n",
+ argv[0]);
+ perror("putenv()");
+ }
+ }
+ }
}
TDEGlobal::locale()->setMainCatalogue("kdesktop");
@@ -289,6 +290,12 @@ extern "C" TDE_EXPORT int kdemain( int argc, char **argv )
myApp->dcopClient()->setDefaultObject( "KDesktopIface" );
-
+ TDEDbusScreenSaver dbusScreenSaverInterface;
+ if (!dbusScreenSaverInterface.isConnectedToDBUS())
+ {
+ fprintf(stderr,"Can't connect to DBus!\nUnable to start tdedbusscreensaver.\n\n"
+ "Restart dbus and try again");
+ }
+
return myApp->exec();
}
diff --git a/kdesktop/screensaverInterfaceImpl.cpp b/kdesktop/screensaverInterfaceImpl.cpp
new file mode 100644
index 000000000..4f05a8391
--- /dev/null
+++ b/kdesktop/screensaverInterfaceImpl.cpp
@@ -0,0 +1,185 @@
+/*
+ * screensaverInterfaceImpl.cpp
+ *
+ *
+ * (C) 2024 Emanoil Kotsev
+ * deloptes (AT) gmail.com
+ *
+ * tdebase Copyright (C) 2009 tdebase development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "screensaverInterfaceImpl.h"
+
+ScreenSaverInterfaceImpl::ScreenSaverInterfaceImpl(TQT_DBusConnection &conn) :
+ m_connection(&conn),
+ m_ccount(1),
+ m_kdesktopdcoprefobj("kdesktop", "KScreensaverIface")
+{
+ isScreenSaverEnabled = screenSaverIsEnabled();
+ tqDebug(TQString("ScreenSaver isEnabled = %1").arg((isScreenSaverEnabled)?"yes":"no"));
+}
+
+ScreenSaverInterfaceImpl::~ScreenSaverInterfaceImpl()
+{
+}
+
+void ScreenSaverInterfaceImpl::restoreState()
+{
+ // restore the state
+ forceScreenSaver(isScreenSaverEnabled);
+}
+
+/*!
+ * Implement virtual methods
+ *
+ */
+void ScreenSaverInterfaceImpl::handleMethodReply(const TQT_DBusMessage& reply)
+{
+ m_connection->send(reply);
+}
+
+bool ScreenSaverInterfaceImpl::handleSignalSend(const TQT_DBusMessage& reply)
+{
+ return true;
+}
+
+TQString ScreenSaverInterfaceImpl::objectPath() const
+{
+ return TQString(DBUS_SCREENSAVER_SERVICE_PATH);
+}
+
+bool ScreenSaverInterfaceImpl::Lock(TQT_DBusError& dbuserror) {
+
+ DCOPReply reply = m_kdesktopdcoprefobj.call("lock");
+ if (!reply.isValid())
+ {
+ TQString e("ScreenSaverInterfaceImpl::Lock: there was some error using DCOP.");
+ tqDebug(e);
+ dbuserror = TQT_DBusError::stdFailed(e);
+ return false;
+ }
+ return true;
+}
+
+bool ScreenSaverInterfaceImpl::SimulateUserActivity(TQT_DBusError& dbuserror) {
+ tqDebug("SimulateUserActivity not implemented");
+ return true;
+}
+
+bool ScreenSaverInterfaceImpl::GetActive(bool& arg0, TQT_DBusError& dbuserror) {
+ tqDebug("GetActive not implemented");
+ return true;
+}
+
+bool ScreenSaverInterfaceImpl::GetActiveTime(TQ_UINT32& seconds, TQT_DBusError& dbuserror) {
+ tqDebug("GetActiveTime not implemented");
+ return true;
+}
+
+bool ScreenSaverInterfaceImpl::GetSessionIdleTime(TQ_UINT32& seconds, TQT_DBusError& dbuserror) {
+ tqDebug("GetSessionIdleTime not implemented");
+ return true;
+}
+
+bool ScreenSaverInterfaceImpl::SetActive(bool& arg0, bool e, TQT_DBusError& dbuserror) {
+ tqDebug("SetActive not implemented");
+ return true;
+}
+
+bool ScreenSaverInterfaceImpl::Inhibit(const TQString& application_name, const TQString& reason_for_inhibit, TQ_UINT32& cookie, TQT_DBusError& dbuserror) {
+
+ //this is to make sure we have the actual state - it could have been changed meanwhile
+ isScreenSaverEnabled = screenSaverIsEnabled();
+ if (isScreenSaverEnabled && m_cookies.isEmpty()) // disable only once
+ {
+ if (!forceScreenSaver(false))
+ {
+ dbuserror = TQT_DBusError::stdFailed(TQString("Failed to disable the screen saver"));
+ }
+ }
+
+ cookie=m_ccount++;
+ ScreenSaverInterfaceImpl::Pair v;
+ v.name = application_name;
+ v.value = reason_for_inhibit;
+ m_cookies[cookie] = v;
+ tqDebug(TQString("Inhibit: cookie(%1), application(%2), reason(%3)")
+ .arg(cookie)
+ .arg(m_cookies[cookie].name)
+ .arg(m_cookies[cookie].value).local8Bit());
+
+ return true;
+}
+
+bool ScreenSaverInterfaceImpl::UnInhibit(TQ_UINT32 cookie, TQT_DBusError& dbuserror) {
+ tqDebug(TQString("UnInhibit: cookie(%1), application(%2), reason(%3)")
+ .arg(cookie)
+ .arg(m_cookies[cookie].name)
+ .arg(m_cookies[cookie].value).local8Bit());
+
+ m_cookies.remove(cookie);
+ if (m_cookies.isEmpty())
+ {
+ // restore states when all applications finished
+ if (!forceScreenSaver(isScreenSaverEnabled))
+ {
+ dbuserror = TQT_DBusError::stdFailed(TQString("Failed to switch ScreenSaver %1!").arg(
+ (isScreenSaverEnabled) ? "on" : "off"));
+ }
+ }
+ return true;
+}
+
+bool ScreenSaverInterfaceImpl::Throttle(const TQString& application_name, const TQString& reason_for_inhibit, TQ_UINT32& cookie, TQT_DBusError& dbuserror) {
+ tqDebug("Throttle not implemented");
+ return true;
+}
+
+bool ScreenSaverInterfaceImpl::UnThrottle(TQ_UINT32 cookie, TQT_DBusError& dbuserror) {
+ tqDebug("UnThrottle not implemented");
+ return true;
+}
+
+bool ScreenSaverInterfaceImpl::screenSaverIsEnabled()
+{
+ DCOPReply reply = m_kdesktopdcoprefobj.call("isEnabled");
+ bool on = false;
+ if (!reply.isValid())
+ {
+ tqDebug("ScreenSaverInterfaceImpl::screenSaverIsEnabled(): there was some error using DCOP.");
+ }
+ else
+ {
+ if (!reply.get(on))
+ {
+ tqDebug("ScreenSaverInterfaceImpl::screenSaverIsEnabled(): there was some error getting the value from DCOPReply");
+ }
+ }
+ return on;
+}
+
+bool ScreenSaverInterfaceImpl::forceScreenSaver(bool on)
+{
+ DCOPReply reply = m_kdesktopdcoprefobj.call("enable", on);
+ if (!reply.isValid())
+ {
+ tqDebug(TQString("Failed to switch ScreenSaver %1!").arg((on) ? "on" : "off"));
+ return false;
+ }
+ return true;
+}
+// End of File
diff --git a/kdesktop/screensaverInterfaceImpl.h b/kdesktop/screensaverInterfaceImpl.h
new file mode 100644
index 000000000..0b79f1693
--- /dev/null
+++ b/kdesktop/screensaverInterfaceImpl.h
@@ -0,0 +1,204 @@
+/*
+ * screensaverInterfaceImpl.h
+ *
+ * (C) 2024 Emanoil Kotsev
+ * deloptes (AT) gmail.com
+ *
+ * tdebase Copyright (C) 2009 tdebase development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifndef KDESKTOP_SCREENSAVERINTERFACEIMPL_H_
+#define KDESKTOP_SCREENSAVERINTERFACEIMPL_H_
+
+#include <dcopref.h>
+#include <tqpair.h>
+#include <tqmap.h>
+#include <tqdbusconnection.h>
+
+#include "dbus/screensaver/screensaverInterface.h"
+
+#define DBUS_SCREENSAVER_SERVICE "TDEDbusScreenSaver"
+#define DBUS_SCREENSAVER_SERVICE_NAME "org.freedesktop.ScreenSaver"
+#define DBUS_SCREENSAVER_SERVICE_PATH "/org/freedesktop/ScreenSaver"
+
+class ScreenSaverInterfaceImpl : public org::freedesktop::ScreenSaverInterface
+{
+ /**
+ *
+ * Idle inhibition is achieved by the application calling an Inhibit method on a well-known D-Bus name.
+ *
+ * Inhibition will stop when the UnInhibit method is called, or the application disconnects from the
+ * D-Bus session bus (which usually happens upon exit).
+ * Implementations of this well-known bus name must have an object /org/freedesktop/ScreenSaver which
+ * implements the org.freedesktop.ScreenSaver interface.
+ *
+ * https://specifications.freedesktop.org/idle-inhibit-spec/latest/ch03.html
+ */
+
+public:
+ ScreenSaverInterfaceImpl(TQT_DBusConnection&);
+ virtual ~ScreenSaverInterfaceImpl();
+
+ void restoreState();
+
+protected:
+ /**
+ * void Lock()
+ * This method gets called when the service daemon
+ * locks the screen
+ */
+ virtual bool Lock(TQT_DBusError& error);
+
+ /**
+ * Name: SimulateUserActivity
+ * Args: (none)
+ * Returns: (nothing)
+ * Description: Simulate use activity to prevent screen saver being spawned
+ *
+ * Not implemented
+ */
+ virtual bool SimulateUserActivity(TQT_DBusError& error);
+
+ /**
+ * Name: GetActive
+ * Args: (none)
+ * Returns: DBUS_TYPE_BOOLEAN
+ * Descriptions: Returns the value of the current state of activity.
+ * See setActive().
+ *
+ * Not implemented
+ */
+ virtual bool GetActive(bool& arg0, TQT_DBusError& error);
+
+ /**
+ * Name: GetActiveTime
+ * Args: (none)
+ * Returns: DBUS_TYPE_UINT32
+ * Descriptions: Returns the number of seconds that the screensaver has
+ * been active. Returns zero if the screensaver is not
+ * active.
+ *
+ * Not implemented
+ */
+ virtual bool GetActiveTime(TQ_UINT32& seconds, TQT_DBusError& error);
+
+ /**
+ *
+ * Name: GetSessionIdleTime
+ * Args: (none)
+ * Returns: DBUS_TYPE_UINT32
+ * Descriptions: Returns the number of seconds that the session has
+ * been idle. Returns zero if the session is not idle.
+ *
+ * Not implemented
+ */
+ virtual bool GetSessionIdleTime(TQ_UINT32& seconds, TQT_DBusError& error);
+
+ /**
+ * Name: SetActive
+ * Args: DBUS_TYPE_BOOLEAN state
+ * state: TRUE to request activation,
+ * FALSE to request deactivation
+ * Returns: (nothing)
+ * Description: Request a change in the state of the screensaver.
+ * Set to TRUE to request that the screensaver activate.
+ * Active means that the screensaver has blanked the
+ * screen and may run a graphical theme. This does
+ * not necessary mean that the screen is locked.
+ *
+ * Not implemented
+ */
+ virtual bool SetActive(bool& arg0, bool e, TQT_DBusError& error);
+
+ /**
+ *
+ * Name: Inhibit
+ * Args: DBUS_TYPE_STRING "application-name"
+ * A unique identifier for the application, usually a reverse domain
+ * (such as 'org.freedesktop.example').
+ * DBUS_TYPE_STRING "reason for inhibit"
+ * A human-readable and possibly translated string
+ * explaining the reason why idleness is inhibited
+ * (such as 'Playing a movie').
+ * Returns: INT cookie
+ * This is a random number used to identify the request.
+ * To be passed to UnInhibit when done.
+ * Description: Request that saving the screen due to system idleness
+ * be blocked until UnInhibit is called or the
+ * calling process exits.
+ *
+ * https://specifications.freedesktop.org/idle-inhibit-spec/latest/re01.html
+ * https://lists.freedesktop.org/archives/xdg/2007-March/009187.html
+ */
+
+ virtual bool Inhibit(const TQString& application_name, const TQString& reason_for_inhibit, TQ_UINT32& cookie, TQT_DBusError& error);
+
+ /**
+ *
+ * Name: UnInhibit
+ * Args: DBUS_TYPE_UINT32 cookie
+ * A cookie representing the inhibition request,
+ * as returned by the 'Inhibit' function.
+ * Returns: (nothing)
+ * Description: Cancel a previous call to Inhibit() identified by the cookie.
+ */
+ virtual bool UnInhibit(TQ_UINT32 cookie, TQT_DBusError& error);
+
+ /**
+ *
+ * Name: Throttle
+ * Args: DBUS_TYPE_STRING "application-name"
+ * DBUS_TYPE_STRING "reason for throttle"
+ * INT cookie
+ * This is a random number used to identify the request.
+ * Description: Request that running themes while the screensaver is
+ * active be blocked until UnThrottle is called or the
+ * calling process exits.
+ *
+ * Not implemented
+ */
+ virtual bool Throttle(const TQString& application_name, const TQString& reason_for_inhibit, TQ_UINT32& cookie, TQT_DBusError& error);
+
+ /**
+ * Name: UnThrottle
+ * Args: DBUS_TYPE_UINT32 cookie
+ * Returns: (nothing)
+ * Description: Cancel a previous call to Throttle() identified by the cookie.
+ * Not implemented
+ */
+ virtual bool UnThrottle(TQ_UINT32 cookie, TQT_DBusError& error);
+
+ virtual void handleMethodReply(const TQT_DBusMessage& reply);
+ virtual bool handleSignalSend(const TQT_DBusMessage& reply);
+ virtual TQString objectPath() const;
+
+private:
+ bool screenSaverIsEnabled();
+ bool forceScreenSaver(bool);
+
+ struct Pair {
+ TQString name;
+ TQString value;
+ };
+
+ TQT_DBusConnection *m_connection;
+ TQMap<TQ_UINT32,Pair> m_cookies;
+ TQ_UINT32 m_ccount;
+
+ DCOPRef m_kdesktopdcoprefobj;
+ bool isScreenSaverEnabled;
+};
+
+#endif /* KDESKTOP_SCREENSAVERINTERFACEIMPL_H_ */