diff options
author | Boram Park <boram1288.park@samsung.com> | 2012-08-21 18:04:11 +0900 |
---|---|---|
committer | Boram Park <boram1288.park@samsung.com> | 2012-08-21 18:04:11 +0900 |
commit | 8542b45178e4cb4e9ed24a5ce0fafb0742894e8d (patch) | |
tree | 31a1326e04a2829c5f3234bc68ba90639aedf330 /src | |
parent | cf276784e49975be2e5a196acf4be5c2dc442622 (diff) | |
download | xcb-util-8542b45178e4cb4e9ed24a5ce0fafb0742894e8d.tar.gz xcb-util-8542b45178e4cb4e9ed24a5ce0fafb0742894e8d.tar.bz2 xcb-util-8542b45178e4cb4e9ed24a5ce0fafb0742894e8d.zip |
upload tizen2.0 sourceHEADsubmit/master/20120920.1511522.0_alphamaster2.0alpha
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 33 | ||||
-rw-r--r-- | src/atomlist.m4 | 71 | ||||
-rw-r--r-- | src/atoms.c | 690 | ||||
-rw-r--r-- | src/atoms.gperf.m4 | 121 | ||||
-rw-r--r-- | src/event.c | 257 | ||||
-rw-r--r-- | src/xcb_atom.h | 21 | ||||
-rw-r--r-- | src/xcb_atom.h.m4 | 21 | ||||
-rw-r--r-- | src/xcb_aux.c | 374 | ||||
-rw-r--r-- | src/xcb_aux.h | 214 | ||||
-rw-r--r-- | src/xcb_bitops.h | 212 | ||||
-rw-r--r-- | src/xcb_event.h | 90 | ||||
-rw-r--r-- | src/xcb_util.h | 8 |
12 files changed, 2112 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..13b5313 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,33 @@ + +lib_LTLIBRARIES = libxcb-util.la + +AM_CPPFLAGS = $(XCB_CFLAGS) +AM_CFLAGS = $(CWARNFLAGS) + +libxcb_util_la_LIBADD = $(XCB_LIBS) +libxcb_util_la_LDFLAGS = -version-info 0:0:0 -no-undefined +libxcb_util_la_SOURCES = \ + atoms.c \ + event.c \ + xcb_aux.c + +xcbinclude_HEADERS = \ + xcb_util.h \ + xcb_atom.h \ + xcb_aux.h \ + xcb_bitops.h \ + xcb_event.h + +BUILT_SOURCES = atoms.c atoms.gperf xcb_atom.h +CLEANFILES = $(BUILT_SOURCES) +EXTRA_DIST = atomlist.m4 atoms.gperf.m4 xcb_atom.h.m4 + +atoms.c: atoms.gperf + $(GPERF) --output-file $@ $< + +atoms.gperf: $(srcdir)/atoms.gperf.m4 $(srcdir)/atomlist.m4 + $(M4) -I$(srcdir) $< >$@ + +xcb_atom.h: $(srcdir)/xcb_atom.h.m4 $(srcdir)/atomlist.m4 + $(M4) -I$(srcdir) $< >$@ + diff --git a/src/atomlist.m4 b/src/atomlist.m4 new file mode 100644 index 0000000..1c84740 --- /dev/null +++ b/src/atomlist.m4 @@ -0,0 +1,71 @@ +define(`FOREACH', `ifelse(`$1', , , `DO($1) +FOREACH(shift($@))')')FOREACH( +PRIMARY, +SECONDARY, +ARC, +ATOM, +BITMAP, +CARDINAL, +COLORMAP, +CURSOR, +CUT_BUFFER0, +CUT_BUFFER1, +CUT_BUFFER2, +CUT_BUFFER3, +CUT_BUFFER4, +CUT_BUFFER5, +CUT_BUFFER6, +CUT_BUFFER7, +DRAWABLE, +FONT, +INTEGER, +PIXMAP, +POINT, +RECTANGLE, +RESOURCE_MANAGER, +RGB_COLOR_MAP, +RGB_BEST_MAP, +RGB_BLUE_MAP, +RGB_DEFAULT_MAP, +RGB_GRAY_MAP, +RGB_GREEN_MAP, +RGB_RED_MAP, +STRING, +VISUALID, +WINDOW, +WM_COMMAND, +WM_HINTS, +WM_CLIENT_MACHINE, +WM_ICON_NAME, +WM_ICON_SIZE, +WM_NAME, +WM_NORMAL_HINTS, +WM_SIZE_HINTS, +WM_ZOOM_HINTS, +MIN_SPACE, +NORM_SPACE, +MAX_SPACE, +END_SPACE, +SUPERSCRIPT_X, +SUPERSCRIPT_Y, +SUBSCRIPT_X, +SUBSCRIPT_Y, +UNDERLINE_POSITION, +UNDERLINE_THICKNESS, +STRIKEOUT_ASCENT, +STRIKEOUT_DESCENT, +ITALIC_ANGLE, +X_HEIGHT, +QUAD_WIDTH, +WEIGHT, +POINT_SIZE, +RESOLUTION, +COPYRIGHT, +NOTICE, +FONT_NAME, +FAMILY_NAME, +FULL_NAME, +CAP_HEIGHT, +WM_CLASS, +WM_TRANSIENT_FOR, +)dnl diff --git a/src/atoms.c b/src/atoms.c new file mode 100644 index 0000000..cdd8e38 --- /dev/null +++ b/src/atoms.c @@ -0,0 +1,690 @@ +/* C code produced by gperf version 3.0.3 */ +/* Command-line: gperf --output-file atoms.c atoms.gperf */ +/* Computed positions: -k'3,6,9,$' */ + +#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ + && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \ + && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \ + && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \ + && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \ + && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \ + && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \ + && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \ + && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \ + && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \ + && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \ + && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \ + && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \ + && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \ + && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \ + && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \ + && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \ + && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \ + && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \ + && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \ + && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \ + && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \ + && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126)) +/* The character set is not based on ISO-646. */ +error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gnu-gperf@gnu.org>." +#endif + +#line 1 "atoms.gperf" + + +/* Rely on vasprintf (GNU extension) instead of vsnprintf if + possible... */ +#ifdef HAVE_VASPRINTF +#define _GNU_SOURCE +#include <stdio.h> +#endif + +#include <xcb/xcb.h> +#include <stdlib.h> +#include <stdarg.h> +#include "xcb_atom.h" + +#line 25 "atoms.gperf" +struct atom_map { int name; xcb_atom_t value; }; +#include <string.h> +/* maximum key range = 146, duplicates = 0 */ + +#ifdef __GNUC__ +__inline +#else +#ifdef __cplusplus +inline +#endif +#endif +static unsigned int +hash (str, len) + register const char *str; + register unsigned int len; +{ + static const unsigned char asso_values[] = + { + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 75, 70, + 65, 60, 40, 35, 20, 5, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 35, 0, 45, 15, 0, + 150, 50, 0, 5, 150, 150, 15, 35, 0, 40, + 5, 150, 10, 15, 0, 25, 150, 20, 70, 40, + 55, 150, 150, 150, 150, 15, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150 + }; + register int hval = len; + + switch (hval) + { + default: + hval += asso_values[(unsigned char)str[8]]; + /*FALLTHROUGH*/ + case 8: + case 7: + case 6: + hval += asso_values[(unsigned char)str[5]]; + /*FALLTHROUGH*/ + case 5: + case 4: + case 3: + hval += asso_values[(unsigned char)str[2]]; + break; + } + return hval + asso_values[(unsigned char)str[len - 1]]; +} + +struct stringpool_t + { + char stringpool_str4[sizeof("FONT")]; + char stringpool_str6[sizeof("NOTICE")]; + char stringpool_str9[sizeof("FONT_NAME")]; + char stringpool_str10[sizeof("POINT")]; + char stringpool_str11[sizeof("WEIGHT")]; + char stringpool_str14[sizeof("MIN_SPACE")]; + char stringpool_str15[sizeof("CAP_HEIGHT")]; + char stringpool_str16[sizeof("BITMAP")]; + char stringpool_str17[sizeof("INTEGER")]; + char stringpool_str19[sizeof("COPYRIGHT")]; + char stringpool_str24[sizeof("FULL_NAME")]; + char stringpool_str26[sizeof("STRIKEOUT_ASCENT")]; + char stringpool_str27[sizeof("STRIKEOUT_DESCENT")]; + char stringpool_str28[sizeof("RGB_GREEN_MAP")]; + char stringpool_str29[sizeof("END_SPACE")]; + char stringpool_str32[sizeof("RGB_BEST_MAP")]; + char stringpool_str33[sizeof("CARDINAL")]; + char stringpool_str36[sizeof("CURSOR")]; + char stringpool_str37[sizeof("WM_CLIENT_MACHINE")]; + char stringpool_str38[sizeof("WM_HINTS")]; + char stringpool_str41[sizeof("CUT_BUFFER7")]; + char stringpool_str42[sizeof("RGB_GRAY_MAP")]; + char stringpool_str43[sizeof("DRAWABLE")]; + char stringpool_str45[sizeof("RGB_DEFAULT_MAP")]; + char stringpool_str46[sizeof("WINDOW")]; + char stringpool_str47[sizeof("RGB_BLUE_MAP")]; + char stringpool_str48[sizeof("UNDERLINE_POSITION")]; + char stringpool_str51[sizeof("RGB_RED_MAP")]; + char stringpool_str53[sizeof("VISUALID")]; + char stringpool_str54[sizeof("RECTANGLE")]; + char stringpool_str56[sizeof("CUT_BUFFER6")]; + char stringpool_str57[sizeof("WM_NAME")]; + char stringpool_str58[sizeof("X_HEIGHT")]; + char stringpool_str61[sizeof("SUBSCRIPT_Y")]; + char stringpool_str62[sizeof("PRIMARY")]; + char stringpool_str63[sizeof("COLORMAP")]; + char stringpool_str64[sizeof("UNDERLINE_THICKNESS")]; + char stringpool_str65[sizeof("QUAD_WIDTH")]; + char stringpool_str66[sizeof("RESOURCE_MANAGER")]; + char stringpool_str67[sizeof("WM_ICON_NAME")]; + char stringpool_str68[sizeof("RGB_COLOR_MAP")]; + char stringpool_str70[sizeof("WM_NORMAL_HINTS")]; + char stringpool_str71[sizeof("CUT_BUFFER5")]; + char stringpool_str73[sizeof("WM_CLASS")]; + char stringpool_str75[sizeof("WM_COMMAND")]; + char stringpool_str76[sizeof("CUT_BUFFER4")]; + char stringpool_str78[sizeof("SUPERSCRIPT_Y")]; + char stringpool_str79[sizeof("ATOM")]; + char stringpool_str80[sizeof("NORM_SPACE")]; + char stringpool_str81[sizeof("WM_TRANSIENT_FOR")]; + char stringpool_str82[sizeof("WM_ICON_SIZE")]; + char stringpool_str83[sizeof("WM_ZOOM_HINTS")]; + char stringpool_str84[sizeof("MAX_SPACE")]; + char stringpool_str85[sizeof("POINT_SIZE")]; + char stringpool_str86[sizeof("PIXMAP")]; + char stringpool_str90[sizeof("RESOLUTION")]; + char stringpool_str91[sizeof("SUBSCRIPT_X")]; + char stringpool_str92[sizeof("ITALIC_ANGLE")]; + char stringpool_str93[sizeof("ARC")]; + char stringpool_str96[sizeof("CUT_BUFFER3")]; + char stringpool_str98[sizeof("WM_SIZE_HINTS")]; + char stringpool_str101[sizeof("CUT_BUFFER2")]; + char stringpool_str106[sizeof("CUT_BUFFER1")]; + char stringpool_str108[sizeof("SUPERSCRIPT_X")]; + char stringpool_str111[sizeof("CUT_BUFFER0")]; + char stringpool_str116[sizeof("STRING")]; + char stringpool_str121[sizeof("FAMILY_NAME")]; + char stringpool_str149[sizeof("SECONDARY")]; + }; +static const struct stringpool_t stringpool_contents = + { + "FONT", + "NOTICE", + "FONT_NAME", + "POINT", + "WEIGHT", + "MIN_SPACE", + "CAP_HEIGHT", + "BITMAP", + "INTEGER", + "COPYRIGHT", + "FULL_NAME", + "STRIKEOUT_ASCENT", + "STRIKEOUT_DESCENT", + "RGB_GREEN_MAP", + "END_SPACE", + "RGB_BEST_MAP", + "CARDINAL", + "CURSOR", + "WM_CLIENT_MACHINE", + "WM_HINTS", + "CUT_BUFFER7", + "RGB_GRAY_MAP", + "DRAWABLE", + "RGB_DEFAULT_MAP", + "WINDOW", + "RGB_BLUE_MAP", + "UNDERLINE_POSITION", + "RGB_RED_MAP", + "VISUALID", + "RECTANGLE", + "CUT_BUFFER6", + "WM_NAME", + "X_HEIGHT", + "SUBSCRIPT_Y", + "PRIMARY", + "COLORMAP", + "UNDERLINE_THICKNESS", + "QUAD_WIDTH", + "RESOURCE_MANAGER", + "WM_ICON_NAME", + "RGB_COLOR_MAP", + "WM_NORMAL_HINTS", + "CUT_BUFFER5", + "WM_CLASS", + "WM_COMMAND", + "CUT_BUFFER4", + "SUPERSCRIPT_Y", + "ATOM", + "NORM_SPACE", + "WM_TRANSIENT_FOR", + "WM_ICON_SIZE", + "WM_ZOOM_HINTS", + "MAX_SPACE", + "POINT_SIZE", + "PIXMAP", + "RESOLUTION", + "SUBSCRIPT_X", + "ITALIC_ANGLE", + "ARC", + "CUT_BUFFER3", + "WM_SIZE_HINTS", + "CUT_BUFFER2", + "CUT_BUFFER1", + "SUPERSCRIPT_X", + "CUT_BUFFER0", + "STRING", + "FAMILY_NAME", + "SECONDARY" + }; +#define stringpool ((const char *) &stringpool_contents) +#ifdef __GNUC__ +__inline +#ifdef __GNUC_STDC_INLINE__ +__attribute__ ((__gnu_inline__)) +#endif +#endif +const struct atom_map * +in_word_set (str, len) + register const char *str; + register unsigned int len; +{ + enum + { + TOTAL_KEYWORDS = 68, + MIN_WORD_LENGTH = 3, + MAX_WORD_LENGTH = 19, + MIN_HASH_VALUE = 4, + MAX_HASH_VALUE = 149 + }; + + static const struct atom_map wordlist[] = + { + {-1}, {-1}, {-1}, {-1}, +#line 44 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str4,18}, + {-1}, +#line 88 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str6,62}, + {-1}, {-1}, +#line 89 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str9,63}, +#line 47 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str10,21}, +#line 84 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str11,58}, + {-1}, {-1}, +#line 69 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str14,43}, +#line 92 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str15,66}, +#line 31 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str16,5}, +#line 45 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str17,19}, + {-1}, +#line 87 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str19,61}, + {-1}, {-1}, {-1}, {-1}, +#line 91 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str24,65}, + {-1}, +#line 79 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str26,53}, +#line 80 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str27,54}, +#line 55 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str28,29}, +#line 72 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str29,46}, + {-1}, {-1}, +#line 51 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str32,25}, +#line 32 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str33,6}, + {-1}, {-1}, +#line 34 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str36,8}, +#line 62 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str37,36}, +#line 61 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str38,35}, + {-1}, {-1}, +#line 42 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str41,16}, +#line 54 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str42,28}, +#line 43 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str43,17}, + {-1}, +#line 53 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str45,27}, +#line 59 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str46,33}, +#line 52 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str47,26}, +#line 77 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str48,51}, + {-1}, {-1}, +#line 56 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str51,30}, + {-1}, +#line 58 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str53,32}, +#line 48 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str54,22}, + {-1}, +#line 41 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str56,15}, +#line 65 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str57,39}, +#line 82 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str58,56}, + {-1}, {-1}, +#line 76 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str61,50}, +#line 27 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str62,1}, +#line 33 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str63,7}, +#line 78 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str64,52}, +#line 83 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str65,57}, +#line 49 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str66,23}, +#line 63 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str67,37}, +#line 50 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str68,24}, + {-1}, +#line 66 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str70,40}, +#line 40 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str71,14}, + {-1}, +#line 93 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str73,67}, + {-1}, +#line 60 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str75,34}, +#line 39 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str76,13}, + {-1}, +#line 74 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str78,48}, +#line 30 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str79,4}, +#line 70 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str80,44}, +#line 94 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str81,68}, +#line 64 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str82,38}, +#line 68 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str83,42}, +#line 71 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str84,45}, +#line 85 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str85,59}, +#line 46 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str86,20}, + {-1}, {-1}, {-1}, +#line 86 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str90,60}, +#line 75 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str91,49}, +#line 81 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str92,55}, +#line 29 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str93,3}, + {-1}, {-1}, +#line 38 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str96,12}, + {-1}, +#line 67 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str98,41}, + {-1}, {-1}, +#line 37 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str101,11}, + {-1}, {-1}, {-1}, {-1}, +#line 36 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str106,10}, + {-1}, +#line 73 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str108,47}, + {-1}, {-1}, +#line 35 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str111,9}, + {-1}, {-1}, {-1}, {-1}, +#line 57 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str116,31}, + {-1}, {-1}, {-1}, {-1}, +#line 90 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str121,64}, + {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, + {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, + {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, +#line 28 "atoms.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str149,2} + }; + + if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) + { + register int key = hash (str, len); + + if (key <= MAX_HASH_VALUE && key >= 0) + { + register int o = wordlist[key].name; + if (o >= 0) + { + register const char *s = o + stringpool; + + if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0') + return &wordlist[key]; + } + } + } + return 0; +} +#line 95 "atoms.gperf" + + +static const char atom_names[] = + "PRIMARY\0" + "SECONDARY\0" + "ARC\0" + "ATOM\0" + "BITMAP\0" + "CARDINAL\0" + "COLORMAP\0" + "CURSOR\0" + "CUT_BUFFER0\0" + "CUT_BUFFER1\0" + "CUT_BUFFER2\0" + "CUT_BUFFER3\0" + "CUT_BUFFER4\0" + "CUT_BUFFER5\0" + "CUT_BUFFER6\0" + "CUT_BUFFER7\0" + "DRAWABLE\0" + "FONT\0" + "INTEGER\0" + "PIXMAP\0" + "POINT\0" + "RECTANGLE\0" + "RESOURCE_MANAGER\0" + "RGB_COLOR_MAP\0" + "RGB_BEST_MAP\0" + "RGB_BLUE_MAP\0" + "RGB_DEFAULT_MAP\0" + "RGB_GRAY_MAP\0" + "RGB_GREEN_MAP\0" + "RGB_RED_MAP\0" + "STRING\0" + "VISUALID\0" + "WINDOW\0" + "WM_COMMAND\0" + "WM_HINTS\0" + "WM_CLIENT_MACHINE\0" + "WM_ICON_NAME\0" + "WM_ICON_SIZE\0" + "WM_NAME\0" + "WM_NORMAL_HINTS\0" + "WM_SIZE_HINTS\0" + "WM_ZOOM_HINTS\0" + "MIN_SPACE\0" + "NORM_SPACE\0" + "MAX_SPACE\0" + "END_SPACE\0" + "SUPERSCRIPT_X\0" + "SUPERSCRIPT_Y\0" + "SUBSCRIPT_X\0" + "SUBSCRIPT_Y\0" + "UNDERLINE_POSITION\0" + "UNDERLINE_THICKNESS\0" + "STRIKEOUT_ASCENT\0" + "STRIKEOUT_DESCENT\0" + "ITALIC_ANGLE\0" + "X_HEIGHT\0" + "QUAD_WIDTH\0" + "WEIGHT\0" + "POINT_SIZE\0" + "RESOLUTION\0" + "COPYRIGHT\0" + "NOTICE\0" + "FONT_NAME\0" + "FAMILY_NAME\0" + "FULL_NAME\0" + "CAP_HEIGHT\0" + "WM_CLASS\0" + "WM_TRANSIENT_FOR\0" +; + +static const uint16_t atom_name_offsets[] = { + 0, + 8, + 18, + 22, + 27, + 34, + 43, + 52, + 59, + 71, + 83, + 95, + 107, + 119, + 131, + 143, + 155, + 164, + 169, + 177, + 184, + 190, + 200, + 217, + 231, + 244, + 257, + 273, + 286, + 300, + 312, + 319, + 328, + 335, + 346, + 355, + 373, + 386, + 399, + 407, + 423, + 437, + 451, + 461, + 472, + 482, + 492, + 506, + 520, + 532, + 544, + 563, + 583, + 600, + 618, + 631, + 640, + 651, + 658, + 669, + 680, + 690, + 697, + 707, + 719, + 729, + 740, + 749, +}; + +xcb_atom_t xcb_atom_get_predefined(uint16_t name_len, const char *name) +{ + const struct atom_map *value = in_word_set(name, name_len); + xcb_atom_t ret = XCB_NONE; + if(value) + ret = value->value; + return ret; +} + +const char *xcb_atom_get_name_predefined(xcb_atom_t atom) +{ + if(atom <= 0 || atom > (sizeof(atom_name_offsets) / sizeof(*atom_name_offsets))) + return 0; + return atom_names + atom_name_offsets[atom - 1]; +} + +static char *makename(const char *fmt, ...) +{ + char *ret; + int n; + va_list ap; + +#ifndef HAVE_VASPRINTF + char *np; + int size = 64; + + /* First allocate 'size' bytes, should be enough usually */ + if((ret = malloc(size)) == NULL) + return NULL; + + while(1) + { + va_start(ap, fmt); + n = vsnprintf(ret, size, fmt, ap); + va_end(ap); + + if(n < 0) + return NULL; + + if(n < size) + return ret; + + size = n + 1; + if((np = realloc(ret, size)) == NULL) + { + free(ret); + return NULL; + } + + ret = np; + } +#else + va_start(ap, fmt); + n = vasprintf(&ret, fmt, ap); + va_end(ap); + + if(n < 0) + return NULL; + + return ret; +#endif +} + +char *xcb_atom_name_by_screen(const char *base, uint8_t screen) +{ + return makename("%s_S%u", base, screen); +} + +char *xcb_atom_name_by_resource(const char *base, uint32_t resource) +{ + return makename("%s_R%08X", base, resource); +} + +char *xcb_atom_name_unique(const char *base, uint32_t id) +{ + if(base) + return makename("%s_U%lu", base, id); + else + return makename("U%lu", id); +} diff --git a/src/atoms.gperf.m4 b/src/atoms.gperf.m4 new file mode 100644 index 0000000..8876e26 --- /dev/null +++ b/src/atoms.gperf.m4 @@ -0,0 +1,121 @@ +%{ + +/* Rely on vasprintf (GNU extension) instead of vsnprintf if + possible... */ +#ifdef HAVE_VASPRINTF +#define _GNU_SOURCE +#include <stdio.h> +#endif + +#include <xcb/xcb.h> +#include <stdlib.h> +#include <stdarg.h> +#include "xcb_atom.h" + +%} + +%readonly-tables +%pic +%null-strings +%enum +%includes +%compare-strncmp + +%struct-type +struct atom_map { int name; xcb_atom_t value; }; +%% +define(`COUNT', 0)dnl +define(`DO', `$1,define(`COUNT', incr(COUNT))COUNT')dnl +include(atomlist.m4)`'dnl +%% + +static const char atom_names[] = +define(`DO', ` "$1\0"')dnl +include(atomlist.m4); + +static const uint16_t atom_name_offsets[] = { +define(`OFFSET', 0)dnl +define(`DO', ` OFFSET,define(`OFFSET', eval(OFFSET+1+len($1)))')dnl +include(atomlist.m4)`'dnl +}; + +xcb_atom_t xcb_atom_get_predefined(uint16_t name_len, const char *name) +{ + const struct atom_map *value = in_word_set(name, name_len); + xcb_atom_t ret = XCB_NONE; + if(value) + ret = value->value; + return ret; +} + +const char *xcb_atom_get_name_predefined(xcb_atom_t atom) +{ + if(atom <= 0 || atom > (sizeof(atom_name_offsets) / sizeof(*atom_name_offsets))) + return 0; + return atom_names + atom_name_offsets[atom - 1]; +} + +static char *makename(const char *fmt, ...) +{ + char *ret; + int n; + va_list ap; + +#ifndef HAVE_VASPRINTF + char *np; + int size = 64; + + /* First allocate 'size' bytes, should be enough usually */ + if((ret = malloc(size)) == NULL) + return NULL; + + while(1) + { + va_start(ap, fmt); + n = vsnprintf(ret, size, fmt, ap); + va_end(ap); + + if(n < 0) + return NULL; + + if(n < size) + return ret; + + size = n + 1; + if((np = realloc(ret, size)) == NULL) + { + free(ret); + return NULL; + } + + ret = np; + } +#else + va_start(ap, fmt); + n = vasprintf(&ret, fmt, ap); + va_end(ap); + + if(n < 0) + return NULL; + + return ret; +#endif +} + +char *xcb_atom_name_by_screen(const char *base, uint8_t screen) +{ + return makename("%s_S%u", base, screen); +} + +char *xcb_atom_name_by_resource(const char *base, uint32_t resource) +{ + return makename("%s_R%08X", base, resource); +} + +char *xcb_atom_name_unique(const char *base, uint32_t id) +{ + if(base) + return makename("%s_U%lu", base, id); + else + return makename("U%lu", id); +} diff --git a/src/event.c b/src/event.c new file mode 100644 index 0000000..de8899a --- /dev/null +++ b/src/event.c @@ -0,0 +1,257 @@ +/* + * Copyright © 2008-2009 Julien Danjou <julien@danjou.info> + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the names of the authors or + * their institutions shall not be used in advertising or otherwise to + * promote the sale, use or other dealings in this Software without + * prior written authorization from the authors. + */ + +#include <assert.h> +#include <stdlib.h> +#include <string.h> + +#include "xcb_event.h" + +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif + +#define ssizeof(foo) (ssize_t)sizeof(foo) +#define countof(foo) (ssizeof(foo) / ssizeof(foo[0])) + +static const char *labelError[] = +{ + "Success", + "BadRequest", + "BadValue", + "BadWindow", + "BadPixmap", + "BadAtom", + "BadCursor", + "BadFont", + "BadMatch", + "BadDrawable", + "BadAccess", + "BadAlloc", + "BadColor", + "BadGC", + "BadIDChoice", + "BadName", + "BadLength", + "BadImplementation", +}; + +static const char *labelRequest[] = +{ + "no request", + "CreateWindow", + "ChangeWindowAttributes", + "GetWindowAttributes", + "DestroyWindow", + "DestroySubwindows", + "ChangeSaveSet", + "ReparentWindow", + "MapWindow", + "MapSubwindows", + "UnmapWindow", + "UnmapSubwindows", + "ConfigureWindow", + "CirculateWindow", + "GetGeometry", + "QueryTree", + "InternAtom", + "GetAtomName", + "ChangeProperty", + "DeleteProperty", + "GetProperty", + "ListProperties", + "SetSelectionOwner", + "GetSelectionOwner", + "ConvertSelection", + "SendEvent", + "GrabPointer", + "UngrabPointer", + "GrabButton", + "UngrabButton", + "ChangeActivePointerGrab", + "GrabKeyboard", + "UngrabKeyboard", + "GrabKey", + "UngrabKey", + "AllowEvents", + "GrabServer", + "UngrabServer", + "QueryPointer", + "GetMotionEvents", + "TranslateCoords", + "WarpPointer", + "SetInputFocus", + "GetInputFocus", + "QueryKeymap", + "OpenFont", + "CloseFont", + "QueryFont", + "QueryTextExtents", + "ListFonts", + "ListFontsWithInfo", + "SetFontPath", + "GetFontPath", + "CreatePixmap", + "FreePixmap", + "CreateGC", + "ChangeGC", + "CopyGC", + "SetDashes", + "SetClipRectangles", + "FreeGC", + "ClearArea", + "CopyArea", + "CopyPlane", + "PolyPoint", + "PolyLine", + "PolySegment", + "PolyRectangle", + "PolyArc", + "FillPoly", + "PolyFillRectangle", + "PolyFillArc", + "PutImage", + "GetImage", + "PolyText", + "PolyText", + "ImageText", + "ImageText", + "CreateColormap", + "FreeColormap", + "CopyColormapAndFree", + "InstallColormap", + "UninstallColormap", + "ListInstalledColormaps", + "AllocColor", + "AllocNamedColor", + "AllocColorCells", + "AllocColorPlanes", + "FreeColors", + "StoreColors", + "StoreNamedColor", + "QueryColors", + "LookupColor", + "CreateCursor", + "CreateGlyphCursor", + "FreeCursor", + "RecolorCursor", + "QueryBestSize", + "QueryExtension", + "ListExtensions", + "ChangeKeyboardMapping", + "GetKeyboardMapping", + "ChangeKeyboardControl", + "GetKeyboardControl", + "Bell", + "ChangePointerControl", + "GetPointerControl", + "SetScreenSaver", + "GetScreenSaver", + "ChangeHosts", + "ListHosts", + "SetAccessControl", + "SetCloseDownMode", + "KillClient", + "RotateProperties", + "ForceScreenSaver", + "SetPointerMapping", + "GetPointerMapping", + "SetModifierMapping", + "GetModifierMapping", + "major 120", + "major 121", + "major 122", + "major 123", + "major 124", + "major 125", + "major 126", + "NoOperation", +}; + +static const char *labelEvent[] = +{ + "error", + "reply", + "KeyPress", + "KeyRelease", + "ButtonPress", + "ButtonRelease", + "MotionNotify", + "EnterNotify", + "LeaveNotify", + "FocusIn", + "FocusOut", + "KeymapNotify", + "Expose", + "GraphicsExpose", + "NoExpose", + "VisibilityNotify", + "CreateNotify", + "DestroyNotify", + "UnmapNotify", + "MapNotify", + "MapRequest", + "ReparentNotify", + "ConfigureNotify", + "ConfigureRequest", + "GravityNotify", + "ResizeRequest", + "CirculateNotify", + "CirculateRequest", + "PropertyNotify", + "SelectionClear", + "SelectionRequest", + "SelectionNotify", + "ColormapNotify", + "ClientMessage", + "MappingNotify", +}; + +const char * +xcb_event_get_label(uint8_t type) +{ + if(type < countof(labelEvent)) + return labelEvent[type]; + return NULL; +} + +const char * +xcb_event_get_error_label(uint8_t type) +{ + if(type < countof(labelError)) + return labelError[type]; + return NULL; +} + +const char * +xcb_event_get_request_label(uint8_t type) +{ + if(type < countof(labelRequest)) + return labelRequest[type]; + return NULL; +} diff --git a/src/xcb_atom.h b/src/xcb_atom.h new file mode 100644 index 0000000..27449bd --- /dev/null +++ b/src/xcb_atom.h @@ -0,0 +1,21 @@ +#ifndef __XCB_ATOM_H__ +#define __XCB_ATOM_H__ + +#include <xcb/xcb.h> + +#ifdef __cplusplus +extern "C" { +#endif + +xcb_atom_t xcb_atom_get_predefined(uint16_t name_len, const char *name); +const char *xcb_atom_get_name_predefined(xcb_atom_t atom); + +char *xcb_atom_name_by_screen(const char *base, uint8_t screen); +char *xcb_atom_name_by_resource(const char *base, uint32_t resource); +char *xcb_atom_name_unique(const char *base, uint32_t id); + +#ifdef __cplusplus +} +#endif + +#endif /* __XCB_ATOM_H__ */ diff --git a/src/xcb_atom.h.m4 b/src/xcb_atom.h.m4 new file mode 100644 index 0000000..27449bd --- /dev/null +++ b/src/xcb_atom.h.m4 @@ -0,0 +1,21 @@ +#ifndef __XCB_ATOM_H__ +#define __XCB_ATOM_H__ + +#include <xcb/xcb.h> + +#ifdef __cplusplus +extern "C" { +#endif + +xcb_atom_t xcb_atom_get_predefined(uint16_t name_len, const char *name); +const char *xcb_atom_get_name_predefined(xcb_atom_t atom); + +char *xcb_atom_name_by_screen(const char *base, uint8_t screen); +char *xcb_atom_name_by_resource(const char *base, uint32_t resource); +char *xcb_atom_name_unique(const char *base, uint32_t id); + +#ifdef __cplusplus +} +#endif + +#endif /* __XCB_ATOM_H__ */ diff --git a/src/xcb_aux.c b/src/xcb_aux.c new file mode 100644 index 0000000..c810398 --- /dev/null +++ b/src/xcb_aux.c @@ -0,0 +1,374 @@ +/* + * Copyright © 2008 Bart Massey <bart@cs.pdx.edu> + * Copyright © 2008 Ian Osgood <iano@quirkster.com> + * Copyright © 2008 Jamey Sharp <jamey@minilop.net> + * Copyright © 2008 Josh Triplett <josh@freedesktop.org> + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the names of the authors or + * their institutions shall not be used in advertising or otherwise to + * promote the sale, use or other dealings in this Software without + * prior written authorization from the authors. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <xcb/xcb.h> +#include "xcb_aux.h" + +/* Connection related functions */ + +uint8_t +xcb_aux_get_depth (xcb_connection_t *c, + xcb_screen_t *screen) +{ + xcb_drawable_t drawable; + xcb_get_geometry_reply_t *geom; + int depth = 0; + + drawable = screen->root; + geom = xcb_get_geometry_reply (c, xcb_get_geometry(c, drawable), 0); + + if (geom) { + depth = geom->depth; + free (geom); + } + + return depth; +} + +uint8_t +xcb_aux_get_depth_of_visual (xcb_screen_t *screen, + xcb_visualid_t id) +{ + xcb_depth_iterator_t i; + xcb_visualtype_iterator_t j; + for (i = xcb_screen_allowed_depths_iterator(screen); + i.rem; xcb_depth_next(&i)) + for (j = xcb_depth_visuals_iterator(i.data); + j.rem; xcb_visualtype_next(&j)) + if (j.data->visual_id == id) + return i.data->depth; + return 0; +} + +xcb_screen_t * +xcb_aux_get_screen (xcb_connection_t *c, + int screen) +{ + xcb_screen_iterator_t i = xcb_setup_roots_iterator(xcb_get_setup(c)); + for (; i.rem; --screen, xcb_screen_next(&i)) + if (screen == 0) + return i.data; + return 0; +} + +xcb_visualtype_t * +xcb_aux_get_visualtype (xcb_connection_t *c, + int scr, + xcb_visualid_t vid) +{ + xcb_screen_t *screen; + xcb_depth_t *depth; + xcb_visualtype_iterator_t iter; + int cur; + + screen = xcb_aux_get_screen (c, scr); + if (!screen) return NULL; + + depth = xcb_screen_allowed_depths_iterator(screen).data; + if (!depth) return NULL; + + iter = xcb_depth_visuals_iterator(depth); + for (cur = 0 ; cur < iter.rem ; xcb_visualtype_next(&iter), ++cur) + if (vid == iter.data->visual_id) + return iter.data; + + return NULL; +} + +xcb_visualtype_t * +xcb_aux_find_visual_by_id (xcb_screen_t *screen, + xcb_visualid_t id) +{ + xcb_depth_iterator_t i; + xcb_visualtype_iterator_t j; + for (i = xcb_screen_allowed_depths_iterator(screen); + i.rem; xcb_depth_next(&i)) + for (j = xcb_depth_visuals_iterator(i.data); + j.rem; xcb_visualtype_next(&j)) + if (j.data->visual_id == id) + return j.data; + return 0; +} + +xcb_visualtype_t * +xcb_aux_find_visual_by_attrs (xcb_screen_t *screen, + int8_t class, + int8_t depth) +{ + xcb_depth_iterator_t i; + xcb_visualtype_iterator_t j; + for (i = xcb_screen_allowed_depths_iterator(screen); + i.rem; xcb_depth_next(&i)) { + if (depth != -1 && i.data->depth != depth) + continue; + for (j = xcb_depth_visuals_iterator(i.data); + j.rem; xcb_visualtype_next(&j)) + if (class == -1 || j.data->_class == class) + return j.data; + } + return 0; +} + +void +xcb_aux_sync (xcb_connection_t *c) +{ + free(xcb_get_input_focus_reply(c, xcb_get_input_focus(c), NULL)); +} + +/* structs instead of value lists */ +/* TODO: generate the struct types and functions from protocol masks and descriptions */ + +/* This generic implementation of pack_list depends on: + a) structs packed to uint32_t size + b) structs consist of just uint32_t/int32_t fields in the same order as bitmask +*/ + +static void +pack_list( uint32_t mask, const uint32_t *src, uint32_t *dest ) +{ + for ( ; mask; mask >>= 1, src++) + if (mask & 1) + *dest++ = *src; +} + +xcb_void_cookie_t +xcb_aux_create_window (xcb_connection_t *c, + uint8_t depth, + xcb_window_t wid, + xcb_window_t parent, + int16_t x, + int16_t y, + uint16_t width, + uint16_t height, + uint16_t border_width, + uint16_t _class, + xcb_visualid_t visual, + uint32_t mask, + const xcb_params_cw_t *params) +{ + uint32_t value_list[16]; + pack_list(mask, (const uint32_t *)params, value_list); + return xcb_create_window(c, depth, wid, parent, + x, y, width, height, border_width, + _class, visual, mask, value_list); +} + +xcb_void_cookie_t +xcb_aux_create_window_checked (xcb_connection_t *c, + uint8_t depth, + xcb_window_t wid, + xcb_window_t parent, + int16_t x, + int16_t y, + uint16_t width, + uint16_t height, + uint16_t border_width, + uint16_t _class, + xcb_visualid_t visual, + uint32_t mask, + const xcb_params_cw_t *params) +{ + uint32_t value_list[16]; + pack_list(mask, (const uint32_t *)params, value_list); + return xcb_create_window_checked(c, depth, wid, parent, + x, y, width, height, border_width, + _class, visual, mask, value_list); +} + +xcb_void_cookie_t +xcb_aux_change_window_attributes_checked (xcb_connection_t *c, + xcb_window_t window, + uint32_t mask, + const xcb_params_cw_t *params) +{ + uint32_t value_list[16]; + pack_list(mask, (const uint32_t *)params, value_list); + return xcb_change_window_attributes_checked( c, window, mask, value_list ); +} + +xcb_void_cookie_t +xcb_aux_change_window_attributes (xcb_connection_t *c, + xcb_window_t window, + uint32_t mask, + const xcb_params_cw_t *params) +{ + uint32_t value_list[16]; + pack_list(mask, (const uint32_t *)params, value_list); + return xcb_change_window_attributes( c, window, mask, value_list ); +} + +xcb_void_cookie_t +xcb_aux_configure_window (xcb_connection_t *c, + xcb_window_t window, + uint16_t mask, + const xcb_params_configure_window_t *params) +{ + uint32_t value_list[8]; + pack_list(mask, (const uint32_t *)params, value_list); + return xcb_configure_window( c, window, mask, value_list ); +} + +xcb_void_cookie_t +xcb_aux_create_gc (xcb_connection_t *c, + xcb_gcontext_t gid, + xcb_drawable_t drawable, + uint32_t mask, + const xcb_params_gc_t *params) +{ + uint32_t value_list[32]; + pack_list(mask, (const uint32_t *)params, value_list); + return xcb_create_gc( c, gid, drawable, mask, value_list ); +} + +xcb_void_cookie_t +xcb_aux_create_gc_checked (xcb_connection_t *c, + xcb_gcontext_t gid, + xcb_drawable_t drawable, + uint32_t mask, + const xcb_params_gc_t *params) +{ + uint32_t value_list[32]; + pack_list(mask, (const uint32_t *)params, value_list); + return xcb_create_gc_checked( c, gid, drawable, mask, value_list); +} + +xcb_void_cookie_t +xcb_aux_change_gc (xcb_connection_t *c, + xcb_gcontext_t gc, + uint32_t mask, + const xcb_params_gc_t *params) +{ + uint32_t value_list[32]; + pack_list(mask, (const uint32_t *)params, value_list); + return xcb_change_gc( c, gc, mask, value_list ); +} + +xcb_void_cookie_t +xcb_aux_change_gc_checked (xcb_connection_t *c, + xcb_gcontext_t gc, + uint32_t mask, + const xcb_params_gc_t *params) +{ + uint32_t value_list[32]; + pack_list(mask, (const uint32_t *)params, value_list); + return xcb_change_gc_checked( c, gc, mask, value_list ); +} + +xcb_void_cookie_t +xcb_aux_change_keyboard_control (xcb_connection_t *c, + uint32_t mask, + const xcb_params_keyboard_t *params) +{ + uint32_t value_list[16]; + pack_list(mask, (const uint32_t *)params, value_list); + return xcb_change_keyboard_control( c, mask, value_list ); +} + +/* Color related functions */ + +/* Return true if the given color name can be translated locally, + in which case load the components. Otherwise, a lookup_color request + will be needed, so return false. */ +int +xcb_aux_parse_color(char *color_name, + uint16_t *red, uint16_t *green, uint16_t *blue) +{ + int n, r, g, b, i; + if (!color_name || *color_name != '#') + return 0; + /* + * Excitingly weird RGB parsing code from Xlib. + */ + n = strlen (color_name); + color_name++; + n--; + if (n != 3 && n != 6 && n != 9 && n != 12) + return 0; + n /= 3; + g = b = 0; + do { + r = g; + g = b; + b = 0; + for (i = n; --i >= 0; ) { + char c = *color_name++; + b <<= 4; + if (c >= '0' && c <= '9') + b |= c - '0'; + else if (c >= 'A' && c <= 'F') + b |= c - ('A' - 10); + else if (c >= 'a' && c <= 'f') + b |= c - ('a' - 10); + else return 0; + } + } while (*color_name != '\0'); + n <<= 2; + n = 16 - n; + *red = r << n; + *green = g << n; + *blue = b << n; + return 1; +} + +/* Drawing related functions */ + +/* Adapted from Xlib */ +xcb_void_cookie_t +xcb_aux_set_line_attributes_checked (xcb_connection_t *dpy, + xcb_gcontext_t gc, + uint16_t linewidth, + int32_t linestyle, + int32_t capstyle, + int32_t joinstyle) +{ + uint32_t mask = 0; + xcb_params_gc_t gv; + + XCB_AUX_ADD_PARAM(&mask, &gv, line_width, linewidth); + XCB_AUX_ADD_PARAM(&mask, &gv, line_style, linestyle); + XCB_AUX_ADD_PARAM(&mask, &gv, cap_style, capstyle); + XCB_AUX_ADD_PARAM(&mask, &gv, join_style, joinstyle); + return xcb_aux_change_gc_checked(dpy, gc, mask, &gv); +} + +/* Adapted from Xlib */ +/* XXX It would be wiser for apps just to call + clear_area() directly. */ +xcb_void_cookie_t +xcb_aux_clear_window(xcb_connection_t * dpy, + xcb_window_t w) +{ + return xcb_clear_area(dpy, 0, w, 0, 0, 0, 0); +} diff --git a/src/xcb_aux.h b/src/xcb_aux.h new file mode 100644 index 0000000..d49d438 --- /dev/null +++ b/src/xcb_aux.h @@ -0,0 +1,214 @@ +#ifndef __XCB_AUX_H__ +#define __XCB_AUX_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + + +uint8_t xcb_aux_get_depth (xcb_connection_t *c, + xcb_screen_t *screen); + +uint8_t xcb_aux_get_depth_of_visual (xcb_screen_t *screen, + xcb_visualid_t id); + +xcb_screen_t *xcb_aux_get_screen (xcb_connection_t *c, + int screen); + +xcb_visualtype_t *xcb_aux_get_visualtype (xcb_connection_t *c, + int screen, + xcb_visualid_t vid); + +xcb_visualtype_t * +xcb_aux_find_visual_by_id (xcb_screen_t *screen, + xcb_visualid_t id); + +xcb_visualtype_t * +xcb_aux_find_visual_by_attrs (xcb_screen_t *screen, + int8_t class_, + int8_t depth); + +void xcb_aux_sync (xcb_connection_t *c); + +/* internal helper macro for XCB_AUX_ADD_PARAM +It gives the offset of the field 'param' in the structure pointed to by +'paramsp' in multiples of an uint32_t's size. */ +#define XCB_AUX_INTERNAL_OFFSETOF(paramsp, param) \ + ((uint32_t const*)(&((paramsp)->param))-(uint32_t const*)(paramsp)) + +/* add an optional parameter to an xcb_params_* structure +parameters: + maskp: pointer to bitmask whos bits mark used parameters + paramsp: pointer to structure with parameters + param: parameter to set + value: value to set the parameter to +*/ +#define XCB_AUX_ADD_PARAM(maskp, paramsp, param, value) \ + ((*(maskp)|=1<<XCB_AUX_INTERNAL_OFFSETOF((paramsp),param)), \ + ((paramsp)->param=(value))) + +typedef struct { + uint32_t back_pixmap; + uint32_t back_pixel; + uint32_t border_pixmap; + uint32_t border_pixel; + uint32_t bit_gravity; + uint32_t win_gravity; + uint32_t backing_store; + uint32_t backing_planes; + uint32_t backing_pixel; + uint32_t override_redirect; + uint32_t save_under; + uint32_t event_mask; + uint32_t dont_propagate; + uint32_t colormap; + uint32_t cursor; +} xcb_params_cw_t; + +xcb_void_cookie_t +xcb_aux_create_window (xcb_connection_t *c, + uint8_t depth, + xcb_window_t wid, + xcb_window_t parent, + int16_t x, + int16_t y, + uint16_t width, + uint16_t height, + uint16_t border_width, + uint16_t class_, + xcb_visualid_t visual, + uint32_t mask, + const xcb_params_cw_t *params); + +xcb_void_cookie_t +xcb_aux_create_window_checked (xcb_connection_t *c, + uint8_t depth, + xcb_window_t wid, + xcb_window_t parent, + int16_t x, + int16_t y, + uint16_t width, + uint16_t height, + uint16_t border_width, + uint16_t class_, + xcb_visualid_t visual, + uint32_t mask, + const xcb_params_cw_t *params); + +xcb_void_cookie_t +xcb_aux_change_window_attributes (xcb_connection_t *c, + xcb_window_t window, + uint32_t mask, + const xcb_params_cw_t *params); + +xcb_void_cookie_t +xcb_aux_change_window_attributes_checked (xcb_connection_t *c, + xcb_window_t window, + uint32_t mask, + const xcb_params_cw_t *params); + +typedef struct { + int32_t x; + int32_t y; + uint32_t width; + uint32_t height; + uint32_t border_width; + uint32_t sibling; + uint32_t stack_mode; +} xcb_params_configure_window_t; + +xcb_void_cookie_t +xcb_aux_configure_window (xcb_connection_t *c, + xcb_window_t window, + uint16_t mask, + const xcb_params_configure_window_t *params); + +typedef struct { + uint32_t function; + uint32_t plane_mask; + uint32_t foreground; + uint32_t background; + uint32_t line_width; + uint32_t line_style; + uint32_t cap_style; + uint32_t join_style; + uint32_t fill_style; + uint32_t fill_rule; + uint32_t tile; + uint32_t stipple; + uint32_t tile_stipple_origin_x; + uint32_t tile_stipple_origin_y; + uint32_t font; + uint32_t subwindow_mode; + uint32_t graphics_exposures; + uint32_t clip_originX; + uint32_t clip_originY; + uint32_t mask; + uint32_t dash_offset; + uint32_t dash_list; + uint32_t arc_mode; +} xcb_params_gc_t; + +xcb_void_cookie_t +xcb_aux_create_gc (xcb_connection_t *c, + xcb_gcontext_t cid, + xcb_drawable_t drawable, + uint32_t mask, + const xcb_params_gc_t *params); + +xcb_void_cookie_t +xcb_aux_create_gc_checked (xcb_connection_t *c, + xcb_gcontext_t gid, + xcb_drawable_t drawable, + uint32_t mask, + const xcb_params_gc_t *params); +xcb_void_cookie_t +xcb_aux_change_gc (xcb_connection_t *c, + xcb_gcontext_t gc, + uint32_t mask, + const xcb_params_gc_t *params); + +xcb_void_cookie_t +xcb_aux_change_gc_checked (xcb_connection_t *c, + xcb_gcontext_t gc, + uint32_t mask, + const xcb_params_gc_t *params); +typedef struct { + uint32_t key_click_percent; + uint32_t bell_percent; + uint32_t bell_pitch; + uint32_t bell_duration; + uint32_t led; + uint32_t led_mode; + uint32_t key; + uint32_t auto_repeat_mode; +} xcb_params_keyboard_t; + +xcb_void_cookie_t +xcb_aux_change_keyboard_control (xcb_connection_t *c, + uint32_t mask, + const xcb_params_keyboard_t *params); + +int +xcb_aux_parse_color(char *color_name, + uint16_t *red, uint16_t *green, uint16_t *blue); + +xcb_void_cookie_t +xcb_aux_set_line_attributes_checked (xcb_connection_t *dpy, + xcb_gcontext_t gc, + uint16_t linewidth, + int32_t linestyle, + int32_t capstyle, + int32_t joinstyle); + +xcb_void_cookie_t +xcb_aux_clear_window(xcb_connection_t * dpy, + xcb_window_t w); + +#ifdef __cplusplus +} +#endif + + +#endif /* __XCB_AUX_H__ */ diff --git a/src/xcb_bitops.h b/src/xcb_bitops.h new file mode 100644 index 0000000..a6872a1 --- /dev/null +++ b/src/xcb_bitops.h @@ -0,0 +1,212 @@ +#ifndef __XCB_BITOPS_H__ +#define __XCB_BITOPS_H__ + +/* Copyright (C) 2007 Bart Massey + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the names of the authors or their + * institutions shall not be used in advertising or otherwise to promote the + * sale, use or other dealings in this Software without prior written + * authorization from the authors. + */ + +#include <assert.h> +#include <inttypes.h> +#include <X11/Xfuncproto.h> + +/** + * @defgroup xcb__bitops XCB Bit Operations + * + * Inline functions for common bit ops used in XCB and elsewhere. + * + * @{ + */ + + +/** + * Create a low-order bitmask. + * @param n Mask size. + * @return Mask. + * + * Create a bitmask with the lower @p n bits set and the + * rest of the word clear. + * @ingroup xcb__bitops + */ +_X_INLINE static uint32_t +xcb_mask(uint32_t n) +{ + return n == 32 ? ~0 : (1 << n) - 1; +} + + +/** + * Population count. + * @param n Integer representing a bitset. + * @return Number of 1 bits in the bitset. + * + * This is a reasonably fast algorithm for counting the bits + * in a 32-bit word. Currently a classic binary + * divide-and-conquer popcount: popcount_2() from + * http://en.wikipedia.org/wiki/Hamming_weight. + * @ingroup xcb__bitops + */ + + +/* 15 ops, 3 long immediates, 14 stages, 9 alu ops, 9 alu stages */ +_X_INLINE static uint32_t +xcb_popcount(uint32_t x) +{ + uint32_t m1 = 0x55555555; + uint32_t m2 = 0x33333333; + uint32_t m4 = 0x0f0f0f0f; + x -= (x >> 1) & m1; + x = (x & m2) + ((x >> 2) & m2); + x = (x + (x >> 4)) & m4; + x += x >> 8; + return (x + (x >> 16)) & 0x3f; +} + + +/** + * Round up to the next power-of-two unit size. + * @param base Number to be rounded up. + * @param pad Multiple to be rounded to; must be a power of two. + * @return Rounded-up number. + * + * Rounds @p base up to a multiple of @p pad, where @p pad + * is a power of two. The more general case is handled by + * xcb_roundup(). + * @ingroup xcb__bitops + */ +_X_INLINE static uint32_t +xcb_roundup_2 (uint32_t base, uint32_t pad) +{ + return (base + pad - 1) & -pad; +} + +/** + * Round down to the next power-of-two unit size. + * @param base Number to be rounded down. + * @param pad Multiple to be rounded to; must be a power of two. + * @return Rounded-down number. + * + * Rounds @p base down to a multiple of @p pad, where @p pad + * is a power of two. The more general case is handled by + * xcb_rounddown(). + * @ingroup xcb__bitops + */ +_X_INLINE static uint32_t +xcb_rounddown_2 (uint32_t base, uint32_t pad) +{ + return base & -pad; +} + +/** + * Round up to the next unit size. + * @param base Number to be rounded up. + * @param pad Multiple to be rounded to. + * @return Rounded-up number. + * + * This is a general routine for rounding @p base up + * to a multiple of @p pad. If you know that @p pad + * is a power of two, you should probably call xcb_roundup_2() + * instead. + * @ingroup xcb__bitops + */ +_X_INLINE static uint32_t +xcb_roundup (uint32_t base, uint32_t pad) +{ + uint32_t b = base + pad - 1; + /* faster if pad is a power of two */ + if (((pad - 1) & pad) == 0) + return b & -pad; + return b - b % pad; +} + + +/** + * Round down to the next unit size. + * @param base Number to be rounded down. + * @param pad Multiple to be rounded to. + * @return Rounded-down number. + * + * This is a general routine for rounding @p base down + * to a multiple of @p pad. If you know that @p pad + * is a power of two, you should probably call xcb_rounddown_2() + * instead. + * @ingroup xcb__bitops + */ +_X_INLINE static uint32_t +xcb_rounddown (uint32_t base, uint32_t pad) +{ + /* faster if pad is a power of two */ + if (((pad - 1) & pad) == 0) + return base & -pad; + return base - base % pad; +} + + +/** + * Reverse bits of word. + * @param x Target word. + * @param n Number of low-order bits to reverse. + * @return Word with low @p n bits reversed, all others 0. + * + * Reverses the bottom @p n bits of @p x. + * @ingroup xcb__bitops + */ +_X_INLINE static uint32_t +xcb_bit_reverse(uint32_t x, uint8_t n) { + uint32_t m1 = 0x00ff00ff; + uint32_t m2 = 0x0f0f0f0f; + uint32_t m3 = 0x33333333; + uint32_t m4 = 0x55555555; + x = ((x << 16) | (x >> 16)); + x = ((x & m1) << 8) | ((x >> 8) & m1); + x = ((x & m2) << 4) | ((x >> 4) & m2); + x = ((x & m3) << 2) | ((x >> 2) & m3); + x = ((x & m4) << 1) | ((x >> 1) & m4); + x >>= 32 - n; + return x; +} + + +/** + * Host byte order. + * @return The byte order of the host. + * + * Tests the host's byte order and returns either + * XCB_IMAGE_ORDER_MSB_FIRST or XCB_IMAGE_ORDER_LSB_FIRST + * as appropriate. + * @ingroup xcb__bitops + */ +_X_INLINE static xcb_image_order_t +xcb_host_byte_order(void) { + uint32_t endian_test = 0x01020304; + + switch (*(char *)&endian_test) { + case 0x01: + return XCB_IMAGE_ORDER_MSB_FIRST; + case 0x04: + return XCB_IMAGE_ORDER_LSB_FIRST; + } + assert(0); +} + +#endif /* __XCB_BITOPS_H__ */ diff --git a/src/xcb_event.h b/src/xcb_event.h new file mode 100644 index 0000000..ee911fc --- /dev/null +++ b/src/xcb_event.h @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2008-2009 Julien Danjou <julien@danjou.info> + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the names of the authors or + * their institutions shall not be used in advertising or otherwise to + * promote the sale, use or other dealings in this Software without + * prior written authorization from the authors. + */ + +/** + * @defgroup xcb__event_t XCB Event Functions + * + * These functions ease the handling of X events received. + * + * @{ + */ + +#ifndef __XCB_EVENT_H__ +#define __XCB_EVENT_H__ + +#include <xcb/xcb.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Bit mask to find event type regardless of event source. + * + * Each event in the X11 protocol contains an 8-bit type code. + * The most-significant bit in this code is set if the event was + * generated from a SendEvent request. This mask can be used to + * determine the type of event regardless of how the event was + * generated. See the X11R6 protocol specification for details. + */ +#define XCB_EVENT_RESPONSE_TYPE_MASK (0x7f) +#define XCB_EVENT_RESPONSE_TYPE(e) (e->response_type & XCB_EVENT_RESPONSE_TYPE_MASK) +#define XCB_EVENT_SENT(e) (e->response_type & ~XCB_EVENT_RESPONSE_TYPE_MASK) + +/** + * @brief Convert an event response type to a label. + * @param type The event type. + * @return A string with the event name, or NULL if unknown. + */ +const char * xcb_event_get_label(uint8_t type); + +/** + * @brief Convert an event error type to a label. + * @param type The error type. + * @return A string with the event name, or NULL if unknown or if the event is + * not an error. + */ +const char * xcb_event_get_error_label(uint8_t type); + +/** + * @brief Convert an event request type to a label. + * @param type The request type. + * @return A string with the event name, or NULL if unknown or if the event is + * not an error. + */ +const char * xcb_event_get_request_label(uint8_t type); + +#ifdef __cplusplus +} +#endif + +/** + * @} + */ + +#endif /* __XCB_EVENT_H__ */ diff --git a/src/xcb_util.h b/src/xcb_util.h new file mode 100644 index 0000000..0f06f1b --- /dev/null +++ b/src/xcb_util.h @@ -0,0 +1,8 @@ +#ifndef __XCB_UTIL_H__ +#define __XCB_UTIL_H__ + +#include <xcb/xcb_atom.h> +#include <xcb/xcb_aux.h> +#include <xcb/xcb_event.h> + +#endif /* __XCB_UTIL_H__ */ |