2
* Copyright (C) 2012 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
13
#include <sys/types.h>
14
#include <sys/socket.h>
16
#include "seat-weston.h"
17
#include "configuration.h"
18
#include "xserver-local.h"
20
#include "wayland-client.h" // FIXME: See https://bugs.freedesktop.org/show_bug.cgi?id=51740
21
#include "weston-protocol.h"
23
struct SeatWestonPrivate
25
/* Compositor process */
26
Process *compositor_process;
28
/* Socket to communicate with compositor */
29
int compositor_socket;
32
G_DEFINE_TYPE (SeatWeston, seat_weston, SEAT_TYPE);
35
seat_weston_setup (Seat *seat)
37
seat_set_can_switch (seat, TRUE);
38
SEAT_CLASS (seat_weston_parent_class)->setup (seat);
42
compositor_stopped_cb (Process *process, SeatWeston *seat)
44
g_debug ("Stopping Weston seat, compositor terminated");
45
seat_stop (SEAT (seat));
49
seat_weston_start (Seat *seat)
52
int socket_fds[2], child_fd;
55
if (socketpair (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, socket_fds) == -1)
57
//perror ("Failed to create compositor sockets");
60
child_fd = dup (socket_fds[0]);
63
close (socket_fds[0]);
64
SEAT_WESTON (seat)->priv->compositor_socket = socket_fds[1];
66
if (socketpair (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, socket_fds) == -1)
68
//perror ("Failed to create compositor sockets");
72
command = g_strdup_printf ("weston --shell=system-compositor.so --display-manager-fd=%d", child_fd);
73
process_set_command (SEAT_WESTON (seat)->priv->compositor_process, command);
74
g_signal_connect (SEAT_WESTON (seat)->priv->compositor_process, "stopped", G_CALLBACK (compositor_stopped_cb), seat);
75
result = process_start (SEAT_WESTON (seat)->priv->compositor_process);
81
return SEAT_CLASS (seat_weston_parent_class)->start (seat);
84
static DisplayServer *
85
seat_weston_create_display_server (Seat *seat)
87
XServerLocal *xserver;
88
const gchar *command = NULL, *layout = NULL, *config_file = NULL, *xdmcp_manager = NULL, *key_name = NULL;
91
int socket_fds[2], child_fd;
93
g_debug ("Starting X server on weston compositor");
95
xserver = xserver_local_new ();
97
if (socketpair (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, socket_fds) == -1)
99
//perror ("Failed to create compositor sockets");
102
child_fd = dup (socket_fds[0]);
105
close (socket_fds[0]);
106
xserver_local_set_wayland_socket (xserver, child_fd);
108
command = seat_get_string_property (seat, "xserver-command");
110
xserver_local_set_command (xserver, command);
112
layout = seat_get_string_property (seat, "xserver-layout");
114
xserver_local_set_layout (xserver, layout);
116
config_file = seat_get_string_property (seat, "xserver-config");
118
xserver_local_set_config (xserver, config_file);
120
allow_tcp = seat_get_boolean_property (seat, "xserver-allow-tcp");
121
xserver_local_set_allow_tcp (xserver, allow_tcp);
123
xdmcp_manager = seat_get_string_property (seat, "xdmcp-manager");
125
xserver_local_set_xdmcp_server (xserver, xdmcp_manager);
127
port = seat_get_integer_property (seat, "xdmcp-port");
129
xserver_local_set_xdmcp_port (xserver, port);
131
key_name = seat_get_string_property (seat, "xdmcp-key");
137
GError *error = NULL;
139
dir = config_get_string (config_get_instance (), "LightDM", "config-directory");
140
path = g_build_filename (dir, "keys.conf", NULL);
143
keys = g_key_file_new ();
144
result = g_key_file_load_from_file (keys, path, G_KEY_FILE_NONE, &error);
146
g_debug ("Error getting key %s", error->message);
147
g_clear_error (&error);
153
if (g_key_file_has_key (keys, "keyring", key_name, NULL))
154
key = g_key_file_get_string (keys, "keyring", key_name, NULL);
156
g_debug ("Key %s not defined", key_name);
159
xserver_local_set_xdmcp_key (xserver, key);
164
g_key_file_free (keys);
167
return DISPLAY_SERVER (xserver);
171
seat_weston_create_session (Seat *seat, Display *display)
173
XServerLocal *xserver;
177
xserver = XSERVER_LOCAL (display_get_display_server (display));
179
session = xsession_new (XSERVER (xserver));
180
tty = g_strdup_printf ("/dev/tty%d", xserver_local_get_vt (xserver));
181
session_set_tty (SESSION (session), tty);
184
return SESSION (session);
188
seat_weston_set_active_display (Seat *seat, Display *display)
192
SEAT_CLASS (seat_weston_parent_class)->set_active_display (seat, display);
196
seat_weston_run_script (Seat *seat, Display *display, Process *script)
199
XServerLocal *xserver;
201
xserver = XSERVER_LOCAL (display_get_display_server (display));
202
path = xserver_local_get_authority_file_path (xserver);
203
process_set_env (script, "DISPLAY", xserver_get_address (XSERVER (xserver)));
204
process_set_env (script, "XAUTHORITY", path);
207
SEAT_CLASS (seat_weston_parent_class)->run_script (seat, display, script);
211
seat_weston_display_removed (Seat *seat, Display *display)
213
if (seat_get_is_stopping (seat))
216
/* If this is the only display and it failed to start then stop this seat */
217
if (g_list_length (seat_get_displays (seat)) == 0 && !display_get_is_ready (display))
219
g_debug ("Stopping Weston seat, failed to start a display");
224
/* Show a new greeter */
225
if (display == seat_get_active_display (seat))
227
g_debug ("Active display stopped, switching to greeter");
228
seat_switch_to_greeter (seat);
233
seat_weston_init (SeatWeston *seat)
235
seat->priv = G_TYPE_INSTANCE_GET_PRIVATE (seat, SEAT_WESTON_TYPE, SeatWestonPrivate);
236
seat->priv->compositor_process = process_new ();
240
seat_weston_finalize (GObject *object)
242
SeatWeston *seat = SEAT_WESTON (object);
244
g_object_unref (seat->priv->compositor_process);
246
G_OBJECT_CLASS (seat_weston_parent_class)->finalize (object);
250
seat_weston_class_init (SeatWestonClass *klass)
252
GObjectClass *object_class = G_OBJECT_CLASS (klass);
253
SeatClass *seat_class = SEAT_CLASS (klass);
255
object_class->finalize = seat_weston_finalize;
256
seat_class->setup = seat_weston_setup;
257
seat_class->start = seat_weston_start;
258
seat_class->create_display_server = seat_weston_create_display_server;
259
seat_class->create_session = seat_weston_create_session;
260
seat_class->set_active_display = seat_weston_set_active_display;
261
seat_class->run_script = seat_weston_run_script;
262
seat_class->display_removed = seat_weston_display_removed;
264
g_type_class_add_private (klass, sizeof (SeatWestonPrivate));