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
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
sudo apt-get update
sudo apt-get install -y xvfb libx11-6
dotnet test tests/OpenSnip.Tests/OpenSnip.Tests.csproj -c Release --nologo
dotnet test tests/OpenSnip.Hotkeys.Tests/OpenSnip.Hotkeys.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
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ Run `OpenSnip.exe --diagnostics` to write a report (displays, audio devices, and

## Linux

The Linux app is a separate native Avalonia build. It covers screenshots, annotation, and pinned images; recording and built-in global shortcuts remain Windows-only.
The Linux app is a separate native Avalonia build. It covers screenshots, annotation, pinned images, and global shortcuts on X11; recording remains 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, 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; 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; 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 on X11; and settings.

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

Expand All @@ -133,7 +133,9 @@ The installer copies the binary to `~/.local/bin/opensnip`, so make sure `~/.loc

### Shortcuts

There are no built-in global shortcuts on Linux; bind your own in GNOME Settings → Keyboard → Custom Shortcuts, or KDE System Settings → Shortcuts. Use `opensnip --snip` for a normal snip, `opensnip --snip-delay` for a delayed one, `opensnip --repeat` to re-capture the last region, `opensnip --pin` to pin the clipboard image, `opensnip --pin file.png` to pin a file, `opensnip --edit file.png` to edit an image, and `opensnip --settings` to open settings.
On X11, OpenSnip uses the same shortcuts as Windows. The defaults are `Win` + `Shift` + `S`, `PrtSc`, `Shift` + `PrtSc`, and `Ctrl` + `PrtSc`. Change them in **Settings → Shortcuts**. `Alt` + `PrtSc` and `Win` + `PrtSc` stay with the desktop, as does any chord the desktop already owns.

On Wayland, bind `opensnip --snip`, `opensnip --snip-delay`, or `opensnip --repeat` in the desktop's shortcut settings. Use `opensnip --pin` to pin the clipboard image, `opensnip --pin file.png` to pin a file, `opensnip --edit file.png` to edit an image, and `opensnip --settings` to open settings.

### Selecting a region

Expand Down Expand Up @@ -222,6 +224,8 @@ Issues and pull requests are welcome. The code is plain WinForms + GDI+; recordi
| `linux/Annotation.cs` | Annotation shapes for the Linux editor |
| `linux/EditorWindow.cs` | Linux annotation editor |
| `linux/SettingsWindow.cs` | Linux Settings window |
| `linux/HotkeyChord.cs` | Shortcut parsing, matching, and grab planning |
| `linux/X11Hotkeys.cs` | X11 global shortcuts |
| `tests/OpenSnip.Tests` | Linux regression tests (capture, window detection, images, command line) |

## License
Expand Down
40 changes: 40 additions & 0 deletions linux/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ sealed class App : Application
NativeMenuItem _delayItem;
SettingsWindow _settingsWindow;
ThumbnailWindow _thumbnail;
X11HotkeyService _hotkeys;
readonly List<PinWindow> _pins = new();
readonly List<EditorWindow> _editors = new();
PixelRect? _lastRegion;
Expand Down Expand Up @@ -67,6 +68,9 @@ async Task StartAsync()

async Task StartAsyncCore()
{
try { _hotkeys = X11HotkeyService.TryStart(HotkeyBindings.From(Settings), OnHotkey); }
catch (Exception ex) { Log.Error(ex); }

try { _trayAvailable = await DBus.TrayHostAvailableAsync(); }
catch (Exception ex) { Log.Error(ex); _trayAvailable = false; }

Expand Down Expand Up @@ -141,6 +145,7 @@ void CreateTray()
};
_tray.Clicked += (_, _) => StartSnip();
TrayIcon.SetIcons(this, new TrayIcons { _tray });
UpdateTrayText();
}

static NativeMenuItem Item(string header, Action action)
Expand All @@ -166,6 +171,39 @@ void HandleCommand(RemoteCommand command)
public void SettingsChanged()
{
if (_delayItem != null) _delayItem.Header = $"Snip after delay ({Settings.DelaySeconds}s)";
_hotkeys?.Update(HotkeyBindings.From(Settings));
UpdateTrayText();
}

public bool HasGlobalHotkeys => _hotkeys != null;

public bool BeginShortcutCapture(Action<HotkeyChord?> onChord) =>
_hotkeys != null && _hotkeys.BeginListen(onChord);

public void EndShortcutCapture() => _hotkeys?.EndListen();

void OnHotkey(HotkeyCommand command)
{
Dispatcher.UIThread.Post(() =>
{
if (_busy) return;
switch (command)
{
case HotkeyCommand.Snip: StartSnip(); break;
case HotkeyCommand.SnipDelay: StartSnip(Settings.DelaySeconds); break;
case HotkeyCommand.Repeat: RepeatLast(); break;
}
});
}

void UpdateTrayText()
{
if (_tray == null) return;
var bindings = HotkeyBindings.From(Settings);
string keys = !bindings.Snip.IsEmpty ? bindings.Snip.Display
: bindings.UsePrintScreen ? "PrtSc" : null;
string text = keys != null ? $"OpenSnip — {keys} to snip" : "OpenSnip";
_tray.ToolTipText = text.Length <= 63 ? text : text[..62] + "…";
}

public void SettingsWindowClosed(SettingsWindow window)
Expand Down Expand Up @@ -554,6 +592,8 @@ async Task ShowErrorAsync(string message)

public void ExitApp()
{
try { _hotkeys?.Dispose(); } catch { }
_hotkeys = null;
try { _tray?.Dispose(); } catch { }
_tray = null;
SingleInstance.Stop();
Expand Down
4 changes: 4 additions & 0 deletions linux/Diagnostics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public static async Task<int> RunAsync(string file)
bool tray = await DBus.TrayHostAvailableAsync();
report.AppendLine("xdg-desktop-portal: " + (portal ? "available" : "unavailable"));
report.AppendLine("Tray host: " + (tray ? "available" : "unavailable"));
var settings = Settings.Load();
SettingsDefaults.ApplyLinux(settings);
string shortcuts = X11HotkeyService.IsSupported ? HotkeyBindings.From(settings).Summary : "off";
report.AppendLine("Global shortcuts: " + shortcuts);
report.AppendLine("Settings: " + ConfigPaths.Dir);

string text = report.ToString();
Expand Down
Loading
Loading