basic x windows applications

I've been digging into x windows of late - talk about a mess! So, tell me, if somebody wanted to just write a basic window app. How would they do it? It seems like there are soooooo many options and no apparent consensus:
  • xlib
  • xcb
  • xawt
  • motif
  • xt
  • qt
  • gtk
  • etc and so on
There is also a lot of FUD about "you really shouldn't use xlib or xcb and you should use a high level toolkit instead," which implies using QT, GTK, or what? Last time I installed the QT SDK, it was a beast, I figure GTK is more of the same. Surely there's simpler, more compact options, preferably ones that get installed with xorg itself and don't requires 2 gbs of downloads just to get a window to pop up with a c program?
 
Depends.

You can write X apps using Xlib and Xt. That's pretty basic no frills but you will need to design and write your own widgits.

Xaw was the first toolkit that provided widgets and an "API". Later on vendors produced Motif which would be used instead of Xaw. Motif, Xaw and others like it used the same philosophy wrt resources.

Then came Qt and gtk. Both of which altered the management of resources and altered the API, significantly. While in the mean time many others produced their own tookits.

Typically you would pick a tookit, i.e. gtk or Qt, and use it with the underlying Xlib.

Regarding Xcb, it's the underlying protocol. X was designed to work across the network. Your Xserver, running on your desktop machine, would display for X clients running either remotely or locally. Back in the day when UNIX workstations were prohibitively expensive one would purchase a large machine, like Sun 2000, and a bunch of smaller Sun workstations. You'd do editing on your workstation, because Sun 2000 would NFS server your $HOME (via NFS and the automounter). One would actually run the compile jobs and run apps on the larger machine.

Today this is not really needed as PCs and laptops are so powerful. Though, I tend to still use this model because I've managed to wear out a laptop CPU fan by working it too hard over the years. While my server systems downstairs can take much more work than the laptop.

That's the idea. Like Scott McNealy (CEO of Sun at the time) said, the network is the computer.

Wayland removes the network capability from its protocol speeding up apps like games. This is why the better computer games were on M$ Windows and not on X workstations. Direct access to graphic card memory. The GPU takes it one step further.
 
Use open-motif, it's the industry standard:
Code:
$ pkg search open-motif
open-motif-2.3.8_2             Motif X11 Toolkit (industry standard GUI (IEEE 1295))

Serious answer: Qt seems to be the best bet if you might ever intend to do a commercially viable product.
 
You can use FLTK. It is a cross-platform C++ GUI toolkit for UNIX®/Linux® (X11), Microsoft® Windows®, and MacOS® X. FLTK provides modern GUI functionality without the bloat and supports 3D graphics via OpenGL® and its built-in GLUT emulation.
 
  • Xlib / Xaw comes with the Xorg distribution but the widget set is fairly limited.

  • If you don't mind the "classic" look, then Motif really is a good option. It only doesn't come with Xorg due to legacy. You can almost think of it as a slightly more industry standard version of Xaw. Lots more widgets and a more expanded featureset of existing widgets.

  • If you need something larger than Xaw and a bit newer looking than Motif, then generally FLTK is my suggestion; it has very few dependencies, lots of widgets and most importantly, they are easy to extend; the whole thing feels a bit more like a simple drawing API than a big heavy GUI library. The inbuilt Gtk theme is probably the only nice one though in my opinion.

  • Qt and Gtk are closer to pyramid schemes rather than GUI libraries. I avoid them whenever possible.
 
Not sure whether Mono works (well) under FreeBSD and supports WinForm. Maybe it is an alternative for small programs.
 
You can use FLTK. It is a cross-platform C++ GUI toolkit for UNIX®/Linux® (X11), Microsoft® Windows®, and MacOS® X. FLTK provides modern GUI functionality without the bloat and supports 3D graphics via OpenGL® and its built-in GLUT emulation.
C+++, and without the bloat, in the same sentence... nice. I'll check it out.
 
  • Xlib / Xaw comes with the Xorg distribution but the widget set is fairly limited.
They say, a pic is worth a 1000 words. Sure enough. That's a limited set. Not a bad thing though. I'm off to finding my pics of the different widget providers.

I like the cleanliness, if uber-retro look, of motif. i may try that along the way.

I'm really hoping to find a nice, simple, and straightforward toolkit where I download the kit, write some code, compile it, send it over to my other machine, and either run it and have it complain that libx is missing, add some tiny lib file and have it run, or just send the src, and just add a tiny toolkit and lib and have it run.
 
I'm really hoping to find a nice, simple, and straightforward toolkit where I download the kit, write some code, compile it, send it over to my other machine, and either run it and have it complain that libx is missing, add some tiny lib file ...
If you are a professional software developer, then you can use that wonderful C or C++ libraries from the beginning.

