From 09e21e297c4252bb5c0da067e0db9d51ccdae8df Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Tue, 15 Apr 2025 18:31:32 -0400 Subject: [PATCH] Added ability to have applications start in the scratchpad. --- i38.sh | 7 ++++++- scripts/bind_to_scratchpad.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100755 scripts/bind_to_scratchpad.sh diff --git a/i38.sh b/i38.sh index 4fbea9b..b651055 100755 --- a/i38.sh +++ b/i38.sh @@ -516,9 +516,13 @@ bindsym Mod1+Tab focus right bindsym \$mod+BackSpace fullscreen toggle -# move the currently focused window to the scratchpad +# Move the currently focused window to the scratchpad bindsym \$mod+Shift+minus move scratchpad +# Bind the currently focused window to the scratchpad +# This means it will always open in the scratchpad +bindsym \$mod+Shift+equal exec --no-startup-id ${i3Path}/scripts/bind_to_scratchpad.sh + # Show the next scratchpad window or hide the focused scratchpad window. # If there are multiple scratchpad windows, this command cycles through them. bindsym \$mod+minus scratchpad show @@ -770,6 +774,7 @@ exec --no-startup-id bash -c 'if [[ -f "${i3Path}/firstrun" ]]; then ${webBrowse include "${i3Path}/customizations" EOF touch "${i3Path}/customizations" +touch "${i3Path}/scratchpad" # Check for markdown or pandoc for converting the welcome document if command -v pandoc &> /dev/null ; then pandoc -f markdown -t html "I38.md" -so "${i3Path}/I38.html" --metadata title="Welcome to I38" diff --git a/scripts/bind_to_scratchpad.sh b/scripts/bind_to_scratchpad.sh new file mode 100755 index 0000000..9e7eb95 --- /dev/null +++ b/scripts/bind_to_scratchpad.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +# Find out if we're using i3 +if ! [[ -n "${WAYLAND_DISPLAY}" ]]; then + cmd="i3-msg" + scratchConfig="${XDG_CONFIG_HOME:-$HOME/.config}/i3" +else + cmd="swaymsg" + scratchConfig="${XDG_CONFIG_HOME:-$HOME/.config}/sway" +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}') + +if [[ -z "$class" ]]; then + notify-send "Unable to move to scratchpad." + exit 1 +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" +fi + +# Move the window to scratchpad now +$cmd "[class=\"$class\"] move to scratchpad"