From 790f526f18e7917e4c066112215e02e94fd628ac Mon Sep 17 00:00:00 2001 From: Emanoil Kotsev Date: Tue, 17 Dec 2024 22:19:42 +0000 Subject: Auto formatting main.cpp incl. dbus screen saver Signed-off-by: Emanoil Kotsev --- kdesktop/dbus/interfaces/CMakeLists.txt | 44 +++++ .../interfaces/org.freedesktop.ScreenSaver.xml | 41 +++++ .../interfaces/org.trinitydesktop.ScreenSaver.xml | 11 ++ kdesktop/dbus/screensaver/CMakeLists.txt | 44 ----- .../dbus/screensaver/dbusscreensaverservice.cpp | 171 +++++++++++++++++ kdesktop/dbus/screensaver/dbusscreensaverservice.h | 126 +++++++++++++ .../screensaver/org.freedesktop.ScreenSaver.xml | 41 ----- .../screensaver/org.trinitydesktop.ScreenSaver.xml | 11 -- .../dbus/screensaver/screensaverInterfaceImpl.cpp | 185 +++++++++++++++++++ .../dbus/screensaver/screensaverInterfaceImpl.h | 204 +++++++++++++++++++++ kdesktop/dbusscreensaverservice.cpp | 171 ----------------- kdesktop/dbusscreensaverservice.h | 126 ------------- kdesktop/main.cpp | 149 ++++++++------- kdesktop/screensaverInterfaceImpl.cpp | 185 ------------------- kdesktop/screensaverInterfaceImpl.h | 204 --------------------- 15 files changed, 855 insertions(+), 858 deletions(-) create mode 100644 kdesktop/dbus/interfaces/CMakeLists.txt create mode 100644 kdesktop/dbus/interfaces/org.freedesktop.ScreenSaver.xml create mode 100644 kdesktop/dbus/interfaces/org.trinitydesktop.ScreenSaver.xml delete mode 100644 kdesktop/dbus/screensaver/CMakeLists.txt create mode 100644 kdesktop/dbus/screensaver/dbusscreensaverservice.cpp create mode 100644 kdesktop/dbus/screensaver/dbusscreensaverservice.h delete mode 100644 kdesktop/dbus/screensaver/org.freedesktop.ScreenSaver.xml delete mode 100644 kdesktop/dbus/screensaver/org.trinitydesktop.ScreenSaver.xml create mode 100644 kdesktop/dbus/screensaver/screensaverInterfaceImpl.cpp create mode 100644 kdesktop/dbus/screensaver/screensaverInterfaceImpl.h delete mode 100644 kdesktop/dbusscreensaverservice.cpp delete mode 100644 kdesktop/dbusscreensaverservice.h delete mode 100644 kdesktop/screensaverInterfaceImpl.cpp delete mode 100644 kdesktop/screensaverInterfaceImpl.h diff --git a/kdesktop/dbus/interfaces/CMakeLists.txt b/kdesktop/dbus/interfaces/CMakeLists.txt new file mode 100644 index 000000000..9fb887326 --- /dev/null +++ b/kdesktop/dbus/interfaces/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/interfaces/org.freedesktop.ScreenSaver.xml b/kdesktop/dbus/interfaces/org.freedesktop.ScreenSaver.xml new file mode 100644 index 000000000..1f7b09b28 --- /dev/null +++ b/kdesktop/dbus/interfaces/org.freedesktop.ScreenSaver.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/kdesktop/dbus/interfaces/org.trinitydesktop.ScreenSaver.xml b/kdesktop/dbus/interfaces/org.trinitydesktop.ScreenSaver.xml new file mode 100644 index 000000000..cac5b2319 --- /dev/null +++ b/kdesktop/dbus/interfaces/org.trinitydesktop.ScreenSaver.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/kdesktop/dbus/screensaver/CMakeLists.txt b/kdesktop/dbus/screensaver/CMakeLists.txt deleted file mode 100644 index 9fb887326..000000000 --- a/kdesktop/dbus/screensaver/CMakeLists.txt +++ /dev/null @@ -1,44 +0,0 @@ -################################################# -# -# (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/dbusscreensaverservice.cpp b/kdesktop/dbus/screensaver/dbusscreensaverservice.cpp new file mode 100644 index 000000000..ba19a970a --- /dev/null +++ b/kdesktop/dbus/screensaver/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 +#include + +#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/dbus/screensaver/dbusscreensaverservice.h b/kdesktop/dbus/screensaver/dbusscreensaverservice.h new file mode 100644 index 000000000..d556f201d --- /dev/null +++ b/kdesktop/dbus/screensaver/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 +#include + +#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 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 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 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 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/dbus/screensaver/org.freedesktop.ScreenSaver.xml b/kdesktop/dbus/screensaver/org.freedesktop.ScreenSaver.xml deleted file mode 100644 index 1f7b09b28..000000000 --- a/kdesktop/dbus/screensaver/org.freedesktop.ScreenSaver.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/kdesktop/dbus/screensaver/org.trinitydesktop.ScreenSaver.xml b/kdesktop/dbus/screensaver/org.trinitydesktop.ScreenSaver.xml deleted file mode 100644 index cac5b2319..000000000 --- a/kdesktop/dbus/screensaver/org.trinitydesktop.ScreenSaver.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/kdesktop/dbus/screensaver/screensaverInterfaceImpl.cpp b/kdesktop/dbus/screensaver/screensaverInterfaceImpl.cpp new file mode 100644 index 000000000..4f05a8391 --- /dev/null +++ b/kdesktop/dbus/screensaver/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/dbus/screensaver/screensaverInterfaceImpl.h b/kdesktop/dbus/screensaver/screensaverInterfaceImpl.h new file mode 100644 index 000000000..0b79f1693 --- /dev/null +++ b/kdesktop/dbus/screensaver/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 +#include +#include +#include + +#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 m_cookies; + TQ_UINT32 m_ccount; + + DCOPRef m_kdesktopdcoprefobj; + bool isScreenSaverEnabled; +}; + +#endif /* KDESKTOP_SCREENSAVERINTERFACEIMPL_H_ */ diff --git a/kdesktop/dbusscreensaverservice.cpp b/kdesktop/dbusscreensaverservice.cpp deleted file mode 100644 index ba19a970a..000000000 --- a/kdesktop/dbusscreensaverservice.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/* - * 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 -#include - -#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 deleted file mode 100644 index d556f201d..000000000 --- a/kdesktop/dbusscreensaverservice.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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 -#include - -#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 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 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 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 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 75038d0c9..71df2ac47 100644 --- a/kdesktop/main.cpp +++ b/kdesktop/main.cpp @@ -1,21 +1,21 @@ /* This file is part of the KDE project - Copyright (C) 1999 David Faure (maintainer) + Copyright (C) 1999 David Faure (maintainer) - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. - This library 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 - Library General Public License for more details. + This library 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 + Library General Public License for more details. - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + */ #include #include @@ -37,7 +37,7 @@ #include "krootwm.h" #include "kdesktopsettings.h" #include "kdesktopapp.h" -#include "dbusscreensaverservice.h" +#include "dbus/screensaver/dbusscreensaverservice.h" #include #include @@ -55,20 +55,19 @@ # include #endif -static const char description[] = - I18N_NOOP("The TDE desktop"); +static const char description[] = I18N_NOOP("The TDE desktop"); static const char version[] = VERSION; static TDECmdLineOptions options[] = { - { "x-root", I18N_NOOP("Use this if the desktop window appears as a real window"), 0 }, - { "noautostart", I18N_NOOP("Obsolete"), 0 }, - { "waitforkded", I18N_NOOP("Wait for kded to finish building database"), 0 }, + { "x-root", I18N_NOOP("Use this if the desktop window appears as a real window"), 0 }, + { "noautostart", I18N_NOOP("Obsolete"), 0 }, + { "waitforkded", I18N_NOOP("Wait for kded to finish building database"), 0 }, #ifdef COMPOSITE - { "bg-transparency", I18N_NOOP("Enable background transparency"), 0 }, + { "bg-transparency", I18N_NOOP("Enable background transparency"), 0}, #endif - TDECmdLineLastOption + TDECmdLineLastOption }; bool argb_visual = false; @@ -82,7 +81,7 @@ TQCString kdesktop_name, kicker_name, twin_name; static void crashHandler(int sigId) { DCOPClient::emergencyClose(); // unregister DCOP - sleep( 1 ); + sleep(1); system("kdesktop &"); // try to restart fprintf(stderr, "*** kdesktop (%ld) got signal %d\n", (long) getpid(), sigId); ::exit(1); @@ -94,7 +93,7 @@ static void signalHandler(int sigId) TDECrash::setEmergencySaveFunction(0); // No restarts any more // try to cleanup all windows signal(SIGTERM, SIG_DFL); // next one kills - signal(SIGHUP, SIG_DFL); // next one kills + signal(SIGHUP, SIG_DFL); // next one kills if (kapp) kapp->quit(); // turn catchable signals into clean shutdown } @@ -106,21 +105,20 @@ void KDesktop::slotUpAndRunning() TDECrash::setEmergencySaveFunction(crashHandler); // Try to restart on crash } -extern "C" TDE_EXPORT int kdemain( int argc, char **argv ) +extern "C" TDE_EXPORT int kdemain(int argc, char **argv) { //setup signal handling signal(SIGTERM, signalHandler); - signal(SIGHUP, signalHandler); + signal(SIGHUP, signalHandler); { 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); + 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); @@ -131,26 +129,27 @@ extern "C" TDE_EXPORT int kdemain( int argc, char **argv ) 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; + 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); + 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]); + if (putenv(strdup(env.data()))) + { + fprintf(stderr, "%s: WARNING: unable to set DISPLAY environment variable\n", argv[0]); perror("putenv()"); } } @@ -159,19 +158,20 @@ extern "C" TDE_EXPORT int kdemain( int argc, char **argv ) TDEGlobal::locale()->setMainCatalogue("kdesktop"); - if (kdesktop_screen_number == 0) { + if (kdesktop_screen_number == 0) + { kdesktop_name = "kdesktop"; kicker_name = "kicker"; twin_name = "twin"; - } else { + } + else + { kdesktop_name.sprintf("kdesktop-screen-%d", kdesktop_screen_number); kicker_name.sprintf("kicker-screen-%d", kdesktop_screen_number); twin_name.sprintf("twin-screen-%d", kdesktop_screen_number); } - TDEAboutData aboutData( kdesktop_name, I18N_NOOP("KDesktop"), - version, description, TDEAboutData::License_GPL, - "(c) 1998-2000, The KDesktop Authors"); + TDEAboutData aboutData(kdesktop_name, I18N_NOOP("KDesktop"), version, description, TDEAboutData::License_GPL, "(c) 1998-2000, The KDesktop Authors"); aboutData.addAuthor("David Faure", 0, "faure@kde.org"); aboutData.addAuthor("Martin Koller", 0, "m.koller@surfeu.at"); aboutData.addAuthor("Waldo Bastian", 0, "bastian@kde.org"); @@ -182,18 +182,19 @@ extern "C" TDE_EXPORT int kdemain( int argc, char **argv ) aboutData.addAuthor("Torben Weis", 0, "weis@kde.org"); aboutData.addAuthor("Matthias Ettrich", 0, "ettrich@kde.org"); - TDECmdLineArgs::init( argc, argv, &aboutData ); - TDECmdLineArgs::addCmdLineOptions( options ); + TDECmdLineArgs::init(argc, argv, &aboutData); + TDECmdLineArgs::addCmdLineOptions(options); - if (!TDEUniqueApplication::start()) { + if (!TDEUniqueApplication::start()) + { fprintf(stderr, "kdesktop is already running!\n"); exit(0); } - DCOPClient* cl = new DCOPClient; + DCOPClient *cl = new DCOPClient; cl->attach(); - DCOPRef r( "ksmserver", "ksmserver" ); - r.setDCOPClient( cl ); - r.send( "suspendStartup", TQCString( "kdesktop" )); + DCOPRef r("ksmserver", "ksmserver"); + r.setDCOPClient(cl); + r.send("suspendStartup", TQCString("kdesktop")); delete cl; TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); @@ -224,12 +225,10 @@ extern "C" TDE_EXPORT int kdemain( int argc, char **argv ) templ.screen = screen; templ.depth = 32; templ.c_class = TrueColor; - XVisualInfo *xvi = XGetVisualInfo( dpy, VisualScreenMask - | VisualDepthMask | VisualClassMask, &templ, &nvi ); + XVisualInfo *xvi = XGetVisualInfo( dpy, VisualScreenMask | VisualDepthMask | VisualClassMask, &templ, &nvi ); for ( int i = 0; i < nvi; i++ ) { - XRenderPictFormat *format = - XRenderFindVisualFormat( dpy, xvi[i].visual ); + XRenderPictFormat *format = XRenderFindVisualFormat( dpy, xvi[i].visual ); if ( format->type == PictTypeDirect && format->direct.alphaMask ) { visual = xvi[i].visual; kdDebug() << "[kdesktop] Found visual with alpha support" << endl; @@ -242,8 +241,7 @@ extern "C" TDE_EXPORT int kdemain( int argc, char **argv ) // as the primary toolkit (e.g. Motif apps also using Qt), with some slightly // unpleasant side effects (e.g. #83974). This code checks if qt-copy patch #0078 // is applied, which allows turning this off. - bool* qt_no_foreign_hack = - static_cast< bool* >( dlsym( RTLD_DEFAULT, "qt_no_foreign_hack" )); + bool* qt_no_foreign_hack = static_cast< bool* >( dlsym( RTLD_DEFAULT, "qt_no_foreign_hack" )); if( qt_no_foreign_hack ) *qt_no_foreign_hack = true; // else argb_visual = false ... ? *shrug* @@ -273,28 +271,27 @@ extern "C" TDE_EXPORT int kdemain( int argc, char **argv ) testLocalInstallation(); // Mark kdeskop as immutable if all of its config modules have been disabled - if (!myApp->config()->isImmutable() && - kapp->authorizeControlModules(KRootWm::configModules()).isEmpty()) + if (!myApp->config()->isImmutable() && kapp->authorizeControlModules(KRootWm::configModules()).isEmpty()) { - myApp->config()->setReadOnly(true); - myApp->config()->reparseConfiguration(); + myApp->config()->setReadOnly(true); + myApp->config()->reparseConfiguration(); } // for the KDE-already-running check in starttde - TDESelectionOwner kde_running( "_KDE_RUNNING", 0 ); - kde_running.claim( false ); + TDESelectionOwner kde_running("_KDE_RUNNING", 0); + kde_running.claim(false); - KDesktop desktop( &saver, x_root_hack, wait_for_kded ); + KDesktop desktop(&saver, x_root_hack, wait_for_kded); args->clear(); - myApp->dcopClient()->setDefaultObject( "KDesktopIface" ); + 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"); + 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 deleted file mode 100644 index 4f05a8391..000000000 --- a/kdesktop/screensaverInterfaceImpl.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/* - * 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 deleted file mode 100644 index 0b79f1693..000000000 --- a/kdesktop/screensaverInterfaceImpl.h +++ /dev/null @@ -1,204 +0,0 @@ -/* - * 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 -#include -#include -#include - -#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 m_cookies; - TQ_UINT32 m_ccount; - - DCOPRef m_kdesktopdcoprefobj; - bool isScreenSaverEnabled; -}; - -#endif /* KDESKTOP_SCREENSAVERINTERFACEIMPL_H_ */ -- cgit v1.2.1