diff --git a/debian/patches/0044-4-fixbug.patch b/debian/patches/0044-4-fixbug.patch new file mode 100644 index 0000000..98b07ac --- /dev/null +++ b/debian/patches/0044-4-fixbug.patch @@ -0,0 +1,344 @@ +From: =?utf-8?b?5p2o5pWP?= +Date: Thu, 4 Jul 2024 06:32:01 +0000 +Subject: =?utf-8?q?!4_fixbug_Merge_pull_request_!4_from_=E6=9D=A8=E6=95=8F/?= + =?utf-8?q?openkylin/nile?= + +--- + src/VirtualKeyboard/src/virtualkeyboardwidget.cpp | 190 ++++++++++++---------- + src/VirtualKeyboard/src/virtualkeyboardwidget.h | 2 +- + 2 files changed, 109 insertions(+), 83 deletions(-) + +diff --git a/src/VirtualKeyboard/src/virtualkeyboardwidget.cpp b/src/VirtualKeyboard/src/virtualkeyboardwidget.cpp +index 4b9db89..bd65ed8 100644 +--- a/src/VirtualKeyboard/src/virtualkeyboardwidget.cpp ++++ b/src/VirtualKeyboard/src/virtualkeyboardwidget.cpp +@@ -14,7 +14,7 @@ + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * +-**/ ++ **/ + #include "virtualkeyboardwidget.h" + + #include +@@ -25,6 +25,8 @@ + #include "commondef.h" + #include + #include ++#include ++#include + #include "dragwidget.h" + #include "kbtitle.h" + #include "letterswidget.h" +@@ -35,60 +37,50 @@ + #include "qtkeyboard.h" + + VirtualKeyboardWidget::VirtualKeyboardWidget(QWidget *parent) +- : QWidget(parent) +- , m_lfWidthScale(1.0) +- , m_lfHeightScale(1.0) +- , m_isVertical(false) ++ : QWidget(parent), m_lfWidthScale(1.0), m_lfHeightScale(1.0), m_isVertical(false) + { + Q_INIT_RESOURCE(keyboard); +- //setAttribute(Qt::WA_TranslucentBackground);//背景透明 +- //setAutoFillBackground(true); +- setWindowFlags(Qt::FramelessWindowHint | +- Qt::WindowStaysOnTopHint | +- Qt::WindowDoesNotAcceptFocus); ++ // setAttribute(Qt::WA_TranslucentBackground);//背景透明 ++ // setAutoFillBackground(true); ++ setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::WindowDoesNotAcceptFocus); + +- if(QX11Info::isPlatformX11()){ ++ if (QX11Info::isPlatformX11()) { + vKeyboard = new X11Keyboard(this); +- }else{ ++ } else { + vKeyboard = new QtKeyboard(this); + } + +- connect(this, SIGNAL(keyPressed(QChar)), +- vKeyboard, SLOT(onKeyPressed(QChar))); +- connect(this, SIGNAL(keyPressed(FuncKey::FUNCKEY)), +- vKeyboard, SLOT(onKeyPressed(FuncKey::FUNCKEY))); ++ connect(this, SIGNAL(keyPressed(QChar)), vKeyboard, SLOT(onKeyPressed(QChar))); ++ connect(this, SIGNAL(keyPressed(FuncKey::FUNCKEY)), vKeyboard, SLOT(onKeyPressed(FuncKey::FUNCKEY))); + initUI(); + qApp->installNativeEventFilter(this); + initConnections(); + } + +-VirtualKeyboardWidget::~VirtualKeyboardWidget() +-{ +- +-} ++VirtualKeyboardWidget::~VirtualKeyboardWidget() {} + + bool VirtualKeyboardWidget::nativeEventFilter(const QByteArray &eventType, void *message, long *result) + { + if (qstrcmp(eventType, "xcb_generic_event_t") != 0) { + return false; + } +- xcb_generic_event_t *event = reinterpret_cast(message); ++ xcb_generic_event_t *event = reinterpret_cast(message); + const uint8_t responseType = event->response_type & ~0x80; + if (responseType == XCB_KEY_PRESS) { +- xcb_key_press_event_t *xc = reinterpret_cast(event); +- } else if (responseType == XCB_KEY_RELEASE) { +- xcb_key_release_event_t *xc = reinterpret_cast(event); ++ xcb_key_press_event_t *xc = reinterpret_cast(event); ++ } else if (responseType == XCB_KEY_RELEASE) { ++ xcb_key_release_event_t *xc = reinterpret_cast(event); + if (xc->detail == 66 /*&& QString(qgetenv("XDG_SESSION_TYPE")) == "wayland"*/) { + m_lettersWidget->onCapsChanged(); + } +- } ++ } + return false; + } + + void VirtualKeyboardWidget::initUI() + { + QVBoxLayout *layoutMain = new QVBoxLayout(this); +- layoutMain->setContentsMargins(0,0,0,0); ++ layoutMain->setContentsMargins(0, 0, 0, 0); + layoutMain->setSpacing(0); + + m_dragWidget = new DragWidget(); +@@ -132,13 +124,13 @@ void VirtualKeyboardWidget::initConnections() + + void VirtualKeyboardWidget::adjustGeometry() + { +- QWidget *parentWidget = qobject_cast(parent()); ++ QWidget *parentWidget = qobject_cast(parent()); + if (parentWidget) { +- //qDebug()<< "parent: " << parentWidget <<"Parent gemotry:"<geometry(); ++ // qDebug()<< "parent: " << parentWidget <<"Parent gemotry:"<geometry(); + double lfWidth = parentWidget->geometry().width(); + double lfHeight = parentWidget->geometry().height(); + m_isVertical = lfHeight > lfWidth; +- m_lfWidthScale = lfWidth/KEYBOARD_PARENT_DEFAULT_WIDTH; ++ m_lfWidthScale = lfWidth / KEYBOARD_PARENT_DEFAULT_WIDTH; + if (m_isVertical) + m_lfHeightScale = lfHeight / KEYBOARD_PARENT_DEFAULT_WIDTH; + else +@@ -146,26 +138,26 @@ void VirtualKeyboardWidget::adjustGeometry() + if (m_isdragState) { + lfWidth = m_lfWidthScale * KEYBOARD_DRAGSHOW_FIXED_DEFAULT_WIDTH; + lfHeight = m_lfHeightScale * KEYBOARD_DRAGSHOW_FIXED_DEFAULT_HEIGHT; +- setGeometry(QRect(m_lfWidthScale * (KEYBOARD_PARENT_DEFAULT_WIDTH - KEYBOARD_DRAGSHOW_FIXED_DEFAULT_WIDTH) / 2, +- parentWidget->geometry().height() - lfHeight, +- lfWidth, lfHeight)); ++ setGeometry(QRect( ++ m_lfWidthScale * (KEYBOARD_PARENT_DEFAULT_WIDTH - KEYBOARD_DRAGSHOW_FIXED_DEFAULT_WIDTH) / 2, ++ parentWidget->geometry().height() - lfHeight, ++ lfWidth, ++ lfHeight)); + m_dragWidget->show(); + } else { + lfWidth = m_lfWidthScale * KEYBOARD_FIXED_DEFAULT_WIDTH; + lfHeight = m_lfHeightScale * KEYBOARD_DRAGHIDE_FIXED_DEFAULT_HEIGHT; + m_dragWidget->hide(); +- setGeometry(QRect(0, parentWidget->geometry().height()-lfHeight, lfWidth, lfHeight)); ++ setGeometry(QRect(0, parentWidget->geometry().height() - lfHeight, lfWidth, lfHeight)); + } + +- //qDebug()<<"Widget geometry:"<show(); + } else { +- setGeometry(QRect(0, 0, +- KEYBOARD_FIXED_DEFAULT_WIDTH, KEYBOARD_DRAGHIDE_FIXED_DEFAULT_HEIGHT)); ++ setGeometry(QRect(0, 0, KEYBOARD_FIXED_DEFAULT_WIDTH, KEYBOARD_DRAGHIDE_FIXED_DEFAULT_HEIGHT)); + m_dragWidget->hide(); + } + m_lfWidthScale = 1.0; +@@ -194,20 +186,32 @@ void VirtualKeyboardWidget::adjustGeometry() + + bool VirtualKeyboardWidget::eventFilter(QObject *watched, QEvent *event) + { +- if(watched != m_dragWidget && !isMove) return QWidget::eventFilter(watched, event); +- switch(event->type()) +- { +- case QEvent::MouseButtonPress: +- onMouseEvents(1); +- return true; +- case QEvent::MouseMove: +- onMouseEvents(2); +- return true; +- case QEvent::MouseButtonRelease: +- onMouseEvents(3); +- return true; +- default: +- break; ++ if (watched != m_dragWidget && !isMove) ++ return QWidget::eventFilter(watched, event); ++ switch (event->type()) { ++ case QEvent::MouseButtonPress: { ++ QMouseEvent *mouseEvent = static_cast(event); ++ if (mouseEvent) { ++ onMouseEvents(1, mouseEvent->pos()); ++ } ++ } ++ return true; ++ case QEvent::MouseMove: { ++ QMouseEvent *mouseEvent = static_cast(event); ++ if (mouseEvent) { ++ onMouseEvents(2, mouseEvent->pos()); ++ } ++ } ++ return true; ++ case QEvent::MouseButtonRelease: { ++ QMouseEvent *mouseEvent = static_cast(event); ++ if (mouseEvent) { ++ onMouseEvents(3, mouseEvent->pos()); ++ } ++ } ++ return true; ++ default: ++ break; + } + return QWidget::eventFilter(watched, event); + } +@@ -222,7 +226,7 @@ void VirtualKeyboardWidget::paintEvent(QPaintEvent *event) + QPainterPath path; + QPainter painter(this); + painter.setOpacity(1.0); +- painter.setRenderHint(QPainter::Antialiasing); // 反锯齿; ++ painter.setRenderHint(QPainter::Antialiasing); // 反锯齿; + painter.setClipping(true); + painter.setPen(Qt::transparent); + if (m_isdragState) { +@@ -242,7 +246,7 @@ void VirtualKeyboardWidget::onSpecialBtnClicked(QString keyName) + Modifier::MOD mod = Modifier::getModifier(keyName); + FuncKey::FUNCKEY funcKey = FuncKey::getKey(keyName); + if (mod != Modifier::UNKNOWN) { +- if(vKeyboard->hasModifier(mod)) { ++ if (vKeyboard->hasModifier(mod)) { + vKeyboard->removeModifier(mod); + m_lettersWidget->changeFuncKeyStyle(keyName, false); + } else { +@@ -253,7 +257,7 @@ void VirtualKeyboardWidget::onSpecialBtnClicked(QString keyName) + Q_EMIT keyPressed(FuncKey::CAPSLOCK); + clearModifier(); + } +- } else if(funcKey != FuncKey::UNKNOWN) { ++ } else if (funcKey != FuncKey::UNKNOWN) { + Q_EMIT keyPressed(funcKey); + } else if (keyName == PAGE_CHARSMORE) { + m_stackedWidget->setCurrentIndex(VKB_PAGE_CHARSMORE); +@@ -284,46 +288,68 @@ void VirtualKeyboardWidget::onNormalBtnClicked(QChar c) + + void VirtualKeyboardWidget::clearModifier() + { +- for(auto mod : vKeyboard->getAllModifier()) { ++ for (auto mod : vKeyboard->getAllModifier()) { + QString modName = Modifier::getModifierName(mod); + m_lettersWidget->changeFuncKeyStyle(modName, false); + } + vKeyboard->clearModifier(); + } + +-void VirtualKeyboardWidget::onMouseEvents(int type) ++void VirtualKeyboardWidget::onMouseEvents(int type, const QPoint &pos) + { ++ QPoint globalPos = mapToGlobal(pos); + switch (type) { +- case 1: +- { +- isMove = true; +- lastPoint = QCursor::pos(); +- break; +- } +- case 2: +- { +- if(isMove) +- { +- QPoint cPoint = QCursor::pos(); +- QPoint p = pos(); +- p.setX(p.x() - lastPoint.x() + cPoint.x()); +- p.setY(p.y() - lastPoint.y() + cPoint.y()); +- lastPoint = cPoint; ++ case 1: { ++ isMove = true; ++ lastPoint = globalPos; ++ break; ++ } ++ case 2: { ++ if (isMove) { ++ QPoint cPoint = globalPos; ++ QPoint p = this->pos(); ++ p.setX(p.x() - lastPoint.x() + cPoint.x()); ++ p.setY(p.y() - lastPoint.y() + cPoint.y()); ++ lastPoint = cPoint; ++ move(p); ++ } ++ break; ++ } ++ case 3: { ++ // 把虚拟键盘坐标检测放在release事件处理中,如果虚拟键盘坐标超出了屏幕, ++ // 则在收到release事件后把坐标设回来 ++ QPoint p = this->pos(); ++ int maxWidth; ++ int maxHeight; ++ if (this->parentWidget()) { ++ maxWidth = this->parentWidget()->width(); ++ maxHeight = this->parentWidget()->height(); ++ } else { ++ QScreen *screen = qApp->primaryScreen(); ++ maxWidth = screen->geometry().width(); ++ maxHeight = screen->geometry().height(); ++ } ++ if (this->x() > maxWidth - 10) { ++ p.setX(maxWidth - 10); ++ } else if (this->x() + this->width() < 10) { ++ p.setX(10 - this->width()); ++ } ++ ++ if (this->y() > maxHeight - 10) { ++ p.setY(maxHeight - 10); ++ } else if (this->y() + m_dragWidget->height() < 10) { ++ p.setY(0); ++ } ++ + move(p); ++ isMove = false; ++ break; + } +- break; +- } +- case 3: +- { +- isMove = false; +- break; +- } +- default: +- break; ++ default: ++ break; + } + } + +- + bool VirtualKeyboardWidget::getFloatStatus() + { + return m_isdragState; +diff --git a/src/VirtualKeyboard/src/virtualkeyboardwidget.h b/src/VirtualKeyboard/src/virtualkeyboardwidget.h +index 3897591..07c1442 100644 +--- a/src/VirtualKeyboard/src/virtualkeyboardwidget.h ++++ b/src/VirtualKeyboard/src/virtualkeyboardwidget.h +@@ -66,7 +66,7 @@ protected: + private: + void initUI(); + void initConnections(); +- void onMouseEvents(int type); ++ void onMouseEvents(int type, const QPoint &pos); + void clearModifier(); + + private: diff --git a/debian/patches/series b/debian/patches/series index 073fc41..4afc7a7 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -41,3 +41,4 @@ 0041-Translated-using-Weblate-Uyghur.patch 0042-Translated-using-Weblate-Mongolian.patch 0043-3-fixbug.patch +0044-4-fixbug.patch