From d22a14293510e7c559edbfc1ddc15e8d06e69926 Mon Sep 17 00:00:00 2001 From: slava Date: Wed, 22 Mar 2006 07:07:21 +0000 Subject: [PATCH] Keyboard input and cleanups for X11 backend --- library/cocoa/ui.factor | 22 +++++------- library/help/help.factor | 2 ++ library/syntax/see.factor | 3 -- library/ui/backend.factor | 4 ++- library/ui/hand.factor | 12 +++++-- library/ui/launchpad.factor | 6 +++- library/ui/layouts.factor | 2 -- library/ui/line-editor.factor | 4 +-- library/ui/listener.factor | 52 ++++++++++++++------------- library/ui/theme.factor | 4 +-- library/ui/timers.factor | 2 -- library/words.factor | 3 ++ library/x11/events.factor | 24 +++++++++---- library/x11/ui.factor | 68 +++++++++++++++++++++++++++++------ library/x11/windows.factor | 20 +++++------ library/x11/xlib.factor | 15 ++++++-- 16 files changed, 161 insertions(+), 82 deletions(-) diff --git a/library/cocoa/ui.factor b/library/cocoa/ui.factor index 1cdde85e0a..c1174c3301 100644 --- a/library/cocoa/ui.factor +++ b/library/cocoa/ui.factor @@ -53,24 +53,18 @@ H{ } clone views set-global { 124 "RIGHT" } { 125 "DOWN" } { 126 "UP" } - } hash ; - -: modifier ( mod -- seq ) - modifiers - [ second swap bitand 0 > ] subset-with - [ first ] map ; + } ; : key-code ( event -- string ) - dup [keyCode] key-codes + dup [keyCode] key-codes hash [ ] [ [charactersIgnoringModifiers] CF>string ] ?if ; -: event>binding ( event -- binding ) - dup [modifierFlags] modifier swap key-code - [ add >list ] [ drop f ] if* ; +: event>gesture ( event -- gesture ) + dup [modifierFlags] modifiers modifier swap key-code + add >list ; : send-key-event ( view event -- ) - >r view world-focus r> dup event>binding - [ pick handle-gesture ] [ t ] if* + >r view world-focus r> dup event>gesture pick handle-gesture [ [characters] CF>string swap user-input ] [ 2drop ] if ; "NSOpenGLView" "FactorView" { @@ -165,8 +159,8 @@ H{ } clone views set-global IN: gadgets -: draw-handle ( handle -- ) - 1 [setNeedsDisplay:] ; +: redraw-world ( handle -- ) + world-handle 1 [setNeedsDisplay:] ; : in-window ( gadget status dim title -- ) >r r> drop ; diff --git a/library/help/help.factor b/library/help/help.factor index 2ab2c4400f..7c9506d1ba 100644 --- a/library/help/help.factor +++ b/library/help/help.factor @@ -17,3 +17,5 @@ DEFER: $heading : glossary ( name -- ) help ; : handbook ( -- ) "handbook" help ; + +: tutorial ( -- ) "tutorial" help ; diff --git a/library/syntax/see.factor b/library/syntax/see.factor index d4c97e5e97..97784340f4 100644 --- a/library/syntax/see.factor +++ b/library/syntax/see.factor @@ -117,9 +117,6 @@ M: word class. drop ; newline ] with-pprint ; -: completions ( substring words -- seq ) - [ word-name subseq? ] subset-with ; - : apropos ( substring -- ) all-words completions natural-sort [ [ synopsis ] keep simple-object terpri ] each ; diff --git a/library/ui/backend.factor b/library/ui/backend.factor index 3437ce4169..aeee02ea47 100644 --- a/library/ui/backend.factor +++ b/library/ui/backend.factor @@ -1,7 +1,9 @@ IN: gadgets USING: kernel opengl ; -DEFER: draw-handle ( handle -- ) +DEFER: draw-world ! defined in world.factor + +: redraw-world ( world -- ) draw-world ; DEFER: in-window ( gadget status dim title -- ) diff --git a/library/ui/hand.factor b/library/ui/hand.factor index 4e03dcde3b..2635bedad8 100644 --- a/library/ui/hand.factor +++ b/library/ui/hand.factor @@ -77,6 +77,10 @@ V{ } clone hand-buttons set-global : request-focus ( gadget -- ) dup focusable-child swap find-world request-focus* ; +: modifier ( mod modifiers -- seq ) + [ second swap bitand 0 > ] subset-with + [ first ] map ; + : drag-loc ( -- loc ) hand-loc get-global hand-click-loc get-global v- ; @@ -114,14 +118,18 @@ V{ } clone hand-buttons set-global drop ] [ deque dup layout - find-world [ world-handle dup set ] when* + find-world [ dup world-handle set ] when* layout-queued ] if ; +: init-ui ( -- ) + H{ } clone \ timers set-global + \ invalid set-global ; + : ui-step ( -- ) do-timers [ layout-queued ] make-hash - [ drop [ draw-handle ] when* ] hash-each + [ nip [ draw-world ] when* ] hash-each 10 sleep ; : close-world ( world -- ) diff --git a/library/ui/launchpad.factor b/library/ui/launchpad.factor index 923d985878..af2d7b2753 100644 --- a/library/ui/launchpad.factor +++ b/library/ui/launchpad.factor @@ -1,6 +1,7 @@ IN: gadgets-launchpad USING: gadgets gadgets-buttons gadgets-labels gadgets-layouts -gadgets-listener io kernel memory namespaces sequences ; +gadgets-listener help inspector io kernel memory namespaces +sequences ; : ( menu -- ) [ first2 >r