File: X11WindowInfo.cs

package info (click to toggle)
opentk 1.1.4c%2Bdfsg-2.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 68,640 kB
  • sloc: cs: 525,501; xml: 277,501; ansic: 3,597; makefile: 41
file content (165 lines) | stat: -rw-r--r-- 6,194 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#region License
//
// The Open Toolkit Library License
//
// Copyright (c) 2006 - 2009 the Open Toolkit library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to 
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
#endregion

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace OpenTK.Platform.X11
{
    /// \internal
    /// <summary>Describes an X11 window.</summary>
    sealed class X11WindowInfo : IWindowInfo
    {
        IntPtr handle, rootWindow, display;
        X11WindowInfo parent;
        int screen;
        XVisualInfo visualInfo;
        EventMask eventMask;

        #region --- Constructors ---

        #region X11WindowInfo()

        /// <summary>Constructs a new X11WindowInfo class.</summary>
        public X11WindowInfo() { }

        #endregion

        #region X11WindowInfo(IntPtr handle, X11WindowInfo parent)

        /// <summary>
        /// Constructs a new X11WindowInfo class from the specified window handle and parent.
        /// </summary>
        /// <param name="handle">The handle of the window.</param>
        /// <param name="parent">The parent of the window.</param>
        public X11WindowInfo(IntPtr handle, X11WindowInfo parent)
        {
            this.handle = handle;
            this.parent = parent;
            if (parent != null)
            {
                this.rootWindow = parent.rootWindow;
                this.display = parent.display;
                this.screen = parent.screen;
                this.visualInfo = parent.visualInfo;
            }
        }

        #endregion

        #endregion

        #region --- Public Methods ---

        /// <summary>Gets or sets the handle of the window.</summary>
        public IntPtr Handle { get { return handle; } set { handle = value; } }
        /// <summary>Gets or sets the parent of the window.</summary>
        public X11WindowInfo Parent { get { return parent; } set { parent = value; } }
        /// <summary>Gets or sets the X11 root window.</summary>
        public IntPtr RootWindow { get { return rootWindow; } set { rootWindow = value; } }
        /// <summary>Gets or sets the connection to the X11 display.</summary>
        public IntPtr Display { get { return display; } set { display = value; } }
        /// <summary>Gets or sets the X11 screen.</summary>
        public int Screen { get { return screen; } set { screen = value; } }
        /// <summary>Gets or sets the X11 VisualInfo.</summary>
        public XVisualInfo VisualInfo
        {
            get
            {
                if (Visual != IntPtr.Zero)
                {
                    return (XVisualInfo)Marshal.PtrToStructure(Visual, typeof(XVisualInfo));
                }
                return default(XVisualInfo);
            }
        }
        /// <summary>Gets or sets the X11 EventMask.</summary>
        public EventMask EventMask { get { return eventMask; } set { eventMask = value; } }

        // For compatibility with whoever thought it would be
        // a good idea to access internal APIs through reflection
        // (e.g. MonoGame)
        public IntPtr WindowHandle { get { return Handle; } set { Handle = value; } }

        public IntPtr Visual { get; set; }
        public IntPtr FBConfig { get; set; }
        public Graphics.GraphicsMode GraphicsMode { get; set; }

        #endregion

        #region --- IDisposable Members ---

        /// <summary>
        /// Disposes of this X11WindowInfo instance.
        /// </summary>
        public void Dispose()
        {
        }

        #endregion

        #region --- Overrides ---

        #region public override string ToString()

        /// <summary>Returns a System.String that represents the current window.</summary>
        /// <returns>A System.String that represents the current window.</returns>
        public override string ToString()
        {
            return String.Format("X11.WindowInfo: Display {0}, Screen {1}, Handle {2}, Parent: ({3})",
                this.Display, this.Screen, this.Handle, this.Parent != null ? this.Parent.ToString() : "null");
        }

        #endregion

        /// <summary>Checks if <c>this</c> and <c>obj</c> reference the same win32 window.</summary>
        /// <param name="obj">The object to check against.</param>
        /// <returns>True if <c>this</c> and <c>obj</c> reference the same win32 window; false otherwise.</returns>
        public override bool Equals(object obj)
        {
            if (obj == null) return false;
            if (this.GetType() != obj.GetType()) return false;
            X11WindowInfo info = (X11WindowInfo)obj;

            if (info == null) return false;
            // TODO: Assumes windows will have unique handles per X11 display.
            return object.Equals(display, info.display) &&
                   handle.Equals(info.handle);
        }

        /// <summary>Returns the hash code for this instance.</summary>
        /// <returns>A hash code for the current <c>X11WindowInfo</c>.</returns>
        public override int GetHashCode()
        {
            return handle.GetHashCode() ^ display.GetHashCode();
        }

        #endregion
    }
}