     [ gtk_dialog_run drop ]
     [ gtk_widget_destroy ] tri ;
 
-M: gtk-clipboard clipboard-contents
+M: gtk-ui-backend (with-ui)
     [
-        handle>> gtk_clipboard_wait_for_text
-        [ &g_free utf8 alien>string ] [ f ] if*
-    ] with-destructors ;
-
-M: gtk-clipboard set-clipboard-contents
-    swap [ handle>> ] [ utf8 string>alien ] bi*
-    -1 gtk_clipboard_set_text ;
+        f f gtk_init
+        f f gtk_gl_init
+        init-clipboard
+        start-ui
+        stop-io-thread
+        [
+            init-io-event-source
+            init-timeout
+            gtk_main
+        ] with-destructors
+    ] ui-running ;
 
 gtk-ui-backend ui-backend set-global
 

        swap >>im-context
        swap >>window ;

TUPLE: gtk-clipboard handle ;

C: <gtk-clipboard> gtk-clipboard

PIXEL-FORMAT-ATTRIBUTE-TABLE: gl-config-attribs ${ GDK_GL_USE_GL GDK_GL_RGBA } H{
    { double-buffered ${ GDK_GL_DOUBLEBUFFER } }
    { stereo ${ GDK_GL_STEREO } }
    ! { offscreen ${ GDK_GL_DRAWABLE_TYPE 2 } }
    ! { fullscreen ${ GDK_GL_DRAWABLE_TYPE 1 } }
    ! { windowed ${ GDK_GL_DRAWABLE_TYPE 1 } }
    { color-bits ${ GDK_GL_BUFFER_SIZE } }
    { red-bits ${ GDK_GL_RED_SIZE } }
    { green-bits ${ GDK_GL_GREEN_SIZE } }
    { blue-bits ${ GDK_GL_BLUE_SIZE } }
    { alpha-bits ${ GDK_GL_ALPHA_SIZE } }
    { accum-red-bits ${ GDK_GL_ACCUM_RED_SIZE } }
    { accum-green-bits ${ GDK_GL_ACCUM_GREEN_SIZE } }
    { accum-blue-bits ${ GDK_GL_ACCUM_BLUE_SIZE } }
    { accum-alpha-bits ${ GDK_GL_ACCUM_ALPHA_SIZE } }
    { depth-bits ${ GDK_GL_DEPTH_SIZE } }
    { stencil-bits ${ GDK_GL_STENCIL_SIZE } }
    { aux-buffers ${ GDK_GL_AUX_BUFFERS } }
    { sample-buffers ${ GDK_GL_SAMPLE_BUFFERS } }
    { samples ${ GDK_GL_SAMPLES } }
}

M: gtk-ui-backend (make-pixel-format)
    nip >gl-config-attribs-int-array gdk_gl_config_new ;

M: gtk-ui-backend (free-pixel-format)
    handle>> g_object_unref ;

M: gtk-ui-backend (pixel-format-attribute)
    [ handle>> ] [ >gl-config-attribs ] bi*
    { int } [ gdk_gl_config_get_attrib drop ]
    with-out-parameters ;

CONSTANT: events-mask
    flags{

    GtkWidget:focus-out-event im connect-signal-with-data
    win "destroy" [ im-on-destroy yield ]
    GtkObject:destroy im connect-signal-with-data ;

! Window controls

CONSTANT: window-controls>decor-flags
    H{
