
Very simple program that accepts from stdin graphic commands to draw in a X11 window. It can also inform over stdout for keyboard and mouse events. It uses plain Xlib but it can optionally uses cairo for antiliased drawing.
It should run in any modern UNIX-like with minimal effort. You need to have installed the Xorg and Xlib development headers. Optionally it also need the cairo development headers. Then just run:
make

rectangle 10 10 280 280
set cairo color 0 0 0.8
cairo line 20 20 280 280
cairo line 20 280 280 20
set cairo color 0 0 0
cairo circle fill 30 150 150
set cairo color 1 0 0.2
cairo text 200 200 Cairo
set color green
text 100 100 Fixed
flush
Usage: ./simpleX11 <window_width> <window_height>
The commands are sent to simpleX11 over the stdin. Most of them are self explanatory:
point <pos_x> <pos_y>
line <pos1_x> <pos1_y> <pos2_x> <pos2_y>
rectangle [fill] <pos_x> <pos_y> <width> <height>
circle [fill] <radius> <pos_x> <pos_y>
text <pos_x> <pos_y> <text> // Only accepts text without spaces
text <pos_x> <pos_y> // Takes the text from the next entire line
set color <name> // Uses names from /usr/share/X11/rgb.txt
set font <name>
set width <width>
clear <pos_x> <pos_y> <width> <height>
set handle keyboard // Enables keyboard events over the stdout
unset handle keyboard // Disables them
set handle mouse
unset handle mouse
set handle mouse_motion
unset handle mouse_motion
set handle mouse_enter_leave
unset handle mouse_enter_leave
get window size
get text size <text> // Only accepts text without spaces
get text size // Takes the text from the next entire line
set pixmap <index> // Selects another pixmap, preserving the content of this
flush // Flushes Xlib output buffer
If you compiled simpleX11 with cairo support, you get this also:
cairo line <pos1_x> <pos1_y> <pos2_x> <pos2_y>
cairo circle [fill] <radius> <pos_x> <pos_y>
cairo text <pos_x> <pos_y> <text> // Only accepts text without spaces
cairo text <pos_x> <pos_y> // Takes the text from the next entire line
set cairo color <r> <g> <b>
set cairo width <width>
set cairo font <name>
In order to close the simpleX11's window press ESC or close the stdin.
Version 1.0 finished, basic functionality implemented.
The program is under the GPLv3.
Send me an email if you have any question about the code, you found a bug or you have a feature request. Send it to:
jimenezrick@gmail.com
Last modified date: Wed May 5 21:44:58 CEST 2010