Custom shortcut to restart Plasmashell?

I am experiencing a problem where sometimes after a reboot or system sleep the widgets in the taskbar (main panel) are blank. They are present but with no display.

I’ve found that restarting plasmashell mostly (but not always) fixes this, and is certainly more convenient than logging out and back in again.

The following all work on the command line-

systemctl restart --user plasma-plasmashell
kquitapp6 plasmashell; kstart plasmashell
plasmashell --replace

However, for convenience I wanted to bind this to a custom shortcut, and that’s not working. I have tried binding each of these to cntrl+alt+r, but nothing happens.

Any idea on why this type of command doesn’t work as a shortcut, and how to fix it, would be very welcome.

plasmashell --replace works for me, both as a custom kb shortcut and as a desktop shortcut. The problem is that I had it crash so hard few times that it no longer took kb input, forget mouse clicks, so both ended up quite useless in such cases, but both work in less drastic situations.

I also read that Ctrl-Alt-Backspace was supposed to restart Plasma by default but maybe in older versions? I don’t know. It doesn’t seem to work for me in 6. So that’s why I assigned this as a custom shortcut.

BTW, what you described seems like a bug, I found few mentions on the web, so maybe the KDE devs are aware of it and someone will chime in to address your core issue with the widgets.

Which version of Plasma are you running? I experienced some widget and panel related bugs in 6.2, though somewhat different from yours, that were fixed in 6.3.

My widgets were not showing at all, except for the first one, when the panel width was set to “fit content”. Changing the width to “custom” fixed the issue. Though this seems to be fixed in 6.3.

I use the command ‘prestart’ (PlasmashellRestart):

#!/usr/bin/env bash

systemctl --user restart plasma-plasmashell.service

save as ~/.local/bin/prestart
chmod +x ~/.local/bin/prestart`

This will run from krunner, or could be bound to something like Ctrl+Alt+P and works equally well for X11 and Wayland.

I’m running Plasma 6.3.1. The whole installation of KDE Neon is only about a week old, and fully updated.

I have reported the bug, although i’m not sure how easy it will be to reproduce. The occurrence is somewhat random, and restarting Plasma (whether a kill/restart, or by logging out and back in again) will only MOSTLY fix it. Sometimes it takes more than one attempt.

Does it make a difference putting the command line in a shell script file vs. just having the command line in the shortcut definition?

For one-liners my preference would be to keep them in the shortcut definition, if I can make it work.

Not really, I just use this because it leaves all options open - for example, a script to have konsave apply a scheme and then restart Plasmashell to make sure it’s applied nicely.

Well that’s interesting. Given the comments here that some of these commands were working as shortcuts for other people, I looked into it again, and found out the problem wasn’t the command string at all, it was the trigger!

As an example, the command plasmashell --replace hooked to the trigger cntrl+p works perfectly. The same command hooked to cntrl+r (R for “restart” in my mind) does absolutely nothing?!

So, thank you to everyone for the helpful replies. It gave me the encouragement to keep prodding at it. Exactly why one sequence works and another doesn’t is a mystery. I have no idea if this is a bug, or a feature i’m not aware of (maybe Cntrl+r does something magical somewhere else in Plasma?). Of course I would be helpful if the shortcut editor prevented you from selecting trigger keys that won’t work.

Ok.

Just be aware that plasmashell --replace is only going to kill the plasmashell process and start a new instance for very quick fixes/glitches, but the command systemctl --user restart plasma-plasmashell.service handles the user-level service to restart the Plasma shell - so it’s more comprehensive by leveraging the systemd service…

That’s the main reason that I made a quick script - though plasmashell --replace was easy to bring up in krunner, the full restart worked better when I had bugs in the past.

I’m still curious as to why the plasmashell --replace command works as a one line shortcut, but the systemctl one doesn’t. Not so much because of this requirement, but because in future I might want to set up another shortcut, and i’d like to know whether I can expect a particular command line to work.

Me too.

If I fire up krunner and paste in systemctl --user restart plasma-plasmashell.service then it works.

Of course, typing in ‘prestart’ also works.

The more I play with this, the more I realise that the problem is more subtle than I thought.

What i’m seeing is that whether any particular command string, hooked to any particular trigger key combination, ends up working, is not just dependent on the command and the trigger, but also on the sequence of actions the user takes to set it up.

Because I have been experimenting with this, I have not just been starting from a blank slate, but also doing things like-

  • Delete and recreate a “Restart Plasmashell” action, with either the same action/trigger as before or different
  • Test the key sequence before or after quitting the Shortcuts tool
  • Test before or after logging out and back in again

I am now fairly certain some of these things have an effect, because the results I see are not consistent, however it’s quite complex so hard to nail down exactly how to reproduce the problem.

One thing I have been doing is exporting section of the shortcuts to a file to try and understand what’s going on. I have seen some things in there, such as “deleted” definitions left in the data, indicating two actions hooked to the same trigger sequence, that make me pretty certain there are these “how the action was taken” bugs muddying the waters.

Unfortunately, based on admittedly fairly quick search, have not found either-

  • Documentation on the file format supported for import/export of shortcuts
  • Any info on how file import is expected to work. In particular whether the imported definitions are expected to add (merge) with the current state, or simply overwrite it

This latter point is pretty important. If I can manually create a macro definition that works reliably, and then just import that one definition without it nuking the whole set of shortcut definitions, I would be prepared to spend the time to do that.

If you’re using x11 it’s a well known and confirmed bug: 496926 – On X11, desktop is black/missing after resuming from suspend or hibernation until plasmashell is restarted or TTYs are switched

For me it happens after plasma auto locks the screen and only then but others in the thread said it happens at other times too. Amazingly KDE removed the ability to run scripts on system unlock which used to be under notifications but since I wasn’t about to run a command every time I unlocked the screen and I didn’t feel like downgrading Fedora I made a service for this. It is hacky and may not work for everyone so ymmv.

Add /path/to/script/monitor_screen_lock.sh with content:

#!/bin/bash

dbus-monitor --session "type='signal',interface='org.freedesktop.ScreenSaver'" |
while read -r line; do
    case "$line" in
        *"boolean true"*)
            # Screen is locked
            ;;
        *"boolean false"*)
            ## Screen is unlocked
            plasmashell --replace &
            ;;
    esac
done

chmod +x /path/to/script/monitor_screen_lock.sh

Create a systemd user service at ~/.config/systemd/user/screen_lock_monitor.service:

[Unit]
Description=Restart plasmashell on session unlock
After=graphical-session.target

[Service]
ExecStart=/path/to/script/monitor_screen_lock.sh
Restart=always
Environment=DISPLAY=:0
Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus

[Install]
WantedBy=default.target

/run/user/1000/bus needs to match your user ID (id -u).

Reload the systemd user services:

systemctl --user daemon-reload

Enable the service so it starts on login:

systemctl --user enable screen_lock_monitor.service

Start the service immediately:

systemctl --user start screen_lock_monitor.service

As it happens i’m running Wayland (default on Neon 6.3).

The problem with blank widgets after a reboot to re-login is not 100% repeatable, it happens roughly 50% of the time. Now I have a working shortcut key set up, I can live with it. It would be nice to see it fixed in a future release though.