Wrong monitor opened if dual screen setup (Linux)


i encounter a strange behavior if i want to open a full-screen window at my second monitor in a dual screen setup. Monitors are recognized correctly at first, but finally the wrong one shows up.
I’m on Linux, Python 3.6.10, pyopengl 3.1.5, glfw 3.3.2, pyglfw 1.11.0 - but i confirmed with pure c, see attached example (c code is not allowed as upload, so inline).

output is:

$ ~/bin/glfw_2screen_minimaldemo 
found 2 monitors
should use monitor 1 with size 1920x1200
have window of size 1600x900
have frame  of size 1600x900

Thanks and all the best,

# example to demonstrate that 2nd screen is not used as intended
# behaviour: screen_0 shows fullscreen black for entire 5 secs
#            screen_1 does not change
# expected:  screen_0 should stay as is with desktop and console
#            screen_1 should show fullscreen black for entire 5 sec; then desktop again
# printed output shows, that second monitor is recognized.
#         but not used at all.
# meanwhile:
# $ xrandr -q | grep '*'
#    1600x900      60.01*+  59.99    59.94    59.95    59.82    40.00  
#    1920x1200     59.95*+

#include <GLFW/glfw3.h> 
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

int main( void ){
  // Initialize the library
  if (!glfwInit()) {
    printf("init failed");

  int count;
  GLFWmonitor** monitors = glfwGetMonitors(&count);             // list available monitors: ok
  printf("found %d monitors\n", count);
  int m;
  int msel = 1;    // chose 2nd monitor
  int mw, mh;      // its width and height
  for (m=0; m<count; m++) {
    const GLFWvidmode* mode = glfwGetVideoMode( monitors[m] );  // show modes of each monitor: ok
    printf( "%dx%d\n", mode->width, mode->height );
    if(m==msel) {
      mw = mode->width;
      mh = mode->height;
  GLFWwindow* window = glfwCreateWindow(mw, mh, "none", monitors[msel], NULL);  // become active
  if (!window) {                                                                // ok
    // Window or OpenGL context creation failed
    printf("create window failed");
  printf("should use monitor %d with size %dx%d\n", msel, mw, mh );             // requested values
  glfwGetWindowSize(window, &mw, &mh);                                          // != used values
  printf("have window of size %dx%d\n", mw, mh );
  glfwGetFramebufferSize(window, &mw, &mh);
  printf("have frame  of size %dx%d\n", mw, mh);
  sleep(5);         // wait log enough to be sure we do not alter something with heavy latency

  glfwDestroyWindow(window);                                                    // end nicely

I don’t have a linux setup with multiple monitors at the moment, so have left this for others to reply to, but in the meantime it might be worth filing this as a GLFW issue.

I did find one Linux issue related to monitor problems: glfwSetWindowMonitor doesn’t seem to work for some video modes, though this isn’t the same problem so it would be worth opening a new issue. If you don’t have Github access let me know and I can file an issue for you.

hi dougbinks,
thanks for the suggestion; I opened an issue: https://github.com/glfw/glfw/issues/1659