]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blob - src/wayland-session.c
Load all users only when really needed
[sojka/lightdm.git] / src / wayland-session.c
1 /*
2  * Copyright (C) 2015 Canonical Ltd.
3  * Author: Robert Ancell <robert.ancell@canonical.com>
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 = WAYLAND_SESSION (object);
85
86     if (self->priv->have_vt_ref)
87         vt_unref (self->priv->vt);
88
89     G_OBJECT_CLASS (wayland_session_parent_class)->finalize (object);
90 }
91
92 static void
93 wayland_session_class_init (WaylandSessionClass *klass)
94 {
95     GObjectClass *object_class = G_OBJECT_CLASS (klass);
96     DisplayServerClass *display_server_class = DISPLAY_SERVER_CLASS (klass);
97
98     display_server_class->get_vt = wayland_session_get_vt;
99     display_server_class->connect_session = wayland_session_connect_session;
100     display_server_class->disconnect_session = wayland_session_disconnect_session;
101     object_class->finalize = wayland_session_finalize;
102
103     g_type_class_add_private (klass, sizeof (WaylandSessionPrivate));
104 }