~leon_plickat/lavalauncher

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
3 2

[PATCH v3] Add multi finger touch support

Details
Message ID
<20200713152502.2022273-1-nicolai@dagestad.fr>
DKIM signature
pass
Download raw message
Patch: +81 -47
---
I should have addressed all your comments.

I also found out that there is a region outside the first button in which 
it is possible to escape the launcher without it being seen as outside the
item (only with touch), but I don't think it is realated to this patch.


 src/input.c | 71 +++++++++++++++++++++--------------------------------
 src/seat.c  | 38 ++++++++++++++++++++++++++++
 src/seat.h  | 19 +++++++++++---
 3 files changed, 81 insertions(+), 47 deletions(-)

diff --git a/src/input.c b/src/input.c
index c9ba753..f50d40e 100644
--- a/src/input.c
+++ b/src/input.c
@@ -2,6 +2,7 @@
 * LavaLauncher - A simple launcher panel for Wayland
 *
 * Copyright (C) 2020 Leon Henrik Plickat
 * Copyright (C) 2020 Nicolai Dagestad
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
@@ -249,32 +250,18 @@ static void touch_handle_up (void *raw_data, struct wl_touch *wl_touch,
		uint32_t serial, uint32_t time, int32_t id)
{
	struct Lava_seat *seat = (struct Lava_seat *)raw_data;
	if ( seat->touch.bar == NULL )
	{
		fputs("ERROR: Touch-Up event could not be handled: "
				"Bar could not be found.\n", stderr);
		return;
	}
	struct Lava_touchpoint *current=NULL;
	wl_list_for_each(current, &seat->touch.touchpoints, link)
		if ( current->id == id )
			goto touchpoint_found;
	return;

touchpoint_found:
	if (seat->data->verbose)
		fputs("Touch up.\n", stderr);

	/* If this touch event does not have the same id as the touch-down event
	 * which initiated the touch operation, abort. Also abort if no touch
	 * operation has been initiated.
	 */
	if ( ! seat->touch.item || id != seat->touch.id )
	{
		seat->touch.item = NULL;
		seat->touch.bar  = NULL;
		return;
	}

	/* At this point, we know for sure that we have received a touch-down
	 * and the following touch-up event over the same item, so we can
	 * interact with it.
	 */
	item_interaction(seat->touch.bar, seat->touch.item, TYPE_TOUCH);
	item_interaction(current->bar, current->item, TYPE_TOUCH);
	destroy_touchpoint(current);
}

static void touch_handle_down (void *raw_data, struct wl_touch *wl_touch,
@@ -283,45 +270,43 @@ static void touch_handle_down (void *raw_data, struct wl_touch *wl_touch,
		wl_fixed_t fx, wl_fixed_t fy)
{
	struct Lava_seat *seat = (struct Lava_seat *)raw_data;

	uint32_t x = wl_fixed_to_int(fx), y = wl_fixed_to_int(fy);

	if (seat->data->verbose)
		fprintf(stderr, "Touch down: x=%d y=%d\n", x, y);

	seat->touch.bar = bar_from_surface(seat->data, surface);

	seat->touch.id   = id;
	seat->touch.item = item_from_coords(seat->touch.bar, x, y);
	struct Lava_bar *bar  = bar_from_surface(seat->data, surface);
	struct Lava_item *item = item_from_coords(bar, x, y);
	if (! create_touchpoint(seat, id, bar, item))
		fputs("ERROR: could not create touchpoint\n", stderr);
}

static void touch_handle_motion (void *raw_data, struct wl_touch *wl_touch,
		uint32_t time, int32_t id, wl_fixed_t x, wl_fixed_t y)
		uint32_t time, int32_t id, wl_fixed_t fx, wl_fixed_t fy)
{
	struct Lava_seat *seat = (struct Lava_seat *)raw_data;
	struct Lava_touchpoint *current=NULL;
	wl_list_for_each(current, &seat->touch.touchpoints, link)
		if ( current->id == id )
			goto touchpoint_found;
	return;

touchpoint_found:
	if (seat->data->verbose)
		fputs("Touch move.\n", stderr);
		fprintf(stderr,"Touch move\n");

	if ( id != seat->touch.id )
		return;

	/* The touch point has been moved, meaning it likely is no longer over
	 * the item, so we simply abort the touch operation.
	/* If the item under the touch point is not the same we first touched,
	 * we simply abort the touch operation.
	 */
	seat->touch.item = NULL;
	seat->touch.bar  = NULL;
	uint32_t x = wl_fixed_to_int(fx), y = wl_fixed_to_int(fy);
	if ( item_from_coords(current->bar, x, y) != current->item )
		destroy_touchpoint(current);
}

/* These are the handlers for touch events. We only want to interact with an
 * item, if both touch-down and touch-up were over the same item. To
 * achieve this, touch_handle_down() will store the touch id and the item in
 * the seat. touch_handle_up() checks whether a item is stored in the seat and
 * whether its id is the same as the one stored in the seat and if both are true
 * interacts with the item. touch_handle_motion() will simply remove the item
 * from the seat, effectively aborting the touch operation.
 *
 * Behold: Since I lack the necessary hardware, touch support is untested.
 * achieve this, each touch event is stored in the wl_list, inside seat->touch.
 * This ways we can follow each of them without needing any extra logic.
 */
