All posts

7 min readPost 33

Selecting a whole day at once, and why double-clicking the Windows tray icon couldn't open the window

Two seemingly tiny desktop UX requests—clicking a calendar day header to batch-act on all items and double-clicking the Windows tray icon to open Obituary—exposed subtle mode-downgrade hazards and a Win32 modal menu message-loop trap. Here is how a 3-state mode guard and a lock-free GWLP_WNDPROC subclass solved both cleanly.

On this page
  1. 1. Calendar day multiselect: protecting batch burials from silent downgrades and lost Undo
  2. 2. Why double-clicking the Windows tray icon couldn't open the window

Obituary's desktop experience pairs a lightweight resident tray daemon (obitd) with a Wails v2 + React calendar window (obit-gui). Late in November, two everyday usability requests came up:

  1. When a single day in the calendar holds a dozen expiring files, clicking them one by one gets tedious—let users click the day column header to select the entire day and batch-extend, bury, resurrect, or purge.
  2. On Windows, users instinctively double-click a tray icon (like Steam, WeChat, or Clash) to bring up the main panel instead of right-clicking a menu every time.

Both sounded like minor UI tweaks. Once implemented and put through independent code review, both uncovered surprisingly deep safety and Win32 systems problems.

Sequence and state diagram: top compares fyne.io/systray calling modal TrackPopupMenu on the first WM_LBUTTONUP (swallowing click 2) versus a lock-free GWLP_WNDPROC subclass swallowing WM_LBUTTONUP and routing WM_LBUTTONDBLCLK via a buffered channel; bottom shows the 3-state graveyard/recycle/unknown batch burial safety guard
Two desktop engineering fixes landed on 27 November: lock-free Win32 tray subclassing above, and the 3-state effective-mode guard for calendar batch burial below.

1. Calendar day multiselect: protecting batch burials from silent downgrades and lost Undo ​

Day-header multiselect and a floating squircle capsule action bar landed in draft on 26 November (151ef2c) and went through two review rounds with 12 targeted fixes (d780e06, de29f9a). Four safety invariants mattered far more than the checkboxes themselves:

Obituary desktop calendar window showing Tomorrow's column header clicked to select all cards in the column, with the floating squircle action capsule at the bottom offering Bury now, Extend, Stop tracking, and Clear
Live desktop calendar day-header multiselect (sample data): clicking the day header selects the full column and brings up the floating batch action capsule.

Three-state effective mode: disable instead of silently recycling ​

Obituary runs in either graveyard mode or recycle (OS Recycle Bin) mode. Previously the frontend read mode from Summary(), which re-read config.toml from disk—meaning a corrupt .obitrules trust file breaking Summary(), or an unsynced disk edit, could leave the UI thinking it was in graveyard mode while the backend actually recycled plain files without showing the Recycle Bin confirmation!

We collapsed the truth to one source:

  • Go's (*API).effectiveMode() reads solely from live Service.Mode (the exact field Bury executes against), returned by both Summary() and Upcoming().
  • The frontend tracks "graveyard" | "recycle" | "unknown". Whenever mode resolves to unknown and the selection contains plain files, Bury now disables in the UI and double-checks inside the executor, never silently degrading to unconfirmed recycling; in recycle mode, both single and mixed confirmations explicitly state when plain files go to the OS Recycle Bin.

Splitting warningCount from failedCount so Undo never disappears ​

During batch burial, a file can commit cleanly into the graveyard (action === "buried" with a valid grave ID) yet attach a non-fatal cleanup warning (for instance, an Explorer label sync hiccup). Early code treated any non-empty error string as failedCount and dropped the entry from buriedIds—telling the user burial "failed" while stripping that grave from one-click Undo. Splitting out warningCount keeps every committed burial inside buriedIds so Undo stays intact.

