2016-11-30 09:06:16 +00:00
|
|
|
#pragma once
|
|
|
|
|
2016-12-05 19:41:00 +00:00
|
|
|
#include <map>
|
|
|
|
|
2017-01-11 02:07:28 +00:00
|
|
|
#include "settings.hpp"
|
2016-11-30 09:06:16 +00:00
|
|
|
|
2016-11-30 11:46:26 +00:00
|
|
|
#if not WITH_XKB
|
2016-11-30 09:06:16 +00:00
|
|
|
#error "X xkb extension is disabled..."
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__clang__)
|
|
|
|
#pragma clang diagnostic push
|
2016-12-01 12:11:55 +00:00
|
|
|
#pragma clang diagnostic ignored "-Wunknown-pragmas"
|
|
|
|
#pragma clang diagnostic ignored "-Wreserved-id-macro"
|
2016-11-30 09:06:16 +00:00
|
|
|
#pragma clang diagnostic ignored "-Wkeyword-macro"
|
|
|
|
#endif
|
|
|
|
#define explicit mask_cxx_explicit_keyword
|
|
|
|
#include <xcb/xkb.h>
|
|
|
|
#undef explicit
|
2016-12-26 08:40:15 +00:00
|
|
|
#include <xpp/proto/xkb.hpp>
|
2016-11-30 09:06:16 +00:00
|
|
|
#if defined(__clang__)
|
|
|
|
#pragma clang diagnostic pop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "common.hpp"
|
|
|
|
|
|
|
|
POLYBAR_NS
|
|
|
|
|
2016-12-05 19:41:00 +00:00
|
|
|
using std::map;
|
|
|
|
|
2016-11-30 09:06:16 +00:00
|
|
|
// fwd
|
|
|
|
class connection;
|
|
|
|
|
|
|
|
namespace evt {
|
|
|
|
using xkb_new_keyboard_notify = xpp::xkb::event::new_keyboard_notify<connection&>;
|
|
|
|
using xkb_map_notify = xpp::xkb::event::map_notify<connection&>;
|
|
|
|
using xkb_state_notify = xpp::xkb::event::state_notify<connection&>;
|
|
|
|
using xkb_controls_notify = xpp::xkb::event::controls_notify<connection&>;
|
|
|
|
using xkb_indicator_state_notify = xpp::xkb::event::indicator_state_notify<connection&>;
|
|
|
|
using xkb_indicator_map_notify = xpp::xkb::event::indicator_map_notify<connection&>;
|
|
|
|
using xkb_names_notify = xpp::xkb::event::names_notify<connection&>;
|
|
|
|
using xkb_compat_map_notify = xpp::xkb::event::compat_map_notify<connection&>;
|
|
|
|
using xkb_bell_notify = xpp::xkb::event::bell_notify<connection&>;
|
|
|
|
using xkb_action_message = xpp::xkb::event::action_message<connection&>;
|
|
|
|
using xkb_access_x_notify = xpp::xkb::event::access_x_notify<connection&>;
|
|
|
|
using xkb_extension_device_notify = xpp::xkb::event::extension_device_notify<connection&>;
|
|
|
|
}
|
|
|
|
|
|
|
|
class keyboard {
|
|
|
|
public:
|
|
|
|
struct indicator {
|
|
|
|
enum class type { NONE = 0U, CAPS_LOCK, NUM_LOCK };
|
|
|
|
xcb_atom_t atom{};
|
|
|
|
uint8_t mask{0};
|
2016-12-15 02:30:41 +00:00
|
|
|
string name{};
|
2016-11-30 09:06:16 +00:00
|
|
|
bool enabled{false};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct layout {
|
2016-12-15 02:30:41 +00:00
|
|
|
string group_name{};
|
|
|
|
vector<string> symbols{};
|
2016-11-30 09:06:16 +00:00
|
|
|
};
|
|
|
|
|
2016-12-08 17:35:06 +00:00
|
|
|
explicit keyboard(vector<layout>&& layouts_, map<indicator::type, indicator>&& indicators_, uint8_t group)
|
|
|
|
: layouts(forward<decltype(layouts)>(layouts_)), indicators(forward<decltype(indicators)>(indicators_)), current_group(group) {}
|
2016-11-30 09:06:16 +00:00
|
|
|
|
|
|
|
const indicator& get(const indicator::type& i) const;
|
2016-12-04 03:11:47 +00:00
|
|
|
void set(uint32_t state);
|
2016-11-30 09:06:16 +00:00
|
|
|
bool on(const indicator::type&) const;
|
2016-12-08 17:35:06 +00:00
|
|
|
void current(uint8_t group);
|
|
|
|
uint8_t current() const;
|
2016-11-30 09:06:16 +00:00
|
|
|
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;
|
2016-12-16 10:26:28 +00:00
|
|
|
size_t size() const;
|
2016-11-30 09:06:16 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
vector<layout> layouts;
|
|
|
|
map<indicator::type, indicator> indicators;
|
2016-12-08 17:35:06 +00:00
|
|
|
uint8_t current_group{0};
|
2016-11-30 09:06:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace xkb_util {
|
|
|
|
static constexpr const char* LAYOUT_SYMBOL_BLACKLIST{";group;inet;pc;"};
|
|
|
|
|
2016-12-21 13:55:19 +00:00
|
|
|
void query_extension(connection& conn);
|
|
|
|
|
2016-12-16 10:26:28 +00:00
|
|
|
void switch_layout(connection& conn, xcb_xkb_device_spec_t device, uint8_t index);
|
2016-12-08 17:35:06 +00:00
|
|
|
uint8_t get_current_group(connection& conn, xcb_xkb_device_spec_t device);
|
2016-11-30 09:06:16 +00:00
|
|
|
vector<keyboard::layout> get_layouts(connection& conn, xcb_xkb_device_spec_t device);
|
|
|
|
map<keyboard::indicator::type, keyboard::indicator> get_indicators(connection& conn, xcb_xkb_device_spec_t device);
|
2016-12-08 17:35:06 +00:00
|
|
|
string parse_layout_symbol(string&& name);
|
2016-11-30 09:06:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
POLYBAR_NS_END
|