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-xlocal.h"
15 #include "configuration.h"
16 #include "xserver-local.h"
20 G_DEFINE_TYPE (SeatXLocal, seat_xlocal, SEAT_TYPE);
23 seat_xlocal_setup (Seat *seat)
25 seat_set_can_switch (seat, TRUE);
26 seat_set_share_display_server (seat, seat_get_boolean_property (seat, "xserver-share"));
27 SEAT_CLASS (seat_xlocal_parent_class)->setup (seat);
30 static DisplayServer *
31 seat_xlocal_create_display_server (Seat *seat)
33 XServerLocal *xserver;
34 const gchar *command = NULL, *layout = NULL, *config_file = NULL, *xdmcp_manager = NULL, *key_name = NULL;
38 g_debug ("Starting local X display");
40 xserver = xserver_local_new ();
42 /* If running inside an X server use Xephyr instead */
43 if (g_getenv ("DISPLAY"))
46 command = seat_get_string_property (seat, "xserver-command");
48 xserver_local_set_command (xserver, command);
50 layout = seat_get_string_property (seat, "xserver-layout");
52 xserver_local_set_layout (xserver, layout);
54 config_file = seat_get_string_property (seat, "xserver-config");
56 xserver_local_set_config (xserver, config_file);
58 allow_tcp = seat_get_boolean_property (seat, "xserver-allow-tcp");
59 xserver_local_set_allow_tcp (xserver, allow_tcp);
61 xdmcp_manager = seat_get_string_property (seat, "xdmcp-manager");
63 xserver_local_set_xdmcp_server (xserver, xdmcp_manager);
65 port = seat_get_integer_property (seat, "xdmcp-port");
67 xserver_local_set_xdmcp_port (xserver, port);
69 key_name = seat_get_string_property (seat, "xdmcp-key");
77 dir = config_get_string (config_get_instance (), "LightDM", "config-directory");
78 path = g_build_filename (dir, "keys.conf", NULL);
81 keys = g_key_file_new ();
82 result = g_key_file_load_from_file (keys, path, G_KEY_FILE_NONE, &error);
84 g_debug ("Error getting key %s", error->message);
85 g_clear_error (&error);
91 if (g_key_file_has_key (keys, "keyring", key_name, NULL))
92 key = g_key_file_get_string (keys, "keyring", key_name, NULL);
94 g_debug ("Key %s not defined", key_name);
97 xserver_local_set_xdmcp_key (xserver, key);
102 g_key_file_free (keys);
105 return DISPLAY_SERVER (xserver);
109 seat_xlocal_create_session (Seat *seat, Display *display)
111 XServerLocal *xserver;
115 xserver = XSERVER_LOCAL (display_get_display_server (display));
117 session = xsession_new ();
118 t = g_strdup_printf ("/dev/tty%d", xserver_local_get_vt (xserver));
119 session_set_tty (SESSION (session), t);
122 /* Set variables for logind */
123 session_set_env (SESSION (session), "XDG_SEAT", "seat0");
124 t = g_strdup_printf ("%d", xserver_local_get_vt (xserver));
125 session_set_env (SESSION (session), "XDG_VTNR", t);
128 return SESSION (session);
132 seat_xlocal_set_active_display (Seat *seat, Display *display)
134 gint vt = xserver_local_get_vt (XSERVER_LOCAL (display_get_display_server (display)));
138 SEAT_CLASS (seat_xlocal_parent_class)->set_active_display (seat, display);
142 seat_xlocal_get_active_display (Seat *seat)
147 vt = vt_get_active ();
151 for (link = seat_get_displays (seat); link; link = link->next)
153 Display *display = link->data;
154 XServerLocal *xserver;
156 xserver = XSERVER_LOCAL (display_get_display_server (display));
157 if (xserver_local_get_vt (xserver) == vt)
165 seat_xlocal_run_script (Seat *seat, Display *display, Process *script)
168 XServerLocal *xserver;
170 xserver = XSERVER_LOCAL (display_get_display_server (display));
171 path = xserver_local_get_authority_file_path (xserver);
172 process_set_env (script, "DISPLAY", xserver_get_address (XSERVER (xserver)));
173 process_set_env (script, "XAUTHORITY", path);
175 SEAT_CLASS (seat_xlocal_parent_class)->run_script (seat, display, script);
179 seat_xlocal_init (SeatXLocal *seat)
184 seat_xlocal_class_init (SeatXLocalClass *klass)
186 SeatClass *seat_class = SEAT_CLASS (klass);
188 seat_class->setup = seat_xlocal_setup;
189 seat_class->create_display_server = seat_xlocal_create_display_server;
190 seat_class->create_session = seat_xlocal_create_session;
191 seat_class->set_active_display = seat_xlocal_set_active_display;
192 seat_class->get_active_display = seat_xlocal_get_active_display;
193 seat_class->run_script = seat_xlocal_run_script;