 C: <pasteboard> pasteboard
 
 M: pasteboard clipboard-contents
-    pasteboard-handle pasteboard-string ;
+    handle>> pasteboard-string ;
 
 M: pasteboard set-clipboard-contents
-    pasteboard-handle set-pasteboard-string ;
+    handle>> set-pasteboard-string ;
 
 : init-clipboard ( -- )
     NSPasteboard -> generalPasteboard <pasteboard>

M: cocoa-ui-backend (open-window) ( world -- )
    dup gadget-window
    dup auto-position
    world-handle handle-window f -> makeKeyAndOrderFront: ;

M: cocoa-ui-backend (close-window) ( handle -- )
    handle-window -> release ;

M: cocoa-ui-backend close-window ( gadget -- )
    find-world [
        world-handle [
            handle-window f -> performClose:
        ] when*
    ] when* ;

M: cocoa-ui-backend raise-window* ( world -- )
    world-handle [
        handle-window dup f -> orderFront: -> makeKeyWindow
        NSApp 1 -> activateIgnoringOtherApps:
    ] when* ;

M: cocoa-ui-backend select-gl-context ( handle -- )
    handle-view -> openGLContext -> makeCurrentContext ;

M: cocoa-ui-backend flush-gl-context ( handle -- )
    handle-view -> openGLContext -> flushBuffer ;

M: cocoa-ui-backend beep ( -- )
    NSBeep ;

    ] keep set-world-handle ;

M: cocoa-ui-backend set-title ( string world -- )
    world-handle window>> swap <NSString> -> setTitle: ;

: enter-fullscreen ( world -- )
    world-handle view>>
    NSScreen -> mainScreen
    f -> enterFullScreenMode:withOptions:
    drop ;

: exit-fullscreen ( world -- )
    world-handle view>> f -> exitFullScreenModeWithOptions: ;

M: cocoa-ui-backend set-fullscreen* ( ? world -- )
    swap [ enter-fullscreen ] [ exit-fullscreen ] if ;

M: cocoa-ui-backend fullscreen* ( world -- ? )
    world-handle view>> -> isInFullScreenMode zero? not ;

: auto-position ( world -- )
    dup window-loc>> { 0 0 } = [
        world-handle window>> -> center
    ] [
        drop
    ] if ;
