2018-08-16 12:22:42 +02:00
|
|
|
#define _POSIX_C_SOURCE 200112L
|
2017-09-23 16:13:05 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
2018-07-29 19:02:00 +02:00
|
|
|
#include <time.h>
|
2017-09-23 16:13:05 +02:00
|
|
|
#include <wayland-server.h>
|
2018-02-12 21:29:23 +01:00
|
|
|
#include <wlr/backend/libinput.h>
|
2018-03-27 09:19:44 +02:00
|
|
|
#include <wlr/config.h>
|
2017-09-23 16:13:05 +02:00
|
|
|
#include <wlr/types/wlr_cursor.h>
|
|
|
|
#include <wlr/util/log.h>
|
|
|
|
#include <wlr/xcursor.h>
|
2018-11-12 10:12:46 +01:00
|
|
|
#if WLR_HAS_XWAYLAND
|
2018-03-27 05:15:21 +02:00
|
|
|
#include <wlr/xwayland.h>
|
2018-03-09 15:17:15 +01:00
|
|
|
#endif
|
2017-09-23 16:13:05 +02:00
|
|
|
#include "rootston/config.h"
|
|
|
|
#include "rootston/input.h"
|
2017-11-03 01:13:10 +01:00
|
|
|
#include "rootston/keyboard.h"
|
2017-11-03 14:01:34 +01:00
|
|
|
#include "rootston/seat.h"
|
2018-02-12 21:29:23 +01:00
|
|
|
#include "rootston/server.h"
|
2017-09-23 16:13:05 +02:00
|
|
|
|
|
|
|
static const char *device_type(enum wlr_input_device_type type) {
|
|
|
|
switch (type) {
|
|
|
|
case WLR_INPUT_DEVICE_KEYBOARD:
|
|
|
|
return "keyboard";
|
|
|
|
case WLR_INPUT_DEVICE_POINTER:
|
|
|
|
return "pointer";
|
2018-11-15 00:24:55 +01:00
|
|
|
case WLR_INPUT_DEVICE_SWITCH:
|
|
|
|
return "switch";
|
2017-09-23 16:13:05 +02:00
|
|
|
case WLR_INPUT_DEVICE_TOUCH:
|
|
|
|
return "touch";
|
|
|
|
case WLR_INPUT_DEVICE_TABLET_TOOL:
|
|
|
|
return "tablet tool";
|
|
|
|
case WLR_INPUT_DEVICE_TABLET_PAD:
|
|
|
|
return "tablet pad";
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-11-22 14:10:06 +01:00
|
|
|
struct roots_seat *input_get_seat(struct roots_input *input, char *name) {
|
2017-11-03 14:01:34 +01:00
|
|
|
struct roots_seat *seat = NULL;
|
|
|
|
wl_list_for_each(seat, &input->seats, link) {
|
|
|
|
if (strcmp(seat->seat->name, name) == 0) {
|
|
|
|
return seat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
seat = roots_seat_create(input, name);
|
|
|
|
return seat;
|
|
|
|
}
|
|
|
|
|
2018-02-12 10:36:43 +01:00
|
|
|
static void handle_new_input(struct wl_listener *listener, void *data) {
|
2017-09-23 16:13:05 +02:00
|
|
|
struct wlr_input_device *device = data;
|
2018-02-12 10:36:43 +01:00
|
|
|
struct roots_input *input = wl_container_of(listener, input, new_input);
|
2017-11-03 14:01:34 +01:00
|
|
|
|
2017-11-18 17:34:24 +01:00
|
|
|
char *seat_name = ROOTS_CONFIG_DEFAULT_SEAT_NAME;
|
2017-11-11 16:59:04 +01:00
|
|
|
struct roots_device_config *dc =
|
|
|
|
roots_config_get_device(input->config, device);
|
2017-11-03 14:01:34 +01:00
|
|
|
if (dc) {
|
|
|
|
seat_name = dc->seat;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct roots_seat *seat = input_get_seat(input, seat_name);
|
|
|
|
if (!seat) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_ERROR, "could not create roots seat");
|
2017-11-03 14:01:34 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_DEBUG, "New input device: %s (%d:%d) %s seat:%s", device->name,
|
2017-11-07 22:32:14 +01:00
|
|
|
device->vendor, device->product, device_type(device->type), seat_name);
|
2017-11-04 18:12:35 +01:00
|
|
|
|
|
|
|
roots_seat_add_device(seat, device);
|
2017-12-24 07:38:21 +01:00
|
|
|
|
|
|
|
if (dc && wlr_input_device_is_libinput(device)) {
|
|
|
|
struct libinput_device *libinput_dev =
|
|
|
|
wlr_libinput_get_device_handle(device);
|
|
|
|
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_DEBUG, "input has config, tap_enabled: %d\n", dc->tap_enabled);
|
2017-12-24 07:38:21 +01:00
|
|
|
if (dc->tap_enabled) {
|
|
|
|
libinput_device_config_tap_set_enabled(libinput_dev,
|
|
|
|
LIBINPUT_CONFIG_TAP_ENABLED);
|
|
|
|
}
|
|
|
|
}
|
2017-09-23 16:13:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct roots_input *input_create(struct roots_server *server,
|
|
|
|
struct roots_config *config) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_DEBUG, "Initializing roots input");
|
2017-09-30 14:46:18 +02:00
|
|
|
assert(server->desktop);
|
|
|
|
|
2017-09-23 16:13:05 +02:00
|
|
|
struct roots_input *input = calloc(1, sizeof(struct roots_input));
|
2017-10-21 13:25:39 +02:00
|
|
|
if (input == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-09-23 16:13:05 +02:00
|
|
|
|
|
|
|
input->config = config;
|
2017-09-23 20:53:15 +02:00
|
|
|
input->server = server;
|
2017-09-23 16:13:05 +02:00
|
|
|
|
2017-11-03 14:01:34 +01:00
|
|
|
wl_list_init(&input->seats);
|
2017-09-23 16:13:05 +02:00
|
|
|
|
2018-02-12 10:36:43 +01:00
|
|
|
input->new_input.notify = handle_new_input;
|
|
|
|
wl_signal_add(&server->backend->events.new_input, &input->new_input);
|
2017-09-23 16:13:05 +02:00
|
|
|
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
|
|
|
void input_destroy(struct roots_input *input) {
|
|
|
|
// TODO
|
|
|
|
}
|
2017-11-07 21:56:11 +01:00
|
|
|
|
|
|
|
struct roots_seat *input_seat_from_wlr_seat(struct roots_input *input,
|
|
|
|
struct wlr_seat *wlr_seat) {
|
|
|
|
struct roots_seat *seat = NULL;
|
|
|
|
wl_list_for_each(seat, &input->seats, link) {
|
|
|
|
if (seat->seat == wlr_seat) {
|
|
|
|
return seat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return seat;
|
|
|
|
}
|
2017-11-10 14:27:45 +01:00
|
|
|
|
|
|
|
bool input_view_has_focus(struct roots_input *input, struct roots_view *view) {
|
|
|
|
if (!view) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
struct roots_seat *seat;
|
|
|
|
wl_list_for_each(seat, &input->seats, link) {
|
2017-11-19 19:14:31 +01:00
|
|
|
if (view == roots_seat_get_focus(seat)) {
|
2017-11-10 14:27:45 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-29 19:02:00 +02:00
|
|
|
|
|
|
|
static inline int64_t timespec_to_msec(const struct timespec *a) {
|
|
|
|
return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
void input_update_cursor_focus(struct roots_input *input) {
|
|
|
|
struct roots_seat *seat;
|
|
|
|
struct timespec now;
|
|
|
|
wl_list_for_each(seat, &input->seats, link) {
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
|
|
|
roots_cursor_update_position(seat->cursor, timespec_to_msec(&now));
|
|
|
|
}
|
|
|
|
}
|