All posts by Mike Massonnet

Build a project with Vala

This post is about using Vala in a project but in the end provide the C code for the releases. I think that this is very essential and that releasing source code to be build from Vala is wrong. Vala will always rewrite the code to GObjects in C, but has already proven that compiling the same code from two different versions of Vala will fail. So when you are doing releases with Vala you will break your releases sooner or later. Another good point is when the Vala code is compiled on top of patched vapi files, doing only C compilation with the releases will drop the requirement to apply them.

I'll take as example the Autotools, if you are using a different tool-chain you can surely adapt it. The idea is simple, the Vala sources are only compiled in maintainer mode. When you compile the application from the development branch you will usually have a script called to build the configure script that will automatically be executed with the parameter --enable-maintainer-mode. When providing the distribution tarball that is created with make distcheck, the configure script will not be run with that parameter (except if specified by hand) and the source files to build from will be filled in with the C filenames.

The example below is very generic and can be copy/pasted but should be adapted.

Autoconf script

1. The initialization of Automake and the maintainer mode in the autoconf script. The Automake version is checked for 1.11 which is the first version that comes with Vala support. The extra dist-bzip2 argument is there to provide an extra bzipped distribution tarball as you guessed it.
AM_INIT_AUTOMAKE([1.11 dist-bzip2])
2. The check for Vala only on maintainer mode. The AM_PROG_VALAC defines the variable VALAC that can be reused inside the files and accepts an optional version check.
if test "x$USE_MAINTAINER_MODE" = "xyes" ; then
if test "x$VALAC" = "x" ; then
AC_MSG_ERROR([Cannot find the "valac" compiler in your PATH])
3. It is possible to sum up the build configuration at the end of the autoconf script.
echo "Build Configuration:"
echo "* Maintainer Mode: $USE_MAINTAINER_MODE"
if test "x$USE_MAINTAINER_MODE" = "xyes" ; then
echo " * Vala: $VALAC"

Automake script

1. The declaration of the Vala sources and their respective compiled C sources.
product_VALASOURCES = \
obj1.vala \
obj2.vala \

product_VALABUILTSOURCES = $(product_VALASOURCES:.vala=.c) product.h
2. Use the special BUILT_SOURCES variable to build given targets before running a dist with e.g. make distcheck. This usually done in maintainer mode, as in this case to be sure the releases won't have anything to do with Vala.
PACKAGES = --pkg=gtk+-2.0
BUILT_SOURCES = vala.stamp
vala.stamp: $(product_VALASOURCES)
$(VALAC) --vapidir=$(srcdir) $(PACKAGES) $^ -C -H product.h
touch $@
3. The final sources for the product are filled in with the generated Vala sources. The Vala sources are not passed to any SOURCES which is why they are passed to the special EXTRA_DIST variable.
product_SOURCES = \
random-source.c \
random-header.h \


That's it

There are many existent Vala projects nowadays from where you can pick up new ideas, and this post is just an example amongst many others. The full example is available in the xfce4-vala bindings.

Update: I corrected some mistakes seen in green in the script portions. If VALAC is unset the configure script must quit otherwise the resulting Makefiles will have empty commands instead of /usr/bin/valac. Also the generated header file must be passed to product_VALABUILTSOURCES otherwise it would have been left out from distributions as it wans't passed to any product_SOURCES nor EXTRA_DIST variables.

Xfce Clipman Plugin 1.0.0

This post is about the latest release of Xfce Clipman Plugin, a Clipboard Manager for the Xfce desktop. I turn it more technical than for end-users. I hope people interested into GTK+, GObjects or Xfce panel plugins will like to read it. The release is going to happen very soon now.

The first major change concerns the plugin being entirely rewritten by using GObjects and Xfconf, this means cleaner, better understandable, maintainable code, etc. There is the "main function" (for sack of clarity) and four objects. A collector which listens to clipboard changes and put them in the history, the history is also an object, a menu (on top of GtkMenu) that displays the history and allows to clear it, and finally another object which is part of a new feature for the clipboard manager.

Now having my objects it's just about instantiating them in the main function and binding them to Xfconf. If there is something missing in an object it is just about modifying a particular aspect of it.

The goal of using Xfconf is to have a less cluttered code for settings, and to make good use of property bindings against the objects. For instance, the object History has a maximum count of items, and being bind against Xfconf, it is possible to run an external command with xfconf-query to change that setting, without having to call a public setter function. Binding a property is a one function call.

Following this major change is the settings dialog. I have written it from scratch with Glade, a UI designer for GTK+, by which I can easily modify and beautify the dialog without having to fight with lines of code several hours a day. In fact it takes a few seconds to change a label and up to 5 minutes to design a goddamn dialog. Glade makes an increased use of memory however, but stop thinking of this when you know you have 1MB times 1000 installed on your system — I have currently 1GB on a netbook and 2GB on a quite-fanless Atom-based workstation but I use only around 300MB in general. If you still fear about having an application that uses only 2 but 5MB with Glade, well I can't help you! From what I have read, the built-in UI designer of GTK+, named GtkBuilder, needs less memory, but the Glade to GtkBuilder conversions are going to happen with Xfce 4.8.

Now about the new feature introduced into this major release. It is called "Actions" which is the fourth object by the way. An action is a match between a text selection and regexes to let you execute specific commands. For example the action "Image" can match text with image filenames and let you choose commands between "View with Ristretto" and "Edit with Gimp". I wrote something simple in the settings dialog to add new actions that is inspired from the Thunar User Custom Actions interface.

Finally, I made other changes that are more geeky than useful, like I made a bundle out of the plugin. The plugin is now installed under the binary directory instead of the common place holder for panel plugins but can still be added inside a panel with the "Add Item" menu action. As you might understand, it can be executed as well now, and if you do so it will run inside the notification area. An item is installed in the applications menu to be able to start it (under the category Utility), and as it is possible to run outside the panel, I added a autostart file.

That's it already. If you have questions, don't mind. If you wanna discuss the Actions/regex feature go ahead. More importantly, I hope you'll take a glimpse at the code.

If you are interested into panel plugins, have a look at the wiki. The panel plugins amongst the goodies are a good way to get to know code and start with something.

Update: ANN: xfce4-clipman-plugin version 1.0.0 released

Refresh the Xfce background

In Xfce 4.4 there was a little hack that worked to refresh the background. I managed to get the same result for Xfce 4.6 with the following "hack":
if [ -z "${DBUS_SESSION_BUS_ADDRESS}" ] ; then
. ${HOME}/.dbus/session-bus/`ls -rt ${HOME}/.dbus/session-bus/ | tail -1`
IMAGE_PATH=`xfconf-query -c xfce4-desktop -p ${PROPERTY}`
xfconf-query -c xfce4-desktop -p ${PROPERTY} -s ""
xfconf-query -c xfce4-desktop -p ${PROPERTY} -s "${IMAGE_PATH}"
Now when will this be useful? Barely never. Still enjoy it :-)

Update: script snipped updated to run within a cronjob.

Vala Notes Plugin

Or better, there is Vala in the Notes plugin. It's been a long time I thought about a hypertext view widget for the notes plugin, so it can highlight links and open them on click, and doing this in pure C/GObject is quite a PITA because there is a lot to take care about (more lines of code), and then you didn't start thinking about the whole functions of the object. Now this is retro with the presence of Vala. I played with Vala some time ago, doing some very rudimentary hello worlds, and I never had a chance to really write something in Vala, untill two days ago. I started to write a very dummy object on top of GtkTextView that implements the simple undo/redo feature I wrote inside notes.c and it was very fast and easy to backport from the C code to Vala, and this gave me a very good start with Vala (now that was one Vala too much, wasn't it? anyway...). Yesterday I added skel functions to support hyperlinks which I finished today. Finally I integrated the Vala object inside the notes plugin in a way that it compiles to C code when you are in MAINTAINER_MODE, which means for end-users they won't need Vala but only gcc.

Now for those interested into Vala, here is the file I played with: hypertext.vala. This source contains at the end of the HypertextView class, another class that contains a main function so it can be compiled to a binary. This proves how easy it is to test a class, and all you need to do is to run the following command: valac --pkg=gtk+-2.0 hypertextview.vala && ./hypertextview.
There are many samples available with the source of Vala and on Gnome Live. The tutorial covers important points, the FAQ too, but the documentation is a little less interesting if you already know GObject IMHO.
One important thing I learned about Vala was the difference between the out and ref arguments.

If you have a hard time at finding the right method definitions, look into /usr/share/vala/vapi/gtk+-2.0.vapi for instance for GTK+. There you can quickly find any function name you now from the C API, for instance if you want to have a look at gtk_text_view_get_iter_at_location search for get_iter_at_location. By scrolling up you will see that you are in the class Gtk.TextView. Vapis are very easy to read.

I am very interested into porting the objects of the Xfmpc project to Vala, and then start trying out the plugin sample (loading modules during runtime)... I hope my fellow will like that idea :-)

