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
27 #include <X11/Intrinsic.h>
31 #define countof(x) (sizeof((x))/sizeof(*(x)))
35 char *progclass = "XScreenSaver";
41 time_t now = time ((time_t *) 0);
42 char *ct = (char *) ctime (&now);
43 int n = strlen(progname);
45 strncpy(buf, progname, n);
48 strncpy(buf+n, ct+11, 8);
49 strcpy(buf+n+9, ": ");
54 apm_cb (XtPointer closure, int *fd, XtInputId *id)
56 apm_event_t events[100];
58 while ((n = apm_get_events (*fd, 0, events, countof(events)))
60 for (i = 0; i < n; i++)
62 fprintf (stderr, "%s: APM event 0x%x: %s.\n", blurb(),
63 events[i], apm_event_name (events[i]));
68 case APM_USER_STANDBY:
70 case APM_USER_SUSPEND:
71 case APM_CRITICAL_SUSPEND:
79 main (int argc, char **argv)
82 Widget toplevel_shell = XtAppInitialize (&app, progclass, 0, 0,
83 &argc, argv, 0, 0, 0);
84 Display *dpy = XtDisplay (toplevel_shell);
87 XtGetApplicationNameAndClass (dpy, &progname, &progclass);
92 fprintf (stderr, "%s: couldn't initialize APM.\n", blurb());
96 id = XtAppAddInput(app, fd,
97 (XtPointer) (XtInputReadMask | XtInputWriteMask),