Merge branch 'develop' into glwidget-gtk3

This commit is contained in:
Jarl Gullberg 2017-06-25 13:45:05 +02:00
commit 13494f515c
No known key found for this signature in database
GPG key ID: 750FF6F6BDA72D23
13 changed files with 533 additions and 192 deletions

416
.gitignore vendored
View file

@ -1,31 +1,63 @@
# =============================================
# Visual Studio & Associated technologies
# =============================================
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# Xamarin Studio / monodevelop user-specific
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
*.dll.mdb
*.exe.mdb
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
build/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
**/Properties/launchSettings.json
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
@ -45,24 +77,31 @@ build/
*.vssscc
.builds
*.pidb
*.log
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Other Visual Studio data
.vs/
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
@ -70,6 +109,10 @@ ipch/
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
@ -77,9 +120,21 @@ _TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
*.ncrunch*
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
@ -98,57 +153,158 @@ DocProject/Help/html
publish/
# Publish Web Output
*.Publish.xml
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Enable nuget.exe in the .nuget folder (though normally executables are not tracked)
!.nuget/NuGet.exe
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# Windows Azure Build Output
csx
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Windows Store app package directory
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
App_Data/*.mdf
App_Data/*.ldf
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
#LightSwitch generated files
GeneratedArtifacts/
_Pvt_Extensions/
ModelManifest.xml
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Typescript v1 declaration files
typings/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# =========================
# Windows detritus
# =========================
# Windows image file caches
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
Desktop.ini
@ -156,8 +312,46 @@ Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Mac desktop service store files
.DS_Store
# Windows Installer files
*.cab
*.msi
*.msm
*.msp
# Windows shortcuts
*.lnk
# ===========
# Macintosh
# ===========
# General
*.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# ===================================================
# Exclude F# project specific directories and files
@ -189,3 +383,165 @@ docs/content/license.md
docs/content/release-notes.md
.fake
docs/tools/FSharp.Formatting.svclog
# ===========
# Covers JetBrains IDEs: Rider, IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# ===========
# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
# CMake
cmake-build-debug/
# Mongo Explorer plugin:
.idea/**/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# ============
# MonoDevelop
# ============
#User Specific
*.userprefs
*.usertasks
#Mono Project Files
*.pidb
*.resources
test-results/
# ================
# Linux-specific
# ================
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
# ============
# VS Code
# ============
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
# ============
# Emacs
# ============
# -*- mode: gitignore; -*-
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*
# Org-mode
.org-id-locations
*_archive
# flymake-mode
*_flymake.*
# eshell files
/eshell/history
/eshell/lastdir
# elpa packages
/elpa/
# reftex files
*.rel
# AUCTeX auto folder
/auto/
# cask packages
.cask/
dist/
# Flycheck
flycheck_*.el
# server auth directory
/server/
# projectiles files
.projectile
# directory configuration
.dir-locals.el
# ===========
# Vim
# ===========
# Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-v][a-z]
[._]sw[a-p]
# Session
Session.vim
# Temporary
.netrwhist
*~
# Auto-generated tag files
tags

View file

@ -750,9 +750,6 @@
<Compile Include="Platform\MacOS\CarbonWindowInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Platform\MacOS\Carbon\CarbonAPI.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Platform\MacOS\Carbon\MacOSKeys.cs">
<SubType>Code</SubType>
</Compile>

View file

