logind: call SetType on the logind session

This allows manual handling of IdleAction and IdleHint rather than automatically
calling the IdleAction every IdleSecs, due to inactivity on the underlying tty.
Fixes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1194

Signed-off-by: aarondill <aaronsacks2006@gmail.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
Aaron Dill 2023-06-12 22:48:03 +00:00 committed by Peter Hutterer
parent 13e513d2f0
commit 2260dea7d8

View File

@ -444,6 +444,7 @@ message_filter(DBusConnection * connection, DBusMessage * message, void *data)
static void
connect_hook(DBusConnection *connection, void *data)
{
const char *session_type = "x11";
struct systemd_logind_info *info = data;
DBusError error;
DBusMessage *msg = NULL;
@ -510,6 +511,33 @@ connect_hook(DBusConnection *connection, void *data)
error.message);
goto cleanup;
}
dbus_message_unref(msg);
dbus_message_unref(reply);
reply = NULL;
msg = dbus_message_new_method_call("org.freedesktop.login1",
session, "org.freedesktop.login1.Session", "SetType");
if (!msg) {
LogMessage(X_ERROR, "systemd-logind: out of memory\n");
goto cleanup;
}
if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &session_type,
DBUS_TYPE_INVALID)) {
LogMessage(X_ERROR, "systemd-logind: out of memory\n");
goto cleanup;
}
reply = dbus_connection_send_with_reply_and_block(connection, msg,
DBUS_TIMEOUT_USE_DEFAULT, &error);
/* Requires systemd >= 246, SetType() is not critical for xserver function */
if (!reply) {
/* unprevileged users get access denied rather than unknown method */
if (!dbus_error_has_name(&error, DBUS_ERROR_ACCESS_DENIED) &&
!dbus_error_has_name(&error, DBUS_ERROR_UNKNOWN_METHOD))
LogMessage(X_WARNING, "systemd-logind: SetType failed: %s\n", error.message);
dbus_error_free(&error);
}
dbus_bus_add_match(connection,
"type='signal',sender='org.freedesktop.login1',interface='org.freedesktop.login1.Session',member='PauseDevice'",