Force application to minimize to icon tray rather than closing

Is there a way to force an application to minimize to the icon tray instead of closing the application when the X is clicked in Windows 10?

Unfortunately no.

I have both types of applications and where I can minimize instead of close, it is an option withing the application as software vendors do not know what you or I might like.

But it is application dependent (not operating system dependent) (at least for the very large majority of apps).

So you would need to appeal to the software vendor to change it. Microsoft is probably least likely to change.


While the other answer here is (mostly) correct as far as your question title, your question itself mentions WSL, and that actually offers some more options that might fit your needs. Three of these are specific to WSL, but there's also a potential "general application" solution that I can't verify:

Short answer:
  • Best option (IMHO): Tmux
  • Easiest option: ConEmu
Details:
  • Tmux (or its older cousin, Screen): I really think you'll find this a better option than minimizing to the tray. Tmux is a utility that is installed by default in Ubuntu WSL. (Oversimplifying here, but) It keeps things running in the background even after the parent window (such as the Windows Terminal tab) is closed.

    Try this. Start up your WSL instance and:

    $ tmux
    $ ls
    bin  boot  dev  etc  home  init  lib  lib32  lib64  libx32  lost+found
    media  mnt  opt  proc  root  run  sbin  snap  srv  sys  tmp  usr  var
    $ nano ~/hello  # or vi, if you prefer
    

    Now close WSL or Windows Terminal.

    Restart it. You should find it starts up almost instantaneously, since it was still running in the background.

    Now:

    tmux attach-session
    

    You'll find you are right back where you were in the editor. Exit the editor, and you'll even see the output from the previous ls command.

    If you want to truly exit, then Ctrl+D or exit from your shell. Tmux will close, then you can exit the shell again (or hit X) to close for real.

    You can automate this with Windows Terminal by setting your "Command line" for the profile to something like wsl -e tmux new-session -AD -t main -s main. This will always start WSL with tmux, and look for a session named main. If found, it will reattach to it. Otherwise, it will create it.

    Tmux provides many more features, including multiple tabs itself.

    One tip, though, is to set the "Prefix" to Ctrl+A instead of the default Ctrl+B. IMHO, it's much less of a finger-stretch.


  • There's always the option of using a different terminal emulator that has the "minimize to tray" feature built-in. ConEmu appears to be one of those, although I haven't tested the feature myself.

    However, I can at least confirm that ConEmu works with WSL just fine.


  • If you really want to have the X minimize to the tray for the Windows Console (that's the default "WSL" terminal) or Windows Terminal, it may be possible. I haven't tried this, and from my searches, no one has in a few years. But a program called AutoHotkey can, in theory, be used to intercept a click on the X. See this Stack Overflow question and its answer, but realize that it was for Windows 7, with a note that it might not work on Aero (which is used by Windows 10 and 11).

    Assuming that you could intercept the click, the AutoHotkey script could then run a third-party app to minimize to the tray.


  • Kind of a poor-man's workaround, but if you have more than one tab open in Windows Terminal, then hitting the X will (by default) result in a message asking, "Do you want to close all tabs?" So just having two tabs open, can at least keep you from "closing accidentally". You can then use a hotkey for one of the other, previously mentioned "minimize to tray" apps.