]> rtime.felk.cvut.cz Git - sojka/lightdm.git/commitdiff
Move Plymouth code out of XServerLocal
authorRobert Ancell <robert.ancell@canonical.com>
Wed, 24 Jul 2013 11:22:04 +0000 (23:22 +1200)
committerRobert Ancell <robert.ancell@canonical.com>
Wed, 24 Jul 2013 11:22:04 +0000 (23:22 +1200)
src/plymouth.c
src/seat-unity.c
src/seat-xlocal.c
src/x-server-local.c
src/x-server-local.h
tests/scripts/unity-plymouth.conf

index 406268063aa582391fe167a2eb8b59cec3a32a7e..aefb81a9498176a53b2d19fcf6d010cb9ec15601 100644 (file)
@@ -83,6 +83,7 @@ plymouth_has_active_vt (void)
 void
 plymouth_deactivate (void)
 {
+    g_debug ("Deactivating Plymouth");
     is_active = FALSE;
     plymouth_run_command ("deactivate", NULL);
 }
@@ -90,6 +91,11 @@ plymouth_deactivate (void)
 void
 plymouth_quit (gboolean retain_splash)
 {
+    if (retain_splash)
+        g_debug ("Quitting Plymouth; retaining splash");
+    else
+        g_debug ("Quitting Plymouth");
+
     have_pinged = TRUE;
     is_running = FALSE;
     if (retain_splash)
index 0789ed0d61c0f11cd4d14e216ffb71eeee4fbc3a..47f82dd8758550ab7b804ec1d892a3788122f74c 100644 (file)
@@ -34,9 +34,6 @@ struct SeatUnityPrivate
     /* VT we are running on */
     gint vt;
 
-    /* TRUE if waiting for X server to start before stopping Plymouth */
-    gboolean stopping_plymouth;
-
     /* File to log to */
     gchar *log_file;
 
@@ -118,13 +115,6 @@ compositor_stopped_cb (Process *process, SeatUnity *seat)
 
     g_debug ("Stopping Unity seat, compositor terminated");
 
-    if (seat->priv->stopping_plymouth)
-    {
-        g_debug ("Stopping Plymouth, compositor failed to start");
-        plymouth_quit (FALSE);
-        seat->priv->stopping_plymouth = FALSE;
-    }
-
     seat_stop (SEAT (seat));
 }
 
@@ -153,12 +143,6 @@ compositor_run_cb (Process *process, SeatUnity *seat)
              close (fd);
          }
     }
-
-    if (seat->priv->stopping_plymouth)
-    {      
-        seat->priv->stopping_plymouth = FALSE;
-        plymouth_quit (TRUE);
-    }  
 }
 
 static void
@@ -321,14 +305,14 @@ seat_unity_start (Seat *seat)
         gint active_vt = vt_get_active ();
         if (active_vt >= vt_get_min ())
         {
-            g_debug ("Compositor will replace Plymouth");
-            SEAT_UNITY (seat)->priv->stopping_plymouth = TRUE;
             SEAT_UNITY (seat)->priv->vt = active_vt;
-            plymouth_deactivate ();
+            plymouth_quit (TRUE);
         }
         else
             g_debug ("Plymouth is running on VT %d, but this is less than the configured minimum of %d so not replacing it", active_vt, vt_get_min ());
     }
+    if (plymouth_get_is_active ())
+        plymouth_quit (FALSE);
     if (SEAT_UNITY (seat)->priv->vt < 0)
         SEAT_UNITY (seat)->priv->vt = vt_get_unused ();
     if (SEAT_UNITY (seat)->priv->vt < 0)
@@ -393,6 +377,19 @@ seat_unity_start (Seat *seat)
     return TRUE;
 }
 
