Fix Funky Background Image on Suspend->Wake

Tip:
When you Suspend and Resume Ubuntu 20.04, if it Resumes with a black background or black tiles around open apps, try this:
Tap twice on the key that will open and close your Brisk Menu. (for details, see My simple fix below)

My Story:
After several months working on various problems, I have Ubuntu Mate 20.04 running very smoothly on two lovely old MacBooks (13" Mid-2010 A1342-7,1). They had grown progressively slower and more annoying with each new MacOS, then this year they lost Apple support and thus became vulnerable to hackers. Now running Mate they're happily secure, sleek and fast again. One last minor nuisance remains, so I'm going to try a simple idea to fix it.

The Problem:
With the laptop open, I can do a Suspend with the Logout button in the Panel and then Wake (Resume) with a tap on the Shift key and it works fine. BUT my more common way to Suspend is simply closing the lid. When I do that and then open the lid to Wake, the background image is gone, leaving solid black other than the bottom Panel that I've set to not autohide. Any windows I've left open when closing the lid also show up fine, but may have a few scattered small tiles of the Background image around their margins. There's also at least several pure black areas of the screen, and they remain black until something is placed over them. That can be a window I drag around over the black areas, or new windows that open in those areas. So clearly this is not a serious problem, but it is annoying.

My simple fix:
I have the Brisk Menu Launcher (version 0.6.0) in the Panel, and when used via the Mac "Command" key (Alt on my PC) it instantly opens full screen. Tap that key again and it instantly disappears. So to fix the funky Background image when I open the lid to Wake from Suspend, for the past month or so I just tap that key twice and carry on.

My Idea:
Now I'd like to have the computer do the open/close of that or some other full-screen app at every Wake event. Since the double keytap method works reliably, rather than find the cause I hope to find and share here a simple solution. Since anyone using this popular Mac model (and probably many other makes and models) will encounter this problem, I'm thinking a functioning script would be useful.

For everyone wondering if I've seen all the prior posts about funky background Wake issue: yes, I've searched exhaustively and as posted by many other moaning newbies nothing works for me. So today I decided to try a simple script to instantly open & close a full-screen app called in pm-utils as described in this post?

First I tried Close Lid (Suspend)->Lid Open->this Terminal command:
exec '/lib/x86_64-linux-gnu/brisk-menu/brisk-menu'
which works perfectly, and seems to happen so fast (also closing the Terminal window) I don't see the Brisk menu at all. Then I put that in a draft script with this name:
/lib/pm-utils/sleep.d/99fixBGscreen
and with these Permissions:
-rwxr-xr-x 1 root root 101
but it doesn't work. There's a new brief pause during wake, but the black areas remain. So maybe the way it works via Terminal differs from what it does when run with exec from the script?

After reading this man page I tried renaming the script to
/usr/lib/pm-utils/sleep.d/39fixBGscreen
in case the execution order was problematic. Still no luck.

What I Seek:
Help with writing the script. Clearly there's plenty of info out there on how to write scripts, but most of it's irrelevant to this effort and quickly forgotten my someone simply using the computer for non-technical daily tasks (me). Is there a kindly soul reading this willing to whip up a sample script and post it here?

Draft Script:

#!/bin/sh

case "$1" in
resume)
exec '/lib/x86_64-linux-gnu/brisk-menu/brisk-menu'
esac

@JohnW there was a similar discussion in Run script after sleeping and at the end of that post I suggested something I had written in the past using /lib/systemd/system-sleep/ instead of /lib/pm-utils/sleep.d/ Copy your scripts in the systemd location and test.

1 Like

Thanks for the idea, Pavlos. Alas, after copying the file to /lib/systemd/system-sleep/ it still wakes with black screen or tiles. Interestingly, unlike before, with Suspend via the Logout button it Resumed after Shift key tap with black screen/tiles. Even more interesting perhaps, after deleting that file it now still has the black screen/tiles with either the Logout button or lid close Suspend method. In case it might help, I tried a Logout button Restart both while the file was there and after deleting it - no change. [UPDATE- the exec command to open Brisk Menu from a Terminal window no longer works either.]

