Context menus move under the cursor near window edges, sometimes every frame #594

Closed
opened 2026-11-15 06:14:08 +00:00 by charles · 1 comment
Owner

Report (Charles, 2026-11-15). Context menus are drawn inside the app window, so near an edge they get pushed around; they sometimes move while the mouse is over them, and in some cases the menu "bounces around every frame".

Likely mechanism (from reading crates/fluxer-ui/src/widgets/context_menu.rs on dailyuse, not yet reproduced).

  • Anchored::layout recomputes every card's position on every layout from the card's current size (place: flip, then shift inside EDGE_PADDING). Anything that changes a card's size while it is open (a row gaining a hint, a label changing, a submenu's content loading) moves the card under the cursor.
  • A submenu goes right of its row, else left, and is then shifted back inside the window. When it fits on neither side (menu near the right edge of a narrow window, or a wide submenu), the shift puts it over the main card, possibly over the hovered row itself. The cursor is then over the submenu instead of the row; if leaving the row closes the submenu, the row is hovered again on the next frame and reopens it: open, close, open, every frame.
  • Other menus and popouts that do their own placement (screens/main/message_actions/menu.rs, threads/menu.rs, widgets/popout.rs, the profile popout, the expression picker) may have the same two faults.

What "fixed" means.

  1. A menu's position is decided when it opens (and when the window is resized), not re-derived from sizes each frame; an open menu never moves because of hover.
  2. A submenu never covers the row that opened it. If neither side has room, it takes the side with more room and overlaps the main card from that side without covering its own row, as floating-ui does in the original.
  3. Hovering from a row into its submenu keeps the submenu open (the cursor may cross the gap); no open/close oscillation is possible.
  4. Menus cannot leave the window: iced draws overlays inside the window surface, and Wayland does not let an app place a separate popup window at a chosen position. So the goal is stable placement inside the window, matching the original web client, which has the same limit.

Tests. For every menu kind (message, channel, category, guild, user, DM, voice participant, thread) opened at each corner and edge of a small window, with a simulated cursor on each submenu row over several consecutive frames: card positions are identical frame to frame, the submenu stays open, and the submenu does not intersect its row.

**Report (Charles, 2026-11-15).** Context menus are drawn inside the app window, so near an edge they get pushed around; they sometimes move while the mouse is over them, and in some cases the menu "bounces around every frame". **Likely mechanism (from reading `crates/fluxer-ui/src/widgets/context_menu.rs` on `dailyuse`, not yet reproduced).** - `Anchored::layout` recomputes every card's position on every layout from the card's current size (`place`: flip, then shift inside `EDGE_PADDING`). Anything that changes a card's size while it is open (a row gaining a hint, a label changing, a submenu's content loading) moves the card under the cursor. - A submenu goes right of its row, else left, and is then shifted back inside the window. When it fits on neither side (menu near the right edge of a narrow window, or a wide submenu), the shift puts it over the main card, possibly over the hovered row itself. The cursor is then over the submenu instead of the row; if leaving the row closes the submenu, the row is hovered again on the next frame and reopens it: open, close, open, every frame. - Other menus and popouts that do their own placement (`screens/main/message_actions/menu.rs`, `threads/menu.rs`, `widgets/popout.rs`, the profile popout, the expression picker) may have the same two faults. **What "fixed" means.** 1. A menu's position is decided when it opens (and when the window is resized), not re-derived from sizes each frame; an open menu never moves because of hover. 2. A submenu never covers the row that opened it. If neither side has room, it takes the side with more room and overlaps the main card from that side without covering its own row, as floating-ui does in the original. 3. Hovering from a row into its submenu keeps the submenu open (the cursor may cross the gap); no open/close oscillation is possible. 4. Menus cannot leave the window: iced draws overlays inside the window surface, and Wayland does not let an app place a separate popup window at a chosen position. So the goal is stable placement inside the window, matching the original web client, which has the same limit. **Tests.** For every menu kind (message, channel, category, guild, user, DM, voice participant, thread) opened at each corner and edge of a small window, with a simulated cursor on each submenu row over several consecutive frames: card positions are identical frame to frame, the submenu stays open, and the submenu does not intersect its row.
Author
Owner

Reproduced and fixed in two PRs, one per branch, because the shared widget has diverged:

  • #608 → textchat (the nightly where the bounce happens). Anchored placed the main card and the open submenu as one block and moved that block back inside the window. A submenu that ran past the bottom or right edge moved the main card too. iced's mouse_area re-checks hover whenever its bounds change, so the next frame another row was under the cursor, it closed or switched the submenu, the block moved back, and this repeated every frame. A headless test catches it: [None, Some(5), Some(6), Some(5), Some(6), …]. Now each card is placed on its own and the main card never moves when a submenu opens or closes. The control_bar_sharing golden changed for that reason (the stream menu no longer jumps 15 px up).
  • #606 → dailyuse. There the main card was already placed on its own, so there is no per-frame bounce. Two other faults remained. Moving diagonally into a submenu closed it, because the rows crossed on the way hovered and closed it. And a submenu with no room on either side was shifted over its own row.

Both PRs:

  • decide placement at open (and on window resize);
  • place submenus as Base UI does: right, else left, top- else bottom-aligned with the row, else under or above the row, shifted only along the row's edge so the submenu never covers its row;
  • add a safe triangle (floating-ui safePolygon), so the submenu stays open on the way in and still closes when the cursor leaves that path.

The tests are in tests/menu_placement.rs: every menu kind at each corner and edge of 640×480 and 900×600, the cursor resting on each submenu row for 8 frames, then moving into the submenu.

Menus still can't leave the window. iced overlays live in the window surface, and Wayland gives no way to position a popup window, so the fix is stable in-window placement, like the web client.

Not covered yet: menus taller than the window don't scroll (the web client caps them at 100vh - 1.5rem), and the safe triangle has no timeout.

🤖 Generated with Claude Code

Reproduced and fixed in two PRs, one per branch, because the shared widget has diverged: - **#608 → `textchat`** (the nightly where the bounce happens). `Anchored` placed the main card and the open submenu as **one block** and moved that block back inside the window. A submenu that ran past the bottom or right edge moved the main card too. iced's `mouse_area` re-checks hover whenever its bounds change, so the next frame another row was under the cursor, it closed or switched the submenu, the block moved back, and this repeated every frame. A headless test catches it: `[None, Some(5), Some(6), Some(5), Some(6), …]`. Now each card is placed on its own and the main card never moves when a submenu opens or closes. The `control_bar_sharing` golden changed for that reason (the stream menu no longer jumps 15 px up). - **#606 → `dailyuse`**. There the main card was already placed on its own, so there is no per-frame bounce. Two other faults remained. Moving diagonally into a submenu closed it, because the rows crossed on the way hovered and closed it. And a submenu with no room on either side was shifted over its own row. Both PRs: - decide placement at open (and on window resize); - place submenus as Base UI does: right, else left, top- else bottom-aligned with the row, else under or above the row, shifted only along the row's edge so the submenu never covers its row; - add a safe triangle (floating-ui `safePolygon`), so the submenu stays open on the way in and still closes when the cursor leaves that path. The tests are in `tests/menu_placement.rs`: every menu kind at each corner and edge of 640×480 and 900×600, the cursor resting on each submenu row for 8 frames, then moving into the submenu. Menus still can't leave the window. iced overlays live in the window surface, and Wayland gives no way to position a popup window, so the fix is stable in-window placement, like the web client. Not covered yet: menus taller than the window don't scroll (the web client caps them at `100vh - 1.5rem`), and the safe triangle has no timeout. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
charles/fluxer-native#594
No description provided.