summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Ancell <robert.ancell@canonical.com>2013-06-04 17:37:38 +1200
committerRobert Ancell <robert.ancell@canonical.com>2013-06-04 17:37:38 +1200
commit0690afa1f147c309f61b382727cfcbfbbce3b6a3 (patch)
treef951ba41583099f4046afbb5ec1585a3ec73d305
parent245b697156b033b420cbc3123f5d08d5155ec7fa (diff)
downloadlightdm-0690afa1f147c309f61b382727cfcbfbbce3b6a3.tar.gz
Start work on Mir sessions
-rw-r--r--liblightdm-gobject/Makefile.am3
-rw-r--r--liblightdm-gobject/greeter.c55
-rw-r--r--liblightdm-gobject/lightdm/greeter.h2
-rw-r--r--liblightdm-gobject/lightdm/session.h2
-rw-r--r--liblightdm-gobject/session.c25
-rw-r--r--liblightdm-qt/QLightDM/sessionsmodel.h3
-rw-r--r--liblightdm-qt/sessionsmodel.cpp3
-rw-r--r--src/greeter.c13
-rw-r--r--src/session.h3
-rw-r--r--tests/src/test-session.c2
10 files changed, 102 insertions, 9 deletions
diff --git a/liblightdm-gobject/Makefile.am b/liblightdm-gobject/Makefile.am
index 449276ca..bd1b45a7 100644
--- a/liblightdm-gobject/Makefile.am
+++ b/liblightdm-gobject/Makefile.am
@@ -6,7 +6,8 @@ liblightdm_gobject_1_la_CFLAGS = $(LIBLIGHTDM_GOBJECT_CFLAGS) \
$(WARN_CFLAGS) \
-DCONFIG_DIR=\"$(sysconfdir)/lightdm\" \
-DXSESSIONS_DIR=\"$(datadir)/xsessions\" \
- -DREMOTE_SESSIONS_DIR=\"$(pkgdatadir)/remote-sessions\"
+ -DREMOTE_SESSIONS_DIR=\"$(pkgdatadir)/remote-sessions\" \
+ -DMIR_SESSIONS_DIR=\"$(datadir)/mir-sessions\"
mainheader_HEADERS = lightdm.h
mainheaderdir=$(includedir)/lightdm-gobject-1
diff --git a/liblightdm-gobject/greeter.c b/liblightdm-gobject/greeter.c
index 1db708f2..ad401d46 100644
--- a/liblightdm-gobject/greeter.c
+++ b/liblightdm-gobject/greeter.c
@@ -81,7 +81,8 @@ typedef enum
GREETER_MESSAGE_START_SESSION,
GREETER_MESSAGE_CANCEL_AUTHENTICATION,
GREETER_MESSAGE_SET_LANGUAGE,
- GREETER_MESSAGE_AUTHENTICATE_REMOTE
+ GREETER_MESSAGE_AUTHENTICATE_REMOTE,
+ GREETER_MESSAGE_START_MIR_SESSION
} GreeterMessage;
/* Messages from the server to the greeter */
@@ -1106,6 +1107,58 @@ lightdm_greeter_start_session_sync (LightDMGreeter *greeter, const gchar *sessio
return return_code == 0;
}
+/**
+ * lightdm_greeter_start_mir_session_sync:
+ * @greeter: A #LightDMGreeter
+ * @session: (allow-none): The Mir session to log into or #NULL to use the default.
+ * @error: return location for a #GError, or %NULL
+ *
+ * Start a session for the authenticated user.
+ *
+ * Return value: TRUE if the session was started.
+ **/
+gboolean
+lightdm_greeter_start_mir_session_sync (LightDMGreeter *greeter, const gchar *session, GError **error)
+{
+ LightDMGreeterPrivate *priv;
+ guint8 message[MAX_MESSAGE_LENGTH];
+ guint8 *response;
+ gsize response_length, offset = 0;
+ guint32 id, return_code = 1;
+
+ g_return_val_if_fail (LIGHTDM_IS_GREETER (greeter), FALSE);
+
+ priv = GET_PRIVATE (greeter);
+
+ g_return_val_if_fail (priv->connected, FALSE);
+ g_return_val_if_fail (priv->is_authenticated, FALSE);
+
+ if (session)
+ g_debug ("Starting Mir session %s", session);
+ else
+ g_debug ("Starting default Mir session");
+
+ write_header (message, MAX_MESSAGE_LENGTH, GREETER_MESSAGE_START_MIR_SESSION, string_length (session), &offset);
+ write_string (message, MAX_MESSAGE_LENGTH, session, &offset);
+ write_message (greeter, message, offset);
+
+ response = read_message (greeter, &response_length, TRUE);
+ if (!response)
+ return FALSE;
+
+ offset = 0;
+ id = read_int (response, response_length, &offset);
+ read_int (response, response_length, &offset);
+ if (id == SERVER_MESSAGE_SESSION_RESULT)
+ return_code = read_int (response, response_length, &offset);
+ else
+ g_warning ("Expected SESSION_RESULT message, got %d", id);
+
+ g_free (response);
+
+ return return_code == 0;
+}
+
static void
lightdm_greeter_init (LightDMGreeter *greeter)
{
diff --git a/liblightdm-gobject/lightdm/greeter.h b/liblightdm-gobject/lightdm/greeter.h
index af409dee..30e7f33b 100644
--- a/liblightdm-gobject/lightdm/greeter.h
+++ b/liblightdm-gobject/lightdm/greeter.h
@@ -121,6 +121,8 @@ void lightdm_greeter_set_language (LightDMGreeter *greeter, const gchar *languag
gboolean lightdm_greeter_start_session_sync (LightDMGreeter *greeter, const gchar *session, GError **error);
+gboolean lightdm_greeter_start_mir_session_sync (LightDMGreeter *greeter, const gchar *session, GError **error);
+
G_END_DECLS
#endif /* LIGHTDM_GREETER_H_ */
diff --git a/liblightdm-gobject/lightdm/session.h b/liblightdm-gobject/lightdm/session.h
index 4123888c..426000cb 100644
--- a/liblightdm-gobject/lightdm/session.h
+++ b/liblightdm-gobject/lightdm/session.h
@@ -46,6 +46,8 @@ GList *lightdm_get_sessions (void);
GList *lightdm_get_remote_sessions (void);
+GList *lightdm_get_mir_sessions (void);
+
const gchar *lightdm_session_get_key (LightDMSession *session);
const gchar *lightdm_session_get_name (LightDMSession *session);
diff --git a/liblightdm-gobject/session.c b/liblightdm-gobject/session.c
index f1ccf6cc..36aec934 100644
--- a/liblightdm-gobject/session.c
+++ b/liblightdm-gobject/session.c
@@ -34,6 +34,7 @@ G_DEFINE_TYPE (LightDMSession, lightdm_session, G_TYPE_OBJECT);
static gboolean have_sessions = FALSE;
static GList *local_sessions = NULL;
static GList *remote_sessions = NULL;
+static GList *mir_sessions = NULL;
static gint
compare_session (gconstpointer a, gconstpointer b)
@@ -173,6 +174,7 @@ update_sessions (void)
gchar *config_path = NULL;
gchar *xsessions_dir;
gchar *remote_sessions_dir;
+ gchar *mir_sessions_dir;
gboolean result;
GError *error = NULL;
@@ -181,6 +183,7 @@ update_sessions (void)
xsessions_dir = g_strdup (XSESSIONS_DIR);
remote_sessions_dir = g_strdup (REMOTE_SESSIONS_DIR);
+ mir_sessions_dir = g_strdup (MIR_SESSIONS_DIR);
/* Use session directory from configuration */
/* FIXME: This should be sent in the greeter connection */
@@ -207,12 +210,20 @@ update_sessions (void)
g_free (remote_sessions_dir);
remote_sessions_dir = value;
}
+
+ value = g_key_file_get_string (config_key_file, "LightDM", "mir-sessions-directory", NULL);
+ if (value)
+ {
+ g_free (mir_sessions_dir);
+ mir_sessions_dir = value;
+ }
}
g_key_file_free (config_key_file);
g_free (config_path);
local_sessions = load_sessions (xsessions_dir);
remote_sessions = load_sessions (remote_sessions_dir);
+ mir_sessions = load_sessions (mir_sessions_dir);
g_free (xsessions_dir);
g_free (remote_sessions_dir);
@@ -249,6 +260,20 @@ lightdm_get_remote_sessions (void)
}
/**
+ * lightdm_get_mir_sessions:
+ *
+ * Get the available Mir sessions.
+ *
+ * Return value: (element-type LightDMSession) (transfer none): A list of #LightDMSession
+ **/
+GList *
+lightdm_get_mir_sessions (void)
+{
+ update_sessions ();
+ return mir_sessions;
+}
+
+/**
* lightdm_session_get_key:
* @session: A #LightDMSession
*
diff --git a/liblightdm-qt/QLightDM/sessionsmodel.h b/liblightdm-qt/QLightDM/sessionsmodel.h
index 77c81fb2..33a67655 100644
--- a/liblightdm-qt/QLightDM/sessionsmodel.h
+++ b/liblightdm-qt/QLightDM/sessionsmodel.h
@@ -32,7 +32,8 @@ namespace QLightDM {
enum SessionType {
LocalSessions,
- RemoteSessions
+ RemoteSessions,
+ MirSessions
};
explicit SessionsModel(QObject *parent = 0); /** Deprecated. Loads local sessions*/
diff --git a/liblightdm-qt/sessionsmodel.cpp b/liblightdm-qt/sessionsmodel.cpp
index 9ad335f9..93295f38 100644
--- a/liblightdm-qt/sessionsmodel.cpp
+++ b/liblightdm-qt/sessionsmodel.cpp
@@ -58,6 +58,9 @@ void SessionsModelPrivate::loadSessions(SessionsModel::SessionType sessionType)
case SessionsModel::RemoteSessions:
ldmSessions = lightdm_get_remote_sessions();
break;
+ case SessionsModel::MirSessions:
+ ldmSessions = lightdm_get_mir_sessions();
+ break;
case SessionsModel::LocalSessions:
/* Fall through*/
default:
diff --git a/src/greeter.c b/src/greeter.c
index 9601c093..05921d23 100644
--- a/src/greeter.c
+++ b/src/greeter.c
@@ -84,7 +84,8 @@ typedef enum
GREETER_MESSAGE_START_SESSION,
GREETER_MESSAGE_CANCEL_AUTHENTICATION,
GREETER_MESSAGE_SET_LANGUAGE,
- GREETER_MESSAGE_AUTHENTICATE_REMOTE
+ GREETER_MESSAGE_AUTHENTICATE_REMOTE,
+ GREETER_MESSAGE_START_MIR_SESSION
} GreeterMessage;
/* Messages from the server to the greeter */
@@ -547,12 +548,11 @@ handle_cancel_authentication (Greeter *greeter)
}
static void
-handle_start_session (Greeter *greeter, const gchar *session)
+handle_start_session (Greeter *greeter, SessionType session_type, const gchar *session)
{
gboolean result;
guint8 message[MAX_MESSAGE_LENGTH];
gsize offset = 0;
- SessionType session_type = SESSION_TYPE_LOCAL;
if (strcmp (session, "") == 0)
session = NULL;
@@ -778,7 +778,12 @@ read_cb (GIOChannel *source, GIOCondition condition, gpointer data)
break;
case GREETER_MESSAGE_START_SESSION:
session_name = read_string (greeter, &offset);
- handle_start_session (greeter, session_name);
+ handle_start_session (greeter, SESSION_TYPE_LOCAL, session_name);
+ g_free (session_name);
+ break;
+ case GREETER_MESSAGE_START_MIR_SESSION:
+ session_name = read_string (greeter, &offset);
+ handle_start_session (greeter, SESSION_TYPE_MIR, session_name);
g_free (session_name);
break;
case GREETER_MESSAGE_SET_LANGUAGE:
diff --git a/src/session.h b/src/session.h
index c3523b1e..13f9962c 100644
--- a/src/session.h
+++ b/src/session.h
@@ -46,7 +46,8 @@ typedef struct
typedef enum
{
SESSION_TYPE_LOCAL,
- SESSION_TYPE_REMOTE
+ SESSION_TYPE_REMOTE,
+ SESSION_TYPE_MIR
} SessionType;
#define XDG_SESSION_CLASS_USER "user"
diff --git a/tests/src/test-session.c b/tests/src/test-session.c
index 7d321cee..ad1dfebe 100644
--- a/tests/src/test-session.c
+++ b/tests/src/test-session.c
@@ -162,7 +162,7 @@ main (int argc, char **argv)
int fd, open_max;
display = getenv ("DISPLAY");
- if (display == NULL)
+ if (display == NULL)
session_id = g_strdup ("SESSION-?");
else if (display[0] == ':')
session_id = g_strdup_printf ("SESSION-X-%s", display + 1);