cursor: Use enum for server set cursor names

This mainly prevents having to use strcmp() on every mouse move.
This commit is contained in:
Consolatis 2022-09-16 02:23:44 +02:00 committed by Johan Malm
parent f491942858
commit e30fce6c34
5 changed files with 110 additions and 76 deletions

View file

@ -66,9 +66,9 @@ struct cursor_context get_cursor_context(struct server *server);
/**
* cursor_set - set cursor icon
* @seat - current seat
* @cursor_name - name of cursor, for example "left_ptr" or "grab"
* @cursor - name of cursor, for example LAB_CURSOR_DEFAULT or LAB_CURSOR_GRAB
*/
void cursor_set(struct seat *seat, const char *cursor_name);
void cursor_set(struct seat *seat, enum lab_cursors cursor);
/**
* cursor_get_resize_edges - calculate resize edge based on cursor position
@ -84,6 +84,18 @@ void cursor_set(struct seat *seat, const char *cursor_name);
uint32_t cursor_get_resize_edges(struct wlr_cursor *cursor,
struct cursor_context *ctx);
/**
* cursor_get_from_edge - translate wlroots edge enum to lab_cursor enum
* @resize_edges - WLR_EDGE_ combination like WLR_EDGE_TOP | WLR_EDGE_RIGHT
*
* Returns LAB_CURSOR_DEFAULT on WLR_EDGE_NONE
* Returns the appropriate lab_cursors enum if @resize_edges
* is one of the 4 corners or one of the 4 edges.
*
* Asserts on invalid edge combinations like WLR_EDGE_LEFT | WLR_EDGE_RIGHT
*/
enum lab_cursors cursor_get_from_edge(uint32_t resize_edges);
/**
* cursor_update_focus - update cursor focus, may update the cursor icon
* @server - server

View file

@ -59,7 +59,6 @@
#define XCURSOR_DEFAULT "left_ptr"
#define XCURSOR_SIZE 24
#define XCURSOR_MOVE "grabbing"
enum input_mode {
LAB_INPUT_STATE_PASSTHROUGH = 0,
@ -80,13 +79,12 @@ struct seat {
struct server *server;
struct wlr_keyboard_group *keyboard_group;
bool cursor_requires_fallback;
/*
* Name of most recent server-side cursor image. Set by
* Enum of most recent server-side cursor image. Set by
* cursor_set(). Cleared when a client surface is entered
* (in that case the client is expected to set a cursor image).
* (in that case the client is expected to set its own cursor image).
*/
char *cursor_set_by_server;
enum lab_cursors server_cursor;
struct wlr_cursor *cursor;
struct wlr_xcursor_manager *xcursor_manager;