mirror of
https://github.com/valinet/ExplorerPatcher.git
synced 2024-11-27 17:00:59 +01:00
Weather: Widget properly respects text size accessibility setting
This commit is contained in:
parent
26ec0df728
commit
dfc2057ec0
@ -3945,11 +3945,24 @@ SIZE WINAPI PeopleButton_CalculateMinimumSizeHook(void* _this, SIZE* pSz)
|
||||
mi.cbSize = sizeof(MONITORINFO);
|
||||
if (GetMonitorInfoW(hMonitor, &mi))
|
||||
{
|
||||
DWORD dwTextScaleFactor = 0, dwSize = sizeof(DWORD);
|
||||
if (SHRegGetValueFromHKCUHKLMFunc && SHRegGetValueFromHKCUHKLMFunc(
|
||||
TEXT("SOFTWARE\\Microsoft\\Accessibility"),
|
||||
TEXT("TextScaleFactor"),
|
||||
SRRF_RT_REG_DWORD,
|
||||
NULL,
|
||||
&dwTextScaleFactor,
|
||||
(LPDWORD)(&dwSize)
|
||||
) != ERROR_SUCCESS)
|
||||
{
|
||||
dwTextScaleFactor = 100;
|
||||
}
|
||||
|
||||
RECT rcWeatherFlyoutWindow;
|
||||
rcWeatherFlyoutWindow.left = mi.rcWork.left;
|
||||
rcWeatherFlyoutWindow.top = mi.rcWork.top;
|
||||
rcWeatherFlyoutWindow.right = rcWeatherFlyoutWindow.left + MulDiv(EP_WEATHER_WIDTH, dpiX, 96);
|
||||
rcWeatherFlyoutWindow.bottom = rcWeatherFlyoutWindow.top + MulDiv(EP_WEATHER_HEIGHT, dpiX, 96);
|
||||
rcWeatherFlyoutWindow.right = rcWeatherFlyoutWindow.left + MulDiv(MulDiv(EP_WEATHER_WIDTH, dpiX, 96), dwTextScaleFactor, 100);
|
||||
rcWeatherFlyoutWindow.bottom = rcWeatherFlyoutWindow.top + MulDiv(MulDiv(EP_WEATHER_HEIGHT, dpiX, 96), dwTextScaleFactor, 100);
|
||||
if (FAILED(epw->lpVtbl->Initialize(epw, wszEPWeatherKillswitch, bAllocConsole, EP_WEATHER_PROVIDER_GOOGLE, rt, rt, dwWeatherTemperatureUnit, dwWeatherUpdateSchedule * 1000, rcWeatherFlyoutWindow, dwWeatherTheme, dwWeatherGeolocationMode, &hWndWeatherFlyout)))
|
||||
{
|
||||
epw->lpVtbl->Release(epw);
|
||||
|
@ -4,6 +4,39 @@
|
||||
#include "ep_weather_error_html.h"
|
||||
|
||||
EPWeather* EPWeather_Instance;
|
||||
FARPROC SHRegGetValueFromHKCUHKLMFunc;
|
||||
|
||||
static void epw_Weather_SetTextScaleFactorFromRegistry(EPWeather* _this, HKEY hKey, BOOL bRefresh)
|
||||
{
|
||||
DWORD dwTextScaleFactor = 100, dwSize = sizeof(DWORD);
|
||||
if (SHRegGetValueFromHKCUHKLMFunc && SHRegGetValueFromHKCUHKLMFunc(L"SOFTWARE\\Microsoft\\Accessibility", L"TextScaleFactor", SRRF_RT_REG_DWORD, NULL, &dwTextScaleFactor, (LPDWORD)(&dwSize)) != ERROR_SUCCESS)
|
||||
{
|
||||
dwTextScaleFactor = 100;
|
||||
}
|
||||
if (InterlockedExchange64(&_this->dwTextScaleFactor, dwTextScaleFactor) == dwTextScaleFactor)
|
||||
{
|
||||
bRefresh = FALSE;
|
||||
}
|
||||
if (hKey == HKEY_CURRENT_USER)
|
||||
{
|
||||
if (RegCreateKeyExW(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Accessibility", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WOW64_64KEY | KEY_WRITE, NULL, &_this->hKCUAccessibility, NULL) == ERROR_SUCCESS)
|
||||
{
|
||||
RegNotifyChangeKeyValue(_this->hKCUAccessibility, FALSE, REG_NOTIFY_CHANGE_LAST_SET, _this->hSignalOnAccessibilitySettingsChangedFromHKCU, TRUE);
|
||||
}
|
||||
}
|
||||
else if (hKey == HKEY_LOCAL_MACHINE)
|
||||
{
|
||||
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Accessibility", 0, KEY_READ | KEY_WOW64_64KEY | KEY_WRITE, NULL, &_this->hKLMAccessibility))
|
||||
{
|
||||
RegNotifyChangeKeyValue(_this->hKLMAccessibility, FALSE, REG_NOTIFY_CHANGE_LAST_SET, _this->hSignalOnAccessibilitySettingsChangedFromHKLM, TRUE);
|
||||
}
|
||||
}
|
||||
if (bRefresh)
|
||||
{
|
||||
_this->cntResizeWindow = 0;
|
||||
SetTimer(_this->hWnd, EP_WEATHER_TIMER_RESIZE_WINDOW, EP_WEATHER_TIMER_RESIZE_WINDOW_DELAY, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE INetworkListManagerEvents_QueryInterface(void* _this, REFIID riid, void** ppv)
|
||||
{
|
||||
@ -108,7 +141,7 @@ HRESULT STDMETHODCALLTYPE _epw_Weather_NavigateToError(EPWeather* _this)
|
||||
_ep_weather_ReboundBrowser(_this, TRUE);
|
||||
InterlockedExchange64(&_this->bIsNavigatingToError, TRUE);
|
||||
UINT dpi = GetDpiForWindow(_this->hWnd);
|
||||
int ch = MulDiv(305, dpi, 96);
|
||||
int ch = MulDiv(MulDiv(305, dpi, 96), epw_Weather_GetTextScaleFactor(_this), 100);
|
||||
RECT rc;
|
||||
GetWindowRect(_this->hWnd, &rc);
|
||||
if (rc.bottom - rc.top != ch)
|
||||
@ -215,10 +248,11 @@ HRESULT STDMETHODCALLTYPE _ep_weather_ReboundBrowser(EPWeather* _this, LONG64 dw
|
||||
}
|
||||
else
|
||||
{
|
||||
bounds.left = 0 - MulDiv(167, dpi, 96);
|
||||
bounds.top = 0 - MulDiv(178, dpi, 96);
|
||||
bounds.right = MulDiv(1333, dpi, 96);// 5560;
|
||||
bounds.bottom = MulDiv(600, dpi, 96);// 15600;
|
||||
DWORD dwTextScaleFactor = epw_Weather_GetTextScaleFactor(_this);
|
||||
bounds.left = 0 - MulDiv(MulDiv(167, dpi, 96), dwTextScaleFactor, 100);
|
||||
bounds.top = 0 - MulDiv(MulDiv(178, dpi, 96), dwTextScaleFactor, 100);
|
||||
bounds.right = MulDiv(MulDiv(1333, dpi, 96), dwTextScaleFactor, 100);// 5560;
|
||||
bounds.bottom = MulDiv(MulDiv(600, dpi, 96), dwTextScaleFactor, 100);// 15600;
|
||||
}
|
||||
if (_this->pCoreWebView2Controller)
|
||||
{
|
||||
@ -451,7 +485,7 @@ HRESULT STDMETHODCALLTYPE ICoreWebView2_ExecuteScriptCompleted(ICoreWebView2Exec
|
||||
int h = _wtoi(wszHeight);
|
||||
int ch = MulDiv(h, EP_WEATHER_HEIGHT, 367);
|
||||
UINT dpi = GetDpiForWindow(_this->hWnd);
|
||||
ch = MulDiv(ch, dpi, 96);
|
||||
ch = MulDiv(MulDiv(ch, dpi, 96), epw_Weather_GetTextScaleFactor(_this), 100);
|
||||
RECT rc;
|
||||
GetWindowRect(_this->hWnd, &rc);
|
||||
if (rc.bottom - rc.top != ch)
|
||||
@ -515,10 +549,17 @@ ULONG STDMETHODCALLTYPE epw_Weather_Release(EPWeather* _this)
|
||||
if (value == 0)
|
||||
{
|
||||
if (_this->hMainThread)
|
||||
{
|
||||
if (_this->hSignalExitMainThread)
|
||||
{
|
||||
SetEvent(_this->hSignalExitMainThread);
|
||||
WaitForSingleObject(_this->hMainThread, INFINITE);
|
||||
}
|
||||
CloseHandle(_this->hMainThread);
|
||||
if (_this->hSignalExitMainThread)
|
||||
{
|
||||
CloseHandle(_this->hSignalExitMainThread);
|
||||
}
|
||||
}
|
||||
if (_this->hInitializeEvent)
|
||||
{
|
||||
@ -534,6 +575,31 @@ ULONG STDMETHODCALLTYPE epw_Weather_Release(EPWeather* _this)
|
||||
{
|
||||
FreeLibrary(_this->hUxtheme);
|
||||
}
|
||||
if (_this->hShlwapi)
|
||||
{
|
||||
FreeLibrary(_this->hShlwapi);
|
||||
}
|
||||
if (_this->hKCUAccessibility)
|
||||
{
|
||||
RegCloseKey(_this->hKCUAccessibility);
|
||||
}
|
||||
if (_this->hKLMAccessibility)
|
||||
{
|
||||
RegCloseKey(_this->hKLMAccessibility);
|
||||
}
|
||||
if (_this->hSignalOnAccessibilitySettingsChangedFromHKCU)
|
||||
{
|
||||
CloseHandle(_this->hSignalOnAccessibilitySettingsChangedFromHKCU);
|
||||
}
|
||||
if (_this->hSignalOnAccessibilitySettingsChangedFromHKLM)
|
||||
{
|
||||
CloseHandle(_this->hSignalOnAccessibilitySettingsChangedFromHKLM);
|
||||
}
|
||||
if (_this->hSignalKillSwitch)
|
||||
{
|
||||
CloseHandle(_this->hSignalKillSwitch);
|
||||
}
|
||||
|
||||
FREE(_this);
|
||||
LONG dwOutstandingObjects = InterlockedDecrement(&epw_OutstandingObjects);
|
||||
LONG dwOutstandingLocks = InterlockedAdd(&epw_LockCount, 0);
|
||||
@ -642,6 +708,22 @@ LRESULT CALLBACK epw_Weather_WindowProc(_In_ HWND hWnd, _In_ UINT uMsg, _In_ WPA
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else if (uMsg == WM_TIMER && wParam == EP_WEATHER_TIMER_RESIZE_WINDOW)
|
||||
{
|
||||
DWORD dwTextScaleFactor = epw_Weather_GetTextScaleFactor(_this);
|
||||
UINT dpi = GetDpiForWindow(_this->hWnd);
|
||||
SetWindowPos(_this->hWnd, NULL, 0, 0, MulDiv(MulDiv(EP_WEATHER_WIDTH, dpi, 96), dwTextScaleFactor, 100), MulDiv(MulDiv(EP_WEATHER_HEIGHT, dpi, 96), dwTextScaleFactor, 100), SWP_NOMOVE | SWP_NOSENDCHANGING);
|
||||
if (_this->cntResizeWindow == 7)
|
||||
{
|
||||
_this->cntResizeWindow = 0;
|
||||
KillTimer(_this->hWnd, EP_WEATHER_TIMER_RESIZE_WINDOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
_this->cntResizeWindow++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else if (uMsg == EP_WEATHER_WM_REBOUND_BROWSER)
|
||||
{
|
||||
LPWSTR uri = NULL;
|
||||
@ -718,7 +800,7 @@ LRESULT CALLBACK epw_Weather_WindowProc(_In_ HWND hWnd, _In_ UINT uMsg, _In_ WPA
|
||||
else if (uMsg == WM_DPICHANGED)
|
||||
{
|
||||
UINT dpiX = LOWORD(wParam);
|
||||
int w = MulDiv(EP_WEATHER_WIDTH, dpiX, 96);
|
||||
int w = MulDiv(MulDiv(EP_WEATHER_WIDTH, dpiX, 96), epw_Weather_GetTextScaleFactor(_this), 100);
|
||||
RECT* rc = lParam;
|
||||
SetWindowPos(_this->hWnd, NULL, rc->left, rc->top, w, rc->bottom - rc->top, 0);
|
||||
return 0;
|
||||
@ -984,6 +1066,14 @@ DWORD WINAPI epw_Weather_MainThread(EPWeather* _this)
|
||||
CloseHandle(_this->hSignalKillSwitch);
|
||||
TerminateProcess(GetCurrentProcess(), 0);
|
||||
}
|
||||
else if (dwRes == WAIT_OBJECT_0 + 2)
|
||||
{
|
||||
epw_Weather_SetTextScaleFactorFromRegistry(_this, HKEY_CURRENT_USER, TRUE);
|
||||
}
|
||||
else if (dwRes == WAIT_OBJECT_0 + 3)
|
||||
{
|
||||
epw_Weather_SetTextScaleFactorFromRegistry(_this, HKEY_LOCAL_MACHINE, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
@ -1125,6 +1215,12 @@ HRESULT STDMETHODCALLTYPE epw_Weather_Initialize(EPWeather* _this, WCHAR wszName
|
||||
}
|
||||
}
|
||||
|
||||
_this->hShlwapi = LoadLibraryW(L"Shlwapi.dll");
|
||||
if (_this->hShlwapi)
|
||||
{
|
||||
SHRegGetValueFromHKCUHKLMFunc = GetProcAddress(_this->hShlwapi, "SHRegGetValueFromHKCUHKLM");
|
||||
}
|
||||
|
||||
_this->hMutexData = CreateMutexW(NULL, FALSE, NULL);
|
||||
if (!_this->hMutexData)
|
||||
{
|
||||
@ -1143,6 +1239,19 @@ HRESULT STDMETHODCALLTYPE epw_Weather_Initialize(EPWeather* _this, WCHAR wszName
|
||||
return HRESULT_FROM_WIN32(GetLastError());
|
||||
}
|
||||
|
||||
_this->hSignalOnAccessibilitySettingsChangedFromHKCU = CreateEventW(NULL, FALSE, FALSE, NULL);
|
||||
if (!_this->hSignalOnAccessibilitySettingsChangedFromHKCU)
|
||||
{
|
||||
return HRESULT_FROM_WIN32(GetLastError());
|
||||
}
|
||||
_this->hSignalOnAccessibilitySettingsChangedFromHKLM = CreateEventW(NULL, FALSE, FALSE, NULL);
|
||||
if (!_this->hSignalOnAccessibilitySettingsChangedFromHKLM)
|
||||
{
|
||||
return HRESULT_FROM_WIN32(GetLastError());
|
||||
}
|
||||
epw_Weather_SetTextScaleFactorFromRegistry(_this, HKEY_CURRENT_USER, FALSE);
|
||||
epw_Weather_SetTextScaleFactorFromRegistry(_this, HKEY_LOCAL_MACHINE, FALSE);
|
||||
|
||||
_this->rc = rc;
|
||||
|
||||
_this->hMainThread = CreateThread(NULL, 0, epw_Weather_MainThread, _this, 0, NULL);
|
||||
|
@ -18,13 +18,15 @@
|
||||
DEFINE_GUID(IID_ITaskbarList,
|
||||
0x56FDF342, 0xFD6D, 0x11d0, 0x95, 0x8A, 0x00, 0x60, 0x97, 0xC9, 0xA0, 0x90);
|
||||
|
||||
#define EP_WEATHER_NUM_SIGNALS 2
|
||||
#define EP_WEATHER_NUM_SIGNALS 4
|
||||
|
||||
#define EP_WEATHER_TIMER_REQUEST_REPAINT 1
|
||||
#define EP_WEATHER_TIMER_REQUEST_REPAINT_DELAY 1000
|
||||
#define EP_WEATHER_TIMER_REQUEST_REFRESH 10
|
||||
#define EP_WEATHER_TIMER_REQUEST_REFRESH_DELAY 2000
|
||||
#define EP_WEATHER_TIMER_SCHEDULE_REFRESH 11
|
||||
#define EP_WEATHER_TIMER_RESIZE_WINDOW 15
|
||||
#define EP_WEATHER_TIMER_RESIZE_WINDOW_DELAY 150
|
||||
|
||||
typedef interface EPWeather
|
||||
{
|
||||
@ -60,7 +62,12 @@ typedef interface EPWeather
|
||||
char* pImage;
|
||||
DWORD cbLocation;
|
||||
LPCWSTR wszLocation;
|
||||
LONG64 dwTextScaleFactor; // interlocked
|
||||
HMODULE hUxtheme;
|
||||
HMODULE hShlwapi;
|
||||
HKEY hKCUAccessibility;
|
||||
HKEY hKLMAccessibility;
|
||||
DWORD cntResizeWindow;
|
||||
|
||||
RECT rcBorderThickness; // local variables:
|
||||
ITaskbarList* pTaskList;
|
||||
@ -72,6 +79,8 @@ typedef interface EPWeather
|
||||
|
||||
HANDLE hSignalExitMainThread;
|
||||
HANDLE hSignalKillSwitch;
|
||||
HANDLE hSignalOnAccessibilitySettingsChangedFromHKCU;
|
||||
HANDLE hSignalOnAccessibilitySettingsChangedFromHKLM;
|
||||
} EPWeather;
|
||||
|
||||
ULONG STDMETHODCALLTYPE epw_Weather_AddRef(EPWeather* _this);
|
||||
@ -131,6 +140,9 @@ static const IEPWeatherVtbl IEPWeather_Vtbl = {
|
||||
.SetWindowCornerPreference = epw_Weather_SetWindowCornerPreference,
|
||||
};
|
||||
|
||||
static inline DWORD epw_Weather_GetTextScaleFactor(EPWeather* _this) { return InterlockedAdd64(&_this->dwTextScaleFactor, 0); }
|
||||
static void epw_Weather_SetTextScaleFactorFromRegistry(EPWeather* _this, HKEY hKey, BOOL bRefresh);
|
||||
|
||||
HRESULT STDMETHODCALLTYPE epw_Weather_static_Stub(void* _this);
|
||||
ULONG STDMETHODCALLTYPE epw_Weather_static_AddRefRelease(EPWeather* _this);
|
||||
HRESULT STDMETHODCALLTYPE epw_Weather_static_QueryInterface(EPWeather* _this, REFIID riid, void** ppv);
|
||||
|
Loading…
Reference in New Issue
Block a user