File: language.hpp

package info (click to toggle)
waybar 0.15.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,464 kB
  • sloc: cpp: 25,331; xml: 742; python: 146; ansic: 77; makefile: 29
file content (68 lines) | stat: -rw-r--r-- 1,722 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#pragma once

#include <fmt/format.h>
#include <xkbcommon/xkbregistry.h>

#include <map>
#include <string>

#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);
  virtual ~Language() = default;
  auto update() -> void override;

 private:
  enum class DisplayedShortFlag { None = 0, ShortName = 1, ShortDescription = 1 << 1 };

  struct Layout {
    std::string full_name;
    std::string short_name;
    std::string variant;
    std::string short_description;
    std::string country_flag() const;
  };

  class XKBContext {
   public:
    XKBContext();
    ~XKBContext();
    auto next_layout() -> Layout*;

   private:
    rxkb_context* context_ = nullptr;
    rxkb_layout* xkb_layout_ = nullptr;
    Layout* layout_ = nullptr;
    std::map<std::string, rxkb_layout*> base_layouts_by_name_;
  };

  void onEvent(const struct Ipc::ipc_response&);
  void onCmd(const struct Ipc::ipc_response&);

  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;

  Layout layout_;
  std::string tooltip_format_ = "";
  std::map<std::string, Layout> layouts_map_;
  bool hide_single_;
  bool is_variant_displayed;
  std::byte displayed_short_flag = static_cast<std::byte>(DisplayedShortFlag::None);

  util::JsonParser parser_;
  std::mutex mutex_;
  Ipc ipc_;
};

}  // namespace waybar::modules::sway