Skip to content

Commit

Permalink
Add close view method (#2158)
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlieQLe authored Feb 23, 2024
1 parent faccd0e commit 997afd4
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions plugins/single_plugins/ipc-rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
method_repository->register_method("window-rules/configure-view", configure_view);
method_repository->register_method("window-rules/focus-view", focus_view);
method_repository->register_method("window-rules/get-focused-view", get_focused_view);
method_repository->register_method("window-rules/close-view", close_view);
method_repository->connect(&on_client_disconnected);
wf::get_core().connect(&on_view_mapped);
wf::get_core().connect(&on_view_unmapped);
Expand All @@ -163,6 +164,7 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
method_repository->unregister_method("window-rules/configure-view");
method_repository->unregister_method("window-rules/focus-view");
method_repository->unregister_method("window-rules/get-focused-view");
method_repository->unregister_method("window-rules/close-view");
fini_output_tracking();
}

Expand Down Expand Up @@ -252,6 +254,19 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
return wf::ipc::json_error("no such view");
};

wf::ipc::method_callback close_view = [=] (nlohmann::json data)
{
WFJSON_EXPECT_FIELD(data, "id", number_integer);
if (auto view = wf::ipc::find_view_by_id(data["id"]))
{
auto response = wf::ipc::json_ok();
view->close();
return response;
}

return wf::ipc::json_error("no such view");
};

nlohmann::json output_to_json(wf::output_t *o)
{
nlohmann::json response;
Expand Down

0 comments on commit 997afd4

Please sign in to comment.