Justifying window titles

It was said that Metacity doesn’t let you decide whether titles of windows are left-justified (as in modern versions of MS Windows) or centre-justified (as on the Mac). But actually, it’s a theme issue to decide how a title is drawn. Here’s how to change your theme from centre-justified to left-justified.

First, find out what theme you’re using. We’ll use gconftool to do this, because it’s the easiest to demonstrate.

$ gconftool -g /apps/metacity/general/theme
Human

Okay, so we’re using Ubuntu’s Human theme here (you may well be using something else, of course; substitute its name for Human in what follows). Presumably you don’t want to work on the main system version of the theme, so take a personal copy and tell Metacity to use it:

$ cp -R /usr/share/themes/Human ~/.themes/LeftHuman
$ gconftool --type=string -s /apps/metacity/general/theme LeftHuman

It will switch to the new theme, but obviously it will look identical at present.

Unfortunately, as I mentioned the other day, there’s no fancy editor for Metacity theme files: you’ll have to edit the file by hand. But it only needs to be done once. So, open ~/.themes/LeftHuman/metacity-1/metacity-theme-1.xml in your favourite editor and search for <title (“title” preceded by a less-than sign, i.e. the opening of a “title” tag in XML). You will see that any of these you find have a formula for their x attribute that involves taking widths and halving them, which screams about centring. All you have to do is change this formula to zero for all the title tags in the file.

However, in the Ubuntu Human theme they obtain a shadow effect on the letters by printing the title multiple times at different tiny offsets. For cases like these, you need to keep the offsets in order to keep the shadow effect. So you’d change
<title color="shade/gtk:bg[SELECTED]/0.75"
x="(3 `max` (width-title_width)) / 2 + 1"
y="(((height - title_height) / 2) `max` 0) + 2"/>
<title color="shade/gtk:bg[SELECTED]/0.7"
x="(3 `max` (width-title_width)) / 2 + 2"
y="(((height - title_height) / 2) `max` 0) + 2"/>
<title color="shade/gtk:bg[SELECTED]/0.4"
x="(3 `max` (width-title_width)) / 2 + 1"
y="(((height - title_height) / 2) `max` 0) + 1"/>
<title color="#ffffff"
x="(3 `max` (width-title_width)) / 2"
y="(((height - title_height) / 2) `max` 0)"/>

to:

<title color="shade/gtk:bg[SELECTED]/0.75"
x="1"
y="(((height - title_height) / 2) `max` 0) + 2"/>
<title color="shade/gtk:bg[SELECTED]/0.7"
x="2"
y="(((height - title_height) / 2) `max` 0) + 2"/>
<title color="shade/gtk:bg[SELECTED]/0.4"
x="1"
y="(((height - title_height) / 2) `max` 0) + 1"/>
<title color="#ffffff"
x="0"
y="(((height - title_height) / 2) `max` 0)"/>

and so on throughout the file.

When you’re done:

$ metacity-message reload-theme

and presto!

You might say that this is a lot of work compared to just selecting a “left justify” button somewhere, and it is, but assuming your original theme file was free software, you can distribute derivatives of it. So you should feel free to give your new left-justified version to your friends or stick it up on the web somewhere. Don’t forget to add your name and copyright in the <info> section first.

4 Comments

  1. Mårten Woxberg
    Posted June 11, 2008 at 6:18 pm | Permalink

    This is great and all, but we have a zillion different configurations of themes. Wouldn’t it be easier just to have ha button to left/center/whatever justify?

  2. Posted June 11, 2008 at 6:41 pm | Permalink

    Are you saying that justification should not be a theme matter at all? In that case theme authors would lose the ability to place and style the title where they pleased.

    Or are you saying that justification should be a theme matter, but the window manager could be made to ignore it? But you could say that about everything else involved in a theme too.

    Of course a script could be trivially written in userspace which performs the work above and allowed you to have a left/centre/etc justify button. I like keeping things out of the window manager where possible.

  3. Mårten Woxberg
    Posted June 12, 2008 at 3:55 pm | Permalink

    I haven’t even thought of it as a problem, since I use the default setting of any theme.
    But It seems like there are ALOT of theme’s that are forks of popular themes that really could have been just color corrections or options in the main theme.

    Though this isn’t a Metacity problem.

  4. Posted June 12, 2008 at 4:00 pm | Permalink

    Mårten:
    It’s funny though– if a person looked at, say, Crux and decided they wanted it red, and they made it red, they could either have done so by going through some rather complicated set of reconfigurations, in which case they couldn’t easily share it with their friends, or they could have made it so that they made a theme file, in which case they could just give their friends the theme file.

    So I think what we have here, with the proliferation of versions, is a better example of the advantages of free software than most actual software. Users understand that they can modify themes even if they’re afraid of digging into code– so they do, and they share it. And nobody has to do patch review or anything, so everyone’s happy. ;)

One Trackback

  1. [...] be an obvious disproportionality.  Something that struck me today was Mårten Woxberg mentioning the proliferation of Metacity themes; I think we see so many of them because they’re something relatively harmless and easy for [...]