Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--grace 1 prevents screenlock #68

Open
leoTlr opened this issue Aug 27, 2024 · 12 comments · May be fixed by #70
Open

--grace 1 prevents screenlock #68

leoTlr opened this issue Aug 27, 2024 · 12 comments · May be fixed by #70
Labels
E-hyprland This issue is related to Hyprland compositor.

Comments

@leoTlr
Copy link

leoTlr commented Aug 27, 2024

Problem

The --grace option doesn't work as expected. The screen doesn't lock. To me it seems like the white default lock screen pops up for a split second but it never actually locks or instantly unlocks itself again without asking for a pw

swaylock -C /dev/null --grace 0: screen locks as expected and I can unlock it by typing the password
swaylock -C /dev/null --grace 1 (or any val > 0): screen seems to lock for a split second and instantly unlocks itself without asking for pw

Any idea why this is happening? Sth with pam maybe?

Info

 ~> swaylock --version
swaylock version 1.7.0.0
 ~> hyprctl version
Hyprland, built from branch main at commit 9a09eac79b85c846e3a865a9078a3f8ff65a9259  (props: bump version to 0.42.0).
Date: 2024-08-07
Tag: v0.42.0, commits: 9a09eac79b85c846e3a865a9078a3f8ff65a9259

flags: (if any)

 ~> uname -a
Linux lt-t14 6.6.47 #1-NixOS SMP PREEMPT_DYNAMIC Mon Aug 19 04:04:32 UTC 2024 x86_64 GNU/Linux

Trace

 ~> swaylock -C /dev/null --trace --grace 0
2024-08-27 22:18:25 - [main.c:1870] Found config at /dev/null
2024-08-27 22:18:25 - [main.c:1880] Parsing CLI Args
2024-08-27 22:18:25 - [main.c:453]: trace: handle_wl_output_geometry
2024-08-27 22:18:25 - [main.c:657]: trace: handle_wl_output_name
2024-08-27 22:18:25 - [main.c:658] output name is eDP-1
2024-08-27 22:18:25 - [main.c:469]: trace: handle_wl_output_scale
2024-08-27 22:18:25 - [main.c:669]: trace: handle_wl_output_done
2024-08-27 22:18:25 - [main.c:453]: trace: handle_wl_output_geometry
2024-08-27 22:18:25 - [main.c:657]: trace: handle_wl_output_name
2024-08-27 22:18:25 - [main.c:658] output name is DP-4
2024-08-27 22:18:25 - [main.c:469]: trace: handle_wl_output_scale
2024-08-27 22:18:25 - [main.c:669]: trace: handle_wl_output_done
2024-08-27 22:18:25 - [main.c:453]: trace: handle_wl_output_geometry
2024-08-27 22:18:25 - [main.c:657]: trace: handle_wl_output_name
2024-08-27 22:18:25 - [main.c:658] output name is DP-5
2024-08-27 22:18:25 - [main.c:469]: trace: handle_wl_output_scale
2024-08-27 22:18:25 - [main.c:669]: trace: handle_wl_output_done
2024-08-27 22:18:25 - [main.c:535]: trace: handle_screencopy_frame_buffer
2024-08-27 22:18:25 - [main.c:535]: trace: handle_screencopy_frame_buffer
2024-08-27 22:18:25 - [main.c:535]: trace: handle_screencopy_frame_buffer
2024-08-27 22:18:25 - [main.c:562]: trace: handle_screencopy_frame_flags
2024-08-27 22:18:25 - [main.c:610]: trace: handle_screencopy_frame_ready
2024-08-27 22:18:25 - [main.c:562]: trace: handle_screencopy_frame_flags
2024-08-27 22:18:25 - [main.c:610]: trace: handle_screencopy_frame_ready
2024-08-27 22:18:25 - [main.c:562]: trace: handle_screencopy_frame_flags
2024-08-27 22:18:25 - [main.c:610]: trace: handle_screencopy_frame_ready
2024-08-27 22:18:25 - [main.c:1970] Using ext-session-lock-v1

 ~> swaylock -C /dev/null --trace --grace 1