If you are a computer user that considers a computer a programmable machine, that writes programs for himself and adapt them from time time, then I insist, try tcl/tk. Later, you can change the toolkit library, but if you want a nice, simple, and straightforward toolkit, then tcl/tk is the right one.
 
Update: Just built a simple app on DragonFly BSD following Jose's post here.

In summ:

Bash:
sudo pkg install fltk
...
New packages to be INSTALLED:
    fltk: 1.3.8 [Avalon]
...

cat <<EOF >hello.cxx
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>

int main(int argc, char **argv) {
  Fl_Window *window = new Fl_Window(340,180);
  Fl_Box *box = new Fl_Box(20,40,300,100,"Hello, World!");
  box->box(FL_UP_BOX);
  box->labelfont(FL_BOLD+FL_ITALIC);
  box->labelsize(36);
  box->labeltype(FL_SHADOW_LABEL);
  window->end();
  window->show(argc, argv);
  return Fl::run();
}
EOF

c++ `fltk-config --cxxflags --ldflags` hello.cxx
./a.out

# or, more concisely

fltk-config --compile hello.cxx
./hello


Screen Shot 2023-01-19 at 6.51.21 PM.png


Nifty! Definitely straightforward and simple. I like it.
 
OK. I'm properly impressed...

Code:
sudo port install fltk

cat <<EOF >hello.cxx
...

fltk-config --compile hello.cxx
./hello

et voila:

Screen Shot 2023-01-19 at 7.47.35 PM.png

compiled and run... on my mac :).

I'm figuring it'd be the same story on linux, etc.

But, hey! That doesn't look like an x window no more. Is it a native app? Can I paste into it text from the clipboard without having to do a bunch of weird stuff?

Off to explore. Boy, I gotta get my freebsd box up and running again. The TrueNAS instance is a lovely thing to behold, but I don't wanna do my x window explorations on it and my knowhow on DragonFly is a severely limiting factor to my fun. I'll prolly just blow it away and reinstall FreeBSD direct on that machine :( so that I can play, fix broken stuff, play some more :).
 
Code:
$ cat b.tcl
package require Tk
frame .a
label .a.l -text "Hello World" -font "Arial 30 italic" -relief raised -borderwidth 2
pack .a .a.l -side top -padx 10 -pady 10
1674189788738.png
 
Use open-motif, it's the industry standard:
Was the industry standard. Commercial UNIX used Motif with CDE (also built using Motif) as a desktop environment. But The last commercial UNIX (AIX) has gone into maintenance mode. There are virtually no commercial UNIX anymore. And the industry standard is, um, Linux and whatever desktop and tookits du jour it comes with.

Talking about industry standard, just before Sun's demise they released Solaris 10. Solaris 10 replaced CDE with Gnome 2. (IMO Gnome 2 was pretty decent however later versions of Gnome have regressed.)

Personally, I like that retro look and feel. It's the reason I maintain the open-motif and cde ports. I would like to bring back the openlook and xview ports one day, should I find the 64-bit patches that were somewhere on the Internet. That might be a post-retirement project, to resurrect the old openlook window manager and xview toolkit and have them build and run on something other than a 32-bit environment. This was why Sun abandoned OpenLook, replacing it with CDE when they released their 64-bit Sparc machines.

Talking about retro desktop environments, I use CDE on my laptop. The last time I went to OpenHack here, a couple of GenZ people there remarked how they loved the look of CDE on my laptop. The 3-D effect of Motif widgets have a certain quality that you don't see on the flat looking toolkits that are the basis of today's desktop environments. OpenLook also had a 3-D look to it. It was style back then. It's no longer stylish to have that 3-D effect, probably because it takes a lot more effort to bake those effects into the toolkit.
 
I love GUI programming because you get to see real results almost straight away. Also it's sort of "programming-lite" - recreational. You can do it absent-mindedly if you want and it still generally works out okay. My favourite toolkit is Gtk.
 
  • Like
Reactions: _al
Was the industry standard.
Indeed. It came from that optimistic era where they thought they could have "standards" when it came to UI. But it still stands up to the fact that it *was* the only UI toolkit to ever have been a standard and in many ways it does show.

GUI systems are unfortunate that they "infect" a codebase. Moving from one GUI toolkit to another is very difficult (unless copious amount of abstraction boilerplate is written which introduces its own issues). I really dislike Qt in that it isn't standard C++ but needs a MOC preprocessor. Maintaining these kinds of projects are difficult and is perhaps why you see many Gtk2 (or even Gtk1) projects still maintained but very few Qt3 and earlier projects.

CDE is great; admittedly it was in such a rotten state when we got it off the Open-Group (and friends). It was a difficult task to get compiling and running again, the build system was absolutely rotten. I *still* haven't gotten round to fixing my slight hack with the front panel.

cy@ As the maintainer, you might be a bit more familiar with the codebase than myself these days; perhaps you may want to attempt this slight visual bug?
 
Back
Top