gtklock icon indicating copy to clipboard operation
gtklock copied to clipboard

Flash of desktop screen on laptop resume

Open ldelossa opened this issue 3 years ago • 25 comments

Hey,

Gtklock working pretty great for me. However, if I shut my laptop screen and allow it to suspend, when I come back, I get a flash of my desktop windows before gtlock renders itself.

Here is my swayidle configuration:

exec swayidle -w \
         timeout 300   'gtklock -d -s ~/.config/gtklock/style.css' \
         timeout 600   'swaymsg "output * dpms off"' \
         resume        'swaymsg "output * dpms on"' \
         after-resume  'gtklock -d -s ~/.config/gtklock/style.css'

I did have that after-resume line as before-sleep at one point, but that failed to invoke gtlock all together.

ldelossa avatar Jun 08 '22 12:06 ldelossa

The flash is probably due to the delay between the laptop resuming and gtklock staring. I can't really do anything about that.

What I'm more worried about is the before-sleep option not working with gtklock. It led me to discover that on my system gtklock just exits if I suspend and resume the device while locked... What's worse is that I found this behaviour in all programs using gtk-layer-shell, but only when using multiple outputs. I want to test this on a different system but don't currently have one on hand.

Maybe this is the same issue that you encountered? Do you have multiple outputs connected when this happens? Can you try starting gtklock by a method other than swayidle and see if it happens?

jovanlanik avatar Jun 09 '22 20:06 jovanlanik

Hey @jovanlanik

So I just did this test:

  1. Killed swayidle in my current session
  2. Plugged in dock so viewing multi-monitor.
  3. Ran "gtklock" from the CLI directly
  4. Hopped to new tty and forced suspend with systemctl suspend
  5. Woke computer up, returned to tty with Sway.

When I returned gtklock is still running and has kept the locked session, so I'm not exactly noticing this flaw you are.

Also, oddly enough the desktop flash screen only occurs when I'm plugged into my dock with multi-monitors.

ldelossa avatar Jun 09 '22 22:06 ldelossa

Can you also try suspending while sway is still active (without changing to tty)?

  1. run `$ sleep 5 && systemctl suspend'
  2. then run gtklock

If I do it your way, it doesn't happen to me either.

jovanlanik avatar Jun 09 '22 22:06 jovanlanik

Tried your way, I still come back to gtklock. No crash.

ldelossa avatar Jun 09 '22 23:06 ldelossa

While multiple output are connected?

jovanlanik avatar Jun 09 '22 23:06 jovanlanik

Yup. With multiple monitor outs.

ldelossa avatar Jun 09 '22 23:06 ldelossa

Well I'm confused... I absolutely do not understand why before-sleep doesn't work with gtklock. I'll have to do try installing elogind and try it for myself... I also don't understand this problem with gtk-layer-shell but until I replicate it on a different system I'll assume it's specific to me.

jovanlanik avatar Jun 09 '22 23:06 jovanlanik

Ill give it another go in a bit, but AFAICT, it lives over a suspend/resume

ldelossa avatar Jun 09 '22 23:06 ldelossa

I think I pinned down the issue I had as the same as or related to #6, so when I fix that I'll try replicating your issue.

jovanlanik avatar Jun 13 '22 18:06 jovanlanik

Thanks, looks promising.

ldelossa avatar Jun 13 '22 18:06 ldelossa

Do you by any chance use bindswitch in your sway config?

jovanlanik avatar Jun 13 '22 18:06 jovanlanik

I do,

bindswitch --reload --locked lid:on output eDP-1 disable
bindswitch --reload --locked lid:off output eDP-1 enable

My laptop display.

ldelossa avatar Jun 13 '22 18:06 ldelossa

I fixed it in the latest commit but it requires some config:

  1. If you use swayidle, lock using before-sleep: `$ swayidle -w before-sleep 'gtklock -d'. This way the window is created and rendered before sleep.
  2. Avoid disabling outputs before sleep. In your config bindswitch disables eDP-1 even when going to sleep, this shouldn't happen because it destroys window and a new one is only created when the output gets enabled after resume. Unfortunately, I can't do anything else about it. It's a limitation of wlr-layer-shell, the window must close if you disable the output. You can still disable the output in situations where the lid doesn't put the device to sleep. Maybe you can check if the laptop is docked before disabling eDP-1 on bindswitch.

