improve error handling when begin-world fails
parent
783c452a6a
commit
30bfce2ce0
|
@ -4,7 +4,7 @@ USING: accessors arrays assocs continuations kernel math models
|
|||
namespaces opengl opengl.textures sequences io combinators
|
||||
combinators.short-circuit fry math.vectors math.rectangles cache
|
||||
ui.gadgets ui.gestures ui.render ui.backend ui.gadgets.tracks
|
||||
ui.commands ui.pixel-formats destructors literals ;
|
||||
ui.commands ui.pixel-formats destructors literals strings ;
|
||||
IN: ui.gadgets.worlds
|
||||
|
||||
CONSTANT: default-world-pixel-format-attributes
|
||||
|
@ -21,7 +21,7 @@ TUPLE: world < track
|
|||
TUPLE: world-attributes
|
||||
{ world-class initial: world }
|
||||
grab-input?
|
||||
title
|
||||
{ title string initial: "Factor Window" }
|
||||
status
|
||||
gadgets
|
||||
{ pixel-format-attributes initial: $ default-world-pixel-format-attributes } ;
|
||||
|
@ -63,7 +63,7 @@ M: world request-focus-on ( child gadget -- )
|
|||
: new-world ( class -- world )
|
||||
vertical swap new-track
|
||||
t >>root?
|
||||
t >>active?
|
||||
f >>active?
|
||||
{ 0 0 } >>window-loc
|
||||
f >>grab-input? ;
|
||||
|
||||
|
|
|
@ -40,12 +40,12 @@ HELP: find-window
|
|||
{ $description "Finds a native window such that the gadget passed to " { $link open-window } " satisfies the quotation, outputting " { $link f } " if no such gadget could be found. The front-most native window is checked first." } ;
|
||||
|
||||
HELP: register-window
|
||||
{ $values { "world" world } { "handle" "a baackend-specific handle" } }
|
||||
{ $values { "world" world } { "handle" "a backend-specific handle" } }
|
||||
{ $description "Adds a window to the global " { $link windows } " variable." }
|
||||
{ $notes "This word should only be called by the UI backend. User code can open new windows with " { $link open-window } "." } ;
|
||||
|
||||
HELP: unregister-window
|
||||
{ $values { "handle" "a baackend-specific handle" } }
|
||||
{ $values { "handle" "a backend-specific handle" } }
|
||||
{ $description "Removes a window from the global " { $link windows } " variable." }
|
||||
{ $notes "This word should only be called only by the UI backend, and not user code." } ;
|
||||
|
||||
|
|
|
@ -59,22 +59,28 @@ SYMBOL: windows
|
|||
[ ?ungrab-input ]
|
||||
[ focus-path f swap focus-gestures ] bi ;
|
||||
|
||||
: try-to-open-window ( world -- )
|
||||
: set-up-window ( world -- )
|
||||
{
|
||||
[ (open-window) ]
|
||||
[ handle>> select-gl-context ]
|
||||
[
|
||||
[ begin-world ]
|
||||
[ [ handle>> (close-window) ] [ ui-error ] bi* ]
|
||||
recover
|
||||
]
|
||||
[ [ title>> ] keep set-title ]
|
||||
[ begin-world ]
|
||||
[ resize-world ]
|
||||
[ t >>active? drop ]
|
||||
[ request-focus ]
|
||||
} cleave ;
|
||||
|
||||
: clean-up-broken-window ( world -- )
|
||||
[
|
||||
dup { [ focused?>> ] [ grab-input?>> ] } 1&&
|
||||
[ handle>> (ungrab-input) ] [ drop ] if
|
||||
] [ handle>> (close-window) ] bi ;
|
||||
|
||||
M: world graft*
|
||||
[ try-to-open-window ]
|
||||
[ [ title>> ] keep set-title ]
|
||||
[ request-focus ] tri ;
|
||||
[ (open-window) ]
|
||||
[
|
||||
[ set-up-window ]
|
||||
[ [ clean-up-broken-window ] [ ui-error ] bi* ] recover
|
||||
] bi ;
|
||||
|
||||
: reset-world ( world -- )
|
||||
#! This is used when a window is being closed, but also
|
||||
|
|
Loading…
Reference in New Issue