Waybar/include/modules/hyprland/workspaces.hpp

65 lines
1.5 KiB
C++
Raw Normal View History

2023-06-27 23:52:01 +00:00
#include <gtkmm/button.h>
#include <gtkmm/label.h>
2023-07-03 22:24:34 +00:00
2023-07-03 22:17:26 +00:00
#include <memory>
2023-06-27 23:52:01 +00:00
#include "AModule.hpp"
#include "bar.hpp"
#include "modules/hyprland/backend.hpp"
namespace waybar::modules::hyprland {
2023-06-30 21:18:57 +00:00
struct WorkspaceDto {
int id;
static WorkspaceDto parse(const Json::Value& value);
};
2023-06-27 23:52:01 +00:00
class Workspace {
public:
Workspace(int id);
2023-06-30 21:18:57 +00:00
Workspace(WorkspaceDto dto);
int id() const { return id_; };
int active() const { return active_; };
std::string& select_icon(std::map<std::string, std::string>& icons_map);
void set_active(bool value = true) { active_ = value; };
2023-06-27 23:52:01 +00:00
Gtk::Button& button() { return button_; };
2023-06-30 21:18:57 +00:00
void update(const std::string& format, const std::string& icon);
2023-06-27 23:52:01 +00:00
private:
int id_;
2023-06-30 21:18:57 +00:00
bool active_;
2023-06-27 23:52:01 +00:00
Gtk::Button button_;
Gtk::Box content_;
Gtk::Label label_;
};
class Workspaces : public AModule, public EventHandler {
public:
Workspaces(const std::string&, const waybar::Bar&, const Json::Value&);
virtual ~Workspaces();
void update() override;
void init();
private:
void onEvent(const std::string&) override;
2023-06-30 21:18:57 +00:00
void sort_workspaces();
2023-07-03 22:17:26 +00:00
void create_workspace(int id);
void remove_workspace(int id);
2023-06-27 23:52:01 +00:00
2023-06-30 21:18:57 +00:00
std::string format_;
std::map<std::string, std::string> icons_map_;
bool with_icon_;
int active_workspace_id;
2023-07-03 22:17:26 +00:00
std::vector<std::unique_ptr<Workspace>> workspaces_;
std::vector<int> workspaces_to_create_;
std::vector<int> workspaces_to_remove_;
2023-06-27 23:52:01 +00:00
std::mutex mutex_;
const Bar& bar_;
Gtk::Box box_;
};
} // namespace waybar::modules::hyprland