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 plugins: Move list-views from stipc to ipc-rules #2011

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 0 additions & 92 deletions plugins/ipc/stipc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,44 +52,6 @@ static void locate_wayland_backend(wlr_backend *backend, void *data)

namespace wf
{
static std::string layer_to_string(std::optional<wf::scene::layer> layer)
{
if (!layer.has_value())
{
return "none";
}

switch (layer.value())
{
case wf::scene::layer::BACKGROUND:
return "background";

case wf::scene::layer::BOTTOM:
return "bottom";

case wf::scene::layer::WORKSPACE:
return "workspace";

case wf::scene::layer::TOP:
return "top";

case wf::scene::layer::UNMANAGED:
return "unmanaged";

case wf::scene::layer::OVERLAY:
return "lock";

case wf::scene::layer::DWIDGET:
return "dew";

default:
break;
}

wf::dassert(false, "invalid layer!");
assert(false); // prevent compiler warning
}

static const struct wlr_pointer_impl pointer_impl = {
.name = "stipc-pointer",
};
Expand Down Expand Up @@ -326,7 +288,6 @@ class stipc_plugin_t : public wf::plugin_interface_t
void init() override
{
input = std::make_unique<headless_input_backend_t>();
method_repository->register_method("stipc/list_views", list_views);
method_repository->register_method("stipc/create_wayland_output", create_wayland_output);
method_repository->register_method("stipc/destroy_wayland_output", destroy_wayland_output);
method_repository->register_method("stipc/feed_key", feed_key);
Expand All @@ -353,59 +314,6 @@ class stipc_plugin_t : public wf::plugin_interface_t
return false;
}

static wf::geometry_t get_view_base_geometry(wayfire_view view)
{
auto sroot = view->get_surface_root_node();
for (auto& ch : sroot->get_children())
{
if (auto wlr_surf = dynamic_cast<scene::wlr_surface_node_t*>(ch.get()))
{
auto bbox = wlr_surf->get_bounding_box();
wf::pointf_t origin = sroot->to_global({0, 0});
bbox.x = origin.x;
bbox.y = origin.y;
return bbox;
}
}

return sroot->get_bounding_box();
}

ipc::method_callback list_views = [] (nlohmann::json)
{
auto response = nlohmann::json::array();

for (auto& view : wf::get_core().get_all_views())
{
nlohmann::json v;
v["id"] = view->get_id();
v["title"] = view->get_title();
v["app-id"] = view->get_app_id();
v["base-geometry"] = wf::ipc::geometry_to_json(get_view_base_geometry(view));
v["bbox"] = wf::ipc::geometry_to_json(view->get_bounding_box());
v["state"] = {};
v["output"] = view->get_output() ? view->get_output()->to_string() : "null";

if (auto toplevel = toplevel_cast(view))
{
v["parent"] = toplevel->parent ? (int)toplevel->parent->get_id() : -1;
v["geometry"] = wf::ipc::geometry_to_json(toplevel->get_geometry());
v["state"]["tiled"] = toplevel->pending_tiled_edges();
v["state"]["fullscreen"] = toplevel->pending_fullscreen();
v["state"]["minimized"] = toplevel->minimized;
v["state"]["activated"] = toplevel->activated;
} else
{
v["geometry"] = wf::ipc::geometry_to_json(view->get_bounding_box());
}

v["layer"] = layer_to_string(get_view_layer(view));
response.push_back(v);
}

return response;
};

ipc::method_callback layout_views = [] (nlohmann::json data)
{
auto views = wf::get_core().get_all_views();
Expand Down
98 changes: 98 additions & 0 deletions plugins/single_plugins/ipc-rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "plugins/ipc/ipc-method-repository.hpp"
#include "wayfire/core.hpp"
#include "wayfire/object.hpp"
#include "wayfire/unstable/wlr-surface-node.hpp"
#include "wayfire/plugins/common/shared-core-data.hpp"
#include "wayfire/signal-definitions.hpp"
#include "wayfire/signal-provider.hpp"
Expand All @@ -21,12 +22,70 @@
#include "config.h"
#include <wayfire/nonstd/wlroots-full.hpp>


static std::string layer_to_string(std::optional<wf::scene::layer> layer)
{
if (!layer.has_value())
{
return "none";
}

switch (layer.value())
{
case wf::scene::layer::BACKGROUND:
return "background";

case wf::scene::layer::BOTTOM:
return "bottom";

case wf::scene::layer::WORKSPACE:
return "workspace";

case wf::scene::layer::TOP:
return "top";

case wf::scene::layer::UNMANAGED:
return "unmanaged";

case wf::scene::layer::OVERLAY:
return "lock";

case wf::scene::layer::DWIDGET:
return "dew";

default:
break;
}

wf::dassert(false, "invalid layer!");
assert(false); // prevent compiler warning
}

static wf::geometry_t get_view_base_geometry(wayfire_view view)
{
auto sroot = view->get_surface_root_node();
for (auto& ch : sroot->get_children())
{
if (auto wlr_surf = dynamic_cast<wf::scene::wlr_surface_node_t*>(ch.get()))
{
auto bbox = wlr_surf->get_bounding_box();
wf::pointf_t origin = sroot->to_global({0, 0});
bbox.x = origin.x;
bbox.y = origin.y;
return bbox;
}
}

return sroot->get_bounding_box();
}

class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker_mixin_t<>
{
public:
void init() override
{
method_repository->register_method("window-rules/events/watch", on_client_watch);
method_repository->register_method("window-rules/list-views", list_views);
method_repository->register_method("window-rules/view-info", get_view_info);
method_repository->register_method("window-rules/output-info", get_output_info);
method_repository->register_method("window-rules/configure-view", configure_view);
Expand All @@ -41,6 +100,7 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
void fini() override
{
method_repository->unregister_method("window-rules/events/watch");
method_repository->unregister_method("window-rules/list-views");
method_repository->unregister_method("window-rules/view-info");
method_repository->unregister_method("window-rules/output-info");
method_repository->unregister_method("window-rules/configure-view");
Expand All @@ -61,6 +121,44 @@ class ipc_rules_t : public wf::plugin_interface_t, public wf::per_output_tracker
// no-op
}

wf::ipc::method_callback list_views = [] (nlohmann::json)
{
auto response = nlohmann::json::array();

for (auto& output : wf::get_core().output_layout->get_outputs())
{
for (auto& view : output->wset()->get_views(wf::WSET_SORT_STACKING))
{
nlohmann::json v;
v["id"] = view->get_id();
v["title"] = view->get_title();
v["app-id"] = view->get_app_id();
v["base-geometry"] = wf::ipc::geometry_to_json(get_view_base_geometry(view));
v["bbox"] = wf::ipc::geometry_to_json(view->get_bounding_box());
v["state"] = {};
v["output"] = view->get_output() ? view->get_output()->to_string() : "null";

if (auto toplevel = toplevel_cast(view))
{
v["parent"] = toplevel->parent ? (int)toplevel->parent->get_id() : -1;
v["geometry"] = wf::ipc::geometry_to_json(toplevel->get_geometry());
v["state"]["tiled"] = toplevel->pending_tiled_edges();
v["state"]["fullscreen"] = toplevel->pending_fullscreen();
v["state"]["minimized"] = toplevel->minimized;
v["state"]["activated"] = toplevel->activated;
} else
{
v["geometry"] = wf::ipc::geometry_to_json(view->get_bounding_box());
}

v["layer"] = layer_to_string(get_view_layer(view));
response.push_back(v);
}
}

return response;
};

wf::ipc::method_callback get_view_info = [=] (nlohmann::json data)
{
WFJSON_EXPECT_FIELD(data, "id", number_integer);
Expand Down
Loading