Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions PARITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ Status of each Windows feature on Linux. This file describes the tree it ships w
| Region snip on a frozen screen | working | `linux/Capture.cs`, `linux/OverlayWindow.cs` |
| Click grabs the monitor | working | `linux/OverlayWindow.cs` |
| Click grabs the window under the cursor | partial. X11 only | `linux/OverlayWindow.cs`, `src/CaptureOverlay.cs` |
| `F` captures the monitor under the cursor immediately | working | `linux/SnipGesture.cs`, `linux/OverlayWindow.cs` |
| `A` captures all monitors immediately | working. Recording selects the monitor under the cursor. | `linux/SnipGesture.cs`, `linux/OverlayWindow.cs` |
| `F` selects the monitor; Enter captures it | partial | `linux/SnipGesture.cs`, `linux/OverlayWindow.cs` |
| `A` selects all monitors; Enter captures them | partial | `linux/SnipGesture.cs`, `linux/OverlayWindow.cs` |
| Enter confirms the selection or monitor; arrows nudge 1 px, or 10 with Shift | working. X11 warps the pointer; Wayland moves the overlay cursor. | `linux/SnipGesture.cs`, `linux/OverlayWindow.cs` |
| Esc and right-click cancel the drag first, then the snip | working | `linux/SnipGesture.cs`, `linux/OverlayWindow.cs` |
| Mixed-DPI placement | partial. The overlay uses one scale for the whole desktop. | `linux/OverlayWindow.cs` |
| Esc and right-click cancel the snip | partial | `linux/SnipGesture.cs`, `linux/OverlayWindow.cs` |
| Mixed-DPI placement | working on X11, with one window per monitor. Wayland cross-monitor drags are exact when scales match. | `linux/OverlayWindow.cs`, `linux/MonitorMap.cs`, `linux/X11Pointer.cs` |
| X11 outputs left of or above the origin | working. Capture falls back to the root at (0, 0) if the server rejects the bounding box. | `linux/X11Randr.cs`, `linux/Capture.cs` |
| Magnifier with coordinates | working | `linux/OverlayWindow.cs` |
| Magnifier color | working | `linux/OverlayWindow.cs` |
| X11 capture | working | `linux/Capture.cs` |
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 screenshots, annotation, pinned images, global shortcuts and screen recording on X11.

**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, window, monitor and all-monitor selection with a magnifier; clipboard as PNG; auto-save as PNG or JPG; preview; annotation; pinned images (under the pointer on X11, centered on Wayland); tray icon; global shortcuts and MP4 recording on X11; 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, window, monitor and all-monitor selection with a magnifier and one overlay window per screen at its scale; clipboard as PNG; auto-save as PNG or JPG; preview; annotation; pinned images (under the pointer on X11, centered on Wayland); tray icon; global shortcuts and MP4 recording on X11; and settings. X11 capture includes outputs left of or above the origin.

