From 0d2838fcd59c6c04aa2b36e45dcb558e86e23947 Mon Sep 17 00:00:00 2001 From: Nolan Prochnau Date: Sat, 19 Dec 2020 12:22:27 -0500 Subject: [PATCH] feat(xkeyboard): Add variant support to layout label (#2163) * Add variant support to xkeyboard layout label Solves #316 * Run style checks, I guess? * Add comment * Return nothing if there is no variant * Update CHANGELOG --- CHANGELOG.md | 2 ++ include/x11/extensions/xkb.hpp | 11 +++++++---- src/modules/xkeyboard.cpp | 17 ++++++++--------- src/x11/extensions/xkb.cpp | 17 ++++++++++++++++- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c50feeb9..e5a5abab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([`#2294`](https://github.com/polybar/polybar/issues/2294)) - `internal/network`: `speed-unit = B/s` can be used to customize how network speeds are displayed. +- `internal/xkeyboard`: `%variant%` can be used to parse the layout variant + ([`#316`](https://github.com/polybar/polybar/issues/316)) ### Changed - Slight changes to the value ranges the different ramp levels are responsible diff --git a/include/x11/extensions/xkb.hpp b/include/x11/extensions/xkb.hpp index 06f7f1ff..603882a9 100644 --- a/include/x11/extensions/xkb.hpp +++ b/include/x11/extensions/xkb.hpp @@ -44,7 +44,7 @@ namespace evt { using xkb_action_message = xpp::xkb::event::action_message; using xkb_access_x_notify = xpp::xkb::event::access_x_notify; using xkb_extension_device_notify = xpp::xkb::event::extension_device_notify; -} +} // namespace evt class keyboard { public: @@ -62,15 +62,18 @@ class keyboard { }; explicit keyboard(vector&& layouts_, map&& indicators_, unsigned char group) - : layouts(forward(layouts_)), indicators(forward(indicators_)), current_group(group) {} + : layouts(forward(layouts_)) + , indicators(forward(indicators_)) + , current_group(group) {} const indicator& get(const indicator::type& i) const; void set(unsigned int state); bool on(const indicator::type&) const; - void current(unsigned char group); + void current(unsigned char group); unsigned char current() const; const string group_name(size_t index = 0) const; const string layout_name(size_t index = 0) const; + const string variant_name(size_t index = 0) const; const string indicator_name(const indicator::type&) const; size_t size() const; @@ -90,6 +93,6 @@ namespace xkb_util { vector get_layouts(connection& conn, xcb_xkb_device_spec_t device); map get_indicators(connection& conn, xcb_xkb_device_spec_t device); string parse_layout_symbol(string&& name); -} +} // namespace xkb_util POLYBAR_NS_END diff --git a/src/modules/xkeyboard.cpp b/src/modules/xkeyboard.cpp index ebfa9a74..0d160333 100644 --- a/src/modules/xkeyboard.cpp +++ b/src/modules/xkeyboard.cpp @@ -1,12 +1,12 @@ #include "modules/xkeyboard.hpp" + #include "drawtypes/iconset.hpp" #include "drawtypes/label.hpp" +#include "modules/meta/base.inl" #include "utils/factory.hpp" #include "x11/atoms.hpp" #include "x11/connection.hpp" -#include "modules/meta/base.inl" - POLYBAR_NS namespace modules { @@ -25,8 +25,6 @@ namespace modules { */ xkeyboard_module::xkeyboard_module(const bar_settings& bar, string name_) : static_module(bar, move(name_)), m_connection(connection::make()) { - - // Setup extension // clang-format off m_connection.xkb().select_events_checked(XCB_XKB_ID_USE_CORE_KBD, @@ -81,7 +79,7 @@ namespace modules { m_indicator_icons_on = factory_util::shared(); auto icon_pair = string_util::tokenize(m_conf.get(name(), DEFAULT_INDICATOR_ICON, ""s), ';'); - if(icon_pair.size() == 2) { + if (icon_pair.size() == 2) { m_indicator_icons_off->add(DEFAULT_INDICATOR_ICON, factory_util::shared