/* timers.c --- detecting when the user is idle, and other timer-related tasks.
- * xscreensaver, Copyright (c) 1991-1997, 1998
- * Jamie Zawinski <jwz@jwz.org>
+ * xscreensaver, Copyright (c) 1991-2002 Jamie Zawinski <jwz@jwz.org>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
# include "config.h"
#endif
-/* #define DEBUG_TIMERS */
-
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
si->timer_id = XtAppAddTimeOut (si->app, when, idle_timer,
(XtPointer) si);
-#ifdef DEBUG_TIMERS
if (verbose_p)
fprintf (stderr, "%s: starting idle_timer (%ld, %ld)\n",
blurb(), when, si->timer_id);
-#endif /* DEBUG_TIMERS */
}
*/
XSelectInput (si->dpy, window, SubstructureNotifyMask | events);
- if (top_p && p->verbose_p && (events & KeyPressMask))
+ if (top_p && p->debug_p && (events & KeyPressMask))
{
/* Only mention one window per tree (hack hack). */
fprintf (stderr, "%s: %d: selected KeyPress on 0x%lX\n",
si->cycle_id = XtAppAddTimeOut (si->app, how_long, cycle_timer,
(XtPointer) si);
-# ifdef DEBUG_TIMERS
- if (p->verbose_p)
+ if (p->debug_p)
fprintf (stderr, "%s: starting cycle_timer (%ld, %ld)\n",
blurb(), how_long, si->cycle_id);
-# endif /* DEBUG_TIMERS */
}
-# ifdef DEBUG_TIMERS
else
{
- if (p->verbose_p)
+ if (p->debug_p)
fprintf (stderr, "%s: not starting cycle_timer: how_long == %d\n",
blurb(), how_long);
}
-# endif /* DEBUG_TIMERS */
}
if (si->timer_id)
{
-#ifdef DEBUG_TIMERS
- if (p->verbose_p)
+ if (p->debug_p)
fprintf (stderr, "%s: killing idle_timer (%ld, %ld)\n",
blurb(), p->timeout, si->timer_id);
-#endif /* DEBUG_TIMERS */
XtRemoveTimeOut (si->timer_id);
}
- schedule_wakeup_event (si, p->timeout, p->verbose_p); /* sets si->timer_id */
+ schedule_wakeup_event (si, p->timeout, p->debug_p); /* sets si->timer_id */
if (si->cycle_id) abort (); /* no cycle timer when inactive */
active_p = True;
-#ifdef DEBUG_TIMERS
- if (p->verbose_p)
+ if (p->debug_p)
{
if (root_x == ssi->poll_mouse_last_root_x &&
root_y == ssi->poll_mouse_last_root_y &&
}
}
-#endif /* DEBUG_TIMERS */
-
si->last_activity_screen = ssi;
ssi->poll_mouse_last_root_x = root_x;
ssi->poll_mouse_last_root_y = root_y;
si->using_proc_interrupts &&
proc_interrupts_activity_p (si))
{
-# ifdef DEBUG_TIMERS
- if (p->verbose_p)
- fprintf (stderr, "%s: /proc/interrupts activity at %s.\n",
- blurb(), timestring());
-# endif /* DEBUG_TIMERS */
active_p = True;
}
#endif /* HAVE_PROC_INTERRUPTS */
time_t now = time ((time_t *) 0);
long shift = now - si->last_wall_clock_time;
-#ifdef DEBUG_TIMERS
- if (p->verbose_p)
+ if (p->debug_p)
{
int i = (si->last_wall_clock_time == 0 ? 0 : shift);
fprintf (stderr,
blurb(),
(i / (60 * 60)), ((i / 60) % 60), (i % 60));
}
-#endif /* DEBUG_TIMERS */
if (si->last_wall_clock_time != 0 &&
shift > (p->timeout / 1000))
is economical: for example, if the screensaver should come on in 5
minutes, and the user has been idle for 2 minutes, then this
timeout will go off no sooner than 3 minutes from now. */
- schedule_wakeup_event (si, p->timeout, p->verbose_p);
+ schedule_wakeup_event (si, p->timeout, p->debug_p);
if (polling_mouse_position)
/* Check to see if the mouse has moved, and set up a repeating timer
yet been idle for long enough. So re-signal the event.
*/
if (polling_for_idleness)
- schedule_wakeup_event (si, p->timeout - idle, p->verbose_p);
+ schedule_wakeup_event (si, p->timeout - idle, p->debug_p);
}
}
break;
if (scanning_all_windows)
{
Window w = event.xcreatewindow.window;
-#ifdef DEBUG_TIMERS
- start_notice_events_timer (si, w, p->verbose_p);
-#else /* !DEBUG_TIMERS */
- start_notice_events_timer (si, w, False);
-#endif /* !DEBUG_TIMERS */
+ start_notice_events_timer (si, w, p->debug_p);
}
break;
case ButtonRelease:
case MotionNotify:
-#ifdef DEBUG_TIMERS
- if (p->verbose_p)
+ if (p->debug_p)
{
Window root, window;
int x, y;
fprintf (stderr, " at %d,%d.\n", x, y);
}
}
-#endif /* DEBUG_TIMERS */
/* If any widgets want to handle this event, let them. */
dispatch_event (si, &event);
static char last_kbd_line[255] = { 0, };
static char last_ptr_line[255] = { 0, };
char new_line[sizeof(last_kbd_line)];
- Bool got_kbd = False, kbd_diff = False;
- Bool got_ptr = False, ptr_diff = False;
+ Bool checked_kbd = False, kbd_changed = False;
+ Bool checked_ptr = False, ptr_changed = False;
if (!f0)
{
while (fgets (new_line, sizeof(new_line)-1, f1))
{
- if (!got_kbd && strstr (new_line, "keyboard"))
+ if (!checked_kbd && strstr (new_line, "keyboard"))
{
- kbd_diff = (*last_kbd_line && !!strcmp (new_line, last_kbd_line));
+ kbd_changed = (*last_kbd_line && !!strcmp (new_line, last_kbd_line));
strcpy (last_kbd_line, new_line);
- got_kbd = True;
+ checked_kbd = True;
}
- else if (!got_ptr && strstr (new_line, "PS/2 Mouse"))
+ else if (!checked_ptr && strstr (new_line, "PS/2 Mouse"))
{
- ptr_diff = (*last_ptr_line && !!strcmp (new_line, last_ptr_line));
+ ptr_changed = (*last_ptr_line && !!strcmp (new_line, last_ptr_line));
strcpy (last_ptr_line, new_line);
- got_ptr = True;
+ checked_ptr = True;
}
- if (got_kbd && got_ptr)
+ if (checked_kbd && checked_ptr)
break;
}
- if (got_kbd || got_ptr)
+ if (checked_kbd || checked_ptr)
{
fclose (f1);
- return (kbd_diff || ptr_diff);
+
+ if (si->prefs.debug_p && (kbd_changed || ptr_changed))
+ fprintf (stderr, "%s: /proc/interrupts activity: %s\n",
+ blurb(),
+ ((kbd_changed && ptr_changed) ? "mouse and kbd" :
+ kbd_changed ? "kbd" :
+ ptr_changed ? "mouse" : "ERR"));
+
+ return (kbd_changed || ptr_changed);
}
if (si->dbox_up_p)
{
-#ifdef DEBUG_TIMERS
- if (si->prefs.verbose_p)
+ if (si->prefs.debug_p)
fprintf (stderr, "%s: dialog box is up: not raising screen.\n",
blurb());
-#endif /* DEBUG_TIMERS */
}
else
{
-#ifdef DEBUG_TIMERS
- if (si->prefs.verbose_p)
+ if (si->prefs.debug_p)
fprintf (stderr, "%s: watchdog timer raising %sscreen.\n",
blurb(), (running_p ? "" : "and clearing "));
-#endif /* DEBUG_TIMERS */
raise_window (si, True, True, running_p);
}
si->watchdog_id = XtAppAddTimeOut (si->app, p->watchdog_timeout,
watchdog_timer, (XtPointer) si);
-#ifdef DEBUG_TIMERS
- if (p->verbose_p)
+ if (p->debug_p)
fprintf (stderr, "%s: restarting watchdog_timer (%ld, %ld)\n",
blurb(), p->watchdog_timeout, si->watchdog_id);
-#endif /* DEBUG_TIMERS */
-
}
}