Code examples for simple applications using Xlib to work with windows on Unix-like operating systems with X Window System.
X Window System is a client-server system for managing the display of windows for raster displays, widely used in Unix-like operating systems. X provides the basis for a graphical environment (GUI), handling the drawing and movement of windows on the screen, as well as interaction with the mouse and keyboard.
X11 is the name of the current version of the X Window System protocol.
Xlib (X Window System library) is a library that is part of the X Window System and implements X11. It provides access to low-level graphics system functions, allowing applications to work directly with window display and screen graphics content.
Here are some examples of how to use the Xlib library. These examples gradually reveal the basic concepts of working with a graphics server and solve typical tasks of building a graphical application.
All examples can be compiled with one command: make
.
Each example can be compiled and run separately. The examples and how to run them are described in detail below.
make simple_window
Minimalistic example showing how to connect to the graphics server and open a window using the XCreateSimpleWindow() function.
make event_handling
Minimalistic example showing how to handle simple events. In this case, the window is closed when the Escape key is pressed.
make create_window
Simple example demonstrating creating a window using the XCreateWindow() function, setting the window title, drawing a square in it, and handling window closing in the window manager.
make font_drawing
Simple example demonstrating basic work with fonts.
make draw_rect
Example in which a rotating rectangle is drawn in a window, which rotation can be controlled using the keys A, D, Left Arrow, Right Arrow, Space.
make dodger_game
Simple game where you have to dodge hordes of bloodthirsty squares. Control is done using arrow keys or WASD.