From ba46af16e693fa86f9270d5e9135a2381a8a62f9 Mon Sep 17 00:00:00 2001 From: Clement Lefebvre Date: Tue, 20 Jun 2017 15:20:08 +0200 Subject: Add support for validating session names (and proper fallback for uninstalled sessions). Ported from slick-greeter. --- src/arctica-greeter.vala | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/greeter-list.vala | 2 +- src/user-list.vala | 2 +- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/arctica-greeter.vala b/src/arctica-greeter.vala index 9b5d279..eb42306 100644 --- a/src/arctica-greeter.vala +++ b/src/arctica-greeter.vala @@ -181,6 +181,52 @@ public class ArcticaGreeter ctx.add_class ("lightdm"); } + public static string? get_default_session () + { + var sessions = new List (); + sessions.append ("lightdm-xsession"); + + // FIXME: this list should be obtained from AGSettings, ideally... + sessions.append ("mate"); + sessions.append ("xfce"); + sessions.append ("kde-plasma"); + sessions.append ("kde"); + sessions.append ("gnome"); + sessions.append ("cinnamon"); + + foreach (string session in sessions) { + var path = Path.build_filename ("/usr/share/xsessions/", session.concat(".desktop"), null); + if (FileUtils.test (path, FileTest.EXISTS)) { + return session; + } + } + + warning ("Could not find a default session."); + return null; + } + + public static string validate_session (string? session) + { + /* Make sure the given session actually exists. Return it if it does. + * otherwise, return the default session. + */ + if (session != null) { + var path = Path.build_filename ("/usr/share/xsessions/", session.concat(".desktop"), null); + if (!FileUtils.test (path, FileTest.EXISTS) ) { + debug ("Invalid session: '%s'", session); + session = null; + } + } + + if (session == null) { + var default_session = ArcticaGreeter.get_default_session (); + debug ("Invalid session: '%s'. Using session '%s' instead.", session, default_session); + return default_session; + } + + return session; + } + public bool start_session (string? session, Background bg) { /* Explicitly set the right scale before closing window */ diff --git a/src/greeter-list.vala b/src/greeter-list.vala index 17d80a8..8e25602 100644 --- a/src/greeter-list.vala +++ b/src/greeter-list.vala @@ -947,7 +947,7 @@ public abstract class GreeterList : FadableBox protected virtual string get_lightdm_session () { - return "ubuntu"; + return ArcticaGreeter.get_default_session (); } /* Testing code below this */ diff --git a/src/user-list.vala b/src/user-list.vala index ad68a17..319e833 100644 --- a/src/user-list.vala +++ b/src/user-list.vala @@ -859,7 +859,7 @@ public class UserList : GreeterList } e.background = background; e.is_active = is_active; - e.session = session; + e.session = ArcticaGreeter.validate_session(session); e.label = label; e.set_show_message_icon (has_messages); e.set_is_active (is_active); -- cgit v1.2.3