diff --git a/plugins/single_plugins/ipc-rules.cpp b/plugins/single_plugins/ipc-rules.cpp index 414902289..c6d026736 100644 --- a/plugins/single_plugins/ipc-rules.cpp +++ b/plugins/single_plugins/ipc-rules.cpp @@ -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(); } @@ -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); @@ -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(); @@ -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) @@ -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(); @@ -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); @@ -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 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 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 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 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 _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. @@ -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 _stickied = [=] (wf::view_set_sticky_signal *ev) + { + send_view_to_subscribes(ev->view, "view-sticky"); + }; + + wf::signal::connection_t _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 on_title_changed = [=] (wf::view_title_changed_signal *ev) { @@ -524,33 +629,67 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker wf::signal::connection_t 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 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 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 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"]); };