Skip to content
Snippets Groups Projects
Commit ebc8a44d authored by Dylan Van Assche's avatar Dylan Van Assche
Browse files

temp/feedbackd: device-specific feedbackd themes

Reads the compatible list from the kernel DTS file and tries to find
a suitable device specific configuration for providing haptic (and
later other) feedback on events
parent d135ba54
No related branches found
No related tags found
No related merge requests found
From 36fbaced41d8a99151b4f5f199a849ff60606d9c Mon Sep 17 00:00:00 2001
From: Dylan Van Assche <me@dylanvanassche.be>
Date: Thu, 24 Dec 2020 16:23:44 +0100
Subject: [PATCH] fbd-feedback-manager: Allow device-specific feedbackd themes
---
build-aux/post_install.py | 14 ++++++++
data/meson.build | 2 +-
meson.build | 5 +++
src/fbd-feedback-manager.c | 66 ++++++++++++++++++++++++++++++++++++--
4 files changed, 84 insertions(+), 3 deletions(-)
create mode 100644 build-aux/post_install.py
diff --git a/build-aux/post_install.py b/build-aux/post_install.py
new file mode 100644
index 0000000..bf5128c
--- /dev/null
+++ b/build-aux/post_install.py
@@ -0,0 +1,14 @@
+#!/usr/bin/python3
+
+import os
+import subprocess
+import sys
+
+destdir = os.environ.get('DESTDIR', '')
+
+if not destdir and len(sys.argv) > 1:
+ datadir = sys.argv[1]
+
+ print('Compiling gsettings schemas...')
+ subprocess.call(['glib-compile-schemas', os.path.join(datadir, 'glib-2.0', 'schemas')])
+
diff --git a/data/meson.build b/data/meson.build
index d90230e..1f4e809 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -53,7 +53,7 @@ install_data(
if json_glib_validate.found()
jsons = []
foreach theme : theme_json
- jsons += (join_paths(meson.current_source_dir(), theme_json))
+ jsons += (join_paths(meson.current_source_dir(), theme))
endforeach
custom_target('validate-json',
build_by_default: true,
diff --git a/meson.build b/meson.build
index 634eefe..54dac50 100644
--- a/meson.build
+++ b/meson.build
@@ -98,6 +98,11 @@ libname = 'libfeedback-' + apiversion
json_glib_validate = find_program('json-glib-validate', required: false)
+meson.add_install_script(
+ join_paths('build-aux', 'post_install.py'),
+ datadir
+)
+
subdir('data')
subdir('libfeedback')
subdir('src')
diff --git a/src/fbd-feedback-manager.c b/src/fbd-feedback-manager.c
index ef508c7..a75a226 100644
--- a/src/fbd-feedback-manager.c
+++ b/src/fbd-feedback-manager.c
@@ -18,13 +18,18 @@
#include <gio/gio.h>
#include <glib-unix.h>
#include <gudev/gudev.h>
+#include <stdio.h>
#define FEEDBACKD_SCHEMA_ID "org.sigxcpu.feedbackd"
#define FEEDBACKD_KEY_PROFILE "profile"
+#define FEEDBACKD_THEME_VAR "FEEDBACK_THEME"
#define APP_SCHEMA FEEDBACKD_SCHEMA_ID ".application"
#define APP_PREFIX "/org/sigxcpu/feedbackd/application/"
+#define DEVICE_TREE_PATH "/sys/firmware/devicetree/base/compatible"
+#define DEVICE_NAME_MAX 1024
+
/**
* SECTION:fbd-feedback-manager
@@ -352,6 +357,55 @@ fbd_feedback_manager_handle_end_feedback (LfbGdbusFeedback *object,
return TRUE;
}
+static gchar *
+find_themefile () {
+ gint i = 0;
+ gsize len;
+ const gchar *comp;
+ g_autoptr(GError) err = NULL;
+ gchar **xdg_data_dirs = (gchar **) g_get_system_data_dirs();
+ gchar *config_path = NULL;
+ gchar *compatibles = NULL;
+
+ // Try to read the device name
+ if (g_file_test(DEVICE_TREE_PATH, (G_FILE_TEST_EXISTS))) {
+ g_debug("Found device tree device compatible at %s", DEVICE_TREE_PATH);
+
+ // Check if feedbackd has a proper config available this device
+ if(!g_file_get_contents(DEVICE_TREE_PATH, &compatibles, &len, &err))
+ g_warning ("Unable to read: %s", err->message);
+
+ comp = compatibles;
+ while(comp - compatibles < len) {
+
+ // Iterate over $XDG_DATA_DIRS
+ for (i = 0; i < g_strv_length(xdg_data_dirs); i++) {
+ config_path = g_strconcat(xdg_data_dirs[i], "feedbackd/themes/", comp, ".json", NULL);
+ g_debug("Searching for device specific themefile in %s", config_path);
+
+ // Check if file exist
+ if (g_file_test(config_path, (G_FILE_TEST_EXISTS))) {
+ g_debug("Found themefile for this device at: %s", config_path);
+ return g_strdup(config_path);
+ }
+ }
+
+ // Next compatible
+ comp = strchr(comp, 0);
+ comp++;
+ }
+ }
+ else {
+ g_debug("Device tree path does not exist: %s", DEVICE_TREE_PATH);
+ }
+
+ // No path found, free all
+ g_free(compatibles);
+ g_free(config_path);
+
+ return NULL;
+}
+
static void
fbd_feedback_manager_constructed (GObject *object)
{
@@ -361,14 +415,22 @@ fbd_feedback_manager_constructed (GObject *object)
G_OBJECT_CLASS (fbd_feedback_manager_parent_class)->constructed (object);
- themefile = g_getenv ("FEEDBACK_THEME");
+ // Search for device-specific configuration
+ themefile = find_themefile ();
+
+ // Overide themefile with environment variable if requested
+ if (!themefile)
+ themefile = g_getenv(FEEDBACKD_THEME_VAR);
+
+ // Fallback to default configuration if needed
if (!themefile)
themefile = FEEDBACKD_THEME_DIR "/default.json";
+ g_info("Using themefile: %s", themefile);
self->theme = fbd_feedback_theme_new_from_file (themefile, &err);
if (!self->theme) {
/* No point to carry on */
- g_error ("Failed to load default theme: %s", err->message);
+ g_error ("Failed to load theme: %s", err->message);
}
g_signal_connect (self, "notify::profile", (GCallback)on_profile_changed, NULL);
--
2.26.2
# Forked from Alpine to provide a newer version
pkgname=feedbackd
pkgver=0_git20200726
pkgrel=0
pkgdesc="A daemon to provide haptic (and later more) feedback on events"
url="https://source.puri.sm/Librem5/feedbackd"
arch="all"
license="GPL-3.0-or-later"
depends="dbus"
makedepends="meson glib-dev gsound-dev libgudev-dev json-glib-dev gtk-doc
vala gobject-introspection-dev"
subpackages="$pkgname-dev"
source="https://source.puri.sm/Librem5/feedbackd/-/archive/v0.0.0+${pkgver#0_}/feedbackd-v0.0.0+${pkgver#0_}.tar.gz
0001-fbd-feedback-manager-Allow-device-specific-feedbackd.patch"
builddir="$srcdir/$pkgname-v0.0.0+${pkgver#0_}"
options="!check" # Tests fail in QEMU
build() {
abuild-meson \
-Dgtk_doc=false \
. output
meson compile ${JOBS:+-j ${JOBS}} -C output
}
check() {
meson test --no-rebuild -v -C output
}
package() {
DESTDIR="$pkgdir" meson install --no-rebuild -C output
install -Dm644 "$builddir"/debian/feedbackd.udev \
"$pkgdir"/usr/lib/udev/rules.d/90-feedbackd.rules
}
sha512sums="2a3e443c5f565dce7cdc25ade73934b5ab29c9efc6ceaa2d404111bfcd67fbc9b02893fc34559c8071aaba218686f2ba8109b2fd92a74e9f16955406ed6af6f6 feedbackd-v0.0.0+git20200726.tar.gz
65ff25262bd6a718c68f1eba911e8f79fe5a48bdc396c1f712039c2b18829e8f0b7307ebe85aeb378f19eabd0580ebc4321196118cfb3fb7710ea20d700b5054 0001-fbd-feedback-manager-Allow-device-specific-feedbackd.patch"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment