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 =
|
proc isWayland*(): bool =
|
||||||
if existsEnv(XDG_SESSION_TYPE) and getEnv(XDG_SESSION_TYPE) == WAYLAND:
|
if existsEnv(XDG_SESSION_TYPE) and getEnv(XDG_SESSION_TYPE) == WAYLAND:
|
||||||
echo "WAYLAND!"
|
|
||||||
return true
|
return true
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -14,6 +14,7 @@ type
|
||||||
ScreenshotTool* = enum
|
ScreenshotTool* = enum
|
||||||
None = ""
|
None = ""
|
||||||
Maim = "maim"
|
Maim = "maim"
|
||||||
|
Grim = "grim"
|
||||||
|
|
||||||
proc newScreenshot*(): Screenshot =
|
proc newScreenshot*(): Screenshot =
|
||||||
var ss = Screenshot()
|
var ss = Screenshot()
|
||||||
|
@ -41,6 +42,7 @@ proc ScreenshotSizes*(): seq[string] =
|
||||||
proc toScreenshotTool*(str: string): ScreenshotTool =
|
proc toScreenshotTool*(str: string): ScreenshotTool =
|
||||||
case str
|
case str
|
||||||
of "maim": return Maim
|
of "maim": return Maim
|
||||||
|
of "grim": return Grim
|
||||||
else: return None
|
else: return None
|
||||||
|
|
||||||
proc isScreenshotTool*(str: string): bool =
|
proc isScreenshotTool*(str: string): bool =
|
||||||
|
@ -49,6 +51,7 @@ proc isScreenshotTool*(str: string): bool =
|
||||||
proc command*(tool: ScreenshotTool): string =
|
proc command*(tool: ScreenshotTool): string =
|
||||||
case tool
|
case tool
|
||||||
of Maim: return "maim -u %s --format png %f"
|
of Maim: return "maim -u %s --format png %f"
|
||||||
|
of Grim: return "grim %s %f"
|
||||||
else: return ""
|
else: return ""
|
||||||
|
|
||||||
proc activeWindowCommand*(tool: ScreenshotTool): string =
|
proc activeWindowCommand*(tool: ScreenshotTool): string =
|
||||||
|
@ -57,6 +60,9 @@ proc activeWindowCommand*(tool: ScreenshotTool): string =
|
||||||
case tool
|
case tool
|
||||||
of Maim:
|
of Maim:
|
||||||
cmd = cmd.replace("%s","-i $(xdotool getactivewindow)")
|
cmd = cmd.replace("%s","-i $(xdotool getactivewindow)")
|
||||||
|
of Grim:
|
||||||
|
echo "Not currently Implemented"
|
||||||
|
quit(1)
|
||||||
else: return cmd
|
else: return cmd
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
|
@ -65,8 +71,11 @@ proc regionCommand*(tool: ScreenshotTool): string =
|
||||||
case tool
|
case tool
|
||||||
of Maim:
|
of Maim:
|
||||||
cmd = cmd.replace("%s","-s")
|
cmd = cmd.replace("%s","-s")
|
||||||
|
of Grim:
|
||||||
|
cmd = cmd.replace("%s","-g \"$(slurp)\"")
|
||||||
else: return cmd
|
else: return cmd
|
||||||
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 argparse
|
||||||
|
|
||||||
import common
|
import common
|
||||||
|
import common/display
|
||||||
import model/pwgen
|
import model/pwgen
|
||||||
import model/volume
|
import model/volume
|
||||||
import model/brightness
|
import model/brightness
|
||||||
|
@ -151,10 +152,15 @@ proc parseScreenshotArgs*(): Screenshot =
|
||||||
help("Args for screenshurrt")
|
help("Args for screenshurrt")
|
||||||
arg("screenshurrt",help="can only ever be 'screenshurrt' as you won't have gotten this far otherwise")
|
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("-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:
|
try:
|
||||||
var opts = p.parse(params)
|
var opts = p.parse(params)
|
||||||
if opts.size != "":
|
if opts.size != "":
|
||||||
ss.size = opts.size.toScreenshotSize()
|
ss.size = opts.size.toScreenshotSize()
|
||||||
|
if opts.tool != "":
|
||||||
|
ss.tool = opts.tool.toScreenshotTool()
|
||||||
|
elif isWayland():
|
||||||
|
ss.tool = GRIM
|
||||||
except ShortCircuit as err:
|
except ShortCircuit as err:
|
||||||
if err.flag == "argparse_help":
|
if err.flag == "argparse_help":
|
||||||
echo err.help
|
echo err.help
|
||||||
|
|
|
@ -5,6 +5,7 @@ import strutils
|
||||||
import sequtils
|
import sequtils
|
||||||
|
|
||||||
import ../common
|
import ../common
|
||||||
|
import ../common/display
|
||||||
import ../output
|
import ../output
|
||||||
import ../parser
|
import ../parser
|
||||||
import ../model/screenshot
|
import ../model/screenshot
|
||||||
|
@ -14,6 +15,8 @@ const FILENAME = "Screenshot-%d.png"
|
||||||
const TEMP_DIR = "/tmp/"
|
const TEMP_DIR = "/tmp/"
|
||||||
let DATE_STR = now().format(DATE_FORMAT)
|
let DATE_STR = now().format(DATE_FORMAT)
|
||||||
|
|
||||||
|
let CLIPBOARD_CMD = if isWayland(): WL_CLIPBOARD_CMD else: X_CLIPBOARD_CMD
|
||||||
|
|
||||||
proc saveToClipboard(filename: string) =
|
proc saveToClipboard(filename: string) =
|
||||||
let cmd = "cat " & filename & " | " & CLIPBOARD_CMD
|
let cmd = "cat " & filename & " | " & CLIPBOARD_CMD
|
||||||
let status = execCmd(cmd)
|
let status = execCmd(cmd)
|
||||||
|
|
Loading…
Reference in a new issue