1 /* test-apm.c --- playing with the APM library.
2 * xscreensaver, Copyright (c) 1999 Jamie Zawinski <jwz@jwz.org>
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation. No representations are made about the suitability of this
9 * software for any purpose. It is provided "as is" without express or
26 #include <X11/Intrinsic.h>
30 #define countof(x) (sizeof((x))/sizeof(*(x)))
34 char *progclass = "XScreenSaver";
40 time_t now = time ((time_t *) 0);
41 char *ct = (char *) ctime (&now);
42 int n = strlen(progname);
44 strncpy(buf, progname, n);
47 strncpy(buf+n, ct+11, 8);
48 strcpy(buf+n+9, ": ");
53 apm_cb (XtPointer closure, int *fd, XtInputId *id)
55 apm_event_t events[100];
57 while ((n = apm_get_events (*fd, 0, events, countof(events)))
59 for (i = 0; i < n; i++)
61 fprintf (stderr, "%s: APM event 0x%x: %s.\n", blurb(),
62 events[i], apm_event_name (events[i]));
67 case APM_USER_STANDBY:
69 case APM_USER_SUSPEND:
70 case APM_CRITICAL_SUSPEND:
78 main (int argc, char **argv)
81 Widget toplevel_shell = XtAppInitialize (&app, progclass, 0, 0,
82 &argc, argv, 0, 0, 0);
83 Display *dpy = XtDisplay (toplevel_shell);
86 XtGetApplicationNameAndClass (dpy, &progname, &progclass);
91 fprintf (stderr, "%s: couldn't initialize APM.\n", blurb());
95 id = XtAppAddInput(app, fd,
96 (XtPointer) (XtInputReadMask | XtInputWriteMask),