meta: restructure project for a modular architechture for more interfaces

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I16f88f649bddad572e0d44cee7e0edec6a6a6964
This commit is contained in:
raf 2026-04-13 11:23:40 +03:00
commit 087f28d726
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
22 changed files with 2494 additions and 0 deletions

View file

@ -0,0 +1,8 @@
#ifndef DBUS_CINNAMON_SCREENSAVER_H
#define DBUS_CINNAMON_SCREENSAVER_H
#include "inhibit-interface.h"
InhibitInterface *dbus_cinnamon_screensaver_create(void);
#endif

40
include/dbus-common.h Normal file
View file

@ -0,0 +1,40 @@
#ifndef DBUS_COMMON_H
#define DBUS_COMMON_H
#include "inhibit-interface.h"
#include <stdarg.h>
#include <systemd/sd-bus.h>
typedef enum {
DBUS_MODE_NONE,
DBUS_MODE_IMPLEMENT, // we own the D-Bus name
DBUS_MODE_MONITOR // we monitor via BecomeMonitor
} DBusMode;
typedef struct {
sd_bus *bus;
DBusMode mode;
char *bus_name;
char *object_path;
char *interface_name;
sd_bus_slot *slot;
InhibitInterface *parent;
} DBusService;
int dbus_service_init(DBusService *svc, const char *bus_name,
const char *object_path, const char *interface_name);
void dbus_service_cleanup(DBusService *svc);
int dbus_service_detect_mode(DBusService *svc);
int dbus_service_claim_name(DBusService *svc);
int dbus_service_become_monitor(DBusService *svc, const char **match_rules,
int num_rules);
int dbus_service_poll(DBusService *svc);
int dbus_parse_inhibit_request(sd_bus_message *m, char **app_name,
char **reason);
int dbus_send_signal(DBusService *svc, const char *signal_name,
const char *signature, ...);
#endif

View file

@ -0,0 +1,8 @@
#ifndef DBUS_POWERMANAGER_H
#define DBUS_POWERMANAGER_H
#include "inhibit-interface.h"
InhibitInterface *dbus_freedesktop_powermanager_create(void);
#endif

View file

@ -0,0 +1,9 @@
#ifndef DBUS_SCREENSAVER_H
#define DBUS_SCREENSAVER_H
#include "dbus-common.h"
#include "inhibit-interface.h"
InhibitInterface *dbus_freedesktop_screensaver_create(void);
#endif

View file

@ -0,0 +1,8 @@
#ifndef DBUS_GNOME_SCREENSAVER_H
#define DBUS_GNOME_SCREENSAVER_H
#include "inhibit-interface.h"
InhibitInterface *dbus_gnome_screensaver_create(void);
#endif

View file

@ -0,0 +1,8 @@
#ifndef DBUS_GNOME_SESSION_H
#define DBUS_GNOME_SESSION_H
#include "inhibit-interface.h"
InhibitInterface *dbus_gnome_session_create(void);
#endif

View file

@ -0,0 +1,8 @@
#ifndef DBUS_MATE_SCREENSAVER_H
#define DBUS_MATE_SCREENSAVER_H
#include "inhibit-interface.h"
InhibitInterface *dbus_mate_screensaver_create(void);
#endif

View file

@ -0,0 +1,8 @@
#ifndef DBUS_SYSTEMD_LOGIN1_H
#define DBUS_SYSTEMD_LOGIN1_H
#include "inhibit-interface.h"
InhibitInterface *dbus_systemd_login1_create(void);
#endif

103
include/inhibit-interface.h Normal file
View file

