[uim-commit] r1176 - trunk/gtk

tkng at freedesktop.org tkng at freedesktop.org
Wed Aug 10 08:46:08 EST 2005


Author: tkng
Date: 2005-08-09 15:46:01 -0700 (Tue, 09 Aug 2005)
New Revision: 1176

Modified:
   trunk/gtk/caret-state-indicator.c
Log:
* gtk/caret-state-indicator.c: This commit aims to handle timout properly.
 -(get_current_time): New function.
 -(caret_state_indicator_timeout): Hide indicator only when time passes enough
   from the recent calling of timeout setting function.
 -(caret_state_indicator_set_timeout): Record called time.


Modified: trunk/gtk/caret-state-indicator.c
===================================================================
--- trunk/gtk/caret-state-indicator.c	2005-08-09 22:05:23 UTC (rev 1175)
+++ trunk/gtk/caret-state-indicator.c	2005-08-09 22:46:01 UTC (rev 1176)
@@ -46,13 +46,29 @@
 #define DEFAULT_WINDOW_HEIGHT 20
 
 static gint
+get_current_time(void);
+static gint
 caret_state_indicator_timeout(gpointer data);
 
+/* This function is not correct, size of tv_sec is glong, not gint */
 static gint
+get_current_time(void)
+{
+  GTimeVal result;
+  g_get_current_time(&result);
+  return result.tv_sec;
+}
+
+static gint
 caret_state_indicator_timeout(gpointer data)
 {
   GtkWidget *window = GTK_WIDGET(data);
-  gtk_widget_hide(window);
+  gint timeout      = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(window), "timeout"));
+  gint called_time  = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(window), "called_time"));
+  gint current_time = get_current_time();
+  if((current_time - called_time)*1000 >= timeout) {
+    gtk_widget_hide(window);
+  }
   return 0;
 }
 
@@ -127,5 +143,10 @@
 void
 caret_state_indicator_set_timeout(GtkWidget *window, gint timeout)
 {
+  gint current_time = get_current_time();
+
   g_timeout_add(timeout, caret_state_indicator_timeout, (gpointer)window);
+  g_object_set_data(G_OBJECT(window), "timeout", GINT_TO_POINTER(timeout));
+  g_object_set_data(G_OBJECT(window), "called_time", GINT_TO_POINTER(current_time));
+  /* "called_time" stores the time of last calling of this function */
 }



More information about the uim-commit mailing list