Can I apply a different GTK3 theme from the main one to an individual application?

39,584

Solution 1

You can use the GTK environment variable GTK_THEME=elementary to launch an app with the elementary theme. For example, running GTK_THEME=elementary pantheon-files will launch the elementary Files app using the elementary GTK theme.

To get this to apply every time you launch a specific app, your best option is likely to create a custom .desktop file (launcher).

Create a custom .desktop file

  1. Open your file browser
  2. Navigate to /usr/share/applications/
  3. Copy the launcher (highlight and Ctrl+C) for the app you want to launch with the elementary theme
  4. Navigate to ~/.local/share/applications/ and paste the launcher (Ctrl+V)
  5. Right-click and open the launcher with a text editor
  6. Modify the line starting with Exec= to include Exec=env GTK_THEME=elementary and then the previous existing contents of the line. (So Exec=pantheon-files would become Exec=env GTK_THEME=elementary pantheon-files)
  7. Save and close the file

The next time you launch the app from Unity (or your app launcher of choice) it will use the elementary theme.

Bonus: make it work when using command line

You may also want the app to launch with the elementary theme when launching it from the command line. To do so:

  1. Open your Terminal app
  2. Type alias pantheon-files="GTK_THEME=elementary pantheon-files" (replacing pantheon-files with the desired app)
  3. Press Enter

Caveats:

  1. This will not change your window manager's theme to the elementary theme.
  2. This (by design) will only apply to your account, not root or anyone else on the machine.
  3. The theme names are cAsE-sEnsItiVe and should be matched with the theme folder name.

Sources:

  1. I'm an elementary contributor ;)
  2. GTK+ 3 Reference Manual: Running GTK+ Applications
  3. Set variable in .desktop file

Solution 2

The question is still valid and I found a way:

  • create any folder path/to/MY_FOLDER

  • create a /share/themes/ folder inside it (that is path/to/MY_FOLDER/share/themes).

  • put any GTK3 theme inside the latter

  • rename the theme to the name of the CURRENTLY ACTIVE THEME.

    At last, this command will make an app use the renamed theme instead of the currently active one:

GTK_DATA_PREFIX=path/to/MY_FOLDER YOUR_APPLICATON

(The path after GTK_DATA_PREFIX= has to be that (and only that) to the folder that contains /share/themes/RENAMED_THEME. That's why it's NOT path/to/MY_FOLDER/share/themes/RENAMED_THEME, but just path/to/MY_FOLDER.)

To have that inside a launcher, replace accordingly:

Exec=sh -c 'GTK_DATA_PREFIX=path/to/MY_FOLDER YOUR_APPLICATION'

Solution 3

Its certainly possible, I don't have much of themeing experience, but when you navigate to /usr/share/themes/*Theme Name*/gtk-3.0/apps/ directory, you'll find .css files, named with apps they target to theme, so yes you can create app-specific Themes.

