From 5719d130fdab6d5cc7b4923097c8df7224bfa441 Mon Sep 17 00:00:00 2001
From: patrick96
Date: Sun, 2 Oct 2022 12:13:32 +0200
Subject: [PATCH] feat(xwindow): %instance%, %class% from WM_CLASS
---
CHANGELOG.md | 1 +
include/modules/xwindow.hpp | 12 ++++++++----
include/x11/atoms.hpp | 3 ++-
include/x11/icccm.hpp | 3 ++-
src/modules/xwindow.cpp | 38 +++++++++++++++++++++++++------------
src/x11/atoms.cpp | 4 +++-
src/x11/icccm.cpp | 10 ++++++++++
7 files changed, 52 insertions(+), 19 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5136ae1c..1c05fc5b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added experimental support for positioning the tray like a module
- `internal/backlight`: `scroll-interval` option ([`#2696`](https://github.com/polybar/polybar/issues/2696), [`#2700`](https://github.com/polybar/polybar/pull/2700))
- `internal/temperature`: Added `zone-type` setting ([`#2572`](https://github.com/polybar/polybar/issues/2572), [`#2752`](https://github.com/polybar/polybar/pull/2752)) by [@xphoniex](https://github.com/xphoniex)
+- `internal/xwindow`: `%class%` and `%instance%` tokens, which show the contents of the `WM_CLASS` property of the active window ([`#2830`](https://github.com/polybar/polybar/pull/2830))
### Changed
- `internal/fs`: Use `/` as a fallback if no mountpoints are specified ([`#2572`](https://github.com/polybar/polybar/issues/2572), [`#2705`](https://github.com/polybar/polybar/pull/2705))
diff --git a/include/modules/xwindow.hpp b/include/modules/xwindow.hpp
index 80c45e44..8b447031 100644
--- a/include/modules/xwindow.hpp
+++ b/include/modules/xwindow.hpp
@@ -11,13 +11,15 @@ POLYBAR_NS
class connection;
namespace modules {
- class active_window {
+ class active_window : public non_copyable_mixin, public non_movable_mixin {
public:
explicit active_window(xcb_connection_t* conn, xcb_window_t win);
~active_window();
- bool match(const xcb_window_t win) const;
+ bool match(xcb_window_t win) const;
string title() const;
+ string instance_name() const;
+ string class_name() const;
private:
xcb_connection_t* m_connection{nullptr};
@@ -33,7 +35,7 @@ namespace modules {
enum class state { NONE, ACTIVE, EMPTY };
explicit xwindow_module(const bar_settings&, string);
- void update(bool force = false);
+ void update();
bool build(builder* builder, const string& tag) const;
static constexpr auto TYPE = "internal/xwindow";
@@ -41,6 +43,8 @@ namespace modules {
protected:
void handle(const evt::property_notify& evt) override;
+ void reset_active_window();
+
private:
static constexpr const char* TAG_LABEL{"