From 726bf58428f937b9ef40684f2a5f38c590ce738b Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 15 Aug 2017 19:17:40 +0200 Subject: Handle multiscreen properly, make background persistent --- src/main.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 67 insertions(+), 7 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index c0ce7bc..50a8d38 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,18 +11,23 @@ #include #include #include +#include +#include #include #include "settings.h" #include "mainwindow.h" +#include "x11util.h" -QFile logfile; -QTextStream ts; +static void messageHandler(QtMsgType type, const QMessageLogContext&, const QString& msg) +{ + std::cerr << type << ": " << msg.toUtf8().constData() << '\n'; +} -void messageHandler(QtMsgType type, const QMessageLogContext&, const QString& msg) +static inline int size(const QRect& r) { - std::cerr << type << ": " << msg.toLatin1().data() << "\n"; + return r.width() * r.height(); } int main(int argc, char *argv[]) @@ -38,12 +43,66 @@ int main(int argc, char *argv[]) QIcon::setThemeName(Settings().iconThemeName()); } + // Build background for X server, in case we start a session that + // doesn't set one on its own this will make sure it's not simply + // black + QImage entire; + QSize desktopSize = QApplication::desktop()->size(); + qDebug() << "Desktop full size is " << desktopSize; + entire = QImage(desktopSize, QImage::Format_RGB32); + QPainter painter(&entire); + + // Get a list of non-overlapping screens, as this might lead to a broken + // greeter with main windows covering other login forms + QMap screens; + for (int i = 0; i < QApplication::desktop()->screenCount(); ++i) { + QRect r = QApplication::desktop()->screenGeometry(i); + QMutableMapIteratorit(screens); + while (it.hasNext()) { + it.next(); + if (!it.value().intersects(r)) + continue; + // Overlap, bigger wins + if (size(it.value()) >= size(r)) { + // Existing is bigger + goto skip_rect; + } + // New is bigger, remove existing and keep going + it.remove(); + } + // We reached here, so add new window + screens.insert(i, r); + skip_rect: ; // Do nothing + } + // Determine primary screen + int primary; + if (screens.contains(QApplication::desktop()->primaryScreen())) { + // Primary screen still in selection + primary = QApplication::desktop()->primaryScreen(); + } else { + // Fallback to first one + primary = screens.begin().key(); + } + + // Now set up all the screens MainWindow *focusWindow = 0; - for (int i = 0; i < QApplication::desktop()->screenCount(); ++i) { - MainWindow *w = new MainWindow(i); + QMapIterator it(screens); + while (it.hasNext()) { + it.next(); + MainWindow *w = new MainWindow(primary == it.key(), it.key(), it.value()); w->show(); - if (w->showLoginForm()) + if (w->showLoginForm()) { focusWindow = w; + } + if (!entire.isNull()) { + QPoint p = it.value().topLeft(); + painter.drawImage(p, w->getBackground()); + } + } + + if (!entire.isNull()) { + qDebug() << "Setting x background"; + AddPixmapToBackground(entire.constBits(), entire.width(), entire.height(), 24, entire.bytesPerLine(), entire.byteCount()); } // Ensure we set the primary screen's widget as active when there @@ -55,3 +114,4 @@ int main(int argc, char *argv[]) return a.exec(); } + -- cgit v1.2.3-55-g7522