138 std::vector<ImGuiKey> keys;
139 if (shortcut.empty()) {
144 std::vector<std::string> parts = absl::StrSplit(shortcut,
'+');
145 for (
auto& part : parts) {
147 while (!part.empty() && (part.front() ==
' ' || part.front() ==
'\t')) {
148 part.erase(part.begin());
150 while (!part.empty() && (part.back() ==
' ' || part.back() ==
'\t')) {
153 if (part.empty())
continue;
156 lower.reserve(part.size());
157 for (
char c : part) lower.push_back(
static_cast<char>(std::tolower(c)));
160 if (lower ==
"ctrl" || lower ==
"control") {
161 keys.push_back(ImGuiMod_Ctrl);
164 if (lower ==
"cmd" || lower ==
"command" || lower ==
"win" ||
166 keys.push_back(ImGuiMod_Super);
169 if (lower ==
"alt" || lower ==
"opt" || lower ==
"option") {
170 keys.push_back(ImGuiMod_Alt);
173 if (lower ==
"shift") {
174 keys.push_back(ImGuiMod_Shift);
179 if (lower.size() >= 2 && lower[0] ==
'f') {
182 fnum = std::stoi(lower.substr(1));
186 if (fnum >= 1 && fnum <= 24) {
187 keys.push_back(
static_cast<ImGuiKey
>(ImGuiKey_F1 + (fnum - 1)));
193 if (part.size() == 1) {
195 if (mapped != ImGuiKey_COUNT) {
196 keys.push_back(mapped);
209 const ImGuiIO& io = ImGui::GetIO();
212 if (io.WantCaptureKeyboard || io.WantTextInput) {
216 const ModifierState mod_state = BuildModifierState(io);
218 for (
const auto& shortcut : shortcut_manager.
GetShortcuts()) {
219 int required_mods = 0;
220 std::vector<ImGuiKey> main_keys;
223 for (
const auto& key : shortcut.second.keys) {
225 int key_value =
static_cast<int>(key);
226 if (key_value & ImGuiMod_Mask_) {
227 required_mods |= key_value & ImGuiMod_Mask_;
231 if (key == ImGuiMod_Shortcut || key == ImGuiMod_Ctrl ||
232 key == ImGuiMod_Alt || key == ImGuiMod_Shift ||
233 key == ImGuiMod_Super) {
234 required_mods |= key_value;
238 main_keys.push_back(key);
243 if (main_keys.size() == 1) {
244 ImGuiKeyChord chord =
static_cast<ImGuiKeyChord
>(required_mods) | main_keys.back();
245 if (ImGui::IsKeyChordPressed(chord) && shortcut.second.callback) {
246 shortcut.second.callback();
252 if (!ModifiersSatisfied(required_mods, mod_state)) {
257 bool chord_pressed = !main_keys.empty();
258 for (
size_t i = 0; i + 1 < main_keys.size(); ++i) {
259 if (!ImGui::IsKeyDown(main_keys[i])) {
260 chord_pressed =
false;
265 if (chord_pressed && !main_keys.empty()) {
267 ImGui::IsKeyPressed(main_keys.back(),
false );
270 if (chord_pressed && shortcut.second.callback) {
271 shortcut.second.callback();
294 std::function<
void()> save_callback, std::function<
void()> open_callback,
295 std::function<
void()> close_callback, std::function<
void()> find_callback,
296 std::function<
void()> settings_callback) {
308 if (close_callback) {
318 if (settings_callback) {
328 std::function<
void()> focus_left, std::function<
void()> focus_right,
329 std::function<
void()> focus_up, std::function<
void()> focus_down,
330 std::function<
void()> close_window, std::function<
void()> split_horizontal,
331 std::function<
void()> split_vertical) {
359 if (split_horizontal) {
361 {ImGuiMod_Ctrl, ImGuiKey_W, ImGuiKey_S}, split_horizontal);
365 if (split_vertical) {
void RegisterWindowNavigationShortcuts(std::function< void()> focus_left, std::function< void()> focus_right, std::function< void()> focus_up, std::function< void()> focus_down, std::function< void()> close_window, std::function< void()> split_horizontal, std::function< void()> split_vertical)