]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blob - src/seat-local.c
Always use Xephyr when DISPLAY is set
[sojka/lightdm.git] / src / seat-local.c
1 /*
2  * Copyright (C) 2010-2011 Robert Ancell.
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 <string.h>
13
14 #include "seat-local.h"
15 #include "configuration.h"
16 #include "xserver.h"
17 #include "vt.h"
18
19 struct SeatLocalPrivate
20 {
21     /* The section in the config for this seat */
22     gchar *config_section;
23 };
24
25 G_DEFINE_TYPE (SeatLocal, seat_local, SEAT_TYPE);
26
27 SeatLocal *
28 seat_local_new (const gchar *config_section)
29 {
30     SeatLocal *seat;
31
32     seat = g_object_new (SEAT_LOCAL_TYPE, NULL);
33     seat->priv->config_section = g_strdup (config_section);
34     seat_load_config (SEAT (seat), config_section);
35     seat_set_can_switch (SEAT (seat), TRUE);
36
37     return seat;
38 }
39
40 static Display *
41 seat_local_add_display (Seat *seat)
42 {
43     XServer *xserver;
44     XAuthorization *authorization = NULL;
45     gchar *dir, *filename, *path;
46     gchar *number;
47     gchar hostname[1024];
48     Display *display;
49
50     g_debug ("Starting display");
51
52     xserver = xserver_new (SEAT_LOCAL (seat)->priv->config_section, XSERVER_TYPE_LOCAL, NULL, xserver_get_free_display_number ());
53     number = g_strdup_printf ("%d", xserver_get_display_number (xserver));
54     gethostname (hostname, 1024);
55     authorization = xauth_new_cookie (XAUTH_FAMILY_LOCAL, hostname, number);
56     g_free (number);
57
58     xserver_set_authorization (xserver, authorization);
59     g_object_unref (authorization);
60
61     filename = g_strdup_printf ("%s.log", xserver_get_address (xserver));
62     dir = config_get_string (config_get_instance (), "Directories", "log-directory");
63     path = g_build_filename (dir, filename, NULL);
64     g_debug ("Logging to %s", path);
65     child_process_set_log_file (CHILD_PROCESS (xserver), path);
66     g_free (filename);
67     g_free (dir);
68     g_free (path);
69
70     display = display_new (SEAT_LOCAL (seat)->priv->config_section, xserver);
71     g_object_unref (xserver);
72
73     return display;
74 }
75
76 static void
77 seat_local_set_active_display (Seat *seat, Display *display)
78 {
79     gint number = xserver_get_vt (display_get_xserver (display));
80     if (number >= 0)
81         vt_set_active (number);
82 }
83
84 static void
85 seat_local_init (SeatLocal *seat)
86 {
87     seat->priv = G_TYPE_INSTANCE_GET_PRIVATE (seat, SEAT_LOCAL_TYPE, SeatLocalPrivate);
88 }
89
90 static void
91 seat_local_finalize (GObject *object)
92 {
93     SeatLocal *self;
94
95     self = SEAT_LOCAL (object);
96
97     g_free (self->priv->config_section);
98
99     G_OBJECT_CLASS (seat_local_parent_class)->finalize (object);
100 }
101
102 static void
103 seat_local_class_init (SeatLocalClass *klass)
104 {
105     GObjectClass *object_class = G_OBJECT_CLASS (klass);
106     SeatClass *seat_class = SEAT_CLASS (klass);
107
108     seat_class->add_display = seat_local_add_display;
109     seat_class->set_active_display = seat_local_set_active_display;
110     object_class->finalize = seat_local_finalize;
111
112     g_type_class_add_private (klass, sizeof (SeatLocalPrivate));
113 }