mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-08-03 14:18:45 +00:00
feat: good framelesswindow for win
This commit is contained in:
parent
80851675f2
commit
f2ec08391b
7 changed files with 53 additions and 56 deletions
|
@ -8,16 +8,4 @@ SOURCES += \
|
||||||
$$PWD/keepratiowidget.cpp \
|
$$PWD/keepratiowidget.cpp \
|
||||||
$$PWD/magneticwidget.cpp
|
$$PWD/magneticwidget.cpp
|
||||||
|
|
||||||
win32 {
|
|
||||||
SOURCES +=
|
|
||||||
}
|
|
||||||
|
|
||||||
mac {
|
|
||||||
SOURCES +=
|
|
||||||
}
|
|
||||||
|
|
||||||
linux {
|
|
||||||
SOURCES +=
|
|
||||||
}
|
|
||||||
|
|
||||||
include ($$PWD/windowframelesshelper/windowframelesshelper.pri)
|
include ($$PWD/windowframelesshelper/windowframelesshelper.pri)
|
||||||
|
|
|
@ -4,9 +4,6 @@
|
||||||
WindowFramelessHelper::WindowFramelessHelper(QObject *parent) : QObject(parent)
|
WindowFramelessHelper::WindowFramelessHelper(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
WindowFramelessManager::Instance()->addWindow(this);
|
WindowFramelessManager::Instance()->addWindow(this);
|
||||||
#ifdef Q_OS_WIN32
|
|
||||||
WindowNativeEventFilter::Instance()->Init();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowFramelessHelper::~WindowFramelessHelper()
|
WindowFramelessHelper::~WindowFramelessHelper()
|
||||||
|
|
|
@ -1,18 +1,21 @@
|
||||||
#include "windowframelessmanager.h"
|
#include "windowframelessmanager.h"
|
||||||
#include "windowframelesshelper.h"
|
|
||||||
#include "nativewindowutils.h"
|
#include "nativewindowutils.h"
|
||||||
|
#include "windowframelesshelper.h"
|
||||||
|
|
||||||
static QVector<WindowFramelessHelper*> s_windowFramelessHelpers;
|
#ifdef Q_OS_WIN32
|
||||||
|
#include "windownativeeventfilterwin.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static QVector<WindowFramelessHelper *> s_windowFramelessHelpers;
|
||||||
|
|
||||||
WindowFramelessManager::WindowFramelessManager()
|
WindowFramelessManager::WindowFramelessManager()
|
||||||
{
|
{
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
WindowNativeEventFilterWin::Instance()->Init();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowFramelessManager::~WindowFramelessManager()
|
WindowFramelessManager::~WindowFramelessManager() {}
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
WindowFramelessManager *WindowFramelessManager::Instance()
|
WindowFramelessManager *WindowFramelessManager::Instance()
|
||||||
{
|
{
|
||||||
|
@ -20,7 +23,7 @@ WindowFramelessManager *WindowFramelessManager::Instance()
|
||||||
return &windowNativeEventFilter;
|
return &windowNativeEventFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowFramelessManager::addWindow(WindowFramelessHelper* win)
|
void WindowFramelessManager::addWindow(WindowFramelessHelper *win)
|
||||||
{
|
{
|
||||||
if (nullptr == win) {
|
if (nullptr == win) {
|
||||||
return;
|
return;
|
||||||
|
@ -28,7 +31,7 @@ void WindowFramelessManager::addWindow(WindowFramelessHelper* win)
|
||||||
s_windowFramelessHelpers.push_back(win);
|
s_windowFramelessHelpers.push_back(win);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowFramelessManager::removeWindow(WindowFramelessHelper* win)
|
void WindowFramelessManager::removeWindow(WindowFramelessHelper *win)
|
||||||
{
|
{
|
||||||
if (nullptr == win) {
|
if (nullptr == win) {
|
||||||
return;
|
return;
|
||||||
|
@ -36,7 +39,7 @@ void WindowFramelessManager::removeWindow(WindowFramelessHelper* win)
|
||||||
s_windowFramelessHelpers.removeOne(win);
|
s_windowFramelessHelpers.removeOne(win);
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowFramelessHelper* WindowFramelessManager::getWindowByHandle(quint64 handle)
|
WindowFramelessHelper *WindowFramelessManager::getWindowByHandle(quint64 handle)
|
||||||
{
|
{
|
||||||
quint64 targetHandle = 0;
|
quint64 targetHandle = 0;
|
||||||
for (auto i = s_windowFramelessHelpers.begin(); i != s_windowFramelessHelpers.end(); i++) {
|
for (auto i = s_windowFramelessHelpers.begin(); i != s_windowFramelessHelpers.end(); i++) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
class windownativeeventfiltermac
|
class WindowNativeEventFilterMac
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
windownativeeventfiltermac();
|
WindowNativeEventFilterMac();
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include "windowframelessmanager.h"
|
#include "windowframelessmanager.h"
|
||||||
|
|
||||||
windownativeeventfiltermac::windownativeeventfiltermac()
|
WindowNativeEventFilterMac::WindowNativeEventFilterMac()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +1,27 @@
|
||||||
#include "windownativeeventfilter.h"
|
#include "windownativeeventfilterwin.h"
|
||||||
|
#include "windowframelesshelper.h"
|
||||||
|
#include "windowframelessmanager.h"
|
||||||
|
|
||||||
#if defined(Q_OS_WIN)
|
|
||||||
#include <QCursor>
|
#include <QCursor>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <windowsx.h>
|
#include <windowsx.h>
|
||||||
|
|
||||||
WindowNativeEventFilter::WindowNativeEventFilter() {}
|
WindowNativeEventFilterWin::WindowNativeEventFilterWin() {}
|
||||||
|
|
||||||
WindowNativeEventFilter::~WindowNativeEventFilter()
|
WindowNativeEventFilterWin::~WindowNativeEventFilterWin()
|
||||||
{
|
{
|
||||||
// do nothing, because this object is static instance
|
// do nothing, because this object is static instance
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowNativeEventFilter *WindowNativeEventFilter::Instance()
|
WindowNativeEventFilterWin *WindowNativeEventFilterWin::Instance()
|
||||||
{
|
{
|
||||||
static WindowNativeEventFilter g_windowNativeEventFilter;
|
static WindowNativeEventFilterWin g_WindowNativeEventFilterWin;
|
||||||
return &g_windowNativeEventFilter;
|
return &g_WindowNativeEventFilterWin;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowNativeEventFilter::Init()
|
void WindowNativeEventFilterWin::Init()
|
||||||
{
|
{
|
||||||
if (!m_inited) {
|
if (!m_inited) {
|
||||||
m_inited = true;
|
m_inited = true;
|
||||||
|
@ -28,7 +29,7 @@ void WindowNativeEventFilter::Init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WindowNativeEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
|
bool WindowNativeEventFilterWin::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
|
||||||
{
|
{
|
||||||
Q_UNUSED(eventType);
|
Q_UNUSED(eventType);
|
||||||
|
|
||||||
|
@ -60,14 +61,19 @@ bool WindowNativeEventFilter::nativeEventFilter(const QByteArray &eventType, voi
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WindowNativeEventFilter::processNcHitTest(void *message, long *result)
|
bool WindowNativeEventFilterWin::processNcHitTest(void *message, long *result)
|
||||||
{
|
{
|
||||||
MSG *param = static_cast<MSG *>(message);
|
MSG *param = static_cast<MSG *>(message);
|
||||||
if (!param) {
|
if (!param) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWindow *window = getWindow((WId)param->hwnd);
|
WindowFramelessHelper *win = WindowFramelessManager::Instance()->getWindowByHandle((quint64)param->hwnd);
|
||||||
|
if (!win) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QWindow *window = win->target();
|
||||||
if (!window) {
|
if (!window) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -96,7 +102,6 @@ bool WindowNativeEventFilter::processNcHitTest(void *message, long *result)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "processNcHitTest:" << ptCursor << window->geometry() << "d:" << nX;
|
|
||||||
int borderWidth = 5;
|
int borderWidth = 5;
|
||||||
if ((nX > m_windowMargin.left()) && (nX < m_windowMargin.left() + borderWidth) && (nY > m_windowMargin.top())
|
if ((nX > m_windowMargin.left()) && (nX < m_windowMargin.left() + borderWidth) && (nY > m_windowMargin.top())
|
||||||
&& (nY < m_windowMargin.top() + borderWidth)) {
|
&& (nY < m_windowMargin.top() + borderWidth)) {
|
||||||
|
@ -126,7 +131,7 @@ bool WindowNativeEventFilter::processNcHitTest(void *message, long *result)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WindowNativeEventFilter::processNcLButtonDown(void *message, long *result)
|
bool WindowNativeEventFilterWin::processNcLButtonDown(void *message, long *result)
|
||||||
{
|
{
|
||||||
Q_UNUSED(result);
|
Q_UNUSED(result);
|
||||||
|
|
||||||
|
@ -135,7 +140,12 @@ bool WindowNativeEventFilter::processNcLButtonDown(void *message, long *result)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWindow *window = getWindow((WId)param->hwnd);
|
WindowFramelessHelper *win = WindowFramelessManager::Instance()->getWindowByHandle((quint64)param->hwnd);
|
||||||
|
if (!win) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QWindow *window = win->target();
|
||||||
if (!window) {
|
if (!window) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -173,7 +183,7 @@ bool WindowNativeEventFilter::processNcLButtonDown(void *message, long *result)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WindowNativeEventFilter::processSetCursor(void *message, long *result)
|
bool WindowNativeEventFilterWin::processSetCursor(void *message, long *result)
|
||||||
{
|
{
|
||||||
Q_UNUSED(result);
|
Q_UNUSED(result);
|
||||||
|
|
||||||
|
@ -182,7 +192,12 @@ bool WindowNativeEventFilter::processSetCursor(void *message, long *result)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWindow *window = getWindow((WId)param->hwnd);
|
WindowFramelessHelper *win = WindowFramelessManager::Instance()->getWindowByHandle((quint64)param->hwnd);
|
||||||
|
if (!win) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QWindow *window = win->target();
|
||||||
if (!window) {
|
if (!window) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -240,7 +255,7 @@ bool WindowNativeEventFilter::processSetCursor(void *message, long *result)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWindow *WindowNativeEventFilter::getWindow(WId wndId)
|
QWindow *WindowNativeEventFilterWin::getWindow(WId wndId)
|
||||||
{
|
{
|
||||||
QWindowList windows = QGuiApplication::topLevelWindows();
|
QWindowList windows = QGuiApplication::topLevelWindows();
|
||||||
for (int i = 0; i < windows.size(); ++i) {
|
for (int i = 0; i < windows.size(); ++i) {
|
||||||
|
@ -250,5 +265,3 @@ QWindow *WindowNativeEventFilter::getWindow(WId wndId)
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //(Q_OS_WIN)
|
|
||||||
|
|
|
@ -1,18 +1,16 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <QWindow>
|
|
||||||
|
|
||||||
#if defined(Q_OS_WIN)
|
|
||||||
#include <QAbstractNativeEventFilter>
|
#include <QAbstractNativeEventFilter>
|
||||||
#include <QMargins>
|
#include <QMargins>
|
||||||
|
#include <QWindow>
|
||||||
|
|
||||||
class WindowNativeEventFilter : public QAbstractNativeEventFilter
|
class WindowNativeEventFilterWin : public QAbstractNativeEventFilter
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
WindowNativeEventFilter();
|
WindowNativeEventFilterWin();
|
||||||
~WindowNativeEventFilter() override;
|
~WindowNativeEventFilterWin() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static WindowNativeEventFilter *Instance();
|
static WindowNativeEventFilterWin *Instance();
|
||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override;
|
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override;
|
||||||
|
@ -28,5 +26,3 @@ private:
|
||||||
bool m_inited = false;
|
bool m_inited = false;
|
||||||
QMargins m_windowMargin = QMargins(0, 0, 0, 0);
|
QMargins m_windowMargin = QMargins(0, 0, 0, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // Q_OS_WIN
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue