I am using the Kivy framework to develop a UI application in Python 3. The Kivy application is fullscreen. Whenever I perform a touch event or type with my physical keyboard, the underlying desktop environment will receive the touch and keyboard events as well as my Kivy application.
For example, if I open a text file on my desktop and then run my Kivy application, I am able to blindly type text into the text file while the Kivy application is in the foreground (fullscreen). The Kivy application ignores the physical keybaord input as it should since I have the keyboard_mode
option set to dock
in my configuration file.
Touch events work in my Kivy application as they should, I am able to select buttons which perform their designated operations; however, the touch event will also be passed through to the desktop. I am aware of this by blindly double clicking in my Kivy application and then returning to the desktop to find a slew of applications opened (through shortcuts on my desktop). A member of the Raspberry Pi community has also had this issue to no avail: https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=132054.
Here is my simple main.kv file for reference:
<Controller>:
ActionBar:
pos_hint: {'top':1}
ActionView:
use_separator: True
ActionPrevious:
title: 'Action Bar'
with_previous: False
on_release: root.action_close()
BoxLayout:
Label:
text: "Test"
And my main.python file:
import kivy
from kivy.uix.floatlayout import FloatLayout
from kivy.app import App
class Controller(FloatLayout):
def action_close(self):
App.get_running_app().stop()
class ControllerApp(App):
def build(self):
self.load_kv('main.kv')
return Controller()
ControllerApp().run()
As well as the relevant snippets from my config.ini file for Kivy:
[kivy]
keyboard_repeat_delay = 300
keyboard_repeat_rate = 30
log_dir = logs
log_enable = 1
log_level = info
log_name = kivy_%y-%m-%d_%_.txt
window_icon =
keyboard_mode = dock
keyboard_layout = qwerty
desktop = 1
exit_on_escape = 1
pause_on_minimize = 0
config_version = 14
[graphics]
display = -1
fullscreen = auto
height = 600
left = 0
maxfps = 60
multisamples = 2
position = auto
rotation = 0
show_cursor = 1
top = 0
width = 800
resizable = 1
borderless = 0
window_state = visible
minimum_width = 0
minimum_height = 0
[input]
mouse = mouse
mtdev_%(name)s = probesysfs,provider=mtdev
hid_%(name)s = probesysfs,provider=hidinput
...
I have tried playing with the values in the configuration file, most notably the window_state
, fullscreen
, and keyboard_mode
options with no success. Kivy configuration information can be found here. Various searches on Google and here turned up nothing, any help would be greatly appreciated.
I think this is caused by using Kivy's rpi-specific window provider, which uses a low level interface with the hardware in order to perform more efficiently, but in turn doesn't interact with the desktop in a normal way - specifically, input and drawing bypass the normal mechanisms.
If you want to use the app in a desktop, I think you can use the normal window backends (ideally SDL2) by recompiling Kivy against them, although this may run slower. However, if you don't actually need the desktop (e.g. if Kivy will be the only thing that needs to run), another advantage of this window provider is that it doesn't actually need X11 etc, in which case you could just not start them to avoid the problem.
Also see this github issue on the topic.