]> 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 3861cded365d836811d3f8699989c728f2053574..39d77cb1dacf63b1acde8dabf91eeac53c0d02f8 100644 (file)
@@ -45,6 +45,12 @@ struct SeatPrivate
     /* The sessions on this seat */
     GList *sessions;
 
+    /* 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;
   
@@ -179,6 +185,10 @@ seat_set_active_session (Seat *seat, Session *session)
 
     g_return_if_fail (seat != NULL);
 
+    /* Unlock this session */
+    if (session != seat->priv->active_session && !IS_GREETER (session))
+        session_unlock (session);
+
     SEAT_GET_CLASS (seat)->set_active_session (seat, session);
 
     /* Stop any greeters */
@@ -195,6 +205,15 @@ seat_set_active_session (Seat *seat, Session *session)
             session_stop (s);
         }
     }
+
+    /* Lock previous sessions */
+    if (seat->priv->active_session)
+    {
+        if (session != seat->priv->active_session && !IS_GREETER (seat->priv->active_session))
+            session_lock (seat->priv->active_session);
+        g_object_unref (seat->priv->active_session);
+    }
+    seat->priv->active_session = g_object_ref (session);
 }
 
 Session *
@@ -204,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)
 {
@@ -457,7 +483,10 @@ run_session (Seat *seat, Session *session)
     }
 
     if (!IS_GREETER (session))
+    {
         g_signal_emit (seat, signals[RUNNING_USER_SESSION], 0, session);
+        emit_upstart_signal ("desktop-session-start");
+    }
 
     session_run (session);
 
@@ -471,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)
 {
@@ -500,6 +564,21 @@ session_stopped_cb (Session *session, Seat *seat)
 
     g_signal_handlers_disconnect_matched (session, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, seat);
     seat->priv->sessions = g_list_remove (seat->priv->sessions, session);
+    if (session == seat->priv->active_session)
+    {
+        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);
+        seat->priv->session_to_activate = NULL;
+    }
 
     display_server = session_get_display_server (session);
     if (!display_server)
@@ -631,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);
@@ -745,12 +826,16 @@ create_user_session (Seat *seat, const gchar *username)
     g_free (sessions_dir);
     if (session_config)
     {
+        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);
+        desktop_name = session_config_get_desktop_name (session_config);
+        if (desktop_name)
+            session_set_env (session, "XDG_CURRENT_DESKTOP", desktop_name);
         if (language && language[0] != '\0')
         {
             session_set_env (session, "LANG", language);
@@ -790,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);
@@ -803,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)));
 
@@ -831,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)
 {
@@ -995,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);
   
@@ -1448,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 ();
 }
@@ -1458,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)
 {
@@ -1532,6 +1604,10 @@ seat_finalize (GObject *object)
         g_signal_handlers_disconnect_matched (session, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, self);
     }
     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);
 
@@ -1550,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;