@ -0,0 +1,103 @@
#ifndef INHIBIT_INTERFACE_H
#define INHIBIT_INTERFACE_H
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#define MAX_INTERFACES 16
#define MAX_INHIBITS_PER_INTERFACE 64
#define INHIBIT_ID_LEN 64
typedef enum {
INHIBIT_TYPE_SCREENSAVER = 1 << 0,
INHIBIT_TYPE_SUSPEND = 1 << 1,
INHIBIT_TYPE_IDLE = 1 << 2,
INHIBIT_TYPE_ALL =
INHIBIT_TYPE_SCREENSAVER | INHIBIT_TYPE_SUSPEND | INHIBIT_TYPE_IDLE
} InhibitType;
typedef enum {
INHIBIT_FLAG_NONE = 0,
INHIBIT_FLAG_FORWARDED = 1 << 0,
INHIBIT_FLAG_LOOP_DETECTED = 1 << 1
} InhibitFlags;
typedef struct {
char id[INHIBIT_ID_LEN];
InhibitType type;
char app_name[256];
char reason[1024];
InhibitFlags flags;
uint64_t cookie;
void *interface_data;
} InhibitEntry;
typedef struct {
InhibitEntry entry;
int interface_idx;
char forwarded_to[MAX_INTERFACES][INHIBIT_ID_LEN];
int num_forwarded;
} TrackedInhibit;
typedef struct InhibitInterface InhibitInterface;
typedef void (*InhibitEventCallback)(InhibitInterface *source,
const InhibitEntry *entry, int is_inhibit);
struct InhibitInterface {
const char *name;
int enabled;
int (*init)(InhibitInterface *iface);
void (*cleanup)(InhibitInterface *iface);
int (*inhibit)(InhibitInterface *iface, InhibitType type,
const char *app_name, const char *reason,
InhibitEntry *out_entry);
int (*uninhibit)(InhibitInterface *iface, const InhibitEntry *entry);
int (*poll)(InhibitInterface *iface);
void (*set_callback)(InhibitInterface *iface, InhibitEventCallback cb);
void *private_data;
};
typedef struct {
InhibitInterface *interfaces[MAX_INTERFACES];
int num_interfaces;
TrackedInhibit inhibits[MAX_INTERFACES * MAX_INHIBITS_PER_INTERFACE];
int num_inhibits;
InhibitEventCallback event_callback;
} InhibitManager;
int inhibit_manager_init(InhibitManager *mgr);
void inhibit_manager_cleanup(InhibitManager *mgr);
int inhibit_manager_register(InhibitManager *mgr, InhibitInterface *iface);
void inhibit_manager_set_callback(InhibitManager *mgr, InhibitEventCallback cb);
int inhibit_manager_forward_inhibit(InhibitManager *mgr,
InhibitInterface *source,
const InhibitEntry *entry);
int inhibit_manager_forward_uninhibit(InhibitManager *mgr,
InhibitInterface *source,
const InhibitEntry *entry);
TrackedInhibit *inhibit_manager_find(InhibitManager *mgr,
InhibitInterface *source, const char *id);
int inhibit_manager_add_tracked(InhibitManager *mgr, InhibitInterface *source,
const InhibitEntry *entry);
void inhibit_manager_remove_tracked(InhibitManager *mgr,
InhibitInterface *source, const char *id);
void inhibit_manager_poll_all(InhibitManager *mgr);
const char *inhibit_type_to_string(InhibitType type);
InhibitType inhibit_type_from_string(const char *str);
#endif

View file

@ -0,0 +1,8 @@
#ifndef KERNEL_WAKELOCK_H
#define KERNEL_WAKELOCK_H
#include "inhibit-interface.h"
InhibitInterface *kernel_wakelock_create(void);
#endif

18
include/shell-command.h Normal file
View file

@ -0,0 +1,18 @@
#ifndef SHELL_COMMAND_H
#define SHELL_COMMAND_H
#include "inhibit-interface.h"
typedef struct {
char *screensaver_inhibit;
char *screensaver_uninhibit;
char *suspend_inhibit;
char *suspend_uninhibit;
char *any_inhibit;
char *any_uninhibit;
} ShellCommandConfig;
InhibitInterface *shell_command_create(const ShellCommandConfig *config);
void shell_command_config_free(ShellCommandConfig *config);
#endif

8
include/xidlehook.h Normal file
View file

@ -0,0 +1,8 @@
#ifndef XIDLEHOOK_H
#define XIDLEHOOK_H
#include "inhibit-interface.h"
InhibitInterface *xidlehook_create(const char *socket_path);
#endif