1 /* 2 * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors 3 * Copyright (C) 2004-2021 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 "util.h" 28 #include "xtypes.h" 29 30 typedef struct { 31 char *name; 32 int screens; 33 int screen; 34 unsigned int pixel_black; 35 unsigned int pixel_white; 36 37 Win rroot; /* Real root window */ 38 Win vroot; /* Virtual root window */ 39 40 void *root_gc; 41 42 int server_grabbed; 43 44 unsigned char last_error_code; 45 } EDisplay; 46 47 extern EDisplay Dpy; 48 extern Display *disp; 49 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 59 typedef void (EXErrorHandler) (const XEvent *); 60 typedef void (EXIOErrorHandler) (void); 61 void EDisplaySetErrorHandlers(EXErrorHandler * error, 62 EXIOErrorHandler * fatal); 63 64 void EGrabServer(void); 65 void EUngrabServer(void); 66 int EServerIsGrabbed(void); 67 void EFlush(void); 68 69 #define ESYNC_MAIN 0x0001 70 #define ESYNC_DESKS 0x0002 71 #define ESYNC_MENUS 0x0004 72 #define ESYNC_MOVRES 0x0008 73 #define ESYNC_FOCUS 0x0010 74 #define ESYNC_SLIDEOUT 0x0080 75 void ESync(unsigned int mask); 76 77 int EVisualIsARGB(Visual * vis); 78 Visual *EVisualFindARGB(void); 79 80 EX_Time EGetTimestamp(void); 81 82 typedef void (EventCallbackFunc) (Win win, XEvent * ev, void *prm); 83 84 typedef struct { 85 EventCallbackFunc *func; 86 void *prm; 87 } EventCallbackItem; 88 89 typedef struct { 90 int num; 91 EventCallbackItem *lst; 92 } EventCallbackList; 93 94 struct _xwin { 95 struct _xwin *next; 96 struct _xwin *prev; 97 EventCallbackList cbl; 98 EX_Window xwin; 99 Win parent; 100 int x, y, w, h; 101 short depth; 102 unsigned short bw; 103 char argb; 104 char mapped; 105 char in_use; 106 signed char do_del; 107 char attached; 108 signed char bg_owned; /* bgpmap "owned" by Win */ 109 int num_rect; 110 int ord; 111 XRectangle *rects; 112 Visual *visual; 113 EX_Colormap cmap; 114 EX_Pixmap bgpmap; 115 unsigned int bgcol; 116 #if USE_XI2 117 unsigned int event_mask; 118 #endif 119 }; 120 121 Win ELookupXwin(EX_Window xwin); 122 123 #define WinGetParent(win) ((win)->parent) 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 WinGetNumRect(win) ((win)->num_rect) 135 #define WinIsMapped(win) ((win)->mapped != 0) 136 #define WinIsShaped(win) ((win)->num_rect != 0) 137 138 Win ECreateWinFromXwin(EX_Window xwin); 139 void EDestroyWin(Win win); 140 141 Win ERegisterWindow(EX_Window xwin, XWindowAttributes * pxwa); 142 void EUnregisterWindow(Win win); 143 void EUnregisterXwin(EX_Window xwin); 144 void EventCallbackRegister(Win win, EventCallbackFunc * func, 145 void *prm); 146 void EventCallbackUnregister(Win win, EventCallbackFunc * func, 147 void *prm); 148 void EventCallbacksProcess(Win win, XEvent * ev); 149 150 Win ECreateWindow(Win parent, int x, int y, int w, int h, 151 int saveunder); 152 Win ECreateArgbWindow(Win parent, int x, int y, int w, int h, 153 Win cwin); 154 Win ECreateClientWindow(Win parent, int x, int y, int w, int h); 155 156 #define WIN_TYPE_CLIENT 0 157 #define WIN_TYPE_INTERNAL 1 158 #define WIN_TYPE_NO_ARGB 2 159 #define WIN_TYPE_GLX 3 160 Win ECreateObjectWindow(Win parent, int x, int y, int w, 161 int h, int saveunder, int type, 162 Win cwin); 163 Win ECreateEventWindow(Win parent, int x, int y, int w, int h); 164 void EWindowSync(Win win); 165 void EWindowSetGeometry(Win win, int x, int y, int w, int h, 166 int bw); 167 void EWindowSetMapped(Win win, int mapped); 168 169 void EMoveWindow(Win win, int x, int y); 170 void EResizeWindow(Win win, int w, int h); 171 void EMoveResizeWindow(Win win, int x, int y, int w, int h); 172 void EDestroyWindow(Win win); 173 void EMapWindow(Win win); 174 void EMapRaised(Win win); 175 void EUnmapWindow(Win win); 176 void EReparentWindow(Win win, Win parent, int x, int y); 177 void EGetWindowAttributes(Win win, XWindowAttributes * pxwa); 178 void EConfigureWindow(Win win, unsigned int mask, 179 XWindowChanges * wc); 180 void ESetWindowBackgroundPixmap(Win win, EX_Pixmap pmap, 181 int kept); 182 EX_Pixmap EGetWindowBackgroundPixmap(Win win); 183 void EFreeWindowBackgroundPixmap(Win win); 184 void ESetWindowBackground(Win win, unsigned int col); 185 int ETranslateCoordinates(Win src_w, Win dst_w, 186 int src_x, int src_y, 187 int *dest_x_return, 188 int *dest_y_return, 189 EX_Window * child_return); 190 int EXDrawableOk(EX_Drawable draw); 191 int EXWindowOk(EX_Window xwin); 192 193 void ESelectInput(Win win, unsigned int event_mask); 194 void ESelectInputChange(Win win, unsigned int set, 195 unsigned int clear); 196 void EChangeWindowAttributes(Win win, unsigned int mask, 197 XSetWindowAttributes * attr); 198 void ESetWindowBorderWidth(Win win, unsigned int bw); 199 void ERaiseWindow(Win win); 200 void ELowerWindow(Win win); 201 void EClearWindow(Win win); 202 void EClearWindowExpose(Win win); 203 void EClearArea(Win win, int x, int y, 204 unsigned int w, unsigned int h); 205 206 EX_Pixmap ECreatePixmap(Win win, unsigned int width, 207 unsigned int height, unsigned int depth); 208 void EFreePixmap(EX_Pixmap pixmap); 209 210 int EShapeUpdate(Win win); 211 void EShapeSetMask(Win win, int x, int y, EX_Pixmap mask); 212 void EShapeUnionMask(Win win, int x, int y, EX_Pixmap mask); 213 void EShapeSetMaskTiled(Win win, int x, int y, EX_Pixmap mask, 214 int w, int h); 215 void EShapeSetRects(Win win, int x, int y, 216 XRectangle * rect, int n_rects); 217 void EShapeUnionRects(Win win, int x, int y, 218 XRectangle * rect, int n_rects); 219 int EShapeSetShape(Win win, int x, int y, Win src_win); 220 int EShapePropagate(Win win); 221 int EShapeCheck(Win win); 222 EX_Pixmap EWindowGetShapePixmap(Win win); 223 EX_Pixmap EWindowGetShapePixmapInverted(Win win); 224 225 void EWarpPointer(Win win, int x, int y); 226 int EQueryPointer(Win win, int *px, int *py, 227 EX_Window * pchild, unsigned int *pmask); 228 229 unsigned int EAllocColor(EX_Colormap cmap, unsigned int argb); 230 231 #define _A(x) (((x) >> 24) & 0xff) 232 #define _R(x) (((x) >> 16) & 0xff) 233 #define _G(x) (((x) >> 8) & 0xff) 234 #define _B(x) (((x) ) & 0xff) 235 #define _A16(x) (((x) >> 16) & 0xff00) 236 #define _R16(x) (((x) >> 8) & 0xff00) 237 #define _G16(x) (((x) ) & 0xff00) 238 #define _B16(x) (((x) << 8) & 0xff00) 239 240 #define COLOR32_FROM_RGB(c, r, g, b) \ 241 c = (0xff000000 | (((r) & 0xff) << 16) | (((g) & 0xff) << 8) | ((b) & 0xff)) 242 #define COLOR32_TO_RGB(c, r, g, b) \ 243 do { r = _R(c); g = _G(c); b = _B(c); } while (0) 244 #define COLOR32_TO_ARGB(c, a, r, g, b) \ 245 do { a = _A(c); r = _R(c); g = _G(c); b = _B(c); } while (0) 246 #define COLOR32_TO_RGB16(c, r, g, b) \ 247 do { r = _R16(c); g = _G16(c); b = _B16(c); } while (0) 248 #define COLOR32_TO_ARGB16(c, a, r, g, b) \ 249 do { a = _A16(c); r = _R16(c); g = _G16(c); b = _B16(c); } while (0) 250 251 EX_Window EXWindowGetParent(EX_Window xwin); 252 int EXGetWindowAttributes(EX_Window xwin, 253 XWindowAttributes * pxwa); 254 int EXGetSize(EX_Window xwin, int *w, int *h); 255 256 void EXRestackWindows(EX_Window * windows, int nwindows); 257 258 void EXCopyAreaGC(EX_Drawable src, EX_Drawable dst, GC gc, 259 int sx, int sy, unsigned int w, unsigned int h, 260 int dx, int dy); 261 void EXCopyArea(EX_Drawable src, EX_Drawable dst, int sx, 262 int sy, unsigned int w, unsigned int h, int dx, 263 int dy); 264 void EXCopyAreaTiled(EX_Drawable src, EX_Pixmap mask, 265 EX_Drawable dst, int sx, int sy, 266 unsigned int w, unsigned int h, int dx, 267 int dy); 268 void EXFillAreaSolid(EX_Drawable dst, int x, int y, 269 unsigned int w, unsigned int h, 270 unsigned int pixel); 271 void EXPaintRectangle(EX_Drawable dst, int x, int y, 272 unsigned int w, unsigned int h, 273 unsigned int fg, unsigned int bg); 274 275 void EXWarpPointer(EX_Window xwin, int x, int y); 276 int EXQueryPointer(EX_Window xwin, int *px, int *py, 277 EX_Window * pchild, unsigned int *pmask); 278 279 EX_Pixmap EXCreatePixmapCopy(EX_Pixmap src, unsigned int w, 280 unsigned int h, unsigned int depth); 281 282 GC EXCreateGC(EX_Drawable draw, unsigned int mask, 283 XGCValues * val); 284 void EXFreeGC(GC gc); 285 286 void EXSendEvent(EX_Window xwin, unsigned int event_mask, 287 XEvent * ev); 288 289 EX_KeyCode EKeysymToKeycode(EX_KeySym keysym); 290 EX_KeyCode EKeynameToKeycode(const char *name); 291 292 typedef struct { 293 char type; 294 char depth; 295 EX_Pixmap pmap; 296 EX_Pixmap mask; 297 unsigned short w, h; 298 } PmapMask; 299 300 void PmapMaskInit(PmapMask * pmm, Win win, int w, int h); 301 void PmapMaskFree(PmapMask * pmm); 302 303 #if USE_XRENDER 304 EX_Picture EPictureCreate(Win win, EX_Drawable draw); 305 EX_Picture EPictureCreateII(Win win, EX_Drawable draw); 306 EX_Picture EPictureCreateSolid(EX_Window xwin, int argb, 307 unsigned int a, unsigned int rgb); 308 EX_Picture EPictureCreateBuffer(Win win, int w, int h, int argb, 309 EX_Pixmap * ppmap); 310 void EPictureDestroy(EX_Picture pict); 311 void EPictureFillRect(EX_Picture pict, int x, int y, 312 int w, int h, unsigned int color); 313 314 #endif /* USE_XRENDER */ 315 316 #if USE_COMPOSITE 317 318 EX_SrvRegion ERegionCreate(void); 319 EX_SrvRegion ERegionCreateRect(int x, int y, int w, int h); 320 321 #if USE_DESK_EXPOSE 322 EX_SrvRegion ERegionCreateFromRects(XRectangle * rectangles, 323 int nrectangles); 324 #endif 325 EX_SrvRegion ERegionCreateFromWindow(Win win); 326 EX_SrvRegion ERegionCreateFromBitmap(EX_Pixmap mask); 327 EX_SrvRegion ERegionCopy(EX_SrvRegion rgn, EX_SrvRegion src); 328 EX_SrvRegion ERegionClone(EX_SrvRegion src); 329 void ERegionDestroy(EX_SrvRegion rgn); 330 void ERegionEmpty(EX_SrvRegion rgn); 331 void ERegionSetRect(EX_SrvRegion rgn, int x, int y, int w, 332 int h); 333 void ERegionTranslate(EX_SrvRegion rgn, int dx, int dy); 334 void ERegionIntersect(EX_SrvRegion dst, EX_SrvRegion src); 335 void ERegionSubtract(EX_SrvRegion dst, EX_SrvRegion src); 336 void ERegionUnion(EX_SrvRegion dst, EX_SrvRegion src); 337 void ERegionIntersectOffset(EX_SrvRegion dst, int dx, int dy, 338 EX_SrvRegion src, EX_SrvRegion tmp); 339 void ERegionSubtractOffset(EX_SrvRegion dst, int dx, int dy, 340 EX_SrvRegion src, EX_SrvRegion tmp); 341 void ERegionUnionOffset(EX_SrvRegion dst, int dx, int dy, 342 EX_SrvRegion src, EX_SrvRegion tmp); 343 #if 0 /* Unused (for debug) */ 344 int ERegionIsEmpty(EX_SrvRegion rgn); 345 #endif 346 void ERegionShow(const char *txt, EX_SrvRegion rgn, 347 void (*prf)(const char *fmt, ...)); 348 349 void EGCSetClip(GC gc, EX_SrvRegion clip); 350 void EPictureSetClip(EX_Picture pict, EX_SrvRegion clip); 351 352 EX_Pixmap EWindowGetPixmap(const Win win); 353 354 #endif /* USE_COMPOSITE */ 355 356 #if USE_XI2 357 #include <X11/extensions/XInput2.h> 358 359 typedef struct { 360 XIEventMask em; 361 unsigned char mb[(XI_LASTEVENT + 8) / 8]; /* Mask bits */ 362 } EXIEventMask; 363 364 void EXIMaskSetup(EXIEventMask * em, int dev, 365 unsigned int event_mask); 366 #endif 367 368 #endif /* _XWIN_H_ */ 369