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
|
namespaces opengl opengl.textures sequences io combinators
|
||||||
combinators.short-circuit fry math.vectors math.rectangles cache
|
combinators.short-circuit fry math.vectors math.rectangles cache
|
||||||
ui.gadgets ui.gestures ui.render ui.backend ui.gadgets.tracks
|
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
|
IN: ui.gadgets.worlds
|
||||||
|
|
||||||
CONSTANT: default-world-pixel-format-attributes
|
CONSTANT: default-world-pixel-format-attributes
|
||||||
|
@ -21,7 +21,7 @@ TUPLE: world < track
|
||||||
TUPLE: world-attributes
|
TUPLE: world-attributes
|
||||||
{ world-class initial: world }
|
{ world-class initial: world }
|
||||||
grab-input?
|
grab-input?
|
||||||
title
|
{ title string initial: "Factor Window" }
|
||||||
status
|
status
|
||||||
gadgets
|
gadgets
|
||||||
{ pixel-format-attributes initial: $ default-world-pixel-format-attributes } ;
|
{ pixel-format-attributes initial: $ default-world-pixel-format-attributes } ;
|
||||||
|
@ -63,7 +63,7 @@ M: world request-focus-on ( child gadget -- )
|
||||||
: new-world ( class -- world )
|
: new-world ( class -- world )
|
||||||
vertical swap new-track
|
vertical swap new-track
|
||||||
t >>root?
|
t >>root?
|
||||||
t >>active?
|
f >>active?
|
||||||
{ 0 0 } >>window-loc
|
{ 0 0 } >>window-loc
|
||||||
f >>grab-input? ;
|
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." } ;
|
{ $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
|
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." }
|
{ $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 } "." } ;
|
{ $notes "This word should only be called by the UI backend. User code can open new windows with " { $link open-window } "." } ;
|
||||||
|
|
||||||
HELP: unregister-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." }
|
{ $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." } ;
|
{ $notes "This word should only be called only by the UI backend, and not user code." } ;
|
||||||
|
|
||||||
|
|
|
@ -59,22 +59,28 @@ SYMBOL: windows
|
||||||
[ ?ungrab-input ]
|
[ ?ungrab-input ]
|
||||||
[ focus-path f swap focus-gestures ] bi ;
|
[ focus-path f swap focus-gestures ] bi ;
|
||||||
|
|
||||||
: try-to-open-window ( world -- )
|
: set-up-window ( world -- )
|
||||||
{
|
{
|
||||||
[ (open-window) ]
|
|
||||||
[ handle>> select-gl-context ]
|
[ handle>> select-gl-context ]
|
||||||
[
|
[ [ title>> ] keep set-title ]
|
||||||
[ begin-world ]
|
[ begin-world ]
|
||||||
[ [ handle>> (close-window) ] [ ui-error ] bi* ]
|
|
||||||
recover
|
|
||||||
]
|
|
||||||
[ resize-world ]
|
[ resize-world ]
|
||||||
|
[ t >>active? drop ]
|
||||||
|
[ request-focus ]
|
||||||
} cleave ;
|
} cleave ;
|
||||||
|
|
||||||
|
: clean-up-broken-window ( world -- )
|
||||||
|
[
|
||||||
|
dup { [ focused?>> ] [ grab-input?>> ] } 1&&
|
||||||
|
[ handle>> (ungrab-input) ] [ drop ] if
|
||||||
|
] [ handle>> (close-window) ] bi ;
|
||||||
|
|
||||||
M: world graft*
|
M: world graft*
|
||||||
[ try-to-open-window ]
|
[ (open-window) ]
|
||||||
[ [ title>> ] keep set-title ]
|
[
|
||||||
[ request-focus ] tri ;
|
[ set-up-window ]
|
||||||
|
[ [ clean-up-broken-window ] [ ui-error ] bi* ] recover
|
||||||
|
] bi ;
|
||||||
|
|
||||||
: reset-world ( world -- )
|
: reset-world ( world -- )
|
||||||
#! This is used when a window is being closed, but also
|
#! This is used when a window is being closed, but also
|
||||||
|
|
Loading…
Reference in New Issue