Skip to content

Commit 0644dce

Browse files
committed
List Wayland sessions on the greeter
Recognize Wayland sessions and show them from the greeter. We are not capable of running those sessions yet, but it's a start. Also, add wayland-session a wrapper script to run a Wayland user session much like Xsession. Issue: #419
1 parent 08ba219 commit 0644dce

File tree

8 files changed

+143
-51
lines changed

8 files changed

+143
-51
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ set(DBUS_CONFIG_DIR "${CMAKE_INSTALL_SYSCONFDIR}/dbus-1/system.d"
137137
set(STATE_DIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/sddm" CACHE PATH "State directory")
138138
set(RUNTIME_DIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/run/sddm" CACHE PATH "Runtime data storage directory")
139139

140-
set(SESSION_COMMAND "${DATA_INSTALL_DIR}/scripts/Xsession" CACHE PATH "Script to execute when starting the desktop session")
140+
set(SESSION_COMMAND "${DATA_INSTALL_DIR}/scripts/Xsession" CACHE PATH "Script to execute when starting the X11 desktop session")
141+
set(WAYLAND_SESSION_COMMAND "${DATA_INSTALL_DIR}/scripts/wayland-session" CACHE PATH "Script to execute when starting the Wayland desktop session")
141142

142143
set(CONFIG_FILE "${CMAKE_INSTALL_FULL_SYSCONFDIR}/sddm.conf" CACHE PATH "Path of the sddm config file")
143144
set(LOG_FILE "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/sddm.log" CACHE PATH "Path of the sddm log file")

data/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ install(FILES
1111
"scripts/Xsession"
1212
"scripts/Xsetup"
1313
"scripts/Xstop"
14+
"scripts/wayland-session"
1415
DESTINATION "${DATA_INSTALL_DIR}/scripts"
1516
PERMISSIONS
1617
OWNER_READ OWNER_WRITE OWNER_EXECUTE

data/man/sddm.conf.rst.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ OPTIONS
9696
increase as new displays added.
9797
Default value is @MINIMUM_VT@.
9898

99+
[WaylandDisplay] section:
100+
101+
`SessionDir=`
102+
Path of the directory containing session files.
103+
Default value is "/usr/share/wayland-sessions".
104+
105+
`SessionCommand=`
106+
Path of script to execute when starting the desktop session.
107+
Default value is "@WAYLAND_SESSION_COMMAND@".
108+
99109
[Users] section:
100110

101111
`DefaultPath=`

data/scripts/wayland-session

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/sh
2+
# wayland-session - run as user
3+
# Copyright (C) 2015 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
4+
5+
# This file is extracted from kde-workspace (kdm/kfrontend/genkdmconf.c)
6+
# Copyright (C) 2001-2005 Oswald Buddenhagen <ossi@kde.org>
7+
8+
session=$1
9+
10+
# Note that the respective logout scripts are not sourced.
11+
case $SHELL in
12+
*/bash)
13+
[ -z "$BASH" ] && exec $SHELL $0 "$@"
14+
set +o posix
15+
[ -f /etc/profile ] && . /etc/profile
16+
if [ -f $HOME/.bash_profile ]; then
17+
. $HOME/.bash_profile
18+
elif [ -f $HOME/.bash_login ]; then
19+
. $HOME/.bash_login
20+
elif [ -f $HOME/.profile ]; then
21+
. $HOME/.profile
22+
fi
23+
;;
24+
*/zsh)
25+
[ -z "$ZSH_NAME" ] && exec $SHELL $0 "$@"
26+
[ -d /etc/zsh ] && zdir=/etc/zsh || zdir=/etc
27+
zhome=${ZDOTDIR:-$HOME}
28+
# zshenv is always sourced automatically.
29+
[ -f $zdir/zprofile ] && . $zdir/zprofile
30+
[ -f $zhome/.zprofile ] && . $zhome/.zprofile
31+
[ -f $zdir/zlogin ] && . $zdir/zlogin
32+
[ -f $zhome/.zlogin ] && . $zhome/.zlogin
33+
emulate -R sh
34+
;;
35+
*/csh|*/tcsh)
36+
# [t]cshrc is always sourced automatically.
37+
# Note that sourcing csh.login after .cshrc is non-standard.
38+
wlsess_tmp=`mktemp /tmp/wlsess-env-XXXXXX`
39+
$SHELL -c "if (-f /etc/csh.login) source /etc/csh.login; if (-f ~/.login) source ~/.login; /bin/sh -c 'export -p' >! $wlsess_tmp"
40+
. $wlsess_tmp
41+
rm -f $wlsess_tmp
42+
;;
43+
*) # Plain sh, ksh, and anything we do not know.
44+
[ -f /etc/profile ] && . /etc/profile
45+
[ -f $HOME/.profile ] && . $HOME/.profile
46+
;;
47+
esac
48+
49+
eval exec "$session"

