From 390551d89eb8b903693d3dd8b28b0420f0ffaa8a Mon Sep 17 00:00:00 2001 From: Campbell Jones Date: Fri, 3 Nov 2023 17:12:25 -0400 Subject: [PATCH] Avoid setting cursor image multiple times --- src/input/cursor.cpp | 15 ++++++++++++--- src/input/cursor.hpp | 3 +++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/input/cursor.cpp b/src/input/cursor.cpp index ca9063f6f..3cde39768 100644 --- a/src/input/cursor.cpp +++ b/src/input/cursor.cpp @@ -6,6 +6,7 @@ #include "surface/surface.hpp" #include "surface/view.hpp" +#include #include #include "wlr-wrap-start.hpp" @@ -76,7 +77,8 @@ void Cursor::process_move(const uint32_t time) { View* view = seat.server.grabbed_view; view->current.x = cursor->x - seat.server.grab_x; view->current.y = fmax(cursor->y - seat.server.grab_y, 0); - wlr_xcursor_manager_set_cursor_image(cursor_mgr, "fleur", cursor); + + set_image("fleur"); wlr_scene_node_set_position(view->scene_node, view->current.x, view->current.y); } @@ -319,7 +321,7 @@ void Cursor::process_motion(const uint32_t time) { /* If there's no view under the cursor, set the cursor image to a * default. This is what makes the cursor image appear when you move it * around the screen, not over any views. */ - wlr_xcursor_manager_set_cursor_image(cursor_mgr, "left_ptr", cursor); + set_image("left_ptr"); } if (surface) { /* @@ -344,7 +346,7 @@ void Cursor::process_motion(const uint32_t time) { void Cursor::reset_mode() { if (mode != MAGPIE_CURSOR_PASSTHROUGH) { - wlr_xcursor_manager_set_cursor_image(cursor_mgr, "left_ptr", cursor); + set_image("left_ptr"); } mode = MAGPIE_CURSOR_PASSTHROUGH; seat.server.grabbed_view = NULL; @@ -368,3 +370,10 @@ void Cursor::warp_to_constraint(PointerConstraint& constraint) { wlr_seat_pointer_warp(seat.seat, x, y); } } + +void Cursor::set_image(const std::string name) { + if (current_image != name) { + wlr_xcursor_manager_set_cursor_image(cursor_mgr, name.c_str(), cursor); + current_image = name; + } +} diff --git a/src/input/cursor.hpp b/src/input/cursor.hpp index ed97db539..8e7c8cf0c 100644 --- a/src/input/cursor.hpp +++ b/src/input/cursor.hpp @@ -5,6 +5,7 @@ #include "types.hpp" #include +#include #include "wlr-wrap-start.hpp" #include @@ -49,6 +50,7 @@ class Cursor { wlr_xcursor_manager* cursor_mgr; wlr_relative_pointer_manager_v1* relative_pointer_mgr; wlr_pointer_gestures_v1* pointer_gestures; + std::string current_image = ""; Cursor(Seat& seat) noexcept; @@ -56,6 +58,7 @@ class Cursor { void process_motion(uint32_t time); void reset_mode(); void warp_to_constraint(PointerConstraint& constraint); + void set_image(const std::string name); }; #endif