From 0bf92fff058caab7ed3e13a5d488a629b4ac9a46 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 1 Jan 2022 13:56:50 +0100 Subject: term: add term_set_user_mouse_cursor() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This function allows setting a custom mouse cursor. This is done by adding a ‘char*’ member to the term struct. When it is non-NULL, we *always* use that pointer (the exception being when the pointer is hidden), while the pointer is over the grid. This is instead of the hand/beam pointers we otherwise would use. --- terminal.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 631e8e68..27ea033a 100644 --- a/terminal.c +++ b/terminal.c @@ -1681,6 +1681,7 @@ term_destroy(struct terminal *term) free(term->foot_exe); free(term->cwd); + free(term->mouse_user_cursor); int ret = EXIT_SUCCESS; @@ -1820,6 +1821,8 @@ term_reset(struct terminal *term, bool hard) tll_free_and_free(term->window_title_stack, free); term_set_window_title(term, term->conf->title); + term_set_user_mouse_cursor(term, NULL); + memset(term->normal.kitty_kbd.flags, 0, sizeof(term->normal.kitty_kbd.flags)); memset(term->alt.kitty_kbd.flags, 0, sizeof(term->alt.kitty_kbd.flags)); term->normal.kitty_kbd.idx = term->alt.kitty_kbd.idx = 0; @@ -2986,7 +2989,11 @@ term_xcursor_update_for_seat(struct terminal *term, struct seat *seat) switch (term->active_surface) { case TERM_SURF_GRID: { + bool have_custom_cursor = + render_xcursor_is_valid(seat, term->mouse_user_cursor); + xcursor = seat->pointer.hidden ? XCURSOR_HIDDEN + : have_custom_cursor ? term->mouse_user_cursor : term->is_searching ? XCURSOR_LEFT_PTR : (seat->mouse.col >= 0 && seat->mouse.row >= 0 && @@ -3575,3 +3582,11 @@ term_osc8_close(struct terminal *term) term->vt.osc8.id = 0; term_update_ascii_printer(term); } + +void +term_set_user_mouse_cursor(struct terminal *term, const char *cursor) +{ + free(term->mouse_user_cursor); + term->mouse_user_cursor = cursor != NULL ? xstrdup(cursor) : NULL; + term_xcursor_update(term); +} -- cgit v1.3