Skip to content

Commit

Permalink
Don't send action if it hasn't changed
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanGriffiths committed Jun 27, 2023
1 parent 8e052b2 commit 32d33f0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/server/frontend_wayland/wl_data_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,21 @@ class mf::WlDataDevice::Offer : public wayland::DataOffer

void set_actions(uint32_t dnd_actions, uint32_t preferred_action) override
{
send_action_event_if_supported(source->offer_set_actions(dnd_actions, preferred_action));
const auto action = source->offer_set_actions(dnd_actions, preferred_action);

if (!dnd_action || dnd_action.value() != action)
{
dnd_action = action;
send_action_event_if_supported(action);
}
}

private:
friend mf::WlDataDevice;
wayland::Weak<WlDataDevice> const device;
std::shared_ptr<ms::DataExchangeSource> const source;
std::optional<std::string> accepted_mime_type;
std::optional<uint32_t> dnd_action;
};

mf::WlDataDevice::Offer::Offer(WlDataDevice* device, std::shared_ptr<ms::DataExchangeSource> const& source) :
Expand Down
6 changes: 5 additions & 1 deletion src/server/frontend_wayland/wl_data_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,11 @@ uint32_t mf::WlDataSource::drag_n_drop_set_actions(uint32_t dnd_actions, uint32_
{
if (action | acceptable_options)
{
send_action_event_if_supported(action);
if (!dnd_action || dnd_action.value() != action)
{
dnd_action = action;
send_action_event_if_supported(action);
}
return action;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/server/frontend_wayland/wl_data_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class WlDataSource : public wayland::DataSource
std::weak_ptr<scene::DataExchangeSource> dnd_source;
bool dnd_source_source_is_ours{false};
uint32_t dnd_actions;
std::optional<uint32_t> dnd_action;
std::optional<DragIconSurface> drag_surface;
};
}
Expand Down

0 comments on commit 32d33f0

Please sign in to comment.