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, wi开发者_高级运维dth, 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
The nesting is as follows:
X server (also known as a display) is the thing you talk to with the X11 protocol. An XID (such as a window ID, GC ID, pixmap ID, etc.) will be unique within a display. Traditionally a display has one keyboard and one mouse, though it's more complex these days.
an X screen corresponds 1-to-1 with a Root Window. A root window is a window with no parent (root of the window tree). All non-root windows are children (or children of children, etc.) of the root window.
a window is a rectangular area within a screen. Windows are arranged in a hierarchical tree, where parent windows clip their children (child windows can be located entirely or partially outside the extents of the parent, but only the part inside the parent is visible). ("Rectangular" is a slight lie, you can really apply a shape mask, but forget it for now.)
a physical monitor may or may not correspond to a screen. TwinView and Xinerama are names for features that extend one screen across two or more monitors. Each monitor can be its own screen or can be a part of a multi-monitor screen.
Traditionally, windows cannot be moved to a different screen, because screens could have different hardware properties (such as different bit depths). With TwinView or Xinerama you can move windows around among monitors, with screen-per-monitor you can't. All screens on a display share the same input devices though (mouse and keyboard).
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.
Above the given answers, take a look on DMX (distributed multihead) which allows one to combine multiple X servers/screens into one large screen, served by a separate X server that dispatches the commands to its slave servers.
http://dmx.sourceforge.net/
精彩评论