mirror of
https://github.com/miracle-wm-org/miracle-wm.git
synced 2024-11-30 02:09:10 +03:00
- IPC_GET_TREE is now minimally supported
This commit is contained in:
parent
df148662b6
commit
e2c47b7272
80
src/ipc.cpp
80
src/ipc.cpp
@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "ipc.h"
|
||||
#include "output_content.h"
|
||||
#include "policy.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/socket.h>
|
||||
@ -87,10 +88,53 @@ json workspace_to_json(std::shared_ptr<OutputContent> const& screen, int key)
|
||||
};
|
||||
}
|
||||
|
||||
json outputs_to_json(std::vector<std::shared_ptr<OutputContent>> const& outputs)
|
||||
{
|
||||
json outputs_json;
|
||||
for (auto const& output : outputs)
|
||||
{
|
||||
json workspaces;
|
||||
for (auto const& workspace : output->get_workspaces())
|
||||
{
|
||||
workspaces.push_back(workspace_to_json(output, workspace->get_workspace()));
|
||||
}
|
||||
|
||||
auto area = outputs[0]->get_area();
|
||||
auto miral_output = output->get_output();
|
||||
outputs_json.push_back({
|
||||
{"id", miral_output.id()},
|
||||
{"name", miral_output.name()},
|
||||
{"layout", "output"},
|
||||
{"rect", {
|
||||
{"x", area.top_left.x.as_int()},
|
||||
{"y", area.top_left.y.as_int()},
|
||||
{"width", area.size.width.as_int()},
|
||||
{"height", area.size.height.as_int()},
|
||||
}},
|
||||
{"nodes", workspaces}
|
||||
});
|
||||
}
|
||||
|
||||
auto area = outputs[0]->get_area();
|
||||
json root = {
|
||||
{"id", 0},
|
||||
{"name", "root"},
|
||||
{"rect", {
|
||||
{"x", area.top_left.x.as_int()},
|
||||
{"y", area.top_left.y.as_int()},
|
||||
{"width", area.size.width.as_int()},
|
||||
{"height", area.size.height.as_int()}
|
||||
}},
|
||||
{"nodes", outputs_json}
|
||||
};
|
||||
return root;
|
||||
}
|
||||
|
||||
Ipc::Ipc(miral::MirRunner& runner, miracle::WorkspaceManager& workspace_manager)
|
||||
: workspace_manager{workspace_manager}
|
||||
}
|
||||
|
||||
Ipc::Ipc(miral::MirRunner& runner, miracle::WorkspaceManager& workspace_manager, Policy& policy)
|
||||
: workspace_manager{workspace_manager},
|
||||
policy{policy}
|
||||
{
|
||||
auto ipc_socket_raw = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (ipc_socket_raw == -1)
|
||||
@ -201,6 +245,7 @@ Ipc::Ipc(miral::MirRunner& runner, miracle::WorkspaceManager& workspace_manager)
|
||||
|
||||
memcpy(&client.pending_read_length, buf + sizeof(ipc_magic), sizeof(uint32_t));
|
||||
memcpy(&client.pending_type, buf + sizeof(ipc_magic) + sizeof(uint32_t), sizeof(uint32_t));
|
||||
mir::log_debug("Received request from IPC client: %d", (int)client.pending_type);
|
||||
|
||||
if (read_available - received >= (long)client.pending_read_length)
|
||||
{
|
||||
@ -359,16 +404,45 @@ void Ipc::handle_command(miracle::Ipc::IpcClient &client, uint32_t payload_lengt
|
||||
for (auto const& i : j)
|
||||
{
|
||||
std::string event_type = i.template get<std::string>();
|
||||
mir::log_debug("Received subscription request from IPC client for event: %s", event_type.c_str());
|
||||
if (event_type == "workspace")
|
||||
{
|
||||
client.subscribed_events |= event_mask(IPC_EVENT_WORKSPACE);
|
||||
const std::string msg = "{\"success\": true}";
|
||||
send_reply(client, payload_type, msg);
|
||||
}
|
||||
|
||||
else if (event_type == "window")
|
||||
{
|
||||
client.subscribed_events |= event_mask(IPC_EVENT_WINDOW);
|
||||
const std::string msg = "{\"success\": true}";
|
||||
send_reply(client, payload_type, msg);
|
||||
}
|
||||
else if (event_type == "input")
|
||||
{
|
||||
client.subscribed_events |= event_mask(IPC_EVENT_INPUT);
|
||||
const std::string msg = "{\"success\": true}";
|
||||
send_reply(client, payload_type, msg);
|
||||
}
|
||||
else if (event_type == "mode")
|
||||
{
|
||||
client.subscribed_events |= event_mask(IPC_EVENT_MODE);
|
||||
const std::string msg = "{\"success\": true}";
|
||||
send_reply(client, payload_type, msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
mir::log_error("Cannot process IPC subscription event for event_type: %s", event_type.c_str());
|
||||
disconnect(client);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IPC_GET_TREE:
|
||||
{
|
||||
auto json_string = to_string(outputs_to_json(policy.get_output_list()));
|
||||
send_reply(client, payload_type, json_string);
|
||||
return;
|
||||
}
|
||||
default:
|
||||
mir::log_warning("Unknown payload type: %d", payload_type);
|
||||
disconnect(client);
|
||||
|
@ -29,6 +29,8 @@ struct sockaddr_un;
|
||||
namespace miracle
|
||||
{
|
||||
|
||||
class Policy;
|
||||
|
||||
/// This it taken directly from SWAY
|
||||
enum IpcCommandType {
|
||||
// i3 command types - see i3's I3_REPLY_TYPE constants
|
||||
@ -72,7 +74,7 @@ enum IpcCommandType {
|
||||
class Ipc : public WorkspaceObserver
|
||||
{
|
||||
public:
|
||||
Ipc(miral::MirRunner& runner, WorkspaceManager&);
|
||||
Ipc(miral::MirRunner& runner, WorkspaceManager&, Policy& policy);
|
||||
|
||||
void on_created(std::shared_ptr<OutputContent> const& info, int key) override;
|
||||
void on_removed(std::shared_ptr<OutputContent> const& info, int key) override;
|
||||
@ -91,6 +93,7 @@ private:
|
||||
};
|
||||
|
||||
WorkspaceManager& workspace_manager;
|
||||
Policy& policy;
|
||||
mir::Fd ipc_socket;
|
||||
std::unique_ptr<miral::FdHandle> socket_handle;
|
||||
sockaddr_un* ipc_sockaddr = nullptr;
|
||||
|
@ -60,7 +60,7 @@ Policy::Policy(
|
||||
tools,
|
||||
workspace_observer_registrar,
|
||||
[&]() { return get_active_output(); })},
|
||||
ipc{std::make_shared<Ipc>(runner, workspace_manager)},
|
||||
ipc{std::make_shared<Ipc>(runner, workspace_manager, *this)},
|
||||
node_interface(tools)
|
||||
{
|
||||
workspace_observer_registrar.register_interest(ipc);
|
||||
|
@ -93,6 +93,7 @@ public:
|
||||
void advise_application_zone_delete(miral::Zone const& application_zone) override;
|
||||
|
||||
std::shared_ptr<OutputContent> const& get_active_output() { return active_output; }
|
||||
std::vector<std::shared_ptr<OutputContent>> const& get_output_list() { return output_list; }
|
||||
|
||||
private:
|
||||
std::shared_ptr<OutputContent> active_output;
|
||||
|
Loading…
Reference in New Issue
Block a user