fix(keyboard): use QCoreApplication::sendEvent when use wayland

Description:wayland下采用QCoreApplication::sendEvent方式来模拟按键事件

Log:https://gitee.com/openkylin/ukui-screensaver/issues/I5XAG9?from=project-issue
This commit is contained in:
liuyuanpeng 2023-04-17 15:46:47 +08:00
parent 784a4eece6
commit 437c17d098
16 changed files with 544 additions and 128 deletions

View File

@ -1,10 +1,21 @@
pkg_check_modules(GLIB REQUIRED glib-2.0)
find_package(X11 REQUIRED)
find_package(KF5WindowSystem)
include_directories(
${Qt5Core_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS}
${Qt5DBus_INCLUDE_DIRS}
${GLIB2_INCLUDE_DIRS}
${KF5Wayland_LIBRARIES}
)
qt5_wrap_cpp(Common_SRC
autoresize.h
checkbutton.h
commonfunc.h
glibinterface.h
plasma-shell-manager.h
)
set(Common_SRC
@ -13,14 +24,8 @@ set(Common_SRC
checkbutton.cpp
commonfunc.cpp
glibinterface.cpp
)
include_directories(
${Qt5Core_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS}
${Qt5DBus_INCLUDE_DIRS}
${GLIB2_INCLUDE_DIRS}
plasma-shell-manager.cpp
)
add_library(Common STATIC ${Common_SRC})
target_link_libraries(Common Qt5::Core Qt5::DBus Qt5::Widgets ${GIOUNIX2_LIBRARIES})
target_link_libraries(Common Qt5::Core Qt5::DBus Qt5::Widgets ${GIOUNIX2_LIBRARIES} ${KF5Wayland_LIBRARIES} -lKF5WaylandClient -lKF5WaylandServer KF5::WindowSystem)

View File

@ -15,6 +15,7 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
**/
#include "plasma-shell-manager.h"
#include <QApplication>
@ -129,8 +130,40 @@ bool PlasmaShellManager::supportPlasmaWindowManagement()
return m_windowManager && m_appWindow;
}
bool PlasmaShellManager::supportFakeInput()
{
return m_fakeInput;
}
bool PlasmaShellManager::supportKeyState()
{
return m_keyState;
}
KWayland::Client::Keystate::State PlasmaShellManager::getKeyState(KWayland::Client::Keystate::Key key)
{
if(!supportKeyState()){
return KWayland::Client::Keystate::Unlocked;
}
return m_keyStateMap[key];
}
void PlasmaShellManager::setKeyPressed(quint32 key)
{
if(!supportFakeInput())
return ;
m_fakeInput->requestKeyboardKeyPress(key);
m_fakeInput->requestKeyboardKeyRelease(key);
}
PlasmaShellManager::PlasmaShellManager(QObject *parent) : QObject(parent)
{
m_keyStateMap.insert(KWayland::Client::Keystate::Key::CapsLock,KWayland::Client::Keystate::Unlocked);
m_keyStateMap.insert(KWayland::Client::Keystate::Key::NumLock,KWayland::Client::Keystate::Unlocked);
m_keyStateMap.insert(KWayland::Client::Keystate::Key::ScrollLock,KWayland::Client::Keystate::Unlocked);
auto connection = KWayland::Client::ConnectionThread::fromApplication(qApp);
auto registry = new KWayland::Client::Registry(this);
registry->create(connection->display());
@ -161,15 +194,15 @@ PlasmaShellManager::PlasmaShellManager(QObject *parent) : QObject(parent)
m_appWindow = window;
connect(m_appWindow, &KWayland::Client::PlasmaWindow::activeChanged,
[this]() {
this->setAppWindowKeepAbove(true);
this->setAppWindowActive();
});
[this]() {
this->setAppWindowKeepAbove(true);
this->setAppWindowActive();
});
connect(m_appWindow, &KWayland::Client::PlasmaWindow::keepAboveChanged,
[this]() {
this->setAppWindowKeepAbove(true);
this->setAppWindowActive();
});
[this]() {
this->setAppWindowKeepAbove(true);
this->setAppWindowActive();
});
}
}
});
@ -183,6 +216,34 @@ PlasmaShellManager::PlasmaShellManager(QObject *parent) : QObject(parent)
}
});
connect(registry, &KWayland::Client::Registry::fakeInputAnnounced, this, [=](){
qDebug()<<"fakeInputAnnounced";
const auto interface = registry->interface(KWayland::Client::Registry::Interface::FakeInput);
if (interface.name != 0) {
qDebug()<<"createFakeInput";
m_fakeInput = registry->createFakeInput(interface.name, interface.version);
m_fakeInput->authenticate("ukui-screensaver-dialog","virual keyboard");
}
});
connect(registry, &KWayland::Client::Registry::keystateAnnounced, this, [=](){
qDebug()<<"keystateAnnounced";
const auto interface = registry->interface(KWayland::Client::Registry::Interface::Keystate);
if (interface.name != 0) {
qDebug()<<"createKeyState";
m_keyState = registry->createKeystate(interface.name, interface.version);
if(m_keyState){
connect(m_keyState, &KWayland::Client::Keystate::stateChanged,
[this](KWayland::Client::Keystate::Key key,KWayland::Client::Keystate::State state) {
qDebug()<<"key = "<<key<<"state = "<<state;
m_keyStateMap[key] = state;
emit keyStateChanged();
});
m_keyState->fetchStates();
}
}
});
registry->setup();
connection->roundtrip();
}

