[NTUSER] Allow Window Snap to be disabled (#5014)
authorKatayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
Wed, 1 Feb 2023 09:13:32 +0000 (18:13 +0900)
committerGitHub <noreply@github.com>
Wed, 1 Feb 2023 09:13:32 +0000 (18:13 +0900)
- Add IntIsWindowSnapEnabled helper function that reads registry value WindowArrangementActive.
- Check the registry and store the value to newly-added g_bWindowSnapEnabled global variable on startup.
- Check the global variable before Window Snap.

Win+Left, Win+Right, Win+Up, and Win+Down can be disabled by registry value WindowArrangementActive.
Snapping mouse can be also disabled. CORE-16379

win32ss/user/ntuser/defwnd.c
win32ss/user/ntuser/nonclient.c
win32ss/user/ntuser/sysparams.c
win32ss/user/ntuser/window.h

index 0faadbc..05a1db0 100644 (file)
@@ -813,7 +813,7 @@ IntDefWindowProc(
 
             if (topWnd && !IsTaskBar)  /* Second test is so we are not touching the Taskbar */
             {
-               if ((topWnd->style & WS_THICKFRAME) == 0)
+               if ((topWnd->style & WS_THICKFRAME) == 0 || !g_bWindowSnapEnabled)
                {
                   return 0;
                }
index aad6fe7..ab7d001 100644 (file)
@@ -418,7 +418,7 @@ DefWndDoSizeMove(PWND pwnd, WORD wParam)
             UserSystemParametersInfo(SPI_GETWORKAREA, 0, &snapRect, 0);
 
             /* if this is the taskbar, then we want to just exit */
-            if (IsTaskBar)
+            if (IsTaskBar || !g_bWindowSnapEnabled)
             {
                break;
             }
index 7b1f2bf..47349ce 100644 (file)
@@ -17,6 +17,7 @@ DBG_DEFAULT_CHANNEL(UserSysparams);
 SPIVALUES gspv;
 BOOL gbSpiInitialized = FALSE;
 BOOL g_PaintDesktopVersion = FALSE;
+BOOL g_bWindowSnapEnabled = TRUE;
 
 // HACK! We initialize SPI before we have a proper surface to get this from.
 #define dpi 96
@@ -100,8 +101,6 @@ static const WCHAR* KEY_KDBPREF = L"Control Panel\\Accessibility\\Keyboard Prefe
 static const WCHAR* KEY_SCRREAD = L"Control Panel\\Accessibility\\Blind Access";
 static const WCHAR* VAL_ON = L"On";
 
-
-
 /** Loading the settings ******************************************************/
 
 static
@@ -215,6 +214,19 @@ SpiFixupValues(VOID)
 
 }
 
+/* Is Window Snap enabled? */
+static BOOL IntIsWindowSnapEnabled(VOID)
+{
+    WCHAR szValue[2];
+    if (RegReadUserSetting(L"Control Panel\\Desktop", L"WindowArrangementActive",
+                           REG_SZ, szValue, sizeof(szValue)))
+    {
+        szValue[RTL_NUMBER_OF(szValue) - 1] = UNICODE_NULL; /* Avoid buffer overrun */
+        return (_wtoi(szValue) != 0);
+    }
+    return TRUE;
+}
+
 static
 VOID
 SpiUpdatePerUserSystemParameters(VOID)
@@ -344,6 +356,8 @@ SpiUpdatePerUserSystemParameters(VOID)
        if (SPITESTPREF(UPM_LISTBOXSMOOTHSCROLLING)) gpsi->PUSIFlags |= PUSIF_LISTBOXSMOOTHSCROLLING;
     }
     gdwLanguageToggleKey = UserGetLanguageToggle();
+
+    g_bWindowSnapEnabled = IntIsWindowSnapEnabled();
 }
 
 BOOL
index 0a463b7..fa0387f 100644 (file)
@@ -4,6 +4,7 @@ extern ATOM AtomMessage;
 extern ATOM AtomWndObj; /* WNDOBJ list */
 extern ATOM AtomLayer;
 extern ATOM AtomFlashWndState;
+extern BOOL g_bWindowSnapEnabled;
 
 #define HAS_DLGFRAME(Style, ExStyle) \
             (((ExStyle) & WS_EX_DLGMODALFRAME) || \