From 844fd58a9734b943006f2fe7995c90e7f6f0427b Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 28 Sep 2021 21:11:35 +0400 Subject: [PATCH] Support Windows 11 rounded corners and themeable title bar. --- Telegram/CMakeLists.txt | 1 + .../platform/win/main_window_win.cpp | 20 +++++++++---------- .../SourceFiles/platform/win/windows_dlls.cpp | 6 +----- .../SourceFiles/platform/win/windows_dlls.h | 14 ------------- Telegram/lib_ui | 2 +- cmake | 2 +- 6 files changed, 14 insertions(+), 31 deletions(-) diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index d9133905d9..4a48af07e1 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -1370,6 +1370,7 @@ if (WIN32) /DELAYLOAD:gdiplus.dll /DELAYLOAD:version.dll /DELAYLOAD:dwmapi.dll + /DELAYLOAD:uxtheme.dll /DELAYLOAD:crypt32.dll /DELAYLOAD:bcrypt.dll /DELAYLOAD:imm32.dll diff --git a/Telegram/SourceFiles/platform/win/main_window_win.cpp b/Telegram/SourceFiles/platform/win/main_window_win.cpp index fbac6d87fa..4595fd1d74 100644 --- a/Telegram/SourceFiles/platform/win/main_window_win.cpp +++ b/Telegram/SourceFiles/platform/win/main_window_win.cpp @@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwindow.h" #include "base/crc32hash.h" #include "base/platform/win/base_windows_wrl.h" +#include "base/platform/base_platform_info.h" #include "core/application.h" #include "lang/lang_keys.h" #include "storage/localstorage.h" @@ -34,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include #include +#include #include #include @@ -401,11 +403,9 @@ void MainWindow::initHook() { } void MainWindow::validateWindowTheme(bool native, bool night) { - if (!Dlls::SetWindowTheme) { - return; - } else if (!IsWindows8OrGreater()) { + if (!IsWindows8OrGreater()) { const auto empty = native ? nullptr : L" "; - Dlls::SetWindowTheme(ps_hWnd, empty, empty); + SetWindowTheme(ps_hWnd, empty, empty); QApplication::setStyle(QStyleFactory::create(u"Windows"_q)); #if 0 } else if (!Platform::IsDarkModeSupported()/* @@ -416,7 +416,7 @@ void MainWindow::validateWindowTheme(bool native, bool night) { return; #endif } else if (!native) { - Dlls::SetWindowTheme(ps_hWnd, nullptr, nullptr); + SetWindowTheme(ps_hWnd, nullptr, nullptr); return; } @@ -435,13 +435,13 @@ void MainWindow::validateWindowTheme(bool native, bool night) { sizeof(darkValue) }; Dlls::SetWindowCompositionAttribute(ps_hWnd, &data); - } else if (kSystemVersion.microVersion() >= 17763 && Dlls::DwmSetWindowAttribute) { - static const auto DWMWA_USE_IMMERSIVE_DARK_MODE = (kSystemVersion.microVersion() >= 18985) + } else if (kSystemVersion.microVersion() >= 17763) { + static const auto kDWMWA_USE_IMMERSIVE_DARK_MODE = (kSystemVersion.microVersion() >= 18985) ? DWORD(20) : DWORD(19); - Dlls::DwmSetWindowAttribute( + DwmSetWindowAttribute( ps_hWnd, - DWMWA_USE_IMMERSIVE_DARK_MODE, + kDWMWA_USE_IMMERSIVE_DARK_MODE, &darkValue, sizeof(darkValue)); } @@ -457,7 +457,7 @@ void MainWindow::validateWindowTheme(bool native, bool night) { //const auto updateWindowTheme = [&] { // 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"))) { // set(L"Explorer"); diff --git a/Telegram/SourceFiles/platform/win/windows_dlls.cpp b/Telegram/SourceFiles/platform/win/windows_dlls.cpp index a9d11138f9..d114115ab0 100644 --- a/Telegram/SourceFiles/platform/win/windows_dlls.cpp +++ b/Telegram/SourceFiles/platform/win/windows_dlls.cpp @@ -36,13 +36,12 @@ SafeIniter::SafeIniter() { LOAD_SYMBOL(LibShell32, SHChangeNotify); LOAD_SYMBOL(LibShell32, SetCurrentProcessExplicitAppUserModelID); - const auto LibUxTheme = LoadLibrary(L"uxtheme.dll"); - LOAD_SYMBOL(LibUxTheme, SetWindowTheme); //if (IsWindows10OrGreater()) { // static const auto kSystemVersion = QOperatingSystemVersion::current(); // static const auto kMinor = kSystemVersion.minorVersion(); // static const auto kBuild = kSystemVersion.microVersion(); // if (kMinor > 0 || (kMinor == 0 && kBuild >= 17763)) { + // const auto LibUxTheme = LoadLibrary(L"uxtheme.dll"); // if (kBuild < 18362) { // LOAD_SYMBOL(LibUxTheme, AllowDarkModeForApp, 135); // } else { @@ -62,9 +61,6 @@ SafeIniter::SafeIniter() { LOAD_SYMBOL(LibPropSys, PropVariantToString); LOAD_SYMBOL(LibPropSys, PSStringFromPropertyKey); - const auto LibDwmApi = LoadLibrary(L"dwmapi.dll"); - LOAD_SYMBOL(LibDwmApi, DwmSetWindowAttribute); - const auto LibPsApi = LoadLibrary(L"psapi.dll"); LOAD_SYMBOL(LibPsApi, GetProcessMemoryInfo); diff --git a/Telegram/SourceFiles/platform/win/windows_dlls.h b/Telegram/SourceFiles/platform/win/windows_dlls.h index 18719727e9..f23e7ff04b 100644 --- a/Telegram/SourceFiles/platform/win/windows_dlls.h +++ b/Telegram/SourceFiles/platform/win/windows_dlls.h @@ -24,12 +24,6 @@ namespace Dlls { void CheckLoadedModules(); -// UXTHEME.DLL -inline HRESULT(__stdcall *SetWindowTheme)( - HWND hWnd, - LPCWSTR pszSubAppName, - LPCWSTR pszSubIdList); - //inline void(__stdcall *RefreshImmersiveColorPolicyState)(); // //inline BOOL(__stdcall *AllowDarkModeForApp)(BOOL allow); @@ -94,14 +88,6 @@ inline HRESULT(__stdcall *PSStringFromPropertyKey)( _Out_writes_(cch) LPWSTR psz, _In_ UINT cch); -// DWMAPI.DLL - -inline HRESULT(__stdcall *DwmSetWindowAttribute)( - HWND hwnd, - DWORD dwAttribute, - _In_reads_bytes_(cbAttribute) LPCVOID pvAttribute, - DWORD cbAttribute); - // PSAPI.DLL inline BOOL(__stdcall *GetProcessMemoryInfo)( diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 40fc5b35f0..a827d9436e 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 40fc5b35f005d14b7216d956051a55429d984065 +Subproject commit a827d9436e9ca258dfdfb9b67ef1ad917c13c5b5 diff --git a/cmake b/cmake index f3a611c82b..c4c2bf4bad 160000 --- a/cmake +++ b/cmake @@ -1 +1 @@ -Subproject commit f3a611c82bfee860f950d5ca6563d8d68262b38d +Subproject commit c4c2bf4bada5207570a78fa3541907a1e9e7bda5