How to launch xev from console?

5,658

Solution 1

All¹ X11 programs open their windows on the display indicated by the environment variable DISPLAY. Thus:

sudo -u 1000 env DISPLAY=:0 xev

or for that matter, since you can run programs as a different user from the X server, just

DISPLAY=:0 xev

:NUMBER is the notation for local displays; in most scenarios, the X11 server that is running on the console is the one that's started first and ends up being number 0. You can run echo "$DISPLAY" in a terminal on that display to check whether the display number is correct. :0.0 is equivalent to :0 (a trailing .0 can be omitted).

If you run the program as a different user from the X server, and sometimes even if you run it as the same user, you may need to set the XAUTHORITY environment variable as well. This variable points to a file that contains a password (called a cookie) that applications must pass to the X server. To see the right value from XAUTHORITY, run echo $XAUTHORITY on that display; if it's unset, the default value is ~/.Xauthority where ~ represents the user's home directory.

If you need to find the values of DISPLAY and XAUTHORITY programmatically, see Open a window on a remote X display (why "Cannot open display")?

¹ At least almost all. It's technically possible for them not to, but it takes active work on the part of the programmer to make it not so, whereas a -display argument is a convention that is far from universal.

Solution 2

You should try:

xev --display localhost:0.0

assuming that X is actually running.

Share:
5,658

Related videos on Youtube

Cestarian
Author by

Cestarian

Updated on September 18, 2022

Comments

  • Cestarian
    Cestarian almost 2 years

    I am trying to launch Xev from console, it always gives "unable to open display", I need to launch xev from a console as another user (I use sudo -u '#1000' to do this).

    I know xev has a "display" argument (xev -display) but I just can't figure out how to use it.

    How do I launch xev from the console from outside of my X11 environment?

    • Admin
      Admin over 9 years
      For all X11 programs there is an environment variable DISPLAY. For Display 0 you can do DISPLAY=:0 xev. Now you will get an error about security X11 has security to stop you doing this. You need to look into xauth. Note xhost + is dangerous.
  • Cestarian
    Cestarian over 9 years
    This did not work for me.
  • Anthon
    Anthon over 9 years
    @Cestarian Have you checked that X is actually running?
  • Cestarian
    Cestarian over 9 years
    Yes of course, it's running on tty 1.
  • Anthon
    Anthon over 9 years
    @Cestarian Maybe you can include some more information in your question, like how started X and other things that might seem relevant. As the other user did you run xhost + to actually allow access to the X server?
  • Cestarian
    Cestarian over 9 years
    I started X with the startx command. I did not even have xhost installed. Naturally I am not familiar with how to operate it either.
  • Cestarian
    Cestarian over 9 years
    Thanks for your detailed answer! This worked perfectly :)