diff --git a/cagebreak.c b/cagebreak.c index 954649a..5eb95f0 100644 --- a/cagebreak.c +++ b/cagebreak.c @@ -39,14 +39,12 @@ #include #include #include -#if CG_HAS_XWAYLAND -#include -#endif #include #include #include #include #if CG_HAS_XWAYLAND +#include #include #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); diff --git a/keybinding.c b/keybinding.c index 9a3f908..0211a0f 100644 --- a/keybinding.c +++ b/keybinding.c @@ -11,6 +11,7 @@ #include #include #include +#include #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: diff --git a/seat.c b/seat.c index b161d0b..89b1eb8 100644 --- a/seat.c +++ b/seat.c @@ -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); diff --git a/server.h b/server.h index fbaab40..551f726 100644 --- a/server.h +++ b/server.h @@ -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