Skip to content

Commit abd8a0e

Browse files
Show/hide tasking when showing/hiding Flow
1 parent bb731bc commit abd8a0e

3 files changed

Lines changed: 33 additions & 17 deletions

File tree

Flow.Launcher.Infrastructure/NativeMethods.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,4 @@ PowerRegisterSuspendResumeNotification
9393
PowerUnregisterSuspendResumeNotification
9494
DeviceNotifyCallbackRoutine
9595

96-
SHAppBarMessage
97-
APPBARDATA
98-
ABM_ACTIVATE
96+
MonitorFromWindow

Flow.Launcher.Infrastructure/Win32Helper.cs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
using Point = System.Windows.Point;
2828
using SystemFonts = System.Windows.SystemFonts;
2929

30+
3031
namespace Flow.Launcher.Infrastructure
3132
{
3233
public static class Win32Helper
@@ -1019,26 +1020,38 @@ protected override bool ReleaseHandle()
10191020

10201021
#region Taskbar
10211022

1022-
/// <summary>
1023-
/// Shows the taskbar temporarily by activating it.
1024-
/// This is useful for auto-hidden taskbars and mimics the behavior of hovering over the taskbar edge.
1025-
/// </summary>
1026-
public static void ShowTaskbar()
1023+
public static unsafe void ShowTaskbar()
10271024
{
10281025
// Find the taskbar window
10291026
var taskbarHwnd = PInvoke.FindWindowEx(HWND.Null, HWND.Null, "Shell_TrayWnd", null);
10301027
if (taskbarHwnd == HWND.Null) return;
10311028

1032-
// Prepare appbar data with the taskbar handle
1033-
var appBarData = new APPBARDATA
1034-
{
1035-
cbSize = (uint)Marshal.SizeOf<APPBARDATA>(),
1036-
hWnd = taskbarHwnd
1037-
};
1029+
// Magic from https://github.com/Oliviaophia/SmartTaskbar
1030+
const uint TrayBarFlag = 0x05D1;
1031+
var mon = PInvoke.MonitorFromWindow(taskbarHwnd, Windows.Win32.Graphics.Gdi.MONITOR_FROM_FLAGS.MONITOR_DEFAULTTONEAREST);
1032+
PInvoke.PostMessage(taskbarHwnd, TrayBarFlag, new WPARAM(1), new LPARAM((nint)mon.Value));
1033+
}
1034+
1035+
public static void HideTaskbar()
1036+
{
1037+
// Find the taskbar window
1038+
var taskbarHwnd = PInvoke.FindWindowEx(HWND.Null, HWND.Null, "Shell_TrayWnd", null);
1039+
if (taskbarHwnd == HWND.Null) return;
10381040

1039-
// Send ABM_ACTIVATE to temporarily show the taskbar
1040-
// This activates the taskbar without permanently changing its auto-hide state
1041-
PInvoke.SHAppBarMessage(PInvoke.ABM_ACTIVATE, ref appBarData);
1041+
// Magic from https://github.com/Oliviaophia/SmartTaskbar
1042+
const uint TrayBarFlag = 0x05D1;
1043+
PInvoke.PostMessage(taskbarHwnd, TrayBarFlag, new WPARAM(0), IntPtr.Zero);
1044+
}
1045+
1046+
[StructLayout(LayoutKind.Sequential)]
1047+
private struct APPBARDATA
1048+
{
1049+
public uint cbSize;
1050+
public HWND hWnd;
1051+
public uint uCallbackMessage;
1052+
public uint uEdge;
1053+
public RECT rc;
1054+
public nint lParam;
10421055
}
10431056

10441057
#endregion

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,6 +2208,11 @@ public async void Hide(bool reset = true)
22082208
Win32Helper.RestorePreviousKeyboardLayout();
22092209
}
22102210

2211+
if (Settings.ShowTaskbarWhenInvoked)
2212+
{
2213+
Win32Helper.HideTaskbar();
2214+
}
2215+
22112216
// Delay for a while to make sure clock will not flicker
22122217
await Task.Delay(50);
22132218

0 commit comments

Comments
 (0)