X11RootHwnd.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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) 2006 Novell, Inc. (http://www.novell.com)
  21. //
  22. //
  23. using System;
  24. using System.Runtime.InteropServices;
  25. using System.Windows.Forms;
  26. namespace System.Windows.Forms.X11Internal {
  27. internal class X11RootHwnd : X11Hwnd
  28. {
  29. public X11RootHwnd (X11Display display, IntPtr window_handle) : base (display)
  30. {
  31. WholeWindow = ClientWindow = window_handle;
  32. Xlib.XSelectInput(display.Handle, WholeWindow, new IntPtr ((int)EventMask.PropertyChangeMask));
  33. }
  34. public override void CreateWindow (CreateParams cp)
  35. {
  36. // we don't do anything here
  37. }
  38. public override void PropertyChanged (XEvent xevent)
  39. {
  40. if (xevent.PropertyEvent.atom == Display.Atoms._NET_ACTIVE_WINDOW) {
  41. IntPtr actual_atom;
  42. int actual_format;
  43. IntPtr nitems;
  44. IntPtr bytes_after;
  45. IntPtr prop = IntPtr.Zero;
  46. Xlib.XGetWindowProperty (Display.Handle, WholeWindow,
  47. Display.Atoms._NET_ACTIVE_WINDOW, IntPtr.Zero, new IntPtr (1), false,
  48. Display.Atoms.XA_WINDOW, out actual_atom, out actual_format, out nitems, out bytes_after, ref prop);
  49. if (((long)nitems > 0) && (prop != IntPtr.Zero)) {
  50. // FIXME - is this 64 bit clean?
  51. Display.SetActiveWindow ((X11Hwnd)Hwnd.ObjectFromHandle((IntPtr)Marshal.ReadInt32(prop)));
  52. Xlib.XFree(prop);
  53. }
  54. }
  55. else if (xevent.PropertyEvent.atom == Display.Atoms._NET_SUPPORTED) {
  56. // we'll need to refetch the supported protocols list
  57. refetch_net_supported = true;
  58. _net_supported = null;
  59. }
  60. else
  61. base.PropertyChanged (xevent);
  62. }
  63. bool refetch_net_supported = true;
  64. IntPtr[] _net_supported;
  65. public IntPtr[] _NET_SUPPORTED {
  66. get {
  67. if (refetch_net_supported) {
  68. _net_supported = GetAtomListProperty (Display.Atoms._NET_SUPPORTED);
  69. refetch_net_supported = false;
  70. }
  71. return _net_supported;
  72. }
  73. }
  74. }
  75. }