* OpenTK.csproj:

* Platform/MacOS/HIDInput.cs:
* Platform/MacOS/MacOSFactory.cs:
* Platform/MacOS/CarbonBindings/CoreFoundation.cs: Initial work on HID
  input manager.
This commit is contained in:
the_fiddler 2010-11-22 15:57:26 +00:00
parent 6c0da79687
commit 4fd279534b
4 changed files with 169 additions and 2 deletions

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<ProjectType>Local</ProjectType>
@ -765,6 +765,7 @@
<EmbeddedResource Include="OpenTK.dll.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<Compile Include="Platform\MacOS\HIDInput.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>

View file

@ -5,6 +5,8 @@ using System.Text;
namespace OpenTK.Platform.MacOS.Carbon
{
using CFRunLoop = System.IntPtr;
struct CFArray
{
IntPtr arrayRef;
@ -112,5 +114,8 @@ namespace OpenTK.Platform.MacOS.Carbon
kCFNumberCGFloatType = 16,
kCFNumberMaxType = 16
};
[DllImport(appServices)]
internal static extern CFRunLoop CFRunLoopGetCurrent();
}
}

View file

@ -0,0 +1,161 @@
#region License
//
// The Open Toolkit Library License
//
// Copyright (c) 2006 - 2010 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.Diagnostics;
using System.Runtime.InteropServices;
using OpenTK.Input;
namespace OpenTK.Platform.MacOS
{
using Carbon;
using CFAllocatorRef = System.IntPtr;
using CFDictionaryRef = System.IntPtr;
using CFRunLoop = System.IntPtr;
using CFString = System.IntPtr;
using IOHIDDeviceRef = System.IntPtr;
using IOHIDManagerRef = System.IntPtr;
using IOOptionBits = System.IntPtr;
using IOReturn = System.IntPtr;
class HIDInput : IMouseDriver2
{
#region Fields
readonly IOHIDManagerRef hidmanager;
readonly static NativeMethods.IOHIDDeviceCallback HandleDeviceAdded = delegate
{
Debug.WriteLine("Device added");
};
readonly static NativeMethods.IOHIDDeviceCallback HandleDeviceRemoved = delegate
{
Debug.WriteLine("Device Removed");
};
readonly static CFString RunLoopMode = CF.CFSTR("OPENTK_INPUT");
readonly static CFDictionary DeviceTypes = new CFDictionary();
#endregion
#region Constructors
public HIDInput()
{
Debug.Print("Using {0}.", typeof(HIDInput).Name);
hidmanager = CreateHIDManager();
RegisterHIDCallbacks(hidmanager);
}
#endregion
#region Private Members
static IOHIDManagerRef CreateHIDManager()
{
return NativeMethods.IOHIDManagerCreate(IntPtr.Zero, IntPtr.Zero);
}
static void RegisterHIDCallbacks(IOHIDManagerRef hidmanager)
{
CFRunLoop runloop = Carbon.CF.CFRunLoopGetCurrent();
NativeMethods.IOHIDManagerRegisterDeviceMatchingCallback(
hidmanager, HandleDeviceAdded, IntPtr.Zero);
NativeMethods.IOHIDManagerRegisterDeviceRemovalCallback(
hidmanager, HandleDeviceRemoved, IntPtr.Zero);
NativeMethods.IOHIDManagerScheduleWithRunLoop(hidmanager,
runloop, RunLoopMode);
NativeMethods.IOHIDManagerSetDeviceMatching(hidmanager, DeviceTypes.Ref);
NativeMethods.IOHIDManagerOpen(hidmanager, IOOptionBits.Zero);
}
#endregion
#region IMouseDriver2 Members
public MouseState GetState()
{
return new MouseState();
}
public MouseState GetState(int index)
{
return new MouseState();
}
#endregion
#region NativeMethods
class NativeMethods
{
const string hid = "/System/Library/Frameworks/IOKit.framework/Versions/Current/IOKit";
[DllImport(hid)]
public static extern IOHIDManagerRef IOHIDManagerCreate(
CFAllocatorRef allocator, IOOptionBits options) ;
// This routine will be called when a new (matching) device is connected.
[DllImport(hid)]
public static extern void IOHIDManagerRegisterDeviceMatchingCallback(
IOHIDManagerRef inIOHIDManagerRef,
IOHIDDeviceCallback inIOHIDDeviceCallback,
IntPtr inContext);
// This routine will be called when a (matching) device is disconnected.
[DllImport(hid)]
public static extern void IOHIDManagerRegisterDeviceRemovalCallback(
IOHIDManagerRef inIOHIDManagerRef,
IOHIDDeviceCallback inIOHIDDeviceCallback,
IntPtr inContext);
[DllImport(hid)]
public static extern void IOHIDManagerScheduleWithRunLoop(
IOHIDManagerRef inIOHIDManagerRef,
CFRunLoop inCFRunLoop,
CFString inCFRunLoopMode);
[DllImport(hid)]
public static extern void IOHIDManagerSetDeviceMatching(
IOHIDManagerRef manager,
CFDictionaryRef matching) ;
[DllImport(hid)]
public static extern IOReturn IOHIDManagerOpen(
IOHIDManagerRef manager,
IOOptionBits options) ;
public delegate void IOHIDDeviceCallback(IntPtr ctx, IOReturn res, IntPtr sender, IOHIDDeviceRef device);
}
#endregion
}
}

View file

@ -77,7 +77,7 @@ namespace OpenTK.Platform.MacOS
public virtual OpenTK.Input.IMouseDriver2 CreateMouseDriver()
{
throw new NotImplementedException();
return new HIDInput();
}
#endregion