From bfb99d8737fd6c62fa24c6980a4d916008de17c4 Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Sat, 6 May 2023 03:09:41 +0200 Subject: src/arctica-greeter.vala: Add D-Bus server with methods needed by the keyboard indicator --- src/arctica-greeter.vala | 98 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/arctica-greeter.vala b/src/arctica-greeter.vala index 9911f87..4a38248 100644 --- a/src/arctica-greeter.vala +++ b/src/arctica-greeter.vala @@ -36,7 +36,7 @@ public class ArcticaGreeter : Object public bool test_bigfont { get; construct; default = false; } private string state_file; private KeyFile state; - + private DBusServer pServer; private Cairo.XlibSurface background_surface; private SettingsDaemon settings_daemon; @@ -57,9 +57,25 @@ public class ArcticaGreeter : Object construct { + Bus.own_name (BusType.SESSION, "org.ArcticaProject.ArcticaGreeter", BusNameOwnerFlags.NONE, onBusAcquired); + greeter = new LightDM.Greeter (); greeter.show_message.connect ((text, type) => { show_message (text, type); }); - greeter.show_prompt.connect ((text, type) => { show_prompt (text, type); }); + + greeter.show_prompt.connect ((text, type) => + { + try + { + this.pServer.sendUserChange (); + } + catch (Error pError) + { + error ("Panic: %s", pError.message); + } + + show_prompt (text, type); + }); + greeter.autologin_timer_expired.connect (() => { try { @@ -129,6 +145,19 @@ public class ArcticaGreeter : Object ); } + private void onBusAcquired (DBusConnection pConnection) + { + try + { + this.pServer = new DBusServer (pConnection, this.greeter); + pConnection.register_object ("/org/ArcticaProject/ArcticaGreeter", this.pServer); + } + catch (IOError pError) + { + error ("%s\n", pError.message); + } + } + public void go () { /* Render things after xsettings is ready */ @@ -1268,3 +1297,68 @@ private interface SettingsDaemonDBusInterface : Object public signal void plugin_activated (string name); public signal void plugin_deactivated (string name); } + +[DBus (name = "org.ArcticaProject.ArcticaGreeter")] +public class DBusServer : Object +{ + private DBusConnection pConnection; + private LightDM.Greeter pGreeter; + + public DBusServer (DBusConnection pConnection, LightDM.Greeter pGreeter) + { + this.pConnection = pConnection; + this.pGreeter = pGreeter; + } + + public void sendUserChange () throws GLib.DBusError, GLib.IOError + { + string sUser = this.pGreeter.get_authentication_user (); + + if (sUser == null) + { + sUser = "GUEST"; + } + + Variant pUser = new Variant ("(s)", sUser); + + try + { + this.pConnection.emit_signal (null, "/org/ArcticaProject/ArcticaGreeter", "org.ArcticaProject.ArcticaGreeter", "UserChanged", pUser); + } + catch (Error pError) + { + error ("Panic: Could not send user change signal: %s", pError.message); + } + } + + public string GetUser () throws GLib.DBusError, GLib.IOError + { + string sUser = this.pGreeter.get_authentication_user (); + + if (sUser == null) + { + sUser = "GUEST"; + } + + return sUser; + } + + public void SetLayout (string sLanguage, string sVariant) throws GLib.DBusError, GLib.IOError + { + string sCommand = "setxkbmap -layout %s".printf (sLanguage); + + if (sVariant != "") + { + sCommand = "%s -variant %s".printf (sCommand, sVariant); + } + + try + { + Process.spawn_command_line_sync (sCommand, null, null, null); + } + catch (Error pError) + { + error ("Panic: Could not set keyboard layout: %s", pError.message); + } + } +} -- cgit v1.2.3