fix: open popup on the same display as the source window in multi-monitor setups#410
Draft
Copilot wants to merge 2 commits into
Draft
fix: open popup on the same display as the source window in multi-monitor setups#410Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
In a multi-display environment, getScreenSize() was calling chrome.windows.getCurrent() from the service worker context to determine which display to use for bounds-checking. This could return a window on the primary/main display rather than the display where the user was actually working, causing adjustWindowPosition() to reposition the popup to the main display. Fix: add an optional `hint` parameter to getScreenSize(). When a hint (top, left) is provided, use those coordinates directly to find the correct display. Callers openPopupWindow() and openPopupWindowMultiple() now pass the popup target coordinates as the hint, so the display where the user is working is always correctly identified. Add screen.test.ts with 6 tests covering single/multi-display scenarios. Agent-Logs-Url: https://github.com/ujiro99/selection-command/sessions/c383e197-1956-435f-902e-69f98e6282bf Co-authored-by: ujiro99 <677231+ujiro99@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix popup window opening on main display in multi-display setup
fix: open popup on the same display as the source window in multi-monitor setups
May 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In multi-display environments, popup windows were always opening on the primary display instead of the display containing the source window.
Root Cause
getScreenSize()in the service worker context callschrome.windows.getCurrent()to determine which display to use for bounds-checking. From a service worker,getCurrent()unreliably returns the last-focused window — often one on the primary display — rather than the window the user was actually interacting with. This causedadjustWindowPosition()to recalculate the popup position using the wrong display's bounds, snapping it to the primary monitor.Changes
screen.ts: Add optionalhint?: { top: number; left: number }togetScreenSize(). When provided, the hint coordinates are used to identify the target display directly, bypassinggetCurrent(). Falls back to existinggetCurrent()behavior when no hint is given.chrome.ts: Pass the popup's target{ top, left }coordinates as the hint when callinggetScreenSize()in bothopenPopupWindowandopenPopupWindowMultiple. These coordinates already originate from the content script's correct window position, so they reliably identify the right display.screen.test.ts(new): Tests covering single/multi-display hint resolution, fallback to primary when hint is out-of-bounds, and non-service-worker path.