Skip to content

Commit 494f2bf

Browse files
committed
dwl/window: add .active styling class for active windows
1 parent c32d5e3 commit 494f2bf

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

include/modules/dwl/window.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Window : public AAppIconLabel, public sigc::trackable {
1919
void handle_layout(const uint32_t layout);
2020
void handle_title(const char *title);
2121
void handle_appid(const char *ppid);
22+
void handle_active(const uint32_t active);
2223
void handle_layout_symbol(const char *layout_symbol);
2324
void handle_frame();
2425

@@ -30,6 +31,9 @@ class Window : public AAppIconLabel, public sigc::trackable {
3031
std::string title_;
3132
std::string appid_;
3233
std::string layout_symbol_;
34+
bool active_;
35+
bool hide_inactive_;
36+
bool hide_empty_;
3337
uint32_t layout_;
3438

3539
struct zdwl_ipc_output_v2 *output_status_;

man/waybar-dwl-window.5.scd

+14
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ Addressed by *dwl/window*
1717
default: {title} ++
1818
The format, how information should be displayed.
1919

20+
*hide-empty*: ++
21+
typeof: bool ++
22+
default: false ++
23+
Option to hide the module when the content would be empty.
24+
25+
*hide-inactive*: ++
26+
typeof: bool ++
27+
default: false ++
28+
Option to hide the module when the window is unfocused.
29+
2030
*rotate*: ++
2131
typeof: integer ++
2232
Positive value to rotate the text label (in 90 degree increments).
@@ -109,6 +119,10 @@ If no expression matches, the format output is left unchanged.
109119

110120
Invalid expressions (e.g., mismatched parentheses) are skipped.
111121

122+
# STYLE
123+
124+
- *#window.active*
125+
112126
# EXAMPLES
113127

114128
```

src/modules/dwl/window.cpp

+27-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static void toggle_visibility(void *data, zdwl_ipc_output_v2 *zdwl_output_v2) {
1919
}
2020

2121
static void active(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, uint32_t active) {
22-
// Intentionally empty
22+
static_cast<Window *>(data)->handle_active(active);
2323
}
2424

2525
static void set_tag(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, uint32_t tag, uint32_t state,
@@ -74,7 +74,17 @@ static const wl_registry_listener registry_listener_impl = {.global = handle_glo
7474
.global_remove = handle_global_remove};
7575

7676
Window::Window(const std::string &id, const Bar &bar, const Json::Value &config)
77-
: AAppIconLabel(config, "window", id, "{}", 0, true), bar_(bar) {
77+
: AAppIconLabel(config, "window", id, "{}", 0, true),
78+
bar_(bar),
79+
active_(false),
80+
hide_inactive_(false),
81+
hide_empty_(false) {
82+
if (config_["hide-inactive"].isBool()) {
83+
hide_inactive_ = config["hide-inactive"].asBool();
84+
}
85+
if (config_["hide-empty"].isBool()) {
86+
hide_empty_ = config["hide-empty"].asBool();
87+
}
7888
struct wl_display *display = Client::inst()->wl_display;
7989
struct wl_registry *registry = wl_display_get_registry(display);
8090

@@ -102,6 +112,8 @@ void Window::handle_title(const char *title) { title_ = Glib::Markup::escape_tex
102112

103113
void Window::handle_appid(const char *appid) { appid_ = Glib::Markup::escape_text(appid); }
104114

115+
void Window::handle_active(const uint32_t active) { active_ = active != 0; }
116+
105117
void Window::handle_layout_symbol(const char *layout_symbol) {
106118
layout_symbol_ = Glib::Markup::escape_text(layout_symbol);
107119
}
@@ -118,6 +130,19 @@ void Window::handle_frame() {
118130
if (tooltipEnabled()) {
119131
label_.set_tooltip_text(title_);
120132
}
133+
if (hide_empty_ && title_ == "") {
134+
box_.set_visible(false);
135+
} else {
136+
if (active_) {
137+
box_.get_style_context()->add_class("active");
138+
box_.set_visible(true);
139+
} else {
140+
box_.get_style_context()->remove_class("active");
141+
if (hide_inactive_) {
142+
box_.set_visible(false);
143+
}
144+
}
145+
}
121146
}
122147

123148
} // namespace waybar::modules::dwl

0 commit comments

Comments
 (0)