chore: cleanup
This commit is contained in:
27
configs/sway/scripts/create-floating
Executable file
27
configs/sway/scripts/create-floating
Executable file
@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
$@ &
|
||||
pid=$!
|
||||
|
||||
|
||||
ALL_NODES='recurse(.nodes[]?, .floating_nodes[]?) | select(.pid and .visible)'
|
||||
|
||||
sleep 0.3
|
||||
|
||||
all_nodes="$(swaymsg -t get_tree | jq -r "$ALL_NODES" | jq -c '.pid')"
|
||||
window_id="$(swaymsg -t get_tree | jq -r "$ALL_NODES" | jq --argjson pid $pid -c 'select(.pid==$pid).id')"
|
||||
swaymsg "[ con_id=$window_id ] floating enable, resize set 800 400, move position 1115 670, sticky enable"
|
||||
|
||||
# swaymsg -t subscribe -m '[ "window" ]' \
|
||||
# | jq --unbuffered --argjson pid "$pid" '.container | select(.pid == $pid) | .id' \
|
||||
# | xargs -I '@' -- swaymsg '[ con_id=@ ] floating enable' &
|
||||
|
||||
# subscription=$!
|
||||
|
||||
# echo Going into wait state
|
||||
|
||||
# # Wait for our process to close
|
||||
# tail --pid=$pid -f /dev/null
|
||||
|
||||
# echo Killing subscription
|
||||
# kill $subscription
|
34
configs/sway/scripts/debug-window
Executable file
34
configs/sway/scripts/debug-window
Executable file
@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
|
||||
ALL_NODES='recurse(.nodes[]?, .floating_nodes[]?) | select(.pid and .visible)'
|
||||
WINDOW_NAME='(.app_id // .window_properties.class)'
|
||||
ID_PREFIX='"\(.pid):"'
|
||||
WINDOW_PROTOCOL='(if .shell == "xwayland" then "X11" else "wayland" end)'
|
||||
WINDOW_GEOMETRY='(.rect | "\(.x),\(.y) \(.width)x\(.height) ")'
|
||||
WINDOW_PID='(.id | tostring)'
|
||||
CLEAR_OBJ="del(.focus, .pid, .border, .current_border_width, .window_rect, .orientation, .layout, .percent, .deco_rect, .geometry, .window, .urgent, .marks, .sticky, .fullscreen_mode, .nodes, .floating_nodes, .shell, .max_render_time, .visible, .idle_inhibitors, .inhibit_idle)"
|
||||
|
||||
# Output format, e.g. "1234 - 12:firefox (wayland)" or "5678 - 17:discord (X11)"
|
||||
FILT="$ALL_NODES | $WINDOW_GEOMETRY + $WINDOW_PID"
|
||||
|
||||
function getprop() {
|
||||
typeset -A views
|
||||
local selected
|
||||
|
||||
while read POS GEOM INFO; do
|
||||
views["$POS $GEOM"]="$INFO"
|
||||
done
|
||||
|
||||
|
||||
selected="$(printf "%s\n" "${!views[@]}" | slurp)"
|
||||
if [[ -n "$selected" ]]; then
|
||||
window_id=${views[${selected}]};
|
||||
echo "SelectedId $window_id"
|
||||
SELECT_ID=$(echo ".. | (.nodes? // empty)[] | select(.id == $window_id) | $CLEAR_OBJ ")
|
||||
selected="$(swaymsg -t get_tree | jq -r "$ALL_NODES" | jq -c ". | select(.id==$window_id)" | jq)"
|
||||
echo "Selected: $selected"
|
||||
notify-send "Debug:" "$(echo $selected | jq -c "$CLEAR_OBJ" | jq)";
|
||||
fi
|
||||
}
|
||||
|
||||
swaymsg -t get_tree | jq -r "$FILT" | getprop
|
154
configs/sway/scripts/grimshot
Executable file
154
configs/sway/scripts/grimshot
Executable file
@ -0,0 +1,154 @@
|
||||
#!/bin/sh
|
||||
|
||||
## Grimshot: a helper for screenshots within sway
|
||||
## Requirements:
|
||||
## - `grim`: screenshot utility for wayland
|
||||
## - `slurp`: to select an area
|
||||
## - `swaymsg`: to read properties of current window
|
||||
## - `wl-copy`: clipboard utility
|
||||
## - `jq`: json utility to parse swaymsg output
|
||||
## - `notify-send`: to show notifications
|
||||
## Those are needed to be installed, if unsure, run `grimshot check`
|
||||
##
|
||||
## See `man 1 grimshot` or `grimshot usage` for further details.
|
||||
|
||||
getTargetDirectory() {
|
||||
test -f ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs && \
|
||||
. ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs
|
||||
|
||||
echo ${XDG_SCREENSHOTS_DIR:-${XDG_PICTURES_DIR:-$HOME}}
|
||||
}
|
||||
|
||||
if [ "$1" = "--notify" ]; then
|
||||
NOTIFY=yes
|
||||
shift 1
|
||||
else
|
||||
NOTIFY=no
|
||||
fi
|
||||
|
||||
ACTION=${1:-usage}
|
||||
SUBJECT=${2:-screen}
|
||||
FILE=${3:-$(getTargetDirectory)/$(date -Ins).png}
|
||||
|
||||
if [ "$ACTION" != "save" ] && [ "$ACTION" != "copy" ] && [ "$ACTION" != "check" ]; then
|
||||
echo "Usage:"
|
||||
echo " grimshot [--notify] (copy|save) [active|screen|output|area|window] [FILE|-]"
|
||||
echo " grimshot check"
|
||||
echo " grimshot usage"
|
||||
echo ""
|
||||
echo "Commands:"
|
||||
echo " copy: Copy the screenshot data into the clipboard."
|
||||
echo " save: Save the screenshot to a regular file or '-' to pipe to STDOUT."
|
||||
echo " check: Verify if required tools are installed and exit."
|
||||
echo " usage: Show this message and exit."
|
||||
echo ""
|
||||
echo "Targets:"
|
||||
echo " active: Currently active window."
|
||||
echo " screen: All visible outputs."
|
||||
echo " output: Currently active output."
|
||||
echo " area: Manually select a region."
|
||||
echo " window: Manually select a window."
|
||||
exit
|
||||
fi
|
||||
|
||||
notify() {
|
||||
notify-send -t 3000 -a grimshot "$@"
|
||||
}
|
||||
notifyOk() {
|
||||
[ "$NOTIFY" = "no" ] && return
|
||||
|
||||
TITLE=${2:-"Screenshot"}
|
||||
MESSAGE=${1:-"OK"}
|
||||
notify "$TITLE" "$MESSAGE"
|
||||
}
|
||||
notifyError() {
|
||||
if [ $NOTIFY = "yes" ]; then
|
||||
TITLE=${2:-"Screenshot"}
|
||||
MESSAGE=${1:-"Error taking screenshot with grim"}
|
||||
notify -u critical "$TITLE" "$MESSAGE"
|
||||
else
|
||||
echo $1
|
||||
fi
|
||||
}
|
||||
|
||||
die() {
|
||||
MSG=${1:-Bye}
|
||||
notifyError "Error: $MSG"
|
||||
exit 2
|
||||
}
|
||||
|
||||
check() {
|
||||
COMMAND=$1
|
||||
if command -v "$COMMAND" > /dev/null 2>&1; then
|
||||
RESULT="OK"
|
||||
else
|
||||
RESULT="NOT FOUND"
|
||||
fi
|
||||
echo " $COMMAND: $RESULT"
|
||||
}
|
||||
|
||||
takeScreenshot() {
|
||||
FILE=$1
|
||||
GEOM=$2
|
||||
OUTPUT=$3
|
||||
if [ ! -z "$OUTPUT" ]; then
|
||||
grim -o "$OUTPUT" "$FILE" || die "Unable to invoke grim"
|
||||
elif [ -z "$GEOM" ]; then
|
||||
grim "$FILE" || die "Unable to invoke grim"
|
||||
else
|
||||
grim -g "$GEOM" "$FILE" || die "Unable to invoke grim"
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "$ACTION" = "check" ] ; then
|
||||
echo "Checking if required tools are installed. If something is missing, install it to your system and make it available in PATH..."
|
||||
check grim
|
||||
check slurp
|
||||
check swaymsg
|
||||
check wl-copy
|
||||
check jq
|
||||
check notify-send
|
||||
exit
|
||||
elif [ "$SUBJECT" = "area" ] ; then
|
||||
GEOM=$(slurp -d)
|
||||
# Check if user exited slurp without selecting the area
|
||||
if [ -z "$GEOM" ]; then
|
||||
exit 1
|
||||
fi
|
||||
WHAT="Area"
|
||||
elif [ "$SUBJECT" = "active" ] ; then
|
||||
FOCUSED=$(swaymsg -t get_tree | jq -r 'recurse(.nodes[]?, .floating_nodes[]?) | select(.focused)')
|
||||
GEOM=$(echo "$FOCUSED" | jq -r '.rect | "\(.x),\(.y) \(.width)x\(.height)"')
|
||||
APP_ID=$(echo "$FOCUSED" | jq -r '.app_id')
|
||||
WHAT="$APP_ID window"
|
||||
elif [ "$SUBJECT" = "screen" ] ; then
|
||||
GEOM=""
|
||||
WHAT="Screen"
|
||||
elif [ "$SUBJECT" = "output" ] ; then
|
||||
GEOM=""
|
||||
OUTPUT=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused)' | jq -r '.name')
|
||||
WHAT="$OUTPUT"
|
||||
elif [ "$SUBJECT" = "window" ] ; then
|
||||
GEOM=$(swaymsg -t get_tree | jq -r '.. | select(.pid? and .visible?) | .rect | "\(.x),\(.y) \(.width)x\(.height)"' | slurp)
|
||||
# Check if user exited slurp without selecting the area
|
||||
if [ -z "$GEOM" ]; then
|
||||
exit 1
|
||||
fi
|
||||
WHAT="Window"
|
||||
else
|
||||
die "Unknown subject to take a screen shot from" "$SUBJECT"
|
||||
fi
|
||||
|
||||
if [ "$ACTION" = "copy" ] ; then
|
||||
takeScreenshot - "$GEOM" "$OUTPUT" | wl-copy --type image/png || die "Clipboard error"
|
||||
notifyOk "$WHAT copied to buffer"
|
||||
else
|
||||
if takeScreenshot "$FILE" "$GEOM" "$OUTPUT"; then
|
||||
TITLE="Screenshot of $SUBJECT"
|
||||
MESSAGE=$(basename "$FILE")
|
||||
notifyOk "$MESSAGE" "$TITLE"
|
||||
echo $FILE
|
||||
else
|
||||
notifyError "Error taking screenshot with grim"
|
||||
fi
|
||||
fi
|
3
configs/sway/scripts/lock-screen
Executable file
3
configs/sway/scripts/lock-screen
Executable file
@ -0,0 +1,3 @@
|
||||
#!/usr/bin/sh
|
||||
|
||||
swaylock -c 000000
|
18
configs/sway/scripts/select-window
Executable file
18
configs/sway/scripts/select-window
Executable file
@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
|
||||
# ------Get available windows:
|
||||
windows=$(swaymsg -t get_tree | jq -r '
|
||||
recurse(.nodes[]?) |
|
||||
recurse(.floating_nodes[]?) |
|
||||
select(.type=="con"), select(.type=="floating_con") |
|
||||
(.id | tostring) + " " + .app_id + ": " + .name')
|
||||
|
||||
# ------Limit wofi's height with the number of opened windows:
|
||||
height=$(echo "$windows" | wc -l)
|
||||
height=$(($height + 2))
|
||||
|
||||
# ------Select window with wofi:
|
||||
selected=$(echo "$windows" | wofi -d --lines $height -i -p "Switch to:" | awk '{print $1}')
|
||||
|
||||
# ------Tell sway to focus said window:
|
||||
swaymsg [con_id="$selected"] focus
|
18
configs/sway/scripts/toggle-bar
Executable file
18
configs/sway/scripts/toggle-bar
Executable file
@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
|
||||
GAPS=3
|
||||
|
||||
# How to get the current inner border from swaymsg
|
||||
#$ echo $(swaymsg -t get_config | jq ".config") | sed -n '/gaps\ inner/p' | sed 's/gaps\ inner//g' | xargs
|
||||
|
||||
bar_mode="$(swaymsg -t get_bar_config bar-0 | jq '.mode')"
|
||||
|
||||
if [ "$bar_mode" != "dock" ]; then
|
||||
swaymsg bar mode hide bar-0
|
||||
swaymsg gaps outer all set 0;
|
||||
swaymsg gaps inner all set 0;
|
||||
else
|
||||
swaymsg bar mode dock bar-0
|
||||
swaymsg gaps outer all set $GAPS;
|
||||
swaymsg gaps inner all set $GAPS;
|
||||
fi
|
16
configs/sway/scripts/toggle-gaps
Executable file
16
configs/sway/scripts/toggle-gaps
Executable file
@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
GAPS=3
|
||||
|
||||
# How to get the current inner border from swaymsg
|
||||
#$ echo $(swaymsg -t get_config | jq ".config") | sed -n '/gaps\ inner/p' | sed 's/gaps\ inner//g' | xargs
|
||||
|
||||
if [ "$(ps cax | grep waybar$)" != "" ]; then
|
||||
swaymsg gaps outer all set 0;
|
||||
swaymsg gaps inner all set 0;
|
||||
killall waybar;
|
||||
else
|
||||
swaymsg gaps outer all set $GAPS;
|
||||
swaymsg gaps inner all set $GAPS;
|
||||
nohup waybar & 2&> /dev/null;
|
||||
fi
|
31
configs/sway/scripts/toggle-layout
Executable file
31
configs/sway/scripts/toggle-layout
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
|
||||
WORKSPACE=$(swaymsg -t get_workspaces --raw | jq '.[] | select(.focused == true)')
|
||||
|
||||
|
||||
WORKSPACE_ID=$(echo $WORKSPACE | jq ".name" | tr -d '"')
|
||||
WORKSPACE_MODE=$(swaymsg -t get_tree | jq 'recurse(.nodes[]) | select(.nodes[].focused == true).layout');
|
||||
echo "WORKSPACE: $WORKSPACE_MODE"
|
||||
|
||||
MODE_SPLITH='"splith"'
|
||||
MODE_SPLITV='"splitv"'
|
||||
MODE_TABBED='"tabbed"'
|
||||
MODE_STACKED='"stacked"'
|
||||
|
||||
function set_layout(){
|
||||
swaymsg "workspace $(swaymsg -t get_workspaces --raw | jq '.[] | select(.focused == true) .name'); layout $1"
|
||||
}
|
||||
|
||||
if [ $WORKSPACE_MODE = $MODE_SPLITH ]; then
|
||||
set_layout splitv
|
||||
elif [ $WORKSPACE_MODE = $MODE_SPLITV ]; then
|
||||
set_layout tabbed
|
||||
# elif [ $WORKSPACE_MODE = $MODE_TABBED ]; then
|
||||
# set_layout stacking
|
||||
elif [ $WORKSPACE_MODE = $MODE_TABBED ]; then
|
||||
set_layout splith
|
||||
fi
|
||||
|
||||
if [ "$1" != "" ]; then
|
||||
set_layout $1
|
||||
fi
|
Reference in New Issue
Block a user