From 33dc2fd715321e3fe345aeef984c489affc54c3b Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Mon, 11 May 2009 12:35:41 -0500 Subject: [PATCH] improve error handling when begin-world fails --- basis/ui/gadgets/worlds/worlds.factor | 6 +++--- basis/ui/ui-docs.factor | 4 ++-- basis/ui/ui.factor | 26 ++++++++++++++++---------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/basis/ui/gadgets/worlds/worlds.factor b/basis/ui/gadgets/worlds/worlds.factor index eec5666f0e..a70d205377 100755 --- a/basis/ui/gadgets/worlds/worlds.factor +++ b/basis/ui/gadgets/worlds/worlds.factor @@ -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? ; diff --git a/basis/ui/ui-docs.factor b/basis/ui/ui-docs.factor index 397fc419fa..e206c7d408 100644 --- a/basis/ui/ui-docs.factor +++ b/basis/ui/ui-docs.factor @@ -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." } ; diff --git a/basis/ui/ui.factor b/basis/ui/ui.factor index d53d4c6753..0a6f26fd5b 100644 --- a/basis/ui/ui.factor +++ b/basis/ui/ui.factor @@ -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