Non-rectangular windows with GTK+

I spent some time trying to figure out how to use the X shape extension to have the window shaped like the calculator. At first I tried loading a separate image mask bitmap, but later realized that it would be much better to simply use an image format that supports transparency, such as PNG. That way I can load the image using gdk_pixbuf_new_from_file() just as I’ve been doing, and call call gdk_pixbuf_render_threshold_alpha() to get a bitmap for masking. The bitmap then is passed with the main window widget to gtk_widget_shape_combine_mask().

I made this selectable by using (or omitting) a “transparency <integer>” statement in the KML file. The integer is used as the threshold for the gdk_pixbuf_render_threshold_alpha() call.

In transparency/shape mode, the menu bar is not created, and gtk_window_set_decorated() is used to eliminate the normal window decorations. Otherwise you get a rectangular frame around the window, even though the region between the calculator outline and the window frame is transparent.

I wasted some time wondering why this wasn’t working and trying to debug it, then discovered that it was because I was using an X server that didn’t support the shape extension. (Don’t ask!) When I ran it on a “real” X server (XFree86, of course), it worked fine.

I’m sure I can create a pop-up menu instead of a menu bar when in transparency/shape mode, but I haven’t figured out how to arrange that the user can “grab” the window in certain regions in order to drag it. Maybe this requires hints to the window manager? At this point I have no clue.

I checked the code into the Subversion repository but don’t plan to do another release yet.

This entry was posted in Calculators, Nonpareil. Bookmark the permalink.

Leave a Reply