I have seen this topic brought up a number of times in this forum and thought I would share my findings. Feel free to comment.
Note: The following has only been tested with:
- Leap 16 and Tumbleweed
- GNOME desktop environment
- Myrlyn 1.0.0
- The built-in GNOME theme (Adwaita)
A few things are necessary for Myrlyn (Read-only and Root) to follow the style (Default or Dark) selected in GNOME Settings (section “Appearance”) of the invoking user.
To have Myrlyn (Root) follow the window style it is necessary to make a few small changes to script “/usr/bin/myrlyn-sudo”.
First, copy the script to your own directory “~/.local/bin/” as you don’t want to make changes to stuff in “/usr/bin/”. Then add the three lines marked with a # New line comment below:
#!/bin/bash
#
# Wrapper around 'sudo' for Myrlyn that can open a graphical password prompt
# and that can keep the connection to the display (X11 or Wayland) alive
# as well as some well-defined environment variables.
#
# Author: Stefan Hundhammer <Stefan.Hundhammer@gmx.de>
# License: GPL V2
MYRLYN_ARGS=$*
MYRLYN_SUDO_CONF=$HOME/.config/openSUSE/myrlyn-sudo.conf
if [ -f $MYRLYN_SUDO_CONF ]; then
# echo "Reading variables from $MYRLYN_SUDO_CONF"
source $MYRLYN_SUDO_CONF
fi
# Environment variables to keep for the 'sudo' call
ENV_KEEP="DISPLAY WAYLAND_DISPLAY XAUTHORITY XDG_RUNTIME_DIR \
QT_QPA_PLATFORMTHEME QT_ENABLE_HIGHDPI_SCALING QT_SCALE_FACTOR \
LANG LANGUAGE LC_MESSAGES LC_COLLATE LC_NUMERIC LC_TIME LC_ALL"
# New line
ENV_KEEP+=" XDG_CURRENT_DESKTOP"
# You can set any of them in ~/.config/openSUSE/myrlyn-sudo.conf like this:
#
# QT_QPA_PLATFORMTHEME=qt6ct
# QT_ENABLE_HIGHDPI_SCALING=0
# QT_SCALE_FACTOR=1
# New line
XDG_RUNTIME_DIR=/run/user/0
# Build an environment for use with /usr/bin/env from the above variables:
# DISPLAY=:0.0 LANG=de_DE.utf8 ...
ENV=""
for VAR in $ENV_KEEP; do
VALUE=${!VAR}
if [ -n "$VALUE" ]; then
# Uncomment for debugging
# echo "$VAR=$VALUE"
ENV="$ENV $VAR=$VALUE"
fi
done
# Uncomment for debugging
# echo $ENV
# New line
XDG_RUNTIME_DIR=/run/user/$UID
# Use our own askpass binary to for a graphical password prompt
ASKPASS=/usr/bin/myrlyn-askpass
# Using /usr/bin/env to set up an environment inside the 'sudo' call,
# not relying on what 'env_keep' in /etc/sudoers might allow or not.
#
# The main command that is called here is /usr/bin/env which builds
# the environment and then calls myrlyn with $MYRLYN_ARGS.
SUDO_ASKPASS=$ASKPASS sudo -A /usr/bin/env $ENV /usr/bin/myrlyn $MYRLYN_ARGS
Now Myrlyn (Root) will follow the window style of the invoking user, that is, look like Myrlyn (Read-only). There is no need to login as Root to make any changes.
If “Dark” style has been chosen in GNOME Settings one additional change has to be made:
Open GNOME Tweaks (install if not already installed) and go to section “Appearance”. Set item “Legacy Applications” to “Adwaita-dark”.
Streamlined a little bit and shamelessly commited upstream:
It’s before reading ~/.config/openSUSE/myrlyn-sudo.conf so users can override it if desired.
Please test, especially dark theme lovers and KDE Plasma users!
It works flawlessly for me on Xfce4 on Slowroll with all available light and dark themes.
It’s just a little thing, but this would be worth releasing as Myrlyn 1.0.1 if it doesn’t cause any problems (which I doubt).
I am afraid that your new script does not work, at least not on GNOME. With your script the close button on the Myrlyn window title bar is missing.
Only when setting XDG_RUNTIME_DIR=/run/user/0 before you build the ENV variable does it work correctly. I am not sure if it is necessary to set it back to XDG_RUNTIME_DIR=/run/user/$UID after the “for” loop.
Think about it: The effective user when running Myrlyn is “root” so using XDG_RUNTIME_DIR=/run/user/0 to me seems reasonable in the environment for Myrlyn.
OK. I tried that, and I wondered why you set it first to 0 and then to the real user again. I do understand using $UID for using the user’s theme when running Myrlyn as root, but using 0 means that root uses root’s settings (and thus theme), so I am not sure why this even changes anything. And setting it back to $UID after the environment is created should really not have any effect because all environment variables are expanded to their previous content when passed to the env command.
I do have all window manager decorations, but of course I am using the Xfce4 window manager which may behave differently. Let me experiment some more.
Now Myrlyn (Read-only and Root) works in GNOME, both “Default” and “Dark” style.
As I mentioned in the OP if using “Dark” style, it is unfortunately necessary to use the GNOME Tweaks application (Appearance section) to change “Legacy Applications” to “Adwaita-dark”. Otherwise, Myrlyn (Read-only and Root) will have a dark title bar while the rest of the window is light.
I guess the problem is the same for other applications not built with GTK4. I do not use “Dark” style myself so have no real knowledge.
Could you try again with that XDG_RUNTIME_DIR=/run/user/0 changed into
XDG_RUNTIME_DIR=/run/user/$UID
@cbravo had problems with that, but I have that gut feeling that it would make more sense if root would use the user’s runtime directory. Sadly, there doesn’t seem to be very much documentation how that all interacts with each other.
No, you don’t need it unless you want to set some variables for your specific setup; like this:
[sh @ meteor] ~ 24 % cat .config/openSUSE/myrlyn-sudo.conf
# Qt theme to use
QT_QPA_PLATFORMTHEME=qt6ct
# No high-DPI scaling - it only results in pixel mush
QT_ENABLE_HIGHDPI_SCALING=0
QT_SCALE_FACTOR=1
On my 128 dpi / 14" laptop that Qt would otherwise massacre:
But if you don’t have this problem, you don’t need those special settings.
Sorry, I meant a different file: myrlyn-sudo in the local bin directory;
~/.local/bin/myrlyn-sudo
If I do not set it to executable it doesn’t work for me. If it is set to executable it does work. Maybe I have some other issues.
First picture, not set to executable:
If you just call it from a shell with myrlyn-sudo, it may find /usr/local/bin/myrlyn-sudo - and ignore it because it’s not executable, and then try other directories in your $PATH until it finds /usr/bin/myrlyn-sudo which is executable, but probably also the older one from the myrlyn package that you have installed.
If /usr/local/bin/myrlyn-sudo is executable, it will be used instead, and if this is the newer one from the GitHub repo, it has those recent changes and will apply your desktop theme.