From 09883c3d405dafebfb547d97c2044468199e61a1 Mon Sep 17 00:00:00 2001 From: Arti Zirk Date: Mon, 20 Jan 2025 14:56:00 +0200 Subject: [PATCH] Switch to dulcepan sway screenshot tool --- .bin/wscreenshot.py | 25 +++++++++++++---------- .config/dulcepan.cfg | 47 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 10 deletions(-) create mode 100644 .config/dulcepan.cfg diff --git a/.bin/wscreenshot.py b/.bin/wscreenshot.py index 715d4a7..9cc8a68 100755 --- a/.bin/wscreenshot.py +++ b/.bin/wscreenshot.py @@ -1,4 +1,18 @@ #!/usr/bin/env python3 +""" +Sway screenshot tool. Saved screenshots are also added to GTK recents list for easy access. + +Uses following tools +* grim +* slurp +* https://codeberg.org/vyivel/dulcepan +* jq + + +Region selection uses dulcepan. It works by first freezing the screen so that popups sway visible. +Then it allows selection of the region you want to screenshot. +""" + import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk, GLib @@ -28,16 +42,7 @@ else: 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): - if not output.get("focused"): - continue - 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) - - region = run('slurp', check=True, capture_output=True) - run(["grim", '-g', '-', file_name], check=True, input=region.stdout) + run(["dulcepan", "-C", "-o", file_name], check=True) elif sys.argv[1] == '--window': tree = run(['swaymsg', '-t', 'get_tree'], check=True, capture_output=True) diff --git a/.config/dulcepan.cfg b/.config/dulcepan.cfg new file mode 100644 index 0000000..b487ac2 --- /dev/null +++ b/.config/dulcepan.cfg @@ -0,0 +1,47 @@ +# An example configuration. + +# RRGGBB or RRGGBBAA +unselected-color = ffffff40 +selected-color = 00000000 +#border-color = ffffff +border-color = 000000 +#border-secondary-color = 000000 +border-secondary-color = ffffff + +# 0 to disable borders +border-size = 2 + +# Border gradient type: +# - none: only the primary border color is used +# - linear: uses a linear gradient relative to the selection +# - loop: uses a repeated linear gradient +border-gradient = none + +# For "linear" gradient mode +# Counterclockwise, in degrees +gradient-angle = 45 + +# For "loop" gradient mode +# The distance between gradient stops +loop-step = 100 + +# For "linear" and "loop" gradient modes +# In milliseconds, 0 to disable animation +# With "linear" mode: the time it takes for the pattern to make one full turn +# With "loop" mode: the time it takes for the pattern to move by double the loop step +animation-duration = 1000 + +# If true, dulcepan will save immediately when interactive selection is stopped +# or when a whole output is selected with a mouse button. +quick-select = true + +# If true, dulcepan will remember selection between runs. +# The state is stored at $XDG_CACHE_HOME/dulcepan. +persistence = false + +# PNG (zlib) compression level, 0-9 +png-compression = 6 + +# Key bindings +quit-key = Escape +save-key = Space