2019-12-26 21:37:31 +00:00
|
|
|
#include "labwc.h"
|
|
|
|
|
|
2019-12-27 22:34:00 +00:00
|
|
|
static void server_new_pointer(struct server *server,
|
|
|
|
|
struct wlr_input_device *device)
|
|
|
|
|
{
|
2020-05-26 12:56:33 +01:00
|
|
|
/* TODO: Configure libinput on device to set tap, acceleration, etc */
|
2019-12-27 22:34:00 +00:00
|
|
|
wlr_cursor_attach_input_device(server->cursor, device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void server_new_input(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
2020-05-26 12:56:33 +01:00
|
|
|
/*
|
|
|
|
|
* 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:
|
|
|
|
|
server_new_keyboard(server, device);
|
|
|
|
|
break;
|
|
|
|
|
case WLR_INPUT_DEVICE_POINTER:
|
|
|
|
|
server_new_pointer(server, device);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-05-26 12:56:33 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 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);
|
2020-05-26 12:56:33 +01:00
|
|
|
/*
|
|
|
|
|
* 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;
|
2020-05-26 12:56:33 +01:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-26 21:37:31 +00:00
|
|
|
void server_new_output(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
2019-12-27 21:22:45 +00:00
|
|
|
/* This event is rasied by the backend when a new output (aka a display
|
|
|
|
|
* or monitor) becomes available. */
|
|
|
|
|
struct server *server = wl_container_of(listener, server, new_output);
|
2019-12-26 21:37:31 +00:00
|
|
|
struct wlr_output *wlr_output = data;
|
|
|
|
|
|
2020-05-10 20:10:36 +01:00
|
|
|
/*
|
|
|
|
|
* Some backends don't have modes. DRM+KMS does, and we need to set a
|
2019-12-27 21:22:45 +00:00
|
|
|
* mode before we can use the output. The mode is a tuple of (width,
|
|
|
|
|
* height, refresh rate), and each monitor supports only a specific set
|
2020-05-10 20:10:36 +01:00
|
|
|
* of modes. We just pick the monitor's preferred mode.
|
|
|
|
|
* TODO: support user configuration
|
|
|
|
|
*/
|
2019-12-26 21:37:31 +00:00
|
|
|
if (!wl_list_empty(&wlr_output->modes)) {
|
2020-05-12 21:00:33 +01:00
|
|
|
struct wlr_output_mode *mode =
|
|
|
|
|
wlr_output_preferred_mode(wlr_output);
|
2019-12-26 21:37:31 +00:00
|
|
|
wlr_output_set_mode(wlr_output, mode);
|
2020-05-10 20:10:36 +01:00
|
|
|
wlr_output_enable(wlr_output, true);
|
|
|
|
|
if (!wlr_output_commit(wlr_output)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-12-26 21:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Allocates and configures our state for this output */
|
2019-12-27 21:22:45 +00:00
|
|
|
struct output *output = calloc(1, sizeof(struct output));
|
2019-12-26 21:37:31 +00:00
|
|
|
output->wlr_output = wlr_output;
|
|
|
|
|
output->server = server;
|
|
|
|
|
/* Sets up a listener for the frame notify event. */
|
|
|
|
|
output->frame.notify = output_frame;
|
|
|
|
|
wl_signal_add(&wlr_output->events.frame, &output->frame);
|
|
|
|
|
wl_list_insert(&server->outputs, &output->link);
|
|
|
|
|
|
2019-12-27 21:22:45 +00:00
|
|
|
/* Adds this to the output layout. The add_auto function arranges
|
|
|
|
|
* outputs from left-to-right in the order they appear. A more
|
|
|
|
|
* sophisticated compositor would let the user configure the arrangement
|
2020-05-11 07:00:20 +01:00
|
|
|
* of outputs in the layout.
|
|
|
|
|
*
|
2020-05-12 21:00:33 +01:00
|
|
|
* The output layout utility automatically adds a wl_output global to
|
|
|
|
|
* the display, which Wayland clients can see to find out information
|
|
|
|
|
* about the output (such as DPI, scale factor, manufacturer, etc).
|
2020-05-11 07:00:20 +01:00
|
|
|
*/
|
2019-12-26 21:37:31 +00:00
|
|
|
wlr_output_layout_add_auto(server->output_layout, wlr_output);
|
|
|
|
|
}
|