jovanlanik avatar Jun 13 '22 20:06 jovanlanik

Hmm, AFA point 2 goes, my laptop will only sleep on lid closed if that setting is there. I tried it with a disable dpms setting as well, but that keeps the laptop awake.

I see what youre saying tho. This gets a little tricky while still supporting clamshell mode

ldelossa avatar Jun 13 '22 20:06 ldelossa

That's strange, I also use clamshell and my device sleeps regardless of sway settings. Maybe check /etc/systemd/logind.conf.

jovanlanik avatar Jun 13 '22 20:06 jovanlanik

Okay let me double check.

ldelossa avatar Jun 13 '22 20:06 ldelossa

May i ask, what are your lid shut settings?

ldelossa avatar Jun 13 '22 21:06 ldelossa

I use the defaults, so the entire file is commented out but I think these are the relevant values:

[Login]
HandleLidSwitch=suspend
HandleLidSwitchExternalPower=suspend
HandleLidSwitchDocked=ignore
LidSwitchIgnoreInhibited=yes

[Sleep]
AllowSuspend=yes
AllowSuspendInterrupts=no
BroadcastSuspendInterrupts=yes

EDIT: some of these options seem specific to elogind and might be different for systemd...

jovanlanik avatar Jun 13 '22 21:06 jovanlanik

Thats helpful, but i meant for sway config.

ldelossa avatar Jun 13 '22 21:06 ldelossa

Oh, sorry. In my sway config I have:

exec_always exec sway-monitors.sh
bindswitch --locked lid:toggle exec exec sway-monitors.sh

And in the sway-monitors.sh script I check if the laptop is docked by connected devices:

#!/bin/sh

# Specific to my setup
docked() {
	lspci -n | grep -q '1002:67df' && return 0
	lsusb | grep -q '258a:0036' && return 0
	return 1
}

docked || exit

if grep -q open /proc/acpi/button/lid/LID/state
then
	swaymsg output eDP-1 enable
else
	swaymsg output eDP-1 disable
fi

jovanlanik avatar Jun 13 '22 22:06 jovanlanik

Ohh nice example. Thanks a lot! Ill give this ago in a bit

ldelossa avatar Jun 13 '22 22:06 ldelossa

The part that checks dock is really specific to my setup, so you might have to change it up a little...

jovanlanik avatar Jun 13 '22 22:06 jovanlanik

Yup, ill find the Guids

ldelossa avatar Jun 13 '22 22:06 ldelossa

Now that I think about it, a better check would be checking the number of available outputs using swaymsg...

EDIT: something like swaymsg -t get_outputs | jq '. | length'. If it equals 1 then you're not docked.

jovanlanik avatar Jun 13 '22 22:06 jovanlanik

I've had some problems with the script... When suspending, undocking and resuming the output would stay disabled. Updated script:

#!/bin/sh

# Specific to my setup
docked() {
	lspci -n | grep -q '1002:67df' && return 0
	lsusb | grep -q '258a:0036' && return 0
	return 1
}

if grep -q open /proc/acpi/button/lid/LID/state
then
	swaymsg output eDP-1 enable
else
	docked && swaymsg output eDP-1 disable
fi

Alternative docking function:

# More universal but depends on jq
docked() {
	[ "$(swaymsg -t get_outputs | jq '. | length')" -ne 1 ] && return 0
	return 1
}

jovanlanik avatar Jun 15 '22 05:06 jovanlanik

I'm closing this issue because it not currently (and as long as gtklock can't use ext-session-lock) possible to fix but can be mostly avoided by never disabling all outputs.

jovanlanik avatar Sep 16 '22 16:09 jovanlanik