What was I doing last night... Seed querying xscreensaver

Published 2011-11-30 00:00:00
Like quite a few developers, I earn income by selling my time, either packaged on a project, or by the hour. For this to work, keeping track of time is essential. Unfortuntally, like most creative people, I really enjoy hacking, but filling in timesheets just really doesnt do it for me... So read on for my solutions using gnome seed...

 

To solve this problem, I have developed plenty of tricks over the years to keep track of myself. Gitlive, and the previous setup of subversion mounted with davfs enabled the tracking of all file writes. So when I was developing code, it was possible to track time using commit logs. I often overlaid this with tracking of outbound emails which helps give context to some of the development, so quite a bit of time is simple to allocate.

However quite often, there are times when I'm researching something, doing some remote access or generally just not writing code, however working on a project. And since I get lazy and ignore all the pop-up messages to remind me to track what I'm doing, I end up loosing income due to lazness.

So to try and solve this I've been eyeing tools which log which window I'm using, and how long I was using it. Unfortunatly there was nothing out there, that I could find that did that simply and easily, so after doing some research I though I'd throw something together.

To track what I'm doing involved two issues.
a) Inquiring what window is focused.
b) Seeing if the desktop is idle.

Finding the currently focused window turned out to be trivial, with the wnck library and seed.

 Wnck = imports.gi.Wnck;
 screen = Wnck.Screen.get_default();
 screen.force_update();
 var aw = screen.get_active_window();
 if (aw) print(aw.get_name());


Seeing if and how long the desktop was idle however turned out to be a bit more complicated..

There is apparently a way to enquire through dbus to org.gnome.SessionManager.Presence to get if a window is active, but since dbus is pretty complex, and not that stable in seed at present, I only ever managed to get it to segfault every so often, and return '0'..

The classic way to get idle time is a little C program described here http://coderrr.wordpress.com/2008/04/20/getting-idle-time-in-unix/ It depends on the libxss xscreensaver library. So after a little playing around, I created a tiny module for seed that includes the single function screensaverinfo_get_idletime() which just returns the number of milliseconds that the desktop has been idle.

xorg = imports.xorg;
print(xorg.screensaverinfo_get_idletime());

The module has been added to Gnome git repository seed-xorg.c

So that enables a very simple piece of code in javascript to basically set_timeout every second to check idle time, which does a few things

if desktop has been idle output a timestamp  + IDLE to a log file.
otherwise if the current window has changed or was idle before output timestamp + the window title.

So here part of the output in /.gitlog/2011/11/30.log (it's called gitlog as i've bolted the code onto the gitlive monitor application). Each day logs to a new file.. etc.

22:22:00 Untitled Document 1 - gedit
22:22:03 *Untitled Document 1 - gedit
22:31:57 WindowLog.js (~/gitlive/gitlive, Project gitlive) - Komodo Edit 6.1
22:32:06 *Untitled Document 1 - gedit

as you can see, I spent a good 9 minutes editing this blog post in gedit before I checked the code in Komodo..

So finally I know what I was doing last night....

The final code can be seen here   WindowLog.js

Comments



Add a comment (requires javascript!)
Name
Email
Homepage
Comment Title
Comment
I am a link spammer?