This patch does 2 things: 1) Defines a DrwTimer that we use instead of GTimer. This is just a thin wrapper around g_get_current_time, and it means we can accurately track typing/idle periods based on real-world wall-clock time, which GTimer is apparently not intended to do. 2) The typing monitor has some complicated state handling where it transitions between an IDLE state and a TYPING state. This transition is based on running a callback once per second, and checking whether any keystrokes have been recorded since the last time the callback was called. The actual idle *time* is tracked separately, independently of these two states, but only when we are in the IDLE *state* was the idle *time* checked to see if we should reset the break timer. This leads to a race condition -- if we suspend while in the TYPING state, then eventually we will wake up, notice that no key press has happened in the last second, *reset the idle timer*, transition to the IDLE state, and then check the amount of time on the idle timer. We will thus never notice the amount of time that the computer was suspended. I considered making the IDLE/TYPING transition code smarter, but it turns out the desired behavior for the two states is entirely identical anyway, so rather than adding more complexity to this pointless code, I just diked it out and replaced them both by a single state called RUNNING. Closes bug #430797.
42 lines
1.6 KiB
C
42 lines
1.6 KiB
C
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
|
/*
|
|
* Copyright (C) 2009 Nathaniel Smith <njs@pobox.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License as
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
* License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public
|
|
* License along with this program; if not, write to the
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
* Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
#ifndef __DRW_TIMER_H__
|
|
#define __DRW_TIMER_H__
|
|
|
|
/*
|
|
* This file defines a timer interface similar to GTimer, but defined in real
|
|
* wall-clock time. A GTimer may stop counting while the computer is suspended
|
|
* or the process is stopped:
|
|
* https://bugzilla.gnome.org/show_bug.cgi?id=552994
|
|
* but a DrwTimer keeps counting regardless.
|
|
*
|
|
* Currently this only provides second resolution as compared to GTimer's
|
|
* microsecond resolution, but a typing break program doesn't really need
|
|
* microsecond resolution anyway.
|
|
*/
|
|
|
|
typedef struct _DrwTimer DrwTimer;
|
|
DrwTimer * drw_timer_new ();
|
|
void drw_timer_start (DrwTimer *timer);
|
|
double drw_timer_elapsed (DrwTimer *timer);
|
|
void drw_timer_destroy (DrwTimer *timer);
|
|
|
|
#endif /* __DRW_TIMER_H__ */
|