[kwin_wrapper] pass the wayland socket name via arguments rather than the env
The initial goal of kwin_wrapper was that it would set up all relevant environment variables that will be used by the clients of kwin. This meant having to cache old variables before we overrode them and pass additional settings to the backends for the old wayland_display. It works, but with X11 about to move too ends up being unnecessarily complex. In hindsight it's easier for kwin to have the environment represent the platform it is currently on, and have kwin explicitly set variables in the QProcessEnvironment of the session it forks itnto. This patch is changed so that we set the wayland socket name used by the wrapper explicitly which is then used by the process environment kwin uses for the main session.
This commit is contained in:
parent
9962a9fe59
commit
9692b49219
2 changed files with 10 additions and 32 deletions
|
@ -8,8 +8,8 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* This tiny executable creates a socket, then starts kwin passing it the FD to the wayland socket.
|
||||
* The WAYLAND_DISPLAY environment variable gets set here and passed to all spawned kwin instances.
|
||||
* This tiny executable creates a socket, then starts kwin passing it the FD to the wayland socket
|
||||
* along with the name of the socket to use
|
||||
* On any non-zero kwin exit kwin gets restarted.
|
||||
*
|
||||
* After restart kwin is relaunched but now with the KWIN_RESTART_COUNT env set to an incrementing counter
|
||||
|
@ -26,8 +26,6 @@
|
|||
|
||||
#include "wl-socket.h"
|
||||
|
||||
#define WAYLAND_ENV_NAME "WAYLAND_DISPLAY"
|
||||
|
||||
class KWinWrapper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -39,7 +37,6 @@ public:
|
|||
|
||||
private:
|
||||
wl_socket *m_socket;
|
||||
QString m_oldWaylandEnv;
|
||||
};
|
||||
|
||||
KWinWrapper::KWinWrapper(QObject *parent)
|
||||
|
@ -49,13 +46,6 @@ KWinWrapper::KWinWrapper(QObject *parent)
|
|||
if (!m_socket) {
|
||||
qFatal("Could not create wayland socket");
|
||||
}
|
||||
|
||||
// copy the old WAYLAND_DISPLAY as we are about to overwrite it and kwin may need it
|
||||
if (qEnvironmentVariableIsSet(WAYLAND_ENV_NAME)) {
|
||||
m_oldWaylandEnv = qgetenv(WAYLAND_ENV_NAME);
|
||||
}
|
||||
|
||||
qputenv(WAYLAND_ENV_NAME, wl_socket_get_display_name(m_socket));
|
||||
}
|
||||
|
||||
KWinWrapper::~KWinWrapper()
|
||||
|
@ -96,10 +86,8 @@ int KWinWrapper::runKwin()
|
|||
|
||||
QStringList args;
|
||||
args << "--wayland_fd" << QString::number(wl_socket_get_fd(m_socket));
|
||||
args << "--socket" << QString::fromUtf8(wl_socket_get_display_name(m_socket));
|
||||
|
||||
if (!m_oldWaylandEnv.isEmpty()) {
|
||||
args << "--wayland-display" << m_oldWaylandEnv;
|
||||
}
|
||||
// attach our main process arguments
|
||||
// the first entry is dropped as it will be our program name
|
||||
args << qApp->arguments().mid(1);
|
||||
|
|
|
@ -294,19 +294,9 @@ static const QString s_fbdevPlugin = QStringLiteral("KWinWaylandFbdevBackend");
|
|||
static const QString s_drmPlugin = QStringLiteral("KWinWaylandDrmBackend");
|
||||
static const QString s_virtualPlugin = QStringLiteral("KWinWaylandVirtualBackend");
|
||||
|
||||
|
||||
enum SpawnMode {
|
||||
Standalone,
|
||||
ReusedSocket
|
||||
};
|
||||
|
||||
static QString automaticBackendSelection(SpawnMode spawnMode)
|
||||
static QString automaticBackendSelection()
|
||||
{
|
||||
/* WAYLAND_DISPLAY is set by the kwin_wayland_wrapper, so we can't use it for automatic detection.
|
||||
* If kwin_wayland_wrapper is used nested on wayland, we won't be in this path as
|
||||
* it explicitly sets '--socket' which means a backend is set and we won't be in this path anyway
|
||||
*/
|
||||
if (qEnvironmentVariableIsSet("WAYLAND_DISPLAY") && spawnMode == Standalone) {
|
||||
if (qEnvironmentVariableIsSet("WAYLAND_DISPLAY")) {
|
||||
return s_waylandPlugin;
|
||||
}
|
||||
if (qEnvironmentVariableIsSet("DISPLAY")) {
|
||||
|
@ -476,7 +466,7 @@ int main(int argc, char * argv[])
|
|||
outputCountOption.setDefaultValue(QString::number(1));
|
||||
|
||||
QCommandLineOption waylandSocketFdOption(QStringLiteral("wayland_fd"),
|
||||
i18n("Wayland socket to use for incoming connections."),
|
||||
i18n("Wayland socket to use for incoming connections. This can be combined with --socket to name the socket"),
|
||||
QStringLiteral("wayland_fd"));
|
||||
|
||||
QCommandLineOption replaceOption(QStringLiteral("replace"),
|
||||
|
@ -640,7 +630,7 @@ int main(int argc, char * argv[])
|
|||
|
||||
if (pluginName.isEmpty()) {
|
||||
std::cerr << "No backend specified through command line argument, trying auto resolution" << std::endl;
|
||||
pluginName = KWin::automaticBackendSelection(parser.isSet(waylandSocketFdOption) ? KWin::ReusedSocket : KWin::Standalone);
|
||||
pluginName = KWin::automaticBackendSelection();
|
||||
}
|
||||
|
||||
auto pluginIt = std::find_if(availablePlugins.begin(), availablePlugins.end(),
|
||||
|
@ -667,20 +657,20 @@ int main(int argc, char * argv[])
|
|||
}
|
||||
|
||||
|
||||
const QString socketName = parser.value(waylandSocketOption);
|
||||
if (parser.isSet(waylandSocketFdOption)) {
|
||||
bool ok;
|
||||
int fd = parser.value(waylandSocketFdOption).toInt(&ok);
|
||||
if (ok ) {
|
||||
// make sure we don't leak this FD to children
|
||||
fcntl(fd, F_SETFD, O_CLOEXEC);
|
||||
server->display()->addSocketFileDescriptor(fd);
|
||||
server->display()->addSocketFileDescriptor(fd, socketName);
|
||||
} else {
|
||||
std::cerr << "FATAL ERROR: could not parse socket FD" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
const QString socketName = parser.value(waylandSocketOption);
|
||||
// being empty is fine here, addSocketName will automatically pick one
|
||||
// socketName empty is fine here, addSocketName will automatically pick one
|
||||
if (!server->display()->addSocketName(socketName)) {
|
||||
std::cerr << "FATAL ERROR: could not add wayland socket " << qPrintable(socketName) << std::endl;
|
||||
return 1;
|
||||
|
|
Loading…
Reference in a new issue