diff --git a/man/wofi.5 b/man/wofi.5 index ac936e9..3d1ce98 100644 --- a/man/wofi.5 +++ b/man/wofi.5 @@ -168,6 +168,9 @@ Specifies whether x and y offsets should be calculated using the global composit .TP .B hide_search=\fIBOOL\fR Specifies whether the search bar should be hidden. Default is false. +.TP +.B dynamic_lines=\fIBOOL\fR +Specifies whether wofi should be dynamically shrunk to fit the number of visible lines or if it should always stay the same size. Default is false. .SH CSS SELECTORS Any GTK widget can be selected by using the name of its CSS node, these however might change with updates and are not guaranteed to stay constant. Wofi also provides certain widgets with names and classes which can be referenced from CSS to give access to the most important widgets easily. \fBwofi\fR(7) contains the current widget layout used by wofi so if you want to get into CSS directly using GTK widget names look there for info. diff --git a/src/wofi.c b/src/wofi.c index fcc9309..cbe5577 100644 --- a/src/wofi.c +++ b/src/wofi.c @@ -90,7 +90,7 @@ static bool user_moved = false; static uint32_t widget_count = 0; static enum sort_order sort_order; static int64_t max_height = 0; -static uint64_t lines; +static uint32_t lines, max_lines; static int8_t line_wrap; static int64_t ix, iy; static uint8_t konami_cycle; @@ -98,6 +98,8 @@ static bool is_konami = false; static GDBusProxy* dbus = NULL; static GdkRectangle resolution = {0}; static bool resize_expander = false; +static uint32_t line_count = 0; +static bool dynamic_lines; static struct map* keys; @@ -446,6 +448,10 @@ static void expand(GtkExpander* expander, gpointer data) { } static void update_surface_size(void) { + if(lines > 0) { + height = max_height * lines; + height += 5; + } if(shell != NULL) { zwlr_layer_surface_v1_set_size(wlr_surface, width, height); wl_surface_commit(wl_surface); @@ -481,8 +487,6 @@ static void widget_allocate(GtkWidget* widget, GdkRectangle* allocation, gpointe max_height = allocation->height; } if(lines > 0) { - height = max_height * lines; - height += 5; update_surface_size(); } } @@ -527,8 +531,9 @@ static gboolean _insert_widget(gpointer data) { g_signal_connect(child, "size-allocate", G_CALLBACK(widget_allocate), NULL); gtk_container_add(GTK_CONTAINER(child), parent); - gtk_container_add(GTK_CONTAINER(inner_box), child); gtk_widget_show_all(child); + gtk_container_add(GTK_CONTAINER(inner_box), child); + ++line_count; if(!user_moved) { GtkFlowBoxChild* child = gtk_flow_box_get_child_at_index(GTK_FLOW_BOX(inner_box), 0); @@ -892,7 +897,25 @@ static gboolean filter_proxy(GtkFlowBoxChild* row) { static gboolean do_filter(GtkFlowBoxChild* row, gpointer data) { (void) data; gboolean ret = filter_proxy(row); + + if(gtk_widget_get_visible(GTK_WIDGET(row)) == !ret && dynamic_lines) { + if(ret) { + ++line_count; + } else { + --line_count; + } + + if(line_count < max_lines) { + lines = line_count; + update_surface_size(); + } else { + lines = max_lines; + update_surface_size(); + } + } + gtk_widget_set_visible(GTK_WIDGET(row), ret); + return ret; } @@ -1514,12 +1537,14 @@ void wofi_init(struct map* _config) { "0", "1", "2", "3", "4", "5", "6", "7", "8"); no_actions = strcmp(config_get(config, "no_actions", "false"), "true") == 0; lines = strtol(config_get(config, "lines", "0"), NULL, 10); + max_lines = lines; columns = strtol(config_get(config, "columns", "1"), NULL, 10); sort_order = config_get_mnemonic(config, "sort_order", "default", 2, "default", "alphabetical"); line_wrap = config_get_mnemonic(config, "line_wrap", "off", 4, "off", "word", "char", "word_char") - 1; bool global_coords = strcmp(config_get(config, "global_coords", "false"), "true") == 0; bool hide_search = strcmp(config_get(config, "hide_search", "false"), "true") == 0; char* search = map_get(config, "search"); + dynamic_lines = strcmp(config_get(config, "dynamic_lines", "false"), "true") == 0; keys = map_init_void();