feat(xwindow): %instance%, %class% from WM_CLASS
This commit is contained in:
parent
c44336573b
commit
5719d130fd
@ -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
|
- 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/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/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
|
### 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))
|
- `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))
|
||||||
|
@ -11,13 +11,15 @@ POLYBAR_NS
|
|||||||
class connection;
|
class connection;
|
||||||
|
|
||||||
namespace modules {
|
namespace modules {
|
||||||
class active_window {
|
class active_window : public non_copyable_mixin, public non_movable_mixin {
|
||||||
public:
|
public:
|
||||||
explicit active_window(xcb_connection_t* conn, xcb_window_t win);
|
explicit active_window(xcb_connection_t* conn, xcb_window_t win);
|
||||||
~active_window();
|
~active_window();
|
||||||
|
|
||||||
bool match(const xcb_window_t win) const;
|
bool match(xcb_window_t win) const;
|
||||||
string title() const;
|
string title() const;
|
||||||
|
string instance_name() const;
|
||||||
|
string class_name() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
xcb_connection_t* m_connection{nullptr};
|
xcb_connection_t* m_connection{nullptr};
|
||||||
@ -33,7 +35,7 @@ namespace modules {
|
|||||||
enum class state { NONE, ACTIVE, EMPTY };
|
enum class state { NONE, ACTIVE, EMPTY };
|
||||||
explicit xwindow_module(const bar_settings&, string);
|
explicit xwindow_module(const bar_settings&, string);
|
||||||
|
|
||||||
void update(bool force = false);
|
void update();
|
||||||
bool build(builder* builder, const string& tag) const;
|
bool build(builder* builder, const string& tag) const;
|
||||||
|
|
||||||
static constexpr auto TYPE = "internal/xwindow";
|
static constexpr auto TYPE = "internal/xwindow";
|
||||||
@ -41,6 +43,8 @@ namespace modules {
|
|||||||
protected:
|
protected:
|
||||||
void handle(const evt::property_notify& evt) override;
|
void handle(const evt::property_notify& evt) override;
|
||||||
|
|
||||||
|
void reset_active_window();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr const char* TAG_LABEL{"<label>"};
|
static constexpr const char* TAG_LABEL{"<label>"};
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ struct cached_atom {
|
|||||||
xcb_atom_t& atom;
|
xcb_atom_t& atom;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern std::array<cached_atom, 37> ATOMS;
|
extern std::array<cached_atom, 38> ATOMS;
|
||||||
|
|
||||||
extern xcb_atom_t _NET_SUPPORTED;
|
extern xcb_atom_t _NET_SUPPORTED;
|
||||||
extern xcb_atom_t _NET_CURRENT_DESKTOP;
|
extern xcb_atom_t _NET_CURRENT_DESKTOP;
|
||||||
@ -49,3 +49,4 @@ extern xcb_atom_t _COMPTON_SHADOW;
|
|||||||
extern xcb_atom_t _NET_WM_WINDOW_OPACITY;
|
extern xcb_atom_t _NET_WM_WINDOW_OPACITY;
|
||||||
extern xcb_atom_t WM_HINTS;
|
extern xcb_atom_t WM_HINTS;
|
||||||
extern xcb_atom_t WM_NAME;
|
extern xcb_atom_t WM_NAME;
|
||||||
|
extern xcb_atom_t WM_CLASS;
|
||||||
|
@ -8,6 +8,7 @@ POLYBAR_NS
|
|||||||
|
|
||||||
namespace icccm_util {
|
namespace icccm_util {
|
||||||
string get_wm_name(xcb_connection_t* c, xcb_window_t w);
|
string get_wm_name(xcb_connection_t* c, xcb_window_t w);
|
||||||
|
pair<string, string> get_wm_class(xcb_connection_t* c, xcb_window_t w);
|
||||||
string get_reply_string(xcb_icccm_get_text_property_reply_t* reply);
|
string get_reply_string(xcb_icccm_get_text_property_reply_t* reply);
|
||||||
|
|
||||||
void set_wm_name(xcb_connection_t* c, xcb_window_t w, const char* wmname, size_t l, const char* wmclass, size_t l2);
|
void set_wm_name(xcb_connection_t* c, xcb_window_t w, const char* wmname, size_t l, const char* wmclass, size_t l2);
|
||||||
@ -15,6 +16,6 @@ namespace icccm_util {
|
|||||||
bool get_wm_urgency(xcb_connection_t* c, xcb_window_t w);
|
bool get_wm_urgency(xcb_connection_t* c, xcb_window_t w);
|
||||||
|
|
||||||
void set_wm_size_hints(xcb_connection_t* c, xcb_window_t w, int x, int y, int width, int height);
|
void set_wm_size_hints(xcb_connection_t* c, xcb_window_t w, int x, int y, int width, int height);
|
||||||
}
|
} // namespace icccm_util
|
||||||
|
|
||||||
POLYBAR_NS_END
|
POLYBAR_NS_END
|
||||||
|
@ -58,6 +58,14 @@ namespace modules {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string active_window::instance_name() const {
|
||||||
|
return icccm_util::get_wm_class(m_connection, m_window).first;
|
||||||
|
}
|
||||||
|
|
||||||
|
string active_window::class_name() const {
|
||||||
|
return icccm_util::get_wm_class(m_connection, m_window).second;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct module
|
* Construct module
|
||||||
*/
|
*/
|
||||||
@ -85,10 +93,13 @@ namespace modules {
|
|||||||
*/
|
*/
|
||||||
void xwindow_module::handle(const evt::property_notify& evt) {
|
void xwindow_module::handle(const evt::property_notify& evt) {
|
||||||
if (evt->atom == _NET_ACTIVE_WINDOW) {
|
if (evt->atom == _NET_ACTIVE_WINDOW) {
|
||||||
update(true);
|
reset_active_window();
|
||||||
|
update();
|
||||||
} else if (evt->atom == _NET_CURRENT_DESKTOP) {
|
} else if (evt->atom == _NET_CURRENT_DESKTOP) {
|
||||||
update(true);
|
reset_active_window();
|
||||||
} else if (evt->atom == _NET_WM_NAME || evt->atom == _NET_WM_VISIBLE_NAME || evt->atom == WM_NAME) {
|
update();
|
||||||
|
} else if (evt->atom == _NET_WM_NAME || evt->atom == _NET_WM_VISIBLE_NAME || evt->atom == WM_NAME ||
|
||||||
|
evt->atom == WM_CLASS) {
|
||||||
update();
|
update();
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -97,24 +108,27 @@ namespace modules {
|
|||||||
broadcast();
|
broadcast();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
void xwindow_module::reset_active_window() {
|
||||||
* Update the currently active window and query its title
|
|
||||||
*/
|
|
||||||
void xwindow_module::update(bool force) {
|
|
||||||
xcb_window_t win;
|
|
||||||
|
|
||||||
if (force) {
|
|
||||||
m_active.reset();
|
m_active.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_active && (win = ewmh_util::get_active_window()) != XCB_NONE) {
|
/**
|
||||||
|
* Update the currently active window and query its title
|
||||||
|
*/
|
||||||
|
void xwindow_module::update() {
|
||||||
|
if (!m_active) {
|
||||||
|
xcb_window_t win = ewmh_util::get_active_window();
|
||||||
|
if (win != XCB_NONE) {
|
||||||
m_active = make_unique<active_window>(m_connection, win);
|
m_active = make_unique<active_window>(m_connection, win);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (m_active) {
|
if (m_active) {
|
||||||
m_label = m_statelabels.at(state::ACTIVE)->clone();
|
m_label = m_statelabels.at(state::ACTIVE)->clone();
|
||||||
m_label->reset_tokens();
|
m_label->reset_tokens();
|
||||||
m_label->replace_token("%title%", m_active->title());
|
m_label->replace_token("%title%", m_active->title());
|
||||||
|
m_label->replace_token("%instance%", m_active->instance_name());
|
||||||
|
m_label->replace_token("%class%", m_active->class_name());
|
||||||
} else {
|
} else {
|
||||||
m_label = m_statelabels.at(state::EMPTY)->clone();
|
m_label = m_statelabels.at(state::EMPTY)->clone();
|
||||||
}
|
}
|
||||||
|
@ -40,9 +40,10 @@ xcb_atom_t _COMPTON_SHADOW;
|
|||||||
xcb_atom_t _NET_WM_WINDOW_OPACITY;
|
xcb_atom_t _NET_WM_WINDOW_OPACITY;
|
||||||
xcb_atom_t WM_HINTS;
|
xcb_atom_t WM_HINTS;
|
||||||
xcb_atom_t WM_NAME;
|
xcb_atom_t WM_NAME;
|
||||||
|
xcb_atom_t WM_CLASS;
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
std::array<cached_atom, 37> ATOMS = {{
|
std::array<cached_atom, 38> ATOMS = {{
|
||||||
{"_NET_SUPPORTED", _NET_SUPPORTED},
|
{"_NET_SUPPORTED", _NET_SUPPORTED},
|
||||||
{"_NET_CURRENT_DESKTOP", _NET_CURRENT_DESKTOP},
|
{"_NET_CURRENT_DESKTOP", _NET_CURRENT_DESKTOP},
|
||||||
{"_NET_ACTIVE_WINDOW", _NET_ACTIVE_WINDOW},
|
{"_NET_ACTIVE_WINDOW", _NET_ACTIVE_WINDOW},
|
||||||
@ -80,5 +81,6 @@ std::array<cached_atom, 37> ATOMS = {{
|
|||||||
{"_NET_WM_WINDOW_OPACITY", _NET_WM_WINDOW_OPACITY},
|
{"_NET_WM_WINDOW_OPACITY", _NET_WM_WINDOW_OPACITY},
|
||||||
{"WM_HINTS", WM_HINTS},
|
{"WM_HINTS", WM_HINTS},
|
||||||
{"WM_NAME", WM_NAME},
|
{"WM_NAME", WM_NAME},
|
||||||
|
{"WM_CLASS", WM_CLASS},
|
||||||
}};
|
}};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
@ -13,6 +13,16 @@ namespace icccm_util {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pair<string, string> get_wm_class(xcb_connection_t* c, xcb_window_t w) {
|
||||||
|
pair<string, string> result{"", ""};
|
||||||
|
xcb_icccm_get_wm_class_reply_t reply{};
|
||||||
|
if (xcb_icccm_get_wm_class_reply(c, xcb_icccm_get_wm_class(c, w), &reply, nullptr)) {
|
||||||
|
result = {string(reply.instance_name), string(reply.class_name)};
|
||||||
|
xcb_icccm_get_wm_class_reply_wipe(&reply);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
string get_reply_string(xcb_icccm_get_text_property_reply_t* reply) {
|
string get_reply_string(xcb_icccm_get_text_property_reply_t* reply) {
|
||||||
string str;
|
string str;
|
||||||
if (reply) {
|
if (reply) {
|
||||||
|
Loading…
Reference in New Issue
Block a user