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