At least my old method of double tap on the Brisk Menu key still works. :slightly_smiling_face:

Maybe I need to try some other app that will paint the whole screen and exit. I'd need to find an app able to open and exit very quickly, and figure out how to put it in a script.

Now I'm wondering though, if having this in the Wake process isn't working because the screen's not yet active. Maybe I need something to open/close the Brisk Menu (or some app) after the screen background has been painted. If so, maybe there's a tweak possible to whatever draws the background after Resume?

So for the moment I'm going to edit the initial post here to recommend the double-tap trick to anyone else seeking a quick and easy way to deal with black screen or tiles after Resume.

Here's my latest attempt that does nothing.

#!/bin/sh
;; Immediately before entering system suspend and/or hibernation
;; systemd-suspend.service (and the other mentioned units, respectively)
;; will run all executables in /lib/systemd/system-sleep/ and pass two
;; arguments to them. The first argument will be "pre", the second either
;; "suspend", "hibernate", "hybrid-sleep", or "suspend-then-hibernate"
;; depending on the chosen action. Immediately after leaving system
;; suspend and/or hibernation the same executables are run, but the
;; first argument is now "post". All executables in this directory are
;; executed in parallel, and execution of the action is not continued
;; until all executables have finished.

case "$1" in
resume|thaw)
DISPLAY=:0.0 ; export DISPLAY
"sleep 5; exec '/lib/x86_64-linux-gnu/brisk-menu/brisk-menu'"
exec '/usr/bin/caja'
;; Fill the screen to cover any black areas, so that the complete
;; background image will show when the above app is closed.
esac
exit 0

It's here in my system with root owner & full x Permissions:
/usr/lib/systemd/system-sleep/wakeTest

I had the snippet of text at the top commented out with hastags (didn't work), but when I tried to paste it in here it came out bold so I changed them to double semicolons I've seen elsewhere and tried it on the computer. Still does nothing during Suspend-> Wake.

It seems that although pm-utils no longer works in Ubuntu 20.04, it's still recommended on many sites and the file structure is still here. So my focus now is on systemd. In trying to find solutions online I see plenty of cases where people are doing everything "right" yet the script does nothing. I guess it has to do with the specific syntax of systemd, so maybe it will require wading into the collection of greek (to me) systemd man pages on ubuntu.com?

John, try this ... for any X app to work upon resume, the app needs to know the DISPLAY and XAUTHORITY. I get the xclock, added /usr/bin/caja and I get the file manager upon resume. (have to throw them in the background) My file /lib/systemd/system-sleep/pak with +x

#!/bin/sh
case $1 in
  post)
  export XAUTHORITY=/home/user/.Xauthority
  export DISPLAY=:0
  /usr/bin/xclock &
  /usr/bin/caja &
  ;;
esac
exit 0
1 Like

Thanks Pavlos. :slightly_smiling_face:
I tried it exactly like that, with the xclock line deleted, no joy. Then I remembered seeing a need for quotes mentioned so this was the next attempt, and didn't work either.

#!/bin/sh
case "$1" in
post)
export XAUTHORITY=/home/user/.Xauthority
export DISPLAY=:0
/usr/bin/caja &
;;
esac
exit 0

Then checked to ensure caja is at that location on my system (it is). Also tried putting exec at the front of the caja line.

I don't understand why the example you sent works for you. Maybe you're running a different Ubuntu Mate version? I'm on 20.04.2 - Linux 5.4.0-70-generic x86_64 - MATE 1.24.0

I'm running UM 20.04 with the same kernel and Mate display. One thing, my login is user, if your login is john, you should change the line of XAUTH to /home/john/.Xauthority

1 Like

