Programming with the XForms Library

The XForms home page calls XForms “a GUI toolkit based on Xlib for the X Window System. It features a rich set of objects, such as buttons, sliders, and menus, etc., integrated into an easy and efficient object/event callback execution model that allows fast and easy construction of X applications.” With this first of three articles on XForms, you can ease into programming for X without having to
A Little More Detail

If you're already thinking ahead to greater things, you are probably a little confused about how to get an XForms application to do anything other than return after a single button is pushed. The next programming example provides a hint, but the whole story will have to wait for the next two articles in the series.

The basic idea is to proceed as in the xhello example, but to add some functionality to each action. We do this by creating a multi-lingual “Hello World” program called xmulti. The source is shown in Listing 2, and is also available on the series web page. Save this file as xmulti.c. It should compile with the command:

gcc -lX11 -lforms -lm xmulti.c -o xmulti

Listing 2. xmulti.c

The program can now be executed by typing xmulti, and should look like the example shown in Figure 2. Examination of the xmulti source code reveals the fundamental steps involved in creating an XForms program are as follows:

Figure 2. Mutlilingual Hello World

  1. Include forms.h to access the XForms routines

  2. Call fl_initialize() as soon as possible

  3. Set up your graphical interface by creating forms

  4. Assign actions to relevant objects by setting callbacks

  5. Show one or more forms

  6. Turn control over to fl_do_forms()

The only thing new here is point 4, which our original xhello program did not include. In xmulti, the English and French buttons are set to call the routine set_language(), which changes the display. But the basic idea is very general, and you can easily add buttons, menus, etc., that call complicated functions, display other forms, or what have you.

Coming Next Month

Next month, we'll expand on this basic discussion by writing a more complicated program. This will involve using menus, multiple windows, and a few other refinements. By the time we've done the third article, you should be well on your way to creating useful applications.

If you can't wait to learn more, then you may want to start reading through the XForms manual. Browsing the example applications' source code is also an excellent way to familiarize yourself with the XForms way of doing things.


Thor Sigvaldason is the author of the statistics program xldlas, which uses the XForms library (see Linux Journal, Issue 34, February 1997). He is trying to complete a PhD in economics, and can be reached at


One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix