Skip to content

fix: open popup on the same display as the source window in multi-monitor setups#410

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-popup-window-display-issue
Draft

fix: open popup on the same display as the source window in multi-monitor setups#410
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-popup-window-display-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 26, 2026

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 calls chrome.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 caused adjustWindowPosition() to recalculate the popup position using the wrong display's bounds, snapping it to the primary monitor.

Changes

  • screen.ts: Add optional hint?: { top: number; left: number } to getScreenSize(). When provided, the hint coordinates are used to identify the target display directly, bypassing getCurrent(). Falls back to existing getCurrent() behavior when no hint is given.

  • chrome.ts: Pass the popup's target { top, left } coordinates as the hint when calling getScreenSize() in both openPopupWindow and openPopupWindowMultiple. These coordinates already originate from the content script's correct window position, so they reliably identify the right display.

// Before
const screenSize = await getScreenSize()

// After — use popup target coordinates to find the correct display
const screenSize = await getScreenSize({ top, left })
  • 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.

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
Copilot AI requested a review from ujiro99 May 26, 2026 04:08
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