about summary refs log tree commit diff stats
path: root/main.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-07-25 15:33:06 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-07-25 15:33:06 -0700
commit94b6d04e83c346ffe4c298536b62803ba1cf4484 (patch)
tree075d675b08c27019b5dda51db49e46b920b454a3 /main.lua
parent6c6a7aab07940ceed1fdbc3d4a98fe93e39e6580 (diff)
downloadlines.love-94b6d04e83c346ffe4c298536b62803ba1cf4484.tar.gz
bugfix: alt-tab shouldn't emit keypress events
Looks like this only happens on Linux:
  https://love2d.org/forums/viewtopic.php?p=249700
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua21
1 files changed, 20 insertions, 1 deletions
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