Files
Waybar/include/modules/ext/workspace_manager.hpp
T

145 lines
3.9 KiB
C++
Raw Normal View History

2020-08-05 23:10:08 +03:00
#pragma once
#include <fmt/format.h>
2020-08-06 01:42:57 +03:00
#include <gtkmm/button.h>
2020-08-05 23:10:08 +03:00
#include <gtkmm/image.h>
2020-08-06 01:42:57 +03:00
#include <gtkmm/label.h>
2020-08-05 23:10:08 +03:00
2020-08-07 02:45:08 +03:00
#include <map>
2020-08-05 23:10:08 +03:00
#include <memory>
#include <vector>
#include "AModule.hpp"
#include "bar.hpp"
2025-04-11 08:00:35 +02:00
#include "ext-workspace-v1-client-protocol.h"
2020-08-05 23:10:08 +03:00
namespace waybar::modules::ext {
2020-08-05 23:10:08 +03:00
class WorkspaceGroup;
2025-04-11 08:00:35 +02:00
class Workspace;
2020-08-05 23:10:08 +03:00
2025-04-11 08:00:35 +02:00
class WorkspaceManager final : public AModule {
2020-08-05 23:10:08 +03:00
public:
2025-04-11 08:00:35 +02:00
WorkspaceManager(const std::string &id, const waybar::Bar &bar, const Json::Value &config);
~WorkspaceManager() override;
void register_manager(wl_registry *registry, uint32_t name, uint32_t version);
void remove_workspace_group(uint32_t id);
void remove_workspace(uint32_t id);
void set_needs_sorting() { needs_sorting_ = true; }
2020-08-05 23:10:08 +03:00
// wl events
2025-04-11 08:00:35 +02:00
void handle_workspace_group(ext_workspace_group_handle_v1 *handle);
void handle_workspace(ext_workspace_handle_v1 *handle);
void handle_done();
void handle_finished();
2020-08-05 23:10:08 +03:00
// wl requests
2025-04-11 08:00:35 +02:00
void commit() const;
2020-08-05 23:10:08 +03:00
private:
2025-04-11 08:00:35 +02:00
void update() override;
bool has_button(const Gtk::Button *button);
void sort_workspaces();
void clear_buttons();
void update_buttons();
2020-08-07 02:45:08 +03:00
2025-04-11 08:00:35 +02:00
static uint32_t group_global_id;
static uint32_t workspace_global_id;
uint32_t workspace_name = 0;
2020-08-05 23:10:08 +03:00
2025-04-11 08:00:35 +02:00
bool sort_by_id_ = false;
bool sort_by_name_ = true;
bool sort_by_coordinates_ = false;
bool active_only_ = false;
bool all_outputs_ = false;
2020-08-05 23:10:08 +03:00
2025-04-11 08:00:35 +02:00
const waybar::Bar &bar_;
Gtk::Box box_;
2020-08-05 23:10:08 +03:00
2025-04-11 08:00:35 +02:00
ext_workspace_manager_v1 *ext_manager_ = nullptr;
std::vector<std::unique_ptr<WorkspaceGroup>> groups_;
std::vector<std::unique_ptr<Workspace>> workspaces_;
bool needs_sorting_ = false;
2020-08-05 23:10:08 +03:00
};
class WorkspaceGroup {
public:
2025-04-11 08:00:35 +02:00
WorkspaceGroup(WorkspaceManager &manager, ext_workspace_group_handle_v1 *handle, uint32_t id);
2020-08-05 23:10:08 +03:00
~WorkspaceGroup();
2025-04-11 08:00:35 +02:00
u_int32_t id() const { return id_; }
bool has_output(const wl_output *output);
bool has_workspace(const ext_workspace_handle_v1 *workspace);
2021-11-23 03:10:44 +03:00
// wl events
2025-04-11 08:00:35 +02:00
void handle_capabilities(uint32_t capabilities);
void handle_output_enter(wl_output *output);
void handle_output_leave(wl_output *output);
void handle_workspace_enter(ext_workspace_handle_v1 *handle);
void handle_workspace_leave(ext_workspace_handle_v1 *handle);
void handle_removed();
2020-08-06 01:42:57 +03:00
2020-08-05 23:10:08 +03:00
private:
2025-04-11 08:00:35 +02:00
WorkspaceManager &workspaces_manager_;
ext_workspace_group_handle_v1 *ext_handle_;
2022-04-06 08:37:19 +02:00
uint32_t id_;
2025-04-11 08:00:35 +02:00
std::vector<wl_output *> outputs_;
std::vector<ext_workspace_handle_v1 *> workspaces_;
2020-08-05 23:10:08 +03:00
};
2025-04-11 08:00:35 +02:00
class Workspace {
2020-08-05 23:10:08 +03:00
public:
2025-04-11 08:00:35 +02:00
Workspace(const Json::Value &config, WorkspaceManager &manager, ext_workspace_handle_v1 *handle,
uint32_t id, const std::string &name);
~Workspace();
2020-08-05 23:10:08 +03:00
2025-04-11 08:00:35 +02:00
ext_workspace_handle_v1 *handle() const { return ext_handle_; }
u_int32_t id() const { return id_; }
std::string &workspace_id() { return workspace_id_; }
std::string &name() { return name_; }
std::vector<u_int32_t> &coordinates() { return coordinates_; }
Gtk::Button &button() { return button_; }
bool is_active() const;
bool is_urgent() const;
bool is_hidden() const;
void update();
2021-11-23 03:10:44 +03:00
// wl events
2025-04-11 08:00:35 +02:00
void handle_id(const std::string &id);
void handle_name(const std::string &name);
void handle_coordinates(const std::vector<uint32_t> &coordinates);
void handle_state(uint32_t state);
void handle_capabilities(uint32_t capabilities);
void handle_removed();
2020-08-05 23:10:08 +03:00
2025-04-11 08:00:35 +02:00
// gdk events
bool handle_clicked(const GdkEventButton *button) const;
2020-08-06 01:42:57 +03:00
2020-08-05 23:10:08 +03:00
private:
2025-04-11 08:00:35 +02:00
std::string icon();
2020-08-05 23:10:08 +03:00
2025-04-11 08:00:35 +02:00
WorkspaceManager &workspace_manager_;
ext_workspace_handle_v1 *ext_handle_ = nullptr;
uint32_t id_;
uint32_t state_ = 0;
std::string workspace_id_;
std::string name_;
std::vector<uint32_t> coordinates_;
2020-08-07 23:46:47 +03:00
2025-04-11 08:00:35 +02:00
std::string format_;
bool with_icon_ = false;
static std::map<std::string, std::string> icon_map_;
std::string on_click_action_;
std::string on_click_middle_action_;
std::string on_click_right_action_;
2021-11-23 03:10:44 +03:00
2025-04-11 08:00:35 +02:00
Gtk::Button button_;
Gtk::Box content_;
Gtk::Label label_;
bool needs_updating_ = false;
2020-08-05 23:10:08 +03:00
};
} // namespace waybar::modules::ext