From 5be490d326b7f25e65611f79fbb08edb5f17413f Mon Sep 17 00:00:00 2001 From: FrzMtrsprt Date: Fri, 7 Oct 2022 12:20:14 +0800 Subject: [PATCH 1/2] Enable dark window border on Windows --- QtScrcpy/CMakeLists.txt | 2 ++ QtScrcpy/ui/dialog.cpp | 6 ++++++ QtScrcpy/util/winutils.cpp | 24 ++++++++++++++++++++++++ QtScrcpy/util/winutils.h | 16 ++++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 QtScrcpy/util/winutils.cpp create mode 100644 QtScrcpy/util/winutils.h diff --git a/QtScrcpy/CMakeLists.txt b/QtScrcpy/CMakeLists.txt index cc3568133..deeb394c3 100755 --- a/QtScrcpy/CMakeLists.txt +++ b/QtScrcpy/CMakeLists.txt @@ -149,6 +149,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows") set(QC_UTIL_SOURCES ${QC_UTIL_SOURCES} util/mousetap/winmousetap.h util/mousetap/winmousetap.cpp + util/winutils.h + util/winutils.cpp ) endif() if(CMAKE_SYSTEM_NAME STREQUAL "Linux") diff --git a/QtScrcpy/ui/dialog.cpp b/QtScrcpy/ui/dialog.cpp index 1fbdf689f..a9da8bbe4 100644 --- a/QtScrcpy/ui/dialog.cpp +++ b/QtScrcpy/ui/dialog.cpp @@ -11,6 +11,10 @@ #include "videoform.h" #include "../groupcontroller/groupcontroller.h" +#ifdef Q_OS_WIN32 +#include "../util/winutils.h" +#endif + QString s_keyMapPath = ""; const QString &getKeyMapPath() @@ -137,6 +141,8 @@ void Dialog::initUI() setWindowTitle(Config::getInstance().getTitle()); + WinUtils::setDarkBorderToWindow((HWND)this->winId(), true); + ui->bitRateEdit->setValidator(new QIntValidator(1, 99999, this)); ui->maxSizeBox->addItem("640"); diff --git a/QtScrcpy/util/winutils.cpp b/QtScrcpy/util/winutils.cpp new file mode 100644 index 000000000..234bc834f --- /dev/null +++ b/QtScrcpy/util/winutils.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +#pragma comment(lib, "dwmapi") + +#include "winutils.h" + +enum : WORD +{ + DwmwaUseImmersiveDarkMode = 20, + DwmwaUseImmersiveDarkModeBefore20h1 = 19 +}; + +// Set dark border to window +// Reference: qt/qtbase.git/tree/src/plugins/platforms/windows/qwindowswindow.cpp +bool WinUtils::setDarkBorderToWindow(const HWND &hwnd, const bool &d) +{ + const BOOL darkBorder = d ? TRUE : FALSE; + const bool ok = SUCCEEDED(DwmSetWindowAttribute(hwnd, DwmwaUseImmersiveDarkMode, &darkBorder, sizeof(darkBorder))) + || SUCCEEDED(DwmSetWindowAttribute(hwnd, DwmwaUseImmersiveDarkModeBefore20h1, &darkBorder, sizeof(darkBorder))); + if (!ok) + qWarning("%s: Unable to set dark window border.", __FUNCTION__); + return ok; +} diff --git a/QtScrcpy/util/winutils.h b/QtScrcpy/util/winutils.h new file mode 100644 index 000000000..58f1fc989 --- /dev/null +++ b/QtScrcpy/util/winutils.h @@ -0,0 +1,16 @@ +#ifndef WINUTILS_H +#define WINUTILS_H + +#include +#include + +class WinUtils +{ +public: + WinUtils(); + ~WinUtils(); + + static bool setDarkBorderToWindow(const HWND &hwnd, const bool &d); +}; + +#endif // WINUTILS_H From b9cd8416088aad344d53d58182c9e7b2ba05de70 Mon Sep 17 00:00:00 2001 From: FrzMtrsprt Date: Sun, 16 Oct 2022 21:29:47 +0800 Subject: [PATCH 2/2] Fix build error --- QtScrcpy/ui/dialog.cpp | 2 ++ QtScrcpy/util/winutils.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/QtScrcpy/ui/dialog.cpp b/QtScrcpy/ui/dialog.cpp index a9da8bbe4..610e244bb 100644 --- a/QtScrcpy/ui/dialog.cpp +++ b/QtScrcpy/ui/dialog.cpp @@ -141,7 +141,9 @@ void Dialog::initUI() setWindowTitle(Config::getInstance().getTitle()); +#ifdef Q_OS_WIN32 WinUtils::setDarkBorderToWindow((HWND)this->winId(), true); +#endif ui->bitRateEdit->setValidator(new QIntValidator(1, 99999, this)); diff --git a/QtScrcpy/util/winutils.cpp b/QtScrcpy/util/winutils.cpp index 234bc834f..53e450cb5 100644 --- a/QtScrcpy/util/winutils.cpp +++ b/QtScrcpy/util/winutils.cpp @@ -11,6 +11,10 @@ enum : WORD DwmwaUseImmersiveDarkModeBefore20h1 = 19 }; +WinUtils::WinUtils(){}; + +WinUtils::~WinUtils(){}; + // Set dark border to window // Reference: qt/qtbase.git/tree/src/plugins/platforms/windows/qwindowswindow.cpp bool WinUtils::setDarkBorderToWindow(const HWND &hwnd, const bool &d)