[crossfire] GTK-v2 Client Theme Extension

Kevin Bulgrien kbulgrien at att.net
Wed Apr 21 00:02:37 CDT 2010


I plan to extend the theme support in the GTK-V2 client slightly - to make it
easier to customize the UI appearance without having to have access to the
client theme directory, and to allow pin-point customization.

The GTK-V2 client uses standard GTK rc files to implement the client themes.
If the player did not configure a theme (None), the client uses GTK default
style/theme setup from conventional places like <SYSCONFDIR>/gtk-2.0/gtkrc
and ${HOME}/.gtkrc-2.0.

If the player has configured a custom client theme like "Standard" or "Black",
the client adds the pathname of the selected theme file to the list of RC
files that GTK will use for the client session.

My extension will add to this in the following way.  Whether the player has
picked a theme or not, the client will add the following pathnames to the
default RC file list:

  ${HOME}/.crossfire/gtkrc
  ${HOME}/.crossfire/<layout>.gtkrc

This means that a player can now setup their own theme in the gtkrc file
without having to have access to the client themes folder.  The gtkrc file
is universally applied, so it can either enhance a client theme like Black
or Standard, but it will also be used when the theme is None.  What does
this mean:

For example, if ${HOME}/.crossfire/gtkrc contains:

style "default"
{
    font_name = "Sans 8"
}
widget_class "*" style "default"

All fonts in the client are set to Sans 8.  Properties like italics, and
bolding still get set normally.  This may not be an ideal example, but
it gets the point across.

The second thing the extension does is allow for a glade-layout-specific
theme file.  For example, if, at run-time, the client is using sixforty.glade,
after looking for ${HOME}/.crossfire/gtkrc, it will next look for a
${HOME}/.crossfire/sixforty.gtkrc file and use it if it exists.

The point of this is to allow particular layouts to be tweaked by the player
without impacting other layouts.  The idea is that if one wanted to use a
particular layout on a laptop when not connected to a really big monitor,
you could even go so far as to customize the theme, not just the layout.

When you get back home to the really big monitor, instead of fiddling with
all your settings, you just switch layouts and can still have custom
settings that only apply to it.

Now, I realize this is a pretty geeky feature that is probably not going to
get a lot of use as-is, but I think the options it adds are good because it
puts the power in the player's hands without them having to have access to
the "official" theme folder.  But more than that, what it opens up is a
possibility that at some point in the future, the client itself could put
stuff in one or the other of these files, though I do not have a short-term
plan to implement that at this time.

Why am I doing this.  There are a few basic reasons.  1) I liked that the
GTK-V1 client rendered its widgets using a smaller font than GTK-V2 did.
2) Until yesterday, I never really figured out how to change GTK-V2 to
use smaller fonts.  Though I can wiki what I learned, it seems better to
be able to wiki something that is client-specific that will not affect
all other GTK applications the user might run.  3) I am still working on
a player request for a working 640x480 layout, and I have one, but the
giant font sizes are a real pain because they soak up so much space.  I
envision having some kind of sixforty.gtkrc file up somewhere and then
referencing on a FAQ.

You might ask why not just distribute a new SixForty theme file...  Well,
I thought of that, but then when I saw how simple it was to force a smaller
font, I thought it was kind of silly to copy/paste/tweak Standard just to
get a font size change, and, as is not presently the case with .glade files,
this allows a very-special purpose file to be left out of the distribution,
but very easy to install (copy to the .crossfire folder).

Note that it doesn't matter in the least whether the ${HOME}/.crossfire
gtkrc or <layout>.rc files are present or not.  GTK happily goes along
doing what it always did before if it does not find the files.  This means
that nobody will notice any difference in the client behavior.  The original
themes will continue to work as they always have.

Kevin Bulgrien



More information about the crossfire mailing list