parent
fc1566897f
commit
4f06aa1206
|
@ -12,15 +12,9 @@ set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
if(WIN32)
|
find_package(Qt5 COMPONENTS Quick REQUIRED)
|
||||||
set(CMAKE_DEBUG_POSTFIX "d")
|
|
||||||
else()
|
|
||||||
set(CMAKE_DEBUG_POSTFIX "_debug")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
find_package(Qt5 COMPONENTS Core Quick QuickCompiler REQUIRED)
|
set(source_files qml.qrc images.qrc main.cpp ../../framelessquickhelper.h ../../framelessquickhelper.cpp)
|
||||||
|
|
||||||
set(source_files images.qrc main.cpp ../../framelessquickhelper.h ../../framelessquickhelper.cpp)
|
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
enable_language(RC)
|
enable_language(RC)
|
||||||
|
@ -29,24 +23,11 @@ else()
|
||||||
list(APPEND source_files ../../framelesshelper.h ../../framelesshelper.cpp)
|
list(APPEND source_files ../../framelesshelper.h ../../framelesshelper.cpp)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
||||||
list(APPEND source_files qml.qrc)
|
|
||||||
else()
|
|
||||||
set(qml_files "")
|
|
||||||
qtquick_compiler_add_resources(qml_files qml.qrc)
|
|
||||||
list(APPEND source_files ${qml_files})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(WIN32)
|
|
||||||
# Without WIN32, a console window will show.
|
|
||||||
add_executable(QQPlayer WIN32 ${source_files})
|
add_executable(QQPlayer WIN32 ${source_files})
|
||||||
else()
|
|
||||||
add_executable(QQPlayer ${source_files})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
# Silence a compiler warning caused by the Chinese comments in the source file.
|
# Silence a compiler warning caused by the Chinese comments in the source file.
|
||||||
target_compile_options(QQPlayer PRIVATE -utf-8)
|
target_compile_options(QQPlayer PRIVATE -utf-8)
|
||||||
endif()
|
endif()
|
||||||
target_compile_definitions(QQPlayer PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
|
target_compile_definitions(QQPlayer PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
|
||||||
target_link_libraries(QQPlayer PRIVATE Qt::Core Qt::Quick Qt::GuiPrivate)
|
target_link_libraries(QQPlayer PRIVATE Qt::Quick Qt::GuiPrivate)
|
||||||
|
|
|
@ -53,6 +53,7 @@
|
||||||
#include <qpa/qplatformwindow_p.h>
|
#include <qpa/qplatformwindow_p.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef WNEF_LINK_SYSLIB
|
#ifdef WNEF_LINK_SYSLIB
|
||||||
|
#include <d2d1.h>
|
||||||
#include <dwmapi.h>
|
#include <dwmapi.h>
|
||||||
#include <shellapi.h>
|
#include <shellapi.h>
|
||||||
#include <shellscalingapi.h>
|
#include <shellscalingapi.h>
|
||||||
|
@ -327,6 +328,22 @@ using BP_PAINTPARAMS = struct _BP_PAINTPARAMS
|
||||||
CONST BLENDFUNCTION *pBlendFunction;
|
CONST BLENDFUNCTION *pBlendFunction;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using D2D1_FACTORY_TYPE = enum _D2D1_FACTORY_TYPE { D2D1_FACTORY_TYPE_SINGLE_THREADED = 0 };
|
||||||
|
|
||||||
|
using D2D1_DEBUG_LEVEL = enum _D2D1_DEBUG_LEVEL {
|
||||||
|
D2D1_DEBUG_LEVEL_NONE = 0,
|
||||||
|
D2D1_DEBUG_LEVEL_ERROR = 1,
|
||||||
|
D2D1_DEBUG_LEVEL_WARNING = 2,
|
||||||
|
D2D1_DEBUG_LEVEL_INFORMATION = 3,
|
||||||
|
D2D1_DEBUG_LEVEL_FORCE_DWORD = 0xffffffff
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
using D2D1_FACTORY_OPTIONS = struct _D2D1_FACTORY_OPTIONS
|
||||||
|
{
|
||||||
|
D2D1_DEBUG_LEVEL debugLevel;
|
||||||
|
};
|
||||||
|
|
||||||
// Some of the following functions are not used by this code anymore,
|
// Some of the following functions are not used by this code anymore,
|
||||||
// but we don't remove them completely because we may still need them later.
|
// but we don't remove them completely because we may still need them later.
|
||||||
WNEF_GENERATE_WINAPI(DwmExtendFrameIntoClientArea, HRESULT, HWND, CONST MARGINS *)
|
WNEF_GENERATE_WINAPI(DwmExtendFrameIntoClientArea, HRESULT, HWND, CONST MARGINS *)
|
||||||
|
@ -394,10 +411,8 @@ WNEF_GENERATE_WINAPI(BeginPaint, HDC, HWND, LPPAINTSTRUCT)
|
||||||
WNEF_GENERATE_WINAPI(EndPaint, BOOL, HWND, CONST PAINTSTRUCT *)
|
WNEF_GENERATE_WINAPI(EndPaint, BOOL, HWND, CONST PAINTSTRUCT *)
|
||||||
WNEF_GENERATE_WINAPI(GetCurrentProcess, HANDLE)
|
WNEF_GENERATE_WINAPI(GetCurrentProcess, HANDLE)
|
||||||
WNEF_GENERATE_WINAPI(IsProcessDPIAware, BOOL)
|
WNEF_GENERATE_WINAPI(IsProcessDPIAware, BOOL)
|
||||||
#if 0
|
WNEF_GENERATE_WINAPI(
|
||||||
WNEF_GENERATE_WINAPI(D2D1CreateFactory, HRESULT, D2D1_FACTORY_TYPE, REFIID,
|
D2D1CreateFactory, HRESULT, D2D1_FACTORY_TYPE, REFIID, CONST D2D1_FACTORY_OPTIONS *, void **)
|
||||||
CONST D2D1_FACTORY_OPTIONS *, void **)
|
|
||||||
#endif
|
|
||||||
WNEF_GENERATE_WINAPI(AdjustWindowRectEx, BOOL, LPRECT, DWORD, BOOL, DWORD)
|
WNEF_GENERATE_WINAPI(AdjustWindowRectEx, BOOL, LPRECT, DWORD, BOOL, DWORD)
|
||||||
WNEF_GENERATE_WINAPI(DwmDefWindowProc, BOOL, HWND, UINT, WPARAM, LPARAM, LRESULT *)
|
WNEF_GENERATE_WINAPI(DwmDefWindowProc, BOOL, HWND, UINT, WPARAM, LPARAM, LRESULT *)
|
||||||
WNEF_GENERATE_WINAPI(DwmGetWindowAttribute, HRESULT, HWND, DWORD, PVOID, DWORD)
|
WNEF_GENERATE_WINAPI(DwmGetWindowAttribute, HRESULT, HWND, DWORD, PVOID, DWORD)
|
||||||
|
@ -547,9 +562,7 @@ void ResolveWin32APIs()
|
||||||
WNEF_RESOLVE_WINAPI(UxTheme, EndBufferedPaint)
|
WNEF_RESOLVE_WINAPI(UxTheme, EndBufferedPaint)
|
||||||
WNEF_RESOLVE_WINAPI(UxTheme, BeginBufferedPaint)
|
WNEF_RESOLVE_WINAPI(UxTheme, BeginBufferedPaint)
|
||||||
// Available since Windows 7.
|
// Available since Windows 7.
|
||||||
#if 0
|
|
||||||
WNEF_RESOLVE_WINAPI(D2D1, D2D1CreateFactory)
|
WNEF_RESOLVE_WINAPI(D2D1, D2D1CreateFactory)
|
||||||
#endif
|
|
||||||
loadDPIFunctions();
|
loadDPIFunctions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -653,15 +666,18 @@ UINT GetDotsPerInchForSystem()
|
||||||
// Using Direct2D to get the screen DPI.
|
// Using Direct2D to get the screen DPI.
|
||||||
// Available since Windows 7.
|
// Available since Windows 7.
|
||||||
ID2D1Factory *m_pDirect2dFactory = nullptr;
|
ID2D1Factory *m_pDirect2dFactory = nullptr;
|
||||||
if (SUCCEEDED(m_lpD2D1CreateFactory(
|
if (SUCCEEDED(WNEF_EXECUTE_WINAPI_RETURN(D2D1CreateFactory,
|
||||||
D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory),
|
E_FAIL,
|
||||||
nullptr, reinterpret_cast<void **>(&m_pDirect2dFactory))) &&
|
D2D1_FACTORY_TYPE_SINGLE_THREADED,
|
||||||
m_pDirect2dFactory) {
|
__uuidof(ID2D1Factory),
|
||||||
|
nullptr,
|
||||||
|
reinterpret_cast<void **>(&m_pDirect2dFactory)))
|
||||||
|
&& m_pDirect2dFactory) {
|
||||||
m_pDirect2dFactory->ReloadSystemMetrics();
|
m_pDirect2dFactory->ReloadSystemMetrics();
|
||||||
FLOAT dpiX = defaultValue, dpiY = defaultValue;
|
FLOAT dpiX = defaultValue, dpiY = defaultValue;
|
||||||
m_pDirect2dFactory->GetDesktopDpi(&dpiX, &dpiY);
|
m_pDirect2dFactory->GetDesktopDpi(&dpiX, &dpiY);
|
||||||
// The values of *dpiX and *dpiY are identical.
|
// The values of *dpiX and *dpiY are identical.
|
||||||
return qRound(dpiX);
|
return qRound(dpiX == dpiY ? dpiY : dpiX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -953,17 +969,7 @@ QScopedPointer<WinNativeEventFilter> m_instance;
|
||||||
|
|
||||||
QList<HWND> m_framelessWindows = {};
|
QList<HWND> m_framelessWindows = {};
|
||||||
|
|
||||||
} // namespace
|
void install()
|
||||||
|
|
||||||
WinNativeEventFilter::WinNativeEventFilter()
|
|
||||||
{
|
|
||||||
ResolveWin32APIs();
|
|
||||||
qCoreAppFixup();
|
|
||||||
}
|
|
||||||
|
|
||||||
WinNativeEventFilter::~WinNativeEventFilter() = default;
|
|
||||||
|
|
||||||
void WinNativeEventFilter::install()
|
|
||||||
{
|
{
|
||||||
qCoreAppFixup();
|
qCoreAppFixup();
|
||||||
if (m_instance.isNull()) {
|
if (m_instance.isNull()) {
|
||||||
|
@ -972,7 +978,8 @@ void WinNativeEventFilter::install()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WinNativeEventFilter::uninstall()
|
#if 0
|
||||||
|
void uninstall()
|
||||||
{
|
{
|
||||||
if (!m_instance.isNull()) {
|
if (!m_instance.isNull()) {
|
||||||
qApp->removeNativeEventFilter(m_instance.data());
|
qApp->removeNativeEventFilter(m_instance.data());
|
||||||
|
@ -982,6 +989,41 @@ void WinNativeEventFilter::uninstall()
|
||||||
m_framelessWindows.clear();
|
m_framelessWindows.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void updateQtFrame_internal(const HWND handle)
|
||||||
|
{
|
||||||
|
Q_ASSERT(handle);
|
||||||
|
ResolveWin32APIs();
|
||||||
|
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, handle)) {
|
||||||
|
const int tbh = WinNativeEventFilter::getSystemMetric(
|
||||||
|
handle, WinNativeEventFilter::SystemMetric::TitleBarHeight);
|
||||||
|
#ifdef QT_WIDGETS_LIB
|
||||||
|
const QWidget *widget = QWidget::find(reinterpret_cast<WId>(handle));
|
||||||
|
if (widget && widget->isTopLevel()) {
|
||||||
|
QWindow *window = widget->windowHandle();
|
||||||
|
if (window) {
|
||||||
|
WinNativeEventFilter::updateQtFrame(window, tbh);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
QWindow *window = findQWindowFromRawHandle(handle);
|
||||||
|
if (window) {
|
||||||
|
WinNativeEventFilter::updateQtFrame(window, tbh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
WinNativeEventFilter::WinNativeEventFilter()
|
||||||
|
{
|
||||||
|
ResolveWin32APIs();
|
||||||
|
qCoreAppFixup();
|
||||||
|
}
|
||||||
|
|
||||||
|
WinNativeEventFilter::~WinNativeEventFilter() = default;
|
||||||
|
|
||||||
void WinNativeEventFilter::addFramelessWindow(void *window,
|
void WinNativeEventFilter::addFramelessWindow(void *window,
|
||||||
const WINDOWDATA *data,
|
const WINDOWDATA *data,
|
||||||
|
@ -2036,30 +2078,6 @@ void WinNativeEventFilter::updateQtFrame(QWindow *window, const int titleBarHeig
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WinNativeEventFilter::updateQtFrame_internal(void *handle)
|
|
||||||
{
|
|
||||||
Q_ASSERT(handle);
|
|
||||||
ResolveWin32APIs();
|
|
||||||
const auto hwnd = reinterpret_cast<HWND>(handle);
|
|
||||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, hwnd)) {
|
|
||||||
const int tbh = getSystemMetric(handle, SystemMetric::TitleBarHeight);
|
|
||||||
#ifdef QT_WIDGETS_LIB
|
|
||||||
const QWidget *widget = QWidget::find(reinterpret_cast<WId>(handle));
|
|
||||||
if (widget && widget->isTopLevel()) {
|
|
||||||
QWindow *window = widget->windowHandle();
|
|
||||||
if (window) {
|
|
||||||
updateQtFrame(window, tbh);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
QWindow *window = findQWindowFromRawHandle(hwnd);
|
|
||||||
if (window) {
|
|
||||||
updateQtFrame(window, tbh);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WinNativeEventFilter::displaySystemMenu(void *handle,
|
bool WinNativeEventFilter::displaySystemMenu(void *handle,
|
||||||
const bool isRtl,
|
const bool isRtl,
|
||||||
const int x,
|
const int x,
|
||||||
|
|
|
@ -50,9 +50,9 @@ class FRAMELESSHELPER_EXPORT WinNativeEventFilter : public QAbstractNativeEventF
|
||||||
public:
|
public:
|
||||||
using WINDOWDATA = struct _WINDOWDATA
|
using WINDOWDATA = struct _WINDOWDATA
|
||||||
{
|
{
|
||||||
bool initialized = false, fixedSize = false, mouseTransparent = false,
|
bool initialized = false /* Internal use only, don't modify it from outside */,
|
||||||
restoreDefaultWindowStyle = false, enableLayeredWindow = false,
|
fixedSize = false, mouseTransparent = false, restoreDefaultWindowStyle = false,
|
||||||
disableTitleBar = false;
|
enableLayeredWindow = false, disableTitleBar = false;
|
||||||
int borderWidth = -1, borderHeight = -1, titleBarHeight = -1;
|
int borderWidth = -1, borderHeight = -1, titleBarHeight = -1;
|
||||||
QList<QRect> ignoreAreas = {}, draggableAreas = {};
|
QList<QRect> ignoreAreas = {}, draggableAreas = {};
|
||||||
QList<QPointer<QObject>> ignoreObjects = {}, draggableObjects = {};
|
QList<QPointer<QObject>> ignoreObjects = {}, draggableObjects = {};
|
||||||
|
@ -68,7 +68,7 @@ public:
|
||||||
// The width and height will be scaled automatically according to DPI. Don't
|
// The width and height will be scaled automatically according to DPI. Don't
|
||||||
// scale them yourself. Just pass the original value. If you don't want to
|
// scale them yourself. Just pass the original value. If you don't want to
|
||||||
// change them, pass negative values to the parameters.
|
// change them, pass negative values to the parameters.
|
||||||
static void addFramelessWindow(void *window,
|
static void addFramelessWindow(void *window /* HWND */,
|
||||||
const WINDOWDATA *data = nullptr,
|
const WINDOWDATA *data = nullptr,
|
||||||
const bool center = false,
|
const bool center = false,
|
||||||
const int x = -1,
|
const int x = -1,
|
||||||
|
@ -82,7 +82,7 @@ public:
|
||||||
const int y = -1,
|
const int y = -1,
|
||||||
const int width = -1,
|
const int width = -1,
|
||||||
const int height = -1);
|
const int height = -1);
|
||||||
static void removeFramelessWindow(void *window);
|
static void removeFramelessWindow(void *window /* HWND */);
|
||||||
static void removeFramelessWindow(QObject *window);
|
static void removeFramelessWindow(QObject *window);
|
||||||
static void clearFramelessWindows();
|
static void clearFramelessWindows();
|
||||||
|
|
||||||
|
@ -90,11 +90,11 @@ public:
|
||||||
// restore default behavior.
|
// restore default behavior.
|
||||||
// Note that it can only affect one specific window.
|
// Note that it can only affect one specific window.
|
||||||
// If you want to change these values globally, use setBorderWidth instead.
|
// If you want to change these values globally, use setBorderWidth instead.
|
||||||
static void setWindowData(void *window, const WINDOWDATA *data);
|
static void setWindowData(void *window /* HWND */, const WINDOWDATA *data);
|
||||||
static void setWindowData(QObject *window, const WINDOWDATA *data);
|
static void setWindowData(QObject *window, const WINDOWDATA *data);
|
||||||
// You can modify the given window's data directly, it's the same with using
|
// You can modify the given window's data directly, it's the same with using
|
||||||
// setWindowData.
|
// setWindowData.
|
||||||
static WINDOWDATA *windowData(void *window);
|
static WINDOWDATA *windowData(void *window /* HWND */);
|
||||||
static WINDOWDATA *windowData(QObject *window);
|
static WINDOWDATA *windowData(QObject *window);
|
||||||
|
|
||||||
// Change settings globally, not a specific window.
|
// Change settings globally, not a specific window.
|
||||||
|
@ -106,12 +106,14 @@ public:
|
||||||
|
|
||||||
// System metric value of the given window (if the pointer is null,
|
// System metric value of the given window (if the pointer is null,
|
||||||
// return the system's standard value).
|
// return the system's standard value).
|
||||||
static int getSystemMetric(void *handle, const SystemMetric metric, const bool dpiAware = false);
|
static int getSystemMetric(void *handle /* HWND */,
|
||||||
|
const SystemMetric metric,
|
||||||
|
const bool dpiAware = false);
|
||||||
|
|
||||||
// Use this function to trigger a frame change event or redraw a
|
// Use this function to trigger a frame change event or redraw a
|
||||||
// specific window. Useful when you want to let some changes
|
// specific window. Useful when you want to let some changes
|
||||||
// in effect immediately.
|
// in effect immediately.
|
||||||
static void updateWindow(void *handle,
|
static void updateWindow(void *handle /* HWND */,
|
||||||
const bool triggerFrameChange = true,
|
const bool triggerFrameChange = true,
|
||||||
const bool redraw = true);
|
const bool redraw = true);
|
||||||
|
|
||||||
|
@ -119,29 +121,28 @@ public:
|
||||||
// The width and height will be scaled automatically according to DPI. So
|
// The width and height will be scaled automatically according to DPI. So
|
||||||
// just pass the original value.
|
// just pass the original value.
|
||||||
static void setWindowGeometry(
|
static void setWindowGeometry(
|
||||||
void *handle, const int x, const int y, const int width, const int height);
|
void *handle /* HWND */, const int x, const int y, const int width, const int height);
|
||||||
|
|
||||||
// Move the window to the center of the desktop.
|
// Move the window to the center of the desktop.
|
||||||
static void moveWindowToDesktopCenter(void *handle);
|
static void moveWindowToDesktopCenter(void *handle /* HWND */);
|
||||||
|
|
||||||
// Update Qt's internal data about the window frame, otherwise Qt will
|
// Update Qt's internal data about the window frame, otherwise Qt will
|
||||||
// take the size of the window frame into account when anyone is trying to
|
// take the size of the window frame into account when anyone is trying to
|
||||||
// change the geometry of the window. That's not what we want.
|
// change the geometry of the window. That's not what we want.
|
||||||
static void updateQtFrame(QWindow *window, const int titleBarHeight);
|
static void updateQtFrame(QWindow *window, const int titleBarHeight);
|
||||||
|
|
||||||
static bool displaySystemMenu(void *handle, const bool isRtl, const int x, const int y);
|
// Display the system context menu.
|
||||||
|
static bool displaySystemMenu(void *handle /* HWND */,
|
||||||
|
const bool isRtl,
|
||||||
|
const int x,
|
||||||
|
const int y);
|
||||||
|
|
||||||
|
///////////////////////////////////////////////
|
||||||
|
/// CORE FUNCTION - THE SOUL OF THIS CODE
|
||||||
|
///////////////////////////////////////////////
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||||
bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) override;
|
bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) override;
|
||||||
#else
|
#else
|
||||||
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override;
|
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
|
||||||
// Do not call these two functions directly, otherwise strange things
|
|
||||||
// will happen.
|
|
||||||
static void install();
|
|
||||||
static void uninstall();
|
|
||||||
|
|
||||||
static void updateQtFrame_internal(void *handle);
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue