107 std::vector<ImGuiKey> shortcuts;
111 size_t end = shortcut.find(kCtrlKey);
112 if (end != std::string::npos) {
113 shortcuts.push_back(ImGuiMod_Ctrl);
114 start = end + kCtrlKey.size();
117 end = shortcut.find(kAltKey, start);
118 if (end != std::string::npos) {
119 shortcuts.push_back(ImGuiMod_Alt);
120 start = end + kAltKey.size();
123 end = shortcut.find(kShiftKey, start);
124 if (end != std::string::npos) {
125 shortcuts.push_back(ImGuiMod_Shift);
126 start = end + kShiftKey.size();
129 end = shortcut.find(kSuperKey, start);
130 if (end != std::string::npos) {
131 shortcuts.push_back(ImGuiMod_Super);
132 start = end + kSuperKey.size();
136 while (start < shortcut.size()) {
146 for (
const auto& shortcut : shortcut_manager.
GetShortcuts()) {
147 bool modifiers_held =
true;
148 bool key_pressed =
false;
149 ImGuiKey main_key = ImGuiKey_None;
152 for (
const auto& key : shortcut.second.keys) {
153 if (key == ImGuiMod_Ctrl || key == ImGuiMod_Alt ||
154 key == ImGuiMod_Shift || key == ImGuiMod_Super) {
156 if (key == ImGuiMod_Ctrl) {
157 modifiers_held &= ImGui::GetIO().KeyCtrl;
158 }
else if (key == ImGuiMod_Alt) {
159 modifiers_held &= ImGui::GetIO().KeyAlt;
160 }
else if (key == ImGuiMod_Shift) {
161 modifiers_held &= ImGui::GetIO().KeyShift;
162 }
else if (key == ImGuiMod_Super) {
163 modifiers_held &= ImGui::GetIO().KeySuper;
172 if (main_key != ImGuiKey_None) {
173 key_pressed = ImGui::IsKeyPressed(main_key,
false);
177 if (modifiers_held && key_pressed && shortcut.second.callback) {
178 shortcut.second.callback();
191 std::function<
void()> save_callback,
192 std::function<
void()> open_callback,
193 std::function<
void()> close_callback,
194 std::function<
void()> find_callback,
195 std::function<
void()> settings_callback) {
208 if (close_callback) {
218 if (settings_callback) {
219 RegisterShortcut(
"settings", {ImGuiMod_Ctrl, ImGuiKey_Comma}, settings_callback);
227 std::function<
void()> focus_left,
228 std::function<
void()> focus_right,
229 std::function<
void()> focus_up,
230 std::function<
void()> focus_down,
231 std::function<
void()> close_window,
232 std::function<
void()> split_horizontal,
233 std::function<
void()> split_vertical) {
237 RegisterShortcut(
"focus_left", {ImGuiMod_Ctrl, ImGuiKey_LeftArrow}, focus_left);
241 RegisterShortcut(
"focus_right", {ImGuiMod_Ctrl, ImGuiKey_RightArrow}, focus_right);
249 RegisterShortcut(
"focus_down", {ImGuiMod_Ctrl, ImGuiKey_DownArrow}, focus_down);
254 RegisterShortcut(
"close_window", {ImGuiMod_Ctrl, ImGuiKey_W, ImGuiKey_C}, close_window);
258 if (split_horizontal) {
259 RegisterShortcut(
"split_horizontal", {ImGuiMod_Ctrl, ImGuiKey_W, ImGuiKey_S}, split_horizontal);
263 if (split_vertical) {
264 RegisterShortcut(
"split_vertical", {ImGuiMod_Ctrl, ImGuiKey_W, ImGuiKey_V}, 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)