diff --git a/events/x11/x11events.cpp b/events/x11/x11events.cpp index e61fde5..ac7040b 100644 --- a/events/x11/x11events.cpp +++ b/events/x11/x11events.cpp @@ -1,212 +1,210 @@ /* This file is part of the KDE project Copyright (C) 2016 by Oleg Chernovskiy 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 2 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "x11events.h" #include #include #include #include #include #include #include #include enum { LEFTSHIFT = 1, RIGHTSHIFT = 2, ALTGR = 4 }; class EventData { public: EventData(); //keyboard Display *dpy; signed char modifiers[0x100]; KeyCode keycodes[0x100]; KeyCode leftShiftCode; KeyCode rightShiftCode; KeyCode altGrCode; char modifierState; //mouse int buttonMask; int x; int y; private: void init(); }; Q_GLOBAL_STATIC(EventData, data) EventData::EventData() { init(); } void EventData::init() { buttonMask = 0; dpy = QX11Info::display(); //initialize keycodes KeySym key, *keymap; int i, j, minkey, maxkey, syms_per_keycode; memset(modifiers, -1, sizeof(modifiers)); XDisplayKeycodes(dpy, &minkey, &maxkey); Q_ASSERT(minkey >= 8); Q_ASSERT(maxkey < 256); keymap = (KeySym *) XGetKeyboardMapping(dpy, minkey, (maxkey - minkey + 1), &syms_per_keycode); Q_ASSERT(keymap); for (i = minkey; i <= maxkey; i++) { for (j = 0; j < syms_per_keycode; j++) { key = keymap[(i-minkey)*syms_per_keycode+j]; if (key >= ' ' && key < 0x100 && i == XKeysymToKeycode(dpy, key)) { keycodes[key] = i; modifiers[key] = j; } } } leftShiftCode = XKeysymToKeycode(dpy, XK_Shift_L); rightShiftCode = XKeysymToKeycode(dpy, XK_Shift_R); altGrCode = XKeysymToKeycode(dpy, XK_Mode_switch); XFree((char *)keymap); } /* this function adjusts the modifiers according to mod (as from modifiers) and data->modifierState */ static void tweakModifiers(signed char mod, bool down) { bool isShift = data->modifierState & (LEFTSHIFT | RIGHTSHIFT); if (mod < 0) { return; } if (isShift && mod != 1) { if (data->modifierState & LEFTSHIFT) { XTestFakeKeyEvent(data->dpy, data->leftShiftCode, down, CurrentTime); } if (data->modifierState & RIGHTSHIFT) { XTestFakeKeyEvent(data->dpy, data->rightShiftCode, down, CurrentTime); } } if (!isShift && mod == 1) { XTestFakeKeyEvent(data->dpy, data->leftShiftCode, down, CurrentTime); } if ((data->modifierState & ALTGR) && mod != 2) { XTestFakeKeyEvent(data->dpy, data->altGrCode, !down, CurrentTime); } if (!(data->modifierState & ALTGR) && mod == 2) { XTestFakeKeyEvent(data->dpy, data->altGrCode, down, CurrentTime); } } void X11EventHandler::handleKeyboard(bool down, rfbKeySym keySym) { #define ADJUSTMOD(sym,state) \ if(keySym==sym) { if(down) data->modifierState|=state; else data->modifierState&=~state; } if (QX11Info::isPlatformX11()) { ADJUSTMOD(XK_Shift_L, LEFTSHIFT); ADJUSTMOD(XK_Shift_R, RIGHTSHIFT); ADJUSTMOD(XK_Mode_switch, ALTGR); if (keySym >= ' ' && keySym < 0x100) { KeyCode k; if (down) { tweakModifiers(data->modifiers[keySym], True); } k = data->keycodes[keySym]; if (k != NoSymbol) { XTestFakeKeyEvent(data->dpy, k, down, CurrentTime); } if (down) { tweakModifiers(data->modifiers[keySym], False); } } else { KeyCode k = XKeysymToKeycode(data->dpy, keySym); if (k != NoSymbol) { XTestFakeKeyEvent(data->dpy, k, down, CurrentTime); } } } /* // Wayland platform and pipweire plugin in use if (KrfbConfig::preferredFrameBufferPlugin() == QStringLiteral("pw")) { }*/ } void X11EventHandler::handlePointer(int buttonMask, int x, int y) { if (QX11Info::isPlatformX11()) { QDesktopWidget *desktopWidget = QApplication::desktop(); int screen = desktopWidget->screenNumber(); if (screen < 0) { screen = 0; } XTestFakeMotionEvent(data->dpy, screen, x, y, CurrentTime); for (int i = 0; i < 5; i++) { if ((data->buttonMask&(1 << i)) != (buttonMask&(1 << i))) { XTestFakeButtonEvent(data->dpy, i + 1, (buttonMask&(1 << i)) ? True : False, CurrentTime); } } data->buttonMask = buttonMask; } } - -#include "x11events.moc" diff --git a/krfb/events.cpp b/krfb/events.cpp index 25cee0d..a58a309 100644 --- a/krfb/events.cpp +++ b/krfb/events.cpp @@ -1,43 +1,40 @@ /* This file is part of the KDE project Copyright (C) 2010 Collabora Ltd. @author George Kiagiadakis Copyright (C) 2007 Alessandro Praduroux Copyright (C) 2001-2003 by Tim Jansen 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 2 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "events.h" EventHandler::EventHandler(QObject *parent) : QObject(parent) { } void EventHandler::setFrameBufferPlugin(const QSharedPointer &frameBuffer) { fb = frameBuffer; } QSharedPointer EventHandler::frameBuffer() { return fb; } - -#include "events.moc" - diff --git a/krfb/eventsmanager.cpp b/krfb/eventsmanager.cpp index e1113a1..9d8306e 100644 --- a/krfb/eventsmanager.cpp +++ b/krfb/eventsmanager.cpp @@ -1,120 +1,117 @@ /* This file is part of the KDE project Copyright (C) 2009 Collabora Ltd @author George Goldberg 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 2 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "eventsmanager.h" #include "eventsplugin.h" #include "krfbconfig.h" #include "rfbservermanager.h" #include #include #include #include #include #include class EventsManagerStatic { public: EventsManager instance; }; Q_GLOBAL_STATIC(EventsManagerStatic, eventsManagerStatic) EventsManager::EventsManager() { //qDebug(); loadPlugins(); } EventsManager::~EventsManager() { //qDebug(); } EventsManager *EventsManager::instance() { //qDebug(); return &eventsManagerStatic->instance; } void EventsManager::loadPlugins() { //qDebug(); const QVector plugins = KPluginLoader::findPlugins(QStringLiteral("krfb"), [](const KPluginMetaData & md) { return md.serviceTypes().contains(QStringLiteral("krfb/events")); }); QVectorIterator i(plugins); i.toBack(); QSet unique; while (i.hasPrevious()) { KPluginMetaData data = i.previous(); // only load plugins once, even if found multiple times! if (unique.contains(data.name())) continue; KPluginFactory *factory = KPluginLoader(data.fileName()).factory(); if (!factory) { qDebug() << "KPluginFactory could not load the plugin:" << data.fileName(); } else { qDebug() << "found plugin at " << data.fileName(); } EventsPlugin *plugin = factory->create(this); if (plugin) { m_plugins.insert(data.pluginId(), plugin); qDebug() << "Loaded plugin with name " << data.pluginId(); } else { qDebug() << "unable to load plugin for " << data.fileName(); } unique.insert (data.name()); } } QSharedPointer EventsManager::eventHandler() { QMap::const_iterator iter = m_plugins.constBegin(); while (iter != m_plugins.constEnd()) { QSharedPointer eventHandler(iter.value()->eventHandler()); if (eventHandler) { eventHandler->setFrameBufferPlugin(RfbServerManager::instance()->framebuffer()); return eventHandler; } ++iter; } // No valid events plugin found. qDebug() << "No valid event handlers found. returning null."; return QSharedPointer(); } - - -#include "eventsmanager.moc" diff --git a/krfb/eventsplugin.cpp b/krfb/eventsplugin.cpp index 662de58..250914d 100644 --- a/krfb/eventsplugin.cpp +++ b/krfb/eventsplugin.cpp @@ -1,34 +1,32 @@ /* This file is part of the KDE project Copyright (C) 2016 Oleg Chernovskiy 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 2 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "eventsplugin.h" #include "events.h" EventsPlugin::EventsPlugin(QObject *parent, const QVariantList &) : QObject(parent) { } EventsPlugin::~EventsPlugin() { } - -#include "eventsplugin.moc"