added -w flag for screenshot for wayland use
This commit is contained in:
parent
4bf9a8e266
commit
aab1c244d3
6 changed files with 15 additions and 3 deletions
0
compile_all.sh
Executable file → Normal file
0
compile_all.sh
Executable file → Normal file
BIN
file.png
Normal file
BIN
file.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 284 KiB |
0
fuzzytime.nim
Executable file → Normal file
0
fuzzytime.nim
Executable file → Normal file
18
screenshot.nim
Normal file → Executable file
18
screenshot.nim
Normal file → Executable file
|
@ -2,18 +2,26 @@ import base
|
|||
import std/[times,os,osproc,strutils,sequtils]
|
||||
|
||||
var screenshot_type = ""
|
||||
var wayland = false
|
||||
const TYPES = @["region", "fullscreen", "window"]
|
||||
const DATE_FORMAT = "yyyyMMdd-hhmmss"
|
||||
const FILENAME = "Screenshot-%d.png"
|
||||
const TEMP_DIR = "/tmp/"
|
||||
const SCREENSHOT_CMD = "maim -u %s --format png %f"
|
||||
const SCREENSHOT_CMD_WL = "grim %s %f"
|
||||
var RUN_CMD = SCREENSHOT_CMD
|
||||
let DATE_STR = now().format(DATE_FORMAT)
|
||||
# where %s is an extra flag or process, i.e. xdotool for getting active window
|
||||
const ACTIVE_WINDOW_CMD = "-i $(xdotool getactivewindow)"
|
||||
const REGION_FLAG = "-s"
|
||||
const REGION_FLAG_WL = "-g \"$(slurp)\""
|
||||
var REGION_CMD = REGION_FLAG
|
||||
const CLIPBOARD_CMD = "xclip -selection clipboard -t image/png"
|
||||
const CLIPBOARD_CMD_WL = "wl-copy"
|
||||
var CLIP_CMD = CLIPBOARD_CMD
|
||||
|
||||
proc saveToClipboard(filename: string) =
|
||||
let cmd = "cat " & filename & " | xclip -selection clipboar -t image/png"
|
||||
let cmd = "cat " & filename & " | " & CLIP_CMD
|
||||
let status = execCmd(cmd)
|
||||
if status == 0 and fileExists(filename):
|
||||
removeFile(filename)
|
||||
|
@ -64,12 +72,12 @@ proc showScreenshotTypeSel() =
|
|||
|
||||
proc takeScreenshot() =
|
||||
let filename = TEMP_DIR & FILENAME.replace("%d",DATE_STR)
|
||||
var cmd = SCREENSHOT_CMD.replace("%f",filename)
|
||||
var cmd = RUN_CMD.replace("%f",filename)
|
||||
case screenshot_type:
|
||||
of "window":
|
||||
cmd = cmd.replace("%s",ACTIVE_WINDOW_CMD)
|
||||
of "region":
|
||||
cmd = cmd.replace("%s",REGION_FLAG)
|
||||
cmd = cmd.replace("%s",REGION_CMD)
|
||||
else: #fullscreen
|
||||
cmd = cmd.replace("%s","")
|
||||
# sleep for a bit otherwise the screen shot grabs dmenu as well
|
||||
|
@ -82,6 +90,10 @@ proc takeScreenshot() =
|
|||
|
||||
if isMainModule:
|
||||
for arg in args:
|
||||
if arg == "-w":
|
||||
RUN_CMD = SCREENSHOT_CMD_WL
|
||||
REGION_CMD = REGION_FLAG_WL
|
||||
CLIP_CMD = CLIPBOARD_CMD_WL
|
||||
if arg in TYPES:
|
||||
screenshot_type = arg
|
||||
break
|
||||
|
|
BIN
screenshot.png
Normal file
BIN
screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 40 KiB |
0
volume.nim
Executable file → Normal file
0
volume.nim
Executable file → Normal file
Loading…
Reference in a new issue