2024-08-27 22:18:32 - [main.c:1870] Found config at /dev/null
2024-08-27 22:18:32 - [main.c:1880] Parsing CLI Args
2024-08-27 22:18:32 - [main.c:453]: trace: handle_wl_output_geometry
2024-08-27 22:18:32 - [main.c:657]: trace: handle_wl_output_name
2024-08-27 22:18:32 - [main.c:658] output name is eDP-1
2024-08-27 22:18:32 - [main.c:469]: trace: handle_wl_output_scale
2024-08-27 22:18:32 - [main.c:669]: trace: handle_wl_output_done
2024-08-27 22:18:32 - [main.c:453]: trace: handle_wl_output_geometry
2024-08-27 22:18:32 - [main.c:657]: trace: handle_wl_output_name
2024-08-27 22:18:32 - [main.c:658] output name is DP-4
2024-08-27 22:18:32 - [main.c:469]: trace: handle_wl_output_scale
2024-08-27 22:18:32 - [main.c:669]: trace: handle_wl_output_done
2024-08-27 22:18:32 - [main.c:453]: trace: handle_wl_output_geometry
2024-08-27 22:18:32 - [main.c:657]: trace: handle_wl_output_name
2024-08-27 22:18:32 - [main.c:658] output name is DP-5
2024-08-27 22:18:32 - [main.c:469]: trace: handle_wl_output_scale
2024-08-27 22:18:32 - [main.c:669]: trace: handle_wl_output_done
2024-08-27 22:18:32 - [main.c:535]: trace: handle_screencopy_frame_buffer
2024-08-27 22:18:32 - [main.c:535]: trace: handle_screencopy_frame_buffer
2024-08-27 22:18:32 - [main.c:535]: trace: handle_screencopy_frame_buffer
2024-08-27 22:18:32 - [main.c:562]: trace: handle_screencopy_frame_flags
2024-08-27 22:18:32 - [main.c:610]: trace: handle_screencopy_frame_ready
2024-08-27 22:18:32 - [main.c:562]: trace: handle_screencopy_frame_flags
2024-08-27 22:18:32 - [main.c:610]: trace: handle_screencopy_frame_ready
2024-08-27 22:18:32 - [main.c:562]: trace: handle_screencopy_frame_flags
2024-08-27 22:18:32 - [main.c:610]: trace: handle_screencopy_frame_ready
2024-08-27 22:18:32 - [main.c:1970] Using ext-session-lock-v1
@LostExcalibur
Copy link

Have the same issue, here is my system info

❯ swaylock --version
swaylock version v1.7.0.0-1-g496059a (" __DATE__ ", branch 'master')
❯ uname -a
Linux 6.10.6-arch1-1 #1 SMP PREEMPT_DYNAMIC Mon, 19 Aug 2024 17:02:39 +0000 x86_64 GNU/Linux
❯ hyprctl version
Hyprland, built from branch  at commit 9a09eac79b85c846e3a865a9078a3f8ff65a9259  (props: bump version to 0.42.0).
Date: Wed Aug 7 19:17:10 2024
Tag: v0.42.0, commits: 5069

flags: (if any)

Logs

❯ swaylock -C /dev/null --trace --grace 1
2024-08-28 13:40:08 - [main.c:1870] Found config at /dev/null
2024-08-28 13:40:08 - [main.c:1880] Parsing CLI Args
2024-08-28 13:40:08 - [main.c:453]: trace: handle_wl_output_geometry
2024-08-28 13:40:08 - [main.c:657]: trace: handle_wl_output_name
2024-08-28 13:40:08 - [main.c:658] output name is eDP-1
2024-08-28 13:40:08 - [main.c:469]: trace: handle_wl_output_scale
2024-08-28 13:40:08 - [main.c:669]: trace: handle_wl_output_done
2024-08-28 13:40:08 - [main.c:535]: trace: handle_screencopy_frame_buffer
2024-08-28 13:40:08 - [main.c:562]: trace: handle_screencopy_frame_flags
2024-08-28 13:40:08 - [main.c:610]: trace: handle_screencopy_frame_ready
2024-08-28 13:40:08 - [main.c:1970] Using ext-session-lock-v1

@pokkos
Copy link

pokkos commented Sep 1, 2024

I have the same issue. By adding --grace-no-mouse, the grace option works as intended, so it seems to have to do with that setting.

Misterio77 added a commit to Misterio77/nix-config that referenced this issue Sep 4, 2024
@Schievel1
Copy link

Schievel1 commented Oct 8, 2024

I added some debug prints into the swaylock_handle_mouse [1] function and it seems like this is called even if the mouse is not moved.
[1]

void swaylock_handle_mouse(struct swaylock_state *state) {

This could work as a quick and dirty fix: only if the pointer is moved more than 1, the function to unlock during grace is called:

static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
		uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
		static int last_x = 0;
		static int last_y = 0;
		int x = wl_fixed_to_int(surface_x);
		int y = wl_fixed_to_int(surface_y);

		if (last_x > 0 && (x - last_x > 1 || y - last_y > 1)) {
		    swaylock_handle_mouse((struct swaylock_state *)data);
		}

		last_x = x;
		last_y = y;
}

The real fix would be to find out why the motion function is called even though the pointer is not moved.

Schievel1 added a commit to Schievel1/swaylock-plugin that referenced this issue Oct 8, 2024
even though there is none.

