1-----------------------------------------------------------------------------
2-- |
3-- Module      :  Graphics.X11.Xlib.Window
4-- Copyright   :  (c) Alastair Reid, 1999-2003
5-- License     :  BSD-style (see the file libraries/base/LICENSE)
6--
7-- Maintainer  :  libraries@haskell.org
8-- Stability   :  provisional
9-- Portability :  portable
10--
11-- A collection of FFI declarations for interfacing with Xlib Windows.
12--
13-----------------------------------------------------------------------------
14
15module Graphics.X11.Xlib.Window(
16        storeName,
17        createSimpleWindow,
18        createWindow,
19        translateCoordinates,
20        moveResizeWindow,
21        resizeWindow,
22        moveWindow,
23        reparentWindow,
24        mapSubwindows,
25        unmapSubwindows,
26        mapWindow,
27        lowerWindow,
28        raiseWindow,
29        circulateSubwindowsDown,
30        circulateSubwindowsUp,
31        circulateSubwindows,
32        iconifyWindow,
33        withdrawWindow,
34        destroyWindow,
35        destroySubwindows,
36        setWindowBorder,
37        setWindowBorderPixmap,
38        setWindowBorderWidth,
39        setWindowBackground,
40        setWindowBackgroundPixmap,
41        setWindowColormap,
42        addToSaveSet,
43        removeFromSaveSet,
44        changeSaveSet,
45        clearWindow,
46        clearArea,
47        restackWindows,
48
49        ) where
50
51import Graphics.X11.Types
52import Graphics.X11.Xlib.Types
53
54import Foreign
55import Foreign.C
56
57----------------------------------------------------------------
58-- Windows
59----------------------------------------------------------------
60
61-- | interface to the X11 library function @XStoreName()@.
62storeName :: Display -> Window -> String -> IO ()
63storeName display window name =
64        withCString name $ \ c_name ->
65        xStoreName display window c_name
66foreign import ccall unsafe "HsXlib.h XStoreName"
67        xStoreName :: Display -> Window -> CString -> IO ()
68
69-- | interface to the X11 library function @XCreateSimpleWindow()@.
70foreign import ccall unsafe "HsXlib.h XCreateSimpleWindow"
71        createSimpleWindow :: Display -> Window -> Position -> Position ->
72                Dimension -> Dimension -> CInt -> Pixel -> Pixel -> IO Window
73
74-- | interface to the X11 library function @XCreateWindow()@.
75foreign import ccall unsafe "HsXlib.h XCreateWindow"
76        createWindow :: Display -> Window -> Position -> Position ->
77                Dimension -> Dimension -> CInt -> CInt -> WindowClass ->
78                Visual -> AttributeMask -> Ptr SetWindowAttributes -> IO Window
79
80----------------------------------------------------------------
81
82--ToDo: find an effective way to use Maybes
83
84-- | interface to the X11 library function @XTranslateCoordinates()@.
85translateCoordinates :: Display -> Window -> Window -> Position -> Position ->
86        IO (Bool,Position,Position,Window)
87translateCoordinates display src_w dest_w src_x src_y =
88        alloca $ \ dest_x_return ->
89        alloca $ \ dest_y_return ->
90        alloca $ \ child_return -> do
91        res <- xTranslateCoordinates display src_w dest_w src_x src_y
92                        dest_x_return dest_y_return child_return
93        dest_x <- peek dest_x_return
94        dest_y <- peek dest_y_return
95        child  <- peek child_return
96        return (res, dest_x, dest_y, child)
97foreign import ccall unsafe "HsXlib.h XTranslateCoordinates"
98        xTranslateCoordinates :: Display -> Window -> Window ->
99                Position -> Position ->
100                Ptr Position -> Ptr Position -> Ptr Window -> IO Bool
101
102-- | interface to the X11 library function @XMoveResizeWindow()@.
103foreign import ccall unsafe "HsXlib.h XMoveResizeWindow"
104        moveResizeWindow             :: Display -> Window -> Position  -> Position  -> Dimension -> Dimension -> IO ()
105
106-- | interface to the X11 library function @XResizeWindow()@.
107foreign import ccall unsafe "HsXlib.h XResizeWindow"
108        resizeWindow                 :: Display -> Window -> Dimension -> Dimension -> IO ()
109
110-- | interface to the X11 library function @XMoveWindow()@.
111foreign import ccall unsafe "HsXlib.h XMoveWindow"
112        moveWindow                   :: Display -> Window -> Position  -> Position  -> IO ()
113
114-- | interface to the X11 library function @XReparentWindow()@.
115foreign import ccall unsafe "HsXlib.h XReparentWindow"
116        reparentWindow               :: Display -> Window -> Window -> Position -> Position  -> IO ()
117
118-- | interface to the X11 library function @XMapSubwindows()@.
119foreign import ccall unsafe "HsXlib.h XMapSubwindows"
120        mapSubwindows                :: Display -> Window -> IO ()
121
122-- | interface to the X11 library function @XUnmapSubwindows()@.
123foreign import ccall unsafe "HsXlib.h XUnmapSubwindows"
124        unmapSubwindows              :: Display -> Window -> IO ()
125
126-- | interface to the X11 library function @XMapWindow()@.
127foreign import ccall unsafe "HsXlib.h XMapWindow"
128        mapWindow                    :: Display -> Window -> IO ()
129-- Disnae exist: %fun XUnmapWindows                :: Display -> Window -> IO ()
130-- Disnae exist: %fun XMapRaisedWindow             :: Display -> Window -> IO ()
131
132-- | interface to the X11 library function @XLowerWindow()@.
133foreign import ccall unsafe "HsXlib.h XLowerWindow"
134        lowerWindow                  :: Display -> Window -> IO ()
135
136-- | interface to the X11 library function @XRaiseWindow()@.
137foreign import ccall unsafe "HsXlib.h XRaiseWindow"
138        raiseWindow                  :: Display -> Window -> IO ()
139
140-- | interface to the X11 library function @XCirculateSubwindowsDown()@.
141foreign import ccall unsafe "HsXlib.h XCirculateSubwindowsDown"
142        circulateSubwindowsDown      :: Display -> Window -> IO ()
143
144-- | interface to the X11 library function @XCirculateSubwindowsUp()@.
145foreign import ccall unsafe "HsXlib.h XCirculateSubwindowsUp"
146        circulateSubwindowsUp        :: Display -> Window -> IO ()
147
148-- | interface to the X11 library function @XCirculateSubwindows()@.
149foreign import ccall unsafe "HsXlib.h XCirculateSubwindows"
150        circulateSubwindows          :: Display -> Window -> CirculationDirection -> IO ()
151
152-- | interface to the X11 library function @XIconifyWindow()@.
153iconifyWindow  :: Display -> Window -> ScreenNumber -> IO ()
154iconifyWindow display window screenno =
155        throwIfZero "iconifyWindow"
156                (xIconifyWindow display window screenno)
157foreign import ccall unsafe "HsXlib.h XIconifyWindow"
158        xIconifyWindow  :: Display -> Window -> ScreenNumber -> IO Status
159
160-- | interface to the X11 library function @XWithdrawWindow()@.
161withdrawWindow :: Display -> Window -> ScreenNumber -> IO ()
162withdrawWindow display window screenno =
163        throwIfZero "withdrawWindow"
164                (xWithdrawWindow display window screenno)
165foreign import ccall unsafe "HsXlib.h XWithdrawWindow"
166        xWithdrawWindow :: Display -> Window -> ScreenNumber -> IO Status
167
168-- | interface to the X11 library function @XDestroyWindow()@.
169foreign import ccall unsafe "HsXlib.h XDestroyWindow"
170        destroyWindow                :: Display -> Window -> IO ()
171
172-- | interface to the X11 library function @XDestroySubwindows()@.
173foreign import ccall unsafe "HsXlib.h XDestroySubwindows"
174        destroySubwindows            :: Display -> Window -> IO ()
175
176-- | interface to the X11 library function @XSetWindowBorder()@.
177foreign import ccall unsafe "HsXlib.h XSetWindowBorder"
178        setWindowBorder              :: Display -> Window -> Pixel     -> IO ()
179
180-- | interface to the X11 library function @XSetWindowBorderPixmap()@.
181foreign import ccall unsafe "HsXlib.h XSetWindowBorderPixmap"
182        setWindowBorderPixmap        :: Display -> Window -> Pixmap    -> IO ()
183
184-- | interface to the X11 library function @XSetWindowBorderWidth()@.
185foreign import ccall unsafe "HsXlib.h XSetWindowBorderWidth"
186        setWindowBorderWidth         :: Display -> Window -> Dimension -> IO ()
187
188-- | interface to the X11 library function @XSetWindowBackground()@.
189foreign import ccall unsafe "HsXlib.h XSetWindowBackground"
190        setWindowBackground          :: Display -> Window -> Pixel     -> IO ()
191
192-- | interface to the X11 library function @XSetWindowBackgroundPixmap()@.
193foreign import ccall unsafe "HsXlib.h XSetWindowBackgroundPixmap"
194        setWindowBackgroundPixmap    :: Display -> Window -> Pixmap    -> IO ()
195
196-- | interface to the X11 library function @XSetWindowColormap()@.
197foreign import ccall unsafe "HsXlib.h XSetWindowColormap"
198        setWindowColormap            :: Display -> Window -> Colormap  -> IO ()
199
200-- | interface to the X11 library function @XAddToSaveSet()@.
201foreign import ccall unsafe "HsXlib.h XAddToSaveSet"
202        addToSaveSet                 :: Display -> Window -> IO ()
203
204-- | interface to the X11 library function @XRemoveFromSaveSet()@.
205foreign import ccall unsafe "HsXlib.h XRemoveFromSaveSet"
206        removeFromSaveSet            :: Display -> Window -> IO ()
207
208-- | interface to the X11 library function @XChangeSaveSet()@.
209foreign import ccall unsafe "HsXlib.h XChangeSaveSet"
210        changeSaveSet                :: Display -> Window -> ChangeSaveSetMode -> IO ()
211
212-- | interface to the X11 library function @XClearWindow()@.
213foreign import ccall unsafe "HsXlib.h XClearWindow"
214        clearWindow                  :: Display -> Window -> IO ()
215
216-- | interface to the X11 library function @XClearArea()@.
217foreign import ccall unsafe "HsXlib.h XClearArea"
218        clearArea                    :: Display -> Window ->
219                Position -> Position -> Dimension -> Dimension -> Bool -> IO ()
220
221-- This is almost good enough - but doesn't call XFree
222-- -- %errfun BadStatus XQueryTree :: Display -> Window -> IO (Window, Window, ListWindow) using err = XQueryTree(arg1,arg2,&res1,&res2,&res3,&res3_size)
223-- %prim XQueryTree :: Display -> Window -> IO (Window, Window, ListWindow)
224-- Window root_w, parent;
225-- Int children_size;
226-- Window *children;
227-- Status r = XQueryTree(arg1,arg2,&root_w, &parent, &children, &children_size);
228-- if (Success != r) { %failWith(BadStatus,r); }
229-- %update(root_w,parent,children);
230-- XFree(children);
231-- return;
232
233-- | interface to the X11 library function @XRestackWindows()@.
234restackWindows :: Display -> [Window] -> IO ()
235restackWindows display windows =
236        withArray windows $ \ window_array ->
237        xRestackWindows display window_array (fromIntegral (length windows))
238foreign import ccall unsafe "HsXlib.h XRestackWindows"
239        xRestackWindows :: Display -> Ptr Window -> CInt -> IO ()
240
241-- ToDo: I want to be able to write this
242-- -- %fun XListInstalledColormaps :: Display -> Window -> IO ListColormap using res1 = XListInstalledColormaps(arg1,arg2,&res1_size)
243-- -- But I have to write this instead - need to add a notion of cleanup code!
244-- %prim XListInstalledColormaps :: Display -> Window -> IO ListColormap
245-- Int r_size;
246-- Colormap* r = XListInstalledColormaps(arg1,arg2,&r_size);
247-- %update(r);
248-- XFree(r);
249-- return;
250--
251-- -- Again, this is almost good enough
252-- -- %errfun BadStatus XGetCommand :: Display -> Window -> IO ListString using err = XGetCommand(arg1,arg2,&res1,&res1_size)
253-- -- but not quite
254-- -- %prim XGetCommand :: Display -> Window -> IO ListString
255-- --Int    argv_size;
256-- --String *argv;
257-- --Status r = XGetCommand(arg1,arg2,&argv,&argv_size);
258-- --if (Success != r) { %failWith(BadStatus, r); }
259-- -- %update(argv);
260-- --XFreeStringList(argv);
261-- --return;
262--
263-- -- %fun XSetCommand :: Display -> Window -> ListString -> IO ()            using XSetCommand(arg1,arg2,arg3,res3_size)
264--
265-- %errfun BadStatus XGetTransientForHint :: Display -> Window -> IO Window using err = XGetTransientForHint(arg1,arg2,&res1)
266--
267-- %fun XSetTransientForHint :: Display -> Window -> Window -> IO ()
268--
269-- -- XRotateWindowProperties omitted
270-- -- XGetWindowProperty omitted
271--
272-- -- XGetWindowAttributes omitted
273-- -- XChangeWindowAttributes omitted
274
275----------------------------------------------------------------
276-- End
277----------------------------------------------------------------
278