Skip to content

Commit 6770cdf

Browse files
committed
wlr/workspace: port to ext-workspace-v1
Rework implementation to match new protocol behavior.
1 parent 4a8d527 commit 6770cdf

8 files changed

+430
-924
lines changed

include/modules/wlr/workspace_manager.hpp

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

8-
#include <functional>
98
#include <map>
109
#include <memory>
1110
#include <vector>
1211

1312
#include "AModule.hpp"
1413
#include "bar.hpp"
15-
#include "ext-workspace-unstable-v1-client-protocol.h"
14+
#include "ext-workspace-v1-client-protocol.h"
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, 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);
5727

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();
8133

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;
11236

11337
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);
12340

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;
13043

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;
15349

154-
private:
15550
const waybar::Bar &bar_;
15651
Gtk::Box box_;
157-
std::vector<std::unique_ptr<WorkspaceGroup>> groups_;
15852

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+
};
16157

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+
};
16381

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_;
170129
};
171130

172131
} // namespace waybar::modules::wlr
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#include "ext-workspace-unstable-v1-client-protocol.h"
1+
#include "ext-workspace-v1-client-protocol.h"
22

33
namespace waybar::modules::wlr {
44
void add_registry_listener(void *data);
5-
void add_workspace_listener(zext_workspace_handle_v1 *workspace_handle, void *data);
6-
void add_workspace_group_listener(zext_workspace_group_handle_v1 *workspace_group_handle,
5+
void add_workspace_listener(ext_workspace_handle_v1 *workspace_handle, void *data);
6+
void add_workspace_group_listener(ext_workspace_group_handle_v1 *workspace_group_handle,
77
void *data);
8-
zext_workspace_manager_v1 *workspace_manager_bind(wl_registry *registry, uint32_t name,
8+
ext_workspace_manager_v1 *workspace_manager_bind(wl_registry *registry, uint32_t name,
99
uint32_t version, void *data);
1010
} // namespace waybar::modules::wlr

man/waybar-wlr-workspaces.5.scd

+7-4
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ Addressed by *wlr/workspaces*
2828

2929
*sort-by-coordinates*: ++
3030
typeof: bool ++
31-
default: true ++
31+
default: false ++
3232
Should workspaces be sorted by coordinates. ++
3333
Note that if both *sort-by-name* and *sort-by-coordinates* are true sort-by name will be first. If both are false - sort by id will be performed.
3434

35-
*sort-by-number*: ++
35+
*sort-by-id*: ++
3636
typeof: bool ++
3737
default: false ++
3838
If set to true, workspace names will be sorted numerically. Takes precedence over any other sort-by option.
@@ -49,7 +49,9 @@ Addressed by *wlr/workspaces*
4949

5050
# FORMAT REPLACEMENTS
5151

52-
*{name}*: Name of workspace assigned by compositor
52+
*{name}*: Name of workspace assigned by compositor.
53+
54+
*{id}*: ID of workspace assigned by compositor.
5355

5456
*{icon}*: Icon, as defined in *format-icons*.
5557

@@ -71,6 +73,7 @@ In addition to workspace name matching, the following *format-icons* can be set.
7173
```
7274
"wlr/workspaces": {
7375
"format": "{name}: {icon}",
76+
"on-click": "activate",
7477
"format-icons": {
7578
"1": "",
7679
"2": "",
@@ -80,7 +83,7 @@ In addition to workspace name matching, the following *format-icons* can be set.
8083
"active": "",
8184
"default": ""
8285
},
83-
"sort-by-number": true
86+
"sort-by-id": true
8487
}
8588
```
8689

meson.build

+11-11
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,17 @@ if true
275275
man_files += files('man/waybar-wlr-taskbar.5.scd')
276276
endif
277277

278+
if dependency('wayland-protocols', version : ['>=1.39']).found()
279+
add_project_arguments('-DHAVE_WLR_WORKSPACES', language: 'cpp')
280+
src_files += files(
281+
'src/modules/wlr/workspace_manager.cpp',
282+
'src/modules/wlr/workspace_manager_binding.cpp',
283+
)
284+
man_files += files(
285+
'man/waybar-wlr-workspaces.5.scd',
286+
)
287+
endif
288+
278289
if true
279290
add_project_arguments('-DHAVE_RIVER', language: 'cpp')
280291
src_files += files(
@@ -474,17 +485,6 @@ else
474485
man_files += files('man/waybar-clock.5.scd')
475486
endif
476487

477-
if get_option('experimental')
478-
add_project_arguments('-DHAVE_WLR_WORKSPACES', language: 'cpp')
479-
src_files += files(
480-
'src/modules/wlr/workspace_manager.cpp',
481-
'src/modules/wlr/workspace_manager_binding.cpp',
482-
)
483-
man_files += files(
484-
'man/waybar-wlr-workspaces.5.scd',
485-
)
486-
endif
487-
488488
cava = dependency('cava',
489489
version : '>=0.10.3',
490490
required: get_option('cava'),

0 commit comments

Comments
 (0)