How to run an X program without a desktop environment
In general it is not possible to run a GNU/Linux program which features a Graphical User Interface from a text only console. For example I had a Python progam using the PyQt5 library, if I start it from a virtual terminal I get the following error:
qt.qpa.xcb: could not connect to display qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found. This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, xcb. Aborted
In some circumstances it is not desiderable to start the full desktop environment (e.g. XFCE or Gnome), but you can still relay on the X.org server to handle the graphics. On a Debian GNU/Linux you can use the startx command (provided by the xinit package) to start the X.org server and to execute just one program:
startx /path/to/my-program.py --arg1 --arg2 > /dev/null 2>&1
Using the full screen
In my case I had to adjust the Python program to enable it in using the entire screen space.
The program initially calls the QMainWindow.setGeometry() with a reduced geometry which leaves some room for the window decorations (title bar, borders, etc.) and for the desktop environment elements (panels, etc.). When the program calls later the QMainWindow.showFullScreen() function, everything is properly resized to fill the entire screen. This approach works fine into a normal desktop environment, but when the program is run directly by startx
, the showFullScreen()
does not fill the entire screen.
To solve the problem I have to initialize the QMainWindow.setGeometry()
with the entire screen size. In pseudo Python code, something like this:
class myApp(QMainWindow): def __init__(self): super(myApp, self).__init__() screen_width = app.desktop().availableGeometry().width() screen_height = app.desktop().availableGeometry().height() self.setGeometry(0, 0, screen_width, screen_height) if __name__ == '__main__': app = QApplication(sys.argv) myMainWindow = myApp() sys.exit(app.exec_())