Myrlyn and theming

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”.

5 Likes

Thank you!

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).

2 Likes

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.

1 Like
% myrlyn-sudo
DISPLAY=:0.0
XAUTHORITY=/ssd-work/home/sh/.Xauthority
XDG_RUNTIME_DIR=/run/user/0
XDG_CURRENT_DESKTOP=XFCE
QT_ENABLE_HIGHDPI_SCALING=0
QT_SCALE_FACTOR=1
LANG=en_US.utf8
LC_MESSAGES=en_US.utf8
LC_COLLATE=de_DE.utf8
LC_NUMERIC=en_US.utf8
LC_TIME=de_DE.utf8

(with the # echo $ENV line uncommented and reformatted for readability)

Please try the current one:

1 Like

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.

Strange. It works in Xfce without any special tweaks.

I am curious what the KDE Plasma folks have to report.

Hi!
I have tested this new script in Tumbleweed with KDE Plasma 6.6.0 and it doesn’t work.

In read-only mode it looks like this (following my user configuration and fonts):

In root mode, it doesn’t have my user configuration (you can see the font is different).

I get this logs if i run the scritp in a terminal:

Failed to create wl_display (No such file or directory)
qt.qpa.plugin: Could not load the Qt platform plugin "wayland" in "" even though it was found.

In any case, it’s much better than with the original myrlyn-sudo included in the distribution that looks like this:

I hope this information will help you.

Thank you very much for your great work.
Regards,
Isaac

I attach the ENV (executing with echo $ENV uncommented and reformatted for readability)

DISPLAY=:1
WAYLAND_DISPLAY=wayland-0
XAUTHORITY=/run/user/1000/xauth_UXgxwR
XDG_RUNTIME_DIR=/run/user/0
XDG_CURRENT_DESKTOP=KDE
LANG=es_ES.UTF-8

Regards,
Isaac

Isaac, thanks for testing!

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.

1 Like

Hi!
Now I don’t get any error when starting in a terminal:

DISPLAY=:1 WAYLAND_DISPLAY=wayland-0 XAUTHORITY=/run/user/1000/xauth_UXgxwR XDG_RUNTIME_DIR=/run/user/1000 XDG_CURRENT_DESKTOP=KDE LANG=es_ES.UTF-8
Logging to /tmp/myrlyn-root/myrlyn.log
Logging to /tmp/myrlyn-root/zypp.log

Anyway, my configuration is not applied.

I have noticed that now instead of an “X” a get the wayland logo, which I think is good.

Maybe I would need to add additional environment variables in ~/.config/openSUSE/myrlyn-sudo.conf?

Let me know if I can run any more tests; I’m happy to help.

Regards,
Isaac

Is ~/.config/openSUSE/myrlyn-sudo.conf set as executable?

It doesn’t need to be executable since it’s read and evaluated with the source shell built-in.

In my case, I don’t have the file ~/.config/openSUSE/myrlyn-sudo.conf.

Looks like we can achieve different levels of broken. :upside_down_face:
This needs more research what it all is and what it does.

1 Like

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.

Yes! We’re one step closer to the solution!

If you want to try anything, let me know and I will tests.

Regards.

1 Like

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:

Second picture, 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.

Mystery solved. :slight_smile:

2 Likes