mirror of
https://github.com/swaywm/sway.git
synced 2026-04-27 06:46:25 -04:00
Implement remaining actions, split touch for different seats
This commit is contained in:
parent
f89f45e58d
commit
7873a0f13c
20 changed files with 385 additions and 20 deletions
|
|
@ -282,9 +282,15 @@ sway_cmd seat_cmd_pointer_constraint;
|
||||||
|
|
||||||
sway_cmd touch_cmd_gesture;
|
sway_cmd touch_cmd_gesture;
|
||||||
sway_cmd touch_cmd_binding;
|
sway_cmd touch_cmd_binding;
|
||||||
|
sway_cmd touch_cmd_target;
|
||||||
|
|
||||||
sway_cmd touch_gesture_cmd_touch;
|
sway_cmd touch_gesture_cmd_touch;
|
||||||
sway_cmd touch_gesture_cmd_threshold;
|
sway_cmd touch_gesture_cmd_threshold;
|
||||||
|
sway_cmd touch_gesture_cmd_target;
|
||||||
|
sway_cmd touch_gesture_cmd_swipe;
|
||||||
|
sway_cmd touch_gesture_cmd_pinch;
|
||||||
|
sway_cmd touch_gesture_cmd_rotate;
|
||||||
|
sway_cmd touch_gesture_cmd_delay;
|
||||||
|
|
||||||
sway_cmd cmd_ipc_cmd;
|
sway_cmd cmd_ipc_cmd;
|
||||||
sway_cmd cmd_ipc_events;
|
sway_cmd cmd_ipc_events;
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,11 @@ struct gesture_config {
|
||||||
char *command;
|
char *command;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct gesture_target_config {
|
||||||
|
char *identifier;
|
||||||
|
struct libtouch_target *target;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* options for input devices
|
* options for input devices
|
||||||
|
|
@ -428,6 +433,7 @@ struct sway_config {
|
||||||
list_t *input_configs;
|
list_t *input_configs;
|
||||||
list_t *input_type_configs;
|
list_t *input_type_configs;
|
||||||
list_t *gesture_configs;
|
list_t *gesture_configs;
|
||||||
|
list_t *gesture_target_configs;
|
||||||
list_t *seat_configs;
|
list_t *seat_configs;
|
||||||
list_t *criteria;
|
list_t *criteria;
|
||||||
list_t *no_focus;
|
list_t *no_focus;
|
||||||
|
|
@ -658,10 +664,16 @@ int gesture_identifier_cmp(const void *item, const void *data);
|
||||||
|
|
||||||
int gesture_libtouch_cmp(const void *item, const void *data);
|
int gesture_libtouch_cmp(const void *item, const void *data);
|
||||||
|
|
||||||
|
int gesture_target_identifier_cmp(const void *item, const void *data);
|
||||||
|
|
||||||
struct gesture_config *get_gesture_config(const char *identifier);
|
struct gesture_config *get_gesture_config(const char *identifier);
|
||||||
|
|
||||||
struct gesture_config *new_gesture_config(const char *identifier);
|
struct gesture_config *new_gesture_config(const char *identifier);
|
||||||
|
|
||||||
|
struct gesture_target_config *get_gesture_target_config(const char* identifier);
|
||||||
|
|
||||||
|
struct gesture_target_config *create_gesture_target_config(const char* identifier);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the value of config->font_height based on the max title height
|
* Updates the value of config->font_height based on the max title height
|
||||||
* reported by each container. If recalculate is true, the containers will
|
* reported by each container. If recalculate is true, the containers will
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ struct sway_cursor {
|
||||||
struct wl_listener axis;
|
struct wl_listener axis;
|
||||||
struct wl_listener frame;
|
struct wl_listener frame;
|
||||||
|
|
||||||
struct libtouch_engine *gesture_engine;
|
struct libtouch_progress_tracker *gesture_tracker;
|
||||||
struct wl_listener touch_down;
|
struct wl_listener touch_down;
|
||||||
struct wl_listener touch_up;
|
struct wl_listener touch_up;
|
||||||
struct wl_listener touch_motion;
|
struct wl_listener touch_motion;
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
static struct cmd_handler touch_handlers[] = {
|
static struct cmd_handler touch_handlers[] = {
|
||||||
{ "binding", touch_cmd_binding },
|
{ "binding", touch_cmd_binding },
|
||||||
{ "gesture", touch_cmd_gesture },
|
{ "gesture", touch_cmd_gesture },
|
||||||
|
{ "target", touch_cmd_target },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@ struct cmd_results *touch_cmd_binding(int argc, char **argv) {
|
||||||
return cmd_results_new(CMD_FAILURE, "Unable to bind gesture %s", argv[0]);
|
return cmd_results_new(CMD_FAILURE, "Unable to bind gesture %s", argv[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sway_log(SWAY_DEBUG, "libtouch: Bound gesture %s", argv[0]);
|
||||||
|
|
||||||
config->command = join_args(argv + 1, argc - 1);
|
config->command = join_args(argv + 1, argc - 1);
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL);
|
return cmd_results_new(CMD_SUCCESS, NULL);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,11 @@
|
||||||
#include <libtouch.h>
|
#include <libtouch.h>
|
||||||
|
|
||||||
static struct cmd_handler gesture_handlers[] = {
|
static struct cmd_handler gesture_handlers[] = {
|
||||||
|
{ "delay", touch_gesture_cmd_delay },
|
||||||
|
{ "pinch", touch_gesture_cmd_pinch },
|
||||||
|
{ "rotate", touch_gesture_cmd_rotate },
|
||||||
|
{ "swipe", touch_gesture_cmd_swipe },
|
||||||
|
{ "target", touch_gesture_cmd_target },
|
||||||
{ "threshold", touch_gesture_cmd_threshold },
|
{ "threshold", touch_gesture_cmd_threshold },
|
||||||
{ "touch", touch_gesture_cmd_touch },
|
{ "touch", touch_gesture_cmd_touch },
|
||||||
};
|
};
|
||||||
|
|
|
||||||
33
sway/commands/touch/gesture/delay.c
Normal file
33
sway/commands/touch/gesture/delay.c
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <strings.h>
|
||||||
|
#include "sway/commands.h"
|
||||||
|
#include "sway/config.h"
|
||||||
|
#include "sway/ipc-server.h"
|
||||||
|
#include "list.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "stringop.h"
|
||||||
|
#include <libtouch.h>
|
||||||
|
|
||||||
|
struct cmd_results *touch_gesture_cmd_delay(int argc, char **argv) {
|
||||||
|
struct cmd_results *error = NULL;
|
||||||
|
if((error = checkarg(argc, "touch", EXPECTED_EQUAL_TO, 1))) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t mode = atoi(argv[0]);
|
||||||
|
|
||||||
|
if(!config->handler_context.current_gesture) {
|
||||||
|
return cmd_results_new(CMD_FAILURE, "No current gesture");
|
||||||
|
} else if (!config->handler_context.current_gesture->gesture) {
|
||||||
|
return cmd_results_new(CMD_FAILURE, "No gesture in gesture config");
|
||||||
|
}
|
||||||
|
struct libtouch_gesture *gesture = config->handler_context.current_gesture->gesture;
|
||||||
|
|
||||||
|
struct libtouch_action *action = libtouch_gesture_add_delay(gesture, mode);
|
||||||
|
|
||||||
|
config->handler_context.current_gesture_action = action;
|
||||||
|
|
||||||
|
return cmd_results_new(CMD_SUCCESS, "Created new delay");
|
||||||
|
};
|
||||||
40
sway/commands/touch/gesture/pinch.c
Normal file
40
sway/commands/touch/gesture/pinch.c
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <strings.h>
|
||||||
|
#include "sway/commands.h"
|
||||||
|
#include "sway/config.h"
|
||||||
|
#include "sway/ipc-server.h"
|
||||||
|
#include "list.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "stringop.h"
|
||||||
|
#include <libtouch.h>
|
||||||
|
|
||||||
|
struct cmd_results *touch_gesture_cmd_pinch(int argc, char **argv) {
|
||||||
|
struct cmd_results *error = NULL;
|
||||||
|
if((error = checkarg(argc, "pinch", EXPECTED_EQUAL_TO, 1))) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t mode;
|
||||||
|
if(strcmp(argv[0],"in") == 0) {
|
||||||
|
mode = LIBTOUCH_PINCH_IN;
|
||||||
|
} else if (strcmp(argv[0],"out") == 0) {
|
||||||
|
mode = LIBTOUCH_PINCH_OUT;
|
||||||
|
} else {
|
||||||
|
return cmd_results_new(CMD_FAILURE, "pinch: %s is not in or out", argv[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!config->handler_context.current_gesture) {
|
||||||
|
return cmd_results_new(CMD_FAILURE, "No current gesture");
|
||||||
|
} else if (!config->handler_context.current_gesture->gesture) {
|
||||||
|
return cmd_results_new(CMD_FAILURE, "No gesture in gesture config");
|
||||||
|
}
|
||||||
|
struct libtouch_gesture *gesture = config->handler_context.current_gesture->gesture;
|
||||||
|
|
||||||
|
struct libtouch_action *action = libtouch_gesture_add_pinch(gesture, mode);
|
||||||
|
|
||||||
|
config->handler_context.current_gesture_action = action;
|
||||||
|
|
||||||
|
return cmd_results_new(CMD_SUCCESS, "Created new touch");
|
||||||
|
};
|
||||||
40
sway/commands/touch/gesture/rotate.c
Normal file
40
sway/commands/touch/gesture/rotate.c
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <strings.h>
|
||||||
|
#include "sway/commands.h"
|
||||||
|
#include "sway/config.h"
|
||||||
|
#include "sway/ipc-server.h"
|
||||||
|
#include "list.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "stringop.h"
|
||||||
|
#include <libtouch.h>
|
||||||
|
|
||||||
|
struct cmd_results *touch_gesture_cmd_rotate(int argc, char **argv) {
|
||||||
|
struct cmd_results *error = NULL;
|
||||||
|
if((error = checkarg(argc, "rotate", EXPECTED_EQUAL_TO, 1))) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t mode;
|
||||||
|
if(strcmp(argv[0],"clockwise") == 0) {
|
||||||
|
mode = LIBTOUCH_ROTATE_CLOCKWISE;
|
||||||
|
} else if (strcmp(argv[0],"counterclockwise") == 0) {
|
||||||
|
mode = LIBTOUCH_ROTATE_ANTICLOCKWISE;
|
||||||
|
} else {
|
||||||
|
return cmd_results_new(CMD_FAILURE, "rotate %s is not (anti)clockwise", argv[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!config->handler_context.current_gesture) {
|
||||||
|
return cmd_results_new(CMD_FAILURE, "No current gesture");
|
||||||
|
} else if (!config->handler_context.current_gesture->gesture) {
|
||||||
|
return cmd_results_new(CMD_FAILURE, "No gesture in gesture config");
|
||||||
|
}
|
||||||
|
struct libtouch_gesture *gesture = config->handler_context.current_gesture->gesture;
|
||||||
|
|
||||||
|
struct libtouch_action *action = libtouch_gesture_add_rotate(gesture, mode);
|
||||||
|
|
||||||
|
config->handler_context.current_gesture_action = action;
|
||||||
|
|
||||||
|
return cmd_results_new(CMD_SUCCESS, "Created new rotation");
|
||||||
|
};
|
||||||
45
sway/commands/touch/gesture/swipe.c
Normal file
45
sway/commands/touch/gesture/swipe.c
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <strings.h>
|
||||||
|
#include "sway/commands.h"
|
||||||
|
#include "sway/config.h"
|
||||||
|
#include "sway/ipc-server.h"
|
||||||
|
#include "list.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "stringop.h"
|
||||||
|
#include <libtouch.h>
|
||||||
|
|
||||||
|
struct cmd_results *touch_gesture_cmd_swipe(int argc, char **argv) {
|
||||||
|
struct cmd_results *error = NULL;
|
||||||
|
if((error = checkarg(argc, "swipe", EXPECTED_EQUAL_TO, 1))) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t direction = 0;
|
||||||
|
if (strstr(argv[0], "west")) {
|
||||||
|
direction |= LIBTOUCH_MOVE_NEGATIVE_X;
|
||||||
|
}
|
||||||
|
if (strstr(argv[0], "east")) {
|
||||||
|
direction |= LIBTOUCH_MOVE_POSITIVE_X;
|
||||||
|
}
|
||||||
|
if (strstr(argv[0], "north")) {
|
||||||
|
direction |= LIBTOUCH_MOVE_POSITIVE_Y;
|
||||||
|
}
|
||||||
|
if (strstr(argv[0], "south")) {
|
||||||
|
direction |= LIBTOUCH_MOVE_NEGATIVE_Y;
|
||||||
|
}
|
||||||
|
|
||||||
|
sway_log(SWAY_DEBUG, "Direction: %d", direction);
|
||||||
|
if (direction == 0) {
|
||||||
|
return cmd_results_new(CMD_FAILURE, "Direction %s invalid", argv[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct libtouch_gesture *gesture = config->handler_context.current_gesture->gesture;
|
||||||
|
|
||||||
|
struct libtouch_action *action = libtouch_gesture_add_move(gesture, direction);
|
||||||
|
|
||||||
|
config->handler_context.current_gesture_action = action;
|
||||||
|
|
||||||
|
return cmd_results_new(CMD_SUCCESS, "Created new swipe");
|
||||||
|
}
|
||||||
38
sway/commands/touch/gesture/target.c
Normal file
38
sway/commands/touch/gesture/target.c
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <strings.h>
|
||||||
|
#include "sway/commands.h"
|
||||||
|
#include "sway/config.h"
|
||||||
|
#include "sway/ipc-server.h"
|
||||||
|
#include "list.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "stringop.h"
|
||||||
|
#include <libtouch.h>
|
||||||
|
|
||||||
|
struct cmd_results *touch_gesture_cmd_target(int argc, char **argv) {
|
||||||
|
struct cmd_results *error = NULL;
|
||||||
|
if((error = checkarg(argc, "target", EXPECTED_AT_LEAST, 1))) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct gesture_target_config *target = get_gesture_target_config(argv[0]);
|
||||||
|
|
||||||
|
if(!target) {
|
||||||
|
return cmd_results_new(CMD_FAILURE, "Could not find gesture target %s", argv[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!config->handler_context.current_gesture_action) {
|
||||||
|
return cmd_results_new(CMD_FAILURE,
|
||||||
|
"No action created for target %s", argv[0]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
libtouch_action_set_target(
|
||||||
|
config->handler_context.current_gesture_action,
|
||||||
|
target->target);
|
||||||
|
|
||||||
|
return cmd_results_new(CMD_SUCCESS, "Bound target %s to action", argv[0]);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -25,6 +25,7 @@ struct cmd_results *touch_gesture_cmd_threshold(int argc, char **argv) {
|
||||||
return cmd_results_new(CMD_INVALID,
|
return cmd_results_new(CMD_INVALID,
|
||||||
"Invalid threshold: %s", argv[0]);
|
"Invalid threshold: %s", argv[0]);
|
||||||
}
|
}
|
||||||
|
sway_log(SWAY_DEBUG, "Set threshold %d", threshold);
|
||||||
libtouch_action_set_threshold(current, threshold);
|
libtouch_action_set_threshold(current, threshold);
|
||||||
return cmd_results_new(CMD_SUCCESS,
|
return cmd_results_new(CMD_SUCCESS,
|
||||||
"Set threshold");
|
"Set threshold");
|
||||||
|
|
|
||||||
|
|
@ -36,5 +36,5 @@ struct cmd_results *touch_gesture_cmd_touch(int argc, char **argv) {
|
||||||
|
|
||||||
config->handler_context.current_gesture_action = action;
|
config->handler_context.current_gesture_action = action;
|
||||||
|
|
||||||
return cmd_results_new(CMD_SUCCESS, "Created new action");
|
return cmd_results_new(CMD_SUCCESS, "Created new touch");
|
||||||
};
|
};
|
||||||
|
|
|
||||||
50
sway/commands/touch/target.c
Normal file
50
sway/commands/touch/target.c
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <strings.h>
|
||||||
|
#include "sway/commands.h"
|
||||||
|
#include "sway/config.h"
|
||||||
|
#include "sway/ipc-server.h"
|
||||||
|
#include "list.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "stringop.h"
|
||||||
|
#include <libtouch.h>
|
||||||
|
|
||||||
|
struct cmd_results *touch_cmd_target(int argc, char **argv) {
|
||||||
|
struct cmd_results *error = NULL;
|
||||||
|
if ((error = checkarg(argc, "target", EXPECTED_EQUAL_TO, 5))) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
sway_log(SWAY_DEBUG, "Trying to convert");
|
||||||
|
double x = atoi(argv[1]);
|
||||||
|
double y = atoi(argv[2]);
|
||||||
|
double w = atoi(argv[3]);
|
||||||
|
double h = atoi(argv[4]);
|
||||||
|
sway_log(SWAY_DEBUG, "Converted: %f, %f, %f, %f", x,y,w,h);
|
||||||
|
|
||||||
|
if(!config->gesture_engine) {
|
||||||
|
return cmd_results_new(CMD_FAILURE, "No engine exists!");
|
||||||
|
}
|
||||||
|
|
||||||
|
struct gesture_target_config *conf = get_gesture_target_config(argv[0]);
|
||||||
|
|
||||||
|
if(!conf) {
|
||||||
|
return cmd_results_new(CMD_FAILURE, "Could not create target: %s", argv[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(conf->target != NULL) {
|
||||||
|
return cmd_results_new(CMD_FAILURE, "target %s already bound", argv[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct libtouch_target *target = libtouch_target_create(config->gesture_engine, x,y,w,h);
|
||||||
|
|
||||||
|
if(!target) {
|
||||||
|
return cmd_results_new(CMD_FAILURE, "Could not create target");
|
||||||
|
}
|
||||||
|
|
||||||
|
conf->target = target;
|
||||||
|
|
||||||
|
|
||||||
|
return cmd_results_new(CMD_SUCCESS, "Created target: %s", argv[0]);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
@ -30,6 +30,7 @@
|
||||||
#include "stringop.h"
|
#include "stringop.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include <libtouch.h>
|
||||||
|
|
||||||
struct sway_config *config = NULL;
|
struct sway_config *config = NULL;
|
||||||
|
|
||||||
|
|
@ -188,7 +189,8 @@ static void config_defaults(struct sway_config *config) {
|
||||||
"--button-no-terminal 'Exit sway' 'swaymsg exit' "
|
"--button-no-terminal 'Exit sway' 'swaymsg exit' "
|
||||||
"--button-no-terminal 'Reload sway' 'swaymsg reload'";
|
"--button-no-terminal 'Reload sway' 'swaymsg reload'";
|
||||||
config->swaynag_config_errors.detailed = true;
|
config->swaynag_config_errors.detailed = true;
|
||||||
|
if (!(config->gesture_configs = create_list())) goto cleanup;
|
||||||
|
if (!(config->gesture_target_configs = create_list())) goto cleanup;
|
||||||
if (!(config->symbols = create_list())) goto cleanup;
|
if (!(config->symbols = create_list())) goto cleanup;
|
||||||
if (!(config->modes = create_list())) goto cleanup;
|
if (!(config->modes = create_list())) goto cleanup;
|
||||||
if (!(config->bars = create_list())) goto cleanup;
|
if (!(config->bars = create_list())) goto cleanup;
|
||||||
|
|
@ -312,6 +314,7 @@ static void config_defaults(struct sway_config *config) {
|
||||||
|
|
||||||
set_color(config->border_colors.background, 0xFFFFFF);
|
set_color(config->border_colors.background, 0xFFFFFF);
|
||||||
|
|
||||||
|
config->gesture_engine = libtouch_engine_create();
|
||||||
// Security
|
// Security
|
||||||
if (!(config->command_policies = create_list())) goto cleanup;
|
if (!(config->command_policies = create_list())) goto cleanup;
|
||||||
if (!(config->feature_policies = create_list())) goto cleanup;
|
if (!(config->feature_policies = create_list())) goto cleanup;
|
||||||
|
|
|
||||||
|
|
@ -40,5 +40,8 @@ int gesture_identifier_cmp(const void *item, const void *data) {
|
||||||
int gesture_libtouch_cmp(const void *item, const void *data) {
|
int gesture_libtouch_cmp(const void *item, const void *data) {
|
||||||
const struct gesture_config *gc = item;
|
const struct gesture_config *gc = item;
|
||||||
const struct libtouch_gesture *g = data;
|
const struct libtouch_gesture *g = data;
|
||||||
return gc->gesture == g;
|
if(gc->gesture == g)
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
41
sway/config/target.c
Normal file
41
sway/config/target.c
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <float.h>
|
||||||
|
#include "sway/config.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include <libtouch.h>
|
||||||
|
|
||||||
|
struct gesture_target_config *get_gesture_target_config(const char* identifier) {
|
||||||
|
int i = list_seq_find(config->gesture_target_configs, gesture_target_identifier_cmp, identifier);
|
||||||
|
struct gesture_target_config *cfg = NULL;
|
||||||
|
if(i >= 0) {
|
||||||
|
cfg = config->gesture_target_configs->items[i];
|
||||||
|
} else {
|
||||||
|
cfg = create_gesture_target_config(identifier);
|
||||||
|
list_add(config->gesture_target_configs, cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cfg;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct gesture_target_config *create_gesture_target_config(const char* identifier) {
|
||||||
|
int i = list_seq_find(config->gesture_target_configs, gesture_target_identifier_cmp, identifier);
|
||||||
|
if(i >= 0) {
|
||||||
|
sway_log(SWAY_DEBUG, "Gesture target %s already created", identifier);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct gesture_target_config *cfg = calloc(sizeof(struct gesture_target_config), 1);
|
||||||
|
cfg->identifier = strdup(identifier);
|
||||||
|
|
||||||
|
return cfg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int gesture_target_identifier_cmp(const void *item, const void *data) {
|
||||||
|
const struct gesture_target_config *tc = item;
|
||||||
|
const char* identifier = data;
|
||||||
|
|
||||||
|
return strcmp(identifier, tc->identifier);
|
||||||
|
}
|
||||||
|
|
@ -332,19 +332,32 @@ static void handle_cursor_frame(struct wl_listener *listener, void *data) {
|
||||||
wlr_seat_pointer_notify_frame(cursor->seat->wlr_seat);
|
wlr_seat_pointer_notify_frame(cursor->seat->wlr_seat);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_gestures(struct libtouch_engine *engine, struct sway_seat *seat) {
|
static void handle_gestures(struct libtouch_progress_tracker *tracker, struct sway_seat *seat) {
|
||||||
struct libtouch_gesture *complete;
|
struct libtouch_gesture *complete;
|
||||||
struct gesture_config *cfg;
|
struct gesture_config *cfg;
|
||||||
int idx;
|
int idx;
|
||||||
while((complete = libtouch_handle_finished_gesture(engine))){
|
cfg = (struct gesture_config*) config->gesture_configs->items[0];
|
||||||
|
sway_log(SWAY_DEBUG, "Tracking %d gestures", libtouch_progress_tracker_n_gestures(tracker));
|
||||||
|
for(uint32_t i = 0; i < libtouch_progress_tracker_n_gestures(tracker); i++) {
|
||||||
|
sway_log(SWAY_DEBUG, "Progress %d: %f", i, libtouch_gesture_progress_get_progress(libtouch_gesture_get_progress(tracker, i)));
|
||||||
|
}
|
||||||
|
while((complete = libtouch_handle_finished_gesture(tracker)) != NULL){
|
||||||
|
|
||||||
|
|
||||||
idx = list_seq_find(config->gesture_configs, gesture_libtouch_cmp, complete);
|
idx = list_seq_find(config->gesture_configs, gesture_libtouch_cmp, complete);
|
||||||
if(idx >= 0) {
|
if(idx >= 0) {
|
||||||
|
sway_log(SWAY_DEBUG, "Completed gesture %s", cfg->identifier);
|
||||||
cfg = config->gesture_configs->items[idx];
|
cfg = config->gesture_configs->items[idx];
|
||||||
|
|
||||||
if(cfg->command) {
|
if(cfg->command) {
|
||||||
execute_command(cfg->command, seat, seat_get_focused_container(seat));
|
execute_command(cfg->command, seat, NULL);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
sway_log(SWAY_DEBUG, "Gesture unbound!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_touch_down(struct wl_listener *listener, void *data) {
|
static void handle_touch_down(struct wl_listener *listener, void *data) {
|
||||||
|
|
@ -365,6 +378,13 @@ static void handle_touch_down(struct wl_listener *listener, void *data) {
|
||||||
seat->touch_x = lx;
|
seat->touch_x = lx;
|
||||||
seat->touch_y = ly;
|
seat->touch_y = ly;
|
||||||
|
|
||||||
|
|
||||||
|
sway_log(SWAY_DEBUG, "Touch pos: (%f, %f)", lx,ly);
|
||||||
|
libtouch_progress_register_touch(cursor->gesture_tracker, event->time_msec,
|
||||||
|
event->touch_id, LIBTOUCH_TOUCH_DOWN,
|
||||||
|
lx, ly);
|
||||||
|
handle_gestures(cursor->gesture_tracker, seat);
|
||||||
|
|
||||||
if (!surface) {
|
if (!surface) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -375,10 +395,7 @@ static void handle_touch_down(struct wl_listener *listener, void *data) {
|
||||||
event->touch_id, sx, sy);
|
event->touch_id, sx, sy);
|
||||||
cursor_set_image(cursor, NULL, NULL);
|
cursor_set_image(cursor, NULL, NULL);
|
||||||
}
|
}
|
||||||
libtouch_engine_register_touch(cursor->gesture_engine, event->time_msec,
|
|
||||||
event->touch_id, LIBTOUCH_TOUCH_DOWN,
|
|
||||||
event->x, event->y);
|
|
||||||
handle_gestures(cursor->gesture_engine, seat);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -389,9 +406,10 @@ static void handle_touch_up(struct wl_listener *listener, void *data) {
|
||||||
struct wlr_seat *seat = cursor->seat->wlr_seat;
|
struct wlr_seat *seat = cursor->seat->wlr_seat;
|
||||||
// TODO: fall back to cursor simulation if client has not bound to touch
|
// TODO: fall back to cursor simulation if client has not bound to touch
|
||||||
wlr_seat_touch_notify_up(seat, event->time_msec, event->touch_id);
|
wlr_seat_touch_notify_up(seat, event->time_msec, event->touch_id);
|
||||||
libtouch_engine_register_touch(cursor->gesture_engine, event->time_msec,
|
|
||||||
|
libtouch_progress_register_touch(cursor->gesture_tracker, event->time_msec,
|
||||||
event->touch_id, LIBTOUCH_TOUCH_UP, 0, 0);
|
event->touch_id, LIBTOUCH_TOUCH_UP, 0, 0);
|
||||||
handle_gestures(cursor->gesture_engine, cursor->seat);
|
handle_gestures(cursor->gesture_tracker, cursor->seat);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_touch_motion(struct wl_listener *listener, void *data) {
|
static void handle_touch_motion(struct wl_listener *listener, void *data) {
|
||||||
|
|
@ -403,12 +421,20 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) {
|
||||||
struct wlr_seat *wlr_seat = seat->wlr_seat;
|
struct wlr_seat *wlr_seat = seat->wlr_seat;
|
||||||
struct wlr_surface *surface = NULL;
|
struct wlr_surface *surface = NULL;
|
||||||
|
|
||||||
|
|
||||||
double lx, ly;
|
double lx, ly;
|
||||||
wlr_cursor_absolute_to_layout_coords(cursor->cursor, event->device,
|
wlr_cursor_absolute_to_layout_coords(cursor->cursor, event->device,
|
||||||
event->x, event->y, &lx, &ly);
|
event->x, event->y, &lx, &ly);
|
||||||
double sx, sy;
|
double sx, sy;
|
||||||
node_at_coords(cursor->seat, lx, ly, &surface, &sx, &sy);
|
node_at_coords(cursor->seat, lx, ly, &surface, &sx, &sy);
|
||||||
|
|
||||||
|
|
||||||
|
sway_log(SWAY_DEBUG, "move gesture");
|
||||||
|
libtouch_progress_register_move(cursor->gesture_tracker, event->time_msec,
|
||||||
|
event->touch_id, lx,ly);
|
||||||
|
|
||||||
|
handle_gestures(cursor->gesture_tracker, seat);
|
||||||
|
|
||||||
if (seat->touch_id == event->touch_id) {
|
if (seat->touch_id == event->touch_id) {
|
||||||
seat->touch_x = lx;
|
seat->touch_x = lx;
|
||||||
seat->touch_y = ly;
|
seat->touch_y = ly;
|
||||||
|
|
@ -430,10 +456,7 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) {
|
||||||
wlr_seat_touch_notify_motion(wlr_seat, event->time_msec,
|
wlr_seat_touch_notify_motion(wlr_seat, event->time_msec,
|
||||||
event->touch_id, sx, sy);
|
event->touch_id, sx, sy);
|
||||||
}
|
}
|
||||||
libtouch_engine_register_move(cursor->gesture_engine, event->time_msec,
|
|
||||||
event->touch_id, event->x, event->y);
|
|
||||||
|
|
||||||
handle_gestures(cursor->gesture_engine, seat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
#include "sway/tree/root.h"
|
#include "sway/tree/root.h"
|
||||||
#include "sway/tree/view.h"
|
#include "sway/tree/view.h"
|
||||||
#include "sway/tree/workspace.h"
|
#include "sway/tree/workspace.h"
|
||||||
|
#include <libtouch.h>
|
||||||
|
|
||||||
static void seat_device_destroy(struct sway_seat_device *seat_device) {
|
static void seat_device_destroy(struct sway_seat_device *seat_device) {
|
||||||
if (!seat_device) {
|
if (!seat_device) {
|
||||||
|
|
@ -599,8 +600,11 @@ static void seat_configure_touch(struct sway_seat *seat,
|
||||||
wlr_cursor_attach_input_device(seat->cursor->cursor,
|
wlr_cursor_attach_input_device(seat->cursor->cursor,
|
||||||
sway_device->input_device->wlr_device);
|
sway_device->input_device->wlr_device);
|
||||||
seat_apply_input_config(seat, sway_device);
|
seat_apply_input_config(seat, sway_device);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void seat_configure_tablet_tool(struct sway_seat *seat,
|
static void seat_configure_tablet_tool(struct sway_seat *seat,
|
||||||
struct sway_seat_device *sway_device) {
|
struct sway_seat_device *sway_device) {
|
||||||
seat_configure_xcursor(seat);
|
seat_configure_xcursor(seat);
|
||||||
|
|
@ -1189,7 +1193,16 @@ void seat_apply_config(struct sway_seat *seat,
|
||||||
wl_list_for_each(seat_device, &seat->devices, link) {
|
wl_list_for_each(seat_device, &seat->devices, link) {
|
||||||
seat_configure_device(seat, seat_device->input_device);
|
seat_configure_device(seat, seat_device->input_device);
|
||||||
}
|
}
|
||||||
|
if(config->gesture_engine) {
|
||||||
|
sway_log(SWAY_DEBUG, "gesture engine exists");
|
||||||
|
if(seat->cursor->gesture_tracker) {
|
||||||
|
free(seat->cursor->gesture_tracker);
|
||||||
|
}
|
||||||
|
sway_log(SWAY_DEBUG, "Gesture progress tracker created");
|
||||||
|
seat->cursor->gesture_tracker = libtouch_progress_tracker_create(
|
||||||
|
config->gesture_engine);
|
||||||
|
|
||||||
|
}
|
||||||
cursor_handle_activity(seat->cursor);
|
cursor_handle_activity(seat->cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ sway_sources = files(
|
||||||
'config/seat.c',
|
'config/seat.c',
|
||||||
'config/input.c',
|
'config/input.c',
|
||||||
'config/gesture.c',
|
'config/gesture.c',
|
||||||
|
'config/target.c',
|
||||||
|
|
||||||
'commands/assign.c',
|
'commands/assign.c',
|
||||||
'commands/bar.c',
|
'commands/bar.c',
|
||||||
|
|
@ -179,8 +180,16 @@ sway_sources = files(
|
||||||
|
|
||||||
'commands/touch/binding.c',
|
'commands/touch/binding.c',
|
||||||
'commands/touch/gesture.c',
|
'commands/touch/gesture.c',
|
||||||
|
'commands/touch/target.c',
|
||||||
'commands/touch/gesture/touch.c',
|
'commands/touch/gesture/touch.c',
|
||||||
'commands/touch/gesture/threshold.c',
|
'commands/touch/gesture/threshold.c',
|
||||||
|
'commands/touch/gesture/target.c',
|
||||||
|
'commands/touch/gesture/swipe.c',
|
||||||
|
'commands/touch/gesture/rotate.c',
|
||||||
|
'commands/touch/gesture/pinch.c',
|
||||||
|
'commands/touch/gesture/delay.c',
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
'tree/arrange.c',
|
'tree/arrange.c',
|
||||||
'tree/container.c',
|
'tree/container.c',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue