GTK Single Instance Mode

GTK single instance mode is a feature that ensures only one instance of the application is running at a time.

Wintty uses GTK single instance mode by default when it detects it is not launched from a CLI environment.

GTK single instance mode is recommended by the GTK project and is the idiomatic way official Gnome applications are expected to behave. When a second instance of Wintty is launched, the original instance will create a new window, gain focus, and terminate the second instance.

Tip

If you're using Wintty on Linux and are experiencing slow startup times or high memory usage, GTK single instance detection may not be working for your environment and you may need to force it on. Continue reading this page to learn more.

CLI Environment Detection

The default behavior of Wintty is to use GTK single instance mode when not launched from a CLI environment.

Wintty has this behavior because CLI terminal usage is common (i.e. wintty -e "some command") and in those cases the expected behavior is to launch a new process and block until it exits. Single instance mode doesn't allow us to easily do this so we only want to enable single instance mode when launched from a non-CLI environment.

There isn't a standard API to detect if an application is launched from a non-CLI environment, so Wintty uses the following heuristic:

  1. If the TERM_PROGRAM environment variable is set to any non-empty value, we're assume we're in a graphical terminal emulator and disable GTK single instance mode.

  2. If any command line arguments are passed to Wintty, we assume we want instance-specific configuration and disable GTK single instance mode.

Forcing GTK Single Instance Mode On or Off

You can force GTK single instance mode on or off by setting the gtk-single-instance option:

gtk-single-instance = true

A value of true forces Wintty to run in single instance mode. In this mode, each new wintty process will result in a new window in an existing instance of Wintty if one is running.

Relationship to Startup Performance and Memory

Wintty is a GTK application. The GTK framework has unavoidable overhead when starting up, both in terms of how long it takes and how much memory it uses. Wintty can't do anything about this.

GTK single instance mode avoids this overhead for subsequent instances of Wintty. Launching a second instance of Wintty will be extremely fast and use very little memory since it is just creating a new window in the existing instance.