From 7bc56f41919af7f2d17211674413eb21a9fa6701 Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Tue, 8 Feb 2022 19:58:02 +0200 Subject: [PATCH] Weather: Widget displays with rounded corner after logon; implemented option to change corner preference --- ExplorerPatcher/dllmain.c | 20 ++++++++++++++++++++ ExplorerPatcher/settings.reg | 5 +++++ ep_weather_host/ep_weather.h | 15 +++++++++++++++ ep_weather_host/ep_weather_host.c | 13 +++++++++++++ ep_weather_host/ep_weather_host.h | 3 +++ ep_weather_host_stub/ep_weather_host.idl | 2 ++ 6 files changed, 58 insertions(+) diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index b97bb3c..28e9604 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -111,6 +111,7 @@ DWORD dwWeatherUpdateSchedule = EP_WEATHER_UPDATE_NORMAL; DWORD bWeatherFixedSize = FALSE; DWORD dwWeatherTheme = 0; DWORD dwWeatherGeolocationMode = 0; +DWORD dwWeatherWindowCornerPreference = DWMWCP_ROUND; WCHAR* wszWeatherTerm = NULL; WCHAR* wszWeatherLanguage = NULL; WCHAR* wszEPWeatherKillswitch = NULL; @@ -3955,6 +3956,7 @@ SIZE WINAPI PeopleButton_CalculateMinimumSizeHook(void* _this, SIZE* pSz) epw = NULL; prev_total_h = 0; } + epw->lpVtbl->SetWindowCornerPreference(epw, dwWeatherWindowCornerPreference); } ReleaseSRWLockExclusive(&lock_epw); AcquireSRWLockShared(&lock_epw); @@ -5867,6 +5869,24 @@ void WINAPI LoadSettings(LPARAM lParam) } } + DWORD dwOldWeatherWindowCornerPreference = dwWeatherWindowCornerPreference; + dwSize = sizeof(DWORD); + RegQueryValueExW( + hKey, + TEXT("WeatherWindowCornerPreference"), + 0, + NULL, + &dwWeatherWindowCornerPreference, + &dwSize + ); + if (dwWeatherWindowCornerPreference != dwOldWeatherWindowCornerPreference && PeopleButton_LastHWND) + { + if (epw) + { + epw->lpVtbl->SetWindowCornerPreference(epw, (LONG64)dwWeatherWindowCornerPreference); + } + } + ReleaseSRWLockShared(&lock_epw); #endif diff --git a/ExplorerPatcher/settings.reg b/ExplorerPatcher/settings.reg index 3d4ef92..08d5964 100644 --- a/ExplorerPatcher/settings.reg +++ b/ExplorerPatcher/settings.reg @@ -404,6 +404,11 @@ ;x 1 Light ;x 2 Dark "WeatherTheme"=dword:00000000 +;c 3 Corner preference +;x 2 Rounded (default) +;x 3 Small rounded +;x 1 Not rounded +"WeatherWindowCornerPreference"=dword:00000002 ;q ;t Weather data courtesy of Google, and weather.com. ;y Learn more about the Weather taskbar widget 🡕 diff --git a/ep_weather_host/ep_weather.h b/ep_weather_host/ep_weather.h index e4cce51..a647c6d 100644 --- a/ep_weather_host/ep_weather.h +++ b/ep_weather_host/ep_weather.h @@ -8,6 +8,21 @@ #pragma comment(lib, "Version.lib") #pragma comment(lib, "Shlwapi.lib") +#ifndef NTDDI_WIN10_CO +#define DWMWA_USE_HOSTBACKDROPBRUSH 17 // [set] BOOL, Allows the use of host backdrop brushes for the window. +#define DWMWA_USE_IMMERSIVE_DARK_MODE 20 // [set] BOOL, Allows a window to either use the accent color, or dark, according to the user Color Mode preferences. +#define DWMWA_WINDOW_CORNER_PREFERENCE 33 // [set] WINDOW_CORNER_PREFERENCE, Controls the policy that rounds top-level window corners +#define DWMWA_BORDER_COLOR 34 // [set] COLORREF, The color of the thin border around a top-level window +#define DWMWA_CAPTION_COLOR 35 // [set] COLORREF, The color of the caption +#define DWMWA_TEXT_COLOR 36 // [set] COLORREF, The color of the caption text +#define DWMWA_VISIBLE_FRAME_BORDER_THICKNESS 37 // [get] UINT, width of the visible border around a thick frame window +#define DWMWCP_DEFAULT 0 +#define DWMWCP_DONOTROUND 1 +#define DWMWCP_ROUND 2 +#define DWMWCP_ROUNDSMALL 3 +#endif +#define DWMWA_MICA_EFFFECT 1029 + #define ALLOC(x) calloc(1, x) #define FREE(x) free(x) diff --git a/ep_weather_host/ep_weather_host.c b/ep_weather_host/ep_weather_host.c index 2176954..fd17130 100644 --- a/ep_weather_host/ep_weather_host.c +++ b/ep_weather_host/ep_weather_host.c @@ -829,6 +829,17 @@ HRESULT STDMETHODCALLTYPE epw_Weather_SetGeolocationMode(EPWeather* _this, LONG6 return S_OK; } +HRESULT STDMETHODCALLTYPE epw_Weather_SetWindowCornerPreference(EPWeather* _this, LONG64 dwWindowCornerPreference) +{ + InterlockedExchange64(&_this->dwWindowCornerPreference, dwWindowCornerPreference); + INT preference = dwWindowCornerPreference; + if (_this->hWnd) + { + DwmSetWindowAttribute(_this->hWnd, DWMWA_WINDOW_CORNER_PREFERENCE, &preference, sizeof(preference)); + } + return S_OK; +} + DWORD WINAPI epw_Weather_MainThread(EPWeather* _this) { HRESULT hr = S_OK; @@ -1149,6 +1160,8 @@ HRESULT STDMETHODCALLTYPE epw_Weather_Initialize(EPWeather* _this, WCHAR wszName HRESULT STDMETHODCALLTYPE epw_Weather_Show(EPWeather* _this) { + INT preference = InterlockedAdd64(&_this->dwWindowCornerPreference, 0); + DwmSetWindowAttribute(_this->hWnd, DWMWA_WINDOW_CORNER_PREFERENCE, &preference, sizeof(preference)); PostMessageW(_this->hWnd, EP_WEATHER_WM_REBOUND_BROWSER, 0, 0); ShowWindow(_this->hWnd, SW_SHOW); _this->pTaskList->lpVtbl->DeleteTab(_this->pTaskList, _this->hWnd); diff --git a/ep_weather_host/ep_weather_host.h b/ep_weather_host/ep_weather_host.h index bbc24ef..3976647 100644 --- a/ep_weather_host/ep_weather_host.h +++ b/ep_weather_host/ep_weather_host.h @@ -47,6 +47,7 @@ typedef interface EPWeather LONG64 bIsNavigatingToError; // interlocked LONG64 g_darkModeEnabled; // interlocked LONG64 dwGeolocationMode; + LONG64 dwWindowCornerPreference; HANDLE hMutexData; // protects the following: DWORD cbTemperature; @@ -100,6 +101,7 @@ HRESULT STDMETHODCALLTYPE epw_Weather_GetIconSize(EPWeather* _this, LONG64* cbx, HRESULT STDMETHODCALLTYPE epw_Weather_SetDarkMode(EPWeather* _this, LONG64 dwDarkMode, LONG64 bRefresh); HRESULT STDMETHODCALLTYPE epw_Weather_IsDarkMode(EPWeather* _this, LONG64 dwDarkMode, LONG64* bEnabled); HRESULT STDMETHODCALLTYPE epw_Weather_SetGeolocationMode(EPWeather* _this, LONG64 dwGeolocationMode); +HRESULT STDMETHODCALLTYPE epw_Weather_SetWindowCornerPreference(EPWeather* _this, LONG64 dwWindowCornerPreference); static const IEPWeatherVtbl IEPWeather_Vtbl = { .QueryInterface = epw_Weather_QueryInterface, @@ -125,6 +127,7 @@ static const IEPWeatherVtbl IEPWeather_Vtbl = { .SetUpdateSchedule = epw_Weather_SetUpdateSchedule, .SetDarkMode = epw_Weather_SetDarkMode, .SetGeolocationMode = epw_Weather_SetGeolocationMode, + .SetWindowCornerPreference = epw_Weather_SetWindowCornerPreference, }; HRESULT STDMETHODCALLTYPE epw_Weather_static_Stub(void* _this); diff --git a/ep_weather_host_stub/ep_weather_host.idl b/ep_weather_host_stub/ep_weather_host.idl index 0e726c7..e8765ee 100644 --- a/ep_weather_host_stub/ep_weather_host.idl +++ b/ep_weather_host_stub/ep_weather_host.idl @@ -62,4 +62,6 @@ import "unknwn.idl"; HRESULT SetDarkMode([in] LONG64 dwDarkMode, [in] LONG64 bRefresh); HRESULT SetGeolocationMode([in] LONG64 dwGeolocationMode); + + HRESULT SetWindowCornerPreference([in] LONG64 dwWindowCornerPreference); }; \ No newline at end of file