Skip to content

Commit b0e5cd0

Browse files
committed
GTK4: migration Niri
Signed-off-by: Viktar Lukashonak <myxabeer@gmail.com>
1 parent 16afd3f commit b0e5cd0

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

include/modules/niri/workspaces.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Workspaces : public AModule, public EventHandler {
1414
Workspaces(const std::string &, const Bar &, const Json::Value &);
1515
~Workspaces() override;
1616
void update() override;
17+
operator Gtk::Widget &() override;
1718

1819
private:
1920
void onEvent(const Json::Value &ev) override;

meson.build

-2
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ man_files += files('man/waybar-hyprland-language.5.scd',
297297
'man/waybar-hyprland-window.5.scd',
298298
'man/waybar-hyprland-workspaces.5.scd')
299299

300-
if 1 == 0
301300
if get_option('niri')
302301
add_project_arguments('-DHAVE_NIRI', language: 'cpp')
303302
src_files += files(
@@ -312,7 +311,6 @@ man_files += files(
312311
'man/waybar-niri-workspaces.5.scd',
313312
)
314313
endif
315-
endif
316314

317315
if libnl.found() and libnlgen.found()
318316
add_project_arguments('-DHAVE_LIBNL', language: 'cpp')

src/modules/niri/window.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ void Window::update() {
9898
void Window::setClass(const std::string &className, bool enable) {
9999
auto styleContext = bar_.window.get_style_context();
100100
if (enable) {
101-
if (!styleContext->has_class(className)) {
102-
styleContext->add_class(className);
101+
if (!label_.get_style_context()->has_class(className)) {
102+
label_.get_style_context()->add_class(className);
103103
}
104104
} else {
105-
styleContext->remove_class(className);
105+
label_.get_style_context()->remove_class(className);
106106
}
107107
}
108108

src/modules/niri/workspaces.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
1313
box_.get_style_context()->add_class(id);
1414
}
1515
box_.get_style_context()->add_class(MODULE_CLASS);
16-
event_box_.add(box_);
1716

1817
if (!gIPC) gIPC = std::make_unique<IPC>();
1918

@@ -121,7 +120,8 @@ void Workspaces::doUpdate() {
121120
if (alloutputs) pos = it - my_workspaces.cbegin();
122121

123122
auto &button = buttons_[ws["id"].asUInt64()];
124-
box_.reorder_child(button, pos);
123+
const auto sibling{box_.get_children().at(pos - 1)};
124+
if (sibling) box_.reorder_child_after(button, *sibling);
125125
}
126126
}
127127

@@ -130,6 +130,9 @@ void Workspaces::update() {
130130
AModule::update();
131131
}
132132

133+
Workspaces::operator Gtk::Widget &() { return box_; };
134+
135+
133136
Gtk::Button &Workspaces::addButton(const Json::Value &ws) {
134137
std::string name;
135138
if (ws["name"]) {
@@ -140,11 +143,12 @@ Gtk::Button &Workspaces::addButton(const Json::Value &ws) {
140143

141144
auto pair = buttons_.emplace(ws["id"].asUInt64(), name);
142145
auto &&button = pair.first->second;
143-
box_.pack_start(button, false, false, 0);
144-
button.set_relief(Gtk::RELIEF_NONE);
146+
box_.append(button);
147+
button.set_has_frame(false);
145148
if (!config_["disable-click"].asBool()) {
149+
AModule::bindEvents(button);
146150
const auto id = ws["id"].asUInt64();
147-
button.signal_pressed().connect([=] {
151+
controllClick_->signal_pressed().connect([=](int n_press, double dx, double dy) {
148152
try {
149153
// {"Action":{"FocusWorkspace":{"reference":{"Id":1}}}}
150154
Json::Value request(Json::objectValue);

0 commit comments

Comments
 (0)