diff options
author | Calvin Morrison <mutantturkey@gmail.com> | 2013-01-04 01:36:55 -0500 |
---|---|---|
committer | Calvin Morrison <mutantturkey@gmail.com> | 2013-01-04 01:36:55 -0500 |
commit | 4a28d65be97cc25959e9bae1f0422bc11a2462d5 (patch) | |
tree | e158a8e72a91337dfa05fc23bb3b10294bcb3011 |
Initial commit of gstopwatch
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | README.md | 23 | ||||
-rw-r--r-- | gstopwatch.c | 62 |
3 files changed, 90 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d5c8c54 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +gstopwatch: + gcc gstopwatch.c `pkg-config --cflags --libs gtk+-2.0` -o gstopwatch + +clean: + rm -vf gstopwatch diff --git a/README.md b/README.md new file mode 100644 index 0000000..dfc88f5 --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ += gstopwatch = + +Okay, so apparently there are absolutely zero good stopwatches around for X11! +I spent my time searching but couldn't find one simple enough for me. This +stopwatch will start counting, stop counting, and reset, a like the simple +pocket stopwatch I had growing up. + +== Usage == + +press space to start timing, space to stop, space again to reset and start +timing again. + + +== Building == + +You'll need the gtk 2.x libraries and headers installed and ready to go. to +build, simple run make in the gstopwatch folder + +== To Do == + +* Laps +* Hours:Minutes:Seconds display +* Font size diff --git a/gstopwatch.c b/gstopwatch.c new file mode 100644 index 0000000..ce7d327 --- /dev/null +++ b/gstopwatch.c @@ -0,0 +1,62 @@ +#include <gtk/gtk.h> +#include <gdk/gdkkeysyms.h> +#include <glib.h> + +gboolean running; +GtkWidget *hbox; +GtkWidget *timer_display; +GtkWidget *window; +GTimer *timer; + +void update_progress_bar () { + gulong gulong; + gdouble time_elapsed = g_timer_elapsed (timer, &gulong); + char *output; + + sprintf(output, "%.2f", time_elapsed); + + gtk_label_set_text(GTK_LABEL(timer_display), output); +} + +gboolean keypress (GtkWidget *widget, GdkEventKey *event) { + + guint(g) = event->keyval; + + if((g == GDK_KEY_space)) { + if(running == FALSE) { + g_timer_start(timer); + running = TRUE; + return TRUE; + } + else { + g_timer_stop(timer); + running = FALSE; + return TRUE; + } + } + return FALSE; +} + +int main (int argc, char *argv[]) { + + gtk_init (&argc, &argv); + + timer_display = gtk_label_new(""); + + hbox = gtk_hbox_new(FALSE, 0); + gtk_box_pack_start(GTK_BOX (hbox), timer_display, FALSE, FALSE, 5); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + gtk_container_add (GTK_CONTAINER (window), hbox); + gtk_widget_show_all (window); + + timer = g_timer_new (); + g_timer_stop(timer); + + gint func_ref = g_timeout_add (50, update_progress_bar, NULL); + g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL); + g_signal_connect(G_OBJECT(window), "key-press-event", G_CALLBACK(keypress), window); + + gtk_main (); +} |