feat: add more protocols + touch support:
* add touch support (experimental) * add support for wlr_cursor_shape_v1 * add support for wlr_relative_pointer_manager_v1
This commit is contained in:
136
cursor.c
136
cursor.c
@@ -1,11 +1,13 @@
|
||||
#define _POSIX_C_SOURCE 200112L
|
||||
#include <wlr/util/log.h>
|
||||
#include <wlr/types/wlr_cursor_shape_v1.h>
|
||||
#include <assert.h>
|
||||
#include "cursor.h"
|
||||
#include "view.h"
|
||||
#include "seat.h"
|
||||
#include "node.h"
|
||||
#include "idle.h"
|
||||
#include "touch.h"
|
||||
|
||||
void diyac_cursor_focus(struct diyac_server *server)
|
||||
{
|
||||
@@ -56,10 +58,10 @@ void diyac_reset_cursor_mode(struct diyac_server *server)
|
||||
|
||||
static void process_cursor_move(struct diyac_server *server, uint32_t time)
|
||||
{
|
||||
(void) time;
|
||||
(void)time;
|
||||
struct diyac_view *toplevel = server->grabbed_view;
|
||||
/* Move the grabbed toplevel to the new position. */
|
||||
if(!toplevel->output)
|
||||
if (!toplevel->output)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -86,7 +88,7 @@ static void process_cursor_move(struct diyac_server *server, uint32_t time)
|
||||
|
||||
static void process_cursor_resize(struct diyac_server *server, uint32_t time)
|
||||
{
|
||||
(void) time;
|
||||
(void)time;
|
||||
/*
|
||||
* Resizing the grabbed toplevel can be a little bit complicated, because we
|
||||
* could be resizing from any corner or edge. This not only resizes the
|
||||
@@ -98,7 +100,7 @@ static void process_cursor_resize(struct diyac_server *server, uint32_t time)
|
||||
* size, then commit any movement that was prepared.
|
||||
*/
|
||||
struct diyac_view *toplevel = server->grabbed_view;
|
||||
if(toplevel->state.fullscreen)
|
||||
if (toplevel->state.fullscreen)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -218,6 +220,11 @@ static void server_cursor_motion(struct wl_listener *listener, void *data)
|
||||
wl_container_of(listener, seat, cursor_motion);
|
||||
struct wlr_pointer_motion_event *event = data;
|
||||
diya_idle_manager_notify_activity(seat->wlr_seat);
|
||||
wlr_relative_pointer_manager_v1_send_relative_motion(
|
||||
seat->server->relative_pointer_manager,
|
||||
seat->wlr_seat, (uint64_t)event->time_msec * 1000,
|
||||
event->delta_x, event->delta_y, event->unaccel_dx,
|
||||
event->unaccel_dy);
|
||||
/* The cursor doesn't move unless we tell it to. The cursor automatically
|
||||
* handles constraining the motion to the output layout, as well as any
|
||||
* special configuration applied for the specific input device which
|
||||
@@ -241,6 +248,16 @@ static void server_cursor_motion_absolute(
|
||||
wl_container_of(listener, seat, cursor_motion_absolute);
|
||||
diya_idle_manager_notify_activity(seat->wlr_seat);
|
||||
struct wlr_pointer_motion_absolute_event *event = data;
|
||||
|
||||
double lx, ly;
|
||||
wlr_cursor_absolute_to_layout_coords(seat->cursor,
|
||||
&event->pointer->base, event->x, event->y, &lx, &ly);
|
||||
double dx = lx - seat->cursor->x;
|
||||
double dy = ly - seat->cursor->y;
|
||||
wlr_relative_pointer_manager_v1_send_relative_motion(
|
||||
seat->server->relative_pointer_manager,
|
||||
seat->wlr_seat, (uint64_t)event->time_msec * 1000,
|
||||
dx, dy, dx, dy);
|
||||
wlr_cursor_warp_absolute(seat->cursor, &event->pointer->base, event->x,
|
||||
event->y);
|
||||
process_cursor_motion(seat->server, event->time_msec);
|
||||
@@ -285,7 +302,7 @@ static void server_cursor_axis(struct wl_listener *listener, void *data)
|
||||
|
||||
static void server_cursor_frame(struct wl_listener *listener, void *data)
|
||||
{
|
||||
(void) data;
|
||||
(void)data;
|
||||
/* This event is forwarded by the cursor when a pointer emits an frame
|
||||
* event. Frame events are sent after regular pointer events to group
|
||||
* multiple events together. For instance, two axis events may happen at the
|
||||
@@ -296,6 +313,90 @@ static void server_cursor_frame(struct wl_listener *listener, void *data)
|
||||
wlr_seat_pointer_notify_frame(seat->wlr_seat);
|
||||
}
|
||||
|
||||
static void request_set_shape_notify(struct wl_listener *listener, void *data)
|
||||
{
|
||||
struct wlr_cursor_shape_manager_v1_request_set_shape_event *event = data;
|
||||
const char *shape_name = wlr_cursor_shape_v1_name(event->shape);
|
||||
struct diyac_seat *seat = wl_container_of(listener, seat, request_set_shape);
|
||||
struct wlr_seat_client *focused_client = seat->wlr_seat->pointer_state.focused_client;
|
||||
|
||||
/* Prevent setting a cursor image when moving or resizing */
|
||||
if (seat->cursor_mode != DIYAC_CURSOR_PASSTHROUGH)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Omit set shape when the current cursor is
|
||||
* invisible, e.g. on touch input.
|
||||
|
||||
if (!seat->cursor_visible)
|
||||
{
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
* This can be sent by any client, so we check to make sure this one
|
||||
* actually has pointer focus first.
|
||||
*/
|
||||
if (event->seat_client != focused_client)
|
||||
{
|
||||
wlr_log(WLR_INFO, "seat client %p != focused client %p",
|
||||
event->seat_client, focused_client);
|
||||
return;
|
||||
}
|
||||
|
||||
wlr_log(WLR_DEBUG, "set xcursor to shape %s", shape_name);
|
||||
wlr_cursor_set_xcursor(seat->cursor, seat->cursor_mgr, shape_name);
|
||||
}
|
||||
|
||||
void diyac_cursor_emulate_move(struct diyac_seat *seat, struct wlr_input_device *device, double dx, double dy, uint32_t time_msec)
|
||||
{
|
||||
if (!dx && !dy)
|
||||
{
|
||||
wlr_log(WLR_DEBUG, "dropping useless cursor_emulate: %.10f,%.10f", dx, dy);
|
||||
return;
|
||||
}
|
||||
|
||||
wlr_relative_pointer_manager_v1_send_relative_motion(
|
||||
seat->server->relative_pointer_manager,
|
||||
seat->wlr_seat, (uint64_t)time_msec * 1000,
|
||||
dx, dy, dx, dy);
|
||||
|
||||
wlr_cursor_move(seat->cursor, device, dx, dy);
|
||||
process_cursor_motion(seat->server, time_msec);
|
||||
}
|
||||
|
||||
void diyac_cursor_emulate_move_absolute(struct diyac_seat *seat, struct wlr_input_device *device, double x, double y, uint32_t time_msec)
|
||||
{
|
||||
double lx, ly;
|
||||
wlr_cursor_absolute_to_layout_coords(seat->cursor, device, x, y, &lx, &ly);
|
||||
|
||||
double dx = lx - seat->cursor->x;
|
||||
double dy = ly - seat->cursor->y;
|
||||
|
||||
diyac_cursor_emulate_move(seat, device, dx, dy, time_msec);
|
||||
}
|
||||
|
||||
void diyac_cursor_emulate_button(struct diyac_seat *seat, uint32_t button, enum wl_pointer_button_state state, uint32_t time_msec)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case WL_POINTER_BUTTON_STATE_PRESSED:
|
||||
wlr_seat_pointer_notify_button(seat->wlr_seat, time_msec, button, state);
|
||||
diyac_cursor_focus(seat->server);
|
||||
break;
|
||||
case WL_POINTER_BUTTON_STATE_RELEASED:
|
||||
wlr_seat_pointer_notify_button(seat->wlr_seat, time_msec, button, state);
|
||||
diyac_reset_cursor_mode(seat->server);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
wlr_seat_pointer_notify_frame(seat->wlr_seat);
|
||||
}
|
||||
|
||||
void diyac_init_cursor_manager(struct diyac_server *server)
|
||||
{
|
||||
/*
|
||||
@@ -333,4 +434,29 @@ void diyac_init_cursor_manager(struct diyac_server *server)
|
||||
wl_signal_add(&server->seat.cursor->events.axis, &server->seat.cursor_axis);
|
||||
server->seat.cursor_frame.notify = server_cursor_frame;
|
||||
wl_signal_add(&server->seat.cursor->events.frame, &server->seat.cursor_frame);
|
||||
|
||||
struct wlr_cursor_shape_manager_v1 *cursor_shape_manager =
|
||||
wlr_cursor_shape_manager_v1_create(server->wl_display, 1);
|
||||
if (cursor_shape_manager)
|
||||
{
|
||||
server->seat.request_set_shape.notify = request_set_shape_notify;
|
||||
wl_signal_add(&cursor_shape_manager->events.request_set_shape,
|
||||
&server->seat.request_set_shape);
|
||||
}
|
||||
diyac_touch_init(&server->seat);
|
||||
}
|
||||
|
||||
void diyac_finish_cusor_manager(struct diyac_server *server)
|
||||
{
|
||||
wl_list_remove(&server->seat.cursor_motion.link);
|
||||
wl_list_remove(&server->seat.cursor_motion_absolute.link);
|
||||
wl_list_remove(&server->seat.cursor_button.link);
|
||||
wl_list_remove(&server->seat.cursor_axis.link);
|
||||
wl_list_remove(&server->seat.cursor_frame.link);
|
||||
wl_list_remove(&server->seat.request_cursor.link);
|
||||
wl_list_remove(&server->seat.request_set_shape.link);
|
||||
wl_list_remove(&server->seat.request_set_selection.link);
|
||||
wl_list_remove(&server->seat.request_set_primary_selection.link);
|
||||
|
||||
diyac_touch_drop(&server->seat);
|
||||
}
|
Reference in New Issue
Block a user