~sircmpwn/sedna

eab787198f0839e8f48673b670403d04c789acc0 — Drew DeVault a month ago 157d7c7
Flesh out input riggings somewhat
6 files changed, 106 insertions(+), 28 deletions(-)

M include/input.h
M include/server.h
A src/cursor.c
M src/input.c
M src/main.c
M src/meson.build
M include/input.h => include/input.h +35 -2
@@ 5,15 5,48 @@

struct sedna_server;

struct sedna_seat {
	struct sedna_server *server;

	struct wlr_cursor *cursor;
	struct wlr_xcursor_manager *xcursor_manager;
	struct wlr_seat *seat;
	struct wl_list inputs;
	struct wl_listener new_input;

	struct wl_listener motion;
	struct wl_listener motion_absolute;
	struct wl_listener button;
	struct wl_listener axis;
	struct wl_listener frame;
	struct wl_listener swipe_begin;
	struct wl_listener swipe_update;
	struct wl_listener swipe_end;
	struct wl_listener pinch_begin;
	struct wl_listener pinch_update;
	struct wl_listener pinch_end;

	struct wl_listener touch_up;
	struct wl_listener touch_down;
	struct wl_listener touch_motion;
	struct wl_listener touch_cancel;

	struct wl_listener tablet_tool_axis;
	struct wl_listener tablet_tool_proximity;
	struct wl_listener tablet_tool_tip;
	struct wl_listener tablet_tool_button;
};

struct sedna_input {
	struct wlr_input_device *wlr_input_device;
	struct sedna_server *server;
	struct sedna_seat *seat;
	struct wl_list link;

	struct wl_listener destroy;
};

void sedna_inputs_init(struct sedna_server *server);
void sedna_seat_init(struct sedna_server *server, struct sedna_seat *seat);
void sedna_cursor_init(struct sedna_seat *seat);

#endif


M include/server.h => include/server.h +2 -4
@@ 6,6 6,7 @@
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/types/wlr_xdg_shell.h>
#include "input.h"

struct sedna_server {
	struct wl_display *wl_display;


@@ 16,10 17,7 @@ struct sedna_server {
	struct wl_list outputs;
	struct wl_listener new_output;

	struct wlr_cursor *cursor;
	struct wlr_seat *seat;
	struct wl_list inputs;
	struct wl_listener new_input;
	struct sedna_seat seat;

	struct wl_list views;


A src/cursor.c => src/cursor.c +47 -0
@@ 0,0 1,47 @@
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_xcursor_manager.h>
#include "input.h"

static void
seat_motion(struct wl_listener *listener, void *data)
{
}

static void
seat_motion_absolute(struct wl_listener *listener, void *data)
{
}

static void
seat_button(struct wl_listener *listener, void *data)
{
}

static void
seat_axis(struct wl_listener *listener, void *data)
{
}

static void
seat_frame(struct wl_listener *listener, void *data)
{
}

void
sedna_cursor_init(struct sedna_seat *seat)
{
	seat->xcursor_manager = wlr_xcursor_manager_create("default", 24);
	wlr_xcursor_manager_load(seat->xcursor_manager, 1);

	seat->motion.notify = seat_motion;
	wl_signal_add(&seat->cursor->events.motion, &seat->motion);
	seat->motion_absolute.notify = seat_motion_absolute;
	wl_signal_add(&seat->cursor->events.motion_absolute, &seat->motion_absolute);
	seat->button.notify = seat_button;
	wl_signal_add(&seat->cursor->events.button, &seat->button);
	seat->axis.notify = seat_axis;
	wl_signal_add(&seat->cursor->events.axis, &seat->axis);
	seat->frame.notify = seat_frame;
	wl_signal_add(&seat->cursor->events.frame, &seat->frame);
	/* TODO: Process other input events */
}

M src/input.c => src/input.c +20 -20
@@ 16,38 16,35 @@ input_device_destroy(struct wl_listener *listener, void *data)
}

static void
new_pointer(struct sedna_input *input)
new_pointer(struct sedna_seat *seat, struct sedna_input *input)
{
	wlr_cursor_attach_input_device(
			input->server->cursor, input->wlr_input_device);
	wlr_cursor_attach_input_device(seat->cursor, input->wlr_input_device);
}

static void
new_touch(struct sedna_input *input)
new_touch(struct sedna_seat *seat, struct sedna_input *input)
{
	wlr_cursor_attach_input_device(
			input->server->cursor, input->wlr_input_device);
	wlr_cursor_attach_input_device(seat->cursor, input->wlr_input_device);
}

static void
new_input_notify(struct wl_listener *listener, void *data)
{
	struct sedna_server *server =
		wl_container_of(listener, server, new_input);
	struct sedna_seat *seat = wl_container_of(listener, seat, new_input);
	struct wlr_input_device *dev = data;
	struct sedna_input *input = calloc(1, sizeof(struct sedna_input));
	input->wlr_input_device = dev;
	input->server = server;
	input->seat = seat;

	switch (dev->type) {
	case WLR_INPUT_DEVICE_KEYBOARD:
		/* TODO */
		break;
	case WLR_INPUT_DEVICE_POINTER:
		new_pointer(input);
		new_pointer(seat, input);
		break;
	case WLR_INPUT_DEVICE_TOUCH:
		new_touch(input);
		new_touch(seat, input);
		break;
	default:
		/* Unsupported input device type */


@@ 56,10 53,10 @@ new_input_notify(struct wl_listener *listener, void *data)

	input->destroy.notify = input_device_destroy;
	wl_signal_add(&dev->events.destroy, &input->destroy);
	wl_list_insert(&server->inputs, &input->link);
	wl_list_insert(&seat->inputs, &input->link);

	uint32_t caps = 0;
	wl_list_for_each(input, &server->inputs, link) {
	wl_list_for_each(input, &seat->inputs, link) {
		switch (input->wlr_input_device->type) {
		case WLR_INPUT_DEVICE_KEYBOARD:
			caps |= WL_SEAT_CAPABILITY_KEYBOARD;


@@ 75,17 72,20 @@ new_input_notify(struct wl_listener *listener, void *data)
			break;
		}
	}
	wlr_seat_set_capabilities(server->seat, caps);
	wlr_seat_set_capabilities(seat->seat, caps);
}

void
sedna_inputs_init(struct sedna_server *server)
sedna_seat_init(struct sedna_server *server, struct sedna_seat *seat)
{
	server->new_input.notify = new_input_notify;
	wl_signal_add(&server->backend->events.new_input, &server->new_input);
	seat->server = server;
	seat->new_input.notify = new_input_notify;
	wl_signal_add(&server->backend->events.new_input, &seat->new_input);

	server->cursor = wlr_cursor_create();
	wlr_cursor_attach_output_layout(server->cursor, server->output_layout);
	seat->cursor = wlr_cursor_create();
	wlr_cursor_attach_output_layout(seat->cursor, server->output_layout);
	sedna_cursor_init(seat);

	server->seat = wlr_seat_create(server->wl_display, "seat-0");
	seat->seat = wlr_seat_create(server->wl_display, "seat-0");
	wl_list_init(&seat->inputs);
}

M src/main.c => src/main.c +1 -2
@@ 39,7 39,6 @@ main(int argc, char *argv[])
	server.renderer = wlr_backend_get_renderer(server.backend);
	wlr_renderer_init_wl_display(server.renderer, server.wl_display);

	wl_list_init(&server.inputs);
	wl_list_init(&server.views);

	wlr_compositor_create(server.wl_display, server.renderer);


@@ 54,7 53,7 @@ main(int argc, char *argv[])

	/* Order-sensitive */
	sedna_outputs_init(&server);
	sedna_inputs_init(&server);
	sedna_seat_init(&server, &server.seat);
	sedna_xdg_shell_init(&server);

	const char *socket = wl_display_add_socket_auto(server.wl_display);

M src/meson.build => src/meson.build +1 -0
@@ 8,6 8,7 @@ sedna_deps = [
executable(
	'sedna',
	files(
		'cursor.c',
		'main.c',
		'input.c',
		'output.c',