diff --git a/linux/ibus-keyman/meson.build b/linux/ibus-keyman/meson.build index 5a8958e983f..8082814a6ce 100644 --- a/linux/ibus-keyman/meson.build +++ b/linux/ibus-keyman/meson.build @@ -8,9 +8,17 @@ conf = configuration_data() ibus = dependency('ibus-1.0', version: '>= 1.2.0') gtk = dependency('gtk+-3.0', version: '>= 2.4') json_glib = dependency('json-glib-1.0', version: '>= 1.0') -systemd = dependency('libsystemd') icu = dependency('icu-i18n') +systemd = dependency('libsystemd', 'libelogind', required: false) +if systemd.found() + conf.set('DBUS_IMPLEMENTATION', 'SYSTEMD') +else + # Gentoo can use libelogind or basu + systemd = dependency('basu', required: true) + conf.set('DBUS_IMPLEMENTATION', 'BASU') +endif + core_dir = meson.current_source_dir() / '../../core' common_dir = meson.current_source_dir() / '../../common' diff --git a/linux/ibus-keyman/src/KeymanSystemServiceClient.cpp b/linux/ibus-keyman/src/KeymanSystemServiceClient.cpp index 635c3ff22dd..50dbccba8d6 100644 --- a/linux/ibus-keyman/src/KeymanSystemServiceClient.cpp +++ b/linux/ibus-keyman/src/KeymanSystemServiceClient.cpp @@ -1,5 +1,10 @@ +#include "config.h" #include +#if DBUS_IMPLEMENTATION == SYSTEMD #include +#else +#include +#endif #include "KeymanSystemServiceClient.h" #define KEYMAN_BUS_NAME "com.keyman.SystemService1" diff --git a/linux/ibus-keyman/tests/KmDbusTestServer.cpp b/linux/ibus-keyman/tests/KmDbusTestServer.cpp index e64a9354d8b..fda2a12c005 100644 --- a/linux/ibus-keyman/tests/KmDbusTestServer.cpp +++ b/linux/ibus-keyman/tests/KmDbusTestServer.cpp @@ -1,9 +1,14 @@ // DBus test server. The server will start and listen on a non-standard DBus. // It runs until the DBus Exit method gets called. +#include "config.h" #include #include #include +#if DBUS_IMPLEMENTATION == SYSTEMD #include +#else +#include +#endif #ifndef KEYMAN_TEST_SERVICE_PATH #warning KEYMAN_TEST_SERVICE_PATH is undefined @@ -73,7 +78,10 @@ KmDbusTestServer::~KmDbusTestServer() { if (bus) sd_bus_release_name(bus, KEYMAN_TESTSVC_BUS_NAME); if (slot) sd_bus_slot_unref(slot); - if (bus) sd_bus_close_unref(bus); + if (bus) { + sd_bus_close(bus); + sd_bus_unref(bus); + } g_test_dbus_down(dbus); g_object_unref(dbus); diff --git a/linux/ibus-keyman/tests/StopTestServer.cpp b/linux/ibus-keyman/tests/StopTestServer.cpp index 97ce5bfbe7f..2790e5b30ef 100644 --- a/linux/ibus-keyman/tests/StopTestServer.cpp +++ b/linux/ibus-keyman/tests/StopTestServer.cpp @@ -1,8 +1,13 @@ // Call the Exit method on the km-dbus-test-server. Remember to source // `/tmp/km-test-server.env` prior to running stop-test-server in order // to run on our non-standard DBus. +#include "config.h" #include +#if DBUS_IMPLEMENTATION == SYSTEMD #include +#else +#include +#endif using namespace std; diff --git a/linux/ibus-keyman/tests/meson.build b/linux/ibus-keyman/tests/meson.build index 73ce8d84d08..cad98974161 100644 --- a/linux/ibus-keyman/tests/meson.build +++ b/linux/ibus-keyman/tests/meson.build @@ -38,6 +38,7 @@ dbus_test_server = executable( 'km-dbus-test-server', 'KmDbusTestServer.cpp', dependencies: dbus_deps, + include_directories: ['..'], cpp_args: [ '-DKEYMAN_TEST_SERVICE_PATH="' + system_service_dir + '"' ] @@ -47,6 +48,7 @@ stop_test_server = executable( 'stop-test-server', 'StopTestServer.cpp', dependencies: dbus_deps, + include_directories: ['..'], ) env_file = '/tmp/env.txt' diff --git a/linux/keyman-system-service/meson.build b/linux/keyman-system-service/meson.build index 66da8f98914..ec3c0c2d181 100644 --- a/linux/keyman-system-service/meson.build +++ b/linux/keyman-system-service/meson.build @@ -3,8 +3,21 @@ project('keyman-system-service', 'c', 'cpp', license: 'GPL-2+', meson_version: '>=0.61') +conf = configuration_data() + evdev = dependency('libevdev', version: '>= 1.9') -systemd = dependency('libsystemd') + +systemd = dependency('libsystemd', 'libelogind', required: false) +if systemd.found() + conf.set('DBUS_IMPLEMENTATION', 'SYSTEMD') +else + # Gentoo can use libelogind or basu + systemd = dependency('basu', required: true) + conf.set('DBUS_IMPLEMENTATION', 'BASU') +endif + +configure_file(output : 'config.h', + configuration : conf) subdir('resources') subdir('src') diff --git a/linux/keyman-system-service/resources/com.keyman.SystemService1.service.basu b/linux/keyman-system-service/resources/com.keyman.SystemService1.service.basu new file mode 100644 index 00000000000..67dd16eb5ad --- /dev/null +++ b/linux/keyman-system-service/resources/com.keyman.SystemService1.service.basu @@ -0,0 +1,7 @@ +# /usr/share/dbus-1/system-services/com.keyman.SystemService1.service +# This version used with elogind and basu (e.g. on Gentoo) + +[D-BUS Service] +Name=com.keyman.SystemService1 +Exec=/usr/libexec/systemd-keyman.service +User=root diff --git a/linux/keyman-system-service/resources/com.keyman.SystemService1.service b/linux/keyman-system-service/resources/com.keyman.SystemService1.service.systemd similarity index 78% rename from linux/keyman-system-service/resources/com.keyman.SystemService1.service rename to linux/keyman-system-service/resources/com.keyman.SystemService1.service.systemd index 3966fb1bbcb..65acc4067a4 100644 --- a/linux/keyman-system-service/resources/com.keyman.SystemService1.service +++ b/linux/keyman-system-service/resources/com.keyman.SystemService1.service.systemd @@ -1,4 +1,5 @@ # /usr/share/dbus-1/system-services/com.keyman.SystemService1.service +# This version used with systemd (e.g. on Debian) [D-BUS Service] Name=com.keyman.SystemService1 diff --git a/linux/keyman-system-service/resources/meson.build b/linux/keyman-system-service/resources/meson.build index c28cb81e585..663a3c558ab 100644 --- a/linux/keyman-system-service/resources/meson.build +++ b/linux/keyman-system-service/resources/meson.build @@ -1,3 +1,10 @@ install_data('com.keyman.SystemService1.conf', install_dir: get_option('datadir') / 'dbus-1/system.d/') -install_data('com.keyman.SystemService1.service', install_dir: get_option('datadir') / 'dbus-1/system-services/') + +if systemd.name() == 'libsystemd' + install_data('com.keyman.SystemService1.service.systemd', install_dir: get_option('datadir') / 'dbus-1/system-services/', rename: ['com.keyman.SystemService1.service']) +else + # libelogind or basu + install_data('com.keyman.SystemService1.service.basu', install_dir: get_option('datadir') / 'dbus-1/system-services/') +endif + install_data('systemd-keyman.service', install_dir: get_option('prefix') / 'lib/systemd/system/') diff --git a/linux/keyman-system-service/src/KeymanSystemService.cpp b/linux/keyman-system-service/src/KeymanSystemService.cpp index deceafd0c39..03d7add5334 100644 --- a/linux/keyman-system-service/src/KeymanSystemService.cpp +++ b/linux/keyman-system-service/src/KeymanSystemService.cpp @@ -2,6 +2,7 @@ // based on the sd-bus library, see // https://0pointer.net/blog/the-new-sd-bus-api-of-systemd.html +#include "config.h" #include #include #include @@ -11,7 +12,11 @@ #include #include #include +#if DBUS_IMPLEMENTATION == SYSTEMD #include +#else +#include +#endif #include "KeymanSystemService.h" #include "KeyboardDevice.h" diff --git a/linux/keyman-system-service/src/KeymanSystemService.h b/linux/keyman-system-service/src/KeymanSystemService.h index 2686bfb99f9..86637f27a96 100644 --- a/linux/keyman-system-service/src/KeymanSystemService.h +++ b/linux/keyman-system-service/src/KeymanSystemService.h @@ -1,8 +1,13 @@ #ifndef __KEYMANSYSTEMSERVICE_H__ #define __KEYMANSYSTEMSERVICE_H__ +#include "config.h" #include +#if DBUS_IMPLEMENTATION == SYSTEMD #include +#else +#include +#endif #include "KeyboardDevice.h" using namespace std; diff --git a/linux/keyman-system-service/src/meson.build b/linux/keyman-system-service/src/meson.build index 51820ab9fa9..3c3dd27fa6e 100644 --- a/linux/keyman-system-service/src/meson.build +++ b/linux/keyman-system-service/src/meson.build @@ -10,6 +10,7 @@ exe = executable( 'keyman-system-service', sources: [service_files], dependencies: deps, + include_directories: ['..'], install: true, install_dir: get_option('libexecdir'), ) diff --git a/linux/keyman-system-service/tests/meson.build b/linux/keyman-system-service/tests/meson.build index f90e12d16a2..749e098591e 100644 --- a/linux/keyman-system-service/tests/meson.build +++ b/linux/keyman-system-service/tests/meson.build @@ -17,7 +17,7 @@ exe = executable( c_args: test_c_args, cpp_args: test_c_args, dependencies: deps, - include_directories: [ '../src' ] + include_directories: [ '..', '../src' ] ) # we currently don't have any unit tests for keyman-system-service.