Added --sort-order
This commit is contained in:
parent
12dd2fbd4d
commit
1e131bdce6
@ -100,6 +100,9 @@ Specifies the height in number of lines instead of pixels.
|
|||||||
.TP
|
.TP
|
||||||
.B \-w, \-\-columns=\fICOLUMNS\fR
|
.B \-w, \-\-columns=\fICOLUMNS\fR
|
||||||
Specifies the number of columns to display, default is 1.
|
Specifies the number of columns to display, default is 1.
|
||||||
|
.TP
|
||||||
|
.B \-O, \-\-sort\-order=\fIORDER\fR
|
||||||
|
Specifies the default sort order. There are currently two orders, default and alphabetical. See \fBwofi\fR(7) for details.
|
||||||
|
|
||||||
.SH CONFIGURATION
|
.SH CONFIGURATION
|
||||||
Wofi has 3 main files used for configuration. All files are completely optional.
|
Wofi has 3 main files used for configuration. All files are completely optional.
|
||||||
|
@ -97,6 +97,9 @@ Specifies the height in number of lines instead of pixels.
|
|||||||
.B columns=\fICOLUMNS\fR
|
.B columns=\fICOLUMNS\fR
|
||||||
Specifies the number of columns to display, default is 1.
|
Specifies the number of columns to display, default is 1.
|
||||||
.TP
|
.TP
|
||||||
|
.B sort_order=\fIORDER\fR
|
||||||
|
Specifies the default sort order. There are currently two orders, default and alphabetical. See \fBwofi\fR(7) for details.
|
||||||
|
.TP
|
||||||
.B orientation=\fIORIENTATION\fR
|
.B orientation=\fIORIENTATION\fR
|
||||||
Specifies the orientation, it can be either horizontal or vertical, default is vertical.
|
Specifies the orientation, it can be either horizontal or vertical, default is vertical.
|
||||||
.TP
|
.TP
|
||||||
|
@ -62,6 +62,9 @@ left 8
|
|||||||
.P
|
.P
|
||||||
The x and y offsets are applied based on layer\-shell anchors which means an x offset can only be applied if wofi is anchored on the x axis, i.e. you can only use an x offset with the top_left, top_right, right, bottom_right, bottom_left, and left locations. center, top, and bottom can't have x offsets as they're not anchored on the x axis. Likewise y offsets can only be applied to top_left, top, top_right, bottom_right, bottom, and bottom_left locations. center, left, and right can't have y offsets because they're not anchored to the y axis. Since center can't have offsets on either as it's not anchored to any axis any x or y offset applied while using center will override the location to top_left for backwards compatiblity reasons seeing as not doing so would simply ignore the offsets anyway.
|
The x and y offsets are applied based on layer\-shell anchors which means an x offset can only be applied if wofi is anchored on the x axis, i.e. you can only use an x offset with the top_left, top_right, right, bottom_right, bottom_left, and left locations. center, top, and bottom can't have x offsets as they're not anchored on the x axis. Likewise y offsets can only be applied to top_left, top, top_right, bottom_right, bottom, and bottom_left locations. center, left, and right can't have y offsets because they're not anchored to the y axis. Since center can't have offsets on either as it's not anchored to any axis any x or y offset applied while using center will override the location to top_left for backwards compatiblity reasons seeing as not doing so would simply ignore the offsets anyway.
|
||||||
|
|
||||||
|
.SH ORDER
|
||||||
|
There are 2 order options currently, default and alphabetical. Default means the entries are displayed in the order they are added by the mode, for all built in modes this is cached items first, followed by other entries in no specific order. Alphabetical means entries are alphabetical sorted period. These orders only affect the order when no search has been entered. Once a search is entered the order is re-arranged based on the current matching preference and this order is ignored.
|
||||||
|
|
||||||
.SH WIDGET LAYOUT
|
.SH WIDGET LAYOUT
|
||||||
This section is for advanced CSS which needs more control than the built in wofi CSS names/classes allow for. This widget layout is subject to change at any time and without warning so your CSS might very well break if you rely on this. Widgets have their corresponding names next to them if they have one.
|
This section is for advanced CSS which needs more control than the built in wofi CSS names/classes allow for. This widget layout is subject to change at any time and without warning so your CSS might very well break if you rely on this. Widgets have their corresponding names next to them if they have one.
|
||||||
|
|
||||||
|
16
src/main.c
16
src/main.c
@ -82,6 +82,7 @@ static void print_usage(char** argv) {
|
|||||||
printf("--define\t-D\tSets a config option\n");
|
printf("--define\t-D\tSets a config option\n");
|
||||||
printf("--lines\t\t-L\tSets the height in number of lines\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");
|
printf("--columns\t-w\tSets the number of columns to display\n");
|
||||||
|
printf("--sort-order\t-O\tSets the sort order\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,6 +374,12 @@ int main(int argc, char** argv) {
|
|||||||
.flag = NULL,
|
.flag = NULL,
|
||||||
.val = 'w'
|
.val = 'w'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.name = "sort-order",
|
||||||
|
.has_arg = required_argument,
|
||||||
|
.flag = NULL,
|
||||||
|
.val = 'O'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.name = NULL,
|
.name = NULL,
|
||||||
.has_arg = 0,
|
.has_arg = 0,
|
||||||
@ -405,13 +412,14 @@ int main(int argc, char** argv) {
|
|||||||
char* no_actions = NULL;
|
char* no_actions = NULL;
|
||||||
char* lines = NULL;
|
char* lines = NULL;
|
||||||
char* columns = NULL;
|
char* columns = NULL;
|
||||||
|
char* sort_order = NULL;
|
||||||
|
|
||||||
struct wl_list options;
|
struct wl_list options;
|
||||||
wl_list_init(&options);
|
wl_list_init(&options);
|
||||||
struct option_node* node;
|
struct option_node* node;
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
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) {
|
while((opt = getopt_long(argc, argv, "hfc:s:C:dS:W:H:p:x:y:nImk:t:P::ebM:iqvl:aD:L:w:O:", opts, NULL)) != -1) {
|
||||||
switch(opt) {
|
switch(opt) {
|
||||||
case 'h':
|
case 'h':
|
||||||
print_usage(argv);
|
print_usage(argv);
|
||||||
@ -508,6 +516,9 @@ int main(int argc, char** argv) {
|
|||||||
case 'w':
|
case 'w':
|
||||||
columns = optarg;
|
columns = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'O':
|
||||||
|
sort_order = optarg;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -678,6 +689,9 @@ int main(int argc, char** argv) {
|
|||||||
if(columns != NULL) {
|
if(columns != NULL) {
|
||||||
map_put(config, "columns", columns);
|
map_put(config, "columns", columns);
|
||||||
}
|
}
|
||||||
|
if(sort_order != NULL) {
|
||||||
|
map_put(config, "sort_order", sort_order);
|
||||||
|
}
|
||||||
|
|
||||||
struct sigaction sigact;
|
struct sigaction sigact;
|
||||||
memset(&sigact, 0, sizeof(sigact));
|
memset(&sigact, 0, sizeof(sigact));
|
||||||
|
25
src/wofi.c
25
src/wofi.c
@ -38,6 +38,11 @@ enum locations {
|
|||||||
LOCATION_LEFT
|
LOCATION_LEFT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum sort_order {
|
||||||
|
SORT_ORDER_DEFAULT,
|
||||||
|
SORT_ORDER_ALPHABETICAL
|
||||||
|
};
|
||||||
|
|
||||||
static uint64_t width, height;
|
static uint64_t width, height;
|
||||||
static char* x, *y;
|
static char* x, *y;
|
||||||
static struct zwlr_layer_shell_v1* shell;
|
static struct zwlr_layer_shell_v1* shell;
|
||||||
@ -62,8 +67,9 @@ static struct map* config;
|
|||||||
static enum locations location;
|
static enum locations location;
|
||||||
static bool no_actions;
|
static bool no_actions;
|
||||||
static uint64_t columns;
|
static uint64_t columns;
|
||||||
static bool is_first = true;
|
static bool user_moved = false;
|
||||||
static uint16_t widget_count = 0;
|
static uint16_t widget_count = 0;
|
||||||
|
static enum sort_order sort_order;
|
||||||
|
|
||||||
struct mode {
|
struct mode {
|
||||||
void (*mode_exec)(const gchar* cmd);
|
void (*mode_exec)(const gchar* cmd);
|
||||||
@ -417,9 +423,8 @@ static gboolean _insert_widget(gpointer data) {
|
|||||||
gtk_container_add(GTK_CONTAINER(inner_box), child);
|
gtk_container_add(GTK_CONTAINER(inner_box), child);
|
||||||
gtk_widget_show_all(child);
|
gtk_widget_show_all(child);
|
||||||
|
|
||||||
if(is_first) {
|
if(!user_moved) {
|
||||||
gtk_flow_box_select_child(GTK_FLOW_BOX(inner_box), GTK_FLOW_BOX_CHILD(child));
|
gtk_flow_box_select_child(GTK_FLOW_BOX(inner_box), gtk_flow_box_get_child_at_index(GTK_FLOW_BOX(inner_box), 0));
|
||||||
is_first = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(GTK_IS_EXPANDER(parent)) {
|
if(GTK_IS_EXPANDER(parent)) {
|
||||||
@ -837,10 +842,20 @@ static gint do_sort(GtkFlowBoxChild* child1, GtkFlowBoxChild* child2, gpointer d
|
|||||||
uint64_t index1 = strtol(wofi_property_box_get_property(WOFI_PROPERTY_BOX(box1), "index"), NULL, 10);
|
uint64_t index1 = strtol(wofi_property_box_get_property(WOFI_PROPERTY_BOX(box1), "index"), NULL, 10);
|
||||||
uint64_t index2 = strtol(wofi_property_box_get_property(WOFI_PROPERTY_BOX(box2), "index"), NULL, 10);
|
uint64_t index2 = strtol(wofi_property_box_get_property(WOFI_PROPERTY_BOX(box2), "index"), NULL, 10);
|
||||||
if(filter == NULL || strcmp(filter, "") == 0) {
|
if(filter == NULL || strcmp(filter, "") == 0) {
|
||||||
|
switch(sort_order) {
|
||||||
|
case SORT_ORDER_DEFAULT:
|
||||||
return index1 - index2;
|
return index1 - index2;
|
||||||
|
case SORT_ORDER_ALPHABETICAL:
|
||||||
|
return strcmp(text1, text2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(text1 == NULL || text2 == NULL) {
|
if(text1 == NULL || text2 == NULL) {
|
||||||
|
switch(sort_order) {
|
||||||
|
case SORT_ORDER_DEFAULT:
|
||||||
return index1 - index2;
|
return index1 - index2;
|
||||||
|
case SORT_ORDER_ALPHABETICAL:
|
||||||
|
return strcmp(text1, text2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(matching) {
|
switch(matching) {
|
||||||
@ -881,6 +896,7 @@ static gboolean key_press(GtkWidget* widget, GdkEvent* event, gpointer data) {
|
|||||||
} else if(event->key.keyval == GDK_KEY_Right && outer_orientation == GTK_ORIENTATION_VERTICAL) {
|
} else if(event->key.keyval == GDK_KEY_Right && outer_orientation == GTK_ORIENTATION_VERTICAL) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
user_moved = true;
|
||||||
if(gtk_widget_has_focus(entry) || gtk_widget_has_focus(scroll)) {
|
if(gtk_widget_has_focus(entry) || gtk_widget_has_focus(scroll)) {
|
||||||
GtkFlowBoxChild* child = gtk_flow_box_get_child_at_index(GTK_FLOW_BOX(inner_box), 0);
|
GtkFlowBoxChild* child = gtk_flow_box_get_child_at_index(GTK_FLOW_BOX(inner_box), 0);
|
||||||
gtk_widget_grab_focus(GTK_WIDGET(child));
|
gtk_widget_grab_focus(GTK_WIDGET(child));
|
||||||
@ -1059,6 +1075,7 @@ void wofi_init(struct map* _config) {
|
|||||||
no_actions = strcmp(config_get(config, "no_actions", "false"), "true") == 0;
|
no_actions = strcmp(config_get(config, "no_actions", "false"), "true") == 0;
|
||||||
uint64_t lines = strtol(config_get(config, "lines", "0"), NULL, 10);
|
uint64_t lines = strtol(config_get(config, "lines", "0"), NULL, 10);
|
||||||
columns = strtol(config_get(config, "columns", "1"), NULL, 10);
|
columns = strtol(config_get(config, "columns", "1"), NULL, 10);
|
||||||
|
sort_order = config_get_mnemonic(config, "sort_order", "default", 2, "default", "alphabetical");
|
||||||
modes = map_init_void();
|
modes = map_init_void();
|
||||||
|
|
||||||
if(lines > 0) {
|
if(lines > 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user