]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blobdiff - src/seat.c
Have seat listen to greeter active username
[sojka/lightdm.git] / src / seat.c
index b434e67cf6db7956661863d0132010b073bef48f..39d77cb1dacf63b1acde8dabf91eeac53c0d02f8 100644 (file)
@@ -48,6 +48,9 @@ struct SeatPrivate
     /* The last session set to active */
     Session *active_session;
 
+    /* The session belonging to the active greeter user */
+    Session *next_session;
+
     /* The session to set active when it starts */
     Session *session_to_activate;
   
@@ -220,6 +223,13 @@ seat_get_active_session (Seat *seat)
     return SEAT_GET_CLASS (seat)->get_active_session (seat);
 }
 
+Session *
+seat_get_next_session (Seat *seat)
+{
+    g_return_val_if_fail (seat != NULL, NULL);
+    return seat->priv->next_session;
+}
+
 gboolean
 seat_get_can_switch (Seat *seat)
 {
@@ -490,6 +500,41 @@ run_session (Seat *seat, Session *session)
     }
 }
 
+static Session *
+find_user_session (Seat *seat, const gchar *username)
+{
+    GList *link;
+
+    if (!username)
+        return NULL;
+
+    for (link = seat->priv->sessions; link; link = link->next)
+    {
+        Session *session = link->data;
+
+        if (!session_get_is_stopping (session) && strcmp (session_get_username (session), username) == 0)
+            return session;
+    }
+
+    return NULL;
+}
+
+static void
+greeter_active_username_changed_cb (Greeter *greeter, GParamSpec *pspec, Seat *seat)
+{
+    Session *session;
+
+    session = find_user_session (seat, greeter_get_active_username (greeter));
+    if (session)
+    {
+        if (seat->priv->next_session)
+            g_object_unref (seat->priv->next_session);
+        seat->priv->next_session = g_object_ref (session);
+
+        SEAT_GET_CLASS (seat)->set_next_session (seat, session);
+    }
+}
+
 static void
 session_authentication_complete_cb (Session *session, Seat *seat)
 {
@@ -524,6 +569,11 @@ session_stopped_cb (Session *session, Seat *seat)
         g_object_unref (seat->priv->active_session);
         seat->priv->active_session = NULL;
     }
+    if (session == seat->priv->next_session)
+    {
+        g_object_unref (seat->priv->next_session);
+        seat->priv->next_session = NULL;
+    }
     if (session == seat->priv->session_to_activate)
     {
         g_object_unref (seat->priv->session_to_activate);
@@ -660,11 +710,13 @@ set_session_env (Session *session)
 }
 
 static Session *
-create_session (Seat *seat, gboolean autostart)
+create_session (Seat *seat, gboolean autostart, const gchar *username)
 {
     Session *session;
+    Session *user_session;
 
-    session = SEAT_GET_CLASS (seat)->create_session (seat);
+    user_session = find_user_session (seat, username);
+    session = SEAT_GET_CLASS (seat)->create_session (seat, user_session);
     seat->priv->sessions = g_list_append (seat->priv->sessions, session);
     if (autostart)
         g_signal_connect (session, "authentication-complete", G_CALLBACK (session_authentication_complete_cb), seat);
@@ -777,7 +829,7 @@ create_user_session (Seat *seat, const gchar *username)
         const gchar *desktop_name;
         gchar **argv;
 
-        session = create_session (seat, TRUE);
+        session = create_session (seat, TRUE, username);
         session_set_session_type (session, session_config_get_session_type (session_config));
         session_set_env (session, "DESKTOP_SESSION", session_name);
         session_set_env (session, "GDMSESSION", session_name);
@@ -823,7 +875,7 @@ create_guest_session (Seat *seat)
         return NULL;
     }
 
-    session = create_session (seat, TRUE);
+    session = create_session (seat, TRUE, NULL);
     session_set_session_type (session, session_config_get_session_type (session_config));
     session_set_do_authenticate (session, TRUE);
     session_set_is_guest (session, TRUE);
@@ -836,11 +888,11 @@ create_guest_session (Seat *seat)
 }
 
 static Session *
-greeter_create_session_cb (Greeter *greeter, Seat *seat)
+greeter_create_session_cb (Greeter *greeter, Seat *seat, const gchar *username)
 {
     Session *session;
 
-    session = create_session (seat, FALSE);
+    session = create_session (seat, FALSE, username);
     session_set_session_type (session, session_get_session_type (SESSION (greeter)));
     session_set_display_server (session, session_get_display_server (SESSION (greeter)));
 
@@ -864,25 +916,6 @@ prepend_argv (gchar ***argv, const gchar *value)
     *argv = new_argv;
 }
 
-static Session *
-find_user_session (Seat *seat, const gchar *username)
-{
-    GList *link;
-
-    if (!username)
-        return NULL;
-
-    for (link = seat->priv->sessions; link; link = link->next)
-    {
-        Session *session = link->data;
-
-        if (!session_get_is_stopping (session) && strcmp (session_get_username (session), username) == 0)
-            return session;
-    }
-
-    return NULL;
-}
-
 static gboolean
 greeter_start_session_cb (Greeter *greeter, SessionType type, const gchar *session_name, Seat *seat)
 {
@@ -1028,6 +1061,7 @@ create_greeter_session (Seat *seat)
     greeter_session = SEAT_GET_CLASS (seat)->create_greeter_session (seat);
     session_set_session_type (SESSION (greeter_session), session_config_get_session_type (session_config));
     seat->priv->sessions = g_list_append (seat->priv->sessions, SESSION (greeter_session));
+    g_signal_connect (greeter_session, "notify::active-username", G_CALLBACK (greeter_active_username_changed_cb), seat);
     g_signal_connect (greeter_session, "authentication-complete", G_CALLBACK (session_authentication_complete_cb), seat);
     g_signal_connect (greeter_session, "stopped", G_CALLBACK (session_stopped_cb), seat);
   
@@ -1481,7 +1515,7 @@ seat_real_create_greeter_session (Seat *seat)
 }
 
 static Session *
-seat_real_create_session (Seat *seat)
+seat_real_create_session (Seat *seat, Session *user_session)
 {
     return session_new ();
 }
@@ -1491,6 +1525,11 @@ seat_real_set_active_session (Seat *seat, Session *session)
 {
 }
 
+static void
+seat_real_set_next_session (Seat *seat, Session *session)
+{
+}
+
 static Session *
 seat_real_get_active_session (Seat *seat)
 {
@@ -1567,6 +1606,8 @@ seat_finalize (GObject *object)
     g_list_free_full (self->priv->sessions, g_object_unref);
     if (self->priv->active_session)
         g_object_unref (self->priv->active_session);
+    if (self->priv->next_session)
+        g_object_unref (self->priv->next_session);
     if (self->priv->session_to_activate)
         g_object_unref (self->priv->session_to_activate);
 
@@ -1585,6 +1626,7 @@ seat_class_init (SeatClass *klass)
     klass->create_session = seat_real_create_session;
     klass->set_active_session = seat_real_set_active_session;
     klass->get_active_session = seat_real_get_active_session;
+    klass->set_next_session = seat_real_set_next_session;
     klass->run_script = seat_real_run_script;
     klass->stop = seat_real_stop;