src/common/Configuration.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ namespace SDDM {
6666
Entry(MinimumVT, int, MINIMUM_VT, _S("Minimum VT\n"
6767
"The lowest virtual terminal number that will be used."));
6868
);
69+
Section(WaylandDisplay,
70+
Entry(SessionDir, QString, _S("/usr/share/wayland-sessions"), _S("Session description directory"));
71+
Entry(SessionCommand, QString, _S(WAYLAND_SESSION_COMMAND), _S("Wayland session script path\n"
72+
"A script to execute when starting the desktop session"));
73+
);
6974
Section(Users,
7075
Entry(DefaultPath, QString, _S("/bin:/usr/bin:/usr/local/bin"), _S("Default $PATH"));
7176
Entry(MinimumUid, int, 1000, _S("Minimum user id for displayed users"));

src/common/Constants.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#define STATE_DIR "@STATE_DIR@"
3131

3232
#define SESSION_COMMAND "@SESSION_COMMAND@"
33+
#define WAYLAND_SESSION_COMMAND "@WAYLAND_SESSION_COMMAND@"
3334

3435
#define CONFIG_FILE "@CONFIG_FILE@"
3536
#define LOG_FILE "@LOG_FILE@"

src/greeter/SessionModel.cpp

Lines changed: 65 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/***************************************************************************
2+
* Copyright (c) 2015 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
23
* Copyright (c) 2013 Abdurrahman AVCI <abdurrahmanavci@gmail.com>
34
*
45
* This program is free software; you can redistribute it and/or modify
@@ -32,6 +33,8 @@
3233
namespace SDDM {
3334
class Session {
3435
public:
36+
SessionModel::SessionType type;
37+
QString directory;
3538
QString file;
3639
QString name;
3740
QString exec;
@@ -47,22 +50,78 @@ namespace SDDM {
4750
};
4851

4952
SessionModel::SessionModel(QObject *parent) : QAbstractListModel(parent), d(new SessionModelPrivate()) {
53+
populate(SessionModel::X11Session, mainConfig.XDisplay.SessionDir.get());
54+
populate(SessionModel::WaylandSession, mainConfig.WaylandDisplay.SessionDir.get());
55+
}
56+
57+
SessionModel::~SessionModel() {
58+
delete d;
59+
}
60+
61+
QHash<int, QByteArray> SessionModel::roleNames() const {
62+
// set role names
63+
QHash<int, QByteArray> roleNames;
64+
roleNames[DirectoryRole] = "directory";
65+
roleNames[FileRole] = "file";
66+
roleNames[NameRole] = "name";
67+
roleNames[ExecRole] = "exec";
68+
roleNames[CommentRole] = "comment";
69+
70+
return roleNames;
71+
}
72+
73+
const int SessionModel::lastIndex() const {
74+
return d->lastIndex;
75+
}
76+
77+
int SessionModel::rowCount(const QModelIndex &parent) const {
78+
return d->sessions.length();
79+
}
80+
81+
QVariant SessionModel::data(const QModelIndex &index, int role) const {
82+
if (index.row() < 0 || index.row() >= d->sessions.count())
83+
return QVariant();
84+
85+
// get session
86+
SessionPtr session = d->sessions[index.row()];
87+
88+
// return correct value
89+
if (role == DirectoryRole)
90+
return session->directory;
91+
if (role == FileRole)
92+
return session->file;
93+
else if (role == NameRole)
94+
return session->name;
95+
else if (role == ExecRole)
96+
return session->exec;
97+
else if (role == CommentRole)
98+
return session->comment;
99+
100+
// return empty value
101+
return QVariant();
102+
}
103+
104+
void SessionModel::populate(SessionModel::SessionType type, const QString &path) {
50105
// read session files
51-
QDir dir(mainConfig.XDisplay.SessionDir.get());
106+
QDir dir(path);
52107
dir.setNameFilters(QStringList() << "*.desktop");
53108
dir.setFilter(QDir::Files);
54109
// read session
55110
foreach(const QString &session, dir.entryList()) {
56111
QFile inputFile(dir.absoluteFilePath(session));
57112
if (!inputFile.open(QIODevice::ReadOnly))
58113
continue;
59-
SessionPtr si { new Session { session, "", "", "" } };
114+
SessionPtr si { new Session { type, path, session, "", "", "" } };
60115
QTextStream in(&inputFile);
61116
bool execAllowed = true;
62117
while (!in.atEnd()) {
63118
QString line = in.readLine();
64-
if (line.startsWith("Name="))
65-
si->name = line.mid(5);
119+
if (line.startsWith("Name=")) {
120+
if (type == WaylandSession)
121+
si->name = tr("%1 (Wayland)").arg(line.mid(5));
122+
else
123+
si->name = line.mid(5);
124+
}
66125
if (line.startsWith("Exec="))
67126
si->exec = line.mid(5);
68127
if (line.startsWith("Comment="))
@@ -96,7 +155,8 @@ namespace SDDM {
96155
inputFile.close();
97156
}
98157
// add failsafe session
99-
d->sessions << SessionPtr { new Session {"failsafe", "Failsafe", "failsafe", "Failsafe Session"} };
158+
if (type == X11Session)
159+
d->sessions << SessionPtr { new Session {type, path, "failsafe", "Failsafe", "failsafe", "Failsafe Session"} };
100160
// find out index of the last session
101161
for (int i = 0; i < d->sessions.size(); ++i) {
102162
if (d->sessions.at(i)->file == stateConfig.Last.Session.get()) {
@@ -105,48 +165,4 @@ namespace SDDM {
105165
}
106166
}
107167
}
108-
109-
SessionModel::~SessionModel() {
110-
delete d;
111-
}
112-
113-
QHash<int, QByteArray> SessionModel::roleNames() const {
114-
// set role names
115-
QHash<int, QByteArray> roleNames;
116-
roleNames[FileRole] = "file";
117-
roleNames[NameRole] = "name";
118-
roleNames[ExecRole] = "exec";
119-
roleNames[CommentRole] = "comment";
120-
121-
return roleNames;
122-
}
123-
124-
const int SessionModel::lastIndex() const {
125-
return d->lastIndex;
126-
}
127-
128-
int SessionModel::rowCount(const QModelIndex &parent) const {
129-
return d->sessions.length();
130-
}
131-
132-
QVariant SessionModel::data(const QModelIndex &index, int role) const {
133-
if (index.row() < 0 || index.row() >= d->sessions.count())
134-
return QVariant();
135-
136-
// get session
137-
SessionPtr session = d->sessions[index.row()];
138-
139-
// return correct value
140-
if (role == FileRole)
141-
return session->file;
142-
else if (role == NameRole)
143-
return session->name;
144-
else if (role == ExecRole)
145-
return session->exec;
146-
else if (role == CommentRole)
147-
return session->comment;
148-
149-
// return empty value
150-
return QVariant();
151-
}
152168
}

src/greeter/SessionModel.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/***************************************************************************
2+
* Copyright (c) 2015 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
23
* Copyright (c) 2013 Abdurrahman AVCI <abdurrahmanavci@gmail.com>
34
*
45
* This program is free software; you can redistribute it and/or modify
@@ -33,12 +34,18 @@ namespace SDDM {
3334
Q_PROPERTY(int lastIndex READ lastIndex CONSTANT)
3435
public:
3536
enum SessionRole {
36-
FileRole = Qt::UserRole + 1,
37+
DirectoryRole = Qt::UserRole + 1,
38+
FileRole,
3739
NameRole,
3840
ExecRole,
3941
CommentRole
4042
};
4143

44+
enum SessionType {
45+
X11Session = 0,
46+
WaylandSession
47+
};
48+
4249
SessionModel(QObject *parent = 0);
4350
~SessionModel();
4451

@@ -51,6 +58,8 @@ namespace SDDM {
5158

5259
private:
5360
SessionModelPrivate *d { nullptr };
61+
62+
void populate(SessionType type, const QString &path);
5463
};
5564
}
5665

0 commit comments

Comments
 (0)