[drwright] Account for idle time when starting a typing break
- From: Christopher Aillon <caillon src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [drwright] Account for idle time when starting a typing break
- Date: Mon, 21 Feb 2011 02:15:31 +0000 (UTC)
commit dca6f0e2f0677acae7eb43b62e8aecba1d94787d
Author: Christopher Aillon <caillon redhat com>
Date: Sat Feb 19 20:02:25 2011 -0800
Account for idle time when starting a typing break
If the user has been idle for a while when the typing break starts, it
should be taken into account. Otherwise, we can get into a situation
where 8 minutes before a 10 minute break starts, the user goes idle,
and returns to the computer to find out they still have a full break
remaining.
However, buffer the elapsed time at intervals of 30s in order to avoid
starting the break at seemingly random times. This way, we will start
at times such as 5:30 or 6:00 instead of something like 5:43.
GNOME Bug 642788
src/drw-break-window.c | 19 ++++++++++++++++---
src/drw-break-window.h | 2 ++
src/drwright.c | 3 +++
3 files changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/src/drw-break-window.c b/src/drw-break-window.c
index 749e506..57d7a39 100644
--- a/src/drw-break-window.c
+++ b/src/drw-break-window.c
@@ -49,9 +49,10 @@ struct _DrwBreakWindowPrivate {
guint clock_timeout_id;
guint postpone_timeout_id;
guint postpone_sensitize_id;
- guint postpone_delay;
+ guint postpone_delay;
+ gint elapsed_idle_time;
- GSettings *settings;
+ GSettings *settings;
};
#define DRW_BREAK_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DRW_TYPE_BREAK_WINDOW, DrwBreakWindowPrivate))
@@ -60,6 +61,8 @@ struct _DrwBreakWindowPrivate {
#define POSTPONE_CANCEL 30
+#define ELAPSED_IDLE_INTERVAL 30 /* s */
+
/* Signals */
enum {
DONE,
@@ -138,6 +141,8 @@ drw_break_window_init (DrwBreakWindow *window)
allow_postpone = g_settings_get_boolean (priv->settings, "allow-postpone");
priv->postpone_delay = POSTPONE_DELAY;
+ priv->elapsed_idle_time = 0;
+
gtk_window_set_keep_above (GTK_WINDOW (window), TRUE);
gtk_window_fullscreen (GTK_WINDOW (window));
gtk_window_set_modal (GTK_WINDOW (window), TRUE);
@@ -319,6 +324,14 @@ drw_break_window_new (void)
return GTK_WIDGET (object);
}
+void
+drw_break_window_set_elapsed_idle_time (DrwBreakWindow *window, gint seconds)
+{
+ /* account for elapsed idle time in blocks of ELAPSED_IDLE_INTERVAL */
+ window->priv->elapsed_idle_time =
+ (seconds / ELAPSED_IDLE_INTERVAL) * ELAPSED_IDLE_INTERVAL;
+}
+
static gboolean
postpone_sensitize_cb (DrwBreakWindow *window)
{
@@ -344,7 +357,7 @@ clock_timeout_cb (DrwBreakWindow *window)
priv = window->priv;
- seconds = priv->break_time - drw_timer_elapsed (priv->timer);
+ seconds = priv->break_time - drw_timer_elapsed (priv->timer) - priv->elapsed_idle_time;
seconds = MAX (0, seconds);
if (seconds == 0) {
diff --git a/src/drw-break-window.h b/src/drw-break-window.h
index a856cd3..b6b038b 100644
--- a/src/drw-break-window.h
+++ b/src/drw-break-window.h
@@ -49,6 +49,8 @@ struct _DrwBreakWindowClass {
GType drw_break_window_get_type (void) G_GNUC_CONST;
GtkWidget * drw_break_window_new (void);
+void drw_break_window_set_elapsed_idle_time (DrwBreakWindow *window,
+ gint seconds);
G_END_DECLS
diff --git a/src/drwright.c b/src/drwright.c
index a17b540..9d41f88 100644
--- a/src/drwright.c
+++ b/src/drwright.c
@@ -423,6 +423,9 @@ maybe_change_state (DrWright *dr)
dr->break_window = drw_break_window_new ();
+ drw_break_window_set_elapsed_idle_time (DRW_BREAK_WINDOW (dr->break_window),
+ elapsed_idle_time);
+
g_signal_connect (dr->break_window, "map_event",
G_CALLBACK (break_window_map_event_cb),
dr);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]