we sometimes accidentally do something great

some days ago, i wanted to know, how i could improve the countdown widget, which we accidentally have in cheese. andreas, calum, chris, benjamin, lennart, patrys, robert accidentally said all the same: why does it have to be red? and they were right ;)

so what i accidentally did was to read out the bg[GTK_STATE_SELECTED] for the background and text[GTK_STATE_SELECTED] for the text which represents the numbers. so far it was pretty easy. too easy? probably: i wanted to have it sexier and lennart provided accidentally a lot of color space information and algorithms (though at the end i copied accidentally everything from gtk, because those functions accidentally are not public). we now just converted the rgb value of the gtk theme color to hsv and played around with the saturation value. after playing around we just converted it back to rgb and had a "light" color and a "dark" one. this accidentally provides a sexy glassy effect.

one thing that took me pretty long to understand was that bg[GTK_STATE_SELECTED] and text[GTK_STATE_SELECTED] reported wrong colors in some cases. patrys accidentally knew some gtk interals and told me that colors do not have to be in a gtkstyle if the widget has not been initialized yet or is initializing. and accidentally i experienced those cases. the solution to this problem was accidentally quite easy: we just had to implement a callback function for the style-set signal. this signal gets emitted as soon as gtk is able to tell you the colors, before the first expose event and sometimes between expose events if the user switches the gtk theme. now it worked. and accidentally the widget changes its color on runtime if you change the gtk theme while taking a photo. sounds cool, not? ;)

there was one issue left: we could set the text color, the background color, but how about the camera icon, which is a svg icon? the icon basically is just white or transparent and again, i saw that drunk developers do a better job when it comes to totally strange problems: the only solution we figured out in #cairo was to do svg dom processing (ugly!!!) or hard-coding the svg (even more ugly!!!). but last night, when i came home, not as dry as i am at day time, i accidentally met a nice cairo function: cairo_set_operator(). now guess what accidentally happend? i tried every operator (at that time i could not think anymore) and i accidentally saw that CAIRO_OPERATOR_XOR was doing an amazing job. what basically was happening is the following: imagine two layers and put the first one below the other. now you combine those two layers to one, but just take those "pixels", which are either in layer one or two, not in both. so you just get those fragments, where the first layer has a color and the second is transparent or the other way round. so, andreas was kind enough to swap the transparent and the white surfaces on the icon and that did the trick: i just paint the first layer in the theme color, and then removed everything, which was outside of the camera symbol by using CAIRO_OPERATOR_XOR. so the camera symbol accidentaly has the color i actually want.

to prove it, i did some screenshots. and remember: accidents happen! ;)

countdown widget

clearlooks theme

countdown widget

crux theme

countdown widget

glossy theme

countdown widget

highcontrast theme

countdown widget

murrina dark orange theme

countdown widget

morningglory theme

note 1: since 2.22 there is actually a gconf setting called /apps/cheese/countdown, where you can decide whether the countdown widget should be displayed or not. the development version features a menu entry for that.

note 2: the screenshots are actually no fakes. i just cut them out from the window, as i do not want to show me to you today ;)