From 31ee2e2ad57cd34171d505d01996c6c71f83498b Mon Sep 17 00:00:00 2001
From: Devan <68340659+DevanMetz@users.noreply.github.com>
Date: Tue, 27 Oct 2026 18:40:43 -0500
Subject: [PATCH 1/2] Show snip pixels as a grid in the Linux magnifier
The loupe scaled a filtered patch and slid off the cursor pixel at the edge of the frame. It now draws a 15 by 15 nearest-neighbor grid, keeps the center cell on that pixel, and shows the color.
---
linux/AssemblyInfo.cs | 3 +
linux/Magnifier.cs | 161 +++++++++++++++++++++
linux/OverlayWindow.cs | 142 +++++++++---------
tests/OpenSnip.Tests/MagnifierTests.cs | 136 +++++++++++++++++
tests/OpenSnip.Tests/OpenSnip.Tests.csproj | 25 ++++
5 files changed, 400 insertions(+), 67 deletions(-)
create mode 100644 linux/AssemblyInfo.cs
create mode 100644 linux/Magnifier.cs
create mode 100644 tests/OpenSnip.Tests/MagnifierTests.cs
create mode 100644 tests/OpenSnip.Tests/OpenSnip.Tests.csproj
diff --git a/linux/AssemblyInfo.cs b/linux/AssemblyInfo.cs
new file mode 100644
index 0000000..2a2947a
--- /dev/null
+++ b/linux/AssemblyInfo.cs
@@ -0,0 +1,3 @@
+using System.Runtime.CompilerServices;
+
+[assembly: InternalsVisibleTo("OpenSnip.Tests")]
diff --git a/linux/Magnifier.cs b/linux/Magnifier.cs
new file mode 100644
index 0000000..520b4a1
--- /dev/null
+++ b/linux/Magnifier.cs
@@ -0,0 +1,161 @@
+namespace OpenSnip;
+
+///
+/// The snip loupe: a 15×15 grid of the frozen frame, centered on the cursor pixel.
+/// Cells are sampled from that pixel so the center stays put when the cursor
+/// reaches the edge of the frame. A clamped source rectangle would slide it.
+///
+static class Magnifier
+{
+ public const int Cells = 15;
+ public const int Center = 7;
+
+ public readonly record struct Box(double X, double Y, double Width, double Height)
+ {
+ public double Right => X + Width;
+ public double Bottom => Y + Height;
+
+ public bool Overlaps(Box other) =>
+ X < other.Right && Right > other.X && Y < other.Bottom && Bottom > other.Y;
+ }
+
+ public static int ImageCoord(double local, double span, int pixels)
+ {
+ if (pixels <= 1 || span <= 0) return 0;
+ int value = (int)(local * pixels / span);
+ if (value < 0) return 0;
+ if (value >= pixels) return pixels - 1;
+ return value;
+ }
+
+ public static bool TryPixel(CapturedFrame frame, int x, int y, out byte r, out byte g, out byte b)
+ {
+ r = g = b = 0;
+ if (frame == null || (uint)x >= (uint)frame.Width || (uint)y >= (uint)frame.Height) return false;
+ int i = (y * frame.Width + x) * 4;
+ b = frame.Bgra[i];
+ g = frame.Bgra[i + 1];
+ r = frame.Bgra[i + 2];
+ return true;
+ }
+
+ public static string Label(int x, int y, byte r, byte g, byte b) =>
+ $"{x}, {y} #{r:X2}{g:X2}{b:X2}";
+
+ /// Packs a square of BGRA pixels. Outside the frame stays black.
+ public static void Fill(CapturedFrame frame, int x, int y, byte[] bgra)
+ {
+ if (frame == null) throw new ArgumentNullException(nameof(frame));
+ if (bgra == null || bgra.Length < Cells * Cells * 4)
+ throw new ArgumentException("The loupe buffer is too small.", nameof(bgra));
+
+ int count = Cells * Cells * 4;
+ for (int i = 0; i < count; i += 4)
+ {
+ bgra[i] = 0;
+ bgra[i + 1] = 0;
+ bgra[i + 2] = 0;
+ bgra[i + 3] = 255;
+ }
+
+ for (int row = 0; row < Cells; row++)
+ {
+ int sy = y + row - Center;
+ if ((uint)sy >= (uint)frame.Height) continue;
+ for (int col = 0; col < Cells; col++)
+ {
+ int sx = x + col - Center;
+ if ((uint)sx >= (uint)frame.Width) continue;
+ int src = (sy * frame.Width + sx) * 4;
+ int dst = (row * Cells + col) * 4;
+ bgra[dst] = frame.Bgra[src];
+ bgra[dst + 1] = frame.Bgra[src + 1];
+ bgra[dst + 2] = frame.Bgra[src + 2];
+ bgra[dst + 3] = 255;
+ }
+ }
+ }
+
+ /// Nearest-neighbor scale of the cell grid into screen pixels per cell.
+ public static void Expand(byte[] cells, int cell, byte[] dest)
+ {
+ if (cell < 1) throw new ArgumentOutOfRangeException(nameof(cell));
+ if (cells == null || cells.Length < Cells * Cells * 4)
+ throw new ArgumentException("The loupe buffer is too small.", nameof(cells));
+ int size = Cells * cell;
+ if (dest == null || dest.Length < size * size * 4)
+ throw new ArgumentException("The scaled buffer is too small.", nameof(dest));
+
+ int dstStride = size * 4;
+ for (int row = 0; row < Cells; row++)
+ {
+ for (int col = 0; col < Cells; col++)
+ {
+ int src = (row * Cells + col) * 4;
+ byte b = cells[src];
+ byte g = cells[src + 1];
+ byte r = cells[src + 2];
+ byte a = cells[src + 3];
+ int row0 = row * cell;
+ int col0 = col * cell;
+ for (int dy = 0; dy < cell; dy++)
+ {
+ int dst = (row0 + dy) * dstStride + col0 * 4;
+ for (int dx = 0; dx < cell; dx++)
+ {
+ dest[dst++] = b;
+ dest[dst++] = g;
+ dest[dst++] = r;
+ dest[dst++] = a;
+ }
+ }
+ }
+ }
+ }
+
+ ///
+ /// Puts the loupe beside the cursor, flipping to stay on screen and off .
+ ///
+ public static Box Place(double cursorX, double cursorY, double width, double height,
+ double boundsWidth, double boundsHeight, Box? avoid)
+ {
+ const double gap = 22;
+ const double margin = 4;
+
+ Box? TryAt(double x, double y)
+ {
+ if (x < margin || y < margin ||
+ x + width > boundsWidth - margin ||
+ y + height > boundsHeight - margin)
+ return null;
+ var rect = new Box(x, y, width, height);
+ if (avoid is { } blocked && rect.Overlaps(blocked)) return null;
+ return rect;
+ }
+
+ double right = cursorX + gap;
+ double left = cursorX - width - gap;
+ double down = cursorY + gap;
+ double up = cursorY - height - gap;
+
+ var found = TryAt(right, down) ?? TryAt(left, down) ?? TryAt(right, up) ?? TryAt(left, up);
+ if (found == null && avoid is { } blocked)
+ {
+ found = TryAt(blocked.Right + gap, down)
+ ?? TryAt(blocked.X - width - gap, down)
+ ?? TryAt(right, blocked.Bottom + gap)
+ ?? TryAt(right, blocked.Y - height - gap)
+ ?? TryAt(left, blocked.Bottom + gap)
+ ?? TryAt(left, blocked.Y - height - gap);
+ }
+ if (found is { } placed) return placed;
+
+ double fx = right;
+ double fy = down;
+ if (fx + width > boundsWidth - margin) fx = left;
+ if (fy + height > boundsHeight - margin) fy = up;
+ fx = Math.Clamp(fx, margin, Math.Max(margin, boundsWidth - width - margin));
+ fy = Math.Clamp(fy, margin, Math.Max(margin, boundsHeight - height - margin));
+ return new Box(fx, fy, width, height);
+ }
+}
diff --git a/linux/OverlayWindow.cs b/linux/OverlayWindow.cs
index df3fdbc..8fa7213 100644
--- a/linux/OverlayWindow.cs
+++ b/linux/OverlayWindow.cs
@@ -1,10 +1,13 @@
using System.Globalization;
+using System.Runtime.InteropServices;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Media;
using Avalonia.Media.Imaging;
+using Avalonia.Platform;
using Avalonia.Threading;
+using Avalonia.VisualTree;
namespace OpenSnip;
@@ -90,11 +93,18 @@ sealed class CaptureCanvas : Control
Point _end;
Point _cursor;
Rect? _selection;
+ byte[] _loupePixels;
+ byte[] _loupeScaled;
+ WriteableBitmap _loupe;
+ int _loupeCell;
static readonly IBrush DimBrush = new SolidColorBrush(Color.FromArgb(150, 0, 0, 0));
static readonly IBrush ReadoutBrush = new SolidColorBrush(Color.FromArgb(238, 38, 38, 44));
+ static readonly IBrush GridTint = new SolidColorBrush(Color.FromArgb(60, AppTheme.AccentColor.R, AppTheme.AccentColor.G, AppTheme.AccentColor.B));
static readonly IPen AccentPen = new Pen(AppTheme.Accent, 2);
static readonly IPen CrosshairPen = new Pen(AppTheme.Accent, 1);
+ static readonly IPen CenterWhite = new Pen(Brushes.White, 1);
+ static readonly IPen CenterBlack = new Pen(Brushes.Black, 1);
public CaptureCanvas(CapturedFrame frame, Settings settings, PixelRect virtualBounds, Action complete)
{
@@ -350,81 +360,79 @@ Rect DrawReadout(DrawingContext context, Rect selection)
return box;
}
- static bool Overlaps(Rect a, Rect b) =>
- a.Left < b.Right && a.Right > b.Left && a.Top < b.Bottom && a.Bottom > b.Top;
-
- Rect PlaceMagnifier(double width, double height, Rect? readout)
+ void DrawMagnifier(DrawingContext context, Rect? readout)
{
- const double gap = 22;
- const double margin = 4;
+ const double pad = 7;
+ const double swatch = 10;
+ const double infoH = 24;
+
+ int imageX = Magnifier.ImageCoord(_cursor.X, Bounds.Width, _frame.Width);
+ int imageY = Magnifier.ImageCoord(_cursor.Y, Bounds.Height, _frame.Height);
+ Magnifier.TryPixel(_frame, imageX, imageY, out byte red, out byte green, out byte blue);
+ var label = new FormattedText(Magnifier.Label(imageX, imageY, red, green, blue), CultureInfo.InvariantCulture,
+ FlowDirection.LeftToRight, _typeface, 12, AppTheme.Text);
+
+ int cell = Math.Max(8, (int)Math.Ceiling((label.Width + swatch + pad * 3) / Magnifier.Cells));
+ double grid = Magnifier.Cells * cell;
+ double boxW = Math.Max(grid, label.Width + swatch + pad * 3);
+ double boxH = grid + infoH;
+ Magnifier.Box? avoid = readout is { } block
+ ? new Magnifier.Box(block.X, block.Y, block.Width, block.Height)
+ : null;
+ var placed = Magnifier.Place(_cursor.X, _cursor.Y, boxW, boxH, Bounds.Width, Bounds.Height, avoid);
+ var box = new Rect(placed.X, placed.Y, placed.Width, placed.Height);
+
+ context.FillRectangle(Brushes.Black, box);
+
+ PaintLoupe(context, imageX, imageY, box.X + Math.Round((boxW - grid) / 2), box.Y, grid, cell);
+
+ double infoY = box.Y + grid;
+ context.FillRectangle(new SolidColorBrush(Color.FromRgb(red, green, blue)),
+ new Rect(box.X + pad, infoY + (infoH - swatch) / 2, swatch, swatch));
+ context.DrawText(label, new Point(box.X + pad + swatch + pad, infoY + (infoH - label.Height) / 2));
+ context.DrawRectangle(null, AccentPen, box);
+ }
- Rect? TryAt(double x, double y)
+ void PaintLoupe(DrawingContext context, int imageX, int imageY, double gridX, double gridY, double grid, int cell)
+ {
+ _loupePixels ??= new byte[Magnifier.Cells * Magnifier.Cells * 4];
+ Magnifier.Fill(_frame, imageX, imageY, _loupePixels);
+ int size = Magnifier.Cells * cell;
+ if (_loupe == null || _loupeCell != cell)
{
- if (x < margin || y < margin ||
- x + width > Bounds.Width - margin ||
- y + height > Bounds.Height - margin)
- return null;
- var rect = new Rect(x, y, width, height);
- if (readout is { } box && Overlaps(rect, box)) return null;
- return rect;
+ _loupe?.Dispose();
+ _loupe = new WriteableBitmap(new PixelSize(size, size), new Vector(96, 96), PixelFormat.Bgra8888, AlphaFormat.Opaque);
+ _loupeScaled = new byte[size * size * 4];
+ _loupeCell = cell;
}
-
- double right = _cursor.X + gap;
- double left = _cursor.X - width - gap;
- double down = _cursor.Y + gap;
- double up = _cursor.Y - height - gap;
-
- var found = TryAt(right, down) ?? TryAt(left, down) ?? TryAt(right, up) ?? TryAt(left, up);
- if (found == null && readout is { } r)
+ Magnifier.Expand(_loupePixels, cell, _loupeScaled);
+ using (var buffer = _loupe.Lock())
{
- found = TryAt(r.Right + gap, down)
- ?? TryAt(r.Left - width - gap, down)
- ?? TryAt(right, r.Bottom + gap)
- ?? TryAt(right, r.Top - height - gap)
- ?? TryAt(left, r.Bottom + gap)
- ?? TryAt(left, r.Top - height - gap);
+ int stride = size * 4;
+ for (int row = 0; row < size; row++)
+ Marshal.Copy(_loupeScaled, row * stride, IntPtr.Add(buffer.Address, row * buffer.RowBytes), stride);
}
- if (found is { } placed) return placed;
-
- // Tiny screen: flip away from the nearest edges and clamp to the bounds.
- double fx = right;
- double fy = down;
- if (fx + width > Bounds.Width - margin) fx = left;
- if (fy + height > Bounds.Height - margin) fy = up;
- fx = Math.Clamp(fx, margin, Math.Max(margin, Bounds.Width - width - margin));
- fy = Math.Clamp(fy, margin, Math.Max(margin, Bounds.Height - height - margin));
- return new Rect(fx, fy, width, height);
+
+ // Already nearest-neighbor. Draw 1:1 so the compositor does not blend the cells.
+ var dest = new Rect(gridX, gridY, grid, grid);
+ context.DrawImage(_loupe, dest);
+
+ double c0 = Magnifier.Center * cell;
+ double cellSize = cell;
+ context.FillRectangle(GridTint, new Rect(dest.X, dest.Y + c0, c0, cellSize));
+ context.FillRectangle(GridTint, new Rect(dest.X + c0 + cellSize, dest.Y + c0, grid - c0 - cellSize, cellSize));
+ context.FillRectangle(GridTint, new Rect(dest.X + c0, dest.Y, cellSize, c0));
+ context.FillRectangle(GridTint, new Rect(dest.X + c0, dest.Y + c0 + cellSize, cellSize, grid - c0 - cellSize));
+
+ var center = new Rect(dest.X + c0, dest.Y + c0, cellSize, cellSize);
+ context.DrawRectangle(null, CenterBlack, new Rect(center.X - 1, center.Y - 1, center.Width + 2, center.Height + 2));
+ context.DrawRectangle(null, CenterWhite, center);
}
- void DrawMagnifier(DrawingContext context, Rect? readout)
+ protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
{
- const double inner = 104;
- const double pad = 3;
- const double labelHeight = 20;
- double total = inner + pad * 2;
- var box = PlaceMagnifier(total, total + labelHeight, readout);
- double x = box.X;
- double y = box.Y;
-
- int imageX = Math.Clamp((int)(_cursor.X * _frame.Width / Math.Max(1, Bounds.Width)), 0, _frame.Width - 1);
- int imageY = Math.Clamp((int)(_cursor.Y * _frame.Height / Math.Max(1, Bounds.Height)), 0, _frame.Height - 1);
- int sourceSize = 24;
- int left = Math.Clamp(imageX - sourceSize / 2, 0, Math.Max(0, _frame.Width - sourceSize));
- int top = Math.Clamp(imageY - sourceSize / 2, 0, Math.Max(0, _frame.Height - sourceSize));
- var source = new Rect(left, top, Math.Min(sourceSize, _frame.Width), Math.Min(sourceSize, _frame.Height));
- var dest = new Rect(x + pad, y + pad, inner, inner);
-
- context.DrawRectangle(ReadoutBrush, new Pen(AppTheme.Accent, 2), new Rect(x, y, total, total + labelHeight), 7, 7);
- using (context.PushClip(dest))
- {
- context.DrawImage(_bitmap, source, dest);
- }
- var center = dest.Center;
- context.DrawLine(CrosshairPen, new Point(center.X - 7, center.Y), new Point(center.X + 7, center.Y));
- context.DrawLine(CrosshairPen, new Point(center.X, center.Y - 7), new Point(center.X, center.Y + 7));
-
- var label = new FormattedText($"{imageX}, {imageY}", CultureInfo.InvariantCulture,
- FlowDirection.LeftToRight, _typeface, 11, AppTheme.Muted);
- context.DrawText(label, new Point(x + (total - label.Width) / 2, y + total + 2));
+ base.OnDetachedFromVisualTree(e);
+ _loupe?.Dispose();
+ _loupe = null;
}
}
diff --git a/tests/OpenSnip.Tests/MagnifierTests.cs b/tests/OpenSnip.Tests/MagnifierTests.cs
new file mode 100644
index 0000000..fd00132
--- /dev/null
+++ b/tests/OpenSnip.Tests/MagnifierTests.cs
@@ -0,0 +1,136 @@
+namespace OpenSnip.Tests;
+
+public class MagnifierTests
+{
+ [Fact]
+ public void CenterCellIsTheCursorPixel()
+ {
+ var frame = Frame(5, 5,
+ (2, 2, 255, 0, 0),
+ (1, 2, 0, 255, 0),
+ (3, 3, 0, 0, 255));
+ var loupe = new byte[Magnifier.Cells * Magnifier.Cells * 4];
+ Magnifier.Fill(frame, 2, 2, loupe);
+
+ Assert.Equal((255, 0, 0, 255), At(loupe, Magnifier.Center, Magnifier.Center));
+ Assert.Equal((0, 255, 0, 255), At(loupe, Magnifier.Center - 1, Magnifier.Center));
+ Assert.Equal((0, 0, 255, 255), At(loupe, Magnifier.Center + 1, Magnifier.Center + 1));
+ }
+
+ [Fact]
+ public void EdgeDoesNotSlideTheCenterCell()
+ {
+ var frame = Frame(4, 3, (0, 0, 10, 20, 30), (3, 2, 200, 10, 1));
+ var loupe = new byte[Magnifier.Cells * Magnifier.Cells * 4];
+
+ Magnifier.Fill(frame, 0, 0, loupe);
+ Assert.Equal((10, 20, 30, 255), At(loupe, Magnifier.Center, Magnifier.Center));
+ Assert.Equal((0, 0, 0, 255), At(loupe, Magnifier.Center - 1, Magnifier.Center));
+ Assert.Equal((0, 0, 0, 255), At(loupe, Magnifier.Center, Magnifier.Center - 1));
+
+ Magnifier.Fill(frame, 3, 2, loupe);
+ Assert.Equal((200, 10, 1, 255), At(loupe, Magnifier.Center, Magnifier.Center));
+ Assert.Equal((0, 0, 0, 255), At(loupe, Magnifier.Center + 1, Magnifier.Center));
+ Assert.Equal((0, 0, 0, 255), At(loupe, Magnifier.Center, Magnifier.Center + 1));
+ }
+
+ [Fact]
+ public void ExpandKeepsCellsCrisp()
+ {
+ var frame = Frame(3, 3, (1, 1, 255, 0, 0), (2, 2, 0, 0, 255));
+ var cells = new byte[Magnifier.Cells * Magnifier.Cells * 4];
+ Magnifier.Fill(frame, 1, 1, cells);
+ const int cell = 3;
+ var scaled = new byte[Magnifier.Cells * cell * Magnifier.Cells * cell * 4];
+ Magnifier.Expand(cells, cell, scaled);
+
+ int origin = Magnifier.Center * cell;
+ for (int dy = 0; dy < cell; dy++)
+ for (int dx = 0; dx < cell; dx++)
+ Assert.Equal((255, 0, 0, 255), ScaledAt(scaled, cell, origin + dx, origin + dy));
+
+ int neighbor = (Magnifier.Center + 1) * cell;
+ Assert.Equal((0, 0, 255, 255), ScaledAt(scaled, cell, neighbor, neighbor));
+ Assert.Equal((255, 0, 0, 255), ScaledAt(scaled, cell, origin + cell - 1, origin + cell - 1));
+ Assert.NotEqual((255, 0, 0, 255), ScaledAt(scaled, cell, origin + cell, origin));
+ }
+
+ [Fact]
+ public void LabelMatchesTheWindowsReadout()
+ {
+ Assert.True(Magnifier.TryPixel(Frame(2, 2, (1, 0, 0x0A, 0xB0, 0xC3)), 1, 0, out byte r, out byte g, out byte b));
+ Assert.Equal("1, 0 #0AB0C3", Magnifier.Label(1, 0, r, g, b));
+ Assert.False(Magnifier.TryPixel(Frame(2, 2), -1, 0, out _, out _, out _));
+ }
+
+ [Theory]
+ [InlineData(0, 100, 100, 0)]
+ [InlineData(50, 100, 200, 100)]
+ [InlineData(99.9, 100, 100, 99)]
+ [InlineData(100, 100, 100, 99)]
+ [InlineData(-4, 100, 100, 0)]
+ [InlineData(10, 0, 100, 0)]
+ [InlineData(10, 100, 1, 0)]
+ public void ImageCoordMatchesTheFrameMapping(double local, double span, int pixels, int expected)
+ {
+ Assert.Equal(expected, Magnifier.ImageCoord(local, span, pixels));
+ }
+
+ [Fact]
+ public void LoupeSitsDownAndRightOfTheCursor()
+ {
+ var box = Magnifier.Place(10, 10, 120, 140, 800, 600, null);
+ Assert.Equal(new Magnifier.Box(32, 32, 120, 140), box);
+ }
+
+ [Fact]
+ public void LoupeFlipsAtTheBottomRightEdge()
+ {
+ var box = Magnifier.Place(790, 590, 120, 140, 800, 600, null);
+ Assert.Equal(new Magnifier.Box(648, 428, 120, 140), box);
+ }
+
+ [Fact]
+ public void LoupeMovesOffTheSizeReadout()
+ {
+ var readout = new Magnifier.Box(122, 122, 120, 140);
+ var box = Magnifier.Place(100, 100, 120, 140, 800, 600, readout);
+ Assert.False(box.Overlaps(readout));
+ Assert.Equal(new Magnifier.Box(264, 122, 120, 140), box);
+ }
+
+ [Fact]
+ public void LoupeClampsWhenItCannotFit()
+ {
+ var box = Magnifier.Place(50, 50, 200, 200, 100, 100, null);
+ Assert.Equal(new Magnifier.Box(4, 4, 200, 200), box);
+ }
+
+ static (byte R, byte G, byte B, byte A) ScaledAt(byte[] bgra, int cell, int x, int y)
+ {
+ int size = Magnifier.Cells * cell;
+ int i = (y * size + x) * 4;
+ return (bgra[i + 2], bgra[i + 1], bgra[i], bgra[i + 3]);
+ }
+
+ static (byte R, byte G, byte B, byte A) At(byte[] bgra, int col, int row)
+ {
+ int i = (row * Magnifier.Cells + col) * 4;
+ return (bgra[i + 2], bgra[i + 1], bgra[i], bgra[i + 3]);
+ }
+
+ static CapturedFrame Frame(int width, int height, params (int X, int Y, byte R, byte G, byte B)[] pixels)
+ {
+ var data = new byte[width * height * 4];
+ for (int i = 3; i < data.Length; i += 4) data[i] = 255;
+ foreach (var pixel in pixels)
+ {
+ int i = (pixel.Y * width + pixel.X) * 4;
+ data[i] = pixel.B;
+ data[i + 1] = pixel.G;
+ data[i + 2] = pixel.R;
+ data[i + 3] = 255;
+ }
+ return new CapturedFrame(width, height, data);
+ }
+}
diff --git a/tests/OpenSnip.Tests/OpenSnip.Tests.csproj b/tests/OpenSnip.Tests/OpenSnip.Tests.csproj
new file mode 100644
index 0000000..69c6f44
--- /dev/null
+++ b/tests/OpenSnip.Tests/OpenSnip.Tests.csproj
@@ -0,0 +1,25 @@
+
+
+
+ net9.0
+ enable
+ disable
+ false
+ OpenSnip.Tests
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
From 9cceebf8b8f1d91a97a81681116f67b6b6ff1f66 Mon Sep 17 00:00:00 2001
From: Devan <68340659+DevanMetz@users.noreply.github.com>
Date: Tue, 27 Oct 2026 18:40:43 -0500
Subject: [PATCH 2/2] Document Linux parity and run the magnifier tests in CI
---
.github/workflows/build.yml | 3 ++
PARITY.md | 84 +++++++++++++++++++++++++++++++++++++
README.md | 4 +-
3 files changed, 89 insertions(+), 2 deletions(-)
create mode 100644 PARITY.md
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 07db7a9..4bca468 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -47,6 +47,9 @@ jobs:
with:
dotnet-version: 9.0.x
+ - name: Test
+ run: dotnet test tests/OpenSnip.Tests/OpenSnip.Tests.csproj -c Release --nologo
+
- name: Publish
run: dotnet publish linux/OpenSnip.Linux.csproj -c Release -r linux-x64 --self-contained true -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true -p:EnableCompressionInSingleFile=true -p:DebugType=none -o dist/linux
diff --git a/PARITY.md b/PARITY.md
new file mode 100644
index 0000000..cbc256f
--- /dev/null
+++ b/PARITY.md
@@ -0,0 +1,84 @@
+# Linux parity
+
+Status of each Windows feature on Linux. This file describes the tree it ships with.
+
+`working` matches Windows. `partial` works, with the gap named here. `missing` has no Linux path yet. `not possible` cannot be added; the closest equivalent is named.
+
+## Selection
+
+| Feature | Linux | Files |
+|---|---|---|
+| Region snip on a frozen screen | partial. The drag omits the pixel under the pointer at the far edge. Windows includes it. | `linux/OverlayWindow.cs`, `linux/Capture.cs` |
+| Click grabs the monitor under the cursor | working | `linux/OverlayWindow.cs` |
+| Click grabs the window under the cursor | missing | `src/CaptureOverlay.cs`, `linux/OverlayWindow.cs` |
+| `F` captures that monitor now | partial. Linux selects it. Enter or the mouse confirms. | `linux/OverlayWindow.cs` |
+| `A` captures every monitor now | partial. Same as `F`. A recording on Windows stays on one monitor. | `linux/OverlayWindow.cs` |
+| Enter confirms the selection, or the monitor when nothing is selected | working | `linux/OverlayWindow.cs` |
+| Arrow keys nudge 1 px, Shift nudges 10 | partial. Linux moves the overlay cursor and does not move the pointer. | `linux/OverlayWindow.cs` |
+| Esc and right-click cancel the drag first, then the snip | partial. Linux cancels the whole snip. | `linux/OverlayWindow.cs` |
+| Pixel-grid magnifier, coordinate, and color | working. 15×15 nearest-neighbor cells, the center cell stays on the cursor pixel at the frame edge, and the strip shows a swatch and `#RRGGBB`. Coordinates are pixels in the frozen frame. | `linux/Magnifier.cs`, `linux/OverlayWindow.cs` |
+| Magnifier can be turned off | working | `linux/SettingsWindow.cs` |
+| Mixed-DPI placement | partial. One window uses one scale for the whole desktop. | `linux/OverlayWindow.cs` |
+| Hint text on the overlay | not possible. It is helper text. | `src/CaptureOverlay.cs` |
+
+## Capture and saving
+
+| Feature | Linux | Files |
+|---|---|---|
+| X11 capture | partial. The import is `libX11`, which looks for `libX11.so`. Desktops ship `libX11.so.6`. `maim`, ImageMagick `import`, and `scrot` are fallbacks. | `linux/Capture.cs` |
+| Wayland capture | working. Portal screenshot, then `grim`, `gnome-screenshot`, and `spectacle`. | `linux/Capture.cs`, `linux/DBus.cs` |
+| Copy a PNG to the clipboard | working. `xclip` on X11, `wl-copy` on Wayland, then Avalonia. | `linux/ClipboardService.cs` |
+| Auto-save PNG or JPG | working. Quality 92 matches Windows. | `linux/CapturedFrame.cs`, `linux/SettingsWindow.cs` |
+| `--capture file.jpeg` | partial. Any extension other than `jpg` is written as PNG. | `linux/CapturedFrame.cs`, `linux/CaptureCli.cs` |
+| Monthly subfolders | working | `src/Settings.cs` |
+| Preview on the monitor that was snipped | partial. The preview sits on the primary monitor and takes focus. | `linux/ThumbnailWindow.cs` |
+| Preview stays up while the pointer is over it, then fades | partial. A timer closes it. Hover does not pause it, and it does not fade. | `linux/ThumbnailWindow.cs` |
+| Click the preview to annotate | partial. Click opens the file with `xdg-open`. | `linux/ThumbnailWindow.cs` |
+| Drag the preview into another app | missing | `src/SmallWindows.cs`, `linux/ThumbnailWindow.cs` |
+| Annotation editor | missing | `src/EditorForm.cs`, `src/Shapes.cs` |
+| Open the editor after a snip | missing. The shared setting is unused on Linux. | `src/Settings.cs`, `linux/App.cs` |
+| Pin a snip, including from the clipboard | missing | `src/SmallWindows.cs` |
+| Delayed snip | partial. The countdown is centered on the primary monitor, takes focus, and can appear in the shot. | `linux/CountdownWindow.cs` |
+| Tray snip waits so the menu is not in the shot | missing | `linux/App.cs`, `src/TrayApp.cs` |
+| Repeat the last region | working | `linux/App.cs` |
+
+## Screen recording
+
+| Feature | Linux | Files |
+|---|---|---|
+| Record a region to MP4 | missing | `src/Recording.cs` |
+| Record the window under the cursor | missing | `src/CaptureOverlay.cs` |
+| Countdown, red outline, and control bar | missing | `src/Recording.cs` |
+| System audio and microphone | missing | `src/Recording.cs`, `src/SettingsForm.cs` |
+| 30 or 60 fps, quality, cursor | missing | `src/Settings.cs` |
+| Copy the MP4 and show a preview | missing | `src/TrayApp.cs`, `src/SmallWindows.cs` |
+| `Win+Shift+R` | missing | `src/TrayApp.cs` |
+
+## Shortcuts, tray, and commands
+
+| Feature | Linux | Files |
+|---|---|---|
+| `Win+Shift+S`, delay, repeat, Print Screen | missing. Bind `opensnip --snip`, `--snip-delay`, and `--repeat` in the desktop. | `linux/Cli.cs`, `linux/SettingsWindow.cs` |
+| Tray: snip, snip after delay, repeat, screenshots folder, settings, exit | working | `linux/App.cs` |
+| Tray click starts a snip | working | `linux/App.cs` |
+| Record, pin, open in editor, recordings folder | missing | `src/TrayApp.cs` |
+| Tooltip names the snip shortcut | missing. The tooltip is "OpenSnip". | `linux/App.cs` |
+| First-run balloon | not possible. It is helper text. The tray menu is the control. | `src/TrayApp.cs` |
+| Second launch forwards snip, delay, repeat, and settings | working | `linux/SingleInstance.cs` |
+| `--capture` and `--diagnostics` | working | `linux/Cli.cs`, `linux/CaptureCli.cs`, `linux/Diagnostics.cs` |
+
+## Settings
+
+| Setting | Linux | Files |
+|---|---|---|
+| Copy to the clipboard | working | `linux/SettingsWindow.cs` |
+| Show a preview, and how long it stays | working | `linux/SettingsWindow.cs` |
+| Open the editor, or do nothing else | partial. Unchecking the preview leaves nothing else. There is no editor option. | `linux/SettingsWindow.cs`, `src/SettingsForm.cs` |
+| Magnifier | working | `linux/SettingsWindow.cs` |
+| Delayed-snip length | working | `linux/SettingsWindow.cs` |
+| Auto-save, screenshot folder, PNG or JPG, monthly folders | working | `linux/SettingsWindow.cs` |
+| Recording folder and recording options | missing | `src/SettingsForm.cs` |
+| Shortcut editor and Print Screen | missing. The Shortcuts page lists commands. | `linux/SettingsWindow.cs` |
+| Start on login | working. XDG autostart. | `linux/Autostart.cs` |
+| Open the settings folder | working | `linux/SettingsWindow.cs` |
+| Reset to defaults | partial. Resets the options this window shows. Shortcut and recording fields stay as stored. | `linux/SettingsWindow.cs` |
diff --git a/README.md b/README.md
index 987b573..f1cf5bb 100644
--- a/README.md
+++ b/README.md
@@ -117,7 +117,7 @@ Run `OpenSnip.exe --diagnostics` to write a report (displays, audio devices, and
The Linux app is a separate native Avalonia build. It covers the screenshot side of OpenSnip; recording, the annotation editor, pins and built-in global shortcuts remain Windows-only.
-**What works:** X11 capture through libX11, with `maim`, ImageMagick `import` and `scrot` as fallbacks; Wayland capture through the `xdg-desktop-portal` Screenshot API, with `grim`, `gnome-screenshot` and `spectacle` as fallbacks; region, monitor and all-monitor selection with a magnifier; clipboard as PNG; auto-save as PNG or JPG; preview; tray icon; and settings.
+**What works:** X11 capture through libX11, with `maim`, ImageMagick `import` and `scrot` as fallbacks; Wayland capture through the `xdg-desktop-portal` Screenshot API, with `grim`, `gnome-screenshot` and `spectacle` as fallbacks; region, monitor and all-monitor selection with a pixel-grid magnifier that shows the coordinate and color; clipboard as PNG; auto-save as PNG or JPG; preview; tray icon; and settings.
**Install:** download `OpenSnip-linux-x64.tar.gz` from [Releases](https://github.com/DevanMetz/OpenSnip/releases), then:
@@ -207,7 +207,7 @@ Issues and pull requests are welcome. The code is plain WinForms + GDI+; recordi
| `src/Imaging.cs` | Screen capture, window detection, clipboard, saving, icon |
| `linux/Program.cs` / `linux/App.cs` | Linux app startup, single instance, tray and snip flow |
| `linux/Capture.cs` / `linux/DBus.cs` | X11, Wayland portal and external capture backends |
-| `linux/OverlayWindow.cs` | Linux selection overlay and magnifier |
+| `linux/OverlayWindow.cs` / `linux/Magnifier.cs` | Linux selection overlay and pixel magnifier |
| `linux/SettingsWindow.cs` | Linux Settings window |
## License