Three more batch and layout invariants ​

  • Resolve each ref once inside ExtendGraves: prepareExtendGraves calls findBurial once per reference inside graveyard.lock and cleans v1 manifests before applyExtendGraves commits, preventing a transient LongPath error from bypassing manifest checks.
  • Distinguishing manual vs. expired container burial: batch-burying an unexpired Docker container now persists Reason: "bury" on ContainerIntent (separate from "expired"), preserved cleanly across disconnect recovery and wired into graveyard FIFO quota enforcement.
  • Short-viewport capsule docking: under @media (max-height: 460px) (such as 600×400), the floating squircle capsule switches to position: static below the columns so it never obscures the bottom card's checkbox.

2. Why double-clicking the Windows tray icon couldn't open the window ​

Next came GitHub Issue #27: double-clicking the Windows tray icon to open Obituary (4b583c4).

We expected a one-line callback registration on fyne.io/systray v1.12.2. Reading systray_windows.go line by line revealed two stacked blockers:

  1. No double-click handling at all: handling WM_USER + 1 (0x0401), systray_windows.go's wndProc switched only on WM_LBUTTONUP (0x0202) and WM_RBUTTONUP (0x0205), completely ignoring WM_LBUTTONDBLCLK (0x0203).
  2. The first click's popup menu swallowed the second click: on a double-click, Windows Explorer posts four messages in sequence: WM_LBUTTONDOWN (0x0201) → WM_LBUTTONUP (0x0202) → WM_LBUTTONDBLCLK (0x0203) → WM_LBUTTONUP (0x0202). On the very first WM_LBUTTONUP, systray called synchronous TrackPopupMenu(...), dropping straight into Win32's modal menu message loop—consuming click #2 just to dismiss the menu so WM_LBUTTONDBLCLK never even arrived!

A zero-dependency fix: lock-free GWLP_WNDPROC subclassing ​

Forking the tray library was overkill, and our Windows visibility and notification code already depends on systray's hidden SystrayClass window. Instead, internal/tray/click_windows.go solves it in under 150 lines of zero-CGO Go:

  1. Race-free subclass install: inside systray.Run's onReady callback, locate our own process's SystrayClass handle via desktop.OwnWindow("SystrayClass"), read the original prev proc, publish *trayWindowHook atomically via atomic.Pointer, and only then swap GWLP_WNDPROC with SetWindowLongPtrW (SetWindowLongW on 386).
  2. Lock-free dispatch and single callback slot: allocate windows.NewCallback once via sync.Once; keep traySubclassProc completely lock-free to avoid reentrancy deadlocks during TrackPopupMenu, cleaning up cleanly on WM_NCDESTROY.
  3. Exact message routing:
    • WM_LBUTTONUP (0x0202): swallowed (return 0), preventing the blocking popup menu so click #2 generates WM_LBUTTONDBLCLK.
    • WM_LBUTTONDBLCLK (0x0203): non-blocking send to a capacity-1 m.activate channel (coalescing rapid clicks off the Win32 UI thread) feeding m.openGUI.open()—reusing OBIT_HOME single-instance window focus and missing-GUI notifications without touching our 1.6.1 ghost-click guards or zero-idle-wakeup guarantee.
    • WM_RBUTTONUP (0x0205), WM_COMMAND, TaskbarCreated, and all other messages: forwarded untouched via CallWindowProcW, keeping right-click menus and Explorer-restart recovery intact.

We verified the subclass against a real isolated Win32 HWND_MESSAGE window replaying LBUTTONDOWN → LBUTTONUP → LBUTTONDBLCLK → LBUTTONUP → RBUTTONUP and clean teardown (TestSubclassWindowDispatchesTrayMessages).

Respecting native platform conventions across all three OSes ​

PlatformMechanismLeft clickRight click
WindowsWin32 Shell_NotifyIconW + GWLP_WNDPROCDouble-click opens/focuses windowRight-click opens full tray menu
Linux (desktop)D-Bus StatusNotifierItem + dbusmenuCalling systray.SetOnTapped before systray.Run exports ItemIsMenu=false race-free; left-click (Activate) opens window on KDE/AppIndicatorRight-click opens full DBusMenu
macOS (desktop)Cocoa NSStatusItemSingle-click opens native menu bar menu ("Open Obituary" at top)Single-click opens menu

Each OS keeps its native desktop feel instead of forcing Windows double-clicks onto macOS or breaking Linux right-click menus.

All posts