Added --parse-search to strip pango markup and image escapes from search text
This commit is contained in:
parent
f6fef341fb
commit
62861d3686
@ -4,5 +4,5 @@
|
||||
|
||||
USER_OBJS :=
|
||||
|
||||
LIBS := -ldl -lgtk-3 -lgdk-3 -lgio-2.0 -lglib-2.0 -lgobject-2.0 -lwayland-client -lgdk_pixbuf-2.0
|
||||
LIBS := -ldl -lgtk-3 -lgdk-3 -lgio-2.0 -lglib-2.0 -lpango-1.0 -lgobject-2.0 -lwayland-client -lgdk_pixbuf-2.0
|
||||
|
||||
|
@ -4,5 +4,5 @@
|
||||
|
||||
USER_OBJS :=
|
||||
|
||||
LIBS := -ldl -lgtk-3 -lgdk-3 -lgio-2.0 -lglib-2.0 -lgobject-2.0 -lwayland-client -lgdk_pixbuf-2.0
|
||||
LIBS := -ldl -lgtk-3 -lgdk-3 -lgio-2.0 -lglib-2.0 -lpango-1.0 -lgobject-2.0 -lwayland-client -lgdk_pixbuf-2.0
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <pango/pango.h>
|
||||
#include <gdk/gdkwayland.h>
|
||||
#include <gio/gdesktopappinfo.h>
|
||||
|
||||
|
16
src/main.c
16
src/main.c
@ -70,6 +70,7 @@ static void print_usage(char** argv) {
|
||||
printf("--hide-scroll\t-b\tHides the scroll bars\n");
|
||||
printf("--matching\t-M\tSets the matching method, default is contains\n");
|
||||
printf("--insensitive\t-i\tAllows case insensitive searching\n");
|
||||
printf("--parse-search\t-q\tParses the search text removing image escapes and pango\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@ -311,6 +312,12 @@ int main(int argc, char** argv) {
|
||||
.flag = NULL,
|
||||
.val = 'i'
|
||||
},
|
||||
{
|
||||
.name = "parse-search",
|
||||
.has_arg = no_argument,
|
||||
.flag = NULL,
|
||||
.val = 'q'
|
||||
},
|
||||
{
|
||||
.name = NULL,
|
||||
.has_arg = 0,
|
||||
@ -338,8 +345,9 @@ int main(int argc, char** argv) {
|
||||
char* hide_scroll = NULL;
|
||||
char* matching = NULL;
|
||||
char* insensitive = NULL;
|
||||
char* parse_search = NULL;
|
||||
int opt;
|
||||
while((opt = getopt_long(argc, argv, "hfc:s:C:dS:W:H:p:x:y:nImk:t:P::ebM:i", opts, NULL)) != -1) {
|
||||
while((opt = getopt_long(argc, argv, "hfc:s:C:dS:W:H:p:x:y:nImk:t:P::ebM:iq", opts, NULL)) != -1) {
|
||||
switch(opt) {
|
||||
case 'h':
|
||||
print_usage(argv);
|
||||
@ -412,6 +420,9 @@ int main(int argc, char** argv) {
|
||||
case 'i':
|
||||
insensitive = "true";
|
||||
break;
|
||||
case 'q':
|
||||
parse_search = "true";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -554,6 +565,9 @@ int main(int argc, char** argv) {
|
||||
if(insensitive != NULL) {
|
||||
map_put(config, "insensitive", insensitive);
|
||||
}
|
||||
if(parse_search != NULL) {
|
||||
map_put(config, "parse_search", parse_search);
|
||||
}
|
||||
|
||||
|
||||
gtk_init(&argc, &argv);
|
||||
|
47
src/wofi.c
47
src/wofi.c
@ -44,6 +44,7 @@ static bool exec_search;
|
||||
static struct map* modes;
|
||||
static enum matching_mode matching;
|
||||
static bool insensitive;
|
||||
static bool parse_search;
|
||||
static struct map* config;
|
||||
|
||||
struct node {
|
||||
@ -94,14 +95,8 @@ static void get_search(GtkSearchEntry* entry, gpointer data) {
|
||||
gtk_flow_box_invalidate_sort(GTK_FLOW_BOX(inner_box));
|
||||
}
|
||||
|
||||
static GtkWidget* create_label(char* mode, char* text, char* search_text, char* action) {
|
||||
GtkWidget* box = wofi_property_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
|
||||
gtk_widget_set_name(box, "unselected");
|
||||
GtkStyleContext* style = gtk_widget_get_style_context(box);
|
||||
gtk_style_context_add_class(style, "entry");
|
||||
wofi_property_box_add_property(WOFI_PROPERTY_BOX(box), "mode", mode);
|
||||
wofi_property_box_add_property(WOFI_PROPERTY_BOX(box), "action", action);
|
||||
if(allow_images) {
|
||||
static char* parse_images(WofiPropertyBox* box, char* text, bool create_widgets) {
|
||||
char* ret = strdup("");
|
||||
struct map* mode_map = map_init();
|
||||
map_put(mode_map, "img", "true");
|
||||
map_put(mode_map, "text", "true");
|
||||
@ -165,7 +160,7 @@ static GtkWidget* create_label(char* mode, char* text, char* search_text, char*
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(strcmp(mode, "img") == 0) {
|
||||
if(strcmp(mode, "img") == 0 && create_widgets) {
|
||||
GdkPixbuf* buf = gdk_pixbuf_new_from_file(str, NULL);
|
||||
int width = gdk_pixbuf_get_width(buf);
|
||||
int height = gdk_pixbuf_get_height(buf);
|
||||
@ -184,11 +179,17 @@ static GtkWidget* create_label(char* mode, char* text, char* search_text, char*
|
||||
gtk_widget_set_name(img, "img");
|
||||
gtk_container_add(GTK_CONTAINER(box), img);
|
||||
} else if(strcmp(mode, "text") == 0) {
|
||||
if(create_widgets) {
|
||||
GtkWidget* label = gtk_label_new(str);
|
||||
gtk_widget_set_name(label, "text");
|
||||
gtk_label_set_use_markup(GTK_LABEL(label), allow_markup);
|
||||
gtk_label_set_xalign(GTK_LABEL(label), 0);
|
||||
gtk_container_add(GTK_CONTAINER(box), label);
|
||||
} else {
|
||||
char* tmp = ret;
|
||||
ret = utils_concat(2, ret, str);
|
||||
free(tmp);
|
||||
}
|
||||
}
|
||||
mode = NULL;
|
||||
if(wl_list_empty(&modes)) {
|
||||
@ -205,6 +206,23 @@ static GtkWidget* create_label(char* mode, char* text, char* search_text, char*
|
||||
wl_list_remove(&node->link);
|
||||
free(node);
|
||||
}
|
||||
if(create_widgets) {
|
||||
free(ret);
|
||||
return NULL;
|
||||
} else {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
static GtkWidget* create_label(char* mode, char* text, char* search_text, char* action) {
|
||||
GtkWidget* box = wofi_property_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
|
||||
gtk_widget_set_name(box, "unselected");
|
||||
GtkStyleContext* style = gtk_widget_get_style_context(box);
|
||||
gtk_style_context_add_class(style, "entry");
|
||||
wofi_property_box_add_property(WOFI_PROPERTY_BOX(box), "mode", mode);
|
||||
wofi_property_box_add_property(WOFI_PROPERTY_BOX(box), "action", action);
|
||||
if(allow_images) {
|
||||
parse_images(WOFI_PROPERTY_BOX(box), text, true);
|
||||
} else {
|
||||
GtkWidget* label = gtk_label_new(text);
|
||||
gtk_widget_set_name(label, "text");
|
||||
@ -212,7 +230,17 @@ static GtkWidget* create_label(char* mode, char* text, char* search_text, char*
|
||||
gtk_label_set_xalign(GTK_LABEL(label), 0);
|
||||
gtk_container_add(GTK_CONTAINER(box), label);
|
||||
}
|
||||
if(parse_search) {
|
||||
search_text = parse_images(WOFI_PROPERTY_BOX(box), search_text, false);
|
||||
char* out;
|
||||
pango_parse_markup(search_text, -1, 0, NULL, &out, NULL, NULL);
|
||||
free(search_text);
|
||||
search_text = out;
|
||||
}
|
||||
wofi_property_box_add_property(WOFI_PROPERTY_BOX(box), "filter", search_text);
|
||||
if(parse_search) {
|
||||
free(search_text);
|
||||
}
|
||||
return box;
|
||||
}
|
||||
|
||||
@ -673,6 +701,7 @@ void wofi_init(struct map* _config) {
|
||||
bool hide_scroll = strcmp(config_get(config, "hide_scroll", "false"), "true") == 0;
|
||||
matching = config_get_mnemonic(config, "matching", "contains", 2, "contains", "fuzzy");
|
||||
insensitive = strcmp(config_get(config, "insensitive", "false"), "true") == 0;
|
||||
parse_search = strcmp(config_get(config, "parse_search", "false"), "true") == 0;
|
||||
modes = map_init_void();
|
||||
|
||||
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
|
Loading…
Reference in New Issue
Block a user