+static void
+x_server_stopped_cb (XServerLocal *x_server, Seat *seat)
+{
+    gint vt;
+
+    /* Can re-use the VT */
+    vt = display_server_get_vt (DISPLAY_SERVER (x_server));
+    if (vt > 0)
+        vt_unref (vt);
+
+    g_signal_handlers_disconnect_matched (x_server, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, x_server_stopped_cb, NULL);
+}
+
 static DisplayServer *
 seat_unity_create_display_server (Seat *seat)
 {
@@ -419,6 +416,16 @@ seat_unity_create_display_server (Seat *seat)
     if (command)
         x_server_local_set_command (x_server, command);
 
+    if (SEAT_UNITY (seat)->priv->use_vt_switching)
+    {
+        gint vt;
+      
+        vt = vt_get_unused ();
+        vt_ref (vt);
+        x_server_local_set_vt (x_server, vt);
+        g_signal_connect (x_server, "stopped", G_CALLBACK (x_server_stopped_cb), seat);
+    }
+
     layout = seat_get_string_property (seat, "xserver-layout");
     if (layout)
         x_server_local_set_layout (x_server, layout);
index 96e734094fce644f0619d18b92432c4d4058653a..b6a85922d606ec99e99344af0feae5e93bb34a7e 100644 (file)
@@ -14,6 +14,7 @@
 #include "seat-xlocal.h"
 #include "configuration.h"
 #include "x-server-local.h"
+#include "plymouth.h"
 #include "vt.h"
 
 G_DEFINE_TYPE (SeatXLocal, seat_xlocal, SEAT_TYPE);
@@ -26,15 +27,55 @@ seat_xlocal_setup (Seat *seat)
     SEAT_CLASS (seat_xlocal_parent_class)->setup (seat);
 }
 
+static gboolean
+seat_xlocal_start (Seat *seat)
+{
+   
+    return SEAT_CLASS (seat_xlocal_parent_class)->start (seat);
+}
+
+static void
+x_server_ready_cb (XServerLocal *x_server, Seat *seat)
+{
+    /* Quit Plymouth */
+    plymouth_quit (TRUE);
+}
+
+static void
+x_server_transition_plymouth_cb (XServerLocal *x_server, Seat *seat)
+{
+    /* Quit Plymouth if we didn't do the transition */
+    if (plymouth_get_is_running ())
+        plymouth_quit (FALSE);
+
+    g_signal_handlers_disconnect_matched (x_server, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, x_server_transition_plymouth_cb, NULL);
+}
+
+static void
+x_server_stopped_cb (XServerLocal *x_server, Seat *seat)
+{
+    gint vt;
+
+    /* Can re-use the VT */
+    vt = display_server_get_vt (DISPLAY_SERVER (x_server));
+    if (vt > 0)
+        vt_unref (vt);
+
+    g_signal_handlers_disconnect_matched (x_server, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, x_server_stopped_cb, NULL);
+}
+
 static DisplayServer *
 seat_xlocal_create_display_server (Seat *seat)
 {
     XServerLocal *x_server;
     const gchar *command = NULL, *layout = NULL, *config_file = NULL, *xdmcp_manager = NULL, *key_name = NULL;
     gboolean allow_tcp;
-    gint port = 0;
+    gint vt = -1, port = 0;
 
-    g_debug ("Starting local X display");
+    if (vt > 0)
+        g_debug ("Starting local X display on VT %d", vt);
+    else
+        g_debug ("Starting local X display");
   
     x_server = x_server_local_new ();
 
@@ -46,6 +87,31 @@ seat_xlocal_create_display_server (Seat *seat)
     if (command)
         x_server_local_set_command (x_server, command);
 
+    /* If Plymouth is running, stop it */
+    if (plymouth_get_is_active () && plymouth_has_active_vt ())
+    {
+        gint active_vt = vt_get_active ();
+        if (active_vt >= vt_get_min ())
+        {
+            vt = active_vt;
+            g_signal_connect (x_server, "ready", G_CALLBACK (x_server_ready_cb), seat);
+            g_signal_connect (x_server, "stopped", G_CALLBACK (x_server_transition_plymouth_cb), seat);
+            plymouth_deactivate ();
+        }
+        else
+            g_debug ("Plymouth is running on VT %d, but this is less than the configured minimum of %d so not replacing it", active_vt, vt_get_min ());
+    }
+    if (plymouth_get_is_active ())
+        plymouth_quit (FALSE);
+    if (vt < 0)
+        vt = vt_get_unused ();
+    if (vt >= 0)
+    {
+        vt_ref (vt);
+        x_server_local_set_vt (x_server, vt);
+        g_signal_connect (x_server, "stopped", G_CALLBACK (x_server_stopped_cb), seat);
+    }
+
     layout = seat_get_string_property (seat, "xserver-layout");
     if (layout)
         x_server_local_set_layout (x_server, layout);
@@ -181,6 +247,7 @@ seat_xlocal_class_init (SeatXLocalClass *klass)
     SeatClass *seat_class = SEAT_CLASS (klass);
 
     seat_class->setup = seat_xlocal_setup;
+    seat_class->start = seat_xlocal_start;
     seat_class->create_display_server = seat_xlocal_create_display_server;
     seat_class->create_greeter_session = seat_xlocal_create_greeter_session;
     seat_class->create_session = seat_xlocal_create_session;
index c475ec30a65e2795d02f1c07c87ecc6669d402a1..bd43ce9f2f514768c494a36d2f2cc928d87b4c25 100644 (file)
@@ -22,7 +22,6 @@
 #include "configuration.h"
 #include "process.h"
 #include "vt.h"
-#include "plymouth.h"
 
 struct XServerLocalPrivate
 {
@@ -67,12 +66,9 @@ struct XServerLocalPrivate
 
     /* VT to run on */
     gint vt;
-  
-    /* TRUE if holding a reference to the VT */
-    gboolean have_vt_ref;
-  
-    /* TRUE if replacing Plymouth */
-    gboolean replacing_plymouth;
+
+    /* Background to set */
+    gchar *background;
 };
 
 G_DEFINE_TYPE (XServerLocal, x_server_local, X_SERVER_TYPE);
@@ -165,28 +161,6 @@ x_server_local_new (void)
     display_server_set_name (DISPLAY_SERVER (self), name);
     g_free (name);
 
-    /* Replace Plymouth if it is running */
-    if (plymouth_get_is_active () && plymouth_has_active_vt ())
-    {
-        gint active_vt = vt_get_active ();
-        if (active_vt >= vt_get_min ())
-        {
-            g_debug ("X server %s will replace Plymouth", x_server_get_address (X_SERVER (self)));
-            self->priv->replacing_plymouth = TRUE;
-            self->priv->vt = active_vt;
-            plymouth_deactivate ();
-        }
-        else
-            g_debug ("Plymouth is running on VT %d, but this is less than the configured minimum of %d so not replacing it", active_vt, vt_get_min ());
-    }
-    if (self->priv->vt < 0)
-        self->priv->vt = vt_get_unused ();
-    if (self->priv->vt >= 0)
-    {
-        vt_ref (self->priv->vt);
-        self->priv->have_vt_ref = TRUE;
-    }
-
     return self;
 }
 