const struct wl_touch_listener touch_listener = {
	.down        = touch_handle_down,
diff --git a/src/seat.c b/src/seat.c
index 0a83a29..d434b62 100644
--- a/src/seat.c
+++ b/src/seat.c
@@ -2,6 +2,7 @@
 * LavaLauncher - A simple launcher panel for Wayland
 *
 * Copyright (C) 2020 Leon Henrik Plickat
 * Copyright (C) 2020 Nicolai Dagestad
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
@@ -97,6 +98,7 @@ bool create_seat (struct Lava_data *data, struct wl_registry *registry,

	seat->data    = data;
	seat->wl_seat = wl_seat;
	wl_list_init(&seat->touch.touchpoints);
	wl_list_insert(&data->seats, &seat->link);
	wl_seat_add_listener(wl_seat, &seat_listener, seat);

@@ -109,7 +111,10 @@ static void destroy_seat (struct Lava_seat *seat)
	wl_seat_release(seat->wl_seat);
	if (seat->pointer.wl_pointer)
		wl_pointer_release(seat->pointer.wl_pointer);
	if (seat->touch.wl_touch)
		wl_touch_release(seat->touch.wl_touch);
	cleanup_cursor(seat);
	destroy_all_touchpoints(seat);
	free(seat);
}

@@ -121,3 +126,36 @@ void destroy_all_seats (struct Lava_data *data)
	wl_list_for_each_safe(st_1, st_2, &data->seats, link)
		destroy_seat(st_1);
}

bool create_touchpoint (struct Lava_seat *seat, int32_t id,
          struct Lava_bar *bar, struct Lava_item *item){
	if (seat->data->verbose)
		fputs("Creatinging touchpoints.\n", stderr);

	struct Lava_touchpoint *touchpoint = calloc(1, sizeof(struct Lava_touchpoint));
	if ( touchpoint == NULL )
	{
		fputs("ERROR: Could not allocate.\n", stderr);
		return false;
	}
	touchpoint->id   = id;
	touchpoint->bar  = bar;
	touchpoint->item = item;
	wl_list_insert(&seat->touch.touchpoints, &touchpoint->link);
	return true;
}

void destroy_touchpoint (struct Lava_touchpoint *touchpoint){
	wl_list_remove(&touchpoint->link);
	free(touchpoint);
}

void destroy_all_touchpoints (struct Lava_seat *seat){
	if (seat->data->verbose)
		fputs("Destroying touchpoints.\n", stderr);
	
	struct Lava_touchpoint *tmp=NULL,*point=NULL;
	wl_list_for_each_safe(point, tmp, &seat->touch.touchpoints, link){
		destroy_touchpoint(point);
	}
}
diff --git a/src/seat.h b/src/seat.h
index ae6f622..c85657f 100644
--- a/src/seat.h
+++ b/src/seat.h
@@ -2,6 +2,7 @@
 * LavaLauncher - A simple launcher panel for Wayland
 *
 * Copyright (C) 2020 Leon Henrik Plickat
 * Copyright (C) 2020 Nicolai Dagestad
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
@@ -55,10 +56,8 @@ struct Lava_seat

	struct
	{
		struct wl_touch  *wl_touch;
		int32_t           id;
		struct Lava_bar  *bar;
		struct Lava_item *item;
		struct wl_touch *wl_touch;
		struct wl_list   touchpoints;
	} touch;
};

@@ -66,4 +65,16 @@ bool create_seat (struct Lava_data *data, struct wl_registry *registry,
		uint32_t name, const char *interface, uint32_t version);
void destroy_all_seats (struct Lava_data *data);

struct Lava_touchpoint
{
	struct wl_list    link;
	int32_t           id;
	struct Lava_bar  *bar;
	struct Lava_item *item;
};

bool create_touchpoint (struct Lava_seat *seat, int32_t id,
		struct Lava_bar *bar, struct Lava_item *item);
void destroy_touchpoint (struct Lava_touchpoint *touchpoint);
void destroy_all_touchpoints (struct Lava_seat *seat);
#endif
-- 
2.27.0
Details
Message ID
<C45LRSSW9WI4.NUKWKNT8GLQX@tarazed>
In-Reply-To
<20200713152502.2022273-1-nicolai@dagestad.fr> (view parent)
DKIM signature
missing
Download raw message
LGTM, will commit. Only a single brace placement is off, but I'll just
fix that myself.

Thanks.

On Mon Jul 13, 2020 at 7:25 PM CEST, Nicolai Dagestad wrote:
> I also found out that there is a region outside the first button in
> which it is possible to escape the launcher without it being seen as
> outside the item (only with touch), but I don't think it is realated
> to this patch.

Nope, that should belong into a dedicated bug-fix patch.


Friendly greetings,
Leon Plickat
Details
Message ID
<C45M102QG2FJ.1FI8SMGC7RZV6@tarazed>
In-Reply-To
<20200713152502.2022273-1-nicolai@dagestad.fr> (view parent)
DKIM signature
missing
Download raw message
By the way, if you have an interesting screenshot of LavaLauncher
running on your pine phone, I'd be interested to see it.

I am planning to replace the example picture with a tiny GIF that
loops over a few different examples to demonstrate some abilities and
I think phones are an important use case of LavaLauncher and should be
included there.


Friendly greetings,
Leon Plickat
Details
Message ID
<C45NH1K7M7DW.33SLFXBY6547Y@bladestealth>
In-Reply-To
<C45M102QG2FJ.1FI8SMGC7RZV6@tarazed> (view parent)
DKIM signature
pass
Download raw message
On Mon Jul 13, 2020 at 5:43 PM CEST, Leon Plickat wrote:
> By the way, if you have an interesting screenshot of LavaLauncher
> running on your pine phone, I'd be interested to see it.

I haven't yet even ran it on my pinephone, all my developpement has been 
done on my laptop's touchscreen. Once I have something I'll let you know 👍
Review patch Export thread (mbox)