2017-12-17 03:25:59 +11:00
|
|
|
#define _XOPEN_SOURCE 700
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <float.h>
|
|
|
|
#include "sway/config.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) {
|
2018-07-10 07:54:30 +10:00
|
|
|
wlr_log(WLR_DEBUG, "Unable to allocate input config");
|
2017-12-17 03:25:59 +11:00
|
|
|
return NULL;
|
|
|
|
}
|
2018-07-10 07:54:30 +10:00
|
|
|
wlr_log(WLR_DEBUG, "new_input_config(%s)", identifier);
|
2017-12-17 03:25:59 +11:00
|
|
|
if (!(input->identifier = strdup(identifier))) {
|
|
|
|
free(input);
|
2018-07-10 07:54:30 +10:00
|
|
|
wlr_log(WLR_DEBUG, "Unable to allocate input config");
|
2017-12-17 03:25:59 +11:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
input->tap = INT_MIN;
|
2018-07-14 15:01:47 +10:00
|
|
|
input->tap_button_map = INT_MIN;
|
2017-12-17 03:25:59 +11:00
|
|
|
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;
|
2018-07-12 06:03:06 +10:00
|
|
|
input->scroll_button = INT_MIN;
|
2018-07-12 20:08:53 +10:00
|
|
|
input->scroll_method = INT_MIN;
|
2017-12-17 03:25:59 +11:00
|
|
|
input->left_handed = INT_MIN;
|
2018-04-18 23:19:23 +10:00
|
|
|
input->repeat_delay = INT_MIN;
|
|
|
|
input->repeat_rate = INT_MIN;
|
2018-07-23 05:16:19 +10:00
|
|
|
input->xkb_numlock = INT_MIN;
|
|
|
|
input->xkb_capslock = INT_MIN;
|
2017-12-17 03:25:59 +11:00
|
|
|
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
|
|
|
void merge_input_config(struct input_config *dst, struct input_config *src) {
|
|
|
|
if (src->identifier) {
|
|
|
|
free(dst->identifier);
|
|
|
|
dst->identifier = strdup(src->identifier);
|
|
|
|
}
|
|
|
|
if (src->accel_profile != INT_MIN) {
|
|
|
|
dst->accel_profile = src->accel_profile;
|
|
|
|
}
|
|
|
|
if (src->click_method != INT_MIN) {
|
|
|
|
dst->click_method = src->click_method;
|
|
|
|
}
|
|
|
|
if (src->drag_lock != INT_MIN) {
|
|
|
|
dst->drag_lock = src->drag_lock;
|
|
|
|
}
|
|
|
|
if (src->dwt != INT_MIN) {
|
|
|
|
dst->dwt = src->dwt;
|
|
|
|
}
|
|
|
|
if (src->middle_emulation != INT_MIN) {
|
|
|
|
dst->middle_emulation = src->middle_emulation;
|
|
|
|
}
|
|
|
|
if (src->natural_scroll != INT_MIN) {
|
|
|
|
dst->natural_scroll = src->natural_scroll;
|
|
|
|
}
|
|
|
|
if (src->pointer_accel != FLT_MIN) {
|
|
|
|
dst->pointer_accel = src->pointer_accel;
|
|
|
|
}
|
2018-04-18 23:19:23 +10:00
|
|
|
if (src->repeat_delay != INT_MIN) {
|
|
|
|
dst->repeat_delay = src->repeat_delay;
|
|
|
|
}
|
|
|
|
if (src->repeat_rate != INT_MIN) {
|
|
|
|
dst->repeat_rate = src->repeat_rate;
|
|
|
|
}
|
2017-12-17 03:25:59 +11:00
|
|
|
if (src->scroll_method != INT_MIN) {
|
|
|
|
dst->scroll_method = src->scroll_method;
|
|
|
|
}
|
2018-07-12 06:03:06 +10:00
|
|
|
if (src->scroll_button != INT_MIN) {
|
2018-07-12 20:08:53 +10:00
|
|
|
dst->scroll_button = src->scroll_button;
|
2018-07-12 06:03:06 +10:00
|
|
|
}
|
2017-12-17 03:25:59 +11:00
|
|
|
if (src->send_events != INT_MIN) {
|
|
|
|
dst->send_events = src->send_events;
|
|
|
|
}
|
|
|
|
if (src->tap != INT_MIN) {
|
|
|
|
dst->tap = src->tap;
|
|
|
|
}
|
2018-07-14 15:01:47 +10:00
|
|
|
if (src->tap_button_map != INT_MIN) {
|
|
|
|
dst->tap_button_map = src->tap_button_map;
|
|
|
|
}
|
2017-12-17 03:25:59 +11:00
|
|
|
if (src->xkb_layout) {
|
|
|
|
free(dst->xkb_layout);
|
|
|
|
dst->xkb_layout = strdup(src->xkb_layout);
|
|
|
|
}
|
|
|
|
if (src->xkb_model) {
|
|
|
|
free(dst->xkb_model);
|
|
|
|
dst->xkb_model = strdup(src->xkb_model);
|
|
|
|
}
|
|
|
|
if (src->xkb_options) {
|
|
|
|
free(dst->xkb_options);
|
|
|
|
dst->xkb_options = strdup(src->xkb_options);
|
|
|
|
}
|
|
|
|
if (src->xkb_rules) {
|
|
|
|
free(dst->xkb_rules);
|
|
|
|
dst->xkb_rules = strdup(src->xkb_rules);
|
|
|
|
}
|
|
|
|
if (src->xkb_variant) {
|
|
|
|
free(dst->xkb_variant);
|
|
|
|
dst->xkb_variant = strdup(src->xkb_variant);
|
|
|
|
}
|
2018-07-23 05:16:19 +10:00
|
|
|
if (src->xkb_numlock != INT_MIN) {
|
|
|
|
dst->xkb_numlock = src->xkb_numlock;
|
|
|
|
}
|
|
|
|
if (src->xkb_capslock != INT_MIN) {
|
|
|
|
dst->xkb_capslock = src->xkb_capslock;
|
|
|
|
}
|
2018-04-25 04:39:29 +10:00
|
|
|
if (src->mapped_from_region) {
|
|
|
|
free(dst->mapped_from_region);
|
|
|
|
dst->mapped_from_region =
|
|
|
|
malloc(sizeof(struct input_config_mapped_from_region));
|
|
|
|
memcpy(dst->mapped_from_region, src->mapped_from_region,
|
|
|
|
sizeof(struct input_config_mapped_from_region));
|
|
|
|
}
|
|
|
|
if (src->mapped_to_output) {
|
|
|
|
free(dst->mapped_to_output);
|
|
|
|
dst->mapped_to_output = strdup(src->mapped_to_output);
|
2018-04-09 04:15:13 +10:00
|
|
|
}
|
2017-12-17 03:25:59 +11:00
|
|
|
}
|
|
|
|
|
2018-01-18 01:49:02 +11:00
|
|
|
struct input_config *copy_input_config(struct input_config *ic) {
|
|
|
|
struct input_config *copy = calloc(1, sizeof(struct input_config));
|
|
|
|
if (copy == NULL) {
|
2018-07-10 07:54:30 +10:00
|
|
|
wlr_log(WLR_ERROR, "could not allocate input config");
|
2018-01-18 01:49:02 +11:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
merge_input_config(copy, ic);
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2017-12-17 03:25:59 +11:00
|
|
|
void free_input_config(struct input_config *ic) {
|
|
|
|
if (!ic) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
free(ic->identifier);
|
|
|
|
free(ic);
|
|
|
|
}
|
|
|
|
|
|
|
|
int input_identifier_cmp(const void *item, const void *data) {
|
|
|
|
const struct input_config *ic = item;
|
|
|
|
const char *identifier = data;
|
|
|
|
return strcmp(ic->identifier, identifier);
|
|
|
|
}
|