View File

@ -15,14 +15,18 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
**/
#ifndef PLASMASHELLMANAGER_H
#define PLASMASHELLMANAGER_H
#include <QObject>
#include <QWindow>
#include <QMap>
#include <KWayland/Client/plasmawindowmanagement.h>
#include <KWayland/Client/plasmashell.h>
#include <KWayland/Client/shell.h>
#include <KWayland/Client/fakeinput.h>
#include <KWayland/Client/keystate.h>
class PlasmaShellManager : public QObject
{
@ -35,9 +39,16 @@ public:
bool setMaximized(QWindow *window);
bool setRole(QWindow *window, KWayland::Client::PlasmaShellSurface::Role role);
bool setPos(QWindow *window, const QPoint &pos);
void setKeyPressed(quint32 key);
bool supportPlasmaShell();
bool supportShell();
bool supportPlasmaWindowManagement();
bool supportFakeInput();
bool supportKeyState();
KWayland::Client::Keystate::State getKeyState(KWayland::Client::Keystate::Key key);
Q_SIGNALS:
void keyStateChanged();
private:
explicit PlasmaShellManager(QObject *parent = nullptr);
@ -46,8 +57,13 @@ private:
KWayland::Client::Shell *m_shell = nullptr;
KWayland::Client::PlasmaWindowManagement *m_windowManager = nullptr;
KWayland::Client::PlasmaWindow *m_appWindow = nullptr;
KWayland::Client::FakeInput *m_fakeInput = nullptr;
KWayland::Client::Keystate *m_keyState = nullptr;
bool isFirstCreate = true;
QMap<KWayland::Client::Keystate::Key,KWayland::Client::Keystate::State> m_keyStateMap;
};

View File

@ -4,9 +4,15 @@ set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
include_directories(${PROJECT_SOURCE_DIR}/Common)
qt5_add_resources(VirtualKeyboard_SRC
src/keyboard.qrc)
qt5_wrap_cpp(VirtualKeyboard_SRC
src/fakekeyboard.h
)
set(VirtualKeyboard_SRC
${VirtualKeyboard_SRC}
src/charsmorewidget.cpp
@ -18,12 +24,13 @@ set(VirtualKeyboard_SRC
src/numberswidget.cpp
src/virtualkeyboardwidget.cpp
src/x11keyboard.cpp
src/qtkeyboard.cpp
)
include_directories(
${Qt5Core_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS}
)
)
add_library(VirtualKeyboard STATIC ${VirtualKeyboard_SRC})
target_link_libraries(VirtualKeyboard Qt5::Core Qt5::Widgets)
target_link_libraries(VirtualKeyboard Qt5::Core Qt5::Widgets Qt5::X11Extras Common)

View File

@ -0,0 +1,114 @@
/*
* Copyright (C) 2023 Tianjin KYLIN Information Technology Co., Ltd.
*
* 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, 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 <http://www.gnu.org/licenses/>.
*
**/
#ifndef FAKEKEYBOARD_H
#define FAKEKEYBOARD_H
#include <QObject>
#include <QMetaEnum>
class Modifier : public QObject
{
Q_OBJECT
public:
Modifier(){}
enum MOD{
UNKNOWN = -1,
CTRL,
SHIFT,
ALT,
SUPER
};
Q_ENUM(MOD)
static QString getModifierName(int mod)
{
QMetaEnum metaEnum = QMetaEnum::fromType<Modifier::MOD>();
const char* modName = metaEnum.valueToKey(mod);
QString result = QString(modName).toLower();
return result;
}
static MOD getModifier(const QString &modName)
{
QMetaEnum metaEnum = QMetaEnum::fromType<Modifier::MOD>();
MOD mod = (MOD)metaEnum.keyToValue(modName.toUpper().toLocal8Bit().data());
return mod;
}
};
class FuncKey : public QObject
{
Q_OBJECT
public:
FuncKey(){}
enum FUNCKEY {
UNKNOWN = -1,
SPACE = 0,
BACKSPACE,
ENTER,
HOME,
END,
PGUP,
PGDN,
INSERT,
DELETE,
UP,
DOWN,
LEFT,
RIGHT,
CAPSLOCK
};
Q_ENUM(FUNCKEY)
static QString getKeyName(int key)
{
QMetaEnum metaEnum = QMetaEnum::fromType<FuncKey::FUNCKEY>();
const char* keyName = metaEnum.valueToKey(key);
QString result = QString(keyName).toLower();
return result;
}
static FUNCKEY getKey(const QString &keyName)
{
QMetaEnum metaEnum = QMetaEnum::fromType<FuncKey::FUNCKEY>();
FUNCKEY key = (FUNCKEY)metaEnum.keyToValue(keyName.toUpper().toLocal8Bit().data());
return key;
}
};
class FakeKeyboard : public QObject
{
Q_OBJECT
public:
explicit FakeKeyboard(QObject *parent = nullptr)
: QObject(parent)
{
}
virtual void addModifier(Modifier::MOD mod) = 0;
virtual void removeModifier(Modifier::MOD mod) = 0;
virtual bool hasModifier(Modifier::MOD mod) = 0;
virtual QList<Modifier::MOD> getAllModifier() = 0;
virtual void clearModifier() = 0;
public Q_SLOTS:
virtual void onKeyPressed(QChar c) = 0;
virtual void onKeyPressed(FuncKey::FUNCKEY key) = 0;
};
#endif // FAKEKEYBOARD_H

View File

@ -17,17 +17,29 @@
**/
#include "letterswidget.h"
#include "commondef.h"
#include "plasma-shell-manager.h"
#include <QDebug>
#include <QX11Info>
#include <KWayland/Client/keystate.h>
LettersWidget::LettersWidget(QWidget *parent/* = nullptr*/)
: QWidget(parent)
{
this->setAttribute(Qt::WA_TranslucentBackground);//背景透明
initUI();
settings = new QGSettings("org.ukui.peripherals-keyboard", "", this);
connect(settings, &QGSettings::changed,
this, &LettersWidget::onCapsChanged);
capsState = settings->get("capslock-state").toBool();
if(QString(qgetenv("XDG_SESSION_TYPE")) == "wayland") {
isWayland = true;
}
if(isWayland){
connect(PlasmaShellManager::getInstance(), &PlasmaShellManager::keyStateChanged,
this, &LettersWidget::onCapsChanged);
}else{
settings = new QGSettings("org.ukui.peripherals-keyboard", "", this);
connect(settings, &QGSettings::changed,
this, &LettersWidget::onCapsChanged);
}
onCapsChanged();
}
@ -319,7 +331,12 @@ void LettersWidget::onBtnClicked(QChar charId)
void LettersWidget::onCapsChanged()
{
capsState = settings->get("capslock-state").toBool();
if(isWayland){
capsState = PlasmaShellManager::getInstance()->getKeyState(KWayland::Client::Keystate::Key::CapsLock);
}else{
capsState = settings->get("capslock-state").toBool();
}
isShift = capsState;
for (int i = 97; i < 123; i++) { //大小写切换
QString objName = QString("btn_%1").arg(QString::number(i));

View File

@ -53,6 +53,7 @@ private:
QGSettings *settings;
bool capsState = false;
bool isWayland = false;
};
#endif // LETTERSWIDGET_H

View File

@ -0,0 +1,225 @@
/*
* Copyright (C) 2023 Tianjin KYLIN Information Technology Co., Ltd.
*
* 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, 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 <http://www.gnu.org/licenses/>.
*
**/
#include "qtkeyboard.h"
#include <QDebug>
#include <QWidget>
#include <QKeyEvent>
#include <QDir>
#include <QApplication>
#include <QCoreApplication>
#include "plasma-shell-manager.h"
QMap<QChar,int> m_specialSymbolMap = {
{' ', Qt::Key_Space},
{',', Qt::Key_Comma},
{'.', Qt::Key_Period},
{'\'', Qt::Key_QuoteLeft},
{'@', Qt::Key_At},
{'#', Qt::Key_NumberSign},
{'$', Qt::Key_Dollar},
{'%', Qt::Key_Percent},
{'&', Qt::Key_Ampersand},
{'*', Qt::Key_Asterisk},
{'(', Qt::Key_ParenLeft},
{')', Qt::Key_ParenRight},
{'-', Qt::Key_Minus},
{'+', Qt::Key_Plus},
{'!', Qt::Key_Exclam},
{'"', Qt::Key_QuoteDbl},
{'<', Qt::Key_Less},
{'>', Qt::Key_Greater},
{':', Qt::Key_Colon},
{';', Qt::Key_Semicolon},
{'/', Qt::Key_Slash},
{'?', Qt::Key_Question},
{'=', Qt::Key_Equal},
{'.', Qt::Key_Period}, /*XK_kana_middledot*/
{'~', Qt::Key_AsciiTilde},
{'`', Qt::Key_QuoteLeft},
{'|', Qt::Key_Bar},
{'^', Qt::Key_AsciiCircum},
{'{', Qt::Key_BraceLeft},
{'}', Qt::Key_BraceRight},
{'[', Qt::Key_BracketLeft},
{']', Qt::Key_BracketRight},
{'_', Qt::Key_Underscore},
{'\\', Qt::Key_Backslash},
};
QMap<FuncKey::FUNCKEY, int> m_funckeyMap = {
{FuncKey::SPACE, Qt::Key_Space},
{FuncKey::BACKSPACE, Qt::Key_Backspace},
{FuncKey::ENTER, Qt::Key_Enter},
{FuncKey::HOME, Qt::Key_Home},
{FuncKey::END, Qt::Key_End},
{FuncKey::PGUP, Qt::Key_PageUp},
{FuncKey::PGDN, Qt::Key_PageDown},
{FuncKey::INSERT, Qt::Key_Insert},
{FuncKey::DELETE, Qt::Key_Delete},
{FuncKey::UP, Qt::Key_Up},
{FuncKey::DOWN, Qt::Key_Down},
{FuncKey::LEFT, Qt::Key_Left},
{FuncKey::RIGHT, Qt::Key_Right}
};
QMap<Modifier::MOD, Qt::KeyboardModifier> m_modifierMap = {
{Modifier::CTRL, Qt::ControlModifier},
{Modifier::ALT, Qt::AltModifier},
{Modifier::SUPER, Qt::MetaModifier},
{Modifier::SHIFT, Qt::ShiftModifier}
};
QVector<QChar> m_shiftKeyVec = {'~', '!', '@', '#', '$', '%', '^', '&', '*',
'(', ')', '_', '+', '{', '}', '|', ':', '"',
'>', '?'};
#define DRM_DIR "/sys/class/leds/"
#define CAPSLOCK_STATUS "capslock_state"
/**
* @brief
* @return true:
*/
bool QtKeyboard::checkCapsLockState()
{
QDir ledDir(DRM_DIR);
QStringList leds = ledDir.entryList(QDir::Dirs);
QString capsFile;
for(int i = 0;i<leds.count();i++){
if(leds.at(i).contains("capslock"))
capsFile = leds.at(i);
}
QFile drmStatusFile(DRM_DIR + capsFile + "/brightness");
if(drmStatusFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream in(&drmStatusFile);
QString status = in.readLine();
if(status == "0") {
return false;
}else{
return true;
}
}
return false;
}
QtKeyboard::QtKeyboard(QObject *parent)
: FakeKeyboard(parent)
{
}
QtKeyboard::~QtKeyboard()
{
}
void QtKeyboard::addModifier(Modifier::MOD mod)
{
modList.push_back(mod);
}
void QtKeyboard::removeModifier(Modifier::MOD mod)
{
modList.removeOne(mod);
}
bool QtKeyboard::hasModifier(Modifier::MOD mod)
{
return modList.contains(mod);
}
QList<Modifier::MOD> QtKeyboard::getAllModifier()
{
return modList;
}
void QtKeyboard::clearModifier()
{
modList.clear();
}
void QtKeyboard::onKeyPressed(QChar c)
{
/*判断大写锁定打开时转换字母大小写状态与x11keyboard类逻辑保持一致*/
if(checkCapsLockState() && c.isLetter()){
if(c.isUpper()){
c = c.toLower();
}
else if(c.isLower()){
c = c.toUpper();
}
}
if(c>='A' && c<='Z'){
sendKey(c.toLatin1(),c);
}else if(c>='a' && c<='z'){
sendKey(c.toLatin1() - 32,c);
}else if(c >= '0' && c<='9'){
sendKey(c.toLatin1(),c);
}else if(m_specialSymbolMap.contains(c)){
sendKey(m_specialSymbolMap[c],c);
}else {
sendKey(c.toLatin1(),c);
}
}
void QtKeyboard::onKeyPressed(FuncKey::FUNCKEY key)
{
int keysym = m_funckeyMap[key];
/*这里的text根据实际按键得到的QEvent中的text内容打印*/
if(key == FuncKey::SPACE){
sendKey(keysym," ");
}else if(key == FuncKey::BACKSPACE){
sendKey(keysym,"\b");
}else if(key == FuncKey::ENTER){
sendKey(keysym,"\r");
}else if(key == FuncKey::INSERT){
sendKey(keysym,"\u007F");
}else if(key == FuncKey::CAPSLOCK){
PlasmaShellManager::getInstance()->setKeyPressed(58);
}else{
sendKey(keysym,"");
}
}
void QtKeyboard::sendKey(const unsigned int keysym,const QString text)
{
Qt::KeyboardModifiers modifier = Qt::NoModifier;
for(auto mod : modList){
modifier = modifier | m_modifierMap[mod];
}
QWidget *objfous = QApplication::focusWidget();
if(objfous){
QKeyEvent event1(QEvent::KeyPress, keysym
, modifier, text
, true, 1);
QKeyEvent event2(QEvent::KeyRelease, keysym
, modifier, text
, true, 1);
QCoreApplication::sendEvent(objfous, &event1);
QCoreApplication::sendEvent(objfous, &event2);
}
}

View File

@ -0,0 +1,49 @@
/*
* Copyright (C) 2023 Tianjin KYLIN Information Technology Co., Ltd.
*
* 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, 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 <http://www.gnu.org/licenses/>.
*
**/
#ifndef QTKEYBOARD_H
#define QTKEYBOARD_H
#include <QObject>
#include <QMetaEnum>
#include "fakekeyboard.h"
class QtKeyboard : public FakeKeyboard
{
Q_OBJECT
public:
explicit QtKeyboard(QObject *parent = nullptr);
~QtKeyboard();
void addModifier(Modifier::MOD mod);
void removeModifier(Modifier::MOD mod);
bool hasModifier(Modifier::MOD mod);
QList<Modifier::MOD> getAllModifier();
void clearModifier();
public Q_SLOTS:
void onKeyPressed(QChar c);
void onKeyPressed(FuncKey::FUNCKEY key);
private:
void sendKey(const unsigned int keyCode,const QString text);
bool checkCapsLockState();
private:
QList<Modifier::MOD> modList;
};
#endif // QTKEYBOARD_H

View File

@ -19,6 +19,7 @@
#include <QPainterPath>
#include <QPainter>
#include <QX11Info>
#include <QMouseEvent>
#include "commondef.h"
#include <QDebug>
@ -29,6 +30,8 @@
#include "numberswidget.h"
#include "charswidget.h"
#include "charsmorewidget.h"
#include "x11keyboard.h"
#include "qtkeyboard.h"
VirtualKeyboardWidget::VirtualKeyboardWidget(QWidget *parent)
: QWidget(parent)
@ -43,7 +46,12 @@ VirtualKeyboardWidget::VirtualKeyboardWidget(QWidget *parent)
Qt::WindowStaysOnTopHint |
Qt::WindowDoesNotAcceptFocus);
vKeyboard = new X11Keyboard(this);
if(QX11Info::isPlatformX11()){
vKeyboard = new X11Keyboard(this);
}else{
vKeyboard = new QtKeyboard(this);
}
connect(this, SIGNAL(keyPressed(QChar)),
vKeyboard, SLOT(onKeyPressed(QChar)));
connect(this, SIGNAL(keyPressed(FuncKey::FUNCKEY)),
@ -222,7 +230,7 @@ void VirtualKeyboardWidget::onSpecialBtnClicked(QString keyName)
m_lettersWidget->changeFuncKeyStyle(keyName, true);
}
if (keyName == BTN_CAPSLOCK) {
Q_EMIT keyPressed(FuncKey::UNKNOWN);
Q_EMIT keyPressed(FuncKey::CAPSLOCK);
clearModifier();
}
} else if(funcKey != FuncKey::UNKNOWN) {

View File

@ -22,7 +22,8 @@
#include <QStackedWidget>
#include <QList>
#include <QMap>
#include "x11keyboard.h"
#include "fakekeyboard.h"
#include "plasma-shell-manager.h"
class DragWidget;
class KBTitle;
@ -82,7 +83,7 @@ private:
bool m_isdragState = false;//是否为悬浮状态
bool isMove;// 是否可移动
QPoint lastPoint;// 拖拽控件时 记录当前控件的位置
X11Keyboard *vKeyboard;
FakeKeyboard *vKeyboard;
};
#endif // VIRTUALKEYBOARDWIDGET_H

