Set cursor to box when not in default mode

This commit is contained in:
project-repo 2022-12-24 14:52:12 +01:00
commit baeb39579b
4 changed files with 42 additions and 20 deletions

View file

@ -39,14 +39,12 @@
#include <wlr/types/wlr_screencopy_v1.h>
#include <wlr/types/wlr_server_decoration.h>
#include <wlr/types/wlr_viewporter.h>
#if CG_HAS_XWAYLAND
#include <wlr/types/wlr_xcursor_manager.h>
#endif
#include <wlr/types/wlr_xdg_decoration_v1.h>
#include <wlr/types/wlr_xdg_output_v1.h>
#include <wlr/types/wlr_xdg_shell.h>
#include <wlr/util/log.h>
#if CG_HAS_XWAYLAND
#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/xwayland.h>
#endif
@ -247,7 +245,6 @@ main(int argc, char *argv[]) {
struct wlr_xdg_shell *xdg_shell = NULL;
#if CG_HAS_XWAYLAND
struct wlr_xwayland *xwayland = NULL;
struct wlr_xcursor_manager *xcursor_manager = NULL;
#endif
int ret = 0;
@ -285,6 +282,17 @@ main(int argc, char *argv[]) {
return 1;
}
server.xcursor_size=XCURSOR_SIZE;
const char *env_cursor_size = getenv("XCURSOR_SIZE");
if (env_cursor_size && strlen(env_cursor_size) > 0) {
errno = 0;
char *end;
unsigned size = strtoul(env_cursor_size, &end, 10);
if (!*end && errno == 0) {
server.xcursor_size = size;
}
}
server.running = true;
server.modes[0] = strdup("top");
@ -534,13 +542,6 @@ main(int argc, char *argv[]) {
server.new_xwayland_surface.notify = handle_xwayland_surface_new;
wl_signal_add(&xwayland->events.new_surface, &server.new_xwayland_surface);
xcursor_manager = wlr_xcursor_manager_create(DEFAULT_XCURSOR, XCURSOR_SIZE);
if(!xcursor_manager) {
wlr_log(WLR_ERROR, "Cannot create XWayland XCursor manager");
ret = 1;
goto end;
}
if(setenv("DISPLAY", xwayland->display_name, true) < 0) {
wlr_log_errno(WLR_ERROR, "Unable to set DISPLAY for XWayland.",
"Clients may not be able to connect");
@ -549,11 +550,9 @@ main(int argc, char *argv[]) {
xwayland->display_name);
}
if(!wlr_xcursor_manager_load(xcursor_manager, 1)) {
wlr_log(WLR_ERROR, "Cannot load XWayland XCursor theme");
}
struct wlr_xcursor *xcursor =
wlr_xcursor_manager_get_xcursor(xcursor_manager, DEFAULT_XCURSOR, 1);
wlr_xcursor_manager_get_xcursor(server.seat->xcursor_manager, DEFAULT_XCURSOR, 1);
if(xcursor) {
struct wlr_xcursor_image *image = xcursor->images[0];
wlr_xwayland_set_cursor(xwayland, image->buffer, image->width * 4,
@ -644,7 +643,6 @@ main(int argc, char *argv[]) {
#if CG_HAS_XWAYLAND
wlr_xwayland_destroy(xwayland);
wlr_xcursor_manager_destroy(xcursor_manager);
#endif
wl_display_destroy_clients(server.wl_display);

View file

@ -11,6 +11,7 @@
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/util/log.h>
#include <wlr/types/wlr_xcursor_manager.h>
#include "input.h"
#include "input_manager.h"
@ -1458,6 +1459,11 @@ run_action(enum keybinding_action action, struct cg_server *server,
keybinding_switch_output(server, data.u);
break;
case KEYBINDING_SWITCH_MODE:
if(data.u!=server->seat->default_mode) {
wlr_seat_pointer_notify_clear_focus(server->seat->seat);
wlr_xcursor_manager_set_cursor_image(server->seat->xcursor_manager,
"dot_box_mask", server->seat->cursor);
}
server->seat->mode = data.u;
break;
case KEYBINDING_SWITCH_DEFAULT_MODE:

25
seat.c
View file

@ -197,9 +197,26 @@ handle_command_key_bindings(struct cg_server *server, xkb_keysym_t sym,
struct keybinding **keybinding = find_keybinding(
server->keybindings,
&(struct keybinding){.key = sym, .mode = mode, .modifiers = modifiers});
server->seat->mode =
server->seat
->default_mode; // Return to mode we are currently in by default
if(server->seat->mode != server->seat->default_mode) {
server->seat->mode =
server->seat
->default_mode; // Return to mode we are currently in by default
double sx, sy;
struct wlr_seat *wlr_seat = server->seat->seat;
struct wlr_surface *surface = NULL;
struct wlr_scene_node *node = wlr_scene_node_at(
&server->scene->node, server->seat->cursor->x, server->seat->cursor->y, &sx, &sy);
if(node && node->type == WLR_SCENE_NODE_SURFACE) {
surface = wlr_scene_surface_from_node(node)->surface;
wlr_seat_pointer_notify_enter(wlr_seat, surface, sx, sy);
} else {
wlr_xcursor_manager_set_cursor_image(server->seat->xcursor_manager,
"left_ptr", server->seat->cursor);
}
}
if(keybinding) {
wlr_log(
WLR_DEBUG,
@ -851,7 +868,7 @@ seat_create(struct cg_server *server, struct wlr_backend *backend) {
wlr_cursor_attach_output_layout(seat->cursor, server->output_layout);
if(!seat->xcursor_manager) {
seat->xcursor_manager = wlr_xcursor_manager_create(NULL, XCURSOR_SIZE);
seat->xcursor_manager = wlr_xcursor_manager_create(NULL, server->xcursor_size);
if(!seat->xcursor_manager) {
wlr_log(WLR_ERROR, "Cannot create XCursor manager");
wlr_cursor_destroy(seat->cursor);

View file

@ -60,6 +60,7 @@ struct cg_server {
float *bg_color;
uint32_t views_curr_id;
uint32_t tiles_curr_id;
uint32_t xcursor_size;
};
void