Setting a custom Gtk theme for specific applications

July 13, 2008

I’m not entirely sure why you’d want to use this, but it does get asked from time to time: How can you use a different Gtk theme, icon theme and/or fonts for specific Gtk applications?

If you just want to change the Gtk theme, you can launch your application with the following command:

	GTK2_RC_FILES=/path/to/your/theme/gtkrc application-command

Thus “GTK2_RC_FILES=/home/urukrama/.themes/royalty/gtkr-2.0/gtkrc thunar” will use the Royalty theme for Thunar. Note that this will use the default font and icon theme, not the icon theme or font you specified in your ~/.gtkrc-2.0 or ~/.gtkrc.mine file.

If you’d also like to set a custom icon theme and font for the application, create an empty file, wherever you find convenient (for example in /home/USERNAME/.themes) and call it whatever you want (for example, custom.gtkrc). Then add the following to that file:

		#To set the Gtk theme
		include "/path/to/your/theme/gtkrc"
		
		#To set the icon theme
		gtk-icon-theme-name = "GnomeCorsair"
		
		#To set the font
		style "Sans"
		{
		font_name = "Sans 8"
		}
		widget_class "*" style "Sans"
		gtk-font-name = "Sans 8"

Change ‘GnomeCorsair’ to the icon theme you’d like to use, and “Sans” to the font you prefer. The /path/to/your/theme/gtkrc is what it says (for example /home/urukrama/.themes/royalty/gtkr-2.0/gtkrc). If you would only like to have a custom icon theme or font, only specify those and leave the rest out.

To launch Thunar with these settings, use the following command (If you saved the file elsewhere, adjust the path accordingly):

	GTK2_RC_FILES=/home/USERNAME/.themes/custom.gtkrc thunar

If you want to use this in a launcher such as Openbox’ menu, rather than the terminal, try the following:

	bash -c 'GTK2_RC_FILES=/path/to/your/gtkrc application-command'

I haven’t managed to get this working with either the gnome-settings-daemon or the xfce-mcs-manager running. It seems they override this.

As proof that this works, here is a screenshot of two instances of Mousepad running, one using the default theme, the other launched with a custom gtkrc:

About these ads

