Skip to content

Commit f4f681f

Browse files
committed
Support Wayland sessions / greeters
1 parent 2db3a8b commit f4f681f

23 files changed

+318
-23
lines changed

data/lightdm.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#log-directory=/var/log/lightdm
2929
#run-directory=/var/run/lightdm
3030
#cache-directory=/var/cache/lightdm
31-
#sessions-directory=/usr/share/lightdm/sessions:/usr/share/xsessions
31+
#sessions-directory=/usr/share/lightdm/sessions:/usr/share/xsessions:/usr/share/wayland-sessions
3232
#remote-sessions-directory=/usr/share/lightdm/remote-sessions
3333
#greeters-directory=/usr/share/lightdm/greeters:/usr/share/xgreeters
3434

liblightdm-gobject/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ liblightdm_gobject_1_la_CFLAGS = $(LIBLIGHTDM_GOBJECT_CFLAGS) \
88
$(WARN_CFLAGS) \
99
-I"$(top_srcdir)/common" \
1010
-DCONFIG_DIR=\"$(sysconfdir)/lightdm\" \
11-
-DSESSIONS_DIR=\"$(pkgdatadir)/sessions:$(datadir)/xsessions\" \
11+
-DSESSIONS_DIR=\"$(pkgdatadir)/sessions:$(datadir)/xsessions:$(datadir)/wayland-sessions\" \
12+
-DWAYLAND_SESSIONS_DIR=\"$(datadir)/wayland-sessions\" \
1213
-DREMOTE_SESSIONS_DIR=\"$(pkgdatadir)/remote-sessions\"
1314

1415
mainheader_HEADERS = lightdm.h

liblightdm-gobject/session.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ compare_session (gconstpointer a, gconstpointer b)
4646
}
4747

4848
static LightDMSession *
49-
load_session (GKeyFile *key_file, const gchar *key)
49+
load_session (GKeyFile *key_file, const gchar *key, const gchar *default_type)
5050
{
51-
gchar *type, *domain, *name;
51+
gchar *domain, *name, *type;
5252
LightDMSession *session;
5353
LightDMSessionPrivate *priv;
5454
gchar *try_exec;
@@ -57,10 +57,6 @@ load_session (GKeyFile *key_file, const gchar *key)
5757
g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_HIDDEN, NULL))
5858
return NULL;
5959

60-
type = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "X-LightDM-Session-Type", NULL);
61-
if (!type)
62-
type = "x";
63-
6460
#ifdef G_KEY_FILE_DESKTOP_KEY_GETTEXT_DOMAIN
6561
domain = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_GETTEXT_DOMAIN, NULL);
6662
#else
@@ -91,14 +87,18 @@ load_session (GKeyFile *key_file, const gchar *key)
9187
g_free (full_path);
9288
}
9389

90+
type = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "X-LightDM-Session-Type", NULL);
91+
if (!type)
92+
type = strdup (default_type);
93+
9494
session = g_object_new (LIGHTDM_TYPE_SESSION, NULL);
9595
priv = GET_PRIVATE (session);
9696

9797
g_free (priv->key);
9898
priv->key = g_strdup (key);
9999

100100
g_free (priv->type);
101-
priv->type = g_strdup (type);
101+
priv->type = type;
102102

103103
g_free (priv->name);
104104
priv->name = name;
@@ -114,7 +114,7 @@ load_session (GKeyFile *key_file, const gchar *key)
114114
}
115115