**Install:** download `OpenSnip-linux-x64.tar.gz` from [Releases](https://github.com/DevanMetz/OpenSnip/releases), then:

Expand Down Expand Up @@ -228,7 +228,8 @@ Issues and pull requests are welcome. The code is plain WinForms + GDI+; recordi
| `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/X11Windows.cs` | Top-level X11 windows for click-to-capture |
| `linux/OverlayWindow.cs` | Linux selection overlay and magnifier |
| `linux/OverlayWindow.cs` | Per-monitor Linux selection overlays and magnifier |
| `linux/MonitorMap.cs` | Desktop-pixel mapping for mixed-DPI snips |
| `linux/RecordingSession.cs` | X11 recording, red outline, and control bar |
| `linux/PinWindow.cs` | Linux pinned images |
| `linux/Annotation.cs` | Annotation shapes for the Linux editor |
Expand Down
8 changes: 3 additions & 5 deletions linux/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,7 @@ public async void StartRecording()
if (hadThumbnail) await Task.Delay(100);

var frame = await CaptureService.CaptureAsync();
var overlay = new OverlayWindow(frame, Settings, WindowsFor(frame), record: true);
var region = await overlay.SelectAsync();
var region = await OverlayWindow.SelectAsync(frame, Settings, WindowsFor(frame), record: true);
if (region is not { } selected) return;

var monitors = X11Monitors.Query();
Expand Down Expand Up @@ -493,12 +492,11 @@ public async void StartSnip(int delaySeconds = 0, int settleMs = 0)
if (delaySeconds > 0) await CountdownWindow.RunAsync(delaySeconds);

var frame = await CaptureService.CaptureAsync();
var overlay = new OverlayWindow(frame, Settings, WindowsFor(frame));
var region = await overlay.SelectAsync();
var region = await OverlayWindow.SelectAsync(frame, Settings, WindowsFor(frame));
if (region is not { } selected) return;

_lastRegion = selected;
_lastScreen = SnipGeometry.ToScreen(selected, overlay.VirtualBounds, frame.Width, frame.Height);
_lastScreen = OverlayWindow.ScreenRect(frame, selected);
var cropped = frame.Crop(selected.X, selected.Y, selected.Width, selected.Height);
await DeliverAsync(cropped, _lastScreen.Value);
}
Expand Down
36 changes: 34 additions & 2 deletions linux/Capture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,23 @@ static CapturedFrame Capture()
throw new CaptureException("Cannot read the X11 screen size.");
if (width == 0 || height == 0) throw new CaptureException("The X11 screen is empty.");

image = XGetImage(display, root, 0, 0, width, height, AllPlanes, ZPixmap);
var monitors = X11Randr.Query(display, root);
var region = CaptureRegion.From(monitors, (int)width, (int)height);
if (region.Width <= 0 || region.Height <= 0)
region = new CaptureRegion(0, 0, (int)width, (int)height);

image = Grab(display, root, region);
var rootRegion = new CaptureRegion(0, 0, (int)width, (int)height);
if (!ImageMatches(image, region) && !SameRegion(region, rootRegion))
{
if (image != IntPtr.Zero)
{
try { XDestroyImage(image); } catch { }
image = IntPtr.Zero;
}
region = rootRegion;
image = Grab(display, root, region);
}
if (image == IntPtr.Zero) throw new CaptureException("XGetImage failed.");

var header = Marshal.PtrToStructure<XImageHeader>(image);
Expand Down Expand Up @@ -233,7 +249,10 @@ static CapturedFrame Capture()
}
}

return new CapturedFrame(w, h, output);
var frame = new CapturedFrame(w, h, output);
if (header.width == region.Width && header.height == region.Height)
frame.NoteOrigin(region.X, region.Y);
return frame;
}
catch (DllNotFoundException ex) { throw new CaptureException("libX11 is not available.", ex); }
catch (EntryPointNotFoundException ex) { throw new CaptureException("libX11 is missing a required function.", ex); }
Expand All @@ -244,6 +263,19 @@ static CapturedFrame Capture()
}
}

static IntPtr Grab(IntPtr display, IntPtr root, CaptureRegion region) =>
XGetImage(display, root, region.X, region.Y, (uint)region.Width, (uint)region.Height, AllPlanes, ZPixmap);

static bool ImageMatches(IntPtr image, CaptureRegion region)
{
if (image == IntPtr.Zero) return false;
var header = Marshal.PtrToStructure<XImageHeader>(image);
return header.width == region.Width && header.height == region.Height && header.data != IntPtr.Zero;
}

static bool SameRegion(CaptureRegion a, CaptureRegion b) =>
a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height;

static byte Extract(uint pixel, ulong mask)
{
if (mask == 0) return 0;
Expand Down
12 changes: 12 additions & 0 deletions linux/CapturedFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ sealed class CapturedFrame
public int Height { get; }
public byte[] Bgra { get; }

/// <summary>Desktop pixel of frame (0, 0). Set by the X11 capture; other backends leave it unknown.</summary>
public int OriginX { get; private set; }
public int OriginY { get; private set; }
public bool OriginKnown { get; private set; }

public void NoteOrigin(int x, int y)
{
OriginX = x;
OriginY = y;
OriginKnown = true;
}

public CapturedFrame(int width, int height, byte[] bgra)
{
if (width <= 0 || height <= 0) throw new ArgumentException("Invalid image size");
Expand Down
Loading
Loading