Skip to content

Commit d7fdf39

Browse files
committed
wlr/workspace: rework implementation
1 parent bb73f4e commit d7fdf39

File tree

3 files changed

+323
-597
lines changed

3 files changed

+323
-597
lines changed

Diff for: include/modules/wlr/workspace_manager.hpp

+97-148
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <gtkmm/image.h>
66
#include <gtkmm/label.h>
77

8-
#include <functional>
98
#include <map>
109
#include <memory>
1110
#include <vector>
@@ -16,168 +15,118 @@
1615

1716
namespace waybar::modules::wlr {
1817

19-
class WorkspaceManager;
2018
class WorkspaceGroup;
19+
class Workspace;
2120

22-
class Workspace {
21+
class WorkspaceManager final : public AModule {
2322
public:
24-
Workspace(const waybar::Bar &bar, const Json::Value &config, WorkspaceManager &workspace_manager,
25-
ext_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_id(const std::string &id) -> void;
37-
auto handle_name(const std::string &name) -> void;
38-
auto handle_coordinates(const std::vector<uint32_t> &coordinates) -> void;
39-
auto handle_state(const uint32_t state) -> void;
40-
auto handle_capabilities(uint32_t capabilities) -> void;
41-
auto handle_remove() -> void;
42-
43-
auto make_persistent() -> void;
44-
45-
auto handle_done() -> void;
46-
auto handle_clicked(GdkEventButton *bt) -> bool;
47-
auto show() -> void;
48-
auto hide() -> void;
49-
auto get_button_ref() -> Gtk::Button & { return button_; }
50-
auto get_workspace_handle() -> ext_workspace_handle_v1 * { return workspace_handle_; }
51-
auto get_name() -> std::string & { return name_; }
52-
auto get_coords() -> std::vector<uint32_t> & { return coordinates_; }
53-
auto set_workspace_group(WorkspaceGroup *group) -> void { workspace_group_ = group; }
54-
55-
enum class State {
56-
ACTIVE = (1 << 0),
57-
URGENT = (1 << 1),
58-
HIDDEN = (1 << 2),
59-
EMPTY = (1 << 3),
60-
};
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);
27+
void set_dirty() { dirty_ = true; }
6128

62-
private:
63-
auto get_icon() -> std::string;
64-
65-
const Bar &bar_;
66-
const Json::Value &config_;
67-
WorkspaceManager &workspace_manager_;
68-
WorkspaceGroup *workspace_group_ = nullptr;
69-
70-
// wlr stuff
71-
ext_workspace_handle_v1 *workspace_handle_;
72-
uint32_t state_ = 0;
73-
74-
uint32_t id_;
75-
std::string name_;
76-
std::vector<uint32_t> coordinates_;
77-
static std::map<std::string, std::string> icons_map_;
78-
std::string format_;
79-
bool with_icon_ = false;
80-
bool persistent_ = false;
81-
82-
Gtk::Button button_;
83-
Gtk::Box content_;
84-
Gtk::Label label_;
85-
};
29+
// wlr events
30+
void handle_workspace_group(ext_workspace_group_handle_v1 *handle);
31+
void handle_workspace(ext_workspace_handle_v1 *handle);
32+
void handle_done();
33+
void handle_finished();
8634

87-
class WorkspaceGroup {
88-
public:
89-
WorkspaceGroup(const waybar::Bar &bar, Gtk::Box &box, const Json::Value &config,
90-
WorkspaceManager &manager, ext_workspace_group_handle_v1 *workspace_group_handle,
91-
uint32_t id);
92-
~WorkspaceGroup();
93-
auto update() -> void;
94-
95-
auto id() const -> uint32_t { return id_; }
96-
auto is_visible() const -> bool;
97-
auto active_only() const -> bool;
98-
auto creation_delayed() const -> bool;
99-
auto workspaces() -> std::vector<Workspace*> & { return workspaces_; }
100-
auto persistent_workspaces() -> std::vector<std::string> & { return persistent_workspaces_; }
101-
102-
auto sort_workspaces() -> void;
103-
auto set_need_to_sort() -> void { need_to_sort = true; }
104-
auto add_button(Gtk::Button &button) -> void;
105-
auto remove_button(Gtk::Button &button) -> void;
106-
auto fill_persistent_workspaces() -> void;
107-
auto create_persistent_workspaces() -> void;
108-
109-
// wlr stuff
110-
auto handle_capabilities(uint32_t capabilities) -> void;
111-
auto handle_workspace_enter(ext_workspace_handle_v1 *workspace_handle) -> void;
112-
auto handle_workspace_leave(ext_workspace_handle_v1 *workspace_handle) -> void;
113-
auto handle_removed() -> void;
114-
auto handle_output_enter(wl_output *output) -> void;
115-
auto handle_output_leave() -> void;
116-
auto handle_done() -> void;
117-
auto commit() -> void;
35+
// wlr requests
36+
void commit() const;
11837

11938
private:
120-
const waybar::Bar &bar_;
121-
Gtk::Box &box_;
122-
const Json::Value &config_;
123-
WorkspaceManager &workspace_manager_;
124-
125-
// wlr stuff
126-
ext_workspace_group_handle_v1 *workspace_group_handle_;
127-
wl_output *output_ = nullptr;
128-
129-
uint32_t id_;
130-
std::vector<Workspace*> workspaces_;
131-
bool need_to_sort = false;
132-
std::vector<std::string> persistent_workspaces_;
133-
bool persistent_created_ = false;
134-
};
39+
void update() override;
40+
bool has_button(const Gtk::Button *button);
13541

136-
class WorkspaceManager : public AModule {
137-
public:
138-
WorkspaceManager(const std::string &id, const waybar::Bar &bar, const Json::Value &config);
139-
~WorkspaceManager() override;
140-
auto update() -> void override;
141-
142-
auto all_outputs() const -> bool { return all_outputs_; }
143-
auto active_only() const -> bool { return active_only_; }
144-
auto workspace_comparator() const
145-
-> std::function<bool(Workspace *, Workspace *)>;
146-
auto creation_delayed() const -> bool { return creation_delayed_; }
147-
148-
auto get_workspace(ext_workspace_handle_v1 *workspace_handle) -> Workspace *;
149-
auto sort_workspaces() -> void;
150-
auto remove_workspace(uint32_t id_) -> void;
151-
auto remove_workspace_group(uint32_t id_) -> void;
152-
153-
// wlr stuff
154-
auto register_manager(wl_registry *registry, uint32_t name, uint32_t version) -> void;
155-
auto handle_workspace_group(ext_workspace_group_handle_v1 *workspace_group_handle)
156-
-> void;
157-
auto handle_workspace(ext_workspace_handle_v1 *workspace_handle)
158-
-> void;
159-
auto handle_done() -> void;
160-
auto handle_finished() -> void;
161-
auto commit() -> void;
42+
static uint32_t group_global_id;
43+
static uint32_t workspace_global_id;
44+
45+
bool sort_by_id_ = false;
46+
bool sort_by_name_ = false;
47+
bool sort_by_coordinates_ = false;
48+
bool active_only_ = false;
49+
bool all_outputs_ = false;
50+
51+
bool dirty_ = false;
16252

163-
private:
16453
const waybar::Bar &bar_;
16554
Gtk::Box box_;
55+
56+
ext_workspace_manager_v1 *ext_manager_ = nullptr;
16657
std::vector<std::unique_ptr<WorkspaceGroup>> groups_;
16758
std::vector<std::unique_ptr<Workspace>> workspaces_;
59+
};
16860

169-
// wlr stuff
170-
ext_workspace_manager_v1 *workspace_manager_ = nullptr;
171-
172-
static uint32_t group_global_id;
173-
static uint32_t workspace_global_id;
61+
class WorkspaceGroup {
62+
public:
63+
WorkspaceGroup(WorkspaceManager &manager, ext_workspace_group_handle_v1 *handle, uint32_t id);
64+
65+
u_int32_t id() const { return id_; }
66+
bool has_output(const wl_output *output);
67+
bool has_workspace(const ext_workspace_handle_v1 *workspace);
68+
69+
// wlr events
70+
void handle_capabilities(uint32_t capabilities);
71+
void handle_output_enter(wl_output *output);
72+
void handle_output_leave(wl_output *output);
73+
void handle_workspace_enter(ext_workspace_handle_v1 *handle);
74+
void handle_workspace_leave(ext_workspace_handle_v1 *handle);
75+
void handle_removed();
76+
77+
private:
78+
WorkspaceManager &workspaces_manager_;
79+
ext_workspace_group_handle_v1 *ext_handle_;
80+
uint32_t id_;
81+
std::vector<wl_output *> outputs_;
82+
std::vector<ext_workspace_handle_v1 *> workspaces_;
83+
};
17484

175-
bool sort_by_name_ = true;
176-
bool sort_by_coordinates_ = true;
177-
bool sort_by_number_ = false;
178-
bool all_outputs_ = false;
179-
bool active_only_ = false;
180-
bool creation_delayed_ = false;
85+
class Workspace {
86+
public:
87+
Workspace(const Json::Value &config, WorkspaceManager &manager, ext_workspace_handle_v1 *handle, uint32_t id);
88+
89+
ext_workspace_handle_v1 * handle() const { return ext_handle_; }
90+
u_int32_t id() const { return id_; }
91+
std::string & workspace_id() { return workspace_id_; }
92+
std::string & name() { return name_; }
93+
std::vector<u_int32_t> & coordinates() { return coordinates_; }
94+
Gtk::Button & button() { return button_; }
95+
bool is_active() const;
96+
void update();
97+
98+
// wlr events
99+
void handle_id(const std::string &id);
100+
void handle_name(const std::string &name);
101+
void handle_coordinates(const std::vector<uint32_t> &coordinates);
102+
void handle_state(uint32_t state);
103+
void handle_capabilities(uint32_t capabilities);
104+
void handle_removed();
105+
106+
// gdk events
107+
bool handle_clicked(const GdkEventButton *button) const;
108+
109+
private:
110+
WorkspaceManager &workspace_manager_;
111+
ext_workspace_handle_v1 *ext_handle_ = nullptr;
112+
uint32_t id_;
113+
uint32_t state_ = 0;
114+
std::string workspace_id_;
115+
std::string name_;
116+
std::vector<uint32_t> coordinates_;
117+
118+
std::string format_;
119+
bool with_icon_ = false;
120+
static std::map<std::string, std::string> icon_map_;
121+
std::string on_click_action_;
122+
std::string on_click_middle_action_;
123+
std::string on_click_right_action_;
124+
125+
bool dirty_ = false;
126+
127+
Gtk::Button button_;
128+
Gtk::Box content_;
129+
Gtk::Label label_;
181130
};
182131

183132
} // namespace waybar::modules::wlr

0 commit comments

Comments
 (0)