waybar/include/modules/hyprland/workspaces.hpp

76 lines
1.9 KiB
C++
Raw Normal View History

2023-06-28 01:52:01 +02:00
#include <gtkmm/button.h>
#include <gtkmm/label.h>
2023-07-04 00:24:34 +02:00
2023-07-04 00:17:26 +02:00
#include <memory>
2023-06-28 01:52:01 +02:00
#include "AModule.hpp"
#include "bar.hpp"
#include "modules/hyprland/backend.hpp"
namespace waybar::modules::hyprland {
class Workspace {
public:
2023-07-15 19:44:57 +02:00
Workspace(const Json::Value& value);
2023-06-30 23:18:57 +02:00
std::string& select_icon(std::map<std::string, std::string>& icons_map);
2023-06-28 01:52:01 +02:00
Gtk::Button& button() { return button_; };
2023-07-15 19:44:57 +02:00
int id() const { return id_; };
std::string name() const { return name_; };
2023-07-16 03:20:30 +02:00
std::string output() const { return output_; };
2023-07-15 19:44:57 +02:00
int active() const { return active_; };
bool is_special() const { return is_special_; };
auto handle_clicked(GdkEventButton* bt) -> bool;
2023-07-16 03:20:30 +02:00
void set_active(bool value = true) { active_ = value; };
2023-07-15 19:44:57 +02:00
2023-06-30 23:18:57 +02:00
void update(const std::string& format, const std::string& icon);
2023-06-28 01:52:01 +02:00
private:
int id_;
2023-07-15 19:44:57 +02:00
std::string name_;
2023-07-16 03:20:30 +02:00
std::string output_;
2023-07-15 19:44:57 +02:00
int windows_;
2023-06-30 23:18:57 +02:00
bool active_;
2023-07-15 19:44:57 +02:00
bool is_special_;
2023-06-28 01:52:01 +02: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();
2023-07-15 19:44:57 +02:00
auto all_outputs() const -> bool { return all_outputs_; }
auto show_special() const -> bool { return show_special_; }
auto get_bar_output() const -> std::string { return bar_.output->name; }
2023-06-28 01:52:01 +02:00
private:
void onEvent(const std::string&) override;
2023-06-30 23:18:57 +02:00
void sort_workspaces();
2023-07-16 03:43:54 +02:00
void create_workspace(Json::Value& value);
2023-07-15 19:44:57 +02:00
void remove_workspace(std::string name);
bool all_outputs_ = false;
bool show_special_ = false;
2023-06-28 01:52:01 +02:00
2023-06-30 23:18:57 +02:00
std::string format_;
std::map<std::string, std::string> icons_map_;
bool with_icon_;
2023-07-15 19:44:57 +02:00
std::string active_workspace_name;
2023-07-04 00:17:26 +02:00
std::vector<std::unique_ptr<Workspace>> workspaces_;
2023-07-16 03:43:54 +02:00
std::vector<Json::Value> workspaces_to_create_;
2023-07-15 19:44:57 +02:00
std::vector<std::string> workspaces_to_remove_;
2023-06-28 01:52:01 +02:00
std::mutex mutex_;
const Bar& bar_;
Gtk::Box box_;
};
} // namespace waybar::modules::hyprland