Skip to content

Commit

Permalink
Avoid setting cursor image multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
serebit committed Nov 3, 2023
1 parent e18d367 commit 390551d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/input/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "surface/surface.hpp"
#include "surface/view.hpp"

#include <cstring>
#include <iostream>

#include "wlr-wrap-start.hpp"
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
/*
Expand All @@ -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;
Expand All @@ -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;
}
}
3 changes: 3 additions & 0 deletions src/input/cursor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "types.hpp"

#include <functional>
#include <string>

#include "wlr-wrap-start.hpp"
#include <wlr/types/wlr_cursor.h>
Expand Down Expand Up @@ -49,13 +50,15 @@ 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;

void attach_input_device(wlr_input_device* device);
void process_motion(uint32_t time);
void reset_mode();
void warp_to_constraint(PointerConstraint& constraint);
void set_image(const std::string name);
};

#endif

0 comments on commit 390551d

Please sign in to comment.