AtlatestRepositorysigil-wm

sigil-wm / tree / testidle-client.c

1/* SPDX-License-Identifier: BSD-3-Clause */
2#include <stdint.h>
3#include <stdio.h>
4#include <stdlib.h>
5#include <string.h>
6#include <wayland-client.h>
7#include "ext-idle-notify-v1-client-protocol.h"
8struct client {
9 struct ext_idle_notifier_v1 *notifier;
10 struct wl_seat *seat;
11};
12static void idled(void *data,struct ext_idle_notification_v1 *notification) {
13 (void)data; (void)notification;
14 puts("IDLE_EVENT=idle"); fflush(stdout);
16static void resumed(void *data,struct ext_idle_notification_v1 *notification) {
17 (void)data; (void)notification;
18 puts("IDLE_EVENT=resume"); fflush(stdout);
20static const struct ext_idle_notification_v1_listener notification_listener={
21 .idled=idled,.resumed=resumed,
22};
23static void global(void *data,struct wl_registry *registry,uint32_t name,const char *interface,uint32_t version) {
24 (void)version;
25 struct client *client=data;
26 if(!strcmp(interface,ext_idle_notifier_v1_interface.name))
27 client->notifier=wl_registry_bind(registry,name,&ext_idle_notifier_v1_interface,1);
28 else if(!strcmp(interface,wl_seat_interface.name))
29 client->seat=wl_registry_bind(registry,name,&wl_seat_interface,1);
31static void removed(void *data,struct wl_registry *registry,uint32_t name) {
32 (void)data; (void)registry; (void)name;
34static const struct wl_registry_listener registry_listener={.global=global,.global_remove=removed};
35int main(int argc,char **argv) {
36 if(argc!=2) return 2;
37 char *end;
38 unsigned long timeout=strtoul(argv[1],&end,10);
39 if(*end || timeout<1 || timeout>60000) return 2;
40 struct wl_display *display=wl_display_connect(NULL);
41 if(!display) return 3;
42 struct client client={0};
43 struct wl_registry *registry=wl_display_get_registry(display);
44 wl_registry_add_listener(registry,&registry_listener,&client);
45 if(wl_display_roundtrip(display)<0 || !client.notifier || !client.seat) return 4;
46 struct ext_idle_notification_v1 *notification=
47 ext_idle_notifier_v1_get_idle_notification(client.notifier,timeout,client.seat);
48 ext_idle_notification_v1_add_listener(notification,&notification_listener,NULL);
49 puts("IDLE_READY=1"); fflush(stdout);
50 while(wl_display_dispatch(display)>=0) {}
51 wl_display_disconnect(display);
52 return 0;