Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tag to application names to find them faster #131

Open
KevinGIRAULT opened this issue Aug 17, 2022 · 3 comments
Open

Add tag to application names to find them faster #131

KevinGIRAULT opened this issue Aug 17, 2022 · 3 comments

Comments

@KevinGIRAULT
Copy link

When I want to open an application whose name I have forgotten, it is very complicated to find it. Sometimes I have to do a Google search on existing applications under Linux to find the name. Or on synaptic.

I use KISS Launcher on Android, and it is possible to put tags to find an application more easily. Is this possible?

Like the example below:

https://help.kisslauncher.com/tags/use-tags/

It would be great to have something similar on J4.

What do you think about it?

@KevinGIRAULT KevinGIRAULT changed the title Add labels to application names to find them faster Add tag to application names to find them faster Aug 17, 2022
@meator
Copy link
Collaborator

meator commented Oct 9, 2022

This seems like a nice addition.

Some desktop files already include "categories". This would be the simplest thing to implement.

I've made a proof of concept commit that adds a -c option that displays the categories. https://github.com/meator/j4-dmenu-desktop/tree/categories It is branched off of my pull request #132.

If you want to try it out, you can run this shell script:

#!/bin/sh
set -e
curl -L https://github.com/meator/j4-dmenu-desktop/archive/refs/heads/categories.zip --output j4dd.zip
unzip j4dd.zip
rm j4dd.zip
cd j4-dmenu-desktop-categories
mkdir build
cd build
cmake -DWITH_TESTS=OFF ..
make

It requires make, cmake, unzip, curl and a C++ compiler. Please install these it you don't have them and if you want to try this out. You will find the updated j4-dmenu-desktop at j4-dmenu-desktop-categories/build/j4-dmenu-desktop.

One problem with this approach is that the entries can get quite long. My solution is to display items vertically with this:

./j4-dmenu-desktop -c --dmenu "dmenu -i -l 10"

image

The KISS laucher allows the user to modify the tags. This would be more complicated to implement. Is this what you are looking for? I haven't read it, but I think the Desktop Menu Specification specifies how this should work. This would require a lot of new code handling this.

@KevinGIRAULT
Copy link
Author

Thank you for your answer. I'll look at what you suggest as soon as possible and get back to you, but it won't be for a while.

I was actually thinking about editing the tags as well, but yes, I can imagine how much work it can be. Managing categories is already a very good thing.

Thanks a lot to you.

@lmccartneystar
Copy link

I find adding categories quite convenient. I don't mind listing vertically, in fact I prefer it that way.

And long entries could be shortened by hiding the categories with a slightly modified version of the tsv patch for dmenu by simply adding a custom delimiter.
I made this one for dmenu 5.2 for example:

diff --git a/dmenu.1 b/dmenu.1
index 323f93c..e8cf31f 100644
--- a/dmenu.1
+++ b/dmenu.1
@@ -22,6 +22,8 @@ dmenu \- dynamic menu
 .IR color ]
 .RB [ \-w
 .IR windowid ]
+.RB [ \-d
+.IR delimiter ]
 .P
 .BR dmenu_run " ..."
 .SH DESCRIPTION
@@ -80,6 +82,9 @@ prints version information to stdout, then exits.
 .TP
 .BI \-w " windowid"
 embed into windowid.
+.TP
+.BI \-d " delimiter"
+displays only the first part of each item before the delimiter. Still matches and prints the entire item to stdout.
 .SH USAGE
 dmenu is completely controlled by the keyboard.  Items are selected using the
 arrow keys, page up, page down, home, and end.
diff --git a/dmenu.c b/dmenu.c
index 7cf253b..0a1d092 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -30,12 +30,14 @@ enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
 
 struct item {
 	char *text;
+	char *stext;
 	struct item *left, *right;
 	int out;
 };
 
 static char text[BUFSIZ] = "";
 static char *embed;
+static char delim;
 static int bh, mw, mh;
 static int inputw = 0, promptw;
 static int lrpad; /* sum of left and right padding */
@@ -104,8 +106,10 @@ cleanup(void)
 	XUngrabKey(dpy, AnyKey, AnyModifier, root);
 	for (i = 0; i < SchemeLast; i++)
 		free(scheme[i]);
-	for (i = 0; items && items[i].text; ++i)
+	for (i = 0; items && items[i].text; ++i) {
 		free(items[i].text);
+		free(items[i].stext);
+	}
 	free(items);
 	drw_free(drw);
 	XSync(dpy, False);
@@ -140,7 +144,7 @@ drawitem(struct item *item, int x, int y, int w)
 	else
 		drw_setscheme(drw, scheme[SchemeNorm]);
 
-	return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
+	return drw_text(drw, x, y, w, bh, lrpad / 2, item->stext, 0);
 }
 
 static void
@@ -182,7 +186,7 @@ drawmenu(void)
 		}
 		x += w;
 		for (item = curr; item != next; item = item->right)
-			x = drawitem(item, x, 0, textw_clamp(item->text, mw - x - TEXTW(">")));
+			x = drawitem(item, x, 0, textw_clamp(item->stext, mw - x - TEXTW(">")));
 		if (next) {
 			w = TEXTW(">");
 			drw_setscheme(drw, scheme[SchemeNorm]);
@@ -549,7 +553,7 @@ paste(void)
 static void
 readstdin(void)
 {
-	char *line = NULL;
+	char *p, *line = NULL;
 	size_t i, junk, size = 0;
 	ssize_t len;
 
@@ -561,10 +565,17 @@ readstdin(void)
 		if (line[len - 1] == '\n')
 			line[len - 1] = '\0';
 		items[i].text = line;
+
+		items[i].stext = strdup(line);
+		if ((p = strchr(items[i].stext, delim)))
+			*p = '\0';
+
 		items[i].out = 0;
 	}
-	if (items)
+	if (items) {
 		items[i].text = NULL;
+		items[i].stext = NULL;
+	}
 	lines = MIN(lines, i);
 }
 
@@ -711,7 +722,8 @@ static void
 usage(void)
 {
 	die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
-	    "             [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]");
+	    "             [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n"
+	    "             [-d delimiter]");
 }
 
 int
@@ -753,6 +765,8 @@ main(int argc, char *argv[])
 			colors[SchemeSel][ColFg] = argv[++i];
 		else if (!strcmp(argv[i], "-w"))   /* embedding window id */
 			embed = argv[++i];
+		else if (!strcmp(argv[i], "-d"))   /* field separator */
+			delim = argv[++i][0];
 		else
 			usage();
 

Then the following will only print 'Firefox', but can still match the entire item.

echo 'Firefox (Network, WebBrowser)' | dmenu -i -d '('

And using this version of j4-dmenu-desktop:

./j4-dmenu-desktop -c --dmenu "dmenu -i -l 10 -d '('"

@meator meator mentioned this issue Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants