X Server – How to Connect from System-Wide Terminal

guiopenboxraspbiantmuxx-server

I am currently trying to make an autonomous drone using the Robot Operating System (ROS). To do this, I have installed Raspbian Lite (Jessie) on a Rasperry Pi 3 and am currently using ROS Kinetic on it. Because it is Raspbian Lite, there were no window managers or desktop environments that came along with the installation. I decided to go with Openbox Window Manager and installed a terminal onto it for convenience. I can just call sudo startx, and the window manager opens up, which can be accesed by Ctrl + alt + F2. Since it is a system-wide terminal, I have also installed tmux for convenience. I am running the xserver on a particular pane and conduct my ROS work on other panes.

Now when I try to run commands that call on a GUI application from my system-wide terminal, I get the error:

QxcbConnection: Could not connect to display
Aborted

Now there are two ways to approach this problem:

  1. Since there is a terminal installed in my Window Manager, I should get ROS working on this? However, I do not know how to change the environment of the terminal emulator inside the window manager so that it is the same as the one on the system-wide terminal. Is it as easy as changing shells?

  2. Actually find a way to send my GUI applications to the tmux pane that is currently running the command sudo startx. How do I switch the parent of a process with another parent?


NOTE: I definitely would prefer the second solution, as it is more elegant and efficient for my workflow.

Best Answer

In a terminal in your GUI environment, type:

xhost +

In the non-GUI environment, type:

export DISPLAY="localhost:0"

Then, graphical applications that you launch from the non-GUI environment will be displayed in the GUI environment.

You can read more in man xhost

See also this answer from: What does this xhost … command do?

Related Question