lv2 / pugl

A minimal portable API for embeddable GUIs
https://gitlab.com/lv2/pugl/
ISC License
181 stars 35 forks source link

Inconsistent initial position between OSes #85

Closed falkTX closed 1 year ago

falkTX commented 2 years ago

I received some user reports of weird behaviour with builds using updated pugl, where the embed view is being offset by half its size.

Example: image

After investigation I found that it is related to me no longer setting a size before realizing the view (I am only setting hints, including default). This makes the initial width and height still be at zero during realize. Issue appears only on Windows and macOS, not on Linux. Checking pugl code it is easy to see why.

This is on X11:

  if (!view->parent && !view->frame.x && !view->frame.y) {
...
    view->frame.x = (PuglCoord)((screenWidth - view->frame.width) / 2);
    view->frame.y = (PuglCoord)((screenHeight - view->frame.height) / 2);
  }

for macOS:

  if (view->frame.width == 0.0 && view->frame.height == 0.0) {
...
    view->frame.x = (PuglCoord)((screenWidthPx - view->frame.width) / 2.0);
    view->frame.y = (PuglCoord)((screenHeightPx - view->frame.height) / 2.0);
  }

and finally for windows:

  if (view->frame.width <= 0.0 && view->frame.height <= 0.0) {
...
    view->frame.x = (PuglCoord)((screenWidth - view->frame.width) / 2);
    view->frame.y = (PuglCoord)((screenHeight - view->frame.height) / 2);
  }

X11 is the only platform for which pugl checks if there is a parent. This is what triggers the issue, pugl is setting a custom offset for embed views, where no such thing should be used.

As extra oddity, note how all the 3 platforms check for non-zero differently.

drobilla commented 1 year ago

Probably fixed in abe98d5, thanks.