Apply clang-format

This commit is contained in:
project-repo 2021-09-16 14:31:20 +02:00
commit e684a81efb
10 changed files with 465 additions and 391 deletions

View file

@ -1,4 +1,4 @@
/*
/*
* Cagebreak: A Wayland tiling compositor.
*
* Copyright (C) 2018-2020 Jente Hidskes
@ -44,12 +44,12 @@
#endif
#include "idle_inhibit_v1.h"
#include "input_manager.h"
#include "ipc_server.h"
#include "keybinding.h"
#include "message.h"
#include "output.h"
#include "parse.h"
#include "input_manager.h"
#include "seat.h"
#include "server.h"
#include "xdg_shell.h"

View file

@ -25,8 +25,8 @@
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_data_control_v1.h>
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_export_dmabuf_v1.h>
#include <wlr/types/wlr_gamma_control_v1.h>
#include <wlr/types/wlr_idle.h>
@ -48,8 +48,8 @@
#endif
#include "../idle_inhibit_v1.h"
#include "../keybinding.h"
#include "../input_manager.h"
#include "../keybinding.h"
#include "../output.h"
#include "../parse.h"
#include "../seat.h"
@ -529,8 +529,7 @@ destroy_input_device(char *line, struct cg_server *server) {
}
devn = devn % wl_list_length(&server->input->devices);
struct cg_input_device *dev, *dev_tmp;
wl_list_for_each_safe(dev, dev_tmp, &server->input->devices,
link) {
wl_list_for_each_safe(dev, dev_tmp, &server->input->devices, link) {
if(devn == 0) {
dev->device_destroy.notify(&dev->device_destroy, NULL);
break;

12
input.h
View file

@ -7,12 +7,16 @@ struct cg_input_device;
struct cg_input_config;
struct cg_server;
void cg_input_configure_libinput_device(struct cg_input_device *device);
void
cg_input_configure_libinput_device(struct cg_input_device *device);
void cg_input_apply_config(struct cg_input_config *config, struct cg_server *server);
void
cg_input_apply_config(struct cg_input_config *config, struct cg_server *server);
void cg_input_reset_libinput_device(struct cg_input_device *device);
void
cg_input_reset_libinput_device(struct cg_input_device *device);
bool cg_libinput_device_is_builtin(struct cg_input_device *device);
bool
cg_libinput_device_is_builtin(struct cg_input_device *device);
#endif

View file

@ -9,48 +9,52 @@
#define _POSIX_C_SOURCE 200812L
#include "config.h"
#include "server.h"
#include "seat.h"
#include "input_manager.h"
#include "config.h"
#include "input.h"
#include "seat.h"
#include "server.h"
#include <ctype.h>
#include <libevdev/libevdev.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wayland-server-core.h>
#include <wlr/backend/libinput.h>
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_input_device.h>
#include <wlr/util/log.h>
#include <wlr/types/wlr_input_inhibitor.h>
#include <wlr/types/wlr_virtual_keyboard_v1.h>
#include <wlr/types/wlr_virtual_pointer_v1.h>
#include <wlr/types/wlr_input_inhibitor.h>
#include <wayland-server-core.h>
#include <libevdev/libevdev.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <wlr/util/log.h>
void strip_whitespace(char *str) {
void
strip_whitespace(char *str) {
static const char whitespace[] = " \f\n\r\t\v";
size_t len = strlen(str);
size_t start = strspn(str, whitespace);
memmove(str, &str[start], len + 1 - start);
if (*str) {
for (len -= start + 1; isspace(str[len]); --len) {}
if(*str) {
for(len -= start + 1; isspace(str[len]); --len) {
}
str[len + 1] = '\0';
}
}
char *input_device_get_identifier(struct wlr_input_device *device) {
char *
input_device_get_identifier(struct wlr_input_device *device) {
int vendor = device->vendor;
int product = device->product;
char *name = strdup(device->name ? device->name : "");
strip_whitespace(name);
char *p = name;
for (; *p; ++p) {
// There are in fact input devices with unprintable characters in its name
if (*p == ' ' || !isprint(*p)) {
for(; *p; ++p) {
// There are in fact input devices with unprintable characters in its
// name
if(*p == ' ' || !isprint(*p)) {
*p = '_';
}
}
@ -58,7 +62,7 @@ char *input_device_get_identifier(struct wlr_input_device *device) {
const char *fmt = "%d:%d:%s";
int len = snprintf(NULL, 0, fmt, vendor, product, name) + 1;
char *identifier = malloc(len);
if (!identifier) {
if(!identifier) {
wlr_log(WLR_ERROR, "Unable to allocate unique input device name");
return NULL;
}
@ -68,11 +72,12 @@ char *input_device_get_identifier(struct wlr_input_device *device) {
return identifier;
}
void input_manager_handle_device_destroy(struct wl_listener *listener, void *data) {
void
input_manager_handle_device_destroy(struct wl_listener *listener, void *data) {
struct cg_input_device *input_device =
wl_container_of(listener, input_device, device_destroy);
wl_container_of(listener, input_device, device_destroy);
if (!input_device) {
if(!input_device) {
wlr_log(WLR_ERROR, "Could not find cagebreak input device to destroy");
return;
}
@ -85,26 +90,27 @@ void input_manager_handle_device_destroy(struct wl_listener *listener, void *dat
free(input_device);
}
static void handle_new_input(struct wl_listener *listener, void *data) {
static void
handle_new_input(struct wl_listener *listener, void *data) {
struct cg_input_manager *input =
wl_container_of(listener, input, new_input);
struct cg_server *server= input->server;
wl_container_of(listener, input, new_input);
struct cg_server *server = input->server;
struct wlr_input_device *device = data;
struct cg_input_device *input_device =
calloc(1, sizeof(struct cg_input_device));
if (!input_device) {
wlr_log(WLR_ERROR,"Could not allocate input device");
calloc(1, sizeof(struct cg_input_device));
if(!input_device) {
wlr_log(WLR_ERROR, "Could not allocate input device");
return;
}
device->data = input_device;
input_device->wlr_device = device;
input_device->identifier = input_device_get_identifier(device);
input_device->server=server;
input_device->pointer=NULL;
input_device->touch=NULL;
input_device->server = server;
input_device->pointer = NULL;
input_device->touch = NULL;
wl_list_insert(&input->devices, &input_device->link);
cg_input_configure_libinput_device(input_device);
@ -116,17 +122,18 @@ static void handle_new_input(struct wl_listener *listener, void *data) {
seat_add_device(seat, input_device);
}
void handle_virtual_keyboard(struct wl_listener *listener, void *data) {
void
handle_virtual_keyboard(struct wl_listener *listener, void *data) {
struct cg_input_manager *input_manager =
wl_container_of(listener, input_manager, virtual_keyboard_new);
wl_container_of(listener, input_manager, virtual_keyboard_new);
struct wlr_virtual_keyboard_v1 *keyboard = data;
struct wlr_input_device *device = &keyboard->input_device;
struct cg_seat *seat = input_manager->server->seat;
struct cg_input_device *input_device =
calloc(1, sizeof(struct cg_input_device));
if (!input_device) {
calloc(1, sizeof(struct cg_input_device));
if(!input_device) {
wlr_log(WLR_ERROR, "could not allocate input device");
return;
}
@ -136,9 +143,9 @@ void handle_virtual_keyboard(struct wl_listener *listener, void *data) {
input_device->wlr_device = device;
input_device->identifier = input_device_get_identifier(device);
wl_list_insert(&input_manager->devices, &input_device->link);
input_device->server=input_manager->server;
input_device->pointer=NULL;
input_device->touch=NULL;
input_device->server = input_manager->server;
input_device->pointer = NULL;
input_device->touch = NULL;
wl_signal_add(&device->events.destroy, &input_device->device_destroy);
input_device->device_destroy.notify = input_manager_handle_device_destroy;
@ -146,9 +153,10 @@ void handle_virtual_keyboard(struct wl_listener *listener, void *data) {
seat_add_device(seat, input_device);
}
void handle_virtual_pointer(struct wl_listener *listener, void *data) {
void
handle_virtual_pointer(struct wl_listener *listener, void *data) {
struct cg_input_manager *input_manager =
wl_container_of(listener, input_manager, virtual_pointer_new);
wl_container_of(listener, input_manager, virtual_pointer_new);
struct wlr_virtual_pointer_v1_new_pointer_event *event = data;
struct wlr_virtual_pointer_v1 *pointer = event->new_pointer;
struct wlr_input_device *device = &pointer->input_device;
@ -156,8 +164,8 @@ void handle_virtual_pointer(struct wl_listener *listener, void *data) {
struct cg_seat *seat = input_manager->server->seat;
struct cg_input_device *input_device =
calloc(1, sizeof(struct cg_input_device));
if (!input_device) {
calloc(1, sizeof(struct cg_input_device));
if(!input_device) {
wlr_log(WLR_ERROR, "could not allocate input device");
return;
}
@ -167,57 +175,57 @@ void handle_virtual_pointer(struct wl_listener *listener, void *data) {
input_device->wlr_device = device;
input_device->identifier = input_device_get_identifier(device);
wl_list_insert(&input_manager->devices, &input_device->link);
input_device->server=input_manager->server;
input_device->pointer=NULL;
input_device->touch=NULL;
input_device->server = input_manager->server;
input_device->pointer = NULL;
input_device->touch = NULL;
wl_signal_add(&device->events.destroy, &input_device->device_destroy);
input_device->device_destroy.notify = input_manager_handle_device_destroy;
seat_add_device(seat, input_device);
if (event->suggested_output) {
if(event->suggested_output) {
wlr_cursor_map_input_to_output(seat->cursor, device,
event->suggested_output);
event->suggested_output);
}
}
struct cg_input_manager *input_manager_create(struct cg_server *server) {
struct cg_input_manager *input =
calloc(1, sizeof(struct cg_input_manager));
if (!input) {
struct cg_input_manager *
input_manager_create(struct cg_server *server) {
struct cg_input_manager *input = calloc(1, sizeof(struct cg_input_manager));
if(!input) {
return NULL;
}
wl_list_init(&input->devices);
input->server=server;
input->server = server;
input->new_input.notify = handle_new_input;
wl_signal_add(&server->backend->events.new_input, &input->new_input);
input->virtual_keyboard = wlr_virtual_keyboard_manager_v1_create(
server->wl_display);
input->virtual_keyboard =
wlr_virtual_keyboard_manager_v1_create(server->wl_display);
wl_signal_add(&input->virtual_keyboard->events.new_virtual_keyboard,
&input->virtual_keyboard_new);
&input->virtual_keyboard_new);
input->virtual_keyboard_new.notify = handle_virtual_keyboard;
input->virtual_pointer = wlr_virtual_pointer_manager_v1_create(
server->wl_display
);
input->virtual_pointer =
wlr_virtual_pointer_manager_v1_create(server->wl_display);
wl_signal_add(&input->virtual_pointer->events.new_virtual_pointer,
&input->virtual_pointer_new);
&input->virtual_pointer_new);
input->virtual_pointer_new.notify = handle_virtual_pointer;
return input;
}
uint32_t get_mouse_bindsym(const char *name, char **error) {
uint32_t
get_mouse_bindsym(const char *name, char **error) {
// Get event code from name
int code = libevdev_event_code_from_name(EV_KEY, name);
if (code == -1) {
if(code == -1) {
size_t len = snprintf(NULL, 0, "Unknown event %s", name) + 1;
*error = malloc(len);
if (*error) {
if(*error) {
snprintf(*error, len, "Unknown event %s", name);
}
return 0;
@ -225,35 +233,38 @@ uint32_t get_mouse_bindsym(const char *name, char **error) {
return code;
}
uint32_t get_mouse_bindcode(const char *name, char **error) {
uint32_t
get_mouse_bindcode(const char *name, char **error) {
// Validate event code
errno = 0;
char *endptr;
int code = strtol(name, &endptr, 10);
if (endptr == name && code <= 0) {
if(endptr == name && code <= 0) {
*error = strdup("Button event code must be a positive integer.");
return 0;
} else if (errno == ERANGE) {
} else if(errno == ERANGE) {
*error = strdup("Button event code out of range.");
return 0;
}
const char *event = libevdev_event_code_get_name(EV_KEY, code);
if (!event || strncmp(event, "BTN_", strlen("BTN_")) != 0) {
if(!event || strncmp(event, "BTN_", strlen("BTN_")) != 0) {
size_t len = snprintf(NULL, 0, "Event code %d (%s) is not a button",
code, event ? event : "(null)") + 1;
code, event ? event : "(null)") +
1;
*error = malloc(len);
if (*error) {
snprintf(*error, len, "Event code %d (%s) is not a button",
code, event ? event : "(null)");
if(*error) {
snprintf(*error, len, "Event code %d (%s) is not a button", code,
event ? event : "(null)");
}
return 0;
}
return code;
}
uint32_t input_manager_get_mouse_button(const char *name, char **error) {
uint32_t
input_manager_get_mouse_button(const char *name, char **error) {
uint32_t button = get_mouse_bindsym(name, error);
if (!button && !*error) {
if(!button && !*error) {
button = get_mouse_bindcode(name, error);
}
return button;

View file

@ -6,11 +6,14 @@
#include <wayland-server-core.h>
#include <wlr/types/wlr_box.h>
struct cg_input_manager *input_manager_create(struct cg_server *server);
struct cg_input_config *input_device_get_config(struct cg_input_device *device);
void input_manager_handle_device_destroy(struct wl_listener *listener, void *data);
uint32_t input_manager_get_mouse_button(const char *name, char **error);
struct cg_input_manager *
input_manager_create(struct cg_server *server);
struct cg_input_config *
input_device_get_config(struct cg_input_device *device);
void
input_manager_handle_device_destroy(struct wl_listener *listener, void *data);
uint32_t
input_manager_get_mouse_button(const char *name, char **error);
struct cg_input_manager {
struct wl_list devices;
@ -24,7 +27,6 @@ struct cg_input_manager {
struct wl_listener virtual_pointer_new;
};
struct cg_input_config_mapped_from_region {
double x1, y1;
double x2, y2;
@ -67,7 +69,7 @@ struct cg_input_config {
int tap;
int tap_button_map;
/* char *xkb_layout;
/*char *xkb_layout;
char *xkb_model;
char *xkb_options;
char *xkb_rules;
@ -100,7 +102,8 @@ struct cg_input_device {
struct wl_listener device_destroy;
bool is_virtual;
/* Only one of the following is non-NULL depending on the type of the input device */
/* Only one of the following is non-NULL depending on the type of the input
* device */
struct cg_pointer *pointer;
struct cg_touch *touch;
};

