Clock Demo

This is a demo of various things, but mostly linking to C libraries, originally inspired by the lovely program adesklets. adesklets is very nice, but unfortunately requires you to write desklets in either perl or python, and it’s based on Imlib, which means raster graphics, which can get a little fuzzy around the edges.

Fortunately, with gst, we can easily hook up to C libraries, which means that we can have the Imlib functionality of adesklets, and lovely vector functionality, courtesy of Cairo. Not only that, but we can use our language of choice, Smalltalk.

Download the tarball here (9.6k): clockdemo.tgz.

I would suggest (though this is optional) creating an image that has already scanned the packages file micro-howto (note to self: must fix / report this).

Update: More importantly, the gst 2.2 can’t load .so libraries. There’s a small patch you need to apply to fix this: mini-howto.

Then you can run the demo with:

gst -gI myimage.im clock.st

You should get a clock with a transparent background ticking away at the centre-right of your screen. The transparent background probably won’t work with KDE and Gnome (I guess that’s all of you, right?), but it works beautifully on Openbox, I can tell you. The code to grab the background on other WMs is there in adesklets. It’s just that I haven’t ported it.

Here’s an action photo from my system:

The window doesn’t have a border. Kill gst to get rid of it.

If you look at the code, you’ll see that most of the linking is done automatically. The library files (Cairo.st, XLib.st, Imlib.st) contain lists of C functions, but those could be generated by scanning C headers as the GTK code does. I believe that that should remain a separate step, though, because then you can still use the library if you don’t have the relevant header files installed.

My code doesn’t attempt to OO-ify the link, so the code you end up writing isn’t very Smalltalk, but the details of that will depend on the C library, so you can’t easily do it in the general case. Also, it is easier not to when you are still at the debugging stage…

This is easiest done like this:

st> PackageLoader refreshDependencies!
st>ObjectMemory snapshot: 'myimage.im'; quit!

This is pretty straightforward, as long as you have libtool on your system, but it does require a complete rebuild of gst.

Apply the following patch…

--- orig/config/ltdl.m4
+++ mod/config/ltdl.m4
@@ -213,7 +213,7 @@
  [libltdl_cv_shlibext],
 [
 module=yes
-eval libltdl_cv_shlibext=$shrext
+eval libltdl_cv_shlibext=$shrext_cmds
   ])
 if test -n "$libltdl_cv_shlibext"; then
   AC_DEFINE_UNQUOTED(LTDL_SHLIB_EXT, "$libltdl_cv_shlibext",

…to config/ltdl.m4:

$ cd smalltalk-2.2/config

$ patch -p2 < ltdl.patch

Rerun the autotools:

$ autoreconf -f -v -i

Run ./configure and make as normal.