wlroots-hyprland/rootston/seat.c

1643 lines
52 KiB
C
Raw Normal View History

2018-08-16 11:54:45 +02:00
#define _POSIX_C_SOURCE 200112L
2017-11-12 15:55:28 +01:00
#include <assert.h>
2018-06-13 08:11:33 +02:00
#include <libinput.h>
2017-11-03 14:01:34 +01:00
#include <stdlib.h>
2017-11-04 18:12:35 +01:00
#include <string.h>
2018-04-03 18:50:05 +02:00
#include <time.h>
2017-11-12 15:55:28 +01:00
#include <wayland-server.h>
#include <wlr/backend/libinput.h>
2018-06-13 08:11:33 +02:00
#include <wlr/config.h>
#include <wlr/types/wlr_data_device.h>
2018-02-12 21:29:23 +01:00
#include <wlr/types/wlr_idle.h>
2018-09-14 19:32:33 +02:00
#include <wlr/types/wlr_layer_shell_v1.h>
#include <wlr/types/wlr_primary_selection.h>
#include <wlr/types/wlr_switch.h>
2018-04-24 08:10:45 +02:00
#include <wlr/types/wlr_tablet_v2.h>
2018-06-13 08:11:33 +02:00
#include <wlr/types/wlr_xcursor_manager.h>
2017-11-04 18:12:35 +01:00
#include <wlr/util/log.h>
2018-02-12 21:29:23 +01:00
#include "rootston/cursor.h"
2017-11-03 14:01:34 +01:00
#include "rootston/input.h"
#include "rootston/keyboard.h"
2018-02-12 21:29:23 +01:00
#include "rootston/seat.h"
#include "rootston/text_input.h"
2018-02-12 21:29:23 +01:00
#include "rootston/xcursor.h"
2017-11-03 14:01:34 +01:00
static void handle_keyboard_key(struct wl_listener *listener, void *data) {
struct roots_keyboard *keyboard =
wl_container_of(listener, keyboard, keyboard_key);
struct roots_desktop *desktop = keyboard->input->server->desktop;
wlr_idle_notify_activity(desktop->idle, keyboard->seat->seat);
2017-11-03 14:01:34 +01:00
struct wlr_event_keyboard_key *event = data;
roots_keyboard_handle_key(keyboard, event);
}
static void handle_keyboard_modifiers(struct wl_listener *listener,
void *data) {
struct roots_keyboard *keyboard =
wl_container_of(listener, keyboard, keyboard_modifiers);
struct roots_desktop *desktop = keyboard->input->server->desktop;
wlr_idle_notify_activity(desktop->idle, keyboard->seat->seat);
roots_keyboard_handle_modifiers(keyboard);
2017-11-03 14:01:34 +01:00
}
2017-11-04 18:12:35 +01:00
static void handle_cursor_motion(struct wl_listener *listener, void *data) {
2017-11-05 15:20:11 +01:00
struct roots_cursor *cursor =
wl_container_of(listener, cursor, motion);
struct roots_desktop *desktop = cursor->seat->input->server->desktop;
wlr_idle_notify_activity(desktop->idle, cursor->seat->seat);
2017-11-05 15:20:11 +01:00
struct wlr_event_pointer_motion *event = data;
roots_cursor_handle_motion(cursor, event);
2017-11-04 18:12:35 +01:00
}
2017-11-18 20:03:31 +01:00
static void handle_cursor_motion_absolute(struct wl_listener *listener,
void *data) {
2017-11-05 15:20:11 +01:00
struct roots_cursor *cursor =
wl_container_of(listener, cursor, motion_absolute);
struct roots_desktop *desktop = cursor->seat->input->server->desktop;
wlr_idle_notify_activity(desktop->idle, cursor->seat->seat);
2017-11-05 15:20:11 +01:00
struct wlr_event_pointer_motion_absolute *event = data;
roots_cursor_handle_motion_absolute(cursor, event);
2017-11-04 18:12:35 +01:00
}
static void handle_cursor_button(struct wl_listener *listener, void *data) {
2017-11-05 15:20:11 +01:00
struct roots_cursor *cursor =
wl_container_of(listener, cursor, button);
struct roots_desktop *desktop = cursor->seat->input->server->desktop;
wlr_idle_notify_activity(desktop->idle, cursor->seat->seat);
2017-11-05 15:20:11 +01:00
struct wlr_event_pointer_button *event = data;
roots_cursor_handle_button(cursor, event);
2017-11-04 18:12:35 +01:00
}
static void handle_cursor_axis(struct wl_listener *listener, void *data) {
2017-11-05 15:20:11 +01:00
struct roots_cursor *cursor =
wl_container_of(listener, cursor, axis);
struct roots_desktop *desktop = cursor->seat->input->server->desktop;
wlr_idle_notify_activity(desktop->idle, cursor->seat->seat);
2017-11-05 15:20:11 +01:00
struct wlr_event_pointer_axis *event = data;
roots_cursor_handle_axis(cursor, event);
2017-11-04 18:12:35 +01:00
}
static void handle_cursor_frame(struct wl_listener *listener, void *data) {
struct roots_cursor *cursor =
wl_container_of(listener, cursor, frame);
struct roots_desktop *desktop = cursor->seat->input->server->desktop;
wlr_idle_notify_activity(desktop->idle, cursor->seat->seat);
roots_cursor_handle_frame(cursor);
}
static void handle_swipe_begin(struct wl_listener *listener, void *data) {
struct roots_cursor *cursor =
wl_container_of(listener, cursor, swipe_begin);
struct wlr_pointer_gestures_v1 *gestures =
cursor->seat->input->server->desktop->pointer_gestures;
struct wlr_event_pointer_swipe_begin *event = data;
wlr_pointer_gestures_v1_send_swipe_begin(gestures, cursor->seat->seat,
event->time_msec, event->fingers);
}
static void handle_swipe_update(struct wl_listener *listener, void *data) {
struct roots_cursor *cursor =
wl_container_of(listener, cursor, swipe_update);
struct wlr_pointer_gestures_v1 *gestures =
cursor->seat->input->server->desktop->pointer_gestures;
struct wlr_event_pointer_swipe_update *event = data;
wlr_pointer_gestures_v1_send_swipe_update(gestures, cursor->seat->seat,
event->time_msec, event->dx, event->dy);
}
static void handle_swipe_end(struct wl_listener *listener, void *data) {
struct roots_cursor *cursor =
wl_container_of(listener, cursor, swipe_end);
struct wlr_pointer_gestures_v1 *gestures =
cursor->seat->input->server->desktop->pointer_gestures;
struct wlr_event_pointer_swipe_end *event = data;
wlr_pointer_gestures_v1_send_swipe_end(gestures, cursor->seat->seat,
event->time_msec, event->cancelled);
}
static void handle_pinch_begin(struct wl_listener *listener, void *data) {
struct roots_cursor *cursor =
wl_container_of(listener, cursor, pinch_begin);
struct wlr_pointer_gestures_v1 *gestures =
cursor->seat->input->server->desktop->pointer_gestures;
struct wlr_event_pointer_pinch_begin *event = data;
wlr_pointer_gestures_v1_send_pinch_begin(gestures, cursor->seat->seat,
event->time_msec, event->fingers);
}
static void handle_pinch_update(struct wl_listener *listener, void *data) {
struct roots_cursor *cursor =
wl_container_of(listener, cursor, pinch_update);
struct wlr_pointer_gestures_v1 *gestures =
cursor->seat->input->server->desktop->pointer_gestures;
struct wlr_event_pointer_pinch_update *event = data;
wlr_pointer_gestures_v1_send_pinch_update(gestures, cursor->seat->seat,
event->time_msec, event->dx, event->dy,
event->scale, event->rotation);
}
static void handle_pinch_end(struct wl_listener *listener, void *data) {
struct roots_cursor *cursor =
wl_container_of(listener, cursor, pinch_end);
struct wlr_pointer_gestures_v1 *gestures =
cursor->seat->input->server->desktop->pointer_gestures;
struct wlr_event_pointer_pinch_end *event = data;
wlr_pointer_gestures_v1_send_pinch_end(gestures, cursor->seat->seat,
event->time_msec, event->cancelled);
}
static void handle_switch_toggle(struct wl_listener *listener, void *data) {
struct roots_switch *switch_device =
wl_container_of(listener, switch_device, toggle);
struct roots_desktop *desktop = switch_device->seat->input->server->desktop;
wlr_idle_notify_activity(desktop->idle, switch_device->seat->seat);
struct wlr_event_switch_toggle *event = data;
roots_switch_handle_toggle(switch_device, event);
}
2017-11-04 18:12:35 +01:00
static void handle_touch_down(struct wl_listener *listener, void *data) {
2017-11-05 15:20:11 +01:00
struct roots_cursor *cursor =
wl_container_of(listener, cursor, touch_down);
struct roots_desktop *desktop = cursor->seat->input->server->desktop;
wlr_idle_notify_activity(desktop->idle, cursor->seat->seat);
2017-11-05 15:20:11 +01:00
struct wlr_event_touch_down *event = data;
roots_cursor_handle_touch_down(cursor, event);
2017-11-04 18:12:35 +01:00
}
static void handle_touch_up(struct wl_listener *listener, void *data) {
2017-11-05 15:20:11 +01:00
struct roots_cursor *cursor =
wl_container_of(listener, cursor, touch_up);
struct roots_desktop *desktop = cursor->seat->input->server->desktop;
wlr_idle_notify_activity(desktop->idle, cursor->seat->seat);
2017-11-05 15:20:11 +01:00
struct wlr_event_touch_up *event = data;
roots_cursor_handle_touch_up(cursor, event);
2017-11-04 18:12:35 +01:00
}
static void handle_touch_motion(struct wl_listener *listener, void *data) {
2017-11-05 15:20:11 +01:00
struct roots_cursor *cursor =
wl_container_of(listener, cursor, touch_motion);
struct roots_desktop *desktop = cursor->seat->input->server->desktop;
wlr_idle_notify_activity(desktop->idle, cursor->seat->seat);
2017-11-05 15:20:11 +01:00
struct wlr_event_touch_motion *event = data;
roots_cursor_handle_touch_motion(cursor, event);
2017-11-04 18:12:35 +01:00
}
2018-05-02 09:26:34 +02:00
static void handle_tablet_tool_position(struct roots_cursor *cursor,
2018-06-18 09:30:32 +02:00
struct roots_tablet *tablet,
struct wlr_tablet_tool *tool,
2018-05-25 10:04:25 +02:00
bool change_x, bool change_y,
double x, double y, double dx, double dy) {
2018-05-02 09:26:34 +02:00
if (!change_x && !change_y) {
return;
}
2018-06-18 09:30:32 +02:00
switch (tool->type) {
2018-05-25 10:04:25 +02:00
case WLR_TABLET_TOOL_TYPE_MOUSE:
// They are 0 either way when they weren't modified
2018-06-18 09:30:32 +02:00
wlr_cursor_move(cursor->cursor, tablet->device, dx, dy);
2018-05-25 10:04:25 +02:00
break;
default:
2018-06-18 09:30:32 +02:00
wlr_cursor_warp_absolute(cursor->cursor, tablet->device,
2018-05-25 10:04:25 +02:00
change_x ? x : NAN, change_y ? y : NAN);
}
2018-05-02 09:26:34 +02:00
double sx, sy;
struct roots_view *view = NULL;
struct roots_seat *seat = cursor->seat;
struct roots_desktop *desktop = seat->input->server->desktop;
struct wlr_surface *surface = desktop_surface_at(desktop,
cursor->cursor->x, cursor->cursor->y, &sx, &sy, &view);
2018-06-18 09:30:32 +02:00
struct roots_tablet_tool *roots_tool = tool->data;
2018-05-02 09:26:34 +02:00
if (!surface) {
wlr_tablet_v2_tablet_tool_notify_proximity_out(roots_tool->tablet_v2_tool);
2018-05-02 09:26:34 +02:00
/* XXX: TODO: Fallback pointer semantics */
return;
}
2018-06-18 09:30:32 +02:00
if (!wlr_surface_accepts_tablet_v2(tablet->tablet_v2, surface)) {
wlr_tablet_v2_tablet_tool_notify_proximity_out(roots_tool->tablet_v2_tool);
2018-05-02 09:26:34 +02:00
/* XXX: TODO: Fallback pointer semantics */
return;
}
wlr_tablet_v2_tablet_tool_notify_proximity_in(roots_tool->tablet_v2_tool,
2018-06-18 09:30:32 +02:00
tablet->tablet_v2, surface);
2018-05-02 09:26:34 +02:00
wlr_tablet_v2_tablet_tool_notify_motion(roots_tool->tablet_v2_tool, sx, sy);
2018-05-02 09:26:34 +02:00
}
2017-11-04 18:12:35 +01:00
static void handle_tool_axis(struct wl_listener *listener, void *data) {
2017-11-05 15:20:11 +01:00
struct roots_cursor *cursor =
wl_container_of(listener, cursor, tool_axis);
struct roots_desktop *desktop = cursor->seat->input->server->desktop;
wlr_idle_notify_activity(desktop->idle, cursor->seat->seat);
2017-11-05 15:20:11 +01:00
struct wlr_event_tablet_tool_axis *event = data;
2018-06-18 09:30:32 +02:00
struct roots_tablet_tool *roots_tool = event->tool->data;
2018-05-02 09:26:34 +02:00
2018-05-04 11:46:32 +02:00
if (!roots_tool) { // Should this be an assert?
wlr_log(WLR_DEBUG, "Tool Axis, before proximity");
2018-05-02 09:26:34 +02:00
return;
}
/**
* We need to handle them ourselves, not pass it into the cursor
* without any consideration
*/
handle_tablet_tool_position(cursor, event->device->data, event->tool,
event->updated_axes & WLR_TABLET_TOOL_AXIS_X,
event->updated_axes & WLR_TABLET_TOOL_AXIS_Y,
2018-05-25 10:04:25 +02:00
event->x, event->y, event->dx, event->dy);
2018-05-02 09:26:34 +02:00
2018-05-17 12:22:15 +02:00
if (event->updated_axes & WLR_TABLET_TOOL_AXIS_PRESSURE) {
wlr_tablet_v2_tablet_tool_notify_pressure(
2018-06-13 08:11:33 +02:00
roots_tool->tablet_v2_tool, event->pressure);
2018-05-17 12:22:15 +02:00
}
2018-05-02 09:26:34 +02:00
if (event->updated_axes & WLR_TABLET_TOOL_AXIS_DISTANCE) {
wlr_tablet_v2_tablet_tool_notify_distance(
2018-06-13 08:11:33 +02:00
roots_tool->tablet_v2_tool, event->distance);
2018-05-02 09:26:34 +02:00
}
if (event->updated_axes & WLR_TABLET_TOOL_AXIS_TILT_X) {
roots_tool->tilt_x = event->tilt_x;
}
if (event->updated_axes & WLR_TABLET_TOOL_AXIS_TILT_Y) {
roots_tool->tilt_y = event->tilt_y;
}
2018-05-17 12:22:15 +02:00
if (event->updated_axes & (WLR_TABLET_TOOL_AXIS_TILT_X | WLR_TABLET_TOOL_AXIS_TILT_Y)) {
wlr_tablet_v2_tablet_tool_notify_tilt(
roots_tool->tablet_v2_tool,
roots_tool->tilt_x, roots_tool->tilt_y);
2018-05-17 12:22:15 +02:00
}
if (event->updated_axes & WLR_TABLET_TOOL_AXIS_ROTATION) {
wlr_tablet_v2_tablet_tool_notify_rotation(
2018-06-13 08:11:33 +02:00
roots_tool->tablet_v2_tool, event->rotation);
2018-05-17 12:22:15 +02:00
}
if (event->updated_axes & WLR_TABLET_TOOL_AXIS_SLIDER) {
wlr_tablet_v2_tablet_tool_notify_slider(
2018-06-13 08:11:33 +02:00
roots_tool->tablet_v2_tool, event->slider);
2018-05-17 12:22:15 +02:00
}
2018-05-02 09:26:34 +02:00
if (event->updated_axes & WLR_TABLET_TOOL_AXIS_WHEEL) {
wlr_tablet_v2_tablet_tool_notify_wheel(
2018-06-13 08:11:33 +02:00
roots_tool->tablet_v2_tool, event->wheel_delta, 0);
2018-05-02 09:26:34 +02:00
}
2017-11-04 18:12:35 +01:00
}
static void handle_tool_tip(struct wl_listener *listener, void *data) {
2017-11-05 15:20:11 +01:00
struct roots_cursor *cursor =
wl_container_of(listener, cursor, tool_tip);
struct roots_desktop *desktop = cursor->seat->input->server->desktop;
wlr_idle_notify_activity(desktop->idle, cursor->seat->seat);
2017-11-05 15:20:11 +01:00
struct wlr_event_tablet_tool_tip *event = data;
2018-06-18 09:30:32 +02:00
struct roots_tablet_tool *roots_tool = event->tool->data;
2018-05-17 12:22:15 +02:00
if (event->state == WLR_TABLET_TOOL_TIP_DOWN) {
wlr_tablet_v2_tablet_tool_notify_down(roots_tool->tablet_v2_tool);
wlr_tablet_tool_v2_start_implicit_grab(roots_tool->tablet_v2_tool);
2018-05-17 12:22:15 +02:00
} else {
wlr_tablet_v2_tablet_tool_notify_up(roots_tool->tablet_v2_tool);
2018-05-17 12:22:15 +02:00
}
2017-11-04 18:12:35 +01:00
}
2018-06-18 09:30:32 +02:00
static void handle_tablet_tool_destroy(struct wl_listener *listener, void *data) {
struct roots_tablet_tool *tool =
2018-05-02 09:26:34 +02:00
wl_container_of(listener, tool, tool_destroy);
2018-05-02 09:26:34 +02:00
wl_list_remove(&tool->link);
wl_list_remove(&tool->tool_link);
wl_list_remove(&tool->tool_destroy.link);
2018-05-17 09:59:37 +02:00
wl_list_remove(&tool->set_cursor.link);
2018-05-02 09:26:34 +02:00
free(tool);
}
2018-05-04 11:46:32 +02:00
static void handle_tool_button(struct wl_listener *listener, void *data) {
struct roots_cursor *cursor =
wl_container_of(listener, cursor, tool_button);
struct roots_desktop *desktop = cursor->seat->input->server->desktop;
wlr_idle_notify_activity(desktop->idle, cursor->seat->seat);
struct wlr_event_tablet_tool_button *event = data;
2018-06-18 09:30:32 +02:00
struct roots_tablet_tool *roots_tool = event->tool->data;
2018-05-04 11:46:32 +02:00
wlr_tablet_v2_tablet_tool_notify_button(roots_tool->tablet_v2_tool,
2018-05-17 11:15:07 +02:00
(enum zwp_tablet_pad_v2_button_state)event->button,
(enum zwp_tablet_pad_v2_button_state)event->state);
2018-05-04 11:46:32 +02:00
}
2018-05-17 09:59:37 +02:00
static void handle_tablet_tool_set_cursor(struct wl_listener *listener, void *data) {
2018-06-18 09:30:32 +02:00
struct roots_tablet_tool *tool =
2018-05-17 09:59:37 +02:00
wl_container_of(listener, tool, set_cursor);
struct wlr_tablet_v2_event_cursor *evt = data;
struct wlr_seat_pointer_request_set_cursor_event event = {
.surface = evt->surface,
.hotspot_x = evt->hotspot_x,
.hotspot_y = evt->hotspot_y,
.serial = evt->serial,
.seat_client = evt->seat_client,
2018-06-13 08:11:33 +02:00
};
2018-05-17 09:59:37 +02:00
roots_cursor_handle_request_set_cursor(tool->seat->cursor, &event);
}
2018-04-24 08:10:45 +02:00
static void handle_tool_proximity(struct wl_listener *listener, void *data) {
struct roots_cursor *cursor =
wl_container_of(listener, cursor, tool_proximity);
struct roots_desktop *desktop = cursor->seat->input->server->desktop;
wlr_idle_notify_activity(desktop->idle, cursor->seat->seat);
struct wlr_event_tablet_tool_proximity *event = data;
struct wlr_tablet_tool *tool = event->tool;
2018-04-24 08:10:45 +02:00
if (!tool->data) {
2018-06-18 09:30:32 +02:00
struct roots_tablet_tool *roots_tool =
calloc(1, sizeof(struct roots_tablet_tool));
2018-05-02 09:26:34 +02:00
roots_tool->seat = cursor->seat;
tool->data = roots_tool;
roots_tool->tablet_v2_tool =
wlr_tablet_tool_create(desktop->tablet_v2,
cursor->seat->seat, tool);
2018-06-18 09:30:32 +02:00
roots_tool->tool_destroy.notify = handle_tablet_tool_destroy;
2018-05-02 09:26:34 +02:00
wl_signal_add(&tool->events.destroy, &roots_tool->tool_destroy);
2018-05-17 09:59:37 +02:00
roots_tool->set_cursor.notify = handle_tablet_tool_set_cursor;
2018-06-13 08:11:33 +02:00
wl_signal_add(&roots_tool->tablet_v2_tool->events.set_cursor,
&roots_tool->set_cursor);
2018-05-17 09:59:37 +02:00
2018-05-04 19:10:30 +02:00
wl_list_init(&roots_tool->link);
wl_list_init(&roots_tool->tool_link);
2018-04-24 08:10:45 +02:00
}
2018-05-02 09:26:34 +02:00
if (event->state == WLR_TABLET_TOOL_PROXIMITY_OUT) {
struct roots_tablet_tool *roots_tool = tool->data;
wlr_tablet_v2_tablet_tool_notify_proximity_out(roots_tool->tablet_v2_tool);
return;
}
2018-05-02 09:26:34 +02:00
handle_tablet_tool_position(cursor, event->device->data, event->tool,
2018-05-25 10:04:25 +02:00
true, true, event->x, event->y, 0, 0);
2018-04-24 08:10:45 +02:00
}
2017-11-08 21:23:56 +01:00
static void handle_request_set_cursor(struct wl_listener *listener,
void *data) {
struct roots_cursor *cursor =
wl_container_of(listener, cursor, request_set_cursor);
struct roots_desktop *desktop = cursor->seat->input->server->desktop;
wlr_idle_notify_activity(desktop->idle, cursor->seat->seat);
2017-11-08 21:23:56 +01:00
struct wlr_seat_pointer_request_set_cursor_event *event = data;
roots_cursor_handle_request_set_cursor(cursor, event);
}
static void handle_pointer_focus_change(struct wl_listener *listener,
void *data) {
struct roots_cursor *cursor =
wl_container_of(listener, cursor, focus_change);
struct wlr_seat_pointer_focus_change_event *event = data;
roots_cursor_handle_focus_change(cursor, event);
}
2017-11-18 20:03:31 +01:00
static void seat_reset_device_mappings(struct roots_seat *seat,
struct wlr_input_device *device) {
2017-11-05 15:20:11 +01:00
struct wlr_cursor *cursor = seat->cursor->cursor;
2017-11-04 18:12:35 +01:00
struct roots_config *config = seat->input->config;
wlr_cursor_map_input_to_output(cursor, device, NULL);
struct roots_device_config *dconfig;
if ((dconfig = roots_config_get_device(config, device))) {
2017-11-04 18:12:35 +01:00
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) {
2017-11-05 15:20:11 +01:00
struct wlr_cursor *cursor = seat->cursor->cursor;
2017-11-04 18:12:35 +01:00
struct roots_config *config = seat->input->config;
struct roots_device_config *dconfig =
roots_config_get_device(config, device);
const char *mapped_output = NULL;
if (dconfig != NULL) {
mapped_output = dconfig->mapped_output;
}
if (mapped_output == NULL) {
mapped_output = device->output_name;
}
if (mapped_output && strcmp(mapped_output, output->name) == 0) {
2017-11-04 18:12:35 +01:00
wlr_cursor_map_input_to_output(cursor, device, output);
}
}
2017-11-07 21:56:11 +01:00
void roots_seat_configure_cursor(struct roots_seat *seat) {
2017-11-04 18:12:35 +01:00
struct roots_config *config = seat->input->config;
struct roots_desktop *desktop = seat->input->server->desktop;
2017-11-05 15:20:11 +01:00
struct wlr_cursor *cursor = seat->cursor->cursor;
2017-11-04 18:12:35 +01:00
struct roots_pointer *pointer;
struct roots_touch *touch;
2018-06-18 09:30:32 +02:00
struct roots_tablet *tablet;
2017-11-04 18:12:35 +01:00
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);
}
2018-06-18 09:30:32 +02:00
wl_list_for_each(tablet, &seat->tablets, link) {
seat_reset_device_mappings(seat, tablet->device);
2017-11-04 18:12:35 +01:00
}
// configure device to output mappings
2017-11-18 17:34:24 +01:00
const char *mapped_output = NULL;
struct roots_cursor_config *cc =
roots_config_get_cursor(config, seat->seat->name);
if (cc != NULL) {
mapped_output = cc->mapped_output;
}
2017-11-04 18:12:35 +01:00
wl_list_for_each(output, &desktop->outputs, link) {
2017-11-18 17:34:24 +01:00
if (mapped_output &&
strcmp(mapped_output, output->wlr_output->name) == 0) {
2017-11-04 18:12:35 +01:00
wlr_cursor_map_to_output(cursor, output->wlr_output);
}
wl_list_for_each(pointer, &seat->pointers, link) {
2017-11-18 17:34:24 +01:00
seat_set_device_output_mappings(seat, pointer->device,
output->wlr_output);
2017-11-04 18:12:35 +01:00
}
2018-06-18 09:30:32 +02:00
wl_list_for_each(tablet, &seat->tablets, link) {
seat_set_device_output_mappings(seat, tablet->device,
2017-11-18 17:34:24 +01:00
output->wlr_output);
2017-11-04 18:12:35 +01:00
}
wl_list_for_each(touch, &seat->touch, link) {
2017-11-18 17:34:24 +01:00
seat_set_device_output_mappings(seat, touch->device,
output->wlr_output);
2017-11-04 18:12:35 +01:00
}
}
}
static void roots_seat_init_cursor(struct roots_seat *seat) {
2017-11-05 15:20:11 +01:00
seat->cursor = roots_cursor_create(seat);
if (!seat->cursor) {
2017-11-04 18:12:35 +01:00
return;
}
2017-11-07 21:56:11 +01:00
seat->cursor->seat = seat;
2017-11-05 15:20:11 +01:00
struct wlr_cursor *wlr_cursor = seat->cursor->cursor;
2017-11-04 18:12:35 +01:00
struct roots_desktop *desktop = seat->input->server->desktop;
2017-11-05 15:20:11 +01:00
wlr_cursor_attach_output_layout(wlr_cursor, desktop->layout);
2017-11-04 18:12:35 +01:00
2017-11-07 21:56:11 +01:00
roots_seat_configure_cursor(seat);
roots_seat_configure_xcursor(seat);
2017-11-07 21:56:11 +01:00
2017-11-04 18:12:35 +01:00
// add input signals
2017-11-05 15:20:11 +01:00
wl_signal_add(&wlr_cursor->events.motion, &seat->cursor->motion);
seat->cursor->motion.notify = handle_cursor_motion;
2017-11-04 18:12:35 +01:00
2017-11-05 15:20:11 +01:00
wl_signal_add(&wlr_cursor->events.motion_absolute,
&seat->cursor->motion_absolute);
seat->cursor->motion_absolute.notify = handle_cursor_motion_absolute;
2017-11-04 18:12:35 +01:00
2017-11-05 15:20:11 +01:00
wl_signal_add(&wlr_cursor->events.button, &seat->cursor->button);
seat->cursor->button.notify = handle_cursor_button;
2017-11-04 18:12:35 +01:00
2017-11-05 15:20:11 +01:00
wl_signal_add(&wlr_cursor->events.axis, &seat->cursor->axis);
seat->cursor->axis.notify = handle_cursor_axis;
2017-11-04 18:12:35 +01:00
wl_signal_add(&wlr_cursor->events.frame, &seat->cursor->frame);
seat->cursor->frame.notify = handle_cursor_frame;
wl_signal_add(&wlr_cursor->events.swipe_begin, &seat->cursor->swipe_begin);
seat->cursor->swipe_begin.notify = handle_swipe_begin;
wl_signal_add(&wlr_cursor->events.swipe_update, &seat->cursor->swipe_update);
seat->cursor->swipe_update.notify = handle_swipe_update;
wl_signal_add(&wlr_cursor->events.swipe_end, &seat->cursor->swipe_end);
seat->cursor->swipe_end.notify = handle_swipe_end;
wl_signal_add(&wlr_cursor->events.pinch_begin, &seat->cursor->pinch_begin);
seat->cursor->pinch_begin.notify = handle_pinch_begin;
wl_signal_add(&wlr_cursor->events.pinch_update, &seat->cursor->pinch_update);
seat->cursor->pinch_update.notify = handle_pinch_update;
wl_signal_add(&wlr_cursor->events.pinch_end, &seat->cursor->pinch_end);
seat->cursor->pinch_end.notify = handle_pinch_end;
2017-11-05 15:20:11 +01:00
wl_signal_add(&wlr_cursor->events.touch_down, &seat->cursor->touch_down);
seat->cursor->touch_down.notify = handle_touch_down;
2017-11-04 18:12:35 +01:00
2017-11-05 15:20:11 +01:00
wl_signal_add(&wlr_cursor->events.touch_up, &seat->cursor->touch_up);
seat->cursor->touch_up.notify = handle_touch_up;
2017-11-04 18:12:35 +01:00
2017-11-18 20:03:31 +01:00
wl_signal_add(&wlr_cursor->events.touch_motion,
&seat->cursor->touch_motion);
2017-11-05 15:20:11 +01:00
seat->cursor->touch_motion.notify = handle_touch_motion;
2017-11-04 18:12:35 +01:00
2017-11-18 20:03:31 +01:00
wl_signal_add(&wlr_cursor->events.tablet_tool_axis,
&seat->cursor->tool_axis);
2017-11-05 15:20:11 +01:00
seat->cursor->tool_axis.notify = handle_tool_axis;
2017-11-04 18:12:35 +01:00
2017-11-05 15:20:11 +01:00
wl_signal_add(&wlr_cursor->events.tablet_tool_tip, &seat->cursor->tool_tip);
seat->cursor->tool_tip.notify = handle_tool_tip;
2017-11-08 21:23:56 +01:00
2018-04-24 08:10:45 +02:00
wl_signal_add(&wlr_cursor->events.tablet_tool_proximity, &seat->cursor->tool_proximity);
seat->cursor->tool_proximity.notify = handle_tool_proximity;
2018-05-04 11:46:32 +02:00
wl_signal_add(&wlr_cursor->events.tablet_tool_button, &seat->cursor->tool_button);
seat->cursor->tool_button.notify = handle_tool_button;
2017-11-08 21:23:56 +01:00
wl_signal_add(&seat->seat->events.request_set_cursor,
&seat->cursor->request_set_cursor);
2017-11-08 21:23:56 +01:00
seat->cursor->request_set_cursor.notify = handle_request_set_cursor;
wl_signal_add(&seat->seat->pointer_state.events.focus_change,
&seat->cursor->focus_change);
seat->cursor->focus_change.notify = handle_pointer_focus_change;
wl_list_init(&seat->cursor->constraint_commit.link);
2017-11-04 18:12:35 +01:00
}
static void roots_drag_icon_handle_surface_commit(struct wl_listener *listener,
void *data) {
struct roots_drag_icon *icon =
wl_container_of(listener, icon, surface_commit);
roots_drag_icon_update_position(icon);
}
2018-06-06 05:01:43 +02:00
static void roots_drag_icon_handle_map(struct wl_listener *listener,
void *data) {
struct roots_drag_icon *icon =
wl_container_of(listener, icon, map);
roots_drag_icon_damage_whole(icon);
}
2018-06-06 00:17:42 +02:00
static void roots_drag_icon_handle_unmap(struct wl_listener *listener,
void *data) {
struct roots_drag_icon *icon =
2018-06-06 00:17:42 +02:00
wl_container_of(listener, icon, unmap);
roots_drag_icon_damage_whole(icon);
}
static void roots_drag_icon_handle_destroy(struct wl_listener *listener,
void *data) {
struct roots_drag_icon *icon =
wl_container_of(listener, icon, destroy);
roots_drag_icon_damage_whole(icon);
assert(icon->seat->drag_icon == icon);
icon->seat->drag_icon = NULL;
wl_list_remove(&icon->surface_commit.link);
2018-06-06 00:17:42 +02:00
wl_list_remove(&icon->unmap.link);
wl_list_remove(&icon->destroy.link);
free(icon);
}
2019-01-30 18:36:19 +01:00
static void roots_seat_handle_request_start_drag(struct wl_listener *listener,
void *data) {
2019-01-30 18:36:19 +01:00
struct roots_seat *seat =
wl_container_of(listener, seat, request_start_drag);
struct wlr_seat_request_start_drag_event *event = data;
if (wlr_seat_validate_pointer_grab_serial(seat->seat,
event->origin, event->serial)) {
wlr_seat_start_pointer_drag(seat->seat, event->drag, event->serial);
return;
}
struct wlr_touch_point *point;
if (wlr_seat_validate_touch_grab_serial(seat->seat,
event->origin, event->serial, &point)) {
wlr_seat_start_touch_drag(seat->seat, event->drag, event->serial, point);
return;
}
wlr_log(WLR_DEBUG, "Ignoring start_drag request: "
"could not validate pointer or touch serial %" PRIu32, event->serial);
wlr_data_source_destroy(event->drag->source);
2019-01-30 18:36:19 +01:00
}
static void roots_seat_handle_start_drag(struct wl_listener *listener,
void *data) {
struct roots_seat *seat = wl_container_of(listener, seat, start_drag);
struct wlr_drag *wlr_drag = data;
struct wlr_drag_icon *wlr_drag_icon = wlr_drag->icon;
if (wlr_drag_icon == NULL) {
return;
}
struct roots_drag_icon *icon = calloc(1, sizeof(struct roots_drag_icon));
if (icon == NULL) {
return;
}
icon->seat = seat;
icon->wlr_drag_icon = wlr_drag_icon;
icon->surface_commit.notify = roots_drag_icon_handle_surface_commit;
wl_signal_add(&wlr_drag_icon->surface->events.commit, &icon->surface_commit);
2018-06-06 00:17:42 +02:00
icon->unmap.notify = roots_drag_icon_handle_unmap;
wl_signal_add(&wlr_drag_icon->events.unmap, &icon->unmap);
2018-06-06 05:01:43 +02:00
icon->map.notify = roots_drag_icon_handle_map;
wl_signal_add(&wlr_drag_icon->events.map, &icon->map);
icon->destroy.notify = roots_drag_icon_handle_destroy;
wl_signal_add(&wlr_drag_icon->events.destroy, &icon->destroy);
assert(seat->drag_icon == NULL);
seat->drag_icon = icon;
roots_drag_icon_update_position(icon);
}
static void roots_seat_handle_request_set_selection(
struct wl_listener *listener, void *data) {
struct roots_seat *seat =
wl_container_of(listener, seat, request_set_selection);
struct wlr_seat_request_set_selection_event *event = data;
wlr_seat_set_selection(seat->seat, event->source, event->serial);
}
static void roots_seat_handle_request_set_primary_selection(
struct wl_listener *listener, void *data) {
struct roots_seat *seat =
wl_container_of(listener, seat, request_set_primary_selection);
struct wlr_seat_request_set_primary_selection_event *event = data;
wlr_seat_set_primary_selection(seat->seat, event->source, event->serial);
}
void roots_drag_icon_update_position(struct roots_drag_icon *icon) {
roots_drag_icon_damage_whole(icon);
struct roots_seat *seat = icon->seat;
2019-01-30 18:36:19 +01:00
struct wlr_drag *wlr_drag = icon->wlr_drag_icon->drag;
assert(wlr_drag != NULL);
switch (seat->seat->drag->grab_type) {
case WLR_DRAG_GRAB_KEYBOARD:
assert(false);
case WLR_DRAG_GRAB_KEYBOARD_POINTER:;
struct wlr_cursor *cursor = seat->cursor->cursor;
icon->x = cursor->x;
icon->y = cursor->y;
2019-01-30 18:36:19 +01:00
break;
case WLR_DRAG_GRAB_KEYBOARD_TOUCH:;
struct wlr_touch_point *point =
2019-01-30 18:36:19 +01:00
wlr_seat_touch_get_point(seat->seat, wlr_drag->touch_id);
if (point == NULL) {
return;
}
icon->x = seat->touch_x;
icon->y = seat->touch_y;
2019-01-30 18:36:19 +01:00
break;
}
roots_drag_icon_damage_whole(icon);
}
void roots_drag_icon_damage_whole(struct roots_drag_icon *icon) {
struct roots_output *output;
wl_list_for_each(output, &icon->seat->input->server->desktop->outputs,
link) {
output_damage_whole_drag_icon(output, icon);
}
}
static void seat_view_destroy(struct roots_seat_view *seat_view);
static void roots_seat_handle_destroy(struct wl_listener *listener,
void *data) {
struct roots_seat *seat = wl_container_of(listener, seat, destroy);
// TODO: probably more to be freed here
wl_list_remove(&seat->destroy.link);
struct roots_seat_view *view, *nview;
wl_list_for_each_safe(view, nview, &seat->views, link) {
seat_view_destroy(view);
}
}
void roots_seat_destroy(struct roots_seat *seat) {
roots_seat_handle_destroy(&seat->destroy, seat->seat);
wlr_seat_destroy(seat->seat);
}
2017-11-03 14:01:34 +01:00
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;
}
2017-11-07 21:56:11 +01:00
wl_list_init(&seat->keyboards);
wl_list_init(&seat->pointers);
wl_list_init(&seat->touch);
2018-06-18 09:30:32 +02:00
wl_list_init(&seat->tablets);
wl_list_init(&seat->tablet_pads);
wl_list_init(&seat->switches);
2017-11-17 12:45:07 +01:00
wl_list_init(&seat->views);
2017-11-07 21:56:11 +01:00
2017-11-05 15:20:11 +01:00
seat->input = input;
2017-11-08 21:23:56 +01:00
seat->seat = wlr_seat_create(input->server->wl_display, name);
if (!seat->seat) {
2017-11-04 18:12:35 +01:00
free(seat);
return NULL;
}
seat->seat->data = seat;
2017-11-04 18:12:35 +01:00
2017-11-08 21:23:56 +01:00
roots_seat_init_cursor(seat);
if (!seat->cursor) {
wlr_seat_destroy(seat->seat);
2017-11-04 18:12:35 +01:00
free(seat);
return NULL;
}
roots_input_method_relay_init(seat, &seat->im_relay);
2017-11-03 14:01:34 +01:00
wl_list_insert(&input->seats, &seat->link);
2017-11-05 15:20:11 +01:00
seat->request_set_selection.notify =
roots_seat_handle_request_set_selection;
wl_signal_add(&seat->seat->events.request_set_selection,
&seat->request_set_selection);
seat->request_set_primary_selection.notify =
roots_seat_handle_request_set_primary_selection;
wl_signal_add(&seat->seat->events.request_set_primary_selection,
&seat->request_set_primary_selection);
2019-01-30 18:36:19 +01:00
seat->request_start_drag.notify = roots_seat_handle_request_start_drag;
wl_signal_add(&seat->seat->events.request_start_drag,
&seat->request_start_drag);
seat->start_drag.notify = roots_seat_handle_start_drag;
wl_signal_add(&seat->seat->events.start_drag, &seat->start_drag);
seat->destroy.notify = roots_seat_handle_destroy;
wl_signal_add(&seat->seat->events.destroy, &seat->destroy);
2017-11-03 14:01:34 +01:00
return seat;
2017-11-03 14:01:34 +01:00
}
2018-01-16 20:33:55 +01:00
static void seat_update_capabilities(struct roots_seat *seat) {
uint32_t caps = 0;
if (!wl_list_empty(&seat->keyboards)) {
caps |= WL_SEAT_CAPABILITY_KEYBOARD;
}
2018-06-18 09:30:32 +02:00
if (!wl_list_empty(&seat->pointers) || !wl_list_empty(&seat->tablets)) {
2018-01-16 20:33:55 +01:00
caps |= WL_SEAT_CAPABILITY_POINTER;
}
if (!wl_list_empty(&seat->touch)) {
caps |= WL_SEAT_CAPABILITY_TOUCH;
}
wlr_seat_set_capabilities(seat->seat, caps);
// Hide cursor if seat doesn't have pointer capability
if ((caps & WL_SEAT_CAPABILITY_POINTER) == 0) {
wlr_cursor_set_image(seat->cursor->cursor, NULL, 0, 0, 0, 0, 0, 0);
} else {
wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager,
seat->cursor->default_xcursor, seat->cursor->cursor);
}
2018-01-16 20:33:55 +01:00
}
static void handle_keyboard_destroy(struct wl_listener *listener, void *data) {
struct roots_keyboard *keyboard =
wl_container_of(listener, keyboard, device_destroy);
struct roots_seat *seat = keyboard->seat;
wl_list_remove(&keyboard->device_destroy.link);
wl_list_remove(&keyboard->keyboard_key.link);
wl_list_remove(&keyboard->keyboard_modifiers.link);
roots_keyboard_destroy(keyboard);
seat_update_capabilities(seat);
}
2017-11-18 20:03:31 +01:00
static void seat_add_keyboard(struct roots_seat *seat,
struct wlr_input_device *device) {
2017-11-07 21:56:11 +01:00
assert(device->type == WLR_INPUT_DEVICE_KEYBOARD);
2017-11-18 20:03:31 +01:00
struct roots_keyboard *keyboard =
roots_keyboard_create(device, seat->input);
2017-11-10 00:32:54 +01:00
if (keyboard == NULL) {
2018-07-09 23:49:54 +02:00
wlr_log(WLR_ERROR, "could not allocate keyboard for seat");
2017-11-10 00:32:54 +01:00
return;
}
2017-11-03 14:01:34 +01:00
keyboard->seat = seat;
2017-11-04 18:12:35 +01:00
2017-11-08 15:04:33 +01:00
wl_list_insert(&seat->keyboards, &keyboard->link);
2017-11-03 14:01:34 +01:00
keyboard->device_destroy.notify = handle_keyboard_destroy;
wl_signal_add(&keyboard->device->events.destroy, &keyboard->device_destroy);
2017-11-03 14:01:34 +01:00
keyboard->keyboard_key.notify = handle_keyboard_key;
wl_signal_add(&keyboard->device->keyboard->events.key,
&keyboard->keyboard_key);
keyboard->keyboard_modifiers.notify = handle_keyboard_modifiers;
wl_signal_add(&keyboard->device->keyboard->events.modifiers,
&keyboard->keyboard_modifiers);
2017-11-12 18:15:39 +01:00
wlr_seat_set_keyboard(seat->seat, device);
2017-11-03 14:01:34 +01:00
}
static void handle_pointer_destroy(struct wl_listener *listener, void *data) {
struct roots_pointer *pointer =
wl_container_of(listener, pointer, device_destroy);
struct roots_seat *seat = pointer->seat;
wl_list_remove(&pointer->link);
wlr_cursor_detach_input_device(seat->cursor->cursor, pointer->device);
wl_list_remove(&pointer->device_destroy.link);
free(pointer);
seat_update_capabilities(seat);
}
2017-11-18 20:03:31 +01:00
static void seat_add_pointer(struct roots_seat *seat,
struct wlr_input_device *device) {
2018-06-13 08:11:33 +02:00
struct roots_pointer *pointer = calloc(1, sizeof(struct roots_pointer));
2017-11-04 18:12:35 +01:00
if (!pointer) {
2018-07-09 23:49:54 +02:00
wlr_log(WLR_ERROR, "could not allocate pointer for seat");
2017-11-04 18:12:35 +01:00
return;
}
device->data = pointer;
pointer->device = device;
pointer->seat = seat;
wl_list_insert(&seat->pointers, &pointer->link);
pointer->device_destroy.notify = handle_pointer_destroy;
wl_signal_add(&pointer->device->events.destroy, &pointer->device_destroy);
2017-11-05 15:20:11 +01:00
wlr_cursor_attach_input_device(seat->cursor->cursor, device);
2017-11-04 18:12:35 +01:00
roots_seat_configure_cursor(seat);
}
static void handle_switch_destroy(struct wl_listener *listener, void *data) {
struct roots_switch *switch_device =
wl_container_of(listener, switch_device, device_destroy);
struct roots_seat *seat = switch_device->seat;
wl_list_remove(&switch_device->link);
wl_list_remove(&switch_device->device_destroy.link);
free(switch_device);
seat_update_capabilities(seat);
}
static void seat_add_switch(struct roots_seat *seat,
struct wlr_input_device *device) {
assert(device->type == WLR_INPUT_DEVICE_SWITCH);
struct roots_switch *switch_device = calloc(1, sizeof(struct roots_switch));
if (!switch_device) {
wlr_log(WLR_ERROR, "could not allocate switch for seat");
return;
}
device->data = switch_device;
switch_device->device = device;
switch_device->seat = seat;
wl_list_insert(&seat->switches, &switch_device->link);
switch_device->device_destroy.notify = handle_switch_destroy;
switch_device->toggle.notify = handle_switch_toggle;
wl_signal_add(&switch_device->device->switch_device->events.toggle, &switch_device->toggle);
}
static void handle_touch_destroy(struct wl_listener *listener, void *data) {
struct roots_pointer *touch =
wl_container_of(listener, touch, device_destroy);
struct roots_seat *seat = touch->seat;
wl_list_remove(&touch->link);
wlr_cursor_detach_input_device(seat->cursor->cursor, touch->device);
wl_list_remove(&touch->device_destroy.link);
free(touch);
seat_update_capabilities(seat);
}
2017-11-18 20:03:31 +01:00
static void seat_add_touch(struct roots_seat *seat,
struct wlr_input_device *device) {
2018-06-13 08:11:33 +02:00
struct roots_touch *touch = calloc(1, sizeof(struct roots_touch));
2017-11-04 18:12:35 +01:00
if (!touch) {
2018-07-09 23:49:54 +02:00
wlr_log(WLR_ERROR, "could not allocate touch for seat");
2017-11-04 18:12:35 +01:00
return;
}
device->data = touch;
touch->device = device;
touch->seat = seat;
wl_list_insert(&seat->touch, &touch->link);
touch->device_destroy.notify = handle_touch_destroy;
wl_signal_add(&touch->device->events.destroy, &touch->device_destroy);
2017-11-05 15:20:11 +01:00
wlr_cursor_attach_input_device(seat->cursor->cursor, device);
2017-11-04 18:12:35 +01:00
roots_seat_configure_cursor(seat);
}
static void handle_tablet_pad_destroy(struct wl_listener *listener,
void *data) {
struct roots_tablet_pad *tablet_pad =
wl_container_of(listener, tablet_pad, device_destroy);
struct roots_seat *seat = tablet_pad->seat;
wl_list_remove(&tablet_pad->device_destroy.link);
wl_list_remove(&tablet_pad->tablet_destroy.link);
wl_list_remove(&tablet_pad->attach.link);
wl_list_remove(&tablet_pad->link);
wl_list_remove(&tablet_pad->button.link);
wl_list_remove(&tablet_pad->strip.link);
wl_list_remove(&tablet_pad->ring.link);
free(tablet_pad);
seat_update_capabilities(seat);
}
static void handle_pad_tool_destroy(struct wl_listener *listener, void *data) {
struct roots_tablet_pad *pad =
wl_container_of(listener, pad, tablet_destroy);
pad->tablet = NULL;
wl_list_remove(&pad->tablet_destroy.link);
wl_list_init(&pad->tablet_destroy.link);
}
static void attach_tablet_pad(struct roots_tablet_pad *pad,
2018-06-18 09:30:32 +02:00
struct roots_tablet *tool) {
wlr_log(WLR_DEBUG, "Attaching tablet pad \"%s\" to tablet tool \"%s\"",
pad->device->name, tool->device->name);
pad->tablet = tool;
wl_list_remove(&pad->tablet_destroy.link);
2018-06-13 08:11:33 +02:00
pad->tablet_destroy.notify = handle_pad_tool_destroy;
wl_signal_add(&tool->device->events.destroy, &pad->tablet_destroy);
}
static void handle_tablet_pad_attach(struct wl_listener *listener, void *data) {
struct roots_tablet_pad *pad =
wl_container_of(listener, pad, attach);
struct wlr_tablet_tool *wlr_tool = data;
2018-06-18 09:30:32 +02:00
struct roots_tablet *tool = wlr_tool->data;
attach_tablet_pad(pad, tool);
}
static void handle_tablet_pad_ring(struct wl_listener *listener, void *data) {
struct roots_tablet_pad *pad =
wl_container_of(listener, pad, ring);
struct wlr_event_tablet_pad_ring *event = data;
wlr_tablet_v2_tablet_pad_notify_ring(pad->tablet_v2_pad,
event->ring, event->position,
event->source == WLR_TABLET_PAD_RING_SOURCE_FINGER,
event->time_msec);
}
static void handle_tablet_pad_strip(struct wl_listener *listener, void *data) {
struct roots_tablet_pad *pad =
wl_container_of(listener, pad, strip);
struct wlr_event_tablet_pad_strip *event = data;
wlr_tablet_v2_tablet_pad_notify_strip(pad->tablet_v2_pad,
event->strip, event->position,
event->source == WLR_TABLET_PAD_STRIP_SOURCE_FINGER,
event->time_msec);
}
static void handle_tablet_pad_button(struct wl_listener *listener, void *data) {
struct roots_tablet_pad *pad =
wl_container_of(listener, pad, button);
struct wlr_event_tablet_pad_button *event = data;
wlr_tablet_v2_tablet_pad_notify_mode(pad->tablet_v2_pad,
event->group, event->mode, event->time_msec);
wlr_tablet_v2_tablet_pad_notify_button(pad->tablet_v2_pad,
2018-05-17 11:15:07 +02:00
event->button, event->time_msec,
(enum zwp_tablet_pad_v2_button_state)event->state);
}
2017-11-18 20:03:31 +01:00
static void seat_add_tablet_pad(struct roots_seat *seat,
struct wlr_input_device *device) {
struct roots_tablet_pad *tablet_pad =
2018-06-13 08:11:33 +02:00
calloc(1, sizeof(struct roots_tablet_pad));
if (!tablet_pad) {
wlr_log(WLR_ERROR, "could not allocate tablet_pad for seat");
return;
}
device->data = tablet_pad;
tablet_pad->device = device;
tablet_pad->seat = seat;
wl_list_insert(&seat->tablet_pads, &tablet_pad->link);
tablet_pad->device_destroy.notify = handle_tablet_pad_destroy;
wl_signal_add(&tablet_pad->device->events.destroy,
&tablet_pad->device_destroy);
tablet_pad->attach.notify = handle_tablet_pad_attach;
wl_signal_add(&tablet_pad->device->tablet_pad->events.attach_tablet,
&tablet_pad->attach);
tablet_pad->button.notify = handle_tablet_pad_button;
wl_signal_add(&tablet_pad->device->tablet_pad->events.button, &tablet_pad->button);
tablet_pad->strip.notify = handle_tablet_pad_strip;
wl_signal_add(&tablet_pad->device->tablet_pad->events.strip, &tablet_pad->strip);
tablet_pad->ring.notify = handle_tablet_pad_ring;
wl_signal_add(&tablet_pad->device->tablet_pad->events.ring, &tablet_pad->ring);
wl_list_init(&tablet_pad->tablet_destroy.link);
2018-04-24 08:10:45 +02:00
struct roots_desktop *desktop = seat->input->server->desktop;
tablet_pad->tablet_v2_pad =
wlr_tablet_pad_create(desktop->tablet_v2, seat->seat, device);
/* Search for a sibling tablet */
if (!wlr_input_device_is_libinput(device)) {
/* We can only do this on libinput devices */
return;
}
2018-04-24 08:10:45 +02:00
struct libinput_device_group *group =
libinput_device_get_device_group(wlr_libinput_get_device_handle(device));
2018-06-18 09:30:32 +02:00
struct roots_tablet *tool;
wl_list_for_each(tool, &seat->tablets, link) {
if (!wlr_input_device_is_libinput(tool->device)) {
continue;
}
struct libinput_device *li_dev =
wlr_libinput_get_device_handle(tool->device);
if (libinput_device_get_device_group(li_dev) == group) {
attach_tablet_pad(tablet_pad, tool);
break;
}
}
2017-11-03 14:01:34 +01:00
}
2018-06-18 09:30:32 +02:00
static void handle_tablet_destroy(struct wl_listener *listener,
void *data) {
2018-06-18 09:30:32 +02:00
struct roots_tablet *tablet =
wl_container_of(listener, tablet, device_destroy);
struct roots_seat *seat = tablet->seat;
2018-06-18 09:30:32 +02:00
wlr_cursor_detach_input_device(seat->cursor->cursor, tablet->device);
wl_list_remove(&tablet->device_destroy.link);
wl_list_remove(&tablet->link);
free(tablet);
seat_update_capabilities(seat);
}
2017-11-18 20:03:31 +01:00
static void seat_add_tablet_tool(struct roots_seat *seat,
struct wlr_input_device *device) {
2018-06-18 09:30:32 +02:00
struct roots_tablet *tablet =
calloc(1, sizeof(struct roots_tablet));
if (!tablet) {
wlr_log(WLR_ERROR, "could not allocate tablet for seat");
2017-11-04 18:12:35 +01:00
return;
}
2018-06-18 09:30:32 +02:00
device->data = tablet;
tablet->device = device;
tablet->seat = seat;
wl_list_insert(&seat->tablets, &tablet->link);
2018-06-18 09:30:32 +02:00
tablet->device_destroy.notify = handle_tablet_destroy;
wl_signal_add(&tablet->device->events.destroy,
&tablet->device_destroy);
2017-11-05 15:20:11 +01:00
wlr_cursor_attach_input_device(seat->cursor->cursor, device);
2017-11-04 18:12:35 +01:00
roots_seat_configure_cursor(seat);
2018-04-24 08:10:45 +02:00
struct roots_desktop *desktop = seat->input->server->desktop;
2018-06-18 09:30:32 +02:00
tablet->tablet_v2 =
wlr_tablet_create(desktop->tablet_v2, seat->seat, device);
struct libinput_device_group *group =
libinput_device_get_device_group(wlr_libinput_get_device_handle(device));
struct roots_tablet_pad *pad;
wl_list_for_each(pad, &seat->tablet_pads, link) {
if (!wlr_input_device_is_libinput(pad->device)) {
continue;
}
struct libinput_device *li_dev =
wlr_libinput_get_device_handle(pad->device);
if (libinput_device_get_device_group(li_dev) == group) {
2018-06-18 09:30:32 +02:00
attach_tablet_pad(pad, tablet);
}
}
2017-11-04 18:12:35 +01:00
}
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_SWITCH:
seat_add_switch(seat, device);
break;
2017-11-04 18:12:35 +01:00
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;
}
2018-01-16 20:33:55 +01:00
seat_update_capabilities(seat);
2017-11-04 18:12:35 +01:00
}
2017-11-07 21:56:11 +01:00
void roots_seat_configure_xcursor(struct roots_seat *seat) {
2017-11-18 17:34:24 +01:00
const char *cursor_theme = NULL;
struct roots_cursor_config *cc =
roots_config_get_cursor(seat->input->config, seat->seat->name);
if (cc != NULL) {
cursor_theme = cc->theme;
2017-12-11 10:36:22 +01:00
if (cc->default_image != NULL) {
seat->cursor->default_xcursor = cc->default_image;
}
2017-11-18 17:34:24 +01:00
}
2017-12-09 18:10:09 +01:00
if (!seat->cursor->xcursor_manager) {
seat->cursor->xcursor_manager =
wlr_xcursor_manager_create(cursor_theme, ROOTS_XCURSOR_SIZE);
if (seat->cursor->xcursor_manager == NULL) {
2018-07-09 23:49:54 +02:00
wlr_log(WLR_ERROR, "Cannot create XCursor manager for theme %s",
2017-12-09 18:10:09 +01:00
cursor_theme);
return;
}
2017-11-18 17:34:24 +01:00
}
struct roots_output *output;
wl_list_for_each(output, &seat->input->server->desktop->outputs, link) {
2017-12-15 01:00:03 +01:00
float scale = output->wlr_output->scale;
if (wlr_xcursor_manager_load(seat->cursor->xcursor_manager, scale)) {
2018-07-09 23:49:54 +02:00
wlr_log(WLR_ERROR, "Cannot load xcursor theme for output '%s' "
2017-12-15 01:00:03 +01:00
"with scale %f", output->wlr_output->name, scale);
}
}
2017-11-12 11:10:56 +01:00
wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager,
2017-12-11 10:36:22 +01:00
seat->cursor->default_xcursor, seat->cursor->cursor);
2017-11-07 21:56:11 +01:00
wlr_cursor_warp(seat->cursor->cursor, NULL, seat->cursor->cursor->x,
seat->cursor->cursor->y);
}
bool roots_seat_has_meta_pressed(struct roots_seat *seat) {
struct roots_keyboard *keyboard;
2017-11-08 15:04:33 +01:00
wl_list_for_each(keyboard, &seat->keyboards, link) {
2017-11-07 21:56:11 +01:00
if (!keyboard->config->meta_key) {
continue;
}
uint32_t modifiers =
wlr_keyboard_get_modifiers(keyboard->device->keyboard);
if ((modifiers ^ keyboard->config->meta_key) == 0) {
return true;
}
}
return false;
}
struct roots_view *roots_seat_get_focus(struct roots_seat *seat) {
2017-11-19 18:15:11 +01:00
if (!seat->has_focus || wl_list_empty(&seat->views)) {
return NULL;
2017-11-07 21:56:11 +01:00
}
2017-11-19 18:15:11 +01:00
struct roots_seat_view *seat_view =
wl_container_of(seat->views.next, seat_view, link);
return seat_view->view;
2017-11-17 12:45:07 +01:00
}
static void seat_view_destroy(struct roots_seat_view *seat_view) {
struct roots_seat *seat = seat_view->seat;
if (seat_view->view == roots_seat_get_focus(seat)) {
2017-11-19 18:15:11 +01:00
seat->has_focus = false;
2017-11-17 12:45:07 +01:00
seat->cursor->mode = ROOTS_CURSOR_PASSTHROUGH;
}
2018-01-23 13:11:54 +01:00
if (seat_view == seat->cursor->pointer_view) {
seat->cursor->pointer_view = NULL;
}
2018-03-13 12:31:45 +01:00
wl_list_remove(&seat_view->view_unmap.link);
wl_list_remove(&seat_view->view_destroy.link);
2017-11-17 12:45:07 +01:00
wl_list_remove(&seat_view->link);
free(seat_view);
// Focus first view
if (!wl_list_empty(&seat->views)) {
struct roots_seat_view *first_seat_view = wl_container_of(
seat->views.next, first_seat_view, link);
2017-11-19 19:21:18 +01:00
roots_seat_set_focus(seat, first_seat_view->view);
2017-11-17 12:45:07 +01:00
}
}
2018-03-13 12:31:45 +01:00
static void seat_view_handle_unmap(struct wl_listener *listener, void *data) {
struct roots_seat_view *seat_view =
wl_container_of(listener, seat_view, view_unmap);
seat_view_destroy(seat_view);
}
2017-11-17 12:45:07 +01:00
static void seat_view_handle_destroy(struct wl_listener *listener, void *data) {
struct roots_seat_view *seat_view =
wl_container_of(listener, seat_view, view_destroy);
2017-11-17 12:45:07 +01:00
seat_view_destroy(seat_view);
}
2017-11-19 18:15:11 +01:00
static struct roots_seat_view *seat_add_view(struct roots_seat *seat,
struct roots_view *view) {
2017-11-17 12:45:07 +01:00
struct roots_seat_view *seat_view =
calloc(1, sizeof(struct roots_seat_view));
if (seat_view == NULL) {
2017-11-19 18:15:11 +01:00
return NULL;
2017-11-17 12:45:07 +01:00
}
seat_view->seat = seat;
seat_view->view = view;
2018-01-17 01:04:26 +01:00
wl_list_insert(seat->views.prev, &seat_view->link);
2017-11-17 12:45:07 +01:00
2018-03-13 12:31:45 +01:00
seat_view->view_unmap.notify = seat_view_handle_unmap;
wl_signal_add(&view->events.unmap, &seat_view->view_unmap);
seat_view->view_destroy.notify = seat_view_handle_destroy;
wl_signal_add(&view->events.destroy, &seat_view->view_destroy);
2017-11-19 18:15:11 +01:00
return seat_view;
2017-11-17 12:45:07 +01:00
}
2018-01-17 01:04:26 +01:00
struct roots_seat_view *roots_seat_view_from_view(
struct roots_seat *seat, struct roots_view *view) {
if (view == NULL) {
return NULL;
}
bool found = false;
struct roots_seat_view *seat_view = NULL;
wl_list_for_each(seat_view, &seat->views, link) {
if (seat_view->view == view) {
found = true;
break;
}
}
if (!found) {
seat_view = seat_add_view(seat, view);
if (seat_view == NULL) {
2018-07-09 23:49:54 +02:00
wlr_log(WLR_ERROR, "Allocation failed");
2018-01-17 01:04:26 +01:00
return NULL;
}
}
return seat_view;
}
2018-04-03 18:50:05 +02:00
bool roots_seat_allow_input(struct roots_seat *seat,
struct wl_resource *resource) {
return !seat->exclusive_client ||
wl_resource_get_client(resource) == seat->exclusive_client;
}
2017-11-19 19:21:18 +01:00
void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) {
2018-04-03 18:50:05 +02:00
if (view && !roots_seat_allow_input(seat, view->wlr_surface->resource)) {
return;
}
// Make sure the view will be rendered on top of others, even if it's
// already focused in this seat
if (view != NULL) {
wl_list_remove(&view->link);
wl_list_insert(&seat->input->server->desktop->views, &view->link);
}
bool unfullscreen = true;
#if WLR_HAS_XWAYLAND
if (view && view->type == ROOTS_XWAYLAND_VIEW) {
struct roots_xwayland_surface *xwayland_surface =
roots_xwayland_surface_from_view(view);
if (xwayland_surface->xwayland_surface->override_redirect) {
unfullscreen = false;
}
}
#endif
if (view && unfullscreen) {
struct roots_desktop *desktop = view->desktop;
struct roots_output *output;
struct wlr_box box;
view_get_box(view, &box);
wl_list_for_each(output, &desktop->outputs, link) {
if (output->fullscreen_view &&
output->fullscreen_view != view &&
wlr_output_layout_intersects(
desktop->layout,
output->wlr_output, &box)) {
view_set_fullscreen(output->fullscreen_view,
false, NULL);
}
}
}
struct roots_view *prev_focus = roots_seat_get_focus(seat);
2017-11-19 18:15:11 +01:00
if (view == prev_focus) {
return;
}
#if WLR_HAS_XWAYLAND
if (view && view->type == ROOTS_XWAYLAND_VIEW) {
struct roots_xwayland_surface *xwayland_surface =
roots_xwayland_surface_from_view(view);
if (!wlr_xwayland_or_surface_wants_focus(
xwayland_surface->xwayland_surface)) {
return;
}
2017-11-19 18:15:11 +01:00
}
#endif
2017-11-19 18:15:11 +01:00
struct roots_seat_view *seat_view = NULL;
if (view != NULL) {
2018-01-17 01:04:26 +01:00
seat_view = roots_seat_view_from_view(seat, view);
if (seat_view == NULL) {
return;
2017-11-19 18:15:11 +01:00
}
}
seat->has_focus = false;
// Deactivate the old view if it is not focused by some other seat
2017-11-19 18:15:11 +01:00
if (prev_focus != NULL && !input_view_has_focus(seat->input, prev_focus)) {
view_activate(prev_focus, false);
}
if (view == NULL) {
seat->cursor->mode = ROOTS_CURSOR_PASSTHROUGH;
wlr_seat_keyboard_clear_focus(seat->seat);
roots_input_method_relay_set_focus(&seat->im_relay, NULL);
2017-11-19 18:15:11 +01:00
return;
2017-11-07 21:56:11 +01:00
}
2017-11-19 18:15:11 +01:00
wl_list_remove(&seat_view->link);
wl_list_insert(&seat->views, &seat_view->link);
2018-01-06 17:06:09 +01:00
view_damage_whole(view);
if (seat->focused_layer) {
return;
}
view_activate(view, true);
seat->has_focus = true;
2018-06-25 00:18:30 +02:00
// An existing keyboard grab might try to deny setting focus, so cancel it
wlr_seat_keyboard_end_grab(seat->seat);
2018-01-06 17:06:09 +01:00
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->seat);
if (keyboard != NULL) {
wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface,
keyboard->keycodes, keyboard->num_keycodes,
2018-01-17 14:31:15 +01:00
&keyboard->modifiers);
/* FIXME: Move this to a better place */
struct roots_tablet_pad *pad;
wl_list_for_each(pad, &seat->tablet_pads, link) {
if (pad->tablet) {
wlr_tablet_v2_tablet_pad_notify_enter(pad->tablet_v2_pad, pad->tablet->tablet_v2, view->wlr_surface);
}
}
2018-01-06 17:06:09 +01:00
} else {
wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface,
NULL, 0, NULL);
}
if (seat->cursor) {
roots_cursor_update_focus(seat->cursor);
}
roots_input_method_relay_set_focus(&seat->im_relay, view->wlr_surface);
2017-11-07 21:56:11 +01:00
}
/**
* Focus semantics of layer surfaces are somewhat detached from the normal focus
* flow. For layers above the shell layer, for example, you cannot unfocus them.
* You also cannot alt-tab between layer surfaces and shell surfaces.
*/
void roots_seat_set_focus_layer(struct roots_seat *seat,
2018-09-14 19:32:33 +02:00
struct wlr_layer_surface_v1 *layer) {
if (!layer) {
if (seat->focused_layer) {
seat->focused_layer = NULL;
if (!wl_list_empty(&seat->views)) {
// Focus first view
struct roots_seat_view *first_seat_view = wl_container_of(
seat->views.next, first_seat_view, link);
roots_seat_set_focus(seat, first_seat_view->view);
}
}
return;
}
2018-04-03 18:50:05 +02:00
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->seat);
if (!roots_seat_allow_input(seat, layer->resource)) {
return;
}
if (seat->has_focus) {
struct roots_view *prev_focus = roots_seat_get_focus(seat);
wlr_seat_keyboard_clear_focus(seat->seat);
view_activate(prev_focus, false);
}
seat->has_focus = false;
if (layer->layer >= ZWLR_LAYER_SHELL_V1_LAYER_TOP) {
seat->focused_layer = layer;
}
if (keyboard != NULL) {
wlr_seat_keyboard_notify_enter(seat->seat, layer->surface,
keyboard->keycodes, keyboard->num_keycodes,
&keyboard->modifiers);
} else {
wlr_seat_keyboard_notify_enter(seat->seat, layer->surface,
NULL, 0, NULL);
}
if (seat->cursor) {
roots_cursor_update_focus(seat->cursor);
}
}
2018-04-03 18:50:05 +02:00
void roots_seat_set_exclusive_client(struct roots_seat *seat,
struct wl_client *client) {
if (!client) {
seat->exclusive_client = client;
// Triggers a refocus of the topmost surface layer if necessary
// TODO: Make layer surface focus per-output based on cursor position
struct roots_output *output;
wl_list_for_each(output, &seat->input->server->desktop->outputs, link) {
arrange_layers(output);
}
return;
}
if (seat->focused_layer) {
if (wl_resource_get_client(seat->focused_layer->resource) != client) {
roots_seat_set_focus_layer(seat, NULL);
}
}
if (seat->has_focus) {
struct roots_view *focus = roots_seat_get_focus(seat);
if (wl_resource_get_client(focus->wlr_surface->resource) != client) {
roots_seat_set_focus(seat, NULL);
}
}
if (seat->seat->pointer_state.focused_client) {
if (seat->seat->pointer_state.focused_client->client != client) {
wlr_seat_pointer_clear_focus(seat->seat);
}
}
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
struct wlr_touch_point *point;
wl_list_for_each(point, &seat->seat->touch_state.touch_points, link) {
if (point->client->client != client) {
wlr_seat_touch_point_clear_focus(seat->seat,
now.tv_nsec / 1000, point->touch_id);
}
}
seat->exclusive_client = client;
}
2017-11-19 19:21:18 +01:00
void roots_seat_cycle_focus(struct roots_seat *seat) {
if (wl_list_empty(&seat->views)) {
return;
}
2017-11-19 21:54:11 +01:00
struct roots_seat_view *first_seat_view = wl_container_of(
seat->views.next, first_seat_view, link);
if (!seat->has_focus) {
roots_seat_set_focus(seat, first_seat_view->view);
return;
}
if (wl_list_length(&seat->views) < 2) {
return;
}
// Focus the next view
struct roots_seat_view *next_seat_view = wl_container_of(
first_seat_view->link.next, next_seat_view, link);
roots_seat_set_focus(seat, next_seat_view->view);
// Move the first view to the end of the list
wl_list_remove(&first_seat_view->link);
wl_list_insert(seat->views.prev, &first_seat_view->link);
2017-11-19 19:21:18 +01:00
}
2017-11-07 21:56:11 +01:00
void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view) {
struct roots_cursor *cursor = seat->cursor;
cursor->mode = ROOTS_CURSOR_MOVE;
cursor->offs_x = cursor->cursor->x;
cursor->offs_y = cursor->cursor->y;
if (view->maximized) {
cursor->view_x = view->saved.x;
cursor->view_y = view->saved.y;
} else {
2018-12-05 10:01:25 +01:00
cursor->view_x = view->box.x;
cursor->view_y = view->box.y;
}
view_maximize(view, false);
2017-11-07 21:56:11 +01:00
wlr_seat_pointer_clear_focus(seat->seat);
2017-11-12 11:10:56 +01:00
wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager,
ROOTS_XCURSOR_MOVE, seat->cursor->cursor);
2017-11-07 21:56:11 +01:00
}
void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view,
uint32_t edges) {
2017-11-08 14:35:27 +01:00
struct roots_cursor *cursor = seat->cursor;
cursor->mode = ROOTS_CURSOR_RESIZE;
cursor->offs_x = cursor->cursor->x;
cursor->offs_y = cursor->cursor->y;
if (view->maximized) {
cursor->view_x = view->saved.x;
cursor->view_y = view->saved.y;
cursor->view_width = view->saved.width;
cursor->view_height = view->saved.height;
} else {
2018-12-05 10:01:25 +01:00
cursor->view_x = view->box.x;
cursor->view_y = view->box.y;
struct wlr_box box;
view_get_box(view, &box);
cursor->view_width = box.width;
cursor->view_height = box.height;
}
2017-11-08 14:35:27 +01:00
cursor->resize_edges = edges;
view_maximize(view, false);
2017-11-08 14:35:27 +01:00
wlr_seat_pointer_clear_focus(seat->seat);
2017-12-08 12:08:06 +01:00
const char *resize_name = wlr_xcursor_get_resize_name(edges);
2017-11-12 11:10:56 +01:00
wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager,
2017-12-07 17:19:43 +01:00
resize_name, seat->cursor->cursor);
2017-11-07 21:56:11 +01:00
}
void roots_seat_begin_rotate(struct roots_seat *seat, struct roots_view *view) {
2017-11-08 14:35:27 +01:00
struct roots_cursor *cursor = seat->cursor;
cursor->mode = ROOTS_CURSOR_ROTATE;
cursor->offs_x = cursor->cursor->x;
cursor->offs_y = cursor->cursor->y;
cursor->view_rotation = view->rotation;
view_maximize(view, false);
2017-11-08 14:35:27 +01:00
wlr_seat_pointer_clear_focus(seat->seat);
2017-11-12 11:10:56 +01:00
wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager,
ROOTS_XCURSOR_ROTATE, seat->cursor->cursor);
2017-11-07 21:56:11 +01:00
}
2018-02-08 13:13:33 +01:00
void roots_seat_end_compositor_grab(struct roots_seat *seat) {
struct roots_cursor *cursor = seat->cursor;
struct roots_view *view = roots_seat_get_focus(seat);
if (view == NULL) {
return;
}
switch(cursor->mode) {
case ROOTS_CURSOR_MOVE:
view_move(view, cursor->view_x, cursor->view_y);
break;
case ROOTS_CURSOR_RESIZE:
view_move_resize(view, cursor->view_x, cursor->view_y, cursor->view_width, cursor->view_height);
break;
case ROOTS_CURSOR_ROTATE:
view->rotation = cursor->view_rotation;
break;
case ROOTS_CURSOR_PASSTHROUGH:
break;
}
cursor->mode = ROOTS_CURSOR_PASSTHROUGH;
}
struct roots_seat *input_last_active_seat(struct roots_input *input) {
struct roots_seat *seat = NULL, *_seat;
wl_list_for_each(_seat, &input->seats, link) {
if (!seat || (seat->seat->last_event.tv_sec > _seat->seat->last_event.tv_sec &&
seat->seat->last_event.tv_nsec > _seat->seat->last_event.tv_nsec)) {
seat = _seat;
}
}
return seat;
}