Fix some bugs
Some checks failed
clang-format / lint (push) Has been cancelled
freebsd / build (push) Has been cancelled
linux / build (c++20, alpine) (push) Has been cancelled
linux / build (c++20, archlinux) (push) Has been cancelled
linux / build (c++20, debian) (push) Has been cancelled
linux / build (c++20, fedora) (push) Has been cancelled
linux / build (c++20, gentoo) (push) Has been cancelled
linux / build (c++20, opensuse) (push) Has been cancelled
Nix-Tests / nix-flake-check (push) Has been cancelled

This commit is contained in:
2025-10-09 23:02:31 -07:00
parent 3db4d5b788
commit cb6bc2f261
5 changed files with 35 additions and 19 deletions

View File

@ -30,6 +30,9 @@ class Tags : public waybar::AModule {
struct zriver_control_v1 *control_;
struct zriver_seat_status_v1 *seat_status_;
struct wl_seat *seat_;
// used to make sure the focused view tags are on the correct output
const wl_output *output_;
const wl_output *focused_output_;
private:
const waybar::Bar &bar_;

View File

@ -3,6 +3,8 @@
#include <gtkmm/button.h>
#include <wayland-client.h>
#include <optional>
#include "ALabel.hpp"
#include "bar.hpp"
#include "river-status-unstable-v1-client-protocol.h"
@ -25,8 +27,9 @@ class Window : public waybar::ALabel {
private:
const waybar::Bar &bar_;
struct wl_output *output_; // stores the output this module belongs to
struct wl_output *focused_output_; // stores the currently focused output
std::optional<std::string> default_format_; // format when there is no window
struct wl_output *output_; // stores the output this module belongs to
struct wl_output *focused_output_; // stores the currently focused output
struct zriver_seat_status_v1 *seat_status_;
};

View File

@ -17,6 +17,10 @@ Addressed by *river/window*
default: {} ++
The format, how information should be displayed. On {} data gets inserted.
*default-format*: ++
typeof: string ++
A string to be show if no window is focused. No formatting is done but markup is supported.
*rotate*: ++
typeof: integer ++
Positive value to rotate the text label (in 90 degree increments).

View File

@ -64,22 +64,21 @@ static const zriver_command_callback_v1_listener command_callback_listener_impl{
static void listen_focused_output(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1,
struct wl_output *output) {
// Intentionally empty
static_cast<Tags *>(data)->focused_output_ = output;
}
static void listen_unfocused_output(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1,
struct wl_output *output) {
// Intentionally empty
}
struct wl_output *output) {}
static void listen_focused_view(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1,
const char *title, uint32_t tags) {
static_cast<Tags *>(data)->handle_focused_view(title, tags);
static_cast<Tags *>(data)->AModule::update();
}
static void listen_mode(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1,
const char *mode) {
// Intentionally empty
static_cast<Tags *>(data)->AModule::update();
}
static const zriver_seat_status_v1_listener seat_status_listener_impl{
@ -125,6 +124,8 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con
status_manager_{nullptr},
control_{nullptr},
seat_{nullptr},
output_{nullptr},
focused_output_{nullptr},
bar_(bar),
box_{bar.orientation, 0},
output_status_{nullptr} {
@ -149,6 +150,8 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con
seat_status_ = zriver_status_manager_v1_get_river_seat_status(status_manager_, seat_);
zriver_seat_status_v1_add_listener(seat_status_, &seat_status_listener_impl, this);
output_ = gdk_wayland_monitor_get_wl_output(bar_.output->monitor->gobj());
box_.set_name("tags");
if (!id.empty()) {
box_.get_style_context()->add_class(id);
@ -317,20 +320,10 @@ void Tags::handle_urgent_tags(uint32_t tags) {
}
void Tags::handle_focused_view(const char *title, uint32_t tags) {
auto hide_vacant = config_["hide-vacant"].asBool();
for (size_t i = 0; i < buttons_.size(); ++i) {
bool visible = buttons_[i].is_visible();
bool occupied = buttons_[i].get_style_context()->has_class("occupied");
bool focused = buttons_[i].get_style_context()->has_class("focused");
if ((1 << i) & tags) {
if (hide_vacant && !visible) {
buttons_[i].set_visible(true);
}
if ((1 << i) & tags && output_ == focused_output_) {
buttons_[i].get_style_context()->add_class("current-view");
} else {
if (hide_vacant && !(occupied || focused)) {
buttons_[i].set_visible(false);
}
buttons_[i].get_style_context()->remove_class("current-view");
}
}

View File

@ -65,6 +65,10 @@ Window::Window(const std::string &id, const waybar::Bar &bar, const Json::Value
seat_{nullptr},
bar_(bar),
seat_status_{nullptr} {
if (config_["default-format"].isString()) {
default_format_ = config_["default-format"].asString();
}
struct wl_display *display = Client::inst()->wl_display;
struct wl_registry *registry = wl_display_get_registry(display);
wl_registry_add_listener(registry, &registry_listener_impl, this);
@ -104,7 +108,16 @@ void Window::handle_focused_view(const char *title, uint32_t tags) {
if (focused_output_ != output_) return;
if (std::strcmp(title, "") == 0 || format_.empty()) {
label_.hide(); // hide empty labels or labels with empty format
if (default_format_.has_value()) {
label_.show();
const std::string &default_format = default_format_.value();
label_.set_markup(default_format);
if (tooltipEnabled()) {
label_.set_tooltip_markup(default_format);
}
} else {
label_.hide(); // hide empty labels or labels with empty format
}
} else {
label_.show();
auto text = fmt::format(fmt::runtime(format_), Glib::Markup::escape_text(title).raw());