From cd61e73f20bff70a44ab6a74229c0e543c4787fc Mon Sep 17 00:00:00 2001 From: Scoopta Date: Tue, 28 Jul 2020 16:18:44 -0700 Subject: [PATCH] v1.2.1: widget_builder now only lets you assign classes. The name will be consistent with the image escape system --- inc/widget_builder_api.h | 4 ++-- man/wofi-widget-builder.3 | 10 +++++----- meson.build | 2 +- modes/drun.c | 6 +++--- src/widget_builder.c | 32 ++++++++++++++++++++++++-------- 5 files changed, 35 insertions(+), 19 deletions(-) diff --git a/inc/widget_builder_api.h b/inc/widget_builder_api.h index dd26d33..3c07767 100644 --- a/inc/widget_builder_api.h +++ b/inc/widget_builder_api.h @@ -30,9 +30,9 @@ void wofi_widget_builder_set_search_text(struct widget_builder* builder, char* s void wofi_widget_builder_set_action(struct widget_builder* builder, char* action); -void wofi_widget_builder_insert_text(struct widget_builder* builder, const char* text, char* css_name); +__attribute__((sentinel)) void wofi_widget_builder_insert_text(struct widget_builder* builder, const char* text, ...); -void wofi_widget_builder_insert_image(struct widget_builder* builder, GdkPixbuf* pixbuf, char* css_name); +__attribute__((sentinel)) void wofi_widget_builder_insert_image(struct widget_builder* builder, GdkPixbuf* pixbuf, ...); struct widget_builder* wofi_widget_builder_get_idx(struct widget_builder* builder, size_t idx); diff --git a/man/wofi-widget-builder.3 b/man/wofi-widget-builder.3 index 67a3b9c..202a527 100644 --- a/man/wofi-widget-builder.3 +++ b/man/wofi-widget-builder.3 @@ -36,7 +36,7 @@ Sets the action for the widget specified by the builder \- The text to set as the action .TP -.B void wofi_widget_builder_insert_text(struct widget_builder* builder, char* text, char* css_name) +.B void wofi_widget_builder_insert_text(struct widget_builder* builder, char* text, ...) Inserts text into the widget specified by the builder .B struct widget_builder* builder @@ -45,8 +45,8 @@ Inserts text into the widget specified by the builder .B char* text \- The text to add to the widget -.B char* css_name -\- The name of the CSS node for this text. The name that will be assigned is #mode_name-css_name where mode_name is the name of the mode, i.e. drun etc. +.B ... +\- The names of the CSS classes for this text. The class that will be assigned is .mode_name-css_name where mode_name is the name of the mode, i.e. drun etc. This should have a NULL sentinel .TP .B void wofi_widget_builder_insert_image(struct widget_builder* builder, GdkPixbuf* pixbuf, char* css_name) @@ -58,8 +58,8 @@ Inserts an image into the widget specified by the builder .B GdkPixbuf* pixbuf \- The image to add to the widget -.B char* css_name -\- The name of the CSS node for this image. The name that will be assigned is #mode_name-css_name where mode_name is the name of the mode, i.e. drun etc. +.B ... +\- The names of the CSS classes for this image. The class that will be assigned is .mode_name-css_name where mode_name is the name of the mode, i.e. drun etc. This should have a NULL sentinel .TP .B struct widget_builder* wofi_widget_builder_get_idx(struct widget_builder* builder, size_t idx) diff --git a/meson.build b/meson.build index 7a15e2b..e88de6e 100644 --- a/meson.build +++ b/meson.build @@ -1,4 +1,4 @@ -project('wofi', 'c', version : 'v1.2', default_options : ['c_std=c99', 'buildtype=release', 'warning_level=2']) +project('wofi', 'c', version : 'v1.2.1', default_options : ['c_std=c99', 'buildtype=release', 'warning_level=2']) cc = meson.get_compiler('c') pkgcfg = import('pkgconfig') diff --git a/modes/drun.c b/modes/drun.c index f3ae876..30934cd 100644 --- a/modes/drun.c +++ b/modes/drun.c @@ -121,11 +121,11 @@ static bool populate_widget(char* file, char* action, struct widget_builder* bui pixbuf = utils_g_resize_pixbuf(pixbuf, wofi_get_image_size() * wofi_get_window_scale(), GDK_INTERP_BILINEAR); - wofi_widget_builder_insert_image(builder, pixbuf, "icon"); + wofi_widget_builder_insert_image(builder, pixbuf, "icon", NULL); g_object_unref(pixbuf); } - wofi_widget_builder_insert_text(builder, name, "name"); - wofi_widget_builder_insert_text(builder, generic_name, "generic-name"); + wofi_widget_builder_insert_text(builder, name, "name", NULL); + wofi_widget_builder_insert_text(builder, generic_name, "generic-name", NULL); free(generic_name); if(action == NULL) { diff --git a/src/widget_builder.c b/src/widget_builder.c index 0da03fe..e70f9d9 100644 --- a/src/widget_builder.c +++ b/src/widget_builder.c @@ -42,27 +42,43 @@ void wofi_widget_builder_set_action(struct widget_builder* builder, char* action wofi_property_box_add_property(builder->box, "action", action); } -void wofi_widget_builder_insert_text(struct widget_builder* builder, const char* text, char* css_name) { +void wofi_widget_builder_insert_text(struct widget_builder* builder, const char* text, ...) { GtkWidget* label = gtk_label_new(text); gtk_container_add(GTK_CONTAINER(builder->box), label); - if(css_name != NULL) { - char* tmp = utils_concat(3, builder->mode->name, "-", css_name); - gtk_widget_set_name(label, tmp); + gtk_widget_set_name(label, "text"); + + GtkStyleContext* ctx = gtk_widget_get_style_context(label); + + va_list args; + va_start(args, text); + char* arg; + while((arg = va_arg(args, char*)) != NULL) { + char* tmp = utils_concat(3, builder->mode->name, "-", arg); + gtk_style_context_add_class(ctx, tmp); free(tmp); } + va_end(args); } -void wofi_widget_builder_insert_image(struct widget_builder* builder, GdkPixbuf* pixbuf, char* css_name) { +void wofi_widget_builder_insert_image(struct widget_builder* builder, GdkPixbuf* pixbuf, ...) { GtkWidget* img = gtk_image_new(); cairo_surface_t* surface = gdk_cairo_surface_create_from_pixbuf(pixbuf, wofi_get_window_scale(), gtk_widget_get_window(img)); gtk_image_set_from_surface(GTK_IMAGE(img), surface); cairo_surface_destroy(surface); gtk_container_add(GTK_CONTAINER(builder->box), img); - if(css_name != NULL) { - char* tmp = utils_concat(3, builder->mode->name, "-", css_name); - gtk_widget_set_name(img, tmp); + gtk_widget_set_name(img, "img"); + + GtkStyleContext* ctx = gtk_widget_get_style_context(img); + + va_list args; + va_start(args, pixbuf); + char* arg; + while((arg = va_arg(args, char*)) != NULL) { + char* tmp = utils_concat(3, builder->mode->name, "-", arg); + gtk_style_context_add_class(ctx, tmp); free(tmp); } + va_end(args); } struct widget_builder* wofi_widget_builder_get_idx(struct widget_builder* builder, size_t idx) {