aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortlatorre <tlatorre@uchicago.edu>2022-11-12 16:33:01 -0800
committertlatorre <tlatorre@uchicago.edu>2022-11-12 16:33:01 -0800
commit30cbf2d44241af2728f4d19c3ffc6f14a0726c20 (patch)
tree73d9c554361215e1ceb737f901b6d328b3e31a59
parentfc8061968cd47cff815e897c0c940e2b3971f816 (diff)
downloadmoji-30cbf2d44241af2728f4d19c3ffc6f14a0726c20.tar.gz
moji-30cbf2d44241af2728f4d19c3ffc6f14a0726c20.tar.bz2
moji-30cbf2d44241af2728f4d19c3ffc6f14a0726c20.zip
add timer
-rw-r--r--moji.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/moji.c b/moji.c
index 7f4dd78..e1042c7 100644
--- a/moji.c
+++ b/moji.c
@@ -205,9 +205,68 @@ static int right_click_released(GtkWidget *widget, gpointer data)
return TRUE;
}
+int left_click_pressed = FALSE;
+
static int pressed(GtkWidget *widget, gpointer data)
{
aeGetTime(&pressed_time_sec,&pressed_time_msec);
+ left_click_pressed = TRUE;
+ return TRUE;
+}
+
+gboolean timer(gpointer data)
+{
+ const char *current_char;
+
+ 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) {
+ current_position = 0;
+ current_letter = 0;
+ aeGetTime(&pressed_time_sec,&pressed_time_msec);
+ } else if (diff > CLICK_TIME) {
+ current_char = current_chars->characters[current_letter % current_chars->len];
+ if (!strcmp(current_char,LEFT_ARROW)) {
+ backspace();
+ } else if (!strcmp(current_char,CLEAR_SCREEN)) {
+ current_position = 0;
+ current_letter = 0;
+ } else if (!strcmp(current_char,SOUND)) {
+ char cmd[1000000];
+ buf[current_position] = '\0';
+ sprintf(cmd, "gtts-cli \"%s\" --output moji.mp3", buf);
+ if (!system(cmd)) {
+ system("mpg123 moji.mp3");
+ system("rm moji.mp3");
+ }
+ } else if (!strcmp(current_char,"_")) {
+ sprintf(buf+current_position," ");
+ current_position += strlen(current_char);
+ } else if (!strcmp(current_char,NEWLINE)) {
+ sprintf(buf+current_position,"\n");
+ current_position += 1;
+ } else {
+ sprintf(buf+current_position,"%s",current_char);
+ current_position += strlen(current_char);
+ }
+ if (current_position > LEN(buf) - 1) {
+ /* FIXME: better way to do this? */
+ current_position = 0;
+ }
+ /* Uncomment the next line to start over at the beginning of the
+ * alphabet after a new letter is entered. But, I think it's better
+ * to keep the current letter. The reason is that you might want to
+ * delete a whole word and so when you navigate to the backspace you
+ * just have to keep entering the same letter. */
+ current_letter = 0;
+
+ write_buf();
+ aeGetTime(&pressed_time_sec,&pressed_time_msec);
+ }
+
return TRUE;
}
@@ -215,6 +274,8 @@ static int released(GtkWidget *widget, gpointer data)
{
const char *current_char;
+ left_click_pressed = FALSE;
+
aeGetTime(&released_time_sec,&released_time_msec);
long long diff = (released_time_sec - pressed_time_sec)*1000 + (released_time_msec - pressed_time_msec);
@@ -337,6 +398,9 @@ static void activate(GtkApplication *app, gpointer user_data)
/* Use a tag to change the color for just one part of the widget */
tag = gtk_text_buffer_create_tag(text_buffer, "red_foreground", "foreground", "red", NULL);
write_buf();
+
+ g_timeout_add(10, timer, NULL);
+
gtk_window_set_child(GTK_WINDOW(window), text_widget);
gtk_window_fullscreen(GTK_WINDOW(window));