mirror of
https://github.com/wizbright/waybox.git
synced 2025-10-29 05:40:20 -04:00
Added very basic cursor tracking
No interaction with wayland clients yet. Just draws the cursor where the pointer device points.
This commit is contained in:
parent
4d2c67040c
commit
4f231567a7
6 changed files with 90 additions and 1 deletions
18
include/waybox/cursor.h
Normal file
18
include/waybox/cursor.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef CURSOR_H
|
||||
#define CURSOR_H
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/types/wlr_cursor.h>
|
||||
#include <wlr/types/wlr_xcursor_manager.h>
|
||||
|
||||
struct wb_cursor {
|
||||
struct wlr_cursor *cursor;
|
||||
struct wlr_xcursor_manager *xcursor_manager;
|
||||
|
||||
struct wl_listener cursor_motion;
|
||||
struct wl_listener cursor_motion_absolute;
|
||||
};
|
||||
|
||||
struct wb_cursor *wb_cursor_create();
|
||||
void wb_cursor_destroy(struct wb_cursor *cursor);
|
||||
|
||||
#endif // cursor.h
|
||||
|
|
@ -19,9 +19,10 @@
|
|||
#include <wlr/types/wlr_matrix.h>
|
||||
#include <wlr/types/wlr_gamma_control.h>
|
||||
#include <wlr/types/wlr_primary_selection.h>
|
||||
#include <wlr/types/wlr_output_layout.h>
|
||||
|
||||
#include "waybox/output.h"
|
||||
|
||||
#include "waybox/cursor.h"
|
||||
|
||||
struct wb_server {
|
||||
struct wl_display *wl_display;
|
||||
|
|
@ -30,7 +31,11 @@ struct wb_server {
|
|||
struct wlr_backend *backend;
|
||||
struct wlr_compositor *compositor;
|
||||
|
||||
struct wlr_output_layout *layout;
|
||||
struct wb_cursor *cursor;
|
||||
|
||||
struct wl_listener new_output;
|
||||
struct wl_listener new_input;
|
||||
struct wl_list outputs; // wb_output::link
|
||||
};
|
||||
|
||||
|
|
|
|||
38
waybox/cursor.c
Normal file
38
waybox/cursor.c
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#include <stdlib.h>
|
||||
#include "waybox/cursor.h"
|
||||
|
||||
static void handle_cursor_motion(struct wl_listener *listener, void *data) {
|
||||
struct wb_cursor *cursor = wl_container_of(listener, cursor, cursor_motion);
|
||||
struct wlr_event_pointer_motion *event = data;
|
||||
wlr_cursor_move(cursor->cursor, event->device, event->delta_x, event->delta_y);
|
||||
}
|
||||
|
||||
static void handle_cursor_motion_absolute(struct wl_listener *listener, void *data) {
|
||||
struct wb_cursor *cursor = wl_container_of(listener, cursor, cursor_motion_absolute);
|
||||
struct wlr_event_pointer_motion_absolute *event = data;
|
||||
wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, event->y);
|
||||
}
|
||||
|
||||
struct wb_cursor *wb_cursor_create() {
|
||||
struct wb_cursor *cursor = malloc(sizeof(struct wb_cursor));
|
||||
cursor->cursor = wlr_cursor_create();
|
||||
cursor->xcursor_manager = wlr_xcursor_manager_create("default", 24);
|
||||
|
||||
cursor->cursor_motion.notify = handle_cursor_motion;
|
||||
wl_signal_add(&cursor->cursor->events.motion, &cursor->cursor_motion);
|
||||
|
||||
cursor->cursor_motion_absolute.notify = handle_cursor_motion_absolute;
|
||||
wl_signal_add(&cursor->cursor->events.motion_absolute, &cursor->cursor_motion_absolute);
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
void wb_cursor_destroy(struct wb_cursor *cursor) {
|
||||
if (!cursor) {
|
||||
return;
|
||||
}
|
||||
|
||||
wlr_xcursor_manager_destroy(cursor->xcursor_manager);
|
||||
wlr_cursor_destroy(cursor->cursor);
|
||||
free(cursor);
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
wb_src = files(
|
||||
'cursor.c',
|
||||
'main.c',
|
||||
'output.c',
|
||||
'server.c',
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ void output_frame_notify(struct wl_listener *listener, void *data) {
|
|||
|
||||
void output_destroy_notify(struct wl_listener *listener, void *data) {
|
||||
struct wb_output *output = wl_container_of(listener, output, destroy);
|
||||
wlr_output_layout_remove(output->server->layout, output->wlr_output);
|
||||
wl_list_remove(&output->link);
|
||||
wl_list_remove(&output->destroy.link);
|
||||
wl_list_remove(&output->frame.link);
|
||||
|
|
@ -72,4 +73,8 @@ void new_output_notify(struct wl_listener *listener, void *data) {
|
|||
wl_signal_add(&wlr_output->events.destroy, &output->destroy);
|
||||
output->frame.notify = output_frame_notify;
|
||||
wl_signal_add(&wlr_output->events.frame, &output->frame);
|
||||
|
||||
wlr_output_layout_add_auto(server->layout, output->wlr_output);
|
||||
wlr_xcursor_manager_load(server->cursor->xcursor_manager, output->wlr_output->scale);
|
||||
wlr_xcursor_manager_set_cursor_image(server->cursor->xcursor_manager, "left_ptr", server->cursor->cursor);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,17 @@
|
|||
#include "waybox/server.h"
|
||||
|
||||
static void new_input_notify(struct wl_listener *listener, void *data) {
|
||||
struct wlr_input_device *device = data;
|
||||
struct wb_server *server = wl_container_of(listener, server, new_input);
|
||||
switch (device->type) {
|
||||
case WLR_INPUT_DEVICE_POINTER:
|
||||
wlr_cursor_attach_input_device(server->cursor->cursor, device);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool init_wb(struct wb_server* server) {
|
||||
|
||||
// create display
|
||||
|
|
@ -21,6 +33,10 @@ bool init_wb(struct wb_server* server) {
|
|||
return false;
|
||||
}
|
||||
|
||||
server->layout = wlr_output_layout_create();
|
||||
server->cursor = wb_cursor_create();
|
||||
wlr_cursor_attach_output_layout(server->cursor->cursor, server->layout);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -30,6 +46,9 @@ bool start_wb(struct wb_server* server) {
|
|||
server->new_output.notify = new_output_notify;
|
||||
wl_signal_add(&server->backend->events.new_output, &server->new_output);
|
||||
|
||||
server->new_input.notify = new_input_notify;
|
||||
wl_signal_add(&server->backend->events.new_input, &server->new_input);
|
||||
|
||||
const char *socket = wl_display_add_socket_auto(server->wl_display);
|
||||
assert(socket);
|
||||
|
||||
|
|
@ -58,5 +77,8 @@ bool terminate_wb(struct wb_server* server) {
|
|||
|
||||
printf("Display destroyed.\n");
|
||||
|
||||
wb_cursor_destroy(server->cursor);
|
||||
wlr_output_layout_destroy(server->layout);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue