Tabbed browsing with uzbl and awesome

I have been using the Awesome WM (window manager) for some time now, but only recently, after discovering the uzbl browser, I upgraded to the new version that is more heavily based on the Lua scripting language.

I found uzbl while looking for an alternative to Firefox. It’s been a long time I have been holding grudges against Firefox (and all of the web, BTW), and I’ve been hearing a lot about webkit lately. In special, there is a couple of webkit based browsers available in Maemo, and that caught my attention, so I was willing to try it out (but I didn’t like them on the tablet).

While configuring my old PIII desktop after my AMD64 Compaq notebook died a young and painful death, I felt that would be a perfect moment to discover some new browser sleeker and cooler than Firefox to run on that slow machine. So I gave it a try, and did apt-cache search webkit (on Debian), and there it was: a browser that is advertised as “adherent to the Unix philosophy”. No more words were necessary, I installed it and I’ve been in love with it ever since, and excited about the many possibilities it offers that have not yet materialized.

The two Firefox plug-ins I liked the most were vimperator, and another one that allowed me to edit text-areas inside with external editors, e.g. emacs. uzbl comes with that “out-of-the-box”, it’s built upon these concepts.

Part of that philosophy is also that there should not be a thing like a “tabbed browser”. We should have one program instance per web page being viewed, and they should cooperate nicely. That is one of the aspects of Firefox I dislike the most, the way it is monolithic , and uzbl moved to the right direction.

Now, of course it’s not easy to just install uzbl and start using it, and having the same experience of using Firefox’ tabs. Some uzbl people are trying to remedy that creating a python script that effectively acts as a window manager, presenting the windows of the different instances with menus etc…

Myself, I didn’t even try it. I saw, as many other did, the perfect chance to instead make my window manager work for me into creating the “tabbed browser” experience by managing uzbl’s windows the proper way. And of course, I am not talking of any windows manager, but of the Awesome windows manager, “awm” or however we should call it so it’s better to find in Google. Awesome is pretty awesome in that it is highly configurable and scriptable, and it should be possible to fit it into my “tabbed-browsing with uzbl” needs.

***

Now, what to do? How exactly do we need to modify Awesome’s standard behaviors? I didn’t know it myself until I started working…

What do we want? The first requisite is very clear to me: we want maximized windows, and change between them with a hotkey. And there is an easy way to do that with Awesome by default, just use the “max” layout, put all your browser clients on the same tag, and screens will be maximized, and switchable using the standard mod-{j,k} keys.

That is OK, but I didn’t like that because of some details. I would prefer to stay in my usual vertical tiling layout as much as possible. That means I can, for example, bring quickly an “intruder” window to that tag, like an editor, and then I will have the two windows tiled there.

Being on the tiling layout also means that when I open a new browser window the focus doesn’t just immediately move to it, neither the page gets loaded on the background. I can have for a moment two open windows, and only after I see the second window loaded, I will then maximize it (yes, I could just be notified somehow, but I do prefer to see that blank window getting filled while I can keep looking at the parent.) These are all small details that can make a lot of difference, and being able to configure programs to satisfy these small needs are the kind of freedom that FLOSS hackers like so much.

So the max layout was out of question. What I needed was something that allowed me to stay in a tiling layout, but managed the windows maximizations…

One possibility was also to go on maximizing windows with the default mod-m key. That also works a bit, but still not what I wanted. I wanted the “maximized” windows to be just standard windows in the tiling layout, that will share the space if I decide to open up new windows. a maximized window is different than a single window in a tiling layout!…

So what I needed was some way to minimize all windows, except one, that would be the “active” window, the “maximized” window. And when needed I could easily bring windows to share the tag, or open more than one “tab” at the same time by de-minimizing other clients…

To do that I then wrote this small Lua script. Some lines of code say much more than a thousand words… Feels very weird to write this large blog post because of just this small detail! But that’s how things are, isn’t it?

-- This function minimizes and restores clients in a tag in sequence.
-- It just looks for the first non-minimized client, and minimizes it,
-- and then depending on the direction specified, restore either the
-- "next" or the "previous" client.
function minimize_cycle(direction)
   local vistag = awful.tag.selected(mouse.screen)
   local clis = vistag.clients(vistag)
   local who = 0

   for i,cli in ipairs(clis) do
      if not cli.minimized then
         cli.minimized = true
         who=i
         break
      end
   end
   if direction=="up" then
      clis[math.mod(who, #clis)+1].minimized=false
   elseif direction=="down" or true then
      clis[math.mod(who+#clis-2, #clis)+1].minimized=false
   end
   
end

-- And here is just how to bind it in the globalkeys list
--(...)
    awful.key({ modkey,         }, "[", function ()
        minimize_cycle("up")
    end),
    awful.key({ modkey,         }, "]", function ()
        minimize_cycle("down")
    end),
--(...)

I started writing this function specifically to uzbl clients, but then I realized that wasn’t needed, I could just pick up the list of clients of a single tag and do the thing. After doing this I suddenly had the same control over other application I needed that but couldn’t see what I could do. For example, now I can open up two separate xterm windows running irssi and switch between them, doing “tabbed” irc. I can also throw in my twitter client on the same tag, and it is ust another “tab” with all the advantages of the tiling layout whenever I need it…

Isn’t it neat? 🙂 I’m very happy with that setup of mine, I hope that by telling my story I can help other people to satisfy their interfacing needs.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s