diff --git a/VERSION b/VERSION index 3eefcb9..ee90284 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.0 +1.0.4 diff --git a/bootstrap/payload/SlipperyContext.Core.cs b/bootstrap/payload/SlipperyContext.Core.cs index fdcb80d..6881a95 100644 --- a/bootstrap/payload/SlipperyContext.Core.cs +++ b/bootstrap/payload/SlipperyContext.Core.cs @@ -38,6 +38,10 @@ internal sealed partial class SlipperyContext : ApplicationContext, IDisposable private bool _lastShouldShow = true; private DateTime _lastApplyUtc = DateTime.MinValue; private DateTime _trayInteractionPinUntilUtc = DateTime.MinValue; + private DateTime _lastAppbarPolicyCheckUtc = DateTime.MinValue; + private DateTime _lastAppbarPolicyRepairUtc = DateTime.MinValue; + private int _appbarPolicyRepairAttempts; + private int _appbarPolicyRepairSuccesses; private IntPtr _mouseHook = IntPtr.Zero; private NativeMethods.LowLevelMouseProc _mouseHookProc; private bool _disposed; @@ -49,6 +53,7 @@ internal sealed partial class SlipperyContext : ApplicationContext, IDisposable private static readonly TimeSpan TrayInteractionPinGrace = TimeSpan.FromMilliseconds(900); private static readonly TimeSpan TrayClickPinGrace = TimeSpan.FromMilliseconds(1800); private static readonly TimeSpan TrayHoverPinGrace = TimeSpan.FromMilliseconds(500); + private static readonly TimeSpan AppbarPolicyWatchInterval = TimeSpan.FromMilliseconds(500); public SlipperyContext() { @@ -215,6 +220,7 @@ private void SetEnabled(bool value) _trayInteractionPinUntilUtc = DateTime.MinValue; _taskbars.EnsureAppbarPolicy(_enabled); _taskbars.EnsureWorkAreaPolicy(_enabled); + _lastAppbarPolicyCheckUtc = DateTime.MinValue; if (!_enabled) { diff --git a/bootstrap/payload/SlipperyContext.Diagnostics.cs b/bootstrap/payload/SlipperyContext.Diagnostics.cs index 1081993..2139664 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.4-policy"); b.AppendLine("Runtime: " + Environment.Version); b.AppendLine("OS: " + Environment.OSVersion); b.AppendLine("Executable: " + Application.ExecutablePath); @@ -29,6 +29,9 @@ private void CopyDiagnostics() b.AppendLine("Start with Windows: " + _startWithWindows); b.AppendLine("Keep visible while interacting: " + _preferencesStore.Current.KeepVisibleWhileInteracting); b.AppendLine("Native auto-hide active: " + ((_taskbars.GetAppbarState() & NativeMethods.ABS_AUTOHIDE) != 0)); + b.AppendLine("Appbar policy repair attempts: " + _appbarPolicyRepairAttempts); + b.AppendLine("Appbar policy repair successes: " + _appbarPolicyRepairSuccesses); + b.AppendLine("Last appbar policy repair UTC: " + (_lastAppbarPolicyRepairUtc == DateTime.MinValue ? "never" : _lastAppbarPolicyRepairUtc.ToString("O"))); b.AppendLine("Tray visibility guard active: " + (DateTime.UtcNow < _trayInteractionPinUntilUtc || _taskbars.IsTrayOverflowOpen())); b.AppendLine("Notification-area mouse guard installed: " + (_mouseHook != IntPtr.Zero)); b.AppendLine("Work area: " + _taskbars.DescribeWorkArea()); diff --git a/bootstrap/payload/SlipperyContext.Messages.cs b/bootstrap/payload/SlipperyContext.Messages.cs index 78dbce1..e8cd48e 100644 --- a/bootstrap/payload/SlipperyContext.Messages.cs +++ b/bootstrap/payload/SlipperyContext.Messages.cs @@ -36,6 +36,7 @@ internal void HandleWindowMessage(ref Message m) case NativeMethods.WM_DISPLAYCHANGE: case NativeMethods.WM_SETTINGCHANGE: _taskbars.RefreshTaskbars(); + RepairAppbarPolicyIfNeeded(); break; case NativeMethods.WM_POWERBROADCAST: int power = m.WParam.ToInt32(); @@ -44,6 +45,7 @@ internal void HandleWindowMessage(ref Message m) _taskbars.RefreshTaskbars(); _taskbars.EnsureAppbarPolicy(_enabled); _taskbars.EnsureWorkAreaPolicy(_enabled); + _lastAppbarPolicyCheckUtc = DateTime.UtcNow; _visibleUntilUtc = DateTime.UtcNow.AddMilliseconds(750); } break; @@ -55,6 +57,7 @@ private void HandleExplorerRestart() _taskbars.RefreshTaskbars(); _taskbars.EnsureAppbarPolicy(_enabled); _taskbars.EnsureWorkAreaPolicy(_enabled); + _lastAppbarPolicyCheckUtc = DateTime.UtcNow; _visibleUntilUtc = DateTime.UtcNow.AddMilliseconds(750); // NotifyIcon normally recreates itself after TaskbarCreated, but @@ -66,6 +69,24 @@ private void HandleExplorerRestart() } } + private void RepairAppbarPolicyIfNeeded() + { + if (!_enabled) return; + + _lastAppbarPolicyCheckUtc = DateTime.UtcNow; + uint state = _taskbars.GetAppbarState(); + if ((state & NativeMethods.ABS_AUTOHIDE) != 0) return; + + _appbarPolicyRepairAttempts++; + _taskbars.RefreshTaskbars(); + _taskbars.EnsureAppbarPolicy(true); + _lastAppbarPolicyRepairUtc = DateTime.UtcNow; + + uint after = _taskbars.GetAppbarState(); + if ((after & NativeMethods.ABS_AUTOHIDE) != 0) + _appbarPolicyRepairSuccesses++; + } + private void HandleRawInput(IntPtr rawInputHandle) { uint size = 0; diff --git a/bootstrap/payload/SlipperyContext.Polling.cs b/bootstrap/payload/SlipperyContext.Polling.cs index 02a80e3..d5b8927 100644 --- a/bootstrap/payload/SlipperyContext.Polling.cs +++ b/bootstrap/payload/SlipperyContext.Polling.cs @@ -28,11 +28,6 @@ private IntPtr MouseHookCallback(int nCode, IntPtr wParam, IntPtr lParam) NativeMethods.MSLLHOOKSTRUCT mouse = (NativeMethods.MSLLHOOKSTRUCT)Marshal.PtrToStructure( lParam, typeof(NativeMethods.MSLLHOOKSTRUCT)); - // Do not touch ABM_SETSTATE here. Changing ABS_AUTOHIDE causes - // Explorer to recalculate the desktop work area, which makes - // maximized windows resize when Win or a tray flyout is used. - // Instead, pre-authorize the notification-area transition and - // keep the actual taskbar window physically on-screen. if (_taskbars.IsPointOverNotificationArea(mouse.pt)) { TimeSpan grace = message == NativeMethods.WM_LBUTTONDOWN @@ -60,6 +55,12 @@ private void PollTaskbarState() ReconcileWinKeyStateFromPolling(); DateTime now = DateTime.UtcNow; + if (_lastAppbarPolicyCheckUtc == DateTime.MinValue || + now - _lastAppbarPolicyCheckUtc >= AppbarPolicyWatchInterval) + { + RepairAppbarPolicyIfNeeded(); + } + bool trayOverflowOpen = _taskbars.IsTrayOverflowOpen(); if (trayOverflowOpen) { @@ -83,17 +84,6 @@ private void PollTaskbarState() bool allTaskbarsVisible; _taskbars.GetActualVisibilityState(out anyTaskbarVisible, out allTaskbarsVisible); - // Native auto-hide is enabled only so Windows releases the taskbar's work - // area. Explorer may still try to reveal the bar when the pointer touches - // an edge, so immediately correct any visibility that Slippery did not - // authorize. Conversely, if Explorer auto-hides while Start/shell UI is - // active, put the taskbar back on-screen. - // Only correct the dangerous direction here: Explorer revealing a - // taskbar that Slippery intends to keep hidden. When the taskbar is - // intentionally visible, Explorer is allowed to own the intermediate - // frames of Start/tray/XAML animations. Re-showing or repositioning the - // taskbar during those frames is what caused the visible close/reopen - // stutter around the hidden-icons flyout. bool unauthorizedReveal = !shouldShow && anyTaskbarVisible; if (shouldShow != _lastShouldShow || unauthorizedReveal || _lastApplyUtc == DateTime.MinValue) 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/src/SlipperyContext.Core.cs b/src/SlipperyContext.Core.cs index fdcb80d..6881a95 100644 --- a/src/SlipperyContext.Core.cs +++ b/src/SlipperyContext.Core.cs @@ -38,6 +38,10 @@ internal sealed partial class SlipperyContext : ApplicationContext, IDisposable private bool _lastShouldShow = true; private DateTime _lastApplyUtc = DateTime.MinValue; private DateTime _trayInteractionPinUntilUtc = DateTime.MinValue; + private DateTime _lastAppbarPolicyCheckUtc = DateTime.MinValue; + private DateTime _lastAppbarPolicyRepairUtc = DateTime.MinValue; + private int _appbarPolicyRepairAttempts; + private int _appbarPolicyRepairSuccesses; private IntPtr _mouseHook = IntPtr.Zero; private NativeMethods.LowLevelMouseProc _mouseHookProc; private bool _disposed; @@ -49,6 +53,7 @@ internal sealed partial class SlipperyContext : ApplicationContext, IDisposable private static readonly TimeSpan TrayInteractionPinGrace = TimeSpan.FromMilliseconds(900); private static readonly TimeSpan TrayClickPinGrace = TimeSpan.FromMilliseconds(1800); private static readonly TimeSpan TrayHoverPinGrace = TimeSpan.FromMilliseconds(500); + private static readonly TimeSpan AppbarPolicyWatchInterval = TimeSpan.FromMilliseconds(500); public SlipperyContext() { @@ -215,6 +220,7 @@ private void SetEnabled(bool value) _trayInteractionPinUntilUtc = DateTime.MinValue; _taskbars.EnsureAppbarPolicy(_enabled); _taskbars.EnsureWorkAreaPolicy(_enabled); + _lastAppbarPolicyCheckUtc = DateTime.MinValue; if (!_enabled) { diff --git a/src/SlipperyContext.Diagnostics.cs b/src/SlipperyContext.Diagnostics.cs index 1081993..2139664 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.4-policy"); b.AppendLine("Runtime: " + Environment.Version); b.AppendLine("OS: " + Environment.OSVersion); b.AppendLine("Executable: " + Application.ExecutablePath); @@ -29,6 +29,9 @@ private void CopyDiagnostics() b.AppendLine("Start with Windows: " + _startWithWindows); b.AppendLine("Keep visible while interacting: " + _preferencesStore.Current.KeepVisibleWhileInteracting); b.AppendLine("Native auto-hide active: " + ((_taskbars.GetAppbarState() & NativeMethods.ABS_AUTOHIDE) != 0)); + b.AppendLine("Appbar policy repair attempts: " + _appbarPolicyRepairAttempts); + b.AppendLine("Appbar policy repair successes: " + _appbarPolicyRepairSuccesses); + b.AppendLine("Last appbar policy repair UTC: " + (_lastAppbarPolicyRepairUtc == DateTime.MinValue ? "never" : _lastAppbarPolicyRepairUtc.ToString("O"))); b.AppendLine("Tray visibility guard active: " + (DateTime.UtcNow < _trayInteractionPinUntilUtc || _taskbars.IsTrayOverflowOpen())); b.AppendLine("Notification-area mouse guard installed: " + (_mouseHook != IntPtr.Zero)); b.AppendLine("Work area: " + _taskbars.DescribeWorkArea()); diff --git a/src/SlipperyContext.Messages.cs b/src/SlipperyContext.Messages.cs index 78dbce1..e8cd48e 100644 --- a/src/SlipperyContext.Messages.cs +++ b/src/SlipperyContext.Messages.cs @@ -36,6 +36,7 @@ internal void HandleWindowMessage(ref Message m) case NativeMethods.WM_DISPLAYCHANGE: case NativeMethods.WM_SETTINGCHANGE: _taskbars.RefreshTaskbars(); + RepairAppbarPolicyIfNeeded(); break; case NativeMethods.WM_POWERBROADCAST: int power = m.WParam.ToInt32(); @@ -44,6 +45,7 @@ internal void HandleWindowMessage(ref Message m) _taskbars.RefreshTaskbars(); _taskbars.EnsureAppbarPolicy(_enabled); _taskbars.EnsureWorkAreaPolicy(_enabled); + _lastAppbarPolicyCheckUtc = DateTime.UtcNow; _visibleUntilUtc = DateTime.UtcNow.AddMilliseconds(750); } break; @@ -55,6 +57,7 @@ private void HandleExplorerRestart() _taskbars.RefreshTaskbars(); _taskbars.EnsureAppbarPolicy(_enabled); _taskbars.EnsureWorkAreaPolicy(_enabled); + _lastAppbarPolicyCheckUtc = DateTime.UtcNow; _visibleUntilUtc = DateTime.UtcNow.AddMilliseconds(750); // NotifyIcon normally recreates itself after TaskbarCreated, but @@ -66,6 +69,24 @@ private void HandleExplorerRestart() } } + private void RepairAppbarPolicyIfNeeded() + { + if (!_enabled) return; + + _lastAppbarPolicyCheckUtc = DateTime.UtcNow; + uint state = _taskbars.GetAppbarState(); + if ((state & NativeMethods.ABS_AUTOHIDE) != 0) return; + + _appbarPolicyRepairAttempts++; + _taskbars.RefreshTaskbars(); + _taskbars.EnsureAppbarPolicy(true); + _lastAppbarPolicyRepairUtc = DateTime.UtcNow; + + uint after = _taskbars.GetAppbarState(); + if ((after & NativeMethods.ABS_AUTOHIDE) != 0) + _appbarPolicyRepairSuccesses++; + } + private void HandleRawInput(IntPtr rawInputHandle) { uint size = 0; diff --git a/src/SlipperyContext.Polling.cs b/src/SlipperyContext.Polling.cs index 02a80e3..d5b8927 100644 --- a/src/SlipperyContext.Polling.cs +++ b/src/SlipperyContext.Polling.cs @@ -28,11 +28,6 @@ private IntPtr MouseHookCallback(int nCode, IntPtr wParam, IntPtr lParam) NativeMethods.MSLLHOOKSTRUCT mouse = (NativeMethods.MSLLHOOKSTRUCT)Marshal.PtrToStructure( lParam, typeof(NativeMethods.MSLLHOOKSTRUCT)); - // Do not touch ABM_SETSTATE here. Changing ABS_AUTOHIDE causes - // Explorer to recalculate the desktop work area, which makes - // maximized windows resize when Win or a tray flyout is used. - // Instead, pre-authorize the notification-area transition and - // keep the actual taskbar window physically on-screen. if (_taskbars.IsPointOverNotificationArea(mouse.pt)) { TimeSpan grace = message == NativeMethods.WM_LBUTTONDOWN @@ -60,6 +55,12 @@ private void PollTaskbarState() ReconcileWinKeyStateFromPolling(); DateTime now = DateTime.UtcNow; + if (_lastAppbarPolicyCheckUtc == DateTime.MinValue || + now - _lastAppbarPolicyCheckUtc >= AppbarPolicyWatchInterval) + { + RepairAppbarPolicyIfNeeded(); + } + bool trayOverflowOpen = _taskbars.IsTrayOverflowOpen(); if (trayOverflowOpen) { @@ -83,17 +84,6 @@ private void PollTaskbarState() bool allTaskbarsVisible; _taskbars.GetActualVisibilityState(out anyTaskbarVisible, out allTaskbarsVisible); - // Native auto-hide is enabled only so Windows releases the taskbar's work - // area. Explorer may still try to reveal the bar when the pointer touches - // an edge, so immediately correct any visibility that Slippery did not - // authorize. Conversely, if Explorer auto-hides while Start/shell UI is - // active, put the taskbar back on-screen. - // Only correct the dangerous direction here: Explorer revealing a - // taskbar that Slippery intends to keep hidden. When the taskbar is - // intentionally visible, Explorer is allowed to own the intermediate - // frames of Start/tray/XAML animations. Re-showing or repositioning the - // taskbar during those frames is what caused the visible close/reopen - // stutter around the hidden-icons flyout. bool unauthorizedReveal = !shouldShow && anyTaskbarVisible; if (shouldShow != _lastShouldShow || unauthorizedReveal || _lastApplyUtc == DateTime.MinValue) diff --git a/src/SlipperyTaskbar.csproj b/src/SlipperyTaskbar.csproj index 7df1bfa..c709dcd 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.4 + 1.0.4.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); }