X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Flogind-user.c;h=fdbccb364c1814f45d07249253c9107b8bbee8c7;hb=952d32609f9bceee444fa2690afb4d28539b4b92;hp=5fffa651a32508c7728962ebd9b082455fe179c1;hpb=2be6107255c3cf47bb5a9eddf2411953f29522e1;p=elogind.git diff --git a/src/login/logind-user.c b/src/login/logind-user.c index 5fffa651a..fdbccb364 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -713,6 +713,43 @@ int user_kill(User *u, int signo) { return manager_kill_unit(u->manager, u->slice, KILL_ALL, signo, NULL); } +void user_elect_display(User *u) { + Session *graphical = NULL, *text = NULL, *s; + + assert(u); + + /* This elects a primary session for each user, which we call + * the "display". We try to keep the assignment stable, but we + * "upgrade" to better choices. */ + + LIST_FOREACH(sessions_by_user, s, u->sessions) { + + if (s->class != SESSION_USER) + continue; + + if (s->stopping) + continue; + + if (SESSION_TYPE_IS_GRAPHICAL(s->type)) + graphical = s; + else + text = s; + } + + if (graphical && + (!u->display || + u->display->class != SESSION_USER || + u->display->stopping || + !SESSION_TYPE_IS_GRAPHICAL(u->display->type))) + u->display = graphical; + + if (text && + (!u->display || + u->display->class != SESSION_USER || + u->display->stopping)) + u->display = text; +} + static const char* const user_state_table[_USER_STATE_MAX] = { [USER_OFFLINE] = "offline", [USER_OPENING] = "opening",