         init-clipboard
         start-ui
         [
-            [ [ gtk_main ] with-timer ] with-event-loop
+            [
+                [
+                    <yield-callback> f g_idle_add drop
+                    gtk_main
+                ] with-timer
+            ] with-event-loop
         ] with-destructors
     ] ui-running ;
 

    ] when* ;

:: connect-user-input-signals ( win -- )
    win "motion-notify-event" [ on-motion yield ]
    GtkWidget:motion-notify-event connect-signal
    win "leave-notify-event" [ on-leave yield ]
    GtkWidget:leave-notify-event connect-signal
    win "button-press-event" [ on-button-press yield ]
    GtkWidget:button-press-event connect-signal
    win "button-release-event" [ on-button-release yield ]
    GtkWidget:button-release-event connect-signal
    win "scroll-event" [ on-scroll yield ]
    GtkWidget:scroll-event connect-signal
    win "key-press-event" [ on-key-press/release yield ]
    GtkWidget:key-press-event connect-signal
    win "key-release-event" [ on-key-press/release yield ]
    GtkWidget:key-release-event connect-signal
    win "focus-in-event" [ on-focus-in yield ]
    GtkWidget:focus-in-event connect-signal
    win "focus-out-event" [ on-focus-out yield ]
    GtkWidget:focus-out-event connect-signal ;

! Window state events

        ] [ gtk_dialog_run drop ] bi
    ] with-destructors ;

: <yield-callback> ( -- callback )
    [ drop yield t ] GSourceFunc ;

M: gtk-ui-backend (with-ui)
    [
        0 gint <ref> f void* <ref> gtk_init
