Nothing Special   »   [go: up one dir, main page]

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

[WIP] Implement touch gestures using libtouch #3428

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft

[WIP] Implement touch gestures using libtouch #3428

wants to merge 17 commits into from

Conversation

grahnen
Copy link
@grahnen grahnen commented Jan 15, 2019

Implementing touch gesture recognition through libtouch, for now at https://github.com/grahnen/libtouch

I've begun doing what I think is correct, but I am not very well versed in the inner workings of sway, so feel free to correct me if I'm doing something wrong.

sway/input/cursor.c Outdated Show resolved Hide resolved
@grahnen
Copy link
Author
grahnen commented Jan 16, 2019

I am starting to come to the conclusion that I have no idea what I'm doing right now. Not sure I understand how the configuration parsing works, and I don't know how to extend it to support the syntax of #1904. I've done what i think looks correct-ish, but sway still says touch is an invalid command.

@RedSoxFan
Copy link
Member

So implementing the syntax in #1904 is going to have some challenges with the current config parser. It predates the generic code blocks PR

I'd propose the following instead:

# Declare variables outside of touch to avoid having to deal with scoping
touch {
    gesture <identifier> {
        # Actions
        # I would also suggest changing it so a command comes first so for example
        #     50ms < delay < 1s
        # would become
        #     delay > 50ms < 1s
        # or even `delay <longer-than> [<shorter-than>]` (this is the easiest)
        #     delay 50ms 1s
    }
    binding <gesture-identifier> <command>

    # gesture ...
    # binding ...
}

# The following would also work since this is what the parser will convert it to
touch gesture <identifier> <first-action>
# ...
touch gesture <identifier> <last-action>
touch binding <gesture-identifier> <command>

Some thoughts for the above syntax:

  • cmd_touch should be in it's own file (sway/commands/touch.c) and have two subcommands touch_cmd_gesture and touch_cmd_binding (which are both in their own files inside of the directory sway/commands/touch)
  • touch_cmd_gesture has subcommands for each action touch_gesture_cmd_<action>
    • They should probably also be split into separate files -- sway/command/touch/gesture/<action>.c
  • current_gesture should be added to config->handler_context and set/unset in touch_cmd_gesture
  • cmd_touch should be added to the handler list in config_command so quotes do not get stripped
    • touch_cmd_gesture should strip quotes
    • touch_cmd_binding should only strip quotes for <gesture-identifier>
  • cmd_touch should be added as a subcommand of cmd_mode
    • touch bindings should be stored per mode
    • I'm indecisive on whether gestures should be per mode or global

