Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions data/lightdm-mini-greeter.conf
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ border-width = 2px
# The pixels of empty space around the password input.
# Do not include a trailing `px`.
layout-space = 15
# Relative position of password window on screen (give value between 0.0 and 1.0)
window-position-x = 0.5
window-position-y = 0.5
# The color of the text in the password input.
password-color = "#F8F8F0"
# The background color of the password input.
Expand Down
21 changes: 21 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

static GdkRGBA *parse_greeter_color_key(GKeyFile *keyfile, const char *key_name);
static guint parse_greeter_hotkey_keyval(GKeyFile *keyfile, const char *key_name);
static gdouble get_relative_position(GKeyFile *keyfile, const char *axis);

/* Initialize the configuration, sourcing the greeter's configuration file */
Config *initialize_config(void)
Expand Down Expand Up @@ -96,6 +97,8 @@ Config *initialize_config(void)
config->layout_spacing = (guint) layout_spacing;
}

config->position_x = get_relative_position(keyfile, "x");
config->position_y = get_relative_position(keyfile, "y");

g_key_file_free(keyfile);

Expand Down Expand Up @@ -157,3 +160,21 @@ static guint parse_greeter_hotkey_keyval(GKeyFile *keyfile, const char *key_name

return gdk_unicode_to_keyval((guint) key[0]);
}

/* Get relative window position double value, return 0.5 if missing or unable to parse */
static gdouble get_relative_position(GKeyFile *keyfile, const char *axis) {
g_autoptr(GError) error = NULL;
char key[80];
gdouble pos = g_key_file_get_double(
keyfile,
"greeter-theme",
strcat(strcpy(key, "window-position-"), axis),
&error);

if (error != NULL || pos < 0.0 || pos > 1.0) {
g_message("Error while parsing window-position-%s", axis);
pos = 0.5;
}

return pos;
}
2 changes: 2 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ typedef struct Config_ {
GdkRGBA *border_color;
gchar *border_width;
guint layout_spacing;
gdouble position_x;
gdouble position_y;
// Password Input
GdkRGBA *password_color;
GdkRGBA *password_background_color;
Expand Down
15 changes: 10 additions & 5 deletions src/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static void setup_main_window(Config *config, UI *ui)
gtk_container_set_border_width(GTK_CONTAINER(main_window), config->layout_spacing);
gtk_widget_set_name(GTK_WIDGET(main_window), "main");

g_signal_connect(main_window, "show", G_CALLBACK(place_main_window), NULL);
g_signal_connect(main_window, "show", G_CALLBACK(place_main_window), config);
g_signal_connect(main_window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

ui->main_window = main_window;
Expand All @@ -144,15 +144,20 @@ static void place_main_window(GtkWidget *main_window, gpointer user_data)
GdkMonitor *primary_monitor = gdk_display_get_primary_monitor(display);
GdkRectangle primary_monitor_geometry;
gdk_monitor_get_geometry(primary_monitor, &primary_monitor_geometry);
Config *config = (Config *) user_data;

// Get the Geometry of the Window
gint window_width, window_height;
gtk_window_get_size(GTK_WINDOW(main_window), &window_width, &window_height);

gtk_window_move(
GTK_WINDOW(main_window),
primary_monitor_geometry.x + primary_monitor_geometry.width / 2 - window_width / 2,
primary_monitor_geometry.y + primary_monitor_geometry.height / 2 - window_height / 2);
gint offset_x = primary_monitor_geometry.x
+ (gint) (primary_monitor_geometry.width * config->position_x)
- window_width / 2;
gint offset_y = primary_monitor_geometry.y
+ (gint) (primary_monitor_geometry.height * config->position_y)
- window_height / 2;

gtk_window_move(GTK_WINDOW(main_window), offset_x, offset_y);
}


Expand Down