2017-09-23 14:13:05 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <wayland-server.h>
|
|
|
|
#include <wlr/types/wlr_cursor.h>
|
|
|
|
#include <wlr/util/log.h>
|
|
|
|
#include <wlr/xcursor.h>
|
2017-11-02 15:49:22 +00:00
|
|
|
#include <wlr/xwayland.h>
|
2017-09-23 14:13:05 +00:00
|
|
|
#include "rootston/server.h"
|
|
|
|
#include "rootston/config.h"
|
|
|
|
#include "rootston/input.h"
|
2017-11-03 00:13:10 +00:00
|
|
|
#include "rootston/keyboard.h"
|
2017-11-03 13:01:34 +00:00
|
|
|
#include "rootston/seat.h"
|
2017-09-23 14:13:05 +00: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";
|
|
|
|
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-03 13:01:34 +00:00
|
|
|
static struct roots_seat *input_get_seat(struct roots_input *input, char *name) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-09-23 14:13:05 +00:00
|
|
|
static void input_add_notify(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_input_device *device = data;
|
|
|
|
struct roots_input *input = wl_container_of(listener, input, input_add);
|
2017-11-03 13:01:34 +00:00
|
|
|
|
|
|
|
char *seat_name = "seat0";
|
|
|
|
struct device_config *dc = config_get_device(input->config, device);
|
|
|
|
if (dc) {
|
|
|
|
seat_name = dc->seat;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct roots_seat *seat = input_get_seat(input, seat_name);
|
|
|
|
if (!seat) {
|
|
|
|
wlr_log(L_ERROR, "could not create roots seat");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-23 14:13:05 +00:00
|
|
|
wlr_log(L_DEBUG, "New input device: %s (%d:%d) %s", device->name,
|
|
|
|
device->vendor, device->product, device_type(device->type));
|
2017-11-04 17:12:35 +00:00
|
|
|
|
|
|
|
roots_seat_add_device(seat, device);
|
2017-09-23 14:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void input_remove_notify(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_input_device *device = data;
|
2017-11-07 21:24:21 +00:00
|
|
|
struct roots_input *input = wl_container_of(listener, input, input_remove);
|
2017-11-04 17:12:35 +00:00
|
|
|
|
|
|
|
struct roots_seat *seat;
|
|
|
|
wl_list_for_each(seat, &input->seats, link) {
|
|
|
|
roots_seat_remove_device(seat, device);
|
2017-09-23 14:13:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct roots_input *input_create(struct roots_server *server,
|
|
|
|
struct roots_config *config) {
|
|
|
|
wlr_log(L_DEBUG, "Initializing roots input");
|
2017-09-30 12:46:18 +00:00
|
|
|
assert(server->desktop);
|
|
|
|
|
2017-09-23 14:13:05 +00:00
|
|
|
struct roots_input *input = calloc(1, sizeof(struct roots_input));
|
2017-10-21 11:25:39 +00:00
|
|
|
if (input == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-09-23 14:13:05 +00:00
|
|
|
|
|
|
|
input->config = config;
|
2017-09-23 18:53:15 +00:00
|
|
|
input->server = server;
|
2017-09-23 14:13:05 +00:00
|
|
|
|
2017-11-03 13:01:34 +00:00
|
|
|
wl_list_init(&input->seats);
|
2017-09-23 14:13:05 +00:00
|
|
|
|
|
|
|
input->input_add.notify = input_add_notify;
|
2017-10-21 10:35:51 +00:00
|
|
|
wl_signal_add(&server->backend->events.input_add, &input->input_add);
|
2017-09-23 14:13:05 +00:00
|
|
|
input->input_remove.notify = input_remove_notify;
|
2017-10-21 10:35:51 +00:00
|
|
|
wl_signal_add(&server->backend->events.input_remove, &input->input_remove);
|
2017-09-23 14:13:05 +00:00
|
|
|
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
|
|
|
void input_destroy(struct roots_input *input) {
|
|
|
|
// TODO
|
|
|
|
}
|
2017-11-07 20:56:11 +00: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;
|
|
|
|
}
|