commit
27937add76
@ -0,0 +1,103 @@
|
|||||||
|
#ifndef _ROOTSTON_CURSOR_H
|
||||||
|
#define _ROOTSTON_CURSOR_H
|
||||||
|
|
||||||
|
#include "rootston/seat.h"
|
||||||
|
|
||||||
|
enum roots_cursor_mode {
|
||||||
|
ROOTS_CURSOR_PASSTHROUGH = 0,
|
||||||
|
ROOTS_CURSOR_MOVE = 1,
|
||||||
|
ROOTS_CURSOR_RESIZE = 2,
|
||||||
|
ROOTS_CURSOR_ROTATE = 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum roots_cursor_resize_edge {
|
||||||
|
ROOTS_CURSOR_RESIZE_EDGE_TOP = 1,
|
||||||
|
ROOTS_CURSOR_RESIZE_EDGE_BOTTOM = 2,
|
||||||
|
ROOTS_CURSOR_RESIZE_EDGE_LEFT = 4,
|
||||||
|
ROOTS_CURSOR_RESIZE_EDGE_RIGHT = 8,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct roots_input_event {
|
||||||
|
uint32_t serial;
|
||||||
|
struct wlr_cursor *cursor;
|
||||||
|
struct wlr_input_device *device;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct roots_cursor {
|
||||||
|
struct roots_seat *seat;
|
||||||
|
struct wlr_cursor *cursor;
|
||||||
|
|
||||||
|
enum roots_cursor_mode mode;
|
||||||
|
|
||||||
|
// state from input (review if this is necessary)
|
||||||
|
struct wlr_xcursor_manager *xcursor_manager;
|
||||||
|
struct wlr_seat *wl_seat;
|
||||||
|
struct wl_client *cursor_client;
|
||||||
|
int offs_x, offs_y;
|
||||||
|
int view_x, view_y, view_width, view_height;
|
||||||
|
float view_rotation;
|
||||||
|
uint32_t resize_edges;
|
||||||
|
// Ring buffer of input events that could trigger move/resize/rotate
|
||||||
|
int input_events_idx;
|
||||||
|
struct wl_list touch_points;
|
||||||
|
struct roots_input_event input_events[16];
|
||||||
|
|
||||||
|
struct wl_listener motion;
|
||||||
|
struct wl_listener motion_absolute;
|
||||||
|
struct wl_listener button;
|
||||||
|
struct wl_listener axis;
|
||||||
|
|
||||||
|
struct wl_listener touch_down;
|
||||||
|
struct wl_listener touch_up;
|
||||||
|
struct wl_listener touch_motion;
|
||||||
|
|
||||||
|
struct wl_listener tool_axis;
|
||||||
|
struct wl_listener tool_tip;
|
||||||
|
|
||||||
|
struct wl_listener pointer_grab_begin;
|
||||||
|
struct wl_listener pointer_grab_end;
|
||||||
|
|
||||||
|
struct wl_listener request_set_cursor;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct roots_cursor *roots_cursor_create(struct roots_seat *seat);
|
||||||
|
|
||||||
|
void roots_cursor_destroy(struct roots_cursor *cursor);
|
||||||
|
|
||||||
|
void roots_cursor_handle_motion(struct roots_cursor *cursor,
|
||||||
|
struct wlr_event_pointer_motion *event);
|
||||||
|
|
||||||
|
void roots_cursor_handle_motion_absolute(struct roots_cursor *cursor,
|
||||||
|
struct wlr_event_pointer_motion_absolute *event);
|
||||||
|
|
||||||
|
void roots_cursor_handle_button(struct roots_cursor *cursor,
|
||||||
|
struct wlr_event_pointer_button *event);
|
||||||
|
|
||||||
|
void roots_cursor_handle_axis(struct roots_cursor *cursor,
|
||||||
|
struct wlr_event_pointer_axis *event);
|
||||||
|
|
||||||
|
void roots_cursor_handle_touch_down(struct roots_cursor *cursor,
|
||||||
|
struct wlr_event_touch_down *event);
|
||||||
|
|
||||||
|
void roots_cursor_handle_touch_up(struct roots_cursor *cursor,
|
||||||
|
struct wlr_event_touch_up *event);
|
||||||
|
|
||||||
|
void roots_cursor_handle_touch_motion(struct roots_cursor *cursor,
|
||||||
|
struct wlr_event_touch_motion *event);
|
||||||
|
|
||||||
|
void roots_cursor_handle_tool_axis(struct roots_cursor *cursor,
|
||||||
|
struct wlr_event_tablet_tool_axis *event);
|
||||||
|
|
||||||
|
void roots_cursor_handle_tool_tip(struct roots_cursor *cursor,
|
||||||
|
struct wlr_event_tablet_tool_tip *event);
|
||||||
|
|
||||||
|
void roots_cursor_handle_request_set_cursor(struct roots_cursor *cursor,
|
||||||
|
struct wlr_seat_pointer_request_set_cursor_event *event);
|
||||||
|
|
||||||
|
void roots_cursor_handle_pointer_grab_begin(struct roots_cursor *cursor,
|
||||||
|
struct wlr_seat_pointer_grab *grab);
|
||||||
|
|
||||||
|
void roots_cursor_handle_pointer_grab_end(struct roots_cursor *cursor,
|
||||||
|
struct wlr_seat_pointer_grab *grab);
|
||||||
|
|
||||||
|
#endif
|
@ -1,171 +1,31 @@
|
|||||||
#ifndef _ROOTSTON_INPUT_H
|
#ifndef _ROOTSTON_INPUT_H
|
||||||
#define _ROOTSTON_INPUT_H
|
#define _ROOTSTON_INPUT_H
|
||||||
#include <xkbcommon/xkbcommon.h>
|
|
||||||
#include <wayland-server.h>
|
#include <wayland-server.h>
|
||||||
#include <wlr/types/wlr_input_device.h>
|
#include <wlr/types/wlr_input_device.h>
|
||||||
#include <wlr/types/wlr_cursor.h>
|
#include <wlr/types/wlr_cursor.h>
|
||||||
#include <wlr/types/wlr_seat.h>
|
#include <wlr/types/wlr_seat.h>
|
||||||
#include <wlr/xcursor.h>
|
#include "rootston/cursor.h"
|
||||||
#include "rootston/config.h"
|
#include "rootston/config.h"
|
||||||
#include "rootston/view.h"
|
#include "rootston/view.h"
|
||||||
#include "rootston/server.h"
|
#include "rootston/server.h"
|
||||||
|
|
||||||
#define ROOTS_KEYBOARD_PRESSED_KEYSYMS_CAP 32
|
|
||||||
|
|
||||||
struct roots_keyboard {
|
|
||||||
struct roots_input *input;
|
|
||||||
struct wlr_input_device *device;
|
|
||||||
struct wl_listener key;
|
|
||||||
struct wl_listener modifiers;
|
|
||||||
struct wl_list link;
|
|
||||||
|
|
||||||
xkb_keysym_t pressed_keysyms[ROOTS_KEYBOARD_PRESSED_KEYSYMS_CAP];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct roots_pointer {
|
|
||||||
struct roots_input *input;
|
|
||||||
struct wlr_input_device *device;
|
|
||||||
struct wl_list link;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct roots_touch {
|
|
||||||
struct roots_input *input;
|
|
||||||
struct wlr_input_device *device;
|
|
||||||
struct wl_list link;
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: tablet pad
|
|
||||||
struct roots_tablet_tool {
|
|
||||||
struct roots_input *input;
|
|
||||||
struct wlr_input_device *device;
|
|
||||||
struct wl_listener axis;
|
|
||||||
struct wl_listener proximity;
|
|
||||||
struct wl_listener tip;
|
|
||||||
struct wl_listener button;
|
|
||||||
struct wl_list link;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum roots_cursor_mode {
|
|
||||||
ROOTS_CURSOR_PASSTHROUGH = 0,
|
|
||||||
ROOTS_CURSOR_MOVE = 1,
|
|
||||||
ROOTS_CURSOR_RESIZE = 2,
|
|
||||||
ROOTS_CURSOR_ROTATE = 3,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum roots_cursor_resize_edge {
|
|
||||||
ROOTS_CURSOR_RESIZE_EDGE_TOP = 1,
|
|
||||||
ROOTS_CURSOR_RESIZE_EDGE_BOTTOM = 2,
|
|
||||||
ROOTS_CURSOR_RESIZE_EDGE_LEFT = 4,
|
|
||||||
ROOTS_CURSOR_RESIZE_EDGE_RIGHT = 8,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct roots_input_event {
|
|
||||||
uint32_t serial;
|
|
||||||
struct wlr_cursor *cursor;
|
|
||||||
struct wlr_input_device *device;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct roots_drag_icon {
|
|
||||||
struct wlr_surface *surface;
|
|
||||||
struct wl_list link; // roots_input::drag_icons
|
|
||||||
bool mapped;
|
|
||||||
|
|
||||||
int32_t sx;
|
|
||||||
int32_t sy;
|
|
||||||
|
|
||||||
struct wl_listener surface_destroy;
|
|
||||||
struct wl_listener surface_commit;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct roots_touch_point {
|
|
||||||
struct roots_touch *device;
|
|
||||||
int32_t slot;
|
|
||||||
double x, y;
|
|
||||||
struct wl_list link;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct roots_input {
|
struct roots_input {
|
||||||
struct roots_config *config;
|
struct roots_config *config;
|
||||||
struct roots_server *server;
|
struct roots_server *server;
|
||||||
|
|
||||||
// TODO: multiseat, multicursor
|
|
||||||
struct wlr_cursor *cursor;
|
|
||||||
struct wlr_xcursor_theme *xcursor_theme;
|
|
||||||
struct wlr_seat *wl_seat;
|
|
||||||
struct wl_list drag_icons;
|
|
||||||
struct wl_client *cursor_client;
|
|
||||||
|
|
||||||
enum roots_cursor_mode mode;
|
|
||||||
struct roots_view *active_view;
|
|
||||||
int offs_x, offs_y;
|
|
||||||
int view_x, view_y, view_width, view_height;
|
|
||||||
float view_rotation;
|
|
||||||
uint32_t resize_edges;
|
|
||||||
|
|
||||||
// Ring buffer of input events that could trigger move/resize/rotate
|
|
||||||
int input_events_idx;
|
|
||||||
struct roots_input_event input_events[16];
|
|
||||||
|
|
||||||
struct wl_list keyboards;
|
|
||||||
struct wl_list pointers;
|
|
||||||
struct wl_list touch;
|
|
||||||
struct wl_list tablet_tools;
|
|
||||||
|
|
||||||
struct wl_listener input_add;
|
struct wl_listener input_add;
|
||||||
struct wl_listener input_remove;
|
struct wl_listener input_remove;
|
||||||
|
|
||||||
struct wl_listener cursor_motion;
|
struct wl_list seats;
|
||||||
struct wl_listener cursor_motion_absolute;
|
|
||||||
struct wl_listener cursor_button;
|
|
||||||
struct wl_listener cursor_axis;
|
|
||||||
|
|
||||||
struct wl_listener cursor_touch_down;
|
|
||||||
struct wl_listener cursor_touch_up;
|
|
||||||
struct wl_listener cursor_touch_motion;
|
|
||||||
|
|
||||||
struct wl_listener cursor_tool_axis;
|
|
||||||
struct wl_listener cursor_tool_tip;
|
|
||||||
|
|
||||||
struct wl_listener pointer_grab_begin;
|
|
||||||
struct wl_list touch_points;
|
|
||||||
|
|
||||||
struct wl_listener pointer_grab_end;
|
|
||||||
|
|
||||||
struct wl_listener request_set_cursor;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct roots_input *input_create(struct roots_server *server,
|
struct roots_input *input_create(struct roots_server *server,
|
||||||
struct roots_config *config);
|
struct roots_config *config);
|
||||||
void input_destroy(struct roots_input *input);
|
void input_destroy(struct roots_input *input);
|
||||||
|
|
||||||
void pointer_add(struct wlr_input_device *device, struct roots_input *input);
|
struct roots_seat *input_seat_from_wlr_seat(struct roots_input *input,
|
||||||
void pointer_remove(struct wlr_input_device *device, struct roots_input *input);
|
struct wlr_seat *seat);
|
||||||
void keyboard_add(struct wlr_input_device *device, struct roots_input *input);
|
|
||||||
void keyboard_remove(struct wlr_input_device *device, struct roots_input *input);
|
|
||||||
void touch_add(struct wlr_input_device *device, struct roots_input *input);
|
|
||||||
void touch_remove(struct wlr_input_device *device, struct roots_input *input);
|
|
||||||
void tablet_tool_add(struct wlr_input_device *device, struct roots_input *input);
|
|
||||||
void tablet_tool_remove(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);
|
|
||||||
const struct roots_input_event *get_input_event(struct roots_input *input,
|
|
||||||
uint32_t serial);
|
|
||||||
void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor,
|
|
||||||
struct roots_view *view);
|
|
||||||
void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor,
|
|
||||||
struct roots_view *view, uint32_t edges);
|
|
||||||
|
|
||||||
struct wlr_xcursor *get_default_xcursor(struct wlr_xcursor_theme *theme);
|
|
||||||
struct wlr_xcursor *get_move_xcursor(struct wlr_xcursor_theme *theme);
|
|
||||||
struct wlr_xcursor *get_resize_xcursor(struct wlr_xcursor_theme *theme,
|
|
||||||
uint32_t edges);
|
|
||||||
struct wlr_xcursor *get_rotate_xcursor(struct wlr_xcursor_theme *theme);
|
|
||||||
|
|
||||||
void set_view_focus(struct roots_input *input, struct roots_desktop *desktop,
|
bool input_view_has_focus(struct roots_input *input, struct roots_view *view);
|
||||||
struct roots_view *view);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
#ifndef _ROOTSTON_KEYBOARD_H
|
||||||
|
#define _ROOTSTON_KEYBOARD_H
|
||||||
|
|
||||||
|
#include <xkbcommon/xkbcommon.h>
|
||||||
|
#include "rootston/input.h"
|
||||||
|
|
||||||
|
#define ROOTS_KEYBOARD_PRESSED_KEYSYMS_CAP 32
|
||||||
|
|
||||||
|
struct roots_keyboard {
|
||||||
|
struct roots_input *input;
|
||||||
|
struct roots_seat *seat;
|
||||||
|
struct wlr_input_device *device;
|
||||||
|
struct roots_keyboard_config *config;
|
||||||
|
struct wl_list link;
|
||||||
|
|
||||||
|
struct wl_listener keyboard_key;
|
||||||
|
struct wl_listener keyboard_modifiers;
|
||||||
|
|
||||||
|
xkb_keysym_t pressed_keysyms_translated[ROOTS_KEYBOARD_PRESSED_KEYSYMS_CAP];
|
||||||
|
xkb_keysym_t pressed_keysyms_raw[ROOTS_KEYBOARD_PRESSED_KEYSYMS_CAP];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device,
|
||||||
|
struct roots_input *input);
|
||||||
|
|
||||||
|
void roots_keyboard_destroy(struct roots_keyboard *keyboard);
|
||||||
|
|
||||||
|
void roots_keyboard_handle_key(struct roots_keyboard *keyboard,
|
||||||
|
struct wlr_event_keyboard_key *event);
|
||||||
|
|
||||||
|
void roots_keyboard_handle_modifiers(struct roots_keyboard *r_keyboard);
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,88 @@
|
|||||||
|
#ifndef _ROOTSTON_SEAT_H
|
||||||
|
#define _ROOTSTON_SEAT_H
|
||||||
|
#include <wayland-server.h>
|
||||||
|
#include "rootston/input.h"
|
||||||
|
#include "rootston/keyboard.h"
|
||||||
|
|
||||||
|
struct roots_drag_icon {
|
||||||
|
struct wlr_surface *surface;
|
||||||
|
struct wl_list link; // roots_seat::drag_icons
|
||||||
|
bool mapped;
|
||||||
|
|
||||||
|
int32_t sx;
|
||||||
|
int32_t sy;
|
||||||
|
|
||||||
|
struct wl_listener surface_destroy;
|
||||||
|
struct wl_listener surface_commit;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct roots_seat {
|
||||||
|
struct roots_input *input;
|
||||||
|
struct wlr_seat *seat;
|
||||||
|
struct roots_cursor *cursor;
|
||||||
|
struct wl_list link;
|
||||||
|
struct wl_list drag_icons;
|
||||||
|
|
||||||
|
struct roots_view *focus;
|
||||||
|
|
||||||
|
struct wl_list keyboards;
|
||||||
|
struct wl_list pointers;
|
||||||
|
struct wl_list touch;
|
||||||
|
struct wl_list tablet_tools;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct roots_pointer {
|
||||||
|
struct roots_seat *seat;
|
||||||
|
struct wlr_input_device *device;
|
||||||
|
struct wl_list link;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct roots_touch {
|
||||||
|
struct roots_seat *seat;
|
||||||
|
struct wlr_input_device *device;
|
||||||
|
struct wl_list link;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct roots_touch_point {
|
||||||
|
struct roots_touch *device;
|
||||||
|
int32_t slot;
|
||||||
|
double x, y;
|
||||||
|
struct wl_list link;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct roots_tablet_tool {
|
||||||
|
struct roots_seat *seat;
|
||||||
|
struct wlr_input_device *device;
|
||||||
|
struct wl_listener axis;
|
||||||
|
struct wl_listener proximity;
|
||||||
|
struct wl_listener tip;
|
||||||
|
struct wl_listener button;
|
||||||
|
struct wl_list link;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct roots_seat *roots_seat_create(struct roots_input *input, char *name);
|
||||||
|
|
||||||
|
void roots_seat_destroy(struct roots_seat *seat);
|
||||||
|
|
||||||
|
void roots_seat_add_device(struct roots_seat *seat,
|
||||||
|
struct wlr_input_device *device);
|
||||||
|
|
||||||
|
void roots_seat_remove_device(struct roots_seat *seat,
|
||||||
|
struct wlr_input_device *device);
|
||||||
|
|
||||||
|
void roots_seat_configure_cursor(struct roots_seat *seat);
|
||||||
|
|
||||||
|
void roots_seat_configure_xcursor(struct roots_seat *seat);
|
||||||
|
|
||||||
|
bool roots_seat_has_meta_pressed(struct roots_seat *seat);
|
||||||
|
|
||||||
|
void roots_seat_focus_view(struct roots_seat *seat, struct roots_view *view);
|
||||||
|
|
||||||
|
void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view);
|
||||||
|
|
||||||
|
void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view,
|
||||||
|
uint32_t edges);
|
||||||
|
|
||||||
|
void roots_seat_begin_rotate(struct roots_seat *seat, struct roots_view *view);
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,14 @@
|
|||||||
|
#ifndef _ROOTSTON_XCURSOR_H
|
||||||
|
#define _ROOTSTON_XCURSOR_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define ROOTS_XCURSOR_SIZE 16
|
||||||
|
|
||||||
|
#define ROOTS_XCURSOR_DEFAULT "left_ptr"
|
||||||
|
#define ROOTS_XCURSOR_MOVE "grabbing"
|
||||||
|
#define ROOTS_XCURSOR_ROTATE "grabbing"
|
||||||
|
|
||||||
|
const char *roots_xcursor_get_resize_name(uint32_t edges);
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,53 @@
|
|||||||
|
#ifndef WLR_TYPES_WLR_XCURSOR_MANAGER_H
|
||||||
|
#define WLR_TYPES_WLR_XCURSOR_MANAGER_H
|
||||||
|
|
||||||
|
#include <wayland-server.h>
|
||||||
|
#include <wlr/types/wlr_cursor.h>
|
||||||
|
#include <wlr/xcursor.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A scaled XCursor theme.
|
||||||
|
*/
|
||||||
|
struct wlr_xcursor_manager_theme {
|
||||||
|
uint32_t scale;
|
||||||
|
struct wlr_xcursor_theme *theme;
|
||||||
|
struct wl_list link;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manage multiple XCursor themes with different scales and set `wlr_cursor`
|
||||||
|
* images.
|
||||||
|
*
|
||||||
|
* This manager can be used to display cursor images on multiple outputs having
|
||||||
|
* different scale factors.
|
||||||
|
*/
|
||||||
|
struct wlr_xcursor_manager {
|
||||||
|
char *name;
|
||||||
|
uint32_t size;
|
||||||
|
struct wl_list scaled_themes; // wlr_xcursor_manager_theme::link
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new XCursor manager. After initialization, scaled themes need to be
|
||||||
|
* loaded with `wlr_xcursor_manager_load`. `size` is the unscaled cursor theme
|
||||||
|
* size.
|
||||||
|
*/
|
||||||
|
struct wlr_xcursor_manager *wlr_xcursor_manager_create(const char *name,
|
||||||
|
uint32_t size);
|
||||||
|
|
||||||
|
void wlr_xcursor_manager_destroy(struct wlr_xcursor_manager *manager);
|
||||||
|
|
||||||
|
int wlr_xcursor_manager_load(struct wlr_xcursor_manager *manager,
|
||||||
|
uint32_t scale);
|
||||||
|
|
||||||
|
struct wlr_xcursor *wlr_xcursor_manager_get_xcursor(
|
||||||
|
struct wlr_xcursor_manager *manager, const char *name, uint32_t scale);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a `wlr_cursor` image. The manager uses all currently loaded scaled
|
||||||
|
* themes.
|
||||||
|
*/
|
||||||
|
void wlr_xcursor_manager_set_cursor_image(struct wlr_xcursor_manager *manager,
|
||||||
|
const char *name, struct wlr_cursor *cursor);
|
||||||
|
|
||||||
|
#endif
|
@ -1,23 +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"
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
@ -0,0 +1,579 @@
|
|||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <wayland-server.h>
|
||||||
|
#include <wlr/types/wlr_xcursor_manager.h>
|
||||||
|
#include <wlr/util/log.h>
|
||||||
|
#include "rootston/xcursor.h"
|
||||||
|
#include "rootston/input.h"
|
||||||
|
#include "rootston/seat.h"
|
||||||
|
#include "rootston/keyboard.h"
|
||||||
|
#include "rootston/cursor.h"
|
||||||
|
|
||||||
|
static void handle_keyboard_key(struct wl_listener *listener, void *data) {
|
||||||
|
struct roots_keyboard *keyboard =
|
||||||
|
wl_container_of(listener, keyboard, keyboard_key);
|
||||||
|
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);
|
||||||
|
roots_keyboard_handle_modifiers(keyboard);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_cursor_motion(struct wl_listener *listener, void *data) {
|
||||||
|
struct roots_cursor *cursor =
|
||||||
|
wl_container_of(listener, cursor, motion);
|
||||||
|
struct wlr_event_pointer_motion *event = data;
|
||||||
|
roots_cursor_handle_motion(cursor, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_cursor_motion_absolute(struct wl_listener *listener, void *data) {
|
||||||
|
struct roots_cursor *cursor =
|
||||||
|
wl_container_of(listener, cursor, motion_absolute);
|
||||||
|
struct wlr_event_pointer_motion_absolute *event = data;
|
||||||
|
roots_cursor_handle_motion_absolute(cursor, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_cursor_button(struct wl_listener *listener, void *data) {
|
||||||
|
struct roots_cursor *cursor =
|
||||||
|
wl_container_of(listener, cursor, button);
|
||||||
|
struct wlr_event_pointer_button *event = data;
|
||||||
|
roots_cursor_handle_button(cursor, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_cursor_axis(struct wl_listener *listener, void *data) {
|
||||||
|
struct roots_cursor *cursor =
|
||||||
|
wl_container_of(listener, cursor, axis);
|
||||||
|
struct wlr_event_pointer_axis *event = data;
|
||||||
|
roots_cursor_handle_axis(cursor, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_touch_down(struct wl_listener *listener, void *data) {
|
||||||
|
struct roots_cursor *cursor =
|
||||||
|
wl_container_of(listener, cursor, touch_down);
|
||||||
|
struct wlr_event_touch_down *event = data;
|
||||||
|
roots_cursor_handle_touch_down(cursor, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_touch_up(struct wl_listener *listener, void *data) {
|
||||||
|
struct roots_cursor *cursor =
|
||||||
|
wl_container_of(listener, cursor, touch_up);
|
||||||
|
struct wlr_event_touch_up *event = data;
|
||||||
|
roots_cursor_handle_touch_up(cursor, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_touch_motion(struct wl_listener *listener, void *data) {
|
||||||
|
struct roots_cursor *cursor =
|
||||||
|
wl_container_of(listener, cursor, touch_motion);
|
||||||
|
struct wlr_event_touch_motion *event = data;
|
||||||
|
roots_cursor_handle_touch_motion(cursor, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_tool_axis(struct wl_listener *listener, void *data) {
|
||||||
|
struct roots_cursor *cursor =
|
||||||
|
wl_container_of(listener, cursor, tool_axis);
|
||||||
|
struct wlr_event_tablet_tool_axis *event = data;
|
||||||
|
roots_cursor_handle_tool_axis(cursor, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_tool_tip(struct wl_listener *listener, void *data) {
|
||||||
|
struct roots_cursor *cursor =
|
||||||
|
wl_container_of(listener, cursor, tool_tip);
|
||||||
|
struct wlr_event_tablet_tool_tip *event = data;
|
||||||
|
roots_cursor_handle_tool_tip(cursor, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 wlr_seat_pointer_request_set_cursor_event *event = data;
|
||||||
|
roots_cursor_handle_request_set_cursor(cursor, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_pointer_grab_begin(struct wl_listener *listener,
|
||||||
|
void *data) {
|
||||||
|
struct roots_cursor *cursor =
|
||||||
|
wl_container_of(listener, cursor, pointer_grab_begin);
|
||||||
|
struct wlr_seat_pointer_grab *grab = data;
|
||||||
|
roots_cursor_handle_pointer_grab_begin(cursor, grab);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_pointer_grab_end(struct wl_listener *listener,
|
||||||
|
void *data) {
|
||||||
|
struct roots_cursor *cursor =
|
||||||
|
wl_container_of(listener, cursor, pointer_grab_end);
|
||||||
|
struct wlr_seat_pointer_grab *grab = data;
|
||||||
|
roots_cursor_handle_pointer_grab_end(cursor, grab);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void seat_reset_device_mappings(struct roots_seat *seat, struct wlr_input_device *device) {
|
||||||
|
struct wlr_cursor *cursor = seat->cursor->cursor;
|
||||||
|
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))) {
|
||||||
|
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->cursor;
|
||||||
|
struct roots_config *config = seat->input->config;
|
||||||
|
struct roots_device_config *dconfig;
|
||||||
|
dconfig = roots_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 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->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) {
|
||||||
|
seat->cursor = roots_cursor_create(seat);
|
||||||
|
if (!seat->cursor) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
seat->cursor->seat = seat;
|
||||||
|
struct wlr_cursor *wlr_cursor = seat->cursor->cursor;
|
||||||
|
struct roots_desktop *desktop = seat->input->server->desktop;
|
||||||
|
wlr_cursor_attach_output_layout(wlr_cursor, desktop->layout);
|
||||||
|
|
||||||
|
// TODO: be able to configure per-seat cursor themes
|
||||||
|
seat->cursor->xcursor_manager = desktop->xcursor_manager;
|
||||||
|
|
||||||
|
wl_list_init(&seat->cursor->touch_points);
|
||||||
|
|
||||||
|
roots_seat_configure_cursor(seat);
|
||||||
|
roots_seat_configure_xcursor(seat);
|
||||||
|
|
||||||
|
// add input signals
|
||||||
|
wl_signal_add(&wlr_cursor->events.motion, &seat->cursor->motion);
|
||||||
|
seat->cursor->motion.notify = handle_cursor_motion;
|
||||||
|
|
||||||
|
wl_signal_add(&wlr_cursor->events.motion_absolute,
|
||||||
|
&seat->cursor->motion_absolute);
|
||||||
|
seat->cursor->motion_absolute.notify = handle_cursor_motion_absolute;
|
||||||
|
|
||||||
|
wl_signal_add(&wlr_cursor->events.button, &seat->cursor->button);
|
||||||
|
seat->cursor->button.notify = handle_cursor_button;
|
||||||
|
|
||||||
|
wl_signal_add(&wlr_cursor->events.axis, &seat->cursor->axis);
|
||||||
|
seat->cursor->axis.notify = handle_cursor_axis;
|
||||||
|
|
||||||
|
wl_signal_add(&wlr_cursor->events.touch_down, &seat->cursor->touch_down);
|
||||||
|
seat->cursor->touch_down.notify = handle_touch_down;
|
||||||
|
|
||||||
|
wl_signal_add(&wlr_cursor->events.touch_up, &seat->cursor->touch_up);
|
||||||
|
seat->cursor->touch_up.notify = handle_touch_up;
|
||||||
|
|
||||||
|
wl_signal_add(&wlr_cursor->events.touch_motion, &seat->cursor->touch_motion);
|
||||||
|
seat->cursor->touch_motion.notify = handle_touch_motion;
|
||||||
|
|
||||||
|
wl_signal_add(&wlr_cursor->events.tablet_tool_axis, &seat->cursor->tool_axis);
|
||||||
|
seat->cursor->tool_axis.notify = handle_tool_axis;
|
||||||
|
|
||||||
|
wl_signal_add(&wlr_cursor->events.tablet_tool_tip, &seat->cursor->tool_tip);
|
||||||
|
seat->cursor->tool_tip.notify = handle_tool_tip;
|
||||||
|
|
||||||
|
wl_signal_add(&seat->seat->events.request_set_cursor,
|
||||||
|
&seat->cursor->request_set_cursor);
|
||||||
|
seat->cursor->request_set_cursor.notify = handle_request_set_cursor;
|
||||||
|
|
||||||
|
wl_signal_add(&seat->seat->events.pointer_grab_begin,
|
||||||
|
&seat->cursor->pointer_grab_begin);
|
||||||
|
seat->cursor->pointer_grab_begin.notify = handle_pointer_grab_begin;
|
||||||
|
|
||||||
|
wl_signal_add(&seat->seat->events.pointer_grab_end,
|
||||||
|
&seat->cursor->pointer_grab_end);
|
||||||
|
seat->cursor->pointer_grab_end.notify = handle_pointer_grab_end;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
wl_list_init(&seat->keyboards);
|
||||||
|
wl_list_init(&seat->pointers);
|
||||||
|
wl_list_init(&seat->touch);
|
||||||
|
wl_list_init(&seat->tablet_tools);
|
||||||
|
wl_list_init(&seat->drag_icons);
|
||||||
|
|
||||||
|
seat->input = input;
|
||||||
|
|
||||||
|
seat->seat = wlr_seat_create(input->server->wl_display, name);
|
||||||
|
if (!seat->seat) {
|
||||||
|
free(seat);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
roots_seat_init_cursor(seat);
|
||||||
|
if (!seat->cursor) {
|
||||||
|
wlr_seat_destroy(seat->seat);
|
||||||
|
free(seat);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
wlr_seat_set_capabilities(seat->seat,
|
||||||
|
WL_SEAT_CAPABILITY_KEYBOARD |
|
||||||
|
WL_SEAT_CAPABILITY_POINTER |
|
||||||
|
WL_SEAT_CAPABILITY_TOUCH);
|
||||||
|
|
||||||
|
wl_list_insert(&input->seats, &seat->link);
|
||||||
|
|
||||||
|
return seat;
|
||||||
|
}
|
||||||
|
|
||||||
|
void roots_seat_destroy(struct roots_seat *seat) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
static void seat_add_keyboard(struct roots_seat *seat, struct wlr_input_device *device) {
|
||||||
|
assert(device->type == WLR_INPUT_DEVICE_KEYBOARD);
|
||||||
|
struct roots_keyboard *keyboard = roots_keyboard_create(device, seat->input);
|
||||||
|
if (keyboard == NULL) {
|
||||||
|
wlr_log(L_ERROR, "could not allocate keyboard for seat");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
keyboard->seat = seat;
|
||||||
|
|
||||||
|
wl_list_insert(&seat->keyboards, &keyboard->link);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
wlr_seat_set_keyboard(seat->seat, device);
|
||||||
|
}
|
||||||
|
|
||||||
|
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->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->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->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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void seat_remove_keyboard(struct roots_seat *seat,
|
||||||
|
struct wlr_input_device *device) {
|
||||||
|
struct roots_keyboard *keyboard;
|
||||||
|
wl_list_for_each(keyboard, &seat->keyboards, link) {
|
||||||
|
if (keyboard->device == device) {
|
||||||
|
roots_keyboard_destroy(keyboard);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void seat_remove_pointer(struct roots_seat *seat,
|
||||||
|
struct wlr_input_device *device) {
|
||||||
|
struct roots_pointer *pointer;
|
||||||
|
wl_list_for_each(pointer, &seat->pointers, link) {
|
||||||
|
if (pointer->device == device) {
|
||||||
|
wl_list_remove(&pointer->link);
|
||||||
|
wlr_cursor_detach_input_device(seat->cursor->cursor, device);
|
||||||
|
free(pointer);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void seat_remove_touch(struct roots_seat *seat,
|
||||||
|
struct wlr_input_device *device) {
|
||||||
|
struct roots_touch *touch;
|
||||||
|
wl_list_for_each(touch, &seat->touch, link) {
|
||||||
|
if (touch->device == device) {
|
||||||
|
wl_list_remove(&touch->link);
|
||||||
|
wlr_cursor_detach_input_device(seat->cursor->cursor, device);
|
||||||
|
free(touch);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void seat_remove_tablet_pad(struct roots_seat *seat,
|
||||||
|
struct wlr_input_device *device) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
static void seat_remove_tablet_tool(struct roots_seat *seat,
|
||||||
|
struct wlr_input_device *device) {
|
||||||
|
struct roots_tablet_tool *tablet_tool;
|
||||||
|
wl_list_for_each(tablet_tool, &seat->tablet_tools, link) {
|
||||||
|
if (tablet_tool->device == device) {
|
||||||
|
wl_list_remove(&tablet_tool->link);
|
||||||
|
wlr_cursor_detach_input_device(seat->cursor->cursor, device);
|
||||||
|
free(tablet_tool);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void roots_seat_remove_device(struct roots_seat *seat,
|
||||||
|
struct wlr_input_device *device) {
|
||||||
|
switch (device->type) {
|
||||||
|
case WLR_INPUT_DEVICE_KEYBOARD:
|
||||||
|
seat_remove_keyboard(seat, device);
|
||||||
|
break;
|
||||||
|
case WLR_INPUT_DEVICE_POINTER:
|
||||||
|
seat_remove_pointer(seat, device);
|
||||||
|
break;
|
||||||
|
case WLR_INPUT_DEVICE_TOUCH:
|
||||||
|
seat_remove_touch(seat, device);
|
||||||
|
break;
|
||||||
|
case WLR_INPUT_DEVICE_TABLET_PAD:
|
||||||
|
seat_remove_tablet_pad(seat, device);
|
||||||
|
break;
|
||||||
|
case WLR_INPUT_DEVICE_TABLET_TOOL:
|
||||||
|
seat_remove_tablet_tool(seat, device);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void roots_seat_configure_xcursor(struct roots_seat *seat) {
|
||||||
|
struct roots_output *output;
|
||||||
|
wl_list_for_each(output, &seat->input->server->desktop->outputs, link) {
|
||||||
|
if (wlr_xcursor_manager_load(seat->cursor->xcursor_manager,
|
||||||
|
output->wlr_output->scale)) {
|
||||||
|
wlr_log(L_ERROR, "Cannot load xcursor theme for output '%s' "
|
||||||
|
"with scale %d", output->wlr_output->name,
|
||||||
|
output->wlr_output->scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager,
|
||||||
|
ROOTS_XCURSOR_DEFAULT, seat->cursor->cursor);
|
||||||
|
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;
|
||||||
|
wl_list_for_each(keyboard, &seat->keyboards, link) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void roots_seat_focus_view(struct roots_seat *seat, struct roots_view *view) {
|
||||||
|
struct roots_desktop *desktop = seat->input->server->desktop;
|
||||||
|
if (seat->focus == view) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (view && view->type == ROOTS_XWAYLAND_VIEW &&
|
||||||
|
view->xwayland_surface->override_redirect) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct roots_view *prev_focus = seat->focus;
|
||||||
|
seat->focus = view;
|
||||||
|
|
||||||
|
// unfocus the old view if it is not focused by some other seat
|
||||||
|
if (prev_focus && !input_view_has_focus(seat->input, prev_focus)) {
|
||||||
|
view_activate(prev_focus, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!seat->focus) {
|
||||||
|
seat->cursor->mode = ROOTS_CURSOR_PASSTHROUGH;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t index = 0;
|
||||||
|
for (size_t i = 0; i < desktop->views->length; ++i) {
|
||||||
|
struct roots_view *_view = desktop->views->items[i];
|
||||||
|
if (_view == view) {
|
||||||
|
index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
view_activate(view, true);
|
||||||
|
// TODO: list_swap
|
||||||
|
wlr_list_del(desktop->views, index);
|
||||||
|
wlr_list_add(desktop->views, view);
|
||||||
|
wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
cursor->view_x = view->x;
|
||||||
|
cursor->view_y = view->y;
|
||||||
|
}
|
||||||
|
view_maximize(view, false);
|
||||||
|
wlr_seat_pointer_clear_focus(seat->seat);
|
||||||
|
|
||||||
|
wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager,
|
||||||
|
ROOTS_XCURSOR_MOVE, seat->cursor->cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view,
|
||||||
|
uint32_t edges) {
|
||||||
|
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 {
|
||||||
|
cursor->view_x = view->x;
|
||||||
|
cursor->view_y = view->y;
|
||||||
|
struct wlr_box box;
|
||||||
|
view_get_box(view, &box);
|
||||||
|
cursor->view_width = box.width;
|
||||||
|
cursor->view_height = box.height;
|
||||||
|
}
|
||||||
|
cursor->resize_edges = edges;
|
||||||
|
view_maximize(view, false);
|
||||||
|
wlr_seat_pointer_clear_focus(seat->seat);
|
||||||
|
|
||||||
|
wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager,
|
||||||
|
roots_xcursor_get_resize_name(edges), seat->cursor->cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void roots_seat_begin_rotate(struct roots_seat *seat, struct roots_view *view) {
|
||||||
|
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);
|
||||||
|
wlr_seat_pointer_clear_focus(seat->seat);
|
||||||
|
|
||||||
|
wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager,
|
||||||
|
ROOTS_XCURSOR_ROTATE, seat->cursor->cursor);
|
||||||
|
}
|
@ -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 <wlr/util/log.h>
|
|
||||||
#include "rootston/input.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);
|
|
||||||
}
|
|
@ -1,26 +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"
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
@ -0,0 +1,84 @@
|
|||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <wlr/types/wlr_xcursor_manager.h>
|
||||||
|
|
||||||
|
struct wlr_xcursor_manager *wlr_xcursor_manager_create(const char *name,
|
||||||
|
uint32_t size) {
|
||||||
|
struct wlr_xcursor_manager *manager =
|
||||||
|
calloc(1, sizeof(struct wlr_xcursor_manager));
|
||||||
|
if (manager == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (name != NULL) {
|
||||||
|
manager->name = strdup(name);
|
||||||
|
}
|
||||||
|
manager->size = size;
|
||||||
|
wl_list_init(&manager->scaled_themes);
|
||||||
|
return manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wlr_xcursor_manager_destroy(struct wlr_xcursor_manager *manager) {
|
||||||
|
if (manager == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
struct wlr_xcursor_manager_theme *theme, *tmp;
|
||||||
|
wl_list_for_each_safe(theme, tmp, &manager->scaled_themes, link) {
|
||||||
|
wl_list_remove(&theme->link);
|
||||||
|
wlr_xcursor_theme_destroy(theme->theme);
|
||||||
|
free(theme);
|
||||||
|
}
|
||||||
|
free(manager->name);
|
||||||
|
free(manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
int wlr_xcursor_manager_load(struct wlr_xcursor_manager *manager,
|
||||||
|
uint32_t scale) {
|
||||||
|
struct wlr_xcursor_manager_theme *theme;
|
||||||
|
wl_list_for_each(theme, &manager->scaled_themes, link) {
|
||||||
|
if (theme->scale == scale) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
theme = calloc(1, sizeof(struct wlr_xcursor_manager_theme));
|
||||||
|
if (theme == NULL) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
theme->scale = scale;
|
||||||
|
theme->theme = wlr_xcursor_theme_load(NULL, manager->size * scale);
|
||||||
|
if (theme->theme == NULL) {
|
||||||
|
free(theme);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
wl_list_insert(&manager->scaled_themes, &theme->link);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct wlr_xcursor *wlr_xcursor_manager_get_xcursor(
|
||||||
|
struct wlr_xcursor_manager *manager, const char *name, uint32_t scale) {
|
||||||
|
struct wlr_xcursor_manager_theme *theme;
|
||||||
|
wl_list_for_each(theme, &manager->scaled_themes, link) {
|
||||||
|
if (theme->scale == scale) {
|
||||||
|
return wlr_xcursor_theme_get_cursor(theme->theme, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wlr_xcursor_manager_set_cursor_image(struct wlr_xcursor_manager *manager,
|
||||||
|
const char *name, struct wlr_cursor *cursor) {
|
||||||
|
struct wlr_xcursor_manager_theme *theme;
|
||||||
|
wl_list_for_each(theme, &manager->scaled_themes, link) {
|
||||||
|
struct wlr_xcursor *xcursor =
|
||||||
|
wlr_xcursor_theme_get_cursor(theme->theme, name);
|
||||||
|
if (xcursor == NULL) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct wlr_xcursor_image *image = xcursor->images[0];
|
||||||
|
wlr_cursor_set_image(cursor, image->buffer, image->width,
|
||||||
|
image->width, image->height, image->hotspot_x, image->hotspot_y,
|
||||||
|
theme->scale);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue