Custom sizing after content scale change


#1

Hello,

I want my app to scale in a specific way and I would like to ask for an advice whether this is possible with GLFW and how I could achieve this.

Requirements:

  • framebuffer maps 1:1 to screen pixels at all times
  • the window is resizable
  • framebuffer size should double when moving from monitor with scale < 2 to scale >= 2
  • framebuffer size should become half when moving from monitor with scale >= 2 to scale < 2
  • framebuffer size should not change when both monitors have content scale < 2 or both >= 2

Example:

  • I want to open a window with framebuffer size 300x200 @ 1x.
  • The window opens on a monitor with scale 2.0 and the framebuffer is 600x400.
  • I move the window to a monitor with scale 1.75 and the framebuffer resizes to 300x200.
  • I move the window to a monitor with scale 1.25, framebuffer stays 300x200.
  • I resize the window using the mouse, the new framebuffer size is 350x250.
  • I move the window back to the monitor with scale 2.0 and the framebuffer changes to 700x500.

I am not sure how to do this, because on some platforms the framebuffer size callback comes before the content scale callback, and I can’t tell whether the framebuffer size callback was triggered by the user resizing the window, or by monitor change.

Thanks for any advice and ideas,
Jakub


#2

Have you tried calling glfwGetMonitorContentScale (available on Github/master branch) to get the scale of the monitor the window is on after a move / resize / scale callback?

To determine which monitor the window is on you can use the monitor virtual coordinates and window position (although it may be overlapping multiple monitors).