Support Windows 11 rounded corners and themeable title bar.

This commit is contained in:
John Preston 2021-09-28 21:11:35 +04:00
parent de2bad51d3
commit 844fd58a97
6 changed files with 14 additions and 31 deletions

View file

@ -1370,6 +1370,7 @@ if (WIN32)
/DELAYLOAD:gdiplus.dll /DELAYLOAD:gdiplus.dll
/DELAYLOAD:version.dll /DELAYLOAD:version.dll
/DELAYLOAD:dwmapi.dll /DELAYLOAD:dwmapi.dll
/DELAYLOAD:uxtheme.dll
/DELAYLOAD:crypt32.dll /DELAYLOAD:crypt32.dll
/DELAYLOAD:bcrypt.dll /DELAYLOAD:bcrypt.dll
/DELAYLOAD:imm32.dll /DELAYLOAD:imm32.dll

View file

@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mainwindow.h" #include "mainwindow.h"
#include "base/crc32hash.h" #include "base/crc32hash.h"
#include "base/platform/win/base_windows_wrl.h" #include "base/platform/win/base_windows_wrl.h"
#include "base/platform/base_platform_info.h"
#include "core/application.h" #include "core/application.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "storage/localstorage.h" #include "storage/localstorage.h"
@ -34,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <Shobjidl.h> #include <Shobjidl.h>
#include <shellapi.h> #include <shellapi.h>
#include <WtsApi32.h> #include <WtsApi32.h>
#include <dwmapi.h>
#include <windows.ui.viewmanagement.h> #include <windows.ui.viewmanagement.h>
#include <UIViewSettingsInterop.h> #include <UIViewSettingsInterop.h>
@ -401,11 +403,9 @@ void MainWindow::initHook() {
} }
void MainWindow::validateWindowTheme(bool native, bool night) { void MainWindow::validateWindowTheme(bool native, bool night) {
if (!Dlls::SetWindowTheme) { if (!IsWindows8OrGreater()) {
return;
} else if (!IsWindows8OrGreater()) {
const auto empty = native ? nullptr : L" "; const auto empty = native ? nullptr : L" ";
Dlls::SetWindowTheme(ps_hWnd, empty, empty); SetWindowTheme(ps_hWnd, empty, empty);
QApplication::setStyle(QStyleFactory::create(u"Windows"_q)); QApplication::setStyle(QStyleFactory::create(u"Windows"_q));
#if 0 #if 0
} else if (!Platform::IsDarkModeSupported()/* } else if (!Platform::IsDarkModeSupported()/*
@ -416,7 +416,7 @@ void MainWindow::validateWindowTheme(bool native, bool night) {
return; return;
#endif #endif
} else if (!native) { } else if (!native) {
Dlls::SetWindowTheme(ps_hWnd, nullptr, nullptr); SetWindowTheme(ps_hWnd, nullptr, nullptr);
return; return;
} }
@ -435,13 +435,13 @@ void MainWindow::validateWindowTheme(bool native, bool night) {
sizeof(darkValue) sizeof(darkValue)
}; };
Dlls::SetWindowCompositionAttribute(ps_hWnd, &data); Dlls::SetWindowCompositionAttribute(ps_hWnd, &data);
} else if (kSystemVersion.microVersion() >= 17763 && Dlls::DwmSetWindowAttribute) { } else if (kSystemVersion.microVersion() >= 17763) {
static const auto DWMWA_USE_IMMERSIVE_DARK_MODE = (kSystemVersion.microVersion() >= 18985) static const auto kDWMWA_USE_IMMERSIVE_DARK_MODE = (kSystemVersion.microVersion() >= 18985)
? DWORD(20) ? DWORD(20)
: DWORD(19); : DWORD(19);
Dlls::DwmSetWindowAttribute( DwmSetWindowAttribute(
ps_hWnd, ps_hWnd,
DWMWA_USE_IMMERSIVE_DARK_MODE, kDWMWA_USE_IMMERSIVE_DARK_MODE,
&darkValue, &darkValue,
sizeof(darkValue)); sizeof(darkValue));
} }
@ -457,7 +457,7 @@ void MainWindow::validateWindowTheme(bool native, bool night) {
//const auto updateWindowTheme = [&] { //const auto updateWindowTheme = [&] {
// const auto set = [&](LPCWSTR name) { // const auto set = [&](LPCWSTR name) {
// return Dlls::SetWindowTheme(ps_hWnd, name, nullptr); // return SetWindowTheme(ps_hWnd, name, nullptr);
// }; // };
// if (!night || FAILED(set(L"DarkMode_Explorer"))) { // if (!night || FAILED(set(L"DarkMode_Explorer"))) {
// set(L"Explorer"); // set(L"Explorer");

View file

@ -36,13 +36,12 @@ SafeIniter::SafeIniter() {
LOAD_SYMBOL(LibShell32, SHChangeNotify); LOAD_SYMBOL(LibShell32, SHChangeNotify);
LOAD_SYMBOL(LibShell32, SetCurrentProcessExplicitAppUserModelID); LOAD_SYMBOL(LibShell32, SetCurrentProcessExplicitAppUserModelID);
const auto LibUxTheme = LoadLibrary(L"uxtheme.dll");
LOAD_SYMBOL(LibUxTheme, SetWindowTheme);
//if (IsWindows10OrGreater()) { //if (IsWindows10OrGreater()) {
// static const auto kSystemVersion = QOperatingSystemVersion::current(); // static const auto kSystemVersion = QOperatingSystemVersion::current();
// static const auto kMinor = kSystemVersion.minorVersion(); // static const auto kMinor = kSystemVersion.minorVersion();
// static const auto kBuild = kSystemVersion.microVersion(); // static const auto kBuild = kSystemVersion.microVersion();
// if (kMinor > 0 || (kMinor == 0 && kBuild >= 17763)) { // if (kMinor > 0 || (kMinor == 0 && kBuild >= 17763)) {
// const auto LibUxTheme = LoadLibrary(L"uxtheme.dll");
// if (kBuild < 18362) { // if (kBuild < 18362) {
// LOAD_SYMBOL(LibUxTheme, AllowDarkModeForApp, 135); // LOAD_SYMBOL(LibUxTheme, AllowDarkModeForApp, 135);
// } else { // } else {
@ -62,9 +61,6 @@ SafeIniter::SafeIniter() {
LOAD_SYMBOL(LibPropSys, PropVariantToString); LOAD_SYMBOL(LibPropSys, PropVariantToString);
LOAD_SYMBOL(LibPropSys, PSStringFromPropertyKey); LOAD_SYMBOL(LibPropSys, PSStringFromPropertyKey);
const auto LibDwmApi = LoadLibrary(L"dwmapi.dll");
LOAD_SYMBOL(LibDwmApi, DwmSetWindowAttribute);
const auto LibPsApi = LoadLibrary(L"psapi.dll"); const auto LibPsApi = LoadLibrary(L"psapi.dll");
LOAD_SYMBOL(LibPsApi, GetProcessMemoryInfo); LOAD_SYMBOL(LibPsApi, GetProcessMemoryInfo);

View file

@ -24,12 +24,6 @@ namespace Dlls {
void CheckLoadedModules(); void CheckLoadedModules();
// UXTHEME.DLL
inline HRESULT(__stdcall *SetWindowTheme)(
HWND hWnd,
LPCWSTR pszSubAppName,
LPCWSTR pszSubIdList);
//inline void(__stdcall *RefreshImmersiveColorPolicyState)(); //inline void(__stdcall *RefreshImmersiveColorPolicyState)();
// //
//inline BOOL(__stdcall *AllowDarkModeForApp)(BOOL allow); //inline BOOL(__stdcall *AllowDarkModeForApp)(BOOL allow);
@ -94,14 +88,6 @@ inline HRESULT(__stdcall *PSStringFromPropertyKey)(
_Out_writes_(cch) LPWSTR psz, _Out_writes_(cch) LPWSTR psz,
_In_ UINT cch); _In_ UINT cch);
// DWMAPI.DLL
inline HRESULT(__stdcall *DwmSetWindowAttribute)(
HWND hwnd,
DWORD dwAttribute,
_In_reads_bytes_(cbAttribute) LPCVOID pvAttribute,
DWORD cbAttribute);
// PSAPI.DLL // PSAPI.DLL
inline BOOL(__stdcall *GetProcessMemoryInfo)( inline BOOL(__stdcall *GetProcessMemoryInfo)(

@ -1 +1 @@
Subproject commit 40fc5b35f005d14b7216d956051a55429d984065 Subproject commit a827d9436e9ca258dfdfb9b67ef1ad917c13c5b5

2
cmake

@ -1 +1 @@
Subproject commit f3a611c82bfee860f950d5ca6563d8d68262b38d Subproject commit c4c2bf4bada5207570a78fa3541907a1e9e7bda5