Trying it with the normal wlroots + patches
This commit is contained in:
		@@ -0,0 +1,14 @@
 | 
			
		||||
diff --git a/types/wlr_output_layout.c b/types/wlr_output_layout.c
 | 
			
		||||
index 28d91e8d42cfb75b9ca151be451e5ba287f33ca0..ef6e2850ca0e81d12b1cac9d1bc059b0f1f93694 100644
 | 
			
		||||
--- a/types/wlr_output_layout.c
 | 
			
		||||
+++ b/types/wlr_output_layout.c
 | 
			
		||||
@@ -231,6 +231,9 @@ bool wlr_output_layout_contains_point(struct wlr_output_layout *layout,
 | 
			
		||||
 	if (reference) {
 | 
			
		||||
 		struct wlr_output_layout_output *l_output =
 | 
			
		||||
 			wlr_output_layout_get(layout, reference);
 | 
			
		||||
+		if (!l_output) {
 | 
			
		||||
+			return false;
 | 
			
		||||
+		}
 | 
			
		||||
 		struct wlr_box output_box;
 | 
			
		||||
 		output_layout_output_get_box(l_output, &output_box);
 | 
			
		||||
 		return wlr_box_contains_point(&output_box, lx, ly);
 | 
			
		||||
@@ -0,0 +1,121 @@
 | 
			
		||||
diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h
 | 
			
		||||
index ebbcfd479e2c8bec747f2ef37ca344eb8cb48645..1946873ae846dcb1b26596fa61962b08b1e57228 100644
 | 
			
		||||
--- a/include/wlr/types/wlr_seat.h
 | 
			
		||||
+++ b/include/wlr/types/wlr_seat.h
 | 
			
		||||
@@ -119,9 +119,11 @@ struct wlr_touch_grab_interface {
 | 
			
		||||
 	void (*enter)(struct wlr_seat_touch_grab *grab, uint32_t time_msec,
 | 
			
		||||
 			struct wlr_touch_point *point);
 | 
			
		||||
 	void (*frame)(struct wlr_seat_touch_grab *grab);
 | 
			
		||||
-	// XXX this will conflict with the actual touch cancel which is different so
 | 
			
		||||
-	// we need to rename this
 | 
			
		||||
+	// Cancel grab
 | 
			
		||||
 	void (*cancel)(struct wlr_seat_touch_grab *grab);
 | 
			
		||||
+	// Send wl_touch::cancel
 | 
			
		||||
+	void (*wl_cancel)(struct wlr_seat_touch_grab *grab,
 | 
			
		||||
+			struct wlr_surface *surface);
 | 
			
		||||
 };
 | 
			
		||||
 
 | 
			
		||||
 /**
 | 
			
		||||
@@ -613,6 +615,14 @@ void wlr_seat_touch_send_up(struct wlr_seat *seat, uint32_t time_msec,
 | 
			
		||||
 void wlr_seat_touch_send_motion(struct wlr_seat *seat, uint32_t time_msec,
 | 
			
		||||
 		int32_t touch_id, double sx, double sy);
 | 
			
		||||
 
 | 
			
		||||
+/**
 | 
			
		||||
+ * Notify the seat that this is a global gesture and the client should cancel
 | 
			
		||||
+ * processing it. The event will go to the client for the surface given.
 | 
			
		||||
+ * This function does not respect touch grabs: you probably want
 | 
			
		||||
+ * `wlr_seat_touch_notify_cancel()` instead.
 | 
			
		||||
+ */
 | 
			
		||||
+void wlr_seat_touch_send_cancel(struct wlr_seat *seat, struct wlr_surface *surface);
 | 
			
		||||
+
 | 
			
		||||
 void wlr_seat_touch_send_frame(struct wlr_seat *seat);
 | 
			
		||||
 
 | 
			
		||||
 /**
 | 
			
		||||
@@ -639,6 +649,13 @@ void wlr_seat_touch_notify_up(struct wlr_seat *seat, uint32_t time_msec,
 | 
			
		||||
 void wlr_seat_touch_notify_motion(struct wlr_seat *seat, uint32_t time_msec,
 | 
			
		||||
 		int32_t touch_id, double sx, double sy);
 | 
			
		||||
 
 | 
			
		||||
+/**
 | 
			
		||||
+ * Notify the seat that this is a global gesture and the client should
 | 
			
		||||
+ * cancel processing it. Defers to any grab of the touch device.
 | 
			
		||||
+ */
 | 
			
		||||
+void wlr_seat_touch_notify_cancel(struct wlr_seat *seat,
 | 
			
		||||
+		struct wlr_surface *surface);
 | 
			
		||||
+
 | 
			
		||||
 void wlr_seat_touch_notify_frame(struct wlr_seat *seat);
 | 
			
		||||
 
 | 
			
		||||
 /**
 | 
			
		||||
diff --git a/types/seat/wlr_seat_touch.c b/types/seat/wlr_seat_touch.c
 | 
			
		||||
index 65a8c7c06c1d9ec35c68e0cb8e7b46ca3039fb3c..abc17ae2ce7a04bb1d533c794a754f30eb681375 100644
 | 
			
		||||
--- a/types/seat/wlr_seat_touch.c
 | 
			
		||||
+++ b/types/seat/wlr_seat_touch.c
 | 
			
		||||
@@ -41,6 +41,11 @@ static void default_touch_cancel(struct wlr_seat_touch_grab *grab) {
 | 
			
		||||
 	// cannot be cancelled
 | 
			
		||||
 }
 | 
			
		||||
 
 | 
			
		||||
+static void default_touch_wl_cancel(struct wlr_seat_touch_grab *grab,
 | 
			
		||||
+		struct wlr_surface *surface) {
 | 
			
		||||
+	wlr_seat_touch_send_cancel(grab->seat, surface);
 | 
			
		||||
+}
 | 
			
		||||
+
 | 
			
		||||
 const struct wlr_touch_grab_interface default_touch_grab_impl = {
 | 
			
		||||
 	.down = default_touch_down,
 | 
			
		||||
 	.up = default_touch_up,
 | 
			
		||||
@@ -48,6 +53,7 @@ const struct wlr_touch_grab_interface default_touch_grab_impl = {
 | 
			
		||||
 	.enter = default_touch_enter,
 | 
			
		||||
 	.frame = default_touch_frame,
 | 
			
		||||
 	.cancel = default_touch_cancel,
 | 
			
		||||
+	.wl_cancel = default_touch_wl_cancel,
 | 
			
		||||
 };
 | 
			
		||||
 
 | 
			
		||||
 
 | 
			
		||||
@@ -238,6 +244,26 @@ void wlr_seat_touch_notify_frame(struct wlr_seat *seat) {
 | 
			
		||||
 	}
 | 
			
		||||
 }
 | 
			
		||||
 
 | 
			
		||||
+void wlr_seat_touch_notify_cancel(struct wlr_seat *seat,
 | 
			
		||||
+		struct wlr_surface *surface) {
 | 
			
		||||
+	struct wlr_seat_touch_grab *grab = seat->touch_state.grab;
 | 
			
		||||
+	if (grab->interface->wl_cancel) {
 | 
			
		||||
+		grab->interface->wl_cancel(grab, surface);
 | 
			
		||||
+	}
 | 
			
		||||
+
 | 
			
		||||
+	struct wl_client *client = wl_resource_get_client(surface->resource);
 | 
			
		||||
+	struct wlr_seat_client *seat_client = wlr_seat_client_for_wl_client(seat, client);
 | 
			
		||||
+	if (seat_client == NULL) {
 | 
			
		||||
+		return;
 | 
			
		||||
+	}
 | 
			
		||||
+	struct wlr_touch_point *point, *tmp;
 | 
			
		||||
+	wl_list_for_each_safe(point, tmp, &seat->touch_state.touch_points, link) {
 | 
			
		||||
+		if (point->client == seat_client) {
 | 
			
		||||
+			touch_point_destroy(point);
 | 
			
		||||
+		}
 | 
			
		||||
+	}
 | 
			
		||||
+}
 | 
			
		||||
+
 | 
			
		||||
 static void handle_point_focus_destroy(struct wl_listener *listener,
 | 
			
		||||
 		void *data) {
 | 
			
		||||
 	struct wlr_touch_point *point =
 | 
			
		||||
@@ -376,6 +402,22 @@ void wlr_seat_touch_send_frame(struct wlr_seat *seat) {
 | 
			
		||||
 	}
 | 
			
		||||
 }
 | 
			
		||||
 
 | 
			
		||||
+void wlr_seat_touch_send_cancel(struct wlr_seat *seat, struct wlr_surface *surface) {
 | 
			
		||||
+	struct wl_client *client = wl_resource_get_client(surface->resource);
 | 
			
		||||
+	struct wlr_seat_client *seat_client = wlr_seat_client_for_wl_client(seat, client);
 | 
			
		||||
+	if (seat_client == NULL) {
 | 
			
		||||
+		return;
 | 
			
		||||
+	}
 | 
			
		||||
+
 | 
			
		||||
+	struct wl_resource *resource;
 | 
			
		||||
+	wl_resource_for_each(resource, &seat_client->touches) {
 | 
			
		||||
+		if (seat_client_from_touch_resource(resource) == NULL) {
 | 
			
		||||
+			continue;
 | 
			
		||||
+		}
 | 
			
		||||
+		wl_touch_send_cancel(resource);
 | 
			
		||||
+	}
 | 
			
		||||
+}
 | 
			
		||||
+
 | 
			
		||||
 int wlr_seat_touch_num_points(struct wlr_seat *seat) {
 | 
			
		||||
 	return wl_list_length(&seat->touch_state.touch_points);
 | 
			
		||||
 }
 | 
			
		||||
@@ -0,0 +1,31 @@
 | 
			
		||||
diff --git a/types/wlr_layer_shell_v1.c b/types/wlr_layer_shell_v1.c
 | 
			
		||||
index d83b22b8660273e13178c9d1899fd33c33d2a8d5..bc68111797552f06337eccd612c6230cfdac5f99 100644
 | 
			
		||||
--- a/types/wlr_layer_shell_v1.c
 | 
			
		||||
+++ b/types/wlr_layer_shell_v1.c
 | 
			
		||||
@@ -307,6 +307,26 @@ static void layer_surface_role_commit(struct wlr_surface *wlr_surface) {
 | 
			
		||||
 		return;
 | 
			
		||||
 	}
 | 
			
		||||
 
 | 
			
		||||
+	const uint32_t horiz = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
 | 
			
		||||
+		ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
 | 
			
		||||
+	if (surface->client_pending.desired_width == 0 &&
 | 
			
		||||
+		(surface->client_pending.anchor & horiz) != horiz) {
 | 
			
		||||
+		wl_resource_post_error(surface->resource,
 | 
			
		||||
+			ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_SIZE,
 | 
			
		||||
+			"width 0 requested without setting left and right anchors");
 | 
			
		||||
+		return;
 | 
			
		||||
+	}
 | 
			
		||||
+
 | 
			
		||||
+	const uint32_t vert = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP |
 | 
			
		||||
+		ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
 | 
			
		||||
+	if (surface->client_pending.desired_height == 0 &&
 | 
			
		||||
+		(surface->client_pending.anchor & vert) != vert) {
 | 
			
		||||
+		wl_resource_post_error(surface->resource,
 | 
			
		||||
+			ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_SIZE,
 | 
			
		||||
+			"height 0 requested without setting top and bottom anchors");
 | 
			
		||||
+		return;
 | 
			
		||||
+	}
 | 
			
		||||
+
 | 
			
		||||
 	if (surface->closed) {
 | 
			
		||||
 		// Ignore commits after the compositor has closed it
 | 
			
		||||
 		return;
 | 
			
		||||
@@ -0,0 +1,83 @@
 | 
			
		||||
diff --git a/types/wlr_xdg_activation_v1.c b/types/wlr_xdg_activation_v1.c
 | 
			
		||||
index 02ba9e07f2b60857a3cdc1848f149c2d476161f7..c54364cccae258daea400724d4822bdb72f97fb5 100644
 | 
			
		||||
--- a/types/wlr_xdg_activation_v1.c
 | 
			
		||||
+++ b/types/wlr_xdg_activation_v1.c
 | 
			
		||||
@@ -248,15 +248,11 @@ static void activation_handle_destroy(struct wl_client *client,
 | 
			
		||||
 	wl_resource_destroy(activation_resource);
 | 
			
		||||
 }
 | 
			
		||||
 
 | 
			
		||||
-static void activation_handle_get_activation_token(struct wl_client *client,
 | 
			
		||||
-		struct wl_resource *activation_resource, uint32_t id) {
 | 
			
		||||
-	struct wlr_xdg_activation_v1 *activation =
 | 
			
		||||
-		activation_from_resource(activation_resource);
 | 
			
		||||
-
 | 
			
		||||
+static struct wlr_xdg_activation_token_v1 *activation_token_create(
 | 
			
		||||
+		struct wlr_xdg_activation_v1 *activation) {
 | 
			
		||||
 	struct wlr_xdg_activation_token_v1 *token = calloc(1, sizeof(*token));
 | 
			
		||||
 	if (token == NULL) {
 | 
			
		||||
-		wl_client_post_no_memory(client);
 | 
			
		||||
-		return;
 | 
			
		||||
+		return NULL;
 | 
			
		||||
 	}
 | 
			
		||||
 	wl_list_init(&token->link);
 | 
			
		||||
 	wl_list_init(&token->seat_destroy.link);
 | 
			
		||||
@@ -265,6 +261,20 @@ static void activation_handle_get_activation_token(struct wl_client *client,
 | 
			
		||||
 
 | 
			
		||||
 	token->activation = activation;
 | 
			
		||||
 
 | 
			
		||||
+	return token;
 | 
			
		||||
+}
 | 
			
		||||
+
 | 
			
		||||
+static void activation_handle_get_activation_token(struct wl_client *client,
 | 
			
		||||
+		struct wl_resource *activation_resource, uint32_t id) {
 | 
			
		||||
+	struct wlr_xdg_activation_v1 *activation =
 | 
			
		||||
+		activation_from_resource(activation_resource);
 | 
			
		||||
+
 | 
			
		||||
+	struct wlr_xdg_activation_token_v1 *token = activation_token_create(activation);
 | 
			
		||||
+	if (token == NULL) {
 | 
			
		||||
+		wl_client_post_no_memory(client);
 | 
			
		||||
+		return;
 | 
			
		||||
+	}
 | 
			
		||||
+
 | 
			
		||||
 	uint32_t version = wl_resource_get_version(activation_resource);
 | 
			
		||||
 	token->resource = wl_resource_create(client,
 | 
			
		||||
 		&xdg_activation_token_v1_interface, version, id);
 | 
			
		||||
@@ -371,19 +381,12 @@ struct wlr_xdg_activation_v1 *wlr_xdg_activation_v1_create(
 | 
			
		||||
 
 | 
			
		||||
 struct wlr_xdg_activation_token_v1 *wlr_xdg_activation_token_v1_create(
 | 
			
		||||
 		struct wlr_xdg_activation_v1 *activation) {
 | 
			
		||||
-	struct wlr_xdg_activation_token_v1 *token = calloc(1, sizeof(*token));
 | 
			
		||||
+	struct wlr_xdg_activation_token_v1 *token = activation_token_create(activation);
 | 
			
		||||
+
 | 
			
		||||
 	if (token == NULL) {
 | 
			
		||||
 		return NULL;
 | 
			
		||||
 	}
 | 
			
		||||
 
 | 
			
		||||
-	wl_list_init(&token->link);
 | 
			
		||||
-	// Currently no way to set seat/surface
 | 
			
		||||
-	wl_list_init(&token->seat_destroy.link);
 | 
			
		||||
-	wl_list_init(&token->surface_destroy.link);
 | 
			
		||||
-	wl_signal_init(&token->events.destroy);
 | 
			
		||||
-
 | 
			
		||||
-	token->activation = activation;
 | 
			
		||||
-
 | 
			
		||||
 	if (!token_init(token)) {
 | 
			
		||||
 		wlr_xdg_activation_token_v1_destroy(token);
 | 
			
		||||
 		return NULL;
 | 
			
		||||
@@ -412,15 +415,10 @@ struct wlr_xdg_activation_token_v1 *wlr_xdg_activation_v1_add_token(
 | 
			
		||||
 		struct wlr_xdg_activation_v1 *activation, const char *token_str) {
 | 
			
		||||
 	assert(token_str);
 | 
			
		||||
 
 | 
			
		||||
-	struct wlr_xdg_activation_token_v1 *token = calloc(1, sizeof(*token));
 | 
			
		||||
+	struct wlr_xdg_activation_token_v1 *token = activation_token_create(activation);
 | 
			
		||||
 	if (token == NULL) {
 | 
			
		||||
 		return NULL;
 | 
			
		||||
 	}
 | 
			
		||||
-	wl_list_init(&token->link);
 | 
			
		||||
-	wl_list_init(&token->seat_destroy.link);
 | 
			
		||||
-	wl_list_init(&token->surface_destroy.link);
 | 
			
		||||
-
 | 
			
		||||
-	token->activation = activation;
 | 
			
		||||
 	token->token = strdup(token_str);
 | 
			
		||||
 
 | 
			
		||||
 	wl_list_insert(&activation->tokens, &token->link);
 | 
			
		||||
@@ -0,0 +1,55 @@
 | 
			
		||||
From 7d950f3dac6cca62635d5e4ff2af33b35372f6db Mon Sep 17 00:00:00 2001
 | 
			
		||||
From: Simon Ser <contact@emersion.fr>
 | 
			
		||||
Date: Sat, 19 Mar 2022 14:00:43 +0100
 | 
			
		||||
Subject: [PATCH] tinywl: don't crash when there is no keyboard
 | 
			
		||||
 | 
			
		||||
Running with WLR_BACKENDS=headless, there is no keyboard device.
 | 
			
		||||
Avoid crashes like so:
 | 
			
		||||
 | 
			
		||||
    ../tinywl/tinywl.c:136:2: runtime error: member access within null pointer of type 'struct wlr_keyboard'
 | 
			
		||||
    ../tinywl/tinywl.c:136:2: runtime error: member access within null pointer of type 'struct wlr_keyboard'
 | 
			
		||||
    AddressSanitizer:DEADLYSIGNAL
 | 
			
		||||
    =================================================================
 | 
			
		||||
    ==331107==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000120 (pc 0x556ed03e4e99 bp 0x7ffce834bc10 sp 0x7ffce834bbb0 T0)
 | 
			
		||||
    ==331107==The signal is caused by a READ memory access.
 | 
			
		||||
    ==331107==Hint: address points to the zero page.
 | 
			
		||||
        #0 0x556ed03e4e99 in focus_view ../tinywl/tinywl.c:136
 | 
			
		||||
        #1 0x556ed03eb3be in xdg_toplevel_map ../tinywl/tinywl.c:603
 | 
			
		||||
        #2 0x7f75d6f768db in wlr_signal_emit_safe ../util/signal.c:29
 | 
			
		||||
        #3 0x7f75d6e9cac7 in xdg_surface_role_commit ../types/xdg_shell/wlr_xdg_surface.c:315
 | 
			
		||||
        #4 0x7f75d6eb6944 in surface_commit_state ../types/wlr_compositor.c:466
 | 
			
		||||
        #5 0x7f75d6eb7b02 in surface_handle_commit ../types/wlr_compositor.c:523
 | 
			
		||||
        #6 0x7f75d5714d49  (/usr/lib/libffi.so.8+0x6d49)
 | 
			
		||||
        #7 0x7f75d5714266  (/usr/lib/libffi.so.8+0x6266)
 | 
			
		||||
        #8 0x7f75d68cb322  (/usr/lib/libwayland-server.so.0+0xd322)
 | 
			
		||||
        #9 0x7f75d68c65cb  (/usr/lib/libwayland-server.so.0+0x85cb)
 | 
			
		||||
        #10 0x7f75d68c91c9 in wl_event_loop_dispatch (/usr/lib/libwayland-server.so.0+0xb1c9)
 | 
			
		||||
        #11 0x7f75d68c6d36 in wl_display_run (/usr/lib/libwayland-server.so.0+0x8d36)
 | 
			
		||||
        #12 0x556ed03eef55 in main ../tinywl/tinywl.c:905
 | 
			
		||||
        #13 0x7f75d5d2330f in __libc_start_call_main (/usr/lib/libc.so.6+0x2d30f)
 | 
			
		||||
        #14 0x7f75d5d233c0 in __libc_start_main@GLIBC_2.2.5 (/usr/lib/libc.so.6+0x2d3c0)
 | 
			
		||||
        #15 0x556ed03e46e4 in _start (/home/simon/src/wlroots/build/tinywl/tinywl+0x136e4)
 | 
			
		||||
---
 | 
			
		||||
 tinywl/tinywl.c | 6 ++++--
 | 
			
		||||
 1 file changed, 4 insertions(+), 2 deletions(-)
 | 
			
		||||
 | 
			
		||||
diff --git a/tinywl/tinywl.c b/tinywl/tinywl.c
 | 
			
		||||
index dd442aac..8796e9df 100644
 | 
			
		||||
--- a/tinywl/tinywl.c
 | 
			
		||||
+++ b/tinywl/tinywl.c
 | 
			
		||||
@@ -130,8 +130,10 @@ static void focus_view(struct tinywl_view *view, struct wlr_surface *surface) {
 | 
			
		||||
 	 * track of this and automatically send key events to the appropriate
 | 
			
		||||
 	 * clients without additional work on your part.
 | 
			
		||||
 	 */
 | 
			
		||||
-	wlr_seat_keyboard_notify_enter(seat, view->xdg_surface->surface,
 | 
			
		||||
-		keyboard->keycodes, keyboard->num_keycodes, &keyboard->modifiers);
 | 
			
		||||
+	if (keyboard != NULL) {
 | 
			
		||||
+		wlr_seat_keyboard_notify_enter(seat, view->xdg_surface->surface,
 | 
			
		||||
+			keyboard->keycodes, keyboard->num_keycodes, &keyboard->modifiers);
 | 
			
		||||
+	}
 | 
			
		||||
 }
 | 
			
		||||
 
 | 
			
		||||
 static void keyboard_handle_modifiers(
 | 
			
		||||
-- 
 | 
			
		||||
2.36.1
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user