static gboolean maybe_change_state (DrWright *dr) { gint elapsed_time; gint elapsed_idle_time; if (debug) { g_timer_reset (dr->idle_timer); } elapsed_time = g_timer_elapsed (dr->timer, NULL); elapsed_idle_time = g_timer_elapsed (dr->idle_timer, NULL); if (elapsed_time > dr->last_elapsed_time + dr->warn_time) { /* If the timeout is delayed by the amount of warning time, then * we must have been suspended or stopped, so we just start * over. */ dr->state = STATE_START; } switch (dr->state) { case STATE_START: if (dr->break_window) { gtk_widget_destroy (dr->break_window); dr->break_window = NULL; } gtk_status_icon_set_from_pixbuf (dr->icon, dr->neutral_bar); g_timer_start (dr->timer); g_timer_start (dr->idle_timer); if (dr->enabled) { dr->state = STATE_IDLE; } update_tooltip (dr); stop_blinking (dr); break; case STATE_IDLE: if (elapsed_idle_time >= dr->break_time) { g_timer_start (dr->timer); g_timer_start (dr->idle_timer); } else if (dr->is_active) { dr->state = STATE_TYPE; } break; case STATE_TYPE: if (elapsed_time >= dr->type_time - dr->warn_time) { dr->state = STATE_WARN_TYPE; g_timer_start (dr->timer); start_blinking (dr); } else if (elapsed_time >= dr->type_time) { dr->state = STATE_BREAK_SETUP; } else if (!dr->is_active) { dr->state = STATE_IDLE; g_timer_start (dr->idle_timer); } break; case STATE_WARN_TYPE: if (elapsed_time >= dr->warn_time) { dr->state = STATE_BREAK_SETUP; } else if (!dr->is_active) { dr->state = STATE_WARN_IDLE; } break; case STATE_WARN_IDLE: if (elapsed_idle_time >= dr->break_time) { dr->state = STATE_BREAK_DONE_SETUP; } else if (dr->is_active) { dr->state = STATE_WARN_TYPE; } break; case STATE_BREAK_SETUP: /* Don't allow more than one break window to coexist, can happen * if a break is manually enforced. */ if (dr->break_window) { dr->state = STATE_BREAK; break; } stop_blinking (dr); gtk_status_icon_set_from_pixbuf (dr->icon, dr->red_bar); g_timer_start (dr->timer); dr->break_window = drw_break_window_new (); g_signal_connect (dr->break_window, "map_event", G_CALLBACK (break_window_map_event_cb), dr); g_signal_connect (dr->break_window, "done", G_CALLBACK (break_window_done_cb), dr); g_signal_connect (dr->break_window, "postpone", G_CALLBACK (break_window_postpone_cb), dr); g_signal_connect (dr->break_window, "destroy", G_CALLBACK (break_window_destroy_cb), dr); dr->secondary_break_windows = create_secondary_break_windows (); gtk_widget_show (dr->break_window); dr->state = STATE_BREAK; break; case STATE_BREAK: if (elapsed_time >= dr->break_time) { dr->state = STATE_BREAK_DONE_SETUP; } break; case STATE_BREAK_DONE_SETUP: stop_blinking (dr); gtk_status_icon_set_from_pixbuf (dr->icon, dr->green_bar); dr->state = STATE_BREAK_DONE; break; case STATE_BREAK_DONE: if (dr->is_active) { dr->state = STATE_START; if (dr->break_window) { gtk_widget_destroy (dr->break_window); dr->break_window = NULL; } } break; } dr->is_active = FALSE; dr->last_elapsed_time = elapsed_time; update_icon (dr); return TRUE; }
static gboolean maybe_change_state (DrWright *dr) { gint elapsed_time; gint elapsed_idle_time; if (debug) { drw_timer_start (dr->idle_timer); } elapsed_time = drw_timer_elapsed (dr->timer) + dr->save_last_time; elapsed_idle_time = drw_timer_elapsed (dr->idle_timer); if (elapsed_time > dr->last_elapsed_time + dr->warn_time) { /* If the timeout is delayed by the amount of warning time, then * we must have been suspended or stopped, so we just start * over. */ dr->state = STATE_START; } switch (dr->state) { case STATE_START: if (dr->break_window) { gtk_widget_destroy (dr->break_window); dr->break_window = NULL; } #ifndef HAVE_APP_INDICATOR gtk_status_icon_set_from_pixbuf (dr->icon, dr->neutral_bar); #endif /* HAVE_APP_INDICATOR */ dr->save_last_time = 0; drw_timer_start (dr->timer); drw_timer_start (dr->idle_timer); if (dr->enabled) { dr->state = STATE_RUNNING; } update_status (dr); stop_blinking (dr); break; case STATE_RUNNING: case STATE_WARN: if (elapsed_idle_time >= dr->break_time) { dr->state = STATE_BREAK_DONE_SETUP; } else if (elapsed_time >= dr->type_time) { dr->state = STATE_BREAK_SETUP; } else if (dr->state != STATE_WARN && elapsed_time >= dr->type_time - dr->warn_time) { dr->state = STATE_WARN; start_blinking (dr); } break; case STATE_BREAK_SETUP: /* Don't allow more than one break window to coexist, can happen * if a break is manually enforced. */ if (dr->break_window) { dr->state = STATE_BREAK; break; } stop_blinking (dr); #ifndef HAVE_APP_INDICATOR gtk_status_icon_set_from_pixbuf (dr->icon, dr->red_bar); #endif /* HAVE_APP_INDICATOR */ drw_timer_start (dr->timer); dr->break_window = drw_break_window_new (); g_signal_connect (dr->break_window, "map_event", G_CALLBACK (break_window_map_event_cb), dr); g_signal_connect (dr->break_window, "done", G_CALLBACK (break_window_done_cb), dr); g_signal_connect (dr->break_window, "postpone", G_CALLBACK (break_window_postpone_cb), dr); g_signal_connect (dr->break_window, "destroy", G_CALLBACK (break_window_destroy_cb), dr); dr->secondary_break_windows = create_secondary_break_windows (); gtk_widget_show (dr->break_window); dr->save_last_time = elapsed_time; dr->state = STATE_BREAK; break; case STATE_BREAK: if (elapsed_time - dr->save_last_time >= dr->break_time) { dr->state = STATE_BREAK_DONE_SETUP; } break; case STATE_BREAK_DONE_SETUP: stop_blinking (dr); #ifndef HAVE_APP_INDICATOR gtk_status_icon_set_from_pixbuf (dr->icon, dr->green_bar); #endif /* HAVE_APP_INDICATOR */ dr->state = STATE_BREAK_DONE; break; case STATE_BREAK_DONE: dr->state = STATE_START; if (dr->break_window) { gtk_widget_destroy (dr->break_window); dr->break_window = NULL; } break; } dr->last_elapsed_time = elapsed_time; #ifdef HAVE_APP_INDICATOR update_app_indicator (dr); #else update_icon (dr); #endif /* HAVE_APP_INDICATOR */ return TRUE; }
static gboolean maybe_change_state (DrWright *dr) { gint elapsed_time; gint elapsed_idle_time; if (debug) { drw_timer_start (dr->idle_timer); } elapsed_time = drw_timer_elapsed (dr->timer) + dr->save_last_time; elapsed_idle_time = drw_timer_elapsed (dr->idle_timer); if (elapsed_time > dr->last_elapsed_time + dr->warn_time) { /* If the timeout is delayed by the amount of warning time, then * we must have been suspended or stopped, so we just start * over. */ dr->state = STATE_START; } switch (dr->state) { case STATE_START: if (dr->break_window) { gtk_widget_destroy (dr->break_window); dr->break_window = NULL; } dr->save_last_time = 0; drw_timer_start (dr->timer); drw_timer_start (dr->idle_timer); show_warning_notification (dr, FALSE); if (dr->enabled) { dr->state = STATE_RUNNING; } break; case STATE_RUNNING: case STATE_WARN: if (elapsed_idle_time >= dr->break_time) { dr->state = STATE_BREAK_DONE_SETUP; } else if (elapsed_time >= dr->type_time) { dr->state = STATE_BREAK_SETUP; } else if (dr->state != STATE_WARN && elapsed_time >= dr->type_time - dr->warn_time) { dr->state = STATE_WARN; } if (dr->state == STATE_WARN) { show_warning_notification (dr, TRUE); } break; case STATE_BREAK_SETUP: /* Don't allow more than one break window to coexist, can happen * if a break is manually enforced. */ if (dr->break_window) { dr->state = STATE_BREAK; break; } show_warning_notification (dr, FALSE); drw_timer_start (dr->timer); dr->break_window = drw_break_window_new (drwright_can_lock_screen (dr)); 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); g_signal_connect (dr->break_window, "done", G_CALLBACK (break_window_done_cb), dr); g_signal_connect (dr->break_window, "postpone", G_CALLBACK (break_window_postpone_cb), dr); g_signal_connect (dr->break_window, "lock", G_CALLBACK (break_window_lock_cb), dr); g_signal_connect (dr->break_window, "destroy", G_CALLBACK (break_window_destroy_cb), dr); dr->secondary_break_windows = create_secondary_break_windows (); gtk_widget_show (dr->break_window); dr->save_last_time = elapsed_time; dr->state = STATE_BREAK; break; case STATE_BREAK: if (elapsed_time - dr->save_last_time >= dr->break_time) { dr->state = STATE_BREAK_DONE_SETUP; } break; case STATE_BREAK_DONE_SETUP: dr->state = STATE_BREAK_DONE; break; case STATE_BREAK_DONE: dr->state = STATE_START; if (dr->break_window) { gtk_widget_destroy (dr->break_window); dr->break_window = NULL; } break; } dr->last_elapsed_time = elapsed_time; return TRUE; }