View file

@ -9,11 +9,11 @@
#include <wlr/types/wlr_output_layout.h>
#include <wlr/util/log.h>
#include "input.h"
#include "input_manager.h"
#include "keybinding.h"
#include "message.h"
#include "output.h"
#include "input.h"
#include "input_manager.h"
#include "seat.h"
#include "server.h"
#include "view.h"
@ -884,14 +884,13 @@ keybinding_configure_output(struct cg_server *server,
void
keybinding_configure_input(struct cg_server *server,
struct cg_input_config *cfg) {
cg_input_apply_config(cfg,server);
struct cg_input_config *cfg) {
cg_input_apply_config(cfg, server);
}
void
keybinding_configure_input_dev(struct cg_server *server, struct cg_input_config *cfg) {
}
keybinding_configure_input_dev(struct cg_server *server,
struct cg_input_config *cfg) {}
/* Hint: see keybinding.h for details on "data" */
int

View file

@ -4,8 +4,8 @@
#include "config.h"
#include <stdint.h>
#include <stdbool.h>
#include <stdint.h>
#include <xkbcommon/xkbcommon.h>
struct cg_server;
@ -25,7 +25,7 @@ enum keybinding_action {
KEYBINDING_CYCLE_OUTPUT, // data.b is 0 if forward, 1 if reverse
KEYBINDING_CONFIGURE_OUTPUT, // data.o_cfg is the desired output
// configuration
KEYBINDING_CONFIGURE_INPUT, // data.i_cfg is the desired input
KEYBINDING_CONFIGURE_INPUT, // data.i_cfg is the desired input
// configuration
KEYBINDING_QUIT,
KEYBINDING_NOOP,

View file

@ -1,23 +1,25 @@
#include "input.h"
#include "input_manager.h"
#include "output.h"
#include <float.h>
#include <libinput.h>
#include <libudev.h>
#include <limits.h>
#include <strings.h>
#include <wlr/backend/libinput.h>
#include <wlr/util/log.h>
#include <strings.h>
#include "input.h"
#include "output.h"
#include "input_manager.h"
static void log_status(enum libinput_config_status status) {
if (status != LIBINPUT_CONFIG_STATUS_SUCCESS) {
static void
log_status(enum libinput_config_status status) {
if(status != LIBINPUT_CONFIG_STATUS_SUCCESS) {
wlr_log(WLR_ERROR, "Failed to apply libinput config: %s",
libinput_config_status_to_str(status));
libinput_config_status_to_str(status));
}
}
static bool set_send_events(struct libinput_device *device, uint32_t mode) {
if (libinput_device_config_send_events_get_mode(device) == mode) {
static bool
set_send_events(struct libinput_device *device, uint32_t mode) {
if(libinput_device_config_send_events_get_mode(device) == mode) {
return false;
}
wlr_log(WLR_DEBUG, "send_events_set_mode(%" PRIu32 ")", mode);
@ -25,10 +27,10 @@ static bool set_send_events(struct libinput_device *device, uint32_t mode) {
return true;
}
static bool set_tap(struct libinput_device *device,
enum libinput_config_tap_state tap) {
if (libinput_device_config_tap_get_finger_count(device) <= 0 ||
libinput_device_config_tap_get_enabled(device) == tap) {
static bool
set_tap(struct libinput_device *device, enum libinput_config_tap_state tap) {
if(libinput_device_config_tap_get_finger_count(device) <= 0 ||
libinput_device_config_tap_get_enabled(device) == tap) {
return false;
}
wlr_log(WLR_DEBUG, "tap_set_enabled(%d)", tap);
@ -36,10 +38,11 @@ static bool set_tap(struct libinput_device *device,
return true;
}
static bool set_tap_button_map(struct libinput_device *device,
enum libinput_config_tap_button_map map) {
if (libinput_device_config_tap_get_finger_count(device) <= 0 ||
libinput_device_config_tap_get_button_map(device) == map) {
static bool
set_tap_button_map(struct libinput_device *device,
enum libinput_config_tap_button_map map) {
if(libinput_device_config_tap_get_finger_count(device) <= 0 ||
libinput_device_config_tap_get_button_map(device) == map) {
return false;
}
wlr_log(WLR_DEBUG, "tap_set_button_map(%d)", map);
@ -47,10 +50,11 @@ static bool set_tap_button_map(struct libinput_device *device,
return true;
}
static bool set_tap_drag(struct libinput_device *device,
enum libinput_config_drag_state drag) {
if (libinput_device_config_tap_get_finger_count(device) <= 0 ||
libinput_device_config_tap_get_drag_enabled(device) == drag) {
static bool
set_tap_drag(struct libinput_device *device,
enum libinput_config_drag_state drag) {
if(libinput_device_config_tap_get_finger_count(device) <= 0 ||
libinput_device_config_tap_get_drag_enabled(device) == drag) {
return false;
}
wlr_log(WLR_DEBUG, "tap_set_drag_enabled(%d)", drag);
@ -58,10 +62,11 @@ static bool set_tap_drag(struct libinput_device *device,
return true;
}
static bool set_tap_drag_lock(struct libinput_device *device,
enum libinput_config_drag_lock_state lock) {
if (libinput_device_config_tap_get_finger_count(device) <= 0 ||
libinput_device_config_tap_get_drag_lock_enabled(device) == lock) {
static bool
set_tap_drag_lock(struct libinput_device *device,
enum libinput_config_drag_lock_state lock) {
if(libinput_device_config_tap_get_finger_count(device) <= 0 ||
libinput_device_config_tap_get_drag_lock_enabled(device) == lock) {
return false;
}
wlr_log(WLR_DEBUG, "tap_set_drag_lock_enabled(%d)", lock);
@ -69,9 +74,10 @@ static bool set_tap_drag_lock(struct libinput_device *device,
return true;
}
static bool set_accel_speed(struct libinput_device *device, double speed) {
if (!libinput_device_config_accel_is_available(device) ||
libinput_device_config_accel_get_speed(device) == speed) {
static bool
set_accel_speed(struct libinput_device *device, double speed) {
if(!libinput_device_config_accel_is_available(device) ||
libinput_device_config_accel_get_speed(device) == speed) {
return false;
}
wlr_log(WLR_DEBUG, "accel_set_speed(%f)", speed);
@ -79,10 +85,11 @@ static bool set_accel_speed(struct libinput_device *device, double speed) {
return true;
}
static bool set_accel_profile(struct libinput_device *device,
enum libinput_config_accel_profile profile) {
if (!libinput_device_config_accel_is_available(device) ||
libinput_device_config_accel_get_profile(device) == profile) {
static bool
set_accel_profile(struct libinput_device *device,
enum libinput_config_accel_profile profile) {
if(!libinput_device_config_accel_is_available(device) ||
libinput_device_config_accel_get_profile(device) == profile) {
return false;
}
wlr_log(WLR_DEBUG, "accel_set_profile(%d)", profile);
@ -90,9 +97,10 @@ static bool set_accel_profile(struct libinput_device *device,
return true;
}
static bool set_natural_scroll(struct libinput_device *d, bool n) {
if (!libinput_device_config_scroll_has_natural_scroll(d) ||
libinput_device_config_scroll_get_natural_scroll_enabled(d) == n) {
static bool
set_natural_scroll(struct libinput_device *d, bool n) {
if(!libinput_device_config_scroll_has_natural_scroll(d) ||
libinput_device_config_scroll_get_natural_scroll_enabled(d) == n) {
return false;
}
wlr_log(WLR_DEBUG, "scroll_set_natural_scroll(%d)", n);
@ -100,9 +108,10 @@ static bool set_natural_scroll(struct libinput_device *d, bool n) {
return true;
}
static bool set_left_handed(struct libinput_device *device, bool left) {
if (!libinput_device_config_left_handed_is_available(device) ||
libinput_device_config_left_handed_get(device) == left) {
static bool
set_left_handed(struct libinput_device *device, bool left) {
if(!libinput_device_config_left_handed_is_available(device) ||
libinput_device_config_left_handed_get(device) == left) {
return false;
}
wlr_log(WLR_DEBUG, "left_handed_set(%d)", left);
@ -110,11 +119,12 @@ static bool set_left_handed(struct libinput_device *device, bool left) {
return true;
}
static bool set_click_method(struct libinput_device *device,
enum libinput_config_click_method method) {
static bool
set_click_method(struct libinput_device *device,
enum libinput_config_click_method method) {
uint32_t click = libinput_device_config_click_get_methods(device);
if ((click & ~LIBINPUT_CONFIG_CLICK_METHOD_NONE) == 0 ||
libinput_device_config_click_get_method(device) == method) {
if((click & ~LIBINPUT_CONFIG_CLICK_METHOD_NONE) == 0 ||
libinput_device_config_click_get_method(device) == method) {
return false;
}
wlr_log(WLR_DEBUG, "click_set_method(%d)", method);
@ -122,10 +132,11 @@ static bool set_click_method(struct libinput_device *device,
return true;
}
static bool set_middle_emulation(struct libinput_device *dev,
enum libinput_config_middle_emulation_state mid) {
if (!libinput_device_config_middle_emulation_is_available(dev) ||
libinput_device_config_middle_emulation_get_enabled(dev) == mid) {
static bool
set_middle_emulation(struct libinput_device *dev,
enum libinput_config_middle_emulation_state mid) {
if(!libinput_device_config_middle_emulation_is_available(dev) ||
libinput_device_config_middle_emulation_get_enabled(dev) == mid) {
return false;
}
wlr_log(WLR_DEBUG, "middle_emulation_set_enabled(%d)", mid);
@ -133,11 +144,12 @@ static bool set_middle_emulation(struct libinput_device *dev,
return true;
}
static bool set_scroll_method(struct libinput_device *device,
enum libinput_config_scroll_method method) {
static bool
set_scroll_method(struct libinput_device *device,
enum libinput_config_scroll_method method) {
uint32_t scroll = libinput_device_config_scroll_get_methods(device);
if ((scroll & ~LIBINPUT_CONFIG_SCROLL_NO_SCROLL) == 0 ||
libinput_device_config_scroll_get_method(device) == method) {
if((scroll & ~LIBINPUT_CONFIG_SCROLL_NO_SCROLL) == 0 ||
libinput_device_config_scroll_get_method(device) == method) {
return false;
}
wlr_log(WLR_DEBUG, "scroll_set_method(%d)", method);
@ -145,10 +157,11 @@ static bool set_scroll_method(struct libinput_device *device,
return true;
}
static bool set_scroll_button(struct libinput_device *dev, uint32_t button) {
static bool
set_scroll_button(struct libinput_device *dev, uint32_t button) {
uint32_t scroll = libinput_device_config_scroll_get_methods(dev);
if ((scroll & ~LIBINPUT_CONFIG_SCROLL_NO_SCROLL) == 0 ||
libinput_device_config_scroll_get_button(dev) == button) {
if((scroll & ~LIBINPUT_CONFIG_SCROLL_NO_SCROLL) == 0 ||
libinput_device_config_scroll_get_button(dev) == button) {
return false;
}
wlr_log(WLR_DEBUG, "scroll_set_button(%" PRIu32 ")", button);
@ -156,9 +169,10 @@ static bool set_scroll_button(struct libinput_device *dev, uint32_t button) {
return true;
}
static bool set_dwt(struct libinput_device *device, bool dwt) {
if (!libinput_device_config_dwt_is_available(device) ||
libinput_device_config_dwt_get_enabled(device) == dwt) {
static bool
set_dwt(struct libinput_device *device, bool dwt) {
if(!libinput_device_config_dwt_is_available(device) ||
libinput_device_config_dwt_get_enabled(device) == dwt) {
return false;
}
wlr_log(WLR_DEBUG, "dwt_set_enabled(%d)", dwt);
@ -166,63 +180,67 @@ static bool set_dwt(struct libinput_device *device, bool dwt) {
return true;
}
static bool set_calibration_matrix(struct libinput_device *dev, float mat[6]) {
if (!libinput_device_config_calibration_has_matrix(dev)) {
static bool
set_calibration_matrix(struct libinput_device *dev, float mat[6]) {
if(!libinput_device_config_calibration_has_matrix(dev)) {
return false;
}
bool changed = false;
float current[6];
libinput_device_config_calibration_get_matrix(dev, current);
for (int i = 0; i < 6; i++) {
if (current[i] != mat[i]) {
for(int i = 0; i < 6; i++) {
if(current[i] != mat[i]) {
changed = true;
break;
}
}
if (changed) {
if(changed) {
wlr_log(WLR_DEBUG, "calibration_set_matrix(%f, %f, %f, %f, %f, %f)",
mat[0], mat[1], mat[2], mat[3], mat[4], mat[5]);
mat[0], mat[1], mat[2], mat[3], mat[4], mat[5]);
log_status(libinput_device_config_calibration_set_matrix(dev, mat));
}
return changed;
}
void output_get_identifier(char *identifier, size_t len,
struct cg_output *output) {
void
output_get_identifier(char *identifier, size_t len, struct cg_output *output) {
struct wlr_output *wlr_output = output->wlr_output;
snprintf(identifier, len, "%s %s %s", wlr_output->make, wlr_output->model,
wlr_output->serial);
wlr_output->serial);
}
struct cg_output *output_by_name_or_id(const char *name_or_id, struct cg_server *server) {
struct cg_output *output=NULL;
wl_list_for_each(output,&server->outputs,link) {
struct cg_output *
output_by_name_or_id(const char *name_or_id, struct cg_server *server) {
struct cg_output *output = NULL;
wl_list_for_each(output, &server->outputs, link) {
char identifier[128];
output_get_identifier(identifier, sizeof(identifier), output);
if (strcasecmp(identifier, name_or_id) == 0
|| strcasecmp(output->wlr_output->name, name_or_id) == 0) {
if(strcasecmp(identifier, name_or_id) == 0 ||
strcasecmp(output->wlr_output->name, name_or_id) == 0) {
return output;
}
}
return NULL;
}
static bool device_is_touchpad(struct cg_input_device *device) {
if (device->wlr_device->type != WLR_INPUT_DEVICE_POINTER ||
!wlr_input_device_is_libinput(device->wlr_device)) {
static bool
device_is_touchpad(struct cg_input_device *device) {
if(device->wlr_device->type != WLR_INPUT_DEVICE_POINTER ||
!wlr_input_device_is_libinput(device->wlr_device)) {
return false;
}
struct libinput_device *libinput_device =
wlr_libinput_get_device_handle(device->wlr_device);
wlr_libinput_get_device_handle(device->wlr_device);
return libinput_device_config_tap_get_finger_count(libinput_device) > 0;
}
const char *input_device_get_type(struct cg_input_device *device) {
switch (device->wlr_device->type) {
const char *
input_device_get_type(struct cg_input_device *device) {
switch(device->wlr_device->type) {
case WLR_INPUT_DEVICE_POINTER:
if (device_is_touchpad(device)) {
if(device_is_touchpad(device)) {
return "touchpad";
} else {
return "pointer";
@ -241,167 +259,181 @@ const char *input_device_get_type(struct cg_input_device *device) {
return "unknown";
}
void apply_config_to_device(struct cg_input_config *config, struct cg_input_device *input_device) {
if (!wlr_input_device_is_libinput(input_device->wlr_device)) {
void
apply_config_to_device(struct cg_input_config *config,
struct cg_input_device *input_device) {
if(!wlr_input_device_is_libinput(input_device->wlr_device)) {
return;
}
struct libinput_device *device =
wlr_libinput_get_device_handle(input_device->wlr_device);
if (config->mapped_to_output &&
!output_by_name_or_id(config->mapped_to_output,input_device->server)) {
wlr_libinput_get_device_handle(input_device->wlr_device);
if(config->mapped_to_output &&
!output_by_name_or_id(config->mapped_to_output, input_device->server)) {
wlr_log(WLR_DEBUG,
"'%s' is mapped to offline output '%s'; disabling input",
config->identifier, config->mapped_to_output);
set_send_events(device,
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
} else if (config->send_events != INT_MIN) {
"'%s' is mapped to offline output '%s'; disabling input",
config->identifier, config->mapped_to_output);
set_send_events(device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
} else if(config->send_events != INT_MIN) {
set_send_events(device, config->send_events);
} else {
// Have to reset to the default mode here, otherwise if ic->send_events
// is unset and a mapped output just came online after being disabled,
// we'd remain stuck sending no events.
set_send_events(device,
libinput_device_config_send_events_get_default_mode(device));
set_send_events(
device,
libinput_device_config_send_events_get_default_mode(device));
}
if (config->tap != INT_MIN) {
if(config->tap != INT_MIN) {
set_tap(device, config->tap);
}
if (config->tap_button_map != INT_MIN) {
if(config->tap_button_map != INT_MIN) {
set_tap_button_map(device, config->tap_button_map);
}
if (config->drag != INT_MIN) {
if(config->drag != INT_MIN) {
set_tap_drag(device, config->drag);
}
if (config->drag_lock != INT_MIN) {
if(config->drag_lock != INT_MIN) {
set_tap_drag_lock(device, config->drag_lock);
}
if (config->pointer_accel != FLT_MIN) {
if(config->pointer_accel != FLT_MIN) {
set_accel_speed(device, config->pointer_accel);
}
if (config->accel_profile != INT_MIN) {
if(config->accel_profile != INT_MIN) {
set_accel_profile(device, config->accel_profile);
}
if (config->natural_scroll != INT_MIN) {
if(config->natural_scroll != INT_MIN) {
set_natural_scroll(device, config->natural_scroll);
}
if (config->left_handed != INT_MIN) {
if(config->left_handed != INT_MIN) {
set_left_handed(device, config->left_handed);
}
if (config->click_method != INT_MIN) {
if(config->click_method != INT_MIN) {
set_click_method(device, config->click_method);
}
if (config->middle_emulation != INT_MIN) {
if(config->middle_emulation != INT_MIN) {
set_middle_emulation(device, config->middle_emulation);
}
if (config->scroll_method != INT_MIN) {
if(config->scroll_method != INT_MIN) {
set_scroll_method(device, config->scroll_method);
}
if (config->scroll_button != INT_MIN) {
if(config->scroll_button != INT_MIN) {
set_scroll_button(device, config->scroll_button);
}
if (config->dwt != INT_MIN) {
if(config->dwt != INT_MIN) {
set_dwt(device, config->dwt);
}
if (config->calibration_matrix.configured) {
if(config->calibration_matrix.configured) {
set_calibration_matrix(device, config->calibration_matrix.matrix);
}
}
void cg_input_apply_config(struct cg_input_config *config, struct cg_server *server) {
struct cg_input_device *device=NULL;
wl_list_for_each(device,&server->input->devices,link) {
if (strcmp(config->identifier, device->identifier) != 0&&strcmp(config->identifier, "*") != 0) {
void
cg_input_apply_config(struct cg_input_config *config,
struct cg_server *server) {
struct cg_input_device *device = NULL;
wl_list_for_each(device, &server->input->devices, link) {
if(strcmp(config->identifier, device->identifier) != 0 &&
strcmp(config->identifier, "*") != 0) {
continue;
}
const char *device_type = input_device_get_type(device);
if (strncmp(config->identifier,"type:",5)==0&&strcmp(config->identifier + 5, device_type) != 0) {
if(strncmp(config->identifier, "type:", 5) == 0 &&
strcmp(config->identifier + 5, device_type) != 0) {
continue;
}
apply_config_to_device(config,device);
apply_config_to_device(config, device);
}
}
void cg_input_configure_libinput_device(struct cg_input_device *input_device) {
struct cg_server *server=input_device->server;
void
cg_input_configure_libinput_device(struct cg_input_device *input_device) {
struct cg_server *server = input_device->server;
struct cg_input_config *config = NULL;
wl_list_for_each(config, &server->input_config, link) {
if (strcmp(config->identifier, input_device->identifier) != 0&&strcmp(config->identifier, "*") != 0) {
if(strcmp(config->identifier, input_device->identifier) != 0 &&
strcmp(config->identifier, "*") != 0) {
continue;
}
const char *device_type = input_device_get_type(input_device);
if (!(strncmp(config->identifier,"type:",5)&&strcmp(config->identifier + 5, device_type) == 0)) {
if(!(strncmp(config->identifier, "type:", 5) &&
strcmp(config->identifier + 5, device_type) == 0)) {
continue;
}
apply_config_to_device(config,input_device);
apply_config_to_device(config, input_device);
}
}
void cg_input_reset_libinput_device(struct cg_input_device *input_device) {
if (!wlr_input_device_is_libinput(input_device->wlr_device)) {
void
cg_input_reset_libinput_device(struct cg_input_device *input_device) {
if(!wlr_input_device_is_libinput(input_device->wlr_device)) {
return;
}
struct libinput_device *device =
wlr_libinput_get_device_handle(input_device->wlr_device);
wlr_libinput_get_device_handle(input_device->wlr_device);
wlr_log(WLR_DEBUG, "cg_input_reset_libinput_device(%s)",
input_device->identifier);
input_device->identifier);
bool changed = false;
changed |= set_send_events(device,
libinput_device_config_send_events_get_default_mode(device));
changed |= set_tap(device,
libinput_device_config_tap_get_default_enabled(device));
changed |= set_tap_button_map(device,
libinput_device_config_tap_get_default_button_map(device));
changed |= set_tap_drag(device,
libinput_device_config_tap_get_default_drag_enabled(device));
changed |= set_tap_drag_lock(device,
libinput_device_config_tap_get_default_drag_lock_enabled(device));
changed |= set_accel_speed(device,
libinput_device_config_accel_get_default_speed(device));
changed |= set_accel_profile(device,
libinput_device_config_accel_get_default_profile(device));
changed |= set_natural_scroll(device,
libinput_device_config_scroll_get_default_natural_scroll_enabled(
device));
changed |= set_left_handed(device,
libinput_device_config_left_handed_get_default(device));
changed |= set_click_method(device,
libinput_device_config_click_get_default_method(device));
changed |= set_middle_emulation(device,
libinput_device_config_middle_emulation_get_default_enabled(device));
changed |= set_scroll_method(device,
libinput_device_config_scroll_get_default_method(device));
changed |= set_scroll_button(device,
libinput_device_config_scroll_get_default_button(device));
changed |= set_dwt(device,
libinput_device_config_dwt_get_default_enabled(device));
changed |= set_send_events(
device, libinput_device_config_send_events_get_default_mode(device));
changed |=
set_tap(device, libinput_device_config_tap_get_default_enabled(device));
changed |= set_tap_button_map(
device, libinput_device_config_tap_get_default_button_map(device));
changed |= set_tap_drag(
device, libinput_device_config_tap_get_default_drag_enabled(device));
changed |= set_tap_drag_lock(
device,
libinput_device_config_tap_get_default_drag_lock_enabled(device));
changed |= set_accel_speed(
device, libinput_device_config_accel_get_default_speed(device));
changed |= set_accel_profile(
device, libinput_device_config_accel_get_default_profile(device));
changed |= set_natural_scroll(
device,
libinput_device_config_scroll_get_default_natural_scroll_enabled(
device));
changed |= set_left_handed(
device, libinput_device_config_left_handed_get_default(device));
changed |= set_click_method(
device, libinput_device_config_click_get_default_method(device));
changed |= set_middle_emulation(
device,
libinput_device_config_middle_emulation_get_default_enabled(device));
changed |= set_scroll_method(
device, libinput_device_config_scroll_get_default_method(device));
changed |= set_scroll_button(
device, libinput_device_config_scroll_get_default_button(device));
changed |=
set_dwt(device, libinput_device_config_dwt_get_default_enabled(device));
float matrix[6];
libinput_device_config_calibration_get_default_matrix(device, matrix);
changed |= set_calibration_matrix(device, matrix);
}
bool cg_libinput_device_is_builtin(struct cg_input_device *cg_device) {
if (!wlr_input_device_is_libinput(cg_device->wlr_device)) {
bool
cg_libinput_device_is_builtin(struct cg_input_device *cg_device) {
if(!wlr_input_device_is_libinput(cg_device->wlr_device)) {
return false;
}
struct libinput_device *device =
wlr_libinput_get_device_handle(cg_device->wlr_device);
struct udev_device *udev_device =
libinput_device_get_udev_device(device);
if (!udev_device) {
wlr_libinput_get_device_handle(cg_device->wlr_device);
struct udev_device *udev_device = libinput_device_get_udev_device(device);
if(!udev_device) {
return false;
}
const char *id_path = udev_device_get_property_value(udev_device, "ID_PATH");
if (!id_path) {
const char *id_path =
udev_device_get_property_value(udev_device, "ID_PATH");
if(!id_path) {
return false;
}

255
parse.c
View file

@ -1,14 +1,14 @@
#define _POSIX_C_SOURCE 200812L
#include <limits.h>
#include <float.h>
#include <libinput.h>
#include <limits.h>
#include <string.h>
#include <wlr/util/log.h>
#include <libinput.h>
#include "input_manager.h"
#include "keybinding.h"
#include "output.h"
#include "input_manager.h"
#include "parse.h"
#include "server.h"
@ -117,7 +117,7 @@ parse_float(char **saveptr, const char *delim) {
return -1;
}
float ufloat = strtof(uint_str, NULL);
if(ufloat != NAN && ufloat != INFINITY && errno!=ERANGE) {
if(ufloat != NAN && ufloat != INFINITY && errno != ERANGE) {
return ufloat;
} else {
wlr_log(WLR_ERROR, "Error parsing float");
@ -127,8 +127,8 @@ parse_float(char **saveptr, const char *delim) {
struct cg_input_config *
parse_input_config(char **saveptr, char **errstr) {
struct cg_input_config *cfg = calloc(1,sizeof(struct cg_input_config));
char *value=NULL;
struct cg_input_config *cfg = calloc(1, sizeof(struct cg_input_config));
char *value = NULL;
char *ident = NULL;
if(cfg == NULL) {
*errstr =
@ -161,10 +161,11 @@ parse_input_config(char **saveptr, char **errstr) {
ident = strtok_r(NULL, " ", saveptr);
if(ident == NULL) {
*errstr = log_error("Expected identifier of input device to configure, got none");
*errstr = log_error(
"Expected identifier of input device to configure, got none");
goto error;
}
cfg->identifier=strdup(ident);
cfg->identifier = strdup(ident);
char *setting = strtok_r(NULL, " ", saveptr);
if(setting == NULL) {
@ -176,154 +177,177 @@ parse_input_config(char **saveptr, char **errstr) {
value = strdup(*saveptr);
if(value == NULL) {
*errstr =
log_error("Failed to obtain value for input device configuration of device \"%s\"",ident);
*errstr = log_error("Failed to obtain value for input device "
"configuration of device \"%s\"",
ident);
goto error;
}
if(strcmp(setting,"accel_profile") == 0) {
if(strcmp(value,"adaptive") == 0) {
cfg->accel_profile=LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE;
} else if(strcmp(value,"flat") == 0) {
cfg->accel_profile=LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT;
if(strcmp(setting, "accel_profile") == 0) {
if(strcmp(value, "adaptive") == 0) {
cfg->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE;
} else if(strcmp(value, "flat") == 0) {
cfg->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT;
} else {
*errstr = log_error("Invalid profile \"%s\" for accel_profile configuration", value);
*errstr = log_error(
"Invalid profile \"%s\" for accel_profile configuration",
value);
goto error;
}
} else if(strcmp(setting,"calibration_matrix") == 0) {
cfg->calibration_matrix.configured=true;
for(int i=0;i<6;++i) {
cfg->calibration_matrix.matrix[i]=parse_float(saveptr," ");
if(cfg->calibration_matrix.matrix[i]==FLT_MIN) {
*errstr = log_error("Failed to read calibration matrix, expected 6 floating point values separated by spaces");
goto error;
}
} else if(strcmp(setting, "calibration_matrix") == 0) {
cfg->calibration_matrix.configured = true;
for(int i = 0; i < 6; ++i) {
cfg->calibration_matrix.matrix[i] = parse_float(saveptr, " ");
if(cfg->calibration_matrix.matrix[i] == FLT_MIN) {
*errstr =
log_error("Failed to read calibration matrix, expected 6 "
"floating point values separated by spaces");
goto error;
}
}
} else if(strcmp(setting,"click_method") == 0) {
if(strcmp(value,"none")) {
cfg->click_method=LIBINPUT_CONFIG_CLICK_METHOD_NONE;
} else if(strcmp(value,"button_areas")) {
cfg->click_method=LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;
} else if(strcmp(value,"clickfinger")) {
cfg->click_method=LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;
} else if(strcmp(setting, "click_method") == 0) {
if(strcmp(value, "none")) {
cfg->click_method = LIBINPUT_CONFIG_CLICK_METHOD_NONE;
} else if(strcmp(value, "button_areas")) {
cfg->click_method = LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;
} else if(strcmp(value, "clickfinger")) {
cfg->click_method = LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;
} else {
*errstr = log_error("Invalid method \"%s\" for click_method configuration", value);
*errstr = log_error(
"Invalid method \"%s\" for click_method configuration", value);
goto error;
}
} else if(strcmp(setting,"drag") == 0) {
if(strcmp(value,"enabled") == 0) {
cfg->drag=LIBINPUT_CONFIG_DRAG_ENABLED;
} else if(strcmp(value,"disabled") == 0) {
cfg->drag=LIBINPUT_CONFIG_DRAG_DISABLED;
} else if(strcmp(setting, "drag") == 0) {
if(strcmp(value, "enabled") == 0) {
cfg->drag = LIBINPUT_CONFIG_DRAG_ENABLED;
} else if(strcmp(value, "disabled") == 0) {
cfg->drag = LIBINPUT_CONFIG_DRAG_DISABLED;
} else {
*errstr = log_error("Invalid option \"%s\" to setting \"drag\"", value);
*errstr =
log_error("Invalid option \"%s\" to setting \"drag\"", value);
goto error;
}
} else if(strcmp(setting,"drag_lock") == 0) {
if(strcmp(value,"enabled") == 0) {
cfg->drag_lock=LIBINPUT_CONFIG_DRAG_LOCK_ENABLED;
} else if(strcmp(value,"disabled") == 0) {
cfg->drag_lock=LIBINPUT_CONFIG_DRAG_LOCK_DISABLED;
} else if(strcmp(setting, "drag_lock") == 0) {
if(strcmp(value, "enabled") == 0) {
cfg->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_ENABLED;
} else if(strcmp(value, "disabled") == 0) {
cfg->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_DISABLED;
} else {
*errstr = log_error("Invalid option \"%s\" to setting \"drag_lock\"", value);
*errstr = log_error(
"Invalid option \"%s\" to setting \"drag_lock\"", value);
goto error;
}
} else if(strcmp(setting,"dwt") == 0) {
if(strcmp(value,"enabled") == 0) {
cfg->dwt=LIBINPUT_CONFIG_DWT_ENABLED;
} else if(strcmp(value,"disabled") == 0) {
cfg->dwt=LIBINPUT_CONFIG_DWT_DISABLED;
} else if(strcmp(setting, "dwt") == 0) {
if(strcmp(value, "enabled") == 0) {
cfg->dwt = LIBINPUT_CONFIG_DWT_ENABLED;
} else if(strcmp(value, "disabled") == 0) {
cfg->dwt = LIBINPUT_CONFIG_DWT_DISABLED;
} else {
*errstr = log_error("Invalid option \"%s\" to setting \"dwt\"", value);
*errstr =
log_error("Invalid option \"%s\" to setting \"dwt\"", value);
goto error;
}
} else if(strcmp(setting,"events") == 0) {
if(strcmp(value,"enabled") == 0) {
cfg->send_events=LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
} else if(strcmp(value,"disabled") == 0) {
cfg->send_events=LIBINPUT_CONFIG_SEND_EVENTS_DISABLED;
} else if(strcmp(value,"disabled_on_external_mouse") == 0) {
cfg->send_events=LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE;
} else if(strcmp(setting, "events") == 0) {
if(strcmp(value, "enabled") == 0) {
cfg->send_events = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
} else if(strcmp(value, "disabled") == 0) {
cfg->send_events = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED;
} else if(strcmp(value, "disabled_on_external_mouse") == 0) {
cfg->send_events =
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE;
} else {
*errstr = log_error("Invalid option \"%s\" to setting \"events\"", value);
*errstr =
log_error("Invalid option \"%s\" to setting \"events\"", value);
goto error;
}
} else if(strcmp(setting,"left_handed") == 0) {
if(strcmp(value,"enabled") == 0) {
cfg->left_handed=true;
} else if(strcmp(value,"disabled") == 0) {
cfg->left_handed=false;
} else if(strcmp(setting, "left_handed") == 0) {
if(strcmp(value, "enabled") == 0) {
cfg->left_handed = true;
} else if(strcmp(value, "disabled") == 0) {
cfg->left_handed = false;
} else {
*errstr = log_error("Invalid option \"%s\" to setting \"left_handed\"", value);
*errstr = log_error(
"Invalid option \"%s\" to setting \"left_handed\"", value);
goto error;
}
} else if(strcmp(setting,"middle_emulation") == 0) {
if(strcmp(value,"enabled") == 0) {
cfg->middle_emulation=LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED;
} else if(strcmp(value,"disabled") == 0) {
cfg->middle_emulation=LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED;
} else if(strcmp(setting, "middle_emulation") == 0) {
if(strcmp(value, "enabled") == 0) {
cfg->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED;
} else if(strcmp(value, "disabled") == 0) {
cfg->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED;
} else {
*errstr = log_error("Invalid option \"%s\" to setting \"middle_emulation\"", value);
*errstr = log_error(
"Invalid option \"%s\" to setting \"middle_emulation\"", value);
goto error;
}
} else if(strcmp(setting,"natural_scroll") == 0) {
if(strcmp(value,"enabled") == 0) {
cfg->natural_scroll=true;
} else if(strcmp(value,"disabled") == 0) {
cfg->natural_scroll=false;
} else if(strcmp(setting, "natural_scroll") == 0) {
if(strcmp(value, "enabled") == 0) {
cfg->natural_scroll = true;
} else if(strcmp(value, "disabled") == 0) {
cfg->natural_scroll = false;
} else {
*errstr = log_error("Invalid option \"%s\" to setting \"natural_scroll\"", value);
*errstr = log_error(
"Invalid option \"%s\" to setting \"natural_scroll\"", value);
goto error;
}
} else if(strcmp(setting,"pointer_accel") == 0) {
cfg->pointer_accel=parse_float(saveptr, " ");
if(cfg->pointer_accel==FLT_MIN) {
*errstr = log_error("Invalid option \"%s\" to setting \"pointer_accel\", expected float value", value);
} else if(strcmp(setting, "pointer_accel") == 0) {
cfg->pointer_accel = parse_float(saveptr, " ");
if(cfg->pointer_accel == FLT_MIN) {
*errstr = log_error("Invalid option \"%s\" to setting "
"\"pointer_accel\", expected float value",
value);
goto error;
}
} else if(strcmp(setting,"scroll_button") == 0) {
char *err=NULL;
cfg->scroll_button=input_manager_get_mouse_button(value,&err);
} else if(strcmp(setting, "scroll_button") == 0) {
char *err = NULL;
cfg->scroll_button = input_manager_get_mouse_button(value, &err);
if(err) {
*errstr = log_error("Error parsing button for \"scroll_button\" setting. Returned error \"%s\"", err);
*errstr = log_error("Error parsing button for \"scroll_button\" "
"setting. Returned error \"%s\"",
err);
free(err);
goto error;
}
} else if(strcmp(setting,"scroll_factor") == 0) {
cfg->scroll_factor=parse_float(saveptr, " ");
if(cfg->scroll_factor==FLT_MIN) {
*errstr = log_error("Invalid option \"%s\" to setting \"scroll_factor\", expected float value", value);
} else if(strcmp(setting, "scroll_factor") == 0) {
cfg->scroll_factor = parse_float(saveptr, " ");
if(cfg->scroll_factor == FLT_MIN) {
*errstr = log_error("Invalid option \"%s\" to setting "
"\"scroll_factor\", expected float value",
value);
goto error;
}
} else if(strcmp(setting,"scroll_method") == 0) {
if(strcmp(value,"none") == 0) {
cfg->scroll_method=LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
} else if(strcmp(value,"two_finger") == 0) {
cfg->scroll_method=LIBINPUT_CONFIG_SCROLL_2FG;
} else if(strcmp(value,"edge") == 0) {
cfg->scroll_method=LIBINPUT_CONFIG_SCROLL_EDGE;
} else if(strcmp(value,"on_button_down") == 0) {
cfg->scroll_method=LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
} else if(strcmp(setting, "scroll_method") == 0) {
if(strcmp(value, "none") == 0) {
cfg->scroll_method = LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
} else if(strcmp(value, "two_finger") == 0) {
cfg->scroll_method = LIBINPUT_CONFIG_SCROLL_2FG;
} else if(strcmp(value, "edge") == 0) {
cfg->scroll_method = LIBINPUT_CONFIG_SCROLL_EDGE;
} else if(strcmp(value, "on_button_down") == 0) {
cfg->scroll_method = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
} else {
*errstr = log_error("Invalid option \"%s\" to setting \"scroll_method\"", value);
*errstr = log_error(
"Invalid option \"%s\" to setting \"scroll_method\"", value);
goto error;
}
} else if(strcmp(setting,"tap") == 0) {
if(strcmp(value,"enabled") == 0) {
cfg->tap=LIBINPUT_CONFIG_TAP_ENABLED;
} else if(strcmp(value,"disabled") == 0) {
cfg->tap=LIBINPUT_CONFIG_TAP_DISABLED;
} else if(strcmp(setting, "tap") == 0) {
if(strcmp(value, "enabled") == 0) {
cfg->tap = LIBINPUT_CONFIG_TAP_ENABLED;
} else if(strcmp(value, "disabled") == 0) {
cfg->tap = LIBINPUT_CONFIG_TAP_DISABLED;
} else {
*errstr = log_error("Invalid option \"%s\" to setting \"tap\"", value);
*errstr =
log_error("Invalid option \"%s\" to setting \"tap\"", value);
goto error;
}
} else if(strcmp(setting,"tap_button_map") == 0) {
if(strcmp(value,"lrm") == 0) {
cfg->tap=LIBINPUT_CONFIG_TAP_MAP_LRM;
} else if(strcmp(value,"lmr") == 0) {
cfg->tap=LIBINPUT_CONFIG_TAP_MAP_LMR;
} else if(strcmp(setting, "tap_button_map") == 0) {
if(strcmp(value, "lrm") == 0) {
cfg->tap = LIBINPUT_CONFIG_TAP_MAP_LRM;
} else if(strcmp(value, "lmr") == 0) {
cfg->tap = LIBINPUT_CONFIG_TAP_MAP_LMR;
} else {
*errstr = log_error("Invalid option \"%s\" to setting \"tap_button_map\"", value);
*errstr = log_error(
"Invalid option \"%s\" to setting \"tap_button_map\"", value);
goto error;
}
}
@ -341,8 +365,8 @@ error:
if(value) {
free(value);
}
wlr_log(WLR_ERROR,
"Input configuration must be of the form 'input \"<ident>\" <setting> <value>'");
wlr_log(WLR_ERROR, "Input configuration must be of the form 'input "
"\"<ident>\" <setting> <value>'");
return NULL;
}
@ -575,9 +599,10 @@ parse_output_config(char **saveptr, char **errstr) {
cfg->refresh_rate = parse_float(saveptr, " ");
if(cfg->refresh_rate <= 0.0) {
*errstr = log_error(
"Error parsing refresh rate of output configuration for output %s, expected positive float",
name);
*errstr =
log_error("Error parsing refresh rate of output configuration for "
"output %s, expected positive float",
name);
goto error;
}

41
seat.c
View file

@ -31,8 +31,8 @@
#include <wlr/xwayland.h>
#endif
#include "keybinding.h"
#include "input_manager.h"
#include "keybinding.h"
#include "message.h"
#include "output.h"
#include "seat.h"
@ -113,13 +113,13 @@ static void
update_capabilities(const struct cg_seat *seat) {
uint32_t caps = 0;
if(seat->num_keyboards>0) {
if(seat->num_keyboards > 0) {
caps |= WL_SEAT_CAPABILITY_KEYBOARD;
}
if(seat->num_pointers>0) {
if(seat->num_pointers > 0) {
caps |= WL_SEAT_CAPABILITY_POINTER;
}
if(seat->num_touch>0) {
if(seat->num_touch > 0) {
caps |= WL_SEAT_CAPABILITY_TOUCH;
}
wlr_seat_set_capabilities(seat->seat, caps);
@ -148,7 +148,7 @@ remove_touch(struct cg_seat *seat, struct cg_touch *touch) {
static void
new_touch(struct cg_seat *seat, struct cg_input_device *input_device) {
struct wlr_input_device *device=input_device->wlr_device;
struct wlr_input_device *device = input_device->wlr_device;
struct cg_touch *touch = calloc(1, sizeof(struct cg_touch));
if(!touch) {
wlr_log(WLR_ERROR, "Cannot allocate touch");
@ -158,7 +158,7 @@ new_touch(struct cg_seat *seat, struct cg_input_device *input_device) {
touch->seat = seat;
touch->device = input_device;
wlr_cursor_attach_input_device(seat->cursor, device);
input_device->touch=touch;
input_device->touch = touch;
++seat->num_touch;
if(device->output_name != NULL) {
@ -187,7 +187,7 @@ remove_pointer(struct cg_seat *seat, struct cg_pointer *pointer) {
static void
new_pointer(struct cg_seat *seat, struct cg_input_device *input_device) {
struct wlr_input_device *device=input_device->wlr_device;
struct wlr_input_device *device = input_device->wlr_device;
struct cg_pointer *pointer = calloc(1, sizeof(struct cg_pointer));
if(!pointer) {
wlr_log(WLR_ERROR, "Cannot allocate pointer");
@ -197,7 +197,7 @@ new_pointer(struct cg_seat *seat, struct cg_input_device *input_device) {
pointer->seat = seat;
pointer->device = input_device;
wlr_cursor_attach_input_device(seat->cursor, device);
input_device->pointer=pointer;
input_device->pointer = pointer;
++seat->num_pointers;
if(device->output_name != NULL) {
@ -430,7 +430,7 @@ cleanup:
static void
new_keyboard(struct cg_seat *seat, struct cg_input_device *input_device) {
struct wlr_input_device *device= input_device->wlr_device;
struct wlr_input_device *device = input_device->wlr_device;
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if(!context) {
wlr_log(WLR_ERROR, "Unable to create XKB context");
@ -482,16 +482,17 @@ seat_add_device(struct cg_seat *seat, struct cg_input_device *device) {
update_capabilities(seat);
}
void remove_keyboard(struct cg_seat *seat, struct cg_input_device *keyboard) {
if (!keyboard) {
void
remove_keyboard(struct cg_seat *seat, struct cg_input_device *keyboard) {
if(!keyboard) {
return;
}
struct wlr_seat *wlr_seat = seat->seat;
struct wlr_keyboard *wlr_keyboard = keyboard->wlr_device->keyboard;
if (keyboard->wlr_device->keyboard->group) {
wlr_keyboard_group_remove_keyboard(wlr_keyboard->group,wlr_keyboard);
if(keyboard->wlr_device->keyboard->group) {
wlr_keyboard_group_remove_keyboard(wlr_keyboard->group, wlr_keyboard);
}
if (wlr_seat_get_keyboard(wlr_seat) == wlr_keyboard) {
if(wlr_seat_get_keyboard(wlr_seat) == wlr_keyboard) {
wlr_seat_set_keyboard(wlr_seat, NULL);
}
--seat->num_keyboards;
@ -505,11 +506,11 @@ seat_remove_device(struct cg_seat *seat, struct cg_input_device *device) {
break;
case WLR_INPUT_DEVICE_POINTER:
remove_pointer(seat, device->pointer);
device->pointer=NULL;
device->pointer = NULL;
break;
case WLR_INPUT_DEVICE_TOUCH:
remove_touch(seat, device->touch);
device->touch=NULL;
device->touch = NULL;
break;
case WLR_INPUT_DEVICE_SWITCH:
wlr_log(WLR_DEBUG, "Switch input is not implemented");
@ -836,7 +837,7 @@ handle_destroy(struct wl_listener *listener, void *_data) {
struct cg_input_device *it, *it_tmp;
wl_list_for_each_safe(it, it_tmp, &seat->server->input->devices, link) {
input_manager_handle_device_destroy(&it->device_destroy,NULL);
input_manager_handle_device_destroy(&it->device_destroy, NULL);
}
wlr_xcursor_manager_destroy(seat->xcursor_manager);
@ -926,9 +927,9 @@ seat_create(struct cg_server *server, struct wlr_backend *backend) {
&seat->request_set_primary_selection);
wl_list_init(&seat->keyboard_groups);
seat->num_keyboards=0;
seat->num_pointers=0;
seat->num_touch=0;
seat->num_keyboards = 0;
seat->num_pointers = 0;
seat->num_touch = 0;
wl_list_init(&seat->drag_icons);
seat->request_start_drag.notify = handle_request_start_drag;