|
27 | 27 | using Point = System.Windows.Point; |
28 | 28 | using SystemFonts = System.Windows.SystemFonts; |
29 | 29 |
|
| 30 | + |
30 | 31 | namespace Flow.Launcher.Infrastructure |
31 | 32 | { |
32 | 33 | public static class Win32Helper |
@@ -1019,26 +1020,38 @@ protected override bool ReleaseHandle() |
1019 | 1020 |
|
1020 | 1021 | #region Taskbar |
1021 | 1022 |
|
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() |
1027 | 1024 | { |
1028 | 1025 | // Find the taskbar window |
1029 | 1026 | var taskbarHwnd = PInvoke.FindWindowEx(HWND.Null, HWND.Null, "Shell_TrayWnd", null); |
1030 | 1027 | if (taskbarHwnd == HWND.Null) return; |
1031 | 1028 |
|
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; |
1038 | 1040 |
|
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; |
1042 | 1055 | } |
1043 | 1056 |
|
1044 | 1057 | #endregion |
|
0 commit comments