factor/contrib/factory/factory.factor

611 lines
20 KiB
Factor
Raw Normal View History

USING: kernel alien compiler namespaces generic math sequences hashtables io
arrays words prettyprint lists concurrency
process rectangle xlib x concurrent-widgets ;
2005-11-30 04:55:53 -05:00
2006-02-06 15:55:26 -05:00
IN: factory
2005-11-30 04:55:53 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2005-12-02 05:47:18 -05:00
DEFER: workspace-menu
DEFER: wm-frame?
DEFER: manage-window
DEFER: window-list
DEFER: refresh-window-list
DEFER: layout-frame
DEFER: mapped-windows
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: popup-window ( -- ) mouse-sensor move-window raise-window map-window ;
: popup-window% [ popup-window ] with-window-object ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2005-11-30 04:55:53 -05:00
SYMBOL: root-menu
: setup-root-menu ( -- )
create-menu root-menu set
"black" lookup-color root-menu get set-window-background%
2006-02-16 20:46:49 -05:00
"Terminal" [ "gnome-terminal &" system ] root-menu get add-popup-menu-item
"Emacs" [ "emacs &" system ] root-menu get add-popup-menu-item
"Firefox" [ "firefox &" system ] root-menu get add-popup-menu-item
2005-12-02 05:47:18 -05:00
"Workspaces"
[ workspace-menu get popup-window% ] root-menu get add-popup-menu-item ;
2005-11-30 04:55:53 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
SYMBOL: drag-gc
: make-drag-gc ( -- GC )
create-gc dup
[ IncludeInferiors set-subwindow-mode
GXxor set-function
white-pixel get set-foreground ] with-gcontext ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2005-11-30 04:55:53 -05:00
: MouseMask
[ ButtonPressMask
ButtonReleaseMask
PointerMotionMask ] 0 [ execute bitor ] reduce ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2005-11-30 04:55:53 -05:00
: drag-mouse-loop ( push last quot -- push release )
MouseMask mask-event XAnyEvent-type ! push last quot type
{ { [ dup MotionNotify = ]
[ drop 3dup call nip mouse-sensor swap drag-mouse-loop ] }
{ [ dup ButtonRelease = ]
[ drop 3dup nip f swap call 2drop
mouse-sensor ungrab-server CurrentTime ungrab-pointer flush-dpy ] }
{ [ t ]
[ drop "drag-mouse-loop ignoring event" print flush drag-mouse-loop ] }
} cond ;
: drag-mouse ( quot -- push release )
MouseMask grab-pointer grab-server mouse-sensor f rot drag-mouse-loop ;
: drag-mouse% [ drag-mouse ] with-window-object ;
2005-11-30 04:55:53 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: ((draw-move-outline)) ( a b - )
swap v- window-position v+ window-size <rect> root get draw-rect+ ;
: (draw-move-outline) ( push last -- )
dupd dup [ ((draw-move-outline)) ] [ 2drop ] if
mouse-sensor ((draw-move-outline)) flush-dpy ;
: draw-move-outline ( push last -- )
drag-gc get [ (draw-move-outline) ] with-gcontext ;
: drag-move-window ( -- )
[ draw-move-outline ] drag-mouse swap v- window-position v+ move-window ;
2005-11-30 04:55:53 -05:00
2006-02-23 18:24:27 -05:00
: drag-move-window% [ drag-move-window raise-window ] with-window-object ;
2005-11-30 04:55:53 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2005-11-30 04:55:53 -05:00
: ((draw-resize-outline)) ( bottom-right -- )
window-position v- window-position swap <rect> root get draw-rect+ ;
: (draw-resize-outline) ( push last -- )
nip dup [ ((draw-resize-outline)) ] [ drop ] if
mouse-sensor ((draw-resize-outline)) flush-dpy ;
: draw-resize-outline ( push last -- )
drag-gc get [ (draw-resize-outline) ] with-gcontext ;
: drag-resize-window ( -- )
[ draw-resize-outline ] drag-mouse nip window-position v- resize-window ;
: drag-resize-window% [ drag-resize-window ] with-window-object ;
2005-11-30 04:55:53 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
GENERIC: move-request-x
GENERIC: move-request-y
GENERIC: move-request-position
GENERIC: execute-move-request
GENERIC: size-request-width
GENERIC: size-request-height
GENERIC: size-request-size
GENERIC: execute-size-request
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! wm-root
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
TUPLE: wm-root ;
: create-wm-root ( window -- )
>r dpy get r> <window> ! <window>
<wm-root> ! <window> <wm-root>
[ set-delegate ] keep ! <wm-root>
[ add-to-window-table ] keep ! <wm-root>
[ SubstructureRedirectMask
SubstructureNotifyMask
ButtonPressMask
ButtonReleaseMask
KeyPressMask
KeyReleaseMask ] 0 [ execute bitor ] reduce ! <wm-frame> mask
over select-input% ; ! <wm-frame>
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! M: wm-root handle-map-request-event
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: id>obj ( id -- obj )
dup ! id id
window-table get hash ! id obj-or-f
dup
[ swap drop ]
[ drop >r dpy get r> <window> ]
2005-12-02 05:47:18 -05:00
if ;
2005-11-30 04:55:53 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
M: wm-root handle-map-request-event ( event <wm-root> -- )
drop XMapRequestEvent-window id>obj ! obj
{ { [ dup wm-frame? ]
[ map-window% ] }
{ [ dup valid-window?% not ]
[ "Not a valid window." print flush drop ] }
2005-11-30 04:55:53 -05:00
{ [ dup window-override-redirect% 1 = ]
[ "Not reparenting: " print
"new window has override_redirect attribute set." print flush
2005-11-30 04:55:53 -05:00
drop ] }
{ [ t ] [ window-id manage-window ] } }
cond ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Words for working with an XConfigureRequestEvent
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: bit-test ( a b -- t-or-f ) bitand 0 = not ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: move-request-x? ( event -- ) XConfigureRequestEvent-value_mask CWX bit-test ;
: move-request-y? ( event -- ) XConfigureRequestEvent-value_mask CWY bit-test ;
: move-request? ( event -- ? ) dup move-request-x? swap move-request-y? or ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: size-request-width? ( event -- )
XConfigureRequestEvent-value_mask CWWidth bit-test ;
: size-request-height? ( event -- )
XConfigureRequestEvent-value_mask CWHeight bit-test ;
: size-request? ( event -- )
dup size-request-width? swap size-request-height? or ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! M: wm-root handle-configure-request-event
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
M: wm-root move-request-x ( event wm-root -- x )
drop
dup move-request-x?
[ XConfigureRequestEvent-x ]
[ XConfigureRequestEvent-window [ window-x ] with-win ]
2005-12-02 05:47:18 -05:00
if ;
2005-11-30 04:55:53 -05:00
M: wm-root move-request-y ( event wm-root -- y )
drop
dup move-request-y?
[ XConfigureRequestEvent-y ]
[ XConfigureRequestEvent-window [ window-y ] with-win ]
2005-12-02 05:47:18 -05:00
if ;
2005-11-30 04:55:53 -05:00
M: wm-root move-request-position ( event wm-root -- { x y } )
2005-12-02 05:47:18 -05:00
2dup move-request-x -rot move-request-y 2array ;
2005-11-30 04:55:53 -05:00
M: wm-root execute-move-request ( event wm-root -- )
dupd move-request-position swap XConfigureRequestEvent-window move-window+ ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
M: wm-root size-request-width ( event wm-root -- width )
drop
dup size-request-width?
[ XConfigureRequestEvent-width ]
[ XConfigureRequestEvent-window [ window-width ] with-win ]
2005-12-02 05:47:18 -05:00
if ;
2005-11-30 04:55:53 -05:00
M: wm-root size-request-height ( event wm-root -- height )
drop
dup size-request-height?
[ XConfigureRequestEvent-height ]
[ XConfigureRequestEvent-window [ window-height ] with-win ]
2005-12-02 05:47:18 -05:00
if ;
2005-11-30 04:55:53 -05:00
M: wm-root size-request-size ( event wm-root -- { width height } )
2005-12-02 05:47:18 -05:00
2dup size-request-width -rot size-request-height 2array ;
2005-11-30 04:55:53 -05:00
M: wm-root execute-size-request ( event wm-root -- )
dupd size-request-size swap XConfigureRequestEvent-window resize-window+ ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
M: wm-root handle-configure-request-event ( event wm-root -- )
over move-request? [ 2dup execute-move-request ] when
over size-request? [ 2dup execute-size-request ] when
drop drop ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! M: wm-root handle-button-press-event
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
M: wm-root handle-button-press-event ( event wm-root -- )
drop ! event
{ { [ dup XButtonEvent-button Button1 = ]
[ root-menu get window-map-state% IsUnmapped =
[ XButtonEvent-root-position root-menu get move-window%
root-menu get raise-window%
root-menu get map-window% ]
[ root-menu get unmap-window% ]
2005-12-02 05:47:18 -05:00
if ] }
2005-11-30 04:55:53 -05:00
{ [ dup XButtonEvent-button Button2 = ]
[ window-list get window-map-state% IsUnmapped =
[ XButtonEvent-root-position window-list get move-window%
window-list get raise-window%
window-list get refresh-window-list
window-list get map-window% ]
[ window-list get unmap-window% ]
if ] }
{ [ t ] [ "Button has no function on root window." print flush drop ] } }
2005-11-30 04:55:53 -05:00
cond ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! M: wm-root handle-key-press-event
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
SYMBOL: f1-keycode 67 f1-keycode set-global
SYMBOL: f2-keycode 68 f2-keycode set-global
SYMBOL: f3-keycode 69 f3-keycode set-global
SYMBOL: f4-keycode 70 f4-keycode set-global
: grab-keys ( -- )
f1-keycode get Mod1Mask False GrabModeAsync GrabModeAsync grab-key
f2-keycode get Mod1Mask False GrabModeAsync GrabModeAsync grab-key
f3-keycode get Mod1Mask False GrabModeAsync GrabModeAsync grab-key
f4-keycode get Mod1Mask False GrabModeAsync GrabModeAsync grab-key ;
2005-11-30 04:55:53 -05:00
M: wm-root handle-key-press-event ( event wm-root -- )
drop
{ { [ dup XKeyEvent-keycode f1-keycode get = ] [ workspace-1 get switch-to ] }
{ [ dup XKeyEvent-keycode f2-keycode get = ] [ workspace-2 get switch-to ] }
{ [ dup XKeyEvent-keycode f3-keycode get = ] [ workspace-3 get switch-to ] }
{ [ dup XKeyEvent-keycode f4-keycode get = ] [ workspace-4 get switch-to ] }
{ [ t ] [ "wm-root ignoring key press" print drop ] } } cond ;
2005-11-30 04:55:53 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
TUPLE: wm-child ;
: create-wm-child ( id -- <wm-child> )
>r dpy get r> <window> <wm-child> ! <window> <wm-child>
[ set-delegate ] keep
[ add-to-window-table ] keep ;
M: wm-child handle-property-event ( child event -- )
"A <wm-child> received a property event" print flush drop drop ;
2005-11-30 04:55:53 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
TUPLE: wm-frame child ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: create-wm-frame ( child -- <wm-frame> )
>r create-window-object r> ! <window> child
<wm-frame> ! <window> <wm-frame>
[ set-delegate ] keep ! <wm-frame>
[ add-to-window-table ] keep ! <wm-frame>
[ SubstructureRedirectMask
SubstructureNotifyMask
ExposureMask
ButtonPressMask
ButtonReleaseMask
EnterWindowMask ] 0 [ execute bitor ] reduce ! <wm-frame> mask
over select-input% ; ! <wm-frame>
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: manage-window ( window -- )
grab-server
create-wm-child ! child
create-wm-frame ! frame
dup "cornflowerblue" lookup-color swap set-window-background%
dup wm-frame-child add-to-save-set% ! frame
dup wm-frame-child window-position% ! frame position
over ! frame position frame
move-window%
dup wm-frame-child 0 swap set-window-border-width%
dup dup wm-frame-child ! frame frame child
reparent-window%
dup wm-frame-child window-size% ! frame child-size
{ 20 20 } v+ ! frame child-size+
over ! frame child-size+ frame
resize-window%
dup wm-frame-child { 10 10 } swap move-window%
dup map-window%
dup map-subwindows%
dup wm-frame-child PropertyChangeMask swap select-input%
flush-dpy 0 sync-dpy ungrab-server ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: destroy-window-event-match? ( event <wm-frame> -- ? )
window-id swap XDestroyWindowEvent-window = ;
M: wm-frame handle-destroy-window-event ( event <wm-frame> -- )
2dup destroy-window-event-match?
2005-12-02 05:47:18 -05:00
[ destroy-window% drop ] [ drop drop ] if ;
2005-11-30 04:55:53 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: map-request-event-match? ( event <wm-frame> -- ? )
window-id swap XMapRequestEvent-window = ;
M: wm-frame handle-map-request-event ( event <wm-frame> -- )
2dup map-request-event-match? ! event frame ?
2005-12-02 05:47:18 -05:00
[ dup wm-frame-child map-window% map-window% drop ] [ drop drop ] if ;
2005-11-30 04:55:53 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: map-event-match? ( event <wm-frame> -- ? )
window-id swap XMapEvent-window = ;
M: wm-frame handle-map-event ( event <wm-frame> -- )
2dup map-event-match?
2005-12-02 05:47:18 -05:00
[ dup map-window% raise-window% drop ] [ drop drop ] if ;
2005-11-30 04:55:53 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! M: wm-frame handle-configure-request-event ( event frame )
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
M: wm-frame move-request-x ( event frame -- x )
over move-request-x?
[ drop XConfigureRequestEvent-x ]
[ nip window-x% ]
2005-12-02 05:47:18 -05:00
if ;
2005-11-30 04:55:53 -05:00
M: wm-frame move-request-y ( event frame -- y )
over move-request-y?
[ drop XConfigureRequestEvent-y ]
[ nip window-y% ]
2005-12-02 05:47:18 -05:00
if ;
2005-11-30 04:55:53 -05:00
M: wm-frame move-request-position ( event frame -- { x y } )
2005-12-02 05:47:18 -05:00
2dup move-request-x -rot move-request-y 2array ;
2005-11-30 04:55:53 -05:00
M: wm-frame execute-move-request ( event frame )
dup -rot move-request-position swap move-window% ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
M: wm-frame size-request-width ( event frame -- width )
over size-request-width?
[ drop XConfigureRequestEvent-width ]
[ nip wm-frame-child window-width% ]
2005-12-02 05:47:18 -05:00
if ;
2005-11-30 04:55:53 -05:00
M: wm-frame size-request-height ( event frame -- height )
over size-request-height?
[ drop XConfigureRequestEvent-height ]
[ nip wm-frame-child window-height% ]
2005-12-02 05:47:18 -05:00
if ;
2005-11-30 04:55:53 -05:00
M: wm-frame size-request-size ( event frame -- size )
2005-12-02 05:47:18 -05:00
2dup size-request-width -rot size-request-height 2array ;
2005-11-30 04:55:53 -05:00
: execute-size-request/child ( event frame )
dup wm-frame-child -rot size-request-size swap resize-window% ;
: execute-size-request/frame ( event frame )
dup -rot size-request-size { 20 20 } v+ swap resize-window% ;
M: wm-frame execute-size-request ( event frame )
2dup execute-size-request/child execute-size-request/frame ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
M: wm-frame handle-configure-request-event ( event frame )
over move-request? [ 2dup execute-move-request ] when
over size-request? [ 2dup execute-size-request ] when
drop drop ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: unmap-event-match? ( event frame -- ? )
wm-frame-child window-id swap XUnmapEvent-window = ;
M: wm-frame handle-unmap-event ( event frame )
2005-12-02 05:47:18 -05:00
2dup unmap-event-match? [ unmap-window% drop ] [ drop drop ] if ;
2005-11-30 04:55:53 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: drag-move-frame ( frame -- ) drag-move-window% ;
: drag-resize-frame ( frame -- ) dup drag-resize-window% layout-frame ;
2005-11-30 04:55:53 -05:00
M: wm-frame handle-button-press-event ( event frame )
over XButtonEvent-button ! event frame button
{ { [ dup Button1 = ] [ drop nip drag-move-frame ] }
{ [ dup Button2 = ] [ drop nip drag-resize-frame ] }
{ [ dup Button3 = ] [ drop nip unmap-window% ] }
2005-11-30 04:55:53 -05:00
{ [ t ] [ drop drop drop ] } }
cond ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
M: wm-frame handle-enter-window-event ( event frame )
nip dup wm-frame-child valid-window?%
[ wm-frame-child >r RevertToPointerRoot CurrentTime r> set-input-focus% ]
[ destroy-window% ]
2005-12-02 05:47:18 -05:00
if ;
2005-11-30 04:55:53 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
M: wm-frame handle-property-event ( event frame )
"Inside handle-property-event" print flush drop drop ;
2005-11-30 04:55:53 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: layout-frame ( frame -- )
dup wm-frame-child { 10 10 } swap move-window%
dup wm-frame-child ! frame child
over window-size% ! frame child size
{ 20 20 } v- ! frame child child-size
swap resize-window% ! frame
drop ;
2005-12-02 05:47:18 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Workspaces
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
GENERIC: switch-to
SYMBOL: current-workspace
TUPLE: workspace windows ;
: create-workspace [ ] <workspace> ;
M: workspace switch-to ( workspace -- )
mapped-windows dup current-workspace get set-workspace-windows
[ unmap-window+ ] each
dup workspace-windows [ map-window+ ] each
2006-02-06 15:55:26 -05:00
current-workspace set-global ;
2005-12-02 05:47:18 -05:00
SYMBOL: workspace-1
SYMBOL: workspace-2
SYMBOL: workspace-3
SYMBOL: workspace-4
2006-02-06 15:55:26 -05:00
create-workspace workspace-1 set-global
create-workspace workspace-2 set-global
create-workspace workspace-3 set-global
create-workspace workspace-4 set-global
2005-12-02 05:47:18 -05:00
2006-02-06 15:55:26 -05:00
workspace-1 get current-workspace set-global
2005-12-02 05:47:18 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
SYMBOL: workspace-menu
: setup-workspace-menu ( -- )
create-menu workspace-menu set
"black" lookup-color workspace-menu get set-window-background%
"Workspace 1"
[ workspace-1 get switch-to ] workspace-menu get add-popup-menu-item
"Workspace 2"
[ workspace-2 get switch-to ] workspace-menu get add-popup-menu-item
"Workspace 3"
[ workspace-3 get switch-to ] workspace-menu get add-popup-menu-item
"Workspace 4"
[ workspace-4 get switch-to ] workspace-menu get add-popup-menu-item ;
2006-02-23 18:26:45 -05:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: invalid-frame? ( <wm-frame> -- ? )
wm-frame-child window-id valid-window?+ not ;
: remove-invalid-frames ( -- )
window-table get hash-values [ wm-frame? ] subset [ invalid-frame? ] subset
[ window-id window-table get remove-hash ] each ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! window-list
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
SYMBOL: window-list
: setup-window-list ( -- )
create-menu window-list set
"black" lookup-color window-list get set-window-background% ;
: not-transient? ( frame -- ? ) wm-frame-child get-transient-for-hint% not ;
: add-window-to-list ( window-list frame -- window-list )
dup ! window-list frame frame
wm-frame-child ! window-list frame child
fetch-name% ! window-list frame name-or-f
dup ! window-list frame name-or-f name-or-f
2005-12-02 05:47:18 -05:00
[ ] [ drop "*untitled*" ] if ! window-list frame name
swap ! window-list name frame
[ map-window% ] ! window-list name frame [ map-window% ]
cons ! window-list name action
pick ! window-list name action window-list
add-popup-menu-item ;
: refresh-window-list ( window-list -- )
dup window-children% [ destroy-window+ ] each
2006-02-23 18:26:45 -05:00
clean-window-table
remove-invalid-frames
window-table get hash-values [ wm-frame? ] subset
[ not-transient? ] subset
[ add-window-to-list ] each
drop ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: window-is-mapped? ( window -- ? ) window-map-state+ IsUnmapped = not ;
: mapped-windows ( -- [ a b c d ... ] )
root get window-children+ [ window-is-mapped? ] subset ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: manage-existing-windows ( -- ) mapped-windows [ manage-window ] each ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: xlib-error-handler ( -- xt ) "void" { "Display*" "XErrorEvent*" }
[ "X11 : error-handler called" print flush ] alien-callback ; compiled
: install-error-handler ( -- ) xlib-error-handler XSetErrorHandler drop ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2005-11-30 04:55:53 -05:00
: start-factory ( dpy-string -- )
initialize-x
install-error-handler
root get [ make-drag-gc ] with-win drag-gc set
root get [ black-pixel get set-window-background clear-window ] with-win
2005-11-30 04:55:53 -05:00
root get create-wm-root
root get [ grab-keys ] with-win
setup-root-menu
setup-window-list
2005-12-02 05:47:18 -05:00
setup-workspace-menu
manage-existing-windows
[ concurrent-event-loop ] spawn ;