Thanks for noticing that. :slightly_smiling_face:
I'd wrongly assumed "user" is a universal that would work.
Alas, when I changed it to my username the script still did nothing detectable. :confused:

Happily tho, I then remembered your log file idea in the other thread so I added a line to test whether the script IS doing anything at all:

#!/bin/sh
case "$1" in
post)
export XAUTHORITY=/home/myUsername/.Xauthority
export DISPLAY=:0
/usr/bin/caja &
echo "Something's working!" >> /home/myUsername/Desktop/BGfix.txt
;;
esac
exit 0

Bingo! So now I "only" need to get the script to call an app.
Ideas?

You can use logger -t "starting caja after resume ..." before the /usr/bin/caja line which will put that line in /var/log/syslog That way you can grep stuff in syslog to figure out what parameters are passed (for example, $1 is "post") and events happen. At least now, caja is displayed upon resume since it figures out the display and the auth cookie.

Is there something special about the brisk-menu ??

1 Like

Wilco. I'd already been rummaging log files in nemo, sorted by mod time, and syslog didn't seem to have anything. Hopefully the logger line will show if anything at all is happening with the caja call.

Brisk Menu is brisk. That is, it opens and closes in a fraction of a second when tapping the key. Plus, it opens full screen and that paints the background when Brisk is closed. Caja was a fallback in case Brisk can't be called and then closed from a script. I just want to see ANY app run from the script, then figure out how to make it full screen when opened. Then of course, the hope that it will paint the background when closed.

Searched the file after Sleep/Wake and got "not found."

Regards calling apps from systemd, maybe it needs the unique language described in the man files and on pages like this one?

But then why is it working fine for you?? Interesting problem, eh?

[UPDATE.1] Looks to me like sh (bash?) commands like echo work fine, so I tried adding sh bash and exec in front of the caja line but of course none of that works either.
[UPDATE.2] I tried this script that does nothing on the MacBook, on my PC:

#!/bin/sh
case "$1" in
post)
export XAUTHORITY=/home/myUname/.Xauthority
export DISPLAY=:0
logger -t "starting caja after resume ..."
/usr/bin/caja &
echo "It's doing this as of '&(date).'" >> "/home/myUname/Desktop/BGfix.txt"
esac
exit 0

Bingo! On the PC, Caja now appears during Resume (opened as root). Just to keep things funky tho, it then vanishes after a few seconds. For my purpose that would work fine, because Caja remembers full-screen so it could paint the screen and exit with no further work.
[UPDATE.3] Nothing happens on the MacBook with that same script, except update adding the "It's doing..." line to the Desktop/BGfix.txt file." Nothing apparent in the syslog.]
So there's something unique about the MacBook, and it may well be the GeForce 320M NVIDIA card and/or driver. I can't use the Ubuntu default driver because it causes far worse problems than this little Resume glitch.

Still nothing on the MacBook. The date stopped appearing in the BGfix.txt file, so I added some stuff to the /lib/systemd/system-sleep/BGwake325 file that's now this:

#!/bin/sh
case "$1" in
post)
export XAUTHORITY=/home/myUname/.Xauthority
export DISPLAY=:0
logger -t "starting caja after resume ..."
/usr/bin/caja &
logger -t "/usr/bin/caja & # Sent on line above."
echo 'Resumed from Suspend:' >> "/home/myUname/Desktop/BGfix.txt"
echo &(date) >> "/home/myUname/Desktop/BGfix.txt"
esac
exit 0

All that script is doing that I can find is 2 lines in the BGfix file for each Sleep/Wake:

Resumed from Suspend:
Sat 27 Mar 2021 12:06:52 AM PDT

Nothing in syslog with "$1" or from the two logger lines or the caja line. I added the date line because it had stopped working as a one-line "Resumed...(date)" in BGfix.

As for why it's working on PC and not MacBook, there are some lines like this in syslog from a brief sleep/wake cycle (all stamped "Mar 27 00:06:52 MyMac":

