1

My computer has only one display. Does it correspond to $DISPLAY :0?

Can an application run on an arbitrary display number, even if I don't see it?

$ DISPLAY=:40 firefox

Can a X server run on an arbitrary display number? Will the kernel implicitly create a virtual display?

$ xpra start :7

Thanks.

Tim
  • 101,790
  • See https://unix.stackexchange.com/questions/503870/what-is-the-relation-between-x-server-and-display. There's no need to mention the kernel – 炸鱼薯条德里克 Mar 12 '19 at 23:20
  • this question is a mess; fix at least the display specs :0, :40 (both starting with a colon). The kernel does not create any virtual display. You can create a virtual display with Xvfb :1337, then run firefox on it with DISPLAY=:1337 firefox. –  Mar 13 '19 at 00:56
  • @mosvy Thanks. Is a display exactly a socket (and a screen id)? What does "a virtual display " mean? – Tim Mar 13 '19 at 01:23
  • 1
    No, the same Xserver (aka display) can listen on multiple sockets (by default on linux it's listening on two unix sockets, one file-based and another one abstract; -listen tcp will let it also listen on a tcp socket). Also, a xserver/display can have multiple "screens", though nowadays multiple monitors are managed as part of a single "screen". An xserver can use a hardware framebuffer, a dummy framebuffer (Xvfb) or a window on another xserver (Xephyr). The latter two are examples of "virtual" xserver/displays. –  Mar 13 '19 at 01:34
  • 2
    Do not confuse the actual display (your monitor(s)), the X11 server ("display"), and the way it's accessed via sockets or other means: DISPLAY=:0 and DISPLAY=localhost:10 as forwarded via ssh refer to the same display/xserver, the same video card, and the same monitor. –  Mar 13 '19 at 01:39
  • @mosvy Thanks. (1) "by default on linux it's listening on two unix sockets, one file-based and another one abstract;" Do you mean an unbound unix socket by "abstract"? What purposes does X server use the two sockets for respectively? – Tim Mar 14 '19 at 23:58
  • @mosvy. (2) "Do not confuse the actual display (your monitor(s)), the X11 server ("display"), and the way it's accessed via sockets or other means: DISPLAY=:0 and DISPLAY=localhost:10 as forwarded via ssh refer to the same display/xserver, the same video card, and the same monitor." I am still confused actually. Does $DISPLAY specify both a listening socket and a rendering target at the same time? – Tim Mar 15 '19 at 00:01
  • An abstract unix socket is a socket which is bound to a simple byte sequence instead of a file system object. It's something that only exists on Linux, but on Linux it's the default for an X11 client to first try to connect to an abstract unix adresss, and then to a path. –  Mar 15 '19 at 11:22
  • (2) No, $DISPLAY does not specify a "rendering target". And no need to harp about what "rendering target" means -- XrandR is able to let a root window (screen) span multiple monitors rendered to through multiple GPUs. The "screen" part of the display spec (the second number of the $DISPLAY) will determine what the DefaultScreen() and DefaultRootWindow() X11 library functions will return. Unless you're using an Xserver configured with multiple old-style screens (with multiple root windows), that number should be omitted or 0. –  Mar 15 '19 at 12:57
  • And nowadays there's 0 reason to configure an Xserver with multiple screens/root-windows, unless there's some hardware incompatibility (eg. multiple video cards with different depths). In the case of modern X11 server, where the same root window can be rendered through multiple GPUs on multiple monitors, an application window can be rendered on multiple "rendering targets" at the same time, or you can simply grab it with the mouse and move it from one "rendering target" to another. –  Mar 15 '19 at 13:06

1 Answers1

5

You can specify an arbitrary display, but you won’t get far if there’s no corresponding X server. The display number is specified when the X server is started, by whatever starts the X server — typically your display manager, or yourself in your Xpra example. It’s :0 by default (see the Xserver manpage). It can be chosen arbitrarily, but the X server won’t start if the corresponding resources aren’t available (port 6000 + the display number if it’s configured to listen on TCP, /tmp/.X11-unix/X followed by the display number if it’s configured to listen on a Unix domain socket, etc.). The kernel isn’t involved.

Stephen Kitt
  • 434,908
  • Thanks. "the corresponding resources aren’t available (port 6000 + the display number if it’s configured to listen on TCP)". Is the corresponding resources only TCP port? Is it by default configured to listen on TCP? – Tim Mar 12 '19 at 18:47
  • 1
    See my update. The defaults depend on your system; typically X listens on TCP and domain sockets, but many setups now disable TCP (with the -nolisten tcp option). – Stephen Kitt Mar 12 '19 at 19:09
  • Thanks. Does "staring a X server at display n" means exactly starting a X server which listens at a port 6000+n (Unix or TCP domain socket)? No more no less? – Tim Mar 12 '19 at 22:10
  • Notice that there's no port number for Unix domain sockets – 炸鱼薯条德里克 Mar 12 '19 at 23:21
  • 1
    @Tim a) the current X11 servers do not listen on tcp by default (you'll have to force them to with -listen tcp b) unix sockets have no ports. If you start an X11 server with Xorg :2000000000, it will create and listen on an unix socket in /tmp/.X11-unix/X2000000000 (and also on an abstract socket with the same name in Linux). The limit for a display number is MAX_INT when listening on a Unix socket, and 65535-6000=59535 when listening on tcp. –  Mar 13 '19 at 00:44
  • Stephen Kitt, does $DISPLAY specify a listening socket, a rendering target, or both? I am confused. https://unix.stackexchange.com/questions/505996/does-display-specify-both-a-listening-socket-and-a-rendering-target-at-the-sa – Tim Mar 14 '19 at 22:38
  • "It can be chosen arbitrarily, but the X server won’t start if the corresponding resources aren’t available" Does "resource" mean rendering target e.g. monitor? – Tim Mar 15 '19 at 00:32
  • DISPLAY only specifies a value for the XOpenDisplay() function; see this answer for details. The resources which need to be available are listed between parentheses just after the part you’ve quoted. – Stephen Kitt Mar 15 '19 at 11:34