Using GTK without DISPLAY

Can GTK be used without a valid X display?

I want to use GTK with Webkit, but for now I'm only interested in using the DOM functions for experimentation, so I don't need to display anything. It is very convenient for me to do this through an SSH connection on a server on which there is no mapping.

But, without the DISPLAY environment variable, gtk_init() just fails with the message:

Gtk-WARNING **: cannot open display:

Can I use GTK without a display?

+6
source share
4 answers

There is an X server called Xvfb that provides a valid DISPLAY and sends the result to a file instead of graphics hardware. You can run this on the same machine where your gtk client is running, and gtk will be able to do whatever it wants without using any of your network bandwidth. As a bonus, you can read the Xvfb output buffer from a file, allowing you to get a screenshot of what will be on the screen.

+5
source

Although this is not a direct answer to your question, I think you are looking for a "headless" web browser. There one is based on WebKit called PhantomJS . It does not require any GUI stack, and you can freely experiment with the DOM there.

+1
source

Gtk + 3 (well, GDK) now supports multiple backends, but this requires X11, Wayland or Broadway (experimental HTML5 backend).

DISPLAY does not necessarily require actual equipment; you can start a fake X server like Xvfb or Xvnc.

+1
source

I am glad that I read the documents deeper and do not just believe in this answer.

gtk_init_check()

This function does the same work as gtk_init (), with only one change: it does not exit the program if the window system cannot be initialized. Instead, it returns FALSE on failure.

0
source

Source: https://habr.com/ru/post/921522/


All Articles