(Also, note some commands in the example in #1904 like workspace --create next_on_output are not currently implemented and if they do get implements, should be done in a separate PR)

Hopefully, that helps iron out structure. As for cmd_touch not being recognized in your current code, it appears to be recognized for me. However, you are returning NULL instead of a result from the handler so sway segfaults (this should probably be handled better -- but that's for a different PR).

(Side note: the meson.build currently in the libtouch repo generates a library called touch not libtouch so currently the dependency line in this PR's meson.build needs to be changed for it to build)

@grahnen
Copy link
Author
grahnen commented Jan 23, 2019

Sorry about the chaos above. Tried to rebase my local branch to upstream master, but I messed it up big time. It's fixed now, anyway. It even compiles correctly when libtouch is installed.

Somewhere hidden in these commits are my commits. Oops.

Thanks @RedSoxFan for the help with the structure!

Should the gestures be mode-specific? Should they be able to be both mode-specific and mode-agnostic?

@RedSoxFan
Copy link
Member
RedSoxFan commented Jan 23, 2019

Somewhere hidden in these commits are my commits.

Depending on what your remotes are, you may need to alter the commands, but the following should fix the commit history

git reset --hard 12590e9 
git rebase upstream/master
git rebase --skip
git log --oneline upstream/master..
# Only your commits should be listed now
git push -f origin touch-gestures

Should the gestures be mode-specific? Should they be able to be both mode-specific and mode-agnostic?

I think the gestures can be mode-agnostic. You can bind the same gesture to different commands in different modes though.

@RedSoxFan
Copy link
Member

I'm just going to leave this here as something to keep in mind when working on the PR:
https://github.com/swaywm/sway/blob/master/CONTRIBUTING.md#style-reference

@grahnen
Copy link
Author
grahnen commented Jan 24, 2019

Now it's crashing with some xcb errors that I have no understanding of. Yet.

The following config is parseable
`touch {

gesture tap {

    touch down

    threshold 3

 }

 binding tap exec "notify-send progress!"

}`

Am I checking for complete gestures in the right place? In cursor.c, after updating the gestures?
I'll give the style guide a proper read before I add anything else! (and commit with a million undescriptive messages, sorry about those)

@RedSoxFan
Copy link
Member

Now it's crashing with some xcb errors that I have no understanding of. Yet.

If you are getting that from the debug log, it's probably unrelated and harmless. You probably want coredumpctl gdb sway followed by bt full.

Am I checking for complete gestures in the right place? In cursor.c, after updating the gestures?

The location is fine. However, this current data structures do not take into account seats or modes. Each action of a gesture could occur on a different seat and the command will execute on the seat that performed the last action. With the current structure of libtouch, it's probably going to be really hard to account for either since there will have to be multiple engines and a gesture is tied to a single engine.

Also, do not pass the focused container to execute_command, just leave the last argument NULL.

I'll give the style guide a proper read before I add anything else! (and commit with a million undescriptive messages, sorry about those)

Although the final product should have well divided commits with good commit messages, WIP commits are fine for now. This will need some squashing/fix-ups later on anyway and you can reword the final commits then.

@grahnen
Copy link
Author
grahnen commented Jan 24, 2019

Is it reasonable to attach the engine to the sway_seat struct, and simply deep-copy it from the config for each seat, or is that too lazy a solution?

@ddevault
Copy link
Contributor

Take a look at how we track xkb state for inspiration.

@ddevault
Copy link
Contributor

Re-emphasizing the importance of the style guide - also applies to the code in libtouch, if you want to upstream that.

@emersion emersion added the enhancement New feature or incremental improvement label Mar 11, 2019
@grahnen
Copy link
Author
grahnen commented Apr 20, 2019

Rotation is still broken but regions, pinch, swipe and n-touches should work. Unless I've messed up git again. It works on my machine :)

I've had a lot of more pressing matters to attend to, and that will probably continue to be the case at least until summer. Completing courses turns out to require participation; who would've thought?

Copy link
Member
@RedSoxFan RedSoxFan left a comment

Choose a reason for hiding this comment

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

Please review the style guide. There are several style issues including a lot of unneeded blank lines, lines that only have tabs, mixed tabs/spaces, removed/added lines that did not need to be touched, lines that are too long, missing whitespace around if/arguments/etc, and several others. I pointed out some, but there are too many to comment on all of them.

Unfortunately, I cannot comment on the functionality as I don't have the hardware to test with. Hopefully, someone else can help with that.

Also, please rebase against master instead of merging master into the branch for a cleaner commit history.

Oh and the commands will need to be documented

@@ -53,7 +53,6 @@ struct sway_binding {
uint32_t modifiers;
char *command;
};

Copy link
Member

Choose a reason for hiding this comment

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

Can you readd this blank line?

struct libtouch_target *target;
};


Copy link
Member

Choose a reason for hiding this comment

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

Extra blank line

@@ -507,7 +521,8 @@ struct sway_config {
list_t *command_policies;
list_t *feature_policies;
list_t *ipc_policies;


Copy link
Member

Choose a reason for hiding this comment

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

Extra tab on blank line

@@ -36,6 +36,8 @@ struct sway_cursor {
struct wl_listener axis;
struct wl_listener frame;


Copy link
Member

Choose a reason for hiding this comment

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

Extra blank line

meson.build Outdated
@@ -58,6 +59,7 @@ xcb = dependency('xcb', required: get_option('xwayland'))
math = cc.find_library('m')
rt = cc.find_library('rt')
git = find_program('git', native: true, required: false)
libtouch = dependency('libtouch')
Copy link
Member

Choose a reason for hiding this comment

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

The dependency is duplicated

struct libtouch_gesture *complete;
struct gesture_config *cfg;
int idx;
cfg = (struct gesture_config*) config->gesture_configs->items[0];
Copy link
Member

Choose a reason for hiding this comment

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

This seems unused


static void handle_gestures(struct libtouch_progress_tracker *tracker, struct sway_seat *seat) {
struct libtouch_gesture *complete;
struct gesture_config *cfg;
Copy link
Member

Choose a reason for hiding this comment

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

cfg and idx can be moved inside the while to where they are used

execute_command(cfg->command, seat, NULL);
}
} else {
sway_log(SWAY_DEBUG, "Gesture unbound!");
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be a SWAY_ERROR as it should not occur

@@ -350,16 +381,22 @@ static void handle_touch_down(struct wl_listener *listener, void *data) {
seat->touch_x = lx;
seat->touch_y = ly;

libtouch_progress_register_touch(cursor->gesture_tracker, event->time_msec,
event->touch_id, LIBTOUCH_TOUCH_DOWN,
Copy link
Member

Choose a reason for hiding this comment

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

style: do not line up the arguments, just ident

@@ -507,7 +521,8 @@ struct sway_config {
list_t *command_policies;
list_t *feature_policies;
list_t *ipc_policies;


struct libtouch_engine *gesture_engine;
Copy link
Member

Choose a reason for hiding this comment

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

I'm not seeing where this is free'd/deinitialized. Also, is the engine reusable between config reloads? If so, it should be moved to sway_server. If not, it is fine here.

@emersion emersion marked this pull request as draft May 1, 2020 09:46
@freswa
Copy link
freswa commented Aug 19, 2020

@grahnen Are you still working on this? I'm willing to help to get this ready for merging...

@grahnen
Copy link
Author
grahnen commented Aug 26, 2020

@freswa Unfortunately not. I had to finish my studies, and got rid of my touchscreen PC. Feel free to take over!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or incremental improvement
Development

Successfully merging this pull request may close these issues.

5 participants