labwc/src/server.c

64 lines
1.9 KiB
C
Raw Normal View History

2019-12-26 21:37:31 +00:00
#include "labwc.h"
2019-12-27 22:34:00 +00:00
void server_new_input(struct wl_listener *listener, void *data)
{
/*
* This event is raised by the backend when a new input device becomes
* available.
*/
2019-12-27 22:34:00 +00:00
struct server *server = wl_container_of(listener, server, new_input);
struct wlr_input_device *device = data;
switch (device->type) {
case WLR_INPUT_DEVICE_KEYBOARD:
keyboard_new(server, device);
2019-12-27 22:34:00 +00:00
break;
case WLR_INPUT_DEVICE_POINTER:
2020-05-29 22:18:03 +01:00
cursor_new(server, device);
2019-12-27 22:34:00 +00:00
break;
default:
break;
}
/*
* We need to let the wlr_seat know what our capabilities are, which is
* communiciated to the client.
*/
2019-12-27 22:34:00 +00:00
uint32_t caps = WL_SEAT_CAPABILITY_POINTER;
if (!wl_list_empty(&server->keyboards)) {
caps |= WL_SEAT_CAPABILITY_KEYBOARD;
}
wlr_seat_set_capabilities(server->seat, caps);
}
void seat_request_cursor(struct wl_listener *listener, void *data)
{
struct server *server =
wl_container_of(listener, server, request_cursor);
/*
* This event is rasied by the seat when a client provides a cursor
* image
*/
2019-12-27 22:34:00 +00:00
struct wlr_seat_pointer_request_set_cursor_event *event = data;
struct wlr_seat_client *focused_client =
server->seat->pointer_state.focused_client;
2019-12-27 22:34:00 +00:00
/* This can be sent by any client, so we check to make sure this one is
* actually has pointer focus first. */
if (focused_client == event->seat_client) {
/* Once we've vetted the client, we can tell the cursor to use
* the provided surface as the cursor image. It will set the
* hardware cursor on the output that it's currently on and
* continue to do so as the cursor moves between outputs. */
wlr_cursor_set_surface(server->cursor, event->surface,
event->hotspot_x, event->hotspot_y);
}
}
2020-05-12 21:00:33 +01:00
void seat_request_set_selection(struct wl_listener *listener, void *data)
{
struct server *server =
wl_container_of(listener, server, request_set_selection);
struct wlr_seat_request_set_selection_event *event = data;
wlr_seat_set_selection(server->seat, event->source, event->serial);
}