@ -45,9 +45,12 @@ namespace OpenTK.Platform.Linux
{
internal const string lib = "libinput";
[DllImport(lib, EntryPoint = "libinput_udev_create_for_seat", CallingConvention = CallingConvention.Cdecl)]
[DllImport(lib, EntryPoint = "libinput_udev_create_context", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr CreateContext(InputInterface @interface,
IntPtr user_data, IntPtr udev, string seat_id);
IntPtr user_data, IntPtr udev);
[DllImport(lib, EntryPoint = "libinput_udev_assign_seat", CallingConvention = CallingConvention.Cdecl)]
public static extern int AssignSeat(IntPtr libinput, string seat_id);
[DllImport(lib, EntryPoint = "libinput_destroy", CallingConvention = CallingConvention.Cdecl)]
public static extern void DestroyContext(IntPtr libinput);
@ -192,31 +195,6 @@ namespace OpenTK.Platform.Linux
HorizontalScroll = 1
}
struct Fixed24
{
internal readonly int Value;
public static implicit operator double(Fixed24 n)
{
long l = ((1023L + 44L) << 52) + (1L << 51) + n.Value;
unsafe
{
double d = *(double*)&l;
return d - (3L << 43);
}
}
public static implicit operator float(Fixed24 n)
{
return (float)(double)n;
}
public static explicit operator int(Fixed24 n)
{
return n.Value >> 8;
}
}
[StructLayout(LayoutKind.Sequential)]
class InputInterface
{
@ -275,14 +253,14 @@ namespace OpenTK.Platform.Linux
public EvdevButton Button { get { return (EvdevButton)GetButton(@event); } }
public uint ButtonCount { get { return GetButtonCount(@event); } }
public ButtonState ButtonState { get { return GetButtonState(@event); } }
public PointerAxis Axis { get { return GetAxis(@event); } }
public Fixed24 AxisValue { get { return GetAxisValue(@event); } }
public Fixed24 DeltaX { get { return GetDX(@event); } }
public Fixed24 DeltaY { get { return GetDY(@event); } }
public Fixed24 X { get { return GetAbsX(@event); } }
public Fixed24 Y { get { return GetAbsY(@event); } }
public Fixed24 TransformedX(int width) { return GetAbsXTransformed(@event, width); }
public Fixed24 TransformedY(int height) { return GetAbsYTransformed(@event, height); }
public bool HasAxis(PointerAxis axis) { return HasAxis(@event, axis) != 0; }
public double AxisValue(PointerAxis axis) { return GetAxisValue(@event, axis); }
public double DeltaX { get { return GetDX(@event); } }
public double DeltaY { get { return GetDY(@event); } }
public double X { get { return GetAbsX(@event); } }
public double Y { get { return GetAbsY(@event); } }
public double TransformedX(int width) { return GetAbsXTransformed(@event, width); }
public double TransformedY(int height) { return GetAbsYTransformed(@event, height); }
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_time", CallingConvention = CallingConvention.Cdecl)]
static extern uint GetTime(IntPtr @event);
@ -302,29 +280,29 @@ namespace OpenTK.Platform.Linux
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_button_state", CallingConvention = CallingConvention.Cdecl)]
static extern ButtonState GetButtonState(IntPtr @event);
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_axis", CallingConvention = CallingConvention.Cdecl)]
static extern PointerAxis GetAxis(IntPtr @event);
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_has_axis", CallingConvention = CallingConvention.Cdecl)]
static extern int HasAxis(IntPtr @event, PointerAxis axis);
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_axis_value", CallingConvention = CallingConvention.Cdecl)]
static extern Fixed24 GetAxisValue(IntPtr @event);
static extern double GetAxisValue(IntPtr @event, PointerAxis axis);
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_dx", CallingConvention = CallingConvention.Cdecl)]
static extern Fixed24 GetDX(IntPtr @event);
static extern double GetDX(IntPtr @event);
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_dy", CallingConvention = CallingConvention.Cdecl)]
static extern Fixed24 GetDY(IntPtr @event);
static extern double GetDY(IntPtr @event);
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_absolute_x", CallingConvention = CallingConvention.Cdecl)]
static extern Fixed24 GetAbsX(IntPtr @event);
static extern double GetAbsX(IntPtr @event);
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_absolute_y", CallingConvention = CallingConvention.Cdecl)]
static extern Fixed24 GetAbsY(IntPtr @event);
static extern double GetAbsY(IntPtr @event);
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_absolute_x_transformed", CallingConvention = CallingConvention.Cdecl)]
static extern Fixed24 GetAbsXTransformed(IntPtr @event, int width);
static extern double GetAbsXTransformed(IntPtr @event, int width);
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_absolute_y_transformed", CallingConvention = CallingConvention.Cdecl)]
static extern Fixed24 GetAbsYTransformed(IntPtr @event, int height);
static extern double GetAbsYTransformed(IntPtr @event, int height);
}
}

