This last month has been a busy period and I managed somehow to work on 3 Gtk2 based CPAN bundles: Champlain, Gtk2::Ex::Entry::Pango and a new module Gtk2::Unique.
In the past weeks someone was looking for the Perl bindings to libunique (a library for writing single instance applications). The bindings didn't exist so I decided to write them as they can be quite useful and might end-up being used one day in Xacobeo.
This project took a little longer than I expected even though the C API is quite small (3 header files). I got delayed considerably because I'm still learning how to write proper GObject bindings. The important thing is that the module has been released and is now in CPAN Gtk2::Unique
In the meanwhile I also managed to release a new version of Gtk2::Ex::Entry::Pango which is backward compatible with all versions of Gtk2 that support Pango and most important behaves correctly when the text entry gains focus. Now when default Pango markup is used to display text when the widget is empty it will clear the default text when the focus is gained and restore it when focus is lost (if there's no text). This is similar to what Firefox's search bar is doing and apparently Windows Vista (I don't have it so I can't tell).
Lastly but not the least, libchamplain had a major release (0.3). The number of improvements and additions is too long to be enumerated in this post. One thing is assured the library is getting better and better. This new version has a lot of API changes, this is for the best so bare with us. The bad thing is that the API changes where so numerous that the bindings are lagging behind. Don't worry it's just a question of time and the bindings will be ready soon.
Why is the module Gtk2::Unique? Shouldn't the libunique work for all app types even if not using Gtk2? I don't write Gtk2 applications but it will be interesting to have a common easy way how to make sure scripts are running just once. Like cron jobs, etc. Is this possible with libunique and/or Gtk2::Unique?
Re:libunique
Aristotle on 2009-05-16T14:52:46
Why is the module Gtk2::Unique?
Because libunique requires gtk+.
Re:libunique
potyl on 2009-05-17T19:32:57
The module is in the prefix Gtk2 because that's was suggested in the perl-gtk IRC channel. The name was even proposed by the creator of libunique.
Nevertheless, the namespace is not a sign of the dependencies required but more of where the module belongs to. Although this particular module does require that an application is given a Gtk2::Window handle. I haven't looked at the C library so I don't really know why this is needed. I will ask the creator of the C library why is a Gtk2::Window handle required.
In the meanwhile if your server is running has D-Bus running then you can implement the same functionality through D-Bus. Keep in mind that libunique purpose is to make sure that there's a single instance of the application running and performing the tasks. This means that when a program detects that there's already an instance running it should send a message to the first instance and ask it to performed the requested task. Of course you can use the module for ensuring that the application is having a single instance running and to simply return when the application is already running.
Re:libunique dependencies
potyl on 2009-05-18T13:59:43
I got a reply from libunique's creator. The purpose of the library is truly to help GUI based programs to ensure an unique instance. Since it is aimed at GUIs the default implementation of libunique provides some custom actions that apply only to a GUI (ex: bring forwards the main window of the application when a message is received).
A command line application that would like to have the same benefits could either use D-Bus and try to register a service name. Service names are unique in D-Bus. Another approach would be to use a traditional lock file.