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/tablet_tool.h"
|
|
|
|
#include "rootston/keyboard.h"
|
|
|
|
#include "rootston/pointer.h"
|
|
|
|
#include "rootston/touch.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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-23 22:32:03 +00:00
|
|
|
keyboard_add(device, input);
|
2017-09-23 14:13:05 +00:00
|
|
|
break;
|
|
|
|
case WLR_INPUT_DEVICE_POINTER:
|
2017-09-23 14:36:32 +00:00
|
|
|
pointer_add(device, input);
|
2017-09-23 14:13:05 +00:00
|
|
|
break;
|
|
|
|
case WLR_INPUT_DEVICE_TOUCH:
|
2017-10-21 03:19:41 +00:00
|
|
|
touch_add(device, input);
|
2017-09-23 14:13:05 +00:00
|
|
|
break;
|
|
|
|
case WLR_INPUT_DEVICE_TABLET_TOOL:
|
2017-10-01 15:21:55 +00:00
|
|
|
tablet_tool_add(device, input);
|
2017-09-23 14:13:05 +00: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-28 23:05:38 +00:00
|
|
|
keyboard_remove(device, input);
|
2017-09-23 14:13:05 +00:00
|
|
|
break;
|
|
|
|
case WLR_INPUT_DEVICE_POINTER:
|
2017-09-28 23:05:38 +00:00
|
|
|
pointer_remove(device, input);
|
2017-09-23 14:13:05 +00:00
|
|
|
break;
|
|
|
|
case WLR_INPUT_DEVICE_TOUCH:
|
2017-10-21 03:19:41 +00:00
|
|
|
touch_remove(device, input);
|
2017-09-23 14:13:05 +00:00
|
|
|
break;
|
|
|
|
case WLR_INPUT_DEVICE_TABLET_TOOL:
|
2017-10-01 15:21:55 +00:00
|
|
|
tablet_tool_remove(device, input);
|
2017-09-23 14:13:05 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-10-27 17:09:38 +00:00
|
|
|
input->xcursor_theme = wlr_xcursor_theme_load("default", 16);
|
|
|
|
if (input->xcursor_theme == NULL) {
|
2017-10-21 11:25:39 +00:00
|
|
|
wlr_log(L_ERROR, "Cannot load xcursor theme");
|
|
|
|
free(input);
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-10-27 17:09:38 +00:00
|
|
|
|
|
|
|
struct wlr_xcursor *xcursor = get_default_xcursor(input->xcursor_theme);
|
|
|
|
if (xcursor == NULL) {
|
2017-10-21 11:25:39 +00:00
|
|
|
wlr_log(L_ERROR, "Cannot load xcursor from theme");
|
2017-10-27 17:09:38 +00:00
|
|
|
wlr_xcursor_theme_destroy(input->xcursor_theme);
|
2017-10-21 11:25:39 +00:00
|
|
|
free(input);
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-09-23 18:53:15 +00:00
|
|
|
|
2017-11-02 15:49:22 +00:00
|
|
|
if (server->desktop->xwayland != NULL) {
|
|
|
|
struct wlr_xcursor_image *xcursor_image = xcursor->images[0];
|
|
|
|
wlr_xwayland_set_cursor(server->desktop->xwayland,
|
|
|
|
xcursor_image->buffer, xcursor_image->width, xcursor_image->width,
|
|
|
|
xcursor_image->height, xcursor_image->hotspot_x,
|
|
|
|
xcursor_image->hotspot_y);
|
|
|
|
}
|
|
|
|
|
2017-10-21 11:25:39 +00:00
|
|
|
input->wl_seat = wlr_seat_create(server->wl_display, "seat0");
|
|
|
|
if (input->wl_seat == NULL) {
|
|
|
|
wlr_log(L_ERROR, "Cannot create seat");
|
2017-10-27 17:09:38 +00:00
|
|
|
wlr_xcursor_theme_destroy(input->xcursor_theme);
|
2017-10-21 11:25:39 +00:00
|
|
|
free(input);
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-09-23 21:48:13 +00:00
|
|
|
wlr_seat_set_capabilities(input->wl_seat, WL_SEAT_CAPABILITY_KEYBOARD
|
|
|
|
| WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_TOUCH);
|
2017-09-23 14:13:05 +00:00
|
|
|
|
|
|
|
wl_list_init(&input->keyboards);
|
|
|
|
wl_list_init(&input->pointers);
|
|
|
|
wl_list_init(&input->touch);
|
|
|
|
wl_list_init(&input->tablet_tools);
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-09-23 18:53:15 +00:00
|
|
|
input->cursor = wlr_cursor_create();
|
|
|
|
cursor_initialize(input);
|
2017-10-29 17:14:58 +00:00
|
|
|
|
|
|
|
struct wlr_xcursor_image *image = xcursor->images[0];
|
|
|
|
wlr_cursor_set_image(input->cursor, image->buffer, image->width,
|
|
|
|
image->width, image->height, image->hotspot_x, image->hotspot_y);
|
2017-09-23 18:53:15 +00:00
|
|
|
|
2017-09-30 12:46:18 +00:00
|
|
|
wlr_cursor_attach_output_layout(input->cursor, server->desktop->layout);
|
|
|
|
wlr_cursor_map_to_region(input->cursor, config->cursor.mapped_box);
|
|
|
|
cursor_load_config(config, input->cursor,
|
|
|
|
input, server->desktop);
|
|
|
|
|
2017-10-15 15:06:03 +00:00
|
|
|
wl_list_init(&input->drag_icons);
|
|
|
|
|
2017-09-23 14:13:05 +00:00
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
|
|
|
void input_destroy(struct roots_input *input) {
|
|
|
|
// TODO
|
|
|
|
}
|