Bug in Custom HTML KMWindow() Screen Position, I think

I hope this small example will illustrate my issue.

Consider this Custom HTML Prompt action:

Here's the source:

<!DOCTYPE html>
<html lang="en">
  <head>
    <script type="text/javascript">
      function KMWindow() {
        return "200, 35, 200, 200";
      }
    </script>
  </head>

  <body>
  </body>
</html>

When I run this, this is what I get:

Even though I specified a top position of 35, the window is actually positioned right below my OS/X menu bar, which is 22 pixels high. When I set it to 41, this is what I get:

So basically, KM is positioning the window incorrectly.

I started to notice this when I ran one of my prompts over and over again, testing something. This prompt saves its position like this, before it closes:

window.KeyboardMaestro.SetVariable(
    'mimWindowPosition',
    window.screenX + ',' + window.screenY);

...and it uses these values to position itself when it opens the next time. But as I ran it over and over again, it started creeping up my screen, and would eventually bump against the menu bar, and I started to notice something wrong.

FYI, I do not have a Retina display.

For this case, you are actually setting the location of the contents of the window (because HTML traditionally is interested in the stuff inside the window frame). So the coordinate is based on the top left corner of the contents of the window.

I guess you’re correct, but none of it makes any sense to me (and this is moving beyond KM but still…)

Inside the HTML Prompt, window.screenY returns the top of the browser window, but calling window.moveTo(window.screenX, window.screenY) sets the top of the browser window to window.screenY + 23.

So, that’s because window.moveTo() is based on the top of the contents of the window, right? Except that the difference between the top of the content window and the top of the browser window is 16, not 23.

However, the system menu bar is 23 pixels high (I said 22 before, but I was wrong). WTH? This would make perfect sense if this was a Windows machine, since the menu bar is included in each app’s window. But not on a Mac. I just don’t get it.

Anyway, whatever. I’ve got a workaround. In KMDidShowWindow(), I compare my saved window.screenY to the current window.screenY, and use window.moveBy() to make up the difference.

But I’d sure like to understand why something works the way it does. Sigh.

Thanks for your help.