Skip to content

Commit

Permalink
Added configure_output and configure_wset
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlieQLe committed Feb 21, 2024
1 parent 5873d17 commit 36d5adf
Showing 1 changed file with 78 additions and 11 deletions.
89 changes: 78 additions & 11 deletions plugins/single_plugins/ipc-rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
method_repository->register_method("window-rules/output-info", get_output_info);
method_repository->register_method("window-rules/wset-info", get_wset_info);
method_repository->register_method("window-rules/configure-view", configure_view);
method_repository->register_method("window-rules/configure-output", configure_output);
method_repository->register_method("window-rules/configure-wset", configure_wset);
method_repository->register_method("window-rules/focus-view", focus_view);
method_repository->register_method("window-rules/get-focused-view", get_focused_view);
method_repository->connect(&on_client_disconnected);
Expand All @@ -165,6 +167,8 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
method_repository->unregister_method("window-rules/output-info");
method_repository->unregister_method("window-rules/wset-info");
method_repository->unregister_method("window-rules/configure-view");
method_repository->unregister_method("window-rules/configure-output");
method_repository->unregister_method("window-rules/configure-wset");
method_repository->unregister_method("window-rules/focus-view");
method_repository->unregister_method("window-rules/get-focused-view");
fini_output_tracking();
Expand Down Expand Up @@ -265,7 +269,7 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
response["name"] = o->to_string();
response["geometry"] = wf::ipc::geometry_to_json(o->get_layout_geometry());
response["workarea"] = wf::ipc::geometry_to_json(o->workarea->get_workarea());
response["wset-id"] = o->wset()->get_id();
response["wset-id"] = o->wset()->get_id();
response["workspace"]["x"] = o->wset()->get_current_workspace().x;
response["workspace"]["y"] = o->wset()->get_current_workspace().y;
response["workspace"]["grid_width"] = o->wset()->get_workspace_grid_size().width;
Expand Down Expand Up @@ -340,21 +344,83 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
return wf::ipc::json_ok();
};

nlohmann::json wset_to_json(wf::workspace_set_t* wset)
wf::ipc::method_callback configure_output = [=] (nlohmann::json data)
{
WFJSON_EXPECT_FIELD(data, "id", number_integer);
WFJSON_OPTIONAL_FIELD(data, "wset_id", number_integer);

auto output = wf::ipc::find_output_by_id(data["id"]);
if (!output)
{
return wf::ipc::json_error("output not found");
}

if (data.contains("wset_id"))
{
auto wset = wf::ipc::find_workspace_set_by_id(data["wset_id"]);
if (!wset)
{
return wf::ipc::json_error("workspace set not found");
}

output->set_workspace_set(wset->shared_from_this());
}

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

wf::ipc::method_callback configure_wset = [=] (nlohmann::json data)
{
WFJSON_EXPECT_FIELD(data, "id", number_integer);
WFJSON_OPTIONAL_FIELD(data, "output_id", number_integer);
WFJSON_OPTIONAL_FIELD(data, "workspace", object);

auto wset = wf::ipc::find_workspace_set_by_id(data["id"]);
if (!wset)
{
return wf::ipc::json_error("workspace set not found");
}

if (data.contains("output_id"))
{
auto output = wf::ipc::find_output_by_id(data["output_id"]);
if (!output)
{
return wf::ipc::json_error("output not found");
}

wset->attach_to_output(output);
}

if (data.contains("object"))
{
auto workspace = wf::ipc::point_from_json(data["workspace"]);
if (!workspace)
{
return wf::ipc::json_error("invalid workspace");
}

wset->request_workspace(*workspace);
}

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

nlohmann::json wset_to_json(wf::workspace_set_t *wset)
{
nlohmann::json response;
response["id"] = wset->get_id();
response["name"] = wset->to_string();

auto output = wset->get_attached_output();
response["output-id"] = output ? output->get_id() : -1;
response["output-id"] = output ? output->get_id() : -1;
response["output-name"] = output ? output->to_string() : "";
response["workspace"]["x"] = wset->get_current_workspace().x;
response["workspace"]["y"] = wset->get_current_workspace().y;
response["workspace"]["grid_width"] = wset->get_workspace_grid_size().width;
response["workspace"]["grid_height"] = wset->get_workspace_grid_size().height;
return response;
};
}

wf::ipc::method_callback list_wsets = [=] (nlohmann::json)
{
Expand All @@ -363,6 +429,7 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
{
response.push_back(wset_to_json(workspace_set.get()));
}

return response;
};

Expand Down Expand Up @@ -467,7 +534,7 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
send_view_to_subscribes(ev->view, "view-fullscreen");
};

wf::signal::connection_t<wf::view_title_changed_signal> on_title_changed =
wf::signal::connection_t<wf::view_title_changed_signal> on_title_changed =
[=] (wf::view_title_changed_signal *ev)
{
send_view_to_subscribes(ev->view, "view-title-changed");
Expand All @@ -494,9 +561,9 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
[=] (wf::workspace_set_changed_signal *ev)
{
nlohmann::json data;
data["event"] = "output-wset-changed";
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["output"] = ev->output ? (int)ev->output->get_id() : -1;
send_event_to_subscribes(data, data["event"]);
};

Expand Down Expand Up @@ -576,9 +643,9 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
description["fullscreen"] = toplevel ? toplevel->pending_fullscreen() : false;
description["minimized"] = toplevel ? toplevel->minimized : false;
description["activated"] = toplevel ? toplevel->activated : false;
description["sticky"] = toplevel ? toplevel->sticky : false;
description["wset-id"] = toplevel && toplevel->get_wset() ? toplevel->get_wset()->get_id() : -1;
description["focusable"] = view->is_focusable();
description["sticky"] = toplevel ? toplevel->sticky : false;
description["wset-id"] = toplevel && toplevel->get_wset() ? toplevel->get_wset()->get_id() : -1;
description["focusable"] = view->is_focusable();
description["type"] = get_view_type(view);

return description;
Expand Down

0 comments on commit 36d5adf

Please sign in to comment.