Skip to content
Snippets Groups Projects
backport-patches-from-swaylock.patch 11.7 KiB
Newer Older
From 7050dd3b448fa23a496b23f92aa2baf7f9dca84d Mon Sep 17 00:00:00 2001
From: Simon Ser <contact@emersion.fr>
Date: Wed, 10 Feb 2021 17:41:50 +0100
Subject: [PATCH 01/10] pool-buffer: handle zero-sized buffers

mako does something similar.
---
 pool-buffer.c | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

Patch-Source: https://github.com/mortie/swaylock-effects/pull/64

diff --git a/pool-buffer.c b/pool-buffer.c
index aada4c07..76722834 100644
--- a/pool-buffer.c
+++ b/pool-buffer.c
@@ -72,18 +72,22 @@ static struct pool_buffer *create_buffer(struct wl_shm *shm,
 	uint32_t stride = width * 4;
 	size_t size = stride * height;
 
-	char *name;
-	int fd = create_pool_file(size, &name);
-	assert(fd != -1);
-	void *data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
-	struct wl_shm_pool *pool = wl_shm_create_pool(shm, fd, size);
-	buf->buffer = wl_shm_pool_create_buffer(pool, 0,
-			width, height, stride, format);
-	wl_shm_pool_destroy(pool);
-	close(fd);
-	unlink(name);
-	free(name);
-	fd = -1;
+	void *data = NULL;
+	if (size > 0) {
+		char *name;
+		int fd = create_pool_file(size, &name);
+		assert(fd != -1);
+		data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+		struct wl_shm_pool *pool = wl_shm_create_pool(shm, fd, size);
+		buf->buffer = wl_shm_pool_create_buffer(pool, 0,
+				width, height, stride, format);
+		wl_buffer_add_listener(buf->buffer, &buffer_listener, buf);
+		wl_shm_pool_destroy(pool);
+		close(fd);
+		unlink(name);
+		free(name);
+		fd = -1;
+	}
 
 	buf->size = size;
 	buf->width = width;
@@ -92,8 +96,6 @@ static struct pool_buffer *create_buffer(struct wl_shm *shm,
 	buf->surface = cairo_image_surface_create_for_data(data,
 			CAIRO_FORMAT_ARGB32, width, height, stride);
 	buf->cairo = cairo_create(buf->surface);
-
-	wl_buffer_add_listener(buf->buffer, &buffer_listener, buf);
 	return buf;
 }
 

From 6ad41707847c04a555f803605c112a43d6b014ea Mon Sep 17 00:00:00 2001
From: Simon Ser <contact@emersion.fr>
Date: Wed, 10 Feb 2021 17:42:36 +0100
Subject: [PATCH 02/10] Initialize indicator size to zero

Initializing to 1 is incorrect when the surface scale is > 1.
---
 main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/main.c b/main.c
index 27621874..23ba1526 100644
--- a/main.c
+++ b/main.c
@@ -351,8 +351,8 @@ static void layer_surface_configure(void *data,
 	struct swaylock_surface *surface = data;
 	surface->width = width;
 	surface->height = height;
-	surface->indicator_width = 1;
-	surface->indicator_height = 1;
+	surface->indicator_width = 0;
+	surface->indicator_height = 0;
 	zwlr_layer_surface_v1_ack_configure(layer_surface, serial);
 
 	if (--surface->events_pending == 0) {

From e4f37a214956928b2134fb4455de1156d962dd1e Mon Sep 17 00:00:00 2001
From: Simon Ser <contact@emersion.fr>
Date: Wed, 10 Feb 2021 17:45:42 +0100
Subject: [PATCH 03/10] Use wl_surface.damage_buffer

We incorrectly used the buffer size instead of the surface size.
Let's not bother and just damage the maximum region.
---
 main.c   | 2 +-
 render.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/main.c b/main.c
index 23ba1526..f62a3a0f 100644
--- a/main.c
+++ b/main.c
@@ -707,7 +707,7 @@ static void handle_global(void *data, struct wl_registry *registry,
 	struct swaylock_state *state = data;
 	if (strcmp(interface, wl_compositor_interface.name) == 0) {
 		state->compositor = wl_registry_bind(registry, name,
-				&wl_compositor_interface, 3);
+				&wl_compositor_interface, 4);
 	} else if (strcmp(interface, wl_subcompositor_interface.name) == 0) {
 		state->subcompositor = wl_registry_bind(registry, name,
 				&wl_subcompositor_interface, 1);
diff --git a/render.c b/render.c
index 8866f6b8..47eda318 100644
--- a/render.c
+++ b/render.c
@@ -95,7 +95,7 @@ void render_frame_background(struct swaylock_surface *surface) {
 
 	wl_surface_set_buffer_scale(surface->surface, surface->scale);
 	wl_surface_attach(surface->surface, surface->current_buffer->buffer, 0, 0);
-	wl_surface_damage(surface->surface, 0, 0, surface->width, surface->height);
+	wl_surface_damage_buffer(surface->surface, 0, 0, INT32_MAX, INT32_MAX);
 	wl_surface_commit(surface->surface);
 }
 
@@ -454,7 +454,7 @@ void render_frame(struct swaylock_surface *surface) {
 
 	wl_surface_set_buffer_scale(surface->child, surface->scale);
 	wl_surface_attach(surface->child, surface->current_buffer->buffer, 0, 0);
-	wl_surface_damage(surface->child, 0, 0, surface->current_buffer->width, surface->current_buffer->height);
+	wl_surface_damage_buffer(surface->child, 0, 0, INT32_MAX, INT32_MAX);
 	wl_surface_commit(surface->child);
 
 	wl_surface_commit(surface->surface);

From 14baedc92de9b97f00aa6c35c2291a3af2d08ccd Mon Sep 17 00:00:00 2001
From: Elyes HAOUAS <ehaouas@noos.fr>
Date: Mon, 12 Apr 2021 18:21:01 +0200
Subject: [PATCH 04/10] Fix some typos

Signed-off-by: Elyes HAOUAS <ehaouas@noos.fr>
---
 render.c                        | 2 +-
 wlr-layer-shell-unstable-v1.xml | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/render.c b/render.c
index 47eda318..56b042bb 100644
--- a/render.c
+++ b/render.c
@@ -408,7 +408,7 @@ void render_frame(struct swaylock_surface *surface) {
 				arc_radius + arc_thickness / 2, 0, 2 * M_PI);
 		cairo_stroke(cairo);
 
-		// display layout text seperately
+		// display layout text separately
 		if (layout_text) {
 			cairo_text_extents_t extents;
 			cairo_font_extents_t fe;
diff --git a/wlr-layer-shell-unstable-v1.xml b/wlr-layer-shell-unstable-v1.xml
index 2bb72edd..f29eb879 100644
--- a/wlr-layer-shell-unstable-v1.xml
+++ b/wlr-layer-shell-unstable-v1.xml
@@ -140,7 +140,7 @@
         how they should interact with surfaces that do. If set to zero, the
         surface indicates that it would like to be moved to avoid occluding
         surfaces with a positive excluzive zone. If set to -1, the surface
-        indicates that it would not like to be moved to accomodate for other
+        indicates that it would not like to be moved to accommodate for other
         surfaces, and the compositor should extend it all the way to the edges
         it is anchored to.
 

From db2e60a8767dff6820c1633d3076213205d0352a Mon Sep 17 00:00:00 2001
From: loserMcloser <reebydobalina@gmail.com>
Date: Mon, 31 May 2021 15:01:59 -0600
Subject: [PATCH 05/10] Draw ring and inner fill separately

---
 render.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/render.c b/render.c
index 56b042bb..846cc076 100644
--- a/render.c
+++ b/render.c
@@ -214,12 +214,18 @@ void render_frame(struct swaylock_surface *surface) {
 
 	if (state->args.indicator ||
 			(upstream_show_indicator && state->auth_state != AUTH_STATE_GRACE)) {
-		// Draw circle
+		// Fill inner circle
+		cairo_set_line_width(cairo, 0);
+		cairo_arc(cairo, buffer_width / 2, buffer_diameter / 2,
+				arc_radius - arc_thickness / 2, 0, 2 * M_PI);
+		set_color_for_state(cairo, state, &state->args.colors.inside);
+		cairo_fill_preserve(cairo);
+		cairo_stroke(cairo);
+
+		// Draw ring
 		cairo_set_line_width(cairo, arc_thickness);
 		cairo_arc(cairo, buffer_width / 2, buffer_diameter / 2, arc_radius,
 				0, 2 * M_PI);
-		set_color_for_state(cairo, state, &state->args.colors.inside);
-		cairo_fill_preserve(cairo);
 		set_color_for_state(cairo, state, &state->args.colors.ring);
 		cairo_stroke(cairo);
 

From b834e01b51816096867797a3d36ed69b4ce226f5 Mon Sep 17 00:00:00 2001
From: Simon Plakolb <s.plakolb@gmail.com>
Date: Tue, 1 Jun 2021 01:49:58 +0200
Subject: [PATCH 06/10] Ensure buffer size is multiple of buffer scale

An odd value of fe.height lead to the indicator disappearing. This was
due to the buffer size no longer being a multiple of the buffer scale.
This commit fixes the issue by checking both height and width to be a
multiple of scale.

This is done early to avoid excessive re-calls of create_buffer if the
buffer_height != new_height in render.c line 314 (now 318).
---
 render.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/render.c b/render.c
index 846cc076..e2449e71 100644
--- a/render.c
+++ b/render.c
@@ -450,6 +450,10 @@ void render_frame(struct swaylock_surface *surface) {
 			}
 		}
 
+		// Ensure buffer size is multiple of buffer scale - required by protocol
+		new_height += surface->scale - (new_height % surface->scale);
+		new_width += surface->scale - (new_width % surface->scale);
+
 		if (buffer_width != new_width || buffer_height != new_height) {
 			destroy_buffer(surface->current_buffer);
 			surface->indicator_width = new_width;

From 7b3212761d0eef56a8cfb4b1034a3129220b7819 Mon Sep 17 00:00:00 2001
From: Michael Swiger <mokkan@gmail.com>
Date: Sun, 27 Jun 2021 20:46:01 -0700
Subject: [PATCH 07/10] Fix indicator buffer not resizing after display powers
 off

---
 render.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/render.c b/render.c
index e2449e71..241367e7 100644
--- a/render.c
+++ b/render.c
@@ -449,17 +449,17 @@ void render_frame(struct swaylock_surface *surface) {
 				new_width = extents.width + 2 * box_padding;
 			}
 		}
+	}
 
-		// Ensure buffer size is multiple of buffer scale - required by protocol
-		new_height += surface->scale - (new_height % surface->scale);
-		new_width += surface->scale - (new_width % surface->scale);
+	// Ensure buffer size is multiple of buffer scale - required by protocol
+	new_height += surface->scale - (new_height % surface->scale);
+	new_width += surface->scale - (new_width % surface->scale);
 
-		if (buffer_width != new_width || buffer_height != new_height) {
-			destroy_buffer(surface->current_buffer);
-			surface->indicator_width = new_width;
-			surface->indicator_height = new_height;
-			render_frame(surface);
-		}
+	if (buffer_width != new_width || buffer_height != new_height) {
+		destroy_buffer(surface->current_buffer);
+		surface->indicator_width = new_width;
+		surface->indicator_height = new_height;
+		render_frame(surface);
 	}
 
 	wl_surface_set_buffer_scale(surface->child, surface->scale);

From 1271020bc51353bfd96c8de393579da8670c8d75 Mon Sep 17 00:00:00 2001
From: Michael Swiger <mokkan@gmail.com>
Date: Mon, 5 Jul 2021 13:52:47 -0700
Subject: [PATCH 08/10] Prevent attaching and committing the surface twice

---
 render.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/render.c b/render.c
index 241367e7..ebf8bfb7 100644
--- a/render.c
+++ b/render.c
@@ -460,6 +460,7 @@ void render_frame(struct swaylock_surface *surface) {
 		surface->indicator_width = new_width;
 		surface->indicator_height = new_height;
 		render_frame(surface);
+		return;
 	}
 
 	wl_surface_set_buffer_scale(surface->child, surface->scale);

From dfff235b09b475e79d75a040a0307a359974d360 Mon Sep 17 00:00:00 2001
From: grumpey <grumpey0@gmail.com>
Date: Sun, 11 Jul 2021 13:40:46 -0400
Subject: [PATCH 09/10] Call fclose vice free, fixes #198

---
 main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/main.c b/main.c
index f62a3a0f..50504ce9 100644
--- a/main.c
+++ b/main.c
@@ -1667,7 +1667,7 @@ static int load_config(char *path, struct swaylock_state *state,
 		char *flag = malloc(nread + 3);
 		if (flag == NULL) {
 			free(line);
-			free(config);
+			fclose(config);
 			swaylock_log(LOG_ERROR, "Failed to allocate memory");
 			return 0;
 		}

From d16fad6453c2ea3ca349713b6d275426ea094a3b Mon Sep 17 00:00:00 2001
From: Simon Ser <contact@emersion.fr>
Date: Thu, 29 Jul 2021 09:08:39 +0200
Subject: [PATCH 10/10] Check for poll errors

---
 loop.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/loop.c b/loop.c
index 5cce8677..674b3107 100644
--- a/loop.c
+++ b/loop.c
@@ -81,7 +81,11 @@ void loop_poll(struct loop *loop) {
 		ms = 0;
 	}
 
-	poll(loop->fds, loop->fd_length, ms);
+	int ret = poll(loop->fds, loop->fd_length, ms);
+	if (ret < 0) {
+		swaylock_log_errno(LOG_ERROR, "poll failed");
+		exit(1);
+	}
 
 	// Dispatch fds
 	size_t fd_index = 0;