Taschenorakel.de

Postings tagged with Tricks

Using DBus as lock-daemon

Recently I found this comment in the source code I am working with:

// what if both processes read in the same time and write at the same time, no increment

Please! Don't do such things! Don't just leave such comments in hope someone else will come around and will fix later. Please take the time to apply a locking mechanism.

Obvious choice when dealing with files would be to create a lock file. Unfortunately creating a ...

Application Theming Tricks

From time to time applications need custom theming rules. Especially when the project has professional UI designers involved. So how to achieve this with GTK+?

Trivial Theming

Most easy and very wrong:

if (gdk_color_parse ("pink", &color))
    gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, &color);

This will break and look childish as soon as your users use a custom color scheme.

Better:

static void
style_set_cb (GtkWidget *widget,
              GtkStyle *old_style)
{
    GtkStyle *style = gtk_widget_get_style (widget);

    if (gtk_style_lookup_color (style, "SecondaryTextColor", &color))

...

GtkBuilder based Plugin System

Seems like GtkBuilder is extremly useful to build efficient plugin systems:

The prettyness of this system is, that it only loads the plugin when some related action is activated:

Implementing this was straightforward. I am pretty sure that I've reinvented some wheel.

libtool aware gdb wrapper and mergetool

Just want to mention some small and rough tools I've written recently to easy my daily hacker's life:

Changelogs and Fortune Cookies

Nasrudin walked into a teahouse and declaimed, "The moon is more useful than the sun."
"Why?", he was asked.
"Because at night we need the light more."

Regularly applaud myself for changing my prepare-changelog script to yield a random fortune cookie with each changelog entry:

`/usr/games/fortune -s wisdom`

Quite entertaining.

...

Project specific editor settings

Everyone knows the problem that seemingly each project uses its own code style. So here is my solution for that problem:

$ cat ~/.vim/after/ftplugin/c.vim 
if filereadable('.project.vim')
    source .project.vim
else
    set sw=2 sta et

...

#ifndef LIBRARY_IS_GPL

There are libraries, which are licensed under GPL, instead of LGPL. This puts people under the risk of accidentely violating the copyright of that library, by using the GPL library from some LGPL library for instance. Well, also could be that doing that changes the license of your LGPL library to GPL or whatever. Don't really want to think about the horrible implications of accidently using a GPL ...

Finding the broken .la file

In case you wonder which .la pulls in /usr/lib/libglib-2.0.so, instead of /opt/gnome/lib/libglib-2.0.so, you can try this code snippet. The first pipeline retreives all .la files libtool reads, the second one scans that file for the unwanted .la file.

strace -f make 2>&1 | grep 'open(".*\.la".*) = [0-9]\+$' | cut -d\" -f2 | sort -u | tee /tmp/labber

...

Use gtk-doc to find required package version

Usually I am quite unsettled when adding package requirements to README files and configure scripts. AI never really know if the version I specified is correct.

This morning I had enough of this uncertainness and hacked a short Python script to extract that information from our find gtk-doc manuals: gtkdoc-check-symbol-versions.

Libxml2 cannot parse the HTML gtk-doc generates, so the script reads the gtk-doc manuals line by line, throws regular expressions at them and puts the ...

Linking to library.gnome.org

Recently the brave gtk-doc guys introduced a tool called gtkdoc-rebase, which updates external links in your API docs to point on the GNOME Library. The gtk-doc.make script has been updated to run gtkdoc-rebase on make dist. Unfortunatly all this pretty stuff doesn't work out of the box on Gutsy, as two premise have to be fulfilled to make this voodoo work:

Saving Bandwidth with git-svn

git-svn is a cool tool to have the joy of local branches and git's outstanding performance, whilest working with a Subversion repository. Unfortunatly git-svn has the disadvantage of wasting insane amounts of bandwidth when cloning a Subversion repository: Cloning for instance the GTK+ repository costs serveral gigs of bandwidth - just do end with about 200 MB of compressed data on your disk. It's told this happens due a bug in ...