Waybar/src/modules/wlr/workspace_manager_binding.cpp

137 lines
5.2 KiB
C++
Raw Normal View History

2020-08-05 20:10:08 +00:00
#include "modules/wlr/workspace_manager_binding.hpp"
#include <spdlog/spdlog.h>
2022-04-06 06:37:19 +00:00
2021-11-23 00:10:44 +00:00
#include <cstdint>
2020-08-05 20:10:08 +00:00
#include "client.hpp"
#include "modules/wlr/workspace_manager.hpp"
namespace waybar::modules::wlr {
static void handle_global(void *data, wl_registry *registry, uint32_t name, const char *interface,
uint32_t version) {
2021-11-21 12:01:25 +00:00
if (std::strcmp(interface, zext_workspace_manager_v1_interface.name) == 0) {
2020-08-05 20:10:08 +00:00
static_cast<WorkspaceManager *>(data)->register_manager(registry, name, version);
}
}
static void handle_global_remove(void *data, wl_registry *registry, uint32_t name) {
/* Nothing to do here */
}
static const wl_registry_listener registry_listener_impl = {.global = handle_global,
.global_remove = handle_global_remove};
void add_registry_listener(void *data) {
2022-04-06 06:37:19 +00:00
wl_display *display = Client::inst()->wl_display;
2020-08-05 20:10:08 +00:00
wl_registry *registry = wl_display_get_registry(display);
wl_registry_add_listener(registry, &registry_listener_impl, data);
wl_display_roundtrip(display);
wl_display_roundtrip(display);
}
static void workspace_manager_handle_workspace_group(
2021-11-21 12:01:25 +00:00
void *data, zext_workspace_manager_v1 *_, zext_workspace_group_handle_v1 *workspace_group) {
2020-08-05 20:10:08 +00:00
static_cast<WorkspaceManager *>(data)->handle_workspace_group_create(workspace_group);
}
2021-11-21 12:01:25 +00:00
static void workspace_manager_handle_done(void *data, zext_workspace_manager_v1 *_) {
2020-08-05 20:10:08 +00:00
static_cast<WorkspaceManager *>(data)->handle_done();
}
2021-11-21 12:01:25 +00:00
static void workspace_manager_handle_finished(void *data, zext_workspace_manager_v1 *_) {
2020-08-05 20:10:08 +00:00
static_cast<WorkspaceManager *>(data)->handle_finished();
}
2021-11-21 12:01:25 +00:00
static const zext_workspace_manager_v1_listener workspace_manager_impl = {
2020-08-05 20:10:08 +00:00
.workspace_group = workspace_manager_handle_workspace_group,
.done = workspace_manager_handle_done,
.finished = workspace_manager_handle_finished,
};
2021-11-21 12:01:25 +00:00
zext_workspace_manager_v1 *workspace_manager_bind(wl_registry *registry, uint32_t name,
2020-08-05 20:10:08 +00:00
uint32_t version, void *data) {
2021-11-21 12:01:25 +00:00
auto *workspace_manager = static_cast<zext_workspace_manager_v1 *>(
wl_registry_bind(registry, name, &zext_workspace_manager_v1_interface, version));
2020-08-05 20:10:08 +00:00
if (workspace_manager)
2021-11-21 12:01:25 +00:00
zext_workspace_manager_v1_add_listener(workspace_manager, &workspace_manager_impl, data);
2020-08-05 20:10:08 +00:00
else
spdlog::error("Failed to register manager");
return workspace_manager;
}
2021-11-21 12:01:25 +00:00
static void workspace_group_handle_output_enter(void *data, zext_workspace_group_handle_v1 *_,
2020-08-05 20:10:08 +00:00
wl_output *output) {
static_cast<WorkspaceGroup *>(data)->handle_output_enter(output);
}
2021-11-21 12:01:25 +00:00
static void workspace_group_handle_output_leave(void *data, zext_workspace_group_handle_v1 *_,
2020-08-05 20:10:08 +00:00
wl_output *output) {
static_cast<WorkspaceGroup *>(data)->handle_output_leave();
}
2021-11-21 12:01:25 +00:00
static void workspace_group_handle_workspace(void *data, zext_workspace_group_handle_v1 *_,
zext_workspace_handle_v1 *workspace) {
2020-08-05 20:10:08 +00:00
static_cast<WorkspaceGroup *>(data)->handle_workspace_create(workspace);
}
2021-11-21 12:01:25 +00:00
static void workspace_group_handle_remove(void *data, zext_workspace_group_handle_v1 *_) {
2020-08-05 20:10:08 +00:00
static_cast<WorkspaceGroup *>(data)->handle_remove();
}
2021-11-21 12:01:25 +00:00
static const zext_workspace_group_handle_v1_listener workspace_group_impl = {
2020-08-05 20:10:08 +00:00
.output_enter = workspace_group_handle_output_enter,
.output_leave = workspace_group_handle_output_leave,
.workspace = workspace_group_handle_workspace,
.remove = workspace_group_handle_remove};
2021-11-21 12:01:25 +00:00
void add_workspace_group_listener(zext_workspace_group_handle_v1 *workspace_group_handle,
2022-04-06 06:37:19 +00:00
void *data) {
2021-11-21 12:01:25 +00:00
zext_workspace_group_handle_v1_add_listener(workspace_group_handle, &workspace_group_impl, data);
2020-08-05 20:10:08 +00:00
}
2021-11-21 12:01:25 +00:00
void workspace_handle_name(void *data, struct zext_workspace_handle_v1 *_, const char *name) {
2020-08-05 20:10:08 +00:00
static_cast<Workspace *>(data)->handle_name(name);
}
2021-11-21 12:01:25 +00:00
void workspace_handle_coordinates(void *data, struct zext_workspace_handle_v1 *_,
2020-08-05 20:10:08 +00:00
struct wl_array *coordinates) {
std::vector<uint32_t> coords_vec;
2022-04-06 06:37:19 +00:00
auto coords = static_cast<uint32_t *>(coordinates->data);
2021-11-23 00:10:44 +00:00
for (size_t i = 0; i < coordinates->size / sizeof(uint32_t); ++i) {
2020-08-05 20:10:08 +00:00
coords_vec.push_back(coords[i]);
}
static_cast<Workspace *>(data)->handle_coordinates(coords_vec);
}
2021-11-21 12:01:25 +00:00
void workspace_handle_state(void *data, struct zext_workspace_handle_v1 *workspace_handle,
2020-08-05 20:10:08 +00:00
struct wl_array *state) {
std::vector<uint32_t> state_vec;
2022-04-06 06:37:19 +00:00
auto states = static_cast<uint32_t *>(state->data);
2021-11-23 00:10:44 +00:00
for (size_t i = 0; i < state->size / sizeof(uint32_t); ++i) {
2020-08-07 20:46:47 +00:00
state_vec.push_back(states[i]);
2020-08-05 20:10:08 +00:00
}
static_cast<Workspace *>(data)->handle_state(state_vec);
}
2021-11-21 12:01:25 +00:00
void workspace_handle_remove(void *data, struct zext_workspace_handle_v1 *_) {
2020-08-05 20:10:08 +00:00
static_cast<Workspace *>(data)->handle_remove();
}
2021-11-21 12:01:25 +00:00
static const zext_workspace_handle_v1_listener workspace_impl = {
2020-08-05 20:10:08 +00:00
.name = workspace_handle_name,
.coordinates = workspace_handle_coordinates,
.state = workspace_handle_state,
.remove = workspace_handle_remove};
2021-11-21 12:01:25 +00:00
void add_workspace_listener(zext_workspace_handle_v1 *workspace_handle, void *data) {
zext_workspace_handle_v1_add_listener(workspace_handle, &workspace_impl, data);
2020-08-05 20:10:08 +00:00
}
} // namespace waybar::modules::wlr