| 40 | } |
| 41 | |
| 42 | std::string KeySpec::toString(bool include_focus) const { |
| 43 | std::string out; |
| 44 | if (modifiers & DFH_MOD_CTRL) out += "Ctrl-"; |
| 45 | if (modifiers & DFH_MOD_ALT) out += "Alt-"; |
| 46 | if (modifiers & DFH_MOD_SUPER) out += "Super-"; |
| 47 | if (modifiers & DFH_MOD_SHIFT) out += "Shift-"; |
| 48 | |
| 49 | std::string key_name; |
| 50 | if (this->sym < 0) { |
| 51 | key_name = "MOUSE" + std::to_string(-this->sym); |
| 52 | } else { |
| 53 | key_name = DFSDL::DFSDL_GetKeyName(this->sym); |
| 54 | } |
| 55 | out += key_name; |
| 56 | |
| 57 | if (include_focus && !this->focus.empty()) { |
| 58 | out += "@"; |
| 59 | bool first = true; |
| 60 | for (const auto& fc : this->focus) { |
| 61 | if (first) { |
| 62 | first = false; |
| 63 | out += fc; |
| 64 | } else { |
| 65 | out += "|" + fc; |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | return out; |
| 71 | } |
| 72 | |
| 73 | std::optional<KeySpec> KeySpec::parse(std::string spec, std::string* err) { |
| 74 | KeySpec out; |