ext/workspaces: moved/renamed from wlr/workspaces

The ext-workspace-v1 protocol is not wlr/wlroots
specific.
This commit is contained in:
Jens Peters
2025-06-20 07:17:46 +02:00
parent 255c0ebe28
commit 29bf5d5da1
7 changed files with 51 additions and 51 deletions

View File

@ -13,7 +13,7 @@
#include "bar.hpp" #include "bar.hpp"
#include "ext-workspace-v1-client-protocol.h" #include "ext-workspace-v1-client-protocol.h"
namespace waybar::modules::wlr { namespace waybar::modules::ext {
class WorkspaceGroup; class WorkspaceGroup;
class Workspace; class Workspace;
@ -27,13 +27,13 @@ class WorkspaceManager final : public AModule {
void remove_workspace(uint32_t id); void remove_workspace(uint32_t id);
void set_needs_sorting() { needs_sorting_ = true; } void set_needs_sorting() { needs_sorting_ = true; }
// wlr events // wl events
void handle_workspace_group(ext_workspace_group_handle_v1 *handle); void handle_workspace_group(ext_workspace_group_handle_v1 *handle);
void handle_workspace(ext_workspace_handle_v1 *handle); void handle_workspace(ext_workspace_handle_v1 *handle);
void handle_done(); void handle_done();
void handle_finished(); void handle_finished();
// wlr requests // wl requests
void commit() const; void commit() const;
private: private:
@ -72,7 +72,7 @@ class WorkspaceGroup {
bool has_output(const wl_output *output); bool has_output(const wl_output *output);
bool has_workspace(const ext_workspace_handle_v1 *workspace); bool has_workspace(const ext_workspace_handle_v1 *workspace);
// wlr events // wl events
void handle_capabilities(uint32_t capabilities); void handle_capabilities(uint32_t capabilities);
void handle_output_enter(wl_output *output); void handle_output_enter(wl_output *output);
void handle_output_leave(wl_output *output); void handle_output_leave(wl_output *output);
@ -105,7 +105,7 @@ class Workspace {
bool is_hidden() const; bool is_hidden() const;
void update(); void update();
// wlr events // wl events
void handle_id(const std::string &id); void handle_id(const std::string &id);
void handle_name(const std::string &name); void handle_name(const std::string &name);
void handle_coordinates(const std::vector<uint32_t> &coordinates); void handle_coordinates(const std::vector<uint32_t> &coordinates);
@ -141,4 +141,4 @@ class Workspace {
bool needs_updating_ = false; bool needs_updating_ = false;
}; };
} // namespace waybar::modules::wlr } // namespace waybar::modules::ext

View File

@ -1,10 +1,10 @@
#include "ext-workspace-v1-client-protocol.h" #include "ext-workspace-v1-client-protocol.h"
namespace waybar::modules::wlr { namespace waybar::modules::ext {
void add_registry_listener(void *data); void add_registry_listener(void *data);
void add_workspace_listener(ext_workspace_handle_v1 *workspace_handle, void *data); void add_workspace_listener(ext_workspace_handle_v1 *workspace_handle, void *data);
void add_workspace_group_listener(ext_workspace_group_handle_v1 *workspace_group_handle, void add_workspace_group_listener(ext_workspace_group_handle_v1 *workspace_group_handle,
void *data); void *data);
ext_workspace_manager_v1 *workspace_manager_bind(wl_registry *registry, uint32_t name, ext_workspace_manager_v1 *workspace_manager_bind(wl_registry *registry, uint32_t name,
uint32_t version, void *data); uint32_t version, void *data);
} // namespace waybar::modules::wlr } // namespace waybar::modules::ext

View File

@ -10,7 +10,7 @@ The *workspaces* module displays the currently used workspaces in wayland compos
# CONFIGURATION # CONFIGURATION
Addressed by *wlr/workspaces* Addressed by *ext/workspaces*
*format*: ++ *format*: ++
typeof: string ++ typeof: string ++
@ -71,7 +71,7 @@ In addition to workspace name matching, the following *format-icons* can be set.
# EXAMPLES # EXAMPLES
``` ```
"wlr/workspaces": { "ext/workspaces": {
"format": "{name}: {icon}", "format": "{name}: {icon}",
"on-click": "activate", "on-click": "activate",
"format-icons": { "format-icons": {

View File

@ -277,13 +277,13 @@ if true
endif endif
if wayland_protos.version().version_compare('>=1.39') if wayland_protos.version().version_compare('>=1.39')
add_project_arguments('-DHAVE_WLR_WORKSPACES', language: 'cpp') add_project_arguments('-DHAVE_EXT_WORKSPACES', language: 'cpp')
src_files += files( src_files += files(
'src/modules/wlr/workspace_manager.cpp', 'src/modules/ext/workspace_manager.cpp',
'src/modules/wlr/workspace_manager_binding.cpp', 'src/modules/ext/workspace_manager_binding.cpp',
) )
man_files += files( man_files += files(
'man/waybar-wlr-workspaces.5.scd', 'man/waybar-ext-workspaces.5.scd',
) )
endif endif

View File

@ -17,8 +17,8 @@
#ifdef HAVE_WLR_TASKBAR #ifdef HAVE_WLR_TASKBAR
#include "modules/wlr/taskbar.hpp" #include "modules/wlr/taskbar.hpp"
#endif #endif
#ifdef HAVE_WLR_WORKSPACES #ifdef HAVE_EXT_WORKSPACES
#include "modules/wlr/workspace_manager.hpp" #include "modules/ext/workspace_manager.hpp"
#endif #endif
#ifdef HAVE_RIVER #ifdef HAVE_RIVER
#include "modules/river/layout.hpp" #include "modules/river/layout.hpp"
@ -178,9 +178,9 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name,
return new waybar::modules::wlr::Taskbar(id, bar_, config_[name]); return new waybar::modules::wlr::Taskbar(id, bar_, config_[name]);
} }
#endif #endif
#ifdef HAVE_WLR_WORKSPACES #ifdef HAVE_EXT_WORKSPACES
if (ref == "wlr/workspaces") { if (ref == "ext/workspaces") {
return new waybar::modules::wlr::WorkspaceManager(id, bar_, config_[name]); return new waybar::modules::ext::WorkspaceManager(id, bar_, config_[name]);
} }
#endif #endif
#ifdef HAVE_RIVER #ifdef HAVE_RIVER

View File

@ -1,4 +1,4 @@
#include "modules/wlr/workspace_manager.hpp" #include "modules/ext/workspace_manager.hpp"
#include <gdk/gdkwayland.h> #include <gdk/gdkwayland.h>
#include <gtkmm.h> #include <gtkmm.h>
@ -10,9 +10,9 @@
#include "client.hpp" #include "client.hpp"
#include "gtkmm/widget.h" #include "gtkmm/widget.h"
#include "modules/wlr/workspace_manager_binding.hpp" #include "modules/ext/workspace_manager_binding.hpp"
namespace waybar::modules::wlr { namespace waybar::modules::ext {
// WorkspaceManager // WorkspaceManager
@ -29,7 +29,7 @@ WorkspaceManager::WorkspaceManager(const std::string &id, const waybar::Bar &bar
const auto config_sort_by_number = config_["sort-by-number"]; const auto config_sort_by_number = config_["sort-by-number"];
if (config_sort_by_number.isBool()) { if (config_sort_by_number.isBool()) {
spdlog::warn("[wlr/workspaces]: Prefer sort-by-id instead of sort-by-number"); spdlog::warn("[ext/workspaces]: Prefer sort-by-id instead of sort-by-number");
sort_by_id_ = config_sort_by_number.asBool(); sort_by_id_ = config_sort_by_number.asBool();
} }
@ -67,7 +67,7 @@ WorkspaceManager::WorkspaceManager(const std::string &id, const waybar::Bar &bar
box_.get_style_context()->add_class(MODULE_CLASS); box_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(box_); event_box_.add(box_);
spdlog::debug("[wlr/workspaces]: Workspace manager created"); spdlog::debug("[ext/workspaces]: Workspace manager created");
} }
WorkspaceManager::~WorkspaceManager() { WorkspaceManager::~WorkspaceManager() {
@ -82,20 +82,20 @@ WorkspaceManager::~WorkspaceManager() {
} }
if (ext_manager_ != nullptr) { if (ext_manager_ != nullptr) {
spdlog::warn("[wlr/workspaces]: Destroying workspace manager before .finished event"); spdlog::warn("[ext/workspaces]: Destroying workspace manager before .finished event");
ext_workspace_manager_v1_destroy(ext_manager_); ext_workspace_manager_v1_destroy(ext_manager_);
} }
spdlog::debug("[wlr/workspaces]: Workspace manager destroyed"); spdlog::debug("[ext/workspaces]: Workspace manager destroyed");
} }
void WorkspaceManager::register_manager(wl_registry *registry, uint32_t name, uint32_t version) { void WorkspaceManager::register_manager(wl_registry *registry, uint32_t name, uint32_t version) {
if (ext_manager_ != nullptr) { if (ext_manager_ != nullptr) {
spdlog::warn("[wlr/workspaces]: Register workspace manager again although already registered!"); spdlog::warn("[ext/workspaces]: Register workspace manager again although already registered!");
return; return;
} }
if (version != 1) { if (version != 1) {
spdlog::warn("[wlr/workspaces]: Using different workspace manager protocol version: {}", spdlog::warn("[ext/workspaces]: Using different workspace manager protocol version: {}",
version); version);
} }
@ -107,7 +107,7 @@ void WorkspaceManager::remove_workspace_group(uint32_t id) {
std::find_if(groups_.begin(), groups_.end(), [id](const auto &g) { return g->id() == id; }); std::find_if(groups_.begin(), groups_.end(), [id](const auto &g) { return g->id() == id; });
if (it == groups_.end()) { if (it == groups_.end()) {
spdlog::warn("[wlr/workspaces]: Can't find workspace group with id {}", id); spdlog::warn("[ext/workspaces]: Can't find workspace group with id {}", id);
return; return;
} }
@ -119,7 +119,7 @@ void WorkspaceManager::remove_workspace(uint32_t id) {
[id](const auto &w) { return w->id() == id; }); [id](const auto &w) { return w->id() == id; });
if (it == workspaces_.end()) { if (it == workspaces_.end()) {
spdlog::warn("[wlr/workspaces]: Can't find workspace with id {}", id); spdlog::warn("[ext/workspaces]: Can't find workspace with id {}", id);
return; return;
} }
@ -129,7 +129,7 @@ void WorkspaceManager::remove_workspace(uint32_t id) {
void WorkspaceManager::handle_workspace_group(ext_workspace_group_handle_v1 *handle) { void WorkspaceManager::handle_workspace_group(ext_workspace_group_handle_v1 *handle) {
const auto new_id = ++group_global_id; const auto new_id = ++group_global_id;
groups_.push_back(std::make_unique<WorkspaceGroup>(*this, handle, new_id)); groups_.push_back(std::make_unique<WorkspaceGroup>(*this, handle, new_id));
spdlog::debug("[wlr/workspaces]: Workspace group {} created", new_id); spdlog::debug("[ext/workspaces]: Workspace group {} created", new_id);
} }
void WorkspaceManager::handle_workspace(ext_workspace_handle_v1 *handle) { void WorkspaceManager::handle_workspace(ext_workspace_handle_v1 *handle) {
@ -137,13 +137,13 @@ void WorkspaceManager::handle_workspace(ext_workspace_handle_v1 *handle) {
const auto new_name = std::to_string(++workspace_name); const auto new_name = std::to_string(++workspace_name);
workspaces_.push_back(std::make_unique<Workspace>(config_, *this, handle, new_id, new_name)); workspaces_.push_back(std::make_unique<Workspace>(config_, *this, handle, new_id, new_name));
set_needs_sorting(); set_needs_sorting();
spdlog::debug("[wlr/workspaces]: Workspace {} created", new_id); spdlog::debug("[ext/workspaces]: Workspace {} created", new_id);
} }
void WorkspaceManager::handle_done() { dp.emit(); } void WorkspaceManager::handle_done() { dp.emit(); }
void WorkspaceManager::handle_finished() { void WorkspaceManager::handle_finished() {
spdlog::debug("[wlr/workspaces]: Finishing workspace manager"); spdlog::debug("[ext/workspaces]: Finishing workspace manager");
ext_workspace_manager_v1_destroy(ext_manager_); ext_workspace_manager_v1_destroy(ext_manager_);
ext_manager_ = nullptr; ext_manager_ = nullptr;
} }
@ -151,7 +151,7 @@ void WorkspaceManager::handle_finished() {
void WorkspaceManager::commit() const { ext_workspace_manager_v1_commit(ext_manager_); } void WorkspaceManager::commit() const { ext_workspace_manager_v1_commit(ext_manager_); }
void WorkspaceManager::update() { void WorkspaceManager::update() {
spdlog::debug("[wlr/workspaces]: Updating state"); spdlog::debug("[ext/workspaces]: Updating state");
if (needs_sorting_) { if (needs_sorting_) {
clear_buttons(); clear_buttons();
@ -278,7 +278,7 @@ WorkspaceGroup::~WorkspaceGroup() {
if (ext_handle_ != nullptr) { if (ext_handle_ != nullptr) {
ext_workspace_group_handle_v1_destroy(ext_handle_); ext_workspace_group_handle_v1_destroy(ext_handle_);
} }
spdlog::debug("[wlr/workspaces]: Workspace group {} destroyed", id_); spdlog::debug("[ext/workspaces]: Workspace group {} destroyed", id_);
} }
bool WorkspaceGroup::has_output(const wl_output *output) { bool WorkspaceGroup::has_output(const wl_output *output) {
@ -290,10 +290,10 @@ bool WorkspaceGroup::has_workspace(const ext_workspace_handle_v1 *workspace) {
} }
void WorkspaceGroup::handle_capabilities(uint32_t capabilities) { void WorkspaceGroup::handle_capabilities(uint32_t capabilities) {
spdlog::debug("[wlr/workspaces]: Capabilities for workspace group {}:", id_); spdlog::debug("[ext/workspaces]: Capabilities for workspace group {}:", id_);
if ((capabilities & EXT_WORKSPACE_GROUP_HANDLE_V1_GROUP_CAPABILITIES_CREATE_WORKSPACE) == if ((capabilities & EXT_WORKSPACE_GROUP_HANDLE_V1_GROUP_CAPABILITIES_CREATE_WORKSPACE) ==
capabilities) { capabilities) {
spdlog::debug("[wlr/workspaces]: create-workspace"); spdlog::debug("[ext/workspaces]: create-workspace");
} }
} }
@ -318,7 +318,7 @@ void WorkspaceGroup::handle_workspace_leave(ext_workspace_handle_v1 *handle) {
} }
void WorkspaceGroup::handle_removed() { void WorkspaceGroup::handle_removed() {
spdlog::debug("[wlr/workspaces]: Removing workspace group {}", id_); spdlog::debug("[ext/workspaces]: Removing workspace group {}", id_);
workspaces_manager_.remove_workspace_group(id_); workspaces_manager_.remove_workspace_group(id_);
} }
@ -372,7 +372,7 @@ Workspace::~Workspace() {
if (ext_handle_ != nullptr) { if (ext_handle_ != nullptr) {
ext_workspace_handle_v1_destroy(ext_handle_); ext_workspace_handle_v1_destroy(ext_handle_);
} }
spdlog::debug("[wlr/workspaces]: Workspace {} destroyed", id_); spdlog::debug("[ext/workspaces]: Workspace {} destroyed", id_);
} }
bool Workspace::is_active() const { bool Workspace::is_active() const {
@ -440,24 +440,24 @@ void Workspace::handle_state(uint32_t state) {
} }
void Workspace::handle_capabilities(uint32_t capabilities) { void Workspace::handle_capabilities(uint32_t capabilities) {
spdlog::debug("[wlr/workspaces]: Capabilities for workspace {}:", id_); spdlog::debug("[ext/workspaces]: Capabilities for workspace {}:", id_);
if ((capabilities & EXT_WORKSPACE_HANDLE_V1_WORKSPACE_CAPABILITIES_ACTIVATE) == capabilities) { if ((capabilities & EXT_WORKSPACE_HANDLE_V1_WORKSPACE_CAPABILITIES_ACTIVATE) == capabilities) {
spdlog::debug("[wlr/workspaces]: activate"); spdlog::debug("[ext/workspaces]: activate");
} }
if ((capabilities & EXT_WORKSPACE_HANDLE_V1_WORKSPACE_CAPABILITIES_DEACTIVATE) == capabilities) { if ((capabilities & EXT_WORKSPACE_HANDLE_V1_WORKSPACE_CAPABILITIES_DEACTIVATE) == capabilities) {
spdlog::debug("[wlr/workspaces]: deactivate"); spdlog::debug("[ext/workspaces]: deactivate");
} }
if ((capabilities & EXT_WORKSPACE_HANDLE_V1_WORKSPACE_CAPABILITIES_REMOVE) == capabilities) { if ((capabilities & EXT_WORKSPACE_HANDLE_V1_WORKSPACE_CAPABILITIES_REMOVE) == capabilities) {
spdlog::debug("[wlr/workspaces]: remove"); spdlog::debug("[ext/workspaces]: remove");
} }
if ((capabilities & EXT_WORKSPACE_HANDLE_V1_WORKSPACE_CAPABILITIES_ASSIGN) == capabilities) { if ((capabilities & EXT_WORKSPACE_HANDLE_V1_WORKSPACE_CAPABILITIES_ASSIGN) == capabilities) {
spdlog::debug("[wlr/workspaces]: assign"); spdlog::debug("[ext/workspaces]: assign");
} }
needs_updating_ = true; needs_updating_ = true;
} }
void Workspace::handle_removed() { void Workspace::handle_removed() {
spdlog::debug("[wlr/workspaces]: Removing workspace {}", id_); spdlog::debug("[ext/workspaces]: Removing workspace {}", id_);
workspace_manager_.remove_workspace(id_); workspace_manager_.remove_workspace(id_);
} }
@ -480,7 +480,7 @@ bool Workspace::handle_clicked(const GdkEventButton *button) const {
} else if (action == "close") { } else if (action == "close") {
ext_workspace_handle_v1_remove(ext_handle_); ext_workspace_handle_v1_remove(ext_handle_);
} else { } else {
spdlog::warn("[wlr/workspaces]: Unknown action {}", action); spdlog::warn("[ext/workspaces]: Unknown action {}", action);
} }
workspace_manager_.commit(); workspace_manager_.commit();
return true; return true;
@ -507,4 +507,4 @@ std::string Workspace::icon() {
return name_; return name_;
} }
} // namespace waybar::modules::wlr } // namespace waybar::modules::ext

View File

@ -1,13 +1,13 @@
#include "modules/wlr/workspace_manager_binding.hpp" #include "modules/ext/workspace_manager_binding.hpp"
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <cstdint> #include <cstdint>
#include "client.hpp" #include "client.hpp"
#include "modules/wlr/workspace_manager.hpp" #include "modules/ext/workspace_manager.hpp"
namespace waybar::modules::wlr { namespace waybar::modules::ext {
static void handle_global(void *data, wl_registry *registry, uint32_t name, const char *interface, static void handle_global(void *data, wl_registry *registry, uint32_t name, const char *interface,
uint32_t version) { uint32_t version) {
@ -156,4 +156,4 @@ static const ext_workspace_handle_v1_listener workspace_impl = {
void add_workspace_listener(ext_workspace_handle_v1 *workspace_handle, void *data) { void add_workspace_listener(ext_workspace_handle_v1 *workspace_handle, void *data) {
ext_workspace_handle_v1_add_listener(workspace_handle, &workspace_impl, data); ext_workspace_handle_v1_add_listener(workspace_handle, &workspace_impl, data);
} }
} // namespace waybar::modules::wlr } // namespace waybar::modules::ext