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
149 changes: 141 additions & 8 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 @@ -343,6 +349,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,6 +385,11 @@ 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();
};

Expand Down Expand Up @@ -458,6 +470,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 +502,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 @@ -506,7 +579,38 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
// Fullscreened rule handler.
wf::signal::connection_t<wf::view_fullscreen_signal> _fullscreened = [=] (wf::view_fullscreen_signal *ev)
{
send_view_to_subscribes(ev->view, "view-fullscreen");
if (clients.empty())
{
return;
}

nlohmann::json data;
data["event"] = "view-fullscreen";
data["state"] = ev->state;
CharlieQLe marked this conversation as resolved.
Show resolved Hide resolved
data["view"] = view_to_json(ev->view);
send_event_to_subscribes(data, data["event"]);
};

// 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 =
Expand All @@ -524,33 +628,62 @@ 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"] = 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"] = wset_to_json(ev->new_wset.get());
CharlieQLe marked this conversation as resolved.
Show resolved Hide resolved
data["output"] = 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"] = output_to_json(ev->output);
data["wset"] = ev->output ? wset_to_json(ev->output->wset().get()) : nullptr;
send_event_to_subscribes(data, data["event"]);
};

Expand Down
Loading