Skip to content

Commit 8685e88

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

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

include/modules/dwl/window.hpp

+2
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,7 @@ class Window : public AAppIconLabel, public sigc::trackable {
3031
std::string title_;
3132
std::string appid_;
3233
std::string layout_symbol_;
34+
bool active_;
3335
uint32_t layout_;
3436

3537
struct zdwl_ipc_output_v2 *output_status_;

man/waybar-dwl-window.5.scd

+4
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ If no expression matches, the format output is left unchanged.
109109

110110
Invalid expressions (e.g., mismatched parentheses) are skipped.
111111

112+
# STYLE
113+
114+
- *#window.active*
115+
112116
# EXAMPLES
113117

114118
```

src/modules/dwl/window.cpp

+11-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,9 @@ 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) {
7880
struct wl_display *display = Client::inst()->wl_display;
7981
struct wl_registry *registry = wl_display_get_registry(display);
8082

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

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

107+
void Window::handle_active(const uint32_t active) { active_ = active != 0; }
108+
105109
void Window::handle_layout_symbol(const char *layout_symbol) {
106110
layout_symbol_ = Glib::Markup::escape_text(layout_symbol);
107111
}
@@ -118,6 +122,11 @@ void Window::handle_frame() {
118122
if (tooltipEnabled()) {
119123
label_.set_tooltip_text(title_);
120124
}
125+
if (active_) {
126+
box_.get_style_context()->add_class("active");
127+
} else {
128+
box_.get_style_context()->remove_class("active");
129+
}
121130
}
122131

123132
} // namespace waybar::modules::dwl

0 commit comments

Comments
 (0)