From 1c150a74abe1fa91d353903e5122ec6895bf23fd Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Fri, 5 May 2023 03:41:42 +0200 Subject: Fix error handlers for D-Bus methods --- src/arctica-greeter.vala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/arctica-greeter.vala') diff --git a/src/arctica-greeter.vala b/src/arctica-greeter.vala index 3ba2ff4..82d679e 100644 --- a/src/arctica-greeter.vala +++ b/src/arctica-greeter.vala @@ -2,6 +2,7 @@ * * Copyright (C) 2011 Canonical Ltd * Copyright (C) 2015-2017 Mike Gabriel + * Copyright (C) 2023 Robert Tari * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -17,6 +18,7 @@ * * Authors: Robert Ancell * Mike Gabriel + * Robert Tari */ public const int grid_size = 40; @@ -1243,12 +1245,12 @@ public class DialogDBusInterface : Object public signal void open_dialog (uint32 type); public signal void close_dialog (); - public void open (uint32 type, uint32 timestamp, uint32 seconds_to_stay_open, ObjectPath[] inhibitor_object_paths) + public void open (uint32 type, uint32 timestamp, uint32 seconds_to_stay_open, ObjectPath[] inhibitor_object_paths) throws GLib.DBusError, GLib.IOError { open_dialog (type); } - public void close () + public void close () throws GLib.DBusError, GLib.IOError { close_dialog (); } -- cgit v1.2.3 From 0718f264357a13b1a55cadcb7eb6a5774b7dd7eb Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Fri, 5 May 2023 05:19:44 +0200 Subject: Fix casting issues --- src/arctica-greeter.vala | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/arctica-greeter.vala') diff --git a/src/arctica-greeter.vala b/src/arctica-greeter.vala index 82d679e..9911f87 100644 --- a/src/arctica-greeter.vala +++ b/src/arctica-greeter.vala @@ -592,7 +592,10 @@ public class ArcticaGreeter : Object /* Check to see if this window is our onboard window, since we don't want to focus it. */ X.Window keyboard_xid = 0; if (main_window.menubar.keyboard_window != null) - keyboard_xid = (main_window.menubar.keyboard_window.get_window () as Gdk.X11.Window).get_xid (); + { + Gdk.X11.Window pWindow = (Gdk.X11.Window) main_window.menubar.keyboard_window.get_window (); + keyboard_xid = pWindow.get_xid (); + } if (xwin != keyboard_xid && win.get_type_hint() != Gdk.WindowTypeHint.NOTIFICATION) { @@ -650,20 +653,22 @@ public class ArcticaGreeter : Object private static Cairo.XlibSurface? create_root_surface (Gdk.Screen screen) { var visual = screen.get_system_visual (); - - unowned X.Display display = (screen.get_display () as Gdk.X11.Display).get_xdisplay (); - unowned X.Screen xscreen = (screen as Gdk.X11.Screen).get_xscreen (); + Gdk.X11.Display pDisplay = (Gdk.X11.Display) screen.get_display (); + unowned X.Display display = pDisplay.get_xdisplay (); + Gdk.X11.Screen pScreen = (Gdk.X11.Screen) screen; + unowned X.Screen xscreen = pScreen.get_xscreen (); var pixmap = X.CreatePixmap (display, - (screen.get_root_window () as Gdk.X11.Window).get_xid (), + ((Gdk.X11.Window) (screen.get_root_window ())).get_xid (), xscreen.width_of_screen (), xscreen.height_of_screen (), visual.get_depth ()); /* Convert into a Cairo surface */ + Gdk.X11.Visual pVisual = (Gdk.X11.Visual) visual; var surface = new Cairo.XlibSurface (display, pixmap, - (visual as Gdk.X11.Visual).get_xvisual (), + pVisual.get_xvisual (), xscreen.width_of_screen (), xscreen.height_of_screen ()); return surface; @@ -1223,7 +1228,8 @@ public class ArcticaGreeter : Object } var screen = Gdk.Screen.get_default (); - unowned X.Display xdisplay = (screen.get_display () as Gdk.X11.Display).get_xdisplay (); + Gdk.X11.Display pDisplay = (Gdk.X11.Display) screen.get_display (); + unowned X.Display xdisplay = pDisplay.get_xdisplay (); var window = xdisplay.default_root_window(); var atom = xdisplay.intern_atom ("AT_SPI_BUS", true); -- cgit v1.2.3 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/arctica-greeter.vala') 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