summaryrefslogtreecommitdiffstats
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp74
1 files changed, 67 insertions, 7 deletions
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 <QtDebug>
#include <QSettings>
#include <QIcon>
+#include <QPainter>
+#include <QMap>
#include <iostream>
#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<int, QRect> screens;
+ for (int i = 0; i < QApplication::desktop()->screenCount(); ++i) {
+ QRect r = QApplication::desktop()->screenGeometry(i);
+ QMutableMapIterator<int, QRect>it(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<int, QRect> 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();
}
+