 
 : setup-window ( window -- window )
     [
-        dup
-        dup parent-window>> [
-            ptr>> swap window-params ffi:derwin
-        ] [
-            window-params ffi:newwin
-        ] if* curses-pointer-error >>ptr &dispose
+        dup [ window-params ] keep
+        parent-window>> [ ptr>> ffi:derwin ] [ ffi:newwin ] if*
+        curses-pointer-error >>ptr &dispose
     ] [ apply-window-options ] bi ;
 
 : with-window ( window quot -- )


: wcread ( n window -- string )
    [ encoding>> ] [ ptr>> ] bi (wcread) ;
: curses-read ( n -- string ) current-window get wcread ;

: wgetch ( window -- key ) ptr>> (wgetch) ;
: getch ( -- key ) current-window get wgetch ;


: fill-in-type ( mouse-event substate -- )
    {
        { BUTTON1_RELEASED       [ +released+ ] }
        { BUTTON1_PRESSED        [ +pressed+ ] }
        { BUTTON1_CLICKED        [ +clicked+ ] }
        { BUTTON1_DOUBLE_CLICKED [ +double+ ] }
        { BUTTON1_TRIPLE_CLICKED [ +triple+ ] }
    } case >>type drop ; inline

: fill-in-bstate ( mouse-event bstate -- )
    2dup {
