diff --git a/.gitignore b/.gitignore
index a9863ae..cda24e6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,20 @@
-buffyboard
-*.o
+# Copyright 2021 Johannes Marbach
+#
+# This file is part of buffyboard, hereafter referred to as the program.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+
+/_build
.vscode
diff --git a/Makefile b/Makefile
deleted file mode 100644
index 3a7e113..0000000
--- a/Makefile
+++ /dev/null
@@ -1,51 +0,0 @@
-# Copyright 2021 Johannes Marbach
-#
-# This file is part of buffyboard, hereafter referred to as the program.
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see .
-
-
-CC ?= gcc
-LVGL_DIR_NAME ?= lvgl
-LVGL_DIR ?= ${shell pwd}
-CFLAGS ?= -O3 -g0 -I$(LVGL_DIR)/ -Wall -Wshadow -Wundef -Wmissing-prototypes -Wno-discarded-qualifiers -Wall -Wextra -Wno-unused-function -Wno-error=strict-prototypes -Wpointer-arith -fno-strict-aliasing -Wno-error=cpp -Wuninitialized -Wmaybe-uninitialized -Wno-unused-parameter -Wno-missing-field-initializers -Wtype-limits -Wsizeof-pointer-memaccess -Wno-format-nonliteral -Wno-cast-qual -Wunreachable-code -Wno-switch-default -Wreturn-type -Wmultichar -Wformat-security -Wno-ignored-qualifiers -Wno-error=pedantic -Wno-sign-compare -Wno-error=missing-prototypes -Wdouble-promotion -Wclobbered -Wdeprecated -Wempty-body -Wtype-limits -Wshift-negative-value -Wstack-usage=2048 -Wno-unused-value -Wno-unused-parameter -Wno-missing-field-initializers -Wuninitialized -Wmaybe-uninitialized -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wtype-limits -Wsizeof-pointer-memaccess -Wno-format-nonliteral -Wpointer-arith -Wno-cast-qual -Wmissing-prototypes -Wunreachable-code -Wno-switch-default -Wreturn-type -Wmultichar -Wno-discarded-qualifiers -Wformat-security -Wno-ignored-qualifiers -Wno-sign-compare
-LDFLAGS ?= -lm -linput
-BIN = buffyboard
-
-MAINSRC = ./cursor.c ./libinput_multi.c ./main.c ./montserrat_extended_32.c ./sq2lv_layouts.c ./squeek2lvgl/sq2lv.c ./terminal.c ./uinput_device.c
-
-include $(LVGL_DIR)/lvgl/lvgl.mk
-include $(LVGL_DIR)/lv_drivers/lv_drivers.mk
-
-OBJEXT ?= .o
-
-AOBJS = $(ASRCS:.S=$(OBJEXT))
-COBJS = $(CSRCS:.c=$(OBJEXT))
-
-MAINOBJ = $(MAINSRC:.c=$(OBJEXT))
-
-SRCS = $(ASRCS) $(CSRCS) $(MAINSRC)
-OBJS = $(AOBJS) $(COBJS)
-
-all: default
-
-%.o: %.c
- @$(CC) $(CFLAGS) -c $< -o $@
- @echo "CC $<"
-
-default: $(AOBJS) $(COBJS) $(MAINOBJ)
- $(CC) -o $(BIN) $(MAINOBJ) $(AOBJS) $(COBJS) $(LDFLAGS)
-
-clean:
- rm -f $(BIN) $(AOBJS) $(COBJS) $(MAINOBJ)
diff --git a/README.md b/README.md
index f364d47..26b794d 100644
--- a/README.md
+++ b/README.md
@@ -51,9 +51,11 @@ Below is a summary of contributions upstreamed thus far.
For development and testing you can run the app in a VT. Unless your user account has special privileges, `sudo` will be needed to access input device files.
```
-$ make
+$ meson _build
+$ meson compile -C _build # Meson 0.55 and above
+$ ninja -C _build # Meson <0.55
$ sudo chvt 2
-$ sudo ./buffyboard
+$ sudo ./_build/buffyboard
```
## Fonts
diff --git a/find-lvgl-sources.sh b/find-lvgl-sources.sh
new file mode 100755
index 0000000..9516c69
--- /dev/null
+++ b/find-lvgl-sources.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+
+# Copyright 2021 Johannes Marbach
+#
+# This file is part of buffyboard, hereafter referred to as the program.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+
+while read -r makefile; do
+ while read -r expr; do
+ # Ignore example code
+ if [[ $(dirname $makefile) =~ .*/examples ]]; then
+ continue
+ fi
+
+ # Handle full & relative paths
+ if [[ $expr =~ .*\$\(LVGL_DIR ]]; then
+ expr=$(echo "$expr" \
+ | sed 's|$(LVGL_DIR)/||g' \
+ | sed 's|$(LVGL_DIR_NAME)/|lvgl/|g' \
+ | sed 's|$(LV_DRIVERS_DIR_NAME)/|lv_drivers/|g')
+ else
+ expr="$(dirname $makefile)/$expr"
+ fi
+
+ # Resolve $(wildcard ...)
+ expr=$(echo "$expr" | sed 's|$(wildcard\s*\(.*\))|\1|g')
+
+ # Resolve $(shell ...)
+ if [[ $expr =~ \$\(shell ]]; then
+ expr=$(echo "$expr" | sed 's|$(shell\s*\(.*\))|\1|g')
+ expr=$(eval "$expr")
+ fi
+
+ # Resolve wildcards
+ for file in $expr; do
+ echo $file
+ done
+ done < <(grep "^CSRCS\s*+=" "$makefile" | sed "s|.*=\s*||g")
+done < <(find "$1" -name "*.mk")
diff --git a/main.c b/main.c
index 63e4914..471d6d7 100644
--- a/main.c
+++ b/main.c
@@ -196,7 +196,7 @@ static void keyboard_value_changed_cb(lv_event_t *event) {
static void emit_key_events(uint16_t btn_id, bool key_down, bool key_up) {
int num_scancodes = 0;
- int *scancodes = sq2lv_get_scancodes(keyboard, btn_id, &num_scancodes);
+ const int *scancodes = sq2lv_get_scancodes(keyboard, btn_id, &num_scancodes);
if (key_down) {
/* Emit key down events in forward order */
@@ -215,7 +215,7 @@ static void emit_key_events(uint16_t btn_id, bool key_down, bool key_up) {
static void pop_checked_modifier_keys(void) {
int num_modifiers = 0;
- int *modifier_idxs = sq2lv_get_modifier_indexes(keyboard, &num_modifiers);
+ const int *modifier_idxs = sq2lv_get_modifier_indexes(keyboard, &num_modifiers);
for (int i = 0; i < num_modifiers; ++i) {
if (!lv_btnmatrix_has_btn_ctrl(keyboard, modifier_idxs[i], LV_BTNMATRIX_CTRL_CHECKED)) {
@@ -310,7 +310,6 @@ int main(void) {
#define MAX_TOUCHSCREENS 1
char *touchscreens[MAX_TOUCHSCREENS] = { NULL };
lv_indev_drv_t touchscreen_indev_drvs[MAX_TOUCHSCREENS];
- lv_indev_t *touchscreen_indevs[MAX_TOUCHSCREENS] = { NULL };
size_t num_touchscreens = libinput_find_devs(LIBINPUT_CAPABILITY_TOUCH, touchscreens, MAX_TOUCHSCREENS, false);
for (int i = 0; i < num_touchscreens; ++i) {
printf("Connecting touchscreen device %s\n", touchscreens[i]);
@@ -320,7 +319,7 @@ int main(void) {
touchscreen_indev_drvs[i].long_press_repeat_time = USHRT_MAX;
libinput_multi_init_driver(&touchscreen_indev_drvs[i]);
libinput_multi_set_file(&touchscreen_indev_drvs[i], touchscreens[i]);
- touchscreen_indevs[i] = lv_indev_drv_register(&touchscreen_indev_drvs[i]);
+ lv_indev_drv_register(&touchscreen_indev_drvs[i]);
}
/* Initialise theme and styles */
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..29f5a49
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,54 @@
+# Copyright 2021 Johannes Marbach
+#
+# This file is part of buffyboard, hereafter referred to as the program.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+
+project(
+ 'buffyboard',
+ 'c',
+ version: '0.0.0',
+ default_options: 'warning_level=1',
+ meson_version: '>=0.53.0'
+)
+
+buffyboard_sources = [
+ 'cursor.c',
+ 'main.c',
+ 'libinput_multi.c',
+ 'montserrat_extended_32.c',
+ 'sq2lv_layouts.c',
+ 'terminal.c',
+ 'uinput_device.c',
+]
+
+squeek2lvgl_sources = [
+ 'squeek2lvgl/sq2lv.c',
+]
+
+lvgl_sources = run_command('find-lvgl-sources.sh', 'lvgl').stdout().strip().split('\n')
+
+lv_drivers_sources = run_command('find-lvgl-sources.sh', 'lv_drivers').stdout().strip().split('\n')
+
+executable(
+ 'buffyboard',
+ sources: buffyboard_sources + squeek2lvgl_sources + lvgl_sources + lv_drivers_sources,
+ include_directories: ['lvgl', 'lv_drivers'],
+ dependencies: [
+ dependency('libinput'),
+ meson.get_compiler('c').find_library('m', required: false),
+ dependency('xkbcommon'),
+ ]
+)
diff --git a/uinput_device.c b/uinput_device.c
index 360ca89..4eb6c38 100644
--- a/uinput_device.c
+++ b/uinput_device.c
@@ -84,7 +84,7 @@ static bool uinput_device_synchronise() {
* Public functions
*/
-bool bb_uinput_device_init(int * const scancodes, int num_scancodes) {
+bool bb_uinput_device_init(const int * const scancodes, int num_scancodes) {
fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
if (fd < 0) {
perror("Could not open /dev/uinput");
diff --git a/uinput_device.h b/uinput_device.h
index ad892c2..24440f7 100644
--- a/uinput_device.h
+++ b/uinput_device.h
@@ -30,7 +30,7 @@
* @param num_scancodes number of scancodes the device can emit
* @return true if creating the device was successful, false otherwise
*/
-bool bb_uinput_device_init(int * const scancodes, int num_scancodes);
+bool bb_uinput_device_init(const int * const scancodes, int num_scancodes);
/**
* Emit a key down event