View File

@ -21,8 +21,6 @@
#include <X11/keysym.h>
#include <X11/extensions/XTest.h>
struct CharMap {
QChar name;
KeySym code;
@ -78,7 +76,8 @@ QMap<FuncKey::FUNCKEY, KeySym> funckeyMap = {
{FuncKey::UP, XK_Up},
{FuncKey::DOWN, XK_Down},
{FuncKey::LEFT, XK_Left},
{FuncKey::RIGHT, XK_Right}
{FuncKey::RIGHT, XK_Right},
{FuncKey::CAPSLOCK, XK_Caps_Lock}
};
QMap<Modifier::MOD, KeySym> modifierMap = {
@ -86,7 +85,6 @@ QMap<Modifier::MOD, KeySym> modifierMap = {
{Modifier::ALT, XK_Alt_L},
{Modifier::SUPER, XK_Super_L},
{Modifier::SHIFT, XK_Shift_L},
{Modifier::CAPSLOCK, XK_Caps_Lock}
};
QVector<QChar> shiftKeyVec = {'~', '!', '@', '#', '$', '%', '^', '&', '*',
@ -123,7 +121,7 @@ unsigned int keyCodeOfChar(QChar c)
}
X11Keyboard::X11Keyboard(QObject *parent)
: QObject(parent)
: FakeKeyboard(parent)
{
}
@ -168,6 +166,7 @@ void X11Keyboard::onKeyPressed(QChar c)
void X11Keyboard::onKeyPressed(FuncKey::FUNCKEY key)
{
KeyCode keyCode;
KeySym keysym = funckeyMap[key];
if(keysym != NoSymbol)

View File

@ -20,77 +20,9 @@
#include <QObject>
#include <QMetaEnum>
#include "fakekeyboard.h"
class Modifier : public QObject
{
Q_OBJECT
public:
Modifier(){}
enum MOD{
UNKNOWN = -1,
CTRL,
SHIFT,
ALT,
SUPER,
CAPSLOCK
};
Q_ENUM(MOD)
static QString getModifierName(int mod)
{
QMetaEnum metaEnum = QMetaEnum::fromType<Modifier::MOD>();
const char* modName = metaEnum.valueToKey(mod);
QString result = QString(modName).toLower();
return result;
}
static MOD getModifier(const QString &modName)
{
QMetaEnum metaEnum = QMetaEnum::fromType<Modifier::MOD>();
MOD mod = (MOD)metaEnum.keyToValue(modName.toUpper().toLocal8Bit().data());
return mod;
}
};
class FuncKey : public QObject
{
Q_OBJECT
public:
FuncKey(){}
enum FUNCKEY {
UNKNOWN = -1,
SPACE = 0,
BACKSPACE,
ENTER,
HOME,
END,
PGUP,
PGDN,
INSERT,
DELETE,
UP,
DOWN,
LEFT,
RIGHT
};
Q_ENUM(FUNCKEY)
static QString getKeyName(int key)
{
QMetaEnum metaEnum = QMetaEnum::fromType<FuncKey::FUNCKEY>();
const char* keyName = metaEnum.valueToKey(key);
QString result = QString(keyName).toLower();
return result;
}
static FUNCKEY getKey(const QString &keyName)
{
QMetaEnum metaEnum = QMetaEnum::fromType<FuncKey::FUNCKEY>();
FUNCKEY key = (FUNCKEY)metaEnum.keyToValue(keyName.toUpper().toLocal8Bit().data());
return key;
}
};
class X11Keyboard : public QObject
class X11Keyboard : public FakeKeyboard
{
Q_OBJECT
public:

View File

@ -112,7 +112,6 @@ qt5_wrap_cpp(dialog_SRC
lockchecker.h
servicemanager.h
mytabwidget.h
plasma-shell-manager.h
modebutton.h
klabel.h
PhysicalDeviceSet/brightnessdeviceset.h
@ -167,7 +166,6 @@ set(dialog_SRC
lockchecker.cpp
servicemanager.cpp
mytabwidget.cpp
plasma-shell-manager.cpp
modebutton.cpp
klabel.cpp
rootWindowBackground.cpp

View File

@ -569,7 +569,6 @@ bool FullBackgroundWidget::nativeEventFilter(const QByteArray &eventType, void *
//onGlobalKeyPress(xc->detail);
} else if (responseType == XCB_KEY_RELEASE) {
xcb_key_release_event_t *xc = reinterpret_cast<xcb_key_release_event_t*>(event);
qDebug()<<"---------------------XCB_KEY_RELEASE:"<<xc->detail;
onGlobalKeyRelease(xc->detail);
} else if(responseType == XCB_GE_GENERIC){
xcb_ge_generic_event_t *xc = reinterpret_cast<xcb_ge_generic_event_t*>(event);

View File

@ -820,27 +820,14 @@ void LockWidget::initUI()
this->setCursor(Qt::ArrowCursor);
});
if(QX11Info::isPlatformX11()){
//虚拟键盘
ui->btnKeyboard->setIcon(QIcon(":/image/assets/keyboard.svg"));
ui->btnKeyboard->setFixedSize(48, 48);
ui->btnKeyboard->setIconSize(QSize(24, 24));
ui->btnKeyboard->setFocusPolicy(Qt::NoFocus);
ui->btnKeyboard->installEventFilter(this);
ui->btnKeyboard->setIcon(QIcon(":/image/assets/keyboard.svg"));
ui->btnKeyboard->setFixedSize(48, 48);
ui->btnKeyboard->setIconSize(QSize(24, 24));
ui->btnKeyboard->setFocusPolicy(Qt::NoFocus);
ui->btnKeyboard->installEventFilter(this);
/* connect(ui->btnKeyboard, &QPushButton::clicked,
this, [&]{
qDebug() << vKeyboard->isHidden();
vKeyboard->setVisible(vKeyboard->isHidden());
});
*/
connect(ui->btnKeyboard, &QPushButton::clicked,
this, &LockWidget::showVirtualKeyboard);
} else {
ui->btnKeyboard->hide();
}
connect(ui->btnKeyboard, &QPushButton::clicked,
this, &LockWidget::showVirtualKeyboard);
//用户切换
if(displayManager->canSwitch())
@ -892,9 +879,6 @@ void LockWidget::netInPutStatus()
void LockWidget::showVirtualKeyboard()
{
if (!QX11Info::isPlatformX11()) {
return ;
}
tabAt = LINEEDIT;
setBottomBtnSheet();
tabAt = BOTTMBTN;