Skip to content

Commit

Permalink
pointer: mark updates caused by geometry change as real updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ammen99 committed Feb 8, 2024
1 parent c538afd commit a85211c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
50 changes: 29 additions & 21 deletions src/core/seat/pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "wayfire/scene.hpp"
#include "wayfire/signal-definitions.hpp"

#include "../scene-priv.hpp"
#include <wayfire/debug.hpp>
#include <wayfire/util/log.hpp>
#include <wayfire/core.hpp>
Expand All @@ -30,7 +29,7 @@ wf::pointer_t::pointer_t(nonstd::observer_ptr<wf::input_manager_t> input,
grab_surface(nullptr);
}

update_cursor_position(get_current_time(), false);
update_cursor_position(get_current_time());
};

wf::get_core().scene()->connect(&on_root_node_updated);
Expand Down Expand Up @@ -60,7 +59,7 @@ void wf::pointer_t::set_enable_focus(bool enabled)
this->update_cursor_focus(nullptr);
} else
{
update_cursor_position(get_current_time(), false);
update_cursor_position(get_current_time());
}
}

Expand All @@ -69,7 +68,7 @@ bool wf::pointer_t::focus_enabled() const
return this->focus_enabled_count > 0;
}

void wf::pointer_t::update_cursor_position(int64_t time_msec, bool real_update)
void wf::pointer_t::update_cursor_position(int64_t time_msec)
{
wf::pointf_t gc = seat->priv->cursor->get_cursor_position();

Expand All @@ -84,15 +83,11 @@ void wf::pointer_t::update_cursor_position(int64_t time_msec, bool real_update)
update_cursor_focus(isec ? isec->node->shared_from_this() : nullptr);
}

if (real_update)
{
this->send_motion(time_msec);
}

this->send_motion(time_msec);
seat->priv->update_drag_icon();
}

void wf::pointer_t::force_release_buttons()
void wf::pointer_t::send_leave_to_focus()
{
if (cursor_focus)
{
Expand All @@ -111,6 +106,7 @@ void wf::pointer_t::force_release_buttons()
}

cursor_focus->pointer_interaction().handle_pointer_leave();
this->last_focus_coords = {};
}
}

Expand All @@ -125,14 +121,11 @@ void wf::pointer_t::transfer_grab(scene::node_ptr node)
}

LOGC(POINTER, "transfer grab ", cursor_focus.get(), " -> ", node.get());
force_release_buttons();
send_leave_to_focus();
cursor_focus = node;

// Send pointer_enter to the grab
auto gc = wf::get_core().get_cursor_position();
auto local = get_node_local_coords(node.get(), gc);
node->pointer_interaction().handle_pointer_enter(local);

send_enter_to_focus();
if (!node->wants_raw_input())
{
currently_sent_buttons.clear();
Expand All @@ -147,6 +140,14 @@ void wf::pointer_t::transfer_grab(scene::node_ptr node)
}
}

void wf::pointer_t::send_enter_to_focus()
{
auto gc = wf::get_core().get_cursor_position();
auto local = get_node_local_coords(cursor_focus.get(), gc);
cursor_focus->pointer_interaction().handle_pointer_enter(local);
this->last_focus_coords = local;
}

void wf::pointer_t::update_cursor_focus(wf::scene::node_ptr new_focus)
{
bool focus_change = (cursor_focus != new_focus);
Expand All @@ -160,16 +161,14 @@ void wf::pointer_t::update_cursor_focus(wf::scene::node_ptr new_focus)
// buttons since otherwise we'll cancel DnD
if (focus_change)
{
force_release_buttons();
send_leave_to_focus();
currently_sent_buttons.clear();
}

cursor_focus = new_focus;
if (focus_change && new_focus)
{
auto gc = wf::get_core().get_cursor_position();
auto local = get_node_local_coords(new_focus.get(), gc);
new_focus->pointer_interaction().handle_pointer_enter(local);
send_enter_to_focus();
} else if (focus_change)
{
// If there is focused surface, we should reset the cursor image to
Expand Down Expand Up @@ -200,7 +199,7 @@ void wf::pointer_t::grab_surface(wf::scene::node_ptr node)

/* End grab */
grabbed_node = nullptr;
update_cursor_position(get_current_time(), false);
update_cursor_position(get_current_time());
}

/* ----------------------- Input event processing --------------------------- */
Expand Down Expand Up @@ -296,7 +295,16 @@ void wf::pointer_t::send_motion(uint32_t time_msec)
{
auto gc = wf::get_core().get_cursor_position();
auto local = get_node_local_coords(cursor_focus.get(), gc);
cursor_focus->pointer_interaction().handle_pointer_motion(local, time_msec);

if (!last_focus_coords.has_value() ||
(local.x != last_focus_coords->x) || (local.y != last_focus_coords->y))
{
// NB: the pointer motion could go to a grab, which could trigger scenegraph changes, which
// trigger re-focus. We need to set the last focus coordinates early, so that we break out of
// infinite loops.
last_focus_coords = local;
cursor_focus->pointer_interaction().handle_pointer_motion(local, time_msec);
}
}
}

Expand Down
13 changes: 9 additions & 4 deletions src/core/seat/pointer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ class pointer_t
* surface currently under the pointer.
*
* @param time_msec The time when the event causing this update occurred
* @param real_update Whether the update is caused by a hardware event or
* was artificially generated.
*/
void update_cursor_position(int64_t time_msec, bool real_update = true);
void update_cursor_position(int64_t time_msec);

/**
* Transfer focus and pressed buttons to the given grab.
Expand All @@ -93,6 +91,11 @@ class pointer_t
nonstd::observer_ptr<wf::input_manager_t> input;
nonstd::observer_ptr<seat_t> seat;

// Store the last motion / surface-local coords sent to the current focus.
// This is useful to avoid sending repetitive motion events if we for ex. have scenegraph changes, but no
// actual movement of the mouse.
std::optional<wf::pointf_t> last_focus_coords;

// Buttons sent to the client currently
// Note that count_pressed_buttons also contains buttons not sent to the
// client
Expand All @@ -107,6 +110,8 @@ class pointer_t
int focus_enabled_count = 1;
bool focus_enabled() const;

void send_enter_to_focus();

/**
* Set the pointer focus.
*/
Expand Down Expand Up @@ -138,7 +143,7 @@ class pointer_t
/**
* Send synthetic button release events to the current cursor focus.
*/
void force_release_buttons();
void send_leave_to_focus();
};
}

Expand Down

0 comments on commit a85211c

Please sign in to comment.