2017-09-23 16:13:05 +02: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>
|
|
|
|
#include "rootston/server.h"
|
|
|
|
#include "rootston/config.h"
|
|
|
|
#include "rootston/input.h"
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
wlr_log(L_DEBUG, "New input device: %s (%d:%d) %s", device->name,
|
|
|
|
device->vendor, device->product, device_type(device->type));
|
|
|
|
switch (device->type) {
|
|
|
|
case WLR_INPUT_DEVICE_KEYBOARD:
|
2017-09-24 00:32:03 +02:00
|
|
|
keyboard_add(device, input);
|
2017-09-23 16:13:05 +02:00
|
|
|
break;
|
|
|
|
case WLR_INPUT_DEVICE_POINTER:
|
2017-09-23 16:36:32 +02:00
|
|
|
pointer_add(device, input);
|
2017-09-23 16:13:05 +02:00
|
|
|
break;
|
|
|
|
case WLR_INPUT_DEVICE_TOUCH:
|
2017-09-23 16:36:32 +02:00
|
|
|
//touch_add(device, input);
|
2017-09-23 16:13:05 +02:00
|
|
|
break;
|
|
|
|
case WLR_INPUT_DEVICE_TABLET_TOOL:
|
2017-09-23 16:36:32 +02:00
|
|
|
//tablet_tool_add(device, input);
|
2017-09-23 16:13:05 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void input_remove_notify(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_input_device *device = data;
|
|
|
|
struct roots_input *input = wl_container_of(listener, input, input_remove);
|
|
|
|
switch (device->type) {
|
|
|
|
case WLR_INPUT_DEVICE_KEYBOARD:
|
2017-09-29 01:05:38 +02:00
|
|
|
keyboard_remove(device, input);
|
2017-09-23 16:13:05 +02:00
|
|
|
break;
|
|
|
|
case WLR_INPUT_DEVICE_POINTER:
|
2017-09-29 01:05:38 +02:00
|
|
|
pointer_remove(device, input);
|
2017-09-23 16:13:05 +02:00
|
|
|
break;
|
|
|
|
case WLR_INPUT_DEVICE_TOUCH:
|
2017-09-23 16:36:32 +02:00
|
|
|
//touch_remove(device, input);
|
2017-09-23 16:13:05 +02:00
|
|
|
break;
|
|
|
|
case WLR_INPUT_DEVICE_TABLET_TOOL:
|
2017-09-23 16:36:32 +02:00
|
|
|
//tablet_tool_remove(device, input);
|
2017-09-23 16:13:05 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct roots_input *input_create(struct roots_server *server,
|
|
|
|
struct roots_config *config) {
|
|
|
|
wlr_log(L_DEBUG, "Initializing roots input");
|
|
|
|
struct roots_input *input = calloc(1, sizeof(struct roots_input));
|
|
|
|
assert(input);
|
|
|
|
|
|
|
|
input->config = config;
|
2017-09-23 20:53:15 +02:00
|
|
|
input->server = server;
|
2017-09-23 16:13:05 +02:00
|
|
|
|
|
|
|
struct wlr_xcursor_theme *theme;
|
|
|
|
assert(theme = wlr_xcursor_theme_load("default", 16));
|
|
|
|
assert(input->xcursor = wlr_xcursor_theme_get_cursor(theme, "left_ptr"));
|
2017-09-23 20:53:15 +02:00
|
|
|
|
2017-09-23 16:13:05 +02:00
|
|
|
assert(input->wl_seat = wlr_seat_create(server->wl_display, "seat0"));
|
2017-09-23 23:48:13 +02:00
|
|
|
wlr_seat_set_capabilities(input->wl_seat, WL_SEAT_CAPABILITY_KEYBOARD
|
|
|
|
| WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_TOUCH);
|
2017-09-23 16:13:05 +02:00
|
|
|
|
|
|
|
wl_list_init(&input->keyboards);
|
|
|
|
wl_list_init(&input->pointers);
|
|
|
|
wl_list_init(&input->touch);
|
|
|
|
wl_list_init(&input->tablet_tools);
|
|
|
|
|
|
|
|
wl_list_init(&input->input_add.link);
|
|
|
|
input->input_add.notify = input_add_notify;
|
|
|
|
wl_list_init(&input->input_remove.link);
|
|
|
|
input->input_remove.notify = input_remove_notify;
|
|
|
|
|
|
|
|
wl_signal_add(&server->backend->events.input_add,
|
|
|
|
&input->input_add);
|
|
|
|
wl_signal_add(&server->backend->events.input_remove,
|
|
|
|
&input->input_remove);
|
|
|
|
|
2017-09-23 20:53:15 +02:00
|
|
|
input->cursor = wlr_cursor_create();
|
|
|
|
cursor_initialize(input);
|
|
|
|
wlr_cursor_set_xcursor(input->cursor, input->xcursor);
|
|
|
|
|
2017-09-23 16:13:05 +02:00
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
|
|
|
void input_destroy(struct roots_input *input) {
|
|
|
|
// TODO
|
|
|
|
}
|