From 0f45fad18cf56910aa339c7c6ad1a661e96cfb0d Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sun, 22 Oct 2017 11:38:30 -0400 Subject: Establish sway input submodule --- sway/CMakeLists.txt | 3 ++- sway/input.c | 69 ----------------------------------------------- sway/input/input.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++ sway/ipc-server.c | 2 ++ sway/server.c | 5 ++-- 5 files changed, 83 insertions(+), 73 deletions(-) delete mode 100644 sway/input.c create mode 100644 sway/input/input.c (limited to 'sway') diff --git a/sway/CMakeLists.txt b/sway/CMakeLists.txt index ac0530e5..3c78aec9 100644 --- a/sway/CMakeLists.txt +++ b/sway/CMakeLists.txt @@ -26,7 +26,6 @@ add_executable(sway criteria.c debug_log.c focus.c - input.c input_state.c ipc-json.c ipc-server.c @@ -37,6 +36,8 @@ add_executable(sway border.c security.c server.c + + input/input.c ) add_definitions( diff --git a/sway/input.c b/sway/input.c deleted file mode 100644 index 6263f79f..00000000 --- a/sway/input.c +++ /dev/null @@ -1,69 +0,0 @@ -#define _XOPEN_SOURCE 700 -#include -#include -#include -#include -#include -#include -#include "sway/config.h" -#include "sway/input.h" -#include "list.h" -#include "log.h" - -struct input_config *new_input_config(const char* identifier) { - struct input_config *input = calloc(1, sizeof(struct input_config)); - if (!input) { - sway_log(L_DEBUG, "Unable to allocate input config"); - return NULL; - } - sway_log(L_DEBUG, "new_input_config(%s)", identifier); - if (!(input->identifier = strdup(identifier))) { - free(input); - sway_log(L_DEBUG, "Unable to allocate input config"); - return NULL; - } - - input->tap = INT_MIN; - input->drag_lock = INT_MIN; - input->dwt = INT_MIN; - input->send_events = INT_MIN; - input->click_method = INT_MIN; - input->middle_emulation = INT_MIN; - input->natural_scroll = INT_MIN; - input->accel_profile = INT_MIN; - input->pointer_accel = FLT_MIN; - input->scroll_method = INT_MIN; - input->left_handed = INT_MIN; - - return input; -} - -char *libinput_dev_unique_id(struct libinput_device *device) { - int vendor = libinput_device_get_id_vendor(device); - int product = libinput_device_get_id_product(device); - char *name = strdup(libinput_device_get_name(device)); - - char *p = name; - for (; *p; ++p) { - if (*p == ' ') { - *p = '_'; - } - } - - sway_log(L_DEBUG, "rewritten name %s", name); - - int len = strlen(name) + sizeof(char) * 6; - char *identifier = malloc(len); - if (!identifier) { - sway_log(L_ERROR, "Unable to allocate unique input device name"); - return NULL; - } - - const char *fmt = "%d:%d:%s"; - snprintf(identifier, len, fmt, vendor, product, name); - free(name); - return identifier; -} - -list_t *input_devices = NULL; -struct input_config *current_input_config = NULL; diff --git a/sway/input/input.c b/sway/input/input.c new file mode 100644 index 00000000..02b4995e --- /dev/null +++ b/sway/input/input.c @@ -0,0 +1,77 @@ +#define _XOPEN_SOURCE 700 +#include +#include +#include +#include +#include +#include +#include "sway/config.h" +#include "sway/input.h" +#include "sway/server.h" +#include "list.h" +#include "log.h" + +struct input_config *current_input_config = NULL; + +struct sway_input *sway_input_create(struct sway_server *server) { + struct sway_input *input = calloc(1, sizeof(struct sway_input)); + if (!input) { + return NULL; + } + return input; +} + +struct input_config *new_input_config(const char* identifier) { + struct input_config *input = calloc(1, sizeof(struct input_config)); + if (!input) { + sway_log(L_DEBUG, "Unable to allocate input config"); + return NULL; + } + sway_log(L_DEBUG, "new_input_config(%s)", identifier); + if (!(input->identifier = strdup(identifier))) { + free(input); + sway_log(L_DEBUG, "Unable to allocate input config"); + return NULL; + } + + input->tap = INT_MIN; + input->drag_lock = INT_MIN; + input->dwt = INT_MIN; + input->send_events = INT_MIN; + input->click_method = INT_MIN; + input->middle_emulation = INT_MIN; + input->natural_scroll = INT_MIN; + input->accel_profile = INT_MIN; + input->pointer_accel = FLT_MIN; + input->scroll_method = INT_MIN; + input->left_handed = INT_MIN; + + return input; +} + +char *libinput_dev_unique_id(struct libinput_device *device) { + int vendor = libinput_device_get_id_vendor(device); + int product = libinput_device_get_id_product(device); + char *name = strdup(libinput_device_get_name(device)); + + char *p = name; + for (; *p; ++p) { + if (*p == ' ') { + *p = '_'; + } + } + + sway_log(L_DEBUG, "rewritten name %s", name); + + int len = strlen(name) + sizeof(char) * 6; + char *identifier = malloc(len); + if (!identifier) { + sway_log(L_ERROR, "Unable to allocate unique input device name"); + return NULL; + } + + const char *fmt = "%d:%d:%s"; + snprintf(identifier, len, fmt, vendor, product, name); + free(name); + return identifier; +} diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 9ba736d8..d4db4e7a 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c @@ -476,12 +476,14 @@ void ipc_client_handle_command(struct ipc_client *client) { goto exit_denied; } json_object *inputs = json_object_new_array(); + /* TODO WLR if (input_devices) { for(int i = 0; ilength; i++) { struct libinput_device *device = input_devices->items[i]; json_object_array_add(inputs, ipc_json_describe_input(device)); } } + */ const char *json_string = json_object_to_json_string(inputs); ipc_send_reply(client, json_string, (uint32_t) strlen(json_string)); json_object_put(inputs); diff --git a/sway/server.c b/sway/server.c index 39fa5d28..4a74cfb5 100644 --- a/sway/server.c +++ b/sway/server.c @@ -10,6 +10,7 @@ // TODO WLR: make Xwayland optional #include #include "sway/server.h" +#include "sway/input.h" #include "log.h" bool server_init(struct sway_server *server) { @@ -22,9 +23,7 @@ bool server_init(struct sway_server *server) { server->renderer = wlr_gles2_renderer_create(server->backend); wl_display_init_shm(server->wl_display); - // TODO WLR - //server->desktop = desktop_create(server, server.config); - //server->input = input_create(&server, server.config); + server->input = sway_input_create(server); server->data_device_manager = wlr_data_device_manager_create(server->wl_display); -- cgit v1.2.3