Skip to content

Commit

Permalink
wayland changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jstkdng committed Jul 31, 2023
1 parent 5177911 commit 1a7b3e7
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/canvas/wayland/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class WaylandConfig

virtual ~WaylandConfig() = default;

[[nodiscard]] virtual auto get_window_info() -> struct WaylandWindowGeometry = 0;
virtual auto get_window_info() -> struct WaylandWindowGeometry = 0;
virtual auto is_dummy() -> bool { return false; }
virtual void initial_setup(std::string_view appid) = 0;
virtual void move_window(std::string_view appid, int xcoord, int ycoord) = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/canvas/wayland/config/dummy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class DummyWaylandConfig : public WaylandConfig
public:
DummyWaylandConfig() = default;
~DummyWaylandConfig() override = default;
[[nodiscard]] auto get_window_info() -> struct WaylandWindowGeometry override;

auto get_window_info() -> struct WaylandWindowGeometry override;
auto is_dummy() -> bool override { return true; }
void initial_setup(std::string_view appid) override;
void move_window(std::string_view appid, int xcoord, int ycoord) override;
Expand Down
3 changes: 2 additions & 1 deletion src/canvas/wayland/config/hyprland.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class HyprlandSocket : public WaylandConfig
public:
explicit HyprlandSocket(std::string_view signature);
~HyprlandSocket() override = default;
[[nodiscard]] auto get_window_info() -> struct WaylandWindowGeometry override;

auto get_window_info() -> struct WaylandWindowGeometry override;
void initial_setup(std::string_view appid) override;
void move_window(std::string_view appid, int xcoord, int ycoord) override;

Expand Down
15 changes: 9 additions & 6 deletions src/canvas/wayland/config/sway.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,25 @@ class SwaySocket : public WaylandConfig
public:
explicit SwaySocket(std::string_view endpoint);
~SwaySocket() override = default;
[[nodiscard]] auto get_window_info() -> struct WaylandWindowGeometry override;

auto get_window_info() -> struct WaylandWindowGeometry override;
void initial_setup(std::string_view appid) override;
void move_window(std::string_view appid, int xcoord, int ycoord) override;

private:
const UnixSocket socket;
std::shared_ptr<spdlog::logger> logger;
static auto get_active_window(const std::vector<nlohmann::json>& nodes) -> nlohmann::json;
static auto get_active_monitor(const std::vector<nlohmann::json>& nodes) -> nlohmann::json;

private:
void disable_focus(std::string_view appid);
void enable_floating(std::string_view appid);
void ipc_command(std::string_view appid, std::string_view command) const;
void ipc_command(std::string_view payload) const;

[[nodiscard]] auto get_nodes() const -> std::vector<nlohmann::json>;
[[nodiscard]] auto ipc_message(ipc_message_type type, std::string_view payload = "") const -> nlohmann::json;
[[nodiscard]] static auto get_active_window(const std::vector<nlohmann::json>& nodes) -> nlohmann::json;
[[nodiscard]] static auto get_active_monitor(const std::vector<nlohmann::json>& nodes) -> nlohmann::json;

const UnixSocket socket;
std::shared_ptr<spdlog::logger> logger;
};

#endif
44 changes: 32 additions & 12 deletions src/canvas/wayland/config/wayfire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "wayfire.hpp"

#include <spdlog/spdlog.h>
#include <nlohmann/json.hpp>

using njson = nlohmann::json;

Expand All @@ -30,7 +29,16 @@ logger(spdlog::get("wayland"))

auto WayfireSocket::get_window_info() -> struct WaylandWindowGeometry
{
return {};
const auto response = request("window-rules/get-focused-view");
const auto& info = response.at("info");
const auto& geometry = info.at("geometry");
const int decoration_height = 25;
return {
.width = geometry.at("width"),
.height = geometry.at("height").get<int>() - decoration_height,
.x = 0,
.y = 0
};
}

void WayfireSocket::initial_setup([[maybe_unused]] const std::string_view appid)
Expand All @@ -39,17 +47,29 @@ void WayfireSocket::initial_setup([[maybe_unused]] const std::string_view appid)
}

void WayfireSocket::move_window(const std::string_view appid, int xcoord, int ycoord)
{
const njson payload_data = {
{"app-id", appid},
{"x", xcoord},
{"y", ycoord}
};
std::ignore = request("ueberzugpp/set_offset", payload_data);
}

auto WayfireSocket::request(const std::string_view method, const njson& data) const -> njson
{
const njson json = {
{"method", "ueberzugpp/set_offset"},
{"data", {
{"app-id", appid},
{"x", xcoord},
{"y", ycoord}
}}
{"method", method},
{"data", data}
};
const auto data = json.dump();
const uint32_t data_size = data.length();
socket.write(&data_size, sizeof(uint32_t));
socket.write(data.c_str(), data_size);
const auto payload = json.dump();
const uint32_t payload_size = payload.length();
socket.write(&payload_size, sizeof(uint32_t));
socket.write(payload.c_str(), payload_size);

uint32_t response_size = 0;
socket.read(&response_size, sizeof(uint32_t));
std::string buffer (response_size, 0);
socket.read(buffer.data(), response_size);
return njson::parse(buffer);
}
5 changes: 4 additions & 1 deletion src/canvas/wayland/config/wayfire.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@
#include "../config.hpp"

#include <spdlog/fwd.h>
#include <nlohmann/json.hpp>

class WayfireSocket : public WaylandConfig
{
public:
explicit WayfireSocket(std::string_view endpoint);
~WayfireSocket() override = default;

[[nodiscard]] auto get_window_info() -> struct WaylandWindowGeometry override;
auto get_window_info() -> struct WaylandWindowGeometry override;
void initial_setup(std::string_view appid) override;
void move_window(std::string_view appid, int xcoord, int ycoord) override;

private:
[[nodiscard]] auto request(std::string_view method, const nlohmann::json& data = {}) const -> nlohmann::json;

const UnixSocket socket;
std::shared_ptr<spdlog::logger> logger;
};
Expand Down

0 comments on commit 1a7b3e7

Please sign in to comment.