mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-02-02 08:31:08 +00:00
[Linux] Improved mouse cursor behavior
This commit is contained in:
parent
fd6ff962a1
commit
36bb366638
|
@ -255,7 +255,7 @@ namespace OpenTK.Platform.Linux
|
||||||
(int)Math.Round(CursorPosition.X + CursorOffset.X),
|
(int)Math.Round(CursorPosition.X + CursorOffset.X),
|
||||||
(int)Math.Round(CursorPosition.Y + CursorOffset.Y));
|
(int)Math.Round(CursorPosition.Y + CursorOffset.Y));
|
||||||
|
|
||||||
DisplayDevice display = DisplayDevice.FromPoint(p.X, p.Y);
|
DisplayDevice display = DisplayDevice.FromPoint(p.X, p.Y) ?? DisplayDevice.Default;
|
||||||
if (display != null)
|
if (display != null)
|
||||||
{
|
{
|
||||||
LinuxDisplay d = (LinuxDisplay)display.Id;
|
LinuxDisplay d = (LinuxDisplay)display.Id;
|
||||||
|
@ -465,8 +465,8 @@ namespace OpenTK.Platform.Linux
|
||||||
}
|
}
|
||||||
|
|
||||||
CursorPosition = new Vector2(
|
CursorPosition = new Vector2(
|
||||||
MathHelper.Clamp(CursorPosition.X + delta.X, bounds.Left, bounds.Right),
|
MathHelper.Clamp(CursorPosition.X + delta.X, bounds.Left, bounds.Right - 1),
|
||||||
MathHelper.Clamp(CursorPosition.Y + delta.Y, bounds.Top, bounds.Bottom));
|
MathHelper.Clamp(CursorPosition.Y + delta.Y, bounds.Top, bounds.Bottom - 1));
|
||||||
UpdateCursor();
|
UpdateCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -260,6 +260,7 @@ namespace OpenTK.Platform.Linux
|
||||||
|
|
||||||
MouseState ProcessMouse(MouseState mouse)
|
MouseState ProcessMouse(MouseState mouse)
|
||||||
{
|
{
|
||||||
|
// Handle mouse buttons
|
||||||
for (MouseButton i = 0; i < MouseButton.LastButton; i++)
|
for (MouseButton i = 0; i < MouseButton.LastButton; i++)
|
||||||
{
|
{
|
||||||
if (mouse[i] && !previous_mouse[i])
|
if (mouse[i] && !previous_mouse[i])
|
||||||
|
@ -273,11 +274,29 @@ namespace OpenTK.Platform.Linux
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mouse.X != previous_mouse.X || mouse.Y != previous_mouse.Y)
|
// Handle mouse movement
|
||||||
{
|
{
|
||||||
OnMouseMove(mouse.X, mouse.Y);
|
int x = mouse.X;
|
||||||
|
int y = mouse.Y;
|
||||||
|
|
||||||
|
// Make sure the mouse cannot leave the GameWindow when captured
|
||||||
|
if (!CursorVisible)
|
||||||
|
{
|
||||||
|
x = MathHelper.Clamp(mouse.X, Bounds.Left, Bounds.Right - 1);
|
||||||
|
y = MathHelper.Clamp(mouse.X, Bounds.Top, Bounds.Bottom - 1);
|
||||||
|
if (x != mouse.X || y != mouse.Y)
|
||||||
|
{
|
||||||
|
Mouse.SetPosition(x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (X != previous_mouse.X || Y != previous_mouse.Y)
|
||||||
|
{
|
||||||
|
OnMouseMove(x, y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle mouse scroll
|
||||||
if (mouse.Scroll != previous_mouse.Scroll)
|
if (mouse.Scroll != previous_mouse.Scroll)
|
||||||
{
|
{
|
||||||
float dx = mouse.Scroll.X - previous_mouse.Scroll.X;
|
float dx = mouse.Scroll.X - previous_mouse.Scroll.X;
|
||||||
|
@ -285,6 +304,7 @@ namespace OpenTK.Platform.Linux
|
||||||
OnMouseWheel(dx, dy);
|
OnMouseWheel(dx, dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle mouse focus
|
||||||
// Note: focus follows mouse. Literally.
|
// Note: focus follows mouse. Literally.
|
||||||
bool cursor_in = Bounds.Contains(new Point(mouse.X, mouse.Y));
|
bool cursor_in = Bounds.Contains(new Point(mouse.X, mouse.Y));
|
||||||
if (!cursor_in && Focused)
|
if (!cursor_in && Focused)
|
||||||
|
|
Loading…
Reference in a new issue