Home > OS >  Starting the default terminal on Linux
Starting the default terminal on Linux

Time:09-22

Tell me, please, is it possible to call the Linux Terminal, which is installed by default, in some way (method)?

Now, I run the process in the xfce4-terminal terminal, specifying this terminal and the arguments to it:

QProcess up;
QString cArg;
 
cArg="/tmp/cp.py -y "   ye;
up.start("xfce4-terminal", QStringList()<< "--geometry=120x40" << "--command" << "python3 "  cArg << "-H");
up.waitForFinished();
up.close();

CodePudding user response:

No, there is no general way in the Linux kernel to find out which (or whether a) terminal emulator is installed on the system by default.

Although the (fairly ubiquitous) freedesktop.org specifications describe how to associate MIME type with a default application, there isn't a specification for default application without an associated file to be opened as far as I can tell. Each desktop environment that has a concept of "default terminal emulator" has their own way of configuring it.

Debian has has "update-alternatives" system that allows configuration of "default" applications based on aliases, and it has a package that creates an alias x-terminal-emulator that can be used to configure the default terminal emulator.

Here is a reasonable strategy for choosing the command in your program:

  • Let the user configure the command. Use this with highest priority if configured.
  • Use XDG_CURRENT_DESKTOP environment variable, and implement logic for each desktop environment to read their configuration to find out the configured default emulator. Use this as the second highest priority when available.
  • Collect a list of commonly used terminal emulators. Put aliases such as x-terminal-emulator with higher priority in the list.
  • With this list starting with user configuration and ending with your hard-coded list, check each command and see if it's executable and pick the first one that is. In case user has configured the command, and it isn't executable, I recommend an optional error message.
  •  Tags:  
  • c qt
  • Related