Move indev to shared component

This commit is contained in:
Johannes Marbach 2024-03-28 14:31:27 +01:00
parent f81f4587f6
commit b98b8d1be2
10 changed files with 58 additions and 153 deletions

View file

@ -32,6 +32,7 @@ For a growing collection of demo videos, see the [wiki].
- [lvgl] (git submodule / linked statically)
- [squeek2lvgl] (git submodule / linked statically)
- [libinput]
- [libudev]
- evdev kernel module
- uinput kernel module
@ -129,6 +130,7 @@ The [FontAwesome] font is licensed under the Open Font License version 1.1.
[arrow-alt-circle-up]: https://fontawesome.com/v5.15/icons/arrow-alt-circle-up?style=solid
[fbkeyboard]: https://github.com/bakonyiferenc/fbkeyboard
[libinput]: https://gitlab.freedesktop.org/libinput/libinput
[libudev]: https://github.com/systemd/systemd/tree/main/src/libudev
[lv_port_linux_frame_buffer]: https://github.com/lvgl/lv_port_linux_frame_buffer
[lv_sim_emscripten]: https://github.com/lvgl/lv_sim_emscripten/blob/master/mouse_cursor_icon.c
[lvgl]: https://github.com/lvgl/lvgl

View file

@ -1,84 +0,0 @@
/**
* Copyright 2021 Johannes Marbach
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include "indev.h"
#include "../shared/cursor/cursor.h"
#include "lvgl/lvgl.h"
#include <limits.h>
/**
* Defines
*/
#define MAX_POINTER_DEVS 4
#define MAX_TOUCHSCREEN_DEVS 1
/**
* Static variables
*/
static int num_pointer_devs = 0;
static char *pointer_devs[MAX_POINTER_DEVS];
static lv_indev_t *pointer_indevs[MAX_POINTER_DEVS];
static int num_touchscreen_devs = 0;
static char *touchscreen_devs[MAX_TOUCHSCREEN_DEVS];
static lv_indev_t *touchscreen_indevs[MAX_TOUCHSCREEN_DEVS];
/**
* Static prototypes
*/
/**
* Auto-connect available input devices having a specific capability.
*
* @param capability capability to filter devices by
* @param max_num_devs maximum number of devices to connect
* @param num_devs pointer for writing the actual number of connected devices into
* @param devs array for storing device paths
* @param indevs array for storing LVGL indevs
*/
static void auto_connect(lv_libinput_capability capability, int max_num_devs, int *num_devs, char *devs[], lv_indev_t *indevs[]);
/**
* Static functions
*/
static void auto_connect(lv_libinput_capability capability, int max_num_devs, int *num_devs, char *devs[], lv_indev_t *indevs[]) {
lv_memset(devs, 0, max_num_devs * sizeof(char *));
lv_memset(indevs, 0, max_num_devs * sizeof(lv_indev_t *));
*num_devs = lv_libinput_find_devs(capability, devs, max_num_devs, false);
for (int i = 0; i < *num_devs; ++i) {
indevs[i] = lv_libinput_create(capability & LV_LIBINPUT_CAPABILITY_KEYBOARD ? LV_INDEV_TYPE_KEYPAD : LV_INDEV_TYPE_POINTER, devs[i]);
}
}
/**
* Public functions
*/
void bb_indev_auto_connect() {
auto_connect(LV_LIBINPUT_CAPABILITY_POINTER, MAX_POINTER_DEVS, &num_pointer_devs, pointer_devs, pointer_indevs);
auto_connect(LV_LIBINPUT_CAPABILITY_TOUCH, MAX_TOUCHSCREEN_DEVS, &num_touchscreen_devs, touchscreen_devs, touchscreen_indevs);
}
void bb_indev_set_up_mouse_cursor() {
lv_obj_t *cursor_obj = lv_img_create(lv_scr_act());
lv_img_set_src(cursor_obj, &bb_cursor_img_dsc);
for (int i = 0; i < num_pointer_devs; ++i) {
lv_indev_set_cursor(pointer_indevs[i], cursor_obj);
}
}

View file

@ -1,20 +0,0 @@
/**
* Copyright 2021 Johannes Marbach
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#ifndef BB_INDEV_H
#define BB_INDEV_H
/**
* Auto-connect currently available keyboard, pointer and touchscreen input devices.
*/
void bb_indev_auto_connect();
/**
* Set up the mouse cursor image for currently connected pointer devices.
*/
void bb_indev_set_up_mouse_cursor();
#endif /* BB_INDEV_H */

View file

@ -6,13 +6,13 @@
#include "buffyboard.h"
#include "command_line.h"
#include "indev.h"
#include "sq2lv_layouts.h"
#include "terminal.h"
#include "uinput_device.h"
#include "lvgl/lvgl.h"
#include "../shared/indev.h"
#include "../squeek2lvgl/sq2lv.h"
#include <limits.h>
@ -279,9 +279,8 @@ int main(int argc, char *argv[]) {
}
}
/* Connect input devices */
bb_indev_auto_connect();
bb_indev_set_up_mouse_cursor();
/* Start input device monitor and auto-connect available devices */
bb_indev_start_monitor_and_autoconnect(false, true, true);
/* Initialise theme and styles */
set_theme(true);

View file

@ -15,7 +15,6 @@ add_project_arguments('-DBB_VERSION="@0@"'.format(meson.project_version()), lang
buffyboard_sources = [
'command_line.c',
'font_32.c',
'indev.c',
'main.c',
'sq2lv_layouts.c',
'terminal.c',
@ -23,7 +22,9 @@ buffyboard_sources = [
]
shared_sources = [
'../shared/cursor/cursor.c'
'../shared/cursor/cursor.c',
'../shared/indev.c',
'../shared/log.c',
]
squeek2lvgl_sources = [
@ -38,6 +39,7 @@ executable(
include_directories: ['..'],
dependencies: [
dependency('libinput'),
dependency('libudev'),
meson.get_compiler('c').find_library('m', required: false),
],
install: true