April 16, 2005 6:11 PM
Gtk themes can usually be selected via gnome-theme-manager though this is applicable only while your current desktop environment is Gnome. Here's another way to change your theme so that it's in effect even while you are on KDE.

First of all, get a GTK2 theme from a site like themes.freshmeat.net or gnome-look.org. My personal favourite is H2O Gtk2 Saphire. Then, extract the contents of the tar file to a suitable directory1. Now, since this is a GTK22 theme, create a ~/.gtkrc-2.0 file with the following contents in the case of H2O theme: (Updated 2005-04-22)

include "/home/anirudh/.themes/H2O-gtk2-Saphire/gtk-2.0/gtkrc"


gtk-theme-name = "H2O-gtk2-Saphire"

That is, just provide the path to the gtkrc file of the theme as an argument to the include directive in your ~/.gtkrc-2.0 file or set gtk-theme-name to the name of the theme.

gtk-theme-switch provides a simple GUI that will even let you preview themes besides from automating the above task. All you need to do is point to the theme's tar file and it will handle the rest.

If you want your custom GTK application to use a specific theme, just add the following C code with suitable modifications before you call gtk_init():

  gchar *rcfile = "/home/anirudh/.themes/H2O-gtk2-Saphire/gtk-2.0/gtkrc";
  gchar *rc_files[] = { rcfile, NULL};

  /* declare other variables */

  gtk_rc_set_default_files (default_files);

  /* initialize gtk */
  gtk_init (&argc, &argv);

  /* code that follows gtk_init here */

If you want to let the user pick a GTK+ theme and have it affect only your application, create a file in your application directory with gtk-theme-name set to the theme the user has selected. Then, simply add it to the set of default files before calling gtk_init(). Later, when the user selects another theme, overwrite this file with the new value.

  gchar *tmprc = "temprc.txt";

  /* declare other variables */


  /* Initialize gtk */
  gtk_init (&argc, &argv);

  /* code that follows gtk_init here */

CategoryProgramming Comment(s)

[1] Recommended: ~/.themes
[2] In the case of a GTK 1.x theme, edit the file ~/.gtkrc.

Copyright © 2004-2011 Anirudh Sasikumar. All rights reserved.
Last Updated: April 22, 2005 3:43 PM