Search code examples
linuxwindowx11xlibxorg

x11/xlib XCreateSimpleWindow over multiple X servers


I'm trying to follow this tutorial for programming with xlib http://tronche.com/gui/x/xlib/

this is the code i've written so far

  display = XOpenDisplay(NULL);
  screen  = XDefaultScreen(display);
  width   = 640;
  height  = 480;

  XLockDisplay(display);
  fullscreen = 0;
  window[0] = XCreateSimpleWindow(display, XDefaultRootWindow(display),
                                  0, 0, width, height, 0, 0, 0);
  window[1] = XCreateSimpleWindow(display, XDefaultRootWindow(display),
                                  0, 0, width, height, 0, 0, 0);

however i don't understand this: on a system with two X11 servers (two gpus) without xinerama, if i want that window[0] goes to the first xserver and the second xserver, what functions should i call? I think i'm confused about display, screen, window....

thanks for any help


Solution

  • If they are indeed two different X servers (see Havoc's explanation for that), then you would need to do something like:

    Display displays[2];
    
    displays[0] = XOpenDisplay(":0.0");
    displays[1] = XOpenDisplay(":1.0");
    
    [...]
    
    window[0] = XCreateSimpleWindow(displays[0], XDefaultRootWindow(displays[0]),
                                    0, 0, width, height, 0, 0, 0);
    window[1] = XCreateSimpleWindow(displays[1], XDefaultRootWindow(displays[1]),
                                    0, 0, width, height, 0, 0, 0);
    

    If they're different X screens on the same X server, then the displays would be :0.0 and :0.1 instead. (And that's all assuming the simplest case of just those X servers, without additional X servers on other VT's or virtual X servers like Xvfb, Xnest, or Xephyr.)

    Of course, any serious GUI programming would be done with a toolkit such as GTK+ or Qt, not raw Xlib calls.