// gKeyMapper - keyboard layout lookups (xkbcommon), shared by GUI and daemon. // // The active layout is read from /etc/default/keyboard (XKBLAYOUT). Without it, // names fall back to the layout-independent US key positions in shared/keys. #ifndef GKEYMAPPER_KEYMAP_H #define GKEYMAPPER_KEYMAP_H #include struct xkb_keymap; struct xkb_state; namespace gkeymapper { // Two-way lookup on the active keyboard layout: // - daemon: canonical key name -> Linux input (evdev) code // - GUI: pressed X keycode -> canonical base key name (level 0) class Keymap { public: Keymap() = default; ~Keymap(); Keymap(const Keymap&) = delete; Keymap& operator=(const Keymap&) = delete; // Builds the keymap from /etc/default/keyboard. Returns false if it cannot // be built; the lookups then use the US fallback. bool init(); bool is_ready() const { return state_ != nullptr; } const std::string& layout_name() const { return layoutName_; } // Canonical key name -> Linux input (evdev) code, e.g. "z" -> 21 on a German // layout. Falls back to linux_key_code() for names that are not part of the // layout. int key_code(const std::string& name) const; // X keycode (same value GDK reports) -> level-0 keysym name, lowercased // ("ssharp", "a", "f4"). Empty if it cannot be resolved. Used by the capture // dialog so "shift+ssharf" is recorded instead of the shifted symbol. std::string base_key_name(unsigned int keycode) const; private: xkb_keymap* keymap_ = nullptr; xkb_state* state_ = nullptr; std::string layoutName_; }; } // namespace gkeymapper #endif // GKEYMAPPER_KEYMAP_H