From 389ed1929cd0de17e533b98b0d3b51c8535110e9 Mon Sep 17 00:00:00 2001 From: tlatorre Date: Sat, 12 Nov 2022 16:46:57 -0800 Subject: add more comments --- moji.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/moji.c b/moji.c index c32ae34..d2724fc 100644 --- a/moji.c +++ b/moji.c @@ -219,21 +219,33 @@ static int pressed(GtkWidget *widget, gpointer data) return TRUE; } +/* Timer function which runs every 10 ms. This function checks if the left + * mouse button is clicked, and if so, checks if it's been clicked for more + * than CLICK_TIME milliseconds. If so, it adds the current character to the + * buffer and sets processed to TRUE, so that when the mouse button is released + * it doesn't move to the next character. + * + * Always returns TRUE to make sure the function keeps running. */ gboolean timer(gpointer data) { const char *current_char; + /* If the left mouse button isn't clicked, there is nothing to do. */ if (left_click_pressed == FALSE) return TRUE; aeGetTime(&released_time_sec,&released_time_msec); long long diff = (released_time_sec - pressed_time_sec)*1000 + (released_time_msec - pressed_time_msec); if (diff > 10000) { + /* If the mouse button has been clicked for more than 10 seconds, clear + * the screen. */ current_position = 0; current_letter = 0; processed = TRUE; aeGetTime(&pressed_time_sec,&pressed_time_msec); } else if (diff > CLICK_TIME) { + /* If the mouse button has been clicked for more than CLICK_TIME + * milliseconds, add the current character to the buffer. */ current_char = current_chars->characters[current_letter % current_chars->len]; if (!strcmp(current_char,LEFT_ARROW)) { backspace(); -- cgit