1 ! Copyright (C) 2005, 2010 Eduardo Cavazos, Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien.data classes.struct fry kernel literals math
4 math.vectors namespaces sequences x11 x11.X x11.events x11.glx
8 CONSTANT: create-window-mask
9 flags{ CWBackPixel CWBorderPixel CWColormap CWEventMask }
11 : create-colormap ( visinfo -- colormap )
12 [ dpy get root get ] dip visual>> AllocNone
30 : window-attributes ( visinfo -- attributes )
31 XSetWindowAttributes new
34 event-mask >>event_mask
35 swap create-colormap >>colormap ;
37 : set-size-hints ( window -- )
40 [ dpy get ] 2dip XSetWMNormalHints ;
42 : auto-position ( window loc -- )
43 { 0 0 } = [ drop ] [ set-size-hints ] if ;
45 : >xy ( pair -- x y ) first2 [ >integer ] bi@ ;
47 : create-window ( loc dim visinfo -- window )
49 [ [ [ dpy get root get ] dip >xy ] dip { 1 1 } vmax >xy 0 ] dip
50 [ depth>> InputOutput ] keep
51 [ visual>> create-window-mask ] keep
52 window-attributes XCreateWindow
56 : glx-window ( loc dim visual -- window glx )
57 [ create-window ] [ create-glx ] bi ;
59 : create-pixmap ( dim visual -- pixmap )
60 [ [ { 0 0 } swap ] dip create-window ] [
61 drop [ dpy get ] 2dip first2 24 XCreatePixmap
62 [ "Failed to create offscreen pixmap" throw ] unless*
65 : (create-glx-pixmap) ( pixmap visual -- pixmap glx-pixmap )
67 [ dpy get ] 2dip swap glXCreateGLXPixmap
68 [ "Failed to create offscreen GLXPixmap" throw ] unless*
71 : create-glx-pixmap ( dim visual -- pixmap glx-pixmap )
72 [ create-pixmap ] [ (create-glx-pixmap) ] bi ;
74 : glx-pixmap ( dim visual -- glx pixmap glx-pixmap )
75 [ nip create-glx ] [ create-glx-pixmap ] 2bi ;
77 : destroy-window ( win -- )
78 dpy get swap XDestroyWindow drop ;
80 : set-closable ( win -- )
81 dpy get swap XA_WM_DELETE_WINDOW Atom <ref> 1
82 XSetWMProtocols drop ;
84 : map-window ( win -- ) dpy get swap XMapWindow drop ;
86 : unmap-window ( win -- ) dpy get swap XUnmapWindow drop ;
88 : pixmap-bits ( dim pixmap -- alien )
89 swap first2 '[ dpy get _ 0 0 _ _ AllPlanes ZPixmap XGetImage ] call
90 [ XImage-pixels ] [ XDestroyImage drop ] bi ;