Now for the people interested to develop Vala classes with VIM I have some tips. First follow these instructions in order to get Vala syntax. Then I suggest you install the Tag List plugin, and to get it working with Vala you will need to add the following lines to your vimrc configuration:
" Work-around Tag List
let tlist_vala_settings='c#;d:macro;t:typedef;n:namespace;c:class;'.
\ 'E:event;g:enum;s:struct;i:interface;'.
\ 'p:properties;m:method'
If you don't know about folding then you miss a lot of VIM culture, in fact you can fold/unfold brackets by going over a bracket and typing zf% in command mode. And that's all folk, thanks for reading til here.


Just like my older post about a "./jamendo-player", this time I am definitely more interested into good online radio stations. And SHOUTcast is the best that comes to my mind! It's been there for years, Winamp is the best music experience ever, and both have been promoting each other even though I don't know/remember what their relation are.

The good things about their widget is that it saves the recent radios and it also has a list of favorites but this one isn't working as-is with the code. It is possible to search for radios and to browse by genre. All of this stuff is saved under ~/.macromedia/Flash_Player/#SharedObjects/<random>/

So of course I couldn't resist but embed their available Flash widget inside a window :-) Again the code is very short, it's just about loading — well not a URL this time — an HTML string cause the Flash application all alone doesn't work out, it needs parameters passed outside. I didn't include the callbacks to handle "_blank" links, which means it is not possible to open any links, but this is useless as the widget is fully functionnal.

You can download the source code here.

Here are some installation instructions:
  1. Look into main.c
  2. The first line of main.c is a comment with a command to compile
  3. If you want a menu item in you desktop menu:
    1. Edit the Exec keys in shoutcast-radio.desktop
    2. Copy the desktop file to ${XDG_DATA_HOME:-~/.local/share}/applications
  4. If you don't have a gnome-radio icon, copy gnome-radio.png to ~/.icons/
By the way, I'm linking on the Xfce blog. Why? Cause there might be Xfce users interested into a simple to compile radio application. At least I hope some of you will enjoy it, more than the jamendo thingy :)

Update: The favorites actually do work, it just that the favorite button isn't always clickable.

Colored Notes

I passed the last night to hack on a gtkrc snippet for the Notes plugin, because I couldn't find my sleep well. So being borred I killed a little bit the time to have a colored notes window :-) I know it was possible since always, I just never carred to do it. Using colors showed one annoying problem which are the icons. They don't fit always once you go away from the default gtk theme colors. In consequence I switched them to bold text labels with minus, plus and times. One other thing I didn't succeed with was to theme the menu that is available on the top right corner or Ctrl+M.

Finally the result is nice.

The snippet is the following:
gtk_color_scheme = "notes_fg_color:#E8E58C\nnotes_bg_color:#77741D\nnotes_base_color:#EBE88C\nnotes_text_color:#6B6A4A\nnotes_selected_bg_color:#ACA94E\nnotes_selected_fg_color:#E8E58C"

style "notes-default"
xthickness = 2
ythickness = 2

fg[NORMAL] = @notes_fg_color
fg[ACTIVE] = @notes_fg_color
fg[PRELIGHT] = @notes_fg_color
fg[SELECTED] = @notes_selected_fg_color
fg[INSENSITIVE] = shade (3.0,@notes_fg_color)

bg[NORMAL] = @notes_bg_color
bg[ACTIVE] = shade (1.0233,@notes_bg_color)
bg[PRELIGHT] = mix(0.90, shade (1.1,@notes_bg_color), @notes_selected_bg_color)
bg[SELECTED] = @notes_selected_bg_color
bg[INSENSITIVE] = shade (1.03,@notes_bg_color)

base[NORMAL] = @notes_base_color
base[ACTIVE] = shade (0.65,@notes_base_color)
base[PRELIGHT] = @notes_base_color
base[SELECTED] = @notes_selected_bg_color
base[INSENSITIVE] = shade (1.025,@notes_bg_color)

