|
5 | 5 | #include <gtkmm/image.h>
|
6 | 6 | #include <gtkmm/label.h>
|
7 | 7 |
|
8 |
| -#include <functional> |
9 | 8 | #include <map>
|
10 | 9 | #include <memory>
|
11 | 10 | #include <vector>
|
12 | 11 |
|
13 | 12 | #include "AModule.hpp"
|
14 | 13 | #include "bar.hpp"
|
15 |
| -#include "ext-workspace-unstable-v1-client-protocol.h" |
| 14 | +#include "ext-workspace-v1-client-protocol.h" |
16 | 15 |
|
17 | 16 | namespace waybar::modules::wlr {
|
18 | 17 |
|
19 |
| -class WorkspaceManager; |
20 | 18 | class WorkspaceGroup;
|
| 19 | +class Workspace; |
21 | 20 |
|
22 |
| -class Workspace { |
| 21 | +class WorkspaceManager final : public AModule { |
23 | 22 | public:
|
24 |
| - Workspace(const waybar::Bar &bar, const Json::Value &config, WorkspaceGroup &workspace_group, |
25 |
| - zext_workspace_handle_v1 *workspace, uint32_t id, std::string name); |
26 |
| - ~Workspace(); |
27 |
| - auto update() -> void; |
28 |
| - |
29 |
| - auto id() const -> uint32_t { return id_; } |
30 |
| - auto is_active() const -> bool { return state_ & static_cast<uint32_t>(State::ACTIVE); } |
31 |
| - auto is_urgent() const -> bool { return state_ & static_cast<uint32_t>(State::URGENT); } |
32 |
| - auto is_hidden() const -> bool { return state_ & static_cast<uint32_t>(State::HIDDEN); } |
33 |
| - auto is_empty() const -> bool { return state_ & static_cast<uint32_t>(State::EMPTY); } |
34 |
| - auto is_persistent() const -> bool { return persistent_; } |
35 |
| - // wlr stuff |
36 |
| - auto handle_name(const std::string &name) -> void; |
37 |
| - auto handle_coordinates(const std::vector<uint32_t> &coordinates) -> void; |
38 |
| - auto handle_state(const std::vector<uint32_t> &state) -> void; |
39 |
| - auto handle_remove() -> void; |
40 |
| - auto make_persistent() -> void; |
41 |
| - auto handle_duplicate() -> void; |
42 |
| - |
43 |
| - auto handle_done() -> void; |
44 |
| - auto handle_clicked(GdkEventButton *bt) -> bool; |
45 |
| - auto show() -> void; |
46 |
| - auto hide() -> void; |
47 |
| - auto get_button_ref() -> Gtk::Button & { return button_; } |
48 |
| - auto get_name() -> std::string & { return name_; } |
49 |
| - auto get_coords() -> std::vector<uint32_t> & { return coordinates_; } |
50 |
| - |
51 |
| - enum class State { |
52 |
| - ACTIVE = (1 << 0), |
53 |
| - URGENT = (1 << 1), |
54 |
| - HIDDEN = (1 << 2), |
55 |
| - EMPTY = (1 << 3), |
56 |
| - }; |
| 23 | + WorkspaceManager(const std::string &id, const waybar::Bar &bar, const Json::Value &config); |
| 24 | + void register_manager(wl_registry *registry, uint32_t name, uint32_t version); |
| 25 | + void remove_workspace_group(uint32_t id); |
| 26 | + void remove_workspace(uint32_t id); |
57 | 27 |
|
58 |
| - private: |
59 |
| - auto get_icon() -> std::string; |
60 |
| - |
61 |
| - const Bar &bar_; |
62 |
| - const Json::Value &config_; |
63 |
| - WorkspaceGroup &workspace_group_; |
64 |
| - |
65 |
| - // wlr stuff |
66 |
| - zext_workspace_handle_v1 *workspace_handle_; |
67 |
| - uint32_t state_ = 0; |
68 |
| - |
69 |
| - uint32_t id_; |
70 |
| - std::string name_; |
71 |
| - std::vector<uint32_t> coordinates_; |
72 |
| - static std::map<std::string, std::string> icons_map_; |
73 |
| - std::string format_; |
74 |
| - bool with_icon_ = false; |
75 |
| - bool persistent_ = false; |
76 |
| - |
77 |
| - Gtk::Button button_; |
78 |
| - Gtk::Box content_; |
79 |
| - Gtk::Label label_; |
80 |
| -}; |
| 28 | + // wlr events |
| 29 | + void handle_workspace_group(ext_workspace_group_handle_v1 *handle); |
| 30 | + void handle_workspace(ext_workspace_handle_v1 *handle); |
| 31 | + void handle_done(); |
| 32 | + void handle_finished(); |
81 | 33 |
|
82 |
| -class WorkspaceGroup { |
83 |
| - public: |
84 |
| - WorkspaceGroup(const waybar::Bar &bar, Gtk::Box &box, const Json::Value &config, |
85 |
| - WorkspaceManager &manager, zext_workspace_group_handle_v1 *workspace_group_handle, |
86 |
| - uint32_t id); |
87 |
| - ~WorkspaceGroup(); |
88 |
| - auto update() -> void; |
89 |
| - |
90 |
| - auto id() const -> uint32_t { return id_; } |
91 |
| - auto is_visible() const -> bool; |
92 |
| - auto remove_workspace(uint32_t id_) -> void; |
93 |
| - auto active_only() const -> bool; |
94 |
| - auto creation_delayed() const -> bool; |
95 |
| - auto workspaces() -> std::vector<std::unique_ptr<Workspace>> & { return workspaces_; } |
96 |
| - auto persistent_workspaces() -> std::vector<std::string> & { return persistent_workspaces_; } |
97 |
| - |
98 |
| - auto sort_workspaces() -> void; |
99 |
| - auto set_need_to_sort() -> void { need_to_sort = true; } |
100 |
| - auto add_button(Gtk::Button &button) -> void; |
101 |
| - auto remove_button(Gtk::Button &button) -> void; |
102 |
| - auto fill_persistent_workspaces() -> void; |
103 |
| - auto create_persistent_workspaces() -> void; |
104 |
| - |
105 |
| - // wlr stuff |
106 |
| - auto handle_workspace_create(zext_workspace_handle_v1 *workspace_handle) -> void; |
107 |
| - auto handle_remove() -> void; |
108 |
| - auto handle_output_enter(wl_output *output) -> void; |
109 |
| - auto handle_output_leave() -> void; |
110 |
| - auto handle_done() -> void; |
111 |
| - auto commit() -> void; |
| 34 | + // wlr requests |
| 35 | + void commit() const; |
112 | 36 |
|
113 | 37 | private:
|
114 |
| - static uint32_t workspace_global_id; |
115 |
| - const waybar::Bar &bar_; |
116 |
| - Gtk::Box &box_; |
117 |
| - const Json::Value &config_; |
118 |
| - WorkspaceManager &workspace_manager_; |
119 |
| - |
120 |
| - // wlr stuff |
121 |
| - zext_workspace_group_handle_v1 *workspace_group_handle_; |
122 |
| - wl_output *output_ = nullptr; |
| 38 | + void update() override; |
| 39 | + bool has_button(const Gtk::Button *button); |
123 | 40 |
|
124 |
| - uint32_t id_; |
125 |
| - std::vector<std::unique_ptr<Workspace>> workspaces_; |
126 |
| - bool need_to_sort = false; |
127 |
| - std::vector<std::string> persistent_workspaces_; |
128 |
| - bool persistent_created_ = false; |
129 |
| -}; |
| 41 | + static uint32_t group_global_id; |
| 42 | + static uint32_t workspace_global_id; |
130 | 43 |
|
131 |
| -class WorkspaceManager : public AModule { |
132 |
| - public: |
133 |
| - WorkspaceManager(const std::string &id, const waybar::Bar &bar, const Json::Value &config); |
134 |
| - ~WorkspaceManager() override; |
135 |
| - auto update() -> void override; |
136 |
| - |
137 |
| - auto all_outputs() const -> bool { return all_outputs_; } |
138 |
| - auto active_only() const -> bool { return active_only_; } |
139 |
| - auto workspace_comparator() const |
140 |
| - -> std::function<bool(std::unique_ptr<Workspace> &, std::unique_ptr<Workspace> &)>; |
141 |
| - auto creation_delayed() const -> bool { return creation_delayed_; } |
142 |
| - |
143 |
| - auto sort_workspaces() -> void; |
144 |
| - auto remove_workspace_group(uint32_t id_) -> void; |
145 |
| - |
146 |
| - // wlr stuff |
147 |
| - auto register_manager(wl_registry *registry, uint32_t name, uint32_t version) -> void; |
148 |
| - auto handle_workspace_group_create(zext_workspace_group_handle_v1 *workspace_group_handle) |
149 |
| - -> void; |
150 |
| - auto handle_done() -> void; |
151 |
| - auto handle_finished() -> void; |
152 |
| - auto commit() -> void; |
| 44 | + bool sort_by_id_ = false; |
| 45 | + bool sort_by_name_ = false; |
| 46 | + bool sort_by_coordinates_ = false; |
| 47 | + bool active_only_ = false; |
| 48 | + bool all_outputs_ = false; |
153 | 49 |
|
154 |
| - private: |
155 | 50 | const waybar::Bar &bar_;
|
156 | 51 | Gtk::Box box_;
|
157 |
| - std::vector<std::unique_ptr<WorkspaceGroup>> groups_; |
158 | 52 |
|
159 |
| - // wlr stuff |
160 |
| - zext_workspace_manager_v1 *workspace_manager_ = nullptr; |
| 53 | + ext_workspace_manager_v1 *ext_manager_ = nullptr; |
| 54 | + std::vector<std::unique_ptr<WorkspaceGroup>> groups_; |
| 55 | + std::vector<std::unique_ptr<Workspace>> workspaces_; |
| 56 | +}; |
161 | 57 |
|
162 |
| - static uint32_t group_global_id; |
| 58 | +class WorkspaceGroup { |
| 59 | + public: |
| 60 | + WorkspaceGroup(WorkspaceManager &manager, ext_workspace_group_handle_v1 *handle, uint32_t id); |
| 61 | + |
| 62 | + u_int32_t id() const { return id_; } |
| 63 | + bool has_output(const wl_output *output); |
| 64 | + bool has_workspace(const ext_workspace_handle_v1 *workspace); |
| 65 | + |
| 66 | + // wlr events |
| 67 | + void handle_capabilities(uint32_t capabilities); |
| 68 | + void handle_output_enter(wl_output *output); |
| 69 | + void handle_output_leave(wl_output *output); |
| 70 | + void handle_workspace_enter(ext_workspace_handle_v1 *handle); |
| 71 | + void handle_workspace_leave(ext_workspace_handle_v1 *handle); |
| 72 | + void handle_removed(); |
| 73 | + |
| 74 | + private: |
| 75 | + WorkspaceManager &workspaces_manager_; |
| 76 | + ext_workspace_group_handle_v1 *ext_handle_; |
| 77 | + uint32_t id_; |
| 78 | + std::vector<wl_output *> outputs_; |
| 79 | + std::vector<ext_workspace_handle_v1 *> workspaces_; |
| 80 | +}; |
163 | 81 |
|
164 |
| - bool sort_by_name_ = true; |
165 |
| - bool sort_by_coordinates_ = true; |
166 |
| - bool sort_by_number_ = false; |
167 |
| - bool all_outputs_ = false; |
168 |
| - bool active_only_ = false; |
169 |
| - bool creation_delayed_ = false; |
| 82 | +class Workspace { |
| 83 | + public: |
| 84 | + Workspace(const Json::Value &config, WorkspaceManager &manager, ext_workspace_handle_v1 *handle, uint32_t id); |
| 85 | + |
| 86 | + ext_workspace_handle_v1 * handle() const { return ext_handle_; } |
| 87 | + u_int32_t id() const { return id_; } |
| 88 | + std::string & workspace_id() { return workspace_id_; } |
| 89 | + std::string & name() { return name_; } |
| 90 | + std::vector<u_int32_t> & coordinates() { return coordinates_; } |
| 91 | + Gtk::Button & button() { return button_; } |
| 92 | + bool is_active() const; |
| 93 | + void update(); |
| 94 | + |
| 95 | + // wlr events |
| 96 | + void handle_id(const std::string &id); |
| 97 | + void handle_name(const std::string &name); |
| 98 | + void handle_coordinates(const std::vector<uint32_t> &coordinates); |
| 99 | + void handle_state(uint32_t state); |
| 100 | + void handle_capabilities(uint32_t capabilities); |
| 101 | + void handle_removed(); |
| 102 | + |
| 103 | + // gdk events |
| 104 | + bool handle_clicked(const GdkEventButton *button) const; |
| 105 | + |
| 106 | + private: |
| 107 | + std::string icon(); |
| 108 | + |
| 109 | + WorkspaceManager &workspace_manager_; |
| 110 | + ext_workspace_handle_v1 *ext_handle_ = nullptr; |
| 111 | + uint32_t id_; |
| 112 | + uint32_t state_ = 0; |
| 113 | + std::string workspace_id_; |
| 114 | + std::string name_; |
| 115 | + std::vector<uint32_t> coordinates_; |
| 116 | + |
| 117 | + std::string format_; |
| 118 | + bool with_icon_ = false; |
| 119 | + static std::map<std::string, std::string> icon_map_; |
| 120 | + std::string on_click_action_; |
| 121 | + std::string on_click_middle_action_; |
| 122 | + std::string on_click_right_action_; |
| 123 | + |
| 124 | + bool dirty_ = false; |
| 125 | + |
| 126 | + Gtk::Button button_; |
| 127 | + Gtk::Box content_; |
| 128 | + Gtk::Label label_; |
170 | 129 | };
|
171 | 130 |
|
172 | 131 | } // namespace waybar::modules::wlr
|
0 commit comments