From 94b6d04e83c346ffe4c298536b62803ba1cf4484 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 25 Jul 2022 15:33:06 -0700 Subject: [PATCH] bugfix: alt-tab shouldn't emit keypress events Looks like this only happens on Linux: https://love2d.org/forums/viewtopic.php?p=249700 --- main.lua | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/main.lua b/main.lua index 8d34a42..5cf8f08 100644 --- a/main.lua +++ b/main.lua @@ -19,8 +19,9 @@ function App.initialize_globals() -- blinking cursor Cursor_time = 0 - -- for hysteresis + -- for hysteresis in a few places Last_resize_time = App.getTime() + Last_focus_time = App.getTime() -- https://love2d.org/forums/viewtopic.php?p=249700 end -- called only for real run @@ -174,17 +175,35 @@ function App.mousereleased(x,y, mouse_button) return edit.mouse_released(Editor_state, x,y, mouse_button) end +function App.focus(in_focus) + if in_focus then + Last_focus_time = App.getTime() + end +end + function App.textinput(t) + -- ignore events for some time after window in focus + if App.getTime() < Last_focus_time + 0.01 then + return + end Cursor_time = 0 -- ensure cursor is visible immediately after it moves return edit.textinput(Editor_state, t) end function App.keychord_pressed(chord, key) + -- ignore events for some time after window in focus + if App.getTime() < Last_focus_time + 0.01 then + return + end Cursor_time = 0 -- ensure cursor is visible immediately after it moves return edit.keychord_pressed(Editor_state, chord, key) end function App.keyreleased(key, scancode) + -- ignore events for some time after window in focus + if App.getTime() < Last_focus_time + 0.01 then + return + end Cursor_time = 0 -- ensure cursor is visible immediately after it moves return edit.key_released(Editor_state, key, scancode) end