aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/rootston/input.h14
-rw-r--r--rootston/cursor.c192
-rw-r--r--rootston/desktop.c2
-rw-r--r--rootston/input.c8
-rw-r--r--rootston/meson.build1
-rw-r--r--rootston/output.c9
-rw-r--r--rootston/pointer.c29
7 files changed, 220 insertions, 35 deletions
diff --git a/include/rootston/input.h b/include/rootston/input.h
index 4177ffa8..4ac11959 100644
--- a/include/rootston/input.h
+++ b/include/rootston/input.h
@@ -68,6 +68,7 @@ struct roots_input_event {
struct roots_input {
struct roots_config *config;
+ struct roots_server *server;
// TODO: multiseat, multicursor
struct wlr_cursor *cursor;
@@ -89,6 +90,13 @@ struct roots_input {
struct wl_listener input_add;
struct wl_listener input_remove;
+
+ struct wl_listener cursor_motion;
+ struct wl_listener cursor_motion_absolute;
+ struct wl_listener cursor_button;
+ struct wl_listener cursor_axis;
+ struct wl_listener cursor_tool_axis;
+ struct wl_listener cursor_tool_tip;
};
struct roots_input *input_create(struct roots_server *server,
@@ -97,4 +105,10 @@ void input_destroy(struct roots_input *input);
void pointer_add(struct wlr_input_device *device, struct roots_input *input);
+void cursor_initialize(struct roots_input *input);
+void cursor_load_config(struct roots_config *config,
+ struct wlr_cursor *cursor,
+ struct roots_input *input,
+ struct roots_desktop *desktop);
+
#endif
diff --git a/rootston/cursor.c b/rootston/cursor.c
index 100e4b32..d5507289 100644
--- a/rootston/cursor.c
+++ b/rootston/cursor.c
@@ -1,3 +1,10 @@
+#include <stdint.h>
+#include <string.h>
+#include <wayland-server.h>
+#include <wlr/types/wlr_cursor.h>
+#include "rootston/config.h"
+#include "rootston/input.h"
+#include "rootston/desktop.h"
void cursor_update_position(struct roots_input *input, uint32_t time) {
/*
@@ -8,7 +15,6 @@ void cursor_update_position(struct roots_input *input, uint32_t time) {
surface->position.ly = sample->cursor->y - sample->motion_context.off_y;
return;
}
- */
struct wlr_xdg_surface_v6 *surface = example_xdg_surface_at(sample,
sample->cursor->x, sample->cursor->y);
@@ -25,4 +31,188 @@ void cursor_update_position(struct roots_input *input, uint32_t time) {
} else {
wlr_seat_pointer_clear_focus(sample->wl_seat);
}
+ */
+}
+
+static void handle_cursor_motion(struct wl_listener *listener, void *data) {
+ struct roots_input *input = wl_container_of(listener, input, cursor_motion);
+ struct wlr_event_pointer_motion *event = data;
+ wlr_cursor_move(input->cursor, event->device,
+ event->delta_x, event->delta_y);
+ cursor_update_position(input, (uint32_t)event->time_usec);
+}
+
+static void handle_cursor_motion_absolute(struct wl_listener *listener,
+ void *data) {
+ struct roots_input *input = wl_container_of(listener,
+ input, cursor_motion_absolute);
+ struct wlr_event_pointer_motion_absolute *event = data;
+ wlr_cursor_warp_absolute(input->cursor, event->device,
+ event->x_mm / event->width_mm, event->y_mm / event->height_mm);
+ cursor_update_position(input, (uint32_t)event->time_usec);
+}
+
+static void handle_cursor_axis(struct wl_listener *listener, void *data) {
+ struct roots_input *input =
+ wl_container_of(listener, input, cursor_axis);
+ struct wlr_event_pointer_axis *event = data;
+ wlr_seat_pointer_send_axis(input->wl_seat, event->time_sec,
+ event->orientation, event->delta);
+}
+
+static void handle_cursor_button(struct wl_listener *listener, void *data) {
+ /* TODO
+ struct sample_state *sample =
+ wl_container_of(listener, sample, cursor_button);
+ struct wlr_event_pointer_button *event = data;
+
+ struct wlr_xdg_surface_v6 *surface =
+ example_xdg_surface_at(sample, sample->cursor->x, sample->cursor->y);
+
+ uint32_t serial = wlr_seat_pointer_send_button(sample->wl_seat,
+ (uint32_t)event->time_usec, event->button, event->state);
+
+ int i;
+ switch (event->state) {
+ case WLR_BUTTON_RELEASED:
+ if (sample->motion_context.surface) {
+ sample->motion_context.surface = NULL;
+ }
+ break;
+ case WLR_BUTTON_PRESSED:
+ i = sample->input_cache_idx;
+ sample->input_cache[i].serial = serial;
+ sample->input_cache[i].cursor = sample->cursor;
+ sample->input_cache[i].device = event->device;
+ sample->input_cache_idx = (i + 1)
+ % (sizeof(sample->input_cache) / sizeof(sample->input_cache[0]));
+ example_set_focused_surface(sample, surface);
+ wlr_log(L_DEBUG, "Stored event %d at %d", serial, i);
+ if (sample->mod_down && event->button == BTN_LEFT) {
+ struct example_xdg_surface_v6 *esurface = surface->data;
+ sample->motion_context.surface = esurface;
+ sample->motion_context.off_x = sample->cursor->x - esurface->position.lx;
+ sample->motion_context.off_y = sample->cursor->y - esurface->position.ly;
+ wlr_seat_pointer_clear_focus(sample->wl_seat);
+ }
+ break;
+ }
+ */
+}
+
+static void handle_tool_axis(struct wl_listener *listener, void *data) {
+ struct roots_input *input = wl_container_of(listener, input, cursor_tool_axis);
+ struct wlr_event_tablet_tool_axis *event = data;
+ if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) &&
+ (event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
+ wlr_cursor_warp_absolute(input->cursor, event->device,
+ event->x_mm / event->width_mm, event->y_mm / event->height_mm);
+ cursor_update_position(input, (uint32_t)event->time_usec);
+ }
+}
+
+static void handle_tool_tip(struct wl_listener *listener, void *data) {
+ /* TODO
+ struct roots_input *input = wl_container_of(listener, input, tool_tip);
+ struct wlr_event_tablet_tool_tip *event = data;
+
+ struct wlr_xdg_surface_v6 *surface =
+ example_xdg_surface_at(sample, sample->cursor->x, sample->cursor->y);
+ example_set_focused_surface(sample, surface);
+
+ wlr_seat_pointer_send_button(sample->wl_seat, (uint32_t)event->time_usec,
+ BTN_LEFT, event->state);
+ */
+}
+
+void cursor_initialize(struct roots_input *input) {
+ struct wlr_cursor *cursor = input->cursor;
+
+ wl_list_init(&input->cursor_motion.link);
+ wl_signal_add(&cursor->events.motion, &input->cursor_motion);
+ input->cursor_motion.notify = handle_cursor_motion;
+
+ wl_list_init(&input->cursor_motion_absolute.link);
+ wl_signal_add(&cursor->events.motion_absolute,
+ &input->cursor_motion_absolute);
+ input->cursor_motion_absolute.notify = handle_cursor_motion_absolute;
+
+ wl_list_init(&input->cursor_button.link);
+ wl_signal_add(&cursor->events.button, &input->cursor_button);
+ input->cursor_button.notify = handle_cursor_button;
+
+ wl_list_init(&input->cursor_axis.link);
+ wl_signal_add(&cursor->events.axis, &input->cursor_axis);
+ input->cursor_axis.notify = handle_cursor_axis;
+
+ wl_list_init(&input->cursor_tool_axis.link);
+ wl_signal_add(&cursor->events.tablet_tool_axis, &input->cursor_tool_axis);
+ input->cursor_tool_axis.notify = handle_tool_axis;
+
+ wl_list_init(&input->cursor_tool_tip.link);
+ wl_signal_add(&cursor->events.tablet_tool_tip, &input->cursor_tool_tip);
+ input->cursor_tool_tip.notify = handle_tool_tip;
+}
+
+static void reset_device_mappings(struct roots_config *config,
+ struct wlr_cursor *cursor, struct wlr_input_device *device) {
+ 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 set_device_output_mappings(struct roots_config *config,
+ struct wlr_cursor *cursor, struct wlr_output *output,
+ struct wlr_input_device *device) {
+ 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);
+ }
+}
+
+void cursor_load_config(struct roots_config *config,
+ struct wlr_cursor *cursor,
+ struct roots_input *input,
+ struct roots_desktop *desktop) {
+ 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, &input->pointers, link) {
+ reset_device_mappings(config, cursor, pointer->device);
+ }
+ wl_list_for_each(touch, &input->touch, link) {
+ reset_device_mappings(config, cursor, touch->device);
+ }
+ wl_list_for_each(tablet_tool, &input->tablet_tools, link) {
+ reset_device_mappings(config, cursor, 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, &input->pointers, link) {
+ set_device_output_mappings(config, cursor, output->wlr_output,
+ pointer->device);
+ }
+ wl_list_for_each(tablet_tool, &input->tablet_tools, link) {
+ set_device_output_mappings(config, cursor, output->wlr_output,
+ tablet_tool->device);
+ }
+ wl_list_for_each(touch, &input->touch, link) {
+ set_device_output_mappings(config, cursor, output->wlr_output,
+ touch->device);
+ }
+ }
}
diff --git a/rootston/desktop.c b/rootston/desktop.c
index fc341a23..fbaf9cac 100644
--- a/rootston/desktop.c
+++ b/rootston/desktop.c
@@ -42,6 +42,8 @@ struct roots_desktop *desktop_create(struct roots_server *server,
wlr_cursor_attach_output_layout(server->input->cursor, desktop->layout);
wlr_cursor_map_to_region(server->input->cursor, config->cursor.mapped_box);
+ cursor_load_config(config, server->input->cursor,
+ server->input, desktop);
desktop->xdg_shell_v6 = wlr_xdg_shell_v6_create(server->wl_display);
wl_signal_add(&desktop->xdg_shell_v6->events.new_surface,
diff --git a/rootston/input.c b/rootston/input.c
index d551715b..9ad20b58 100644
--- a/rootston/input.c
+++ b/rootston/input.c
@@ -75,12 +75,12 @@ struct roots_input *input_create(struct roots_server *server,
assert(input);
input->config = config;
- input->cursor = wlr_cursor_create();
+ 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"));
- wlr_cursor_set_xcursor(input->cursor, input->xcursor);
+
assert(input->wl_seat = wlr_seat_create(server->wl_display, "seat0"));
wl_list_init(&input->keyboards);
@@ -98,6 +98,10 @@ struct roots_input *input_create(struct roots_server *server,
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);
+
return input;
}
diff --git a/rootston/meson.build b/rootston/meson.build
index 03ca837a..787d0cf1 100644
--- a/rootston/meson.build
+++ b/rootston/meson.build
@@ -1,6 +1,7 @@
executable(
'rootson', [
'config.c',
+ 'cursor.c',
'desktop.c',
'ini.c',
'input.c',
diff --git a/rootston/output.c b/rootston/output.c
index 481832cf..0f015fb6 100644
--- a/rootston/output.c
+++ b/rootston/output.c
@@ -73,6 +73,7 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
void output_add_notify(struct wl_listener *listener, void *data) {
struct wlr_output *wlr_output = data;
struct roots_desktop *desktop = wl_container_of(listener, desktop, output_add);
+ struct roots_input *input = desktop->server->input;
struct roots_config *config = desktop->config;
wlr_log(L_DEBUG, "Output '%s' added", wlr_output->name);
@@ -101,10 +102,9 @@ void output_add_notify(struct wl_listener *listener, void *data) {
wlr_output_layout_add_auto(desktop->layout, wlr_output);
}
- /* TODO: cursor
- example_config_configure_cursor(sample->config, sample->cursor,
- sample->compositor);
+ cursor_load_config(config, input->cursor, input, desktop);
+ struct wlr_xcursor_image *image = input->xcursor->images[0];
// TODO the cursor must be set depending on which surface it is displayed
// over which should happen in the compositor.
if (!wlr_output_set_cursor(wlr_output, image->buffer,
@@ -113,8 +113,7 @@ void output_add_notify(struct wl_listener *listener, void *data) {
return;
}
- wlr_cursor_warp(sample->cursor, NULL, sample->cursor->x, sample->cursor->y);
- */
+ wlr_cursor_warp(input->cursor, NULL, input->cursor->x, input->cursor->y);
}
void output_remove_notify(struct wl_listener *listener, void *data) {
diff --git a/rootston/pointer.c b/rootston/pointer.c
index 84c23d39..1693893e 100644
--- a/rootston/pointer.c
+++ b/rootston/pointer.c
@@ -2,39 +2,14 @@
#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"
-static void pointer_motion_notify(struct wl_listener *listener, void *data) {
- //struct wlr_event_pointer_motion *event = data;
- struct roots_pointer *pointer = wl_container_of(listener, pointer, motion);
-}
-
-static void pointer_motion_absolute_notify(struct wl_listener *listener, void *data) {
- //struct wlr_event_pointer_motion *event = data;
- struct roots_pointer *pointer = wl_container_of(listener, pointer, motion_absolute);
-}
-
void pointer_add(struct wlr_input_device *device, struct roots_input *input) {
struct roots_pointer *pointer = calloc(sizeof(struct roots_pointer), 1);
pointer->device = device;
pointer->input = input;
- wl_list_init(&pointer->motion.link);
- wl_list_init(&pointer->motion_absolute.link);
- wl_list_init(&pointer->button.link);
- wl_list_init(&pointer->axis.link);
- pointer->motion.notify = pointer_motion_notify;
- pointer->motion_absolute.notify = pointer_motion_absolute_notify;
- //pointer->button.notify = pointer_button_notify;
- //pointer->axis.notify = pointer_axis_notify;
- wl_signal_add(&device->pointer->events.motion, &pointer->motion);
- wl_signal_add(&device->pointer->events.motion_absolute, &pointer->motion_absolute);
- wl_signal_add(&device->pointer->events.button, &pointer->button);
- wl_signal_add(&device->pointer->events.axis, &pointer->axis);
wl_list_insert(&input->pointers, &pointer->link);
-
wlr_cursor_attach_input_device(input->cursor, device);
- // TODO: rootston/cursor.c
- //example_config_configure_cursor(sample->config, sample->cursor,
- // sample->compositor);
+ cursor_load_config(input->server->config, input->cursor,
+ input, input->server->desktop);
}