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

Enable dark window border on Windows #690

Merged
merged 4 commits into from
Oct 17, 2022
Merged
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
2 changes: 2 additions & 0 deletions QtScrcpy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 8 additions & 0 deletions QtScrcpy/ui/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -137,6 +141,10 @@ 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));

ui->maxSizeBox->addItem("640");
Expand Down
28 changes: 28 additions & 0 deletions QtScrcpy/util/winutils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <QDebug>
#include <Windows.h>
#include <dwmapi.h>
#pragma comment(lib, "dwmapi")

#include "winutils.h"

enum : WORD
{
DwmwaUseImmersiveDarkMode = 20,
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)
{
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;
}
16 changes: 16 additions & 0 deletions QtScrcpy/util/winutils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef WINUTILS_H
#define WINUTILS_H

#include <QApplication>
#include <Windows.h>

class WinUtils
{
public:
WinUtils();
~WinUtils();

static bool setDarkBorderToWindow(const HWND &hwnd, const bool &d);
};

#endif // WINUTILS_H