From 06b225fe1e590a45acd75464dd40592d73e87608 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Mon, 9 Sep 2024 18:32:08 +0900 Subject: kcontrol touchpad: rename syndaemon to tdesyndaemon Signed-off-by: Michele Calgaro --- doc/kcontrol/touchpad/index.docbook | 4 +- kcontrol/input/CMakeLists.txt | 6 +- kcontrol/input/syndaemon.cpp | 201 ----------------------------------- kcontrol/input/syndaemon.h | 78 -------------- kcontrol/input/syndaemon_iface.h | 34 ------ kcontrol/input/tdesyndaemon.cpp | 201 +++++++++++++++++++++++++++++++++++ kcontrol/input/tdesyndaemon.h | 78 ++++++++++++++ kcontrol/input/tdesyndaemon_iface.h | 34 ++++++ kcontrol/input/touchpad_settings.cpp | 10 +- 9 files changed, 323 insertions(+), 323 deletions(-) delete mode 100644 kcontrol/input/syndaemon.cpp delete mode 100644 kcontrol/input/syndaemon.h delete mode 100644 kcontrol/input/syndaemon_iface.h create mode 100644 kcontrol/input/tdesyndaemon.cpp create mode 100644 kcontrol/input/tdesyndaemon.h create mode 100644 kcontrol/input/tdesyndaemon_iface.h diff --git a/doc/kcontrol/touchpad/index.docbook b/doc/kcontrol/touchpad/index.docbook index 328e8c1fd..800090af3 100644 --- a/doc/kcontrol/touchpad/index.docbook +++ b/doc/kcontrol/touchpad/index.docbook @@ -391,7 +391,7 @@ method. On-button scrolling converts the motion of a device into scroll events w -* Synaptics supported using external syndaemon service, automatically started/stopped. +* Synaptics supported using external tdesyndaemon service, automatically started/stopped. ** Not configurable with the Synaptics driver. *** Disabling vertical scrolling under the Libinput driver disables scrolling entirely. @@ -399,4 +399,4 @@ method. On-button scrolling converts the motion of a device into scroll events w - \ No newline at end of file + diff --git a/kcontrol/input/CMakeLists.txt b/kcontrol/input/CMakeLists.txt index 81d4a2384..9cf3248d5 100644 --- a/kcontrol/input/CMakeLists.txt +++ b/kcontrol/input/CMakeLists.txt @@ -69,11 +69,11 @@ tde_add_kpart( kcm_input AUTOMOC ) -##### syndaemon (executable) #################### +##### tdesyndaemon (executable) #################### -tde_add_executable( syndaemon AUTOMOC +tde_add_executable( tdesyndaemon AUTOMOC SOURCES - syndaemon.cpp syndaemon_iface.skel + tdesyndaemon.cpp tdesyndaemon_iface.skel touchpad_settings.cpp LINK tdecore-shared ${XINPUT_LIBRARIES} DESTINATION ${BIN_INSTALL_DIR} diff --git a/kcontrol/input/syndaemon.cpp b/kcontrol/input/syndaemon.cpp deleted file mode 100644 index 53d8346ca..000000000 --- a/kcontrol/input/syndaemon.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/******************************************************************************* - syndaemon - daemon for the Synaptics touchpad driver which disables touchpad - on keyboard input - - Copyright © 2004 Nadeem Hasan - Stefan Kombrink - 2024 Mavridis Philippe - - This program is free software: you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free Software - Foundation, either version 3 of the License, or (at your option) any later - version. - - 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, see . - -*******************************************************************************/ - -// TQt -#include -#include - -// TDE -#include -#include -#include -#include -#include -#include - -// DCOP -#include - -// tdecm_touchpad -#include "touchpad_settings.h" - -// SynDaemon -#include "syndaemon.h" -#include "syndaemon.moc" - -const unsigned int SynDaemon::TIME_OUT = 150; -const unsigned int SynDaemon::POLL_INTERVAL = 100; -const unsigned int SynDaemon::KEYMAP_SIZE = 32; - -unsigned char* SynDaemon::m_keyboard_mask; - -SynDaemon::SynDaemon() : DCOPObject("syndaemon"), TQObject() -{ - m_typing = false; - m_time = new TQTime(); - d_settings = new TouchpadSettings; - - m_keyboard_mask = new unsigned char[ KEYMAP_SIZE ]; - - // open a connection to the X server - m_display = XOpenDisplay(NULL); - - if (!m_display) kdError() << "Can't open display!" << endl; - - // setup keymap - XModifierKeymap *modifiers; - - for (unsigned int i = 0; i < KEYMAP_SIZE; ++i) - m_keyboard_mask[i] = 0xFF; - - modifiers = XGetModifierMapping(m_display); - for (int i = 0; i < 8 * modifiers->max_keypermod; ++i) - { - KeyCode kc = modifiers->modifiermap[i]; - if (kc != 0) clearBit(m_keyboard_mask, kc); - } - - XFreeModifiermap(modifiers); - - m_poll = new TQTimer(this); - connect(m_poll, TQ_SIGNAL(timeout()), this, TQ_SLOT(poll())); - m_poll->start(POLL_INTERVAL); -} - -SynDaemon::~SynDaemon() -{ - setTouchpadOn(true); - m_poll->stop(); - delete m_keyboard_mask; -} - -void SynDaemon::stop() -{ - kapp->quit(); -} - -void SynDaemon::poll() -{ - // do nothing if the user has explicitly disabled the touchpad in the settings - if (!touchpadEnabled()) return; - - if (hasKeyboardActivity()) - { - m_time->start(); - - if (!m_typing) - { - setTouchpadOn(false); - } - } - - else - { - if (m_typing && (m_time->elapsed() > TIME_OUT)) - { - setTouchpadOn(true); - } - } -} - -bool SynDaemon::touchpadEnabled() -{ - // We can't read from our own TouchpadSettings - // as it contains the currently applied value - // so we revert to this - KSimpleConfig cfg("kcminputrc"); - cfg.setGroup("Touchpad"); - return cfg.readBoolEntry("Enabled", true); -} - -void SynDaemon::setTouchpadOn(bool on) -{ - m_typing = !on; - if (!d_settings->setTouchpadEnabled(on)) - { - kdWarning() << "unable to turn off touchpad!" << endl; - } -} - -void SynDaemon::clearBit(unsigned char *ptr, int bit) -{ - int byteNum = bit / 8; - int bitNum = bit % 8; - ptr[byteNum] &= ~(1 << bitNum); -} - -bool SynDaemon::hasKeyboardActivity() -{ - static unsigned char oldKeyState[KEYMAP_SIZE]; - unsigned char keyState[KEYMAP_SIZE]; - - bool result = false; - - XQueryKeymap(m_display, (char*)keyState); - - // find pressed keys - for (unsigned int i = 0; i < KEYMAP_SIZE; ++i) - { - if ((keyState[i] & ~oldKeyState[i]) & m_keyboard_mask[i]) - { - result = true; - break; - } - } - - // ignore any modifiers - for (unsigned int i = 0; i < KEYMAP_SIZE; ++i) - { - if (keyState[i] & ~m_keyboard_mask[i]) - { - result = false; - break; - } - } - - // back up key states... - for (unsigned int i = 0; i < KEYMAP_SIZE; ++i) - { - oldKeyState[i] = keyState[i]; - } - - return result; -} - -extern "C" TDE_EXPORT int main(int argc, char *argv[]) -{ - TDEAboutData aboutData( "syndaemon", I18N_NOOP("Synaptics helper daemon"), - "0.1", I18N_NOOP("Synaptics helper daemon"), TDEAboutData::License_GPL_V2, - "© 2024 Mavridis Philippe" ); - - aboutData.addAuthor("Nadeem Hasan", I18N_NOOP("Author"), "nhasan@kde.org"); - aboutData.addAuthor("Mavridis Philippe", I18N_NOOP("Author"), "mavridisf@gmail.com"); - - TDECmdLineArgs::init(argc, argv, &aboutData); - - TDEApplication app; - app.disableSessionManagement(); - app.dcopClient()->registerAs("syndaemon", false); - - SynDaemon syndaemon; - return app.exec(); -} \ No newline at end of file diff --git a/kcontrol/input/syndaemon.h b/kcontrol/input/syndaemon.h deleted file mode 100644 index 0556345eb..000000000 --- a/kcontrol/input/syndaemon.h +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - syndaemon - daemon for the Synaptics touchpad driver which disables touchpad - on keyboard input - - Copyright © 2004 Nadeem Hasan - Stefan Kombrink - 2024 Mavridis Philippe - - This program is free software: you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free Software - Foundation, either version 3 of the License, or (at your option) any later - version. - - 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, see . - -*******************************************************************************/ - -#ifndef __SYNDAEMON_H__ -#define __SYNDAEMON_H__ - -// TQt -#include -#include - -// DCOP -#include - -// X11 -#include -#undef Bool /* fix problems in --enable-final mode */ -#undef None /* fix problems in --enable-final mode */ - -// Syndaemon -#include "syndaemon_iface.h" - - -class TQTimer; - -class SynDaemon : public TQObject, public virtual SynDaemonIface -{ - TQ_OBJECT - - public: - SynDaemon(); - ~SynDaemon(); - - bool touchpadEnabled(); - - public slots: - void poll(); - void setTouchpadOn(bool on); - virtual void stop(); - - protected: - void clearBit(unsigned char* ptr, int bit); - bool hasKeyboardActivity(); - - private: - TouchpadSettings *d_settings; - - TQTimer *m_poll; - TQTime *m_time; - Display *m_display; - bool m_typing; - - static const unsigned int POLL_INTERVAL; - static const unsigned int TIME_OUT; - static const unsigned int KEYMAP_SIZE; - static unsigned char *m_keyboard_mask; -}; - -#endif - diff --git a/kcontrol/input/syndaemon_iface.h b/kcontrol/input/syndaemon_iface.h deleted file mode 100644 index 0f3d33929..000000000 --- a/kcontrol/input/syndaemon_iface.h +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - syndaemon - daemon for the Synaptics touchpad driver which disables touchpad - on keyboard input - - Copyright © 2024 Mavridis Philippe - - This program is free software: you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free Software - Foundation, either version 3 of the License, or (at your option) any later - version. - - 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, see . - -*******************************************************************************/ - -#ifndef __SYNDAEMON_IFACE_H__ -#define __SYNDAEMON_IFACE_H__ - -// DCOP -#include - -class SynDaemonIface : virtual public DCOPObject -{ - K_DCOP - k_dcop: - virtual void stop() = 0; -}; - -#endif \ No newline at end of file diff --git a/kcontrol/input/tdesyndaemon.cpp b/kcontrol/input/tdesyndaemon.cpp new file mode 100644 index 000000000..46b6d1c92 --- /dev/null +++ b/kcontrol/input/tdesyndaemon.cpp @@ -0,0 +1,201 @@ +/******************************************************************************* + tdesyndaemon - daemon for the Synaptics touchpad driver which disables touchpad + on keyboard input + + Copyright © 2004 Nadeem Hasan + Stefan Kombrink + 2024 Mavridis Philippe + + This program is free software: you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free Software + Foundation, either version 3 of the License, or (at your option) any later + version. + + 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, see . + +*******************************************************************************/ + +// TQt +#include +#include + +// TDE +#include +#include +#include +#include +#include +#include + +// DCOP +#include + +// tdecm_touchpad +#include "touchpad_settings.h" + +// TDESynDaemon +#include "tdesyndaemon.h" +#include "tdesyndaemon.moc" + +const unsigned int TDESynDaemon::TIME_OUT = 150; +const unsigned int TDESynDaemon::POLL_INTERVAL = 100; +const unsigned int TDESynDaemon::KEYMAP_SIZE = 32; + +unsigned char* TDESynDaemon::m_keyboard_mask; + +TDESynDaemon::TDESynDaemon() : DCOPObject("tdesyndaemon"), TQObject() +{ + m_typing = false; + m_time = new TQTime(); + d_settings = new TouchpadSettings; + + m_keyboard_mask = new unsigned char[ KEYMAP_SIZE ]; + + // open a connection to the X server + m_display = XOpenDisplay(NULL); + + if (!m_display) kdError() << "Can't open display!" << endl; + + // setup keymap + XModifierKeymap *modifiers; + + for (unsigned int i = 0; i < KEYMAP_SIZE; ++i) + m_keyboard_mask[i] = 0xFF; + + modifiers = XGetModifierMapping(m_display); + for (int i = 0; i < 8 * modifiers->max_keypermod; ++i) + { + KeyCode kc = modifiers->modifiermap[i]; + if (kc != 0) clearBit(m_keyboard_mask, kc); + } + + XFreeModifiermap(modifiers); + + m_poll = new TQTimer(this); + connect(m_poll, TQ_SIGNAL(timeout()), this, TQ_SLOT(poll())); + m_poll->start(POLL_INTERVAL); +} + +TDESynDaemon::~TDESynDaemon() +{ + setTouchpadOn(true); + m_poll->stop(); + delete m_keyboard_mask; +} + +void TDESynDaemon::stop() +{ + kapp->quit(); +} + +void TDESynDaemon::poll() +{ + // do nothing if the user has explicitly disabled the touchpad in the settings + if (!touchpadEnabled()) return; + + if (hasKeyboardActivity()) + { + m_time->start(); + + if (!m_typing) + { + setTouchpadOn(false); + } + } + + else + { + if (m_typing && (m_time->elapsed() > TIME_OUT)) + { + setTouchpadOn(true); + } + } +} + +bool TDESynDaemon::touchpadEnabled() +{ + // We can't read from our own TouchpadSettings + // as it contains the currently applied value + // so we revert to this + KSimpleConfig cfg("kcminputrc"); + cfg.setGroup("Touchpad"); + return cfg.readBoolEntry("Enabled", true); +} + +void TDESynDaemon::setTouchpadOn(bool on) +{ + m_typing = !on; + if (!d_settings->setTouchpadEnabled(on)) + { + kdWarning() << "unable to turn off touchpad!" << endl; + } +} + +void TDESynDaemon::clearBit(unsigned char *ptr, int bit) +{ + int byteNum = bit / 8; + int bitNum = bit % 8; + ptr[byteNum] &= ~(1 << bitNum); +} + +bool TDESynDaemon::hasKeyboardActivity() +{ + static unsigned char oldKeyState[KEYMAP_SIZE]; + unsigned char keyState[KEYMAP_SIZE]; + + bool result = false; + + XQueryKeymap(m_display, (char*)keyState); + + // find pressed keys + for (unsigned int i = 0; i < KEYMAP_SIZE; ++i) + { + if ((keyState[i] & ~oldKeyState[i]) & m_keyboard_mask[i]) + { + result = true; + break; + } + } + + // ignore any modifiers + for (unsigned int i = 0; i < KEYMAP_SIZE; ++i) + { + if (keyState[i] & ~m_keyboard_mask[i]) + { + result = false; + break; + } + } + + // back up key states... + for (unsigned int i = 0; i < KEYMAP_SIZE; ++i) + { + oldKeyState[i] = keyState[i]; + } + + return result; +} + +extern "C" TDE_EXPORT int main(int argc, char *argv[]) +{ + TDEAboutData aboutData( "tdesyndaemon", I18N_NOOP("TDE Synaptics helper daemon"), + "0.1", I18N_NOOP("TDE Synaptics helper daemon"), TDEAboutData::License_GPL_V2, + "© 2024 Mavridis Philippe" ); + + aboutData.addAuthor("Nadeem Hasan", I18N_NOOP("Author"), "nhasan@kde.org"); + aboutData.addAuthor("Mavridis Philippe", I18N_NOOP("Author"), "mavridisf@gmail.com"); + + TDECmdLineArgs::init(argc, argv, &aboutData); + + TDEApplication app; + app.disableSessionManagement(); + app.dcopClient()->registerAs("tdesyndaemon", false); + + TDESynDaemon tdesyndaemon; + return app.exec(); +} diff --git a/kcontrol/input/tdesyndaemon.h b/kcontrol/input/tdesyndaemon.h new file mode 100644 index 000000000..47b799284 --- /dev/null +++ b/kcontrol/input/tdesyndaemon.h @@ -0,0 +1,78 @@ +/******************************************************************************* + tdesyndaemon - daemon for the Synaptics touchpad driver which disables touchpad + on keyboard input + + Copyright © 2004 Nadeem Hasan + Stefan Kombrink + 2024 Mavridis Philippe + + This program is free software: you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free Software + Foundation, either version 3 of the License, or (at your option) any later + version. + + 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, see . + +*******************************************************************************/ + +#ifndef __TDESYNDAEMON_H__ +#define __TDESYNDAEMON_H__ + +// TQt +#include +#include + +// DCOP +#include + +// X11 +#include +#undef Bool /* fix problems in --enable-final mode */ +#undef None /* fix problems in --enable-final mode */ + +// TDESynDaemon +#include "tdesyndaemon_iface.h" + + +class TQTimer; + +class TDESynDaemon : public TQObject, public virtual TDESynDaemonIface +{ + TQ_OBJECT + + public: + TDESynDaemon(); + ~TDESynDaemon(); + + bool touchpadEnabled(); + + public slots: + void poll(); + void setTouchpadOn(bool on); + virtual void stop(); + + protected: + void clearBit(unsigned char* ptr, int bit); + bool hasKeyboardActivity(); + + private: + TouchpadSettings *d_settings; + + TQTimer *m_poll; + TQTime *m_time; + Display *m_display; + bool m_typing; + + static const unsigned int POLL_INTERVAL; + static const unsigned int TIME_OUT; + static const unsigned int KEYMAP_SIZE; + static unsigned char *m_keyboard_mask; +}; + +#endif + diff --git a/kcontrol/input/tdesyndaemon_iface.h b/kcontrol/input/tdesyndaemon_iface.h new file mode 100644 index 000000000..68dc8a387 --- /dev/null +++ b/kcontrol/input/tdesyndaemon_iface.h @@ -0,0 +1,34 @@ +/******************************************************************************* + tdesyndaemon - daemon for the Synaptics touchpad driver which disables touchpad + on keyboard input + + Copyright © 2024 Mavridis Philippe + + This program is free software: you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free Software + Foundation, either version 3 of the License, or (at your option) any later + version. + + 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, see . + +*******************************************************************************/ + +#ifndef __TDESYNDAEMON_IFACE_H__ +#define __TDESYNDAEMON_IFACE_H__ + +// DCOP +#include + +class TDESynDaemonIface : virtual public DCOPObject +{ + K_DCOP + k_dcop: + virtual void stop() = 0; +}; + +#endif diff --git a/kcontrol/input/touchpad_settings.cpp b/kcontrol/input/touchpad_settings.cpp index 1230efcee..ff15e4c21 100644 --- a/kcontrol/input/touchpad_settings.cpp +++ b/kcontrol/input/touchpad_settings.cpp @@ -339,13 +339,13 @@ void TouchpadSettings::apply(bool force) prop->set(); } - // start/stop syndaemon - DCOPRef syndaemon("syndaemon", "syndaemon"); - syndaemon.call("stop()"); + // start/stop tdesyndaemon + DCOPRef tdesyndaemon("tdesyndaemon", "tdesyndaemon"); + tdesyndaemon.call("stop()"); if (offWhileTyping) { - kapp->tdeinitExec("syndaemon"); + kapp->tdeinitExec("tdesyndaemon"); } } @@ -406,4 +406,4 @@ bool TouchpadSettings::foundTouchpad() bool TouchpadSettings::supportedTouchpad() { return m_foundTouchpad && m_touchpad.driver != Touchpad::Driver::None; -} \ No newline at end of file +} -- cgit v1.2.1