aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUnia <jthidskes@live.nl>2013-03-31 13:53:42 +0200
committerUnia <jthidskes@live.nl>2013-03-31 13:53:42 +0200
commit2ae3c219a0354f60709380281fcbf80cdb392d7a (patch)
treed11ce19b44d7f6b98eddf67eb0248491547a64a9
parente3a97906eae49d4759ab1fe0c5a3a9f0c6628354 (diff)
initial code cleanup, switch to gtk3
-rw-r--r--Makefile4
-rw-r--r--README.md23
-rw-r--r--gstopwatch.c77
3 files changed, 49 insertions, 55 deletions
diff --git a/Makefile b/Makefile
index d5c8c54..dfd15a8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
gstopwatch:
- gcc gstopwatch.c `pkg-config --cflags --libs gtk+-2.0` -o gstopwatch
+ gcc gstopwatch.c `pkg-config --cflags --libs gtk+-3.0` -o gstopwatch
clean:
- rm -vf gstopwatch
+ rm -f gstopwatch
diff --git a/README.md b/README.md
index 68fe853..803dc74 100644
--- a/README.md
+++ b/README.md
@@ -1,23 +1,22 @@
-# gstopwatch
-
+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
+stopwatch will start counting, stop counting and reset.
-press space to start timing, space to stop, space again to reset and start
+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
+Building
+--------
+You'll need the gtk 3.x libraries and headers installed and ready to go. To
build, simple run make in the gstopwatch folder
-## To Do
-
+ToDo
+----
* Laps
* Hours:Minutes:Seconds display
* Font size
diff --git a/gstopwatch.c b/gstopwatch.c
index d3381f8..52a0ea7 100644
--- a/gstopwatch.c
+++ b/gstopwatch.c
@@ -3,61 +3,56 @@
#include <glib.h>
gboolean running;
-GtkWidget *hbox;
-GtkWidget *timer_display;
-GtkWidget *window;
+GtkWidget *window, *box, *timer_display;
GTimer *timer;
-gboolean update_progress_bar () {
- gulong gulong;
- gdouble time_elapsed = g_timer_elapsed (timer, &gulong);
- char *output;
+gboolean update_progress_bar (void) {
+ gulong gulong;
+ gdouble time_elapsed;
+ char *output;
- sprintf(output, "%.2f", time_elapsed);
+ time_elapsed = g_timer_elapsed (timer, &gulong);
+ sprintf(output, "%.2f", time_elapsed);
- gtk_label_set_text(GTK_LABEL(timer_display), output);
- return TRUE;
+ gtk_label_set_text(GTK_LABEL(timer_display), output);
+ return TRUE;
}
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;
+ 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);
- 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);
+ timer_display = gtk_label_new("");
+ box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
+ gtk_box_pack_start(GTK_BOX (box), timer_display, FALSE, FALSE, 5);
- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- gtk_container_add (GTK_CONTAINER (window), hbox);
- gtk_widget_show_all (window);
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_container_add (GTK_CONTAINER (window), box);
+ gtk_widget_show_all (window);
- timer = g_timer_new ();
- g_timer_stop(timer);
+ timer = g_timer_new ();
+ g_timer_stop(timer);
- g_timeout_add_full(G_PRIORITY_HIGH, 50, (GSourceFunc) update_progress_bar, NULL, 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);
+ g_timeout_add_full(G_PRIORITY_HIGH, 50, (GSourceFunc) update_progress_bar, NULL, 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 ();
+ gtk_main ();
}