73 lines
2.5 KiB
C
73 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 diyac_server *server;
|
|
};
|
|
|
|
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 (inhibitor->server->idle_notifier) {
|
|
bool still_inhibited = wl_list_length(&inhibitor->server->idle_inhibitor_mngr->inhibitors) > 1;
|
|
wlr_idle_notifier_v1_set_inhibited(inhibitor->server->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)
|
|
{
|
|
struct wlr_idle_inhibitor_v1 *wlr_inhibitor = data;
|
|
struct diyac_server *server = wl_container_of(listener, server, idle_inhibitor_new);
|
|
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;
|
|
inhibitor->server = server;
|
|
wl_signal_add(&wlr_inhibitor->events.destroy, &inhibitor->on_inhibitor_destroy);
|
|
|
|
wlr_idle_notifier_v1_set_inhibited(server->idle_notifier, true);
|
|
}
|
|
|
|
void diyac_init_idle_manager(struct diyac_server *server)
|
|
{
|
|
server->idle_notifier = wlr_idle_notifier_v1_create(server->wl_display);
|
|
server->idle_inhibitor_mngr = wlr_idle_inhibit_v1_create(server->wl_display);
|
|
|
|
server->idle_inhibitor_new.notify = handle_idle_inhibitor_new;
|
|
wl_signal_add(&server->idle_inhibitor_mngr->events.new_inhibitor,&server->idle_inhibitor_new);
|
|
|
|
//g_idle_mngr.on_display_destroy.notify = handle_display_destroy;
|
|
//wl_display_add_destroy_listener(display, &g_idle_mngr.on_display_destroy);
|
|
}
|
|
|
|
void diyac_idle_manager_notify_activity(struct diyac_seat *seat)
|
|
{
|
|
if (seat->server->idle_notifier) {
|
|
wlr_idle_notifier_v1_notify_activity(seat->server->idle_notifier, seat->wlr_seat);
|
|
}
|
|
}
|
|
|
|
void diyac_release_idle_manager(struct diyac_server *server)
|
|
{
|
|
wl_list_remove(&server->idle_inhibitor_new.link);
|
|
} |