116116
static GList *
117-
load_sessions_dir (GList *sessions, const gchar *sessions_dir)
117+
load_sessions_dir (GList *sessions, const gchar *sessions_dir, const gchar *default_type)
118118
{
119119
GDir *directory;
120120
GError *error = NULL;
@@ -154,7 +154,7 @@ load_sessions_dir (GList *sessions, const gchar *sessions_dir)
154154
LightDMSession *session;
155155

156156
key = g_strndup (filename, strlen (filename) - strlen (".desktop"));
157-
session = load_session (key_file, key);
157+
session = load_session (key_file, key, default_type);
158158
if (session)
159159
{
160160
g_debug ("Loaded session %s (%s, %s)", path, GET_PRIVATE (session)->name, GET_PRIVATE (session)->comment);
@@ -182,8 +182,16 @@ load_sessions (const gchar *sessions_dir)
182182
int i;
183183

184184
dirs = g_strsplit (sessions_dir, ":", -1);
185-
for (i = 0; dirs[i]; i++)
186-
sessions = load_sessions_dir (sessions, dirs[i]);
185+
for (i = 0; dirs[i]; i++)
186+
{
187+
const gchar *default_type = "x";
188+
189+
if (strcmp (dirs[i], WAYLAND_SESSIONS_DIR) == 0)
190+
default_type = "wayland";
191+
192+
sessions = load_sessions_dir (sessions, dirs[i], default_type);
193+
}
194+
187195
g_strfreev (dirs);
188196

189197
return sessions;

liblightdm-qt/Makefile.am

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ common_cflags = \
1212
$(WARN_CXXFLAGS) \
1313
-I$(top_srcdir)/liblightdm-gobject \
1414
$(GLIB_CFLAGS) \
15-
-DQT_NO_KEYWORDS \
16-
-DXSESSIONS_DIR=\"$(datadir)/xsessions\"
15+
-DQT_NO_KEYWORDS
1716
liblightdm_qt_3_la_CXXFLAGS = \
1817
$(LIBLIGHTDM_QT4_CFLAGS) \
1918
$(common_cflags)

src/Makefile.am

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ lightdm_SOURCES = \
5151
vnc-server.h \
5252
vt.c \
5353
vt.h \
54+
wayland-session.c \
55+
wayland-session.h \
5456
x-authority.c \
5557
x-authority.h \
5658
x-server-local.c \
@@ -78,7 +80,8 @@ lightdm_CFLAGS = \
7880
-DLOG_DIR=\"$(localstatedir)/log/lightdm\" \
7981
-DRUN_DIR=\"$(localstatedir)/run/lightdm\" \
8082
-DCACHE_DIR=\"$(localstatedir)/cache/lightdm\" \
81-
-DSESSIONS_DIR=\"$(pkgdatadir)/sessions:$(datadir)/xsessions\" \
83+
-DSESSIONS_DIR=\"$(pkgdatadir)/sessions:$(datadir)/xsessions:$(datadir)/wayland-sessions\" \
84+
-DWAYLAND_SESSIONS_DIR=\"$(datadir)/wayland-sessions\" \
8285
-DREMOTE_SESSIONS_DIR=\"$(pkgdatadir)/remote-sessions\" \
8386
-DGREETERS_DIR=\"$(pkgdatadir)/greeters:$(datadir)/xgreeters\"
8487

src/seat-xlocal.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "configuration.h"
1616
#include "x-server-local.h"
1717
#include "unity-system-compositor.h"
18+
#include "wayland-session.h"
1819
#include "plymouth.h"
1920
#include "vt.h"
2021

@@ -247,6 +248,21 @@ create_unity_system_compositor (Seat *seat)
247248
return DISPLAY_SERVER (compositor);
248249
}
249250

251+
static DisplayServer *
252+
create_wayland_session (Seat *seat)
253+
{
254+
WaylandSession *session;
255+
gint vt;
256+
257+
session = wayland_session_new ();
258+
259+
vt = get_vt (seat, DISPLAY_SERVER (session));
260+
if (vt >= 0)
261+
wayland_session_set_vt (session, vt);
262+
263+
return DISPLAY_SERVER (session);
264+
}
265+
250266
static DisplayServer *
251267
seat_xlocal_create_display_server (Seat *seat, Session *session)
252268
{
@@ -257,6 +273,8 @@ seat_xlocal_create_display_server (Seat *seat, Session *session)
257273
return DISPLAY_SERVER (create_x_server (seat));
258274
else if (strcmp (session_type, "mir") == 0)
259275
return create_unity_system_compositor (seat);
276+
else if (strcmp (session_type, "wayland") == 0)
277+
return create_wayland_session (seat);
260278
else if (strcmp (session_type, "mir-container") == 0)
261279
{
262280
DisplayServer *compositor;

src/seat.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,11 +962,15 @@ find_session_config (Seat *seat, const gchar *sessions_dir, const gchar *session
962962
for (i = 0; dirs[i]; i++)
963963
{
964964
gchar *filename, *path;
965+
const gchar *default_session_type = "x";
966+
967+
if (strcmp (dirs[i], WAYLAND_SESSIONS_DIR) == 0)
968+
default_session_type = "wayland";
965969

966970
filename = g_strdup_printf ("%s.desktop", session_name);
967971
path = g_build_filename (dirs[i], filename, NULL);
968972
g_free (filename);
969-
session_config = session_config_new_from_file (path, &error);
973+
session_config = session_config_new_from_file (path, default_session_type, &error);
970974
g_free (path);
971975
if (session_config)
972976
break;

src/session-config.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct SessionConfigPrivate
2929
G_DEFINE_TYPE (SessionConfig, session_config, G_TYPE_OBJECT);
3030

3131
SessionConfig *
32-
session_config_new_from_file (const gchar *filename, GError **error)
32+
session_config_new_from_file (const gchar *filename, const gchar *default_session_type, GError **error)
3333
{
3434
GKeyFile *desktop_file;
3535
SessionConfig *config;
@@ -52,7 +52,7 @@ session_config_new_from_file (const gchar *filename, GError **error)
5252
config->priv->command = command;
5353
config->priv->session_type = g_key_file_get_string (desktop_file, G_KEY_FILE_DESKTOP_GROUP, "X-LightDM-Session-Type", NULL);
5454
if (!config->priv->session_type)
55-
config->priv->session_type = g_strdup ("x");
55+
config->priv->session_type = g_strdup (default_session_type);
5656

5757
config->priv->desktop_names = g_key_file_get_string_list (desktop_file, G_KEY_FILE_DESKTOP_GROUP, "DesktopNames", NULL, NULL);
5858
if (!config->priv->desktop_names)

src/session-config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ typedef struct
3636

3737
GType session_config_get_type (void);
3838

39-
SessionConfig *session_config_new_from_file (const gchar *filename, GError **error);
39+
SessionConfig *session_config_new_from_file (const gchar *filename, const gchar *default_session_type, GError **error);
4040

4141
const gchar *session_config_get_command (SessionConfig *config);
4242

src/wayland-session.c

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright (C) 2015 Canonical Ltd.
3+
* Author: Robert Ancell <[email protected]>
4+
*
5+
* This program is free software: you can redistribute it and/or modify it under
6+
* the terms of the GNU General Public License as published by the Free Software
7+
* Foundation, either version 3 of the License, or (at your option) any later
8+
* version. See http://www.gnu.org/copyleft/gpl.html the full text of the
9+
* license.
10+
*/
11+
12+
#include "wayland-session.h"
13+
#include "vt.h"
14+
15+
struct WaylandSessionPrivate
16+
{
17+
/* VT to run on */
18+
gint vt;
19+
gboolean have_vt_ref;
20+
};
21+
22+
G_DEFINE_TYPE (WaylandSession, wayland_session, DISPLAY_SERVER_TYPE);
23+
24+
WaylandSession *
25+
wayland_session_new (void)
26+
{
27+
return g_object_new (WAYLAND_SESSION_TYPE, NULL);
28+
}
29+
30+
void
31+
wayland_session_set_vt (WaylandSession *session, gint vt)
32+
{
33+
g_return_if_fail (session != NULL);
34+
35+
if (session->priv->have_vt_ref)
36+
vt_unref (session->priv->vt);
37+
session->priv->have_vt_ref = FALSE;
38+
session->priv->vt = vt;
39+
if (vt > 0)
40+
{
41+
vt_ref (vt);
42+
session->priv->have_vt_ref = TRUE;
43+
}
44+
}
45+
46+
static gint
47+
wayland_session_get_vt (DisplayServer *server)
48+
{
49+
g_return_val_if_fail (server != NULL, 0);
50+
return WAYLAND_SESSION (server)->priv->vt;
51+
}
52+
53+
static void
54+
wayland_session_connect_session (DisplayServer *display_server, Session *session)
55+
{
56+
WaylandSession *wayland_session = WAYLAND_SESSION (display_server);
57+
58+
session_set_env (session, "XDG_SESSION_TYPE", "wayland");
59+
60+
if (wayland_session->priv->vt >= 0)
61+
{
62+
gchar *value = g_strdup_printf ("%d", wayland_session->priv->vt);
63+
session_set_env (session, "XDG_VTNR", value);
64+
g_free (value);
65+
}
66+
}
67+
68+
static void
69+
wayland_session_disconnect_session (DisplayServer *display_server, Session *session)
70+
{
71+
session_unset_env (session, "XDG_SESSION_TYPE");
72+
session_unset_env (session, "XDG_VTNR");
73+
}
74+
75+
static void
76+
wayland_session_init (WaylandSession *session)
77+
{
78+
session->priv = G_TYPE_INSTANCE_GET_PRIVATE (session, WAYLAND_SESSION_TYPE, WaylandSessionPrivate);
79+
}
80+
81+
static void
82+
wayland_session_finalize (GObject *object)
83+
{
84+
WaylandSession *self;
85+
86+
self = WAYLAND_SESSION (object);
87+
88+
if (self->priv->have_vt_ref)
89+
vt_unref (self->priv->vt);
90+
91+
G_OBJECT_CLASS (wayland_session_parent_class)->finalize (object);
92+
}
93+
94+
static void
95+
wayland_session_class_init (WaylandSessionClass *klass)
96+
{
97+
GObjectClass *object_class = G_OBJECT_CLASS (klass);
98+
DisplayServerClass *display_server_class = DISPLAY_SERVER_CLASS (klass);
99+
100+
display_server_class->get_vt = wayland_session_get_vt;
101+
display_server_class->connect_session = wayland_session_connect_session;
102+
display_server_class->disconnect_session = wayland_session_disconnect_session;
103+
object_class->finalize = wayland_session_finalize;
104+
105+
g_type_class_add_private (klass, sizeof (WaylandSessionPrivate));
106+
}

src/wayland-session.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (C) 2015 Canonical Ltd.
3+
* Author: Robert Ancell <[email protected]>
4+
*
5+
* This program is free software: you can redistribute it and/or modify it under
6+
* the terms of the GNU General Public License as published by the Free Software
7+
* Foundation, either version 3 of the License, or (at your option) any later
8+
* version. See http://www.gnu.org/copyleft/gpl.html the full text of the
9+
* license.
10+
*/
11+
12+
#ifndef WAYLAND_SESSION_H_
13+
#define WAYLAND_SESSION_H_
14+
15+
#include <glib-object.h>
16+
#include "display-server.h"
17+
18+
G_BEGIN_DECLS
19+
20+
#define WAYLAND_SESSION_TYPE (wayland_session_get_type())
21+
#define WAYLAND_SESSION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WAYLAND_SESSION_TYPE, WaylandSession))
22+
#define IS_WAYLAND_SESSION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WAYLAND_SESSION_TYPE))
23+
24+
typedef struct WaylandSessionPrivate WaylandSessionPrivate;
25+
26+
typedef struct
27+
{
28+
DisplayServer parent_instance;
29+
WaylandSessionPrivate *priv;
30+
} WaylandSession;
31+
32+
typedef struct
33+
{
34+
DisplayServerClass parent_class;
35+
} WaylandSessionClass;
36+
37+
GType wayland_session_get_type (void);
38+
39+
WaylandSession *wayland_session_new (void);
40+
41+
void wayland_session_set_vt (WaylandSession *session, gint vt);
42+
43+
G_END_DECLS
44+
45+
#endif /* WAYLAND_SESSION_H_ */

tests/Makefile.am

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ TESTS = \
198198
test-mir-session-crash \
199199
test-mir-session-compositor-crash \
200200
test-mir-container-session \
201+
test-wayland-autologin \
202+
test-wayland-greeter \
203+
test-wayland-session \
201204
test-unity-compositor-command \
202205
test-unity-compositor-not-found \
203206
test-unity-compositor-fail-start \
@@ -348,12 +351,14 @@ EXTRA_DIST = \
348351
data/greeters/test-python-greeter.desktop \
349352
data/greeters/test-qt4-greeter.desktop \
350353
data/greeters/test-qt5-greeter.desktop \
354+
data/greeters/test-wayland-greeter.desktop \
351355
data/sessions/alternative.desktop \
352356
data/sessions/default.desktop \
353357
data/sessions/mir.desktop \
354358
data/sessions/mir-container.desktop \
355359
data/sessions/named.desktop \
356360
data/sessions/named-legacy.desktop \
361+
data/sessions/wayland.desktop \
357362
scripts/0-additional.conf \
358363
scripts/1-additional.conf \
359364
scripts/additional-config.conf \
@@ -565,6 +570,9 @@ EXTRA_DIST = \
565570
scripts/vnc-guest.conf \
566571
scripts/vnc-login.conf \
567572
scripts/vnc-open-file-descriptors.conf \
573+
scripts/wayland-autologin.conf \
574+
scripts/wayland-greeter.conf \
575+
scripts/wayland-session.conf \
568576
scripts/xauthority.conf \
569577
scripts/xdg-current-desktop.conf \
570578
scripts/xdg-current-desktop-legacy.conf \

0 commit comments

Comments
 (0)