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

ipc: add more ipc events #2252

Merged
merged 12 commits into from
Mar 24, 2024
143 changes: 141 additions & 2 deletions plugins/single_plugins/ipc-rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,14 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
method_repository->connect(&on_client_disconnected);
wf::get_core().connect(&on_view_mapped);
wf::get_core().connect(&on_view_unmapped);
wf::get_core().connect(&on_view_set_output);
wf::get_core().connect(&on_view_geometry_changed);
wf::get_core().connect(&on_view_moved_to_wset);
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);
wf::get_core().connect(&on_output_gain_focus);
init_output_tracking();
}

Expand Down Expand Up @@ -179,6 +183,8 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
output->connect(&_tiled);
output->connect(&_minimized);
output->connect(&_fullscreened);
output->connect(&_stickied);
output->connect(&_view_workspace);
output->connect(&on_wset_changed);
output->connect(&on_wset_workspace_changed);

Expand Down Expand Up @@ -301,6 +307,11 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker

nlohmann::json output_to_json(wf::output_t *o)
{
if (!o)
{
return nullptr;
}

nlohmann::json response;
response["id"] = o->get_id();
response["name"] = o->to_string();
Expand Down Expand Up @@ -343,6 +354,7 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
WFJSON_EXPECT_FIELD(data, "id", number_integer);
WFJSON_OPTIONAL_FIELD(data, "output_id", number_integer);
WFJSON_OPTIONAL_FIELD(data, "geometry", object);
WFJSON_OPTIONAL_FIELD(data, "sticky", boolean);

auto view = wf::ipc::find_view_by_id(data["id"]);
if (!view)
Expand Down Expand Up @@ -378,11 +390,21 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
toplevel->set_geometry(*geometry);
}

if (data.contains("sticky"))
{
toplevel->set_sticky(data["sticky"]);
}

return wf::ipc::json_ok();
};

nlohmann::json wset_to_json(wf::workspace_set_t *wset)
{
if (!wset)
{
return nullptr;
}

nlohmann::json response;
response["index"] = wset->get_index();
response["name"] = wset->to_string();
Expand Down Expand Up @@ -458,6 +480,11 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker

void send_view_to_subscribes(wayfire_view view, std::string event_name)
{
if (clients.empty())
{
return;
}

nlohmann::json event;
event["event"] = event_name;
event["view"] = view_to_json(view);
Expand Down Expand Up @@ -485,16 +512,72 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
send_view_to_subscribes(ev->view, "view-unmapped");
};

wf::signal::connection_t<wf::view_set_output_signal> on_view_set_output =
[=] (wf::view_set_output_signal *ev)
{
if (clients.empty())
{
return;
}

nlohmann::json data;
data["event"] = "view-set-output";
data["output"] = output_to_json(ev->output);
data["view"] = view_to_json(ev->view);
send_event_to_subscribes(data, data["event"]);
};

wf::signal::connection_t<wf::view_geometry_changed_signal> on_view_geometry_changed =
[=] (wf::view_geometry_changed_signal *ev)
{
if (clients.empty())
{
return;
}

nlohmann::json data;
data["event"] = "view-geometry-changed";
data["old-geometry"] = wf::ipc::geometry_to_json(ev->old_geometry);
data["view"] = view_to_json(ev->view);
send_event_to_subscribes(data, data["event"]);
};

wf::signal::connection_t<wf::view_moved_to_wset_signal> on_view_moved_to_wset =
[=] (wf::view_moved_to_wset_signal *ev)
{
if (clients.empty())
{
return;
}

nlohmann::json data;
data["event"] = "view-wset-changed";
data["old-wset"] = wset_to_json(ev->old_wset.get());
data["new-wset"] = wset_to_json(ev->new_wset.get());
data["view"] = view_to_json(ev->view);
send_event_to_subscribes(data, data["event"]);
};

wf::signal::connection_t<wf::keyboard_focus_changed_signal> on_kbfocus_changed =
[=] (wf::keyboard_focus_changed_signal *ev)
{
send_view_to_subscribes(wf::node_to_view(ev->new_focus), "view-focused");
};

// Maximized rule handler.
// Tiled rule handler.
wf::signal::connection_t<wf::view_tiled_signal> _tiled = [=] (wf::view_tiled_signal *ev)
{
send_view_to_subscribes(ev->view, "view-tiled");
if (clients.empty())
{
return;
}

nlohmann::json data;
data["event"] = "view-tiled";
data["old-edges"] = ev->old_edges;
data["new-edges"] = ev->new_edges;
data["view"] = view_to_json(ev->view);
send_event_to_subscribes(data, data["event"]);
};

// Minimized rule handler.
Expand All @@ -509,6 +592,28 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
send_view_to_subscribes(ev->view, "view-fullscreen");
};

