]> gitweb.factorcode.org Git - factor.git/blob - basis/x11/x11.factor
Fixes #2966
[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.c-types continuations io kernel namespaces
4 vocabs.loader x11.io x11.xlib ;
5 FROM: alien.c-types => c-bool> ;
6 IN: x11
7
8 SYMBOL: dpy
9 SYMBOL: scr
10 SYMBOL: root
11
12 : init-locale ( -- )
13    LC_ALL "" setlocale [ "setlocale() failed" print flush ] unless
14    XSupportsLocale c-bool> [ "XSupportsLocale() failed" print flush ] unless ;
15
16 : flush-dpy ( -- ) dpy get XFlush drop ;
17
18 : x-atom ( string -- atom ) [ dpy get ] dip 0 XInternAtom ;
19
20 : check-display ( alien -- alien' )
21     [ "Cannot connect to X server - check $DISPLAY" throw ] unless* ;
22
23 : init-x ( display-string -- )
24     init-locale
25     XOpenDisplay check-display dpy set-global
26     dpy get XDefaultScreen scr set-global
27     dpy get scr get XRootWindow root set-global
28     init-x-io ;
29
30 : close-x ( -- ) dpy get XCloseDisplay drop ;
31
32 : with-x ( display-string quot -- )
33     [ init-x ] dip [ close-x ] finally ; inline
34
35 { "x11" "io.backend.unix" } "x11.io.unix" require-when