1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-11 13:50:56 -05:00
polybar/include/modules/xkeyboard.hpp
Michael Carlberg 519172b6ec feat(xkeyboard): Switch layout group on click
When serveral layout groups are defined for the keyboard
they can be cycled when clicking on the module.

   For example:

   $ setxkbmap -layout us,sv,fr

Ref #84
2016-12-16 11:31:08 +01:00

60 lines
1.6 KiB
C++

#pragma once
#include "common.hpp"
#include "components/config.hpp"
#include "components/types.hpp"
#include "modules/meta/static_module.hpp"
#include "x11/events.hpp"
#include "x11/window.hpp"
#include "x11/xkb.hpp"
POLYBAR_NS
class connection;
namespace modules {
/**
* Keyboard module using the X keyboard extension
*/
class xkeyboard_module : public static_module<xkeyboard_module>,
public xpp::event::sink<evt::xkb_new_keyboard_notify, evt::xkb_state_notify, evt::xkb_indicator_state_notify> {
public:
explicit xkeyboard_module(const bar_settings& bar, string name);
void setup();
void teardown();
void update();
bool build(builder* builder, const string& tag) const;
bool handle_event(string cmd);
bool receive_events() const {
return true;
}
protected:
bool query_keyboard();
bool blacklisted(const string& indicator_name);
void handle(const evt::xkb_new_keyboard_notify& evt);
void handle(const evt::xkb_state_notify& evt);
void handle(const evt::xkb_indicator_state_notify& evt);
private:
static constexpr const char* TAG_LABEL_LAYOUT{"<label-layout>"};
static constexpr const char* TAG_LABEL_INDICATOR{"<label-indicator>"};
static constexpr const char* FORMAT_DEFAULT{"<label-layout> <label-indicator>"};
static constexpr const char* EVENT_SWITCH{"xkeyboard/switch"};
connection& m_connection;
event_timer m_xkbnotify{};
unique_ptr<keyboard> m_keyboard;
label_t m_layout;
label_t m_indicator;
map<keyboard::indicator::type, label_t> m_indicators;
vector<string> m_blacklist;
};
}
POLYBAR_NS_END