View file

@ -67,9 +67,6 @@ namespace OpenTK.Platform.Linux
{
base.SwapBuffers();
bo_next = LockSurface();
int fb = GetFramebuffer(bo_next);
if (is_flip_queued)
{
// Todo: if we don't wait for the page flip,
@ -84,6 +81,8 @@ namespace OpenTK.Platform.Linux
}
}
bo_next = LockSurface();
int fb = GetFramebuffer(bo_next);
QueueFlip(fb);
}

View file

@ -314,7 +314,7 @@ namespace OpenTK.Platform.Linux
}
Debug.Print("[Input] Udev.New() = {0:x}", udev);
input_context = LibInput.CreateContext(input_interface, IntPtr.Zero, udev, "seat0");
input_context = LibInput.CreateContext(input_interface, IntPtr.Zero, udev);
if (input_context == IntPtr.Zero)
{
Debug.Print("[Input] LibInput.CreateContext({0:x}) failed.", udev);
@ -323,6 +323,16 @@ namespace OpenTK.Platform.Linux
}
Debug.Print("[Input] LibInput.CreateContext({0:x}) = {1:x}", udev, input_context);
string seat_id = "seat0";
int seat_assignment = LibInput.AssignSeat(input_context, seat_id);
if (seat_assignment == -1)
{
Debug.Print("[Input] LibInput.AssignSeat({0:x}) = {1} failed.", input_context, seat_id);
Interlocked.Increment(ref exit);
return;
}
Debug.Print("[Input] LibInput.AssignSeat({0:x}) = {1}", input_context, seat_id);
fd = LibInput.GetFD(input_context);
if (fd < 0)
{
@ -475,21 +485,13 @@ namespace OpenTK.Platform.Linux
{
mouse.State.SetIsConnected(true);
double value = e.AxisValue;
PointerAxis axis = e.Axis;
switch (axis)
if (e.HasAxis(PointerAxis.HorizontalScroll))
{
case PointerAxis.HorizontalScroll:
mouse.State.SetScrollRelative((float)value, 0);
break;
case PointerAxis.VerticalScroll:
mouse.State.SetScrollRelative(0, (float)value);
break;
default:
Debug.Print("[Input] Unknown scroll axis {0}.", axis);
break;
mouse.State.SetScrollRelative((float)e.AxisValue(PointerAxis.HorizontalScroll), 0);
}
if (e.HasAxis(PointerAxis.VerticalScroll))
{
mouse.State.SetScrollRelative(0, (float)e.AxisValue(PointerAxis.VerticalScroll));
}
}
}
@ -508,7 +510,7 @@ namespace OpenTK.Platform.Linux
void HandlePointerMotion(MouseDevice mouse, PointerEvent e)
{
Vector2 delta = new Vector2((float)e.X, (float)e.Y);
Vector2 delta = new Vector2((float)e.DeltaX, (float)e.DeltaY);
if (mouse != null)
{
mouse.State.SetIsConnected(true);
@ -526,12 +528,12 @@ namespace OpenTK.Platform.Linux
if (mouse != null)
{
mouse.State.SetIsConnected(true);
mouse.State.Position = new Vector2(e.X, e.Y);
mouse.State.Position = new Vector2((float)e.X, (float)e.Y);
}
CursorPosition = new Vector2(
e.TransformedX(bounds.Width),
e.TransformedY(bounds.Height));
(float)e.TransformedX(bounds.Width),
(float)e.TransformedY(bounds.Height));
UpdateCursor();
}

View file

@ -366,6 +366,7 @@ namespace OpenTK.Platform.Linux
if (disposing)
{
Debug.Print("[KMS] Destroying window {0}.", window.Handle);
Drm.SetCursor(window.FD, window.DisplayDevice.Id, 0, 0, 0, 0, 0);
window.Dispose();
Gbm.DestroySurface(window.Handle);
}

View file

@ -1,78 +0,0 @@
#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
// Created by Erik Ylvisaker on 3/17/08.
using System;
using System.Runtime.InteropServices;
namespace OpenTK.Platform.MacOS.Carbon
{
#region --- Types defined in HIGeometry.h ---
[StructLayout(LayoutKind.Sequential)]
internal struct HIPoint
{
public float X;
public float Y;
public HIPoint(float x, float y)
{
X = x;
Y = y;
}
public HIPoint(double x, double y)
: this((float)x, (float)y)
{ }
}
[StructLayout(LayoutKind.Sequential)]
internal struct HISize
{
public float Width;
public float Height;
}
[StructLayout(LayoutKind.Sequential)]
internal struct HIRect
{
public HIPoint Origin;
public HISize Size;
public override string ToString()
{
return string.Format(
"Rect: [{0}, {1}, {2}, {3}]", Origin.X, Origin.Y, Size.Width, Size.Height);
}
}
#endregion
}

View file

@ -160,7 +160,32 @@ namespace OpenTK.Platform.MacOS
// Not the _stret version, perhaps because a NSPoint fits in one register?
// thefiddler: gcc is indeed using objc_msgSend for NSPoint on i386
[DllImport (LibObjC, EntryPoint="objc_msgSend")]
public extern static NSPoint SendPoint(IntPtr receiver, IntPtr selector);
public extern static NSPointF SendPointF(IntPtr receiver, IntPtr selector);
[DllImport (LibObjC, EntryPoint="objc_msgSend")]
public extern static NSPointD SendPointD(IntPtr receiver, IntPtr selector);
public static NSPoint SendPoint(IntPtr receiver, IntPtr selector)
{
NSPoint r = new NSPoint();
unsafe
{
if (IntPtr.Size == 4)
{
NSPointF pf = SendPointF(receiver, selector);
r.X.Value = *(IntPtr *)&pf.X;
r.Y.Value = *(IntPtr *)&pf.Y;
}
else
{
NSPointD pd = SendPointD(receiver, selector);
r.X.Value = *(IntPtr *)&pd.X;
r.Y.Value = *(IntPtr *)&pd.Y;
}
}
return r;
}
[DllImport (LibObjC, EntryPoint="objc_msgSend_stret")]
extern static void SendRect(out NSRect retval, IntPtr receiver, IntPtr selector);

View file

@ -45,6 +45,18 @@ namespace OpenTK.Platform.MacOS
{
IntPtr value;
public IntPtr Value
{
get
{
return value;
}
set
{
this.value = value;
}
}
public static implicit operator NSFloat(float v)
{
NSFloat f;
@ -106,7 +118,7 @@ namespace OpenTK.Platform.MacOS
}
else
{
return *(float*)&f.value;
return *(double*)&f.value;
}
}
}
@ -179,5 +191,21 @@ namespace OpenTK.Platform.MacOS
return new RectangleF(s.Location, s.Size);
}
}
}
// Using IntPtr in NSFloat cause that if imported function
// return struct that consist of them you will get wrong data
// This types are used for such function.
[StructLayout(LayoutKind.Sequential)]
struct NSPointF
{
public float X;
public float Y;
}
[StructLayout(LayoutKind.Sequential)]
struct NSPointD
{
public double X;
public double Y;
}
}

View file

@ -273,7 +273,7 @@ namespace OpenTK.Platform.MacOS
case CGEventType.RightMouseDragged:
case CGEventType.OtherMouseDragged:
{
Carbon.HIPoint p = CG.EventGetLocation(@event);
NSPoint p = CG.EventGetLocation(@event);
CursorState.X = (int)Math.Round(p.X);
CursorState.Y = (int)Math.Round(p.Y);
}
@ -1045,7 +1045,15 @@ namespace OpenTK.Platform.MacOS
void IMouseDriver2.SetPosition(double x, double y)
{
CG.SetLocalEventsSuppressionInterval(0.0);
CG.WarpMouseCursorPosition(new Carbon.HIPoint(x, y));
NSPoint p = new NSPoint();
unsafe
{
p.X.Value = *(IntPtr *)&x;
p.Y.Value = *(IntPtr *)&y;
}
CG.WarpMouseCursorPosition(p);
}
#endregion

