egra: checkbox fixes
[iv.d.git] / x11 / util.d
blob63ddd62e7b7102abe93712a61d51084a8f717584
1 module iv.x11.util /*is aliced*/;
3 import core.stdc.config : c_long, c_ulong;
4 import core.stdc.stddef : wchar_t;
6 import iv.alice;
7 import iv.x11.md;
8 import iv.x11.x11;
9 import iv.x11.xlib;
10 import iv.x11.region;
11 import iv.x11.resource : XrmStringToQuark;
12 import iv.x11.keysym;
14 extern(C):
17 * Bitmask returned by XParseGeometry(). Each bit tells if the corresponding
18 * value (x, y, width, height) was found in the parsed string.
20 enum : int {
21 NoValue = 0x0000,
22 XValue = 0x0001,
23 YValue = 0x0002,
24 WidthValue = 0x0004,
25 HeightValue = 0x0008,
26 AllValues = 0x000F,
27 XNegative = 0x0010,
28 YNegative = 0x0020,
32 * new version containing base_width, base_height, and win_gravity fields;
33 * used with WM_NORMAL_HINTS.
35 struct XSizeHints {
36 c_long flags; /* marks which fields in this structure are defined */
37 int x, y; /* obsolete for new window mgrs, but clients */
38 int width, height; /* should set so old wm's don't mess up */
39 int min_width, min_height;
40 int max_width, max_height;
41 int width_inc, height_inc;
42 struct aspect {
43 int x; /* numerator */
44 int y; /* denominator */
46 aspect min_aspect, max_aspect;
47 int base_width, base_height; /* added by ICCCM version 1 */
48 int win_gravity; /* added by ICCCM version 1 */
52 * The next block of definitions are for window manager properties that
53 * clients and applications use for communication.
55 /* flags argument in size hints */
56 enum : c_ulong {
57 USPosition = 1<<0, /* user specified x, y */
58 USSize = 1<<1, /* user specified width, height */
60 PPosition = 1<<2, /* program specified position */
61 PSize = 1<<3, /* program specified size */
62 PMinSize = 1<<4, /* program specified minimum size */
63 PMaxSize = 1<<5, /* program specified maximum size */
64 PResizeInc = 1<<6, /* program specified resize increments */
65 PAspect = 1<<7, /* program specified min and max aspect ratios */
66 PBaseSize = 1<<8, /* program specified base for incrementing */
67 PWinGravity = 1<<9, /* program specified window gravity */
70 /* obsolete */
71 enum c_long PAllHints = (PPosition|PSize|PMinSize|PMaxSize|PResizeInc|PAspect);
73 struct XWMHints {
74 c_long flags; /* marks which fields in this structure are defined */
75 Bool input; /* does this application rely on the window manager to get keyboard input? */
76 int initial_state; /* see below */
77 Pixmap icon_pixmap; /* pixmap to be used as icon */
78 Window icon_window; /* window to be used as icon */
79 int icon_x, icon_y; /* initial position of icon */
80 Pixmap icon_mask; /* icon mask bitmap */
81 XID window_group; /* id of related window group */
82 /* this structure may be extended in the future */
85 /* definition for flags of XWMHints */
86 enum : c_ulong {
87 InputHint = (1<<0),
88 StateHint = (1<<1),
89 IconPixmapHint = (1<<2),
90 IconWindowHint = (1<<3),
91 IconPositionHint = (1<<4),
92 IconMaskHint = (1<<5),
93 WindowGroupHint = (1<<6),
94 AllHints = (InputHint|StateHint|IconPixmapHint|IconWindowHint|IconPositionHint|IconMaskHint|WindowGroupHint),
95 XUrgencyHint = (1<<8),
98 /* definitions for initial window state */
99 enum {
100 WithdrawnState = 0, /* for windows that are not mapped */
101 NormalState = 1, /* most applications want to start this way */
102 IconicState = 3, /* application wants to start as an icon */
106 * Obsolete states no longer defined by ICCCM
108 enum {
109 DontCareState = 0, /* don't know or care */
110 ZoomState = 2, /* application wants to start zoomed */
111 InactiveState = 4, /* application believes it is seldom used; */
113 /* some wm's may put it on inactive menu */
117 * new structure for manipulating TEXT properties; used with WM_NAME,
118 * WM_ICON_NAME, WM_CLIENT_MACHINE, and WM_COMMAND.
120 struct XTextProperty {
121 ubyte* value; /* same as Property routines */
122 Atom encoding; /* prop type */
123 int format; /* prop data format: 8, 16, or 32 */
124 c_ulong nitems; /* number of data items in value */
127 enum int XNoMemory = -1;
128 enum int XLocaleNotSupported = -2;
129 enum int XConverterNotFound = -3;
131 alias XICCEncodingStyle = int;
132 enum {
133 XStringStyle, /* STRING */
134 XCompoundTextStyle, /* COMPOUND_TEXT */
135 XTextStyle, /* text in owner's encoding (current locale) */
136 XStdICCTextStyle, /* STRING, else COMPOUND_TEXT */
137 /* The following is an XFree86 extension, introduced in November 2000 */
138 XUTF8StringStyle, /* UTF8_STRING */
141 struct XIconSize {
142 int min_width, min_height;
143 int max_width, max_height;
144 int width_inc, height_inc;
147 struct XClassHint {
148 const(char)* res_name; // was `char*`
149 const(char)* res_class; // was `char*`
152 version (XUTIL_DEFINE_FUNCTIONS) {
153 int XDestroyImage (XImage* ximage);
154 c_ulong XGetPixel (XImage *ximage, int x, int y);
155 int XPutPixel (XImage* ximage, int x, int y, c_ulong pixel);
156 XImage* XSubImage (XImage *ximage, int x, int y, uint width, uint height);
157 int XAddPixel (XImage *ximage, c_long value);
158 } else {
160 * These macros are used to give some sugar to the image routines so that
161 * naive people are more comfortable with them.
164 * XDestroyImage
165 * The XDestroyImage() function deallocates the memory associated with the XImage structure.
166 * Note that when the image is created using XCreateImage(), XGetImage(), or XSubImage(), the destroy procedure that this macro calls frees both the image structure and the data pointed to by the image structure.
167 * Params:
168 * ximage = Specifies the image.
169 * See_Also:
170 * XAddPixel(), XCreateImage(), XGetPixel(), XPutPixel(), XSubImage(), http://tronche.com/gui/x/xlib/utilities/manipulating-images.html
172 int XDestroyImage (XImage* ximage) { return ximage.f.destroy_image(ximage); }
174 * XGetPixel
175 * The XGetPixel() function returns the specified pixel from the named image. The pixel value is returned in normalized format (that is, the least-significant byte of the long is the least-significant byte of the pixel). The image must contain the x and y coordinates.
176 * Params:
177 * ximage = Specifies the image.
178 * x = Specify the x coordinate.
179 * y = Specify the y coordinate.
180 * See_Also:
181 * XAddPixel(), XCreateImage(), XGetPixel(), XPutPixel(), XSubImage(), http://tronche.com/gui/x/xlib/utilities/manipulating-images.html
183 c_ulong XGetPixel (XImage* ximage, int x, int y) { return ximage.f.get_pixel(ximage, x, y); }
185 * XPutPixel
186 * The XPutPixel() function overwrites the pixel in the named image with the specified pixel value. The input pixel value must be in normalized format (that is, the least-significant byte of the long is the least-significant byte of the pixel). The image must contain the x and y coordinates.
187 * Params:
188 * ximage = Specifies the image.
189 * x = Specify the x coordinate.
190 * y = Specify the y coordinate.
191 * pixel = Specifies the new pixel value.
192 * See_Also:
193 * XAddPixel(), XCreateImage(), XGetPixel(), XPutPixel(), XSubImage(), http://tronche.com/gui/x/xlib/utilities/manipulating-images.html
195 int XPutPixel (XImage* ximage, int x, int y, c_ulong pixel) { return ximage.f.put_pixel(ximage, x, y, pixel); }
197 * XSubImage
198 * The XSubImage() function creates a new image that is a subsection of an existing one. It allocates the memory necessary for the new XImage structure and returns a pointer to the new image. The data is copied from the source image, and the image must contain the rectangle defined by x, y, subimage_width, and subimage_height.
199 * Params:
200 * ximage = Specifies the image.
201 * x = Specify the x coordinate.
202 * y = Specify the y coordinate.
203 * subimage_width = Specifies the width of the new subimage, in pixels.
204 * subimage_height = Specifies the height of the new subimage, in pixels.
205 * See_Also:
206 * XAddPixel(), XCreateImage(), XGetPixel(), XPutPixel(), XSubImage(), http://tronche.com/gui/x/xlib/utilities/manipulating-images.html
208 XImage* XSubImage (XImage* ximage, int x, int y, uint width, uint height) { return ximage.f.sub_image(ximage, x, y, width, height); }
210 * XAddPixel
211 * The XAddPixel() function adds a constant value to every pixel in an image. It is useful when you have a base pixel value from allocating color resources and need to manipulate the image to that form.
212 * Params:
213 * ximage = Specifies the image.
214 * value = Specifies the constant value that is to be added.
215 * See_Also:
216 * XAddPixel(), XCreateImage(), XGetPixel(), XPutPixel(), XSubImage(), http://tronche.com/gui/x/xlib/utilities/manipulating-images.html
218 int XAddPixel (XImage* ximage, c_long value) { return ximage.f.add_pixel(ximage, value); }
222 nothrow @trusted @nogc:
224 * Compose sequence status structure, used in calling XLookupString.
226 struct XComposeStatus {
227 XPointer compose_ptr; /* state table pointer */
228 int chars_matched; /* match state */
232 * Keysym macros, used on Keysyms to test for classes of symbols
234 //TODO
235 template IsKeypadKey (KeySym keysym) {
236 enum IsKeypadKey = (keysym >= XK_KP_Space && keysym <= XK_KP_Equal);
239 template IsPrivateKeypadKey (KeySym keysym) {
240 enum IsPrivateKeypadKey = (keysym >= 0x11000000 && keysym <= 0x1100FFFF);
243 template IsCursorKey (KeySym keysym) {
244 enum IsCursorKey = (keysym >= XK_Home && keysym < XK_Select);
247 template IsPFKey (KeySym keysym) {
248 enum IsPFKey = (keysym >= XK_KP_F1 && keysym <= XK_KP_F4);
251 template IsFunctionKey (KeySym keysym) {
252 enum IsFunctionKey = (keysym >= XK_F1 && keysym <= XK_F35);
255 template IsMiscFunctionKey (KeySym keysym) {
256 enum IsMiscFunctionKey = (keysym >= XK_Select && keysym <= XK_Break);
259 template IsModifierKey (KeySym keysym) {
260 enum IsModifierKey = (
261 (keysym >= XK_Shift_L && keysym <= XK_Hyper_R) ||
262 (keysym >= XK_ISO_Lock && keysym <= XK_ISO_Last_Group_Lock) ||
263 (keysym == XK_Mode_switch) ||
264 (keysym == XK_Num_Lock)
269 * opaque reference to Region data type
271 //alias Region = _XRegion*;
273 /* Return values from XRectInRegion() */
274 enum {
275 RectangleOut = 0,
276 RectangleIn = 1,
277 RectanglePart = 2,
282 * Information used by the visual utility routines to find desired visual
283 * type from the many visuals a display may support.
285 struct XVisualInfo {
286 Visual* visual;
287 VisualID visualid;
288 int screen;
289 int depth;
290 int c_class; /* C++ */;
291 c_ulong red_mask;
292 c_ulong green_mask;
293 c_ulong blue_mask;
294 int colormap_size;
295 int bits_per_rgb;
298 enum {
299 VisualNoMask = 0x0,
300 VisualIDMask = 0x1,
301 VisualScreenMask = 0x2,
302 VisualDepthMask = 0x4,
303 VisualClassMask = 0x8,
304 VisualRedMaskMask = 0x10,
305 VisualGreenMaskMask = 0x20,
306 VisualBlueMaskMask = 0x40,
307 VisualColormapSizeMask = 0x80,
308 VisualBitsPerRGBMask = 0x100,
309 VisualAllMask = 0x1FF,
313 * This defines a window manager property that clients may use to
314 * share standard color maps of type RGB_COLOR_MAP:
316 struct XStandardColormap{
317 Colormap colormap;
318 c_ulong red_max;
319 c_ulong red_mult;
320 c_ulong green_max;
321 c_ulong green_mult;
322 c_ulong blue_max;
323 c_ulong blue_mult;
324 c_ulong base_pixel;
325 VisualID visualid; /* added by ICCCM version 1 */
326 XID killid; /* added by ICCCM version 1 */
329 enum XID ReleaseByFreeingColormap = cast(XID)1; /* for killid field above */
333 * return codes for XReadBitmapFile and XWriteBitmapFile
335 enum {
336 BitmapSuccess = 0,
337 BitmapOpenFailed = 1,
338 BitmapFileInvalid = 2,
339 BitmapNoMemory = 3,
343 * Context Management
346 /* Associative lookup table return codes */
347 enum {
348 XCSUCCESS = 0, /* No error. */
349 XCNOMEM = 1, /* Out of memory */
350 XCNOENT = 2, /* No entry in table */
353 //typedef XContext = int;
354 alias XContext = int;
356 template XUniqueContext () {
357 const XContext XUniqueContext = XrmUniqueQuark();
360 //TODO: const?
361 XContext XStringToContext (char* statement) { return cast(XContext)XrmStringToQuark(statement); }
363 /* The following declarations are alphabetized. */
364 XClassHint* XAllocClassHint ();
365 XIconSize* XAllocIconSize ();
366 XSizeHints* XAllocSizeHints ();
367 XStandardColormap* XAllocStandardColormap ();
368 XWMHints* XAllocWMHints ();
369 int XClipBox (XRegion r, XRectangle* rect_return);
370 XRegion XCreateRegion ();
371 char* XDefaultString ();
372 int XDeleteContext (Display* display, XID rid, XContext context);
373 int XDestroyRegion (XRegion r);
374 int XEmptyRegion (XRegion r);
375 int XEqualRegion (XRegion r1, XRegion r2);
376 int XFindContext (Display* display, XID rid, XContext context, XPointer* data_return);
377 Status XGetClassHint (Display* display, Window w, XClassHint* class_hints_return);
378 Status XGetIconSizes (Display* display, Window w, XIconSize** size_list_return, int* count_return);
379 Status XGetNormalHints (Display* display, Window w, XSizeHints* hints_return);
380 Status XGetRGBColormaps (Display* display, Window w, XStandardColormap** stdcmap_return, int* count_return, Atom property);
381 Status XGetSizeHints (Display* display, Window w, XSizeHints* hints_return, Atom property);
382 Status XGetStandardColormap (Display* display, Window w, XStandardColormap* colormap_return, Atom property);
383 Status XGetTextProperty (Display* display, Window window, XTextProperty* text_prop_return, Atom property);
384 XVisualInfo* XGetVisualInfo (Display* display, long vinfo_mask, XVisualInfo* vinfo_template, int* nitems_return);
385 Status XGetWMClientMachine (Display* display, Window w, XTextProperty* text_prop_return);
386 XWMHints *XGetWMHints (Display* display, Window w);
387 Status XGetWMIconName (Display* display, Window w, XTextProperty* text_prop_return);
388 Status XGetWMName (Display* display, Window w, XTextProperty* text_prop_return);
389 Status XGetWMNormalHints (Display* display, Window w, XSizeHints* hints_return, long* supplied_return);
390 Status XGetWMSizeHints (Display* display, Window w, XSizeHints* hints_return, long* supplied_return, Atom property);
391 Status XGetZoomHints (Display* display, Window w, XSizeHints* zhints_return);
392 int XIntersectRegion (XRegion sra, XRegion srb, XRegion dr_return);
393 void XConvertCase (KeySym sym, KeySym* lower, KeySym* upper);
394 int XLookupString (XKeyEvent* event_struct, char* buffer_return, int bytes_buffer, KeySym* keysym_return, XComposeStatus* status_in_out);
395 Status XMatchVisualInfo (Display* display, int screen, int depth, int cclass, XVisualInfo* vinfo_return);
396 int XOffsetRegion (XRegion r, int dx, int dy);
397 Bool XPointInRegion (XRegion r, int x, int y);
398 XRegion XPolygonRegion (iv.x11.xlib.XPoint* points, int n, int fill_rule);
399 int XRectInRegion (XRegion r, int x, int y, uint width, uint height);
400 int XSaveContext (Display* display, XID rid, XContext context, char* data);
401 int XSetClassHint (Display* display, Window w, XClassHint* class_hints);
402 int XSetIconSizes (Display* display, Window w, XIconSize* size_list, int count);
403 int XSetNormalHints (Display* display, Window w, XSizeHints* hints);
404 void XSetRGBColormaps (Display* display, Window w, XStandardColormap* stdcmaps, int count, Atom property);
405 int XSetSizeHints (Display* display, Window w, XSizeHints* hints, Atom property);
406 int XSetStandardProperties (Display* display, Window w, const(char)* window_name, const(char)* icon_name, Pixmap icon_pixmap, char** argv, int argc, XSizeHints* hints);
407 void XSetTextProperty (Display* display, Window w, XTextProperty* text_prop, Atom property);
408 void XSetWMClientMachine (Display* display, Window w, XTextProperty* text_prop);
409 int XSetWMHints (Display* display, Window w, XWMHints* wm_hints);
410 void XSetWMIconName (Display* display, Window w, XTextProperty* text_prop);
411 void XSetWMName (Display* display, Window w, XTextProperty* text_prop);
412 void XSetWMNormalHints (Display* display, Window w, XSizeHints* hints);
413 void XSetWMProperties (Display* display, Window w, XTextProperty* window_name, XTextProperty* icon_name, char** argv, int argc, XSizeHints* normal_hints, XWMHints* wm_hints, XClassHint* class_hints);
414 void XmbSetWMProperties (Display* display, Window w, const(char)* window_name, const(char)* icon_name, char** argv, int argc, XSizeHints* normal_hints, XWMHints* wm_hints, XClassHint* class_hints);
415 void Xutf8SetWMProperties (Display* display, Window w, const(char)* window_name, const(char)* icon_name, char** argv, int argc, XSizeHints* normal_hints, XWMHints* wm_hints, XClassHint* class_hints);
416 void XSetWMSizeHints (Display* display, Window w, XSizeHints* hints, Atom property);
417 int XSetRegion (Display* display, GC gc, XRegion r);
418 void XSetStandardColormap (Display* display, Window w, XStandardColormap* colormap, Atom property);
419 int XSetZoomHints (Display* display, Window w, XSizeHints* zhints);
420 int XShrinkRegion (XRegion r, int dx, int dy);
421 Status XStringListToTextProperty (char** list, int count, XTextProperty* text_prop_return);
422 int XSubtractRegion (XRegion sra, XRegion srb, XRegion dr_return);
423 int XmbTextListToTextProperty (Display* display, char** list, int count, XICCEncodingStyle style, XTextProperty* text_prop_return);
424 int XwcTextListToTextProperty (Display* display, wchar_t** list, int count, XICCEncodingStyle style, XTextProperty* text_prop_return);
425 int Xutf8TextListToTextProperty (Display* display, char** list, int count, XICCEncodingStyle style, XTextProperty* text_prop_return);
426 void XwcFreeStringList (wchar_t** list);
427 Status XTextPropertyToStringList (XTextProperty* text_prop, char*** list_return, int* count_return);
428 int XmbTextPropertyToTextList (Display* display, const XTextProperty* text_prop, char*** list_return, int* count_return);
429 int XwcTextPropertyToTextList (Display* display, const(XTextProperty)* text_prop, wchar_t*** list_return, int* count_return);
430 int Xutf8TextPropertyToTextList (Display* display, const(XTextProperty)* text_prop, char*** list_return, int* count_return);
431 int XUnionRectWithRegion (XRectangle* rectangle, XRegion src_region, XRegion dest_region_return);
432 int XUnionRegion (XRegion sra, XRegion srb, XRegion dr_return);
433 int XWMGeometry (Display* display, int screen_number, char* user_geometry, char* default_geometry, uint border_width,
434 XSizeHints* hints, int* x_return, int* y_return, int* width_return, int* height_return, int* gravity_return);
435 int XXorRegion (XRegion sra, XRegion srb, XRegion dr_return);