Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that Xwayland exists before enabling it #9077

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ void CCompositor::initManagers(eManagersInitStage stage) {
g_pDonationNagManager = std::make_unique<CDonationNagManager>();

Debug::log(LOG, "Starting XWayland");
g_pXWayland = std::make_unique<CXWayland>(g_pCompositor->m_bEnableXwayland);
g_pXWayland = std::make_unique<CXWayland>(g_pCompositor->m_bWantsXwayland);
} break;
default: UNREACHABLE();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Compositor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class CCompositor {
bool m_bIsShuttingDown = false;
bool m_bFinalRequests = false;
bool m_bDesktopEnvSet = false;
bool m_bEnableXwayland = true;
bool m_bWantsXwayland = true;

// ------------------------------------------------- //

Expand Down
22 changes: 6 additions & 16 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,26 +947,16 @@ void CConfigManager::postConfigReload(const Hyprlang::CParseResult& result) {
}

#ifndef NO_XWAYLAND
const auto PENABLEXWAYLAND = std::any_cast<Hyprlang::INT>(m_pConfig->getConfigValue("xwayland:enabled"));
const auto PENABLEXWAYLAND = std::any_cast<Hyprlang::INT>(m_pConfig->getConfigValue("xwayland:enabled"));
g_pCompositor->m_bWantsXwayland = PENABLEXWAYLAND;
// enable/disable xwayland usage
if (!isFirstLaunch) {
bool prevEnabledXwayland = g_pCompositor->m_bEnableXwayland;
if (PENABLEXWAYLAND != prevEnabledXwayland) {
g_pCompositor->m_bEnableXwayland = PENABLEXWAYLAND;
if (PENABLEXWAYLAND) {
Debug::log(LOG, "xwayland has been enabled");
} else {
Debug::log(LOG, "xwayland has been disabled, cleaning up...");
for (auto& w : g_pCompositor->m_vWindows) {
if (w->m_pXDGSurface || !w->m_bIsX11)
continue;
g_pCompositor->closeWindow(w);
}
}
g_pXWayland = std::make_unique<CXWayland>(g_pCompositor->m_bEnableXwayland);
bool prevEnabledXwayland = g_pXWayland->enabled();
if (g_pCompositor->m_bWantsXwayland != prevEnabledXwayland) {
g_pXWayland = std::make_unique<CXWayland>(g_pCompositor->m_bWantsXwayland);
}
} else
g_pCompositor->m_bEnableXwayland = PENABLEXWAYLAND;
g_pCompositor->m_bWantsXwayland = PENABLEXWAYLAND;
#endif

if (!isFirstLaunch && !g_pCompositor->m_bUnsafeState)
Expand Down
34 changes: 28 additions & 6 deletions src/xwayland/XWayland.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
#include "XWayland.hpp"
#include "../Compositor.hpp"
#include "../debug/Log.hpp"
#include "../helpers/fs/FsUtils.hpp"

CXWayland::CXWayland(const bool enabled) {
CXWayland::CXWayland(const bool wantsEnabled) {
m_enabled = false;
#ifndef NO_XWAYLAND
Debug::log(LOG, "Starting up the XWayland server");

pServer = std::make_unique<CXWaylandServer>();

if (!enabled) {
// Disable Xwayland and clean up if the user disabled it.
if (!wantsEnabled) {
Debug::log(LOG, "XWayland has been disabled, cleaning up...");
for (auto& w : g_pCompositor->m_vWindows) {
if (!w->m_bIsX11)
continue;
g_pCompositor->closeWindow(w);
}
unsetenv("DISPLAY");
return;
}

if (!NFsUtils::executableExistsInPath("Xwayland")) {
earboxer marked this conversation as resolved.
Show resolved Hide resolved
// If Xwayland doesn't exist, don't try to start it.
Debug::log(LOG, "Unable to find XWayland; not starting it.");
return;
}

Debug::log(LOG, "Starting up the XWayland server");
earboxer marked this conversation as resolved.
Show resolved Hide resolved

pServer = std::make_unique<CXWaylandServer>();

if (!pServer->create()) {
Debug::log(ERR, "XWayland failed to start: it will not work.");
return;
}

m_enabled = true;
#else
Debug::log(LOG, "Not starting XWayland: disabled at compile time");
#endif
Expand All @@ -31,3 +49,7 @@ void CXWayland::setCursor(unsigned char* pixData, uint32_t stride, const Vector2
pWM->setCursor(pixData, stride, size, hotspot);
#endif
}

bool CXWayland::enabled() {
return m_enabled;
}
6 changes: 5 additions & 1 deletion src/xwayland/XWayland.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@ class CXWM;

class CXWayland {
public:
CXWayland(const bool enabled);
CXWayland(const bool wantsEnabled);

#ifndef NO_XWAYLAND
std::unique_ptr<CXWaylandServer> pServer;
std::unique_ptr<CXWM> pWM;
#endif
bool enabled();

void setCursor(unsigned char* pixData, uint32_t stride, const Vector2D& size, const Vector2D& hotspot);

struct {
CSignal newSurface;
} events;

private:
bool m_enabled;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still not initializeddd

};

inline std::unique_ptr<CXWayland> g_pXWayland;
Expand Down
Loading