Skip to content

Commit d7c8107

Browse files
committed
Support pipemenu format (with -p)
...and fix a no-duplicates bug.
1 parent ff7f0d3 commit d7c8107

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

main.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,22 @@
1818
static bool no_duplicates;
1919
static bool no_footer;
2020
static bool no_header;
21+
static bool pipemenu;
2122

2223
static const struct option long_options[] = {
2324
{"bare", no_argument, NULL, 'b'},
2425
{"help", no_argument, NULL, 'h'},
2526
{"no-duplicates", no_argument, NULL, 'n'},
27+
{"pipemenu", no_argument, NULL, 'p'},
2628
{0, 0, 0, 0}
2729
};
2830

2931
static const char labwc_menu_generator_usage[] =
3032
"Usage: labwc-menu-generator [options...]\n"
3133
" -b, --bare Show no header or footer\n"
3234
" -h, --help Show help message and quit\n"
33-
" -n, --no-duplicates Limit desktop entries to one directory only\n";
35+
" -n, --no-duplicates Limit desktop entries to one directory only\n"
36+
" -p, --pipemenu Output in pipemenu format\n";
3437

3538
static void
3639
usage(void)
@@ -144,9 +147,13 @@ print_menu(GList *dirs, GList *apps)
144147
GString *submenu = g_string_new(NULL);
145148

146149
if (!no_header) {
147-
printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
148-
printf("<openbox_menu>\n");
149-
printf("<menu id=\"root-menu\" label=\"root-menu\">\n");
150+
if (pipemenu) {
151+
printf("<openbox_pipe_menu>\n");
152+
} else {
153+
printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
154+
printf("<openbox_menu>\n");
155+
printf("<menu id=\"root-menu\" label=\"root-menu\">\n");
156+
}
150157
}
151158

152159
/* Handle all directories except 'Other' */
@@ -186,8 +193,12 @@ print_menu(GList *dirs, GList *apps)
186193
}
187194

188195
if (!no_footer) {
189-
printf("</menu> <!-- root-menu -->\n");
190-
printf("</openbox_menu>\n");
196+
if (pipemenu) {
197+
printf("</openbox_pipe_menu>\n");
198+
} else {
199+
printf("</menu> <!-- root-menu -->\n");
200+
printf("</openbox_menu>\n");
201+
}
191202
}
192203

193204
g_string_free(submenu, TRUE);
@@ -273,7 +284,7 @@ main(int argc, char **argv)
273284
int c;
274285
while (1) {
275286
int index = 0;
276-
c = getopt_long(argc, argv, "bhn", long_options, &index);
287+
c = getopt_long(argc, argv, "bhnp", long_options, &index);
277288
if (c == -1) {
278289
break;
279290
}
@@ -283,7 +294,10 @@ main(int argc, char **argv)
283294
no_header = true;
284295
break;
285296
case 'n':
286-
no_duplicates = false;
297+
no_duplicates = true;
298+
break;
299+
case 'p':
300+
pipemenu = true;
287301
break;
288302
case 'h':
289303
default:

0 commit comments

Comments
 (0)