UnixReview.com
Welcome to UnixReview.com

[Advertisement - Verisign]


Main Menu
  Home
  Archives
  Reviews
  Books
  Editor's Choice
  Geek Links
  Contact Us

Sections
  Open Source
  Certification
  Shell Corner
  lost+found
  Unix Shows
  Updates

[Advertisement]
Newsletter
Get the Newsletter
Get the Newsletter

   When you start programming X Window applications, one of the first things you need to figure out is where the documentation is located. Programming X Window applications has never been easy -- there's a huge set of functions to call to get even the simplest applications running. Anyone who works in this area tends to collect a shelf full of programming books detailing the various APIs and tricks you need to know to get your work done.

Cross Thoughts This is especially true for Motif applications, which depend on a number of layered programming libraries. At the top layer sits the Xm or Motif library, which provides the Motif menus, scroll bars, and other widgets. The next layer down is the Xt or X Toolkit Intrinsics library, which provides for the concept of a widget-a user interface item such as a menu or pushbutton. Beneath Xt lies the low-level X library. This library is common to nearly all X applications, regardless of the toolkit used. Beneath the X library reside networking socket libraries, but you normally don't have to deal with these. Newer X applications may also use session-management libraries at this layer. Programmers working on X Window applications need to know all the layered libraries, or at least the basics of each.

For years, Motif has been the premier programming API for X Window applications on commercial versions of UNIX. Modern Motif programmers can even call on programming layers higher than Motif with the Common Desktop Environment (CDE) libraries. CDE adds many convenience functions and special widgets on top of Motif. So there's a lot to learn.

Motif's popularity has been waning in recent years, though, for several reasons. Motif is a commercial product, which hits the fast-growing freeware market -- especially the Linux market -- hard. The costs and complications of licensing made many developers turn away from Motif. Furthermore, vendors standardized on a relatively old version of Motif, making it appear that Motif development had ended, despite ongoing efforts to improve it.

Some open-source developers have turned to LessTif, a free Motif workalike. Although each version keeps getting better, LessTif is still not at a 1.0 release after a number of years of development. This is a reflection of both the difficulty of the Motif libraries, as well as the volunteer nature of freeware projects.

But Motif was never a popular library, and its popularity has sunk further in this age of object-oriented programming. Designed before C++ gained widespread acceptance, Motif is built on a C-based object model imposed by the X Toolkit Intrinsics library (Xt). While Xt has many neat features, its C object model and callback functions don't hold up well when you can create C++ classes using constructs supported by the compiler, and define object constructors to initialize data.

Furthermore, extending Motif by writing your own widgets has always been a problematic and extremely difficult process. Using a programming language with object-oriented support built in, like C++, makes a lot of developers cringe at writing Motif widgets using the old-style C API.

For all these reasons, many developers want to get away from the model of past C-based applications and develop a new application framework. And of course, the desire to recreate the world to their liking is common in software developers. Over the past year, two new systems have matured and are now aiming to displace Motif -- and the freeware LessTif version -- as the premier X Window programming API. Known by their initials, KDE and GNOME have recently released major versions and are maturing rapidly. And both systems are free, part of the burgeoning open-source-software movement.

KDE and GNOME are intended as more than mere X programming libraries. Indeed, they are each a complete desktop environment with a window manager and a set of general-purpose productivity applications. KDE goes even further with KOffice, an attempt to create a full-featured office suite of applications, including a word processor. GNOME also includes office applications such as gnumeric (pronounced "numeric"), a spreadsheet application.

Both KDE and GNOME include a number of programming libraries, as well as ways for compatible applications to communicate.

Being so new and under active development, there are few books available to fill your X programming bookshelf and help you through all the subtleties of programming these APIs. So this month I'll lead you through the documentation available for these toolkits. Most of it is easily accessible online.

KDE

KDE, or the K Desktop Environment, was originally the Kool Desktop Environment, but the Kool part was dropped. At least the name, that is. Covered in my KDE column ("The Holy Grail In Beta," March 1998, p. 67), the name KDE is intended to be similar to CDE.

KDE, based at http://www.kde.org, is written in C++ and includes an extensive set of C++ objects. Underlying KDE is the semi-free Qt library from Troll Tech (http://www.troll.no) in Norway.

By starting out with C++, the KDE effort frees itself from the C-language bindings of the past, letting developers take advantage of the object-oriented features offered by C++.

There's one main quirk of Qt's usage of C++ that may cause developers to pause. Qt extends the concept of the C++ language by adding what are called signals and slots. With Qt, signals send messages. (These signals have no relation to UNIX signals.) Qt slots, basically member functions, receive messages. So, to handle the standard task of callbacks, in Qt you connect a signal from one object to a slot in another object.

The problem with signals and slots is that you need to run a Qt application through a preprocessor, called moc (the Qt meta object compiler), before compiling your applications. The fact that the code you write is not the code that gets compiled can complicate debugging. My March 1999 column ("Too Cute," p. 68) covered Qt and provided a sample application.

Another quirk of Qt is its history as a commercial product. There's a free edition of Qt at http://www.troll.no/qpl/. You should check out this license before using Qt alone or with the KDE.

Qt documentation is available at http://www.troll.no/qt/. A book, Programming with Qt, by Matthias Kalle Dalheimer, one of the KDE luminaries, will be available soon from O'Reilly. See http://www.oreilly.com/catalog/prowqt/ for more.

The KDE developer's library, the main KDE documentation page, is located at http://developer.kde.org. From this page, you can access most of the online KDE tutorials and references. One such tutorial is GUI Building with KDE, by Richard J. Moore. This tutorial is located at http://www.developer.kde.org/kde-tutorial.html.

Daniel Marjamäki provides a KDE tutorial at http://www.ida.his.se/ida/~a96danma/, and another short tutorial is located at http://www.wenet.net/~garbanzo/kde/tutorial/.

The KDE API reference guide is located at http://www.ph.unimelb.edu.au/~ssk/kde/devel/, with advanced programming information at http://developer.kde.org/advkde.html.

The KDE project actively promotes a number of standards, which all KDE applications should adhere to. You can find out more from http://developer.kde.org/kdestd.html. The style guides are quite extensive, going into the choices on the File menu and so on. There's also an icon style guide, http://developer.kde.org/kdestd/www/icon-style.html, and a standard set of icons, http://developer.kde.org/kdestd/www/kde-icons.html. Using the standard icons will make your applications fit better into the KDE desktop. The icon style guide goes so far as to list the colors you should use. Not only does this help keep things consistent, it helps for users with only 256-color displays. Rather than using three similar-but not identical-shades of blue, applications can all share the same colors.

In addition to style guidelines, KDE developers should look at KAppTemplate, available from http://home.sprintmail.com/~granroth/kapptemplate/. Kurt Granroth developed a shell script that can generate a bare-bones KDE application when you give it a few details on the command line. In the future, a more-extensive program called Shaman, (http://www.kirchheim.netsurf.de/~tfischer/shaman.html), aims to replace KAppTemplate. Shaman uses tags that look familiar to anyone who knows HTML or XML.

GNOME

The GNU Network Object Model Environment, or GNOME, can be considered even more ambitious than KDE, as GNOME attempts to make all applications communicate using the Common Object Request Broker Architecture (CORBA). Based at http://www.gnome.org, GNOME is associated with the GNU efforts for creating a free version of UNIX and associated utilities. GNOME even has a manifesto, at http://www.gnome.org/about/manifesto.htm. GNOME is licensed under the GNU Library Public License.

GNOME is built on top of the GTK (also called GTK+) library. (You'll notice that where KDE uses a K prefix, just about everything related to GNOME uses a G.) GTK, short for GIMP toolkit, is a C API created for the image-processing program, the GIMP (http://www.gimp.org). The GIMP needed a freely-available X programming toolkit, so the developers created GTK. GTK includes two lower-level libraries, Glib, a portability library and GDK, a thin wrapper over the X library drawing functions. You can find information on these at http://www.gtk.org/docs/glib_toc.html for Glib and http://www.gtk.org/docs/gdk_toc.html for GDK, the general drawing kit. Glib is very useful for C programmers wanting a set of portable routines for things like linked lists.

You can find information on programming to GTK at http://www.gtk.org/documentation.html. You'll even find Chinese, Italian, and Korean tutorials, as well as a Spanish FAQ here.

A GTK 1.2 tutorial is at http://www.gtk.org/tutorial1.2/. The reference manual can be found at http://www.gtk.org/docs/gtk_toc.html.

For communications between programs, GNOME uses the ORBit CORBA Object Request Broker, or ORB. ORBit documentation resides at http://www.labs.redhat.com/orbit/, and the development is helped by Red Hat, a major Linux vendor. An excellent book on CORBA programming with C++ is Advanced CORBA Programming with C++, by Michi Henning and Steve Vinoski. A beginner's guide to ORBit from Ewan Birney and Michael Lausch is available at http://www.sanger.ac.uk/Users/birney/orbit-html/book1.htm.

To find out more on how to use ORBit with GTK applications, which includes GNOME applications, Ian Main has put together a tutorial at http://www.gimp.org/~imain/ORBit-GTK/ORBit-GTK.html. This page includes a lot of code-always a plus in my opinion.

The Object Management Group, http://www.omg.org, has more information on CORBA.

So far, this covers just the toolkits that provide a foundation for GNOME. GNOME programming documentation appears at http://www.gnome.org/devel/docs/index.htm. Developers should also look at http://www.gnome.org/devel/index.htm. Horacio Peña wrote an online GNOME developer book at http://www.gnome.org/devel/docs/gnome-dev-info/book1.html.

Because there are so many libraries associated with GNOME, it's often hard to figure out where to get started. To help with that, N. Adam Walker, also known as "Reklaw," publishes a page at http://home.earthlink.net/~nawalker/hello.html.

Soren Harward has a guide to getting GNOME to work from CVS, at http://www.cinternet.net/~soren/gnome/cvs.htm. All the GNOME code is available via CVS, the concurrent version system that is widely used in UNIX for managing source-code versions. While the GNOME core is written in C, GNOME provides bindings for C, C++, Guile, Objective C, and TOM.

GNOME and KDE are often rivals, but GNOME wins hands-down for its naming scheme. For example, both KDE and GNOME are developing separate document-component architectures so documents like spreadsheet tables can get inserted into word processor documents. The GNOME architecture is called Baboon.

For those sticking to Motif, you can find a lot of documentation at http://www.lesstif.org/Lessdox/lesstif.html. This is for the LessTif version of Motif, available at http://www.lesstif.org. You can find official Motif information at http://www.opengroup.org/motif/. There are also numerous books available on Motif.

Eric Foster-Johnson is the co-author of Power Programming Motif (with Kevin Reichard), and author of UNIX Programming Tools, (MIS: Press/M&T Books). He can be reached at erc@pconline.com.


   
Home | Top | Editor's Choice

[Advertisement]
Copyright © 2001 UnixReview.com, UnixReview.com's Privacy Policy
Comments about the website: rreames@cmp.com
SDMG Web Sites: C/C++ Users Journal, Dr. Dobb's Journal, MSDN Magazine, Sys Admin, SD Expo, SD Magazine, UnixReview.com, Windows Developer's Journal