Tag Archives: Program

Workrave, with no fake microbreaks

I’ve been using Workrave to help me remember to take breaks from the computer. I always end up not using it after a while though.

That’s because I get irritated by it because it gets frustrating after a while. I’ve always been a bit too optimistic about my breaks. Specifically because the program comes with an insane setting as standard.

However, this time I’ve set the settings to:

  • One two-minute microbreak every hour.
  • One ten minute break every three hours.
  • Eight hour PC-time, give me one extra hour three times if I ask for it.

Hope I’ll use it for a longer time now.

A key press is an activity!

I quickly found another of my common irritations after using it. Workrave is not detecting my keypresses properly, so even though I am sitting at the computer, it thinks I’m not.

This especially happens with the microbreaks, they never seem to actually work. I’m very often reading stuff on the screen, only pressing “Page down” button once every 10 seconds.

The reason Workrave behaves so strangely is because it uses an algorithm like this:

  • Get keyinput / mousemove or whatever
  • If mode is MODE_IDLE:
    • Set mode MODE_NOISE
    • Set last_time to now
  • Else if mode is MODE_NOISE:
    • If last_time is more than ACTIVITY ms ago, set mode to MODE_ACTIVE.

So, as you see, there’s a config setting ACTIVITY that messes things up. The code is not exactly like that, but close enough.

Anyway, when I found out that, I was happy. Easy fix!

But not so easy anyway. I saw there was a config system going on there, and tried finding the workrave.ini file residing in .workrave/. Sadly, I couldn’t find it, so I made it, with:

[monitor]
activity=0

Ok, that worked. It dumped a whole lot of new config options into that file, and when restarting Workrave, it stopped working. That was probably because many of the options were truly bogus.

Instead of fixing it, — I found out that my default config provider was gconf, so I rather did it that way.

The real fix

Opening up gconf-editor, I browsed to apps/workrave and inputted "monitor/activity" as an integer with value 0.

Restarting Workrave, and lo! It resets the counter when you press one button, just as I wanted!

Other irritations

It also doesn’t react on the mouse when it’s moved less than 3 pixels from where it was. That’s hard coded, so you’d have to change the source and compile it.

Another thing is that with the settings I have, which is 2 minute microbreak every hour, it’s still way too easy for it to register my 2 minute break when I did in fact not use it. It’s very possible for me to read a full screenful of a text (and think hard about it), or watch a video for over 2 minute.

Workrave has it’s own «reading mode» button for that. However, I don’t like that because

  1. I have to remember it
  2. It’s not easily accessible
  3. I have to remember turning it off

I could fix something with point 2 and Workrave’s dbus integration. But, well, it’s still a drag.

I think maybe we could raise the IDLE-time limit. These are the default limits:

NOISE = 9 seconds
ACTIVITY = 1 second
IDLE = 5 seconds

So we know what ACTIVITY is, I’ve set that to 0, so that it doesn’t need 2 events 1 second apart in order to register activity.

NOISE is how long until it waits until it sees a new keyboard input resets its ACTIVITY-lookup. Having that as 9 seconds is OK for me now that I’ve set ACTIVITY to 0.

IDLE is the time it waits until it starts counting. I’m not too happy with it at 5 seconds. I’m using Workrave with much bigger time lapses, so it should be really be upped.

I’ll put IDLE at 60 seconds, so that it won’t start counting IDLE time unless I’ve been off the keyboard for 60 seconds. So this will still make me take my 2 minute microbreak when I’m not touching the computer for 3 minutes, but it won’t happen as often.

So opening up gconf-editor and going to apps/workrave/monitor, and then inputting idle with integer value 0 will fix it.

And then Workrave is better to use!

Nicer pdf2png, with poppler

Updated: so poppler now includes pdftocairo which does this. No need to do this anymore! Blog post here for reference.

I’ve been using convert from ImageMagick to convert PDF-files to png files. However, they’re butt ugly, or rather fugly. So I created a pdf2png script / python program to do it better.

Just look at the text here from convert:

Rather ugly. Look at the kerning. It’s truly horrible.

Not to say poppler doesn’t have its share of problems, but it looks rather much better, don’t you agree?

So, since I had to manually edit a presentation I had to use some time making a PDF-to-PNG converter since I couldn’t find another pdf2png.

So without further ado, here is pdf2png.py (updated to use cairo as Raimund posted code for in comments, also updated with width+height extra params):

#!/usr/bin/env python
 
import poppler
import cairo
import gtk
import urllib
import sys, os
 
width = height = 0
 
if len(sys.argv) != 2 and len(sys.argv) != 4:
    print("Usage: %s <filename> [width height]")
    sys.exit()
 
if len(sys.argv) == 4:
    width = sys.argv[2]
    height = sys.argv[3]
 
input_filename = os.path.abspath(sys.argv[1])
output_filename = os.path.splitext(os.path.basename(sys.argv[1]))[0] + '-%.2d.png'
 
doc = poppler.document_new_from_file('file://%s' % \
            urllib.pathname2url(input_filename), password=None)
 
for i in xrange(doc.get_n_pages()):
    page = doc.get_page(i)
 
    if width and height:
        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(width), int(height))
        ctx = cairo.Context(surface)
    else:
        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,
                int(page.get_size()[0] * 2), int(page.get_size()[1] * 2))
        ctx = cairo.Context(surface)
        ctx.scale(2, 2)
 
    page.render(ctx)
    ctx.set_operator(cairo.OPERATOR_DEST_OVER)
    ctx.set_source_rgb(1, 1, 1)
    ctx.paint()
    surface.write_to_png(output_filename % i)

It’s very far from perfect. Note the hard coded height and width, all of these things are possible fixes. Not anymore! The default should be sensible now, or you can force it with arguments. I didn’t find any python-poppler documentation, but I used C++-docs instead, they were helpful enough.

If you do any improvements (thanks Raimund) or just use it, it’d make me happy if you told me in a comment. :-)