00001 #region --- License ---
00002
00003
00004
00005
00006 #endregion
00007
00008 using System;
00009 using System.Collections.Generic;
00010 using System.Text;
00011 using System.Runtime.InteropServices;
00012 using System.Diagnostics;
00013
00014 #pragma warning disable 3019 // CLS-compliance checking
00015 #pragma warning disable 0649 // struct members not explicitly initialized
00016 #pragma warning disable 0169 // field / method is never used.
00017 #pragma warning disable 0414 // field assigned but never used.
00018
00019 namespace OpenTK.Platform.X11
00020 {
00021 #region Types
00022
00023
00024 using Window = System.IntPtr;
00025 using Drawable = System.IntPtr;
00026 using Font = System.IntPtr;
00027 using Pixmap = System.IntPtr;
00028 using Cursor = System.IntPtr;
00029 using Colormap = System.IntPtr;
00030 using GContext = System.IntPtr;
00031 using KeySym = System.IntPtr;
00032 using Mask = System.IntPtr;
00033 using Atom = System.IntPtr;
00034 using VisualID = System.IntPtr;
00035 using Time = System.IntPtr;
00036 using KeyCode = System.Byte;
00037
00038 using Display = System.IntPtr;
00039 using XPointer = System.IntPtr;
00040
00041
00042 using Bool = System.Boolean;
00043 using XRRScreenConfiguration = System.IntPtr;
00044 using Rotation = System.UInt16;
00045 using Status = System.Int32;
00046 using SizeID = System.UInt16;
00047
00048 #endregion
00049
00050 #region internal static class API
00051
00052 internal static class API
00053 {
00054 #region --- Fields ---
00055
00056 private const string _dll_name = "libX11";
00057 private const string _dll_name_vid = "libXxf86vm";
00058
00059 static Display defaultDisplay;
00060 static int defaultScreen;
00061 static Window rootWindow;
00062 static int screenCount;
00063
00064 internal static Display DefaultDisplay { get { return defaultDisplay; } }
00065 static int DefaultScreen { get { return defaultScreen; } }
00066
00067 internal static int ScreenCount { get { return screenCount; } }
00068
00069 internal static object Lock = new object();
00070
00071 #endregion
00072
00073 static API()
00074 {
00075 Debug.Print("Initializing threaded X11: {0}.", Functions.XInitThreads().ToString());
00076
00077 defaultDisplay = Functions.XOpenDisplay(IntPtr.Zero);
00078
00079 if (defaultDisplay == IntPtr.Zero)
00080 throw new PlatformException("Could not establish connection to the X-Server.");
00081
00082 using (new XLock(defaultDisplay))
00083 {
00084 screenCount = Functions.XScreenCount(DefaultDisplay);
00085 }
00086 Debug.Print("Display connection: {0}, Screen count: {1}", DefaultDisplay, ScreenCount);
00087
00088 AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);
00089 }
00090
00091 static void CurrentDomain_ProcessExit(object sender, EventArgs e)
00092 {
00093 if (defaultDisplay != IntPtr.Zero)
00094 {
00095 Functions.XCloseDisplay(defaultDisplay);
00096 defaultDisplay = IntPtr.Zero;
00097 defaultScreen = 0;
00098 rootWindow = IntPtr.Zero;
00099 }
00100 }
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 #region Window handling
00113
00114 [Obsolete("Use XCreateWindow instead")]
00115 [DllImport(_dll_name, EntryPoint = "XCreateWindow")]
00116 public extern static Window CreateWindow(
00117 Display display,
00118 Window parent,
00119 int x, int y,
00120
00121 int width, int height,
00122
00123 int border_width,
00124 int depth,
00125
00126 int @class,
00127 IntPtr visual,
00128 [MarshalAs(UnmanagedType.SysUInt)] CreateWindowMask valuemask,
00129 SetWindowAttributes attributes
00130 );
00131
00132 [DllImport(_dll_name, EntryPoint = "XCreateSimpleWindow")]
00133 public extern static Window CreateSimpleWindow(
00134 Display display,
00135 Window parent,
00136 int x, int y,
00137 int width, int height,
00138 int border_width,
00139 long border,
00140 long background
00141 );
00142
00143 [DllImport(_dll_name, EntryPoint = "XResizeWindow")]
00144 public extern static int XResizeWindow(Display display, Window window, int width, int height);
00145
00146 [DllImport(_dll_name, EntryPoint = "XDestroyWindow")]
00147 public extern static void DestroyWindow(Display display, Window window);
00148
00149 [DllImport(_dll_name, EntryPoint = "XMapWindow")]
00150 extern public static void MapWindow(Display display, Window window);
00151
00152 [DllImport(_dll_name, EntryPoint = "XMapRaised")]
00153 extern public static void MapRaised(Display display, Window window);
00154
00155 #endregion
00156
00157 [DllImport(_dll_name, EntryPoint = "XDefaultVisual")]
00158 extern public static IntPtr DefaultVisual(Display display, int screen_number);
00159
00160 #region XFree
00161
00166 [DllImport(_dll_name, EntryPoint = "XFree")]
00167 extern public static void Free(IntPtr buffer);
00168
00169 #endregion
00170
00171 #region Event queue management
00172
00173 [System.Security.SuppressUnmanagedCodeSecurity]
00174 [DllImport(_dll_name, EntryPoint = "XEventsQueued")]
00175 extern public static int EventsQueued(Display display, int mode);
00176
00177 [System.Security.SuppressUnmanagedCodeSecurity]
00178 [DllImport(_dll_name, EntryPoint = "XPending")]
00179 extern public static int Pending(Display display);
00180
00181
00182 [DllImport(_dll_name, EntryPoint = "XNextEvent")]
00183 extern public static void NextEvent(
00184 Display display,
00185 [MarshalAs(UnmanagedType.AsAny)][In, Out]object e);
00186
00187 [DllImport(_dll_name, EntryPoint = "XNextEvent")]
00188 extern public static void NextEvent(Display display, [In, Out] IntPtr e);
00189
00190 [DllImport(_dll_name, EntryPoint = "XPeekEvent")]
00191 extern public static void PeekEvent(
00192 Display display,
00193 [MarshalAs(UnmanagedType.AsAny)][In, Out]object event_return
00194 );
00195
00196 [DllImport(_dll_name, EntryPoint = "XPeekEvent")]
00197 extern public static void PeekEvent(Display display, [In, Out]XEvent event_return);
00198
00199 [DllImport(_dll_name, EntryPoint = "XSendEvent")]
00200 [return: MarshalAs(UnmanagedType.Bool)]
00201 extern public static bool SendEvent(Display display, Window window, bool propagate,
00202 [MarshalAs(UnmanagedType.SysInt)]EventMask event_mask, ref XEvent event_send);
00203
00225 [DllImport(_dll_name, EntryPoint = "XSelectInput")]
00226 public static extern void SelectInput(Display display, Window w, EventMask event_mask);
00227
00236 [DllImport(_dll_name, EntryPoint = "XCheckIfEvent")]
00237 [return: MarshalAs(UnmanagedType.Bool)]
00238 public static extern bool CheckIfEvent(Display display, ref XEvent event_return,
00239 CheckEventPredicate predicate, IntPtr arg);
00240
00241 [DllImport(_dll_name, EntryPoint = "XIfEvent")]
00242 [return: MarshalAs(UnmanagedType.Bool)]
00243 public static extern bool IfEvent(Display display, ref XEvent event_return,
00244 CheckEventPredicate predicate, IntPtr arg);
00245
00246 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
00247 public delegate bool CheckEventPredicate(Display display, ref XEvent @event, IntPtr arg);
00248
00249 [DllImport(_dll_name, EntryPoint = "XCheckMaskEvent")]
00250 [return: MarshalAs(UnmanagedType.Bool)]
00251 public static extern bool CheckMaskEvent(Display display, EventMask event_mask, ref XEvent event_return);
00252
00253 #endregion
00254
00255 #region Pointer and Keyboard functions
00256
00257 [DllImport(_dll_name, EntryPoint = "XGrabPointer")]
00258 extern public static ErrorCodes GrabPointer(Display display, IntPtr grab_window,
00259 bool owner_events, int event_mask, GrabMode pointer_mode, GrabMode keyboard_mode,
00260 IntPtr confine_to, IntPtr cursor, int time);
00261
00262 [DllImport(_dll_name, EntryPoint = "XUngrabPointer")]
00263 extern public static ErrorCodes UngrabPointer(Display display, int time);
00264
00265 [DllImport(_dll_name, EntryPoint = "XGrabKeyboard")]
00266 extern public static ErrorCodes GrabKeyboard(Display display, IntPtr grab_window,
00267 bool owner_events, GrabMode pointer_mode, GrabMode keyboard_mode, int time);
00268
00269 [DllImport(_dll_name, EntryPoint = "XUngrabKeyboard")]
00270 extern public static void UngrabKeyboard(Display display, int time);
00271
00292 [DllImport(_dll_name, EntryPoint = "XGetKeyboardMapping")]
00293 public static extern KeySym GetKeyboardMapping(Display display, KeyCode first_keycode, int keycode_count,
00294 ref int keysyms_per_keycode_return);
00295
00303 [DllImport(_dll_name, EntryPoint = "XDisplayKeycodes")]
00304 public static extern void DisplayKeycodes(Display display, ref int min_keycodes_return, ref int max_keycodes_return);
00305
00306 #endregion
00307
00308 #region Xf86VidMode internal structures
00309
00310 [StructLayout(LayoutKind.Sequential)]
00311 internal struct XF86VidModeModeLine
00312 {
00313 short hdisplay;
00314 short hsyncstart;
00315 short hsyncend;
00316 short htotal;
00317 short vdisplay;
00318 short vsyncstart;
00319 short vsyncend;
00320 short vtotal;
00321 int flags;
00322 int privsize;
00323 IntPtr _private;
00324 }
00325
00329 [StructLayout(LayoutKind.Sequential)]
00330 internal struct XF86VidModeModeInfo
00331 {
00335 public int dotclock;
00336
00340 public short hdisplay;
00341
00345 public short hsyncstart;
00346
00350 public short hsyncend;
00351
00355 public short htotal;
00356
00360 public short hskew;
00361
00365 public short vdisplay;
00366
00370 public short vsyncstart;
00371
00375 public short vsyncend;
00376
00380 public short vtotal;
00381
00385 public short vskew;
00386
00390 public int flags;
00391
00392 int privsize;
00393 IntPtr _private;
00394 }
00395
00396
00397 [StructLayout(LayoutKind.Sequential)]
00398 internal struct XF86VidModeMonitor
00399 {
00400 [MarshalAs(UnmanagedType.LPStr)]
00401 string vendor;
00402 [MarshalAs(UnmanagedType.LPStr)]
00403 string model;
00404 float EMPTY;
00405 byte nhsync;
00406
00407 IntPtr hsync;
00408 byte nvsync;
00409
00410 IntPtr vsync;
00411 }
00412
00413 [StructLayout(LayoutKind.Sequential)]
00414 internal struct XF86VidModeSyncRange
00415 {
00416 float hi;
00417 float lo;
00418 }
00419
00420 [StructLayout(LayoutKind.Sequential)]
00421 internal struct XF86VidModeNotifyEvent
00422 {
00423 int type;
00424 ulong serial;
00425 bool send_event;
00426 Display display;
00427 IntPtr root;
00428 int state;
00429 int kind;
00430 bool forced;
00431
00432 IntPtr time;
00433 }
00434
00435 [StructLayout(LayoutKind.Sequential)]
00436 internal struct XF86VidModeGamma
00437 {
00438 float red;
00439 float green;
00440 float blue;
00441 }
00442 #endregion
00443
00444 #region libXxf86vm Functions
00445
00446 [DllImport(_dll_name_vid)]
00447 extern public static bool XF86VidModeQueryExtension(
00448 Display display,
00449 out int event_base_return,
00450 out int error_base_return);
00451
00452
00453
00454
00455
00456
00457
00458
00459 [DllImport(_dll_name_vid)]
00460 extern public static bool XF86VidModeSwitchToMode(
00461 Display display,
00462 int screen,
00463 IntPtr
00464 modeline);
00465
00466
00467 [DllImport(_dll_name_vid)]
00468 extern public static bool XF86VidModeQueryVersion(
00469 Display display,
00470 out int major_version_return,
00471 out int minor_version_return);
00472
00473 [DllImport(_dll_name_vid)]
00474 extern public static bool XF86VidModeGetAllModeLines(
00475 Display display,
00476 int screen,
00477 out int modecount_return,
00478
00479 out IntPtr modesinfo);
00480
00481 [DllImport(_dll_name_vid)]
00482 extern public static bool XF86VidModeSetViewPort(
00483 Display display,
00484 int screen,
00485 int x,
00486 int y);
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571 #endregion
00572
00573 [DllImport(_dll_name, EntryPoint = "XLookupKeysym")]
00574 public static extern KeySym LookupKeysym(ref XKeyEvent key_event, int index);
00575
00576 }
00577 #endregion
00578
00579 #region X11 Structures
00580
00581 #region internal class XVisualInfo
00582
00583 [StructLayout(LayoutKind.Sequential)]
00584 struct XVisualInfo
00585 {
00586 public IntPtr Visual;
00587 public VisualID VisualID;
00588 public int Screen;
00589 public int Depth;
00590 public XVisualClass Class;
00591 public long RedMask;
00592 public long GreenMask;
00593 public long blueMask;
00594 public int ColormapSize;
00595 public int BitsPerRgb;
00596
00597 public override string ToString()
00598 {
00599 return String.Format("id ({0}), screen ({1}), depth ({2}), class ({3})",
00600 VisualID, Screen, Depth, Class);
00601 }
00602 }
00603
00604 #endregion
00605
00606 #region internal class SetWindowAttributes
00607
00608 [StructLayout(LayoutKind.Sequential), Obsolete("Use XSetWindowAttributes instead")]
00609 internal class SetWindowAttributes
00610 {
00614 public Pixmap background_pixmap;
00618 public long background_pixel;
00622 public Pixmap border_pixmap;
00626 public long border_pixel;
00630 public int bit_gravity;
00634 public int win_gravity;
00638 public int backing_store;
00642 public long backing_planes;
00646 public long backing_pixel;
00650 public bool save_under;
00654 public EventMask event_mask;
00658 public long do_not_propagate_mask;
00662 public bool override_redirect;
00666 public Colormap colormap;
00670 public Cursor cursor;
00671 }
00672
00673 #endregion
00674
00675 #region internal struct SizeHints
00676
00677 [StructLayout(LayoutKind.Sequential)]
00678 internal struct SizeHints
00679 {
00680 public long flags;
00681 public int x, y;
00682 public int width, height;
00683 public int min_width, min_height;
00684 public int max_width, max_height;
00685 public int width_inc, height_inc;
00686 public Rectangle min_aspect, max_aspect;
00687 public int base_width, base_height;
00688 public int win_gravity;
00689 internal struct Rectangle
00690 {
00691 public int x;
00692 public int y;
00693 private void stop_the_compiler_warnings() { x = y = 0; }
00694 }
00695
00696 }
00697
00698 #endregion
00699
00700 #region internal struct XRRScreenSize
00701
00702 internal struct XRRScreenSize
00703 {
00704 internal int Width, Height;
00705 internal int MWidth, MHeight;
00706 };
00707
00708 #endregion
00709
00710 #region unsafe internal struct Screen
00711
00712 unsafe internal struct Screen
00713 {
00714 XExtData ext_data;
00715 IntPtr display;
00716 Window root;
00717 int width, height;
00718 int mwidth, mheight;
00719 int ndepths;
00720
00721 int root_depth;
00722
00723 IntPtr default_gc;
00724 Colormap cmap;
00725 UIntPtr white_pixel;
00726 UIntPtr black_pixel;
00727 int max_maps, min_maps;
00728 int backing_store;
00729 Bool save_unders;
00730 long root_input_mask;
00731 }
00732
00733 #endregion
00734
00735 #region unsafe internal class XExtData
00736
00737 unsafe internal class XExtData
00738 {
00739 int number;
00740 XExtData next;
00741 delegate int FreePrivateDelegate(XExtData extension);
00742 FreePrivateDelegate FreePrivate;
00743 XPointer private_data;
00744 };
00745
00746 #endregion
00747
00748 #region Motif
00749
00750 [StructLayout(LayoutKind.Sequential)]
00751 internal struct MotifWmHints
00752 {
00753 internal IntPtr flags;
00754 internal IntPtr functions;
00755 internal IntPtr decorations;
00756 internal IntPtr input_mode;
00757 internal IntPtr status;
00758
00759 public override string ToString ()
00760 {
00761 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 ());
00762 }
00763 }
00764
00765 [Flags]
00766 internal enum MotifFlags
00767 {
00768 Functions = 1,
00769 Decorations = 2,
00770 InputMode = 4,
00771 Status = 8
00772 }
00773
00774 [Flags]
00775 internal enum MotifFunctions
00776 {
00777 All = 0x01,
00778 Resize = 0x02,
00779 Move = 0x04,
00780 Minimize = 0x08,
00781 Maximize = 0x10,
00782 Close = 0x20
00783 }
00784
00785 [Flags]
00786 internal enum MotifDecorations
00787 {
00788 All = 0x01,
00789 Border = 0x02,
00790 ResizeH = 0x04,
00791 Title = 0x08,
00792 Menu = 0x10,
00793 Minimize = 0x20,
00794 Maximize = 0x40,
00795
00796 }
00797
00798 [Flags]
00799 internal enum MotifInputMode
00800 {
00801 Modeless = 0,
00802 ApplicationModal = 1,
00803 SystemModal = 2,
00804 FullApplicationModal = 3
00805 }
00806
00807 #endregion
00808
00809 #endregion
00810
00811 #region X11 Constants and Enums
00812
00813 internal struct Constants
00814 {
00815 public const int QueuedAlready = 0;
00816 public const int QueuedAfterReading = 1;
00817 public const int QueuedAfterFlush = 2;
00818
00819 public const int CopyFromParent = 0;
00820 public const int CWX = 1;
00821 public const int InputOutput = 1;
00822 public const int InputOnly = 2;
00823
00824
00825 public const string XA_WIN_PROTOCOLS = "_WIN_PROTOCOLS";
00826 public const string XA_WIN_ICONS = "_WIN_ICONS";
00827 public const string XA_WIN_WORKSPACE = "_WIN_WORKSPACE";
00828 public const string XA_WIN_WORKSPACE_COUNT = "_WIN_WORKSPACE_COUNT";
00829 public const string XA_WIN_WORKSPACE_NAMES = "_WIN_WORKSPACE_NAMES";
00830 public const string XA_WIN_LAYER = "_WIN_LAYER";
00831 public const string XA_WIN_STATE = "_WIN_STATE";
00832 public const string XA_WIN_HINTS = "_WIN_HINTS";
00833 public const string XA_WIN_WORKAREA = "_WIN_WORKAREA";
00834 public const string XA_WIN_CLIENT_LIST = "_WIN_CLIENT_LIST";
00835 public const string XA_WIN_APP_STATE = "_WIN_APP_STATE";
00836 public const string XA_WIN_EXPANDED_SIZE = "_WIN_EXPANDED_SIZE";
00837 public const string XA_WIN_CLIENT_MOVING = "_WIN_CLIENT_MOVING";
00838 public const string XA_WIN_SUPPORTING_WM_CHECK = "_WIN_SUPPORTING_WM_CHECK";
00839 }
00840
00841 internal enum WindowLayer
00842 {
00843 Desktop = 0,
00844 Below = 2,
00845 Normal = 4,
00846 OnTop = 6,
00847 Dock = 8,
00848 AboveDock = 10,
00849 Menu = 12,
00850 }
00851
00852 internal enum WindowState
00853 {
00854 Sticky = (1<<0),
00855 Minimized = (1<<1),
00856 MaximizedVertically = (1<<2),
00857 MaximizedHorizontally = (1<<3),
00858 Hidden = (1<<4),
00859 Shaded = (1<<5),
00860 HID_WORKSPACE = (1<<6),
00861 HID_TRANSIENT = (1<<7),
00862 FixedPosition = (1<<8),
00863 ArrangeIgnore = (1<<9),
00864 }
00865
00866 internal enum WindowHints
00867 {
00868 SkipFocus = (1<<0),
00869 SkipWinlist = (1<<1),
00870 SkipTaskbar = (1<<2),
00871 GroupTransient = (1<<3),
00872 FocusOnClick = (1<<4),
00873 DoNotCover = (1<<5),
00874 }
00875
00876 internal enum ErrorCodes : int
00877 {
00878 Success = 0,
00879 BadRequest = 1,
00880 BadValue = 2,
00881 BadWindow = 3,
00882 BadPixmap = 4,
00883 BadAtom = 5,
00884 BadCursor = 6,
00885 BadFont = 7,
00886 BadMatch = 8,
00887 BadDrawable = 9,
00888 BadAccess = 10,
00889 BadAlloc = 11,
00890 BadColor = 12,
00891 BadGC = 13,
00892 BadIDChoice = 14,
00893 BadName = 15,
00894 BadLength = 16,
00895 BadImplementation = 17,
00896 }
00897
00898 [Flags]
00899 internal enum CreateWindowMask : long
00900 {
00901 CWBackPixmap = (1L<<0),
00902 CWBackPixel = (1L<<1),
00903 CWSaveUnder = (1L<<10),
00904 CWEventMask = (1L<<11),
00905 CWDontPropagate = (1L<<12),
00906 CWColormap = (1L<<13),
00907 CWCursor = (1L<<14),
00908 CWBorderPixmap = (1L<<2),
00909 CWBorderPixel = (1L<<3),
00910 CWBitGravity = (1L<<4),
00911 CWWinGravity = (1L<<5),
00912 CWBackingStore = (1L<<6),
00913 CWBackingPlanes = (1L<<7),
00914 CWBackingPixel = (1L<<8),
00915 CWOverrideRedirect = (1L<<9),
00916
00917
00918
00919
00920
00921
00922
00923 }
00924
00925 #region XKey
00926
00930 [CLSCompliant(false)]
00931 internal enum XKey
00932 {
00933
00934
00935
00936
00937
00938
00939 BackSpace = 0xff08,
00940 Tab = 0xff09,
00941 Linefeed = 0xff0a,
00942 Clear = 0xff0b,
00943 Return = 0xff0d,
00944 Pause = 0xff13,
00945 Scroll_Lock = 0xff14,
00946 Sys_Req = 0xff15,
00947 Escape = 0xff1b,
00948 Delete = 0xffff,
00949
00950
00951
00952
00953
00954 Multi_key = 0xff20,
00955 Codeinput = 0xff37,
00956 SingleCandidate = 0xff3c,
00957 MultipleCandidate = 0xff3d,
00958 PreviousCandidate = 0xff3e,
00959
00960
00961
00962 Kanji = 0xff21,
00963 Muhenkan = 0xff22,
00964 Henkan_Mode = 0xff23,
00965 Henkan = 0xff23,
00966 Romaji = 0xff24,
00967 Hiragana = 0xff25,
00968 Katakana = 0xff26,
00969 Hiragana_Katakana = 0xff27,
00970 Zenkaku = 0xff28,
00971 Hankaku = 0xff29,
00972 Zenkaku_Hankaku = 0xff2a,
00973 Touroku = 0xff2b,
00974 Massyo = 0xff2c,
00975 Kana_Lock = 0xff2d,
00976 Kana_Shift = 0xff2e,
00977 Eisu_Shift = 0xff2f,
00978 Eisu_toggle = 0xff30,
00979 Kanji_Bangou = 0xff37,
00980 Zen_Koho = 0xff3d,
00981 Mae_Koho = 0xff3e,
00982
00983
00984
00985
00986
00987 Home = 0xff50,
00988 Left = 0xff51,
00989 Up = 0xff52,
00990 Right = 0xff53,
00991 Down = 0xff54,
00992 Prior = 0xff55,
00993 Page_Up = 0xff55,
00994 Next = 0xff56,
00995 Page_Down = 0xff56,
00996 End = 0xff57,
00997 Begin = 0xff58,
00998
00999
01000
01001
01002 Select = 0xff60,
01003 Print = 0xff61,
01004 Execute = 0xff62,
01005 Insert = 0xff63,
01006 Undo = 0xff65,
01007 Redo = 0xff66,
01008 Menu = 0xff67,
01009 Find = 0xff68,
01010 Cancel = 0xff69,
01011 Help = 0xff6a,
01012 Break = 0xff6b,
01013 Mode_switch = 0xff7e,
01014 script_switch = 0xff7e,
01015 Num_Lock = 0xff7f,
01016
01017
01018
01019 KP_Space = 0xff80,
01020 KP_Tab = 0xff89,
01021 KP_Enter = 0xff8d,
01022 KP_F1 = 0xff91,
01023 KP_F2 = 0xff92,
01024 KP_F3 = 0xff93,
01025 KP_F4 = 0xff94,
01026 KP_Home = 0xff95,
01027 KP_Left = 0xff96,
01028 KP_Up = 0xff97,
01029 KP_Right = 0xff98,
01030 KP_Down = 0xff99,
01031 KP_Prior = 0xff9a,
01032 KP_Page_Up = 0xff9a,
01033 KP_Next = 0xff9b,
01034 KP_Page_Down = 0xff9b,
01035 KP_End = 0xff9c,
01036 KP_Begin = 0xff9d,
01037 KP_Insert = 0xff9e,
01038 KP_Delete = 0xff9f,
01039 KP_Equal = 0xffbd,
01040 KP_Multiply = 0xffaa,
01041 KP_Add = 0xffab,
01042 KP_Separator = 0xffac,
01043 KP_Subtract = 0xffad,
01044 KP_Decimal = 0xffae,
01045 KP_Divide = 0xffaf,
01046
01047 KP_0 = 0xffb0,
01048 KP_1 = 0xffb1,
01049 KP_2 = 0xffb2,
01050 KP_3 = 0xffb3,
01051 KP_4 = 0xffb4,
01052 KP_5 = 0xffb5,
01053 KP_6 = 0xffb6,
01054 KP_7 = 0xffb7,
01055 KP_8 = 0xffb8,
01056 KP_9 = 0xffb9,
01057
01058
01059
01060
01061
01062
01063
01064
01065 F1 = 0xffbe,
01066 F2 = 0xffbf,
01067 F3 = 0xffc0,
01068 F4 = 0xffc1,
01069 F5 = 0xffc2,
01070 F6 = 0xffc3,
01071 F7 = 0xffc4,
01072 F8 = 0xffc5,
01073 F9 = 0xffc6,
01074 F10 = 0xffc7,
01075 F11 = 0xffc8,
01076 L1 = 0xffc8,
01077 F12 = 0xffc9,
01078 L2 = 0xffc9,
01079 F13 = 0xffca,
01080 L3 = 0xffca,
01081 F14 = 0xffcb,
01082 L4 = 0xffcb,
01083 F15 = 0xffcc,
01084 L5 = 0xffcc,
01085 F16 = 0xffcd,
01086 L6 = 0xffcd,
01087 F17 = 0xffce,
01088 L7 = 0xffce,
01089 F18 = 0xffcf,
01090 L8 = 0xffcf,
01091 F19 = 0xffd0,
01092 L9 = 0xffd0,
01093 F20 = 0xffd1,
01094 L10 = 0xffd1,
01095 F21 = 0xffd2,
01096 R1 = 0xffd2,
01097 F22 = 0xffd3,
01098 R2 = 0xffd3,
01099 F23 = 0xffd4,
01100 R3 = 0xffd4,
01101 F24 = 0xffd5,
01102 R4 = 0xffd5,
01103 F25 = 0xffd6,
01104 R5 = 0xffd6,
01105 F26 = 0xffd7,
01106 R6 = 0xffd7,
01107 F27 = 0xffd8,
01108 R7 = 0xffd8,
01109 F28 = 0xffd9,
01110 R8 = 0xffd9,
01111 F29 = 0xffda,
01112 R9 = 0xffda,
01113 F30 = 0xffdb,
01114 R10 = 0xffdb,
01115 F31 = 0xffdc,
01116 R11 = 0xffdc,
01117 F32 = 0xffdd,
01118 R12 = 0xffdd,
01119 F33 = 0xffde,
01120 R13 = 0xffde,
01121 F34 = 0xffdf,
01122 R14 = 0xffdf,
01123 F35 = 0xffe0,
01124 R15 = 0xffe0,
01125
01126
01127
01128 Shift_L = 0xffe1,
01129 Shift_R = 0xffe2,
01130 Control_L = 0xffe3,
01131 Control_R = 0xffe4,
01132 Caps_Lock = 0xffe5,
01133 Shift_Lock = 0xffe6,
01134
01135 Meta_L = 0xffe7,
01136 Meta_R = 0xffe8,
01137 Alt_L = 0xffe9,
01138 Alt_R = 0xffea,
01139 Super_L = 0xffeb,
01140 Super_R = 0xffec,
01141 Hyper_L = 0xffed,
01142 Hyper_R = 0xffee,
01143
01144
01145
01146
01147
01148
01149
01150 space = 0x0020,
01151 exclam = 0x0021,
01152 quotedbl = 0x0022,
01153 numbersign = 0x0023,
01154 dollar = 0x0024,
01155 percent = 0x0025,
01156 ampersand = 0x0026,
01157 apostrophe = 0x0027,
01158 quoteright = 0x0027,
01159 parenleft = 0x0028,
01160 parenright = 0x0029,
01161 asterisk = 0x002a,
01162 plus = 0x002b,
01163 comma = 0x002c,
01164 minus = 0x002d,
01165 period = 0x002e,
01166 slash = 0x002f,
01167 Number0 = 0x0030,
01168 Number1 = 0x0031,
01169 Number2 = 0x0032,
01170 Number3 = 0x0033,
01171 Number4 = 0x0034,
01172 Number5 = 0x0035,
01173 Number6 = 0x0036,
01174 Number7 = 0x0037,
01175 Number8 = 0x0038,
01176 Number9 = 0x0039,
01177 colon = 0x003a,
01178 semicolon = 0x003b,
01179 less = 0x003c,
01180 equal = 0x003d,
01181 greater = 0x003e,
01182 question = 0x003f,
01183 at = 0x0040,
01184 A = 0x0041,
01185 B = 0x0042,
01186 C = 0x0043,
01187 D = 0x0044,
01188 E = 0x0045,
01189 F = 0x0046,
01190 G = 0x0047,
01191 H = 0x0048,
01192 I = 0x0049,
01193 J = 0x004a,
01194 K = 0x004b,
01195 L = 0x004c,
01196 M = 0x004d,
01197 N = 0x004e,
01198 O = 0x004f,
01199 P = 0x0050,
01200 Q = 0x0051,
01201 R = 0x0052,
01202 S = 0x0053,
01203 T = 0x0054,
01204 U = 0x0055,
01205 V = 0x0056,
01206 W = 0x0057,
01207 X = 0x0058,
01208 Y = 0x0059,
01209 Z = 0x005a,
01210 bracketleft = 0x005b,
01211 backslash = 0x005c,
01212 bracketright = 0x005d,
01213 asciicircum = 0x005e,
01214 underscore = 0x005f,
01215 grave = 0x0060,
01216 quoteleft = 0x0060,
01217 a = 0x0061,
01218 b = 0x0062,
01219 c = 0x0063,
01220 d = 0x0064,
01221 e = 0x0065,
01222 f = 0x0066,
01223 g = 0x0067,
01224 h = 0x0068,
01225 i = 0x0069,
01226 j = 0x006a,
01227 k = 0x006b,
01228 l = 0x006c,
01229 m = 0x006d,
01230 n = 0x006e,
01231 o = 0x006f,
01232 p = 0x0070,
01233 q = 0x0071,
01234 r = 0x0072,
01235 s = 0x0073,
01236 t = 0x0074,
01237 u = 0x0075,
01238 v = 0x0076,
01239 w = 0x0077,
01240 x = 0x0078,
01241 y = 0x0079,
01242 z = 0x007a,
01243 braceleft = 0x007b,
01244 bar = 0x007c,
01245 braceright = 0x007d,
01246 asciitilde = 0x007e,
01247 }
01248
01249 #endregion
01250
01251 #pragma warning disable 1591
01252
01253 public enum XVisualClass : int
01254 {
01255 StaticGray = 0,
01256 GrayScale = 1,
01257 StaticColor = 2,
01258 PseudoColor = 3,
01259 TrueColor = 4,
01260 DirectColor = 5,
01261 }
01262
01263 #pragma warning restore 1591
01264
01265 [Flags]
01266 internal enum XVisualInfoMask
01267 {
01268 No = 0x0,
01269 ID = 0x1,
01270 Screen = 0x2,
01271 Depth = 0x4,
01272 Class = 0x8,
01273 Red = 0x10,
01274 Green = 0x20,
01275 Blue = 0x40,
01276 ColormapSize = 0x80,
01277 BitsPerRGB = 0x100,
01278 All = 0x1FF,
01279 }
01280
01281 #region internal enum MouseMask
01282
01283 internal enum MouseMask
01284 {
01285 Button1MotionMask = (1 << 8),
01286 Button2MotionMask = (1 << 9),
01287 Button3MotionMask = (1 << 10),
01288 Button4MotionMask = (1 << 11),
01289 Button5MotionMask = (1 << 12),
01290 Button1Mask = (1 << 8),
01291 Button2Mask = (1 << 9),
01292 Button3Mask = (1 << 10),
01293 Button4Mask = (1 << 11),
01294 Button5Mask = (1 << 12),
01295 Button6Mask = (1 << 13),
01296 Button7Mask = (1 << 14),
01297 Button8Mask = (1 << 15),
01298 ShiftMask = (1 << 0),
01299 LockMask = (1 << 1),
01300 ControlMask = (1 << 2),
01301 Mod1Mask = (1 << 3),
01302 Mod2Mask = (1 << 4),
01303 Mod3Mask = (1 << 5),
01304 Mod4Mask = (1 << 6),
01305 Mod5Mask = (1 << 7),
01306 }
01307
01308 #endregion
01309
01310 #endregion
01311
01312 internal static partial class Functions
01313 {
01314 internal const string X11Library = "libX11";
01315
01316 #region XCreateWindow
01317
01342 [DllImport(X11Library, EntryPoint = "XCreateWindow")]
01343 public extern static Window XCreateWindow(Display display, Window parent,
01344 int x, int y, int width, int height, int border_width, int depth,
01345 int @class, IntPtr visual, UIntPtr valuemask, ref XSetWindowAttributes attributes);
01346
01347 #endregion
01348
01349 #region XChangeWindowAttributes
01350
01351 [DllImport(X11Library)]
01352 internal static extern void XChangeWindowAttributes(Display display, Window w, UIntPtr valuemask, ref XSetWindowAttributes attributes);
01353
01354 internal static void XChangeWindowAttributes(Display display, Window w, SetWindowValuemask valuemask, ref XSetWindowAttributes attributes)
01355 {
01356 XChangeWindowAttributes(display, w, (UIntPtr)valuemask, ref attributes);
01357 }
01358
01359 #endregion
01360
01361 #region XQueryKeymap
01362
01363
01370
01371
01372
01373
01380 [DllImport(X11Library, EntryPoint = "XQueryKeymap")]
01381 extern public static void XQueryKeymap(IntPtr display, byte[] keys);
01382
01383 #endregion
01384
01385 #region XMaskEvent
01386
01393 [DllImport(X11Library, EntryPoint = "XMaskEvent")]
01394 extern public static void XMaskEvent(IntPtr display, EventMask event_mask, ref XEvent e);
01395
01396 #endregion
01397
01398 #region XPutBackEvent
01399
01405 [DllImport(X11Library, EntryPoint = "XPutBackEvent")]
01406 public static extern void XPutBackEvent(IntPtr display, ref XEvent @event);
01407
01408 #endregion
01409
01410 #region Xrandr
01411
01412 const string XrandrLibrary = "libXrandr.so.2";
01413
01414 [DllImport(XrandrLibrary)]
01415 public static extern Bool XRRQueryExtension(Display dpy, ref int event_basep, ref int error_basep);
01416
01417 [DllImport(XrandrLibrary)]
01418 public static extern Status XRRQueryVersion(Display dpy, ref int major_versionp, ref int minor_versionp);
01419
01420 [DllImport(XrandrLibrary)]
01421 public static extern XRRScreenConfiguration XRRGetScreenInfo(Display dpy, Drawable draw);
01422
01423 [DllImport(XrandrLibrary)]
01424 public static extern void XRRFreeScreenConfigInfo(XRRScreenConfiguration config);
01425
01426 [DllImport(XrandrLibrary)]
01427 public static extern Status XRRSetScreenConfig(Display dpy, XRRScreenConfiguration config,
01428 Drawable draw, int size_index, ref Rotation rotation, Time timestamp);
01429
01430 [DllImport(XrandrLibrary)]
01431 public static extern Status XRRSetScreenConfigAndRate(Display dpy, XRRScreenConfiguration config,
01432 Drawable draw, int size_index, Rotation rotation, short rate, Time timestamp);
01433
01434 [DllImport(XrandrLibrary)]
01435 public static extern Rotation XRRConfigRotations(XRRScreenConfiguration config, ref Rotation current_rotation);
01436
01437 [DllImport(XrandrLibrary)]
01438 public static extern Time XRRConfigTimes(XRRScreenConfiguration config, ref Time config_timestamp);
01439
01440 [DllImport(XrandrLibrary)]
01441 [return: MarshalAs(UnmanagedType.LPStruct)]
01442 public static extern XRRScreenSize XRRConfigSizes(XRRScreenConfiguration config, int[] nsizes);
01443
01444 [DllImport(XrandrLibrary)]
01445 unsafe public static extern short* XRRConfigRates(XRRScreenConfiguration config, int size_index, int[] nrates);
01446
01447 [DllImport(XrandrLibrary)]
01448 public static extern SizeID XRRConfigCurrentConfiguration(XRRScreenConfiguration config, out Rotation rotation);
01449
01450 [DllImport(XrandrLibrary)]
01451 public static extern short XRRConfigCurrentRate(XRRScreenConfiguration config);
01452
01453 [DllImport(XrandrLibrary)]
01454 public static extern int XRRRootToScreen(Display dpy, Window root);
01455
01456 [DllImport(XrandrLibrary)]
01457 public static extern XRRScreenConfiguration XRRScreenConfig(Display dpy, int screen);
01458
01459 [DllImport(XrandrLibrary)]
01460 public static extern XRRScreenConfiguration XRRConfig(ref Screen screen);
01461
01462 [DllImport(XrandrLibrary)]
01463 public static extern void XRRSelectInput(Display dpy, Window window, int mask);
01464
01465
01466
01467
01468
01469
01470 [DllImport(XrandrLibrary)]
01471 public static extern int XRRUpdateConfiguration(ref XEvent @event);
01472
01473
01474
01475
01476
01477 [DllImport(XrandrLibrary)]
01478 public static extern Rotation XRRRotations(Display dpy, int screen, ref Rotation current_rotation);
01479
01480 [DllImport(XrandrLibrary)]
01481 unsafe static extern IntPtr XRRSizes(Display dpy, int screen, int* nsizes);
01482
01483 public static XRRScreenSize[] XRRSizes(Display dpy, int screen)
01484 {
01485 XRRScreenSize[] sizes;
01486
01487 int count;
01488 unsafe
01489 {
01490
01491
01492 byte* data = (byte*)XRRSizes(dpy, screen, &count);
01493 if (count == 0)
01494 return null;
01495 sizes = new XRRScreenSize[count];
01496 for (int i = 0; i < count; i++)
01497 {
01498 sizes[i] = new XRRScreenSize();
01499 sizes[i] = (XRRScreenSize)Marshal.PtrToStructure((IntPtr)data, typeof(XRRScreenSize));
01500 data += Marshal.SizeOf(typeof(XRRScreenSize));
01501 }
01502
01503 return sizes;
01504 }
01505 }
01506
01507 [DllImport(XrandrLibrary)]
01508 unsafe static extern short* XRRRates(Display dpy, int screen, int size_index, int* nrates);
01509
01510 public static short[] XRRRates(Display dpy, int screen, int size_index)
01511 {
01512 short[] rates;
01513 int count;
01514 unsafe
01515 {
01516 short* data = (short*)XRRRates(dpy, screen, size_index, &count);
01517 if (count == 0)
01518 return null;
01519 rates = new short[count];
01520 for (int i = 0; i < count; i++)
01521 rates[i] = *(data + i);
01522 }
01523 return rates;
01524 }
01525
01526 [DllImport(XrandrLibrary)]
01527 public static extern Time XRRTimes(Display dpy, int screen, out Time config_timestamp);
01528
01529 #endregion
01530
01531 #region Display, Screen and Window functions
01532
01533 #region XScreenCount
01534
01535 [DllImport(X11Library)]
01536 public static extern int XScreenCount(Display display);
01537
01538 #endregion
01539
01540 #region XListDepths
01541
01542 [DllImport(X11Library)]
01543 unsafe static extern int *XListDepths(Display display, int screen_number, int* count_return);
01544
01545 public static int[] XListDepths(Display display, int screen_number)
01546 {
01547 unsafe
01548 {
01549 int count;
01550 int* data = XListDepths(display, screen_number, &count);
01551 if (count == 0)
01552 return null;
01553 int[] depths = new int[count];
01554 for (int i = 0; i < count; i++)
01555 depths[i] = *(data + i);
01556
01557 return depths;
01558 }
01559 }
01560
01561 #endregion
01562
01563 #endregion
01564 }
01565
01566
01567
01568
01569
01570
01571
01572
01573
01574
01575
01576
01577
01578
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588 struct XLock : IDisposable
01589 {
01590 IntPtr _display;
01591
01592 public IntPtr Display
01593 {
01594 get
01595 {
01596 if (_display == IntPtr.Zero)
01597 throw new InvalidOperationException("Internal error (XLockDisplay with IntPtr.Zero). Please report this at http://www.opentk.com/node/add/project-issue/opentk");
01598 return _display;
01599 }
01600 set
01601 {
01602 if (value == IntPtr.Zero)
01603 throw new ArgumentException();
01604 _display = value;
01605 }
01606 }
01607
01608 public XLock(IntPtr display)
01609 : this()
01610 {
01611 Display = display;
01612 Functions.XLockDisplay(Display);
01613 }
01614
01615 public void Dispose()
01616 {
01617 Functions.XUnlockDisplay(Display);
01618 }
01619 }
01620 }
01621
01622 #pragma warning restore 3019
01623 #pragma warning restore 0649
01624 #pragma warning restore 0169
01625 #pragma warning restore 0414