Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api, ipc: add signal for when a plugin is activated or deactivated #2144

Merged
merged 1 commit into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion plugins/single_plugins/ipc-rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
wf::get_core().connect(&on_kbfocus_changed);
wf::get_core().connect(&on_title_changed);
wf::get_core().connect(&on_app_id_changed);
wf::get_core().connect(&on_plugin_activation_changed);
init_output_tracking();
}

Expand Down Expand Up @@ -372,11 +373,16 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
nlohmann::json event;
event["event"] = event_name;
event["view"] = view_to_json(view);
send_event_to_subscribes(event, event_name);
}

void send_event_to_subscribes(const nlohmann::json& data, const std::string& event_name)
{
for (auto& [client, events] : clients)
{
if (events.empty() || events.count(event_name))
{
client->send_json(event);
client->send_json(data);
}
}
}
Expand Down Expand Up @@ -427,6 +433,17 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
send_view_to_subscribes(ev->view, "view-app-id-changed");
};

wf::signal::connection_t<wf::output_plugin_activated_changed_signal> on_plugin_activation_changed =
[=] (wf::output_plugin_activated_changed_signal *ev)
{
nlohmann::json data;
data["event"] = "plugin-activation-state-changed";
data["plugin"] = ev->plugin_name;
data["state"] = ev->activated;
data["output"] = ev->output ? (int)ev->output->get_id() : -1;
send_event_to_subscribes(data, data["event"]);
};

std::string get_view_type(wayfire_view view)
{
if (view->role == wf::VIEW_ROLE_TOPLEVEL)
Expand Down
2 changes: 1 addition & 1 deletion src/api/wayfire/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class plugin_interface_t
using wayfire_plugin_load_func = wf::plugin_interface_t * (*)();

/** The version of Wayfire's API/ABI */
constexpr uint32_t WAYFIRE_API_ABI_VERSION = 2023'11'23;
constexpr uint32_t WAYFIRE_API_ABI_VERSION = 2024'02'16;

/**
* Each plugin must also provide a function which returns the Wayfire API/ABI
Expand Down
17 changes: 16 additions & 1 deletion src/api/wayfire/signal-definitions.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef SIGNAL_DEFINITIONS_HPP
#define SIGNAL_DEFINITIONS_HPP

#include "wayfire/object.hpp"
#include "wayfire/view.hpp"
#include "wayfire/output.hpp"

Expand Down Expand Up @@ -263,6 +262,22 @@ struct output_gain_focus_signal
wf::output_t *output;
};

/**
* on: output, core
* when: When an output activates or deactivates. Note that not all plugin actions are reflected with this
* signal. A plugin activates on an output usually if it (temporarily) changes the way Wayfire works like
* Expo, Scale, Vswitch. One-shot actions like command or wsets do not send this signal.
*/
struct output_plugin_activated_changed_signal
{
// The output on which the plugin was activated. May be NULL if the plugin works globally.
wf::output_t *output;
// The name of the plugin.
std::string plugin_name;
// Whether the plugin was activated (true) or deactivated (false).
bool activated;
};

/* ----------------------------------------------------------------------------/
* Output rendering signals (see also wayfire/workspace-stream.hpp)
* -------------------------------------------------------------------------- */
Expand Down
14 changes: 13 additions & 1 deletion src/output/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,13 @@ bool wf::output_impl_t::activate_plugin(wf::plugin_activation_data_t *owner, uin
} else
{
LOGD("output ", handle->name, ": activate plugin ", owner->name);

wf::output_plugin_activated_changed_signal data;
data.output = this;
data.plugin_name = owner->name;
data.activated = true;
this->emit(&data);
wf::get_core().emit(&data);
}

active_plugins.insert(owner);
Expand All @@ -312,7 +319,12 @@ bool wf::output_impl_t::deactivate_plugin(wf::plugin_activation_data_t *owner)

if (active_plugins.count(owner) == 0)
{
active_plugins.erase(owner);
wf::output_plugin_activated_changed_signal data;
data.output = this;
data.plugin_name = owner->name;
data.activated = false;
this->emit(&data);
wf::get_core().emit(&data);
return true;
}

Expand Down
Loading