5#include "fifechan/shortcut.hpp"
12#include "fifechan/events/keyevent.hpp"
13#include "fifechan/key.hpp"
27 if ((sdlMods & 1) != 0) {
28 mods |= Modifier::Shift;
30 if ((sdlMods & 64) != 0) {
31 mods |= Modifier::Control;
33 if ((sdlMods & 256) != 0) {
34 mods |= Modifier::Alt;
36 if ((sdlMods & 1024) != 0) {
37 mods |= Modifier::Meta;
40 return Shortcut(Key(
static_cast<int>(keycode)), mods);
45 assert(
"event key must be valid" && event.
getKey().getValue() != 0);
46 if (
mKey.getValue() != event.
getKey().getValue()) {
50 uint16_t eventMods = 0;
52 eventMods |= Modifier::Shift;
55 eventMods |= Modifier::Control;
58 eventMods |= Modifier::Alt;
61 eventMods |= Modifier::Meta;
70 if (
mKey.getValue() != other.
mKey.getValue()) {
81 if ((
mModMask & Modifier::Control) != 0) {
84 if ((
mModMask & Modifier::Shift) != 0) {
87 if ((
mModMask & Modifier::Alt) != 0) {
90 if ((
mModMask & Modifier::Meta) != 0) {
95 int const val =
mKey.getValue();
96 if (val >= 32 && val <= 126) {
97 result +=
static_cast<char>(val);
99 result +=
"Key(" + std::to_string(val) +
")";
122 return !(*
this == other);
Key const & getKey() const
Gets the key of the event.
uint16_t mModMask
Bitmask of Modifier flags.
bool conflicts(Shortcut const &other) const
Checks for collision with another shortcut.
std::string to_string() const
Returns a human-readable string, e.g.
bool operator==(Shortcut const &other) const
Compares two shortcuts for equality (same key + same mods).
static Shortcut fromKeycode(uint32_t keycode, uint16_t sdlMods=0)
Creates a Shortcut from a raw SDL keycode + SDL modifier mask.
Key mKey
The semantic key.
bool operator!=(Shortcut const &other) const
Compares two shortcuts for inequality.
bool matches(KeyEvent const &event) const
Compares the shortcut to a KeyEvent.
Shortcut()=default
Default constructor creates an unbound shortcut (key 0, no mods).
Key getKey() const
Gets the semantic key.
uint16_t getModMask() const
Gets the modifier bitmask.
Used replacement tokens by configure_file():