~kennylevinsen/gtkgreet

ebbca3c03a6418e690311224baf90a254d466aa8 — Kenny Levinsen 4 months ago ffdf607
Add support for background images
4 files changed, 22 insertions(+), 2 deletions(-)

M gtkgreet/gtkgreet.h
M gtkgreet/main.c
M gtkgreet/window.c
M gtkgreet/window.h
M gtkgreet/gtkgreet.h => gtkgreet/gtkgreet.h +1 -0
@@ 19,6 19,7 @@ struct Window;
struct GtkGreet {
    GtkApplication *app;
    GArray *windows;
    GdkPixbuf *background;

    struct Window *focused_window;
    guint draw_clock_source;

M gtkgreet/main.c => gtkgreet/main.c +9 -1
@@ 9,6 9,7 @@
struct GtkGreet *gtkgreet = NULL;

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

#ifdef LAYER_SHELL
static gboolean use_layer_shell = FALSE;


@@ 21,7 22,7 @@ static GOptionEntry entries[] =
  { "layer-shell", 'l', 0, G_OPTION_ARG_NONE, &use_layer_shell, "Use layer shell", NULL},
  { "command", 'c', 0, G_OPTION_ARG_STRING, &command, "Command to run", "sway"},
#endif

  { "background", 'b', 0, G_OPTION_ARG_STRING, &background, "Background image to use", NULL},
  { NULL }
};



@@ 118,6 119,13 @@ int main (int argc, char **argv) {
#endif
    gtkgreet->command = command;

    if (background != NULL) {
        gtkgreet->background = gdk_pixbuf_new_from_file(background, &error);
        if (gtkgreet->background == NULL) {
            g_print("background loading failed: %s\n", error->message);
        }
    }

    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 +11 -0
@@ 291,6 291,13 @@ void window_configure(struct Window *w) {
    gtk_widget_show_all(w->window);
}


static gboolean window_background(GtkWidget *widget, cairo_t *cr, gpointer data) {
    gdk_cairo_set_source_pixbuf(cr, gtkgreet->background, 0, 0);
    cairo_paint(cr);
    return FALSE;
}

struct Window *create_window(GdkMonitor *monitor) {
    struct Window *w = calloc(1, sizeof(struct Window));
    if (w == NULL) {


@@ 305,5 312,9 @@ struct Window *create_window(GdkMonitor *monitor) {
    gtk_window_set_title(GTK_WINDOW(w->window), "Greeter");
    gtk_window_set_default_size(GTK_WINDOW(w->window), 200, 200);

    if (gtkgreet->background != NULL) {
        gtk_widget_set_app_paintable(w->window, TRUE);
        g_signal_connect(w->window, "draw", G_CALLBACK(window_background), NULL);
    }
    return w;
}

M gtkgreet/window.h => gtkgreet/window.h +1 -1
@@ 31,4 31,4 @@ void window_setup_question(struct Window *ctx, enum QuestionType type, char* que
void window_update_clock(struct Window *ctx);
void window_swap_focus(struct Window *win, struct Window *old);

#endif
\ No newline at end of file
#endif