aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUnia <jthidskes@live.nl>2013-04-08 01:32:43 +0200
committerUnia <jthidskes@live.nl>2013-04-08 01:32:43 +0200
commit64c058fe2c99b31e7e4b5d35ce9bc6dd80af75af (patch)
tree805b6dd57071f021ae653269a4864842dc8f9f13
parent2dcd37fee61ee7f638f393dbf7684d960a30290d (diff)
added reset option
-rw-r--r--README.md5
-rw-r--r--gstopwatch.c23
2 files changed, 21 insertions, 7 deletions
diff --git a/README.md b/README.md
index d0c0825..ab07e27 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@ stopwatch will start counting, stop counting and reset.
Usage
-----
-The spacebar does it all! Press space to start timing, space to stop, space again to reset and space to start timing again.
+The spacebar does it all! Press space to start timing, space to pause, space again to continue and r to reset the timer when it is paused.
Installation
------------
@@ -35,6 +35,9 @@ ToDo
* Display text like gnome-clocks?
* Font size depend on available space?
* Add about dialog back in?
+* Add a timer function too, in GtkNotebook?
+* Keyboard shortcut to add/delete laps?
+* Clever lap deleting
License
-------
diff --git a/gstopwatch.c b/gstopwatch.c
index e09c2a6..0a910b1 100644
--- a/gstopwatch.c
+++ b/gstopwatch.c
@@ -4,7 +4,7 @@
#include <glib/gi18n.h>
gchar output[100];
-gint lap = 0;
+gint lap = 0, seconds;
GTimer *timer;
gboolean running;
GtkWidget *timer_display, *tree, *button_delete;
@@ -19,15 +19,19 @@ enum {
};
gboolean update_progress_bar (void) {
- gint hours, minutes, seconds = -1;
+ gint hours, minutes;
gchar *markup;
gulong gulong;
+ gdouble hseconds;
+ /*hseconds = g_timer_elapsed (timer, &gulong);
+ hseconds = */
seconds = g_timer_elapsed (timer, &gulong);
hours = seconds / 3600;
seconds -= 3600 * hours;
minutes = seconds / 60;
seconds -= 60 * minutes;
+ /*sprintf(output, "%02d:%02d:%02d:%.2f", hours, minutes, seconds, hseconds);*/
sprintf(output, "%02d:%02d:%02d", hours, minutes, seconds);
gtk_label_set_text(GTK_LABEL(timer_display), output);
@@ -40,12 +44,19 @@ gboolean update_progress_bar (void) {
gboolean start_timer (GtkWidget *widget, GdkEventKey *event) {
guint(g) = event->keyval;
- if((g == GDK_KEY_space)) {
- if(running == FALSE) {
- g_timer_start(timer);
+ if(running == FALSE) {
+ if((g == GDK_KEY_space)) {
+ g_timer_continue(timer);
running = TRUE;
return TRUE;
- } else {
+ } else if((g == GDK_KEY_r)) {
+ seconds = 0;
+ g_timer_reset(timer);
+ running = FALSE;
+ return TRUE;
+ }
+ } else if(running == TRUE) {
+ if((g == GDK_KEY_space)) {
g_timer_stop(timer);
running = FALSE;
return TRUE;