Latest

Archive

Community news

C++

Communities and Content

Databases

Editorials

Emacs

General

HTML

Java

Notices

PHP

XML

Apache

C++

Database

General

HTML

Java

Javascript

Linux

Object oriented programming

Open source

Perl

PHP

Python

Ruby

SOAP

XML

Suggest a link

Advertise on zez

Contribute

Contact us

About zez


Xlib tutorial 1 - painting colors, graphics contexts and fonts



Make it run


    while(true)
    {
        // sleep here, so we won't use 100% cpu.
        sleep(10);
        break; // quit after 10 seconds
    }

    XFreeFont( dpy, font );
    XFreeGC( dpy, gc );
    XCloseDisplay( dpy );


All X programs need an event loop which processes events from the X server until the program wants to quit. As events will be covered in tutorial 2, a fake eventloop will do the trick. It let's the program sleep for 10 seconds then exits our "event loop".

Finally we clean up the resources we have allocated. Usually most located X resources are freed with XFree(). Fonts and GC's are exceptions and are freed with XFreeFont and XFreeGC. XCloseDisplay disconnects us from the X server and frees the resources used by the Display struct. Naturaly you can't use resources after they have been freed.


Final words


This tutorial has shown some basic features of the Xlib library. However a more object oriented approach is preferable when dealing with larger applications. I have enhanced the tutorial code to include a painter and a font class which hides some of the X details from the user. The next tutorial will be based on the object oriented version.
Also worth noting is that repainting after resize or covering does not work. This will be handled in the second tutorial.

The latest version of this tutorial is part of the frekko project and can always be found here.

Attached files:


<< Previous page | 1 | 2 | 3 | < 4 > | Printer-friendly page |

Comment List


There are no comments.


Forgot your password?

Register a new user

Results

Polls