YORIK’S COFFEE CORNER

You are currently viewing a single post of this guestblog.

Click here to go back the complete page. I would be glad to hear your comments, so don’t hesitate to leave me your feedback below. It will appear on the main guestblog page.


in categories  opensource  linux  permalink:  293   posted on 28.11.2009 1:47
From Yorik
Fluxbox and pseudo-transparency



Fluxbox is a window manager for linux and other unix-based systems, like KDE or Gnome (the default window manager in ubuntu). On a linux system, your desktop is made of a stack of different programs, basically the linux kernel, which drives your hardware, the X.org server, which is a graphical server and a window manager, which actually draws your desktop and its windows. More advanced window managers such as gnome are also called desktop managers because they do much more than just drawing windows. Like most pieces of a linux system, nothing prevents you from changing your window manager anytime.

Fluxbox is an extremely simple window manager, based on the old and famous blackbox (which even has a version for windows). Several other window managers have evolved from blackbox, such as openbox. They all behave more or less the same and have the same qualities: they are extremely simple and fast. The big difference between fluxbox and the others is that it looks much cooler, because of two things: it can use bitmap images to draw icons and window borders, so you can draw almost everything yourself, and it supports pseusdo-transparency.

Almost all recent linux distributions support openGL composition. That means that your desktop can do all kinds of cool effects such as having transparent windows or toolbars. This is done at a lower level by the X.org server, so basically anything can be made transparent (= composited) against the desktop background or other underlying windows. The problem is that this behaviour is pretty heavy on your graphic resources. Many people actually prefer to disable those desktop effects to have a faster desktop. And if you work with openGL-based 3D software such as blender or games, you will very probably encounter conflicts, bugs or slow performance and have to turn them off anyway.

Pseudo-transparency is not real transparency. It is a trick, basically a portion of the background image, which lies exactly under a window, is copied and then applied to the window. You can do other operations with that portion of image, such as mixing it with a color, etc. Then, the contents of the window are drawn. You will have a perfect illusion of transparency. Of course, if you have several overlapping window, you won't see them all through the upper one.

While this can be seen by many as a poor trick, to me it has fantastic advantages: It is all done by very basic software operations (copy an image, cut a portion of it, etc...), so basically any piece of software can do it, it doesn't use your 3D graphic board, and the fact that it is "false" transparency is actually very effective: How do you read the contents of a window if you can see the contents of the other windows beneath it? You need more effects, such as blurring the other windows, like windows vista does. More graphical resources used.

The main use I do of my system is producing 3D content. I want all the power of my system available for rendering or displaying complex 3D scenes. The biggest advantage of linux is that it is possible. A Windows Vista system uses about 500Mb of your memory. A typical Gnome desktop uses about 300Mb. They all have a lot of resident programs to monitor things like network, user input, mounting/unmounting, etc. A fluxbox desktop can occupy less than 100Mb, and almost zero load of the graphic board. Applications start in fractions of seconds (no resident programs have to check for this or that), and, best of all, pseudo-transparency allows for totally cool desktop look...

Another advantage of all blackbox-based window managers is the extreme simplicity of configuration. All the behavior of your desktop is stored in 2 or 3 text files, that you can either edit with a text editor or use specially-made configuration applications such as fbconf. The themes are also single text files, with an extremely easy syntax, like window.title.color = #FF3300. And on debian-based systems, the debian menu system takes care of updating your applications menu automatically. Fluxbox also has a couple of specific goodies, such as the ability to group windows different into one tabbed window.



How to try

It is very easy to have a look. Install the "fluxbox" package in your software repository, and next time you login, on your login screen, you will have a new fluxbox session available. You can have just a try, and come back to your default desktop by logging out/logging in again. Once you are in fluxbox, right-click anywhere on the desktop background to display the fluxbox menu, that contain about everything, your applications, styles (themes) and fluxbox configuration options.

You also have per-window settings, available by right-clicking any window title bar. Fluxbox can remember several things for each applications, such as window position, level, etc.



How to configure

In your home directory, a ".fluxbox" folder will be created. Inside that folder, there is an init file that contains fluxbox general parameters. The contents of that file basically reflect what you can configure from the fluxbox menu itself. The second important file is the menu file, which contains all the contents of your fluxbox menu. If you are on a debian-based system, make sure it contains a "[include] (/etc/X11/fluxbox/fluxbox-menu)" line (or "[include] (/home/yorik/.fluxbox/fluxbox-menu)" for user-space version), so your menu will automatically show installed applications.

You then have a keys that contains all keyboard shortcuts, and a couple of other files that usually don't need to be edited by hand (they are used for example to remember windows states). There is also a styles folder that contains all your user-installed custom styles (or themes).

The two file types you will usually edit to customize your fluxbox desktop are the menu file and the style files. Both have a very complete man page: just type man fluxbox and man fluxstyle in a terminal.



Transparency

Fluxbox itself can apply pseudo-transparency to everything it draws: toolbar, window bars and menu. Simply right-click and browse the available options to set the transparency levels.

Then, you have several terminals that support pseudo-transparency as well, such as aterm or urxvt (my favorite). You have then several excellent terminal applications (such as emacs or midnight commander) that, if run inside a pseudo-transparent terminal, will behave the same way.

Finally, if you know a bit of coding, making your own pseudo-transparent application is quite easy too. Here is a pygtk code to produce a pseudo-transparent application such as in the first screenshot above (look at the twitter application):

import os, gtk

class pseudoTransparentWindow:
      def __init__(self):
          self.toolbarheight=19
          self.win = gtk.Window()
          self.win.set_size_request(250, 200)
          btn1 = gtk.Button("Test Button")
          fixed = gtk.Fixed()
          fixed.put(btn1, 20, 30)
          layout = gtk.ScrolledWindow()
          layout.set_policy(gtk.POLICY_NEVER,gtk.POLICY_AUTOMATIC)
          layout.add_with_viewport(fixed)
          layout.get_child().set_shadow_type(gtk.SHADOW_NONE)
          self.style(layout.get_child())
          self.win.add(layout)
          self.win.show_all()
          self.updateBackground()
          self.win.connect('configure-event', self.updateBackground)

     def updateBackground(self,args=None,stuff=None):
          self.style(self.win)

     def style(self,widget):
          x,y = self.win.get_position()
          w,h = self.win.get_size()
          wpfile = open(os.path.expanduser('~') + os.sep + '.fluxbox/lastwallpaper')
          pb=gtk.gdk.pixbuf_new_from_file(wpfile.read().split('|')[1])
          wpfile.close()
          crop = gtk.gdk.Pixbuf( gtk.gdk.COLORSPACE_RGB, False, 8, w, h )
          pb.copy_area(x, y+self.toolbarheight, w, h, crop, 0, 0)
          mask = crop.copy()
          mask.fill(0x00000000)
          mask.composite(crop, 0, 0, w, h, 0, 0, 1, 1, gtk.gdk.INTERP_BILINEAR, 127)
          pm,m = crop.render_pixmap_and_mask(255)
          style = widget.get_style().copy()
          style.bg_pixmap[gtk.STATE_NORMAL] = pm
          widget.set_style(style)
 
if __name__ == '__main__':
     pseudoTransparentWindow()
     gtk.main()



First and foremost, your name:

And your message:

To publish it, just press this ...