! Copyright (C) 2005, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays assocs kernel math math.order models
-namespaces make sequences words strings system hashtables math.parser
-math.vectors classes.tuple classes boxes calendar alarms combinators
-sets columns fry deques ui.gadgets ui.gadgets.private ascii
-combinators.short-circuit ;
-FROM: namespaces => set ;
-FROM: sets => members ;
+USING: accessors arrays ascii assocs boxes calendar classes columns
+combinators combinators.short-circuit deques kernel make math
+math.order math.parser math.vectors namespaces sequences sets system
+timers ui.gadgets ui.gadgets.private words ;
IN: ui.gestures
: get-gesture-handler ( gesture gadget -- quot )
- class superclasses [ "gestures" word-prop ] map assoc-stack ;
+ class-of superclasses-of [ "gestures" word-prop ] map assoc-stack ;
GENERIC: handle-gesture ( gesture gadget -- ? )
GENERIC: handles-gesture? ( gesture gadget -- ? )
-M: object handles-gesture? ( gesture gadget -- ? )
+M: object handles-gesture?
get-gesture-handler >boolean ;
: parents-handle-gesture? ( gesture gadget -- ? )
GENERIC: send-queued-gesture ( request -- )
-TUPLE: send-gesture gesture gadget ;
+TUPLE: send-gesture-tuple gesture gadget ;
-M: send-gesture send-queued-gesture
+M: send-gesture-tuple send-queued-gesture
[ gesture>> ] [ gadget>> ] bi handle-gesture drop ;
: queue-gesture ( ... class -- )
boa gesture-queue push-front notify-ui-thread ; inline
: send-gesture ( gesture gadget -- )
- \ send-gesture queue-gesture ;
+ \ send-gesture-tuple queue-gesture ;
: each-gesture ( gesture seq -- ) [ send-gesture ] with each ;
-TUPLE: propagate-gesture gesture gadget ;
+TUPLE: propagate-gesture-tuple gesture gadget ;
: resend-gesture ( gesture gadget -- ? )
[ handle-gesture ] with each-parent ;
-M: propagate-gesture send-queued-gesture
+M: propagate-gesture-tuple send-queued-gesture
[ gesture>> ] [ gadget>> ] bi resend-gesture drop ;
: propagate-gesture ( gesture gadget -- )
- \ propagate-gesture queue-gesture ;
+ \ propagate-gesture-tuple queue-gesture ;
-TUPLE: propagate-key-gesture gesture world ;
+TUPLE: propagate-key-gesture-tuple gesture world ;
: world-focus ( world -- gadget )
dup focus>> [ world-focus ] [ ] ?if ;
-M: propagate-key-gesture send-queued-gesture
+M: propagate-key-gesture-tuple send-queued-gesture
[ gesture>> ] [ world>> world-focus ] bi
[ handle-gesture ] with each-parent drop ;
-: propagate-key-gesture ( gesture world -- )
- \ propagate-key-gesture queue-gesture ;
+:: propagate-key-gesture ( gesture world -- )
+ world world-focus preedit? [
+ gesture world \ propagate-key-gesture-tuple queue-gesture
+ ] unless ;
-TUPLE: user-input string world ;
+TUPLE: user-input-tuple string world ;
-M: user-input send-queued-gesture
+M: user-input-tuple send-queued-gesture
[ string>> ] [ world>> world-focus ] bi
[ user-input* ] with each-parent drop ;
: user-input ( string world -- )
- '[ _ \ user-input queue-gesture ] unless-empty ;
+ '[ _ \ user-input-tuple queue-gesture ] unless-empty ;
! Gesture objects
TUPLE: drag # ; C: <drag> drag
TUPLE: button-up mods # ; C: <button-up> button-up
TUPLE: button-down mods # ; C: <button-down> button-down
+TUPLE: file-drop mods ; C: <file-drop> file-drop
+
+SYMBOL: dropped-files
SINGLETONS:
-motion
-mouse-scroll
-mouse-enter mouse-leave
-lose-focus gain-focus ;
+ motion
+ mouse-scroll
+ mouse-enter mouse-leave
+ lose-focus gain-focus ;
! Higher-level actions
SINGLETONS:
-undo-action redo-action
-cut-action copy-action paste-action
-delete-action select-all-action
-left-action right-action up-action down-action
-zoom-in-action zoom-out-action
-new-action open-action save-action save-as-action
-revert-action close-action ;
+ undo-action redo-action
+ cut-action copy-action paste-action
+ delete-action select-all-action
+ left-action right-action up-action down-action
+ zoom-in-action zoom-out-action
+ new-action open-action save-action save-as-action
+ revert-action close-action ;
UNION: action
-undo-action redo-action
-cut-action copy-action paste-action
-delete-action select-all-action
-left-action right-action up-action down-action
-zoom-in-action zoom-out-action
-new-action open-action save-action save-as-action
-revert-action close-action ;
+ undo-action redo-action
+ cut-action copy-action paste-action
+ delete-action select-all-action
+ left-action right-action up-action down-action
+ zoom-in-action zoom-out-action
+ new-action open-action save-action save-as-action
+ revert-action close-action ;
CONSTANT: action-gestures
{
TUPLE: key-down < key-gesture ;
-: new-key-gesture ( mods sym action? class -- mods' sym' )
+: new-key-gesture ( mods sym action? class -- key-gesture )
[ [ [ S+ swap remove f like ] dip ] unless ] dip boa ; inline
: <key-down> ( mods sym action? -- key-down )
300 milliseconds double-click-timeout set-global
: hand-moved? ( -- ? )
- hand-loc get hand-click-loc get = not ;
+ hand-loc get-global hand-click-loc get-global = not ;
: button-gesture ( gesture -- )
hand-clicked get-global propagate-gesture ;
[ drag-gesture ]
300 milliseconds
100 milliseconds
- add-alarm drag-timer get-global >box
+ <timer>
+ [ drag-timer get-global >box ]
+ [ start-timer ] bi
] when ;
: stop-drag-timer ( -- )
hand-buttons get-global empty? [
drag-timer get-global ?box
- [ cancel-alarm ] [ drop ] if
+ [ stop-timer ] [ drop ] if
] when ;
: fire-motion ( -- )
dup send-lose-focus
f swap t focus-child
] when*
- dupd (>>focus) [
+ dupd focus<< [
send-gain-focus
] when*
] [
- (>>focus)
+ focus<<
] if ;
: modifier ( mod modifiers -- seq )
dup hand-last-button get = ;
: multi-click-position? ( -- ? )
- hand-loc get hand-click-loc get distance 10 <= ;
+ hand-loc get-global hand-click-loc get-global distance 10 <= ;
: multi-click? ( button -- ? )
{
} 0&& nip ;
: update-click# ( button -- )
- global [
+ [
dup multi-click? [
hand-click# inc
] [
- 1 hand-click# set
+ 1 hand-click# namespaces:set
] if
- hand-last-button set
- nano-count hand-last-time set
- ] bind ;
+ hand-last-button namespaces:set
+ nano-count hand-last-time namespaces:set
+ ] with-global ;
: update-clicked ( -- )
hand-gadget get-global hand-clicked set-global
M: macosx modifiers>string
[
{
- { A+ [ "\u002318" ] }
- { M+ [ "\u002325" ] }
+ { M+ [ "\u002318" ] }
+ { A+ [ "\u002325" ] }
{ S+ [ "\u0021e7" ] }
{ C+ [ "\u002303" ] }
} case
- ] map "" join ;
+ ] map "" concat-as ;
M: object modifiers>string
- [ name>> ] map "" join ;
+ [ name>> ] map "" concat-as ;
HOOK: keysym>string os ( keysym -- string )
#>> [ " " % # ] when*
] "" make ;
+M: file-drop gesture>string drop "Drop files" ;
+
M: left-action gesture>string drop "Swipe left" ;
M: right-action gesture>string drop "Swipe right" ;
HOOK: action-modifier os ( -- mod )
M: object action-modifier C+ ;
-M: macosx action-modifier A+ ;
+M: macosx action-modifier M+ ;
M: action gesture>string
action-gestures value-at