# Super+c closes a window
gsettings set org.gnome.desktop.wm.keybindings close "['<Super>c']"

# Make it easy to maximize like you can fill left/right
gsettings set org.gnome.desktop.wm.keybindings maximize "['<Super>Up']"

# Full-screen with title/navigation bar
gsettings set org.gnome.desktop.wm.keybindings toggle-fullscreen "['<Shift>F11']"

# Use 6 fixed workspaces instead of dynamic mode
gsettings set org.gnome.mutter dynamic-workspaces false
gsettings set org.gnome.desktop.wm.preferences num-workspaces 6

# Unbind any existing Super+num binds
info "Unbinding any Super+N keys to use for workspaces instead"
for i in {1..9}; do
    gsettings set org.gnome.shell.keybindings switch-to-application-$i "[]"
done

# Use super for workspaces
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-1 "['<Super>1']"
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-2 "['<Super>2']"
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-3 "['<Super>3']"
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-4 "['<Super>4']"
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-5 "['<Super>5']"
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-6 "['<Super>6']"

# Set right click to resize
gsettings set org.gnome.desktop.wm.preferences resize-with-right-button true

# Clear all existing custom keybindings
echo "Clearing existing GNOME custom keybindings..."

# Get existing keybinding paths
existing=$(gsettings get org.gnome.settings-daemon.plugins.media-keys custom-keybindings)
existing=$(echo "$existing" | sed "s/^\[//;s/\]$//;s/,//g" | tr -d "'")

# Loop through each and clear its keys
for path in $existing; do
    gsettings reset-recursively "org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:$path" 2>/dev/null
done

# Clear the master list
gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybindings "[]"

echo "Adding custom keybindings"

reservebindslots 8
custombind 0 'Flameshot' "sh -c -- \"flameshot gui\"" '<Control>Print'
custombind 1 'New Brave window' "brave-browser" '<Super><Shift>o'
custombind 2 'New Brave incognito window' 'brave-browser --incognito' '<Super><Shift>p'
custombind 3 'Kitty' 'kitty' '<Super>q'
custombind 4 'File Explorer' 'nautilus --new-window' '<Super>e'
custombind 5 'Project selector' 'kitty --start-as=normal -- bash -ic "proj"' '<Control><Shift>p'
custombind 6 'TODO List' 'brave-browser --new-window --app=https://do.thatshit.live' '<Control><Shift>t'
custombind 7 'ChatGPT' 'brave-browser --new-window --app=https://chatgpt.com' '<Super>Return'
