The Expectation
Here's a simple function to calculate the distance of the active window from the top of the active monitor (i.e. the one that it's on)...
async function getNumber(varName) {
return await get_number_variable({
variable_name: varName
});
}
async function distanceFromTop() {
let focused_screen_y = await getNumber("focused_screen_y")
let focused_window_y = await getNumber("focused_window_y")
return `${focused_screen_y}, ${focused_window_y}, ${focused_window_y - focused_screen_y}`
}
Pretty straight forward. It just gets the y
values for both the active window and active screen, then subtracts one from the other.
The Problem
First, here's my current screen layout. Note that the 'primary' display is on the left, not the middle display, and that it's higher than the primary display too.
Now if the active app is on the primary monitor (on the left) or on the right monitor (which is exactly aligned to it to the pixel), as expected, I get 0, 25, 25
for both, with the delta of 25 representing the height of the menu bar.
However, when the app is on the middle monitor, I unexpectedly get -346, -349, -3
which is clearly wrong! While it is expected both y
values would be negative since the display is higher than the primary one, the delta definitely shouldn't be negative as that would mean the window would be off the top of the screen!
Retina vs Native Resolutions
As an experiment, I switched my monitor from 'full 4k res' to 'retina' making it appear as a 1920x1080 screen which resulted in the following layout.
Again, note the middle display is still higher than the 'primary' one so again, it's y
value should be negative. But when I tried it with that resolution, I now get even wilder numbers... 734, -349, -1083
! Again, the window is right up against the top edge. I even moved it down a little, and now got 734, -336, -1070
(13 px lower) so it is picking up that it moved. I just have no idea what it's relative to being that the delta is now wildly over negative 1000!
Not sure how to work around this so I'll have to abandon my scripting efforts for now until there's either a fix, or if this is a 'me' error, you can help me figure out what I'm doing incorrectly.