Skip to content

Commit

Permalink
Let users choose a desired X display number
Browse files Browse the repository at this point in the history
  • Loading branch information
iphands committed Mar 28, 2024
1 parent 38ad694 commit 2c094fc
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 4 deletions.
1 change: 1 addition & 0 deletions common/configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 3 additions & 0 deletions src/seat-local.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 9 additions & 2 deletions src/seat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
2 changes: 2 additions & 0 deletions src/seat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 21 additions & 2 deletions src/x-server-local.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/x-server-local.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2c094fc

Please sign in to comment.