Files
diyac/idle.c
DanyLE 194b7894cd feat: add support to two new wayland protocols
- Idle notify
- Idle inhibit
2025-07-07 16:37:23 +02:00

77 lines
2.5 KiB
C

#include "diyac.h"
#include "idle.h"
#include <stdlib.h>
#include <wlr/types/wlr_idle_notify_v1.h>
#include <wlr/types/wlr_idle_inhibit_v1.h>
struct diya_idle_inhibitor
{
struct wlr_idle_inhibitor_v1 *wlr_inhibitor;
struct wl_listener on_inhibitor_destroy;
};
struct diya_idle_mngr
{
struct wlr_idle_inhibit_manager_v1 *wlr_inhibitor_mngr;
struct wl_listener on_new_inhibitor;
struct wlr_idle_notifier_v1 *wlr_idle_notifier;
// struct wl_listener on_display_destroy;
};
static struct diya_idle_mngr g_idle_mngr;
static void handle_idle_inhibitor_destroy(struct wl_listener *listener, void *data)
{
(void) data;
struct diya_idle_inhibitor *inhibitor = wl_container_of(listener, inhibitor, on_inhibitor_destroy);
if (g_idle_mngr.wlr_idle_notifier) {
bool still_inhibited = wl_list_length(&g_idle_mngr.wlr_inhibitor_mngr->inhibitors) > 1;
wlr_idle_notifier_v1_set_inhibited(g_idle_mngr.wlr_idle_notifier, still_inhibited);
}
wl_list_remove(&inhibitor->on_inhibitor_destroy.link);
free(inhibitor);
}
/*
static void handle_display_destroy(struct wl_listener *listener, void *data)
{
(void) data;
(void) listener;
wl_list_remove(&g_idle_mngr.on_display_destroy.link);
g_idle_mngr.wlr_idle_notifier = NULL;
}
*/
static void handle_idle_inhibitor_new(struct wl_listener *listener, void *data)
{
(void) listener;
struct wlr_idle_inhibitor_v1 *wlr_inhibitor = data;
struct diya_idle_inhibitor *inhibitor = malloc(sizeof(struct diya_idle_inhibitor));
inhibitor->wlr_inhibitor = wlr_inhibitor;
inhibitor->on_inhibitor_destroy.notify = handle_idle_inhibitor_destroy;
wl_signal_add(&wlr_inhibitor->events.destroy, &inhibitor->on_inhibitor_destroy);
wlr_idle_notifier_v1_set_inhibited(g_idle_mngr.wlr_idle_notifier, true);
}
void diya_init_idle_manager(struct wl_display *display)
{
g_idle_mngr.wlr_idle_notifier = wlr_idle_notifier_v1_create(display);
g_idle_mngr.wlr_inhibitor_mngr = wlr_idle_inhibit_v1_create(display);
g_idle_mngr.on_new_inhibitor.notify = handle_idle_inhibitor_new;
wl_signal_add(&g_idle_mngr.wlr_inhibitor_mngr->events.new_inhibitor,&g_idle_mngr.on_new_inhibitor);
//g_idle_mngr.on_display_destroy.notify = handle_display_destroy;
//wl_display_add_destroy_listener(display, &g_idle_mngr.on_display_destroy);
}
void diya_idle_manager_notify_activity(struct wlr_seat *seat)
{
if (g_idle_mngr.wlr_idle_notifier) {
wlr_idle_notifier_v1_notify_activity(g_idle_mngr.wlr_idle_notifier, seat);
}
}