Friday, July 1, 2011

GUI to Change the Window Button Order, all Ubuntus

It's been a while since Canonical kicked off a more or less phylosophical controversy about where the window control buttons 'belong', or actually, where everyone wants to have them, when it started placing them on the left side by default, instead of where they were used to be, the right side. A lot of users, obviously, wanted to have them back on the right side, at least initially, understandably.

Now that Unity has been released, with the window controls in the Global Menu bar on the left, obviously, because the clock, the power button, the indicators and all that system stuff are on the right, it's rather the other way around. Seems like Canonical proved that they really had something in mind when they made the decision to move the buttons in the first place, isn't it!?

When I installed Lucid 10.04 back in October 2010, I, too, initially felt the need to put the window buttons back on the right side, so I picked up a script for a GUI to do that, also since most themes have window button settings included and are putting the buttons where they want, and not like you do, at least not half of the time. Later I modified the script to fit my needs and include some more options. This is about installing those GUI, the usage is too easy to be worth to explain in detail, as you can already see in the screenshot.

Sorry, the installation process may seem a bit multi-stepped, maybe I can provide a deb-package or PPA later.

Create the Script

1. In the Terminal, enter:

gksudo gedit /usr/local/bin/

2. Paste this into the text editor:

#!/usr/bin/env python
# A nifty GUI controlling the window controls position
# Depends on python-gconf (started from a python-gconf example)
# Author: alex(at)eftimie(dot)ro
# modified by: Krytarik

import gtk
import gconf

def callback(button, client):
    global left, leftmenu, right, rightmenu, key, entry
    if left.get_active():
        s = "close,minimize,maximize:"
    elif leftmenu.get_active():
        s = "close,minimize,maximize:menu"
    elif right.get_active():
        s = ":maximize,minimize,close"
    elif rightmenu.get_active():
        s = "menu:maximize,minimize,close"
        s = entry.get_text()
    client.set_string (key, s)

# Gconf stuff
client = gconf.client_get_default ()
key = "/apps/metacity/general/button_layout"

# Gtk window
window = gtk.Window()
window.set_geometry_hints(min_width=210, min_height=180, max_width=-1, max_height=-1, base_width=-1, base_height=-1, width_inc=-1, height_inc=-1, min_aspect=-1.0, max_aspect=-1.0)
window.set_title("Window Controls")
left = gtk.RadioButton(group=None, label='Left')
leftmenu = gtk.RadioButton(left, label='Left w/ Menu')
right = gtk.RadioButton(left, label='Right')
rightmenu = gtk.RadioButton(left, label='Right w/ Menu')
custom = gtk.RadioButton(left, label='Custom')
entry = gtk.Entry()
box1 = gtk.VBox(False, 0)
box1.add(gtk.Label("Choose position: "))
box2 = gtk.VBox(False, 0)
apply_button = gtk.Button('Apply')
done = gtk.Button('Done')
box3 = gtk.HButtonBox()
window.add (box1)
window.show_all ()

# Widget events
window.connect('delete_event', gtk.main_quit)
done.connect('clicked', gtk.main_quit)
left.connect ('toggled', callback, client)
leftmenu.connect ('toggled', callback, client)
right.connect ('toggled', callback, client)
rightmenu.connect ('toggled', callback, client)
custom.connect ('toggled', callback, client)
apply_button.connect('clicked', callback, client)

# If key isn't writable, then set insensitive
left.set_sensitive (client.key_is_writable (key))
leftmenu.set_sensitive (client.key_is_writable (key))
right.set_sensitive (client.key_is_writable (key))
rightmenu.set_sensitive (client.key_is_writable (key))

# Get current settings
if entry.get_text() == "close,minimize,maximize:":
elif entry.get_text() == "close,minimize,maximize:menu":
elif entry.get_text() == ":maximize,minimize,close":
elif entry.get_text() == "menu:maximize,minimize,close":

gtk.main ()

3. Save the file, quit.

4. Make the script executable:

sudo chmod +x /usr/local/bin/

Create the Launcher

1. In the Terminal, enter:

gksudo gedit /usr/share/applications/window-controls.desktop

2. Paste this into the text editor:

[Desktop Entry]
Name=Window Controls
Comment=Change the order of the window control buttons

3. Save the file, quit.

4. Update the menu item cache (otherwise done by dpkg during a usual installation/upgrade):

sudo rm /usr/share/applications/desktop.*.cache
sudo sh -c "/usr/share/gnome-menus/update-gnome-menus-cache /usr/share/applications/ > /usr/share/applications/desktop.${LANG}.cache"

Note: This last step can't be done in Oneiric 11.10, as it doesn't include those tool in the first place, and apparently doesn't do those caching anymore. There you just need to relogin for the new menu item to show up.


Once the steps are completed, you will find "Window Controls" under "System > Preferences" in classic Gnome, or by typing its name into the Unity Dash. The actual usage is really self-explanatory, as you can see in the screenshot at the top.

Related Posts:

Appearance , Usability