gtk_clipboard_wait_for_text_timeout



In applications it is often useful to have a way to wait on the clipboard,
but only tolerate short waits. A delay of 50ms, for example, is not
noticeable by the user and is *usually* enough to get text from the
clipboard. In case the time window is not enough to get the text, the
application can act as if the request failed.

I'd like to suggest the following be included in gtk/gtkclipboard.c:
(This is a simple function, but it can't simply be put in user code
because it uses some private gtk symbols)

/* adapted from gtk_clipboard_wait_for_text */
gchar *
gtk_clipboard_wait_for_text_timeout (GtkClipboard *clipboard, gint timeout)
{ 
  WaitResults results;
  guint tag;

  g_return_val_if_fail (clipboard != NULL, NULL);
  g_return_val_if_fail (clipboard != NULL, NULL);

  results.data = NULL;
  results.loop = g_main_loop_new (NULL, TRUE);

  tag = g_timeout_add(timeout, (GSourceFunc)g_main_loop_quit, results.loop);

  gtk_clipboard_request_text (clipboard,
                  clipboard_text_received_func,
                  &results);

  if (g_main_loop_is_running (results.loop))
    { 
      GDK_THREADS_LEAVE ();
      g_main_loop_run (results.loop);
      GDK_THREADS_ENTER ();
    }

  g_source_remove(tag);

  g_main_loop_unref (results.loop);

  return results.data;
}


-- 
Gaal Yahas <gaal forum2 org>
http://gaal.livejournal.com/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]