#pragma once #include "config.hpp" #if not WITH_XKB #error "X xkb extension is disabled..." #endif #if defined(__clang__) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunknown-pragmas" #pragma clang diagnostic ignored "-Wreserved-id-macro" #pragma clang diagnostic ignored "-Wkeyword-macro" #endif #define explicit mask_cxx_explicit_keyword #include #include #undef explicit #if defined(__clang__) #pragma clang diagnostic pop #endif #include "common.hpp" POLYBAR_NS // fwd class connection; namespace evt { using xkb_new_keyboard_notify = xpp::xkb::event::new_keyboard_notify; using xkb_map_notify = xpp::xkb::event::map_notify; using xkb_state_notify = xpp::xkb::event::state_notify; using xkb_controls_notify = xpp::xkb::event::controls_notify; using xkb_indicator_state_notify = xpp::xkb::event::indicator_state_notify; using xkb_indicator_map_notify = xpp::xkb::event::indicator_map_notify; using xkb_names_notify = xpp::xkb::event::names_notify; using xkb_compat_map_notify = xpp::xkb::event::compat_map_notify; using xkb_bell_notify = xpp::xkb::event::bell_notify; 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; } class keyboard { public: struct indicator { enum class type { NONE = 0U, CAPS_LOCK, NUM_LOCK }; xcb_atom_t atom{}; uint8_t mask{0}; string name; bool enabled{false}; }; struct layout { string group_name; vector symbols; }; explicit keyboard(vector&& layouts_, map&& indicators_) : layouts(forward(layouts_)), indicators(forward(indicators_)) {} const indicator& get(const indicator::type& i) const; void set(uint32_t state); bool on(const indicator::type&) const; const string group_name(size_t index = 0) const; const string layout_name(size_t index = 0) const; const string indicator_name(const indicator::type&) const; private: vector layouts; map indicators; }; namespace xkb_util { static constexpr const char* LAYOUT_SYMBOL_BLACKLIST{";group;inet;pc;"}; string parse_layout_symbol(string&& name); vector get_layouts(connection& conn, xcb_xkb_device_spec_t device); map get_indicators(connection& conn, xcb_xkb_device_spec_t device); } POLYBAR_NS_END