File indexing completed on 2024-04-21 03:54:14

0001 /*
0002     SPDX-FileCopyrightText: 2009 Michael Leupold <lemma@confuego.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "kmodifierkeyinfo.h"
0008 #include "kmodifierkeyinfoprovider_p.h"
0009 #include <kguiaddons_debug.h>
0010 
0011 #include <QGuiApplication>
0012 
0013 #include "config.h"
0014 
0015 #if WITH_WAYLAND
0016 #include "kmodifierkeyinfoprovider_wayland.h"
0017 #endif
0018 
0019 #if WITH_X11
0020 #include "kmodifierkeyinfoprovider_xcb.h"
0021 #endif
0022 
0023 KModifierKeyInfoProvider *createProvider()
0024 {
0025 #if WITH_WAYLAND
0026     if (qGuiApp->platformName() == QLatin1String("wayland")) {
0027         return new KModifierKeyInfoProviderWayland;
0028     }
0029 #endif
0030 
0031 #if WITH_X11
0032     if (qGuiApp->platformName() == QLatin1String("xcb")) {
0033         return new KModifierKeyInfoProviderXcb;
0034     }
0035 #endif
0036 
0037     qCWarning(KGUIADDONS_LOG) << "No modifierkeyinfo backend for platform" << qGuiApp->platformName();
0038     return new KModifierKeyInfoProvider;
0039 }
0040 
0041 KModifierKeyInfo::KModifierKeyInfo(QObject *parent)
0042     : QObject(parent)
0043     , p(createProvider())
0044 {
0045     connect(p.data(), &KModifierKeyInfoProvider::keyPressed, this, &KModifierKeyInfo::keyPressed);
0046     connect(p.data(), &KModifierKeyInfoProvider::keyLatched, this, &KModifierKeyInfo::keyLatched);
0047     connect(p.data(), &KModifierKeyInfoProvider::keyLocked, this, &KModifierKeyInfo::keyLocked);
0048     connect(p.data(), &KModifierKeyInfoProvider::buttonPressed, this, &KModifierKeyInfo::buttonPressed);
0049     connect(p.data(), &KModifierKeyInfoProvider::keyAdded, this, &KModifierKeyInfo::keyAdded);
0050     connect(p.data(), &KModifierKeyInfoProvider::keyRemoved, this, &KModifierKeyInfo::keyRemoved);
0051 }
0052 
0053 KModifierKeyInfo::~KModifierKeyInfo()
0054 {
0055 }
0056 
0057 bool KModifierKeyInfo::knowsKey(Qt::Key key) const
0058 {
0059     return p->knowsKey(key);
0060 }
0061 
0062 const QList<Qt::Key> KModifierKeyInfo::knownKeys() const
0063 {
0064     return p->knownKeys();
0065 }
0066 
0067 bool KModifierKeyInfo::isKeyPressed(Qt::Key key) const
0068 {
0069     return p->isKeyPressed(key);
0070 }
0071 
0072 bool KModifierKeyInfo::isKeyLatched(Qt::Key key) const
0073 {
0074     return p->isKeyLatched(key);
0075 }
0076 
0077 bool KModifierKeyInfo::setKeyLatched(Qt::Key key, bool latched)
0078 {
0079     return p->setKeyLatched(key, latched);
0080 }
0081 
0082 bool KModifierKeyInfo::isKeyLocked(Qt::Key key) const
0083 {
0084     return p->isKeyLocked(key);
0085 }
0086 
0087 bool KModifierKeyInfo::setKeyLocked(Qt::Key key, bool locked)
0088 {
0089     return p->setKeyLocked(key, locked);
0090 }
0091 
0092 bool KModifierKeyInfo::isButtonPressed(Qt::MouseButton button) const
0093 {
0094     return p->isButtonPressed(button);
0095 }
0096 
0097 #include "moc_kmodifierkeyinfo.cpp"