~kennylevinsen/greetd-devel

gtkgreet: Add support for user CSS styles. v1 APPLIED

Aleksei Bavshin: 1
 Add support for user CSS styles.

 2 files changed, 24 insertions(+), 0 deletions(-)
#399993 .build.yml failed
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~kennylevinsen/greetd-devel/patches/19642/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH gtkgreet] Add support for user CSS styles. Export this patch

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;
}
---
 gtkgreet/main.c   | 21 +++++++++++++++++++++
 gtkgreet/window.c |  3 +++
 2 files changed, 24 insertions(+)

diff --git a/gtkgreet/main.c b/gtkgreet/main.c
index 78f1018..2535592 100644
--- a/gtkgreet/main.c
+++ b/gtkgreet/main.c
@@ -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");
@@ -127,6 +144,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);
diff --git a/gtkgreet/window.c b/gtkgreet/window.c
index 86e6223..c4cd283 100644
--- a/gtkgreet/window.c
+++ b/gtkgreet/window.c
@@ -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);
-- 
2.28.0
Applied, thanks!