Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix current monitor detection using active window #363

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xiamaz
Copy link

@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
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
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
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
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
2 participants