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:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
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.
20 // Copyright (c) 2006 Novell, Inc. (http://www.novell.com)
25 using System.Runtime.InteropServices;
26 using System.Windows.Forms;
28 namespace System.Windows.Forms.X11Internal {
30 internal class X11RootHwnd : X11Hwnd
32 public X11RootHwnd (X11Display display, IntPtr window_handle) : base (display)
34 WholeWindow = ClientWindow = window_handle;
36 Xlib.XSelectInput(display.Handle, WholeWindow, new IntPtr ((int)EventMask.PropertyChangeMask));
39 public override void CreateWindow (CreateParams cp)
41 // we don't do anything here
44 public override void PropertyChanged (XEvent xevent)
46 if (xevent.PropertyEvent.atom == Display.Atoms._NET_ACTIVE_WINDOW) {
51 IntPtr prop = IntPtr.Zero;
54 prev_active = Display.ActiveWindow;
55 Xlib.XGetWindowProperty (Display.Handle, WholeWindow,
56 Display.Atoms._NET_ACTIVE_WINDOW, IntPtr.Zero, new IntPtr (1), false,
57 Display.Atoms.XA_WINDOW, out actual_atom, out actual_format, out nitems, out bytes_after, ref prop);
59 if (((long)nitems > 0) && (prop != IntPtr.Zero)) {
60 // FIXME - is this 64 bit clean?
61 Display.ActiveWindow = (X11Hwnd)Hwnd.ObjectFromHandle((IntPtr)Marshal.ReadInt32(prop));
64 if (prev_active != Display.ActiveWindow) {
65 if (prev_active != null) {
66 Display.PostMessage (prev_active.Handle, Msg.WM_ACTIVATE,
67 (IntPtr)WindowActiveFlags.WA_INACTIVE, IntPtr.Zero);
69 if (Display.ActiveWindow != null) {
70 Display.PostMessage (Display.ActiveWindow.Handle, Msg.WM_ACTIVATE,
71 (IntPtr)WindowActiveFlags.WA_ACTIVE, IntPtr.Zero);
75 // XXX this next bit should be in the X11Display.ActiveWindow setter
77 if (Display.ModalWindows.Count > 0) {
78 // Modality handling, if we are modal and the new active window is one
79 // of ours but not the modal one, switch back to the modal window
81 if (NativeWindow.FindWindow (Display.ActiveWindow.Handle) != null) {
82 if (Display.ActiveWindow != (X11Hwnd)Display.ModalWindows.Peek()) {
83 ((X11Hwnd)Display.ModalWindows.Peek()).Activate ();
89 else if (xevent.PropertyEvent.atom == Display.Atoms._NET_SUPPORTED) {
90 // we'll need to refetch the supported protocols list
91 refetch_net_supported = true;
92 _net_supported = null;
95 base.PropertyChanged (xevent);
98 bool refetch_net_supported = true;
99 IntPtr[] _net_supported;
100 public IntPtr[] _NET_SUPPORTED {
102 if (refetch_net_supported) {
103 _net_supported = GetAtomListProperty (Display.Atoms._NET_SUPPORTED);
104 refetch_net_supported = false;
107 return _net_supported;