2 * Copyright (C) 2010-2011 Robert Ancell.
3 * Author: Robert Ancell <robert.ancell@canonical.com>
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
14 #include "seat-local.h"
15 #include "configuration.h"
19 struct SeatLocalPrivate
21 /* The section in the config for this seat */
22 gchar *config_section;
25 G_DEFINE_TYPE (SeatLocal, seat_local, SEAT_TYPE);
28 seat_local_new (const gchar *config_section)
32 seat = g_object_new (SEAT_LOCAL_TYPE, NULL);
33 seat->priv->config_section = g_strdup (config_section);
39 seat_local_get_can_switch (Seat *seat)
45 seat_local_add_display (Seat *seat)
48 XAuthorization *authorization = NULL;
49 gchar *dir, *filename, *path, *command, *xserver_section = NULL;
54 g_debug ("Starting new display to switch user");
56 xserver = xserver_new (XSERVER_TYPE_LOCAL, NULL, xserver_get_free_display_number ());
57 number = g_strdup_printf ("%d", xserver_get_display_number (xserver));
58 gethostname (hostname, 1024);
59 authorization = xauth_new_cookie (XAUTH_FAMILY_LOCAL, hostname, number);
62 xserver_set_vt (xserver, vt_get_unused ());
64 command = config_get_string (config_get_instance (), "LightDM", "default-xserver-command");
65 xserver_set_command (xserver, command);
68 xserver_set_authorization (xserver, authorization);
69 g_object_unref (authorization);
71 filename = g_strdup_printf ("%s.log", xserver_get_address (xserver));
72 dir = config_get_string (config_get_instance (), "LightDM", "log-directory");
73 path = g_build_filename (dir, filename, NULL);
74 g_debug ("Logging to %s", path);
75 child_process_set_log_file (CHILD_PROCESS (xserver), path);
80 /* Get the X server configuration */
81 if (SEAT_LOCAL (seat)->priv->config_section)
82 xserver_section = config_get_string (config_get_instance (), SEAT_LOCAL (seat)->priv->config_section, "xserver");
84 xserver_section = config_get_string (config_get_instance (), "LightDM", "xserver");
88 gchar *xserver_command, *xserver_layout, *xserver_config_file;
90 g_debug ("Using X server configuration '%s' for display '%s'", xserver_section, SEAT_LOCAL (seat)->priv->config_section ? SEAT_LOCAL (seat)->priv->config_section : "<anonymous>");
92 xserver_command = config_get_string (config_get_instance (), xserver_section, "command");
94 xserver_set_command (xserver, xserver_command);
95 g_free (xserver_command);
97 xserver_layout = config_get_string (config_get_instance (), xserver_section, "layout");
99 xserver_set_layout (xserver, xserver_layout);
100 g_free (xserver_layout);
102 xserver_config_file = config_get_string (config_get_instance (), xserver_section, "config-file");
103 if (xserver_config_file)
104 xserver_set_config_file (xserver, xserver_config_file);
105 g_free (xserver_config_file);
107 g_free (xserver_section);
110 if (config_get_boolean (config_get_instance (), "LightDM", "use-xephyr"))
111 xserver_set_command (xserver, "Xephyr");
113 display = display_new (xserver);
114 g_object_unref (xserver);
120 seat_local_set_active_display (Seat *seat, Display *display)
122 gint number = xserver_get_vt (display_get_xserver (display));
124 vt_set_active (number);
128 seat_local_init (SeatLocal *seat)
130 seat->priv = G_TYPE_INSTANCE_GET_PRIVATE (seat, SEAT_LOCAL_TYPE, SeatLocalPrivate);
134 seat_local_finalize (GObject *object)
138 self = SEAT_LOCAL (object);
140 g_free (self->priv->config_section);
142 G_OBJECT_CLASS (seat_local_parent_class)->finalize (object);
146 seat_local_class_init (SeatLocalClass *klass)
148 GObjectClass *object_class = G_OBJECT_CLASS (klass);
149 SeatClass *seat_class = SEAT_CLASS (klass);
151 seat_class->get_can_switch = seat_local_get_can_switch;
152 seat_class->add_display = seat_local_add_display;
153 seat_class->set_active_display = seat_local_set_active_display;
154 object_class->finalize = seat_local_finalize;
156 g_type_class_add_private (klass, sizeof (SeatLocalPrivate));