Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.0.5
5 changes: 5 additions & 0 deletions bootstrap/payload/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ internal static class NativeMethods
public const uint ABM_GETSTATE = 0x00000004;
public const uint ABM_SETSTATE = 0x0000000A;
public const uint ABS_AUTOHIDE = 0x0000001;
public const int GWL_STYLE = -16;
public const long WS_MAXIMIZE = 0x01000000L;

[StructLayout(LayoutKind.Sequential)] public struct POINT { public int X; public int Y; }
[StructLayout(LayoutKind.Sequential)] public struct RECT { public int Left; public int Top; public int Right; public int Bottom; }
Expand Down Expand Up @@ -95,8 +97,11 @@ 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", EntryPoint = "GetWindowLongPtrW", SetLastError = true)] public static extern IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", EntryPoint = "SetWindowLongPtrW", SetLastError = true)] public static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr newLong);
[DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr hWnd, out RECT rect);
[DllImport("user32.dll")] public static extern IntPtr MonitorFromWindow(IntPtr hWnd, uint flags);
[DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern bool GetMonitorInfo(IntPtr hMonitor, ref MONITORINFO info);
Expand Down
4 changes: 3 additions & 1 deletion bootstrap/payload/SlipperyContext.Diagnostics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.5-force-maximized");
b.AppendLine("Runtime: " + Environment.Version);
b.AppendLine("OS: " + Environment.OSVersion);
b.AppendLine("Executable: " + Application.ExecutablePath);
Expand All @@ -29,6 +29,8 @@ 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("Forced maximized windows last pass: " + _taskbars.LastForcedMaximizedCount);
b.AppendLine("Forced maximized windows total: " + _taskbars.TotalForcedMaximizedCount);
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());
Expand Down
19 changes: 3 additions & 16 deletions bootstrap/payload/SlipperyContext.Polling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -79,21 +74,13 @@ private void PollTaskbarState()

bool shouldShow = _winDown || shellUi || interacting || trayVisibilityGuard || now < _visibleUntilUtc;

if (!shouldShow)
_taskbars.ForceAllMaximizedWindowsIntoTopAndSideGaps();

bool anyTaskbarVisible;
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)
Expand Down
100 changes: 95 additions & 5 deletions bootstrap/payload/TaskbarController.Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ internal sealed partial class TaskbarController
private bool _originalAppbarCaptured;
private readonly List<WorkAreaEntry> _originalWorkAreas = new List<WorkAreaEntry>();
private bool _workAreasCaptured;
private DateTime _lastForcedMaximizedPassUtc = DateTime.MinValue;
private int _lastForcedMaximizedCount;
private int _totalForcedMaximizedCount;

private sealed class WorkAreaEntry
{
Expand Down Expand Up @@ -73,15 +76,98 @@ 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);
}
}

public void ForceAllMaximizedWindowsIntoTopAndSideGaps()
{
DateTime now = DateTime.UtcNow;
if (_lastForcedMaximizedPassUtc != DateTime.MinValue &&
now - _lastForcedMaximizedPassUtc < TimeSpan.FromMilliseconds(90))
return;
_lastForcedMaximizedPassUtc = now;
_lastForcedMaximizedCount = 0;

NativeMethods.EnumWindows(delegate(IntPtr hWnd, IntPtr lParam)
{
if (!NativeMethods.IsWindow(hWnd) || !NativeMethods.IsWindowVisible(hWnd)) return true;
if (!NativeMethods.IsZoomed(hWnd)) return true;

string cls = GetWindowClass(hWnd);
if (IsTaskbarClass(cls) || IsShellUiWindow(hWnd)) return true;

IntPtr monitor = NativeMethods.MonitorFromWindow(hWnd, NativeMethods.MONITOR_DEFAULTTONEAREST);
if (monitor == IntPtr.Zero) return true;

NativeMethods.MONITORINFO mi = new NativeMethods.MONITORINFO();
mi.cbSize = Marshal.SizeOf(typeof(NativeMethods.MONITORINFO));
if (!NativeMethods.GetMonitorInfo(monitor, ref mi)) return true;

int topReserve = mi.rcWork.Top - mi.rcMonitor.Top;
int leftReserve = mi.rcWork.Left - mi.rcMonitor.Left;
int rightReserve = mi.rcMonitor.Right - mi.rcWork.Right;

if (topReserve < 8 && leftReserve < 8 && rightReserve < 8) return true;

NativeMethods.RECT r;
if (!NativeMethods.GetWindowRect(hWnd, out r)) return true;

int tolerance = 40;
bool looksLikeWorkAreaMaximized =
r.Left <= mi.rcWork.Left + tolerance &&
r.Top <= mi.rcWork.Top + tolerance &&
r.Right >= mi.rcWork.Right - tolerance &&
r.Bottom >= mi.rcWork.Bottom - tolerance;
if (!looksLikeWorkAreaMaximized) return true;

IntPtr stylePtr = NativeMethods.GetWindowLongPtr(hWnd, NativeMethods.GWL_STYLE);
long style = stylePtr.ToInt64();
if ((style & NativeMethods.WS_MAXIMIZE) == 0) return true;

int extraLeft = Math.Max(0, mi.rcWork.Left - r.Left);
int extraTop = Math.Max(0, mi.rcWork.Top - r.Top);
int extraRight = Math.Max(0, r.Right - mi.rcWork.Right);
int extraBottom = Math.Max(0, r.Bottom - mi.rcWork.Bottom);

int x = mi.rcMonitor.Left - extraLeft;
int y = mi.rcMonitor.Top - extraTop;
int right = mi.rcMonitor.Right + extraRight;
int bottom = mi.rcMonitor.Bottom + extraBottom;
int cx = right - x;
int cy = bottom - y;
if (cx <= 0 || cy <= 0) return true;

IntPtr restoredStyle = new IntPtr(style & ~NativeMethods.WS_MAXIMIZE);
IntPtr previousStyle = NativeMethods.SetWindowLongPtr(hWnd, NativeMethods.GWL_STYLE, restoredStyle);
bool clearedMaximizeStyle = previousStyle != IntPtr.Zero;

bool moved = NativeMethods.SetWindowPos(hWnd, IntPtr.Zero, x, y, cx, cy,
NativeMethods.SWP_NOACTIVATE | NativeMethods.SWP_NOZORDER | NativeMethods.SWP_NOSENDCHANGING);

if (clearedMaximizeStyle)
NativeMethods.SetWindowLongPtr(hWnd, NativeMethods.GWL_STYLE, stylePtr);

if (moved)
{
_lastForcedMaximizedCount++;
_totalForcedMaximizedCount++;
}

return true;
}, IntPtr.Zero);
}

public int LastForcedMaximizedCount
{
get { return _lastForcedMaximizedCount; }
}

public int TotalForcedMaximizedCount
{
get { return _totalForcedMaximizedCount; }
}

private static void ForceTaskbarOnScreen(IntPtr h)
{
NativeMethods.RECT r;
Expand Down Expand Up @@ -131,8 +217,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);
}
Expand Down
5 changes: 5 additions & 0 deletions src/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ internal static class NativeMethods
public const uint ABM_GETSTATE = 0x00000004;
public const uint ABM_SETSTATE = 0x0000000A;
public const uint ABS_AUTOHIDE = 0x0000001;
public const int GWL_STYLE = -16;
public const long WS_MAXIMIZE = 0x01000000L;

[StructLayout(LayoutKind.Sequential)] public struct POINT { public int X; public int Y; }
[StructLayout(LayoutKind.Sequential)] public struct RECT { public int Left; public int Top; public int Right; public int Bottom; }
Expand Down Expand Up @@ -95,8 +97,11 @@ 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", EntryPoint = "GetWindowLongPtrW", SetLastError = true)] public static extern IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", EntryPoint = "SetWindowLongPtrW", SetLastError = true)] public static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr newLong);
[DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr hWnd, out RECT rect);
[DllImport("user32.dll")] public static extern IntPtr MonitorFromWindow(IntPtr hWnd, uint flags);
[DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern bool GetMonitorInfo(IntPtr hMonitor, ref MONITORINFO info);
Expand Down
4 changes: 3 additions & 1 deletion src/SlipperyContext.Diagnostics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.5-force-maximized");
b.AppendLine("Runtime: " + Environment.Version);
b.AppendLine("OS: " + Environment.OSVersion);
b.AppendLine("Executable: " + Application.ExecutablePath);
Expand All @@ -29,6 +29,8 @@ 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("Forced maximized windows last pass: " + _taskbars.LastForcedMaximizedCount);
b.AppendLine("Forced maximized windows total: " + _taskbars.TotalForcedMaximizedCount);
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());
Expand Down
24 changes: 8 additions & 16 deletions src/SlipperyContext.Polling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -79,21 +74,18 @@ private void PollTaskbarState()

bool shouldShow = _winDown || shellUi || interacting || trayVisibilityGuard || now < _visibleUntilUtc;

// On top/left/right layouts some Explorer variants keep a real work-area
// reservation even though Slippery hides the taskbar. Standard maximized
// windows then refuse a normal SetWindowPos and snap back to rcWork.
// While hidden, force every visible maximized window to the full monitor
// by temporarily clearing WS_MAXIMIZE during the move, then restoring it.
if (!shouldShow)
_taskbars.ForceAllMaximizedWindowsIntoTopAndSideGaps();

bool anyTaskbarVisible;
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)
Expand Down
4 changes: 2 additions & 2 deletions src/SlipperyTaskbar.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<PublishSingleFile>true</PublishSingleFile>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<PublishTrimmed>false</PublishTrimmed>
<Version>1.0.0</Version>
<FileVersion>1.0.0.0</FileVersion>
<Version>1.0.5</Version>
<FileVersion>1.0.5.0</FileVersion>
<Product>Slippery Taskbar</Product>
<Description>Hide the Windows 11 taskbar until the Windows key or shell UI intentionally reveals it.</Description>
</PropertyGroup>
Expand Down
Loading
Loading