struct SeatXLocalPrivate
{
+ /* System compositor being used for Mir sessions */
+ UnitySystemCompositor *compositor;
+
+ /* Session currently active on compositor */
+ Session *active_compositor_session;
+
/* X server being used for XDMCP */
XServerLocal *xdmcp_x_server;
};
G_DEFINE_TYPE (SeatXLocal, seat_xlocal, SEAT_TYPE);
-static XServerLocal *create_x_server (Seat *seat);
+static XServerLocal *create_x_server (SeatXLocal *seat);
static void
seat_xlocal_setup (Seat *seat)
}
static void
-xdmcp_x_server_stopped_cb (DisplayServer *display_server, Seat *seat)
+xdmcp_x_server_stopped_cb (DisplayServer *display_server, SeatXLocal *seat)
{
l_debug (seat, "XDMCP X server stopped");
- g_signal_handlers_disconnect_matched (SEAT_XLOCAL (seat)->priv->xdmcp_x_server, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, seat);
- SEAT_XLOCAL (seat)->priv->xdmcp_x_server = NULL;
- g_object_unref (display_server);
+ g_signal_handlers_disconnect_matched (seat->priv->xdmcp_x_server, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, seat);
+ g_clear_object (&seat->priv->xdmcp_x_server);
- if (seat_get_is_stopping (seat))
- check_stopped (SEAT_XLOCAL (seat));
+ if (seat_get_is_stopping (SEAT (seat)))
+ check_stopped (seat);
else
- seat_stop (seat);
+ seat_stop (SEAT (seat));
}
+static void
+compositor_stopped_cb (UnitySystemCompositor *compositor, SeatXLocal *seat)
+{
+ l_debug (seat, "Compositor stopped");
+
+ g_clear_object (&seat->priv->compositor);
+
+ if (seat_get_is_stopping (SEAT (seat)))
+ check_stopped (seat);
+}
+
static gboolean
seat_xlocal_start (Seat *seat)
{
const gchar *key_name = NULL;
gint port = 0;
- s->priv->xdmcp_x_server = create_x_server (seat);
+ s->priv->xdmcp_x_server = create_x_server (s);
x_server_local_set_xdmcp_server (s->priv->xdmcp_x_server, xdmcp_manager);
port = seat_get_integer_property (seat, "xdmcp-port");
if (port > 0)
}
static gint
-get_vt (Seat *seat, DisplayServer *display_server)
+get_vt (SeatXLocal *seat, DisplayServer *display_server)
{
gint vt = -1;
- const gchar *xdg_seat = seat_get_name (seat);
+ const gchar *xdg_seat = seat_get_name (SEAT (seat));
if (strcmp (xdg_seat, "seat0") != 0)
return vt;
return vt;
}
+static UnitySystemCompositor *
+create_unity_system_compositor (SeatXLocal *seat)
+{
+ UnitySystemCompositor *compositor;
+ const gchar *command;
+ gint timeout, vt;
+
+ compositor = unity_system_compositor_new ();
+
+ command = seat_get_string_property (SEAT (seat), "unity-compositor-command");
+ if (command)
+ unity_system_compositor_set_command (compositor, command);
+
+ timeout = seat_get_integer_property (SEAT (seat), "unity-compositor-timeout");
+ if (timeout <= 0)
+ timeout = 60;
+ unity_system_compositor_set_timeout (compositor, timeout);
+
+ vt = get_vt (seat, DISPLAY_SERVER (compositor));
+ if (vt >= 0)
+ unity_system_compositor_set_vt (compositor, vt);
+
+ return compositor;
+}
+
+static UnitySystemCompositor *
+get_unity_system_compositor (SeatXLocal *seat)
+{
+ if (seat->priv->compositor)
+ return seat->priv->compositor;
+
+ seat->priv->compositor = create_unity_system_compositor (seat);
+ g_signal_connect (seat->priv->compositor, DISPLAY_SERVER_SIGNAL_STOPPED, G_CALLBACK (compositor_stopped_cb), seat);
+
+ return seat->priv->compositor;
+}
+
static XServerLocal *
-create_x_server (Seat *seat)
+create_x_server (SeatXLocal *seat)
{
XServerLocal *x_server;
gchar *number;
if (g_getenv ("DISPLAY"))
command = "Xephyr";
if (!command)
- command = seat_get_string_property (seat, "xserver-command");
+ command = seat_get_string_property (SEAT (seat), "xserver-command");
if (command)
x_server_local_set_command (x_server, command);
g_free (number);
g_object_unref (cookie);
- layout = seat_get_string_property (seat, "xserver-layout");
+ layout = seat_get_string_property (SEAT (seat), "xserver-layout");
if (layout)
x_server_local_set_layout (x_server, layout);
- x_server_local_set_xdg_seat (x_server, seat_get_name (seat));
+ x_server_local_set_xdg_seat (x_server, seat_get_name (SEAT (seat)));
- config_file = seat_get_string_property (seat, "xserver-config");
+ config_file = seat_get_string_property (SEAT (seat), "xserver-config");
if (config_file)
x_server_local_set_config (x_server, config_file);
- allow_tcp = seat_get_boolean_property (seat, "xserver-allow-tcp");
+ allow_tcp = seat_get_boolean_property (SEAT (seat), "xserver-allow-tcp");
x_server_local_set_allow_tcp (x_server, allow_tcp);
return x_server;
}
static DisplayServer *
-create_unity_system_compositor (Seat *seat)
-{
- UnitySystemCompositor *compositor;
- const gchar *command;
- gchar *socket_name;
- gint vt, timeout, i;
-
- compositor = unity_system_compositor_new ();
-
- command = seat_get_string_property (seat, "unity-compositor-command");
- if (command)
- unity_system_compositor_set_command (compositor, command);
-
- timeout = seat_get_integer_property (seat, "unity-compositor-timeout");
- if (timeout <= 0)
- timeout = 60;
- unity_system_compositor_set_timeout (compositor, timeout);
-
- vt = get_vt (seat, DISPLAY_SERVER (compositor));
- if (vt >= 0)
- unity_system_compositor_set_vt (compositor, vt);
-
- for (i = 0; ; i++)
- {
- socket_name = g_strdup_printf ("/run/lightdm-mir-%d", i);
- if (!g_file_test (socket_name, G_FILE_TEST_EXISTS))
- break;
- }
- unity_system_compositor_set_socket (compositor, socket_name);
- g_free (socket_name);
-
- return DISPLAY_SERVER (compositor);
-}
-
-static DisplayServer *
-create_wayland_session (Seat *seat)
+create_wayland_session (SeatXLocal *seat)
{
WaylandSession *session;
gint vt;
}
static DisplayServer *
-seat_xlocal_create_display_server (Seat *seat, Session *session)
+seat_xlocal_create_display_server (Seat *s, Session *session)
{
+ SeatXLocal *seat = SEAT_XLOCAL (s);
const gchar *session_type;
session_type = session_get_session_type (session);
if (strcmp (session_type, "x") == 0)
return DISPLAY_SERVER (create_x_server (seat));
else if (strcmp (session_type, "mir") == 0)
- return create_unity_system_compositor (seat);
+ return g_object_ref (get_unity_system_compositor (seat));
else if (strcmp (session_type, "wayland") == 0)
return create_wayland_session (seat);
else if (strcmp (session_type, "mir-container") == 0)
{
- DisplayServer *compositor;
+ UnitySystemCompositor *compositor;
const gchar *compositor_command;
compositor = create_unity_system_compositor (seat);
compositor_command = session_config_get_compositor_command (session_get_config (session));
if (compositor_command)
- unity_system_compositor_set_command (UNITY_SYSTEM_COMPOSITOR (compositor), compositor_command);
+ unity_system_compositor_set_command (compositor, compositor_command);
- return compositor;
+ return DISPLAY_SERVER (compositor);
}
else
{
}
}
+static gboolean
+seat_xlocal_display_server_is_used (Seat *seat, DisplayServer *display_server)
+{
+ if (display_server == DISPLAY_SERVER (SEAT_XLOCAL (seat)->priv->compositor))
+ return TRUE;
+
+ return SEAT_CLASS (seat_xlocal_parent_class)->display_server_is_used (seat, display_server);
+}
+
static GreeterSession *
seat_xlocal_create_greeter_session (Seat *seat)
{
}
static void
-seat_xlocal_set_active_session (Seat *seat, Session *session)
+seat_xlocal_set_active_session (Seat *s, Session *session)
{
+ SeatXLocal *seat = SEAT_XLOCAL (s);
DisplayServer *display_server;
display_server = session_get_display_server (session);
if (vt >= 0)
vt_set_active (vt);
- if (IS_UNITY_SYSTEM_COMPOSITOR (display_server))
+ g_clear_object (&seat->priv->active_compositor_session);
+ if (IS_UNITY_SYSTEM_COMPOSITOR (display_server)) {
unity_system_compositor_set_active_session (UNITY_SYSTEM_COMPOSITOR (display_server), session_get_env (session, "MIR_SERVER_NAME"));
+ seat->priv->active_compositor_session = g_object_ref (session);
+ }
- SEAT_CLASS (seat_xlocal_parent_class)->set_active_session (seat, session);
+ SEAT_CLASS (seat_xlocal_parent_class)->set_active_session (s, session);
}
static Session *
-seat_xlocal_get_active_session (Seat *seat)
+seat_xlocal_get_active_session (Seat *s)
{
+ SeatXLocal *seat = SEAT_XLOCAL (s);
gint vt;
GList *link;
if (vt < 0)
return NULL;
- for (link = seat_get_sessions (seat); link; link = link->next)
+ /* If the compositor is active return the session it is displaying */
+ if (seat->priv->compositor && display_server_get_vt (DISPLAY_SERVER (seat->priv->compositor)) == vt)
+ return seat->priv->active_compositor_session;
+
+ /* Otherwise find out which session is on this VT */
+ for (link = seat_get_sessions (s); link; link = link->next)
{
Session *session = link->data;
DisplayServer *display_server;
return NULL;
}
+static void
+seat_xlocal_set_next_session (Seat *seat, Session *session)
+{
+ const gchar *id = NULL;
+
+ if (!session)
+ return;
+
+ id = session_get_env (session, "MIR_SERVER_NAME");
+ if (id)
+ {
+ l_debug (seat, "Marking Mir session %s as the next session", id);
+ unity_system_compositor_set_next_session (SEAT_XLOCAL (seat)->priv->compositor, id);
+ }
+ else
+ l_debug (seat, "Failed to work out session ID to mark");
+
+ SEAT_CLASS (seat_xlocal_parent_class)->set_next_session (seat, session);
+}
+
static void
seat_xlocal_run_script (Seat *seat, DisplayServer *display_server, Process *script)
{
}
static void
-seat_xlocal_stop (Seat *seat)
+seat_xlocal_stop (Seat *s)
{
- /* Stop the XDMCP X server first */
- if (SEAT_XLOCAL (seat)->priv->xdmcp_x_server)
- display_server_stop (DISPLAY_SERVER (SEAT_XLOCAL (seat)->priv->xdmcp_x_server));
+ SeatXLocal *seat = SEAT_XLOCAL (s);
+
+ /* Stop the compositor */
+ if (seat->priv->compositor)
+ display_server_stop (DISPLAY_SERVER (seat->priv->compositor));
+
+ /* Stop the XDMCP X server */
+ if (seat->priv->xdmcp_x_server)
+ display_server_stop (DISPLAY_SERVER (seat->priv->xdmcp_x_server));
- check_stopped (SEAT_XLOCAL (seat));
+ check_stopped (seat);
}
static void
{
SeatXLocal *seat = SEAT_XLOCAL (object);
+ g_clear_object (&seat->priv->compositor);
+ g_clear_object (&seat->priv->active_compositor_session);
if (seat->priv->xdmcp_x_server)
{
g_signal_handlers_disconnect_matched (seat->priv->xdmcp_x_server, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, seat);
seat_class->setup = seat_xlocal_setup;
seat_class->start = seat_xlocal_start;
seat_class->create_display_server = seat_xlocal_create_display_server;
+ seat_class->display_server_is_used = seat_xlocal_display_server_is_used;
seat_class->create_greeter_session = seat_xlocal_create_greeter_session;
seat_class->create_session = seat_xlocal_create_session;
seat_class->set_active_session = seat_xlocal_set_active_session;
seat_class->get_active_session = seat_xlocal_get_active_session;
+ seat_class->set_next_session = seat_xlocal_set_next_session;
seat_class->run_script = seat_xlocal_run_script;
seat_class->stop = seat_xlocal_stop;