Skip to content

Fix Bugs While Dragging Modals#129

Open
Lightning11wins wants to merge 2 commits into
masterfrom
fix-modal-dragging
Open

Fix Bugs While Dragging Modals#129
Lightning11wins wants to merge 2 commits into
masterfrom
fix-modal-dragging

Conversation

@Lightning11wins

Copy link
Copy Markdown
Contributor

This PR will fix bugs caused by the assumption that modal child widget will never be dragged. Modals with visible titlebars can be dragged, so this PR makes that experience much smoother.

@Lightning11wins Lightning11wins self-assigned this Jun 22, 2026
@Lightning11wins Lightning11wins added bug ai-review Request AI review for PRs. size: trivial Easy to review, probably ~100 lines or fewer. labels Jun 22, 2026
@greptile-apps

greptile-apps Bot commented Jun 22, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes two related bugs that caused broken UX when dragging a modal window by its titlebar: non-left-button clicks could accidentally start a drag, and the existing modal event guard blocked mousemove/mouseup from reaching the drag handler once the cursor left the modal bounds.

  • htdrv_window.js: Adds an e.which == 1 guard before setting wn_current in wn_mousedown, so only primary (left) button presses on the titlebar start a drag.
  • htdrv_page.js: Adds && !window.wn_current to the modal guard in both pg_mousemove and pg_mouseup, allowing move and release events to flow through the event pipeline while a drag is in progress. Because the "pg" event handlers are registered before the "wn" handlers, wn_current is still non-null when these checks fire, so the bypass is reliable.

Confidence Score: 5/5

The change is safe to merge; both modifications are narrow and well-targeted to the drag path.

Both changes are small, logically correct, and do not alter any code path unrelated to window dragging. The e.which == 1 guard in wn_mousedown eliminates unintended drag initiation on non-left-button clicks. The !wn_current bypass in pg_mousemove and pg_mouseup is safe because the pg handlers are registered and fire before the wn handlers, so wn_current is guaranteed non-null for the duration of an active drag when these checks execute.

No files require special attention.

Important Files Changed

Filename Overview
centrallix-os/sys/js/htdrv_page.js Adds !window.wn_current bypass to pg_mousemove and pg_mouseup so modal restrictions are skipped during an active window drag; event-handler registration order (pg before wn) ensures wn_current is still set when these checks run.
centrallix-os/sys/js/htdrv_window.js Adds e.which == 1 guard to wn_mousedown so only left-button clicks on the titlebar initiate a window drag; prevents right-click / middle-click from setting wn_current.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant User
    participant wn_mousedown
    participant pg_mousemove
    participant wn_mousemove
    participant pg_mouseup
    participant wn_mouseup

    User->>wn_mousedown: "left-click (e.which==1) on titlebar"
    wn_mousedown->>wn_mousedown: "set wn_current = mainlayer"
    note over wn_mousedown: NEW: e.which==1 gate prevents right/middle-click drag

    User->>pg_mousemove: mousemove (cursor outside modal)
    pg_mousemove->>pg_mousemove: pg_checkmodal() true (outside modal)
    pg_mousemove->>pg_mousemove: !wn_current false bypass halt
    note over pg_mousemove: NEW: skip EVENT_HALT when drag is active
    pg_mousemove-->>wn_mousemove: EVENT_CONTINUE
    wn_mousemove->>wn_mousemove: move window, return EVENT_HALT

    User->>pg_mouseup: mouseup (released outside modal)
    pg_mouseup->>pg_mouseup: pg_checkmodal() true
    pg_mouseup->>pg_mouseup: !wn_current false bypass halt
    note over pg_mouseup: NEW: skip EVENT_HALT when drag is active
    pg_mouseup-->>wn_mouseup: EVENT_CONTINUE
    wn_mouseup->>wn_mouseup: "finalize drag, wn_current = null"
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant User
    participant wn_mousedown
    participant pg_mousemove
    participant wn_mousemove
    participant pg_mouseup
    participant wn_mouseup

    User->>wn_mousedown: "left-click (e.which==1) on titlebar"
    wn_mousedown->>wn_mousedown: "set wn_current = mainlayer"
    note over wn_mousedown: NEW: e.which==1 gate prevents right/middle-click drag

    User->>pg_mousemove: mousemove (cursor outside modal)
    pg_mousemove->>pg_mousemove: pg_checkmodal() true (outside modal)
    pg_mousemove->>pg_mousemove: !wn_current false bypass halt
    note over pg_mousemove: NEW: skip EVENT_HALT when drag is active
    pg_mousemove-->>wn_mousemove: EVENT_CONTINUE
    wn_mousemove->>wn_mousemove: move window, return EVENT_HALT

    User->>pg_mouseup: mouseup (released outside modal)
    pg_mouseup->>pg_mouseup: pg_checkmodal() true
    pg_mouseup->>pg_mouseup: !wn_current false bypass halt
    note over pg_mouseup: NEW: skip EVENT_HALT when drag is active
    pg_mouseup-->>wn_mouseup: EVENT_CONTINUE
    wn_mouseup->>wn_mouseup: "finalize drag, wn_current = null"
Loading

Reviews (2): Last reviewed commit: "Fix edge cases from the previous bug fix..." | Re-trigger Greptile

Comment thread centrallix-os/sys/js/htdrv_page.js Outdated
@Lightning11wins

Copy link
Copy Markdown
Contributor Author

This PR is ready for human review.

@Lightning11wins Lightning11wins changed the title Fix Modal Dragging Fix Bugs When Dragging Modals Jun 22, 2026
@Lightning11wins Lightning11wins changed the title Fix Bugs When Dragging Modals Fix Bugs While Dragging Modals Jun 22, 2026
@Lightning11wins Lightning11wins removed the request for review from nboard June 22, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Request AI review for PRs. bug size: trivial Easy to review, probably ~100 lines or fewer.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant