diff options
author | Tony Crisci <tony@dubstepdish.com> | 2017-11-04 13:12:35 -0400 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2017-11-04 13:12:35 -0400 |
commit | 704f0f158a669689b78311cde35a736057f983b4 (patch) | |
tree | 9218ed70e84e542202df15fa93a805953130d259 /rootston | |
parent | 5354fe8729b8c52f8f3ff63f23f932c49bf8c880 (diff) |
rootston: move device init to seat
Diffstat (limited to 'rootston')
-rw-r--r-- | rootston/cursor.c | 4 | ||||
-rw-r--r-- | rootston/input.c | 44 | ||||
-rw-r--r-- | rootston/meson.build | 3 | ||||
-rw-r--r-- | rootston/pointer.c | 24 | ||||
-rw-r--r-- | rootston/seat.c | 241 | ||||
-rw-r--r-- | rootston/tablet_tool.c | 25 | ||||
-rw-r--r-- | rootston/touch.c | 27 |
7 files changed, 242 insertions, 126 deletions
diff --git a/rootston/cursor.c b/rootston/cursor.c index 61dcae7a..9028c5bb 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -19,9 +19,7 @@ #include "rootston/desktop.h" #include "rootston/view.h" #include "rootston/keyboard.h" -#include "rootston/pointer.h" -#include "rootston/tablet_tool.h" -#include "rootston/touch.h" +#include "rootston/seat.h" const struct roots_input_event *get_input_event(struct roots_input *input, uint32_t serial) { diff --git a/rootston/input.c b/rootston/input.c index 51a64720..4a567763 100644 --- a/rootston/input.c +++ b/rootston/input.c @@ -8,10 +8,7 @@ #include "rootston/server.h" #include "rootston/config.h" #include "rootston/input.h" -#include "rootston/tablet_tool.h" #include "rootston/keyboard.h" -#include "rootston/pointer.h" -#include "rootston/touch.h" #include "rootston/seat.h" static const char *device_type(enum wlr_input_device_type type) { @@ -60,44 +57,17 @@ static void input_add_notify(struct wl_listener *listener, void *data) { 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: { - struct roots_keyboard *keyboard = roots_keyboard_create(device, input); - roots_seat_add_keyboard(seat, keyboard); - 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; - } + + roots_seat_add_device(seat, device); } 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: - roots_keyboard_destroy(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 = wl_container_of(listener, input, input_add); + + struct roots_seat *seat; + wl_list_for_each(seat, &input->seats, link) { + roots_seat_remove_device(seat, device); } } diff --git a/rootston/meson.build b/rootston/meson.build index 0367e43f..9c543c4f 100644 --- a/rootston/meson.build +++ b/rootston/meson.build @@ -7,10 +7,7 @@ sources = [ 'keyboard.c', 'main.c', 'output.c', - 'pointer.c', 'seat.c', - 'tablet_tool.c', - 'touch.c', 'xcursor.c', 'xdg_shell_v6.c', 'wl_shell.c', diff --git a/rootston/pointer.c b/rootston/pointer.c deleted file mode 100644 index cb099264..00000000 --- a/rootston/pointer.c +++ /dev/null @@ -1,24 +0,0 @@ -#include <stdlib.h> -#include <wayland-server.h> -#include <wlr/types/wlr_input_device.h> -#include <wlr/types/wlr_pointer.h> -#include "rootston/input.h" -#include "rootston/pointer.h" - -void pointer_add(struct wlr_input_device *device, struct roots_input *input) { - struct roots_pointer *pointer = calloc(sizeof(struct roots_pointer), 1); - device->data = pointer; - pointer->device = device; - pointer->input = input; - wl_list_insert(&input->pointers, &pointer->link); - wlr_cursor_attach_input_device(input->cursor, device); - cursor_load_config(input->server->config, input->cursor, - input, input->server->desktop); -} - -void pointer_remove(struct wlr_input_device *device, struct roots_input *input) { - struct roots_pointer *pointer = device->data; - wlr_cursor_detach_input_device(input->cursor, device); - wl_list_remove(&pointer->link); - free(pointer); -} diff --git a/rootston/seat.c b/rootston/seat.c index 2103e0d2..c8f689bc 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -1,5 +1,8 @@ #include <wayland-server.h> #include <stdlib.h> +#include <string.h> + +#include <wlr/util/log.h> #include "rootston/input.h" #include "rootston/seat.h" @@ -20,18 +23,175 @@ static void handle_keyboard_modifiers(struct wl_listener *listener, roots_keyboard_handle_modifiers(keyboard, event); } +static void handle_cursor_motion(struct wl_listener *listener, void *data) { + // TODO +} + +static void handle_cursor_motion_absolute(struct wl_listener *listener, void *data) { + // TODO +} + +static void handle_cursor_button(struct wl_listener *listener, void *data) { + // TODO +} + +static void handle_cursor_axis(struct wl_listener *listener, void *data) { + // TODO +} + +static void handle_touch_down(struct wl_listener *listener, void *data) { + // TODO +} + +static void handle_touch_up(struct wl_listener *listener, void *data) { + // TODO +} + +static void handle_touch_motion(struct wl_listener *listener, void *data) { + // TODO +} + +static void handle_tool_axis(struct wl_listener *listener, void *data) { + // TODO +} + +static void handle_tool_tip(struct wl_listener *listener, void *data) { + // TODO +} + +static void seat_reset_device_mappings(struct roots_seat *seat, struct wlr_input_device *device) { + struct wlr_cursor *cursor = seat->cursor; + struct roots_config *config = seat->input->config; + + wlr_cursor_map_input_to_output(cursor, device, NULL); + struct device_config *dconfig; + if ((dconfig = config_get_device(config, device))) { + wlr_cursor_map_input_to_region(cursor, device, dconfig->mapped_box); + } +} + +static void seat_set_device_output_mappings(struct roots_seat *seat, + struct wlr_input_device *device, struct wlr_output *output) { + struct wlr_cursor *cursor = seat->cursor; + struct roots_config *config = seat->input->config; + struct device_config *dconfig; + dconfig = config_get_device(config, device); + if (dconfig && dconfig->mapped_output && + strcmp(dconfig->mapped_output, output->name) == 0) { + wlr_cursor_map_input_to_output(cursor, device, output); + } +} + +static void roots_seat_configure_cursor(struct roots_seat *seat) { + struct roots_config *config = seat->input->config; + struct roots_desktop *desktop = seat->input->server->desktop; + struct wlr_cursor *cursor = seat->cursor; + + struct roots_pointer *pointer; + struct roots_touch *touch; + struct roots_tablet_tool *tablet_tool; + struct roots_output *output; + + // reset mappings + wlr_cursor_map_to_output(cursor, NULL); + wl_list_for_each(pointer, &seat->pointers, link) { + seat_reset_device_mappings(seat, pointer->device); + } + wl_list_for_each(touch, &seat->touch, link) { + seat_reset_device_mappings(seat, touch->device); + } + wl_list_for_each(tablet_tool, &seat->tablet_tools, link) { + seat_reset_device_mappings(seat, tablet_tool->device); + } + + // configure device to output mappings + const char *mapped_output = config->cursor.mapped_output; + wl_list_for_each(output, &desktop->outputs, link) { + if (mapped_output && strcmp(mapped_output, output->wlr_output->name) == 0) { + wlr_cursor_map_to_output(cursor, output->wlr_output); + } + + wl_list_for_each(pointer, &seat->pointers, link) { + seat_set_device_output_mappings(seat, pointer->device, output->wlr_output); + } + wl_list_for_each(tablet_tool, &seat->tablet_tools, link) { + seat_set_device_output_mappings(seat, tablet_tool->device, output->wlr_output); + } + wl_list_for_each(touch, &seat->touch, link) { + seat_set_device_output_mappings(seat, touch->device, output->wlr_output); + } + } +} + +static void roots_seat_init_cursor(struct roots_seat *seat) { + struct wlr_cursor *cursor = wlr_cursor_create(); + if (!cursor) { + return; + } + seat->cursor = cursor; + + // add output layout and configure + struct roots_desktop *desktop = seat->input->server->desktop; + wlr_cursor_attach_output_layout(cursor, desktop->layout); + roots_seat_configure_cursor(seat); + // TODO configure cursor by seat + + // add input signals + wl_signal_add(&cursor->events.motion, &seat->cursor_motion); + seat->cursor_motion.notify = handle_cursor_motion; + + wl_signal_add(&cursor->events.motion_absolute, + &seat->cursor_motion_absolute); + seat->cursor_motion_absolute.notify = handle_cursor_motion_absolute; + + wl_signal_add(&cursor->events.button, &seat->cursor_button); + seat->cursor_button.notify = handle_cursor_button; + + wl_signal_add(&cursor->events.axis, &seat->cursor_axis); + seat->cursor_axis.notify = handle_cursor_axis; + + wl_signal_add(&cursor->events.touch_down, &seat->cursor_touch_down); + seat->cursor_touch_down.notify = handle_touch_down; + + wl_signal_add(&cursor->events.touch_up, &seat->cursor_touch_up); + seat->cursor_touch_up.notify = handle_touch_up; + + wl_signal_add(&cursor->events.touch_motion, &seat->cursor_touch_motion); + seat->cursor_touch_motion.notify = handle_touch_motion; + + wl_signal_add(&cursor->events.tablet_tool_axis, &seat->cursor_tool_axis); + seat->cursor_tool_axis.notify = handle_tool_axis; + + wl_signal_add(&cursor->events.tablet_tool_tip, &seat->cursor_tool_tip); + seat->cursor_tool_tip.notify = handle_tool_tip; +} + struct roots_seat *roots_seat_create(struct roots_input *input, char *name) { struct roots_seat *seat = calloc(1, sizeof(struct roots_seat)); if (!seat) { return NULL; } + roots_seat_init_cursor(seat); + if (!seat->cursor) { + free(seat); + return NULL; + } + seat->seat = wlr_seat_create(input->server->wl_display, name); + if (!seat->seat) { + free(seat); + wlr_cursor_destroy(seat->cursor); + return NULL; + } + wlr_seat_set_capabilities(seat->seat, WL_SEAT_CAPABILITY_KEYBOARD | WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_TOUCH); + seat->input = input; + wl_list_insert(&input->seats, &seat->link); wl_list_init(&seat->keyboards); @@ -42,12 +202,10 @@ void roots_seat_destroy(struct roots_seat *seat) { // TODO } -void roots_seat_add_keyboard(struct roots_seat *seat, - struct roots_keyboard *keyboard) { - if (keyboard->seat) { - roots_seat_remove_keyboard(keyboard->seat, keyboard); - } +static void seat_add_keyboard(struct roots_seat *seat, struct wlr_input_device *device) { + struct roots_keyboard *keyboard = roots_keyboard_create(device, seat->input); keyboard->seat = seat; + wl_list_insert(&seat->keyboards, &keyboard->seat_link); keyboard->keyboard_key.notify = handle_keyboard_key; @@ -59,8 +217,77 @@ void roots_seat_add_keyboard(struct roots_seat *seat, &keyboard->keyboard_modifiers); } -void roots_seat_remove_keyboard(struct roots_seat *seat, - struct roots_keyboard *keyboard) { +static void seat_add_pointer(struct roots_seat *seat, struct wlr_input_device *device) { + struct roots_pointer *pointer = calloc(sizeof(struct roots_pointer), 1); + if (!pointer) { + wlr_log(L_ERROR, "could not allocate pointer for seat"); + return; + } + + device->data = pointer; + pointer->device = device; + pointer->seat = seat; + wl_list_insert(&seat->pointers, &pointer->link); + wlr_cursor_attach_input_device(seat->cursor, device); + roots_seat_configure_cursor(seat); +} + +static void seat_add_touch(struct roots_seat *seat, struct wlr_input_device *device) { + struct roots_touch *touch = calloc(sizeof(struct roots_touch), 1); + if (!touch) { + wlr_log(L_ERROR, "could not allocate touch for seat"); + return; + } + + device->data = touch; + touch->device = device; + touch->seat = seat; + wl_list_insert(&seat->touch, &touch->link); + wlr_cursor_attach_input_device(seat->cursor, device); + roots_seat_configure_cursor(seat); +} + +static void seat_add_tablet_pad(struct roots_seat *seat, struct wlr_input_device *device) { // TODO } +static void seat_add_tablet_tool(struct roots_seat *seat, struct wlr_input_device *device) { + struct roots_tablet_tool *tablet_tool = calloc(sizeof(struct roots_tablet_tool), 1); + if (!tablet_tool) { + wlr_log(L_ERROR, "could not allocate tablet_tool for seat"); + return; + } + + device->data = tablet_tool; + tablet_tool->device = device; + tablet_tool->seat = seat; + wl_list_insert(&seat->tablet_tools, &tablet_tool->link); + wlr_cursor_attach_input_device(seat->cursor, device); + roots_seat_configure_cursor(seat); +} + +void roots_seat_add_device(struct roots_seat *seat, + struct wlr_input_device *device) { + switch (device->type) { + case WLR_INPUT_DEVICE_KEYBOARD: + seat_add_keyboard(seat, device); + break; + case WLR_INPUT_DEVICE_POINTER: + seat_add_pointer(seat, device); + break; + case WLR_INPUT_DEVICE_TOUCH: + seat_add_touch(seat, device); + break; + case WLR_INPUT_DEVICE_TABLET_PAD: + seat_add_tablet_pad(seat, device); + break; + case WLR_INPUT_DEVICE_TABLET_TOOL: + seat_add_tablet_tool(seat, device); + break; + } +} + +void roots_seat_remove_device(struct roots_seat *seat, + struct wlr_input_device *device) { + // TODO +} diff --git a/rootston/tablet_tool.c b/rootston/tablet_tool.c deleted file mode 100644 index 3327115d..00000000 --- a/rootston/tablet_tool.c +++ /dev/null @@ -1,25 +0,0 @@ -#include <stdlib.h> -#include <wayland-server.h> -#include <wlr/types/wlr_input_device.h> -#include <wlr/types/wlr_pointer.h> -#include <wlr/util/log.h> -#include "rootston/input.h" -#include "rootston/tablet_tool.h" - -void tablet_tool_add(struct wlr_input_device *device, struct roots_input *input) { - struct roots_tablet_tool *tool = calloc(sizeof(struct roots_tablet_tool), 1); - device->data = tool; - tool->device = device; - tool->input = input; - wl_list_insert(&input->tablet_tools, &tool->link); - wlr_cursor_attach_input_device(input->cursor, device); - cursor_load_config(input->server->config, input->cursor, - input, input->server->desktop); -} - -void tablet_tool_remove(struct wlr_input_device *device, struct roots_input *input) { - struct roots_tablet_tool *tablet_tool = device->data; - wlr_cursor_detach_input_device(input->cursor, device); - wl_list_remove(&tablet_tool->link); - free(tablet_tool); -} diff --git a/rootston/touch.c b/rootston/touch.c deleted file mode 100644 index 069853ab..00000000 --- a/rootston/touch.c +++ /dev/null @@ -1,27 +0,0 @@ -#include <stdlib.h> -#include <wayland-server.h> -#include <wlr/types/wlr_input_device.h> -#include <wlr/types/wlr_pointer.h> -#include "rootston/input.h" -#include "rootston/touch.h" - -// TODO: we'll likely want touch events to both control the cursor *and* be -// submitted directly to the seat. - -void touch_add(struct wlr_input_device *device, struct roots_input *input) { - struct roots_touch *touch = calloc(sizeof(struct roots_touch), 1); - device->data = touch; - touch->device = device; - touch->input = input; - wl_list_insert(&input->touch, &touch->link); - wlr_cursor_attach_input_device(input->cursor, device); - cursor_load_config(input->server->config, input->cursor, - input, input->server->desktop); -} - -void touch_remove(struct wlr_input_device *device, struct roots_input *input) { - struct roots_touch *touch = device->data; - wlr_cursor_detach_input_device(input->cursor, device); - wl_list_remove(&touch->link); - free(touch); -} |