Note that the way you mentioned to theme your apps may require some work to be done (like having both Ambiance and Elementary work simultaneously, since every theme has a base file on top of which app specific styling is done, (a file gtkrc in Gtk 2.0 while, a file gtk.css in case of Gtk3.0).

And this base theme file contains styling rules that specifically target the given theme, hence you cannot create Elementary like look and feel from Ambiance's base theme file without making some heavy changes, and even if you do, you'll loose Ambiance look itself.

Also, in GNOME, it is possible to have only single theme applied at a time, For Example, if you have used Appearance window in Ubuntu 12.04, you know can can select any single theme from the dropdown, in case you have used gnome-tweak-tool, than you can set different themes, for Gtk, Window frames, and icons, but still, it doesn't allow to target specific applications to theme, so as I said earlier, you can set totally different themes for different applications if you cleverly work with base theme file, as of now, no third party applications can do it by itself.

One way you can do it by yourself is that, let the base theme file (gtk.css) have only essential rules which are neutral to any theme, being dark or light. And have the actual theme design written in app-specific files that reside in above mentioned directory, i.e. for styling Nautilus, you can write all required properties in nautilus.css file. Same with every app you wish to target. Obviously, doing such requires some decent Gtk themeing experience.

You may refer this for creating your own theme using template, Also there's a decent documentation on Gtk+ themeing.

Solution 4

Yes, the simple way is to point the application at the required path where your rc file lives, in the command that runs your application:

GTK2_RC_FILES=/usr/share/themes/Redmond/gtk-2.0/gtkrc inkscape

This on 12.04 for inkscape (which is still Gnome2 btw) produces this:

inkscape window with windows theme

See more information about Gtk2 theme running here.

Solution 5

Yes you can, actually I googled and got some answers:

  1. Look for the exact executable for the program you want to change the theme. For example, if you want it for ooffice then type which ooffice in the terminal.
  2. Look for the bin folder where all applications put their binary executables. Type echo $PATH in the terminal and you will ge the path. I recommend you to create a bin folder in your home directory by typing mkdir ~/bin
  3. Type gedit ~/.bashrc to open your bash rc file.
  4. Go to the bottom of this file and add this line export PATH=~/bin:${PATH}

Now we will create a script which will execute your program with custom theme:

  1. Create application's script file by typing: gedit ~/bin/ooffice
  2. Type these lines in the opened file:

    #!/bin/bash
    env GTK2_RC_FILES=/usr/share/themes/SlicknessX/gtk-2.0/gtkrc /usr/bin/ooffice "$@"
    
  3. Change the mode of the file to executable by typing: chmod +x ~/bin/ooffice.

Hope this helps, you have to remember only one thing, the format of the script as shown below:

#!/bin/bash
env GTK2_RC_FILES=PATH_TO_GTKRC PATH_TO_EXECUTABLE "$@"
Share:
39,584

Related videos on Youtube

matt
Author by

matt

Updated on September 18, 2022

Comments

  • matt
    matt almost 2 years

    For example, can I keep Ambiance as main theme but assign elementary theme to elementary's app?

    • neonboy
      neonboy about 12 years
      Current answers ara about Gtk2, I am asking about Gtk3.
    • ish
      ish about 12 years
      I edited the question to better reflect what you seek. Sorry, but the short answer from my research is no, you cannot without having to spend some effort creating a new "hybrid" theme as @Kush explained :( It's not as simple as GTK2 any more.
  • ish
    ish about 12 years
    It is certainly possible for GTK2 apps using GTK2_RC_FILES env. variable. Also, what themes are you talking about compiling? The question is about systemwide GTK themes available in Ubuntu.
  • Marceau
    Marceau about 12 years
    I believe the method you mentioned targets Gtk2.0 while Ubuntu 12.04 uses Gtk3.0 for themes, so if might not work.
  • neonboy
    neonboy about 12 years
    I'm sorry, that's a solution for Gtk2, question is about Gtk3.
  • neonboy
    neonboy about 12 years
    I don't want to create a new theme, I want to assign an existing one.
  • Marceau
    Marceau about 12 years
    @neonboy: As I said that with GTK3, its not that simple, a theme is distributed across multiple files, and if dependencies are not satisfied, broken theme is all you'll get. That's why I posted the answer that shows possible solution with GTK3, and not GTK2 (in which doing this is fairly easier).
  • Martin Owens -doctormo-
    Martin Owens -doctormo- about 12 years
    You didn't specify that in your original question. Please no antagonise the questioneers.
  • neonboy
    neonboy about 12 years
    Originally it was "Can I use different GTK3 themes for individual apps?" wich still had Gtk3 subject in the question, then foss freedom ask me to comment on non valid answers and edit the question if it was necessary, I'm not antagonise anyone.
  • Redsandro
    Redsandro about 10 years
    Nice reply but I cannot get this to work for any theme. Can you give an example using terminal, find /usr/share/themes -type d -name 'gtk-3.0' | awk -F'/' '{print $5}' and gedit for demonstration purposes? E.g. GTK_THEME="HighContrast" gedit or env GTK_THEME="HighContrast" gedit or GTK_THEME=Adwaita:dark gedit... nothing.
  • Drew Chapin
    Drew Chapin almost 10 years
    I just changed it in /usr/share/applications/<appname>.desktop and it worked for me.
  • Has QUIT--Anony-Mousse
    Has QUIT--Anony-Mousse almost 10 years
    Any way to do this from code inside the app?
  • runDOSrun
    runDOSrun over 7 years
    which file/folder exactly do we point to using GTK_DATA_PREFIX?
  • Cedric Reichenbach
    Cedric Reichenbach almost 7 years
    It's worth noting that theme names are case sensitive.
  • Admin
    Admin over 6 years
    This works for some apps but not for all.
  • Admin
    Admin over 6 years
    This was rather confusing, but I have figured it out and edited the answer.
  • Admin
    Admin over 6 years
    Another way is to put the app-specific renamed theme in ~/.themes (the current active has to be in /usr/share/themes) and then use some path GTK_DATA_PREFIX=path/to/nowhere to launch that app, which will reset the app theme to the current one, only it will look first in ~/.themes and take the one with the same name there.
  • Admin
    Admin over 6 years
    @runDOSrun - the path after GTK_DATA_PREFIX= has to be that (and only that) to the folder that contains /share/themes/RENAMED_THEME. That's why it's NOT FOLDER/share/themes/RENAMED_THEME, but just FOLDER.
  • Admin
    Admin over 6 years
    can we do something similar in relation to the icon theme?
  • Scindix
    Scindix over 5 years
    Also it's worth mentioning that the env variable GTK_THEME works with actual paths. So if you want tons of different variations of the same theme for different applications, but don't want them all to show up at your global theme selector tool you may create a second folder (e.g. ~/.themes-apps) and use something like GTK_THEME=../.themes-apps/elementary-mint-green.
  • AlphaLife
    AlphaLife about 3 years
    +1 Works for codeblocks running in ubuntu 20.04 using adwaita theme. Orchis light theme had messed up my codeblocks colours.
  • Евгений Крамаров
    Евгений Крамаров over 2 years
    For apps that use QT5, as a GUI framework instead of env GTK_THEME=<ThemeName> use env QT_QPA_PLATFORMTHEME=<ThemeName>. It requires qt5-style-plugins apt package to be installed
  • Admin
    Admin about 2 years
    I tried this and thought it was not working, but it turns out I had already got an instance of the app working (in this case meld), and it only worked after I ran sudo killall meld before running the command again from the CLI. E.g. GTK_THEME="Adwaita" meld.