| 55 | } |
| 56 | |
| 57 | std::optional<InputTrigger> triggerFromDict(const nb::dict& d) { |
| 58 | if (!d.contains("type")) { |
| 59 | return std::nullopt; |
| 60 | } |
| 61 | |
| 62 | const auto type = nb::cast<std::string>(d["type"]); |
| 63 | const int modifiers = d.contains("modifiers") ? nb::cast<int>(d["modifiers"]) : MODIFIER_NONE; |
| 64 | const auto chord_key = [&]() -> std::optional<int> { |
| 65 | if (!d.contains("chord_key")) { |
| 66 | return std::nullopt; |
| 67 | } |
| 68 | return nb::cast<int>(d["chord_key"]); |
| 69 | }(); |
| 70 | |
| 71 | if (type == "key") { |
| 72 | if (!d.contains("key")) { |
| 73 | return std::nullopt; |
| 74 | } |
| 75 | return KeyTrigger{nb::cast<int>(d["key"]), modifiers, false}; |
| 76 | } |
| 77 | if (type == "mouse_button") { |
| 78 | if (!d.contains("button")) { |
| 79 | return std::nullopt; |
| 80 | } |
| 81 | const bool double_click = d.contains("double_click") && nb::cast<bool>(d["double_click"]); |
| 82 | return MouseButtonTrigger{static_cast<MouseButton>(nb::cast<int>(d["button"])), |
| 83 | modifiers, |
| 84 | double_click}; |
| 85 | } |
| 86 | if (type == "scroll") { |
| 87 | return MouseScrollTrigger{modifiers, chord_key}; |
| 88 | } |
| 89 | if (type == "drag") { |
| 90 | if (!d.contains("button")) { |
| 91 | return std::nullopt; |
| 92 | } |
| 93 | return MouseDragTrigger{static_cast<MouseButton>(nb::cast<int>(d["button"])), |
| 94 | modifiers, |
| 95 | chord_key}; |
| 96 | } |
| 97 | return std::nullopt; |
| 98 | } |
| 99 | } // namespace |
| 100 | |
| 101 | void register_keymap(nb::module_& m) { |
no test coverage detected