mirror of
https://github.com/wizbright/waybox.git
synced 2025-10-29 05:40:20 -04:00
More cleanups; added missing request_cursor functionality
This commit is contained in:
parent
8bc4352eb8
commit
cd96e1c124
6 changed files with 43 additions and 17 deletions
|
|
@ -25,9 +25,11 @@ struct wb_cursor {
|
|||
struct wl_listener cursor_button;
|
||||
struct wl_listener cursor_axis;
|
||||
struct wl_listener cursor_frame;
|
||||
|
||||
struct wl_listener request_cursor;
|
||||
};
|
||||
|
||||
struct wb_cursor *wb_cursor_create();
|
||||
struct wb_cursor *wb_cursor_create(struct wb_server *server);
|
||||
void wb_cursor_destroy(struct wb_cursor *cursor);
|
||||
|
||||
#endif // cursor.h
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@
|
|||
struct wb_output {
|
||||
struct wlr_output *wlr_output;
|
||||
struct wb_server *server;
|
||||
struct timespec last_frame;
|
||||
|
||||
struct wl_listener destroy;
|
||||
struct wl_listener frame;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
#endif
|
||||
#define _POSIX_C_SOURCE 200112L
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <wlr/backend.h>
|
||||
|
|
@ -28,7 +27,6 @@
|
|||
|
||||
struct wb_server {
|
||||
struct wl_display *wl_display;
|
||||
struct wl_event_loop *wl_event_loop;
|
||||
|
||||
struct wlr_backend *backend;
|
||||
struct wlr_compositor *compositor;
|
||||
|
|
|
|||
|
|
@ -140,9 +140,30 @@ static void handle_cursor_frame(struct wl_listener *listener, void *data) {
|
|||
wlr_seat_pointer_notify_frame(cursor->server->seat->seat);
|
||||
}
|
||||
|
||||
struct wb_cursor *wb_cursor_create() {
|
||||
static void handle_cursor_request(struct wl_listener *listener, void *data) {
|
||||
struct wb_cursor *cursor = wl_container_of(
|
||||
listener, cursor, request_cursor);
|
||||
/* This event is rasied by the seat when a client provides a cursor image */
|
||||
struct wlr_seat_pointer_request_set_cursor_event *event = data;
|
||||
struct wlr_seat_client *focused_client =
|
||||
cursor->server->seat->seat->pointer_state.focused_client;
|
||||
/* 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(cursor->cursor, event->surface,
|
||||
event->hotspot_x, event->hotspot_y);
|
||||
}
|
||||
}
|
||||
|
||||
struct wb_cursor *wb_cursor_create(struct wb_server *server) {
|
||||
struct wb_cursor *cursor = malloc(sizeof(struct wb_cursor));
|
||||
cursor->cursor = wlr_cursor_create();
|
||||
cursor->server = server;
|
||||
|
||||
cursor->xcursor_manager = wlr_xcursor_manager_create("default", 24);
|
||||
wlr_xcursor_manager_load(cursor->xcursor_manager, 1);
|
||||
|
||||
|
|
@ -161,6 +182,12 @@ struct wb_cursor *wb_cursor_create() {
|
|||
cursor->cursor_frame.notify = handle_cursor_frame;
|
||||
wl_signal_add(&cursor->cursor->events.frame, &cursor->cursor_frame);
|
||||
|
||||
cursor->request_cursor.notify = handle_cursor_request;
|
||||
wl_signal_add(&server->seat->seat->events.request_set_cursor,
|
||||
&cursor->request_cursor);
|
||||
|
||||
wlr_cursor_attach_output_layout(cursor->cursor, server->layout);
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -105,7 +105,6 @@ void output_frame_notify(struct wl_listener *listener, void *data) {
|
|||
|
||||
wlr_renderer_end(renderer);
|
||||
wlr_output_commit(wlr_output);
|
||||
output->last_frame = now;
|
||||
}
|
||||
|
||||
void output_destroy_notify(struct wl_listener *listener, void *data) {
|
||||
|
|
@ -134,7 +133,6 @@ void new_output_notify(struct wl_listener *listener, void *data) {
|
|||
}
|
||||
|
||||
struct wb_output *output = calloc(1, sizeof(struct wb_output));
|
||||
clock_gettime(CLOCK_MONOTONIC, &output->last_frame);
|
||||
output->server = server;
|
||||
output->wlr_output = wlr_output;
|
||||
wl_list_insert(&server->outputs, &output->link);
|
||||
|
|
|
|||
|
|
@ -5,15 +5,13 @@ bool init_wb(struct wb_server* server) {
|
|||
|
||||
// create display
|
||||
server->wl_display = wl_display_create();
|
||||
assert(server->wl_display);
|
||||
|
||||
// event loop stuff
|
||||
server->wl_event_loop = wl_display_get_event_loop(server->wl_display);
|
||||
assert(server->wl_event_loop);
|
||||
if (server->wl_display == NULL) {
|
||||
fprintf(stderr, "Failed to connect to a Wayland display\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// create backend
|
||||
server->backend = wlr_backend_autocreate(server->wl_display, NULL);
|
||||
assert(server->backend);
|
||||
if (server->backend == NULL) {
|
||||
printf("Failed to create backend\n");
|
||||
return false;
|
||||
|
|
@ -23,10 +21,8 @@ bool init_wb(struct wb_server* server) {
|
|||
wlr_renderer_init_wl_display(server->renderer, server->wl_display);
|
||||
|
||||
server->layout = wlr_output_layout_create();
|
||||
server->cursor = wb_cursor_create();
|
||||
server->cursor->server = server;
|
||||
wlr_cursor_attach_output_layout(server->cursor->cursor, server->layout);
|
||||
server->seat = wb_seat_create(server);
|
||||
server->cursor = wb_cursor_create(server);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -38,10 +34,15 @@ bool start_wb(struct wb_server* server) {
|
|||
wl_signal_add(&server->backend->events.new_output, &server->new_output);
|
||||
|
||||
const char *socket = wl_display_add_socket_auto(server->wl_display);
|
||||
assert(socket);
|
||||
if (!socket)
|
||||
{
|
||||
wlr_backend_destroy(server->backend);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!wlr_backend_start(server->backend)) {
|
||||
fprintf(stderr, "Failed to start backend\n");
|
||||
wlr_backend_destroy(server->backend);
|
||||
wl_display_destroy(server->wl_display);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -64,6 +65,7 @@ bool start_wb(struct wb_server* server) {
|
|||
}
|
||||
|
||||
bool terminate_wb(struct wb_server* server) {
|
||||
wl_display_destroy_clients(server->wl_display);
|
||||
wb_cursor_destroy(server->cursor);
|
||||
wb_seat_destroy(server->seat);
|
||||
wlr_output_layout_destroy(server->layout);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue