diff --git a/src/daemon/TreelandConnector.cpp b/src/daemon/TreelandConnector.cpp index 0c9daee..c840b6b 100644 --- a/src/daemon/TreelandConnector.cpp +++ b/src/daemon/TreelandConnector.cpp @@ -35,19 +35,25 @@ static void onAcquireDisplay() { auto user = daemonApp->displayManager()->findUserByVt(vtnr); if (!user.isEmpty()) { qDebug("Activate session at VT %d for user %s", vtnr, qPrintable(user)); - daemonApp->treelandConnector()->switchToUser(user); daemonApp->treelandConnector()->activateSession(); + daemonApp->treelandConnector()->enableRender(); + daemonApp->treelandConnector()->switchToUser(user); } } static void onReleaseDisplay() { + // TODO: Wayland request is asynchronous, which may leads a late execution, + // makes treeland still possible to draw on DRM after VT switching. + daemonApp->treelandConnector()->disableRender(); + int fd = open(defaultVtPath, O_RDWR | O_NOCTTY); ioctl(fd, VT_RELDISP, 1); close(fd); + int activeVtFd = open(defaultVtPath, O_RDWR | O_NOCTTY); int activeVt = VirtualTerminal::getVtActive(activeVtFd); auto user = daemonApp->displayManager()->findUserByVt(activeVt); - qDebug("Next VT: %d, user: %s", activeVt, qPrintable(user)); + qDebug("Next VT: %d, user: %s", activeVt, user.isEmpty() ? "None" : qPrintable(user)); if (user.isEmpty()) { // We must switch Treeland to greeter mode before we switch back to it, // or it will get stuck. @@ -58,6 +64,7 @@ static void onReleaseDisplay() { // ddm-helper. It uses VT signals from VirtualTerminal.h, // which is not what we want, so we should acquire VT control here. VirtualTerminal::handleVtSwitches(activeVtFd); + daemonApp->treelandConnector()->enableRender(); } close(activeVtFd); } @@ -184,4 +191,22 @@ void TreelandConnector::deactivateSession() { } } +void TreelandConnector::enableRender() { + if (isConnected()) { + treeland_ddm_enable_render(m_ddm); + wl_display_flush(m_display); + } else { + qWarning("Treeland is not connected when trying to call enableRender"); + } +} + +void TreelandConnector::disableRender() { + if (isConnected()) { + treeland_ddm_disable_render(m_ddm); + wl_display_flush(m_display); + } else { + qWarning("Treeland is not connected when trying to call disableRender"); + } +} + } diff --git a/src/daemon/TreelandConnector.h b/src/daemon/TreelandConnector.h index c2b8fd9..9c4db91 100644 --- a/src/daemon/TreelandConnector.h +++ b/src/daemon/TreelandConnector.h @@ -21,6 +21,8 @@ class TreelandConnector : QObject { void switchToUser(const QString username); void activateSession(); void deactivateSession(); + void enableRender(); + void disableRender(); private: struct wl_display *m_display { nullptr }; QSocketNotifier *m_notifier { nullptr };