Skip to content

Add deferred work area option to position updates - #165

Merged
dremin merged 9 commits into
cairoshell:masterfrom
xoascf:reserve-position-on-demand
Aug 14, 2026
Merged

Add deferred work area option to position updates#165
dremin merged 9 commits into
cairoshell:masterfrom
xoascf:reserve-position-on-demand

Conversation

@xoascf

@xoascf xoascf commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Introduces a DeferWorkArea property on AppBarWindow so callers can reposition app bars without immediately updating the shell work area (useful when dragging an app bar). When DeferWorkArea is enabled:

  • UpdatePosition avoids calling ABSetPos in normal non-shell mode and applies the desired rect directly, enabling staged/multi-step layout updates without premature work area changes
  • SetWindowPosition skips updating the work area in shell mode
  • Incoming position change notifications (PosChanged) and WM_WINDOWPOSCHANGED notifications are ignored/deferred until positioning is complete

Misc updates:

  • Fix POINT struct for x64: In ManagedShell.Interop\NativeMethods.cs, POINT was defined with 64-bit long fields, causing memory corruption in Win32 functions like GetCursorPos:

    • Corrected the fields to 32-bit int to restore the proper 8-byte size
    • Added [StructLayout(LayoutKind.Sequential)] for precise memory alignment
    • Preserved the long constructor for backward compatibility
  • Win32 Interop additions & consolidation:

    • Moved TrackPopupMenuEx and the TPM enum from ManagedShell.ShellFolders into ManagedShell.Interop.NativeMethods.User32 to avoid duplicate definitions.
    • Added system menu APIs and constants (GetSystemMenu, EnableMenuItem, SC_*, MF_*) to NativeMethods.User32.cs.
    • Added window region APIs: SetWindowRgn (user32.dll) and CreateRectRgn (gdi32.dll).
  • Fix fallback to XP balloon sound for toast notifications: Corrected fallback logic so legacy Windows / XP sound schemes play properly when Windows 8+ toast sound schemes are unavailable.

  • User32 sources:

  • Additional notes:

    • TrackPopupMenuEx is also defined in ManagedShell\src\ManagedShell.ShellFolders\Interop.cs, we will probably need to update that one too Moved in 12720b8
    • Not sure why ManagedShell\src\ManagedShell.ShellFolders\Structs\TPMPARAMS.cs is there, or why it has no public fields. Since it is not touched in this PR, maybe it's not relevant?

xoascf added 4 commits August 9, 2026 13:19
Skip app bar reposition and broadcast handling while `DeferWorkArea` is enabled. This prevents `AppBarWindow` from reacting to position-change notifications or unexpected moves during deferred work area updates.
Expose the user32 constants and P/Invokes needed to work with window system menus, including cursor position, menu enabling, and popup tracking.
@dremin
dremin self-requested a review August 10, 2026 06:20
@dremin

dremin commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

TrackPopupMenuEx is also defined in ManagedShell\src\ManagedShell.ShellFolders\Interop.cs, we will probably need to update that one too

Yes, if moving to NativeMethods.User32 then the old one should be removed :)

Comment thread src/ManagedShell.AppBar/AppBarWindow.cs
Comment thread src/ManagedShell.Interop/NativeMethods.User32.cs
xoascf added 2 commits August 12, 2026 10:14
Remove the extra `deferWorkArea` parameters from window positioning methods and rely on the `DeferWorkArea` property instead. This keeps work area updates tied to the app bar's current state and simplifies the positioning flow.
When `Notification.Default` is set to `(None)` (such as in legacy or custom sound schemes), `PlaySound` with `SND_ALIAS` returned `true` without playing an audible sound, preventing the fallback to the XP notification sound.

Using the registry-checking `PlaySystemSound` overload ensures empty sound assignments return `false` and trigger the fallback.
Comment thread src/ManagedShell.AppBar/AppBarWindow.cs Outdated
xoascf added 2 commits August 13, 2026 18:47
Adds missing P/Invoke declarations for `CreateRectRgn` (Gdi32) and `SetWindowRgn` (User32). This enables creating and applying custom window regions from managed code, supporting non-rectangular window shaping/clipping.
Combine nested if conditions in AppBarWindow.UpdatePosition per review suggestion from @dremin.

@dremin dremin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dremin
dremin merged commit d3a85b1 into cairoshell:master Aug 14, 2026
1 check passed
@xoascf
xoascf deleted the reserve-position-on-demand branch August 14, 2026 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants