1 // x11-rs: Rust bindings for X11 libraries
2 // The X11 libraries are available under the MIT license.
3 // These bindings are public domain.
4 
5 use std::os::raw::{
6   c_char,
7   c_double,
8   c_int,
9   c_short,
10   c_uint,
11   c_ulong,
12   c_ushort,
13 };
14 
15 use ::xlib::{
16   Atom,
17   Bool,
18   Colormap,
19   Cursor,
20   Display,
21   Pixmap,
22   Region,
23   Visual,
24   XID,
25   XRectangle,
26 };
27 
28 
29 //
30 // functions
31 //
32 
33 
34 x11_link! { Xrender, xrender, ["libXrender.so.1", "libXrender.so"], 44,
35   pub fn XRenderAddGlyphs (_7: *mut Display, _6: c_ulong, _5: *const c_ulong, _4: *const XGlyphInfo, _3: c_int, _2: *const c_char, _1: c_int) -> (),
36   pub fn XRenderAddTraps (_6: *mut Display, _5: c_ulong, _4: c_int, _3: c_int, _2: *const XTrap, _1: c_int) -> (),
37   pub fn XRenderChangePicture (_4: *mut Display, _3: c_ulong, _2: c_ulong, _1: *const XRenderPictureAttributes) -> (),
38   pub fn XRenderComposite (_13: *mut Display, _12: c_int, _11: c_ulong, _10: c_ulong, _9: c_ulong, _8: c_int, _7: c_int, _6: c_int, _5: c_int, _4: c_int, _3: c_int, _2: c_uint, _1: c_uint) -> (),
39   pub fn XRenderCompositeDoublePoly (_12: *mut Display, _11: c_int, _10: c_ulong, _9: c_ulong, _8: *const XRenderPictFormat, _7: c_int, _6: c_int, _5: c_int, _4: c_int, _3: *const XPointDouble, _2: c_int, _1: c_int) -> (),
40   pub fn XRenderCompositeString16 (_12: *mut Display, _11: c_int, _10: c_ulong, _9: c_ulong, _8: *const XRenderPictFormat, _7: c_ulong, _6: c_int, _5: c_int, _4: c_int, _3: c_int, _2: *const c_ushort, _1: c_int) -> (),
41   pub fn XRenderCompositeString32 (_12: *mut Display, _11: c_int, _10: c_ulong, _9: c_ulong, _8: *const XRenderPictFormat, _7: c_ulong, _6: c_int, _5: c_int, _4: c_int, _3: c_int, _2: *const c_uint, _1: c_int) -> (),
42   pub fn XRenderCompositeString8 (_12: *mut Display, _11: c_int, _10: c_ulong, _9: c_ulong, _8: *const XRenderPictFormat, _7: c_ulong, _6: c_int, _5: c_int, _4: c_int, _3: c_int, _2: *const c_char, _1: c_int) -> (),
43   pub fn XRenderCompositeText16 (_11: *mut Display, _10: c_int, _9: c_ulong, _8: c_ulong, _7: *const XRenderPictFormat, _6: c_int, _5: c_int, _4: c_int, _3: c_int, _2: *const XGlyphElt16, _1: c_int) -> (),
44   pub fn XRenderCompositeText32 (_11: *mut Display, _10: c_int, _9: c_ulong, _8: c_ulong, _7: *const XRenderPictFormat, _6: c_int, _5: c_int, _4: c_int, _3: c_int, _2: *const XGlyphElt32, _1: c_int) -> (),
45   pub fn XRenderCompositeText8 (_11: *mut Display, _10: c_int, _9: c_ulong, _8: c_ulong, _7: *const XRenderPictFormat, _6: c_int, _5: c_int, _4: c_int, _3: c_int, _2: *const XGlyphElt8, _1: c_int) -> (),
46   pub fn XRenderCompositeTrapezoids (_9: *mut Display, _8: c_int, _7: c_ulong, _6: c_ulong, _5: *const XRenderPictFormat, _4: c_int, _3: c_int, _2: *const XTrapezoid, _1: c_int) -> (),
47   pub fn XRenderCompositeTriangles (_9: *mut Display, _8: c_int, _7: c_ulong, _6: c_ulong, _5: *const XRenderPictFormat, _4: c_int, _3: c_int, _2: *const XTriangle, _1: c_int) -> (),
48   pub fn XRenderCompositeTriFan (_9: *mut Display, _8: c_int, _7: c_ulong, _6: c_ulong, _5: *const XRenderPictFormat, _4: c_int, _3: c_int, _2: *const XPointFixed, _1: c_int) -> (),
49   pub fn XRenderCompositeTriStrip (_9: *mut Display, _8: c_int, _7: c_ulong, _6: c_ulong, _5: *const XRenderPictFormat, _4: c_int, _3: c_int, _2: *const XPointFixed, _1: c_int) -> (),
50   pub fn XRenderCreateAnimCursor (_3: *mut Display, _2: c_int, _1: *mut XAnimCursor) -> c_ulong,
51   pub fn XRenderCreateConicalGradient (_5: *mut Display, _4: *const XConicalGradient, _3: *const c_int, _2: *const XRenderColor, _1: c_int) -> c_ulong,
52   pub fn XRenderCreateCursor (_4: *mut Display, _3: c_ulong, _2: c_uint, _1: c_uint) -> c_ulong,
53   pub fn XRenderCreateGlyphSet (_2: *mut Display, _1: *const XRenderPictFormat) -> c_ulong,
54   pub fn XRenderCreateLinearGradient (_5: *mut Display, _4: *const XLinearGradient, _3: *const c_int, _2: *const XRenderColor, _1: c_int) -> c_ulong,
55   pub fn XRenderCreatePicture (_5: *mut Display, _4: c_ulong, _3: *const XRenderPictFormat, _2: c_ulong, _1: *const XRenderPictureAttributes) -> c_ulong,
56   pub fn XRenderCreateRadialGradient (_5: *mut Display, _4: *const XRadialGradient, _3: *const c_int, _2: *const XRenderColor, _1: c_int) -> c_ulong,
57   pub fn XRenderCreateSolidFill (_2: *mut Display, _1: *const XRenderColor) -> c_ulong,
58   pub fn XRenderFillRectangle (_8: *mut Display, _7: c_int, _6: c_ulong, _5: *const XRenderColor, _4: c_int, _3: c_int, _2: c_uint, _1: c_uint) -> (),
59   pub fn XRenderFillRectangles (_6: *mut Display, _5: c_int, _4: c_ulong, _3: *const XRenderColor, _2: *const XRectangle, _1: c_int) -> (),
60   pub fn XRenderFindFormat (_4: *mut Display, _3: c_ulong, _2: *const XRenderPictFormat, _1: c_int) -> *mut XRenderPictFormat,
61   pub fn XRenderFindStandardFormat (_2: *mut Display, _1: c_int) -> *mut XRenderPictFormat,
62   pub fn XRenderFindVisualFormat (_2: *mut Display, _1: *const Visual) -> *mut XRenderPictFormat,
63   pub fn XRenderFreeGlyphs (_4: *mut Display, _3: c_ulong, _2: *const c_ulong, _1: c_int) -> (),
64   pub fn XRenderFreeGlyphSet (_2: *mut Display, _1: c_ulong) -> (),
65   pub fn XRenderFreePicture (_2: *mut Display, _1: c_ulong) -> (),
66   pub fn XRenderParseColor (_3: *mut Display, _2: *mut c_char, _1: *mut XRenderColor) -> c_int,
67   pub fn XRenderQueryExtension (_3: *mut Display, _2: *mut c_int, _1: *mut c_int) -> c_int,
68   pub fn XRenderQueryFilters (_2: *mut Display, _1: c_ulong) -> *mut XFilters,
69   pub fn XRenderQueryFormats (_1: *mut Display) -> c_int,
70   pub fn XRenderQueryPictIndexValues (_3: *mut Display, _2: *const XRenderPictFormat, _1: *mut c_int) -> *mut XIndexValue,
71   pub fn XRenderQuerySubpixelOrder (_2: *mut Display, _1: c_int) -> c_int,
72   pub fn XRenderQueryVersion (_3: *mut Display, _2: *mut c_int, _1: *mut c_int) -> c_int,
73   pub fn XRenderReferenceGlyphSet (_2: *mut Display, _1: c_ulong) -> c_ulong,
74   pub fn XRenderSetPictureClipRectangles (_6: *mut Display, _5: c_ulong, _4: c_int, _3: c_int, _2: *const XRectangle, _1: c_int) -> (),
75   pub fn XRenderSetPictureClipRegion (_3: *mut Display, _2: c_ulong, _1: Region) -> (),
76   pub fn XRenderSetPictureFilter (_5: *mut Display, _4: c_ulong, _3: *const c_char, _2: *mut c_int, _1: c_int) -> (),
77   pub fn XRenderSetPictureTransform (_3: *mut Display, _2: c_ulong, _1: *mut XTransform) -> (),
78   pub fn XRenderSetSubpixelOrder (_3: *mut Display, _2: c_int, _1: c_int) -> c_int,
79 variadic:
80 globals:
81 }
82 
83 
84 //
85 // types
86 //
87 
88 
89 pub type Glyph = XID;
90 pub type GlyphSet = XID;
91 pub type PictFormat = XID;
92 pub type Picture = XID;
93 pub type XDouble = c_double;
94 pub type XFixed = c_int;
95 
96 #[derive(Debug, Clone, Copy, PartialEq)]
97 #[repr(C)]
98 pub struct _XAnimCursor {
99   pub cursor: Cursor,
100   pub delay: c_ulong,
101 }
102 pub type XAnimCursor = _XAnimCursor;
103 
104 #[derive(Debug, Clone, Copy, PartialEq)]
105 #[repr(C)]
106 pub struct _XCircle {
107   pub x: XFixed,
108   pub y: XFixed,
109   pub radius: XFixed,
110 }
111 pub type XCircle = _XCircle;
112 
113 #[derive(Debug, Clone, Copy, PartialEq)]
114 #[repr(C)]
115 pub struct _XConicalGradient {
116   pub center: XPointFixed,
117   pub angle: XFixed,
118 }
119 pub type XConicalGradient = _XConicalGradient;
120 
121 #[derive(Debug, Clone, Copy, PartialEq)]
122 #[repr(C)]
123 pub struct _XFilters {
124   pub nfilter: c_int,
125   pub filter: *mut *mut c_char,
126   pub nalias: c_int,
127   pub alias: *mut c_short,
128 }
129 pub type XFilters = _XFilters;
130 
131 #[derive(Debug, Clone, Copy, PartialEq)]
132 #[repr(C)]
133 pub struct _XGlyphElt8 {
134   pub glyphset: GlyphSet,
135   pub chars: *mut c_char,
136   pub nchars: c_int,
137   pub xOff: c_int,
138   pub yOff: c_int,
139 }
140 pub type XGlyphElt8 = _XGlyphElt8;
141 
142 #[derive(Debug, Clone, Copy, PartialEq)]
143 #[repr(C)]
144 pub struct _XGlyphElt16 {
145   pub glyphset: GlyphSet,
146   pub chars: *mut c_ushort,
147   pub nchars: c_int,
148   pub xOff: c_int,
149   pub yOff: c_int,
150 }
151 pub type XGlyphElt16 = _XGlyphElt16;
152 
153 #[derive(Debug, Clone, Copy, PartialEq)]
154 #[repr(C)]
155 pub struct _XGlyphElt32 {
156   pub glyphset: GlyphSet,
157   pub chars: *mut c_uint,
158   pub nchars: c_int,
159   pub xOff: c_int,
160   pub yOff: c_int,
161 }
162 pub type XGlyphElt32 = _XGlyphElt32;
163 
164 #[derive(Debug, Clone, Copy, PartialEq)]
165 #[repr(C)]
166 pub struct _XGlyphInfo {
167   pub width: c_ushort,
168   pub height: c_ushort,
169   pub x: c_short,
170   pub y: c_short,
171   pub xOff: c_short,
172   pub yOff: c_short,
173 }
174 pub type XGlyphInfo = _XGlyphInfo;
175 
176 #[derive(Debug, Clone, Copy, PartialEq)]
177 #[repr(C)]
178 pub struct _XIndexValue {
179   pub pixel: c_ulong,
180   pub red: c_ushort,
181   pub green: c_ushort,
182   pub blue: c_ushort,
183   pub alpha: c_ushort,
184 }
185 pub type XIndexValue = _XIndexValue;
186 
187 #[derive(Debug, Clone, Copy, PartialEq)]
188 #[repr(C)]
189 pub struct _XLinearGradient {
190   pub p1: XPointFixed,
191   pub p2: XPointFixed,
192 }
193 pub type XLinearGradient = _XLinearGradient;
194 
195 #[derive(Debug, Clone, Copy, PartialEq)]
196 #[repr(C)]
197 pub struct _XLineFixed {
198   pub p1: XPointFixed,
199   pub p2: XPointFixed,
200 }
201 pub type XLineFixed = _XLineFixed;
202 
203 #[derive(Debug, Clone, Copy, PartialEq)]
204 #[repr(C)]
205 pub struct _XPointDouble {
206   pub x: XDouble,
207   pub y: XDouble,
208 }
209 pub type XPointDouble = _XPointDouble;
210 
211 #[derive(Debug, Clone, Copy, PartialEq)]
212 #[repr(C)]
213 pub struct _XPointFixed {
214   pub x: XFixed,
215   pub y: XFixed,
216 }
217 pub type XPointFixed = _XPointFixed;
218 
219 #[derive(Debug, Clone, Copy, PartialEq)]
220 #[repr(C)]
221 pub struct _XRadialGradient {
222   pub inner: XCircle,
223   pub outer: XCircle,
224 }
225 pub type XRadialGradient = _XRadialGradient;
226 
227 #[derive(Debug, Clone, Copy, PartialEq)]
228 #[repr(C)]
229 pub struct XRenderColor {
230   pub red: c_ushort,
231   pub green: c_ushort,
232   pub blue: c_ushort,
233   pub alpha: c_ushort,
234 }
235 
236 #[derive(Debug, Clone, Copy, PartialEq)]
237 #[repr(C)]
238 pub struct XRenderDirectFormat {
239   pub red: c_short,
240   pub redMask: c_short,
241   pub green: c_short,
242   pub greenMask: c_short,
243   pub blue: c_short,
244   pub blueMask: c_short,
245   pub alpha: c_short,
246   pub alphaMask: c_short,
247 }
248 
249 #[derive(Debug, Clone, Copy, PartialEq)]
250 #[repr(C)]
251 pub struct XRenderPictFormat {
252   pub id: PictFormat,
253   pub type_: c_int,
254   pub depth: c_int,
255   pub direct: XRenderDirectFormat,
256   pub colormap: Colormap,
257 }
258 
259 #[derive(Debug, Clone, Copy, PartialEq)]
260 #[repr(C)]
261 pub struct _XRenderPictureAttributes {
262   pub repeat: c_int,
263   pub alpha_map: Picture,
264   pub alpha_x_origin: c_int,
265   pub alpha_y_origin: c_int,
266   pub clip_x_origin: c_int,
267   pub clip_y_origin: c_int,
268   pub clip_mask: Pixmap,
269   pub graphics_exposures: Bool,
270   pub subwindow_mode: c_int,
271   pub poly_edge: c_int,
272   pub poly_mode: c_int,
273   pub dither: Atom,
274   pub component_alpha: Bool,
275 }
276 pub type XRenderPictureAttributes = _XRenderPictureAttributes;
277 
278 #[derive(Debug, Clone, Copy, PartialEq)]
279 #[repr(C)]
280 pub struct _XSpanFix {
281   pub left: XFixed,
282   pub right: XFixed,
283   pub y: XFixed,
284 }
285 pub type XSpanFix = _XSpanFix;
286 
287 #[derive(Debug, Clone, Copy, PartialEq)]
288 #[repr(C)]
289 pub struct _XTrap {
290   pub top: XSpanFix,
291   pub bottom: XSpanFix,
292 }
293 pub type XTrap = _XTrap;
294 
295 #[derive(Debug, Clone, Copy, PartialEq)]
296 #[repr(C)]
297 pub struct _XTrapezoid {
298   pub top: XFixed,
299   pub bottom: XFixed,
300   pub left: XLineFixed,
301   pub right: XLineFixed,
302 }
303 pub type XTrapezoid = _XTrapezoid;
304 
305 #[derive(Debug, Clone, Copy, PartialEq)]
306 #[repr(C)]
307 pub struct _XTriangle {
308   pub p1: XPointFixed,
309   pub p2: XPointFixed,
310   pub p3: XPointFixed,
311 }
312 pub type XTriangle = _XTriangle;
313 
314 #[derive(Debug, Clone, Copy, PartialEq)]
315 #[repr(C)]
316 pub struct _XTransform {
317   pub matrix: [[XFixed; 3]; 3],
318 }
319 pub type XTransform = _XTransform;
320 
321 
322 //
323 // constants
324 //
325 
326 
327 // pict format mask
328 pub const PictFormatID: c_ulong = 1 << 0;
329 pub const PictFormatType: c_ulong = 1 << 1;
330 pub const PictFormatDepth: c_ulong = 1 << 2;
331 pub const PictFormatRed: c_ulong = 1 << 3;
332 pub const PictFormatRedMask: c_ulong = 1 << 4;
333 pub const PictFormatGreen: c_ulong = 1 << 5;
334 pub const PictFormatGreenMask: c_ulong = 1 << 6;
335 pub const PictFormatBlue: c_ulong = 1 << 7;
336 pub const PictFormatBlueMask: c_ulong = 1 << 8;
337 pub const PictFormatAlpha: c_ulong = 1 << 9;
338 pub const PictFormatAlphaMask: c_ulong = 1 << 10;
339 pub const PictFormatColormap: c_ulong = 1 << 11;
340 
341 // error codes
342 pub const BadPictFormat: c_int = 0;
343 pub const BadPicture: c_int = 1;
344 pub const BadPictOp: c_int = 2;
345 pub const BadGlyphSet: c_int = 3;
346 pub const BadGlyph: c_int = 4;
347 pub const RenderNumberErrors: c_int = BadGlyph + 1;
348 
349 // pict types
350 pub const PictTypeIndexed: c_int = 0;
351 pub const PictTypeDirect: c_int = 1;
352 
353 // ops
354 pub const PictOpMinimum: c_int = 0;
355 pub const PictOpClear: c_int = 0;
356 pub const PictOpSrc: c_int = 1;
357 pub const PictOpDst: c_int = 2;
358 pub const PictOpOver: c_int = 3;
359 pub const PictOpOverReverse: c_int = 4;
360 pub const PictOpIn: c_int = 5;
361 pub const PictOpInReverse: c_int = 6;
362 pub const PictOpOut: c_int = 7;
363 pub const PictOpOutReverse: c_int = 8;
364 pub const PictOpAtop: c_int = 9;
365 pub const PictOpAtopReverse: c_int = 10;
366 pub const PictOpXor: c_int = 11;
367 pub const PictOpAdd: c_int = 12;
368 pub const PictOpSaturate: c_int = 13;
369 pub const PictOpMaximum: c_int = 13;
370 
371 pub const PictOpDisjointMinimum: c_int = 0x10;
372 pub const PictOpDisjointClear: c_int = 0x10;
373 pub const PictOpDisjointSrc: c_int = 0x11;
374 pub const PictOpDisjointDst: c_int = 0x12;
375 pub const PictOpDisjointOver: c_int = 0x13;
376 pub const PictOpDisjointOverReverse: c_int = 0x14;
377 pub const PictOpDisjointIn: c_int = 0x15;
378 pub const PictOpDisjointInReverse: c_int = 0x16;
379 pub const PictOpDisjointOut: c_int = 0x17;
380 pub const PictOpDisjointOutReverse: c_int = 0x18;
381 pub const PictOpDisjointAtop: c_int = 0x19;
382 pub const PictOpDisjointAtopReverse: c_int = 0x1a;
383 pub const PictOpDisjointXor: c_int = 0x1b;
384 pub const PictOpDisjointMaximum: c_int = 0x1b;
385 
386 pub const PictOpConjointMinimum: c_int = 0x20;
387 pub const PictOpConjointClear: c_int = 0x20;
388 pub const PictOpConjointSrc: c_int = 0x21;
389 pub const PictOpConjointDst: c_int = 0x22;
390 pub const PictOpConjointOver: c_int = 0x23;
391 pub const PictOpConjointOverReverse: c_int = 0x24;
392 pub const PictOpConjointIn: c_int = 0x25;
393 pub const PictOpConjointInReverse: c_int = 0x26;
394 pub const PictOpConjointOut: c_int = 0x27;
395 pub const PictOpConjointOutReverse: c_int = 0x28;
396 pub const PictOpConjointAtop: c_int = 0x29;
397 pub const PictOpConjointAtopReverse: c_int = 0x2a;
398 pub const PictOpConjointXor: c_int = 0x2b;
399 pub const PictOpConjointMaximum: c_int = 0x2b;
400 
401 pub const PictOpBlendMinimum: c_int = 0x30;
402 pub const PictOpMultiply: c_int = 0x30;
403 pub const PictOpScreen: c_int = 0x31;
404 pub const PictOpOverlay: c_int = 0x32;
405 pub const PictOpDarken: c_int = 0x33;
406 pub const PictOpLighten: c_int = 0x34;
407 pub const PictOpColorDodge: c_int = 0x35;
408 pub const PictOpColorBurn: c_int = 0x36;
409 pub const PictOpHardLight: c_int = 0x37;
410 pub const PictOpSoftLight: c_int = 0x38;
411 pub const PictOpDifference: c_int = 0x39;
412 pub const PictOpExclusion: c_int = 0x3a;
413 pub const PictOpHSLHue: c_int = 0x3b;
414 pub const PictOpHSLSaturation: c_int = 0x3c;
415 pub const PictOpHSLColor: c_int = 0x3d;
416 pub const PictOpHSLLuminosity: c_int = 0x3e;
417 pub const PictOpBlendMaximum: c_int = 0x3e;
418 
419 // poly edge types
420 pub const PolyEdgeSharp: c_int = 0;
421 pub const PolyEdgeSmooth: c_int = 1;
422 
423 // poly modes
424 pub const PolyModePrecise: c_int = 0;
425 pub const PolyModeImprecise: c_int = 1;
426 
427 // picture attributes mask
428 pub const CPRepeat: c_int = 1 << 0;
429 pub const CPAlphaMap: c_int = 1 << 1;
430 pub const CPAlphaXOrigin: c_int = 1 << 2;
431 pub const CPAlphaYOrigin: c_int = 1 << 3;
432 pub const CPClipXOrigin: c_int = 1 << 4;
433 pub const CPClipYOrigin: c_int = 1 << 5;
434 pub const CPClipMask: c_int = 1 << 6;
435 pub const CPGraphicsExposure: c_int = 1 << 7;
436 pub const CPSubwindowMode: c_int = 1 << 8;
437 pub const CPPolyEdge: c_int = 1 << 9;
438 pub const CPPolyMode: c_int = 1 << 10;
439 pub const CPDither: c_int = 1 << 11;
440 pub const CPComponentAlpha: c_int = 1 << 12;
441 pub const CPLastBit: c_int = 12;
442 
443 // filter methods
444 pub const FilterNearest: &'static str = "nearest";
445 pub const FilterBilinear: &'static str = "bilinear";
446 pub const FilterConvolution: &'static str = "convolution";
447 pub const FilterFast: &'static str = "fast";
448 pub const FilterGood: &'static str = "good";
449 pub const FilterBest: &'static str = "best";
450 
451 // subpixel orders
452 pub const SubPixelUnknown: c_int = 0;
453 pub const SubPixelHorizontalRGB: c_int = 1;
454 pub const SubPixelHorizontalBGR: c_int = 2;
455 pub const SubPixelVerticalRGB: c_int = 3;
456 pub const SubPixelVerticalBGR: c_int = 4;
457 pub const SubPixelNone: c_int = 5;
458 
459 // repeat attributes
460 pub const RepeatNone: c_int = 0;
461 pub const RepeatNormal: c_int = 1;
462 pub const RepeatPad: c_int = 2;
463 pub const RepeatReflect: c_int = 3;
464