@@ -198,6 +172,13 @@ x_server_local_set_command (XServerLocal *server, const gchar *command)
     server->priv->command = g_strdup (command);
 }
 
+void
+x_server_local_set_vt (XServerLocal *server, gint vt)
+{
+    g_return_if_fail (server != NULL);
+    server->priv->vt = vt;
+}
+
 void
 x_server_local_set_config (XServerLocal *server, const gchar *path)
 {
@@ -259,19 +240,20 @@ x_server_local_set_xdmcp_key (XServerLocal *server, const gchar *key)
     x_server_set_authority (X_SERVER (server), NULL);
 }
 
+void
+x_server_local_set_background (XServerLocal *server, const gchar *background)
+{
+    g_return_if_fail (server != NULL);
+    g_free (server->priv->background);
+    server->priv->background = g_strdup (background);
+}
+
 void
 x_server_local_set_mir_id (XServerLocal *server, const gchar *id)
 {
     g_return_if_fail (server != NULL);
     g_free (server->priv->mir_id);
     server->priv->mir_id = g_strdup (id);
-
-    if (server->priv->have_vt_ref)
-    {
-        vt_unref (server->priv->vt);
-        server->priv->have_vt_ref = FALSE;
-    }
-    server->priv->vt = -1;
 }
 
 const gchar *x_server_local_get_mir_id (XServerLocal *server)
