Skip to content

Fixes: preserve taskbar monitor selection + widget vanishing when start menu opens#47

Open
andreescocard wants to merge 2 commits into
CodeZeno:mainfrom
andreescocard:fix/start-menu-vanish-keepchild
Open

Fixes: preserve taskbar monitor selection + widget vanishing when start menu opens#47
andreescocard wants to merge 2 commits into
CodeZeno:mainfrom
andreescocard:fix/start-menu-vanish-keepchild

Conversation

@andreescocard

Copy link
Copy Markdown

No description provided.

andreescocard and others added 2 commits June 24, 2026 18:09
Store the selected taskbar's monitor device name in settings and
prefer it when reattaching the widget.

This keeps the widget anchored to the same physical monitor when
taskbar ordering changes after monitor connect, disconnect, or
reconfiguration, while still falling back to the saved index for
existing settings and compatibility.
The widget embeds as a child of the taskbar, which keeps it painted above
the shell's Start/Search acrylic backdrop. The actual bug was the watchdog:
opening the Start menu makes the taskbar briefly drop out of EnumWindows
(~5s) even though its HWND is still valid, and the watchdog read that as an
explorer restart and relaunched the whole process, wiping the widget.

Guard the watchdog with IsWindow on the stored taskbar handle: if the handle
still exists it is a transient Start-menu enumeration blip, so skip. Only
relaunch when the handle is truly destroyed (a real explorer restart) and
only after TASKBAR_MISSING_TICKS consecutive confirmations.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017m74C6QgGGawTbeTb8NkBG
androosio added a commit to androosio/Claude-Code-Usage-Monitor that referenced this pull request Jun 26, 2026
Opening the Start menu/search makes the taskbar briefly drop out of
EnumWindows (~5s) even though its HWND is still valid. The watchdog read
that as an explorer restart and relaunched the process, wiping the widget.

Guard the watchdog with IsWindow on the stored taskbar handle: if it still
exists, treat it as a transient enumeration blip and skip. Only relaunch
when the handle is truly gone for TASKBAR_MISSING_TICKS consecutive checks.

Fix originally by André Escocard (andreescocard) in CodeZeno PR CodeZeno#47.

Co-Authored-By: André Escocard <andreescocard@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@androosio

Copy link
Copy Markdown

Nice, I landed on the same device-name approach independently while looking at #43, so I can confirm the core mechanism is sound (and nice work on the start menu issue, I totally missed that!).

I closed my PR (#48) in favor of yours as you got there first. A few suggestions from my PR you might consider folding in:

  1. Fall back to the primary monitor instead of the geometric index

When the remembered device isn't found (first run, monitor swapped/renamed), attach_to_taskbar currently falls back to requested_index.min(len-1). Since find_taskbars() sorts by rect.top first, index 0 is the topmost taskbar (which on a setup with a vertical secondary monitor is often that secondary screen, i.e. the exact symptom from #43). Anchoring the fallback to the primary monitor avoids re-triggering the bug in that path:

// in TaskbarWindow: also capture the primary flag
// (MONITORINFO.dwFlags & MONITORINFOF_PRIMARY) != 0  → pub is_primary: bool

let index = requested_device
    .filter(|d| !d.is_empty())
    .and_then(|device| taskbars.iter().position(|t| t.device == device))
    .or_else(|| taskbars.iter().position(|t| t.is_primary))   // <- primary before index
    .unwrap_or_else(|| requested_index.min(taskbars.len().saturating_sub(1)));
  1. Briefly wait for the remembered monitor's taskbar on startup

A short retry in attach_to_taskbar (e.g., up to ~2s, 200 ms ticks) when requested_device is set but not yet present makes restarts stick to the right monitor.

  1. (Optional UX) Let the user pick the monitor explicitly

A small Settings > Monitor submenu listing each detected taskbar (primary marked) is a nice complement as it gives users a direct way to move the widget without dragging, and writes the same taskbar_device. Pairs well with having Reset position, also clear the stored device so it falls back to primary, as an escape hatch if it ever gets stuck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants