Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions frame/utility_x11.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "private/utility_x11_p.h"

#include <QLoggingCategory>

Check warning on line 7 in frame/utility_x11.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QLoggingCategory> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QMouseEvent>

Check warning on line 8 in frame/utility_x11.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMouseEvent> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QTouchEvent>

Check warning on line 9 in frame/utility_x11.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTouchEvent> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <xcb/xcb.h>

Check warning on line 11 in frame/utility_x11.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <xcb/xcb.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <X11/Xlib.h>

Check warning on line 12 in frame/utility_x11.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <X11/Xlib.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <X11/extensions/XTest.h>

DS_BEGIN_NAMESPACE
Expand Down Expand Up @@ -119,13 +120,28 @@
if (isMainWindow()) {
trySelectGrabWindow(static_cast<QMouseEvent *>(event));
}
} else if (event->type() == QEvent::TouchBegin) {
// Handle touch events - close popup when touching outside
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
if (!touchEvent->points().isEmpty()) {
QEventPoint pt = touchEvent->points().first();
// Use frameGeometry() to get global coordinates for comparison
const auto bounding = m_target->frameGeometry();
const auto pos = pt.globalPosition();
if (!bounding.contains(pos.toPoint())) {
qCDebug(dsLog) << "touch outside menu window:" << m_target->winId();
emit outsideMousePressed();
return true;
}
}
}
return false;
}

void MouseGrabEventFilter::mousePressEvent(QMouseEvent *e)
{
const auto bounding = m_target->geometry();
// Use frameGeometry() to get global coordinates for comparison with globalPosition()
const auto bounding = m_target->frameGeometry();
const auto pos = e->globalPosition();
if ((e->position().toPoint().isNull() && !pos.isNull()) ||
!bounding.contains(pos.toPoint())) {
Expand All @@ -137,14 +153,16 @@

bool MouseGrabEventFilter::trySelectGrabWindow(QMouseEvent *e)
{
const auto bounding = m_target->geometry();
// Use frameGeometry() to get global coordinates for comparison with globalPosition()
const auto bounding = m_target->frameGeometry();
auto pos = QPointF(e->globalPosition());
if ((e->position().toPoint().isNull() && !pos.isNull()) ||
!bounding.contains(pos.toPoint())) {
for (auto item : Utility::instance()->allChildrenWindows(m_target)) {
if (!item->isVisible() || isMainWindow(item))
continue;
if (item->geometry().contains(pos.toPoint())) {
// Use frameGeometry() for child windows too
if (item->frameGeometry().contains(pos.toPoint())) {
qCDebug(dsLog) << "grab mouse for the window:" << item->winId();
m_target->setMouseGrabEnabled(false);
item->setMouseGrabEnabled(true);
Expand Down
Loading