From afb544d2938f0ea1c09f818fe249cebc3560a63c Mon Sep 17 00:00:00 2001 From: Devan <68340659+DevanMetz@users.noreply.github.com> Date: Tue, 27 Oct 2026 17:41:51 -0500 Subject: [PATCH 1/3] Match the Windows selection keys on Linux F and A finish immediately, Enter confirms the selection or the monitor, and Esc or a right-click cancels the drag before the snip. On X11 the arrow keys move the real pointer. --- linux/AssemblyInfo.cs | 3 + linux/OverlayWindow.cs | 149 ++++++++++++++------- linux/SnipGeometry.cs | 118 ++++++++++++++++ linux/SnipGesture.cs | 75 +++++++++++ linux/X11Cursor.cs | 78 +++++++++++ tests/OpenSnip.Tests/OpenSnip.Tests.csproj | 25 ++++ tests/OpenSnip.Tests/SnipGeometryTests.cs | 91 +++++++++++++ tests/OpenSnip.Tests/SnipGestureTests.cs | 64 +++++++++ 8 files changed, 557 insertions(+), 46 deletions(-) create mode 100644 linux/AssemblyInfo.cs create mode 100644 linux/SnipGeometry.cs create mode 100644 linux/SnipGesture.cs create mode 100644 linux/X11Cursor.cs create mode 100644 tests/OpenSnip.Tests/OpenSnip.Tests.csproj create mode 100644 tests/OpenSnip.Tests/SnipGeometryTests.cs create mode 100644 tests/OpenSnip.Tests/SnipGestureTests.cs 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/OverlayWindow.cs b/linux/OverlayWindow.cs index df3fdbc..7da2a9b 100644 --- a/linux/OverlayWindow.cs +++ b/linux/OverlayWindow.cs @@ -43,6 +43,8 @@ public OverlayWindow(CapturedFrame frame, Settings settings) Closed += (_, _) => _result.TrySetResult(null); } + public PixelRect VirtualBounds => _virtualBounds; + public Task SelectAsync() { Show(); @@ -86,6 +88,7 @@ sealed class CaptureCanvas : Control bool _dragging; bool _hasPointer; bool _keyboardCursor; + IPointer _pointer; Point _start; Point _end; Point _cursor; @@ -109,54 +112,97 @@ public CaptureCanvas(CapturedFrame frame, Settings settings, PixelRect virtualBo public bool HandleKey(KeyEventArgs e) { - switch (e.Key) + if (!TryMapKey(e.Key, out var key)) return false; + bool pastSlop = DragPastSlop(); + bool ready = pastSlop && SelectionReady; + Apply(SnipGesture.FromKey(key, e.KeyModifiers.HasFlag(KeyModifiers.Shift), _dragging, ready, pastSlop)); + return true; + } + + bool DragPastSlop() + { + if (!_dragging) return false; + return Math.Abs(_end.X - _start.X) > 3 || Math.Abs(_end.Y - _start.Y) > 3; + } + + static bool TryMapKey(Key key, out SnipKey mapped) + { + switch (key) + { + case Key.Escape: mapped = SnipKey.Escape; return true; + case Key.Enter: mapped = SnipKey.Enter; return true; + case Key.F: mapped = SnipKey.Monitor; return true; + case Key.A: mapped = SnipKey.All; return true; + case Key.Left: mapped = SnipKey.Left; return true; + case Key.Right: mapped = SnipKey.Right; return true; + case Key.Up: mapped = SnipKey.Up; return true; + case Key.Down: mapped = SnipKey.Down; return true; + default: mapped = default; return false; + } + } + + bool SelectionReady => _selection is { Width: >= 1, Height: >= 1 }; + + void Apply(SnipGesture gesture) + { + switch (gesture.Kind) { - case Key.Escape: + case SnipGestureKind.Cancel: _complete(null); - return true; - case Key.Enter: + break; + case SnipGestureKind.ResetDrag: + ResetDrag(); + break; + case SnipGestureKind.CompleteSelection: if (_selection is { } current) _complete(ToImageRect(current)); - else _complete(MonitorAt(CurrentCursor())); - return true; - case Key.A: - _selection = new Rect(0, 0, Bounds.Width, Bounds.Height); - _keyboardCursor = false; - InvalidateVisual(); - return true; - case Key.F: - _selection = MonitorRect(CurrentCursor()); - _keyboardCursor = false; - InvalidateVisual(); - return true; - case Key.Left: - case Key.Right: - case Key.Up: - case Key.Down: - Nudge(e.Key, e.KeyModifiers.HasFlag(KeyModifiers.Shift)); - return true; + break; + case SnipGestureKind.CompleteMonitor: + _complete(MonitorAt(CurrentCursor())); + break; + case SnipGestureKind.CompleteAll: + _complete(new PixelRect(0, 0, _frame.Width, _frame.Height)); + break; + case SnipGestureKind.Nudge: + Nudge(gesture.Dx, gesture.Dy); + break; } - return false; } - void Nudge(Key key, bool large) + void ResetDrag() + { + _dragging = false; + _selection = null; + try { _pointer?.Capture(null); } catch { } + _pointer = null; + InvalidateVisual(); + } + + void Nudge(int dx, int dy) { - double step = large ? 10 : 1; - var delta = key switch + if (X11Cursor.TryGet() is { } pointer) { - Key.Left => new Vector(-step, 0), - Key.Right => new Vector(step, 0), - Key.Up => new Vector(0, -step), - _ => new Vector(0, step), - }; - if (!_hasPointer) + var screen = SnipGeometry.ClampTo(pointer.X + dx, pointer.Y + dy, _virtualBounds); + bool warped = X11Cursor.TryWarp(screen.X, screen.Y); + MoveCursor(ScreenToLocal(screen.X, screen.Y), keyboard: !warped); + return; + } + + var delta = SnipGeometry.ControlDelta(dx, dy, Bounds.Width, Bounds.Height, _frame.Width, _frame.Height); + var origin = _hasPointer ? _cursor : new Point(Bounds.Width / 2, Bounds.Height / 2); + MoveCursor(origin + new Vector(delta.X, delta.Y), keyboard: true); + } + + void MoveCursor(Point local, bool keyboard) + { + _cursor = ClampPoint(local); + _hasPointer = true; + _keyboardCursor = keyboard; + if (_dragging) { - _cursor = new Point(Bounds.Width / 2, Bounds.Height / 2); - _hasPointer = true; + _end = _cursor; + var rect = RectFromPoints(_start, _end); + _selection = rect.Width >= 1 && rect.Height >= 1 ? rect : null; } - _cursor = ClampPoint(_cursor + delta); - if (_selection is { } current) - _selection = ClampRect(current.Translate(delta)); - _keyboardCursor = true; InvalidateVisual(); } @@ -167,13 +213,14 @@ protected override void OnPointerPressed(PointerPressedEventArgs e) var point = e.GetPosition(this); if (e.GetCurrentPoint(this).Properties.IsRightButtonPressed) { - _complete(null); + Apply(SnipGesture.FromRightClick(_dragging)); e.Handled = true; return; } if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return; _dragging = true; + _pointer = e.Pointer; _start = _end = _cursor = ClampPoint(point); _hasPointer = true; _keyboardCursor = false; @@ -189,6 +236,7 @@ protected override void OnPointerMoved(PointerEventArgs e) var point = ClampPoint(e.GetPosition(this)); _cursor = point; _hasPointer = true; + _keyboardCursor = false; if (_dragging) { _end = point; @@ -203,6 +251,7 @@ protected override void OnPointerReleased(PointerReleasedEventArgs e) base.OnPointerReleased(e); if (!_dragging) return; _dragging = false; + _pointer = null; e.Pointer.Capture(null); var point = ClampPoint(e.GetPosition(this)); _cursor = point; @@ -233,17 +282,24 @@ Rect RectFromPoints(Point a, Point b) Point ClampPoint(Point point) => new(Math.Clamp(point.X, 0, Math.Max(0, Bounds.Width)), Math.Clamp(point.Y, 0, Math.Max(0, Bounds.Height))); - Rect ClampRect(Rect rect) + Point CurrentCursor() { - double x = Math.Clamp(rect.X, 0, Math.Max(0, Bounds.Width - rect.Width)); - double y = Math.Clamp(rect.Y, 0, Math.Max(0, Bounds.Height - rect.Height)); - return new Rect(x, y, rect.Width, rect.Height); + if (_hasPointer) return _cursor; + if (Bounds.Width > 1 && X11Cursor.TryGet() is { } pointer) + { + _cursor = ClampPoint(ScreenToLocal(pointer.X, pointer.Y)); + _hasPointer = true; + return _cursor; + } + if (Bounds.Width > 1) return new Point(Bounds.Width / 2, Bounds.Height / 2); + return new Point(0, 0); } - Point CurrentCursor() + Point ScreenToLocal(int screenX, int screenY) { - if (_hasPointer) return _cursor; - return new Point(Bounds.Width / 2, Bounds.Height / 2); + double sx = Bounds.Width / Math.Max(1, _virtualBounds.Width); + double sy = Bounds.Height / Math.Max(1, _virtualBounds.Height); + return new Point((screenX - _virtualBounds.X) * sx, (screenY - _virtualBounds.Y) * sy); } Rect MonitorRect(Point local) @@ -287,6 +343,7 @@ PixelRect ToImageRect(Rect local) public override void Render(DrawingContext context) { + if (!_hasPointer) CurrentCursor(); base.Render(context); var bounds = new Rect(0, 0, Bounds.Width, Bounds.Height); context.DrawImage(_bitmap, bounds); diff --git a/linux/SnipGeometry.cs b/linux/SnipGeometry.cs new file mode 100644 index 0000000..b7b5b09 --- /dev/null +++ b/linux/SnipGeometry.cs @@ -0,0 +1,118 @@ +using Avalonia; + +namespace OpenSnip; + +static class SnipGeometry +{ + public static PixelRect ToScreen(PixelRect image, PixelRect virtualBounds, int frameWidth, int frameHeight) + { + if (frameWidth <= 0 || frameHeight <= 0) return image; + if (frameWidth == virtualBounds.Width && frameHeight == virtualBounds.Height) + return new PixelRect(virtualBounds.X + image.X, virtualBounds.Y + image.Y, image.Width, image.Height); + + double sx = virtualBounds.Width / (double)frameWidth; + double sy = virtualBounds.Height / (double)frameHeight; + return new PixelRect( + virtualBounds.X + (int)Math.Round(image.X * sx), + virtualBounds.Y + (int)Math.Round(image.Y * sy), + Math.Max(1, (int)Math.Round(image.Width * sx)), + Math.Max(1, (int)Math.Round(image.Height * sy))); + } + + public static PixelRect ScreenToImage(PixelRect screen, PixelRect virtualBounds, int frameWidth, int frameHeight) + { + if (frameWidth <= 0 || frameHeight <= 0) return new PixelRect(0, 0, 1, 1); + if (virtualBounds.Width <= 0 || virtualBounds.Height <= 0) + return new PixelRect(0, 0, frameWidth, frameHeight); + + double sx = frameWidth / (double)virtualBounds.Width; + double sy = frameHeight / (double)virtualBounds.Height; + int x = (int)Math.Round((screen.X - virtualBounds.X) * sx); + int y = (int)Math.Round((screen.Y - virtualBounds.Y) * sy); + int width = Math.Max(1, (int)Math.Round(screen.Width * sx)); + int height = Math.Max(1, (int)Math.Round(screen.Height * sy)); + x = Math.Clamp(x, 0, Math.Max(0, frameWidth - 1)); + y = Math.Clamp(y, 0, Math.Max(0, frameHeight - 1)); + width = Math.Clamp(width, 1, frameWidth - x); + height = Math.Clamp(height, 1, frameHeight - y); + return new PixelRect(x, y, width, height); + } + + /// Screen that contains the most of , or the nearest when none overlap. + public static int BestScreen(PixelRect rect, IReadOnlyList screens) + { + if (screens == null || screens.Count == 0) return -1; + + int best = 0; + long bestArea = -1; + for (int i = 0; i < screens.Count; i++) + { + long area = OverlapArea(rect, screens[i]); + if (area > bestArea) + { + bestArea = area; + best = i; + } + } + if (bestArea > 0) return best; + + int closest = 0; + long bestDistance = long.MaxValue; + for (int i = 0; i < screens.Count; i++) + { + long distance = Separation(rect, screens[i]); + if (distance < bestDistance) + { + bestDistance = distance; + closest = i; + } + } + return closest; + } + + public static PixelPoint BottomCenter(PixelRect area, int width, int height, int margin) + { + width = Math.Max(1, width); + height = Math.Max(1, height); + int x = area.X + Math.Max(0, area.Width - width) / 2; + int y = area.Bottom - height - Math.Max(0, margin); + if (x < area.X) x = area.X; + if (y < area.Y) y = area.Y; + return new PixelPoint(x, y); + } + + public static PixelPoint ClampTo(int x, int y, PixelRect bounds) + { + int maxX = bounds.Width <= 1 ? bounds.X : bounds.Right - 1; + int maxY = bounds.Height <= 1 ? bounds.Y : bounds.Bottom - 1; + return new PixelPoint(Math.Clamp(x, bounds.X, maxX), Math.Clamp(y, bounds.Y, maxY)); + } + + public static (double X, double Y) ControlDelta(int dx, int dy, double controlWidth, double controlHeight, int imageWidth, int imageHeight) + { + double sx = controlWidth <= 1 || imageWidth <= 0 ? 1 : controlWidth / imageWidth; + double sy = controlHeight <= 1 || imageHeight <= 0 ? 1 : controlHeight / imageHeight; + return (dx * sx, dy * sy); + } + + static long OverlapArea(PixelRect a, PixelRect b) + { + int left = Math.Max(a.X, b.X); + int top = Math.Max(a.Y, b.Y); + int right = Math.Min(a.Right, b.Right); + int bottom = Math.Min(a.Bottom, b.Bottom); + if (right <= left || bottom <= top) return 0; + return (long)(right - left) * (bottom - top); + } + + static long Separation(PixelRect a, PixelRect b) + { + long dx = 0; + if (a.Right <= b.X) dx = b.X - a.Right; + else if (b.Right <= a.X) dx = a.X - b.Right; + long dy = 0; + if (a.Bottom <= b.Y) dy = b.Y - a.Bottom; + else if (b.Bottom <= a.Y) dy = a.Y - b.Bottom; + return dx + dy; + } +} diff --git a/linux/SnipGesture.cs b/linux/SnipGesture.cs new file mode 100644 index 0000000..2809ecb --- /dev/null +++ b/linux/SnipGesture.cs @@ -0,0 +1,75 @@ +namespace OpenSnip; + +enum SnipKey +{ + Escape, + Enter, + Monitor, + All, + Left, + Right, + Up, + Down, +} + +enum SnipGestureKind +{ + None, + Cancel, + ResetDrag, + CompleteSelection, + CompleteMonitor, + CompleteAll, + Nudge, +} + +/// What a selection key does. Matches the Windows overlay. +readonly record struct SnipGesture(SnipGestureKind Kind, int Dx, int Dy) +{ + public static SnipGesture FromKey(SnipKey key, bool shift, bool pointerDown, bool selectionReady, bool dragPastSlop = false) + { + int step = shift ? 10 : 1; + switch (key) + { + case SnipKey.Escape: + return pointerDown + ? new SnipGesture(SnipGestureKind.ResetDrag, 0, 0) + : new SnipGesture(SnipGestureKind.Cancel, 0, 0); + case SnipKey.Enter: + // A fresh press still confirms the monitor. Only a drag that moved, and never + // formed a rectangle, is ignored — that is what the Windows overlay does. + if (selectionReady) return new SnipGesture(SnipGestureKind.CompleteSelection, 0, 0); + if (dragPastSlop) return new SnipGesture(SnipGestureKind.None, 0, 0); + return new SnipGesture(SnipGestureKind.CompleteMonitor, 0, 0); + case SnipKey.Monitor: + return new SnipGesture(SnipGestureKind.CompleteMonitor, 0, 0); + case SnipKey.All: + return new SnipGesture(SnipGestureKind.CompleteAll, 0, 0); + case SnipKey.Left: + return new SnipGesture(SnipGestureKind.Nudge, -step, 0); + case SnipKey.Right: + return new SnipGesture(SnipGestureKind.Nudge, step, 0); + case SnipKey.Up: + return new SnipGesture(SnipGestureKind.Nudge, 0, -step); + default: + return new SnipGesture(SnipGestureKind.Nudge, 0, step); + } + } + + public static SnipGesture FromRightClick(bool pointerDown) => + pointerDown + ? new SnipGesture(SnipGestureKind.ResetDrag, 0, 0) + : new SnipGesture(SnipGestureKind.Cancel, 0, 0); +} + +static class SnipTiming +{ + /// Windows waits this long after a tray click so the menu is gone before the shot. + public const int MenuSettleMs = 250; + + /// Windows hides its own preview, then waits at least this long before capturing. + public const int ThumbnailClearMs = 100; + + /// Windows hides the countdown, then waits this long so it is not in the shot. + public const int CountdownClearMs = 120; +} diff --git a/linux/X11Cursor.cs b/linux/X11Cursor.cs new file mode 100644 index 0000000..2cc53c4 --- /dev/null +++ b/linux/X11Cursor.cs @@ -0,0 +1,78 @@ +using System.Runtime.InteropServices; +using Avalonia; + +namespace OpenSnip; + +/// Moves the X11 pointer. Wayland does not allow this, so callers fall back. +static class X11Cursor +{ + const string Lib = "libX11.so.6"; + + public static bool IsAvailable => PlatformInfo.HasDisplay && !PlatformInfo.IsWayland; + + public static (int X, int Y)? TryGet() + { + if (!IsAvailable) return null; + if (!TryOpen(out IntPtr display)) return null; + try + { + IntPtr root = XDefaultRootWindow(display); + if (root == IntPtr.Zero) return null; + if (XQueryPointer(display, root, out _, out _, out int x, out int y, out _, out _, out _) == 0) + return null; + return (x, y); + } + catch (DllNotFoundException) { return null; } + catch (EntryPointNotFoundException) { return null; } + finally + { + try { XCloseDisplay(display); } catch { } + } + } + + public static bool TryWarp(int x, int y) + { + if (!IsAvailable) return false; + if (!TryOpen(out IntPtr display)) return false; + try + { + IntPtr root = XDefaultRootWindow(display); + if (root == IntPtr.Zero) return false; + XWarpPointer(display, IntPtr.Zero, root, 0, 0, 0, 0, x, y); + XSync(display, 0); + return true; + } + catch (DllNotFoundException) { return false; } + catch (EntryPointNotFoundException) { return false; } + finally + { + try { XCloseDisplay(display); } catch { } + } + } + + public static PixelPoint? TryClampWarp(int x, int y, PixelRect bounds) + { + var clamped = SnipGeometry.ClampTo(x, y, bounds); + if (!TryWarp(clamped.X, clamped.Y)) return null; + return clamped; + } + + static bool TryOpen(out IntPtr display) + { + display = IntPtr.Zero; + try + { + display = XOpenDisplay(null); + return display != IntPtr.Zero; + } + catch (DllNotFoundException) { return false; } + catch (EntryPointNotFoundException) { return false; } + } + + [DllImport(Lib)] static extern IntPtr XOpenDisplay(string displayName); + [DllImport(Lib)] static extern int XCloseDisplay(IntPtr display); + [DllImport(Lib)] static extern IntPtr XDefaultRootWindow(IntPtr display); + [DllImport(Lib)] static extern int XQueryPointer(IntPtr display, IntPtr window, out IntPtr root, out IntPtr child, out int rootX, out int rootY, out int winX, out int winY, out uint mask); + [DllImport(Lib)] static extern int XWarpPointer(IntPtr display, IntPtr src, IntPtr dest, int srcX, int srcY, uint srcWidth, uint srcHeight, int destX, int destY); + [DllImport(Lib)] static extern int XSync(IntPtr display, int discard); +} 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 + + + + + + + + + + + + + + + + + diff --git a/tests/OpenSnip.Tests/SnipGeometryTests.cs b/tests/OpenSnip.Tests/SnipGeometryTests.cs new file mode 100644 index 0000000..24d0bf9 --- /dev/null +++ b/tests/OpenSnip.Tests/SnipGeometryTests.cs @@ -0,0 +1,91 @@ +using Avalonia; + +namespace OpenSnip.Tests; + +public class SnipGeometryTests +{ + [Fact] + public void Image_rect_maps_onto_a_virtual_desktop_whose_origin_is_not_zero() + { + var image = new PixelRect(10, 20, 30, 40); + var desktop = new PixelRect(-1920, -100, 3840, 1200); + var screen = SnipGeometry.ToScreen(image, desktop, 3840, 1200); + Assert.Equal(new PixelRect(-1910, -80, 30, 40), screen); + + var back = SnipGeometry.ScreenToImage(screen, desktop, 3840, 1200); + Assert.Equal(image, back); + } + + [Fact] + public void Screen_rect_scales_when_the_capture_and_desktop_differ() + { + var desktop = new PixelRect(0, 0, 200, 100); + var screen = new PixelRect(50, 0, 100, 100); + var image = SnipGeometry.ScreenToImage(screen, desktop, 100, 50); + Assert.Equal(new PixelRect(25, 0, 50, 50), image); + } + + [Fact] + public void Best_screen_is_the_one_with_the_largest_overlap() + { + var screens = new[] + { + new PixelRect(0, 0, 1920, 1080), + new PixelRect(1920, 0, 1920, 1080), + }; + var snip = new PixelRect(1800, 100, 400, 200); + Assert.Equal(1, SnipGeometry.BestScreen(snip, screens)); + } + + [Fact] + public void Best_screen_falls_back_to_the_nearest() + { + var screens = new[] + { + new PixelRect(0, 0, 100, 100), + new PixelRect(500, 0, 100, 100), + }; + Assert.Equal(1, SnipGeometry.BestScreen(new PixelRect(420, 10, 20, 20), screens)); + Assert.Equal(-1, SnipGeometry.BestScreen(new PixelRect(0, 0, 1, 1), Array.Empty())); + } + + [Fact] + public void Countdown_sits_at_the_bottom_center_of_the_working_area() + { + var area = new PixelRect(0, 40, 1920, 1040); + var point = SnipGeometry.BottomCenter(area, 128, 128, 40); + Assert.Equal((1920 - 128) / 2, point.X); + Assert.Equal(40 + 1040 - 128 - 40, point.Y); + } + + [Fact] + public void Countdown_stays_inside_a_short_working_area() + { + var point = SnipGeometry.BottomCenter(new PixelRect(10, 20, 80, 30), 128, 128, 40); + Assert.Equal(10, point.X); + Assert.Equal(20, point.Y); + } + + [Fact] + public void Pointer_nudge_clamps_to_the_desktop() + { + var desktop = new PixelRect(-10, 0, 100, 50); + Assert.Equal(new PixelPoint(89, 0), SnipGeometry.ClampTo(200, -5, desktop)); + Assert.Equal(new PixelPoint(-10, 49), SnipGeometry.ClampTo(-40, 80, desktop)); + } + + [Fact] + public void One_image_pixel_is_one_control_pixel_when_sizes_match() + { + var delta = SnipGeometry.ControlDelta(10, -1, 1920, 1080, 1920, 1080); + Assert.Equal(10, delta.X); + Assert.Equal(-1, delta.Y); + } + + [Fact] + public void Control_delta_shrinks_when_the_overlay_is_scaled() + { + var delta = SnipGeometry.ControlDelta(2, 0, 960, 540, 1920, 1080); + Assert.Equal(1, delta.X); + } +} diff --git a/tests/OpenSnip.Tests/SnipGestureTests.cs b/tests/OpenSnip.Tests/SnipGestureTests.cs new file mode 100644 index 0000000..82c9312 --- /dev/null +++ b/tests/OpenSnip.Tests/SnipGestureTests.cs @@ -0,0 +1,64 @@ +namespace OpenSnip.Tests; + +public class SnipGestureTests +{ + [Fact] + public void Monitor_key_captures_immediately() + { + var gesture = SnipGesture.FromKey(SnipKey.Monitor, shift: false, pointerDown: false, selectionReady: false); + Assert.Equal(SnipGestureKind.CompleteMonitor, gesture.Kind); + + var midDrag = SnipGesture.FromKey(SnipKey.Monitor, shift: false, pointerDown: true, selectionReady: true); + Assert.Equal(SnipGestureKind.CompleteMonitor, midDrag.Kind); + } + + [Fact] + public void All_key_captures_every_monitor_immediately() + { + var gesture = SnipGesture.FromKey(SnipKey.All, shift: true, pointerDown: true, selectionReady: true); + Assert.Equal(SnipGestureKind.CompleteAll, gesture.Kind); + } + + [Fact] + public void Escape_and_right_click_cancel_the_drag_before_the_snip() + { + Assert.Equal(SnipGestureKind.ResetDrag, SnipGesture.FromKey(SnipKey.Escape, false, pointerDown: true, false).Kind); + Assert.Equal(SnipGestureKind.Cancel, SnipGesture.FromKey(SnipKey.Escape, false, pointerDown: false, false).Kind); + Assert.Equal(SnipGestureKind.ResetDrag, SnipGesture.FromRightClick(pointerDown: true).Kind); + Assert.Equal(SnipGestureKind.Cancel, SnipGesture.FromRightClick(pointerDown: false).Kind); + } + + [Fact] + public void Enter_confirms_the_selection_or_the_monitor() + { + Assert.Equal(SnipGestureKind.CompleteSelection, SnipGesture.FromKey(SnipKey.Enter, false, pointerDown: true, selectionReady: true).Kind); + Assert.Equal(SnipGestureKind.CompleteMonitor, SnipGesture.FromKey(SnipKey.Enter, false, pointerDown: true, selectionReady: false).Kind); + Assert.Equal(SnipGestureKind.None, SnipGesture.FromKey(SnipKey.Enter, false, pointerDown: true, selectionReady: false, dragPastSlop: true).Kind); + Assert.Equal(SnipGestureKind.CompleteMonitor, SnipGesture.FromKey(SnipKey.Enter, false, pointerDown: false, selectionReady: false).Kind); + Assert.Equal(SnipGestureKind.CompleteSelection, SnipGesture.FromKey(SnipKey.Enter, false, pointerDown: false, selectionReady: true).Kind); + } + + [Fact] + public void Arrows_nudge_one_pixel_or_ten_with_shift() + { + var one = SnipGesture.FromKey(SnipKey.Left, shift: false, false, false); + Assert.Equal(SnipGestureKind.Nudge, one.Kind); + Assert.Equal(-1, one.Dx); + Assert.Equal(0, one.Dy); + + var ten = SnipGesture.FromKey(SnipKey.Down, shift: true, true, true); + Assert.Equal(0, ten.Dx); + Assert.Equal(10, ten.Dy); + + Assert.Equal(10, SnipGesture.FromKey(SnipKey.Right, true, false, false).Dx); + Assert.Equal(-10, SnipGesture.FromKey(SnipKey.Up, true, false, false).Dy); + } + + [Fact] + public void Tray_and_countdown_waits_match_windows() + { + Assert.Equal(250, SnipTiming.MenuSettleMs); + Assert.Equal(120, SnipTiming.CountdownClearMs); + Assert.Equal(100, SnipTiming.ThumbnailClearMs); + } +} From fdbdfc586fec38bc57b8534d1101a3431eeb0c39 Mon Sep 17 00:00:00 2001 From: Devan <68340659+DevanMetz@users.noreply.github.com> Date: Tue, 27 Oct 2026 17:41:51 -0500 Subject: [PATCH 2/3] Keep the Linux countdown and preview out of the shot The countdown sits at the bottom of the monitor under the pointer, does not take focus, and on X11 clicks pass through it. Tray snips wait for the menu to close, and the preview opens on the snipped monitor without taking focus. --- linux/App.cs | 41 ++++++---- linux/CountdownWindow.cs | 56 +++++++++++--- linux/ThumbnailWindow.cs | 23 +++++- linux/X11ClickThrough.cs | 83 ++++++++++++++++++++ tests/OpenSnip.Tests/X11InputTests.cs | 107 ++++++++++++++++++++++++++ 5 files changed, 280 insertions(+), 30 deletions(-) create mode 100644 linux/X11ClickThrough.cs create mode 100644 tests/OpenSnip.Tests/X11InputTests.cs diff --git a/linux/App.cs b/linux/App.cs index 5df37c6..d5b92d3 100644 --- a/linux/App.cs +++ b/linux/App.cs @@ -18,6 +18,7 @@ sealed class App : Application SettingsWindow _settingsWindow; ThumbnailWindow _thumbnail; PixelRect? _lastRegion; + PixelRect? _lastScreen; bool _trayAvailable; bool _busy; @@ -100,10 +101,10 @@ async Task StartAsyncCore() void CreateTray() { var menu = new NativeMenu(); - menu.Add(Item("Snip", () => StartSnip())); - _delayItem = Item($"Snip after delay ({Settings.DelaySeconds}s)", () => StartSnip(Settings.DelaySeconds)); + menu.Add(Item("Snip", () => StartSnip(0, SnipTiming.MenuSettleMs))); + _delayItem = Item($"Snip after delay ({Settings.DelaySeconds}s)", () => StartSnip(Settings.DelaySeconds, SnipTiming.MenuSettleMs)); menu.Add(_delayItem); - menu.Add(Item("Repeat last region", RepeatLast)); + menu.Add(Item("Repeat last region", () => RepeatLast(SnipTiming.MenuSettleMs))); menu.Add(new NativeMenuItemSeparator()); menu.Add(Item("Open screenshots folder", OpenScreenshotsFolder)); menu.Add(Item("Settings…", () => ShowSettings())); @@ -117,7 +118,7 @@ void CreateTray() Menu = menu, IsVisible = true, }; - _tray.Clicked += (_, _) => StartSnip(); + _tray.Clicked += (_, _) => StartSnip(0, SnipTiming.MenuSettleMs); TrayIcon.SetIcons(this, new TrayIcons { _tray }); } @@ -179,7 +180,7 @@ public void OpenScreenshotsFolder() } } - public async void StartSnip(int delaySeconds = 0) + public async void StartSnip(int delaySeconds = 0, int settleMs = 0) { if (_busy) return; _busy = true; @@ -187,7 +188,7 @@ public async void StartSnip(int delaySeconds = 0) { bool hadThumbnail = _thumbnail != null; CloseThumbnail(); - if (hadThumbnail) await Task.Delay(100); + await SettleAsync(settleMs, hadThumbnail); if (delaySeconds > 0) await CountdownWindow.RunAsync(delaySeconds); var frame = await CaptureService.CaptureAsync(); @@ -196,8 +197,9 @@ public async void StartSnip(int delaySeconds = 0) if (region is not { } selected) return; _lastRegion = selected; + _lastScreen = SnipGeometry.ToScreen(selected, overlay.VirtualBounds, frame.Width, frame.Height); var cropped = frame.Crop(selected.X, selected.Y, selected.Width, selected.Height); - await DeliverAsync(cropped); + await DeliverAsync(cropped, _lastScreen.Value); } catch (CaptureException ex) { @@ -215,12 +217,12 @@ public async void StartSnip(int delaySeconds = 0) } } - public async void RepeatLast() + public async void RepeatLast(int settleMs = 0) { if (_busy) return; if (_lastRegion is not { } region) { - StartSnip(); + StartSnip(0, settleMs); return; } @@ -230,7 +232,7 @@ public async void RepeatLast() { bool hadThumbnail = _thumbnail != null; CloseThumbnail(); - if (hadThumbnail) await Task.Delay(100); + await SettleAsync(settleMs, hadThumbnail); var frame = await CaptureService.CaptureAsync(); if (region.X < 0 || region.Y < 0 || region.Right > frame.Width || region.Bottom > frame.Height) { @@ -238,7 +240,8 @@ public async void RepeatLast() return; } var cropped = frame.Crop(region.X, region.Y, region.Width, region.Height); - await DeliverAsync(cropped); + var screen = _lastScreen ?? SnipGeometry.ToScreen(region, new PixelRect(0, 0, frame.Width, frame.Height), frame.Width, frame.Height); + await DeliverAsync(cropped, screen); } catch (CaptureException ex) { @@ -257,7 +260,15 @@ public async void RepeatLast() } } - async Task DeliverAsync(CapturedFrame frame) + static async Task SettleAsync(int settleMs, bool hadThumbnail) + { + // The tray menu and our own preview are still on screen for a moment. + int wait = settleMs; + if (hadThumbnail) wait = Math.Max(wait, SnipTiming.ThumbnailClearMs); + if (wait > 0) await Task.Delay(wait); + } + + async Task DeliverAsync(CapturedFrame frame, PixelRect screenRect) { bool copied = false; if (Settings.CopyToClipboard) @@ -290,13 +301,13 @@ async Task DeliverAsync(CapturedFrame frame) } if (Settings.ShowThumbnail || (!copied && saved == null)) - ShowThumbnail(frame, saved); + ShowThumbnail(frame, saved, screenRect); } - void ShowThumbnail(CapturedFrame frame, string path) + void ShowThumbnail(CapturedFrame frame, string path, PixelRect screenRect) { CloseThumbnail(); - var thumbnail = new ThumbnailWindow(frame, path, Settings.PreviewSeconds); + var thumbnail = new ThumbnailWindow(frame, path, Settings.PreviewSeconds, screenRect); thumbnail.Closed += (_, _) => { if (ReferenceEquals(_thumbnail, thumbnail)) _thumbnail = null; diff --git a/linux/CountdownWindow.cs b/linux/CountdownWindow.cs index a3e101a..9d1ca5c 100644 --- a/linux/CountdownWindow.cs +++ b/linux/CountdownWindow.cs @@ -2,6 +2,7 @@ using Avalonia.Controls; using Avalonia.Layout; using Avalonia.Media; +using Avalonia.Threading; namespace OpenSnip; @@ -24,6 +25,8 @@ public CountdownWindow(int seconds) CanResize = false; Topmost = true; ShowInTaskbar = false; + ShowActivated = false; + Focusable = false; Width = 128; Height = 128; WindowStartupLocation = WindowStartupLocation.Manual; @@ -36,18 +39,47 @@ public CountdownWindow(int seconds) Child = _number, }; _number.Text = seconds.ToString(); + Place(); + } + + protected override void OnOpened(EventArgs e) + { + base.OnOpened(e); + Place(); + PassClicksThrough(); + // Avalonia may map the window after OnOpened. Apply the shape again once that settles. + Dispatcher.UIThread.Post(PassClicksThrough, DispatcherPriority.Background); + } - var screen = Screens.Primary - ?? Screens.All.FirstOrDefault(candidate => candidate.IsPrimary) - ?? Screens.All.FirstOrDefault(); - if (screen != null) + void Place() + { + var screen = ScreenUnderPointer(); + if (screen == null) return; + double scale = screen.Scaling <= 0 ? 1 : screen.Scaling; + int width = (int)Math.Round(Width * scale); + int height = (int)Math.Round(Height * scale); + int margin = (int)Math.Round(40 * scale); + Position = SnipGeometry.BottomCenter(screen.WorkingArea, width, height, margin); + } + + Avalonia.Platform.Screen ScreenUnderPointer() + { + var screens = Screens?.All; + if (screens == null || screens.Count == 0) return null; + if (X11Cursor.TryGet() is { } pointer) { - var area = screen.WorkingArea; - double scale = screen.Scaling <= 0 ? 1 : screen.Scaling; - Position = new PixelPoint( - (int)(area.X + area.Width / 2.0 - Width * scale / 2), - (int)(area.Y + area.Height / 2.0 - Height * scale / 2)); + var hit = Screens.ScreenFromPoint(new PixelPoint(pointer.X, pointer.Y)); + if (hit != null) return hit; } + return Screens.Primary + ?? screens.FirstOrDefault(candidate => candidate.IsPrimary) + ?? screens[0]; + } + + void PassClicksThrough() + { + if (TryGetPlatformHandle() is { Handle: var xid } && xid != IntPtr.Zero) + X11ClickThrough.TryEnable(xid); } public static async Task RunAsync(int seconds) @@ -65,8 +97,10 @@ public static async Task RunAsync(int seconds) } finally { - window.Close(); + // Hide first so the compositor can drop the window before the screen is captured. + try { window.Hide(); } catch { } + await Task.Delay(SnipTiming.CountdownClearMs); + try { window.Close(); } catch { } } - await Task.Delay(80); } } diff --git a/linux/ThumbnailWindow.cs b/linux/ThumbnailWindow.cs index 4b0a383..40d0843 100644 --- a/linux/ThumbnailWindow.cs +++ b/linux/ThumbnailWindow.cs @@ -5,6 +5,7 @@ using Avalonia.Layout; using Avalonia.Media; using Avalonia.Media.Imaging; +using Avalonia.Platform; using Avalonia.Threading; namespace OpenSnip; @@ -12,17 +13,20 @@ namespace OpenSnip; sealed class ThumbnailWindow : Window { readonly string _path; + readonly PixelRect? _anchor; readonly DispatcherTimer _timer; - public ThumbnailWindow(CapturedFrame frame, string savedPath, int seconds) + public ThumbnailWindow(CapturedFrame frame, string savedPath, int seconds, PixelRect? anchor = null) { _path = savedPath; + _anchor = anchor; Title = "OpenSnip"; Icon = IconLoader.Icon; SystemDecorations = SystemDecorations.None; CanResize = false; Topmost = true; ShowInTaskbar = false; + ShowActivated = false; WindowStartupLocation = WindowStartupLocation.Manual; double maxWidth = 300; @@ -70,9 +74,7 @@ public ThumbnailWindow(CapturedFrame frame, string savedPath, int seconds) void PlaceBottomRight() { - var screen = Screens.Primary - ?? Screens.All.FirstOrDefault(candidate => candidate.IsPrimary) - ?? Screens.All.FirstOrDefault(); + var screen = ScreenForAnchor(); if (screen == null) return; var area = screen.WorkingArea; double scale = screen.Scaling <= 0 ? 1 : screen.Scaling; @@ -81,6 +83,19 @@ void PlaceBottomRight() (int)(area.Bottom - Height * scale - 16 * scale)); } + Screen ScreenForAnchor() + { + var screens = Screens?.All; + if (screens == null || screens.Count == 0) return Screens?.Primary; + if (_anchor is not { } anchor) return Screens.Primary ?? screens[0]; + + var bounds = new PixelRect[screens.Count]; + for (int i = 0; i < screens.Count; i++) bounds[i] = screens[i].Bounds; + int index = SnipGeometry.BestScreen(anchor, bounds); + if (index < 0 || index >= screens.Count) return Screens.Primary ?? screens[0]; + return screens[index]; + } + void OnPressed(object sender, PointerPressedEventArgs e) { var point = e.GetCurrentPoint(this); diff --git a/linux/X11ClickThrough.cs b/linux/X11ClickThrough.cs new file mode 100644 index 0000000..7f7415c --- /dev/null +++ b/linux/X11ClickThrough.cs @@ -0,0 +1,83 @@ +using System.Runtime.InteropServices; + +namespace OpenSnip; + +/// +/// Gives an X11 window an empty input shape so clicks fall through to whatever is underneath. +/// The delay countdown has to stay visible without blocking the menu the user is opening. +/// +static class X11ClickThrough +{ + const string X11 = "libX11.so.6"; + const string Xext = "libXext.so.6"; + const int ShapeSet = 0; + const int ShapeInput = 2; + + public static bool TryEnable(IntPtr xid) + { + if (xid == IntPtr.Zero || !X11Cursor.IsAvailable) return false; + IntPtr display = IntPtr.Zero; + try + { + display = XOpenDisplay(null); + if (display == IntPtr.Zero) return false; + if (XShapeQueryExtension(display, out _, out _) == 0) return false; + XShapeCombineRectangles(display, xid, ShapeInput, 0, 0, IntPtr.Zero, 0, ShapeSet, 0); + XSync(display, 0); + return InputRectangleCount(display, xid) == 0; + } + catch (Exception ex) when (ex is DllNotFoundException or EntryPointNotFoundException) + { + return false; + } + catch (Exception ex) + { + Log.Error(ex); + return false; + } + finally + { + if (display != IntPtr.Zero) + { + try { XCloseDisplay(display); } catch { } + } + } + } + + public static int? InputRectangleCount(IntPtr xid) + { + if (xid == IntPtr.Zero || !X11Cursor.IsAvailable) return null; + IntPtr display = IntPtr.Zero; + try + { + display = XOpenDisplay(null); + if (display == IntPtr.Zero) return null; + if (XShapeQueryExtension(display, out _, out _) == 0) return null; + return InputRectangleCount(display, xid); + } + catch (DllNotFoundException) { return null; } + catch (EntryPointNotFoundException) { return null; } + finally + { + if (display != IntPtr.Zero) + { + try { XCloseDisplay(display); } catch { } + } + } + } + + static int InputRectangleCount(IntPtr display, IntPtr xid) + { + IntPtr rects = XShapeGetRectangles(display, xid, ShapeInput, out int count, out _); + if (rects != IntPtr.Zero) XFree(rects); + return count; + } + + [DllImport(X11)] static extern IntPtr XOpenDisplay(string displayName); + [DllImport(X11)] static extern int XCloseDisplay(IntPtr display); + [DllImport(X11)] static extern int XSync(IntPtr display, int discard); + [DllImport(X11)] static extern int XFree(IntPtr data); + [DllImport(Xext)] static extern int XShapeQueryExtension(IntPtr display, out int eventBase, out int errorBase); + [DllImport(Xext)] static extern void XShapeCombineRectangles(IntPtr display, IntPtr window, int destKind, int xOff, int yOff, IntPtr rectangles, int count, int op, int ordering); + [DllImport(Xext)] static extern IntPtr XShapeGetRectangles(IntPtr display, IntPtr window, int kind, out int count, out int ordering); +} diff --git a/tests/OpenSnip.Tests/X11InputTests.cs b/tests/OpenSnip.Tests/X11InputTests.cs new file mode 100644 index 0000000..faca251 --- /dev/null +++ b/tests/OpenSnip.Tests/X11InputTests.cs @@ -0,0 +1,107 @@ +using System.Runtime.InteropServices; + +namespace OpenSnip.Tests; + +public class X11InputTests +{ + const string Lib = "libX11.so.6"; + const ulong CwOverrideRedirect = 512; + + [Fact] + public void Arrow_nudge_moves_the_x11_pointer_and_back() + { + if (!X11Cursor.IsAvailable) return; + var start = X11Cursor.TryGet(); + if (start == null) return; + + try + { + Assert.True(X11Cursor.TryWarp(start.Value.X + 7, start.Value.Y + 3)); + var moved = X11Cursor.TryGet(); + Assert.NotNull(moved); + Assert.Equal(start.Value.X + 7, moved.Value.X); + Assert.Equal(start.Value.Y + 3, moved.Value.Y); + } + finally + { + X11Cursor.TryWarp(start.Value.X, start.Value.Y); + } + } + + [Fact] + public void Empty_input_shape_lets_the_pointer_fall_through() + { + if (!X11Cursor.IsAvailable) return; + + IntPtr display = XOpenDisplay(null); + if (display == IntPtr.Zero) return; + + var start = X11Cursor.TryGet(); + IntPtr back = IntPtr.Zero; + IntPtr front = IntPtr.Zero; + try + { + IntPtr root = XDefaultRootWindow(display); + back = CreateWindow(display, root, 80, 90, 40, 30, 0x0000FF); + front = CreateWindow(display, root, 80, 90, 40, 30, 0x00FF00); + XMapWindow(display, back); + XMapWindow(display, front); + XRaiseWindow(display, front); + XWarpPointer(display, IntPtr.Zero, root, 0, 0, 0, 0, 100, 100); + XSync(display, 0); + + Assert.Equal(front, ChildAt(display, root, 100, 100)); + Assert.True(X11ClickThrough.TryEnable(front)); + Assert.Equal(0, X11ClickThrough.InputRectangleCount(front)); + Assert.Equal(back, ChildAt(display, root, 100, 100)); + } + finally + { + if (front != IntPtr.Zero) XDestroyWindow(display, front); + if (back != IntPtr.Zero) XDestroyWindow(display, back); + XCloseDisplay(display); + if (start != null) X11Cursor.TryWarp(start.Value.X, start.Value.Y); + } + } + + static IntPtr ChildAt(IntPtr display, IntPtr root, int x, int y) + { + XQueryPointer(display, root, out _, out IntPtr child, out _, out _, out _, out _, out _); + if (child == IntPtr.Zero) return IntPtr.Zero; + // Walk down so a parent that merely contains the point is not the answer. + while (child != IntPtr.Zero) + { + if (XQueryPointer(display, child, out _, out IntPtr nested, out _, out _, out _, out _, out _) == 0) + break; + if (nested == IntPtr.Zero) return child; + child = nested; + } + return child; + } + + static IntPtr CreateWindow(IntPtr display, IntPtr root, int x, int y, uint width, uint height, ulong pixel) + { + IntPtr window = XCreateSimpleWindow(display, root, x, y, width, height, 0, 0, pixel); + var attrs = new XSetWindowAttributes { override_redirect = 1 }; + XChangeWindowAttributes(display, window, CwOverrideRedirect, ref attrs); + return window; + } + + [StructLayout(LayoutKind.Explicit, Size = 112)] + struct XSetWindowAttributes + { + [FieldOffset(88)] public int override_redirect; + } + + [DllImport(Lib)] static extern IntPtr XOpenDisplay(string name); + [DllImport(Lib)] static extern int XCloseDisplay(IntPtr display); + [DllImport(Lib)] static extern IntPtr XDefaultRootWindow(IntPtr display); + [DllImport(Lib)] static extern IntPtr XCreateSimpleWindow(IntPtr display, IntPtr parent, int x, int y, uint width, uint height, uint border, ulong borderPixel, ulong background); + [DllImport(Lib)] static extern int XChangeWindowAttributes(IntPtr display, IntPtr window, ulong valueMask, ref XSetWindowAttributes attributes); + [DllImport(Lib)] static extern int XMapWindow(IntPtr display, IntPtr window); + [DllImport(Lib)] static extern int XRaiseWindow(IntPtr display, IntPtr window); + [DllImport(Lib)] static extern int XDestroyWindow(IntPtr display, IntPtr window); + [DllImport(Lib)] static extern int XWarpPointer(IntPtr display, IntPtr src, IntPtr dest, int srcX, int srcY, uint srcWidth, uint srcHeight, int destX, int destY); + [DllImport(Lib)] static extern int XSync(IntPtr display, int discard); + [DllImport(Lib)] static extern int XQueryPointer(IntPtr display, IntPtr window, out IntPtr root, out IntPtr child, out int rootX, out int rootY, out int winX, out int winY, out uint mask); +} From 36b59609f7c9b26c5b31a2e5caf520cb728e25ad Mon Sep 17 00:00:00 2001 From: Devan <68340659+DevanMetz@users.noreply.github.com> Date: Tue, 27 Oct 2026 17:41:51 -0500 Subject: [PATCH 3/3] Document Linux snip-gesture parity and run the tests in CI --- .github/workflows/build.yml | 3 ++ PARITY.md | 63 +++++++++++++++++++++++++++++++++++++ README.md | 2 +- 3 files changed, 67 insertions(+), 1 deletion(-) 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..326d76b --- /dev/null +++ b/PARITY.md @@ -0,0 +1,63 @@ +# Linux parity + +Status of each Windows feature on Linux. This file describes the tree it ships with. + +`working` matches Windows. `partial` works with a gap named here. `missing` has no Linux path yet. `not possible` cannot exist on Linux; the closest equivalent is named. + +## Capture + +| Feature | Linux | Files | +|---|---|---| +| Region snip on a frozen screen | working | `linux/Capture.cs`, `linux/OverlayWindow.cs` | +| Click grabs the monitor under the cursor | working | `linux/OverlayWindow.cs` | +| Click grabs the window under the cursor | missing | `linux/OverlayWindow.cs`, `src/CaptureOverlay.cs` | +| `F` captures that monitor now | working | `linux/SnipGesture.cs`, `linux/OverlayWindow.cs` | +| `A` captures every monitor now | working | `linux/SnipGesture.cs`, `linux/OverlayWindow.cs` | +| Enter confirms the selection, or the monitor when nothing is selected | working | `linux/SnipGesture.cs`, `linux/OverlayWindow.cs` | +| Arrow keys nudge 1 px, Shift nudges 10 | partial. On X11 the pointer moves. On Wayland only the overlay cursor moves, because a client cannot warp the Wayland pointer. | `linux/OverlayWindow.cs`, `linux/X11Cursor.cs` | +| Esc and right-click cancel the drag first, then the snip | working | `linux/SnipGesture.cs`, `linux/OverlayWindow.cs` | +| Magnifier with coordinates | working. It opens on the X11 pointer before the mouse moves. | `linux/OverlayWindow.cs` | +| Magnifier color | missing | `linux/OverlayWindow.cs`, `src/CaptureOverlay.cs` | +| Mixed-DPI placement | partial. The overlay uses one scale for the whole desktop. Windows keeps the overlay in physical pixels. | `linux/OverlayWindow.cs` | +| X11 capture | partial. The import is `libX11`, which looks for `libX11.so`. Desktops ship `libX11.so.6`. | `linux/Capture.cs` | +| Wayland capture (portal screenshot) | working | `linux/Capture.cs`, `linux/DBus.cs` | +| Copy PNG to the clipboard | working. `xclip` on X11, `wl-copy` on Wayland, then Avalonia. | `linux/ClipboardService.cs` | +| Auto-save PNG or JPG | working | `linux/CapturedFrame.cs`, `linux/SettingsWindow.cs` | +| Monthly folders | working | `src/Settings.cs` | +| Preview thumbnail | working. It does not take focus, and it opens on the monitor that was snipped. | `linux/ThumbnailWindow.cs`, `linux/SnipGeometry.cs` | +| Click the preview to annotate | partial. Click opens the file with `xdg-open`. | `linux/ThumbnailWindow.cs` | +| Drag the preview into another app | missing | `linux/ThumbnailWindow.cs`, `src/SmallWindows.cs` | +| Annotation editor | missing | `src/EditorForm.cs` | +| Open the editor after a snip | missing. The shared setting exists. Linux follows the preview checkbox. | `src/Settings.cs`, `linux/App.cs`, `linux/SettingsWindow.cs` | +| Pin a snip, including from the clipboard | missing | `src/SmallWindows.cs` | +| Delayed snip | working. The countdown sits at the bottom of the monitor under the pointer, does not take focus, and closes before the shot. On X11 clicks pass through it. On Wayland they do not. | `linux/CountdownWindow.cs`, `linux/X11ClickThrough.cs` | +| Tray snip waits so the menu is not in the shot | working | `linux/App.cs`, `linux/SnipGesture.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` | +| 3-2-1 countdown, 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 and settings + +| 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` | +| Settings pages for capture, saving, shortcuts, general | partial. There is no Recording page, and Shortcuts lists commands instead of recording a key. | `linux/SettingsWindow.cs` | +| Copy, preview, magnifier, delay | working | `linux/SettingsWindow.cs` | +| Auto-save, folder, PNG or JPG, monthly folders | working | `linux/SettingsWindow.cs` | +| Reset defaults | working | `linux/SettingsWindow.cs` | +| Start on login | working. XDG autostart. | `linux/Autostart.cs` | +| First-run tray balloon | missing. Windows shows a one-time hint. Linux does not add it. | `src/TrayApp.cs` | +| Tray tooltip names the snip shortcut | missing. The tooltip is "OpenSnip". | `linux/App.cs` | +| Diagnostics | working. Capture backends, clipboard tools, portal, and tray host. | `linux/Diagnostics.cs` | +| Second launch forwards snip, delay, repeat, and settings | working | `linux/SingleInstance.cs` | +| `--capture` and `--diagnostics` | working | `linux/Cli.cs`, `linux/CaptureCli.cs` | diff --git a/README.md b/README.md index 987b573..fae3b94 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,7 @@ There are no built-in global shortcuts on Linux; bind your own in GNOME Settings | `A` | All monitors | | `Enter` | Grab what's selected | | Arrow keys | Nudge the cursor 1 px (`Shift` for 10 px) | -| `Esc` / right-click | Cancel | +| `Esc` / right-click | Cancel the current drag, or cancel | ### Command line