     with-out-parameters 
     [ [ utf8 alien>string ] [ g_free ] bi ] dip ;
             
-: on-preedit-changed ( im-context user-data -- )
+: on-preedit-changed ( im-context win -- )
     window world-focus dup support-input-methods? [
         [ get-preedit-string ] dip set-preedit-string
     ] [ 2drop ] if ;
 
-: on-commit ( sender str user_data -- )
+: on-commit ( im-context str win -- )
     [ drop ] [ utf8 alien>string ] [ window ] tri* user-input ;
 
 : gadget-location ( gadget -- loc )

: mouse-event>gesture ( event -- modifiers button loc )
    [ event-modifiers ] [ button>> ] [ event-loc ] tri ;

: on-motion ( sender event user-data -- result )
    drop swap
    [ GdkEventMotion memory>struct event-loc ] dip window
    move-hand fire-motion t ;

: on-enter ( sender event user-data -- result )
    on-motion ;

: on-leave ( sender event user-data -- result )
    3drop forget-rollover t ;

: on-button-press ( sender event user-data -- result )
    drop swap [
        GdkEventButton memory>struct
        mouse-event>gesture [ <button-down> ] dip
    ] dip window send-button-down t ;

: on-button-release ( sender event user-data -- result )
    drop swap [
        GdkEventButton memory>struct
        mouse-event>gesture [ <button-up> ] dip
    ] dip window send-button-up t ;

: on-scroll ( sender event user-data -- result )
    drop swap [
        GdkEventScroll memory>struct
        [ scroll-direction ] [ event-loc ] bi

    [ gtk_dialog_run drop ]
    [ gtk_widget_destroy ] tri ;

M: gtk-ui-backend (with-ui)
    [
        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

