Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
# ***Note*** You need machinectl installed.
# This can be found in the systemd-container package on Ubuntu!
#
# Place this nvidia-wallpaper-restore-on-resume.sh script in /lib/systemd/system-sleep/
# Then run: sudo chmod +x /lib/systemd/system-sleep/nvidia-wallpaper-restore-on-resume.sh
#
# This works around the wallpaper corruption on resume from suspend with Nvidia GPUs
# reported at https://gitlab.gnome.org/GNOME/gnome-shell/issues/1084
# and due to this feature of the Nvidia driver:
# https://www.khronos.org/registry/OpenGL/extensions/NV/NV_robustness_video_memory_purge.txt
# Adapted from Paul Knopf (https://gitlab.gnome.org/GNOME/gnome-shell/issues/1084)
# and via https://bugs.launchpad.net/ubuntu/+source/mutter/+bug/1809407/comments/22
# Note that this does show the user's screen when coming out of sleep briefly.
# Note that this is fixed in mutter version 3.33.4, which should be in stable mutter 3.34 builds.
PROGNAME=$(/usr/bin/basename "$0")
state=$1
action=$2
function log {
/usr/bin/logger -i -t "$PROGNAME" "$*"
}
log "Running $action $state"
if [[ $state == post ]]; then
log "WAKE UP"
pid_Gnome=($(/usr/bin/pgrep gnome-session))
pid_Gnome=("${pid_Gnome[@]%%:*}")
command="/usr/bin/dbus-send --type=method_call --dest=org.gnome.Shell /org/gnome/Shell org.gnome.Shell.Eval "string:global.reexec_self\(\)""
for i in "${pid_Gnome[@]}"
do
user=$(/bin/ps -o user= -p $i)
log $i $user
if [ "$user" != "gdm" ] || [ ${#pid_Gnome[@]} == 1 ]; then
log "machinectl shell $user@.host $command"
/bin/machinectl shell $user@.host $command
fi
done
fi
exit 0
@mehrandvm

This comment has been minimized.

Copy link

mehrandvm commented Jul 11, 2019

Guess it fixed my problem. Thank you.

@diegogiglio

This comment has been minimized.

Copy link

diegogiglio commented Jul 12, 2019

Hello.
I just need to run this .sh ?
I did it and after I suspend my laptop, but when it back the pixels garbage continuous... :(
IMG_20190711_221552562

@diegogiglio

This comment has been minimized.

Copy link

diegogiglio commented Jul 12, 2019

Hello.
I just need to run this .sh ?
I did it and after I suspend my laptop, but when it back the pixels garbage continuous... :(
IMG_20190711_221552562

Sorry for disturb you, man.
I read the script again and see I needed to install systemd-container. Thank you for help me and others :D

@satmandu

This comment has been minimized.

Copy link
Owner Author

satmandu commented Jul 12, 2019

Thanks @diegogiglio I updated the top of the script to make that more explicit!

@AllenKVarghese

This comment has been minimized.

Copy link

AllenKVarghese commented Jul 23, 2019

Background error disco
does the above fix work in this case also? This started to happen after I configured my GPU to nvidia-418

@satmandu

This comment has been minimized.

Copy link
Owner Author

satmandu commented Jul 23, 2019

Try it?

It won't harm your system.

And this is more of a workaround than a fix, for which you need to wait for the next version of mutter to go stable in Gnome.

@AllenKVarghese

This comment has been minimized.

Copy link

AllenKVarghese commented Jul 23, 2019

"Place this nvidia-wallpaper-restore-on-resume.sh script in /lib/systemd/system-sleep/"
Can you tell me how I'm to copy this file inside systemd? Copy/Paste is not working. Any help appreciated :)

@satmandu

This comment has been minimized.

Copy link
Owner Author

satmandu commented Jul 23, 2019

"Place this nvidia-wallpaper-restore-on-resume.sh script in /lib/systemd/system-sleep/"
Can you tell me how I'm to copy this file inside systemd? Copy/Paste is not working. Any help appreciated :)

Open a terminal app and paste in the following and hit enter, and type in your password when prompted since sudo needs it to elevate permissions for the install:

sudo bash <<"EOF"
wget https://gist.githubusercontent.com/satmandu/2f2da70a7a6bbbacdba01ef8fb8c18f4/raw/092d51c0ed4a662d343482ca727f56186dbebe40/nvidia-wallpaper-restore-on-resume.sh -O /lib/systemd/system-sleep/nvidia-wallpaper-restore-on-resume.sh
chmod +x /lib/systemd/system-sleep/nvidia-wallpaper-restore-on-resume.sh
EOF
@AllenKVarghese

This comment has been minimized.

Copy link

AllenKVarghese commented Jul 23, 2019

Thanks a lot @satmandu. This worked for me :D

@AllenKVarghese

This comment has been minimized.

Copy link

AllenKVarghese commented Jul 23, 2019

"Place this nvidia-wallpaper-restore-on-resume.sh script in /lib/systemd/system-sleep/"
Can you tell me how I'm to copy this file inside systemd? Copy/Paste is not working. Any help appreciated :)

Open a terminal app and paste in the following and hit enter, and type in your password when prompted since sudo needs it to elevate permissions for the install:

sudo bash <<"EOF"
wget https://gist.githubusercontent.com/satmandu/2f2da70a7a6bbbacdba01ef8fb8c18f4/raw/092d51c0ed4a662d343482ca727f56186dbebe40/nvidia-wallpaper-restore-on-resume.sh -O /lib/systemd/system-sleep/nvidia-wallpaper-restore-on-resume.sh
chmod +x /lib/systemd/system-sleep/nvidia-wallpaper-restore-on-resume.sh
EOF

Would you mind shedding some light on why copy/paste didn't work there? My guess is it's because of permission issues. Any other way to copy/paste code there?

@AllenKVarghese

This comment has been minimized.

Copy link

AllenKVarghese commented Aug 9, 2019

Hey, I wanna undo this command as it's now taking too long to get back from the lock screen. Can you tell how to revert the changes made after executing the above code?

@satmandu

This comment has been minimized.

Copy link
Owner Author

satmandu commented Aug 9, 2019

sudo rm /lib/systemd/system-sleep/nvidia-wallpaper-restore-on-resume.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.