You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
202 lines
5.1 KiB
202 lines
5.1 KiB
6 months ago
|
/*******************************************************************************
|
||
2 months ago
|
tdesyndaemon - daemon for the Synaptics touchpad driver which disables touchpad
|
||
|
on keyboard input
|
||
6 months ago
|
|
||
|
Copyright © 2004 Nadeem Hasan <nhasan@kde.org>
|
||
|
Stefan Kombrink <katakombi@web.de>
|
||
|
2024 Mavridis Philippe <mavridisf@gmail.com>
|
||
|
|
||
|
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 <https://www.gnu.org/licenses/>.
|
||
|
|
||
|
*******************************************************************************/
|
||
|
|
||
|
// TQt
|
||
|
#include <tqdatetime.h>
|
||
|
#include <tqtimer.h>
|
||
|
|
||
|
// TDE
|
||
|
#include <ksimpleconfig.h>
|
||
|
#include <tdecmdlineargs.h>
|
||
|
#include <kuniqueapplication.h>
|
||
|
#include <tdeaboutdata.h>
|
||
|
#include <tdelocale.h>
|
||
|
#include <kdebug.h>
|
||
|
|
||
|
// DCOP
|
||
|
#include <dcopclient.h>
|
||
|
|
||
|
// tdecm_touchpad
|
||
|
#include "touchpad_settings.h"
|
||
|
|
||
2 months ago
|
// TDESynDaemon
|
||
|
#include "tdesyndaemon.h"
|
||
|
#include "tdesyndaemon.moc"
|
||
6 months ago
|
|
||
2 months ago
|
const unsigned int TDESynDaemon::TIME_OUT = 150;
|
||
|
const unsigned int TDESynDaemon::POLL_INTERVAL = 100;
|
||
|
const unsigned int TDESynDaemon::KEYMAP_SIZE = 32;
|
||
6 months ago
|
|
||
2 months ago
|
unsigned char* TDESynDaemon::m_keyboard_mask;
|
||
6 months ago
|
|
||
2 months ago
|
TDESynDaemon::TDESynDaemon() : DCOPObject("tdesyndaemon"), TQObject()
|
||
6 months ago
|
{
|
||
|
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);
|
||
|
}
|
||
|
|
||
2 months ago
|
TDESynDaemon::~TDESynDaemon()
|
||
6 months ago
|
{
|
||
|
setTouchpadOn(true);
|
||
|
m_poll->stop();
|
||
|
delete m_keyboard_mask;
|
||
|
}
|
||
|
|
||
2 months ago
|
void TDESynDaemon::stop()
|
||
6 months ago
|
{
|
||
|
kapp->quit();
|
||
|
}
|
||
|
|
||
2 months ago
|
void TDESynDaemon::poll()
|
||
6 months ago
|
{
|
||
|
// 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);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
2 months ago
|
bool TDESynDaemon::touchpadEnabled()
|
||
6 months ago
|
{
|
||
|
// 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);
|
||
|
}
|
||
|
|
||
2 months ago
|
void TDESynDaemon::setTouchpadOn(bool on)
|
||
6 months ago
|
{
|
||
|
m_typing = !on;
|
||
|
if (!d_settings->setTouchpadEnabled(on))
|
||
|
{
|
||
|
kdWarning() << "unable to turn off touchpad!" << endl;
|
||
|
}
|
||
|
}
|
||
|
|
||
2 months ago
|
void TDESynDaemon::clearBit(unsigned char *ptr, int bit)
|
||
6 months ago
|
{
|
||
|
int byteNum = bit / 8;
|
||
|
int bitNum = bit % 8;
|
||
|
ptr[byteNum] &= ~(1 << bitNum);
|
||
|
}
|
||
|
|
||
2 months ago
|
bool TDESynDaemon::hasKeyboardActivity()
|
||
6 months ago
|
{
|
||
|
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[])
|
||
|
{
|
||
2 months ago
|
TDEAboutData aboutData( "tdesyndaemon", I18N_NOOP("TDE Synaptics helper daemon"),
|
||
|
"0.1", I18N_NOOP("TDE Synaptics helper daemon"), TDEAboutData::License_GPL_V2,
|
||
6 months ago
|
"© 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();
|
||
2 months ago
|
app.dcopClient()->registerAs("tdesyndaemon", false);
|
||
6 months ago
|
|
||
2 months ago
|
TDESynDaemon tdesyndaemon;
|
||
6 months ago
|
return app.exec();
|
||
2 months ago
|
}
|