Subversion Repositories AndroidProjects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1452 chris 1
#region --- License ---
2
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
3
 * Contributions from Erik Ylvisaker
4
 * See license.txt for license info
5
 */
6
#endregion
7
 
8
using System;
9
using System.Collections.Generic;
10
using System.Text;
11
using System.Runtime.InteropServices;
12
using System.Diagnostics;
13
 
14
#pragma warning disable 3019    // CLS-compliance checking
15
#pragma warning disable 0649    // struct members not explicitly initialized
16
#pragma warning disable 0169    // field / method is never used.
17
#pragma warning disable 0414    // field assigned but never used.
18
 
19
namespace OpenTK.Platform.X11
20
{
21
    #region Types
22
 
23
    // using XID = System.Int32;
24
    using Window = System.IntPtr;
25
    using Drawable = System.IntPtr;
26
    using Font = System.IntPtr;
27
    using Pixmap = System.IntPtr;
28
    using Cursor = System.IntPtr;
29
    using Colormap = System.IntPtr;
30
    using GContext = System.IntPtr;
31
    using KeySym = System.IntPtr;
32
    using Mask = System.IntPtr;
33
    using Atom = System.IntPtr;
34
    using VisualID = System.IntPtr;
35
    using Time = System.IntPtr;
36
    using KeyCode = System.Byte;    // Or maybe ushort?
37
 
38
    using Display = System.IntPtr;
39
    using XPointer = System.IntPtr;
40
 
41
    // Randr and Xrandr
42
    using Bool = System.Boolean;
43
    using XRRScreenConfiguration = System.IntPtr; // opaque datatype
44
    using Rotation = System.UInt16;
45
    using Status = System.Int32;
46
    using SizeID = System.UInt16;
47
 
48
    #endregion
49
 
50
    #region internal static class API
51
 
52
    internal static class API
53
    {
54
        #region --- Fields ---
55
 
56
        private const string _dll_name = "libX11";
57
        private const string _dll_name_vid = "libXxf86vm";
58
 
59
        static Display defaultDisplay;
60
        static int defaultScreen;
61
        static Window rootWindow;
62
        static int screenCount;
63
 
64
        internal static Display DefaultDisplay { get { return defaultDisplay; } }
65
        static int DefaultScreen { get { return defaultScreen; } }
66
        //internal static Window RootWindow { get { return rootWindow; } }
67
        internal static int ScreenCount { get { return screenCount; } }
68
 
69
        internal static object Lock = new object();
70
 
71
        #endregion
72
 
73
        static API()
74
        {
75
            int has_threaded_x = Functions.XInitThreads();
76
            Debug.Print("Initializing threaded X11: {0}.", has_threaded_x.ToString());
77
 
78
            defaultDisplay = Functions.XOpenDisplay(IntPtr.Zero);
79
 
80
            if (defaultDisplay == IntPtr.Zero)
81
                throw new PlatformException("Could not establish connection to the X-Server.");
82
 
83
            using (new XLock(defaultDisplay))
84
            {
85
                screenCount = Functions.XScreenCount(DefaultDisplay);
86
            }
87
            Debug.Print("Display connection: {0}, Screen count: {1}", DefaultDisplay, ScreenCount);
88
 
89
            //AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);
90
        }
91
 
92
        static void CurrentDomain_ProcessExit(object sender, EventArgs e)
93
        {
94
            if (defaultDisplay != IntPtr.Zero)
95
            {
96
                Functions.XCloseDisplay(defaultDisplay);
97
                defaultDisplay = IntPtr.Zero;
98
                defaultScreen = 0;
99
                rootWindow = IntPtr.Zero;
100
            }
101
        }
102
 
103
        // Display management
104
        //[DllImport(_dll_name, EntryPoint = "XOpenDisplay")]
105
        //extern public static IntPtr OpenDisplay([MarshalAs(UnmanagedType.LPTStr)] string display_name);
106
 
107
        //[DllImport(_dll_name, EntryPoint = "XCloseDisplay")]
108
        //extern public static void CloseDisplay(Display display);
109
 
110
        //[DllImport(_dll_name, EntryPoint = "XCreateColormap")]
111
        //extern public static IntPtr CreateColormap(Display display, Window window, IntPtr visual, int alloc);
112
 
113
        #region Window handling
114
 
115
        [Obsolete("Use XCreateWindow instead")]
116
        [DllImport(_dll_name, EntryPoint = "XCreateWindow")]
117
        public extern static Window CreateWindow(
118
            Display display,
119
            Window parent,
120
            int x, int y,
121
            //uint width, uint height,
122
            int width, int height,
123
            //uint border_width,
124
            int border_width,
125
            int depth,
126
            //uint @class,
127
            int @class,
128
            IntPtr visual,
129
            [MarshalAs(UnmanagedType.SysUInt)] CreateWindowMask valuemask,
130
            SetWindowAttributes attributes
131
        );
132
 
133
        [DllImport(_dll_name, EntryPoint = "XCreateSimpleWindow")]
134
        public extern static Window CreateSimpleWindow(
135
            Display display,
136
            Window parent,
137
            int x, int y,
138
            int width, int height,
139
            int border_width,
140
            long border,
141
            long background
142
        );
143
 
144
        [DllImport(_dll_name, EntryPoint = "XResizeWindow")]
145
        public extern static int XResizeWindow(Display display, Window window, int width, int height);
146
 
147
        [DllImport(_dll_name, EntryPoint = "XDestroyWindow")]
148
        public extern static void DestroyWindow(Display display, Window window);
149
 
150
        [DllImport(_dll_name, EntryPoint = "XMapWindow")]
151
        extern public static void MapWindow(Display display, Window window);
152
 
153
        [DllImport(_dll_name, EntryPoint = "XMapRaised")]
154
        extern public static void MapRaised(Display display, Window window);
155
 
156
        #endregion
157
 
158
        [DllImport(_dll_name, EntryPoint = "XDefaultVisual")]
159
        extern public static IntPtr DefaultVisual(Display display, int screen_number);
160
 
161
        #region XFree
162
 
163
        /// <summary>
164
        /// Frees the memory used by an X structure. Only use on unmanaged structures!
165
        /// </summary>
166
        /// <param name="buffer">A pointer to the structure that will be freed.</param>
167
        [DllImport(_dll_name, EntryPoint = "XFree")]
168
        extern public static void Free(IntPtr buffer);
169
 
170
        #endregion
171
 
172
        #region Event queue management
173
 
174
        [System.Security.SuppressUnmanagedCodeSecurity]
175
        [DllImport(_dll_name, EntryPoint = "XEventsQueued")]
176
        extern public static int EventsQueued(Display display, int mode);
177
 
178
        [System.Security.SuppressUnmanagedCodeSecurity]
179
        [DllImport(_dll_name, EntryPoint = "XPending")]
180
        extern public static int Pending(Display display);
181
 
182
        //[System.Security.SuppressUnmanagedCodeSecurity]
183
        [DllImport(_dll_name, EntryPoint = "XNextEvent")]
184
        extern public static void NextEvent(
185
            Display display,
186
            [MarshalAs(UnmanagedType.AsAny)][In, Out]object e);
187
 
188
        [DllImport(_dll_name, EntryPoint = "XNextEvent")]
189
        extern public static void NextEvent(Display display, [In, Out] IntPtr e);
190
 
191
        [DllImport(_dll_name, EntryPoint = "XPeekEvent")]
192
        extern public static void PeekEvent(
193
            Display display,
194
            [MarshalAs(UnmanagedType.AsAny)][In, Out]object event_return
195
        );
196
 
197
        [DllImport(_dll_name, EntryPoint = "XPeekEvent")]
198
        extern public static void PeekEvent(Display display, [In, Out]XEvent event_return);
199
 
200
        [DllImport(_dll_name, EntryPoint = "XSendEvent")]
201
        [return: MarshalAs(UnmanagedType.Bool)]
202
        extern public static bool SendEvent(Display display, Window window, bool propagate,
203
            [MarshalAs(UnmanagedType.SysInt)]EventMask event_mask, ref XEvent event_send);
204
 
205
        /// <summary>
206
        /// The XSelectInput() function requests that the X server report the events associated
207
        /// with the specified event mask.
208
        /// </summary>
209
        /// <param name="display">Specifies the connection to the X server.</param>
210
        /// <param name="w">Specifies the window whose events you are interested in.</param>
211
        /// <param name="event_mask">Specifies the event mask.</param>
212
        /// <remarks>
213
        /// Initially, X will not report any of these events.
214
        /// Events are reported relative to a window.
215
        /// If a window is not interested in a device event,
216
        /// it usually propagates to the closest ancestor that is interested,
217
        /// unless the do_not_propagate mask prohibits it.
218
        /// Setting the event-mask attribute of a window overrides any previous call for the same window but not for other clients. Multiple clients can select for the same events on the same window with the following restrictions: 
219
        /// <para>Multiple clients can select events on the same window because their event masks are disjoint. When the X server generates an event, it reports it to all interested clients. </para>
220
        /// <para>Only one client at a time can select CirculateRequest, ConfigureRequest, or MapRequest events, which are associated with the event mask SubstructureRedirectMask. </para>
221
        /// <para>Only one client at a time can select a ResizeRequest event, which is associated with the event mask ResizeRedirectMask. </para>
222
        /// <para>Only one client at a time can select a ButtonPress event, which is associated with the event mask ButtonPressMask. </para>
223
        /// <para>The server reports the event to all interested clients. </para>
224
        /// <para>XSelectInput() can generate a BadWindow error.</para>
225
        /// </remarks>
226
        [DllImport(_dll_name, EntryPoint = "XSelectInput")]
227
        public static extern void SelectInput(Display display, Window w, EventMask event_mask);
228
 
229
        /// <summary>
230
        /// When the predicate procedure finds a match, XCheckIfEvent() copies the matched event into the client-supplied XEvent structure and returns True. (This event is removed from the queue.) If the predicate procedure finds no match, XCheckIfEvent() returns False, and the output buffer will have been flushed. All earlier events stored in the queue are not discarded.
231
        /// </summary>
232
        /// <param name="display">Specifies the connection to the X server.</param>
233
        /// <param name="event_return">Returns a copy of the matched event's associated structure.</param>
234
        /// <param name="predicate">Specifies the procedure that is to be called to determine if the next event in the queue matches what you want</param>
235
        /// <param name="arg">Specifies the user-supplied argument that will be passed to the predicate procedure.</param>
236
        /// <returns>true if the predicate returns true for some event, false otherwise</returns>
237
        [DllImport(_dll_name, EntryPoint = "XCheckIfEvent")]
238
        [return: MarshalAs(UnmanagedType.Bool)]
239
        public static extern bool CheckIfEvent(Display display, ref XEvent event_return,
240
            /*[MarshalAs(UnmanagedType.FunctionPtr)] */ CheckEventPredicate predicate, /*XPointer*/ IntPtr arg);
241
 
242
        [DllImport(_dll_name, EntryPoint = "XIfEvent")]
243
        [return: MarshalAs(UnmanagedType.Bool)]
244
        public static extern bool IfEvent(Display display, ref XEvent event_return,
245
            /*[MarshalAs(UnmanagedType.FunctionPtr)] */ CheckEventPredicate predicate, /*XPointer*/ IntPtr arg);
246
 
247
        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
248
        public delegate bool CheckEventPredicate(Display display, ref XEvent @event, IntPtr arg);
249
 
250
        [DllImport(_dll_name, EntryPoint = "XCheckMaskEvent")]
251
        [return: MarshalAs(UnmanagedType.Bool)]
252
        public static extern bool CheckMaskEvent(Display display, EventMask event_mask, ref XEvent event_return);
253
 
254
        #endregion
255
 
256
        #region Pointer and Keyboard functions
257
 
258
        [DllImport(_dll_name, EntryPoint = "XGrabPointer")]
259
        extern public static ErrorCodes GrabPointer(Display display, IntPtr grab_window,
260
            bool owner_events, int event_mask, GrabMode pointer_mode, GrabMode keyboard_mode,
261
            IntPtr confine_to, IntPtr cursor, int time);
262
 
263
        [DllImport(_dll_name, EntryPoint = "XUngrabPointer")]
264
        extern public static ErrorCodes UngrabPointer(Display display, int time);
265
 
266
        [DllImport(_dll_name, EntryPoint = "XGrabKeyboard")]
267
        extern public static ErrorCodes GrabKeyboard(Display display, IntPtr grab_window,
268
            bool owner_events, GrabMode pointer_mode, GrabMode keyboard_mode, int time);
269
 
270
        [DllImport(_dll_name, EntryPoint = "XUngrabKeyboard")]
271
        extern public static void UngrabKeyboard(Display display, int time);
272
 
273
        /// <summary>
274
        /// The XGetKeyboardMapping() function returns the symbols for the specified number of KeyCodes starting with first_keycode.
275
        /// </summary>
276
        /// <param name="display">Specifies the connection to the X server.</param>
277
        /// <param name="first_keycode">Specifies the first KeyCode that is to be returned.</param>
278
        /// <param name="keycode_count">Specifies the number of KeyCodes that are to be returned</param>
279
        /// <param name="keysyms_per_keycode_return">Returns the number of KeySyms per KeyCode.</param>
280
        /// <returns></returns>
281
        /// <remarks>
282
        /// <para>The value specified in first_keycode must be greater than or equal to min_keycode as returned by XDisplayKeycodes(), or a BadValue error results. In addition, the following expression must be less than or equal to max_keycode as returned by XDisplayKeycodes(): </para>
283
        /// <para>first_keycode + keycode_count - 1 </para>
284
        /// <para>If this is not the case, a BadValue error results. The number of elements in the KeySyms list is: </para>
285
        /// <para>keycode_count * keysyms_per_keycode_return </para>
286
        /// <para>KeySym number N, counting from zero, for KeyCode K has the following index in the list, counting from zero: </para>
287
        /// <para> (K - first_code) * keysyms_per_code_return + N </para>
288
        /// <para>The X server arbitrarily chooses the keysyms_per_keycode_return value to be large enough to report all requested symbols. A special KeySym value of NoSymbol is used to fill in unused elements for individual KeyCodes. To free the storage returned by XGetKeyboardMapping(), use XFree(). </para>
289
        /// <para>XGetKeyboardMapping() can generate a BadValue error.</para>
290
        /// <para>Diagnostics:</para>
291
        /// <para>BadValue:    Some numeric value falls outside the range of values accepted by the request. Unless a specific range is specified for an argument, the full range defined by the argument's type is accepted. Any argument defined as a set of alternatives can generate this error.</para>
292
        /// </remarks>
293
        [DllImport(_dll_name, EntryPoint = "XGetKeyboardMapping")]
294
        public static extern KeySym GetKeyboardMapping(Display display, KeyCode first_keycode, int keycode_count,
295
            ref int keysyms_per_keycode_return);
296
 
297
        /// <summary>
298
        /// The XDisplayKeycodes() function returns the min-keycodes and max-keycodes supported by the specified display.
299
        /// </summary>
300
        /// <param name="display">Specifies the connection to the X server.</param>
301
        /// <param name="min_keycodes_return">Returns the minimum number of KeyCodes</param>
302
        /// <param name="max_keycodes_return">Returns the maximum number of KeyCodes.</param>
303
        /// <remarks> The minimum number of KeyCodes returned is never less than 8, and the maximum number of KeyCodes returned is never greater than 255. Not all KeyCodes in this range are required to have corresponding keys.</remarks>
304
        [DllImport(_dll_name, EntryPoint = "XDisplayKeycodes")]
305
        public static extern void DisplayKeycodes(Display display, ref int min_keycodes_return, ref int max_keycodes_return);
306
 
307
        #endregion
308
 
309
        #region Xf86VidMode internal structures
310
 
311
        [StructLayout(LayoutKind.Sequential)]
312
        internal struct XF86VidModeModeLine
313
        {
314
            short hdisplay;   /* Number of display pixels horizontally */
315
            short hsyncstart; /* Horizontal sync start */
316
            short hsyncend;   /* Horizontal sync end */
317
            short htotal;     /* Total horizontal pixels */
318
            short vdisplay;   /* Number of display pixels vertically */
319
            short vsyncstart; /* Vertical sync start */
320
            short vsyncend;   /* Vertical sync start */
321
            short vtotal;     /* Total vertical pixels */
322
            int flags;      /* Mode flags */
323
            int privsize;   /* Size of private */
324
            IntPtr _private;   /* Server privates */
325
        }
326
 
327
        /// <summary>
328
        /// Specifies an XF86 display mode.
329
        /// </summary>
330
        [StructLayout(LayoutKind.Sequential)]
331
        internal struct XF86VidModeModeInfo
332
        {
333
            /// <summary>
334
            /// Pixel clock.
335
            /// </summary>
336
            public int dotclock;
337
 
338
            /// <summary>
339
            /// Number of display pixels horizontally
340
            /// </summary>
341
            public short hdisplay;
342
 
343
            /// <summary>
344
            /// Horizontal sync start
345
            /// </summary>
346
            public short hsyncstart;
347
 
348
            /// <summary>
349
            /// Horizontal sync end
350
            /// </summary>
351
            public short hsyncend;
352
 
353
            /// <summary>
354
            /// Total horizontal pixel
355
            /// </summary>
356
            public short htotal;
357
 
358
            /// <summary>
359
            /// 
360
            /// </summary>
361
            public short hskew;
362
 
363
            /// <summary>
364
            /// Number of display pixels vertically
365
            /// </summary>
366
            public short vdisplay;
367
 
368
            /// <summary>
369
            /// Vertical sync start
370
            /// </summary>
371
            public short vsyncstart;
372
 
373
            /// <summary>
374
            /// Vertical sync end
375
            /// </summary>
376
            public short vsyncend;
377
 
378
            /// <summary>
379
            /// Total vertical pixels
380
            /// </summary>
381
            public short vtotal;
382
 
383
            /// <summary>
384
            /// 
385
            /// </summary>
386
            public short vskew;
387
 
388
            /// <summary>
389
            /// Mode flags
390
            /// </summary>
391
            public int flags;
392
 
393
            int privsize;   /* Size of private */
394
            IntPtr _private;   /* Server privates */
395
        }
396
 
397
        //Monitor information:
398
        [StructLayout(LayoutKind.Sequential)]
399
        internal struct XF86VidModeMonitor
400
        {
401
            [MarshalAs(UnmanagedType.LPStr)]
402
            string vendor;     /* Name of manufacturer */
403
            [MarshalAs(UnmanagedType.LPStr)]
404
            string model;      /* Model name */
405
            float EMPTY;      /* unused, for backward compatibility */
406
            byte nhsync;     /* Number of horiz sync ranges */
407
            /*XF86VidModeSyncRange* */
408
            IntPtr hsync;/* Horizontal sync ranges */
409
            byte nvsync;     /* Number of vert sync ranges */
410
            /*XF86VidModeSyncRange* */
411
            IntPtr vsync;/* Vertical sync ranges */
412
        }
413
 
414
        [StructLayout(LayoutKind.Sequential)]
415
        internal struct XF86VidModeSyncRange
416
        {
417
            float hi;         /* Top of range */
418
            float lo;         /* Bottom of range */
419
        }
420
 
421
        [StructLayout(LayoutKind.Sequential)]
422
        internal struct XF86VidModeNotifyEvent
423
        {
424
            int type;                      /* of event */
425
            ulong serial;          /* # of last request processed by server */
426
            bool send_event;               /* true if this came from a SendEvent req */
427
            Display display;              /* Display the event was read from */
428
            IntPtr root;                   /* root window of event screen */
429
            int state;                     /* What happened */
430
            int kind;                      /* What happened */
431
            bool forced;                   /* extents of new region */
432
            /* Time */
433
            IntPtr time;                     /* event timestamp */
434
        }
435
 
436
        [StructLayout(LayoutKind.Sequential)]
437
        internal struct XF86VidModeGamma
438
        {
439
            float red;                     /* Red Gamma value */
440
            float green;                   /* Green Gamma value */
441
            float blue;                    /* Blue Gamma value */
442
        }
443
        #endregion
444
 
445
        #region libXxf86vm Functions
446
 
447
        [DllImport(_dll_name_vid)]
448
        extern public static bool XF86VidModeQueryExtension(
449
            Display display,
450
            out int event_base_return,
451
            out int error_base_return);
452
        /*
453
        [DllImport(_dll_name_vid)]
454
        extern public static bool XF86VidModeSwitchMode(
455
            Display display,
456
            int screen,
457
            int zoom);
458
        */
459
 
460
        [DllImport(_dll_name_vid)]
461
        extern public static bool XF86VidModeSwitchToMode(
462
            Display display,
463
            int screen,
464
            IntPtr
465
            /*XF86VidModeModeInfo* */ modeline);
466
 
467
 
468
        [DllImport(_dll_name_vid)]
469
        extern public static bool XF86VidModeQueryVersion(
470
            Display display,
471
            out int major_version_return,
472
            out int minor_version_return);
473
 
474
        [DllImport(_dll_name_vid)]
475
        extern public static bool XF86VidModeGetAllModeLines(
476
            Display display,
477
            int screen,
478
            out int modecount_return,
479
            /*XF86VidModeModeInfo***  <-- yes, that's three *'s. */
480
            out IntPtr modesinfo);
481
 
482
        [DllImport(_dll_name_vid)]
483
        extern public static bool XF86VidModeSetViewPort(
484
            Display display,
485
            int screen,
486
            int x,
487
            int y);
488
 
489
        /*
490
Bool XF86VidModeSetClientVersion(
491
    Display *display);
492
 
493
Bool XF86VidModeGetModeLine(
494
    Display *display,
495
    int screen,
496
    int *dotclock_return,
497
    XF86VidModeModeLine *modeline);
498
 
499
Bool XF86VidModeDeleteModeLine(
500
    Display *display,
501
    int screen,
502
    XF86VidModeModeInfo *modeline);
503
 
504
Bool XF86VidModeModModeLine(
505
    Display *display,
506
    int screen,
507
    XF86VidModeModeLine *modeline);
508
 
509
Status XF86VidModeValidateModeLine(
510
    Display *display,
511
    int screen,
512
    XF86VidModeModeLine *modeline);
513
 
514
 
515
Bool XF86VidModeLockModeSwitch(
516
    Display *display,
517
    int screen,
518
    int lock);
519
 
520
Bool XF86VidModeGetMonitor(
521
    Display *display,
522
    int screen,
523
    XF86VidModeMonitor *monitor);
524
 
525
Bool XF86VidModeGetViewPort(
526
    Display *display,
527
    int screen,
528
    int *x_return,
529
    int *y_return);
530
 
531
 
532
XF86VidModeGetDotClocks(
533
    Display *display,
534
    int screen,
535
    int *flags return,
536
    int *number of clocks return,
537
    int *max dot clock return,
538
    int **clocks return);
539
 
540
XF86VidModeGetGamma(
541
    Display *display,
542
    int screen,
543
    XF86VidModeGamma *Gamma);
544
 
545
XF86VidModeSetGamma(
546
    Display *display,
547
    int screen,
548
    XF86VidModeGamma *Gamma);
549
 
550
XF86VidModeGetGammaRamp(
551
    Display *display,
552
    int screen,
553
    int size,
554
    unsigned short *red array,
555
    unsigned short *green array,
556
    unsigned short *blue array);
557
 
558
XF86VidModeSetGammaRamp(
559
    Display *display,
560
    int screen,
561
    int size,
562
    unsigned short *red array,
563
    unsigned short *green array,
564
    unsigned short *blue array);
565
 
566
XF86VidModeGetGammaRampSize(
567
    Display *display,
568
    int screen,
569
    int *size);
570
         * */
571
 
572
        #endregion
573
 
574
        [DllImport(_dll_name, EntryPoint = "XLookupKeysym")]
575
        public static extern KeySym LookupKeysym(ref XKeyEvent key_event, int index);
576
 
577
    }
578
    #endregion
579
 
580
    #region X11 Structures
581
 
582
    #region internal class XVisualInfo
583
 
584
    [StructLayout(LayoutKind.Sequential)]
585
    struct XVisualInfo
586
    {
587
        public IntPtr Visual;
588
        public VisualID VisualID;
589
        public int Screen;
590
        public int Depth;
591
        public XVisualClass Class;
592
        public long RedMask;
593
        public long GreenMask;
594
        public long blueMask;
595
        public int ColormapSize;
596
        public int BitsPerRgb;
597
 
598
        public override string ToString()
599
        {
600
            return String.Format("id ({0}), screen ({1}), depth ({2}), class ({3})",
601
                VisualID, Screen, Depth, Class);
602
        }
603
    }
604
 
605
    #endregion
606
 
607
    #region internal class SetWindowAttributes
608
 
609
    [StructLayout(LayoutKind.Sequential), Obsolete("Use XSetWindowAttributes instead")]
610
    internal class SetWindowAttributes
611
    {
612
        /// <summary>
613
        /// background, None, or ParentRelative
614
        /// </summary>
615
        public Pixmap background_pixmap;
616
        /// <summary>
617
        /// background pixel
618
        /// </summary>
619
        public long background_pixel;
620
        /// <summary>
621
        /// border of the window or CopyFromParent
622
        /// </summary>
623
        public Pixmap border_pixmap;
624
        /// <summary>
625
        /// border pixel value
626
        /// </summary>
627
        public long border_pixel;
628
        /// <summary>
629
        /// one of bit gravity values
630
        /// </summary>
631
        public int bit_gravity;
632
        /// <summary>
633
        /// one of the window gravity values
634
        /// </summary>
635
        public int win_gravity;
636
        /// <summary>
637
        /// NotUseful, WhenMapped, Always
638
        /// </summary>
639
        public int backing_store;
640
        /// <summary>
641
        /// planes to be preserved if possible
642
        /// </summary>
643
        public long backing_planes;
644
        /// <summary>
645
        /// value to use in restoring planes
646
        /// </summary>
647
        public long backing_pixel;
648
        /// <summary>
649
        /// should bits under be saved? (popups)
650
        /// </summary>
651
        public bool save_under;
652
        /// <summary>
653
        /// set of events that should be saved
654
        /// </summary>
655
        public EventMask event_mask;
656
        /// <summary>
657
        /// set of events that should not propagate
658
        /// </summary>
659
        public long do_not_propagate_mask;
660
        /// <summary>
661
        /// boolean value for override_redirect
662
        /// </summary>
663
        public bool override_redirect;
664
        /// <summary>
665
        /// color map to be associated with window
666
        /// </summary>
667
        public Colormap colormap;
668
        /// <summary>
669
        /// cursor to be displayed (or None)
670
        /// </summary>
671
        public Cursor cursor;
672
    }
673
 
674
    #endregion
675
 
676
    #region internal struct SizeHints
677
 
678
    [StructLayout(LayoutKind.Sequential)]
679
    internal struct SizeHints
680
    {
681
        public long flags;         /* marks which fields in this structure are defined */
682
        public int x, y;           /* Obsolete */
683
        public int width, height;  /* Obsolete */
684
        public int min_width, min_height;
685
        public int max_width, max_height;
686
        public int width_inc, height_inc;
687
        public Rectangle min_aspect, max_aspect;
688
        public int base_width, base_height;
689
        public int win_gravity;
690
        internal struct Rectangle
691
        {
692
            public int x;       /* numerator */
693
            public int y;       /* denominator */
694
            private void stop_the_compiler_warnings() { x = y = 0; }
695
        }
696
        /* this structure may be extended in the future */
697
    }
698
 
699
    #endregion
700
 
701
    #region internal struct XRRScreenSize
702
 
703
    internal struct XRRScreenSize
704
    {
705
        internal int Width, Height;
706
        internal int MWidth, MHeight;
707
    };
708
 
709
    #endregion
710
 
711
    #region unsafe internal struct Screen
712
 
713
    unsafe internal struct Screen
714
    {
715
        XExtData ext_data;    /* hook for extension to hang buffer */
716
        IntPtr display;     /* back pointer to display structure */ /* _XDisplay */
717
        Window root;        /* Root window id. */
718
        int width, height;    /* width and height of screen */
719
        int mwidth, mheight;    /* width and height of  in millimeters */
720
        int ndepths;        /* number of depths possible */
721
        //Depth *depths;        /* list of allowable depths on the screen */
722
        int root_depth;        /* bits per pixel */
723
        //Visual* root_visual;    /* root visual */
724
        IntPtr default_gc;        /* GC for the root root visual */   // GC
725
        Colormap cmap;        /* default color map */
726
        UIntPtr white_pixel;    // unsigned long
727
        UIntPtr black_pixel;    /* White and Black pixel values */  // unsigned long
728
        int max_maps, min_maps;    /* max and min color maps */
729
        int backing_store;    /* Never, WhenMapped, Always */
730
        Bool save_unders;    
731
        long root_input_mask;    /* initial root input mask */
732
    }
733
 
734
    #endregion
735
 
736
    #region unsafe internal class XExtData
737
 
738
    unsafe internal class XExtData
739
    {
740
        int number;        /* number returned by XRegisterExtension */
741
        XExtData next;    /* next item on list of buffer for structure */
742
        delegate int FreePrivateDelegate(XExtData extension);
743
        FreePrivateDelegate FreePrivate;    /* called to free private storage */
744
        XPointer private_data;    /* buffer private to this extension. */
745
    };
746
 
747
    #endregion
748
 
749
    #region Motif
750
 
751
    [StructLayout(LayoutKind.Sequential)]
752
    internal struct MotifWmHints
753
    {
754
        internal IntPtr flags;
755
        internal IntPtr functions;
756
        internal IntPtr decorations;
757
        internal IntPtr input_mode;
758
        internal IntPtr status;
759
 
760
        public override string ToString ()
761
        {
762
            return string.Format("MotifWmHints <flags={0}, functions={1}, decorations={2}, input_mode={3}, status={4}", (MotifFlags) flags.ToInt32 (), (MotifFunctions) functions.ToInt32 (), (MotifDecorations) decorations.ToInt32 (), (MotifInputMode) input_mode.ToInt32 (), status.ToInt32 ());
763
        }
764
    }
765
 
766
    [Flags]
767
    internal enum MotifFlags
768
    {
769
        Functions    = 1,
770
        Decorations  = 2,
771
        InputMode    = 4,
772
        Status       = 8
773
    }
774
 
775
    [Flags]
776
    internal enum MotifFunctions
777
    {
778
        All         = 0x01,
779
        Resize      = 0x02,
780
        Move        = 0x04,
781
        Minimize    = 0x08,
782
        Maximize    = 0x10,
783
        Close       = 0x20
784
    }
785
 
786
    [Flags]
787
    internal enum MotifDecorations
788
    {
789
        All         = 0x01,
790
        Border      = 0x02,
791
        ResizeH     = 0x04,
792
        Title       = 0x08,
793
        Menu        = 0x10,
794
        Minimize    = 0x20,
795
        Maximize    = 0x40,
796
 
797
    }
798
 
799
    [Flags]
800
    internal enum MotifInputMode
801
    {
802
        Modeless                = 0,
803
        ApplicationModal        = 1,
804
        SystemModal             = 2,
805
        FullApplicationModal    = 3
806
    }
807
 
808
    #endregion
809
 
810
    #endregion
811
 
812
    #region X11 Constants and Enums
813
 
814
    internal struct Constants
815
    {
816
        public const int QueuedAlready = 0;
817
        public const int QueuedAfterReading = 1;
818
        public const int QueuedAfterFlush = 2;
819
 
820
        public const int CopyFromParent = 0;
821
        public const int CWX = 1;
822
        public const int InputOutput = 1;
823
        public const int InputOnly = 2;
824
 
825
        /* The hints we recognize */
826
        public const string XA_WIN_PROTOCOLS           = "_WIN_PROTOCOLS";
827
        public const string XA_WIN_ICONS               = "_WIN_ICONS";
828
        public const string XA_WIN_WORKSPACE           = "_WIN_WORKSPACE";
829
        public const string XA_WIN_WORKSPACE_COUNT     = "_WIN_WORKSPACE_COUNT";
830
        public const string XA_WIN_WORKSPACE_NAMES     = "_WIN_WORKSPACE_NAMES";
831
        public const string XA_WIN_LAYER               = "_WIN_LAYER";
832
        public const string XA_WIN_STATE               = "_WIN_STATE";
833
        public const string XA_WIN_HINTS               = "_WIN_HINTS";
834
        public const string XA_WIN_WORKAREA            = "_WIN_WORKAREA";
835
        public const string XA_WIN_CLIENT_LIST         = "_WIN_CLIENT_LIST";
836
        public const string XA_WIN_APP_STATE           = "_WIN_APP_STATE";
837
        public const string XA_WIN_EXPANDED_SIZE       = "_WIN_EXPANDED_SIZE";
838
        public const string XA_WIN_CLIENT_MOVING       = "_WIN_CLIENT_MOVING";
839
        public const string XA_WIN_SUPPORTING_WM_CHECK = "_WIN_SUPPORTING_WM_CHECK";
840
    }
841
 
842
    internal enum WindowLayer
843
    {
844
        Desktop    = 0,
845
        Below      = 2,
846
        Normal     = 4,
847
        OnTop      = 6,
848
        Dock       = 8,
849
        AboveDock  = 10,
850
        Menu       = 12,
851
    }
852
 
853
    internal enum WindowState
854
    {
855
        Sticky           = (1<<0), /* everyone knows sticky */
856
        Minimized        = (1<<1), /* ??? */
857
        MaximizedVertically = (1<<2), /* window in maximized V state */
858
        MaximizedHorizontally = (1<<3), /* window in maximized H state */
859
        Hidden           = (1<<4), /* not on taskbar but window visible */
860
        Shaded           = (1<<5), /* shaded (NeXT style), */
861
        HID_WORKSPACE    = (1<<6), /* not on current desktop */
862
        HID_TRANSIENT    = (1<<7), /* owner of transient is hidden */
863
        FixedPosition    = (1<<8), /* window is fixed in position even */
864
        ArrangeIgnore    = (1<<9),  /* ignore for auto arranging */
865
    }
866
 
867
    internal enum WindowHints
868
    {
869
        SkipFocus = (1<<0), /* "alt-tab" skips this win */
870
        SkipWinlist = (1<<1), /* not in win list */
871
        SkipTaskbar = (1<<2), /* not on taskbar */
872
        GroupTransient = (1<<3), /* ??????? */
873
        FocusOnClick = (1<<4), /* app only accepts focus when clicked */
874
        DoNotCover = (1<<5),  /* attempt to not cover this window */
875
    }
876
 
877
    internal enum ErrorCodes : int
878
    {
879
        Success = 0,
880
        BadRequest = 1,
881
        BadValue = 2,
882
        BadWindow = 3,
883
        BadPixmap = 4,
884
        BadAtom = 5,
885
        BadCursor = 6,
886
        BadFont = 7,
887
        BadMatch = 8,
888
        BadDrawable = 9,
889
        BadAccess = 10,
890
        BadAlloc = 11,
891
        BadColor = 12,
892
        BadGC = 13,
893
        BadIDChoice = 14,
894
        BadName = 15,
895
        BadLength = 16,
896
        BadImplementation = 17,
897
    }
898
 
899
    [Flags]
900
    internal enum CreateWindowMask : long//: ulong
901
    {
902
        CWBackPixmap    = (1L<<0),
903
        CWBackPixel     = (1L<<1),
904
        CWSaveUnder        = (1L<<10),
905
        CWEventMask        = (1L<<11),
906
        CWDontPropagate    = (1L<<12),
907
        CWColormap      = (1L<<13),
908
        CWCursor        = (1L<<14),
909
        CWBorderPixmap    = (1L<<2),
910
        CWBorderPixel    = (1L<<3),
911
        CWBitGravity    = (1L<<4),
912
        CWWinGravity    = (1L<<5),
913
        CWBackingStore    = (1L<<6),
914
        CWBackingPlanes    = (1L<<7),
915
        CWBackingPixel     = (1L<<8),
916
        CWOverrideRedirect    = (1L<<9),
917
 
918
        //CWY    = (1<<1),
919
        //CWWidth    = (1<<2),
920
        //CWHeight    = (1<<3),
921
        //CWBorderWidth    = (1<<4),
922
        //CWSibling    = (1<<5),
923
        //CWStackMode    = (1<<6),
924
    }
925
 
926
    #region XKey
927
 
928
    /// <summary>
929
    /// Defines LATIN-1 and miscellaneous keys.
930
    /// </summary>
931
    [CLSCompliant(false)]
932
    internal enum XKey
933
    {
934
        /*
935
         * TTY function keys, cleverly chosen to map to ASCII, for convenience of
936
         * programming, but could have been arbitrary (at the cost of lookup
937
         * tables in client code).
938
         */
939
 
940
        BackSpace                   = 0xff08,  /* Back space, back char */
941
        Tab                         = 0xff09,
942
        Linefeed                    = 0xff0a,  /* Linefeed, LF */
943
        Clear                       = 0xff0b,
944
        Return                      = 0xff0d,  /* Return, enter */
945
        Pause                       = 0xff13,  /* Pause, hold */
946
        Scroll_Lock                 = 0xff14,
947
        Sys_Req                     = 0xff15,
948
        Escape                      = 0xff1b,
949
        Delete                      = 0xffff,  /* Delete, rubout */
950
 
951
 
952
 
953
        /* International & multi-key character composition */
954
 
955
        Multi_key                   = 0xff20,  /* Multi-key character compose */
956
        Codeinput                   = 0xff37,
957
        SingleCandidate             = 0xff3c,
958
        MultipleCandidate           = 0xff3d,
959
        PreviousCandidate           = 0xff3e,
960
 
961
        /* Japanese keyboard support */
962
 
963
        Kanji                       = 0xff21,  /* Kanji, Kanji convert */
964
        Muhenkan                    = 0xff22,  /* Cancel Conversion */
965
        Henkan_Mode                 = 0xff23,  /* Start/Stop Conversion */
966
        Henkan                      = 0xff23,  /* Alias for Henkan_Mode */
967
        Romaji                      = 0xff24,  /* to Romaji */
968
        Hiragana                    = 0xff25,  /* to Hiragana */
969
        Katakana                    = 0xff26,  /* to Katakana */
970
        Hiragana_Katakana           = 0xff27,  /* Hiragana/Katakana toggle */
971
        Zenkaku                     = 0xff28,  /* to Zenkaku */
972
        Hankaku                     = 0xff29,  /* to Hankaku */
973
        Zenkaku_Hankaku             = 0xff2a,  /* Zenkaku/Hankaku toggle */
974
        Touroku                     = 0xff2b,  /* Add to Dictionary */
975
        Massyo                      = 0xff2c,  /* Delete from Dictionary */
976
        Kana_Lock                   = 0xff2d,  /* Kana Lock */
977
        Kana_Shift                  = 0xff2e,  /* Kana Shift */
978
        Eisu_Shift                  = 0xff2f,  /* Alphanumeric Shift */
979
        Eisu_toggle                 = 0xff30,  /* Alphanumeric toggle */
980
        Kanji_Bangou                = 0xff37,  /* Codeinput */
981
        Zen_Koho                    = 0xff3d,  /* Multiple/All Candidate(s) */
982
        Mae_Koho                    = 0xff3e,  /* Previous Candidate */
983
 
984
        /* 0xff31 thru 0xff3f are under XK_KOREAN */
985
 
986
        /* Cursor control & motion */
987
 
988
        Home                        = 0xff50,
989
        Left                        = 0xff51,  /* Move left, left arrow */
990
        Up                          = 0xff52,  /* Move up, up arrow */
991
        Right                       = 0xff53,  /* Move right, right arrow */
992
        Down                        = 0xff54,  /* Move down, down arrow */
993
        Prior                       = 0xff55,  /* Prior, previous */
994
        Page_Up                     = 0xff55,
995
        Next                        = 0xff56,  /* Next */
996
        Page_Down                   = 0xff56,
997
        End                         = 0xff57,  /* EOL */
998
        Begin                       = 0xff58,  /* BOL */
999
 
1000
 
1001
        /* Misc functions */
1002
 
1003
        Select                      = 0xff60,  /* Select, mark */
1004
        Print                       = 0xff61,
1005
        Execute                     = 0xff62,  /* Execute, run, do */
1006
        Insert                      = 0xff63,  /* Insert, insert here */
1007
        Undo                        = 0xff65,
1008
        Redo                        = 0xff66,  /* Redo, again */
1009
        Menu                        = 0xff67,
1010
        Find                        = 0xff68,  /* Find, search */
1011
        Cancel                      = 0xff69,  /* Cancel, stop, abort, exit */
1012
        Help                        = 0xff6a,  /* Help */
1013
        Break                       = 0xff6b,
1014
        Mode_switch                 = 0xff7e,  /* Character set switch */
1015
        script_switch               = 0xff7e,  /* Alias for mode_switch */
1016
        Num_Lock                    = 0xff7f,
1017
 
1018
        /* Keypad functions, keypad numbers cleverly chosen to map to ASCII */
1019
 
1020
        KP_Space                    = 0xff80,  /* Space */
1021
        KP_Tab                      = 0xff89,
1022
        KP_Enter                    = 0xff8d,  /* Enter */
1023
        KP_F1                       = 0xff91,  /* PF1, KP_A, ... */
1024
        KP_F2                       = 0xff92,
1025
        KP_F3                       = 0xff93,
1026
        KP_F4                       = 0xff94,
1027
        KP_Home                     = 0xff95,
1028
        KP_Left                     = 0xff96,
1029
        KP_Up                       = 0xff97,
1030
        KP_Right                    = 0xff98,
1031
        KP_Down                     = 0xff99,
1032
        KP_Prior                    = 0xff9a,
1033
        KP_Page_Up                  = 0xff9a,
1034
        KP_Next                     = 0xff9b,
1035
        KP_Page_Down                = 0xff9b,
1036
        KP_End                      = 0xff9c,
1037
        KP_Begin                    = 0xff9d,
1038
        KP_Insert                   = 0xff9e,
1039
        KP_Delete                   = 0xff9f,
1040
        KP_Equal                    = 0xffbd,  /* Equals */
1041
        KP_Multiply                 = 0xffaa,
1042
        KP_Add                      = 0xffab,
1043
        KP_Separator                = 0xffac,  /* Separator, often comma */
1044
        KP_Subtract                 = 0xffad,
1045
        KP_Decimal                  = 0xffae,
1046
        KP_Divide                   = 0xffaf,
1047
 
1048
        KP_0                        = 0xffb0,
1049
        KP_1                        = 0xffb1,
1050
        KP_2                        = 0xffb2,
1051
        KP_3                        = 0xffb3,
1052
        KP_4                        = 0xffb4,
1053
        KP_5                        = 0xffb5,
1054
        KP_6                        = 0xffb6,
1055
        KP_7                        = 0xffb7,
1056
        KP_8                        = 0xffb8,
1057
        KP_9                        = 0xffb9,
1058
 
1059
        /*
1060
         * Auxiliary functions; note the duplicate definitions for left and right
1061
         * function keys;  Sun keyboards and a few other manufacturers have such
1062
         * function key groups on the left and/or right sides of the keyboard.
1063
         * We've not found a keyboard with more than 35 function keys total.
1064
         */
1065
 
1066
        F1                          = 0xffbe,
1067
        F2                          = 0xffbf,
1068
        F3                          = 0xffc0,
1069
        F4                          = 0xffc1,
1070
        F5                          = 0xffc2,
1071
        F6                          = 0xffc3,
1072
        F7                          = 0xffc4,
1073
        F8                          = 0xffc5,
1074
        F9                          = 0xffc6,
1075
        F10                         = 0xffc7,
1076
        F11                         = 0xffc8,
1077
        L1                          = 0xffc8,
1078
        F12                         = 0xffc9,
1079
        L2                          = 0xffc9,
1080
        F13                         = 0xffca,
1081
        L3                          = 0xffca,
1082
        F14                         = 0xffcb,
1083
        L4                          = 0xffcb,
1084
        F15                         = 0xffcc,
1085
        L5                          = 0xffcc,
1086
        F16                         = 0xffcd,
1087
        L6                          = 0xffcd,
1088
        F17                         = 0xffce,
1089
        L7                          = 0xffce,
1090
        F18                         = 0xffcf,
1091
        L8                          = 0xffcf,
1092
        F19                         = 0xffd0,
1093
        L9                          = 0xffd0,
1094
        F20                         = 0xffd1,
1095
        L10                         = 0xffd1,
1096
        F21                         = 0xffd2,
1097
        R1                          = 0xffd2,
1098
        F22                         = 0xffd3,
1099
        R2                          = 0xffd3,
1100
        F23                         = 0xffd4,
1101
        R3                          = 0xffd4,
1102
        F24                         = 0xffd5,
1103
        R4                          = 0xffd5,
1104
        F25                         = 0xffd6,
1105
        R5                          = 0xffd6,
1106
        F26                         = 0xffd7,
1107
        R6                          = 0xffd7,
1108
        F27                         = 0xffd8,
1109
        R7                          = 0xffd8,
1110
        F28                         = 0xffd9,
1111
        R8                          = 0xffd9,
1112
        F29                         = 0xffda,
1113
        R9                          = 0xffda,
1114
        F30                         = 0xffdb,
1115
        R10                         = 0xffdb,
1116
        F31                         = 0xffdc,
1117
        R11                         = 0xffdc,
1118
        F32                         = 0xffdd,
1119
        R12                         = 0xffdd,
1120
        F33                         = 0xffde,
1121
        R13                         = 0xffde,
1122
        F34                         = 0xffdf,
1123
        R14                         = 0xffdf,
1124
        F35                         = 0xffe0,
1125
        R15                         = 0xffe0,
1126
 
1127
        /* Modifiers */
1128
 
1129
        Shift_L                     = 0xffe1,  /* Left shift */
1130
        Shift_R                     = 0xffe2,  /* Right shift */
1131
        Control_L                   = 0xffe3,  /* Left control */
1132
        Control_R                   = 0xffe4,  /* Right control */
1133
        Caps_Lock                   = 0xffe5,  /* Caps lock */
1134
        Shift_Lock                  = 0xffe6,  /* Shift lock */
1135
 
1136
        Meta_L                      = 0xffe7,  /* Left meta */
1137
        Meta_R                      = 0xffe8,  /* Right meta */
1138
        Alt_L                       = 0xffe9,  /* Left alt */
1139
        Alt_R                       = 0xffea,  /* Right alt */
1140
        Super_L                     = 0xffeb,  /* Left super */
1141
        Super_R                     = 0xffec,  /* Right super */
1142
        Hyper_L                     = 0xffed,  /* Left hyper */
1143
        Hyper_R                     = 0xffee,  /* Right hyper */
1144
 
1145
        /*
1146
         * Latin 1
1147
         * (ISO/IEC 8859-1 = Unicode U+0020..U+00FF)
1148
         * Byte 3 = 0
1149
         */
1150
 
1151
        space                       = 0x0020,  /* U+0020 SPACE */
1152
        exclam                      = 0x0021,  /* U+0021 EXCLAMATION MARK */
1153
        quotedbl                    = 0x0022,  /* U+0022 QUOTATION MARK */
1154
        numbersign                  = 0x0023,  /* U+0023 NUMBER SIGN */
1155
        dollar                      = 0x0024,  /* U+0024 DOLLAR SIGN */
1156
        percent                     = 0x0025,  /* U+0025 PERCENT SIGN */
1157
        ampersand                   = 0x0026,  /* U+0026 AMPERSAND */
1158
        apostrophe                  = 0x0027,  /* U+0027 APOSTROPHE */
1159
        quoteright                  = 0x0027,  /* deprecated */
1160
        parenleft                   = 0x0028,  /* U+0028 LEFT PARENTHESIS */
1161
        parenright                  = 0x0029,  /* U+0029 RIGHT PARENTHESIS */
1162
        asterisk                    = 0x002a,  /* U+002A ASTERISK */
1163
        plus                        = 0x002b,  /* U+002B PLUS SIGN */
1164
        comma                       = 0x002c,  /* U+002C COMMA */
1165
        minus                       = 0x002d,  /* U+002D HYPHEN-MINUS */
1166
        period                      = 0x002e,  /* U+002E FULL STOP */
1167
        slash                       = 0x002f,  /* U+002F SOLIDUS */
1168
        Number0                           = 0x0030,  /* U+0030 DIGIT ZERO */
1169
        Number1                           = 0x0031,  /* U+0031 DIGIT ONE */
1170
        Number2                           = 0x0032,  /* U+0032 DIGIT TWO */
1171
        Number3                           = 0x0033,  /* U+0033 DIGIT THREE */
1172
        Number4                           = 0x0034,  /* U+0034 DIGIT FOUR */
1173
        Number5                           = 0x0035,  /* U+0035 DIGIT FIVE */
1174
        Number6                           = 0x0036,  /* U+0036 DIGIT SIX */
1175
        Number7                           = 0x0037,  /* U+0037 DIGIT SEVEN */
1176
        Number8                           = 0x0038,  /* U+0038 DIGIT EIGHT */
1177
        Number9                     = 0x0039,  /* U+0039 DIGIT NINE */
1178
        colon                       = 0x003a,  /* U+003A COLON */
1179
        semicolon                   = 0x003b,  /* U+003B SEMICOLON */
1180
        less                        = 0x003c,  /* U+003C LESS-THAN SIGN */
1181
        equal                       = 0x003d,  /* U+003D EQUALS SIGN */
1182
        greater                     = 0x003e,  /* U+003E GREATER-THAN SIGN */
1183
        question                    = 0x003f,  /* U+003F QUESTION MARK */
1184
        at                          = 0x0040,  /* U+0040 COMMERCIAL AT */
1185
        A                           = 0x0041,  /* U+0041 LATIN CAPITAL LETTER A */
1186
        B                           = 0x0042,  /* U+0042 LATIN CAPITAL LETTER B */
1187
        C                           = 0x0043,  /* U+0043 LATIN CAPITAL LETTER C */
1188
        D                           = 0x0044,  /* U+0044 LATIN CAPITAL LETTER D */
1189
        E                           = 0x0045,  /* U+0045 LATIN CAPITAL LETTER E */
1190
        F                           = 0x0046,  /* U+0046 LATIN CAPITAL LETTER F */
1191
        G                           = 0x0047,  /* U+0047 LATIN CAPITAL LETTER G */
1192
        H                           = 0x0048,  /* U+0048 LATIN CAPITAL LETTER H */
1193
        I                           = 0x0049,  /* U+0049 LATIN CAPITAL LETTER I */
1194
        J                           = 0x004a,  /* U+004A LATIN CAPITAL LETTER J */
1195
        K                           = 0x004b,  /* U+004B LATIN CAPITAL LETTER K */
1196
        L                           = 0x004c,  /* U+004C LATIN CAPITAL LETTER L */
1197
        M                           = 0x004d,  /* U+004D LATIN CAPITAL LETTER M */
1198
        N                           = 0x004e,  /* U+004E LATIN CAPITAL LETTER N */
1199
        O                           = 0x004f,  /* U+004F LATIN CAPITAL LETTER O */
1200
        P                           = 0x0050,  /* U+0050 LATIN CAPITAL LETTER P */
1201
        Q                           = 0x0051,  /* U+0051 LATIN CAPITAL LETTER Q */
1202
        R                           = 0x0052,  /* U+0052 LATIN CAPITAL LETTER R */
1203
        S                           = 0x0053,  /* U+0053 LATIN CAPITAL LETTER S */
1204
        T                           = 0x0054,  /* U+0054 LATIN CAPITAL LETTER T */
1205
        U                           = 0x0055,  /* U+0055 LATIN CAPITAL LETTER U */
1206
        V                           = 0x0056,  /* U+0056 LATIN CAPITAL LETTER V */
1207
        W                           = 0x0057,  /* U+0057 LATIN CAPITAL LETTER W */
1208
        X                           = 0x0058,  /* U+0058 LATIN CAPITAL LETTER X */
1209
        Y                           = 0x0059,  /* U+0059 LATIN CAPITAL LETTER Y */
1210
        Z                           = 0x005a,  /* U+005A LATIN CAPITAL LETTER Z */
1211
        bracketleft                 = 0x005b,  /* U+005B LEFT SQUARE BRACKET */
1212
        backslash                   = 0x005c,  /* U+005C REVERSE SOLIDUS */
1213
        bracketright                = 0x005d,  /* U+005D RIGHT SQUARE BRACKET */
1214
        asciicircum                 = 0x005e,  /* U+005E CIRCUMFLEX ACCENT */
1215
        underscore                  = 0x005f,  /* U+005F LOW LINE */
1216
        grave                       = 0x0060,  /* U+0060 GRAVE ACCENT */
1217
        quoteleft                   = 0x0060,  /* deprecated */
1218
        a                           = 0x0061,  /* U+0061 LATIN SMALL LETTER A */
1219
        b                           = 0x0062,  /* U+0062 LATIN SMALL LETTER B */
1220
        c                           = 0x0063,  /* U+0063 LATIN SMALL LETTER C */
1221
        d                           = 0x0064,  /* U+0064 LATIN SMALL LETTER D */
1222
        e                           = 0x0065,  /* U+0065 LATIN SMALL LETTER E */
1223
        f                           = 0x0066,  /* U+0066 LATIN SMALL LETTER F */
1224
        g                           = 0x0067,  /* U+0067 LATIN SMALL LETTER G */
1225
        h                           = 0x0068,  /* U+0068 LATIN SMALL LETTER H */
1226
        i                           = 0x0069,  /* U+0069 LATIN SMALL LETTER I */
1227
        j                           = 0x006a,  /* U+006A LATIN SMALL LETTER J */
1228
        k                           = 0x006b,  /* U+006B LATIN SMALL LETTER K */
1229
        l                           = 0x006c,  /* U+006C LATIN SMALL LETTER L */
1230
        m                           = 0x006d,  /* U+006D LATIN SMALL LETTER M */
1231
        n                           = 0x006e,  /* U+006E LATIN SMALL LETTER N */
1232
        o                           = 0x006f,  /* U+006F LATIN SMALL LETTER O */
1233
        p                           = 0x0070,  /* U+0070 LATIN SMALL LETTER P */
1234
        q                           = 0x0071,  /* U+0071 LATIN SMALL LETTER Q */
1235
        r                           = 0x0072,  /* U+0072 LATIN SMALL LETTER R */
1236
        s                           = 0x0073,  /* U+0073 LATIN SMALL LETTER S */
1237
        t                           = 0x0074,  /* U+0074 LATIN SMALL LETTER T */
1238
        u                           = 0x0075,  /* U+0075 LATIN SMALL LETTER U */
1239
        v                           = 0x0076,  /* U+0076 LATIN SMALL LETTER V */
1240
        w                           = 0x0077,  /* U+0077 LATIN SMALL LETTER W */
1241
        x                           = 0x0078,  /* U+0078 LATIN SMALL LETTER X */
1242
        y                           = 0x0079,  /* U+0079 LATIN SMALL LETTER Y */
1243
        z                           = 0x007a,  /* U+007A LATIN SMALL LETTER Z */
1244
        braceleft                   = 0x007b,  /* U+007B LEFT CURLY BRACKET */
1245
        bar                         = 0x007c,  /* U+007C VERTICAL LINE */
1246
        braceright                  = 0x007d,  /* U+007D RIGHT CURLY BRACKET */
1247
        asciitilde                  = 0x007e,  /* U+007E TILDE */
1248
    }
1249
 
1250
    #endregion
1251
 
1252
#pragma warning disable 1591
1253
 
1254
    public enum XVisualClass : int
1255
    {
1256
        StaticGray = 0,
1257
        GrayScale = 1,
1258
        StaticColor = 2,
1259
        PseudoColor = 3,
1260
        TrueColor = 4,
1261
        DirectColor = 5,
1262
    }
1263
 
1264
#pragma warning restore 1591
1265
 
1266
    [Flags]
1267
    internal enum XVisualInfoMask
1268
    {
1269
        No = 0x0,
1270
        ID = 0x1,
1271
        Screen = 0x2,
1272
        Depth = 0x4,
1273
        Class = 0x8,
1274
        Red = 0x10,
1275
        Green = 0x20,
1276
        Blue = 0x40,
1277
        ColormapSize = 0x80,
1278
        BitsPerRGB = 0x100,
1279
        All = 0x1FF,
1280
    }
1281
 
1282
    #region internal enum MouseMask
1283
 
1284
    internal enum MouseMask
1285
    {
1286
        Button1MotionMask = (1 << 8),
1287
        Button2MotionMask = (1 << 9),
1288
        Button3MotionMask = (1 << 10),
1289
        Button4MotionMask = (1 << 11),
1290
        Button5MotionMask = (1 << 12),
1291
        Button1Mask = (1 << 8),
1292
        Button2Mask = (1 << 9),
1293
        Button3Mask = (1 << 10),
1294
        Button4Mask = (1 << 11),
1295
        Button5Mask = (1 << 12),
1296
        Button6Mask = (1 << 13),
1297
        Button7Mask = (1 << 14),
1298
        Button8Mask = (1 << 15),
1299
        ShiftMask = (1 << 0),
1300
        LockMask = (1 << 1),
1301
        ControlMask = (1 << 2),
1302
        Mod1Mask = (1 << 3),
1303
        Mod2Mask = (1 << 4),
1304
        Mod3Mask = (1 << 5),
1305
        Mod4Mask = (1 << 6),
1306
        Mod5Mask = (1 << 7),
1307
    }
1308
 
1309
    #endregion
1310
 
1311
    #endregion
1312
 
1313
    internal static partial class Functions
1314
    {
1315
        internal const string X11Library = "libX11";
1316
 
1317
        #region XCreateWindow
1318
 
1319
        /// <summary>
1320
        /// The XCreateWindow function creates an unmapped subwindow for a specified parent window, returns the window ID of the created window, and causes the X server to generate a CreateNotify event. The created window is placed on top in the stacking order with respect to siblings.
1321
        /// </summary>
1322
        /// <param name="display">Specifies the connection to the X server.</param>
1323
        /// <param name="parent">Specifies the parent window.</param>
1324
        /// <param name="x">Specify the x coordinates, which are the top-left outside corner of the window's borders and are relative to the inside of the parent window's borders.</param>
1325
        /// <param name="y">Specify the y coordinates, which are the top-left outside corner of the window's borders and are relative to the inside of the parent window's borders.</param>
1326
        /// <param name="width">Specify the width, which is the created window's inside dimensions and do not include the created window's borders.</param>
1327
        /// <param name="height">Specify the height, which is the created window's inside dimensions and do not include the created window's borders.</param>
1328
        /// <param name="border_width">Specifies the width of the created window's border in pixels.</param>
1329
        /// <param name="depth">Specifies the window's depth. A depth of CopyFromParent means the depth is taken from the parent.</param>
1330
        /// <param name="class">Specifies the created window's class. You can pass InputOutput, InputOnly, or CopyFromParent. A class of CopyFromParent means the class is taken from the parent.</param>
1331
        /// <param name="visual">Specifies the visual type. A visual of CopyFromParent means the visual type is taken from the parent.</param>
1332
        /// <param name="valuemask">Specifies which window attributes are defined in the attributes argument. This mask is the bitwise inclusive OR of the valid attribute mask bits. If valuemask is zero, the attributes are ignored and are not referenced.</param>
1333
        /// <param name="attributes">Specifies the structure from which the values (as specified by the value mask) are to be taken. The value mask should have the appropriate bits set to indicate which attributes have been set in the structure.</param>
1334
        /// <returns>The window ID of the created window.</returns>
1335
        /// <remarks>
1336
        /// The coordinate system has the X axis horizontal and the Y axis vertical with the origin [0, 0] at the upper-left corner. Coordinates are integral, in terms of pixels, and coincide with pixel centers. Each window and pixmap has its own coordinate system. For a window, the origin is inside the border at the inside, upper-left corner. 
1337
        /// <para>The border_width for an InputOnly window must be zero, or a BadMatch error results. For class InputOutput, the visual type and depth must be a combination supported for the screen, or a BadMatch error results. The depth need not be the same as the parent, but the parent must not be a window of class InputOnly, or a BadMatch error results. For an InputOnly window, the depth must be zero, and the visual must be one supported by the screen. If either condition is not met, a BadMatch error results. The parent window, however, may have any depth and class. If you specify any invalid window attribute for a window, a BadMatch error results. </para>
1338
        /// <para>The created window is not yet displayed (mapped) on the user's display. To display the window, call XMapWindow(). The new window initially uses the same cursor as its parent. A new cursor can be defined for the new window by calling XDefineCursor(). The window will not be visible on the screen unless it and all of its ancestors are mapped and it is not obscured by any of its ancestors. </para>
1339
        /// <para>XCreateWindow can generate BadAlloc BadColor, BadCursor, BadMatch, BadPixmap, BadValue, and BadWindow errors. </para>
1340
        /// <para>The XCreateSimpleWindow function creates an unmapped InputOutput subwindow for a specified parent window, returns the window ID of the created window, and causes the X server to generate a CreateNotify event. The created window is placed on top in the stacking order with respect to siblings. Any part of the window that extends outside its parent window is clipped. The border_width for an InputOnly window must be zero, or a BadMatch error results. XCreateSimpleWindow inherits its depth, class, and visual from its parent. All other window attributes, except background and border, have their default values. </para>
1341
        /// <para>XCreateSimpleWindow can generate BadAlloc, BadMatch, BadValue, and BadWindow errors.</para>
1342
        /// </remarks>
1343
        [DllImport(X11Library, EntryPoint = "XCreateWindow")]//, CLSCompliant(false)]
1344
        public extern static Window XCreateWindow(Display display, Window parent,
1345
            int x, int y, int width, int height, int border_width, int depth,
1346
            int @class, IntPtr visual, UIntPtr valuemask, ref XSetWindowAttributes attributes);
1347
 
1348
        #endregion
1349
 
1350
        #region XChangeWindowAttributes
1351
 
1352
        [DllImport(X11Library)]
1353
        internal static extern void XChangeWindowAttributes(Display display, Window w, UIntPtr valuemask, ref XSetWindowAttributes attributes);
1354
 
1355
        internal static void XChangeWindowAttributes(Display display, Window w, SetWindowValuemask valuemask, ref XSetWindowAttributes attributes)
1356
        {
1357
            XChangeWindowAttributes(display, w, (UIntPtr)valuemask, ref attributes);
1358
        }
1359
 
1360
        #endregion
1361
 
1362
        #region XQueryKeymap
1363
 
1364
        /*
1365
        /// <summary>
1366
        /// The XQueryKeymap() function returns a bit vector for the logical state of the keyboard, where each bit set to 1 indicates that the corresponding key is currently pressed down. The vector is represented as 32 bytes. Byte N (from 0) contains the bits for keys 8N to 8N + 7 with the least-significant bit in the byte representing key 8N.
1367
        /// </summary>
1368
        /// <param name="display">Specifies the connection to the X server.</param>
1369
        /// <param name="keys">Returns an array of bytes that identifies which keys are pressed down. Each bit represents one key of the keyboard.</param>
1370
        /// <remarks>Note that the logical state of a device (as seen by client applications) may lag the physical state if device event processing is frozen.</remarks>
1371
        [DllImport(_dll_name, EntryPoint = "XQueryKeymap")]
1372
        extern public static void XQueryKeymap(IntPtr display, [MarshalAs(UnmanagedType.LPArray, SizeConst = 32), In, Out] Keymap keys);
1373
        */
1374
 
1375
        /// <summary>
1376
        /// The XQueryKeymap() function returns a bit vector for the logical state of the keyboard, where each bit set to 1 indicates that the corresponding key is currently pressed down. The vector is represented as 32 bytes. Byte N (from 0) contains the bits for keys 8N to 8N + 7 with the least-significant bit in the byte representing key 8N.
1377
        /// </summary>
1378
        /// <param name="display">Specifies the connection to the X server.</param>
1379
        /// <param name="keys">Returns an array of bytes that identifies which keys are pressed down. Each bit represents one key of the keyboard.</param>
1380
        /// <remarks>Note that the logical state of a device (as seen by client applications) may lag the physical state if device event processing is frozen.</remarks>
1381
        [DllImport(X11Library, EntryPoint = "XQueryKeymap")]
1382
        extern public static void XQueryKeymap(IntPtr display, byte[] keys);
1383
 
1384
        #endregion
1385
 
1386
        #region XMaskEvent
1387
 
1388
        /// <summary>
1389
        /// The XMaskEvent() function searches the event queue for the events associated with the specified mask. When it finds a match, XMaskEvent() removes that event and copies it into the specified XEvent structure. The other events stored in the queue are not discarded. If the event you requested is not in the queue, XMaskEvent() flushes the output buffer and blocks until one is received.
1390
        /// </summary>
1391
        /// <param name="display">Specifies the connection to the X server.</param>
1392
        /// <param name="event_mask">Specifies the event mask.</param>
1393
        /// <param name="e">Returns the matched event's associated structure.</param>
1394
        [DllImport(X11Library, EntryPoint = "XMaskEvent")]
1395
        extern public static void XMaskEvent(IntPtr display, EventMask event_mask, ref XEvent e);
1396
 
1397
        #endregion
1398
 
1399
        #region XPutBackEvent
1400
 
1401
        /// <summary>
1402
        /// The XPutBackEvent() function pushes an event back onto the head of the display's event queue by copying the event into the queue. This can be useful if you read an event and then decide that you would rather deal with it later. There is no limit to the number of times in succession that you can call XPutBackEvent().
1403
        /// </summary>
1404
        /// <param name="display">Specifies the connection to the X server.</param>
1405
        /// <param name="event">Specifies the event.</param>
1406
        [DllImport(X11Library, EntryPoint = "XPutBackEvent")]
1407
        public static extern void XPutBackEvent(IntPtr display, ref XEvent @event);
1408
 
1409
        #endregion
1410
 
1411
        #region Xrandr
1412
 
1413
        const string XrandrLibrary = "libXrandr.so.2";
1414
 
1415
        [DllImport(XrandrLibrary)]
1416
        public static extern Bool XRRQueryExtension(Display dpy, ref int event_basep, ref int error_basep);
1417
 
1418
        [DllImport(XrandrLibrary)]
1419
        public static extern Status XRRQueryVersion(Display dpy, ref int major_versionp, ref int minor_versionp);
1420
 
1421
        [DllImport(XrandrLibrary)]
1422
        public static extern XRRScreenConfiguration XRRGetScreenInfo(Display dpy, Drawable draw);
1423
 
1424
        [DllImport(XrandrLibrary)]
1425
        public static extern void XRRFreeScreenConfigInfo(XRRScreenConfiguration config);
1426
 
1427
        [DllImport(XrandrLibrary)]
1428
        public static extern Status XRRSetScreenConfig(Display dpy, XRRScreenConfiguration config,
1429
            Drawable draw, int size_index, ref Rotation rotation, Time timestamp);
1430
 
1431
        [DllImport(XrandrLibrary)]
1432
        public static extern Status XRRSetScreenConfigAndRate(Display dpy, XRRScreenConfiguration config,
1433
            Drawable draw, int size_index, Rotation rotation, short rate, Time timestamp);
1434
 
1435
        [DllImport(XrandrLibrary)]
1436
        public static extern Rotation XRRConfigRotations(XRRScreenConfiguration config, ref Rotation current_rotation);
1437
 
1438
        [DllImport(XrandrLibrary)]
1439
        public static extern Time XRRConfigTimes(XRRScreenConfiguration config, ref Time config_timestamp);
1440
 
1441
        [DllImport(XrandrLibrary)]
1442
        [return: MarshalAs(UnmanagedType.LPStruct)]
1443
        public static extern XRRScreenSize XRRConfigSizes(XRRScreenConfiguration config, int[] nsizes);
1444
 
1445
        [DllImport(XrandrLibrary)]
1446
        unsafe public static extern short* XRRConfigRates(XRRScreenConfiguration config, int size_index, int[] nrates);
1447
 
1448
        [DllImport(XrandrLibrary)]
1449
        public static extern SizeID XRRConfigCurrentConfiguration(XRRScreenConfiguration config, out Rotation rotation);
1450
 
1451
        [DllImport(XrandrLibrary)]
1452
        public static extern short XRRConfigCurrentRate(XRRScreenConfiguration config);
1453
 
1454
        [DllImport(XrandrLibrary)]
1455
        public static extern int XRRRootToScreen(Display dpy, Window root);
1456
 
1457
        [DllImport(XrandrLibrary)]
1458
        public static extern XRRScreenConfiguration XRRScreenConfig(Display dpy, int screen);
1459
 
1460
        [DllImport(XrandrLibrary)]
1461
        public static extern XRRScreenConfiguration XRRConfig(ref Screen screen);
1462
 
1463
        [DllImport(XrandrLibrary)]
1464
        public static extern void XRRSelectInput(Display dpy, Window window, int mask);
1465
 
1466
        /*
1467
         * intended to take RRScreenChangeNotify,  or
1468
         * ConfigureNotify (on the root window)
1469
         * returns 1 if it is an event type it understands, 0 if not
1470
         */
1471
        [DllImport(XrandrLibrary)]
1472
        public static extern int XRRUpdateConfiguration(ref XEvent @event);
1473
 
1474
        /*
1475
         * the following are always safe to call, even if RandR is
1476
         * not implemented on a screen
1477
         */
1478
        [DllImport(XrandrLibrary)]
1479
        public static extern Rotation XRRRotations(Display dpy, int screen, ref Rotation current_rotation);
1480
 
1481
        [DllImport(XrandrLibrary)]
1482
        unsafe static extern IntPtr XRRSizes(Display dpy, int screen, int* nsizes);
1483
 
1484
        public static XRRScreenSize[] XRRSizes(Display dpy, int screen)
1485
        {
1486
            XRRScreenSize[] sizes;
1487
            //IntPtr ptr;
1488
            int count;
1489
            unsafe
1490
            {
1491
                //ptr = XRRSizes(dpy, screen, &nsizes);
1492
 
1493
                byte* data = (byte*)XRRSizes(dpy, screen, &count);//(byte*)ptr;
1494
                if (count == 0)
1495
                    return null;
1496
                sizes = new XRRScreenSize[count];
1497
                for (int i = 0; i < count; i++)
1498
                {
1499
                    sizes[i] = new XRRScreenSize();
1500
                    sizes[i] = (XRRScreenSize)Marshal.PtrToStructure((IntPtr)data, typeof(XRRScreenSize));
1501
                    data += Marshal.SizeOf(typeof(XRRScreenSize));
1502
                }
1503
                //XFree(ptr);   // Looks like we must not free this.
1504
                return sizes;
1505
            }
1506
        }
1507
 
1508
        [DllImport(XrandrLibrary)]
1509
        unsafe static extern short* XRRRates(Display dpy, int screen, int size_index, int* nrates);
1510
 
1511
        public static short[] XRRRates(Display dpy, int screen, int size_index)
1512
        {
1513
            short[] rates;
1514
            int count;
1515
            unsafe
1516
            {
1517
                short* data = (short*)XRRRates(dpy, screen, size_index, &count);
1518
                if (count == 0)
1519
                    return null;
1520
                rates = new short[count];
1521
                for (int i = 0; i < count; i++)
1522
                    rates[i] = *(data + i);
1523
            }
1524
            return rates;
1525
        }
1526
 
1527
        [DllImport(XrandrLibrary)]
1528
        public static extern Time XRRTimes(Display dpy, int screen, out Time config_timestamp);
1529
 
1530
        #endregion
1531
 
1532
        #region Display, Screen and Window functions
1533
 
1534
        #region XScreenCount
1535
 
1536
        [DllImport(X11Library)]
1537
        public static extern int XScreenCount(Display display);
1538
 
1539
        #endregion
1540
 
1541
        #region XListDepths
1542
 
1543
        [DllImport(X11Library)]
1544
        unsafe static extern int *XListDepths(Display display, int screen_number, int* count_return);
1545
 
1546
        public static int[] XListDepths(Display display, int screen_number)
1547
        {
1548
            unsafe
1549
            {
1550
                int count;
1551
                int* data = XListDepths(display, screen_number, &count);
1552
                if (count == 0)
1553
                    return null;
1554
                int[] depths = new int[count];
1555
                for (int i = 0; i < count; i++)
1556
                    depths[i] = *(data + i);
1557
 
1558
                return depths;
1559
            }
1560
        }
1561
 
1562
        #endregion
1563
 
1564
        #endregion
1565
    }
1566
    /*
1567
    [StructLayout(LayoutKind.Sequential)]
1568
    internal struct Keymap
1569
    {
1570
        unsafe fixed byte bits[32];
1571
 
1572
        public bool this[KeyCode key]
1573
        {
1574
            get
1575
            {
1576
                unsafe
1577
                {
1578
                    fixed (Keymap* ptr = &this)
1579
                    {
1580
                        return ((ptr->bits[key / 8] >> (key % 8)) & 0x01) != 0;
1581
                    }
1582
                }
1583
            }
1584
        }
1585
    }
1586
    */
1587
 
1588
    // Helper structure for calling XLock/UnlockDisplay
1589
    struct XLock : IDisposable
1590
    {
1591
        IntPtr _display;
1592
 
1593
        public IntPtr Display
1594
        {
1595
            get
1596
            {
1597
                if (_display == IntPtr.Zero)
1598
                    throw new InvalidOperationException("Internal error (XLockDisplay with IntPtr.Zero). Please report this at http://www.opentk.com/node/add/project-issue/opentk");
1599
                return _display;
1600
            }
1601
            set
1602
            {
1603
                if (value == IntPtr.Zero)
1604
                    throw new ArgumentException();
1605
                _display = value;
1606
            }
1607
        }
1608
 
1609
        public XLock(IntPtr display)
1610
            : this()
1611
        {
1612
            Display = display;
1613
            Functions.XLockDisplay(Display);
1614
        }
1615
 
1616
        public void Dispose()
1617
        {
1618
            Functions.XUnlockDisplay(Display);
1619
        }
1620
    }
1621
}
1622
 
1623
#pragma warning restore 3019
1624
#pragma warning restore 0649
1625
#pragma warning restore 0169
1626
#pragma warning restore 0414