Skip to content

glfwCreateWindow() and glfwSetWindowPos() completely broken on multi-display setups: position and dimensions of window utterly unpredictable #2770

@php4fan

Description

@php4fan

To reproduce:

  1. On Manjaro Linux with KDE and X11 (or Wayland, using glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_X11) as below), connect an external monitor to a laptop, or anyway have two monitors in total. Set up the Display Configuration so that the monitor on the left is the primary one; make sure they both have a resolution of 1920 x 1080 (I guess you can reproduce with any resolution, adapting the numbers used in the example, but given how utterly random the issue is, who knows);
  2. Compile the example/gears.c example after applying this patch:
diff --git a/examples/gears.c b/examples/gears.c
index 3d63013d..ee2eab6c 100644
--- a/examples/gears.c
+++ b/examples/gears.c
@@ -307,6 +307,8 @@ int main(int argc, char *argv[])
     GLFWwindow* window;
     int width, height;
 
+    glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_X11);
+    
     if( !glfwInit() )
     {
         fprintf( stderr, "Failed to initialize GLFW\n" );
@@ -315,14 +317,16 @@ int main(int argc, char *argv[])
 
     glfwWindowHint(GLFW_DEPTH_BITS, 16);
     glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE);
+    glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
 
-    window = glfwCreateWindow( 300, 300, "Gears", NULL, NULL );
+    window = glfwCreateWindow( 1920, 1080, "Gearsz", NULL, NULL ); /////////////////////// NOTE THIS
     if (!window)
     {
         fprintf( stderr, "Failed to open GLFW window\n" );
         glfwTerminate();
         exit( EXIT_FAILURE );
     }
+    glfwSetWindowPos(window, 1920, 0); ///////////////////////////////////////// AND THIS
 
     // Set callback functions
     glfwSetFramebufferSizeCallback(window, reshape);
  1. Run it
  2. Now change the glfwCreateWindow() line to this:
    window = glfwCreateWindow( 1919, 1080, "Gearsz", NULL, NULL );
  1. run again

Expected Behavior

Both version should behave almost identically. They should create the window, borderless, entirely in the second monitor, starting at (0,0) of the second monitor.
The first version should fill the screen completely and exactly both in width and in height.
The second version should fill the height completely, and leave an empty 1-pixel-wide column on the right

Observed Behavior

The first version creates the window entirely on the first screen instead of the second, as if glfwSetWindowPos() had been completely ignored.

The second version creates the window on the second screen as expected, and with the expected width, but either the height is less than expected, or the window is displaced upwards of approximately 44 pixels (I can't tell which one it is), leaving an empty space approximately 44px high at the bottom.

This makes it impossible to accurately control the position and dimensions of the window, which is a disastrous, crippling issue.

I originally found this issue in a real-life application that uses glfw, namely Gem, the graphics framework for Pure Data:
umlaeute/Gem#508

The issue there is identical to this one that I've been able to reproduce on the "gears" example.

I would very much appreciate if anyone can suggest a workaround, as this bug completely destroys the application I'm using rendering it completely unusable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    X11bugBug reports and bugfix pull requests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions