mirror of
https://github.com/swaywm/sway.git
synced 2026-04-28 06:46:26 -04:00
Restructure and add a hiearchy of commands
This commit is contained in:
parent
cb94176e27
commit
ba2020aebd
10 changed files with 177 additions and 57 deletions
|
|
@ -280,6 +280,12 @@ sway_cmd seat_cmd_fallback;
|
||||||
sway_cmd seat_cmd_hide_cursor;
|
sway_cmd seat_cmd_hide_cursor;
|
||||||
sway_cmd seat_cmd_pointer_constraint;
|
sway_cmd seat_cmd_pointer_constraint;
|
||||||
|
|
||||||
|
sway_cmd touch_cmd_gesture;
|
||||||
|
sway_cmd touch_cmd_binding;
|
||||||
|
|
||||||
|
sway_cmd touch_gesture_cmd_touch;
|
||||||
|
|
||||||
|
|
||||||
sway_cmd cmd_ipc_cmd;
|
sway_cmd cmd_ipc_cmd;
|
||||||
sway_cmd cmd_ipc_events;
|
sway_cmd cmd_ipc_events;
|
||||||
sway_cmd cmd_ipc_event_cmd;
|
sway_cmd cmd_ipc_event_cmd;
|
||||||
|
|
|
||||||
|
|
@ -53,12 +53,6 @@ struct sway_binding {
|
||||||
uint32_t modifiers;
|
uint32_t modifiers;
|
||||||
char *command;
|
char *command;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sway_gesture_binding {
|
|
||||||
struct libtouch_gesture *gesture;
|
|
||||||
char *command;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A mouse binding and an associated command.
|
* A mouse binding and an associated command.
|
||||||
*/
|
*/
|
||||||
|
|
@ -106,6 +100,13 @@ struct input_config_mapped_from_region {
|
||||||
bool mm;
|
bool mm;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct gesture_config {
|
||||||
|
char *identifier;
|
||||||
|
struct libtouch_gesture *gesture;
|
||||||
|
char *command;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* options for input devices
|
* options for input devices
|
||||||
*/
|
*/
|
||||||
|
|
@ -426,6 +427,7 @@ struct sway_config {
|
||||||
list_t *output_configs;
|
list_t *output_configs;
|
||||||
list_t *input_configs;
|
list_t *input_configs;
|
||||||
list_t *input_type_configs;
|
list_t *input_type_configs;
|
||||||
|
list_t *gesture_configs;
|
||||||
list_t *seat_configs;
|
list_t *seat_configs;
|
||||||
list_t *criteria;
|
list_t *criteria;
|
||||||
list_t *no_focus;
|
list_t *no_focus;
|
||||||
|
|
@ -514,6 +516,7 @@ struct sway_config {
|
||||||
list_t *feature_policies;
|
list_t *feature_policies;
|
||||||
list_t *ipc_policies;
|
list_t *ipc_policies;
|
||||||
|
|
||||||
|
struct libtouch_engine *gesture_engine;
|
||||||
// Context for command handlers
|
// Context for command handlers
|
||||||
struct {
|
struct {
|
||||||
struct input_config *input_config;
|
struct input_config *input_config;
|
||||||
|
|
@ -523,6 +526,10 @@ struct sway_config {
|
||||||
struct sway_node *node;
|
struct sway_node *node;
|
||||||
struct sway_container *container;
|
struct sway_container *container;
|
||||||
struct sway_workspace *workspace;
|
struct sway_workspace *workspace;
|
||||||
|
|
||||||
|
struct gesture_config *current_gesture;
|
||||||
|
|
||||||
|
|
||||||
bool using_criteria;
|
bool using_criteria;
|
||||||
struct {
|
struct {
|
||||||
int argc;
|
int argc;
|
||||||
|
|
@ -647,6 +654,12 @@ void free_bar_binding(struct bar_binding *binding);
|
||||||
|
|
||||||
void free_workspace_config(struct workspace_config *wsc);
|
void free_workspace_config(struct workspace_config *wsc);
|
||||||
|
|
||||||
|
int gesture_identifier_cmp(const void *item, const void *data);
|
||||||
|
|
||||||
|
struct gesture_config *get_gesture_config(const char *identifier);
|
||||||
|
|
||||||
|
struct gesture_config *new_gesture_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
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ static struct cmd_handler handlers[] = {
|
||||||
{ "force_focus_wrapping", cmd_force_focus_wrapping },
|
{ "force_focus_wrapping", cmd_force_focus_wrapping },
|
||||||
{ "fullscreen", cmd_fullscreen },
|
{ "fullscreen", cmd_fullscreen },
|
||||||
{ "gaps", cmd_gaps },
|
{ "gaps", cmd_gaps },
|
||||||
{ "gesture", cmd_gesture },
|
{ "touch", cmd_touch },
|
||||||
{ "hide_edge_borders", cmd_hide_edge_borders },
|
{ "hide_edge_borders", cmd_hide_edge_borders },
|
||||||
{ "include", cmd_include },
|
{ "include", cmd_include },
|
||||||
{ "input", cmd_input },
|
{ "input", cmd_input },
|
||||||
|
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
#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>
|
|
||||||
|
|
||||||
|
|
||||||
void free_sway_gesture_binding(struct sway_gesture_binding *binding) {
|
|
||||||
if(!binding) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
free(binding->command);
|
|
||||||
free(binding);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct cmd_results *cmd_touch(int argc, char **argv) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct cmd_results *cmd_gesture(int argc, char **argv) {
|
|
||||||
struct cmd_results *error = NULL;
|
|
||||||
|
|
||||||
struct sway_gesture_binding *binding = calloc(1, sizeof(struct sway_gesture_binding));
|
|
||||||
if(!binding) {
|
|
||||||
return cmd_results_new(CMD_FAILURE, "Unable to allocate binding");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(argc < 2) {
|
|
||||||
free_sway_gesture_binding(binding);
|
|
||||||
return cmd_results_new(CMD_FAILURE, "Invalid gesture command "
|
|
||||||
"(expected at least 2 arguments, got %d)", argc);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
binding->command = join_args(argv+1, argc -1);
|
|
||||||
//list_t *bindings = config->current_mode->gesture_bindings;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
35
sway/commands/touch.c
Normal file
35
sway/commands/touch.c
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
#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>
|
||||||
|
|
||||||
|
static struct cmd_handler touch_handlers[] = {
|
||||||
|
{ "gesture", touch_cmd_gesture },
|
||||||
|
{ "binding", touch_cmd_binding },
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct cmd_results *cmd_touch(int argc, char **argv) {
|
||||||
|
struct cmd_results *error = NULL;
|
||||||
|
if ((error = checkarg(argc, "touch", EXPECTED_AT_LEAST, 2))) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
if(!config->gesture_engine) {
|
||||||
|
config->gesture_engine = libtouch_engine_create();
|
||||||
|
}
|
||||||
|
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");
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
15
sway/commands/touch/binding.c
Normal file
15
sway/commands/touch/binding.c
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
#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_binding(int argc, char **argv) {
|
||||||
|
return NULL;
|
||||||
|
};
|
||||||
41
sway/commands/touch/gesture.c
Normal file
41
sway/commands/touch/gesture.c
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
#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>
|
||||||
|
|
||||||
|
static struct cmd_handler gesture_handlers[] = {
|
||||||
|
{ "touch", touch_gesture_cmd_touch },
|
||||||
|
};
|
||||||
|
|
||||||
|
struct cmd_results *touch_cmd_gesture(int argc, char **argv) {
|
||||||
|
struct cmd_results *error = NULL;
|
||||||
|
if((error = checkarg(argc, "gesture", EXPECTED_AT_LEAST, 1))) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
sway_log(SWAY_DEBUG, "entering gesture block: %s", argv[0]);
|
||||||
|
struct gesture_config *gesture = get_gesture_config(argv[0]);
|
||||||
|
|
||||||
|
if(!gesture) {
|
||||||
|
return cmd_results_new(CMD_FAILURE,
|
||||||
|
"Could not create/find gesture config");
|
||||||
|
}
|
||||||
|
|
||||||
|
config->handler_context.current_gesture = gesture;
|
||||||
|
|
||||||
|
struct cmd_handler *cmd = find_handler(argv[1], gesture_handlers, sizeof(gesture_handlers));
|
||||||
|
if (cmd) {
|
||||||
|
return config_subcommand(argv,argc,gesture_handlers, sizeof(gesture_handlers));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return cmd_results_new(CMD_FAILURE,
|
||||||
|
"Invalid Subcommand");
|
||||||
|
};
|
||||||
15
sway/commands/touch/gesture/touch.c
Normal file
15
sway/commands/touch/gesture/touch.c
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
#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_touch(int argc, char **argv) {
|
||||||
|
return NULL;
|
||||||
|
};
|
||||||
38
sway/config/gesture.c
Normal file
38
sway/config/gesture.c
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
#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_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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
@ -36,6 +36,7 @@ sway_sources = files(
|
||||||
'config/output.c',
|
'config/output.c',
|
||||||
'config/seat.c',
|
'config/seat.c',
|
||||||
'config/input.c',
|
'config/input.c',
|
||||||
|
'config/gesture.c',
|
||||||
|
|
||||||
'commands/assign.c',
|
'commands/assign.c',
|
||||||
'commands/bar.c',
|
'commands/bar.c',
|
||||||
|
|
@ -62,7 +63,7 @@ sway_sources = files(
|
||||||
'commands/force_focus_wrapping.c',
|
'commands/force_focus_wrapping.c',
|
||||||
'commands/fullscreen.c',
|
'commands/fullscreen.c',
|
||||||
'commands/gaps.c',
|
'commands/gaps.c',
|
||||||
'commands/gesture.c',
|
'commands/touch.c',
|
||||||
'commands/hide_edge_borders.c',
|
'commands/hide_edge_borders.c',
|
||||||
'commands/inhibit_idle.c',
|
'commands/inhibit_idle.c',
|
||||||
'commands/kill.c',
|
'commands/kill.c',
|
||||||
|
|
@ -176,6 +177,10 @@ sway_sources = files(
|
||||||
'commands/output/subpixel.c',
|
'commands/output/subpixel.c',
|
||||||
'commands/output/transform.c',
|
'commands/output/transform.c',
|
||||||
|
|
||||||
|
'commands/touch/binding.c',
|
||||||
|
'commands/touch/gesture.c',
|
||||||
|
'commands/touch/gesture/touch.c',
|
||||||
|
|
||||||
'tree/arrange.c',
|
'tree/arrange.c',
|
||||||
'tree/container.c',
|
'tree/container.c',
|
||||||
'tree/node.c',
|
'tree/node.c',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue