diff options
author | Kristian Høgsberg <krh@bitplanet.net> | 2011-09-19 17:24:49 -0400 |
---|---|---|
committer | Kristian Høgsberg <krh@bitplanet.net> | 2011-09-19 17:24:49 -0400 |
commit | e80a36db781da89ef6a31e5733d17887f0f01ccc (patch) | |
tree | f0d7169c80287127879a3079b8b84cac0fd773ab | |
parent | b2f55d60777873ea8ac0390085087965ccf757b7 (diff) |
session-manager: Manage user list in session-managersession-manager
-rw-r--r-- | clients/greeter.c | 117 | ||||
-rw-r--r-- | clients/session-manager.c | 53 |
2 files changed, 110 insertions, 60 deletions
diff --git a/clients/greeter.c b/clients/greeter.c index f5401e4f..f90a7304 100644 --- a/clients/greeter.c +++ b/clients/greeter.c @@ -399,6 +399,15 @@ dialog_redraw_handler(struct window *window, void *data) cairo_move_to(cr, allocation.x, allocation.y + 20); cairo_show_text(cr, dialog->name); + cairo_move_to(cr, allocation.x, allocation.y + 40); + cairo_show_text(cr, "Change password"); + + cairo_move_to(cr, allocation.x, allocation.y + 60); + cairo_show_text(cr, "Change user"); + + cairo_move_to(cr, allocation.x, allocation.y + 80); + cairo_show_text(cr, "Login screen"); + cairo_destroy(cr); cairo_surface_destroy(surface); window_flush(window); @@ -453,74 +462,66 @@ dialog_create(struct display *display, const char *name) return dialog; } -#define FACES "/usr/share/pixmaps/faces/" -static const struct { - const char *icon; - const char *name; - const char *quote; - const char *username; -} users[] = { - { - "data/leon-kowalsky.png", - "Leon Kowalsky", - "\"Let me tell you about my mother.\"", - "leonk" - }, - - { - "data/roy-batty.png", - "Roy Batty", - "\"Gosh, you've... really got some nice toys here.\"", - "batty" - }, - - { - "data/rick-deckard.png", - "Rick Deckard", - "\"I made a bad joke. You're not a replicant.\"", - "rick" - }, -}; +#define ACCOUNT_ACTIVE 1 static void handle_stdin_data(struct task *task, uint32_t events) { - struct greeter *greeter; + struct greeter *greeter = NULL; struct dialog *dialog; struct rectangle allocation; struct application *application = container_of(task, struct application, stdin_task); char line[256], *arg; - int len, i, prefix; - - len = read(STDIN_FILENO, line, sizeof line); - line[len - 1] = '\0'; - fprintf(stderr, "greeter: read command \"%s\"\n", line); - - prefix = strcspn(line, "\n "); - line[prefix] = '\0'; - arg = line + prefix + 1; - - if (strcmp(line, "login") == 0) { - greeter = greeter_create(application->display); - - for (i = 0; i < ARRAY_LENGTH(users); i++) - greeter_add_item(greeter, users[i].icon, - users[i].name, - users[i].quote, - users[i].username); - - display_get_screen_allocation(application->display, - &allocation); - greeter_allocate(greeter, allocation.width, allocation.height); - greeter_set_background_image(greeter, "data/linen.png"); - } else if (strcmp(line, "sak-dialog") == 0) { - dialog = dialog_create(application->display, arg); - session_manager_show_dialog(application->session_manager, - window_get_wl_surface(dialog->window)); - - + char *icon = NULL, *name = NULL, *username = NULL, *quote = NULL; + int len, prefix; + uint32_t flags = 0; + + while (fgets(line, sizeof line, stdin)) { + len = strlen(line); + if (line[len - 1] == '\n') + line[len - 1] = '\0'; + fprintf(stderr, "greeter: read command \"%s\"\n", line); + + prefix = strcspn(line, "\n "); + line[prefix] = '\0'; + arg = line + prefix + 1; + + if (strcmp(line, "login") == 0) { + greeter = greeter_create(application->display); + } else if (strcmp(line, "sak-dialog") == 0) { + dialog = dialog_create(application->display, arg); + session_manager_show_dialog(application->session_manager, + window_get_wl_surface(dialog->window)); + } else if (strcmp(line, "run") == 0) { + display_get_screen_allocation(application->display, + &allocation); + greeter_allocate(greeter, allocation.width, allocation.height); + greeter_set_background_image(greeter, "data/linen.png"); + } else if (strcmp(line, "username") == 0) { + username = strdup(arg); + } else if (strcmp(line, "fullname") == 0) { + name = strdup(arg); + } else if (strcmp(line, "icon") == 0) { + icon = strdup(arg); + } else if (strcmp(line, "quote") == 0) { + quote = strdup(arg); + } else if (strcmp(line, "flags") == 0) { + if (strstr(arg, "active")) + flags |= ACCOUNT_ACTIVE; + } else if (strcmp(line, "add-user") == 0) { + greeter_add_item(greeter, icon, name, quote, username); + free(icon); + free(name); + free(username); + free(quote); + flags = 0; + } else { + fprintf(stderr, "unknown command \"%s\"\n", line); + } } + + fprintf(stderr, "done\n"); } int main(int argc, char *argv[]) diff --git a/clients/session-manager.c b/clients/session-manager.c index 34d56479..895e8978 100644 --- a/clients/session-manager.c +++ b/clients/session-manager.c @@ -112,7 +112,8 @@ toy_session_manager_launch(struct toy_session_manager *manager, return NULL;; } - if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, p) < 0) { + if (socketpair(AF_UNIX, + SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, p) < 0) { close(sv[0]); close(sv[1]); fprintf(stderr, "socketpair failed: %m\n"); @@ -270,11 +271,42 @@ toy_session_manager_handle_greeter_event(struct toy_session_manager *manager) } } +#define FACES "/usr/share/pixmaps/faces/" +static const struct { + const char *icon; + const char *name; + const char *quote; + const char *username; +} users[] = { + { + "data/leon-kowalsky.png", + "Leon Kowalsky", + "\"Let me tell you about my mother.\"", + "leonk" + }, + + { + "data/roy-batty.png", + "Roy Batty", + "\"Gosh, you've... really got some nice toys here.\"", + "batty" + }, + + { + "data/rick-deckard.png", + "Rick Deckard", + "\"I made a bad joke. You're not a replicant.\"", + "rick" + }, +}; + static struct toy_session_manager * toy_session_manager_create(void) { static char *const argv[] = { "./clients/greeter", NULL }; struct toy_session_manager *manager; + FILE *fp; + int i; manager = malloc(sizeof *manager); if (manager == NULL) @@ -292,7 +324,24 @@ toy_session_manager_create(void) manager->greeter = toy_session_manager_launch(manager, "@greeter", argv); - write(manager->greeter->fd, "login\n", 6); + fp = fdopen(dup(manager->greeter->fd), "w"); + fprintf(fp, "login\n"); + for (i = 0; i < ARRAY_LENGTH(users); i++) { + fprintf(fp, + "username %s\n" + "fullname %s\n" + "icon %s\n" + "quote %s\n" + "flags active\n" + "add-user\n", + users[i].username, + users[i].name, + users[i].icon, + users[i].quote); + } + + fprintf(fp, "run\n"); + fclose(fp); return manager; } |