FUNCTION: CGLError CGLSetParameter ( CGLContextObj ctx, CGLContextParameter pname, GLint* params ) ;
+FUNCTION: CGDirectDisplayID CGMainDisplayID ( ) ;
+
+FUNCTION: CGError CGDisplayHideCursor ( CGDirectDisplayID display ) ;
+FUNCTION: CGError CGDisplayShowCursor ( CGDirectDisplayID display ) ;
+
+FUNCTION: CGError CGAssociateMouseAndMouseCursorPosition ( boolean_t connected ) ;
+
+FUNCTION: CGError CGWarpMouseCursorPosition ( CGPoint newCursorPosition ) ;
+
<PRIVATE
: bitmap-flags ( -- flags )
TYPEDEF: uint CGBitmapInfo
TYPEDEF: int CGLError
+TYPEDEF: int CGError
+TYPEDEF: uint CGDirectDisplayID
+TYPEDEF: int boolean_t
TYPEDEF: void* CGLContextObj
-TYPEDEF: int CGLContextParameter
\ No newline at end of file
+TYPEDEF: int CGLContextParameter
: rect-extent ( rect -- loc ext ) rect-bounds over v+ ;
+: rect-center ( rect -- center ) rect-bounds 2 v/n v+ ;
+
: with-rect-extents ( rect1 rect2 loc-quot: ( loc1 loc2 -- ) ext-quot: ( ext1 ext2 -- ) -- )
[ [ rect-extent ] bi@ ] 2dip bi-curry* bi* ; inline
'[ select-gl-context @ ]
[ flush-gl-context gl-error ] bi ; inline
-HOOK: (with-ui) ui-backend ( quot -- )
\ No newline at end of file
+HOOK: (with-ui) ui-backend ( quot -- )
+
+HOOK: (grab-input) ui-backend ( handle -- )
+
+HOOK: (ungrab-input) ui-backend ( handle -- )
M: cocoa-ui-backend (close-window) ( handle -- )
window>> -> release ;
+M: cocoa-ui-backend (grab-input) ( handle -- )
+ 0 CGAssociateMouseAndMouseCursorPosition drop
+ CGMainDisplayID CGDisplayHideCursor drop
+ window>> -> frame CGRect>rect rect-center
+ first2 <CGPoint> CGWarpMouseCursorPosition drop ;
+
+M: cocoa-ui-backend (ungrab-input) ( handle -- )
+ drop
+ CGMainDisplayID CGDisplayShowCursor drop
+ 1 CGAssociateMouseAndMouseCursorPosition drop ;
+
M: cocoa-ui-backend close-window ( gadget -- )
find-world [
handle>> [
: hwnd>RECT ( hwnd -- RECT )
"RECT" <c-object> [ GetWindowRect win32-error=0/f ] keep ;
+M: windows-ui-backend (grab-input) ( handle -- )
+ 0 ShowCursor drop
+ hWnd>> hwnd>RECT ClipCursor drop ;
+M: windows-ui-backend (ungrab-input) ( handle -- )
+ drop
+ f ClipCursor drop
+ 1 ShowCursor drop ;
+
: fullscreen-flags ( -- n )
{ WS_CAPTION WS_BORDER WS_THICKFRAME } flags ; inline
{ windowed double-buffered T{ depth-bits { value 16 } } }
TUPLE: world < track
- active? focused?
+ active? focused? grab-input?
layers
title status status-owner
text-handle handle images
TUPLE: world-attributes
{ world-class initial: world }
+ grab-input?
title
status
gadgets
vertical swap new-track
t >>root?
t >>active?
- { 0 0 } >>window-loc ;
+ { 0 0 } >>window-loc
+ f >>grab-input? ;
: apply-world-attributes ( world attributes -- world )
{
[ title>> >>title ]
[ status>> >>status ]
[ pixel-format-attributes>> >>pixel-format-attributes ]
+ [ grab-input?>> >>grab-input? ]
[ gadgets>> [ 1 track-add ] each ]
} cleave ;
lose-focus swap each-gesture
gain-focus swap each-gesture ;
+: ?grab-input ( world -- )
+ dup grab-input?>> [ handle>> (grab-input) ] [ drop ] if ;
+
+: ?ungrab-input ( world -- )
+ dup grab-input?>> [ handle>> (ungrab-input) ] [ drop ] if ;
+
: focus-world ( world -- )
t >>focused?
- dup raised-window
- focus-path f focus-gestures ;
+ [ ?grab-input ] [
+ dup raised-window
+ focus-path f focus-gestures
+ ] bi ;
: unfocus-world ( world -- )
f >>focused?
- focus-path f swap focus-gestures ;
+ [ ?ungrab-input ]
+ [ focus-path f swap focus-gestures ] bi ;
: try-to-open-window ( world -- )
{
! FUNCTION: ClientThreadSetup
! FUNCTION: ClientToScreen
! FUNCTION: CliImmSetHotKey
-! FUNCTION: ClipCursor
+FUNCTION: int ClipCursor ( RECT* clipRect ) ;
FUNCTION: BOOL CloseClipboard ( ) ;
! FUNCTION: CloseDesktop
! FUNCTION: CloseWindow
! FUNCTION: SetWindowWord
! FUNCTION: SetWinEventHook
! FUNCTION: ShowCaret
-! FUNCTION: ShowCursor
+FUNCTION: int ShowCursor ( BOOL show ) ;
! FUNCTION: ShowOwnedPopups
! FUNCTION: ShowScrollBar
! FUNCTION: ShowStartGlass
double-buffered
T{ depth-bits { value 24 } }
} }
+ { grab-input? t }
} open-window
] with-ui ;