To achieve what you want, you need to write some configuration in your i3 config file. Follow the steps below:
-
Open your i3 config file. It's usually located in ~/.config/i3/config or ~/.i3/config.
-
To autostart an xterm window and move it to the scratchpad when i3 starts, add the following lines to your config:
exec --no-startup-id xterm -title Scratchpad
for_window [title="^Scratchpad$"] move scratchpad
This will start an xterm with the title "Scratchpad" and move it to the scratchpad.
-
To show or hide the xterm window on a keypress (let's say Mod+Shift+Enter), add the following line:
bindsym $mod+Shift+Return [title="^Scratchpad$"] scratchpad show
This will show the xterm window if it's hidden, or hide it if it's visible.
-
If you accidentally close the xterm window and want to start it again in the scratchpad with the same keypress, you can use the following more complex command:
bindsym $mod+Shift+Return exec xterm -title Scratchpad && [title="^Scratchpad$"] scratchpad show
This will start a new xterm window with the title "Scratchpad" (if it's not already running) and show it.
-
Save your config file and reload i3 (usually with Mod+Shift+R).
Please replace $mod with your Mod key, usually it's either the Windows key or Alt. Also replace xterm -title Scratchpad with the command to start your terminal if you're not using xterm. The ^Scratchpad$ is a regex that matches the window title exactly, so make sure the title of your terminal window matches this.
Please note that the above solution is not perfect. If you accidentally close the xterm window and press Mod+Shift+Enter, it will start a new xterm window, but it won't hide the existing ones. To fix this, you might need to use a more complex script. For example, you could use a script that checks if an xterm window with the title "Scratchpad" is already running, and if not, starts a new one.