systemd-sleep[10657]: System resumed.
...[two lines apparently about HDD wakeup]
MyMac kernel: [ 5368.148970] ata1.00: ACPI cmd ef/10:03:00:00:00:a0 (SET FEATURES) filtered out
MyMac kernel: [ 5368.149014] ata1.00: supports DRM functions and may not be fully accessible
MyMac kernel: [ 5368.152247] ata1.00: ACPI cmd ef/10:03:00:00:00:a0 (SET FEATURES) filtered out
MyMac kernel: [ 5368.152286] ata1.00: supports DRM functions and may not be fully accessible
MyMac kernel: [ 5368.152784] ata2.00: ACPI cmd ef/10:03:00:00:00:a0 (SET FEATURES) filtered out
MyMac kernel: [ 5368.154917] ata1.00: configured for UDMA/133
MyMac kernel: [ 5368.155085] ata1.00: Enabling discard_zeroes_data
MyMac kernel: [ 5368.157696] ata2.00: ACPI cmd ef/10:03:00:00:00:a0 (SET FEATURES) filtered out
MyMac kernel: [ 5368.157700] ata2.00: configured for UDMA/133
MyMac systemd-sleep[10675]: Could not parse arguments: Cannot open display:
MyMac systemd[1]: systemd-suspend.service: Succeeded.
MyMac systemd[1]: Finished Suspend.
MyMac systemd[1]: Stopped target Sleep.
MyMac systemd[1]: Reached target Suspend.

So maybe the kernel is allowing the two shell echo commands to update BGfix.txt but "filtering out" the caja and two logger commands that work on the PC?

I assume you meant echo $(date) instead of &(date).
if you add special chars in the logger message, you need to escape them
I dont know if the Macbook kernel has more filtering, I'm testing this on a Lenovo laptop.

why do you get this line?
MyMac systemd-sleep[10675]: Could not parse arguments: Cannot open display:

1 Like

Hi Pavlos,
Thanks for the reply. I've been distracted by another issue (changing username) and it's all but disabled the Mac, so I'm typing this on another computer. Right now the Mac's a strange new world that feels like growing up in Oz and being whisked into Kansas.

Anyway, as to your questions: Thanks for catching the & where a $ should be. I plead temporary blindness. My only uninformed idea about the "Could not parse.." is that it relates to the prior "filtered out" line(s) rather than the "UDMA" line. I have no guess what UDMA is, so maybe that's related?
UPDATE: While trying to fix the disabled MacBook mentioned above, I used the PC running MATE to look up UDMA and found it's for an ATA device (RAM or hard drive?). Apparently related to the command filtered out in the line above. ACPI is the Advanced Configuration and Power Interface that puts the MacBook to sleep. If this issue ever gets resolved, I guess it will be by turning off the filtering that's presumably done by ACPI command ef/10:03:00:00:00:a0 (maybe accessible in the MacBook firmware). Scary enough for a newbie like me not to mess with, unless a MacBook MATE expert happens to reply here. So if I get it running MATE again today, I'll just go back to the double-tap on the Brisk Menu key. Thanks for the help, Pavlos. :slightly_smiling_face:

So now I'm going to make a new "Change Username" post pleading for help getting back to OZ with my familiar Panel where the default Terminal app isn't XTerm. There's no place like Home...

Hmm... :thinking:
What if there's a shell command that would paint the whole screen?

That is, the echo command is working (not filtered) so maybe the MacBook firmware is filtering only Ubuntu and/or MATE commands? Since the script is probably running before the screen is activated in the resume process, maybe no shell commands in the script would help anyway. Any ideas of things to try along this line?

@JohnW

I was troubleshooting a similar issue and one idea was to export the DBUS_SESSION env variable in the script. You can find your setting with env | grep DBUS Add this line to your script and give it a test?

the line is: DBUS_SESSION_BUS_ADDRESS=unix:path=/run/myusername/1000/bus
(replace myusername with your login id)

1 Like