made screenshurrt semi-wayland compatible
This commit is contained in:
parent
6e31377f8a
commit
ade0f07359
4 changed files with 19 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue