From 2c094fc8f3db2a51d5b916140e5984624cb4d5d1 Mon Sep 17 00:00:00 2001 From: Ian Page Hands Date: Wed, 27 Mar 2024 21:19:25 -0700 Subject: [PATCH 1/3] Let users choose a desired X display number --- common/configuration.c | 1 + src/seat-local.c | 3 +++ src/seat.c | 11 +++++++++-- src/seat.h | 2 ++ src/x-server-local.c | 23 +++++++++++++++++++++-- src/x-server-local.h | 2 ++ 6 files changed, 38 insertions(+), 4 deletions(-) diff --git a/common/configuration.c b/common/configuration.c index 30580ead..c277416f 100644 --- a/common/configuration.c +++ b/common/configuration.c @@ -354,6 +354,7 @@ config_init (Configuration *config) g_hash_table_insert (config->priv->seat_keys, "pam-greeter-service", GINT_TO_POINTER (KEY_SUPPORTED)); g_hash_table_insert (config->priv->seat_keys, "xserver-backend", GINT_TO_POINTER (KEY_DEPRECATED)); g_hash_table_insert (config->priv->seat_keys, "xserver-command", GINT_TO_POINTER (KEY_SUPPORTED)); + g_hash_table_insert (config->priv->seat_keys, "desired-display-number", GINT_TO_POINTER (KEY_SUPPORTED)); g_hash_table_insert (config->priv->seat_keys, "xmir-command", GINT_TO_POINTER (KEY_SUPPORTED)); g_hash_table_insert (config->priv->seat_keys, "xserver-config", GINT_TO_POINTER (KEY_SUPPORTED)); g_hash_table_insert (config->priv->seat_keys, "xserver-layout", GINT_TO_POINTER (KEY_SUPPORTED)); diff --git a/src/seat-local.c b/src/seat-local.c index 142dbaf5..44850c88 100644 --- a/src/seat-local.c +++ b/src/seat-local.c @@ -151,6 +151,9 @@ create_x_server (SeatLocal *seat) { g_autoptr(XServerLocal) x_server = x_server_local_new (); + gint desired_display_number = seat_get_integer_property_with_fallback (SEAT (seat), "desired-display-number", -1); + x_server_local_init_display_number (x_server, desired_display_number); + gint vt = get_vt (seat, DISPLAY_SERVER (x_server)); if (vt >= 0) x_server_local_set_vt (x_server, vt); diff --git a/src/seat.c b/src/seat.c index 0b55906c..9fd5109c 100644 --- a/src/seat.c +++ b/src/seat.c @@ -180,10 +180,17 @@ seat_get_boolean_property (Seat *seat, const gchar *name) } gint -seat_get_integer_property (Seat *seat, const gchar *name) +seat_get_integer_property_with_fallback (Seat *seat, const gchar *name, gint fallback) { const gchar *value = seat_get_string_property (seat, name); - return value ? atoi (value) : 0; + return value ? atoi (value) : fallback; +} + + +gint +seat_get_integer_property (Seat *seat, const gchar *name) +{ + return seat_get_integer_property_with_fallback (seat, name, 0); } const gchar * diff --git a/src/seat.h b/src/seat.h index 31cd05a2..772c0d8a 100644 --- a/src/seat.h +++ b/src/seat.h @@ -75,6 +75,8 @@ gchar **seat_get_string_list_property (Seat *seat, const gchar *name); gboolean seat_get_boolean_property (Seat *seat, const gchar *name); +gint seat_get_integer_property_with_fallback (Seat *seat, const gchar *name, gint fallback); + gint seat_get_integer_property (Seat *seat, const gchar *name); const gchar *seat_get_name (Seat *seat); diff --git a/src/x-server-local.c b/src/x-server-local.c index 6c540d18..eaa7dca5 100644 --- a/src/x-server-local.c +++ b/src/x-server-local.c @@ -154,8 +154,16 @@ display_number_in_use (guint display_number) } static guint -x_server_local_get_unused_display_number (void) +x_server_local_get_unused_display_number (gint desired_display_number) { + // First attempt to use the requested display number + if (desired_display_number >= 0) { + if (!display_number_in_use (desired_display_number)) { + return desired_display_number; + } + } + + // Else fall back guint number = config_get_integer (config_get_instance (), "LightDM", "minimum-display-number"); while (display_number_in_use (number)) number++; @@ -194,6 +202,16 @@ x_server_local_set_command (XServerLocal *server, const gchar *command) priv->command = g_strdup (command); } +void +x_server_local_init_display_number (XServerLocal *server, gint number) +{ + XServerLocalPrivate *priv = x_server_local_get_instance_private (server); + g_return_if_fail (server != NULL); + + priv->display_number = x_server_local_get_unused_display_number (number); + l_debug (server, "Requested display number %d, actual display number: %d", number, priv->display_number); +} + void x_server_local_set_vt (XServerLocal *server, gint vt) { @@ -574,9 +592,10 @@ static void x_server_local_init (XServerLocal *server) { XServerLocalPrivate *priv = x_server_local_get_instance_private (server); + priv->vt = -1; priv->command = g_strdup ("X"); - priv->display_number = x_server_local_get_unused_display_number (); + priv->display_number = -1; } static void diff --git a/src/x-server-local.h b/src/x-server-local.h index 9eda19f4..512937b8 100644 --- a/src/x-server-local.h +++ b/src/x-server-local.h @@ -45,6 +45,8 @@ XServerLocal *x_server_local_new (void); void x_server_local_set_command (XServerLocal *server, const gchar *command); +void x_server_local_init_display_number (XServerLocal *server, gint number); + void x_server_local_set_vt (XServerLocal *server, gint vt); void x_server_local_set_config (XServerLocal *server, const gchar *path); From 41d2b0c7d146377d02053b2ab001ba1230ccb3a8 Mon Sep 17 00:00:00 2001 From: Ian Page Hands Date: Wed, 27 Mar 2024 21:36:40 -0700 Subject: [PATCH 2/3] Add note in lightdm.conf --- data/lightdm.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/data/lightdm.conf b/data/lightdm.conf index 60e3e8b4..8d9c0514 100644 --- a/data/lightdm.conf +++ b/data/lightdm.conf @@ -56,6 +56,7 @@ # xserver-share = True if the X server is shared for both greeter and session # xserver-hostname = Hostname of X server (only for type=xremote) # xserver-display-number = Display number of X server (only for type=xremote) +# desired-display-number = The display number you wish to have this seat have, if it is already used the next available will be used # xdmcp-manager = XDMCP manager to connect to (implies xserver-allow-tcp=true) # xdmcp-port = XDMCP UDP/IP port to communicate on # xdmcp-key = Authentication key to use for XDM-AUTHENTICATION-1 (stored in keys.conf) From f02d9660aaa99f2615c088c85d050d747a492c67 Mon Sep 17 00:00:00 2001 From: Ian Page Hands Date: Thu, 28 Mar 2024 10:05:04 -0700 Subject: [PATCH 3/3] Empty commit to re-trigger CLA check