diff --git a/VERSION b/VERSION index 3eefcb9..6d7de6e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.0 +1.0.2 diff --git a/bootstrap/payload/NativeMethods.cs b/bootstrap/payload/NativeMethods.cs index a5f2aac..df9b1aa 100644 --- a/bootstrap/payload/NativeMethods.cs +++ b/bootstrap/payload/NativeMethods.cs @@ -95,6 +95,7 @@ internal static class NativeMethods [DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern IntPtr FindWindowEx(IntPtr parent, IntPtr childAfter, string className, string windowName); [DllImport("user32.dll")] public static extern bool IsWindow(IntPtr hWnd); [DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr hWnd); + [DllImport("user32.dll")] public static extern bool IsZoomed(IntPtr hWnd); [DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); [DllImport("user32.dll", SetLastError = true)] public static extern bool SetWindowPos(IntPtr hWnd, IntPtr insertAfter, int x, int y, int cx, int cy, uint flags); [DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr hWnd, out RECT rect); diff --git a/bootstrap/payload/SlipperyContext.Diagnostics.cs b/bootstrap/payload/SlipperyContext.Diagnostics.cs index 1081993..24724ed 100644 --- a/bootstrap/payload/SlipperyContext.Diagnostics.cs +++ b/bootstrap/payload/SlipperyContext.Diagnostics.cs @@ -20,7 +20,7 @@ private void CopyDiagnostics() { StringBuilder b = new StringBuilder(); b.AppendLine("Slippery Taskbar C# diagnostics"); - b.AppendLine("Build: 1.0.0"); + b.AppendLine("Build: 1.0.2-test"); b.AppendLine("Runtime: " + Environment.Version); b.AppendLine("OS: " + Environment.OSVersion); b.AppendLine("Executable: " + Application.ExecutablePath); @@ -39,9 +39,10 @@ private void CopyDiagnostics() IList taskbars = _taskbars.RefreshTaskbars(); b.AppendLine("Taskbars found: " + taskbars.Count); IntPtr foreground = NativeMethods.GetForegroundWindow(); - b.AppendLine("Foreground: " + _taskbars.DescribeWindow(foreground)); + b.AppendLine("Foreground: " + DescribeWindowGeometry(foreground)); for (int i = 0; i < taskbars.Count; i++) - b.AppendLine("Taskbar " + i + ": " + _taskbars.DescribeWindow(taskbars[i])); + b.AppendLine("Taskbar " + i + ": " + DescribeWindowGeometry(taskbars[i])); + b.AppendLine("Maximized windows: " + DescribeMaximizedWindows()); try { @@ -54,6 +55,49 @@ private void CopyDiagnostics() } } + private string DescribeWindowGeometry(IntPtr h) + { + if (h == IntPtr.Zero) return "hwnd=0"; + StringBuilder b = new StringBuilder(_taskbars.DescribeWindow(h)); + + NativeMethods.RECT windowRect; + if (NativeMethods.GetWindowRect(h, out windowRect)) + b.Append(", rect=").Append(RectText(windowRect)); + + IntPtr monitor = NativeMethods.MonitorFromWindow(h, NativeMethods.MONITOR_DEFAULTTONEAREST); + if (monitor != IntPtr.Zero) + { + NativeMethods.MONITORINFO mi = new NativeMethods.MONITORINFO(); + mi.cbSize = Marshal.SizeOf(typeof(NativeMethods.MONITORINFO)); + if (NativeMethods.GetMonitorInfo(monitor, ref mi)) + { + b.Append(", monitor=").Append(RectText(mi.rcMonitor)); + b.Append(", nativeWork=").Append(RectText(mi.rcWork)); + } + } + return b.ToString(); + } + + private string DescribeMaximizedWindows() + { + List windows = new List(); + NativeMethods.EnumWindows(delegate(IntPtr h, IntPtr lParam) + { + if (windows.Count >= 12) return false; + if (!NativeMethods.IsWindowVisible(h) || !NativeMethods.IsZoomed(h)) return true; + windows.Add(DescribeWindowGeometry(h)); + return true; + }, IntPtr.Zero); + + if (windows.Count == 0) return "none"; + return string.Join(" | ", windows.ToArray()); + } + + private static string RectText(NativeMethods.RECT r) + { + return string.Format("[{0},{1},{2},{3}]", r.Left, r.Top, r.Right, r.Bottom); + } + protected override void ExitThreadCore() { Dispose(); diff --git a/bootstrap/payload/TaskbarController.Core.cs b/bootstrap/payload/TaskbarController.Core.cs index 21a84fe..d3d18a1 100644 --- a/bootstrap/payload/TaskbarController.Core.cs +++ b/bootstrap/payload/TaskbarController.Core.cs @@ -72,12 +72,6 @@ public void ApplyVisibility(bool show) foreach (IntPtr h in _taskbars) { if (!NativeMethods.IsWindow(h)) continue; - - // Match Buttery Taskbar's least-invasive visibility model: one - // synchronous ShowWindow call, with Explorer left in control of the - // taskbar's own auto-hide/XAML animation and position. Do not pair - // this with SetWindowPos or force the bar back onto the monitor; those - // operations can fight Explorer mid-animation and create a flash. NativeMethods.ShowWindow(h, show ? NativeMethods.SW_SHOWNOACTIVATE : NativeMethods.SW_HIDE); } } @@ -131,8 +125,12 @@ public uint GetAppbarState() private void SetAppbarState(uint state) { + IntPtr primaryTaskbar = NativeMethods.FindWindow("Shell_TrayWnd", null); + if (primaryTaskbar == IntPtr.Zero) return; + NativeMethods.APPBARDATA data = new NativeMethods.APPBARDATA(); data.cbSize = (uint)Marshal.SizeOf(typeof(NativeMethods.APPBARDATA)); + data.hWnd = primaryTaskbar; data.lParam = new IntPtr((long)state); NativeMethods.SHAppBarMessage(NativeMethods.ABM_SETSTATE, ref data); } diff --git a/bootstrap/payload/TaskbarController.WorkArea.cs b/bootstrap/payload/TaskbarController.WorkArea.cs index 2c760ea..2d4aec1 100644 --- a/bootstrap/payload/TaskbarController.WorkArea.cs +++ b/bootstrap/payload/TaskbarController.WorkArea.cs @@ -16,11 +16,28 @@ namespace SlipperyTaskbar { internal sealed partial class TaskbarController { + private bool _lastWorkAreaCorrectionSucceeded; + public void EnsureWorkAreaPolicy(bool enabled) { _originalWorkAreas.Clear(); _workAreasCaptured = false; DeleteWorkAreaState(); + _lastWorkAreaCorrectionSucceeded = false; + + if (!enabled) return; + + Screen[] screens = Screen.AllScreens; + if (screens.Length == 0) return; + + bool success = true; + foreach (Screen screen in screens) + { + NativeMethods.RECT full = RectFromRectangle(screen.Bounds); + if (!NativeMethods.SystemParametersInfoSetWorkArea(ref full, NativeMethods.SPIF_SENDCHANGE)) + success = false; + } + _lastWorkAreaCorrectionSucceeded = success; } private void CaptureOriginalWorkAreas() @@ -197,6 +214,7 @@ public string DescribeWorkArea() b.Append(" work=").Append(RectangleText(screens[i].WorkingArea)); } b.Append(", reservation=native-auto-hide"); + b.Append(", correction=").Append(_lastWorkAreaCorrectionSucceeded); return b.ToString(); } @@ -204,6 +222,5 @@ private static string RectangleText(Rectangle r) { return string.Format("[{0},{1},{2},{3}]", r.Left, r.Top, r.Right, r.Bottom); } - } } diff --git a/src/NativeMethods.cs b/src/NativeMethods.cs index a5f2aac..df9b1aa 100644 --- a/src/NativeMethods.cs +++ b/src/NativeMethods.cs @@ -95,6 +95,7 @@ internal static class NativeMethods [DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern IntPtr FindWindowEx(IntPtr parent, IntPtr childAfter, string className, string windowName); [DllImport("user32.dll")] public static extern bool IsWindow(IntPtr hWnd); [DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr hWnd); + [DllImport("user32.dll")] public static extern bool IsZoomed(IntPtr hWnd); [DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); [DllImport("user32.dll", SetLastError = true)] public static extern bool SetWindowPos(IntPtr hWnd, IntPtr insertAfter, int x, int y, int cx, int cy, uint flags); [DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr hWnd, out RECT rect); diff --git a/src/SlipperyContext.Diagnostics.cs b/src/SlipperyContext.Diagnostics.cs index 1081993..bd94f5f 100644 --- a/src/SlipperyContext.Diagnostics.cs +++ b/src/SlipperyContext.Diagnostics.cs @@ -20,7 +20,7 @@ private void CopyDiagnostics() { StringBuilder b = new StringBuilder(); b.AppendLine("Slippery Taskbar C# diagnostics"); - b.AppendLine("Build: 1.0.0"); + b.AppendLine("Build: 1.0.2-test"); b.AppendLine("Runtime: " + Environment.Version); b.AppendLine("OS: " + Environment.OSVersion); b.AppendLine("Executable: " + Application.ExecutablePath); @@ -39,9 +39,10 @@ private void CopyDiagnostics() IList taskbars = _taskbars.RefreshTaskbars(); b.AppendLine("Taskbars found: " + taskbars.Count); IntPtr foreground = NativeMethods.GetForegroundWindow(); - b.AppendLine("Foreground: " + _taskbars.DescribeWindow(foreground)); + b.AppendLine("Foreground: " + DescribeWindowGeometry(foreground)); for (int i = 0; i < taskbars.Count; i++) - b.AppendLine("Taskbar " + i + ": " + _taskbars.DescribeWindow(taskbars[i])); + b.AppendLine("Taskbar " + i + ": " + DescribeWindowGeometry(taskbars[i])); + b.AppendLine("Maximized windows: " + DescribeMaximizedWindows()); try { @@ -54,6 +55,51 @@ private void CopyDiagnostics() } } + private string DescribeWindowGeometry(IntPtr h) + { + if (h == IntPtr.Zero) return "hwnd=0"; + StringBuilder b = new StringBuilder(_taskbars.DescribeWindow(h)); + + NativeMethods.RECT windowRect; + if (NativeMethods.GetWindowRect(h, out windowRect)) + { + b.Append(", rect=").Append(RectText(windowRect)); + } + + IntPtr monitor = NativeMethods.MonitorFromWindow(h, NativeMethods.MONITOR_DEFAULTTONEAREST); + if (monitor != IntPtr.Zero) + { + NativeMethods.MONITORINFO mi = new NativeMethods.MONITORINFO(); + mi.cbSize = Marshal.SizeOf(typeof(NativeMethods.MONITORINFO)); + if (NativeMethods.GetMonitorInfo(monitor, ref mi)) + { + b.Append(", monitor=").Append(RectText(mi.rcMonitor)); + b.Append(", nativeWork=").Append(RectText(mi.rcWork)); + } + } + return b.ToString(); + } + + private string DescribeMaximizedWindows() + { + List windows = new List(); + NativeMethods.EnumWindows(delegate(IntPtr h, IntPtr lParam) + { + if (windows.Count >= 12) return false; + if (!NativeMethods.IsWindowVisible(h) || !NativeMethods.IsZoomed(h)) return true; + windows.Add(DescribeWindowGeometry(h)); + return true; + }, IntPtr.Zero); + + if (windows.Count == 0) return "none"; + return string.Join(" | ", windows.ToArray()); + } + + private static string RectText(NativeMethods.RECT r) + { + return string.Format("[{0},{1},{2},{3}]", r.Left, r.Top, r.Right, r.Bottom); + } + protected override void ExitThreadCore() { Dispose(); diff --git a/src/SlipperyTaskbar.csproj b/src/SlipperyTaskbar.csproj index 7df1bfa..a85a330 100644 --- a/src/SlipperyTaskbar.csproj +++ b/src/SlipperyTaskbar.csproj @@ -13,8 +13,8 @@ true true false - 1.0.0 - 1.0.0.0 + 1.0.2 + 1.0.2.0 Slippery Taskbar Hide the Windows 11 taskbar until the Windows key or shell UI intentionally reveals it. diff --git a/src/TaskbarController.Core.cs b/src/TaskbarController.Core.cs index 21a84fe..97e6434 100644 --- a/src/TaskbarController.Core.cs +++ b/src/TaskbarController.Core.cs @@ -73,11 +73,6 @@ public void ApplyVisibility(bool show) { if (!NativeMethods.IsWindow(h)) continue; - // Match Buttery Taskbar's least-invasive visibility model: one - // synchronous ShowWindow call, with Explorer left in control of the - // taskbar's own auto-hide/XAML animation and position. Do not pair - // this with SetWindowPos or force the bar back onto the monitor; those - // operations can fight Explorer mid-animation and create a flash. NativeMethods.ShowWindow(h, show ? NativeMethods.SW_SHOWNOACTIVATE : NativeMethods.SW_HIDE); } } @@ -131,8 +126,12 @@ public uint GetAppbarState() private void SetAppbarState(uint state) { + IntPtr primaryTaskbar = NativeMethods.FindWindow("Shell_TrayWnd", null); + if (primaryTaskbar == IntPtr.Zero) return; + NativeMethods.APPBARDATA data = new NativeMethods.APPBARDATA(); data.cbSize = (uint)Marshal.SizeOf(typeof(NativeMethods.APPBARDATA)); + data.hWnd = primaryTaskbar; data.lParam = new IntPtr((long)state); NativeMethods.SHAppBarMessage(NativeMethods.ABM_SETSTATE, ref data); } diff --git a/src/TaskbarController.WorkArea.cs b/src/TaskbarController.WorkArea.cs index 2c760ea..fe7171f 100644 --- a/src/TaskbarController.WorkArea.cs +++ b/src/TaskbarController.WorkArea.cs @@ -16,11 +16,35 @@ namespace SlipperyTaskbar { internal sealed partial class TaskbarController { + private bool _lastWorkAreaCorrectionSucceeded; + public void EnsureWorkAreaPolicy(bool enabled) { _originalWorkAreas.Clear(); _workAreasCaptured = false; DeleteWorkAreaState(); + _lastWorkAreaCorrectionSucceeded = false; + + if (!enabled) return; + + // ABM_SETSTATE can make Windows report the full monitor as its work area + // without forcing already-maximized windows to recalculate their maximize + // rectangle. Re-applying each monitor's full bounds through SPI_SETWORKAREA + // with SPIF_SENDCHANGE both makes the desired work area explicit and sends + // the normal system-wide work-area notification. This happens only when the + // policy is applied (startup/re-enable/Explorer recovery), never on Win-key + // taskbar show/hide transitions. + Screen[] screens = Screen.AllScreens; + if (screens.Length == 0) return; + + bool success = true; + foreach (Screen screen in screens) + { + NativeMethods.RECT full = RectFromRectangle(screen.Bounds); + if (!NativeMethods.SystemParametersInfoSetWorkArea(ref full, NativeMethods.SPIF_SENDCHANGE)) + success = false; + } + _lastWorkAreaCorrectionSucceeded = success; } private void CaptureOriginalWorkAreas() @@ -197,6 +221,7 @@ public string DescribeWorkArea() b.Append(" work=").Append(RectangleText(screens[i].WorkingArea)); } b.Append(", reservation=native-auto-hide"); + b.Append(", correction=").Append(_lastWorkAreaCorrectionSucceeded); return b.ToString(); } @@ -204,6 +229,5 @@ private static string RectangleText(Rectangle r) { return string.Format("[{0},{1},{2},{3}]", r.Left, r.Top, r.Right, r.Bottom); } - } }