1 ! Copyright (C) 2005, 2006 Eduardo Cavazos and Slava Pestov
2 ! See http://factorcode.org/license.txt for BSD license.
4 USING: alien arrays errors gadgets hashtables io kernel math
5 namespaces prettyprint sequences threads ;
7 : >int-array ( seq -- <int-array> )
8 dup length dup "int" <c-array> -rot
9 [ pick set-int-nth ] 2each ;
15 : flush-dpy ( -- ) dpy get XFlush drop ;
17 : x-atom ( string -- atom ) dpy get swap 0 XInternAtom ;
20 [ "Cannot connect to X server - check $DISPLAY" throw ] unless* ;
22 : initialize-x ( display-string -- )
23 dup [ string>char-alien ] when
24 XOpenDisplay check-display dpy set-global
25 dpy get XDefaultScreen scr set-global
26 dpy get scr get XRootWindow root set-global ;
28 : close-x ( -- ) dpy get XCloseDisplay drop ;
30 : with-x ( display-string quot -- )
31 >r initialize-x r> [ close-x ] cleanup ;