Skip to content

Commit 65649f1

Browse files
committed
Support for StartAllBack multitaskbar notification area
StartAllBack provides support for per-taskbar notification area. Shell APIs would return active (last clicked) taskbar. - Get active taskbar rect via ABM_GETTASKBARPOS with special flag; use that rect to get monitor instead of primary tray monitor - Get taskbar DPI via proper API which would account for active / auto-hidden taskbar - Readjust popup window position by repeating calculation with new DPI to account for DPI changes File-New-Project#1611
1 parent 39386fd commit 65649f1

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

EarTrumpet/Interop/Helpers/WindowsTaskbar.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static uint Dpi
3434
{
3535
unsafe
3636
{
37-
return PInvoke.GetDpiForWindow(new HWND(GetHwnd()));
37+
return PInvoke.GetDpiForShellUIComponent(SHELL_UI_COMPONENT.SHELL_UI_COMPONENT_NOTIFICATIONAREA);
3838
}
3939
}
4040
}
@@ -53,7 +53,7 @@ public static State Current
5353
var appBarData = new APPBARDATA
5454
{
5555
cbSize = (uint)Marshal.SizeOf(typeof(APPBARDATA)),
56-
hWnd = new HWND(hwnd)
56+
lParam = 0x42 // magic to get active taskbar rect with StartAllBack
5757
};
5858

5959
// SHAppBarMessage: Understands Taskbar auto-hide
@@ -62,6 +62,7 @@ public static State Current
6262
{
6363
state.Size = appBarData.rc;
6464
state.Location = (Position)appBarData.uEdge;
65+
state.ContainingScreen = Screen.FromRectangle((System.Drawing.Rectangle)appBarData.rc);
6566
}
6667
else
6768
{

EarTrumpet/NativeMethods.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ GET_GUI_RESOURCES_FLAGS
3333
GetApplicationUserModelId
3434
GetClassName
3535
GetCurrentProcess
36+
GetDpiForShellUIComponent
3637
GetDpiForSystem
3738
GetDpiForWindow
3839
GetForegroundWindow

EarTrumpet/UI/Views/FlyoutWindow.xaml.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ private void OnStateChanged(object sender, object e)
4949

5050
Show();
5151
EnableAcrylicIfApplicable(taskbar);
52+
var prevDpi = this.DpiX();
5253
PositionWindowRelativeToTaskbar(taskbar);
54+
// Account for DPI changing due to SetWindowPos
55+
if (this.DpiX() != prevDpi)
56+
PositionWindowRelativeToTaskbar(taskbar);
5357

5458
// Focus the first device if available.
5559
DevicesList.FindVisualChild<DeviceView>()?.FocusAndRemoveFocusVisual();

0 commit comments

Comments
 (0)