Skip to content
Snippets Groups Projects
Commit b0c228ba authored by Bart Ribbers's avatar Bart Ribbers
Browse files

community/plasma-bigscreen: enable CEC input support

parent f553c775
No related branches found
No related tags found
1 merge request!28711community/plasma-bigscreen: enable CEC input support
Pipeline #103678 passed
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ecdf04e..8ad1961 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -64,6 +64,8 @@ plasma_install_package(lookandfeel org.kde.plasma.mycroft.bigscreen look-and-fee
install(FILES bin/mycroft-skill-launcher.py DESTINATION ${BIN_INSTALL_DIR})
+install(FILES bin/cec-daemon.py DESTINATION ${BIN_INSTALL_DIR})
+install(FILES bin/40-uinput.rules DESTINATION ${LIB_INSTALL_DIR}/udev/rules.d)
if(ECM_VERSION VERSION_GREATER_EQUAL 5.79)
include(KDEClangFormat)
diff --git a/bin/40-uinput.rules b/bin/40-uinput.rules
new file mode 100644
index 0000000..918e0a7
--- /dev/null
+++ b/bin/40-uinput.rules
@@ -0,0 +1 @@
+SUBSYSTEM=="misc", KERNEL=="uinput", MODE="0660", GROUP="video"
diff --git a/bin/CMakeLists.txt b/bin/CMakeLists.txt
index 2f1bb3b..85eee3b 100644
--- a/bin/CMakeLists.txt
+++ b/bin/CMakeLists.txt
@@ -1,6 +1,12 @@
configure_file(plasma-bigscreen-wayland.in ${CMAKE_CURRENT_BINARY_DIR}/plasma-bigscreen-wayland)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/plasma-bigscreen-wayland DESTINATION ${BIN_INSTALL_DIR})
+configure_file(cec-daemon.desktop.cmake ${CMAKE_CURRENT_BINARY_DIR}/cec-daemon.desktop)
+install(FILES
+ ${CMAKE_CURRENT_BINARY_DIR}/cec-daemon.desktop
+ DESTINATION ${KDE_INSTALL_SYSCONFDIR}/xdg/autostart
+)
+
configure_file(plasma-bigscreen-wayland.desktop.cmake ${CMAKE_CURRENT_BINARY_DIR}/plasma-bigscreen-wayland.desktop)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/plasma-bigscreen-wayland.desktop
diff --git a/bin/cec-daemon.desktop.cmake b/bin/cec-daemon.desktop.cmake
new file mode 100644
index 0000000..2435539
--- /dev/null
+++ b/bin/cec-daemon.desktop.cmake
@@ -0,0 +1,5 @@
+[Desktop Entry]
+Exec=${CMAKE_INSTALL_FULL_BINDIR}/cec-daemon.py
+Name=CEC Daemon
+Description=Allows input using TV remote controls through the CEC protocol
+X-KDE-PluginInfo-Version=${PROJECT_VERSION}
diff --git a/bin/cec-daemon.py b/bin/cec-daemon.py
new file mode 100755
index 0000000..b731970
--- /dev/null
+++ b/bin/cec-daemon.py
@@ -0,0 +1,95 @@
+#!/usr/bin/python3
+
+import cec
+import uinput
+import time
+import psutil
+
+u = uinput
+
+KEYMAP = {
+ 0: u.KEY_ENTER,
+ 1: u.KEY_UP,
+ 2: u.KEY_DOWN,
+ 3: u.KEY_LEFT,
+ 4: u.KEY_RIGHT,
+ 9: u.KEY_HOMEPAGE,
+ 10: u.KEY_MENU,
+ 13: u.KEY_BACK,
+ 44: u.KEY_HOMEPAGE,
+ 68: u.KEY_PLAY,
+ 69: u.KEY_STOP,
+ 70: u.KEY_PAUSE,
+ 75: u.KEY_FASTFORWARD,
+ 76: u.KEY_REWIND,
+ 103: u.KEY_HOMEPAGE,
+ 113: u.KEY_BLUE,
+ 114: u.KEY_RED,
+ 115: u.KEY_YELLOW,
+ 116: u.KEY_GREEN
+}
+
+device = uinput.Device(KEYMAP.values())
+
+keystate = None
+override = False
+
+
+def check_override():
+ global override
+ if "kodi-x11" in (p.name() for p in psutil.process_iter()):
+ override = True
+ else:
+ override = False
+
+
+def init_cec():
+ cecconfig = cec.libcec_configuration()
+ cecconfig.strDeviceName = "libcec"
+ cecconfig.bActivateSource = 0
+ cecconfig.deviceTypes.Add(cec.CEC_DEVICE_TYPE_RECORDING_DEVICE)
+ cecconfig.clientVersion = cec.LIBCEC_VERSION_CURRENT
+
+ cecconfig.SetKeyPressCallback(keypress_callback)
+
+ lib = cec.ICECAdapter.Create(cecconfig)
+ adapters = lib.DetectAdapters()
+ returned_adapter = None
+
+ # Wait till we get a CEC device
+ while returned_adapter is None:
+ for adapter in adapters:
+ print("Found a CEC adapter:")
+ print("Port: " + adapter.strComName)
+ print("Vendor: " + hex(adapter.iVendorId))
+ print("Product: " + hex(adapter.iProductId))
+ returned_adapter = adapter.strComName
+
+ if lib.Open(returned_adapter):
+ print("Connection opened")
+
+ main_loop()
+
+
+def main_loop():
+ while True:
+ # Just make sure we live forever
+ time.sleep(9e9)
+
+
+def keypress_callback(key, duration):
+ global keystate
+
+ if override:
+ return
+
+ if keystate is None:
+ device.emit(KEYMAP[key], 1)
+ keystate = "down"
+ else:
+ device.emit(KEYMAP[key], 0)
+ keystate = None
+
+
+if __name__ == '__main__':
+ init_cec()
......@@ -2,7 +2,7 @@
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=plasma-bigscreen
pkgver=0_git20211219
pkgrel=0
pkgrel=1
_commit="1f44b4a1c5b0c16e47a40a8ad0c03305ea275806"
pkgdesc="A 10-feet interface made for TVs"
url="https://invent.kde.org/plasma/plasma-bigscreen/"
......@@ -18,6 +18,8 @@ depends="
plasma-pa
plasma-settings
plasma-workspace
py3-libcec
py3-uinput
"
makedepends="
extra-cmake-modules
......@@ -37,7 +39,10 @@ makedepends="
qt5-qtdeclarative-dev
qt5-qtmultimedia-dev
"
source="https://invent.kde.org/plasma/plasma-bigscreen/-/archive/$_commit/plasma-bigscreen-$_commit.tar.gz"
source="https://invent.kde.org/plasma/plasma-bigscreen/-/archive/$_commit/plasma-bigscreen-$_commit.tar.gz
0001-cec-daemon.patch
uinput.conf
"
builddir="$srcdir/plasma-bigscreen-$_commit"
build() {
......@@ -55,8 +60,13 @@ check() {
package() {
DESTDIR="$pkgdir" cmake --install build
install -Dm644 -t "$pkgdir"/etc/modules-load.d \
"$srcdir"/uinput.conf
}
sha512sums="
3e3841658ff84650c2a491f22a28d0afec557d4ed781ef1adf4d37db85da57e23037ae5a99dc2014a2f23d792477644fb119119929d5e825e32d62954d126af4 plasma-bigscreen-1f44b4a1c5b0c16e47a40a8ad0c03305ea275806.tar.gz
8c96e9bac10ddddfe07300b3a08a67d06fbffc1e775047ffc855537765e4843d1dbc56c26040ee2a15ff97099866ca2ae497f1c7dcd01b6568ccb5d485671b09 0001-cec-daemon.patch
a9b069ed121ffeee887e0583d8cb46035ecf1fa90a26a4ecb3aa11ff03178b2b08621f6676db6b2350f290694c04aabcf36f2ce3e0813a76dde9a33555edb112 uinput.conf
"
uinput
diff --git a/libsuinput/src/suinput.c b/libsuinput/src/suinput.c
index 8d5fb71..8c368e6 100644
--- a/libsuinput/src/suinput.c
+++ b/libsuinput/src/suinput.c
@@ -28,6 +28,14 @@
#include "suinput.h"
+#ifndef input_event_sec
+#define input_event_sec time.tv_sec
+#endif
+
+#ifndef input_event_usec
+#define input_event_usec time.tv_usec
+#endif
+
int suinput_write_event(int uinput_fd, const struct input_event *event_p)
{
ssize_t bytes;
@@ -43,9 +51,12 @@ int suinput_emit(int uinput_fd, uint16_t ev_type, uint16_t ev_code,
int32_t ev_value)
{
struct input_event event;
+ struct timeval tv;
memset(&event, 0, sizeof(event));
- gettimeofday(&event.time, 0);
+ gettimeofday(&tv, 0);
+ event.input_event_sec = tv.tv_sec;
+ event.input_event_usec = tv.tv_usec;
event.type = ev_type;
event.code = ev_code;
event.value = ev_value;
......@@ -13,7 +13,9 @@ makedepends="
linux-headers
py3-setuptools
"
source="https://pypi.python.org/packages/source/p/python-uinput/python-uinput-$pkgver.tar.gz"
source="https://pypi.python.org/packages/source/p/python-uinput/python-uinput-$pkgver.tar.gz
0001-fix-32bit-build.patch
"
builddir="$srcdir/python-uinput-$pkgver"
build() {
......@@ -26,4 +28,5 @@ package() {
sha512sums="
47cf878c57da8117010caa3ccbdfe8ee96106b2c7164639c779ea16be05eed2ffea0341c14738c7491ff98827f756772944783d560a747b4b011c76e77693fda python-uinput-0.11.2.tar.gz
3c5d3b39fa5cd6f44700fb767dd351d90cfb0efe50d5e1eb10f3e214ddd998acb71117e86acae66288ca3bae4b704368d9406ac603e612ae23c475ed7e6e5532 0001-fix-32bit-build.patch
"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment