#include <QX11Info>
#include <QDebug>
-#include <QHBoxLayout>
+#include <QVBoxLayout>
#include <QLabel>
#include <X11/Xlib.h>
#include <X11/extensions/XInput2.h>
#include <X11/Xutil.h>
+static QString colorToString(QColor col)
+{
+ return QString("#%1%2%3").arg(col.red(), 2, 16, QChar('0'))
+ .arg(col.green(), 2, 16, QChar('0'))
+ .arg(col.blue(), 2, 16, QChar('0'));
+}
+
MultypoWindow::MultypoWindow(QWidget *parent) :
QWidget(parent),
xiInited(false)
{
- QHBoxLayout *layout = new QHBoxLayout(this);
- setLayout(layout);
+ /* Prepare colors */
+ setStyleSheet("background-color: black; color: green; font-size: 30pt");
+
+ /* Prepare conents */
+ setLayout(new QVBoxLayout(this));
- mainLabel = new QLabel(this);
- layout->addWidget(mainLabel);
+ mainLabel = new QLabel("Hit <Esc> to quit", this);
+ layout()->addWidget(mainLabel);
- setMinimumSize(300, 300);
+ /* Fullscreen, no cursor */
+ setWindowState(Qt::WindowFullScreen);
+ setCursor(QCursor(Qt::BlankCursor));
}
MultypoWindow::~MultypoWindow()
void MultypoWindow::handleKeyPress(int device, QString string)
{
qDebug() << "Device" << device << "String" << string;
- mainLabel->setText(QString("%1 pressed on %2").arg(string).arg(device));
+
+ if (string == "Escape")
+ close();
+
+ if (!players.contains(device)) {
+ QLabel *label = new QLabel(this);
+ layout()->addWidget(label);
+ players[device] = label;
+ }
+ QColor textColor = QColor(Qt::blue);
+ players[device]->setText(players[device]->text() + "<span style='color:"+colorToString(textColor)+"'>"+string+"</span>");
}
bool MultypoWindow::handleX11Event(XEvent *event)
qDebug() << "Found master keyboard with ID" << devices[i].deviceid;
XISetFocus(dpy, devices[i].deviceid, winId(), CurrentTime);
}
+ XIFreeDeviceInfo(devices);
xiInited = true;