chiark / gitweb /
Imported Upstream version 1.0.0
[e16] / src / xwin.h
1 /*
2  * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
3  * Copyright (C) 2004-2008 Kim Woelders
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to
7  * deal in the Software without restriction, including without limitation the
8  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9  * sell copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies of the Software, its documentation and marketing & publicity
14  * materials, and acknowledgment shall be given in the documentation, materials
15  * and software packages that this Software was used.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20  * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #ifndef _XWIN_H_
25 #define _XWIN_H_
26
27 #include <X11/Xlib.h>
28 #include "util.h"
29 #include "xtypes.h"
30
31 typedef struct {
32    Display            *disp;
33    char               *name;
34    int                 screens;
35    int                 screen;
36    unsigned int        pixel_black;
37    unsigned int        pixel_white;
38
39    Win                 rroot;   /* Real root window */
40    Win                 vroot;   /* Virtual root window */
41
42    int                 server_grabbed;
43
44    unsigned char       last_error_code;
45 } EDisplay;
46
47 __EXPORT__ extern EDisplay Dpy;
48
49 #define disp  Dpy.disp
50 #define RROOT Dpy.rroot
51 #define VROOT Dpy.vroot
52
53 void                EXInit(void);
54
55 int                 EDisplayOpen(const char *dstr, int scr);
56 void                EDisplayClose(void);
57 void                EDisplayDisconnect(void);
58 void                EDisplaySetErrorHandlers(void (*fatal) (void));
59
60 void                EGrabServer(void);
61 void                EUngrabServer(void);
62 int                 EServerIsGrabbed(void);
63 void                EFlush(void);
64
65 #define ESYNC_MAIN      0x0001
66 #define ESYNC_DESKS     0x0002
67 #define ESYNC_MENUS     0x0004
68 #define ESYNC_MOVRES    0x0008
69 #define ESYNC_FOCUS     0x0010
70 #define ESYNC_TLOOP     0x0040
71 #define ESYNC_SLIDEOUT  0x0080
72 #define ESYNC_STARTUP   0x0100
73 void                ESync(unsigned int mask);
74
75 #if USE_COMPOSITE
76 int                 EVisualIsARGB(Visual * vis);
77 Visual             *EVisualFindARGB(void);
78 #endif
79
80 Time                EGetTimestamp(void);
81
82 typedef void        (EventCallbackFunc) (Win win, XEvent * ev, void *prm);
83
84 #define EXPOSE_WIN 1
85 #if EXPOSE_WIN || DECLARE_WIN
86 typedef struct {
87    EventCallbackFunc  *func;
88    void               *prm;
89 } EventCallbackItem;
90
91 typedef struct {
92    int                 num;
93    EventCallbackItem  *lst;
94 } EventCallbackList;
95
96 struct _xwin {
97    struct _xwin       *next;
98    struct _xwin       *prev;
99    EventCallbackList   cbl;
100    Window              xwin;
101    Win                 parent;
102    int                 x, y, w, h;
103    short               depth;
104    unsigned short      bw;
105    char                argb;
106    char                mapped;
107    char                in_use;
108    signed char         do_del;
109    char                attached;
110    signed char         bg_owned;        /* bgpmap "owned" by Win */
111    int                 num_rect;
112    int                 ord;
113    XRectangle         *rects;
114    Visual             *visual;
115    Colormap            cmap;
116    Pixmap              bgpmap;
117    unsigned int        bgcol;
118 };
119 #endif
120
121 Win                 ELookupXwin(Window xwin);
122
123 #if EXPOSE_WIN
124 #define             WinGetXwin(win)             ((win)->xwin)
125 #define             WinGetPmap(win)             ((win)->bgpmap)
126 #define             WinGetX(win)                ((win)->x)
127 #define             WinGetY(win)                ((win)->y)
128 #define             WinGetW(win)                ((win)->w)
129 #define             WinGetH(win)                ((win)->h)
130 #define             WinGetBorderWidth(win)      ((win)->bw)
131 #define             WinGetDepth(win)            ((win)->depth)
132 #define             WinGetVisual(win)           ((win)->visual)
133 #define             WinGetCmap(win)             ((win)->cmap)
134 #define             WinIsShaped(win)            ((win)->num_rect != 0)
135 #else
136 Window              WinGetXwin(const Win win);
137 int                 WinGetX(const Win win);
138 int                 WinGetY(const Win win);
139 int                 WinGetW(const Win win);
140 int                 WinGetH(const Win win);
141 int                 WinGetBorderWidth(const Win win);
142 int                 WinGetDepth(const Win win);
143 Visual             *WinGetVisual(const Win win);
144 Colormap            WinGetCmap(const Win win);
145 #endif
146
147 Win                 ECreateWinFromXwin(Window xwin);
148 void                EDestroyWin(Win win);
149
150 Win                 ERegisterWindow(Window xwin, XWindowAttributes * pxwa);
151 void                EUnregisterWindow(Win win);
152 void                EUnregisterXwin(Window xwin);
153 void                EventCallbackRegister(Win win, int type,
154                                           EventCallbackFunc * func, void *prm);
155 void                EventCallbackUnregister(Win win, int type,
156                                             EventCallbackFunc * func,
157                                             void *prm);
158 void                EventCallbacksProcess(Win win, XEvent * ev);
159
160 Win                 ECreateWindow(Win parent, int x, int y, int w, int h,
161                                   int saveunder);
162 Win                 ECreateArgbWindow(Win parent, int x, int y, int w, int h,
163                                       Win cwin);
164 Win                 ECreateWindowVD(Win parent, int x, int y, int w, int h,
165                                     Visual * vis, unsigned int depth);
166 Win                 ECreateClientWindow(Win parent, int x, int y, int w, int h);
167
168 #define WIN_TYPE_CLIENT     0
169 #define WIN_TYPE_INTERNAL   1
170 #define WIN_TYPE_NO_ARGB    2
171 #define WIN_TYPE_GLX        3
172 Win                 ECreateObjectWindow(Win parent, int x, int y, int w,
173                                         int h, int saveunder, int type,
174                                         Win cwin);
175 Win                 ECreateEventWindow(Win parent, int x, int y, int w, int h);
176 Win                 ECreateFocusWindow(Win parent, int x, int y, int w, int h);
177 void                EWindowSync(Win win);
178 void                EWindowSetGeometry(Win win, int x, int y, int w, int h,
179                                        int bw);
180 void                EWindowSetMapped(Win win, int mapped);
181 void                ESelectInputChange(Win win, unsigned long set,
182                                        unsigned long clear);
183
184 void                EMoveWindow(Win win, int x, int y);
185 void                EResizeWindow(Win win, int w, int h);
186 void                EMoveResizeWindow(Win win, int x, int y, int w, int h);
187 void                EDestroyWindow(Win win);
188 void                EMapWindow(Win win);
189 void                EMapRaised(Win win);
190 void                EUnmapWindow(Win win);
191 void                EReparentWindow(Win win, Win parent, int x, int y);
192 int                 EGetGeometry(Win win, Window * root_return,
193                                  int *x, int *y, int *w, int *h, int *bw,
194                                  int *depth);
195 void                EGetWindowAttributes(Win win, XWindowAttributes * pxwa);
196 void                EConfigureWindow(Win win, unsigned int mask,
197                                      XWindowChanges * wc);
198 void                ESetWindowBackgroundPixmap(Win win, Pixmap pmap);
199 Pixmap              EGetWindowBackgroundPixmap(Win win);
200 void                EFreeWindowBackgroundPixmap(Win win);
201 void                ESetWindowBackground(Win win, unsigned int col);
202 int                 ETranslateCoordinates(Win src_w, Win dst_w,
203                                           int src_x, int src_y,
204                                           int *dest_x_return,
205                                           int *dest_y_return,
206                                           Window * child_return);
207 int                 EDrawableCheck(Drawable draw, int grab);
208
209 void                ESelectInput(Win win, unsigned int event_mask);
210 void                EChangeWindowAttributes(Win win, unsigned int mask,
211                                             XSetWindowAttributes * attr);
212 void                ESetWindowBorderWidth(Win win, unsigned int bw);
213 void                ERaiseWindow(Win win);
214 void                ELowerWindow(Win win);
215 void                EClearWindow(Win win);
216 void                EClearArea(Win win, int x, int y,
217                                unsigned int w, unsigned int h);
218
219 Pixmap              ECreatePixmap(Win win, unsigned int width,
220                                   unsigned int height, unsigned int depth);
221 void                EFreePixmap(Pixmap pixmap);
222
223 void                EShapeSetMask(Win win, int x, int y, Pixmap mask);
224 void                EShapeUnionMask(Win win, int x, int y, Pixmap mask);
225 void                EShapeSetMaskTiled(Win win, int x, int y, Pixmap mask,
226                                        int w, int h);
227 void                EShapeSetRects(Win win, int x, int y,
228                                    XRectangle * rect, int n_rects);
229 void                EShapeUnionRects(Win win, int x, int y,
230                                      XRectangle * rect, int n_rects);
231 int                 EShapeSetShape(Win win, int x, int y, Win src_win);
232 int                 EShapePropagate(Win win);
233 int                 EShapeCheck(Win win);
234 Pixmap              EWindowGetShapePixmap(Win win);
235
236 Bool                EQueryPointer(Win win, int *px, int *py,
237                                   Window * pchild, unsigned int *pmask);
238
239 typedef struct {
240    unsigned long       pixel;
241    unsigned char       alpha, red, green, blue;
242 } EColor;
243
244 void                EAllocColor(Colormap cmap, EColor * pec);
245 void                EAllocXColor(Colormap cmap, XColor * pxc, EColor * pec);
246
247 #define SET_COLOR(xc, _r, _g, _b) \
248     do { (xc)->red = _r; (xc)->green = _g; (xc)->blue = _b; } while(0)
249
250 #define GET_COLOR(xc, _r, _g, _b) \
251     do { _r = (xc)->red; _g = (xc)->green; _b = (xc)->blue; } while(0)
252
253 Window              EXWindowGetParent(Window xwin);
254 int                 EXGetGeometry(Window xwin, Window * root_return,
255                                   int *x, int *y, int *w, int *h, int *bw,
256                                   int *depth);
257
258 void                EXRestackWindows(Window * windows, int nwindows);
259
260 void                EXCopyArea(Drawable src, Drawable dst, int sx, int sy,
261                                unsigned int w, unsigned int h, int dx, int dy);
262 void                EXCopyAreaTiled(Drawable src, Pixmap mask, Drawable dst,
263                                     int sx, int sy,
264                                     unsigned int w, unsigned int h,
265                                     int dx, int dy);
266
267 void                EXWarpPointer(Window xwin, int x, int y);
268
269 Pixmap              EXCreatePixmapCopy(Pixmap src, unsigned int w,
270                                        unsigned int h, unsigned int depth);
271
272 GC                  EXCreateGC(Drawable draw, unsigned long mask,
273                                XGCValues * val);
274 int                 EXFreeGC(GC gc);
275
276 void                EXSendEvent(Window xwin, long event_mask, XEvent * ev);
277
278 KeyCode             EKeysymToKeycode(KeySym keysym);
279 KeyCode             EKeynameToKeycode(const char *name);
280 const char         *EKeycodeToString(KeyCode keycode, int index);
281
282 Atom                EInternAtom(const char *name);
283
284 typedef struct {
285    char                type;
286    Pixmap              pmap;
287    Pixmap              mask;
288    int                 w, h;
289 } PmapMask;
290
291 void                FreePmapMask(PmapMask * pmm);
292
293 #endif /* _XWIN_H_ */