00001 #region --- License ---
00002
00003
00004
00005
00006
00007 #endregion
00008
00009 using System;
00010 using System.Collections.Generic;
00011 using System.Text;
00012 using System.Runtime.InteropServices;
00013
00014 namespace OpenTK.Platform.X11
00015 {
00016 #region Types
00017
00018
00019 using Window = System.IntPtr;
00020 using Drawable = System.IntPtr;
00021 using Font = System.IntPtr;
00022 using Pixmap = System.IntPtr;
00023 using Cursor = System.IntPtr;
00024 using Colormap = System.IntPtr;
00025 using GContext = System.IntPtr;
00026 using KeySym = System.IntPtr;
00027 using Mask = System.IntPtr;
00028 using Atom = System.IntPtr;
00029 using VisualID = System.IntPtr;
00030 using Time = System.UInt32;
00031 using KeyCode = System.Byte;
00032
00033 using Display = System.IntPtr;
00034 using XPointer = System.IntPtr;
00035
00036
00037 using Bool = System.Boolean;
00038 using XRRScreenConfiguration = System.IntPtr;
00039 using Rotation = System.UInt16;
00040 using Status = System.Int32;
00041 using SizeID = System.UInt16;
00042
00043 #endregion
00044
00045 #region Structs
00046
00047 #endregion
00048
00049 internal static partial class Functions
00050 {
00051 public static readonly object Lock = API.Lock;
00052
00053 [DllImport("libX11", EntryPoint = "XOpenDisplay")]
00054 extern static IntPtr sys_XOpenDisplay(IntPtr display);
00055 public static IntPtr XOpenDisplay(IntPtr display)
00056 {
00057 lock (Lock)
00058 {
00059 return sys_XOpenDisplay(display);
00060 }
00061 }
00062
00063 [DllImport("libX11", EntryPoint = "XCloseDisplay")]
00064 public extern static int XCloseDisplay(IntPtr display);
00065 [DllImport("libX11", EntryPoint = "XSynchronize")]
00066 public extern static IntPtr XSynchronize(IntPtr display, bool onoff);
00067
00068
00069
00070 [DllImport("libX11", EntryPoint = "XCreateWindow")]
00071 public extern static IntPtr XCreateWindow(IntPtr display, IntPtr parent, int x, int y, int width, int height, int border_width, int depth, int xclass, IntPtr visual, IntPtr valuemask, ref XSetWindowAttributes attributes);
00072
00073 [DllImport("libX11", EntryPoint = "XCreateSimpleWindow")]
00074 public extern static IntPtr XCreateSimpleWindow(IntPtr display, IntPtr parent, int x, int y, int width, int height, int border_width, UIntPtr border, UIntPtr background);
00075 [DllImport("libX11", EntryPoint = "XCreateSimpleWindow")]
00076 public extern static IntPtr XCreateSimpleWindow(IntPtr display, IntPtr parent, int x, int y, int width, int height, int border_width, IntPtr border, IntPtr background);
00077
00078 [DllImport("libX11", EntryPoint = "XMapWindow")]
00079 public extern static int XMapWindow(IntPtr display, IntPtr window);
00080 [DllImport("libX11", EntryPoint = "XUnmapWindow")]
00081 public extern static int XUnmapWindow(IntPtr display, IntPtr window);
00082 [DllImport("libX11", EntryPoint = "XMapSubwindows")]
00083 public extern static int XMapSubindows(IntPtr display, IntPtr window);
00084 [DllImport("libX11", EntryPoint = "XUnmapSubwindows")]
00085 public extern static int XUnmapSubwindows(IntPtr display, IntPtr window);
00086 [DllImport("libX11", EntryPoint = "XRootWindow")]
00087 public extern static IntPtr XRootWindow(IntPtr display, int screen_number);
00088
00089 [DllImport("libX11", EntryPoint = "XNextEvent")]
00090 public extern static IntPtr XNextEvent(IntPtr display, ref XEvent xevent);
00091 [DllImport("libX11")]
00092 public extern static Bool XWindowEvent(Display display, Window w, EventMask event_mask, ref XEvent event_return);
00093 [DllImport("libX11")]
00094 public extern static Bool XCheckWindowEvent(Display display, Window w, EventMask event_mask, ref XEvent event_return);
00095 [DllImport("libX11")]
00096 public extern static Bool XCheckTypedWindowEvent(Display display, Window w, XEventName event_type, ref XEvent event_return);
00097
00098 [DllImport("libX11")]
00099 public extern static int XConnectionNumber(IntPtr diplay);
00100 [DllImport("libX11")]
00101 public extern static int XPending(IntPtr diplay);
00102 [DllImport("libX11", EntryPoint = "XSelectInput")]
00103 public extern static IntPtr XSelectInput(IntPtr display, IntPtr window, IntPtr mask);
00104
00105 [DllImport("libX11", EntryPoint = "XDestroyWindow")]
00106 public extern static int XDestroyWindow(IntPtr display, IntPtr window);
00107
00108 [DllImport("libX11", EntryPoint = "XReparentWindow")]
00109 public extern static int XReparentWindow(IntPtr display, IntPtr window, IntPtr parent, int x, int y);
00110
00111 [DllImport("libX11", EntryPoint = "XMoveResizeWindow")]
00112 public extern static int XMoveResizeWindow(IntPtr display, IntPtr window, int x, int y, int width, int height);
00113
00114
00115 [DllImport("libX11", EntryPoint = "XResizeWindow")]
00116 public extern static int XMoveWindow(IntPtr display, IntPtr w, int x, int y);
00117
00118 [DllImport("libX11", EntryPoint = "XResizeWindow")]
00119 public extern static int XResizeWindow(IntPtr display, IntPtr window, int width, int height);
00120
00121 [DllImport("libX11", EntryPoint = "XGetWindowAttributes")]
00122 public extern static int XGetWindowAttributes(IntPtr display, IntPtr window, ref XWindowAttributes attributes);
00123
00124 [DllImport("libX11", EntryPoint = "XFlush")]
00125 public extern static int XFlush(IntPtr display);
00126
00127 [DllImport("libX11", EntryPoint = "XSetWMName")]
00128 public extern static int XSetWMName(IntPtr display, IntPtr window, ref XTextProperty text_prop);
00129
00130 [DllImport("libX11", EntryPoint = "XStoreName")]
00131 public extern static int XStoreName(IntPtr display, IntPtr window, string window_name);
00132
00133 [DllImport("libX11", EntryPoint = "XFetchName")]
00134 public extern static int XFetchName(IntPtr display, IntPtr window, ref IntPtr window_name);
00135
00136 [DllImport("libX11", EntryPoint = "XSendEvent")]
00137 public extern static int XSendEvent(IntPtr display, IntPtr window, bool propagate, IntPtr event_mask, ref XEvent send_event);
00138
00139 public static int XSendEvent(IntPtr display, IntPtr window, bool propagate, EventMask event_mask, ref XEvent send_event)
00140 {
00141 return XSendEvent(display, window, propagate, new IntPtr((int)event_mask), ref send_event);
00142 }
00143
00144 [DllImport("libX11", EntryPoint = "XQueryTree")]
00145 public extern static int XQueryTree(IntPtr display, IntPtr window, out IntPtr root_return, out IntPtr parent_return, out IntPtr children_return, out int nchildren_return);
00146
00147 [DllImport("libX11", EntryPoint = "XFree")]
00148 public extern static int XFree(IntPtr data);
00149
00150 [DllImport("libX11", EntryPoint = "XRaiseWindow")]
00151 public extern static int XRaiseWindow(IntPtr display, IntPtr window);
00152
00153 [DllImport("libX11", EntryPoint = "XLowerWindow")]
00154 public extern static uint XLowerWindow(IntPtr display, IntPtr window);
00155
00156 [DllImport("libX11", EntryPoint = "XConfigureWindow")]
00157 public extern static uint XConfigureWindow(IntPtr display, IntPtr window, ChangeWindowAttributes value_mask, ref XWindowChanges values);
00158
00159 [DllImport("libX11", EntryPoint = "XInternAtom")]
00160 public extern static IntPtr XInternAtom(IntPtr display, string atom_name, bool only_if_exists);
00161
00162 [DllImport("libX11", EntryPoint = "XInternAtoms")]
00163 public extern static int XInternAtoms(IntPtr display, string[] atom_names, int atom_count, bool only_if_exists, IntPtr[] atoms);
00164
00165 [DllImport("libX11", EntryPoint = "XSetWMProtocols")]
00166 public extern static int XSetWMProtocols(IntPtr display, IntPtr window, IntPtr[] protocols, int count);
00167
00168 [DllImport("libX11", EntryPoint = "XGrabPointer")]
00169 public extern static int XGrabPointer(IntPtr display, IntPtr window, bool owner_events, EventMask event_mask, GrabMode pointer_mode, GrabMode keyboard_mode, IntPtr confine_to, IntPtr cursor, IntPtr timestamp);
00170
00171 [DllImport("libX11", EntryPoint = "XUngrabPointer")]
00172 public extern static int XUngrabPointer(IntPtr display, IntPtr timestamp);
00173
00174 [DllImport("libX11", EntryPoint = "XQueryPointer")]
00175 public extern static bool XQueryPointer(IntPtr display, IntPtr window, out IntPtr root, out IntPtr child, out int root_x, out int root_y, out int win_x, out int win_y, out int keys_buttons);
00176
00177 [DllImport("libX11", EntryPoint = "XTranslateCoordinates")]
00178 public extern static bool XTranslateCoordinates(IntPtr display, IntPtr src_w, IntPtr dest_w, int src_x, int src_y, out int intdest_x_return, out int dest_y_return, out IntPtr child_return);
00179
00180 [DllImport("libX11", EntryPoint = "XGetGeometry")]
00181 public extern static bool XGetGeometry(IntPtr display, IntPtr window, out IntPtr root, out int x, out int y, out int width, out int height, out int border_width, out int depth);
00182
00183 [DllImport("libX11", EntryPoint = "XGetGeometry")]
00184 public extern static bool XGetGeometry(IntPtr display, IntPtr window, IntPtr root, out int x, out int y, out int width, out int height, IntPtr border_width, IntPtr depth);
00185
00186 [DllImport("libX11", EntryPoint = "XGetGeometry")]
00187 public extern static bool XGetGeometry(IntPtr display, IntPtr window, IntPtr root, out int x, out int y, IntPtr width, IntPtr height, IntPtr border_width, IntPtr depth);
00188
00189 [DllImport("libX11", EntryPoint = "XGetGeometry")]
00190 public extern static bool XGetGeometry(IntPtr display, IntPtr window, IntPtr root, IntPtr x, IntPtr y, out int width, out int height, IntPtr border_width, IntPtr depth);
00191
00192 [DllImport("libX11", EntryPoint = "XWarpPointer")]
00193 public extern static uint XWarpPointer(IntPtr display, IntPtr src_w, IntPtr dest_w, int src_x, int src_y, uint src_width, uint src_height, int dest_x, int dest_y);
00194
00195 [DllImport("libX11", EntryPoint = "XClearWindow")]
00196 public extern static int XClearWindow(IntPtr display, IntPtr window);
00197
00198 [DllImport("libX11", EntryPoint = "XClearArea")]
00199 public extern static int XClearArea(IntPtr display, IntPtr window, int x, int y, int width, int height, bool exposures);
00200
00201
00202 [DllImport("libX11", EntryPoint = "XDefaultScreenOfDisplay")]
00203 public extern static IntPtr XDefaultScreenOfDisplay(IntPtr display);
00204
00205 [DllImport("libX11", EntryPoint = "XScreenNumberOfScreen")]
00206 public extern static int XScreenNumberOfScreen(IntPtr display, IntPtr Screen);
00207
00208 [DllImport("libX11", EntryPoint = "XDefaultVisual")]
00209 public extern static IntPtr XDefaultVisual(IntPtr display, int screen_number);
00210
00211 [DllImport("libX11", EntryPoint = "XDefaultDepth")]
00212 public extern static uint XDefaultDepth(IntPtr display, int screen_number);
00213
00214 [DllImport("libX11", EntryPoint = "XDefaultScreen")]
00215 public extern static int XDefaultScreen(IntPtr display);
00216
00217 [DllImport("libX11", EntryPoint = "XDefaultColormap")]
00218 public extern static IntPtr XDefaultColormap(IntPtr display, int screen_number);
00219
00220 [DllImport("libX11", EntryPoint = "XLookupColor")]
00221 public extern static int XLookupColor(IntPtr display, IntPtr Colormap, string Coloranem, ref XColor exact_def_color, ref XColor screen_def_color);
00222
00223 [DllImport("libX11", EntryPoint = "XAllocColor")]
00224 public extern static int XAllocColor(IntPtr display, IntPtr Colormap, ref XColor colorcell_def);
00225
00226 [DllImport("libX11", EntryPoint = "XSetTransientForHint")]
00227 public extern static int XSetTransientForHint(IntPtr display, IntPtr window, IntPtr prop_window);
00228
00229 [DllImport("libX11", EntryPoint = "XChangeProperty")]
00230 public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, ref MotifWmHints data, int nelements);
00231
00232 [DllImport("libX11", EntryPoint = "XChangeProperty")]
00233 public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, ref uint value, int nelements);
00234 [DllImport("libX11", EntryPoint = "XChangeProperty")]
00235 public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, ref int value, int nelements);
00236
00237 [DllImport("libX11", EntryPoint = "XChangeProperty")]
00238 public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, ref IntPtr value, int nelements);
00239
00240 [DllImport("libX11", EntryPoint = "XChangeProperty")]
00241 public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, uint[] data, int nelements);
00242
00243 [DllImport("libX11", EntryPoint = "XChangeProperty")]
00244 public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, int[] data, int nelements);
00245
00246 [DllImport("libX11", EntryPoint = "XChangeProperty")]
00247 public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, IntPtr[] data, int nelements);
00248
00249 [DllImport("libX11", EntryPoint = "XChangeProperty")]
00250 public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, IntPtr atoms, int nelements);
00251
00252 [DllImport("libX11", EntryPoint = "XChangeProperty", CharSet = CharSet.Ansi)]
00253 public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, string text, int text_length);
00254
00255 [DllImport("libX11", EntryPoint = "XDeleteProperty")]
00256 public extern static int XDeleteProperty(IntPtr display, IntPtr window, IntPtr property);
00257
00258
00259 [DllImport("libX11", EntryPoint = "XCreateGC")]
00260 public extern static IntPtr XCreateGC(IntPtr display, IntPtr window, IntPtr valuemask, XGCValues[] values);
00261
00262 [DllImport("libX11", EntryPoint = "XFreeGC")]
00263 public extern static int XFreeGC(IntPtr display, IntPtr gc);
00264
00265 [DllImport("libX11", EntryPoint = "XSetFunction")]
00266 public extern static int XSetFunction(IntPtr display, IntPtr gc, GXFunction function);
00267
00268 [DllImport("libX11", EntryPoint = "XSetLineAttributes")]
00269 public extern static int XSetLineAttributes(IntPtr display, IntPtr gc, int line_width, GCLineStyle line_style, GCCapStyle cap_style, GCJoinStyle join_style);
00270
00271 [DllImport("libX11", EntryPoint = "XDrawLine")]
00272 public extern static int XDrawLine(IntPtr display, IntPtr drawable, IntPtr gc, int x1, int y1, int x2, int y2);
00273
00274 [DllImport("libX11", EntryPoint = "XDrawRectangle")]
00275 public extern static int XDrawRectangle(IntPtr display, IntPtr drawable, IntPtr gc, int x1, int y1, int width, int height);
00276
00277 [DllImport("libX11", EntryPoint = "XFillRectangle")]
00278 public extern static int XFillRectangle(IntPtr display, IntPtr drawable, IntPtr gc, int x1, int y1, int width, int height);
00279
00280 [DllImport("libX11", EntryPoint = "XSetWindowBackground")]
00281 public extern static int XSetWindowBackground(IntPtr display, IntPtr window, IntPtr background);
00282
00283 [DllImport("libX11", EntryPoint = "XCopyArea")]
00284 public extern static int XCopyArea(IntPtr display, IntPtr src, IntPtr dest, IntPtr gc, int src_x, int src_y, int width, int height, int dest_x, int dest_y);
00285
00286 [DllImport("libX11", EntryPoint = "XGetWindowProperty")]
00287 public extern static int XGetWindowProperty(IntPtr display, IntPtr window, IntPtr atom, IntPtr long_offset, IntPtr long_length, bool delete, IntPtr req_type, out IntPtr actual_type, out int actual_format, out IntPtr nitems, out IntPtr bytes_after, ref IntPtr prop);
00288
00289 [DllImport("libX11", EntryPoint = "XSetInputFocus")]
00290 public extern static int XSetInputFocus(IntPtr display, IntPtr window, RevertTo revert_to, IntPtr time);
00291
00292 [DllImport("libX11", EntryPoint = "XIconifyWindow")]
00293 public extern static int XIconifyWindow(IntPtr display, IntPtr window, int screen_number);
00294
00295 [DllImport("libX11", EntryPoint = "XDefineCursor")]
00296 public extern static int XDefineCursor(IntPtr display, IntPtr window, IntPtr cursor);
00297
00298 [DllImport("libX11", EntryPoint = "XUndefineCursor")]
00299 public extern static int XUndefineCursor(IntPtr display, IntPtr window);
00300
00301 [DllImport("libX11", EntryPoint = "XFreeCursor")]
00302 public extern static int XFreeCursor(IntPtr display, IntPtr cursor);
00303
00304 [DllImport("libX11", EntryPoint = "XCreateFontCursor")]
00305 public extern static IntPtr XCreateFontCursor(IntPtr display, CursorFontShape shape);
00306
00307 [DllImport("libX11", EntryPoint = "XCreatePixmapCursor")]
00308 public extern static IntPtr XCreatePixmapCursor(IntPtr display, IntPtr source, IntPtr mask, ref XColor foreground_color, ref XColor background_color, int x_hot, int y_hot);
00309
00310 [DllImport("libX11", EntryPoint = "XCreatePixmapFromBitmapData")]
00311 public extern static IntPtr XCreatePixmapFromBitmapData(IntPtr display, IntPtr drawable, byte[] data, int width, int height, IntPtr fg, IntPtr bg, int depth);
00312
00313 [DllImport("libX11", EntryPoint = "XCreatePixmap")]
00314 public extern static IntPtr XCreatePixmap(IntPtr display, IntPtr d, int width, int height, int depth);
00315
00316 [DllImport("libX11", EntryPoint = "XFreePixmap")]
00317 public extern static IntPtr XFreePixmap(IntPtr display, IntPtr pixmap);
00318
00319 [DllImport("libX11", EntryPoint = "XQueryBestCursor")]
00320 public extern static int XQueryBestCursor(IntPtr display, IntPtr drawable, int width, int height, out int best_width, out int best_height);
00321
00322 [DllImport("libX11", EntryPoint = "XQueryExtension")]
00323 public extern static int XQueryExtension(IntPtr display, string extension_name, ref int major, ref int first_event, ref int first_error);
00324
00325 [DllImport("libX11", EntryPoint = "XWhitePixel")]
00326 public extern static IntPtr XWhitePixel(IntPtr display, int screen_no);
00327
00328 [DllImport("libX11", EntryPoint = "XBlackPixel")]
00329 public extern static IntPtr XBlackPixel(IntPtr display, int screen_no);
00330
00331 [DllImport("libX11", EntryPoint = "XGrabServer")]
00332 public extern static void XGrabServer(IntPtr display);
00333
00334 [DllImport("libX11", EntryPoint = "XUngrabServer")]
00335 public extern static void XUngrabServer(IntPtr display);
00336
00337 [DllImport("libX11", EntryPoint = "XGetWMNormalHints")]
00338 public extern static int XGetWMNormalHints(IntPtr display, IntPtr window, ref XSizeHints hints, out IntPtr supplied_return);
00339
00340 [DllImport("libX11", EntryPoint = "XSetWMNormalHints")]
00341 public extern static void XSetWMNormalHints(IntPtr display, IntPtr window, ref XSizeHints hints);
00342
00343 [DllImport("libX11", EntryPoint = "XSetZoomHints")]
00344 public extern static void XSetZoomHints(IntPtr display, IntPtr window, ref XSizeHints hints);
00345
00346 [DllImport("libX11")]
00347 public static extern IntPtr XGetWMHints(Display display, Window w);
00348
00349 [DllImport("libX11")]
00350 public static extern void XSetWMHints(Display display, Window w, ref XWMHints wmhints);
00351
00352 [DllImport("libX11")]
00353 public static extern IntPtr XAllocWMHints();
00354
00355 [DllImport("libX11", EntryPoint = "XGetIconSizes")]
00356 public extern static int XGetIconSizes(IntPtr display, IntPtr window, out IntPtr size_list, out int count);
00357
00358 [DllImport("libX11", EntryPoint = "XSetErrorHandler")]
00359 public extern static IntPtr XSetErrorHandler(XErrorHandler error_handler);
00360
00361 [DllImport("libX11", EntryPoint = "XGetErrorText")]
00362 public extern static IntPtr XGetErrorText(IntPtr display, byte code, StringBuilder buffer, int length);
00363
00364 [DllImport("libX11", EntryPoint = "XInitThreads")]
00365 public extern static int XInitThreads();
00366
00367 [DllImport("libX11", EntryPoint = "XConvertSelection")]
00368 public extern static int XConvertSelection(IntPtr display, IntPtr selection, IntPtr target, IntPtr property, IntPtr requestor, IntPtr time);
00369
00370 [DllImport("libX11", EntryPoint = "XGetSelectionOwner")]
00371 public extern static IntPtr XGetSelectionOwner(IntPtr display, IntPtr selection);
00372
00373 [DllImport("libX11", EntryPoint = "XSetSelectionOwner")]
00374 public extern static int XSetSelectionOwner(IntPtr display, IntPtr selection, IntPtr owner, IntPtr time);
00375
00376 [DllImport("libX11", EntryPoint = "XSetPlaneMask")]
00377 public extern static int XSetPlaneMask(IntPtr display, IntPtr gc, IntPtr mask);
00378
00379 [DllImport("libX11", EntryPoint = "XSetForeground")]
00380 public extern static int XSetForeground(IntPtr display, IntPtr gc, UIntPtr foreground);
00381 [DllImport("libX11", EntryPoint = "XSetForeground")]
00382 public extern static int XSetForeground(IntPtr display, IntPtr gc, IntPtr foreground);
00383
00384 [DllImport("libX11", EntryPoint = "XSetBackground")]
00385 public extern static int XSetBackground(IntPtr display, IntPtr gc, UIntPtr background);
00386 [DllImport("libX11", EntryPoint = "XSetBackground")]
00387 public extern static int XSetBackground(IntPtr display, IntPtr gc, IntPtr background);
00388
00389 [DllImport("libX11", EntryPoint = "XBell")]
00390 public extern static int XBell(IntPtr display, int percent);
00391
00392 [DllImport("libX11", EntryPoint = "XChangeActivePointerGrab")]
00393 public extern static int XChangeActivePointerGrab(IntPtr display, EventMask event_mask, IntPtr cursor, IntPtr time);
00394
00395 [DllImport("libX11", EntryPoint = "XFilterEvent")]
00396 public extern static bool XFilterEvent(ref XEvent xevent, IntPtr window);
00397
00398 [DllImport("libX11")]
00399 public extern static bool XkbSetDetectableAutoRepeat(IntPtr display, bool detectable, out bool supported);
00400
00401 [DllImport("libX11")]
00402 public extern static void XPeekEvent(IntPtr display, ref XEvent xevent);
00403
00404 [DllImport("libX11", EntryPoint = "XGetVisualInfo")]
00405 static extern IntPtr XGetVisualInfoInternal(IntPtr display, IntPtr vinfo_mask, ref XVisualInfo template, out int nitems);
00406
00407 public static IntPtr XGetVisualInfo(IntPtr display, XVisualInfoMask vinfo_mask, ref XVisualInfo template, out int nitems)
00408 {
00409 return XGetVisualInfoInternal(display, (IntPtr)(int)vinfo_mask, ref template, out nitems);
00410 }
00411
00412 [DllImport("libX11")]
00413 public static extern IntPtr XCreateColormap(Display display, Window window, IntPtr visual, int alloc);
00414
00415 [DllImport("libX11")]
00416 public static extern void XLockDisplay(Display display);
00417
00418 [DllImport("libX11")]
00419 public static extern void XUnlockDisplay(Display display);
00420
00421 [DllImport("libX11")]
00422 public static extern Status XGetTransientForHint(Display display, Window w, out Window prop_window_return);
00423
00424 [DllImport("libX11")]
00425 public static extern void XSync(Display display, bool discard);
00426
00427 [DllImport("libX11")]
00428 public static extern void XAutoRepeatOff(IntPtr display);
00429
00430 [DllImport("libX11")]
00431 public static extern void XAutoRepeatOn(IntPtr display);
00432
00433 [DllImport("libX11")]
00434 public static extern IntPtr XDefaultRootWindow(IntPtr display);
00435
00436 [DllImport("libX11")]
00437 public static extern int XBitmapBitOrder(Display display);
00438
00439 [DllImport("libX11")]
00440 public static extern IntPtr XCreateImage(Display display, IntPtr visual,
00441 uint depth, ImageFormat format, int offset, byte[] data, uint width, uint height,
00442 int bitmap_pad, int bytes_per_line);
00443
00444 [DllImport("libX11")]
00445 public static extern IntPtr XCreateImage(Display display, IntPtr visual,
00446 uint depth, ImageFormat format, int offset, IntPtr data, uint width, uint height,
00447 int bitmap_pad, int bytes_per_line);
00448
00449 [DllImport("libX11")]
00450 public static extern void XPutImage(Display display, IntPtr drawable,
00451 IntPtr gc, IntPtr image, int src_x, int src_y, int dest_x, int dest_y, uint width, uint height);
00452
00453 [DllImport("libX11")]
00454 public static extern int XLookupString(ref XKeyEvent event_struct, [Out] byte[] buffer_return,
00455 int bytes_buffer, [Out] KeySym[] keysym_return, IntPtr status_in_out);
00456
00457 [DllImport("libX11")]
00458 public static extern int XRefreshKeyboardMapping(ref XMappingEvent event_map);
00459
00460 static readonly IntPtr CopyFromParent = IntPtr.Zero;
00461
00462 public static void SendNetWMMessage(X11WindowInfo window, IntPtr message_type, IntPtr l0, IntPtr l1, IntPtr l2)
00463 {
00464 XEvent xev;
00465
00466 xev = new XEvent();
00467 xev.ClientMessageEvent.type = XEventName.ClientMessage;
00468 xev.ClientMessageEvent.send_event = true;
00469 xev.ClientMessageEvent.window = window.WindowHandle;
00470 xev.ClientMessageEvent.message_type = message_type;
00471 xev.ClientMessageEvent.format = 32;
00472 xev.ClientMessageEvent.ptr1 = l0;
00473 xev.ClientMessageEvent.ptr2 = l1;
00474 xev.ClientMessageEvent.ptr3 = l2;
00475
00476 XSendEvent(window.Display, window.RootWindow, false,
00477 new IntPtr((int)(EventMask.SubstructureRedirectMask | EventMask.SubstructureNotifyMask)),
00478 ref xev);
00479 }
00480
00481 public static void SendNetClientMessage(X11WindowInfo window, IntPtr message_type,
00482 IntPtr l0, IntPtr l1, IntPtr l2)
00483 {
00484 XEvent xev;
00485
00486 xev = new XEvent();
00487 xev.ClientMessageEvent.type = XEventName.ClientMessage;
00488 xev.ClientMessageEvent.send_event = true;
00489 xev.ClientMessageEvent.window = window.WindowHandle;
00490 xev.ClientMessageEvent.message_type = message_type;
00491 xev.ClientMessageEvent.format = 32;
00492 xev.ClientMessageEvent.ptr1 = l0;
00493 xev.ClientMessageEvent.ptr2 = l1;
00494 xev.ClientMessageEvent.ptr3 = l2;
00495
00496 XSendEvent(window.Display, window.WindowHandle, false, new IntPtr((int)EventMask.NoEventMask), ref xev);
00497 }
00498
00499 [StructLayout(LayoutKind.Sequential, Pack = 1)]
00500 struct Pixel
00501 {
00502 public byte A, R, G, B;
00503 public Pixel(byte a, byte r, byte g, byte b)
00504 {
00505 A= a;
00506 R = r;
00507 G = g;
00508 B = b;
00509 }
00510 public static implicit operator Pixel(int argb)
00511 {
00512 return new Pixel(
00513 (byte)((argb >> 24) & 0xFF),
00514 (byte)((argb >> 16) & 0xFF),
00515 (byte)((argb >> 8) & 0xFF),
00516 (byte)(argb & 0xFF));
00517 }
00518 }
00519 public static IntPtr CreatePixmapFromImage(Display display, System.Drawing.Bitmap image)
00520 {
00521 int width = image.Width;
00522 int height = image.Height;
00523 int size = width * height;
00524
00525 System.Drawing.Imaging.BitmapData data = image.LockBits(new System.Drawing.Rectangle(0, 0, width, height),
00526 System.Drawing.Imaging.ImageLockMode.ReadOnly,
00527 System.Drawing.Imaging.PixelFormat.Format32bppArgb);
00528
00529 IntPtr ximage = XCreateImage(display, CopyFromParent, 24, ImageFormat.ZPixmap,
00530 0, data.Scan0, (uint)width, (uint)height, 32, 0);
00531 IntPtr pixmap = XCreatePixmap(display, XDefaultRootWindow(display),
00532 width, height, 24);
00533 IntPtr gc = XCreateGC(display, pixmap, IntPtr.Zero, null);
00534
00535 XPutImage(display, pixmap, gc, ximage, 0, 0, 0, 0, (uint)width, (uint)height);
00536
00537 XFreeGC(display, gc);
00538 image.UnlockBits(data);
00539
00540 return pixmap;
00541 }
00542
00543 public static IntPtr CreateMaskFromImage(Display display, System.Drawing.Bitmap image)
00544 {
00545 int width = image.Width;
00546 int height = image.Height;
00547 int stride = (width + 7) >> 3;
00548 byte[] mask = new byte[stride * height];
00549 bool msbfirst = (XBitmapBitOrder(display) == 1);
00550
00551 for (int y = 0; y < height; ++y)
00552 {
00553 for (int x = 0; x < width; ++x)
00554 {
00555 byte bit = (byte) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
00556 int offset = y * stride + (x >> 3);
00557
00558 if (image.GetPixel(x, y).A >= 128)
00559 mask[offset] |= bit;
00560 }
00561 }
00562
00563 Pixmap pixmap = XCreatePixmapFromBitmapData(display, XDefaultRootWindow(display),
00564 mask, width, height, new IntPtr(1), IntPtr.Zero, 1);
00565
00566 return pixmap;
00567 }
00568 }
00569 }