Archive for July, 2011

Throw: A Compiz Plugin

One feature that I’ve really been wanting from compiz is to give windows a bit of momentum when I’m moving them around. In other words, if I flick a window with the pointer and then let go, I want it to continue moving, so that it can be “thrown” across the screen. Thankfully, someone involved in compiz wrote such a plugin, found on his blog here. Unfortunately, the strategy that he uses doesn’t work well for me. There are essentially three problems with it:

  1. In order to calculate the velocity of the window after it is released, he compares the window position at the time it is released to the window position at the time it was grabbed, and calculates the delta. This leads to weird behavior when the users is indecisive and moving the window around sporadically before releasing it.
  2. The velocity of the window has an unnatural association to the actual “velocity” that the user was moving it with.
  3. The velocity appears to be zero when using a pen-tablet (wacom) input because my hand generally stops before the pen moves out of range of the tablet.

While the compiz API documentation is in a very sad state, Sam’s plugin showed me all the parts of the API that I needed. I rewrote the plugin to essentially low-pass the velocity of the window, sampled at the compiz frame rate. At each “movement” event, I update the delta in the x direction and the y direction. At each “frame” of compiz, I bake the accumulated deltas, along with the time (in ms) since the last sample. The accumulated deltas and the number of milliseconds are stored in a ring buffer. When the window is released, the buffer is averaged to get a window velocity in pixels-per-millisecond.

I also augmented the window structure to store a floating point representation of the window location. Together with the low-pass on the velocity, the outcome seems to be a lot smoother.

The window velocity exactly matches what I “feel” like the velocity of the window is when I let go of it. Also, the filter only has enough history for a couple of frames so weird movement of the window prior to release is “forgotten”, and only the “most recent velocity” is used.

The code for the plugin can be found in my redmine

No Comments

Ubuntu Stopwatch Applet

It has occured to me several times that I would like to have a small stopwatch utility with quick access (particularly for time tracking on various projects). I figured the Ubuntu timer applet would have this function, but alas, it did not. To my surprise, there wasn’t any applet in the ubuntu repositories that does this. I decided it would be sufficiently useful to look into writing one myself. As usual, documentation was pretty sparse but I managed to find a good starting point and cobbled together a simple proof of concept. I’d tell you how much time it took, but I didn’t have a handy stop-watch applet for me to time myself.

You can find the code in my redmine here. Compile with gcc or just run (it’s only one line). The .server file needs to go in /usr/lib/bonobo/servers. It also needs to be edited to point to wherever it is that you put the binary. After moving it, log out and then back in. Right click on the panel you want to add it to and select “add to panel”. You should see “Stopwatch Applet” in the list.

Add To Panel

Add To Panel Dialog

It’ll drop the simple applet on your panel. The applet steals the “timer-applet.png” image from the timer applet package so you might need that in /usr/share/pixmaps in order for the entry to show up in your list of available applets. The applet looks like this:


The Stopwatch Applet

There are basically no features. It starts counting when it’s loaded. You can click on it to reset it. I do have some planned improvements for when I get around to it.

  • Ability to control multiple timers from one instance
  • Ability to choose which timer is displayed in the panel
  • Ability to pause/lap/resume by clicking on it (configurable)

Also, just in case you were wondering, I spent a total of 23 minutes and 49 seconds on putting this code in version control, adding the project to redmine, and writing this post.


Openbook: Introduction

For the past few months I’ve been working on a side project I’ve dubbed “openbook”. It was my plan to give up on wordpress and not post anything until I had openbook up and running and I would make the development blog on the running build. Development has been slow going, so I’ll continue using wordpress to document the progress on this project.

Basically, I have a lot of problems with the way web-based tools work. Most of the problems are cultural, not technical. I worry about the implications as we as a society become immune to violations of our privacy, bait and switch tactics, and addiction as a business model. It seems that the majority of internet entrepreneurs have embraced these poor cultural trends. Perhaps I can do something about it.

Read more about my ideas for this project in my working document

No Comments