text[NORMAL] = @notes_text_color
text[ACTIVE] = shade (0.95,@notes_base_color)
text[PRELIGHT] = @notes_text_color
text[SELECTED] = @notes_selected_fg_color
text[INSENSITIVE] = mix (0.675,shade (0.95,@notes_bg_color),@notes_fg_color)

widget "xfce4-notes-plugin*" style:highest "notes-default"
widget "xfce4-notes-plugin*.*GtkMenu*" style:highest "notes-default"
widget "xfce4-notes-plugin*.*GtkMenuItem*" style:highest "notes-default"
# TODO Set the colors for the menu
The shade() and mix() functions are specific to either Clearlooks or Aurora. But this can be fixed. Actually I didn't include a default rc style inside the notes plugin, in fact this snippet can be saved for instance as notesrc inside your current theme and you add include "notesrc" in the gtkrc file.

All for the sharing, please enjoy.

Update: The shade() and mix() functions are a feature from GTK+ 2.10 just like gtk_color_scheme.

Update: I released a new version 1.6.4 that has a configurable background color setting.


I was enough bored from my (small) music collection that I wanted to listen to something new, without actually caring what it is. I know Jamendo has a big load of music with artists uploading music under creative commons licence. So I went on their website to have a look, and they have "widgets". They are a small flash application not bigger than 200x300, but I actually didn't find any link to open such a widget inside an external window, except some lost links on some pages. In conclusion it was enough annoying to get an external player that I fired up vim and wrote a 20 lines C program.

/* gcc `pkg-config --cflags --libs webkit-1.0` main.c -o jamendo-player */

#include <gtk/gtk.h>
#include <webkit/webkit.h>

#define URL_FORMAT ""

int main (int argc, char *argv[])
GtkWidget *window;
GtkWidget *webview;
gchar *url;
gchar *playlist_id = argv[1];
if (argc < 2)
playlist_id = g_strdup ("65196");
g_message ("Loading the default playlist %s", playlist_id);
url = g_strdup_printf (URL_FORMAT, playlist_id);
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (window, "delete-event", G_CALLBACK (gtk_main_quit), NULL);
gtk_window_set_icon_name (GTK_WINDOW (window), "multimedia-player");
gtk_window_set_title (GTK_WINDOW (window), "Jamendo Player");
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
webview = webkit_web_view_new ();
gtk_widget_set_size_request (webview, 200, 300);
gtk_container_add (GTK_CONTAINER (window), webview);
webkit_web_view_open (WEBKIT_WEB_VIEW (webview), url);
gtk_widget_show_all (window);
gtk_main ();
return 0;

The result is pleasing, the flash application has nice colors, and is something I would never be able to do with GTK+ :-)

If you like the code, feel free to extend it and send patches, I will enjoy any contribution. For now I will just leave a desktop file inside my applications directory to open it when I am bored again of my music :-p

Update: I hacked a little on the program to handle the links inside the Flash application. This means it is possible to change the playlist, which was one the thing that started to annoy me very much.

However, this update requires WebKit 1.0.3 and GLib 2.16.

This time I'm making the code available here instead of pasting it as it has grown up to 120 lines.

Prospective work on Xfce

As Xfce 4.6 is coming it might be good to throw updates for the panel plugins I maintain at the same time.

The panel plugins I maintain are:
  • The notes plugin
  • The FS guard plugin
  • The clipman plugin (this one is prolly the most wanted)

For the notes plugin I got already most features I was thinking of in, except formatting (which I doubt that I will work on), so the release going on here will be minor.

For the FS guard plugin I was asked to reverse the progress bar so that it shows the capacity remaining and not the free space... well something like that :-) Now I'm confused and don't remember what it really displays.

The clipman plugin needs a rewrite. To my taste it features too many options, and I will split most none-obvious options to an "Advanced..." tab. The first release will most probably be the rewrite, than will follow another release for a long asked feature that is action on pattern matching — open a web page automatically, display a menu, and so forth.

Other than plugins I maintain applications.

The applications I maintain are:
  • Xfmpc
  • Eatmonkey

Sadly for Xfmpc — a client for MPD — I no longer run MPD to listen to my music, so this hacking is freezed at the moment. My current favorite player is Audacious.

Eatmonkey is a small application where I learn to use new frameworks. There won't be an official release before very long.

Hopefully I will get the clipman plugin out before end of December!