tdrop icon indicating copy to clipboard operation
tdrop copied to clipboard

Fix current monitor detection using active window

Open xiamaz opened this issue 2 years ago • 4 comments

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

xiamaz avatar Aug 18 '22 21:08 xiamaz

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.

noctuid avatar Sep 08 '22 19:09 noctuid

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

xiamaz avatar Sep 09 '22 09:09 xiamaz

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).

noctuid avatar Sep 10 '22 01:09 noctuid

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.

xiamaz avatar Sep 11 '22 19:09 xiamaz