Skip to content

Commit 469ea13

Browse files
Don't pass a display ID to X, let X figure out what ID to use
1 parent f104ac4 commit 469ea13

File tree

6 files changed

+22
-55
lines changed

6 files changed

+22
-55
lines changed

src/daemon/Display.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
#include <unistd.h>
4141

4242
namespace SDDM {
43-
Display::Display(const int displayId, const int terminalId, Seat *parent) : QObject(parent),
44-
m_displayId(displayId), m_terminalId(terminalId),
43+
Display::Display(const int terminalId, Seat *parent) : QObject(parent),
44+
m_terminalId(terminalId),
4545
m_auth(new Auth(this)),
4646
m_displayServer(new XorgDisplayServer(this)),
4747
m_seat(parent),
@@ -73,8 +73,8 @@ namespace SDDM {
7373
stop();
7474
}
7575

76-
const int Display::displayId() const {
77-
return m_displayId;
76+
QString Display::displayId() const {
77+
return m_displayServer->display();
7878
}
7979

8080
const int Display::terminalId() const {

src/daemon/Display.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ namespace SDDM {
3939
Q_OBJECT
4040
Q_DISABLE_COPY(Display)
4141
public:
42-
explicit Display(const int displayId, const int terminalId, Seat *parent);
42+
explicit Display(int terminalId, Seat *parent);
4343
~Display();
4444

45-
const int displayId() const;
45+
QString displayId() const;
4646
const int terminalId() const;
4747

4848
const QString &name() const;
@@ -71,7 +71,6 @@ namespace SDDM {
7171
bool m_relogin { true };
7272
bool m_started { false };
7373

74-
int m_displayId { 0 };
7574
int m_terminalId { 7 };
7675

7776
QString m_passPhrase;

src/daemon/Seat.cpp

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -51,36 +51,25 @@ namespace SDDM {
5151
return m_name;
5252
}
5353

54-
void Seat::createDisplay(int displayId, int terminalId) {
54+
void Seat::createDisplay(int terminalId) {
5555
//reload config if needed
5656
mainConfig.load();
5757

58-
if (displayId == -1) {
59-
// find unused display
60-
displayId = findUnused(0, [&](const int number) {
61-
bool alreadyExists = m_displayIds.contains(number);
62-
if (!alreadyExists)
63-
alreadyExists = XorgDisplayServer::displayExists(number);
64-
return alreadyExists;
65-
});
66-
67-
// find unused terminal
58+
if (terminalId == -1) {
59+
// find unused terminal
6860
terminalId = findUnused(mainConfig.XDisplay.MinimumVT.get(), [&](const int number) {
6961
return m_terminalIds.contains(number);
7062
});
7163
}
7264

73-
// mark display as used
74-
m_displayIds << displayId;
75-
7665
// mark terminal as used
7766
m_terminalIds << terminalId;
7867

7968
// log message
80-
qDebug() << "Adding new display" << displayId << "on vt" << terminalId << "...";
69+
qDebug() << "Adding new display" << "on vt" << terminalId << "...";
8170

8271
// create a new display
83-
Display *display = new Display(displayId, terminalId, this);
72+
Display *display = new Display(terminalId, this);
8473

8574
// restart display on stop
8675
connect(display, SIGNAL(stopped()), this, SLOT(displayStopped()));
@@ -92,26 +81,14 @@ namespace SDDM {
9281
display->start();
9382
}
9483

95-
void Seat::removeDisplay(int displayId) {
96-
qDebug() << "Removing display" << displayId << "...";
97-
98-
// display object
99-
Display *display = nullptr;
100-
101-
// find display
102-
for (Display *d: m_displays)
103-
if (d->displayId() == displayId)
104-
display = d;
84+
void Seat::removeDisplay(Display* display) {
85+
qDebug() << "Removing display" << display->displayId() << "...";
10586

106-
// check if found
107-
if (display == nullptr)
108-
return;
10987

11088
// remove display from list
11189
m_displays.removeAll(display);
11290

11391
// mark display and terminal ids as unused
114-
m_displayIds.removeAll(display->displayId());
11592
m_terminalIds.removeAll(display->terminalId());
11693

11794
// stop the display
@@ -127,7 +104,7 @@ namespace SDDM {
127104
Display *display = qobject_cast<Display *>(sender());
128105

129106
// remove display
130-
removeDisplay(display->displayId());
107+
removeDisplay(display);
131108

132109
// restart otherwise
133110
if (m_displays.isEmpty())

src/daemon/Seat.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ namespace SDDM {
3434
const QString &name() const;
3535

3636
public slots:
37-
void createDisplay(int displayId = -1, int terminalId = -1);
38-
void removeDisplay(int displayId);
37+
void createDisplay(int terminalId = -1);
38+
void removeDisplay(SDDM::Display* display);
3939

4040
private slots:
4141
void displayStopped();
@@ -45,7 +45,6 @@ namespace SDDM {
4545

4646
QList<Display *> m_displays;
4747
QList<int> m_terminalIds;
48-
QList<int> m_displayIds;
4948
};
5049
}
5150

src/daemon/XorgDisplayServer.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <QDebug>
2929
#include <QFile>
3030
#include <QProcess>
31+
#include <QUuid>
3132

3233
#include <xcb/xcb.h>
3334

@@ -36,9 +37,6 @@
3637

3738
namespace SDDM {
3839
XorgDisplayServer::XorgDisplayServer(Display *parent) : DisplayServer(parent) {
39-
// figure out the X11 display
40-
m_display = QString(":%1").arg(displayPtr()->displayId());
41-
4240
// get auth directory
4341
QString authDir = RUNTIME_DIR;
4442

@@ -50,7 +48,7 @@ namespace SDDM {
5048
QDir().mkpath(authDir);
5149

5250
// set auth path
53-
m_authPath = QString("%1/%2").arg(authDir).arg(m_display);
51+
m_authPath = QString("%1/%2").arg(authDir).arg(QUuid::createUuid().toString());
5452

5553
// generate cookie
5654
std::random_device rd;
@@ -70,10 +68,6 @@ namespace SDDM {
7068
stop();
7169
}
7270

73-
bool XorgDisplayServer::displayExists(int number) {
74-
return QFile(QString("/tmp/.X%1-lock").arg(number)).exists();
75-
}
76-
7771
const QString &XorgDisplayServer::display() const {
7872
return m_display;
7973
}
@@ -151,7 +145,6 @@ namespace SDDM {
151145
} else {
152146
// set process environment
153147
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
154-
env.insert("XAUTHORITY", m_authPath);
155148
env.insert("XCURSOR_THEME", mainConfig.Theme.CursorTheme.get());
156149
process->setProcessEnvironment(env);
157150

@@ -164,8 +157,7 @@ namespace SDDM {
164157

165158
// start display server
166159
QStringList args;
167-
args << m_display
168-
<< "-auth" << m_authPath
160+
args << "-auth" << m_authPath
169161
<< "-nolisten" << "tcp"
170162
<< "-background" << "none"
171163
<< "-noreset"
@@ -195,7 +187,9 @@ namespace SDDM {
195187
return false;
196188
}
197189
QByteArray displayNumber = readPipe.readLine();
198-
190+
displayNumber.prepend(QByteArray(":"));
191+
displayNumber.remove(displayNumber.size() -1, 1); //trim trailing whitespace
192+
m_display= displayNumber;
199193

200194
// close our pipe
201195
close(pipeFds[0]);

src/daemon/XorgDisplayServer.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ namespace SDDM {
3333
explicit XorgDisplayServer(Display *parent);
3434
~XorgDisplayServer();
3535

36-
static bool displayExists(int number);
37-
3836
const QString &display() const;
3937
const QString &authPath() const;
4038

0 commit comments

Comments
 (0)