~kennylevinsen/gtkgreet

90424c865f3b8509ec684a987c76599e697fbb83 — Aleksei Bavshin a month ago 24f826f
Add support for user CSS styles.

Add a few element names to simplify styling.

Example with transparent bg and swaybg (for Adwaita-dark theme):
window { background-color: transparent; }
box#body {
    background-color: #353535;
    box-shadow: 1 0 0 1px rgba(27, 27, 27, 0.9);
    padding: 50px;
}

Example with background-image:
window {
  background-image: url("file:///usr/share/backgrounds/default.png");
  background-size: cover;
  background-position: center;
}
box#body {
    background-color: #353535;
    box-shadow: 1 0 0 1px rgba(27, 27, 27, 0.9);
    padding: 50px;
}
2 files changed, 24 insertions(+), 0 deletions(-)

M gtkgreet/main.c
M gtkgreet/window.c
M gtkgreet/main.c => gtkgreet/main.c +21 -0
@@ 10,6 10,7 @@ struct GtkGreet *gtkgreet = NULL;

static char* command = NULL;
static char* background = NULL;
static char* style = NULL;

#ifdef LAYER_SHELL
static gboolean use_layer_shell = FALSE;


@@ 23,6 24,7 @@ static GOptionEntry entries[] =
#endif
  { "command", 'c', 0, G_OPTION_ARG_STRING, &command, "Command to run", "sway"},
  { "background", 'b', 0, G_OPTION_ARG_STRING, &background, "Background image to use", NULL},
  { "style", 's', 0, G_OPTION_ARG_FILENAME, &style, "CSS style to use", NULL },
  { NULL }
};



@@ 101,6 103,21 @@ static void activate(GtkApplication *app, gpointer user_data) {
    }
}

static void attach_custom_style(const char* path) {
    GtkCssProvider *provider = gtk_css_provider_new();
    GError *err = NULL;

    gtk_css_provider_load_from_path(provider, path, &err);
    if (err != NULL) {
        g_warning("style loading failed: %s", err->message);
        g_error_free(err);
    } else {
        gtk_style_context_add_provider_for_screen(gdk_screen_get_default(),
                GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
    }
    g_object_unref(provider);
}

int main (int argc, char **argv) {
    GError *error = NULL;
    GOptionContext *option_context = g_option_context_new("- GTK-based greeter for greetd");


@@ 125,6 142,10 @@ int main (int argc, char **argv) {
        }
    }

    if (style != NULL) {
        attach_custom_style(style);
    }

    g_signal_connect(gtkgreet->app, "activate", G_CALLBACK(activate), NULL);

    int status = g_application_run(G_APPLICATION(gtkgreet->app), argc, argv);

M gtkgreet/window.c => gtkgreet/window.c +3 -0
@@ 199,9 199,11 @@ static void window_setup(struct Window *ctx) {

    if (ctx->window_box == NULL) {
        ctx->window_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
        gtk_widget_set_name(ctx->window_box, "window");
        gtk_container_add(GTK_CONTAINER(ctx->revealer), ctx->window_box);

        ctx->clock_label = gtk_label_new("");
        gtk_widget_set_name(ctx->clock_label, "clock");
        g_object_set(ctx->clock_label, "margin-bottom", 10, NULL);
        gtk_container_add(GTK_CONTAINER(ctx->window_box), ctx->clock_label);
        window_update_clock(ctx);


@@ 212,6 214,7 @@ static void window_setup(struct Window *ctx) {
        if (ctx->body == NULL) {
            ctx->body = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
            gtk_widget_set_halign(ctx->body, GTK_ALIGN_CENTER);
            gtk_widget_set_name(ctx->body, "body");
            gtk_widget_set_size_request(ctx->body, 384, -1);
            gtk_container_add(GTK_CONTAINER(ctx->window_box), ctx->body);
            window_update_clock(ctx);