See also: jirutka#68

Signed-off-by: Pascal Jäger <[email protected]>
Schievel1 added a commit to Schievel1/swaylock-plugin that referenced this issue Oct 8, 2024
even though there is none.

See also: jirutka#68

Signed-off-by: Pascal Jäger <[email protected]>
@Schievel1
Copy link

Ok, after some fiddling with WAYLAND_DEBUG=1 I can pinpoint it to 2 function calls:

render_frame(surface);

and
wl_surface_commit(surface->surface);

The first one is no wonder, because render_frame ultimately calls wl_surface_commit().

If I comment those, the motion function is not called periodically without pointer movement anymore. So the actual drawing of the surface by wayland triggers the motion event.
Maybe it is better to use the fix from above then changing the inner workings of swaylocks frame drawing.

@AThePeanut4
Copy link

This is a Hyprland issue, and I've managed to figure out the root cause there after much troubleshooting and debugging. I've made hyprwm/Hyprland#8584 there which fixes the issue for me - if anyone could test it that would be much appreciated :)

@AThePeanut4 AThePeanut4 linked a pull request Nov 27, 2024 that will close this issue
@Schievel1
Copy link

Iirc in the PR you did for hyprland, swaylock still needs to check for the actual pointer movement like in my quickfix above because you did remove that one commit from your PR. Correct?

@leoTlr
Copy link
Author

leoTlr commented Nov 27, 2024

Can confirm that the combination of hyprwm/Hyprland#8584 and #70 resolves the issue. Only applying the hyprland patch wasnt enough

@AThePeanut4
Copy link

Iirc in the PR you did for hyprland, swaylock still needs to check for the actual pointer movement like in my quickfix above because you did remove that one commit from your PR. Correct?

Yep - I've made #70 for that.

an confirm that the combination of hyprwm/Hyprland#8584 and #70 resolves the issue. Only applying the hyprland patch wasnt enough

Awesome, thanks. I changed my Hyprland PR, so it doesn't fix the issue anymore. #70 should fix the issue with or without the Hyprland patch.

@jirutka jirutka added the E-hyprland This issue is related to Hyprland compositor. label Jan 5, 2025
@jirutka
Copy link
Owner

jirutka commented Jan 5, 2025

I’ve been using swaylock-effects with --grace since the beginning on Sway and never had this problem. However, it might be thanks to --grace-no-mouse. I just tried to run swaylock --grace 10 without --grace-no-mouse on Sway 1.8.1 and it also works correctly.

So the actual drawing of the surface by wayland triggers the motion event.

This is the problem, there’s no reason why drawing on the surface should trigger the mouse motion event and apparently Sway doesn’t to that. So it still looks like yet another hyprland bug.

@AThePeanut4
Copy link

@jirutka This is entirely caused (on Hyprland) by pointer motion events, so it won't happen with --grace-no-mouse. There was a Hyprland bug that caused a motion event on each surface commit (draw), but I fixed that with hyprwm/Hyprland#8584. The reason why the issue still occurs now is because Hyprland sends a single "zero distance" motion event immediately after the surface is focused, and swaylock treats this as a mouse movement and unlocks the screen. Imo this is a bug, which is why hyprwm/Hyprland#8584 originally also fixed this second issue. However vaxry didn't agree, so I removed that from the PR, and I do understand his viewpoint - the Wayland protocol is not very specific on what pointer motion events should mean. In any case, I don't think it's worth fighting to try and change Hyprland behaviour, especially since the fix on the swaylock side is very straightforward.

The TL;DR is that simply ignoring "zero distance" motion events on the swaylock side fixes this issue, which is what I've done in #70. I've also been running swaylock-effects locally with my fix applied since I made that PR with no issues.

@Schievel1
Copy link

Schievel1 commented Jan 6, 2025

I still don't see why they react so harshly. It is obviously not correct to trigger a pointer motion event when committing a surface, isn't it?

@AThePeanut4
Copy link

@Schievel1 No, that's been fixed, as I mentioned...

The issue still present is that a pointer motion event is sent when the surface is focused. And the ext-session-lock-v1 protocol specifies that the compositor is free to handle focusing for lock surfaces however it chooses, and Hyprland chooses to focus lock surfaces immediately after they are mapped. This focus results in a pointer enter event, followed by a motion event. This last motion event is sent with the same coordinates as the pointer event, making it what I'm calling a "zero distance" motion event. The spec says "Notification of pointer location change", which implies that zero distance events shouldn't be sent, but it isn't specified explicitly.

I'm just trying to be pragmatic and get the issue (that is, --grace not working) resolved, and the easiest and simplest way is just #70.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-hyprland This issue is related to Hyprland compositor.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants