Skip to content

Commit

Permalink
Linux: Fixed scrolling with mouse wheel sometimes scrolling far more …
Browse files Browse the repository at this point in the history
…than intended
  • Loading branch information
SourMesen committed Jul 6, 2024
1 parent caaf8ed commit 9ca0fe5
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 9 deletions.
2 changes: 1 addition & 1 deletion UI/Debugger/Controls/CodeScrollBar.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private void UpdatePosition()
protected override void OnPointerWheelChanged(PointerWheelEventArgs e)
{
base.OnPointerWheelChanged(e);
Value = Math.Max(0, Math.Min(Maximum, Value - (int)(e.Delta.Y * 3)));
Value = Math.Max(0, Math.Min(Maximum, Value - (int)(e.GetDeltaY() * 3)));
}

private void IncrementClick(object? sender, RoutedEventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion UI/Debugger/Controls/HexEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ private void ScrollIntoView(int byteIndex, bool scrollToTop = false)
protected override void OnPointerWheelChanged(PointerWheelEventArgs e)
{
base.OnPointerWheelChanged(e);
this.TopRow = Math.Min((DataProvider.Length / BytesPerRow) - 1, Math.Max(0, this.TopRow - (int)(e.Delta.Y * 3)));
this.TopRow = Math.Min((DataProvider.Length / BytesPerRow) - 1, Math.Max(0, this.TopRow - (int)(e.GetDeltaY() * 3)));
}

protected override void OnPointerPressed(PointerPressedEventArgs e)
Expand Down
5 changes: 3 additions & 2 deletions UI/Debugger/Controls/PictureViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,10 @@ protected override void OnPointerWheelChanged(PointerWheelEventArgs e)
{
base.OnPointerWheelChanged(e);
if(e.KeyModifiers == KeyModifiers.Control) {
if(e.Delta.Y > 0) {
double delta = e.GetDeltaY();
if(delta > 0) {
ZoomIn();
} else {
} else if(delta < 0) {
ZoomOut();
}
e.Handled = true;
Expand Down
6 changes: 4 additions & 2 deletions UI/Debugger/Controls/ScrollPictureViewer.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Avalonia.Media;
using Avalonia.Metadata;
using Avalonia.Threading;
using Mesen.Utilities;
using System;
using System.Collections.Generic;

Expand Down Expand Up @@ -211,9 +212,10 @@ protected override void OnPointerWheelChanged(PointerWheelEventArgs e)
{
base.OnPointerWheelChanged(e);
if(e.KeyModifiers == KeyModifiers.Control) {
if(e.Delta.Y > 0) {
double delta = e.GetDeltaY();
if(delta > 0) {
InnerViewer.ZoomIn();
} else {
} else if(delta < 0) {
InnerViewer.ZoomOut();
}
e.Handled = true;
Expand Down
2 changes: 1 addition & 1 deletion UI/Debugger/Utilities/CodeViewerSelectionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void Viewer_CodePointerMoved(DisassemblyViewer sender, CodePointerMovedEv

public void Viewer_PointerWheelChanged(object? sender, PointerWheelEventArgs e)
{
_model.Scroll((int)(-e.Delta.Y * 3));
_model.Scroll((int)(-e.GetDeltaY() * 3));
}

private void Viewer_KeyDown(object? sender, KeyEventArgs e)
Expand Down
4 changes: 4 additions & 0 deletions UI/Debugger/ViewModels/DisassemblyViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ public void SetViewer(DisassemblyViewer? viewer)

public void Scroll(int lineNumberOffset)
{
if(lineNumberOffset == 0) {
return;
}

SetTopAddress(DataProvider.GetRowAddress(TopAddress, lineNumberOffset));
}

Expand Down
5 changes: 3 additions & 2 deletions UI/Debugger/Windows/PaletteViewerWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ public PaletteViewerWindow(CpuType cpuType)
private void Window_PointerWheelChanged(object? sender, PointerWheelEventArgs e)
{
if(e.KeyModifiers == KeyModifiers.Control) {
if(e.Delta.Y > 0) {
double delta = e.GetDeltaY();
if(delta > 0) {
_model.ZoomIn();
} else {
} else if(delta < 0) {
_model.ZoomOut();
}
e.Handled = true;
Expand Down
27 changes: 27 additions & 0 deletions UI/Utilities/PointerWheelEventArgsExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Avalonia.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mesen.Utilities;

static class PointerWheelEventArgsExtensions
{
public static double GetDeltaY(this PointerWheelEventArgs e)
{
if(OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) {
return e.Delta.Y;
}

if(Math.Abs(e.Delta.Y) > 8) {
//Avalonia currently seems to have an issue with mouse wheel events on Linux
//Alt-tabbing to another application, scrolling, alt-tabbing back, and then
//trying to scroll will return a large delta value that includes the amount
//of scrolling done in the other application. In this case, return 0.
return 0;
}
return e.Delta.Y;
}
}

0 comments on commit 9ca0fe5

Please sign in to comment.