Permalink
Browse files

[Linux] Implemented MouseCursor

  • Loading branch information...
1 parent 015acba commit 153522c0a4aa15d864a37bad117766367c4f7853 @thefiddler thefiddler committed Jul 17, 2014
@@ -351,6 +351,26 @@ internal DisplayResolution OriginalResolution
#endregion
+ #region FromPoint
+
+ internal static DisplayDevice FromPoint(int x, int y)
+ {
+ for (DisplayIndex i = DisplayIndex.First; i < DisplayIndex.Sixth; i++)
+ {
+ DisplayDevice display = DisplayDevice.GetDisplay(i);
+ if (display != null)
+ {
+ if (display.Bounds.Contains(x, y))
+ {
+ return display;
+ }
+ }
+ }
+ return null;
+ }
+
+ #endregion
+
#endregion
#region --- Private Methods ---
@@ -822,6 +822,8 @@
<Compile Include="Platform\Linux\Bindings\Terminal.cs" />
<Compile Include="Platform\DeviceCollection.cs" />
<Compile Include="Platform\Linux\Bindings\Evdev.cs" />
+ <Compile Include="Platform\Linux\DefaultCursor.cs" />
+ <Compile Include="Platform\Linux\Bindings\Kms.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
@@ -89,6 +89,13 @@ class Drm
[DllImport(lib, EntryPoint = "drmModeSetCrtc", CallingConvention = CallingConvention.Cdecl)]
unsafe public static extern int ModeSetCrtc(int fd, int crtcId, int bufferId,
int x, int y, int* connectors, int count, ModeInfo* mode);
+
+ [DllImport(lib, EntryPoint = "drmModeSetCursor2", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int SetCursor(int fd, int crtcId, int bo_handle, int width, int height, int hot_x, int hot_y);
+
+ [DllImport(lib, EntryPoint = "drmModeMoveCursor", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int MoveCursor(int fd, int crtcId, int x, int y);
+
}
enum ModeConnection
@@ -32,9 +32,8 @@
namespace OpenTK.Platform.Linux
{
- using Device = IntPtr; // opaque pointer "struct gbm_device*"
+ using Device = IntPtr; // struct gbm_device*
using Surface = IntPtr;
- using BufferObject = IntPtr;
using BufferObjectHandle = IntPtr;
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
@@ -44,23 +43,32 @@ class Gbm
{
const string lib = "gbm";
+ [DllImport(lib, EntryPoint = "gbm_bo_create", CallingConvention = CallingConvention.Cdecl)]
+ public static extern BufferObject CreateBuffer(Device gbm, int width, int height, SurfaceFormat format, SurfaceFlags flags);
+
+ [DllImport(lib, EntryPoint = "gbm_bo_destroy", CallingConvention = CallingConvention.Cdecl)]
+ public static extern void DestroyBuffer(BufferObject bo);
+
+ [DllImport(lib, EntryPoint = "gbm_bo_write", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int BOWrite(IntPtr bo, IntPtr buf, IntPtr count);
+
[DllImport(lib, EntryPoint = "gbm_bo_get_device", CallingConvention = CallingConvention.Cdecl)]
- public static extern Device BOGetDevice(BufferObject bo);
+ public static extern Device BOGetDevice(IntPtr bo);
[DllImport(lib, EntryPoint = "gbm_bo_get_handle", CallingConvention = CallingConvention.Cdecl)]
- public static extern BufferObjectHandle BOGetHandle(BufferObject bo);
+ public static extern BufferObjectHandle BOGetHandle(IntPtr bo);
[DllImport(lib, EntryPoint = "gbm_bo_get_height", CallingConvention = CallingConvention.Cdecl)]
- public static extern int BOGetHeight(BufferObject bo);
+ public static extern int BOGetHeight(IntPtr bo);
[DllImport(lib, EntryPoint = "gbm_bo_get_width", CallingConvention = CallingConvention.Cdecl)]
- public static extern int BOGetWidth(BufferObject bo);
+ public static extern int BOGetWidth(IntPtr bo);
[DllImport(lib, EntryPoint = "gbm_bo_get_stride", CallingConvention = CallingConvention.Cdecl)]
- public static extern int BOGetStride(BufferObject bo);
+ public static extern int BOGetStride(IntPtr bo);
[DllImport(lib, EntryPoint = "gbm_bo_set_user_data", CallingConvention = CallingConvention.Cdecl)]
- public static extern void BOSetUserData(BufferObject bo, IntPtr data, DestroyUserDataCallback callback);
+ public static extern void BOSetUserData(IntPtr bo, IntPtr data, DestroyUserDataCallback callback);
[DllImport(lib, EntryPoint = "gbm_create_device", CallingConvention = CallingConvention.Cdecl)]
public static extern Device CreateDevice(int fd);
@@ -174,5 +182,97 @@ enum SurfaceFlags
Rendering = (1 << 2),
Write = (1 << 3),
}
+
+ [StructLayout(LayoutKind.Sequential)]
+ struct BufferObject : IEquatable<BufferObject>
+ {
+ IntPtr buffer;
+
+ public static readonly BufferObject Zero =
+ default(BufferObject);
+
+ public int Write(byte[] data)
+ {
+ unsafe
+ {
+ fixed (byte* pdata = data)
+ {
+ return Gbm.BOWrite(buffer, (IntPtr)pdata, (IntPtr)data.Length);
+ }
+ }
+ }
+
+ public void SetUserData(IntPtr data, DestroyUserDataCallback destroyFB)
+ {
+ Gbm.BOSetUserData(buffer, data, destroyFB);
+ }
+
+ public Device Device
+ {
+ get { return Gbm.BOGetDevice(buffer); }
+ }
+
+ public int Handle
+ {
+ get { return Gbm.BOGetHandle(buffer).ToInt32(); }
+ }
+
+ public int Width
+ {
+ get { return Gbm.BOGetWidth(buffer); }
+ }
+
+ public int Height
+ {
+ get { return Gbm.BOGetHeight(buffer); }
+ }
+
+ public int Stride
+ {
+ get { return Gbm.BOGetStride(buffer); }
+ }
+
+ public void Dispose()
+ {
+ Gbm.DestroyBuffer(this);
+ buffer = IntPtr.Zero;
+ }
+
+ public static bool operator ==(BufferObject left, BufferObject right)
+ {
+ return left.Equals(right);
+ }
+
+ public static bool operator !=(BufferObject left, BufferObject right)
+ {
+ return !left.Equals(right);
+ }
+
+ public override bool Equals(object obj)
+ {
+ return
+ obj is BufferObject &&
+ this.Equals((BufferObject)obj);
+ }
+
+ public override int GetHashCode()
+ {
+ return buffer.GetHashCode();
+ }
+
+ public override string ToString()
+ {
+ return string.Format("[BufferObject: {0}]", buffer);
+ }
+
+ #region IEquatable implementation
+
+ public bool Equals(BufferObject other)
+ {
+ return buffer == other.buffer;
+ }
+
+ #endregion
+ }
}
@@ -0,0 +1,46 @@
+#region License
+//
+// Kms.cs
+//
+// Author:
+// Stefanos A. <stapostol@gmail.com>
+//
+// Copyright (c) 2006-2014
+//
+// 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.Runtime.InteropServices;
+
+namespace OpenTK.Platform.Linux
+{
+ class Kms
+ {
+ const string lib = "libkms";
+
+ [DllImport(lib, EntryPoint = "kms_bo_map", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int MapBuffer(IntPtr bo, out IntPtr @out);
+
+ [DllImport(lib, EntryPoint = "kms_bo_unmap", CallingConvention = CallingConvention.Cdecl)]
+ public static extern int UnmapBuffer(IntPtr bo);
+ }
+}
+
Oops, something went wrong.

0 comments on commit 153522c

Please sign in to comment.