2020-08-05 20:10:08 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <fmt/format.h>
|
2020-08-05 22:42:57 +00:00
|
|
|
#include <gtkmm/button.h>
|
2020-08-05 20:10:08 +00:00
|
|
|
#include <gtkmm/image.h>
|
2020-08-05 22:42:57 +00:00
|
|
|
#include <gtkmm/label.h>
|
2020-08-05 20:10:08 +00:00
|
|
|
|
2020-08-06 23:45:08 +00:00
|
|
|
#include <map>
|
2020-08-05 20:10:08 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "AModule.hpp"
|
|
|
|
#include "bar.hpp"
|
2021-11-21 12:01:25 +00:00
|
|
|
#include "ext-workspace-unstable-v1-client-protocol.h"
|
2020-08-05 20:10:08 +00:00
|
|
|
|
|
|
|
namespace waybar::modules::wlr {
|
|
|
|
|
|
|
|
class WorkspaceManager;
|
|
|
|
class WorkspaceGroup;
|
|
|
|
|
|
|
|
class Workspace {
|
|
|
|
public:
|
|
|
|
Workspace(const waybar::Bar &bar, const Json::Value &config, WorkspaceGroup &workspace_group,
|
2021-11-21 12:01:25 +00:00
|
|
|
zext_workspace_handle_v1 *workspace, uint32_t id);
|
2020-08-05 20:10:08 +00:00
|
|
|
~Workspace();
|
|
|
|
auto update() -> void;
|
|
|
|
|
|
|
|
auto id() const -> uint32_t { return id_; }
|
2020-08-06 23:45:08 +00:00
|
|
|
auto is_active() const -> bool { return state_ & static_cast<uint32_t>(State::ACTIVE); }
|
2020-08-05 22:42:57 +00:00
|
|
|
// wlr stuff
|
2020-08-07 20:46:47 +00:00
|
|
|
auto handle_name(const std::string &name) -> void;
|
|
|
|
auto handle_coordinates(const std::vector<uint32_t> &coordinates) -> void;
|
2020-08-05 20:10:08 +00:00
|
|
|
auto handle_state(const std::vector<uint32_t> &state) -> void;
|
|
|
|
auto handle_remove() -> void;
|
|
|
|
|
2020-08-06 23:45:08 +00:00
|
|
|
auto handle_done() -> void;
|
|
|
|
auto handle_clicked() -> void;
|
2020-08-07 20:46:47 +00:00
|
|
|
auto show() -> void { button_.show(); }
|
|
|
|
auto hide() -> void { button_.hide(); }
|
|
|
|
auto get_button_ref() -> Gtk::Button & { return button_; }
|
|
|
|
auto get_name() -> std::string & { return name_; }
|
|
|
|
auto get_coords() -> std::vector<uint32_t> & { return coordinates_; }
|
2020-08-06 23:45:08 +00:00
|
|
|
|
2020-08-05 20:10:08 +00:00
|
|
|
enum class State { ACTIVE = 1 << 0 };
|
|
|
|
|
|
|
|
private:
|
2020-08-06 23:45:08 +00:00
|
|
|
auto get_icon() -> std::string;
|
|
|
|
|
2020-08-05 20:10:08 +00:00
|
|
|
const Bar & bar_;
|
|
|
|
const Json::Value &config_;
|
|
|
|
WorkspaceGroup & workspace_group_;
|
|
|
|
|
|
|
|
// wlr stuff
|
2021-11-21 12:01:25 +00:00
|
|
|
zext_workspace_handle_v1 *workspace_handle_;
|
2020-08-05 20:10:08 +00:00
|
|
|
uint32_t state_ = 0;
|
|
|
|
|
2020-08-06 23:45:08 +00:00
|
|
|
uint32_t id_;
|
|
|
|
std::string name_;
|
|
|
|
std::vector<uint32_t> coordinates_;
|
|
|
|
static std::map<std::string, std::string> icons_map_;
|
|
|
|
std::string format_;
|
|
|
|
bool with_icon_ = false;
|
2020-08-05 20:10:08 +00:00
|
|
|
|
2020-08-05 22:42:57 +00:00
|
|
|
Gtk::Button button_;
|
|
|
|
Gtk::Box content_;
|
|
|
|
Gtk::Label label_;
|
2020-08-05 20:10:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class WorkspaceGroup {
|
|
|
|
public:
|
2020-08-07 20:46:47 +00:00
|
|
|
WorkspaceGroup(const waybar::Bar &bar, Gtk::Box &box, const Json::Value &config,
|
2021-11-21 12:01:25 +00:00
|
|
|
WorkspaceManager &manager, zext_workspace_group_handle_v1 *workspace_group_handle,
|
2020-08-07 20:46:47 +00:00
|
|
|
uint32_t id);
|
2020-08-05 20:10:08 +00:00
|
|
|
~WorkspaceGroup();
|
|
|
|
auto update() -> void;
|
|
|
|
|
|
|
|
auto id() const -> uint32_t { return id_; }
|
2020-08-06 23:45:08 +00:00
|
|
|
auto is_visible() const -> bool { return output_ != nullptr; }
|
2020-08-05 20:10:08 +00:00
|
|
|
auto remove_workspace(uint32_t id_) -> void;
|
|
|
|
|
|
|
|
// wlr stuff
|
2021-11-21 12:01:25 +00:00
|
|
|
auto handle_workspace_create(zext_workspace_handle_v1 *workspace_handle) -> void;
|
2020-08-05 20:10:08 +00:00
|
|
|
auto handle_remove() -> void;
|
|
|
|
auto handle_output_enter(wl_output *output) -> void;
|
|
|
|
auto handle_output_leave() -> void;
|
|
|
|
|
2020-08-05 22:42:57 +00:00
|
|
|
auto add_button(Gtk::Button &button) -> void;
|
2020-08-10 21:28:56 +00:00
|
|
|
auto remove_button(Gtk::Button &button) -> void;
|
2020-08-06 23:45:08 +00:00
|
|
|
auto handle_done() -> void;
|
|
|
|
auto commit() -> void;
|
2020-08-07 20:46:47 +00:00
|
|
|
auto sort_workspaces() -> void;
|
2020-08-05 22:42:57 +00:00
|
|
|
|
2020-08-05 20:10:08 +00:00
|
|
|
private:
|
2020-08-07 20:46:47 +00:00
|
|
|
static uint32_t workspace_global_id;
|
2020-08-05 20:10:08 +00:00
|
|
|
const waybar::Bar &bar_;
|
2020-08-07 20:46:47 +00:00
|
|
|
Gtk::Box & box_;
|
2020-08-05 20:10:08 +00:00
|
|
|
const Json::Value &config_;
|
|
|
|
WorkspaceManager & workspace_manager_;
|
|
|
|
|
|
|
|
// wlr stuff
|
2021-11-21 12:01:25 +00:00
|
|
|
zext_workspace_group_handle_v1 *workspace_group_handle_;
|
2020-08-05 20:10:08 +00:00
|
|
|
wl_output * output_ = nullptr;
|
|
|
|
|
|
|
|
uint32_t id_;
|
|
|
|
std::vector<std::unique_ptr<Workspace>> workspaces_;
|
2020-08-07 20:46:47 +00:00
|
|
|
bool sort_by_name = true;
|
|
|
|
bool sort_by_coordinates = true;
|
2020-08-05 20:10:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class WorkspaceManager : public AModule {
|
|
|
|
public:
|
|
|
|
WorkspaceManager(const std::string &id, const waybar::Bar &bar, const Json::Value &config);
|
|
|
|
~WorkspaceManager() override;
|
|
|
|
auto update() -> void override;
|
|
|
|
|
|
|
|
auto remove_workspace_group(uint32_t id_) -> void;
|
|
|
|
|
|
|
|
// wlr stuff
|
|
|
|
auto register_manager(wl_registry *registry, uint32_t name, uint32_t version) -> void;
|
2021-11-21 12:01:25 +00:00
|
|
|
auto handle_workspace_group_create(zext_workspace_group_handle_v1 *workspace_group_handle)
|
2020-08-05 20:10:08 +00:00
|
|
|
-> void;
|
|
|
|
auto handle_done() -> void;
|
|
|
|
auto handle_finished() -> void;
|
|
|
|
|
2020-08-06 23:45:08 +00:00
|
|
|
auto commit() -> void;
|
2020-08-05 22:42:57 +00:00
|
|
|
|
2020-08-05 20:10:08 +00:00
|
|
|
private:
|
|
|
|
const waybar::Bar & bar_;
|
|
|
|
Gtk::Box box_;
|
|
|
|
std::vector<std::unique_ptr<WorkspaceGroup>> groups_;
|
|
|
|
|
|
|
|
// wlr stuff
|
2021-11-21 12:01:25 +00:00
|
|
|
zext_workspace_manager_v1 *workspace_manager_ = nullptr;
|
2020-08-07 20:46:47 +00:00
|
|
|
|
|
|
|
static uint32_t group_global_id;
|
2020-08-05 20:10:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace waybar::modules::wlr
|