kivy / kivy

Open source UI framework written in Python, running on Windows, Linux, macOS, Android and iOS
https://kivy.org
MIT License
17.75k stars 3.07k forks source link

Support for Plasma Mobile and Phosh #7367

Open goffi-contrib opened 3 years ago

goffi-contrib commented 3 years ago

Hello,

I have a working Kivy based app which I would like to run on FOSS mobiles OSes like Plasma Mobile and Phosh (here on Pinephone with Manjaro and Mobian). But there are 2 issues so far which make Kivy unusable on those platforms:

It would be great to have native Kivy support for those platforms, or at least some documentation on how to compile in way similar to what is done for Raspbery Pi. Input field should activate the OS virtual keyboard, and focus should not be lost, touching the OS keyboard should not raise touch events in Kivy.

Thanks

goffi-contrib commented 3 years ago

Regarding the OS keyboard on input, Kivy needs to support text-input-v3 or text-input-v2 from wayland protocol cf. https://social.tchncs.de/@Jbb/105680940679299415

goffi-contrib commented 3 years ago

small update: even with the following in KV:

<VKeyboard>:
    size_hint_y: 0.5
    font_size: 40

The VKeyboard is unusable. Keys are appearing twice, trying to backspace will remove the keyboard.

dogtopus commented 3 years ago

One more nice thing to have: Add arm64 wheels to the distribution so installing kivy directly on those phones via pip/pipenv will not require the build step which takes forever on those lower powered devices.

coryholl-kivy commented 2 months ago

It is possible to write Kivy apps to run on Phosh, but you may need to add some workarounds to your code.

Touches are registered as two touches on the touch screens of both the PinePhone running Phosh and the Librem 5. You can workaround that behavior with a tiny bit of code that can protect against double presses like this:

import time
from kivy.app import App
class MainApp(App):
    over_press_timer = 0

    def some_touch_event_processor_like_a_button_or_vkey_press(self, *kwargs):
        if (time.time() - self.over_press_timer) > 0.3:
            self.over_press_timer = time.time()
            # put your touch processing logic here

You cannot use Phosh's native Squeekboard as a soft keyboard as it is VERY incompatible with Kivy. You need to use managed keyboard_mode for InputText widgets. You can use vkeyboard, but the default layouts are unusable on the small Librem 5 and PinePhone screens. Instead you will need to create your own custom layouts. I have an app that has 7 different keyboard layouts that my soft keyboard management code will swap among. Last but not least you need to fix Kivy's vkeyboard key_background_disabled_normal/key_disabled_background_normal bug or typo so your app will not randomly crash (not technically a Phosh issue but important when using vkeyboard on a Phosh device).

from kivy.uix.vkeyboard import VKeyboard
soft_keyboard = VKeyboard()
soft_keyboard.key_background_disabled_normal = soft_keyboard.key_disabled_background_normal

There is also a touchscreen calibration issue on Phosh. Kivy registers touches at the relative touch location of the touchscreen device rather than the widget render location on the screen. This is because Kivy doesn't know about the 36 pixels Phosh uses at the top and bottom of the screen for its own icons and controls. It doesn't make the app unusable, but it does mean that you have to reach a little higher and lower on the screen to activate a widget when the widget is near the top or bottom of the screen. This can be fixed to some extent by intercepting collide_point calls and calibrating the y position parameter. I am still looking for a more elegant solution to this issue. If I come up with a better workaround I might post it to this issue thread.