bugfix: initial textinput event on iOS
`love.textinput` is fragile on iOS. Various things can cause an app to stop receiving textinput events. Resizing the window is one reliable way, but there's also another ghost, something that's triggering on every frame of LÖVE. Fortunately, it looks like `love.keyboard.setTextInput(true)` reliably resubscribes the app to textinput events, regardless of their cause. https://github.com/love2d/love/issues/1959 The one remaining open question here is why the call in `App.keychord_press` (equivalent to `love.keypressed`) doesn't fix the breakage caused by the initial window resize (that happens before any keys are pressed). I've confirmed that `keypressed` comes before `textinput` on iOS just like everywhere else.
This commit is contained in:
parent
864ee0a8b2
commit
239077e8e1
10
app.lua
10
app.lua
|
@ -68,7 +68,15 @@ function love.run()
|
|||
App.fake_mouse_press = nil
|
||||
App.fake_mouse_release = nil
|
||||
-- other methods dispatch to real hardware
|
||||
App.screen.resize = love.window.setMode
|
||||
|
||||
App.screen.resize = function(width, height, flags)
|
||||
love.window.setMode(width, height, flags)
|
||||
if OS == 'iOS' then
|
||||
love.keyboard.setTextInput(true) -- magic. iOS seems to lose textinput events after calls to setMode.
|
||||
-- https://github.com/love2d/love/issues/1959
|
||||
end
|
||||
end
|
||||
|
||||
App.screen.size = love.window.getMode
|
||||
App.screen.move = love.window.setPosition
|
||||
App.screen.position = love.window.getPosition
|
||||
|
|
9
main.lua
9
main.lua
|
@ -1,6 +1,8 @@
|
|||
utf8 = require 'utf8'
|
||||
json = require 'json'
|
||||
|
||||
OS = love.system.getOS()
|
||||
|
||||
require 'app'
|
||||
require 'test'
|
||||
require 'live'
|
||||
|
@ -8,8 +10,6 @@ require 'live'
|
|||
require 'keychord'
|
||||
require 'button'
|
||||
|
||||
OS = love.system.getOS()
|
||||
|
||||
-- delegate most business logic to a layer that can be reused by other projects
|
||||
require 'edit'
|
||||
Editor_state = {}
|
||||
|
@ -216,7 +216,10 @@ function App.keychord_press(chord, key)
|
|||
end
|
||||
return
|
||||
end
|
||||
love.keyboard.setTextInput(true) -- magic. keeps iOS from losing textinput events after switching apps.
|
||||
if OS == 'iOS' then
|
||||
love.keyboard.setTextInput(true) -- magic. iOS is prone to losing textinput events.
|
||||
-- https://github.com/love2d/love/issues/1959
|
||||
end
|
||||
-- ignore events for some time after window in focus (mostly alt-tab)
|
||||
if Current_time < Last_focus_time + 0.01 then
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue