~ci-train-bot/lightdm/lightdm-ubuntu-zesty-1679

« back to all changes in this revision

Viewing changes to src/wayland-session.c

  • Committer: Robert Ancell
  • Date: 2015-07-28 08:38:40 UTC
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: robert.ancell@canonical.com-20150728083840-0c0rt3j8sl7mwhvo
Support Wayland sessions / greeters

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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;
 
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
}