mirror of
https://github.com/swaywm/sway.git
synced 2026-04-27 06:46:25 -04:00
Follow style guide
This commit is contained in:
parent
16e60f2ea5
commit
068c777de2
15 changed files with 112 additions and 109 deletions
|
|
@ -53,6 +53,7 @@ struct sway_binding {
|
|||
uint32_t modifiers;
|
||||
char *command;
|
||||
};
|
||||
|
||||
/**
|
||||
* A mouse binding and an associated command.
|
||||
*/
|
||||
|
|
@ -111,7 +112,6 @@ struct gesture_target_config {
|
|||
struct libtouch_target *target;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* options for input devices
|
||||
*/
|
||||
|
|
@ -521,7 +521,7 @@ struct sway_config {
|
|||
list_t *command_policies;
|
||||
list_t *feature_policies;
|
||||
list_t *ipc_policies;
|
||||
|
||||
|
||||
struct libtouch_engine *gesture_engine;
|
||||
// Context for command handlers
|
||||
struct {
|
||||
|
|
|
|||
|
|
@ -72,7 +72,6 @@ static struct cmd_handler handlers[] = {
|
|||
{ "force_focus_wrapping", cmd_force_focus_wrapping },
|
||||
{ "fullscreen", cmd_fullscreen },
|
||||
{ "gaps", cmd_gaps },
|
||||
{ "touch", cmd_touch },
|
||||
{ "hide_edge_borders", cmd_hide_edge_borders },
|
||||
{ "include", cmd_include },
|
||||
{ "input", cmd_input },
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@
|
|||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <libtouch.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>
|
||||
|
||||
// Must be in alphabetical order for bsearch
|
||||
static struct cmd_handler touch_handlers[] = {
|
||||
|
|
@ -28,13 +28,10 @@ struct cmd_results *cmd_touch(int argc, char **argv) {
|
|||
config->gesture_engine = libtouch_engine_create();
|
||||
sway_log(SWAY_DEBUG, "Created a new gesture engine");
|
||||
}
|
||||
struct cmd_handler *cmd = find_handler(argv[0], touch_handlers, sizeof(touch_handlers));
|
||||
if( cmd ) {
|
||||
return config_subcommand(argv, argc, touch_handlers, sizeof(touch_handlers));
|
||||
}
|
||||
return cmd_results_new(CMD_FAILURE,
|
||||
"Invalid subcommand: %s",
|
||||
argv[0]);
|
||||
|
||||
|
||||
if (find_handler(argv[0], touch_handlers, sizeof(touch_handlers))) {
|
||||
return config_subcommand(
|
||||
argv,argc,touch_handlers, sizeof(touch_handlers));
|
||||
}
|
||||
return cmd_results_new(CMD_INVALID, "Invalid subcommand: %s", argv[0]);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,29 +2,28 @@
|
|||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <libtouch.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_binding(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
|
||||
if((error = checkarg(argc, "binding", EXPECTED_AT_LEAST, 2))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
struct gesture_config *config = get_gesture_config(argv[0]);
|
||||
|
||||
if (!config) {
|
||||
return cmd_results_new(CMD_FAILURE, "Unable to bind gesture %s", argv[0]);
|
||||
return cmd_results_new(
|
||||
CMD_INVALID, "Unknown gesture %s", argv[0]);
|
||||
}
|
||||
|
||||
sway_log(SWAY_DEBUG, "libtouch: Bound gesture %s", argv[0]);
|
||||
|
||||
|
||||
config->command = join_args(argv + 1, argc - 1);
|
||||
return cmd_results_new(CMD_SUCCESS, NULL);
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ struct cmd_results *touch_cmd_gesture(int argc, char **argv) {
|
|||
if((error = checkarg(argc, "gesture", EXPECTED_AT_LEAST, 2))) {
|
||||
return error;
|
||||
}
|
||||
sway_log(SWAY_DEBUG, "Getting gesture conf");
|
||||
|
||||
struct gesture_config *gesture = get_gesture_config(argv[0]);
|
||||
|
||||
|
|
@ -36,12 +35,14 @@ struct cmd_results *touch_cmd_gesture(int argc, char **argv) {
|
|||
|
||||
config->handler_context.current_gesture = gesture;
|
||||
|
||||
struct cmd_handler *cmd = find_handler(argv[1], gesture_handlers, sizeof(gesture_handlers));
|
||||
struct cmd_handler *cmd = find_handler(
|
||||
argv[1], gesture_handlers, sizeof(gesture_handlers));
|
||||
if (cmd) {
|
||||
return config_subcommand(argv + 1,argc - 1,gesture_handlers, sizeof(gesture_handlers));
|
||||
return config_subcommand(
|
||||
argv + 1,argc - 1,
|
||||
gesture_handlers, sizeof(gesture_handlers));
|
||||
}
|
||||
|
||||
|
||||
|
||||
return cmd_results_new(CMD_FAILURE,
|
||||
"Invalid Subcommand: %s",
|
||||
argv[1]);
|
||||
|
|
|
|||
|
|
@ -12,22 +12,27 @@
|
|||
|
||||
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))) {
|
||||
if((error = checkarg(argc, "delay", 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");
|
||||
long int delay = strtol(argv[0],NULL,10);
|
||||
if(delay == 0) {
|
||||
return cmd_results_new(
|
||||
CMD_INVALID, "Invalid delay %s", argv[0]);
|
||||
}
|
||||
if(!config->handler_context.current_gesture) {
|
||||
return cmd_results_new(
|
||||
CMD_FAILURE, "No current gesture");
|
||||
}
|
||||
struct libtouch_gesture *gesture = config->handler_context.current_gesture->gesture;
|
||||
|
||||
struct libtouch_action *action = libtouch_gesture_add_delay(gesture, mode);
|
||||
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");
|
||||
return cmd_results_new(CMD_SUCCESS, NULL);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -22,13 +22,11 @@ struct cmd_results *touch_gesture_cmd_pinch(int argc, char **argv) {
|
|||
} 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]);
|
||||
return cmd_results_new(CMD_INVALID, "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;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,17 +22,22 @@ struct cmd_results *touch_gesture_cmd_rotate(int argc, char **argv) {
|
|||
} 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]);
|
||||
return cmd_results_new(
|
||||
CMD_INVALID,
|
||||
"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");
|
||||
return cmd_results_new(
|
||||
CMD_FAILURE, "No gesture in gesture config");
|
||||
}
|
||||
struct libtouch_gesture *gesture = config->handler_context.current_gesture->gesture;
|
||||
struct libtouch_gesture *gesture =
|
||||
config->handler_context.current_gesture->gesture;
|
||||
|
||||
struct libtouch_action *action = libtouch_gesture_add_rotate(gesture, mode);
|
||||
struct libtouch_action *action =
|
||||
libtouch_gesture_add_rotate(gesture, mode);
|
||||
|
||||
config->handler_context.current_gesture_action = action;
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ struct cmd_results *touch_gesture_cmd_swipe(int argc, char **argv) {
|
|||
|
||||
sway_log(SWAY_DEBUG, "Direction: %d", direction);
|
||||
if (direction == 0) {
|
||||
return cmd_results_new(CMD_FAILURE, "Direction %s invalid", argv[0]);
|
||||
return cmd_results_new(CMD_INVALID, "Direction %s invalid", argv[0]);
|
||||
}
|
||||
|
||||
struct libtouch_gesture *gesture = config->handler_context.current_gesture->gesture;
|
||||
|
|
|
|||
|
|
@ -15,15 +15,16 @@ struct cmd_results *touch_gesture_cmd_threshold(int argc, char **argv) {
|
|||
if((error = checkarg(argc, "touch", EXPECTED_EQUAL_TO, 1))) {
|
||||
return error;
|
||||
}
|
||||
struct libtouch_action *current = config->handler_context.current_gesture_action;
|
||||
struct libtouch_action *current =
|
||||
config->handler_context.current_gesture_action;
|
||||
if(!current) {
|
||||
return cmd_results_new(CMD_FAILURE, "No action created");
|
||||
}
|
||||
|
||||
int threshold = atoi(argv[0]);
|
||||
if(threshold < 0) {
|
||||
return cmd_results_new(CMD_INVALID,
|
||||
"Invalid threshold: %s", argv[0]);
|
||||
long int threshold = strtol(argv[0], NULL, 10);
|
||||
if(threshold == 0) {
|
||||
return cmd_results_new(
|
||||
CMD_INVALID, "Invalid threshold: %s", argv[0]);
|
||||
}
|
||||
sway_log(SWAY_DEBUG, "Set threshold %d", threshold);
|
||||
libtouch_action_set_threshold(current, threshold);
|
||||
|
|
|
|||
|
|
@ -16,10 +16,10 @@ struct cmd_results *touch_cmd_target(int argc, char **argv) {
|
|||
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]);
|
||||
double x = strtod(argv[1], NULL);
|
||||
double y = strtod(argv[2], NULL);
|
||||
double w = strtod(argv[3], NULL);
|
||||
double h = strtod(argv[4], NULL);
|
||||
sway_log(SWAY_DEBUG, "Converted: %f, %f, %f, %f", x,y,w,h);
|
||||
|
||||
if(!config->gesture_engine) {
|
||||
|
|
@ -29,14 +29,17 @@ struct cmd_results *touch_cmd_target(int argc, char **argv) {
|
|||
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]);
|
||||
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]);
|
||||
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);
|
||||
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");
|
||||
|
|
@ -46,5 +49,4 @@ struct cmd_results *touch_cmd_target(int argc, char **argv) {
|
|||
|
||||
|
||||
return cmd_results_new(CMD_SUCCESS, "Created target: %s", argv[0]);
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -132,6 +132,7 @@ void free_config(struct sway_config *config) {
|
|||
}
|
||||
list_free(config->criteria);
|
||||
}
|
||||
|
||||
list_free(config->no_focus);
|
||||
list_free(config->active_bar_modifiers);
|
||||
list_free_items_and_destroy(config->config_chain);
|
||||
|
|
@ -143,6 +144,7 @@ void free_config(struct sway_config *config) {
|
|||
free(config->floating_scroll_left_cmd);
|
||||
free(config->floating_scroll_right_cmd);
|
||||
free(config->font);
|
||||
free(config->gesture_engine);
|
||||
free(config->swaybg_command);
|
||||
free(config->swaynag_command);
|
||||
free((char *)config->current_config_path);
|
||||
|
|
@ -314,7 +316,7 @@ static void config_defaults(struct sway_config *config) {
|
|||
|
||||
set_color(config->border_colors.background, 0xFFFFFF);
|
||||
|
||||
config->gesture_engine = libtouch_engine_create();
|
||||
if (!(config->gesture_engine = libtouch_engine_create())) goto cleanup;
|
||||
// Security
|
||||
if (!(config->command_policies = create_list())) goto cleanup;
|
||||
if (!(config->feature_policies = create_list())) goto cleanup;
|
||||
|
|
|
|||
|
|
@ -6,42 +6,46 @@
|
|||
#include "log.h"
|
||||
#include <libtouch.h>
|
||||
|
||||
struct gesture_config *get_gesture_config(const char* identifier) {
|
||||
int i = list_seq_find(config->gesture_configs, gesture_identifier_cmp, identifier);
|
||||
|
||||
struct gesture_config *cfg = NULL;
|
||||
if(i >= 0) {
|
||||
sway_log(SWAY_DEBUG, "Retrieving existing gesture");
|
||||
cfg = config->gesture_configs->items[i];
|
||||
} else {
|
||||
sway_log(SWAY_DEBUG, "Adding new gesture");
|
||||
cfg = new_gesture_config(identifier);
|
||||
list_add(config->gesture_configs, cfg);
|
||||
}
|
||||
struct gesture_config *get_gesture_config(const char *identifier) {
|
||||
int i = list_seq_find(
|
||||
config->gesture_configs, gesture_identifier_cmp, identifier);
|
||||
|
||||
struct gesture_config *cfg = NULL;
|
||||
if(i >= 0) {
|
||||
sway_log(SWAY_DEBUG, "Retrieving existing gesture");
|
||||
cfg = config->gesture_configs->items[i];
|
||||
} else {
|
||||
sway_log(SWAY_DEBUG, "Adding new gesture");
|
||||
cfg = new_gesture_config(identifier);
|
||||
}
|
||||
|
||||
return cfg;
|
||||
|
||||
return cfg;
|
||||
}
|
||||
|
||||
struct gesture_config *new_gesture_config(const char *identifier) {
|
||||
struct gesture_config *cfg = calloc(sizeof(struct gesture_config), 1);
|
||||
cfg->identifier = strdup(identifier);
|
||||
cfg->gesture = libtouch_gesture_create(config->gesture_engine);
|
||||
struct gesture_config *cfg = calloc(sizeof(struct gesture_config), 1);
|
||||
if (!cfg) {
|
||||
sway_log(SWAY_ERROR, "Failed to allocate gesture_config");
|
||||
return NULL;
|
||||
}
|
||||
cfg->identifier = strdup(identifier);
|
||||
cfg->gesture = libtouch_gesture_create(config->gesture_engine);
|
||||
|
||||
return cfg;
|
||||
return cfg;
|
||||
}
|
||||
|
||||
int gesture_identifier_cmp(const void *item, const void *data) {
|
||||
const struct gesture_config *gc = item;
|
||||
const char *identifier = data;
|
||||
return strcmp(gc->identifier, identifier);
|
||||
const struct gesture_config *gc = item;
|
||||
const char *identifier = data;
|
||||
return strcmp(gc->identifier, identifier);
|
||||
}
|
||||
|
||||
int gesture_libtouch_cmp(const void *item, const void *data) {
|
||||
const struct gesture_config *gc = item;
|
||||
const struct libtouch_gesture *g = data;
|
||||
if(gc->gesture == g)
|
||||
return 0;
|
||||
else
|
||||
return -1;
|
||||
const struct gesture_config *gc = item;
|
||||
const struct libtouch_gesture *g = data;
|
||||
if(gc->gesture == g) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,19 +20,17 @@ struct gesture_target_config *get_gesture_target_config(const char* identifier)
|
|||
}
|
||||
|
||||
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);
|
||||
if (!cfg) {
|
||||
sway_log(
|
||||
SWAY_ERROR, "Could not allocate gesture_target_config");
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -334,30 +334,19 @@ static void handle_cursor_frame(struct wl_listener *listener, void *data) {
|
|||
|
||||
static void handle_gestures(struct libtouch_progress_tracker *tracker, struct sway_seat *seat) {
|
||||
struct libtouch_gesture *complete;
|
||||
struct gesture_config *cfg;
|
||||
int idx;
|
||||
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);
|
||||
if(idx >= 0) {
|
||||
sway_log(SWAY_DEBUG, "Completed gesture %s", cfg->identifier);
|
||||
while ((complete = libtouch_handle_finished_gesture(tracker)) != NULL) {
|
||||
int idx = list_seq_find(config->gesture_configs,
|
||||
gesture_libtouch_cmp, complete);
|
||||
if (idx >= 0) {
|
||||
struct gesture_config *cfg;
|
||||
cfg = config->gesture_configs->items[idx];
|
||||
|
||||
if(cfg->command) {
|
||||
if (cfg->command) {
|
||||
execute_command(cfg->command, seat, NULL);
|
||||
}
|
||||
} else {
|
||||
sway_log(SWAY_DEBUG, "Gesture unbound!");
|
||||
sway_log(SWAY_ERROR, "Gesture unbound!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void handle_touch_down(struct wl_listener *listener, void *data) {
|
||||
|
|
@ -378,9 +367,12 @@ 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,
|
||||
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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue