2020-10-10 16:09:18 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <fmt/format.h>
|
2021-07-13 01:33:12 +00:00
|
|
|
#include <xkbcommon/xkbregistry.h>
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
2020-10-10 16:09:18 +00:00
|
|
|
#include "ALabel.hpp"
|
|
|
|
#include "bar.hpp"
|
|
|
|
#include "client.hpp"
|
|
|
|
#include "modules/sway/ipc/client.hpp"
|
|
|
|
#include "util/json.hpp"
|
|
|
|
|
|
|
|
namespace waybar::modules::sway {
|
|
|
|
|
|
|
|
class Language : public ALabel, public sigc::trackable {
|
|
|
|
public:
|
|
|
|
Language(const std::string& id, const Json::Value& config);
|
|
|
|
~Language() = default;
|
|
|
|
auto update() -> void;
|
|
|
|
|
|
|
|
private:
|
2021-07-13 01:33:12 +00:00
|
|
|
struct Layout {
|
|
|
|
std::string full_name;
|
|
|
|
std::string short_name;
|
|
|
|
std::string variant;
|
|
|
|
};
|
|
|
|
|
|
|
|
class XKBContext {
|
|
|
|
public:
|
|
|
|
XKBContext();
|
|
|
|
~XKBContext();
|
|
|
|
auto next_layout() -> Layout*;
|
|
|
|
private:
|
|
|
|
rxkb_context* context_ = nullptr;
|
|
|
|
rxkb_layout* xkb_layout_ = nullptr;
|
|
|
|
Layout* layout_ = nullptr;
|
|
|
|
};
|
|
|
|
|
2020-10-10 16:09:18 +00:00
|
|
|
void onEvent(const struct Ipc::ipc_response&);
|
|
|
|
void onCmd(const struct Ipc::ipc_response&);
|
2021-07-13 01:33:12 +00:00
|
|
|
|
|
|
|
auto set_current_layout(std::string current_layout) -> void;
|
|
|
|
auto init_layouts_map(const std::vector<std::string>& used_layouts) -> void;
|
|
|
|
|
|
|
|
const static std::string XKB_LAYOUT_NAMES_KEY;
|
|
|
|
const static std::string XKB_ACTIVE_LAYOUT_NAME_KEY;
|
2020-10-10 16:09:18 +00:00
|
|
|
|
2021-07-13 01:33:12 +00:00
|
|
|
Layout layout_;
|
|
|
|
std::map<std::string, Layout> layouts_map_;
|
|
|
|
XKBContext xkb_context_;
|
|
|
|
bool is_variant_displayed;
|
|
|
|
|
|
|
|
util::JsonParser parser_;
|
|
|
|
std::mutex mutex_;
|
|
|
|
Ipc ipc_;
|
2020-10-10 16:09:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace waybar::modules::sway
|