// Stickied rule handler.
wf::signal::connection_t<wf::view_set_sticky_signal> _stickied = [=] (wf::view_set_sticky_signal *ev)
{
send_view_to_subscribes(ev->view, "view-sticky");
};

wf::signal::connection_t<wf::view_change_workspace_signal> _view_workspace =
[=] (wf::view_change_workspace_signal *ev)
{
if (clients.empty())
{
return;
}

nlohmann::json data;
data["event"] = "view-workspace-changed";
data["from"] = wf::ipc::point_to_json(ev->from);
data["to"] = wf::ipc::point_to_json(ev->to);
data["view"] = view_to_json(ev->view);
send_event_to_subscribes(data, data["event"]);
};

wf::signal::connection_t<wf::view_title_changed_signal> on_title_changed =
[=] (wf::view_title_changed_signal *ev)
{
Expand All @@ -524,33 +629,67 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
wf::signal::connection_t<wf::output_plugin_activated_changed_signal> on_plugin_activation_changed =
[=] (wf::output_plugin_activated_changed_signal *ev)
{
if (clients.empty())
{
return;
}

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;
data["output-data"] = output_to_json(ev->output);
send_event_to_subscribes(data, data["event"]);
};

wf::signal::connection_t<wf::output_gain_focus_signal> on_output_gain_focus =
[=] (wf::output_gain_focus_signal *ev)
{
if (clients.empty())
{
return;
}

nlohmann::json data;
data["event"] = "output-gain-focus";
data["output"] = output_to_json(ev->output);
send_event_to_subscribes(data, data["event"]);
};

wf::signal::connection_t<wf::workspace_set_changed_signal> on_wset_changed =
[=] (wf::workspace_set_changed_signal *ev)
{
if (clients.empty())
{
return;
}

nlohmann::json data;
data["event"] = "output-wset-changed";
data["new-wset"] = ev->new_wset ? (int)ev->new_wset->get_id() : -1;
data["output"] = ev->output ? (int)ev->output->get_id() : -1;
data["new-wset-data"] = wset_to_json(ev->new_wset.get());
data["output-data"] = output_to_json(ev->output);
send_event_to_subscribes(data, data["event"]);
};

wf::signal::connection_t<wf::workspace_changed_signal> on_wset_workspace_changed =
[=] (wf::workspace_changed_signal *ev)
{
if (clients.empty())
{
return;
}

nlohmann::json data;
data["event"] = "wset-workspace-changed";
data["previous-workspace"] = wf::ipc::point_to_json(ev->old_viewport);
data["new-workspace"] = wf::ipc::point_to_json(ev->new_viewport);
data["output"] = ev->output ? (int)ev->output->get_id() : -1;
data["wset"] = (ev->output && ev->output->wset()) ? (int)ev->output->wset()->get_id() : -1;
data["output-data"] = output_to_json(ev->output);
data["wset-data"] = ev->output ? wset_to_json(ev->output->wset().get()) : nullptr;
send_event_to_subscribes(data, data["event"]);
};

Expand Down
Loading