Waybar/include/modules/hyprland/workspaces.hpp

109 lines
3.1 KiB
C++
Raw Normal View History

2023-09-02 20:22:26 +00:00
#pragma once
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-09-02 20:22:26 +00:00
#include <map>
2023-07-03 22:17:26 +00:00
#include <memory>
2023-09-02 20:22:26 +00:00
#include <string>
#include <vector>
2023-06-27 23:52:01 +00:00
#include "AModule.hpp"
#include "bar.hpp"
#include "modules/hyprland/backend.hpp"
namespace waybar::modules::hyprland {
class Workspaces;
2023-06-27 23:52:01 +00:00
class Workspace {
public:
explicit Workspace(const Json::Value& workspace_data, Workspaces& workspace_manager);
2023-06-30 21:18:57 +00:00
std::string& select_icon(std::map<std::string, std::string>& icons_map);
2023-06-27 23:52:01 +00:00
Gtk::Button& button() { return button_; };
2023-07-15 17:44:57 +00:00
int id() const { return id_; };
std::string name() const { return name_; };
2023-07-16 01:20:30 +00:00
std::string output() const { return output_; };
bool active() const { return active_; };
2023-07-15 17:44:57 +00:00
bool is_special() const { return is_special_; };
bool is_persistent() const { return is_persistent_; };
bool is_visible() const { return is_visible_; };
bool is_empty() const { return windows_ == 0; };
2023-08-23 17:18:35 +00:00
bool is_urgent() const { return is_urgent_; };
2023-07-15 17:44:57 +00:00
auto handle_clicked(GdkEventButton* bt) -> bool;
2023-07-16 01:20:30 +00:00
void set_active(bool value = true) { active_ = value; };
void set_persistent(bool value = true) { is_persistent_ = value; };
2023-08-23 17:18:35 +00:00
void set_urgent(bool value = true) { is_urgent_ = value; };
void set_visible(bool value = true) { is_visible_ = value; };
void set_windows(uint value) { windows_ = value; };
void set_name(std::string value) { name_ = value; };
2023-07-15 17:44:57 +00:00
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:
Workspaces& workspace_manager_;
2023-06-27 23:52:01 +00:00
int id_;
2023-07-15 17:44:57 +00:00
std::string name_;
2023-07-16 01:20:30 +00:00
std::string output_;
uint windows_;
bool active_ = false;
bool is_special_ = false;
bool is_persistent_ = false;
2023-08-23 17:18:35 +00:00
bool is_urgent_ = false;
bool is_visible_ = false;
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&);
2023-07-16 12:47:14 +00:00
~Workspaces() override;
2023-06-27 23:52:01 +00:00
void update() override;
void init();
2023-07-15 17:44:57 +00:00
auto all_outputs() const -> bool { return all_outputs_; }
auto show_special() const -> bool { return show_special_; }
auto active_only() const -> bool { return active_only_; }
2023-07-15 17:44:57 +00:00
auto get_bar_output() const -> std::string { return bar_.output->name; }
2023-06-27 23:52:01 +00:00
private:
void onEvent(const std::string&) override;
void update_window_count();
2023-06-30 21:18:57 +00:00
void sort_workspaces();
2023-07-16 01:43:54 +00:00
void create_workspace(Json::Value& value);
2023-07-15 17:44:57 +00:00
void remove_workspace(std::string name);
2023-08-23 17:18:35 +00:00
void set_urgent_workspace(std::string windowaddress);
void parse_config(const Json::Value& config);
void register_ipc();
2023-07-15 17:44:57 +00:00
bool all_outputs_ = false;
bool show_special_ = false;
bool active_only_ = false;
2023-06-27 23:52:01 +00:00
void fill_persistent_workspaces();
void create_persistent_workspaces();
std::vector<std::string> persistent_workspaces_to_create_;
bool persistent_created_ = false;
2023-06-30 21:18:57 +00:00
std::string format_;
std::map<std::string, std::string> icons_map_;
bool with_icon_;
uint64_t monitor_id_;
std::string active_workspace_name_;
2023-07-03 22:17:26 +00:00
std::vector<std::unique_ptr<Workspace>> workspaces_;
2023-07-16 01:43:54 +00:00
std::vector<Json::Value> workspaces_to_create_;
2023-07-15 17:44:57 +00:00
std::vector<std::string> workspaces_to_remove_;
2023-06-27 23:52:01 +00:00
std::mutex mutex_;
const Bar& bar_;
Gtk::Box box_;
};
} // namespace waybar::modules::hyprland