View file

@ -60,9 +60,9 @@ namespace OpenTK.Platform.MacOS
{
const string lib = "/System/Library/Frameworks/ApplicationServices.framework/Versions/Current/ApplicationServices";
// CGPoint -> HIPoint
// CGSize -> HISize
// CGRect -> HIRect
// CGPoint -> NSPoint
// CGSize -> NSSize
// CGRect -> NSRect
[DllImport(lib,EntryPoint="CGGetActiveDisplayList")]
internal unsafe static extern CGDisplayErr GetActiveDisplayList(int maxDisplays, IntPtr* activeDspys, out int dspyCnt);
@ -75,15 +75,15 @@ namespace OpenTK.Platform.MacOS
// first parameter slot. This is normally handled automatically
// by gcc/clang, but here we have to do it ourselves.
// See "Listing 4" on https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/LowLevelABI/130-IA-32_Function_Calling_Conventions/IA32.html#//apple_ref/doc/uid/TP40002492-SW3
internal unsafe static HIRect DisplayBounds(IntPtr display)
internal unsafe static NSRect DisplayBounds(IntPtr display)
{
HIRect rect;
NSRect rect;
DisplayBounds(out rect, display);
return rect;
}
[DllImport(lib, EntryPoint = "CGDisplayBounds")]
unsafe static extern void DisplayBounds(out HIRect rect, IntPtr display);
unsafe static extern void DisplayBounds(out NSRect rect, IntPtr display);
[DllImport(lib,EntryPoint="CGDisplayPixelsWide")]
internal static extern int DisplayPixelsWide(IntPtr display);
@ -116,7 +116,7 @@ namespace OpenTK.Platform.MacOS
internal static extern IntPtr DisplaySwitchToMode(IntPtr display, IntPtr displayMode);
[DllImport(lib, EntryPoint = "CGWarpMouseCursorPosition")]
internal static extern CGError WarpMouseCursorPosition(HIPoint newCursorPosition);
internal static extern CGError WarpMouseCursorPosition(NSPoint newCursorPosition);
[DllImport(lib, EntryPoint = "CGCursorIsVisible")]
internal static extern bool CursorIsVisible();

View file

@ -66,7 +66,32 @@ namespace OpenTK.Platform.MacOS
CGEventField field);
[DllImport(lib, EntryPoint = "CGEventGetLocation")]
internal static extern Carbon.HIPoint EventGetLocation(CGEventRef @event);
internal static extern NSPointF EventGetLocationF(CGEventRef @event);
[DllImport(lib, EntryPoint = "CGEventGetLocation")]
internal static extern NSPointD EventGetLocationD(CGEventRef @event);
internal static NSPoint EventGetLocation(CGEventRef @event)
{
NSPoint r = new NSPoint();
unsafe {
if (IntPtr.Size == 4)
{
NSPointF pf = EventGetLocationF(@event);
r.X.Value = *(IntPtr *)&pf.X;
r.Y.Value = *(IntPtr *)&pf.Y;
}
else
{
NSPointD pd = EventGetLocationD(@event);
r.X.Value = *(IntPtr *)&pd.X;
r.Y.Value = *(IntPtr *)&pd.Y;
}
}
return r;
}
}
enum CGEventTapLocation

View file

@ -109,8 +109,8 @@ namespace OpenTK.Platform.MacOS
}
HIRect bounds = CG.DisplayBounds(currentDisplay);
Rectangle newRect = new Rectangle((int)bounds.Origin.X, (int)bounds.Origin.Y, (int)bounds.Size.Width, (int)bounds.Size.Height);
NSRect bounds = CG.DisplayBounds(currentDisplay);
Rectangle newRect = new Rectangle((int)bounds.Location.X, (int)bounds.Location.Y, (int)bounds.Size.Width, (int)bounds.Size.Height);
Debug.Print("Display {0} bounds: {1}", i, newRect);