2

I have a computer with two (non simultaneous) users who are both in the sudo group. Is there a way to preserve the user's GTK theme with gksudo, for instance when running the update manager? By default the Raleigh theme is used.

I use Lubuntu 14.04 with a simple window manager (Blackbox) and no display manager.

2 Answers 2

1

I'm not sure why applications launched through gksudo aren't using your user's theme. It works for me on a full Lubuntu system. (But that uses Openbox, not Blackbox.) Fortunately:

  • The best solution for a program like the Update Manager is probably to install polkit (which is normally present) and run the Update Manager without gksudo. (See Way 1 below.)
  • For applications that do have to be started as root, or if you don't want polkit installed, a workaround is to specify the theme you want with GTK_THEME (see Way 2 and Way 3).

Way 1: Install polkit (a.k.a. PolicyKit).

The best solution for utilities like:

  • Software Updater / Update Manager (update-manager)
  • Ubuntu Software Center (software-center)
  • Lubuntu Software Center (lubuntu-software-center)
  • Software & Updates (software-properties-gtk)

...and many of the other system administration utilities in Ubuntu, is to just not run them as root at all.

Normally you don't need to run these utilities as root because they integrate with polkit and use it (instead of sudo) to perform authentication (just) when neccessary. Since the program showing you the user interface actually runs as you and not as root, it displays in accordance with your user account's configuration.

Typically nothing special must be done to achieve this, even on a Lubuntu system. Ubuntu is designed so that these utilities can just be run as a non-root user, without any special configuration.

But since your system is especially minimal, you probably don't have polkit installed. You can get it by installing the policykit-1 Install policykit-1 and policykit-1-gnome Install policykit-1-gnome packages.

sudo apt-get update
sudo apt-get install policykit-1 policykit1-1-gnome

With polkit installed, these utlities should automatically use it and won't need to be launched as root.

However, this may not be suitable:

  • if you don't want to install polkit, or
  • for running GTK+ programs as root that haven't been written to use polkit (such as Leafpad or Gedit).

Way 2: Set the desired GTK+ theme when you run gksudo.

Suppose you wish to run gedit as root. Note that this technique works the same way for other GTK+ programs (such as the Update Manager).

Instead of running gksudo gedit, you can run:

gksudo env GTK_THEME=HighContrast gedit

Replace HighContrast with the name of the desired theme.

(I use env because although sudo supports sudo VARIABLE=name command syntax, gksu/gksudo does not.)

Way 3: Make a launcher that that sets the desired theme.

This is the same as Way 2, just running your program through a launcher rather than typing a command each time.

To make a shortcut to run a program (like gedit) with a particular GTK+ theme (like HighContrast) as root in LXDE, run:

lxshortcut -o ~/Desktop/'gedit (as root)'

In place of gedit (as root), put whatever you want as the launcher's display name.

In the File Properties window that comes up when you run that command, click the Desktop Entry tab. In the text box labeled command, put:

gksudo env GTK_THEME=HighContrast gedit

You can leave everything else blank and just click OK.

If you want, you can use the full paths of the executables being run (/usr/bin/gksudo and, in this example, /usr/bin/gedit.) But this is not generally necessary.

enter image description here
Making a launcher for gksudo env GTK_THEME HighContrast gedit. (The left part of the command is not visible.)

6
  • Thanks for the detailed answer. Actually, I have policykit-1 and policykit1-1-gnome installed but when I launch update-manager (as non-root) it is first checking for updates and then a dialog pops up saying "You are not allowed to perform this action". Aug 31, 2014 at 11:58
  • When I run gksudo env GTK_THEME=HighContrast gedit Gedit still uses the Raleigh theme although I have HighContrast in /usr/share/themes/. Setting the theme in ~/.gtkrc-2.0 and ~/.config/gtk-3.0/settings.ini works. Maybe something is incompletely configured. Aug 31, 2014 at 12:02
  • @AugustKarlstrom Does GTK_THEME work at all on your system--that is, even without gksudo? That is, suppose your user's configured theme is something other than HighContrast (so, when you just run gedit, it runs with some other theme). Does GTK_THEME=HighContrast gedit work to make it run with the HighContrast theme? (You don't need the env when leaving off gksudo, though it should work the same with and without the leading env.) Aug 31, 2014 at 20:42
  • The command GTK_THEME=HighContrast gedit launches Gedit with the user's GTK theme, i.e. setting GTK_THEME has no effect. Sep 1, 2014 at 14:11
  • If I understand your comment, you've set your theme in the way you described here. Interestingly, I tried that on a "regular" Lubuntu system (using openbox instead of blackbox) and it didn't change the theme for me (but setting GTK_THEME does work for me with openbox). ...What happens if you create those config files for the root user, then try gksudo again? For example, for GTK+3, /root/.config/gtk-3.0/settings.ini (/root = root's home dir) with the desired config. Sep 4, 2014 at 23:18
0

I actually have the same problem as I use i3wm. I suppose since you are using Lubuntu, you should have lxappearance installed. Run that with gksudo, then you should see your theme for gksudo selected. Change and apply that, you should have the theme desired for the gksudo.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .