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.2
1 change: 1 addition & 0 deletions bootstrap/payload/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
50 changes: 47 additions & 3 deletions 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.2-test");
b.AppendLine("Runtime: " + Environment.Version);
b.AppendLine("OS: " + Environment.OSVersion);
b.AppendLine("Executable: " + Application.ExecutablePath);
Expand All @@ -39,9 +39,10 @@ private void CopyDiagnostics()
IList<IntPtr> 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
{
Expand All @@ -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<string> windows = new List<string>();
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();
Expand Down
10 changes: 4 additions & 6 deletions bootstrap/payload/TaskbarController.Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
Expand Down
19 changes: 18 additions & 1 deletion bootstrap/payload/TaskbarController.WorkArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -197,13 +214,13 @@ 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();
}

private static string RectangleText(Rectangle r)
{
return string.Format("[{0},{1},{2},{3}]", r.Left, r.Top, r.Right, r.Bottom);
}

}
}
1 change: 1 addition & 0 deletions src/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
52 changes: 49 additions & 3 deletions 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.2-test");
b.AppendLine("Runtime: " + Environment.Version);
b.AppendLine("OS: " + Environment.OSVersion);
b.AppendLine("Executable: " + Application.ExecutablePath);
Expand All @@ -39,9 +39,10 @@ private void CopyDiagnostics()
IList<IntPtr> 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
{
Expand All @@ -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<string> windows = new List<string>();
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();
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.2</Version>
<FileVersion>1.0.2.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
9 changes: 4 additions & 5 deletions src/TaskbarController.Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
Expand Down
26 changes: 25 additions & 1 deletion src/TaskbarController.WorkArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -197,13 +221,13 @@ 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();
}

private static string RectangleText(Rectangle r)
{
return string.Format("[{0},{1},{2},{3}]", r.Left, r.Top, r.Right, r.Bottom);
}

}
}
Loading