@@ -363,13 +345,6 @@ got_signal_cb (Process *process, int signum, XServerLocal *server)
         server->priv->got_signal = TRUE;
         g_debug ("Got signal from X server :%d", x_server_get_display_number (X_SERVER (server)));
 
-        if (server->priv->replacing_plymouth)
-        {
-            g_debug ("Stopping Plymouth, X server is ready");
-            server->priv->replacing_plymouth = FALSE;
-            plymouth_quit (TRUE);
-        }
-
         // FIXME: Check return value
         DISPLAY_SERVER_CLASS (x_server_local_parent_class)->start (DISPLAY_SERVER (server));
     }
@@ -392,19 +367,6 @@ stopped_cb (Process *process, XServerLocal *server)
         server->priv->authority_file = NULL;
     }
 
-    if (server->priv->have_vt_ref)
-    {
-        vt_unref (server->priv->vt);
-        server->priv->have_vt_ref = FALSE;
-    }  
-
-    if (server->priv->replacing_plymouth && plymouth_get_is_running ())
-    {
-        g_debug ("Stopping Plymouth, X server failed to start");
-        server->priv->replacing_plymouth = FALSE;
-        plymouth_quit (FALSE);
-    }
-
     DISPLAY_SERVER_CLASS (x_server_local_parent_class)->stop (DISPLAY_SERVER (server));
 }
 
@@ -513,8 +475,9 @@ x_server_local_start (DisplayServer *display_server)
     if (server->priv->vt >= 0)
         g_string_append_printf (command, " vt%d -novtswitch", server->priv->vt);
 
-    if (server->priv->replacing_plymouth)
-        g_string_append (command, " -background none");
+    if (server->priv->background)
+        g_string_append_printf (command, " -background %s", server->priv->background);
+
     process_set_command (server->priv->x_server_process, command->str);
     g_string_free (command, TRUE);
 
@@ -589,8 +552,7 @@ x_server_local_finalize (GObject *object)
     g_free (self->priv->mir_id);
     g_free (self->priv->mir_socket);
     g_free (self->priv->authority_file);
-    if (self->priv->have_vt_ref)
-        vt_unref (self->priv->vt);
+    g_free (self->priv->background);
 
     G_OBJECT_CLASS (x_server_local_parent_class)->finalize (object);
 }
index efcd8c471d2d0b97910e7613ce2d4409c99a6032..6d1d6abb436168cf745064810b937c0cf4ce33f9 100644 (file)
@@ -45,6 +45,8 @@ XServerLocal *x_server_local_new (void);
 
 void x_server_local_set_command (XServerLocal *server, const gchar *command);
 
+void x_server_local_set_vt (XServerLocal *server, gint vt);
+
 void x_server_local_set_config (XServerLocal *server, const gchar *path);
 
 void x_server_local_set_layout (XServerLocal *server, const gchar *layout);
@@ -61,6 +63,8 @@ guint x_server_local_get_xdmcp_port (XServerLocal *server);
 
 void x_server_local_set_xdmcp_key (XServerLocal *server, const gchar *key);
 
+void x_server_local_set_background (XServerLocal *server, const gchar *background);
+
 void x_server_local_set_mir_id (XServerLocal *server, const gchar *id);
 
 const gchar *x_server_local_get_mir_id (XServerLocal *server);
index 39a85a945c650d4d48d438ca6841e2b844cff846..2594be7ed647295ee76144981122101300ec7ac0 100644 (file)
@@ -17,15 +17,12 @@ active=true
 # Check if Plymouth is running
 #?PLYMOUTH PING ACTIVE=TRUE
 #?PLYMOUTH HAS-ACTIVE-VT=TRUE
-#?PLYMOUTH DEACTIVATE
+#?PLYMOUTH QUIT RETAIN-SPLASH=TRUE
 
 # System compositor starts
 #?UNITY-SYSTEM-COMPOSITOR START VT=7
 #?*UNITY-SYSTEM-COMPOSITOR READY
 
-# Plymouth quits but keeps image in framebuffer
-#?PLYMOUTH QUIT RETAIN-SPLASH=TRUE
-
 # X server starts
 #?XSERVER-0 START MIR-ID=0