diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 4fb1f09..bcef2a3 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -43,6 +43,8 @@ add_library(qmltermwidget STATIC kptydevice.h kptyprocess.cpp kptyprocess.h + utils.cpp + utils.h ) target_include_directories(qmltermwidget PUBLIC diff --git a/src/lib/Session.cpp b/src/lib/Session.cpp index 49168b3..263d557 100644 --- a/src/lib/Session.cpp +++ b/src/lib/Session.cpp @@ -330,13 +330,40 @@ void Session::run() // the background color is deemed dark or not QString backgroundColorHint = _hasDarkBackground ? "COLORFGBG=15;0" : "COLORFGBG=0;15"; + QStringList environmentVars = _environment; + environmentVars.append(backgroundColorHint); + + // If we are running on Flatpak, we should have access to the host + if (isRunningOnFlatpak()) { + QStringList flatpakArgs; + flatpakArgs << QLatin1String("--host") << QLatin1String("--watch-bus"); + + for (const QString &envLine : environmentVars) + flatpakArgs << QStringLiteral("--env=%1").arg(envLine); + + QStringList whitelist; + whitelist + << QLatin1String("TERM") << QLatin1String("PATH") + << QLatin1String("EDITOR") << QLatin1String("PS1") + << QLatin1String("DISPLAY") << QLatin1String("WAYLAND_DISPLAY"); + for (const QString &envName : whitelist) { + const QString value = qEnvironmentVariable(qPrintable(envName)); + if (!value.isEmpty()) + flatpakArgs << QStringLiteral("--env=%1=%2").arg(envName).arg(value); + } + + flatpakArgs << exec; + exec = QLatin1String("/usr/bin/flatpak-spawn"); + arguments = flatpakArgs; + } + /* if we do all the checking if this shell exists then we use it ;) * Dont know about the arguments though.. maybe youll need some more checking im not sure * However this works on Arch and FreeBSD now. */ int result = _shellProcess->start(exec, arguments, - _environment << backgroundColorHint, + environmentVars, windowId(), _addToUtmp); diff --git a/src/lib/kpty.cpp b/src/lib/kpty.cpp index 0baa640..bd41904 100644 --- a/src/lib/kpty.cpp +++ b/src/lib/kpty.cpp @@ -145,6 +145,8 @@ extern "C" { //#include //#include // findExe +#include "utils.h" + // not defined on HP-UX for example #ifndef CTRL # define CTRL(x) ((x) & 037) @@ -474,13 +476,15 @@ void KPty::setCTty() // and get rid of the old controlling terminal. setsid(); - // make our slave pty the new controlling terminal. + if (!isRunningOnFlatpak()) { + // make our slave pty the new controlling terminal. #ifdef TIOCSCTTY - ioctl(d->slaveFd, TIOCSCTTY, 0); + ioctl(d->slaveFd, TIOCSCTTY, 0); #else - // __svr4__ hack: the first tty opened after setsid() becomes controlling tty - ::close(::open(d->ttyName, O_WRONLY, 0)); + // __svr4__ hack: the first tty opened after setsid() becomes controlling tty + ::close(::open(d->ttyName, O_WRONLY, 0)); #endif + } // make our new process group the foreground group on the pty int pgrp = getpid(); diff --git a/src/lib/utils.cpp b/src/lib/utils.cpp new file mode 100644 index 0000000..741549e --- /dev/null +++ b/src/lib/utils.cpp @@ -0,0 +1,31 @@ +/**************************************************************************** + * This file is part of Liri. + * + * Copyright (C) 2019 Pier Luigi Fiorini + * + * $BEGIN_LICENSE:LGPLv3+$ + * + * This program 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 Lesser General Public License + * along with this program. If not, see . + * + * $END_LICENSE$ + ***************************************************************************/ + +#include + +#include "utils.h" + +bool isRunningOnFlatpak() +{ + return QFile::exists(QLatin1String("/.flatpak-info")); +} diff --git a/src/lib/utils.h b/src/lib/utils.h new file mode 100644 index 0000000..a639f83 --- /dev/null +++ b/src/lib/utils.h @@ -0,0 +1,29 @@ +/**************************************************************************** + * This file is part of Liri. + * + * Copyright (C) 2019 Pier Luigi Fiorini + * + * $BEGIN_LICENSE:LGPLv3+$ + * + * This program 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 Lesser General Public License + * along with this program. If not, see . + * + * $END_LICENSE$ + ***************************************************************************/ + +#ifndef UTILS_H +#define UTILS_H + +bool isRunningOnFlatpak(); + +#endif // UTILS_H