// ==WindhawkMod== // @id winv-right-dock-unblock-background // @name Win+V Right Dock Unblock Background // @description Dock Win+V right, horizontal resize only, and move light dismiss overlay offscreen to unblock background interaction. // @version 1.0 // @author Test // @include explorer.exe // @architecture x86-64 // @compilerOptions -luser32 // ==/WindhawkMod== // ==WindhawkModSettings== /* - initialWidth: 620 $name: Initial width - minWidth: 450 $name: Minimum width - maxWidth: 1000 $name: Maximum width - rightMargin: 12 $name: Right margin - moveOverlayOffscreen: true $name: Move light dismiss overlay offscreen - debugLog: false $name: Debug log */ // ==/WindhawkModSettings== #include #include struct Settings { int initialWidth; int minWidth; int maxWidth; int rightMargin; bool moveOverlayOffscreen; bool debugLog; }; static Settings g; static HANDLE g_thread = nullptr; static HANDLE g_stopEvent = nullptr; static HWND g_winv = nullptr; static WNDPROC g_origProc = nullptr; static int g_fixedTop = 0; static int g_fixedHeight = 0; static int g_currentWidth = 0; static void LoadSettings() { g.initialWidth = Wh_GetIntSetting(L"initialWidth"); g.minWidth = Wh_GetIntSetting(L"minWidth"); g.maxWidth = Wh_GetIntSetting(L"maxWidth"); g.rightMargin = Wh_GetIntSetting(L"rightMargin"); g.moveOverlayOffscreen = Wh_GetIntSetting(L"moveOverlayOffscreen") != 0; g.debugLog = Wh_GetIntSetting(L"debugLog") != 0; if (g.minWidth < 350) g.minWidth = 350; if (g.maxWidth < g.minWidth) g.maxWidth = g.minWidth + 100; if (g.initialWidth < g.minWidth) g.initialWidth = g.minWidth; if (g.initialWidth > g.maxWidth) g.initialWidth = g.maxWidth; if (g.rightMargin < 0) g.rightMargin = 0; } static bool IsClass(HWND hwnd, const wchar_t* wanted) { wchar_t cls[256] = {}; GetClassNameW(hwnd, cls, ARRAYSIZE(cls)); return wcscmp(cls, wanted) == 0; } static bool IsOwnProcessWindow(HWND hwnd) { DWORD pid = 0; GetWindowThreadProcessId(hwnd, &pid); return pid == GetCurrentProcessId(); } static bool IsWinVWindow(HWND hwnd) { if (!IsWindow(hwnd) || !IsWindowVisible(hwnd)) return false; if (!IsOwnProcessWindow(hwnd)) return false; if (!IsClass(hwnd, L"ApplicationFrameWindow")) return false; RECT rc = {}; if (!GetWindowRect(hwnd, &rc)) return false; int w = rc.right - rc.left; int h = rc.bottom - rc.top; return w >= 300 && w <= 1400 && h >= 250 && h <= 900; } static bool IsLightDismissOverlay(HWND hwnd) { if (!IsWindow(hwnd)) return false; if (!IsOwnProcessWindow(hwnd)) return false; return IsClass(hwnd, L"Shell_LightDismissOverlay"); } static void MoveOverlayOffscreen(HWND hwnd) { if (!g.moveOverlayOffscreen) return; LONG_PTR exStyle = GetWindowLongPtrW(hwnd, GWL_EXSTYLE); exStyle |= WS_EX_NOACTIVATE | WS_EX_TRANSPARENT; exStyle &= ~WS_EX_TOPMOST; SetWindowLongPtrW(hwnd, GWL_EXSTYLE, exStyle); SetWindowPos( hwnd, HWND_BOTTOM, -32000, -32000, 1, 1, SWP_NOACTIVATE | SWP_FRAMECHANGED | SWP_SHOWWINDOW ); if (g.debugLog) { Wh_Log(L"[WinVUnblock] overlay moved offscreen hwnd=%p", hwnd); } } static void ForceTopMost(HWND hwnd) { LONG_PTR exStyle = GetWindowLongPtrW(hwnd, GWL_EXSTYLE); exStyle |= WS_EX_TOPMOST; SetWindowLongPtrW(hwnd, GWL_EXSTYLE, exStyle); SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_SHOWWINDOW ); } static void DockRight(HWND hwnd, int width) { HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); MONITORINFO mi = {}; mi.cbSize = sizeof(mi); if (!GetMonitorInfoW(monitor, &mi)) return; RECT work = mi.rcWork; if (width < g.minWidth) width = g.minWidth; if (width > g.maxWidth) width = g.maxWidth; int x = work.right - width - g.rightMargin; SetWindowPos( hwnd, HWND_TOPMOST, x, g_fixedTop, width, g_fixedHeight, SWP_NOACTIVATE | SWP_SHOWWINDOW ); g_currentWidth = width; } static LRESULT CALLBACK WinVProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_SIZING: { RECT* rc = (RECT*)lParam; int width = rc->right - rc->left; if (width < g.minWidth) width = g.minWidth; if (width > g.maxWidth) width = g.maxWidth; HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); MONITORINFO mi = {}; mi.cbSize = sizeof(mi); if (GetMonitorInfoW(monitor, &mi)) { RECT work = mi.rcWork; rc->right = work.right - g.rightMargin; rc->left = rc->right - width; rc->top = g_fixedTop; rc->bottom = g_fixedTop + g_fixedHeight; } g_currentWidth = width; ForceTopMost(hwnd); return TRUE; } case WM_WINDOWPOSCHANGING: { WINDOWPOS* wp = (WINDOWPOS*)lParam; wp->hwndInsertAfter = HWND_TOPMOST; wp->flags &= ~SWP_NOZORDER; if (!(wp->flags & SWP_NOSIZE)) { if (wp->cx < g.minWidth) wp->cx = g.minWidth; if (wp->cx > g.maxWidth) wp->cx = g.maxWidth; wp->cy = g_fixedHeight; g_currentWidth = wp->cx; } if (!(wp->flags & SWP_NOMOVE)) { HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); MONITORINFO mi = {}; mi.cbSize = sizeof(mi); if (GetMonitorInfoW(monitor, &mi)) { RECT work = mi.rcWork; wp->x = work.right - wp->cx - g.rightMargin; wp->y = g_fixedTop; } } break; } case WM_GETMINMAXINFO: { MINMAXINFO* mmi = (MINMAXINFO*)lParam; mmi->ptMinTrackSize.x = g.minWidth; mmi->ptMaxTrackSize.x = g.maxWidth; mmi->ptMinTrackSize.y = g_fixedHeight; mmi->ptMaxTrackSize.y = g_fixedHeight; return 0; } case WM_WINDOWPOSCHANGED: case WM_ACTIVATE: case WM_SETFOCUS: ForceTopMost(hwnd); break; } return CallWindowProcW(g_origProc, hwnd, msg, wParam, lParam); } static void ApplyWinV(HWND hwnd) { if (g_winv == hwnd) return; RECT rc = {}; if (!GetWindowRect(hwnd, &rc)) return; g_fixedTop = rc.top; g_fixedHeight = rc.bottom - rc.top; if (g_currentWidth <= 0) g_currentWidth = g.initialWidth; LONG_PTR style = GetWindowLongPtrW(hwnd, GWL_STYLE); LONG_PTR exStyle = GetWindowLongPtrW(hwnd, GWL_EXSTYLE); style |= WS_THICKFRAME | WS_SIZEBOX; style &= ~WS_MAXIMIZEBOX; exStyle &= ~WS_EX_TOOLWINDOW; exStyle |= WS_EX_TOPMOST; SetWindowLongPtrW(hwnd, GWL_STYLE, style); SetWindowLongPtrW(hwnd, GWL_EXSTYLE, exStyle); if (g_winv && g_origProc && IsWindow(g_winv)) { SetWindowLongPtrW(g_winv, GWLP_WNDPROC, (LONG_PTR)g_origProc); } g_winv = hwnd; g_origProc = (WNDPROC)SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)WinVProc ); DockRight(hwnd, g_currentWidth); ForceTopMost(hwnd); if (g.debugLog) { Wh_Log( L"[WinVUnblock] docked hwnd=%p width=%d height=%d", hwnd, g_currentWidth, g_fixedHeight ); } } static BOOL CALLBACK EnumProc(HWND hwnd, LPARAM) { if (IsWinVWindow(hwnd)) { ApplyWinV(hwnd); } if (IsLightDismissOverlay(hwnd)) { MoveOverlayOffscreen(hwnd); } return TRUE; } static DWORD WINAPI WorkerThread(LPVOID) { while (WaitForSingleObject(g_stopEvent, 80) == WAIT_TIMEOUT) { EnumWindows(EnumProc, 0); if (g_winv && IsWindow(g_winv) && IsWindowVisible(g_winv)) { ForceTopMost(g_winv); } } return 0; } BOOL Wh_ModInit() { LoadSettings(); g_stopEvent = CreateEventW(nullptr, TRUE, FALSE, nullptr); if (!g_stopEvent) return FALSE; g_thread = CreateThread(nullptr, 0, WorkerThread, nullptr, 0, nullptr); return g_thread != nullptr; } void Wh_ModSettingsChanged() { LoadSettings(); } void Wh_ModUninit() { if (g_winv && g_origProc && IsWindow(g_winv)) { SetWindowLongPtrW(g_winv, GWLP_WNDPROC, (LONG_PTR)g_origProc); } if (g_stopEvent) SetEvent(g_stopEvent); if (g_thread) { WaitForSingleObject(g_thread, 2000); CloseHandle(g_thread); g_thread = nullptr; } if (g_stopEvent) { CloseHandle(g_stopEvent); g_stopEvent = nullptr; } }