9

Is it possible to use GTK without a valid X display?

I want to use GTK with Webkit, but for now I'm only interested in using the DOM functions to experiment, so I have no need to actually display anything. It's very convenient for me to do this over an SSH connection on a server that has no display.

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

Gtk-WARNING **: cannot open display:

Is there anyway to use GTK without a display?

4 Answers 4

8

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

Sign up to request clarification or add additional context in comments.

1 Comment

Xvnc can be used with similar effect. The difference is that Xvnc allows vncviewer to fully interact with the display.
2

I'm glad I read the docs deeper and didn't just believe this answer.

gtk_init_check()

This function does the same work as gtk_init() with only a single change: It does not terminate the program if the windowing system can’t be initialized. Instead it returns FALSE on failure.

1 Comment

If you read even deeper you'll find Note that calling any GTK function or instantiating any GTK type after this function returns FALSE results in undefined behavior.... so Your Milage May Vary.
1

While it's not an direct answer to your question, I think what you are looking for is a “headless” web browser. There's one based on WebKit, called PhantomJS. It doesn't require any GUI stack, and you can freely experiment with DOM there.

Comments

1

Gtk+ 3 (well, GDK) has support for multiple backends now, but still requires X11, Wayland, or Broadway (experimental HTML5 backend) to run.

DISPLAY doesn't necessarily need actual hardware; you can run a fake X server such as Xvfb or Xvnc.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.