-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Tricks
throwaway1037 edited this page Feb 23, 2021
·
27 revisions
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"
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