mirror of
https://github.com/artizirk/dotfiles.git
synced 2024-11-22 08:20:59 +02:00
Capture the whole screen before region seleciton
This commit is contained in:
parent
b4055d318c
commit
ab60d05c28
@ -6,9 +6,17 @@ from gi.repository import Gtk, GLib
|
||||
import time
|
||||
import sys
|
||||
import os
|
||||
from subprocess import run
|
||||
import json
|
||||
import atexit
|
||||
from subprocess import run, Popen, PIPE
|
||||
from urllib.parse import urljoin
|
||||
|
||||
image_viewers = []
|
||||
def kill_image_viewers():
|
||||
for viewer in image_viewers:
|
||||
viewer.terminate()
|
||||
atexit.register(kill_image_viewers)
|
||||
|
||||
file_name = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES)
|
||||
file_name = os.path.join(file_name, time.strftime('screenshot_%Y-%m-%d-%H%M%S_grim.png'))
|
||||
|
||||
@ -18,17 +26,29 @@ else:
|
||||
if sys.argv[1] in ('-h','--help'):
|
||||
print("Usage: {} [-h|--help|--region|--window]".format(sys.argv[0]))
|
||||
sys.exit(0)
|
||||
|
||||
elif sys.argv[1] == '--region':
|
||||
outputs = run(['swaymsg', '-t', 'get_outputs'], check=True, capture_output=True)
|
||||
for output in json.loads(outputs.stdout):
|
||||
image = Popen(["grim", "-o", f"{output.get('name')}", '-'], stdout=PIPE)
|
||||
viewer = Popen(['swayimg', '-f', '-o', f'{output.get("name")}','-'], stdin=image.stdout)
|
||||
image_viewers.append(viewer)
|
||||
|
||||
time.sleep(0.3)
|
||||
|
||||
region = run('slurp', check=True, capture_output=True)
|
||||
run(["grim", '-g', '-', file_name], check=True, input=region.stdout)
|
||||
|
||||
elif sys.argv[1] == '--window':
|
||||
tree = run(['swaymsg', '-t', 'get_tree'], check=True, capture_output=True)
|
||||
regions = run(['jq', '-r', '.. | select(.pid? and .visible?) | .rect | "\(.x),\(.y) \(.width)x\(.height)"'],
|
||||
check=True, capture_output=True, input=tree.stdout)
|
||||
region = run('slurp', check=True, capture_output=True, input=regions.stdout)
|
||||
run(["grim", '-g', '-', file_name], check=True, input=region.stdout)
|
||||
|
||||
else:
|
||||
sys.exit(1)
|
||||
|
||||
# Add created screenshot to Gtk recents list
|
||||
recent_mgr = Gtk.RecentManager.get_default()
|
||||
uri = urljoin("file:", file_name)
|
||||
|
Loading…
Reference in New Issue
Block a user