]> rtime.felk.cvut.cz Git - sojka/lightdm.git/commitdiff
Have seat listen to greeter active username
authorMichael Terry <michael.terry@canonical.com>
Sun, 25 Aug 2013 20:12:21 +0000 (16:12 -0400)
committerMichael Terry <michael.terry@canonical.com>
Sun, 25 Aug 2013 20:12:21 +0000 (16:12 -0400)
src/seat.c
src/seat.h

index dfab9878ada9d184652f42eaed35bba60d197566..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);
@@ -659,25 +709,6 @@ set_session_env (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 Session *
 create_session (Seat *seat, gboolean autostart, const gchar *username)
 {
@@ -1030,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);
   
@@ -1493,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)
 {
@@ -1569,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);
 
@@ -1587,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;
 
index 111242910b77ada5568fa05ae0cd7ae6c379a7cc..1ed82058bf19053834b1cd4d4bea60e6f05651c2 100644 (file)
@@ -45,6 +45,7 @@ typedef struct
     Greeter *(*create_greeter_session) (Seat *seat);
     Session *(*create_session) (Seat *seat, Session *user_session);
     void (*set_active_session)(Seat *seat, Session *session);
+    void (*set_next_session)(Seat *seat, Session *session);
     Session *(*get_active_session)(Seat *seat);
     void (*run_script)(Seat *seat, DisplayServer *display_server, Process *script);
     void (*stop)(Seat *seat);
@@ -81,6 +82,8 @@ void seat_set_active_session (Seat *seat, Session *session);
 
 Session *seat_get_active_session (Seat *seat);
 
+Session *seat_get_next_session (Seat *seat);
+
 gboolean seat_get_can_switch (Seat *seat);
 
 gboolean seat_get_allow_guest (Seat *seat);