Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is $DISPLAY sometimes :0 and sometimes :1

I'm using xmacro to record keyboard shortcuts, which requires a $DISPLAY to replay on. But, sometimes my $DISPLAY is :0 and sometimes :1, so every time that happens I have to change the value manually. Why does it keep changing, and is there a way to set the $DISPLAY value to either :0 or :1 permanently? (I can export DISPLAY=:0 in one terminal, but that doesn't change the value of $DISPLAY in new terminals.)

like image 647
Trong Truong Avatar asked Jan 18 '13 08:01

Trong Truong


People also ask

What does display 0.0 mean?

X" suffix will specify a specific screen/device. So, DISPLAY=:0 usually means "The GPUs in the system." DISPLAY=:0.0 means "The first configured screen/GPU" - I think it's actually screen, but with one screen configured per card, it's the same. DISPLAY=:0.1 means "The second configured screen/GPU."

What does Export display 0.0 do?

Explicitly setting DISPLAY=:0 is usually a way to access a machine's local display from outside the local session, such as over a remote access or from a cron job.

What is $display in Linux?

The DISPLAY variable is used by X11 to identify your display (and keyboard and mouse). Usually it'll be :0 on a desktop PC, referring to the primary monitor, etc. If you're using SSH with X forwarding ( ssh -X otherhost ), then it'll be set to something like localhost:10.0 .

What should I set display variable to?

If you use an X Window System shell window such as Xterm, you must set the DISPLAY environment variable to point to the IP address and screen number of the system you are using.


1 Answers

The number identifies the display ("a collection of monitors that share a keyboard and mouse")

:0 is usually the local display (i.e. the main display of the computer when you sit in front of it).

:1 is often used by services like SSH when you enable display forwarding and log into a remote computer.

It can also be modified by startup scripts which try to "fix" it. To find out whether this is happening, run

grep DISPLAY ~/.??*

.??* is a trick to get all dot files without .. and . (parent and current folder).

If that doesn't print anything, check /etc/profile, /etc/bash* and /etc/bash*/* in a similar manner.

I couldn't find a useful manual for xmacro but most X11 application support the option -d or -display to override $DISPLAY.

If this doesn't work, create xmacro.sh with this content:

 #!/bin/bash

 export DISPLAY=:0
 exec xmacro "$@"

Now invoke the tool with xmacro.sh and it should always work.

like image 159
Aaron Digulla Avatar answered Sep 28 '22 17:09

Aaron Digulla