Earnestly / sx

Start an xorg server
MIT License
231 stars 16 forks source link

Error: Can't open display: :0 #10

Closed mustaqimM closed 4 years ago

mustaqimM commented 4 years ago

I get this is terminal emacs when trying to copy something. I think the error comes from xclip. I'm starting sx from .profile:

#!/bin/sh
# .profile

if test -z "${XDG_RUNTIME_DIR}"; then
    XDG_RUNTIME_DIR=/tmp/"$(id -u)"-runtime-dir
    export XDG_RUNTIME_DIR
    if ! test -d "${XDG_RUNTIME_DIR}"; then
        mkdir "${XDG_RUNTIME_DIR}"
        chmod 0700 "${XDG_RUNTIME_DIR}"
    fi
fi

if [ -f ~/.bashrc ]; then . .bashrc; fi

if [ ! "$DISPLAY" ]; then
  sx sh ~/.xinitrc 2> .xsession-errors
  #startx 2> .xsession-errors
fi
#!/bin/sh

if [ -d /etc/X11/xinit ] ; then
  for f in /etc/X11/xinit/* ; do
    [ -x "$f" ] && . "$f"
    done
  unset f
fi

awesome
xrdb -merge ~/.Xresources
Earnestly commented 4 years ago

sx itself can't possibly set DISPLAY to :0 so somewhere this value has been hardcoded.

If you're using a system where the tty you log in on is actually returning tty0 from ps -o tty= -p $$ then check to see if the environment (both DISPLAY and XAUTHORITY) are being inherited correctly.

mustaqimM commented 4 years ago

I set in my .profile:

export XAUTHORITY=~/.local/share/sx/xauthority

And $DISPLAY shows as :1. I think I have to manually set certain applications to use :1 as they default to :0. This includes emacs, xclip(sometimes) and the racket interpreter

Earnestly commented 4 years ago

It would be very odd if they default DISPLAY to anything. If you find out where they do this, please share as I'd be interested to see this.

Also you need not export XAUTHORITY manually as sx does that unless you use software that needs to be aware of XAUTHORITY of which aren't started in an environment inherited from sx.

mustaqimM commented 4 years ago

Since I started using sx, I have to specify the display in emacs daemon mode like this:

/bin/emacs --display=void:1.0 --daemon --no-x-resources

And the racket repl exits with this error:

; On-demand, one-time instantiation of racket/gui/base.
Unable to init server: Could not connect: Connection refused
; Gtk initialization failed for display ":0"
; Context:
;  "/usr/share/racket/pkgs/gui-lib/mred/private/wx/gtk/queue.rkt":1:1 [running body]
;  "/usr/share/racket/pkgs/gui-lib/mred/private/wx/platform.rkt":1:1 [running body]

Process Racket REPL exited abnormally with code 1
Earnestly commented 4 years ago

Unfortunately I can't reproduce those issues with either emacs or racket.

Why are you specifying the hostname and screen number in the --display argument to emacs? I.e. why are you using void:1.0 instead of just :1? Perhaps knowing more about how you're using sx might be more helpful.

mustaqimM commented 4 years ago

I saw in the man pages that that's how you specify the display for emacs (I tried :1 and it's the same. I don't normally use the display flag, only because I was getting errors when starting with sx).

I linked above my .profile and .xinitrc. I run sx from the .profile like this: sx sh ~/.xinitrc 2> .xsession-errors. I don't do anything else then when running xinit

Earnestly commented 4 years ago

I can't see anything in your .profile or .xinitrc which would prevent sx from working as expected. I can't reproduce any of this when using awesome either.

Find out what environment the parent process of emacs as within it, specifically if DISPLAY is present. E.g.

# Changing awesome for whatever actually starts emacs
$ tr \\0 \\n < /proc/"$(pgrep -x awesome)"/environ | grep DISPLAY
DISPLAY=:2
mustaqimM commented 4 years ago

I get:

$❯  tr \\0 \\n < /proc/"$(pgrep -x awesome)"/environ | grep DISPLAY
DISPLAY=:1
Earnestly commented 4 years ago

If awesome is the parent of emacs then it should inherit it without issue. I think you'll have to investigate more thoroughly to find out where you're either overriding DISPLAY or unsetting it.

I can't think of any reason why Xlib software should be attempting to try :0 unless DISPLAY has been set to that value. I can't replicate any of your conditions either, even from empty environments.

Earnestly commented 4 years ago

Any updates on this @mustaqimM or can it be closed?

mustaqimM commented 4 years ago

@Earnestly I'm currently using it as is. I still don't know what's setting DISPLAY to :1 but it works fine.

(sorry for not responding earlier, I didn't see/get a notification)