Using the i3 window manager, you can configure it to autostart applications and manage windows in various ways, including sending them to the scratchpad and showing them again with a keypress. Here's how you can set up your i3 configuration to autostart an xterm window, move it to the scratchpad, and bind a key to toggle its visibility.
-
Edit your i3 configuration file: Usually, the i3 config file is located at ~/.config/i3/config. Open this file with your preferred text editor.
-
Autostart xterm: Add the following line to your i3 config file to autostart xterm when i3 starts:
exec_always --no-startup-id xterm -name scratchpad-term
The --no-startup-id flag is to prevent i3 from waiting for a startup notification. The -name scratchpad-term is setting a specific window instance name for the xterm window, so we can easily identify it later.
-
Move xterm to the scratchpad: To automatically move the xterm window to the scratchpad upon startup, you can use a for_window directive with a criteria that matches the instance name you set earlier. Add the following to your i3 config file:
for_window [instance="scratchpad-term"] move scratchpad
-
Bind a key to show/hide the xterm scratchpad: Choose a key combination to toggle the xterm window's visibility. For example, if you want to use $mod+grave (where $mod is usually the Alt or Super/Windows key, depending on your configuration), add the following line to your i3 config file:
bindsym $mod+grave [instance="scratchpad-term"] scratchpad show
-
Reload i3 configuration: After saving the changes to your i3 config file, you need to reload the configuration. You can do this by pressing $mod+Shift+r (assuming $mod is your configured modifier key).
-
Using Scratchpad: Now, when you start i3, xterm should start and move to the scratchpad automatically. Pressing $mod+grave will toggle the visibility of the xterm window.
Remember that you can customize the instance name, the key binding, and other parameters according to your preferences. The instance name scratchpad-term is just an example and can be replaced with any name you like, but make sure it is consistent in both the exec_always and for_window directives.
Always back up your configuration file before making changes, so you can easily revert back if something goes wrong. After editing and saving your config file, you can use the i3-msg tool for troubleshooting and testing your config without reloading i3:
i3-msg 'exec xterm -name scratchpad-term'
i3-msg '[instance="scratchpad-term"] move scratchpad'
These commands mimic the behavior you configured but are executed immediately in your current session.