]> gitweb.factorcode.org Git - factor.git/blob - core/ui/x11/utilities.factor
5166bed6bbf9618a4992643b709a6328ad1647ed
[factor.git] / core / ui / x11 / utilities.factor
1 ! Copyright (C) 2005, 2006 Eduardo Cavazos and Slava Pestov
2 ! See http://factorcode.org/license.txt for BSD license.
3 IN: x11
4 USING: alien arrays errors gadgets hashtables io kernel math
5 namespaces prettyprint sequences threads ;
6
7 : >int-array ( seq -- <int-array> )
8     dup length dup "int" <c-array> -rot
9     [ pick set-int-nth ] 2each ;
10
11 SYMBOL: dpy
12 SYMBOL: scr
13 SYMBOL: root
14
15 : flush-dpy ( -- ) dpy get XFlush drop ;
16
17 : x-atom ( string -- atom ) dpy get swap 0 XInternAtom ;
18
19 : check-display
20     [ "Cannot connect to X server - check $DISPLAY" throw ] unless* ;
21
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 ;
27
28 : close-x ( -- ) dpy get XCloseDisplay drop ;
29     
30 : with-x ( display-string quot -- )
31     >r initialize-x r> [ close-x ] cleanup ;