From ade0f07359144c50d904c46d33d0eb2620c3b52c Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Thu, 21 Mar 2024 09:59:29 +0000 Subject: [PATCH] made screenshurrt semi-wayland compatible --- src/common/display.nim | 1 - src/model/screenshot.nim | 11 ++++++++++- src/parser.nim | 6 ++++++ src/util/screenshurrt.nim | 3 +++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/common/display.nim b/src/common/display.nim index 9d58792..4ffdc33 100644 --- a/src/common/display.nim +++ b/src/common/display.nim @@ -5,6 +5,5 @@ const WAYLAND = "wayland" proc isWayland*(): bool = if existsEnv(XDG_SESSION_TYPE) and getEnv(XDG_SESSION_TYPE) == WAYLAND: - echo "WAYLAND!" return true return false diff --git a/src/model/screenshot.nim b/src/model/screenshot.nim index 006deac..e06a7be 100644 --- a/src/model/screenshot.nim +++ b/src/model/screenshot.nim @@ -14,6 +14,7 @@ type ScreenshotTool* = enum None = "" Maim = "maim" + Grim = "grim" proc newScreenshot*(): Screenshot = var ss = Screenshot() @@ -41,6 +42,7 @@ proc ScreenshotSizes*(): seq[string] = proc toScreenshotTool*(str: string): ScreenshotTool = case str of "maim": return Maim + of "grim": return Grim else: return None proc isScreenshotTool*(str: string): bool = @@ -49,6 +51,7 @@ proc isScreenshotTool*(str: string): bool = proc command*(tool: ScreenshotTool): string = case tool of Maim: return "maim -u %s --format png %f" + of Grim: return "grim %s %f" else: return "" proc activeWindowCommand*(tool: ScreenshotTool): string = @@ -57,6 +60,9 @@ proc activeWindowCommand*(tool: ScreenshotTool): string = case tool of Maim: cmd = cmd.replace("%s","-i $(xdotool getactivewindow)") + of Grim: + echo "Not currently Implemented" + quit(1) else: return cmd return cmd @@ -65,8 +71,11 @@ proc regionCommand*(tool: ScreenshotTool): string = case tool of Maim: cmd = cmd.replace("%s","-s") + of Grim: + cmd = cmd.replace("%s","-g \"$(slurp)\"") else: return cmd return cmd -const CLIPBOARD_CMD* = "xclip -selection clipboard -t image/png" +const X_CLIPBOARD_CMD* = "xclip -selection clipboard -t image/png" +const WL_CLIPBOARD_CMD* = "wl-copy" diff --git a/src/parser.nim b/src/parser.nim index 76b1eca..6900b98 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -3,6 +3,7 @@ import os import argparse import common +import common/display import model/pwgen import model/volume import model/brightness @@ -151,10 +152,15 @@ proc parseScreenshotArgs*(): Screenshot = help("Args for screenshurrt") arg("screenshurrt",help="can only ever be 'screenshurrt' as you won't have gotten this far otherwise") option("-s","--size",help="size/region i.e. region, fullscreen or window") + option("-t","--tool",help="the tool to take the screenshot, i.e. maim or grim") try: var opts = p.parse(params) if opts.size != "": ss.size = opts.size.toScreenshotSize() + if opts.tool != "": + ss.tool = opts.tool.toScreenshotTool() + elif isWayland(): + ss.tool = GRIM except ShortCircuit as err: if err.flag == "argparse_help": echo err.help diff --git a/src/util/screenshurrt.nim b/src/util/screenshurrt.nim index 8408405..f2b9359 100644 --- a/src/util/screenshurrt.nim +++ b/src/util/screenshurrt.nim @@ -5,6 +5,7 @@ import strutils import sequtils import ../common +import ../common/display import ../output import ../parser import ../model/screenshot @@ -14,6 +15,8 @@ const FILENAME = "Screenshot-%d.png" const TEMP_DIR = "/tmp/" let DATE_STR = now().format(DATE_FORMAT) +let CLIPBOARD_CMD = if isWayland(): WL_CLIPBOARD_CMD else: X_CLIPBOARD_CMD + proc saveToClipboard(filename: string) = let cmd = "cat " & filename & " | " & CLIPBOARD_CMD let status = execCmd(cmd)