]> gitweb.factorcode.org Git - factor.git/blob - basis/x11/x11.factor
continuations[-docs]: add the finally word
[factor.git] / basis / x11 / x11.factor
1 ! Copyright (C) 2005, 2009 Eduardo Cavazos, Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien.strings continuations io
4 io.encodings.ascii kernel namespaces x11.xlib x11.io
5 vocabs vocabs.loader ;
6 FROM: alien.c-types => c-bool> ;
7 IN: x11
8
9 SYMBOL: dpy
10 SYMBOL: scr
11 SYMBOL: root
12
13 : init-locale ( -- )
14    LC_ALL "" setlocale [ "setlocale() failed" print flush ] unless
15    XSupportsLocale c-bool> [ "XSupportsLocale() failed" print flush ] unless ;
16
17 : flush-dpy ( -- ) dpy get XFlush drop ;
18
19 : x-atom ( string -- atom ) [ dpy get ] dip 0 XInternAtom ;
20
21 : check-display ( alien -- alien' )
22     [ "Cannot connect to X server - check $DISPLAY" throw ] unless* ;
23
24 : init-x ( display-string -- )
25     init-locale
26     XOpenDisplay check-display dpy set-global
27     dpy get XDefaultScreen scr set-global
28     dpy get scr get XRootWindow root set-global
29     init-x-io ;
30
31 : close-x ( -- ) dpy get XCloseDisplay drop ;
32
33 : with-x ( display-string quot -- )
34     [ init-x ] dip [ close-x ] finally ; inline
35
36 { "x11" "io.backend.unix" } "x11.io.unix" require-when