aboutsummaryrefslogtreecommitdiff
path: root/rootston/input.c
blob: 9157ecc7f5bacf27d4ba839cdfb4b76d13a79474 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#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:
		keyboard_add(device, input);
		break;
	case WLR_INPUT_DEVICE_POINTER:
		pointer_add(device, input);
		break;
	case WLR_INPUT_DEVICE_TOUCH:
		//touch_add(device, input);
		break;
	case WLR_INPUT_DEVICE_TABLET_TOOL:
		//tablet_tool_add(device, input);
		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:
		keyboard_remove(device, input);
		break;
	case WLR_INPUT_DEVICE_POINTER:
		pointer_remove(device, input);
		break;
	case WLR_INPUT_DEVICE_TOUCH:
		//touch_remove(device, input);
		break;
	case WLR_INPUT_DEVICE_TABLET_TOOL:
		//tablet_tool_remove(device, input);
		break;
	default:
		break;
	}
}

struct roots_input *input_create(struct roots_server *server,
		struct roots_config *config) {
	wlr_log(L_DEBUG, "Initializing roots input");
	assert(server->desktop);

	struct roots_input *input = calloc(1, sizeof(struct roots_input));
	assert(input);

	input->config = config;
	input->server = server;

	struct wlr_xcursor_theme *theme;
	assert(theme = wlr_xcursor_theme_load("default", 16));
	assert(input->xcursor = wlr_xcursor_theme_get_cursor(theme, "left_ptr"));

	assert(input->wl_seat = wlr_seat_create(server->wl_display, "seat0"));
	wlr_seat_set_capabilities(input->wl_seat, WL_SEAT_CAPABILITY_KEYBOARD
		| WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_TOUCH);

	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);

	input->cursor = wlr_cursor_create();
	cursor_initialize(input);
	wlr_cursor_set_xcursor(input->cursor, input->xcursor);

	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);

	return input;
}

void input_destroy(struct roots_input *input) {
	// TODO
}