More robust Gyro toggle (#5104)

* Make toggling Gyro events more robust

Actually ask to turn it on/off depending on the setting, instead of a
blind toggle

A quick succession of suspend/resume events could otherwise leave it
in an unexpected state (i.e., off when it should have been on).
This commit is contained in:
NiLuJe
2019-07-01 17:12:24 +02:00
committed by GitHub
parent 64cc7e0827
commit 38e7975728
6 changed files with 28 additions and 13 deletions

View File

@@ -696,14 +696,29 @@ function Input:handleMiscEvNTX(ev)
end
-- Allow toggling it at runtime
function Input:toggleMiscEvNTX()
if self.isNTXAccelHooked then
self.handleMiscEv = function() end
function Input:toggleMiscEvNTX(toggle)
if toggle and toggle == true then
-- Honor Gyro events
if not self.isNTXAccelHooked then
self.handleMiscEv = self.handleMiscEvNTX
self.isNTXAccelHooked = true
end
elseif toggle and toggle == false then
-- Ignore Gyro events
if self.isNTXAccelHooked then
self.handleMiscEv = function() end
self.isNTXAccelHooked = false
end
else
self.handleMiscEv = self.handleMiscEvNTX
end
-- Toggle it
if self.isNTXAccelHooked then
self.handleMiscEv = function() end
else
self.handleMiscEv = self.handleMiscEvNTX
end
self.isNTXAccelHooked = not self.isNTXAccelHooked
self.isNTXAccelHooked = not self.isNTXAccelHooked
end
end
-- helpers for touch event data management: