Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync: from linuxdeepin/qt5platform-plugins #50

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
49 changes: 31 additions & 18 deletions xcb/dnotitlebarwindowhelper.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
// SPDX-FileCopyrightText: 2017 - 2022 Uniontech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2017 - 2024 Uniontech Software Technology Co.,Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#define protected public
#include <QWindow>
#undef protected
#include "dnotitlebarwindowhelper.h"
#include "vtablehook.h"
#include "utility.h"
#include "dwmsupport.h"
#include "dnativesettings.h"
#include "dplatformintegration.h"

#include <QWindow>
#include <QMouseEvent>
#include <QTimer>
#include <QMetaProperty>
#include <QScreen>
#include <qpa/qplatformwindow.h>
#include <QGuiApplication>
#include <QStyleHints>
#include <QDebug>

#define _DEEPIN_SCISSOR_WINDOW "_DEEPIN_SCISSOR_WINDOW"
Q_DECLARE_METATYPE(QPainterPath)
Expand Down Expand Up @@ -81,9 +79,8 @@ DNoTitlebarWindowHelper::~DNoTitlebarWindowHelper()
{
g_pressPoint.remove(this);

if (VtableHook::hasVtable(m_window)) {
VtableHook::resetVtable(m_window);
}
if (m_enableSystemMove)
m_window->removeEventFilter(this);

mapped.remove(qobject_cast<QWindow*>(parent()));

Expand Down Expand Up @@ -426,9 +423,9 @@ void DNoTitlebarWindowHelper::updateEnableSystemMoveFromProperty()
m_enableSystemMove = !v.isValid() || v.toBool();

if (m_enableSystemMove) {
VtableHook::overrideVfptrFun(m_window, &QWindow::event, this, &DNoTitlebarWindowHelper::windowEvent);
} else if (VtableHook::hasVtable(m_window)) {
VtableHook::resetVfptrFun(m_window, &QWindow::event);
m_window->installEventFilter(this);
} else {
m_window->removeEventFilter(this);
}
}

Expand Down Expand Up @@ -510,9 +507,24 @@ void DNoTitlebarWindowHelper::updateAutoInputMaskByClipPathFromProperty()
updateWindowShape();
}

bool DNoTitlebarWindowHelper::windowEvent(QEvent *event)
bool DNoTitlebarWindowHelper::eventFilter(QObject *watched, QEvent *event)
{
QWindow *w = this->window();
QWindow *w = qobject_cast<QWindow *>(watched);
if (!w)
return false;

static QSet<QEvent::Type> filterEvents {
QEvent::TouchBegin,
QEvent::TouchUpdate,
QEvent::TouchEnd,
// mouse event
QEvent::MouseButtonPress,
QEvent::MouseButtonRelease,
QEvent::MouseMove,
};

if (!filterEvents.contains(event->type()))
return false;

// get touch begin position
static bool isTouchDown = false;
Expand All @@ -531,7 +543,7 @@ bool DNoTitlebarWindowHelper::windowEvent(QEvent *event)
QPointF currentPos = static_cast<QMouseEvent*>(event)->globalPos();
QPointF delta = touchBeginPosition - currentPos;
if (delta.manhattanLength() < QGuiApplication::styleHints()->startDragDistance()) {
return VtableHook::callOriginalFun(w, &QWindow::event, event);
return watched->event(event);
}
}

Expand All @@ -549,7 +561,8 @@ bool DNoTitlebarWindowHelper::windowEvent(QEvent *event)
updateMoveWindow(winId);
}

bool ret = VtableHook::callOriginalFun(w, &QWindow::event, event);
// call first to set accept false(quickwindow)
watched->event(event);

// workaround for kwin: Qt receives no release event when kwin finishes MOVE operation,
// which makes app hang in windowMoving state. when a press happens, there's no sense of
Expand All @@ -563,12 +576,12 @@ bool DNoTitlebarWindowHelper::windowEvent(QEvent *event)
QMouseEvent *me = static_cast<QMouseEvent*>(event);
QRect windowRect = QRect(QPoint(0, 0), w->size());
if (!windowRect.contains(me->windowPos().toPoint())) {
return ret;
return true;
}

QPointF delta = me->globalPos() - g_pressPoint[this];
if (delta.manhattanLength() < QGuiApplication::styleHints()->startDragDistance()) {
return ret;
return true;
}

if (!self->m_windowMoving && self->isEnableSystemMove(winId)) {
Expand All @@ -583,7 +596,7 @@ bool DNoTitlebarWindowHelper::windowEvent(QEvent *event)
}
}

return ret;
return true;
}

bool DNoTitlebarWindowHelper::isEnableSystemMove(quint32 winId)
Expand Down
2 changes: 1 addition & 1 deletion xcb/dnotitlebarwindowhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private slots:
Q_SLOT void updateAutoInputMaskByClipPathFromProperty();

private:
bool windowEvent(QEvent *event);
virtual bool eventFilter(QObject *watched, QEvent *event) override;
bool isEnableSystemMove(quint32 winId);
bool updateWindowBlurAreasForWM();
void updateWindowShape();
Expand Down
Loading