From e128a1b4ea74f02bc4a9047ea0e95e7563e6d3ac Mon Sep 17 00:00:00 2001 From: Martin Briza Date: Wed, 2 Nov 2016 17:13:40 +0100 Subject: [PATCH] Switch to another managed VT when the current one quits --- src/daemon/Seat.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/daemon/Seat.cpp b/src/daemon/Seat.cpp index 3ef1b2f..966d445 100644 --- a/src/daemon/Seat.cpp +++ b/src/daemon/Seat.cpp @@ -30,6 +30,12 @@ #include +#include +#include +#include +#include +#include + namespace SDDM { int findUnused(int minimum, std::function used) { // initialize with minimum @@ -84,7 +90,6 @@ namespace SDDM { void Seat::removeDisplay(Display* display) { qDebug() << "Removing display" << display->displayId() << "..."; - // remove display from list m_displays.removeAll(display); @@ -102,12 +107,30 @@ namespace SDDM { void Seat::displayStopped() { Display *display = qobject_cast(sender()); + int oldVT = display->terminalId(); // remove display removeDisplay(display); + // try switching to some other active VT + bool success = false; + char path[33] = { 0 }; + snprintf(path, 32, "/dev/tty%d", oldVT); + int ttyfd = open(path, O_RDONLY); + + if (ttyfd >= 0) { + for (int newVT : m_terminalIds) { + int result = ioctl(ttyfd, VT_ACTIVATE, newVT); + if (result == 0) { + success = true; + break; + } + } + close(ttyfd); + } + // restart otherwise - if (m_displays.isEmpty()) + if (!success) createDisplay(); } }