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

config: add option to enable/disable xwayland #7633

Merged
merged 9 commits into from
Sep 5, 2024
2 changes: 1 addition & 1 deletion src/Compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ void CCompositor::initManagers(eManagersInitStage stage) {
g_pCursorManager = std::make_unique<CCursorManager>();

Debug::log(LOG, "Starting XWayland");
g_pXWayland = std::make_unique<CXWayland>();
g_pXWayland = std::make_unique<CXWayland>(g_pCompositor->m_bEnableXwayland);
} break;
default: UNREACHABLE();
}
Expand Down
1 change: 1 addition & 0 deletions src/Compositor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class CCompositor {
CMonitor* m_pUnsafeOutput = nullptr; // fallback output for the unsafe state
bool m_bIsShuttingDown = false;
bool m_bDesktopEnvSet = false;
bool m_bEnableXwayland = true;

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

Expand Down
6 changes: 6 additions & 0 deletions src/config/ConfigDescriptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,12 @@ inline static const std::vector<SConfigOptionDescription> CONFIG_OPTIONS = {
* xwayland:
*/

SConfigOptionDescription{
.value = "xwayland:enabled",
.description = "allow running applications using X11",
.type = CONFIG_OPTION_BOOL,
.data = SConfigOptionDescription::SBoolData{true},
},
SConfigOptionDescription{
.value = "xwayland:use_nearest_neighbor",
.description = "uses the nearest neighbor filtering for xwayland apps, making them pixelated rather than blurry",
Expand Down
25 changes: 25 additions & 0 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "config/ConfigValue.hpp"
#include "helpers/varlist/VarList.hpp"
#include "../protocols/LayerShell.hpp"
#include "../xwayland/XWayland.hpp"

#include <cstddef>
#include <cstdint>
Expand Down Expand Up @@ -523,6 +524,7 @@ CConfigManager::CConfigManager() {
m_pConfig->addConfigValue("gestures:workspace_swipe_touch", Hyprlang::INT{0});
m_pConfig->addConfigValue("gestures:workspace_swipe_touch_invert", Hyprlang::INT{0});

m_pConfig->addConfigValue("xwayland:enabled", Hyprlang::INT{1});
m_pConfig->addConfigValue("xwayland:use_nearest_neighbor", Hyprlang::INT{1});
m_pConfig->addConfigValue("xwayland:force_zero_scaling", Hyprlang::INT{0});

Expand Down Expand Up @@ -860,6 +862,29 @@ void CConfigManager::postConfigReload(const Hyprlang::CParseResult& result) {
ensureVRR();
}

#ifndef NO_XWAYLAND
const auto PENABLEXWAYLAND = std::any_cast<Hyprlang::INT>(m_pConfig->getConfigValue("xwayland:enabled"));
// 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);
}
} else
g_pCompositor->m_bEnableXwayland = PENABLEXWAYLAND;
#endif

if (!isFirstLaunch && !g_pCompositor->m_bUnsafeState)
refreshGroupBarGradients();

Expand Down
3 changes: 2 additions & 1 deletion src/xwayland/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,8 @@ int CXWaylandServer::ready(int fd, uint32_t mask) {
pipeSource = nullptr;

// start the wm
g_pXWayland->pWM = std::make_unique<CXWM>();
if (!g_pXWayland->pWM)
g_pXWayland->pWM = std::make_unique<CXWM>();

g_pCursorManager->setXWaylandCursor();

Expand Down
3 changes: 3 additions & 0 deletions src/xwayland/XWM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,9 @@ CXWM::~CXWM() {

if (eventSource)
wl_event_source_remove(eventSource);

for (auto const& sr : surfaces)
Trimutex marked this conversation as resolved.
Show resolved Hide resolved
sr->events.destroy.emit();
}

void CXWM::setActiveWindow(xcb_window_t window) {
Expand Down
9 changes: 7 additions & 2 deletions src/xwayland/XWayland.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
#include "XWayland.hpp"
#include "../debug/Log.hpp"

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

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

if (!enabled) {
unsetenv("DISPLAY");
return;
}

if (!pServer->create()) {
Debug::log(ERR, "XWayland failed to start: it will not work.");
return;
Expand All @@ -25,4 +30,4 @@ void CXWayland::setCursor(unsigned char* pixData, uint32_t stride, const Vector2

pWM->setCursor(pixData, stride, size, hotspot);
#endif
}
}
4 changes: 2 additions & 2 deletions src/xwayland/XWayland.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CXWM;

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

#ifndef NO_XWAYLAND
std::unique_ptr<CXWaylandServer> pServer;
Expand Down Expand Up @@ -126,4 +126,4 @@ inline std::unordered_map<std::string, uint32_t> HYPRATOMS = {
HYPRATOM("DELETE"),
HYPRATOM("TEXT"),
HYPRATOM("INCR"),
};
};
Loading