Skip to content

Commit

Permalink
GTK4: migration Niri
Browse files Browse the repository at this point in the history
Signed-off-by: Viktar Lukashonak <myxabeer@gmail.com>
  • Loading branch information
LukashonakV committed Nov 1, 2024
1 parent 16afd3f commit b0e5cd0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions include/modules/niri/workspaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Workspaces : public AModule, public EventHandler {
Workspaces(const std::string &, const Bar &, const Json::Value &);
~Workspaces() override;
void update() override;
operator Gtk::Widget &() override;

private:
void onEvent(const Json::Value &ev) override;
Expand Down
2 changes: 0 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ man_files += files('man/waybar-hyprland-language.5.scd',
'man/waybar-hyprland-window.5.scd',
'man/waybar-hyprland-workspaces.5.scd')

if 1 == 0
if get_option('niri')
add_project_arguments('-DHAVE_NIRI', language: 'cpp')
src_files += files(
Expand All @@ -312,7 +311,6 @@ man_files += files(
'man/waybar-niri-workspaces.5.scd',
)
endif
endif

if libnl.found() and libnlgen.found()
add_project_arguments('-DHAVE_LIBNL', language: 'cpp')
Expand Down
6 changes: 3 additions & 3 deletions src/modules/niri/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ void Window::update() {
void Window::setClass(const std::string &className, bool enable) {
auto styleContext = bar_.window.get_style_context();
if (enable) {
if (!styleContext->has_class(className)) {
styleContext->add_class(className);
if (!label_.get_style_context()->has_class(className)) {
label_.get_style_context()->add_class(className);
}
} else {
styleContext->remove_class(className);
label_.get_style_context()->remove_class(className);
}
}

Expand Down
14 changes: 9 additions & 5 deletions src/modules/niri/workspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
box_.get_style_context()->add_class(id);
}
box_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(box_);

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

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

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

Expand All @@ -130,6 +130,9 @@ void Workspaces::update() {
AModule::update();
}

Workspaces::operator Gtk::Widget &() { return box_; };


Gtk::Button &Workspaces::addButton(const Json::Value &ws) {
std::string name;
if (ws["name"]) {
Expand All @@ -140,11 +143,12 @@ Gtk::Button &Workspaces::addButton(const Json::Value &ws) {

auto pair = buttons_.emplace(ws["id"].asUInt64(), name);
auto &&button = pair.first->second;
box_.pack_start(button, false, false, 0);
button.set_relief(Gtk::RELIEF_NONE);
box_.append(button);
button.set_has_frame(false);
if (!config_["disable-click"].asBool()) {
AModule::bindEvents(button);
const auto id = ws["id"].asUInt64();
button.signal_pressed().connect([=] {
controllClick_->signal_pressed().connect([=](int n_press, double dx, double dy) {
try {
// {"Action":{"FocusWorkspace":{"reference":{"Id":1}}}}
Json::Value request(Json::objectValue);
Expand Down

0 comments on commit b0e5cd0

Please sign in to comment.