mirror of
https://github.com/liberatedsystems/openCom-Companion.git
synced 2024-11-22 05:20:36 +01:00
Circumvention for SDL2 focus bug
This commit is contained in:
parent
efefdbebe8
commit
d338e6196c
38
main.py
38
main.py
@ -26,6 +26,10 @@ from kivymd.uix.dialog import MDDialog
|
|||||||
__version__ = "0.1.5"
|
__version__ = "0.1.5"
|
||||||
__variant__ = "alpha"
|
__variant__ = "alpha"
|
||||||
|
|
||||||
|
if RNS.vendor.platformutils.get_platform() == "android":
|
||||||
|
from jnius import autoclass
|
||||||
|
from android.runnable import run_on_ui_thread
|
||||||
|
|
||||||
class SidebandApp(MDApp):
|
class SidebandApp(MDApp):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
@ -85,16 +89,48 @@ class SidebandApp(MDApp):
|
|||||||
if self.announces_view != None:
|
if self.announces_view != None:
|
||||||
self.announces_view.update()
|
self.announces_view.update()
|
||||||
|
|
||||||
def on_start(self):
|
def on_start(self):
|
||||||
self.last_exit_event = time.time()
|
self.last_exit_event = time.time()
|
||||||
EventLoop.window.bind(on_keyboard=self.keyboard_event)
|
EventLoop.window.bind(on_keyboard=self.keyboard_event)
|
||||||
EventLoop.window.bind(on_key_down=self.keydown_event)
|
EventLoop.window.bind(on_key_down=self.keydown_event)
|
||||||
|
|
||||||
|
# This incredibly hacky hack circumvents a bug in SDL2
|
||||||
|
# that prevents focus from being correctly released from
|
||||||
|
# the software keyboard on Android. Without this the back
|
||||||
|
# button/gesture does not work after the soft-keyboard has
|
||||||
|
# appeared for the first time.
|
||||||
|
if RNS.vendor.platformutils.get_platform() == "android":
|
||||||
|
BIND_CLASSES = ["kivymd.uix.textfield.textfield.MDTextField",]
|
||||||
|
|
||||||
|
for e in self.root.ids:
|
||||||
|
te = self.root.ids[e]
|
||||||
|
ts = str(te).split(" ")[0].replace("<", "")
|
||||||
|
|
||||||
|
if ts in BIND_CLASSES:
|
||||||
|
te.bind(focus=self.android_focus_fix)
|
||||||
|
# RNS.log("Bound "+str(e)+" / "+ts)
|
||||||
|
# else:
|
||||||
|
# RNS.log("Did not bind "+str(e)+" / "+ts)
|
||||||
|
|
||||||
|
# RNS.log(str(e))
|
||||||
|
|
||||||
self.root.ids.screen_manager.app = self
|
self.root.ids.screen_manager.app = self
|
||||||
self.root.ids.app_version_info.text = "Sideband v"+__version__+" "+__variant__
|
self.root.ids.app_version_info.text = "Sideband v"+__version__+" "+__variant__
|
||||||
self.open_conversations()
|
self.open_conversations()
|
||||||
|
|
||||||
Clock.schedule_interval(self.jobs, 1)
|
Clock.schedule_interval(self.jobs, 1)
|
||||||
|
|
||||||
|
# Part of the focus hack fix
|
||||||
|
def android_focus_fix(self, sender, val):
|
||||||
|
if not val:
|
||||||
|
@run_on_ui_thread
|
||||||
|
def fix_back_button():
|
||||||
|
activity = autoclass('org.kivy.android.PythonActivity').mActivity
|
||||||
|
activity.onWindowFocusChanged(False)
|
||||||
|
activity.onWindowFocusChanged(True)
|
||||||
|
|
||||||
|
fix_back_button()
|
||||||
|
|
||||||
|
|
||||||
def keydown_event(self, instance, keyboard, keycode, text, modifiers):
|
def keydown_event(self, instance, keyboard, keycode, text, modifiers):
|
||||||
if len(modifiers) > 0 and modifiers[0] == 'ctrl' and (text == "w" or text == "q"):
|
if len(modifiers) > 0 and modifiers[0] == 'ctrl' and (text == "w" or text == "q"):
|
||||||
|
Loading…
Reference in New Issue
Block a user