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>
|
|
|
|
|
2022-11-24 11:28:52 +00:00
|
|
|
#include "ALabel.hpp"
|
2020-10-10 16:09:18 +00:00
|
|
|
#include "bar.hpp"
|
|
|
|
#include "client.hpp"
|
|
|
|
#include "modules/sway/ipc/client.hpp"
|
|
|
|
#include "util/json.hpp"
|
|
|
|
|
|
|
|
namespace waybar::modules::sway {
|
|
|
|
|
2022-11-24 11:28:52 +00:00
|
|
|
class Language : public ALabel, public sigc::trackable {
|
2020-10-10 16:09:18 +00:00
|
|
|
public:
|
|
|
|
Language(const std::string& id, const Json::Value& config);
|
2023-03-02 13:57:07 +00:00
|
|
|
virtual ~Language() = default;
|
|
|
|
auto update() -> void override;
|
2020-10-10 16:09:18 +00:00
|
|
|
|
|
|
|
private:
|
2022-04-06 06:37:19 +00:00
|
|
|
enum class DispayedShortFlag { None = 0, ShortName = 1, ShortDescription = 1 << 1 };
|
2021-08-19 22:09:16 +00:00
|
|
|
|
2021-07-13 01:33:12 +00:00
|
|
|
struct Layout {
|
|
|
|
std::string full_name;
|
|
|
|
std::string short_name;
|
|
|
|
std::string variant;
|
2021-08-17 02:28:41 +00:00
|
|
|
std::string short_description;
|
2021-08-25 20:26:04 +00:00
|
|
|
std::string country_flag() const;
|
2021-07-13 01:33:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class XKBContext {
|
|
|
|
public:
|
2022-04-06 06:37:19 +00:00
|
|
|
XKBContext();
|
|
|
|
~XKBContext();
|
|
|
|
auto next_layout() -> Layout*;
|
|
|
|
|
2021-07-13 01:33:12 +00:00
|
|
|
private:
|
2022-04-06 06:37:19 +00:00
|
|
|
rxkb_context* context_ = nullptr;
|
|
|
|
rxkb_layout* xkb_layout_ = nullptr;
|
|
|
|
Layout* layout_ = nullptr;
|
|
|
|
std::map<std::string, rxkb_layout*> base_layouts_by_name_;
|
2021-07-13 01:33:12 +00:00
|
|
|
};
|
|
|
|
|
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;
|
2021-11-23 12:15:55 +00:00
|
|
|
|
2022-04-06 06:37:19 +00:00
|
|
|
Layout layout_;
|
2021-07-24 14:24:37 +00:00
|
|
|
std::string tooltip_format_ = "";
|
2021-07-13 01:33:12 +00:00
|
|
|
std::map<std::string, Layout> layouts_map_;
|
2024-02-22 04:22:35 +00:00
|
|
|
bool hide_single_;
|
2021-07-13 01:33:12 +00:00
|
|
|
bool is_variant_displayed;
|
2021-08-19 22:09:16 +00:00
|
|
|
std::byte displayed_short_flag = static_cast<std::byte>(DispayedShortFlag::None);
|
2021-07-13 01:33:12 +00:00
|
|
|
|
2022-04-06 06:37:19 +00:00
|
|
|
util::JsonParser parser_;
|
|
|
|
std::mutex mutex_;
|
|
|
|
Ipc ipc_;
|
2020-10-10 16:09:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace waybar::modules::sway
|