-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Tricks
swaymsg -t get_outputs | jq -r '.. | select(.focused?) | .current_mode | "\(.width)x\(.height)"'
swaymsg 'workspace test; exec gnome-calculator; workspace back_and_forth'
This works as long as sway can match the PID of a new window to the PID of the exec'd command (or one of its children).
bindsym $mod+Shift+Print exec slurp | grim -g - - | curl --form 'file=@-' http://0x0.st | wl-copy && swaynag -m "screenshot uploaded & url copied to clipboard"
It's super convenient to be able to take a screenshot and pass it to Swappy for possible annotations in one step.
Actions in the .desktop
file feel like a natural place to offer these options.
Using rofi as a launcher, ".desktop" file actions are findable if the -drun-show-actions
is passed.
With these actions, you can snapshot any of the following and have the result opened in swappy:
- current window
- current output
- select a window
- select an area
Install this file into ~/.local/share/applications/grimshot-swappy.desktop
:
[Desktop Entry]
Name=Swappy
GenericName=Annotation Tool
GenericName[de]=Anmerkungswerkzeug
GenericName[fr]="Outil d'annotat"
GenericName[pt_BR]=Ferramenta de Anotação
Comment=A Wayland native snapshot editing tool
Comment[de]=Ein natives Wayland Bildschirmfoto-Bearbeitungswerkzeug
Comment[fr]="Un outil d'édition de capture d'écran avec support natif pour Wayland"
Comment[pt_BR]=Uma ferramenta de edição de snapshot nativa do Wayland
TryExec=swappy
Exec=swappy -f %F
Terminal=false
Type=Application
Keywords=wayland;snapshot;annotation;editing;
Icon=swappy
Categories=Utility;Graphics;Annotation;
StartupNotify=true
MimeType=image/png;image/jpeg;
Actions=current-window;current-output;select-window;select-area;
[Desktop Action current-window]
Name=Current Window
Exec=sh -c 'grimshot save active - | swappy -f -'
[Desktop Action current-output]
Name=Current Output
Exec=sh -c 'grimshot save output - | swappy -f -'
[Desktop Action select-window]
Name=Select Window
Exec=sh -c 'grimshot save window - | swappy -f -'
[Desktop Action select-area]
Name=Select Area
Exec=sh -c 'grimshot save area - | swappy -f -'
Bind this to a key, select a point on the screen and get a HTML color code for that point copied to the clipboard. Requires ImageMagick, grim
and slurp
to be installed.
grim -g "$(slurp -p)" -t ppm - | convert - -format '%[pixel:p{0,0}]' txt:- | tail -n 1 | cut -d ' ' -f 4 | wl-copy
If you don't use a color picker frequently enough to reminder the keybinding, you can create a simple .desktop file for it in ~/.local/share/applications/ and then launch it searching for the name with a desktop file launcher like Rofi. Here's an example .desktop file:
[Desktop Entry]
Name=HTML Color Picker for Sway
Comment=Copies HTML color code to clipboard
Encoding=UTF-8
Version=1.0
Keywords=
Icon=
Exec=$HOME/.local/bin/html-color-picker-for-sway
Terminal=false
Type=Application
StartupNotify=true
Put the command above in ~/.local/bin/html-color-picker-for-sway
and add a shebang line as the first line: #!/bin/sh
#!/bin/sh
firefox=
swaymsg -m -t subscribe '["window"]' | \
jq -r --unbuffered '.change +" "+ .container.app_id + " " + (.container.pid | tostring)' | \
grep --line-buffered '^focus ' | \
while read -r x app pid; do
#echo "# x=$x app=$app pid=$pid" >&2
if [ "$app" = 'firefox' ]; then
echo "CONT $pid" >&2
firefox=$pid
kill -CONT $pid
pkill -CONT -P $pid
elif [ -n "$firefox" ]; then
echo "STOP $firefox" >&2
pkill -STOP -P $firefox
kill -STOP $firefox
fi
done
save it as $HOME/bin/tamefox
and add this to your .config/sway/config
:
exec [ -x $HOME/bin/tamefox ] && $HOME/bin/tamefox