x11.h (8892B)
1 /* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail> 2 * See LICENSE file for license details. 3 */ 4 #define Window XWindow 5 #define Font XFont 6 #define Screen XScreen 7 #define Mask XMask 8 #include <stuff/geom.h> 9 #include <X11/Xlib.h> 10 #include <X11/Xutil.h> 11 #include <X11/extensions/Xrender.h> 12 #ifdef _X11_VISIBLE 13 # include <X11/Xatom.h> 14 # include <X11/extensions/shape.h> 15 # include <X11/extensions/Xrandr.h> 16 #endif 17 #undef Window 18 #undef Font 19 #undef Screen 20 #undef Mask 21 22 enum FontType { 23 FX11 = 1, 24 FFontSet, 25 FXft, 26 }; 27 28 enum WindowType { 29 WWindow, 30 WImage, 31 }; 32 33 typedef enum FontType FontType; 34 typedef enum WindowType WindowType; 35 36 typedef XSetWindowAttributes WinAttr; 37 38 typedef union ClientMessageData ClientMessageData; 39 typedef struct Color Color; 40 typedef struct CTuple CTuple; 41 typedef struct ErrorCode ErrorCode; 42 typedef struct Ewmh Ewmh; 43 typedef struct Font Font; 44 typedef struct Handlers Handlers; 45 typedef struct HandlersLink HandlersLink; 46 typedef struct Screen Screen; 47 typedef struct WinHints WinHints; 48 typedef struct Window Image; 49 typedef struct Window Window; 50 typedef struct Xft Xft; 51 typedef struct XftColor XftColor; 52 typedef void XftDraw; 53 typedef struct XftFont XftFont; 54 55 union ClientMessageData { 56 char b[20]; 57 short s[10]; 58 long l[5]; 59 }; 60 61 struct Color { 62 ushort red; 63 ushort green; 64 ushort blue; 65 ushort alpha; 66 ulong pixel; 67 }; 68 69 struct CTuple { 70 Color bg; 71 Color fg; 72 Color border; 73 char colstr[64]; 74 }; 75 76 struct ErrorCode { 77 uchar rcode; 78 uchar ecode; 79 }; 80 81 struct Ewmh { 82 long type; 83 ulong ping; 84 ulong lag; 85 }; 86 87 struct Font { 88 int type; 89 union { 90 XFontStruct* x11; 91 XFontSet set; 92 XftFont* xft; 93 } font; 94 Rectangle pad; 95 int ascent; 96 int descent; 97 uint height; 98 char* name; 99 }; 100 101 struct Handlers { 102 Rectangle (*dndmotion)(Window*, void*, Point); 103 bool (*bdown)(Window*, void*, XButtonEvent*); 104 bool (*bup)(Window*, void*, XButtonEvent*); 105 bool (*config)(Window*, void*, XConfigureEvent*); 106 bool (*configreq)(Window*, void*, XConfigureRequestEvent*); 107 bool (*destroy)(Window*, void*, XDestroyWindowEvent*); 108 bool (*enter)(Window*, void*, XCrossingEvent*); 109 bool (*expose)(Window*, void*, XExposeEvent*); 110 bool (*focusin)(Window*, void*, XFocusChangeEvent*); 111 bool (*focusout)(Window*, void*, XFocusChangeEvent*); 112 bool (*kdown)(Window*, void*, XKeyEvent*); 113 bool (*kup)(Window*, void*, XKeyEvent*); 114 bool (*leave)(Window*, void*, XCrossingEvent*); 115 bool (*map)(Window*, void*, XMapEvent*); 116 bool (*mapreq)(Window*, void*, XMapRequestEvent*); 117 bool (*message)(Window*, void*, XClientMessageEvent*); 118 bool (*motion)(Window*, void*, XMotionEvent*); 119 bool (*property)(Window*, void*, XPropertyEvent*); 120 bool (*reparent)(Window*, void*, XReparentEvent*); 121 bool (*selection)(Window*, void*, XSelectionEvent*); 122 bool (*selectionclear)(Window*, void*, XSelectionClearEvent*); 123 bool (*selectionrequest)(Window*, void*, XSelectionRequestEvent*); 124 bool (*unmap)(Window*, void*, XUnmapEvent*); 125 }; 126 127 struct HandlersLink { 128 HandlersLink* next; 129 void* aux; 130 Handlers* handler; 131 }; 132 133 struct WinHints { 134 Point min; 135 Point max; 136 Point base; 137 Point baspect; 138 Point inc; 139 Point grav; 140 Rectangle aspect; 141 XWindow group; 142 bool gravstatic; 143 bool position; 144 }; 145 146 struct Window { 147 int type; 148 XID xid; 149 XIC xic; 150 GC gc; 151 Visual* visual; 152 Colormap colormap; 153 XftDraw* xft; 154 Rectangle r; 155 int border; 156 Window* parent; 157 Window* next; 158 Window* prev; 159 Handlers* handler; 160 HandlersLink* handler_link; 161 WinHints* hints; 162 Ewmh ewmh; 163 long eventmask; 164 void* dnd; 165 void* aux; 166 bool mapped; 167 int unmapped; 168 int depth; 169 }; 170 171 struct Xft { 172 XftDraw* (*drawcreate)(Display*, Drawable, Visual*, Colormap); 173 void (*drawdestroy)(XftDraw*); 174 XftFont* (*fontopen)(Display*, int, const char*); 175 XftFont* (*fontopenname)(Display*, int, const char*); 176 XftFont* (*fontclose)(Display*, XftFont*); 177 void (*textextents)(Display*, XftFont*, const char*, int len, XGlyphInfo*); 178 void (*drawstring)(Display*, XftColor*, XftFont*, int x, int y, const char*, int len); 179 }; 180 181 struct XftColor { 182 ulong pixel; 183 XRenderColor color; 184 }; 185 186 struct XftFont { 187 int ascent; 188 int descent; 189 int height; 190 int max_advance_width; 191 void* charset; 192 void* pattern; 193 }; 194 195 struct Screen { 196 int screen; 197 Window root; 198 GC gc; 199 Colormap colormap; 200 Colormap colormap32; 201 Visual* visual; 202 Visual* visual32; 203 Rectangle rect; 204 int depth; 205 int fd; 206 XIM xim; 207 }; 208 209 #ifdef VARARGCK 210 # pragma varargck type "A" Atom 211 # pragma varargck type "P" Point 212 # pragma varargck type "R" Rectangle 213 # pragma varargck type "W" Window* 214 #endif 215 216 Display *display; 217 Screen scr; 218 219 extern char* modkey_names[]; 220 extern struct Map windowmap; 221 extern struct Map atommap; 222 extern struct Map atomnamemap; 223 extern const Point ZP; 224 extern const Rectangle ZR; 225 extern const WinHints ZWinHints; 226 extern Window* pointerwin; 227 extern Xft* xft; 228 229 XRectangle XRect(Rectangle r); 230 231 #define RGBA_P(tuple) (\ 232 ((long)(tuple).fg.alpha + (long)(tuple).bg.alpha + (long)(tuple).border.alpha) < 3 * 0xff00) 233 234 #define changeprop(w, prop, type, data, n) \ 235 changeproperty(w, prop, type, \ 236 ((sizeof(*(data)) == 8 ? 4 : sizeof(*(data))) * 8), \ 237 (uchar*)(data), n) 238 239 /* x11.c */ 240 XRectangle XRect(Rectangle); 241 Image* allocimage(int w, int h, int depth); 242 char* atomname(ulong); 243 void border(Image *dst, Rectangle, int w, Color*); 244 void changeprop_char(Window*, const char*, const char*, const char*, int); 245 void changeprop_long(Window*, const char*, const char*, long[], int); 246 void changeprop_short(Window*, const char*, const char*, short[], int); 247 void changeprop_string(Window*, const char*, const char*); 248 void changeprop_textlist(Window*, const char*, const char*, char*[]); 249 void changeprop_ulong(Window*, const char*, const char*, ulong[], int); 250 void changeproperty(Window*, const char*, const char*, int width, const uchar*, int); 251 void cleanupwindow(Window*); 252 void clientmessage(Window*, const char*, long, int, ClientMessageData); 253 void copyimage(Image*, Rectangle, Image*, Point); 254 Window* createwindow(Window*, Rectangle, int depth, uint class, WinAttr*, int valuemask); 255 Window* createwindow_rgba(Window*, Rectangle, WinAttr*, int valuemask); 256 Window* createwindow_visual(Window*, Rectangle, int depth, Visual*, uint class, WinAttr*, int); 257 void delproperty(Window*, const char*); 258 void destroywindow(Window*); 259 void drawline(Image*, Point, Point, int cap, int w, Color*); 260 void drawpoly(Image*, Point*, int, int cap, int w, Color*); 261 uint drawstring(Image*, Font*, Rectangle, Align, const char*, Color*); 262 void fill(Image*, Rectangle, Color*); 263 void fillpoly(Image*, Point*, int, Color*); 264 uint fillstring(Image*, Font*, Rectangle, Align, const char*, CTuple*, int border); 265 Window* findwin(XWindow); 266 void freefont(Font*); 267 void freeimage(Image *); 268 void freestringlist(char**); 269 XWindow getfocus(void); 270 void gethints(Window*); 271 ulong getprop(Window*, const char*, const char*, Atom*, int*, ulong, uchar**, ulong); 272 ulong getprop_long(Window*, const char*, const char*, ulong, long**, ulong); 273 char* getprop_string(Window*, const char*); 274 int getprop_textlist(Window *w, const char *name, char **ret[]); 275 ulong getprop_ulong(Window*, const char*, const char*, ulong, ulong**, ulong); 276 ulong getproperty(Window*, char *prop, char *type, Atom *actual, ulong offset, uchar **ret, ulong length); 277 Rectangle getwinrect(Window*); 278 int grabkeyboard(Window*); 279 int grabpointer(Window*, Window *confine, Cursor, int mask); 280 void getselection(char*, void (*)(void*, char*), void*); 281 bool havexft(void); 282 void initdisplay(void); 283 KeyCode keycode(const char*); 284 uint labelh(Font*); 285 int loadcolor(CTuple*, const char*, const char*); 286 Font* loadfont(const char*); 287 void lowerwin(Window*); 288 int mapwin(Window*); 289 void movewin(Window*, Point); 290 int numlockmask(void); 291 bool parsecolor(const char *name, Color*); 292 bool parsekey(char*, int*, char**); 293 ulong pixelvalue(Image*, Color*); 294 int pointerscreen(void); 295 bool pophandler(Window*, Handlers*); 296 void pushhandler(Window*, Handlers*, void*); 297 Point querypointer(Window*); 298 void raisewin(Window*); 299 void reparentwindow(Window*, Window*, Point); 300 void reshapewin(Window*, Rectangle); 301 void selectinput(Window*, long); 302 void sendevent(Window*, bool propagate, long mask, void*); 303 void sendmessage(Window*, const char*, long, long, long, long, long); 304 void setborder(Window*, int, Color*); 305 void setfocus(Window*, int mode); 306 Handlers* sethandler(Window*, Handlers*); 307 void sethints(Window*, WinHints*); 308 void setshapemask(Window *dst, Image *src, Point); 309 void setwinattr(Window*, WinAttr*, int valmask); 310 Rectangle sizehint(WinHints*, Rectangle); 311 char** strlistdup(char**); 312 void sync(void); 313 Rectangle textextents_l(Font*, const char*, uint, int*); 314 uint textwidth(Font*, const char*); 315 uint textwidth_l(Font*, const char*, uint len); 316 Point translate(Window*, Window*, Point); 317 int traperrors(bool); 318 void ungrabkeyboard(void); 319 void ungrabpointer(void); 320 int unmapwin(Window*); 321 void warppointer(Point); 322 Window* window(XWindow); 323 char* windowname(Window*); 324 long winprotocols(Window*); 325 Atom xatom(const char*); 326