Thursday, December 06, 2012 is down

Unfortunately many of my snippets in this blog have been written and uploaded exclusively on . It was a free service for uploading snippets of any kind, with a friendly versioning system and other cool features.
It's now inactive since several months. I'm sorry for anybody stumbling upon any post that has code hosted at . From now on I will try to put the code in the post itself whenever I can, or find better places to upload the code.

Thursday, November 22, 2012

Grab focus on Gtk Widget

Many times I had to give focus to a newly created Gtk widget that still had to be mapped to screen. Since widget.grab_focus() does not work if the widget is not displayed on the screen, then I always used an idle source to delay the operation.
Today I noticed that the idle may be too late: if the user is writing something, then some key strokes may be lost because the idle runs slightly after the widget has been mapped. You may think that's imperceptible to the user, but that's not true in some cases.

So I've tried connecting to the map, map-event and show signals (also "after"), without success: the handler is called slightly before the right time thus grab_focus() will not work.

Then I ended up with this working solution, that will grab the focus as soon as the widget is first drawn to the screen:

void focus_widget (Widget widget) {
  // it may be already displayed
  widget.grab_focus ();
  // grab focus right after the widget is drawn
  // for the first time
  ulong sigid = 0;
  sigid = widget.draw.connect (() => {
    widget.grab_focus ();
    widget.disconnect (sigid);
    return false;

I still don't know exactly what's the best way to grab focus as soon as the widget can really grab it. So if you have any better idea, please let me know :-)

Sunday, November 11, 2012

Code Search is dead. Long live Code Search!

I'm bumping a breaking news from Introducing, a regexp code search engine

The days of google codesearch are ended since a while, but now we have an up-to-date and open source debian codesearch.

(from the about page):
It searches all the open source projects which are included in the Debian archive (the "main" distribution only, not non-free or contrib). Currently, that includes about 18000 packages with 140 GiB of source code.
The search engine itself is based on Russ Cox’ codesearch tools, meaning it uses Regular Expressions as input. Like the codesearch tools, it was implemented in Go.

The project is a thesis so the source code won't be available until January 2013, and we all hope that the project continues beyond that date.