tightened up Sway support. There shouldn't be any bugs, but with something like this you never know. I3 users should certainly not encounter any bugs from these changes, please yell if something weird happens.

Oh, and finally pushed the ai.py script I have been using for some time without pushing. I guess several months of testing should be fine. lol
This commit is contained in:
Storm Dragon
2025-12-01 02:24:20 -05:00
parent fa9a6f3c7d
commit 63be4fc9e7
7 changed files with 1805 additions and 55 deletions

View File

@@ -1,21 +1,31 @@
#!/usr/bin/env bash
# Find out if we're using i3
# Find out if we're using i3 or sway
if ! [[ -n "${WAYLAND_DISPLAY}" ]]; then
cmd="i3-msg"
scratchConfig="${XDG_CONFIG_HOME:-$HOME/.config}/i3"
usingWayland=false
else
cmd="swaymsg"
scratchConfig="${XDG_CONFIG_HOME:-$HOME/.config}/sway"
usingWayland=true
fi
scratchConfig+="/scratchpad"
touch "${scratchConfig}"
# Get the focused window ID
windowId=$(xdotool getactivewindow)
# Get the class name of the window
class=$(xprop -id "$windowId" WM_CLASS | awk -F '"' '{print $4}')
# Get the class name of the focused window
if [[ "$usingWayland" == "true" ]]; then
# Wayland/Sway: use swaymsg to get focused window info
class=$($cmd -t get_tree | jq -r '.. | select(.focused? == true) | .app_id // .window_properties.class' | head -n 1)
else
# X11/i3: use xdotool and xprop
if ! command -v xdotool &> /dev/null || ! command -v xprop &> /dev/null; then
notify-send "Error: xdotool and xprop required for i3"
exit 1
fi
windowId=$(xdotool getactivewindow)
class=$(xprop -id "$windowId" WM_CLASS | awk -F '"' '{print $4}')
fi
if [[ -z "$class" ]]; then
notify-send "Unable to move to scratchpad."
@@ -23,10 +33,20 @@ if [[ -z "$class" ]]; then
fi
# Check if it's already in the config
if ! grep -q "class=\"$class\"" "$scratchConfig"; then
echo "for_window [class=\"$class\"] move to scratchpad" >> "$scratchConfig"
notify-send "Added window class $class to scratchpad"
if [[ "$usingWayland" == "true" ]]; then
# Sway uses app_id for Wayland-native apps, class for XWayland apps
if ! grep -q "app_id=\"$class\"" "$scratchConfig" && ! grep -q "class=\"$class\"" "$scratchConfig"; then
echo "for_window [app_id=\"$class\"] move to scratchpad" >> "$scratchConfig"
notify-send "Added window app_id $class to scratchpad"
fi
# Move the window to scratchpad now (try both app_id and class)
$cmd "[app_id=\"$class\"] move to scratchpad" 2>/dev/null || $cmd "[class=\"$class\"] move to scratchpad"
else
# i3 uses class
if ! grep -q "class=\"$class\"" "$scratchConfig"; then
echo "for_window [class=\"$class\"] move to scratchpad" >> "$scratchConfig"
notify-send "Added window class $class to scratchpad"
fi
# Move the window to scratchpad now
$cmd "[class=\"$class\"] move to scratchpad"
fi
# Move the window to scratchpad now
$cmd "[class=\"$class\"] move to scratchpad"