Skip to content

Commit

Permalink
ipc plugins: Move list-views from stipc to ipc-rules (#2011)
Browse files Browse the repository at this point in the history
This also lists the views in z-order.
  • Loading branch information
soreau authored Nov 15, 2023
1 parent 9bed909 commit 77c9214
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 92 deletions.
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

0 comments on commit 77c9214

Please sign in to comment.