The Motif widget toolkit (Part 1)

A basic Hello World example in Motif

Mario Emmanuel
The Console
4 min readJul 10, 2021

--

A screenshot of the classic Motif-based UNIX Common Desktop Environment. Image from forums.freebsd.org user Ozric used with permission.

Motif was once the UNIX standard widget toolkit. It has been used as the core UNIX GUI library that has built most of the scientific, industrial and mission critical software in the 90s.

While its relevance has gone long time ago, it is still used in legacy software and it can be still used in new projects. It is well documented, extremely robust, stable, lightweight and efficient.

Some references to Motif

While now it seems like an ancient user interface, Motif was a breakthrough innovation at its time.

Motif was introduced in the late 80s as an attempt to set an standard on UNIX workstations.

Motif can be also seen in action in several scenes of some 90s major blockbusters, such as Jurassic Park, Congo or Twister.

Some documentaries about science and research programs that include computer screens footage often shows Motif applications too. It was widely used in many science and research fields. The footage of NASA scientists receiving the first Hubble images around a UNIX workstation will show Motif in action.

A first Motif window

I will show a couple of basic template examples. The first one shows how to create an empty window. The source code can be found in this repository.

Sample empty window for our first example

The second example (included in this repository) shows how to draw a line in the Drawing Canvas widget. Note how a callback function to handle the expose event is required, this is common to almost all widget toolkits, not only Motif.

In this second example we draw a line across the Canvas. Notice how we have used the default White color.

Further learning resources

Motif is a stable toolkit. Despite it no longer experiences relevant changes it is still maintained. The best introduction are probably the O’Reilly Definitive Guides to the X Window System.

Among the series, the specific book that covers Motif is the Volume Six A: Motif Programming Manual, at the time of writing this post they can be freely and legally downloaded from the IST website.

While Xlib is not strictly needing when programming Motif it is recommended to read the chapters related to drawing primitives. Unless your UI can be covered with buttons and other standard widgets, you will end up needed some custom drawing.

For Xlib, you can find a good introduction in Volume One: Xlib Programming Manual. This book is again part of the Definitive Guides to the X Window System from O’Reilly. I own almost all books from the series, they are usually easy to find and cheap, and can be often a good reference.

Motif faq can be still found here and might solve some doubts. Some of the major internet contributors to Motif (such as Kenton Lee, who also was in charge of the FAQs for a while) are no longer active (remember that its commercial usage peak was early 90s, so most of the people experienced in Motif are already retired). Some websites can be still reached in the Internet Archive, such as old Kenton Lee’s 90s web site.

Stack Overflow does not have that much activity in Motif anymore, but a properly researched and documented question will often find quality answers from developers that used Motif in the past. I recommend using the tags [c], [unix], [x11] and [motif]. Trying UNIX Stack Exchange might work too as there are some experienced folks there too.

Despite its age all Motif packages are actively maintained and available in all UNIX, UNIX-alike and Linux distributions, so installing and developing does not require any particular effort in terms of environment. Motif (and X11 in general) is best suited to C, there are wrappers for other languages too but I have the feeling that it is better to use it as it was intended (i.e. using C).

Motif will not make you the cool guy of the cocktail parties because it is old and considered ugly by many. But despite its age and lack of modern look and feel it is a solid mission-critical grade toolkit. It is easy to code, it is extremely fast, lightweight and its widget availability is modern enough to build a useful UI.

--

--