25 Responses to “Setting a custom Gtk theme for specific applications”

  1. volante said

    thank you, for me this is very useful

    i like black themes, but icon in firefox are awful with that themes

  2. 3ark said

    Yes, this is often used by people who enjoy dark themes. Its a great work around for things like OpenOffice which will force the ugly high-contrast icons into use on dark themes. This blog is incredibly useful by the way, keep it up!

  3. Daniel Añez said

    it doesnt work for me :S i have linux mint6 and open office.org 3.0 and i tried those steps! maybe it doesnt work in the latest version of gnome?
    look at the command of the launcher i made:

    bash -c GTK2_RC_FILES=/home/daniel/.themes/Shiki-Wise/gtk-2.0/gtkrc openoffice.org3 -writer

    and i get get the same openoffice window with my blue-joy theme and the ugly high-contrast look =/

  4. Daniel Añez said

    i guess you dont have the time to answer =/

  5. urukrama said

    I’m not sure this works with OpenOffice, which isn’t really a GTK application (but emulates GTK).

  6. Edu said

    Thanks you, it work with OOo but only with some themes.

  7. @ Daniel Añez:
    Your command will work when you add the missing quotation marks.

  8. daspostloch said

    Hi urukrama, thanks, this would actually solve a lot of problems with small apps and my dark theme for me. However, I think I’m in the gnome-settings-daemon case.
    At least it doesnt work for me and I set my gtk theme via
    System->Prefs->Look and feel->appearance under Fedora/Gnome. So do you know another way to set a gtk theme, circumventing this gnome setting thing?
    Thanks, dpl

  9. tscheka said

    hi,

    i posted a bug report a while ago on this.

    http://www.openoffice.org/issues/show_bug.cgi?id=106620

    openoffice would have pretty much use for this, afaik. is there any way making theme exceptions for Qt, btw?

  10. [...] The solutions was to use a custom GTK theme and setting this using an applications specific GTK setting [ref]. [...]

  11. Rockadoodle said

    Hi, i found this article and it is nice.

    is there any chance to do this under gtk3???

  12. how can i use dark adwaita for inkscape?

  13. xkr47 said

    In my experience, the procedure by which the theme is chosen in GTK-2 is as follows:

    1. If defined in GConf (gtk2) or GSettings (gtk3), use that one
    2. Otherwise, if GTK2_RC_FILES is set, use that one
    3. Otherwise, if $HOME/.gtkrc-2.0 is found, use that one
    4. Otherwise, use default theme (whatever that is)

    So if GConf or GSettings has been set to some valid theme, GTK2_RC_FILES has no effect.

    So in order to be able to do theme override, we need to
    a) get rid of the theme in GConf/GSettings
    b) create a $HOME/.gtkrc-2.0 instead to set the user’s default theme
    c) then we can use GTK2_RC_FILES to override the theme

    So, let’s do this!

    If we used one of the regular system themes, they are probably found in /usr/share/themes/. Let’s say we want to use the Crux theme by default. This is one way to do it:

    ln -s /usr/share/themes/Crux/gtk-2.0/gtkrc $HOME/.gtkrc-2.0

    Then we clear the theme setting in GConf or GSettings, using either of the following commands:

    gtk2: gconftool-2 –set /desktop/gnome/interface/gtk_theme –type string “”
    gtk3: gsettings set org.gnome.desktop.interface gtk-theme “”

    Hopefully this helps.

    If things get messed up due to my instructions, just remove the $HOME/.gtkrc-2.0 file and use your favourite theme selection tool to restore the theme setting or alternatively one of the following commands:

    gtk2: gconftool-2 –set /desktop/gnome/interface/gtk_theme –type string “Crux”
    gtk3: gsettings set org.gnome.desktop.interface gtk-theme “Crux”

    Good luck! :)

  14. Morgen said

    Hmm, I have the gsettings and gconftool-2 values set and it still works flawlessly for me.

    Thanks for this! Gnuplot with a dark background is a pain in the neck to see what’s going on.

  15. kerenskyy said

    thnx!
    i’m interested in this b/c latest tixati either freezes or evaporates when using oxygen-gtk.

  16. > I’m not entirely sure why you’d want to use this, but it does get asked from time to time: How can you use a different Gtk theme, icon theme and/or fonts for specific Gtk applications?

    One reason for me: Eclipse. It uses the system colors for stuff like tooltips, but for some reason, renders it badly. In my case, setting Eclipse to not use system colors does not work. So, the only other option is to customize the theme. Eclipse 4.2 (Juno) supposedly allows all views to be customized, but not upgrading to that heap of crap.

  17. kerenskyy said

    i see now on slackware this is not necessary. wonder what the difference is compared to kubuntu…

  18. Does it work on ubuntu 12.04 ?

    • kkk said

      can’t see why it would not, unless Canonical changed the GTK runtime found in 12.04 to remove it.
      Have you tried it?

  19. Yes. But nothing happened. I have tried different themes, but without success. In ubuntu 10.04 – 10.10 it works.

    • jeckyl said

      Hi,
      I’m using kubuntu 12.10. Tixati, ( a gtk software), freezes when using oxygen-gtk theme so I use “GTK2_RC_FILES=/usr/share/themes/Nodoka-Squared/gtk-2.0/gtkrc tixati” to launch the program. And it consistently works so far.
      Additionally, after entering “GTK2_RC_FILES=/usr/share/themes/Nodoka-Squared/gtk-2.0/gtkrc” in konsole & pressing Enter, should i type “filezilla” in konsole and hit Enter, Filezilla launches using Nodoka-Squared theme.

      What happens if u use “/usr/share/themes/Raleigh/gtk-2.0/gtkrc” ?

      Sorry I can’t be more help. Best of luck!

  20. ngolo said

    this doesn’t seem to be needed on up to date fedora core 18 when using tixati. nice.

  21. I’m using ElementaryOS Luna, and I would really really like a better theme than this high-contrast ugly one in Audacity. Does this work? I haven’t tried, because it looks very complicated, and I would have to spent much time on it, so if I could just have som,eone confirm it works in EOS… thanks.

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

Follow

Get every new post delivered to your Inbox.

Join 81 other followers