File idle_detect.spec of Package idle_detect
# SPDX-License-Identifier: MIT
%define _name idle_detect
# Using project name also for package name, adjust if needed
# --- Basic Package Information ---
Name: %{_name}
Version: 0.8.3.0c
Release: 0
Summary: System and User services to detect user idle time and activity
License: MIT
URL: https://github.com/jamescowens/idle_detect
Source: %{name}-%{version}.tar.gz
# --- Build Dependencies ---
%if 0%{?suse_version} && 0%{?suse_version} <= 1560
# We need at least GCC13
BuildRequires: gcc13-c++
%else
BuildRequires: gcc-c++
%endif
BuildRequires: cmake >= 3.15
BuildRequires: pkgconfig
# Core deps based on CMakeLists.txt and code
BuildRequires: pkgconfig(libevdev) >= 1.0
BuildRequires: pkgconfig(xscrnsaver) >= 1.1
BuildRequires: pkgconfig(dbus-1) >= 1.6
BuildRequires: pkgconfig(glib-2.0) >= 2.56
BuildRequires: pkgconfig(gobject-2.0) >= 2.56
BuildRequires: pkgconfig(gio-2.0) >= 2.56
# BuildRequires: pkgconfig(libX11-dev)
BuildRequires: pkgconfig(wayland-client)
BuildRequires: pkgconfig(wayland-protocols) >= 1.17
# BuildRequires: wayland-scanner
# For systemd macros and service file installation path
BuildRequires: systemd-rpm-macros
# --- Runtime Dependencies (Auto-detection usually works) ---
Requires: systemd
# --- Description ---
%description
This package provides two services for monitoring user activity on Linux systems,
primarily intended for controlling background tasks like Distributed Computing
(e.g., BOINC).
* event_detect: A system service that monitors low-level input devices (mice),
TTY access times, and messages from idle_detect instances via a named pipe.
It provides an aggregated 'last active time' via shmem or file.
* idle_detect: A user service that detects graphical session idle time using
X11 (XScreenSaver), KDE D-Bus (ksmserver), or GNOME D-Bus (Mutter) methods,
accounting for application inhibitions where possible (currently KDE). It can
report activity to event_detect and optionally run commands on state changes.
# --- Preparation ---
%prep
%autosetup -p1
# --- Build ---
%build
%if 0%{?suse_version} && 0%{?suse_version} <= 1560
export CC='gcc-13'
export CXX='g++-13'
%endif
%cmake
%cmake_build
# --- Installation ---
%install
%cmake_install
# --- Scriptlets for System Service and User/Group ---
%pre
getent group event_detect >/dev/null || groupadd -r event_detect
getent passwd event_detect >/dev/null || useradd -r -g event_detect -d / -s /sbin/nologin -c "Event Detect Service User" event_detect
getent group input >/dev/null || groupadd -r input
getent group tty >/dev/null || groupadd -r tty
usermod -aG input event_detect || :
usermod -aG tty event_detect || :
exit 0
%post
# Reload systemd manager config and enable/start service after install
%systemd_post dc_event_detection.service
# On a fresh install ($1 == 1), explicitly start the service.
# On an upgrade ($1 == 2), the service would have been restarted by the
# %postun_with_restart of the *old* package if it was running.
if [ "$1" -eq 1 ]; then
# Use 'try-restart' which starts the service if it's not running.
# The '|| :' part ensures the script doesn't fail if this command returns an error.
systemctl try-restart dc_event_detection.service >/dev/null 2>&1 || :
fi
%preun
# Disable/stop service before uninstall
%systemd_preun dc_event_detection.service
%postun
# Reload systemd manager config after uninstall
%systemd_postun_with_restart dc_event_detection.service
# --- File List ---
%files
# Binaries
%{_bindir}/event_detect
%{_bindir}/idle_detect
%{_bindir}/read_shmem_timestamps
%{_bindir}/idle_detect_wrapper.sh
%{_bindir}/dc_pause
%{_bindir}/dc_unpause
%{_bindir}/force_state.sh
%{_bindir}/event_detect_control.sh
%{_bindir}/idle_detect_resources.sh
%{_bindir}/idle_detect_new_user_setup.sh
# System Config File (marked as config, don't replace user changes on upgrade)
%config(noreplace) %{_sysconfdir}/event_detect.conf
# Systemd System Service File
%{_unitdir}/dc_event_detection.service
# Systemd System Preset File
%{_presetdir}/90-event-detect.preset
# Systemd Default User Service File
%{_userunitdir}/dc_idle_detection.service
# Systemd Default User Preset File
%{_userpresetdir}/90-idle-detect.preset
# Own the directory first with %dir
%dir %{_datadir}/idle_detect
# Default user configuration template for first-run logic
%{_datadir}/idle_detect/idle_detect.conf.default
# Add the XDG autostart file
%{_sysconfdir}/xdg/autostart/idle-detect-autostart.desktop
# License File (ensure filename matches)
%license LICENSE.md
# Documentation Files (README, etc.)
%doc README.md
# Man pages (if generated and installed by CMake)
%{_mandir}/man3/*
%{_docdir}/*
# --- Changelog ---
%changelog
* Tue Aug 19 2025 James C. Owens <jamesowens@optonline.net> - %{version}-%{release}
- See https://github.com/jamescowens/idle_detect/releases/tag/0.8.3.0.
* Sun Aug 10 2025 James C. Owens <jamesowens@optonline.net> - %{version}-%{release}
- Implemented service templates to properly deal with different paths for package install versus local compile install
* Sun Apr 27 2025 James C. Owens <jamesowens@optonline.net> - %{version}-%{release}
- Implemented ext-idle-detect-v1 monitor for Non-KDE, Non-Gnome Wayland sessions
* Sun Apr 20 2025 James C. Owens <jamesowens@optonline.net> - %{version}-%{release}
- See https://github.com/jamescowens/idle_detect/releases/tag/0.8.0.0.
* Mon Apr 14 2025 James C. Owens <jamesowens@optonline.net> - %{version}-%{release}
- First draft packaging for OBS