From df75b649a5f7524eed189d824469ffa41e1c4f54 Mon Sep 17 00:00:00 2001 From: Scoopta Date: Thu, 6 Feb 2020 18:22:50 -0800 Subject: [PATCH] Added --columns --- man/wofi.1 | 3 +++ man/wofi.5 | 3 +++ src/main.c | 16 +++++++++++++++- src/wofi.c | 8 +++++--- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/man/wofi.1 b/man/wofi.1 index 47e6510..92c2f06 100644 --- a/man/wofi.1 +++ b/man/wofi.1 @@ -97,6 +97,9 @@ Sets a config option .TP .B \-L, \-\-lines=\fILINES\fR Specifies the height in number of lines instead of pixels. +.TP +.B \-w, \-\-columns=\fICOLUMNS\fR +Specifies the number of columns to display, default is 1. .SH CONFIGURATION Wofi has 3 main files used for configuration. All files are completely optional. diff --git a/man/wofi.5 b/man/wofi.5 index 406c58a..0de6aec 100644 --- a/man/wofi.5 +++ b/man/wofi.5 @@ -94,6 +94,9 @@ If true disables multiple actions for modes that support it, default is false. .B lines=\fILINES\fR Specifies the height in number of lines instead of pixels. .TP +.B columns=\fICOLUMNS\fR +Specifies the number of columns to display, default is 1. +.TP .B orientation=\fIORIENTATION\fR Specifies the orientation, it can be either horizontal or vertical, default is vertical. .TP diff --git a/src/main.c b/src/main.c index bfa9097..98c8772 100644 --- a/src/main.c +++ b/src/main.c @@ -81,6 +81,7 @@ static void print_usage(char** argv) { printf("--no-actions\t-a\tDisables multiple actions for modes that support it\n"); printf("--define\t-D\tSets a config option\n"); printf("--lines\t\t-L\tSets the height in number of lines\n"); + printf("--columns\t-w\tSets the number of columns to display\n"); exit(0); } @@ -366,6 +367,12 @@ int main(int argc, char** argv) { .flag = NULL, .val = 'L' }, + { + .name = "columns", + .has_arg = required_argument, + .flag = NULL, + .val = 'w' + }, { .name = NULL, .has_arg = 0, @@ -397,13 +404,14 @@ int main(int argc, char** argv) { char* location = NULL; char* no_actions = NULL; char* lines = NULL; + char* columns = NULL; struct wl_list options; wl_list_init(&options); struct option_node* node; int opt; - while((opt = getopt_long(argc, argv, "hfc:s:C:dS:W:H:p:x:y:nImk:t:P::ebM:iqvl:aD:L:", opts, NULL)) != -1) { + while((opt = getopt_long(argc, argv, "hfc:s:C:dS:W:H:p:x:y:nImk:t:P::ebM:iqvl:aD:L:w:", opts, NULL)) != -1) { switch(opt) { case 'h': print_usage(argv); @@ -497,6 +505,9 @@ int main(int argc, char** argv) { case 'L': lines = optarg; break; + case 'w': + columns = optarg; + break; } } @@ -664,6 +675,9 @@ int main(int argc, char** argv) { if(lines != NULL) { map_put(config, "lines", lines); } + if(columns != NULL) { + map_put(config, "columns", columns); + } struct sigaction sigact; memset(&sigact, 0, sizeof(sigact)); diff --git a/src/wofi.c b/src/wofi.c index 029ef08..0741ca9 100644 --- a/src/wofi.c +++ b/src/wofi.c @@ -63,6 +63,7 @@ static GtkAlign content_halign; static struct map* config; static enum locations location; static bool no_actions; +static uint64_t columns; struct mode { void (*mode_exec)(const gchar* cmd); @@ -405,9 +406,9 @@ static gboolean _insert_widget(gpointer data) { } if(allow_images) { - gtk_widget_set_size_request(child, width, (image_size + 10) * lf_count); + gtk_widget_set_size_request(child, width / columns, (image_size + 10) * lf_count); } else { - gtk_widget_set_size_request(child, width, LINE_HEIGHT * lf_count); + gtk_widget_set_size_request(child, width / columns, LINE_HEIGHT * lf_count); } gtk_container_add(GTK_CONTAINER(child), parent); @@ -1057,6 +1058,7 @@ 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; uint64_t lines = strtol(config_get(config, "lines", "0"), NULL, 10); + columns = strtol(config_get(config, "columns", "1"), NULL, 10); modes = map_init_void(); if(lines > 0) { @@ -1118,7 +1120,7 @@ void wofi_init(struct map* _config) { } inner_box = gtk_flow_box_new(); - gtk_flow_box_set_max_children_per_line(GTK_FLOW_BOX(inner_box), 1); + gtk_flow_box_set_max_children_per_line(GTK_FLOW_BOX(inner_box), columns); gtk_orientable_set_orientation(GTK_ORIENTABLE(inner_box), orientation); gtk_widget_set_halign(inner_box, halign); gtk_widget_set_valign(inner_box, valign);