mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
ADD: Auto-detect default terminal emulator
This commit is contained in:
parent
137c2af384
commit
ff6f89e618
4 changed files with 232 additions and 11 deletions
|
|
@ -65,12 +65,12 @@ const
|
|||
RunInTermCloseParams = '';
|
||||
MonoSpaceFont = 'Monaco';
|
||||
{$ELSE}
|
||||
RunTermCmd = 'xterm'; // default terminal
|
||||
RunTermParams = '';
|
||||
RunInTermStayOpenCmd = 'xterm'; // default run in terminal command AND Stay open after command
|
||||
RunInTermStayOpenParams = '-e sh -c ''{command}; echo -n Press ENTER to exit... ; read a''';
|
||||
RunInTermCloseCmd = 'xterm'; // default run in terminal command AND Close after command
|
||||
RunInTermCloseParams = '-e sh -c {command}';
|
||||
RunTermCmd: String = 'xterm'; // default terminal
|
||||
RunTermParams: String = '';
|
||||
RunInTermStayOpenCmd: String = 'xterm'; // default run in terminal command AND Stay open after command
|
||||
RunInTermStayOpenParams: String = '-e sh -c ''{command}; echo -n Press ENTER to exit... ; read a''';
|
||||
RunInTermCloseCmd: String = 'xterm'; // default run in terminal command AND Close after command
|
||||
RunInTermCloseParams: String = '-e sh -c {command}';
|
||||
MonoSpaceFont = 'Monospace';
|
||||
{$ENDIF}
|
||||
fmtCommandPath = '[%s]$:';
|
||||
|
|
|
|||
214
src/platform/unix/udefaultterminal.pas
Normal file
214
src/platform/unix/udefaultterminal.pas
Normal file
|
|
@ -0,0 +1,214 @@
|
|||
{
|
||||
Double commander
|
||||
-------------------------------------------------------------------------
|
||||
Auto-detect default terminal emulator
|
||||
|
||||
Copyright (C) 2021 Alexander Koblov (alexx2000@mail.ru)
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
}
|
||||
|
||||
unit uDefaultTerminal;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
DCOSUtils, DCClassesUtf8, uMyUnix, uGio, uOSUtils;
|
||||
|
||||
const
|
||||
TERM_KDE = 'konsole';
|
||||
TERM_LXQT = 'qterminal';
|
||||
TERM_LXDE = 'lxterminal';
|
||||
TERM_MATE = 'mate-terminal';
|
||||
TERM_XFCE = 'xfce4-terminal';
|
||||
TERM_GNOME = 'gnome-terminal';
|
||||
TERM_DEBIAN = 'x-terminal-emulator';
|
||||
|
||||
function GetPathTerminal(const Exe: String; var Cmd: String): Boolean;
|
||||
begin
|
||||
Result:= ExecutableInSystemPath(Exe);
|
||||
if Result then Cmd:= Exe;
|
||||
end;
|
||||
|
||||
function GetKdeTerminal(var Cmd, Params: String): Boolean;
|
||||
const
|
||||
kde5Config = '/.kde/share/config/kdeglobals';
|
||||
kde4Config = '/.kde4/share/config/kdeglobals';
|
||||
var
|
||||
I: Integer;
|
||||
S: String = '';
|
||||
iniCfg: TIniFileEx = nil;
|
||||
kdeConfig: array[1..2] of String = (kde4Config, kde5Config);
|
||||
begin
|
||||
for I:= Low(kdeConfig) to High(kdeConfig) do
|
||||
begin
|
||||
if (Length(S) = 0) and mbFileExists(GetHomeDir + kdeConfig[I]) then
|
||||
try
|
||||
iniCfg:= TIniFileEx.Create(GetHomeDir + kdeConfig[I]);
|
||||
try
|
||||
S:= iniCfg.ReadString('General', 'TerminalApplication', EmptyStr);
|
||||
finally
|
||||
iniCfg.Free;
|
||||
end;
|
||||
except
|
||||
// Skip
|
||||
end;
|
||||
end;
|
||||
Params:= EmptyStr;
|
||||
Result:= Length(S) > 0;
|
||||
if not Result then begin
|
||||
Result:= GetPathTerminal(TERM_KDE, S);
|
||||
end;
|
||||
if Result then Cmd:= S;
|
||||
end;
|
||||
|
||||
function GetXfceTerminal(var Cmd, Params: String): Boolean;
|
||||
const
|
||||
xfceConfig = '/.config/xfce4/helpers.rc';
|
||||
var
|
||||
S: String = '';
|
||||
FileName: String;
|
||||
begin
|
||||
FileName:= GetHomeDir + xfceConfig;
|
||||
if mbFileExists(FileName) then
|
||||
begin
|
||||
with TStringListEx.Create do
|
||||
try
|
||||
try
|
||||
LoadFromFile(FileName);
|
||||
S:= Values['TerminalEmulator'];
|
||||
except
|
||||
// Skip
|
||||
end;
|
||||
finally
|
||||
Free;
|
||||
end;
|
||||
end;
|
||||
Result:= (Length(S) > 0);
|
||||
if not Result then begin
|
||||
Result:= GetPathTerminal(TERM_XFCE, S);
|
||||
end;
|
||||
if (S = TERM_XFCE) then
|
||||
begin
|
||||
Params:= '-x';
|
||||
end;
|
||||
if Result then Cmd:= S;
|
||||
end;
|
||||
|
||||
function GetLxdeTerminal(var Cmd, Params: String): Boolean;
|
||||
begin
|
||||
Params:= EmptyStr;
|
||||
Result:= GetPathTerminal(TERM_LXDE, Cmd);
|
||||
end;
|
||||
|
||||
function GetLxqtTerminal(var Cmd, Params: String): Boolean;
|
||||
begin
|
||||
Params:= EmptyStr;
|
||||
Result:= GetPathTerminal(TERM_LXQT, Cmd);
|
||||
end;
|
||||
|
||||
function GetGioTerminal(const Scheme: String; var Cmd, Params: String): Boolean;
|
||||
begin
|
||||
Cmd:= GioGetSetting(Scheme, 'exec');
|
||||
Params:= GioGetSetting(Scheme, 'exec-arg');
|
||||
Result:= Length(Cmd) > 0;
|
||||
end;
|
||||
|
||||
function GetGnomeTerminal(var Cmd, Params: String): Boolean;
|
||||
begin
|
||||
Result:= GetGioTerminal('org.gnome.desktop.default-applications.terminal', Cmd, Params);
|
||||
if not Result then
|
||||
begin
|
||||
Params:= '-x';
|
||||
Result:= GetPathTerminal(TERM_GNOME, Cmd);
|
||||
end;
|
||||
end;
|
||||
|
||||
function GetMateTerminal(var Cmd, Params: String): Boolean;
|
||||
begin
|
||||
Result:= GetGioTerminal('org.mate.applications-terminal', Cmd, Params);
|
||||
if not Result then
|
||||
begin
|
||||
Params:= '-x';
|
||||
Result:= GetPathTerminal(TERM_MATE, Cmd);
|
||||
end;
|
||||
end;
|
||||
|
||||
function GetCinnamonTerminal(var Cmd, Params: String): Boolean;
|
||||
begin
|
||||
Result:= GetGioTerminal('org.cinnamon.desktop.default-applications.terminal', Cmd, Params);
|
||||
if not Result then
|
||||
begin
|
||||
Params:= '-x';
|
||||
Result:= GetPathTerminal(TERM_GNOME, Cmd);
|
||||
end;
|
||||
end;
|
||||
|
||||
function GetDefaultTerminal(var Cmd, Params: String): Boolean;
|
||||
begin
|
||||
if mbFileExists('/etc/debian_version') then
|
||||
begin
|
||||
Cmd:= TERM_DEBIAN;
|
||||
Exit(True);
|
||||
end;
|
||||
case DesktopEnv of
|
||||
DE_UNKNOWN:
|
||||
Result:= False;
|
||||
DE_KDE:
|
||||
Result:= GetKdeTerminal(Cmd, Params);
|
||||
DE_XFCE:
|
||||
Result:= GetXfceTerminal(Cmd, Params);
|
||||
DE_LXDE:
|
||||
Result:= GetLxdeTerminal(Cmd, Params);
|
||||
DE_LXQT:
|
||||
Result:= GetLxqtTerminal(Cmd, Params);
|
||||
DE_MATE:
|
||||
Result:= GetMateTerminal(Cmd, Params);
|
||||
DE_GNOME:
|
||||
Result:= GetGnomeTerminal(Cmd, Params);
|
||||
DE_CINNAMON:
|
||||
Result:= GetCinnamonTerminal(Cmd, Params);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure Initialize;
|
||||
var
|
||||
Cmd: String = '';
|
||||
Params: String = '';
|
||||
begin
|
||||
if GetDefaultTerminal(Cmd, Params) then
|
||||
begin
|
||||
RunTermCmd:= Cmd;
|
||||
RunInTermCloseCmd:= Cmd;
|
||||
RunInTermStayOpenCmd:= Cmd;
|
||||
if (Length(Params) > 0) then
|
||||
begin
|
||||
RunInTermCloseParams:= StringReplace(RunInTermCloseParams, '-e', Params, []);
|
||||
RunInTermStayOpenParams:= StringReplace(RunInTermStayOpenParams, '-e', Params, []);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
initialization
|
||||
Initialize;
|
||||
|
||||
end.
|
||||
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
Interface to GIO - GLib Input, Output and Streaming Library
|
||||
This unit loads all libraries dynamically so it can work without it
|
||||
|
||||
Copyright (C) 2011-2019 Alexander Koblov (alexx2000@mail.ru)
|
||||
Copyright (C) 2011-2021 Alexander Koblov (alexx2000@mail.ru)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -35,6 +35,7 @@ function GioOpen(const Uri: String): Boolean;
|
|||
function GioNewFile(const Address: String): PGFile;
|
||||
function GioGetIconTheme(const Scheme: String): String;
|
||||
function GioFileGetIcon(const FileName: String): String;
|
||||
function GioGetSetting(const Scheme, Key: String): String;
|
||||
function GioFileGetEmblem(const FileName: String): String;
|
||||
function GioMimeTypeGetActions(const MimeType: String): TDynamicStringArray;
|
||||
function GioGetMimeType(const FileName: String; MaxExtent: LongWord): String;
|
||||
|
|
@ -101,14 +102,15 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
function GioGetIconTheme(const Scheme: String): String;
|
||||
function GioGetSetting(const Scheme, Key: String): String;
|
||||
var
|
||||
Theme: Pgchar;
|
||||
Settings: PGSettings;
|
||||
SettingsSchema: PGSettingsSchema;
|
||||
SchemaSource: PGSettingsSchemaSource;
|
||||
begin
|
||||
if not HasGio then Exit(EmptyStr);
|
||||
Result:= EmptyStr;
|
||||
if not HasGio then Exit;
|
||||
SchemaSource:= g_settings_schema_source_get_default();
|
||||
if Assigned(SchemaSource) then
|
||||
begin
|
||||
|
|
@ -118,7 +120,7 @@ begin
|
|||
Settings:= g_settings_new(Pgchar(Scheme));
|
||||
if Assigned(Settings) then
|
||||
begin
|
||||
Theme:= g_settings_get_string(Settings, 'icon-theme');
|
||||
Theme:= g_settings_get_string(Settings, Pgchar(Key));
|
||||
if Assigned(Theme) then
|
||||
begin
|
||||
Result:= StrPas(Theme);
|
||||
|
|
@ -132,6 +134,11 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
function GioGetIconTheme(const Scheme: String): String;
|
||||
begin
|
||||
Result:= GioGetSetting(Scheme, 'icon-theme');
|
||||
end;
|
||||
|
||||
function GioFileGetIcon(const FileName: String): String;
|
||||
var
|
||||
GFile: PGFile;
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ uses
|
|||
, BaseUnix, Errors, fFileProperties, uJpegThumb
|
||||
{$IF NOT DEFINED(DARWIN)}
|
||||
, uDCReadSVG, uMagickWand, uGio, uGioFileSource, uVfsModule, uVideoThumb
|
||||
, uDCReadWebP, uFolderThumb, uAudioThumb
|
||||
, uDCReadWebP, uFolderThumb, uAudioThumb, uDefaultTerminal
|
||||
{$ELSE}
|
||||
, MacOSAll, uQuickLook, uMyDarwin, uShowMsg, uLng
|
||||
{$ENDIF}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue