diff options
author | Robert Tari <robert@tari.in> | 2023-05-06 03:09:41 +0200 |
---|---|---|
committer | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2023-05-07 20:52:13 +0200 |
commit | bfb99d8737fd6c62fa24c6980a4d916008de17c4 (patch) | |
tree | 1043bc53c1bb25d386d7ebd59bb9637aa50f204c /src | |
parent | 36ac6b17fe6e4087c49b636123071bdfc1533f5a (diff) | |
download | arctica-greeter-bfb99d8737fd6c62fa24c6980a4d916008de17c4.tar.gz arctica-greeter-bfb99d8737fd6c62fa24c6980a4d916008de17c4.tar.bz2 arctica-greeter-bfb99d8737fd6c62fa24c6980a4d916008de17c4.zip |
src/arctica-greeter.vala: Add D-Bus server with methods needed by the keyboard indicator
Diffstat (limited to 'src')
-rw-r--r-- | src/arctica-greeter.vala | 98 |
1 files changed, 96 insertions, 2 deletions
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); + } + } +} |