Skip to content

Better keyboard input #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,21 @@ pkg_check_modules(GBM REQUIRED gbm)
pkg_check_modules(EGL REQUIRED egl)
pkg_check_modules(GLESV2 REQUIRED glesv2)
pkg_check_modules(LIBSYSTEMD REQUIRED libsystemd)
pkg_check_modules(LIBINPUT libinput)
pkg_check_modules(LIBINPUT REQUIRED libinput)
pkg_check_modules(LIBXKBCOMMON REQUIRED xkbcommon)
pkg_check_modules(LIBUDEV libudev)
pkg_check_modules(GPIOD libgpiod)

set(FLUTTER_PI_SRC
src/flutter-pi.c
src/platformchannel.c
src/pluginregistry.c
src/console_keyboard.c
src/texture_registry.c
src/compositor.c
src/modesetting.c
src/collection.c
src/cursor.c
src/cursor.c
src/keyboard.c
src/plugins/services.c
src/plugins/testplugin.c
src/plugins/text_input.c
Expand Down Expand Up @@ -136,6 +137,7 @@ target_link_libraries(flutter-pi
${LIBINPUT_LDFLAGS}
${LIBUDEV_LDFLAGS}
${GPIOD_LDFLAGS}
${LIBXKBCOMMON_LDFLAGS}
pthread dl rt m
)

Expand All @@ -151,6 +153,7 @@ target_include_directories(flutter-pi PRIVATE
${LIBINPUT_INCLUDE_DIRS}
${LIBUDEV_INCLUDE_DIRS}
${GPIOD_INCLUDE_DIRS}
${LIBXKBCOMMON_INCLUDE_DIRS}
)

target_compile_options(flutter-pi PRIVATE
Expand All @@ -162,6 +165,7 @@ target_compile_options(flutter-pi PRIVATE
${LIBINPUT_CFLAGS}
${LIBUDEV_CFLAGS}
${GPIOD_CFLAGS}
${LIBXKBCOMMON_CFLAGS}
-ggdb
-DBUILD_TEXT_INPUT_PLUGIN
-DBUILD_SPIDEV_PLUGIN
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
REAL_CFLAGS = -I./include $(shell pkg-config --cflags gbm libdrm glesv2 egl libsystemd libinput libudev) \
REAL_CFLAGS = -I./include $(shell pkg-config --cflags gbm libdrm glesv2 egl libsystemd libinput libudev xkbcommon) \
-DBUILD_TEXT_INPUT_PLUGIN \
-DBUILD_TEST_PLUGIN \
-DBUILD_OMXPLAYER_VIDEO_PLAYER_PLUGIN \
-O0 -ggdb \
$(CFLAGS)

REAL_LDFLAGS = \
$(shell pkg-config --libs gbm libdrm glesv2 egl libsystemd libinput libudev) \
$(shell pkg-config --libs gbm libdrm glesv2 egl libsystemd libinput libudev xkbcommon) \
-lrt \
-lpthread \
-ldl \
Expand All @@ -17,12 +17,12 @@ REAL_LDFLAGS = \
SOURCES = src/flutter-pi.c \
src/platformchannel.c \
src/pluginregistry.c \
src/console_keyboard.c \
src/texture_registry.c \
src/compositor.c \
src/modesetting.c \
src/collection.c \
src/cursor.c \
src/keyboard.c \
src/plugins/services.c \
src/plugins/testplugin.c \
src/plugins/text_input.c \
Expand Down
17 changes: 3 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
## 📰 NEWS
- the physical dimensions of the screen can now be specified via cmdline, using the `--dimensions` option.
- the layout of the engine-binaries branch has changed again. The symbolic link from `libflutter_engine.so` to the fitting `libflutter_engine.so.release` or `libflutter_engine.so.debug` is no longer needed, flutter-pi will now dynamically load the engine fitting the the runtime mode that was specified via cmdline. (if `--release` is given, flutter-pi will load `libflutter_engine.so.release`, else `libflutter_engine.so.debug`)
- flutter-pi now requires `libsystemd-dev`, `libinput-dev` and `libudev-dev` at compile-time. (`libudev-dev` is actually optional. To build without udev support, use cmake.)
- flutter-pi and the engine binaries updated for flutter 1.20.
- it's possible to run flutter-pi in AOT mode now. Instructions for that are WIP.
- `--aot` was renamed to `--release`
- flutter-pi now requires `libxkbcommon`. Install using `sudo apt install libxkbcommon-dev`
- keyboard input works better now. You can now use any keyboard connected to the Raspberry Pi for text and raw keyboard input.

# flutter-pi
A light-weight Flutter Engine Embedder for Raspberry Pi. Inspired by https://github.com/chinmaygarde/flutter_from_scratch.
Expand Down Expand Up @@ -236,7 +232,7 @@ sudo fc-cache
```
### libgpiod (for the included GPIO plugin), libsystemd, libinput, libudev
```bash
sudo apt-get install gpiod libgpiod-dev libsystemd-dev libinput-dev libudev-dev
sudo apt-get install gpiod libgpiod-dev libsystemd-dev libinput-dev libudev-dev libxkbcommon-dev
```

## Compiling flutter-pi (on the Raspberry Pi)
Expand All @@ -250,13 +246,6 @@ The _flutter-pi_ executable will then be located at this path: `/path/to/the/clo
## Performance
Performance is actually better than I expected. With most of the apps inside the `flutter SDK -> examples -> catalog` directory I get smooth 50-60fps.

## Keyboard Input
Keyboard input is supported. **There is one important limitation though**. Text input (i.e. writing any kind of text/symbols to flutter input fields) only works when typing on the keyboard, which is attached to the terminal flutter-pi is running on. So, if you ssh into your Raspberry Pi to run flutter-pi, you have to enter text into your ssh terminal.

Raw Keyboard input (i.e. using tab to iterate through focus nodes) works with any keyboard attached to your Raspberry Pi.

converting raw key-codes to text symbols is not that easy (because of all the different keyboard layouts), so for text input flutter-pi basically uses `stdin`.

## Touchscreen Latency
Due to the way the touchscreen driver works in raspbian, there's some delta between an actual touch of the touchscreen and a touch event arriving at userspace. The touchscreen driver in the raspbian kernel actually just repeatedly polls some buffer shared with the firmware running on the VideoCore, and the videocore repeatedly polls the touchscreen. (both at 60Hz) So on average, there's a delay of 17ms (minimum 0ms, maximum 34ms). If I have enough time in the future, I'll try to build a better touchscreen driver to lower the delay.

191 changes: 0 additions & 191 deletions include/console_keyboard.h

This file was deleted.

6 changes: 5 additions & 1 deletion include/flutter-pi.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <modesetting.h>
#include <collection.h>
#include <keyboard.h>

#define LOAD_EGL_PROC(flutterpi_struct, name) \
do { \
Expand Down Expand Up @@ -394,13 +395,15 @@ struct flutterpi {
struct {
bool use_paths;
bool disable_text_input;

glob_t input_devices_glob;
# ifndef BUILD_WITHOUT_UDEV_SUPPORT
struct libudev libudev;
# endif
struct libinput *libinput;
sd_event_source *libinput_event_source;
sd_event_source *stdin_event_source;
struct keyboard_config *keyboard_config;

int64_t next_unused_flutter_device_id;
double cursor_x, cursor_y;
} input;
Expand Down Expand Up @@ -452,6 +455,7 @@ extern struct flutterpi flutterpi;

struct input_device_data {
int64_t flutter_device_id_offset;
struct keyboard_state *keyboard_state;
double x, y;
int64_t buttons;
uint64_t timestamp;
Expand Down
Loading