XplatUIX11.cs 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. // Permission is hereby granted, free of charge, to any person obtaining
  2. // a copy of this software and associated documentation files (the
  3. // "Software"), to deal in the Software without restriction, including
  4. // without limitation the rights to use, copy, modify, merge, publish,
  5. // distribute, sublicense, and/or sell copies of the Software, and to
  6. // permit persons to whom the Software is furnished to do so, subject to
  7. // the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be
  10. // included in all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. // Copyright (c) 2004 Novell, Inc.
  21. //
  22. // Authors:
  23. // Peter Bartok [email protected]
  24. //
  25. //
  26. // NOT COMPLETE
  27. using System;
  28. using System.Threading;
  29. using System.Drawing;
  30. using System.ComponentModel;
  31. using System.Collections;
  32. using System.Diagnostics;
  33. using System.Runtime.InteropServices;
  34. /// X11 Version
  35. namespace System.Windows.Forms {
  36. internal class XplatUIX11 : XplatUIDriver {
  37. #region Local Variables
  38. private static XplatUIX11 instance;
  39. private static int ref_count;
  40. private static bool themes_enabled;
  41. private static IntPtr DisplayHandle; // X11 handle to display
  42. private static IntPtr root_window; // Handle of the root window for the screen/display
  43. private static IntPtr FosterParent; // Container to hold child windows until their parent exists
  44. private static int wm_protocols; // X Atom
  45. private static int wm_delete_window; // X Atom
  46. private static IntPtr async_method;
  47. private static uint default_colormap; // X Colormap ID
  48. internal static Keys key_state;
  49. internal static MouseButtons mouse_state;
  50. internal static Point mouse_position;
  51. internal static bool grab_confined; // Is the current grab (if any) confined to grab_area?
  52. internal static IntPtr grab_hwnd; // The window that is grabbed
  53. internal static Rectangle grab_area; // The area the current grab is confined to
  54. internal static bool is_visible;
  55. private static Hashtable handle_data;
  56. private Queue message_queue;
  57. private ArrayList timer_list;
  58. private Thread timer_thread;
  59. private AutoResetEvent timer_wait;
  60. private static readonly EventMask SelectInputMask = EventMask.ButtonPressMask |
  61. EventMask.ButtonReleaseMask |
  62. EventMask.KeyPressMask |
  63. EventMask.KeyReleaseMask |
  64. EventMask.EnterWindowMask |
  65. EventMask.LeaveWindowMask |
  66. EventMask.ExposureMask |
  67. EventMask.PointerMotionMask |
  68. EventMask.VisibilityChangeMask |
  69. EventMask.StructureNotifyMask;
  70. #endregion // Local Variables
  71. internal override Keys ModifierKeys {
  72. get {
  73. return key_state;
  74. }
  75. }
  76. internal override MouseButtons MouseButtons {
  77. get {
  78. return mouse_state;
  79. }
  80. }
  81. internal override Point MousePosition {
  82. get {
  83. return mouse_position;
  84. }
  85. }
  86. internal override bool DropTarget {
  87. get {
  88. return false;
  89. }
  90. set {
  91. if (value) {
  92. throw new NotImplementedException("Need to figure out D'n'D for X11");
  93. }
  94. }
  95. }
  96. #region Constructor & Destructor
  97. // This is always called from a locked context
  98. private XplatUIX11() {
  99. // Handle singleton stuff first
  100. ref_count=0;
  101. message_queue = new Queue ();
  102. ArrayList timers = new ArrayList ();
  103. timer_list = ArrayList.Synchronized (timers);
  104. // Now regular initialization
  105. SetDisplay(XOpenDisplay(IntPtr.Zero));
  106. }
  107. ~XplatUIX11() {
  108. lock (this) {
  109. if (DisplayHandle!=IntPtr.Zero) {
  110. XCloseDisplay(DisplayHandle);
  111. DisplayHandle=IntPtr.Zero;
  112. }
  113. }
  114. }
  115. #endregion // Constructor & Destructor
  116. #region Singleton Specific Code
  117. public static XplatUIX11 GetInstance() {
  118. lock (typeof (XplatUIX11)) {
  119. if (instance==null) {
  120. instance=new XplatUIX11();
  121. }
  122. ref_count++;
  123. }
  124. return instance;
  125. }
  126. public int Reference {
  127. get {
  128. return ref_count;
  129. }
  130. }
  131. #endregion
  132. #region Public Static Methods
  133. internal override IntPtr InitializeDriver() {
  134. lock (this) {
  135. if (DisplayHandle==IntPtr.Zero) {
  136. DisplayHandle=XOpenDisplay(IntPtr.Zero);
  137. key_state=Keys.None;
  138. mouse_state=MouseButtons.None;
  139. mouse_position=Point.Empty;
  140. }
  141. }
  142. return IntPtr.Zero;
  143. }
  144. internal static void SetDisplay(IntPtr display_handle) {
  145. if (display_handle != IntPtr.Zero) {
  146. if (FosterParent != IntPtr.Zero) {
  147. XDestroyWindow(DisplayHandle, FosterParent);
  148. }
  149. if (DisplayHandle != IntPtr.Zero) {
  150. XCloseDisplay(DisplayHandle);
  151. }
  152. DisplayHandle=display_handle;
  153. // Create a few things
  154. key_state = Keys.None;
  155. mouse_state = MouseButtons.None;
  156. mouse_position = Point.Empty;
  157. root_window = XRootWindow(display_handle, 0);
  158. default_colormap = XDefaultColormap(display_handle, 0);
  159. // Create the foster parent
  160. FosterParent=XCreateSimpleWindow(display_handle, root_window, 0, 0, 1, 1, 4, 0, 0);
  161. if (FosterParent==IntPtr.Zero) {
  162. Console.WriteLine("XplatUIX11 Constructor failed to create FosterParent");
  163. }
  164. // Prepare for shutdown
  165. wm_protocols=XInternAtom(display_handle, "WM_PROTOCOLS", false);
  166. wm_delete_window=XInternAtom(display_handle, "WM_DELETE_WINDOW", false);
  167. handle_data = new Hashtable ();
  168. }
  169. }
  170. internal override void ShutdownDriver(IntPtr token) {
  171. lock (this) {
  172. if (DisplayHandle!=IntPtr.Zero) {
  173. XCloseDisplay(DisplayHandle);
  174. DisplayHandle=IntPtr.Zero;
  175. }
  176. }
  177. }
  178. internal void Version() {
  179. Console.WriteLine("Xplat version $revision: $");
  180. }
  181. internal override void Exit() {
  182. Console.WriteLine("XplatUIX11.Exit");
  183. }
  184. internal override void GetDisplaySize(out Size size) {
  185. XWindowAttributes attributes=new XWindowAttributes();
  186. lock (this) {
  187. XGetWindowAttributes(DisplayHandle, XRootWindow(DisplayHandle, 0), ref attributes);
  188. }
  189. size = new Size(attributes.width, attributes.height);
  190. }
  191. internal override void EnableThemes() {
  192. themes_enabled=true;
  193. }
  194. internal override IntPtr CreateWindow(CreateParams cp) {
  195. IntPtr WindowHandle;
  196. IntPtr ParentHandle;
  197. int X;
  198. int Y;
  199. int Width;
  200. int Height;
  201. int BorderWidth;
  202. int protocols;
  203. ParentHandle=cp.Parent;
  204. X=cp.X;
  205. Y=cp.Y;
  206. Width=cp.Width;
  207. Height=cp.Height;
  208. BorderWidth=0;
  209. if (Width<1) Width=1;
  210. if (Height<1) Height=1;
  211. lock (this) {
  212. if (ParentHandle==IntPtr.Zero) {
  213. if ((cp.Style & (int)WindowStyles.WS_CHILD)!=0) {
  214. // We need to use our foster parent window until
  215. // this poor child gets it's parent assigned
  216. ParentHandle=FosterParent;
  217. } else {
  218. if (X<1) X=50;
  219. if (Y<1) Y=50;
  220. BorderWidth=4;
  221. ParentHandle=XRootWindow(DisplayHandle, 0);
  222. }
  223. }
  224. WindowHandle=XCreateSimpleWindow(DisplayHandle, ParentHandle, X, Y, Width, Height, BorderWidth, 0, 0);
  225. XMapWindow(DisplayHandle, WindowHandle);
  226. XSelectInput(DisplayHandle, WindowHandle, SelectInputMask);
  227. is_visible=true;
  228. protocols=wm_delete_window;
  229. XSetWMProtocols(DisplayHandle, WindowHandle, ref protocols, 1);
  230. }
  231. return(WindowHandle);
  232. }
  233. internal override IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
  234. CreateParams create_params = new CreateParams();
  235. create_params.Caption = "";
  236. create_params.X = X;
  237. create_params.Y = Y;
  238. create_params.Width = Width;
  239. create_params.Height = Height;
  240. create_params.ClassName=XplatUI.DefaultClassName;
  241. create_params.ClassStyle = 0;
  242. create_params.ExStyle=0;
  243. create_params.Parent=IntPtr.Zero;
  244. create_params.Param=0;
  245. return CreateWindow(create_params);
  246. }
  247. internal override void DestroyWindow(IntPtr handle) {
  248. lock (this) {
  249. HandleData data = (HandleData) handle_data [handle];
  250. if (data != null) {
  251. data.Dispose ();
  252. handle_data [handle] = null;
  253. }
  254. }
  255. }
  256. internal override void RefreshWindow(IntPtr handle) {
  257. XEvent xevent = new XEvent();
  258. IntPtr root;
  259. int border_width;
  260. int depth;
  261. int x;
  262. int y;
  263. int width;
  264. int height;
  265. lock (this) {
  266. // We need info about our window to generate the expose
  267. XGetGeometry(DisplayHandle, handle, out root, out x, out y,
  268. out width, out height, out border_width, out depth);
  269. xevent.type=XEventName.Expose;
  270. xevent.ExposeEvent.display=DisplayHandle;
  271. xevent.ExposeEvent.window=handle;
  272. xevent.ExposeEvent.x=0;
  273. xevent.ExposeEvent.y=0;
  274. xevent.ExposeEvent.width=width;
  275. xevent.ExposeEvent.height=height;
  276. XSendEvent(DisplayHandle, handle, false, EventMask.ExposureMask, ref xevent);
  277. XFlush(DisplayHandle);
  278. }
  279. }
  280. internal override void SetWindowBackground(IntPtr handle, Color color) {
  281. uint backcolor;
  282. // backcolor = ((uint)(color.ToArgb() & 0xff0000)>>16) | (uint)(color.ToArgb() & 0xff00) | (uint)((color.ToArgb() & 0xff) << 16);
  283. backcolor = ((uint)(color.ToArgb() & 0xff0000)) | (uint)(color.ToArgb() & 0xff00) | (uint)((color.ToArgb() & 0xff) );
  284. lock (this) {
  285. XSetWindowBackground(DisplayHandle, handle, backcolor);
  286. }
  287. }
  288. [MonoTODO("Add support for internal table of windows/DCs for looking up paint area and cleanup")]
  289. internal override PaintEventArgs PaintEventStart(IntPtr handle) {
  290. PaintEventArgs paint_event;
  291. HandleData data = (HandleData) handle_data [handle];
  292. if (data == null) {
  293. throw new Exception ("null data on paint event start: " + handle);
  294. }
  295. data.DeviceContext = Graphics.FromHwnd (handle);
  296. paint_event = new PaintEventArgs((Graphics)data.DeviceContext, data.InvalidArea);
  297. return paint_event;
  298. }
  299. internal override void PaintEventEnd(IntPtr handle) {
  300. HandleData data = (HandleData) handle_data [handle];
  301. if (data == null)
  302. throw new Exception ("null data on PaintEventEnd");
  303. data.ClearInvalidArea ();
  304. Graphics g = (Graphics) data.DeviceContext;
  305. g.Flush ();
  306. g.Dispose ();
  307. }
  308. internal override void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
  309. // X requires a sanity check for width & height; otherwise it dies
  310. if (width < 1) {
  311. width = 1;
  312. }
  313. if (height < 1) {
  314. height = 1;
  315. }
  316. lock (this) {
  317. XMoveResizeWindow(DisplayHandle, handle, x, y, width, height);
  318. }
  319. return;
  320. }
  321. internal override void GetWindowPos(IntPtr handle, out int x, out int y, out int width, out int height, out int client_width, out int client_height) {
  322. IntPtr root;
  323. int border_width;
  324. int depth;
  325. lock (this) {
  326. XGetGeometry(DisplayHandle, handle, out root, out x,
  327. out y, out width, out height, out border_width, out depth);
  328. }
  329. client_width = width;
  330. client_height = height;
  331. return;
  332. }
  333. internal override void Activate(IntPtr handle) {
  334. lock (this) {
  335. // Not sure this is the right method, but we don't use ICs either...
  336. XRaiseWindow(DisplayHandle, handle);
  337. }
  338. return;
  339. }
  340. internal override void Invalidate(IntPtr handle, Rectangle rc, bool clear) {
  341. XEvent xevent = new XEvent();
  342. xevent.type=XEventName.Expose;
  343. xevent.ExposeEvent.display=DisplayHandle;
  344. xevent.ExposeEvent.window=handle;
  345. xevent.ExposeEvent.count=0;
  346. lock (this) {
  347. if (clear) {
  348. // Need to clear the whole window, so we force a redraw for the whole window
  349. XWindowAttributes attributes=new XWindowAttributes();
  350. // We need info about our window to generate the expose
  351. XGetWindowAttributes(DisplayHandle, handle, ref attributes);
  352. xevent.ExposeEvent.x=0;
  353. xevent.ExposeEvent.y=0;
  354. xevent.ExposeEvent.width=attributes.width;
  355. xevent.ExposeEvent.height=attributes.height;
  356. } else {
  357. xevent.ExposeEvent.x=rc.Left;
  358. xevent.ExposeEvent.y=rc.Top;
  359. xevent.ExposeEvent.width=rc.Width;
  360. xevent.ExposeEvent.height=rc.Height;
  361. }
  362. XSendEvent(DisplayHandle, handle, false, EventMask.ExposureMask, ref xevent);
  363. // Flush is not needed, invalidate does not guarantee an immediate effect
  364. }
  365. }
  366. internal override IntPtr DefWndProc(ref Message msg) {
  367. #if not
  368. switch (msg.Msg) {
  369. case (int)Msg.WM_PAINT: {
  370. IntPtr gc;
  371. if (msg.Hwnd!=IntPtr.Zero) {
  372. gc=XCreateGC(DisplayHandle, msg.Hwnd, 0, IntPtr.Zero);
  373. XSetBackground(DisplayHandle, gc, this.BackColor.ToArgb());
  374. XFreeGC(DisplayHandle, gc);
  375. }
  376. break;
  377. }
  378. }
  379. #endif
  380. #if debug
  381. Console.WriteLine("XplatUIX11.DefWndProc");
  382. #endif
  383. return IntPtr.Zero;
  384. }
  385. internal override void HandleException(Exception e) {
  386. StackTrace st = new StackTrace(e);
  387. Console.WriteLine("Exception '{0}'", e.Message+st.ToString());
  388. Console.WriteLine("{0}{1}", e.Message, st.ToString());
  389. }
  390. internal override void DoEvents() {
  391. Console.WriteLine("XplatUIX11.DoEvents");
  392. }
  393. internal override bool PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
  394. Console.WriteLine("XplatUIX11.PeekMessage");
  395. return true;
  396. }
  397. private void CreateKeyBoardMsg (XEvent xevent, ref MSG msg)
  398. {
  399. IntPtr buffer = Marshal.AllocHGlobal(24);
  400. XKeySym keysym;
  401. string keys;
  402. int len;
  403. msg.wParam = IntPtr.Zero;
  404. lock (this) {
  405. len = XLookupString(ref xevent, buffer, 24, out keysym, IntPtr.Zero);
  406. }
  407. if ((keysym==XKeySym.XK_Control_L) || (keysym==XKeySym.XK_Control_R)) {
  408. if (xevent.type==XEventName.KeyPress) {
  409. key_state |= Keys.Control;
  410. } else {
  411. key_state &= ~Keys.Control;
  412. }
  413. }
  414. if ((keysym==XKeySym.XK_Shift_L) || (keysym==XKeySym.XK_Shift_R)) {
  415. if (xevent.type==XEventName.KeyPress) {
  416. key_state |= Keys.Shift;
  417. } else {
  418. key_state &= ~Keys.Shift;
  419. }
  420. }
  421. if (len>0) /* String is not zero terminated*/
  422. Marshal.WriteByte (buffer, len, 0);
  423. keys=Marshal.PtrToStringAuto(buffer);
  424. for (int i = 0; i < KeyMapping.Length; i++) {
  425. if (KeyMapping[i].X11Key == keysym) {
  426. msg.wParam = (IntPtr) KeyMapping[i].Win32Key;
  427. Console.WriteLine("Got special key {0} {1:x} ", keysym, keysym);
  428. break;
  429. }
  430. }
  431. if ((msg.wParam == IntPtr.Zero) && (keys.Length>0)) {
  432. char[] keychars;
  433. keychars=keys.ToCharArray(0, 1);
  434. msg.wParam=(IntPtr)keychars[0];
  435. Console.WriteLine("Got key {0} {1:x} ", keysym, keysym);
  436. }
  437. Marshal.FreeHGlobal (buffer);
  438. msg.lParam = (IntPtr) 1;
  439. }
  440. private IntPtr GetMousewParam(int Delta) {
  441. int result = 0;
  442. if ((mouse_state & MouseButtons.Left) != 0) {
  443. result |= (int)MsgButtons.MK_LBUTTON;
  444. }
  445. if ((mouse_state & MouseButtons.Middle) != 0) {
  446. result |= (int)MsgButtons.MK_MBUTTON;
  447. }
  448. if ((mouse_state & MouseButtons.Right) != 0) {
  449. result |= (int)MsgButtons.MK_RBUTTON;
  450. }
  451. if ((key_state & Keys.Control) != 0) {
  452. result |= (int)MsgButtons.MK_CONTROL;
  453. }
  454. if ((key_state & Keys.Shift) != 0) {
  455. result |= (int)MsgButtons.MK_SHIFT;
  456. }
  457. result |= Delta << 16;
  458. return (IntPtr)result;
  459. }
  460. // The message_queue should be locked when this is called
  461. private void UpdateMessageQueue ()
  462. {
  463. int pending;
  464. lock (this) {
  465. pending = XPending (DisplayHandle);
  466. }
  467. while (pending > 0) {
  468. XEvent xevent = new XEvent ();
  469. lock (this) {
  470. XNextEvent (DisplayHandle, ref xevent);
  471. }
  472. switch (xevent.type) {
  473. case XEventName.Expose:
  474. HandleData data = (HandleData) handle_data [xevent.AnyEvent.window];
  475. if (data == null) {
  476. data = new HandleData ();
  477. handle_data [xevent.AnyEvent.window] = data;
  478. }
  479. data.AddToInvalidArea (xevent.ExposeEvent.x, xevent.ExposeEvent.y,
  480. xevent.ExposeEvent.width, xevent.ExposeEvent.height);
  481. if (!data.HasExpose) {
  482. message_queue.Enqueue (xevent);
  483. data.HasExpose = true;
  484. }
  485. break;
  486. default:
  487. message_queue.Enqueue (xevent);
  488. break;
  489. }
  490. lock (this) {
  491. pending = XPending (DisplayHandle);
  492. }
  493. }
  494. }
  495. internal override bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
  496. XEvent xevent;
  497. lock (message_queue) {
  498. if (message_queue.Count > 0) {
  499. xevent = (XEvent) message_queue.Dequeue ();
  500. } else {
  501. UpdateMessageQueue ();
  502. if (message_queue.Count > 0) {
  503. xevent = (XEvent) message_queue.Dequeue ();
  504. } else {
  505. msg.hwnd= IntPtr.Zero;
  506. msg.message = Msg.WM_ENTERIDLE;
  507. return true;
  508. }
  509. }
  510. }
  511. msg.hwnd=xevent.AnyEvent.window;
  512. switch(xevent.type) {
  513. case XEventName.KeyPress: {
  514. msg.message = Msg.WM_KEYDOWN;
  515. CreateKeyBoardMsg (xevent, ref msg);
  516. break;
  517. }
  518. case XEventName.KeyRelease: {
  519. msg.message=Msg.WM_KEYUP;
  520. CreateKeyBoardMsg (xevent, ref msg);
  521. break;
  522. }
  523. case XEventName.ButtonPress: {
  524. switch(xevent.ButtonEvent.button) {
  525. case 1: {
  526. mouse_state |= MouseButtons.Left;
  527. msg.message=Msg.WM_LBUTTONDOWN;
  528. msg.wParam=GetMousewParam(0);
  529. break;
  530. }
  531. case 2: {
  532. mouse_state |= MouseButtons.Middle;
  533. msg.message=Msg.WM_MBUTTONDOWN;
  534. msg.wParam=GetMousewParam(0);
  535. break;
  536. }
  537. case 3: {
  538. mouse_state |= MouseButtons.Right;
  539. msg.message=Msg.WM_RBUTTONDOWN;
  540. msg.wParam=GetMousewParam(0);
  541. break;
  542. }
  543. case 4: {
  544. msg.message=Msg.WM_MOUSEWHEEL;
  545. msg.wParam=GetMousewParam(120);
  546. break;
  547. }
  548. case 5: {
  549. msg.message=Msg.WM_MOUSEWHEEL;
  550. msg.wParam=GetMousewParam(-120);
  551. break;
  552. }
  553. }
  554. msg.lParam=(IntPtr) (xevent.ButtonEvent.y << 16 | xevent.ButtonEvent.x);
  555. mouse_position.X=xevent.ButtonEvent.x;
  556. mouse_position.Y=xevent.ButtonEvent.y;
  557. break;
  558. }
  559. case XEventName.ButtonRelease: {
  560. switch(xevent.ButtonEvent.button) {
  561. case 1: {
  562. mouse_state &= ~MouseButtons.Left;
  563. msg.message=Msg.WM_LBUTTONUP;
  564. msg.wParam=GetMousewParam(0);
  565. break;
  566. }
  567. case 2: {
  568. mouse_state &= ~MouseButtons.Middle;
  569. msg.message=Msg.WM_MBUTTONUP;
  570. msg.wParam=GetMousewParam(0);
  571. break;
  572. }
  573. case 3: {
  574. mouse_state &= ~MouseButtons.Right;
  575. msg.message=Msg.WM_RBUTTONUP;
  576. msg.wParam=GetMousewParam(0);
  577. break;
  578. }
  579. case 4: {
  580. return true;
  581. }
  582. case 5: {
  583. return true;
  584. }
  585. }
  586. msg.lParam=(IntPtr) (xevent.ButtonEvent.y << 16 | xevent.ButtonEvent.x);
  587. mouse_position.X=xevent.ButtonEvent.x;
  588. mouse_position.Y=xevent.ButtonEvent.y;
  589. break;
  590. }
  591. case XEventName.MotionNotify: {
  592. msg.message=Msg.WM_MOUSEMOVE;
  593. msg.wParam=GetMousewParam(0);
  594. msg.lParam=(IntPtr) (xevent.MotionEvent.y << 16 | xevent.MotionEvent.x);
  595. mouse_position.X=xevent.MotionEvent.x;
  596. mouse_position.Y=xevent.MotionEvent.y;
  597. break;
  598. }
  599. case XEventName.EnterNotify: {
  600. if (xevent.CrossingEvent.mode != NotifyMode.NotifyNormal) {
  601. return true;
  602. }
  603. msg.message=Msg.WM_MOUSE_ENTER;
  604. break;
  605. }
  606. case XEventName.LeaveNotify: {
  607. if (xevent.CrossingEvent.mode != NotifyMode.NotifyNormal) {
  608. return true;
  609. }
  610. msg.message=Msg.WM_MOUSE_LEAVE;
  611. break;
  612. }
  613. case XEventName.ConfigureNotify: {
  614. msg.message=Msg.WM_WINDOWPOSCHANGED;
  615. msg.wParam=IntPtr.Zero;
  616. msg.lParam=IntPtr.Zero;
  617. break;
  618. }
  619. case XEventName.Expose: {
  620. msg.message=Msg.WM_PAINT;
  621. msg.wParam=IntPtr.Zero;
  622. msg.lParam=IntPtr.Zero;
  623. break;
  624. }
  625. case XEventName.DestroyNotify: {
  626. msg.message=Msg.WM_DESTROY;
  627. msg.wParam=IntPtr.Zero;
  628. msg.lParam=IntPtr.Zero;
  629. break;
  630. }
  631. case XEventName.ClientMessage: {
  632. if (xevent.ClientMessageEvent.message_type == async_method) {
  633. GCHandle handle = (GCHandle)xevent.ClientMessageEvent.ptr1;
  634. AsyncMethodData data = (AsyncMethodData) handle.Target;
  635. AsyncMethodResult result = data.Result.Target as AsyncMethodResult;
  636. object ret = data.Method.DynamicInvoke (data.Args);
  637. if (result != null)
  638. result.Complete (ret);
  639. handle.Free ();
  640. } else {
  641. msg.message=Msg.WM_QUIT;
  642. msg.wParam=IntPtr.Zero;
  643. msg.lParam=IntPtr.Zero;
  644. return false;
  645. }
  646. break;
  647. }
  648. case XEventName.TimerNotify: {
  649. xevent.TimerNotifyEvent.handler (this, EventArgs.Empty);
  650. break;
  651. }
  652. default: {
  653. msg.message = Msg.WM_NULL;
  654. break;
  655. }
  656. }
  657. NativeWindow.WndProc(msg.hwnd, msg.message, msg.wParam, msg.lParam);
  658. return true;
  659. }
  660. internal override bool TranslateMessage(ref MSG msg) {
  661. return true;
  662. }
  663. internal override bool DispatchMessage(ref MSG msg) {
  664. return true;
  665. }
  666. internal override bool SetZOrder(IntPtr hWnd, IntPtr AfterhWnd, bool Top, bool Bottom) {
  667. if (Top) {
  668. XRaiseWindow(DisplayHandle, hWnd);
  669. return true;
  670. } else if (!Bottom) {
  671. XWindowChanges values = new XWindowChanges();
  672. values.sibling = AfterhWnd;
  673. values.stack_mode = StackMode.Below;
  674. XConfigureWindow(DisplayHandle, hWnd, ChangeWindowFlags.CWStackMode, ref values);
  675. } else {
  676. XLowerWindow(DisplayHandle, hWnd);
  677. return true;
  678. }
  679. return false;
  680. }
  681. internal override bool Text(IntPtr handle, string text) {
  682. #if notdef
  683. XTextProperty property = new XTextProperty();
  684. property.encoding=
  685. XSetWMName(DisplayHandle, handle, ref property);
  686. #else
  687. lock (this) {
  688. XStoreName(DisplayHandle, handle, text);
  689. }
  690. #endif
  691. return true;
  692. }
  693. internal override bool GetText(IntPtr handle, out string text) {
  694. IntPtr textptr;
  695. textptr = IntPtr.Zero;
  696. lock (this) {
  697. XFetchName(DisplayHandle, handle, ref textptr);
  698. }
  699. if (textptr != IntPtr.Zero) {
  700. text = Marshal.PtrToStringAnsi(textptr);
  701. XFree(textptr);
  702. return true;
  703. } else {
  704. text = "";
  705. return false;
  706. }
  707. }
  708. internal override bool SetVisible(IntPtr handle, bool visible) {
  709. lock (this) {
  710. if (visible) {
  711. XMapWindow(DisplayHandle, handle);
  712. is_visible=true;
  713. } else {
  714. XUnmapWindow(DisplayHandle, handle);
  715. is_visible=false;
  716. }
  717. }
  718. return true;
  719. }
  720. internal override bool IsVisible(IntPtr handle) {
  721. return is_visible;
  722. }
  723. internal override IntPtr SetParent(IntPtr handle, IntPtr parent) {
  724. XWindowAttributes attributes=new XWindowAttributes();
  725. lock (this) {
  726. XGetWindowAttributes(DisplayHandle, handle, ref attributes);
  727. XReparentWindow(DisplayHandle, handle, parent, attributes.x, attributes.y);
  728. }
  729. return IntPtr.Zero;
  730. }
  731. internal override IntPtr GetParent(IntPtr handle) {
  732. IntPtr Root;
  733. IntPtr Parent;
  734. IntPtr Children;
  735. int ChildCount;
  736. Root=IntPtr.Zero;
  737. Parent=IntPtr.Zero;
  738. Children=IntPtr.Zero;
  739. ChildCount=0;
  740. lock (this) {
  741. XQueryTree(DisplayHandle, handle, ref Root, ref Parent, ref Children, ref ChildCount);
  742. }
  743. if (Children!=IntPtr.Zero) {
  744. lock (this) {
  745. XFree(Children);
  746. }
  747. }
  748. return Parent;
  749. }
  750. internal override void GrabWindow(IntPtr hWnd, IntPtr confine_hwnd) {
  751. if (confine_hwnd != IntPtr.Zero) {
  752. XWindowAttributes attributes = new XWindowAttributes();
  753. lock (this) {
  754. XGetWindowAttributes(DisplayHandle, confine_hwnd, ref attributes);
  755. }
  756. grab_area.X = attributes.x;
  757. grab_area.Y = attributes.y;
  758. grab_area.Width = attributes.width;
  759. grab_area.Height = attributes.height;
  760. grab_confined = true;
  761. }
  762. grab_hwnd = hWnd;
  763. lock (this) {
  764. XGrabPointer(DisplayHandle, hWnd, false,
  765. EventMask.ButtonPressMask | EventMask.ButtonMotionMask |
  766. EventMask.ButtonReleaseMask | EventMask.PointerMotionMask,
  767. GrabMode.GrabModeAsync, GrabMode.GrabModeAsync, confine_hwnd, 0, 0);
  768. }
  769. }
  770. internal override void GrabInfo(out IntPtr hWnd, out bool GrabConfined, out Rectangle GrabArea) {
  771. hWnd = grab_hwnd;
  772. GrabConfined = grab_confined;
  773. GrabArea = grab_area;
  774. }
  775. internal override void ReleaseWindow(IntPtr hWnd) {
  776. lock (this) {
  777. XUngrabPointer(DisplayHandle, 0);
  778. grab_hwnd = IntPtr.Zero;
  779. grab_confined = false;
  780. }
  781. }
  782. internal override bool CalculateWindowRect(IntPtr hWnd, ref Rectangle ClientRect, int Style, bool HasMenu, out Rectangle WindowRect) {
  783. WindowRect = new Rectangle(ClientRect.Left, ClientRect.Top, ClientRect.Width, ClientRect.Height);
  784. return true;
  785. }
  786. internal override void SetCursorPos(IntPtr handle, int x, int y) {
  787. lock (this) {
  788. XWarpPointer(DisplayHandle, IntPtr.Zero, (handle!=IntPtr.Zero) ? handle : IntPtr.Zero, 0, 0, 0, 0, x, y);
  789. }
  790. }
  791. internal override void GetCursorPos(IntPtr handle, out int x, out int y) {
  792. IntPtr root;
  793. IntPtr child;
  794. int root_x;
  795. int root_y;
  796. int win_x;
  797. int win_y;
  798. int keys_buttons;
  799. lock (this) {
  800. XQueryPointer(DisplayHandle, (handle!=IntPtr.Zero) ? handle : root_window,
  801. out root, out child, out root_x, out root_y,
  802. out win_x, out win_y, out keys_buttons);
  803. }
  804. if (handle != IntPtr.Zero) {
  805. x = win_x;
  806. y = win_y;
  807. } else {
  808. x = root_x;
  809. y = root_y;
  810. }
  811. }
  812. internal override void ScreenToClient(IntPtr handle, ref int x, ref int y)
  813. {
  814. int dest_x_return;
  815. int dest_y_return;
  816. IntPtr child;
  817. lock (this) {
  818. XTranslateCoordinates (DisplayHandle, root_window,
  819. handle, x, y, out dest_x_return, out dest_y_return, out child);
  820. }
  821. x = dest_x_return;
  822. y = dest_y_return;
  823. }
  824. internal override void SendAsyncMethod (AsyncMethodData method)
  825. {
  826. XEvent xevent = new XEvent ();
  827. xevent.type = XEventName.ClientMessage;
  828. xevent.ClientMessageEvent.display = DisplayHandle;
  829. xevent.ClientMessageEvent.window = IntPtr.Zero;
  830. xevent.ClientMessageEvent.message_type = async_method;
  831. xevent.ClientMessageEvent.format = 32;
  832. xevent.ClientMessageEvent.ptr1 = (IntPtr) GCHandle.Alloc (method);
  833. lock (message_queue) {
  834. message_queue.Enqueue (xevent);
  835. }
  836. }
  837. internal void TimerProc ()
  838. {
  839. while (true) {
  840. int next_fire = -1;
  841. ArrayList fire_list = new ArrayList ();
  842. DateTime now = DateTime.Now;
  843. for (int i = 0; i < timer_list.Count; i++) {
  844. Timer timer = (Timer) timer_list [i];
  845. if (timer.Enabled && timer.Expires <= now) {
  846. XEvent xevent = new XEvent ();
  847. xevent.type = XEventName.TimerNotify;
  848. xevent.AnyEvent.window = IntPtr.Zero;
  849. xevent.TimerNotifyEvent.handler = new EventHandler (timer.TickHandler);
  850. fire_list.Add (xevent);
  851. timer.Update (now);
  852. }
  853. int next = (int) (timer.Expires.AddMilliseconds (timer.Interval) - now).TotalMilliseconds;
  854. if (i == 0 || next < next_fire)
  855. next_fire = next;
  856. }
  857. // Everything is copied to a list and then to the queue so we
  858. // don't lock the queue while calculating all the times
  859. if (fire_list.Count > 0) {
  860. lock (message_queue) {
  861. foreach (object obj in fire_list) {
  862. message_queue.Enqueue (obj);
  863. }
  864. }
  865. }
  866. if (next_fire < Timer.Minimum)
  867. next_fire = Timer.Minimum;
  868. timer_wait.WaitOne (next_fire, true);
  869. }
  870. }
  871. internal override void SetTimer (Timer timer)
  872. {
  873. timer_list.Add (timer);
  874. if (timer_thread == null) {
  875. ThreadStart thread_start = new ThreadStart (TimerProc);
  876. timer_thread = new Thread (thread_start);
  877. timer_thread.IsBackground = true;
  878. timer_wait = new AutoResetEvent (true);
  879. timer_thread.Start();
  880. }
  881. }
  882. internal override void KillTimer (Timer timer)
  883. {
  884. timer_list.Remove (timer);
  885. }
  886. // Santa's little helper
  887. static void Where()
  888. {
  889. Console.WriteLine("Here: {0}", new StackTrace().ToString());
  890. }
  891. #endregion // Public Static Methods
  892. internal struct X11ToWin32KeyMapping {
  893. internal XKeySym X11Key;
  894. internal XplatUIWin32.VirtualKeys Win32Key;
  895. internal X11ToWin32KeyMapping (XKeySym x11, XplatUIWin32.VirtualKeys win32)
  896. {
  897. X11Key = x11;
  898. Win32Key = win32;
  899. }
  900. }
  901. /* X11 to Win32 VK mapping */
  902. static readonly X11ToWin32KeyMapping[] KeyMapping = new X11ToWin32KeyMapping[]
  903. {
  904. /* Cursor navigation*/
  905. new X11ToWin32KeyMapping (XKeySym.XK_Left, XplatUIWin32.VirtualKeys.VK_LEFT),
  906. new X11ToWin32KeyMapping (XKeySym.XK_Right, XplatUIWin32.VirtualKeys.VK_RIGHT),
  907. new X11ToWin32KeyMapping (XKeySym.XK_Up, XplatUIWin32.VirtualKeys.VK_UP),
  908. new X11ToWin32KeyMapping (XKeySym.XK_Down, XplatUIWin32.VirtualKeys.VK_DOWN),
  909. new X11ToWin32KeyMapping (XKeySym.XK_Page_Up, XplatUIWin32.VirtualKeys.VK_PRIOR),
  910. new X11ToWin32KeyMapping (XKeySym.XK_Page_Down, XplatUIWin32.VirtualKeys.VK_NEXT),
  911. new X11ToWin32KeyMapping (XKeySym.XK_End, XplatUIWin32.VirtualKeys.VK_END),
  912. new X11ToWin32KeyMapping (XKeySym.XK_Home, XplatUIWin32.VirtualKeys.VK_HOME),
  913. /* Modifiers*/
  914. new X11ToWin32KeyMapping (XKeySym.XK_Shift_R, XplatUIWin32.VirtualKeys.VK_SHIFT),
  915. new X11ToWin32KeyMapping (XKeySym.XK_Shift_L, XplatUIWin32.VirtualKeys.VK_SHIFT),
  916. new X11ToWin32KeyMapping (XKeySym.XK_Control_R, XplatUIWin32.VirtualKeys.VK_CONTROL),
  917. new X11ToWin32KeyMapping (XKeySym.XK_Control_L, XplatUIWin32.VirtualKeys.VK_CONTROL),
  918. /* Others */
  919. new X11ToWin32KeyMapping (XKeySym.XK_Return, XplatUIWin32.VirtualKeys.VK_RETURN),
  920. new X11ToWin32KeyMapping (XKeySym.XK_Tab, XplatUIWin32.VirtualKeys.VK_TAB),
  921. new X11ToWin32KeyMapping (XKeySym.XK_Menu, XplatUIWin32.VirtualKeys.VK_MENU),
  922. new X11ToWin32KeyMapping (XKeySym.XK_BackSpace, XplatUIWin32.VirtualKeys.VK_BACK),
  923. new X11ToWin32KeyMapping (XKeySym.XK_Clear, XplatUIWin32.VirtualKeys.VK_CLEAR),
  924. };
  925. #region X11 Imports
  926. [DllImport ("libX11.so", EntryPoint="XOpenDisplay")]
  927. internal extern static IntPtr XOpenDisplay(IntPtr display);
  928. [DllImport ("libX11.so", EntryPoint="XCloseDisplay")]
  929. internal extern static void XCloseDisplay(IntPtr display);
  930. [DllImport ("libX11.so", EntryPoint="XCreateWindow")]
  931. internal extern static IntPtr XCreateWindow(IntPtr display, IntPtr parent, int x, int y, int width, int height, int border_width, int depth, int xclass, IntPtr visual, IntPtr attributes);
  932. [DllImport ("libX11.so", EntryPoint="XCreateSimpleWindow")]
  933. internal extern static IntPtr XCreateSimpleWindow(IntPtr display, IntPtr parent, int x, int y, int width, int height, int border_width, int border, int background);
  934. [DllImport ("libX11.so", EntryPoint="XMapWindow")]
  935. internal extern static int XMapWindow(IntPtr display, IntPtr window);
  936. [DllImport ("libX11.so", EntryPoint="XUnmapWindow")]
  937. internal extern static int XUnmapWindow(IntPtr display, IntPtr window);
  938. [DllImport ("libX11.so", EntryPoint="XRootWindow")]
  939. internal extern static IntPtr XRootWindow(IntPtr display, int screen_number);
  940. [DllImport ("libX11.so", EntryPoint="XNextEvent")]
  941. internal extern static IntPtr XNextEvent(IntPtr display, ref XEvent xevent);
  942. [DllImport ("libX11.so")]
  943. internal extern static int XPending (IntPtr diplay);
  944. [DllImport ("libX11.so")]
  945. internal extern static bool XCheckWindowEvent (IntPtr display, IntPtr window, EventMask mask, ref XEvent xevent);
  946. [DllImport ("libX11.so")]
  947. internal extern static bool XCheckMaskEvent (IntPtr display, EventMask mask, ref XEvent xevent);
  948. [DllImport ("libX11.so", EntryPoint="XSelectInput")]
  949. internal extern static IntPtr XSelectInput(IntPtr display, IntPtr window, EventMask mask);
  950. [DllImport ("libX11.so", EntryPoint="XLookupString")]
  951. internal extern static int XLookupString(ref XEvent xevent, IntPtr buffer, int num_bytes, out XKeySym keysym, IntPtr status);
  952. [DllImport ("libX11.so", EntryPoint="XDestroyWindow")]
  953. internal extern static int XDestroyWindow(IntPtr display, IntPtr window);
  954. [DllImport ("libX11.so", EntryPoint="XReparentWindow")]
  955. internal extern static int XReparentWindow(IntPtr display, IntPtr window, IntPtr parent, int x, int y);
  956. [DllImport ("libX11.so", EntryPoint="XMoveResizeWindow")]
  957. internal extern static int XMoveResizeWindow(IntPtr display, IntPtr window, int x, int y, int width, int height);
  958. [DllImport ("libX11.so", EntryPoint="XResizeWindow")]
  959. internal extern static int XResizeWindow(IntPtr display, IntPtr window, int width, int height);
  960. [DllImport ("libX11.so", EntryPoint="XGetWindowAttributes")]
  961. internal extern static int XGetWindowAttributes(IntPtr display, IntPtr window, ref XWindowAttributes attributes);
  962. [DllImport ("libX11.so", EntryPoint="XFlush")]
  963. internal extern static int XFlush(IntPtr display);
  964. [DllImport ("libX11.so", EntryPoint="XSetWMName")]
  965. internal extern static int XSetWMName(IntPtr display, IntPtr window, ref XTextProperty text_prop);
  966. [DllImport ("libX11.so", EntryPoint="XStoreName")]
  967. internal extern static int XStoreName(IntPtr display, IntPtr window, string window_name);
  968. [DllImport ("libX11.so", EntryPoint="XFetchName")]
  969. internal extern static int XFetchName(IntPtr display, IntPtr window, ref IntPtr window_name);
  970. [DllImport ("libX11.so", EntryPoint="XSendEvent")]
  971. internal extern static int XSendEvent(IntPtr display, IntPtr window, bool propagate, EventMask event_mask, ref XEvent send_event);
  972. [DllImport ("libX11.so", EntryPoint="XQueryTree")]
  973. internal extern static int XQueryTree(IntPtr display, IntPtr window, ref IntPtr root_return, ref IntPtr parent_return, ref IntPtr children_return, ref int nchildren_return);
  974. [DllImport ("libX11.so", EntryPoint="XFree")]
  975. internal extern static int XFree(IntPtr data);
  976. [DllImport ("libX11.so", EntryPoint="XRaiseWindow")]
  977. internal extern static int XRaiseWindow(IntPtr display, IntPtr window);
  978. [DllImport ("libX11.so", EntryPoint="XLowerWindow")]
  979. internal extern static uint XLowerWindow(IntPtr display, IntPtr window);
  980. [DllImport ("libX11.so", EntryPoint="XConfigureWindow")]
  981. internal extern static uint XConfigureWindow(IntPtr display, IntPtr window, ChangeWindowFlags value_mask, ref XWindowChanges values);
  982. [DllImport ("libX11.so", EntryPoint="XInternAtom")]
  983. internal extern static int XInternAtom(IntPtr display, string atom_name, bool only_if_exists);
  984. [DllImport ("libX11.so", EntryPoint="XSetWMProtocols")]
  985. internal extern static int XSetWMProtocols(IntPtr display, IntPtr window, ref int protocols, int count);
  986. [DllImport ("libX11.so", EntryPoint="XGrabPointer")]
  987. internal extern static int XGrabPointer(IntPtr display, IntPtr window, bool owner_events, EventMask event_mask, GrabMode pointer_mode, GrabMode keyboard_mode, IntPtr confine_to, uint cursor, uint timestamp);
  988. [DllImport ("libX11.so", EntryPoint="XUngrabPointer")]
  989. internal extern static int XUngrabPointer(IntPtr display, uint timestamp);
  990. [DllImport ("libX11.so", EntryPoint="XQueryPointer")]
  991. internal extern static bool XQueryPointer(IntPtr display, IntPtr window, out IntPtr root, out IntPtr child, out int root_x, out int root_y, out int win_x, out int win_y, out int keys_buttons);
  992. [DllImport ("libX11.so", EntryPoint="XTranslateCoordinates")]
  993. internal extern static bool XTranslateCoordinates (IntPtr display, IntPtr src_w, IntPtr dest_w, int src_x, int src_y, out int intdest_x_return, out int dest_y_return, out IntPtr child_return);
  994. [DllImport ("libX11.so", EntryPoint="XGetGeometry")]
  995. internal extern static bool XGetGeometry(IntPtr display, IntPtr window, out IntPtr root, out int x, out int y, out int width, out int height, out int border_width, out int depth);
  996. [DllImport ("libX11.so", EntryPoint="XAllocColor")]
  997. internal extern static int XAllocColor(IntPtr display, uint Colormap, ref XColor colorcell_def);
  998. [DllImport ("libX11.so", EntryPoint="XGetStandardColormap")]
  999. internal extern static int XGetStandardColormap(IntPtr display, IntPtr window, ref XStandardColormap cmap_info, Atom property);
  1000. [DllImport ("libX11.so", EntryPoint="XSetRGBColormaps")]
  1001. internal extern static int XSetRGBColormaps(IntPtr display, IntPtr window, ref XStandardColormap cmap_info, int count, Atom property);
  1002. [DllImport ("libX11.so", EntryPoint="XInstallColormap")]
  1003. internal extern static int XInstallColormap(IntPtr display, uint cmap);
  1004. [DllImport ("libX11.so", EntryPoint="XDefaultColormap")]
  1005. internal extern static uint XDefaultColormap(IntPtr display, int screen_number);
  1006. [DllImport ("libX11.so", EntryPoint="XDefaultDepth")]
  1007. internal extern static uint XDefaultDepth(IntPtr display, int screen_number);
  1008. [DllImport ("libX11.so", EntryPoint="XDefaultVisual")]
  1009. internal extern static uint XDefaultVisual(IntPtr display, int screen_number);
  1010. [DllImport ("libX11.so", EntryPoint="XSetWindowColormap")]
  1011. internal extern static uint XSetWindowColormap(IntPtr display, IntPtr window, uint cmap);
  1012. [DllImport ("libX11.so", EntryPoint="XWarpPointer")]
  1013. internal extern static uint XWarpPointer(IntPtr display, IntPtr src_w, IntPtr dest_w, int src_x, int src_y, uint src_width, uint src_height, int dest_x, int dest_y);
  1014. // Drawing
  1015. [DllImport ("libX11.so", EntryPoint="XCreateGC")]
  1016. internal extern static IntPtr XCreateGC(IntPtr display, IntPtr window, int valuemask, IntPtr values);
  1017. [DllImport ("libX11.so", EntryPoint="XFreeGC")]
  1018. internal extern static int XFreeGC(IntPtr display, IntPtr gc);
  1019. [DllImport ("libX11.so", EntryPoint="XSetWindowBackground")]
  1020. internal extern static int XSetWindowBackground(IntPtr display, IntPtr window, uint background);
  1021. #endregion
  1022. }
  1023. }