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

#29: adding touch support #50

Merged
merged 1 commit into from
Apr 7, 2020
Merged

Conversation

gg-rewrite
Copy link
Contributor

Selection by a single touch point, similar to the mouse.

Boilerplate code for touch handling is added.

Three pieces of code are moved to separate functions from handle_pointer* methods so as to be reused by the corresponding handle_touch* one.

@gg-rewrite gg-rewrite mentioned this pull request Mar 13, 2020
include/slurp.h Outdated
// touch:
struct wl_touch *wl_touch;
bool already_touched;
struct slurp_output *current_touch_output;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this field? Can't we just use current_output?

Copy link
Contributor Author

@gg-rewrite gg-rewrite Mar 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but this one is a bit trickier.

Initially I wanted to use current_output but it was null when entering touch_handle_motion. I've investigated further and found out that

  1. pointer_leave event is triggered whenever touch down happens (even if mouse is not moved).
  2. handle_pointer_leave clears the current_output.

I think the solution is either

  • checking if has_selection is true and then leaving current_output be
  • leaving pointer_handle_leave empty since clearing current_output is the only thing the method does (until multi-monitor funcitonality is added).

Which one is better?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pointer_leave event is triggered whenever touch down happens (even if mouse is not moved).

That sounds like a Sway bug.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like a Sway bug.

Confirmed as this doesn't happen in wayfire. Opened an issue swaywm/sway#5145 for this one.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tracking it down!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "real" solution would be to handle pointer input and touch input completely separately. Basically put the currently shared state in a struct and have two separate fields with this struct (one for pointer, one for touch). It would be a bigger change though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure I got it right:

//selection (pointer/touch):
	struct {
		struct slurp_output *current_output;
		struct slurp_output *current_touch_output;
		int32_t x, y;
		int32_t anchor_x, anchor_y;
		struct slurp_box selection;
		bool has_selection;
	} selection;

Something like this?

Copy link
Owner

@emersion emersion Apr 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is to track the position of the pointer and touch points independently. So we'd have:

struct slurp_selection {
	struct slurp_output *current_output;
	int32_t x, y;
	int32_t anchor_x, anchor_y;
	struct slurp_box box;
	bool valid;
};

struct slurp_seat {
	…

	struct slurp_selection pointer;
	struct slurp_selection touch;
};

However, I'm fine with keeping this for a future pull request.

Now that the Sway patch has been merged, we can get rid of current_touch_output.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And done 4e127e3.

main.c Outdated
@@ -218,6 +231,54 @@ static const struct wl_keyboard_listener keyboard_listener = {
.modifiers = noop,
};

static void touch_handle_down(void *data, struct wl_touch *touch, uint32_t serial,
uint32_t time, struct wl_surface *surface, int32_t id,
Copy link
Owner

@emersion emersion Apr 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: we don't align, we use two tabs instead (also applies to other functions).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 1e21b35.

main.c Outdated
}

static void touch_handle_cancel(void *data, struct wl_touch *touch)
{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: no newline between ) and {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also done.

main.c Outdated
uint32_t time, struct wl_surface *surface, int32_t id,
wl_fixed_t x, wl_fixed_t y) {
struct slurp_seat *seat = data;
if (!seat->already_touched) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having a bool already_touched field, can we store the touch id and check it's the correct one in touch_handle_motion?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed 585646d. Turns out this also fixes segfaults when attempting to select with different fingers, thanks for this one.

include/slurp.h Outdated
@@ -82,8 +84,8 @@ struct slurp_seat {
int32_t anchor_x, anchor_y;
struct slurp_box selection;
bool has_selection;
bool already_touched;

int32_t touch_id;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last nit:" can we move this to the "touch" section below?

@emersion
Copy link
Owner

emersion commented Apr 7, 2020

If you could rebase and squash everything into a single commit, that'd make it ready for being merged :)

Copy link
Owner

@emersion emersion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for working on this!

@emersion
Copy link
Owner

emersion commented Apr 7, 2020

Can we pick a better commit summary + message? Something like:

Add touch support

Closes: https://github.com/emersion/slurp/issues/29

@emersion emersion merged commit 8d2117c into emersion:master Apr 7, 2020
@emersion
Copy link
Owner

emersion commented Apr 7, 2020

Thanks!

@gg-rewrite gg-rewrite deleted the touch-selection branch May 30, 2020 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants