Obtaining List of all Xorg Displays
I would like to know how I can obtain a list of all Xorg displays on my system, along with a list of screens associated with each display. I spent some time looking through the Xlib documentation, but was not able to find a function that does what I want. Please assume that I have no other dependencies other than a POSIX-complaint OS and X (e.g., no GTK). If what I ask is not possible assuming these minimal dependencies, then a solution using other libraries is fine.
Thank you very much for your help!
2 Answers 2
The only way I know of to get a list of displays is to check the /tmp/.X11-unix directory.
Once you do that, you can use Xlib to query each display for more information.
Running the above gives me this output with my current displays/screens:
Never found a better way of listing X displays other than that. I’d very much like to know if any better alternative exists.
Like netcoder wrote, the problem has two distinct parts:
Connection to the X server
The process establishes a connection to an X server using XOpenDisplay() . The connection is torn down using XCloseDisplay() . netcoders code in this thread is a good example of how to do it correctly.
As netcoder mentioned, the problem is that there is no reliable way find out which X servers a process can connect to. His code checks the typical location where the X sockets are, /tmp/.X11-unix/ . That approach does not work at all if the user is remotely connected, for example via SSH (with X forwarding enabled). In that case there is really only the DISPLAY environment variable (and perhaps some trickery wrt.
Unfortunately, I do not know of any better method either. I personally prefer to use a per-user configuration file — say
/.application/displays —, where the user can list the server names the application should try to connect in the same format as the DISPLAY environment variable, in addition to the default one. It is not automatic (netcoder’s code is), but this approach suits me better.
Finding out about the screens provided by an X server
XScreenCount() will return the number of screens provided by the X server the process is currently connected to. If you only need the screen dimensions, follow netcoders example. For more detailed information, use XScreenOfDisplay(Display,index) to obtain the Screen pointers; 0 index XScreenCount(Display) .
In C code, the macros ScreenCount() and ScreenOfDisplay() are usually a bit more efficient than the actual function calls.
Источник
Is there a command to list all open displays on a machine?
When SSH’d locally into my computer (don’t ask, it’s a workaround), I can’t start graphical applications without running:
If I run this first and then run a graphical application, things work out. If not, it doesn’t work, there’s no display to attach to.
Is there a command for listing all available displays (ie: all possible values) on a machine?
5 Answers 5
If you want the X connection forwarded over SSH, you need to enable it on both the server side and the client side. (Depending on the distribution, it may be enabled or disabled by default.) On the server side, make sure that you have X11Forwarding yes in /etc/sshd_config (or /etc/ssh/sshd_config or wherever the configuration file is). On the client side, pass the -X option to the ssh command, or put ForwardX11 in your
If you run ssh -X localhost , you should see that $DISPLAY is (probably) localhost:10.0 . Contrast with :0.0 , which is the value when you’re not connected over SSH. (The .0 part may be omitted; it’s a screen number, but multiple screens are rarely used.) There are two forms of X displays that you’re likely to ever encounter:
- Local displays, with nothing before the : .
- TCP displays, with a hostname before the : .
With ssh -X localhost , you can access the X server through both displays, but the applications will use a different method: :NUMBER accesses the server via local sockets and shared memory, whereas HOSTNAME:NUMBER accesses the server over TCP, which is slower and disables some extensions.
Note that you need a form of authorization to access an X server, called a cookie and normally stored behind the scenes in the file
/.Xauthority . If you’re using ssh to access a different user account, or if your distribution puts the cookies in a different file, you may find that DISPLAY=:0 doesn’t work within the SSH session (but ssh -X will, if it’s enabled in the server; you never need to mess with XAUTHORITY when doing ssh -X ). If that’s a problem, you need to set the XAUTHORITY environment variable or obtain the other user’s cookies.
To answer your actual question:
Local displays correspond to a socket in /tmp/.X11-unix .
Remote displays correspond to open TCP ports above 6000; accessing display number N on machine M is done by connecting to TCP port 6000+N on machine M. From machine M itself:
(The rest of this bullet point is of academic interest only.)
From another machine, you can use nmap -p 6000-6099 host_name to probe open TCP ports in the usual range. It’s rare nowadays to have X servers listening on a TCP socket, especially outside the loopback interface.
Strictly speaking, another application could be using a port in the range usually used by X servers. You can tell whether an X server is listening by checking which program has the port open.
If that shows something ambiguous like sshd , there’s no way to know for sure whether it’s an X server or a coincidence.
Источник
Get list of screen in display
I understand that a screen is identified by :D.S where:
- D is the display number
- S is the screen number
I’m looking to list all screens associated with a display.
I can get all the current displays with something like cd /tmp/.X11-unix && for x in X*; do echo «:$
Also, I’m looking to get the display and screen number associated with a screen name. For example, with xrandr -q returning :
Is there a way to get the X identifier for HDMI1 , something like :0.0 ?
Thanks for any lead you might provide!
2 Answers 2
I’m looking to list all screens associated with a display.
Also, I’m looking to get the display and screen number associated with a screen name. For example, with xrandr -q returning :
They’re not associated. All of the outputs shown by xrandr are parts of the same display and screen.
But if your x11 server («display») is configured with more than one screen («screen» being here the abstraction used by x11, not a physical monitor or such), you can select which one xrandr will show info about with xrandr —screen snum , or with —display :dnum.snum . If those options are not used, xrandr will only display info about the first screen configured, not about all of them.
Notice that x11 can (and will, by default) handle multiple monitors as parts of the same «screen», provided that they have the same depth.
The screens mentioned with :D.S are associated with an obsolete style of multi-screen X11 displays, in which each application was «trapped» on the screen it was started on, unless it had special facilities to switch from one screen to another.
Think about an early professional CAD workstation with CRT displays: it might have had one «main» display with a very limited number of colors but high refresh rate (to minimize eyestrain) for working with the design, and another display with a lower refresh rate but better color capabilities, dedicated to viewing the resulting design rendered in full color.
Today, the standard approach is to join all the physical screens into one large unified display surface, so that you can move windows freely between the screens. As a result, the screen number in the :D.S pair is practically always 0. To manage these kinds of setups, a new X11 protocol extension, X Rotate and Resize, or XRandR for short, was developed.
There is another extension called XINERAMA for reporting this multi-display layout to applications, so that they can, for example, display a dialog box in the middle of a physical screen and not half in one physical screen and half in another in a two-screen configuration.
Источник
How do I list connected displays using the command line?
Is there a command that will list displays connected to the computer?
Specifically, I’m looking to find out how my external monitor is being detected by the system when connected by HDMI cable and what it’s (not sure of the correct term here) hardware address is (eg. «CRT-0» or «DFP-1»).
This is just a general question, but for reference, I’m using:
- Asus UL30JT laptop — running Ubuntu 12.04 beta and 11.10
- Asus PA238 23″ monitor
- HDMI 1.4 cable
- Optimus graphics (Intel + nVidia GeForce 310M) — running with Bumblebee
2 Answers 2
This lists the display names and detected available resolutions. You can also reconfigure your displays using xrandr.
Note that this might not work if you’re using the NVidia or ATI drivers; I’m not sure.
For most machines with the proprietary driver loaded, /usr/lib/nvidia-current/bin/nvidia-xconfig —query-gpu-info —nvidia-cfg-path=/usr/lib/nvidia-current works. Note that I said «with the proprietary driver loaded». For instance, it does not work if the driver is unloaded or nouveau is loaded. Therefore, when using Bumblebee, run optirun /usr/lib/nvidia-current/bin/nvidia-xconfig —query-gpu-info . The —nvidia-cfg-path part is not needed here as optirun sets the correct library path.
/var/log/Xorg.0.log (where 0 is the display number) may also contain valuable information about available screens. For Optimus laptops, this log contains only details on the Intel screen, so replace 0 by 8 to find out the log from the X server started by Bumblebee.
Источник
How to get the display number I was assigned by X
From X(7) man pages
How can I find the display number I have been assigned?
Or list currently open displays and their users?
5 Answers 5
If you know of one process ID running in the user’s session, and you have permission to access that process’ information, you can grep its environment for the DISPLAY variable:
As an example, to list all the main displays used by your UID on the current computer, use:
If you are only logged in to one X session, the above should output only one line with something like DISPLAY=:0 .
In the X session, you can always consult the DISPLAY environment variable to get you current display number ( echo $DISPLAY ).
Finding out others’ display numbers is tougher. I don’t think there is any standard way of getting the information other than asking all the users which display they are connected to, so any attempt to gain this information requires some sort of hackery and will not work for all cases.
There are some options given elsewhere in SE but they won’t work on Debian Wheezy, for instance. However, listing the displays currently active is easy, as shown in the post I linked above:
ps axu | grep «X » will show you the X processes that are currently running, something like the following:
The first parameter after /usr/bin/X is the display number prefixed by colon, and the next one shows you the virtual terminal assigned to the session.
You might get you answer from looking at the process list, though:
ps axu |grep -3 «X «
Look at the lines after /usr/bin/X — as the X session starts, a window manager is typically started as the user the session belongs to, and there you get the username. In my case user_1 is using KDE and user_2 is using LXDE. However, this solution relies purely on the fact that the kernel happens to be assigning new process IDs in ascending sequence, which might not be the case always.
Источник