factor/library/ui/x11/utilities.factor

32 lines
825 B
Factor
Raw Normal View History

2006-03-19 19:37:01 -05:00
! Copyright (C) 2005, 2006 Eduardo Cavazos and Slava Pestov
! See http://factorcode.org/license.txt for BSD license.
IN: x11
2006-03-20 00:05:04 -05:00
USING: alien arrays errors gadgets hashtables io kernel math
namespaces prettyprint sequences threads ;
2006-03-19 19:37:01 -05:00
SYMBOL: dpy
SYMBOL: scr
SYMBOL: root
: flush-dpy ( -- ) dpy get XFlush drop ;
: sync-dpy ( discard -- ) >r dpy get r> XSync ;
: x-atom ( string -- atom ) dpy get swap 0 XInternAtom ;
2006-03-19 23:17:14 -05:00
: check-display
[ "Cannot connect to X server - check $DISPLAY" throw ] unless* ;
2006-03-20 00:05:04 -05:00
: initialize-x ( display-string -- )
2006-03-19 23:17:14 -05:00
XOpenDisplay check-display dpy set
dpy get XDefaultScreen scr set
dpy get scr get XRootWindow root set ;
2006-03-22 17:22:05 -05:00
: close-x ( -- ) dpy get XCloseDisplay drop ;
2006-03-20 00:05:04 -05:00
: with-x ( display-string quot -- )
[
swap initialize-x
2006-03-22 17:22:05 -05:00
[ close-x ] cleanup
2006-03-20 00:05:04 -05:00
] with-scope ;