Skip to content

Fix current monitor detection using active window#363

Open
xiamaz wants to merge 1 commit intonoctuid:masterfrom
xiamaz:master
Open

Fix current monitor detection using active window#363
xiamaz wants to merge 1 commit intonoctuid:masterfrom
xiamaz:master

Conversation

@xiamaz
Copy link
Copy Markdown

@xiamaz xiamaz commented Aug 18, 2022

Currently the detection uses the topleft corner of an application window to determine the active monitor. This is inaccurate, as a window corner might be outside a screen, which can be common in stacking window managers.

This fix implements proper intersection of the window area with the screen area to determine actual overlap. This should always ensure, that active window should return a screen. Fixes #362

@noctuid
Copy link
Copy Markdown
Owner

noctuid commented Sep 8, 2022

Would using the approximate current window center (rounded) as the current_x and current_y be good enough? I think that would be more readable/less code.

@xiamaz
Copy link
Copy Markdown
Author

xiamaz commented Sep 9, 2022

No that would not work if the window center is outside the display, which can be the case with floating windows.

@noctuid
Copy link
Copy Markdown
Owner

noctuid commented Sep 10, 2022

Having the majority of a window completely out of view is a bit bizarre, but it should still be handled correctly. I don't think this PR will handle all cases correctly either though. Example: two side-by-side monitors with an active window that is mostly on the right monitor (in terms of width), slightly on the left monitor (the problem), and whose middle is above the top of both monitors. Since it overlaps with both monitors you would have to either store the overlap amount or distance from the middle for each monitor and compare to determine which monitor the window is mostly on (instead of taking the first monitor there is any overlap with, which could be incorrect).

@xiamaz
Copy link
Copy Markdown
Author

xiamaz commented Sep 11, 2022

This is mostly about solving the edge case that if the active window coordinate is outside of any monitor, the terminal popup will not work.

Alternatively if no display is selected a fallback should exist. If you prefer this, I can change the implementation.

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.

Automatic detection of current monitor does not work if the window origin coordinates is outside the active screen

2 participants