configure: Add detection of library kvm that is used under OpenBSD
[wmaker-crm.git] / util / wmgenmenu.c
blob002e0250fbd4045c4003e55adb76d5fbf9f90116
1 /* Copyright (C) 2010 Carlos R. Mafra */
3 #ifdef __GLIBC__
4 #define _GNU_SOURCE /* getopt_long */
5 #endif
7 #include <ctype.h>
8 #include <getopt.h>
9 #include <limits.h>
10 #include <locale.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
15 #include <WINGs/WUtil.h>
17 #include "../src/wconfig.h"
19 #define MAX_NR_APPS 128 /* Maximum number of entries in each apps list */
20 #define MAX_WMS 10 /* Maximum number of other window managers to check */
22 #include "wmgenmenu.h"
24 static void find_and_write(char *group, char *list[][2], int this_is_terminals);
25 static void other_window_managers(void);
26 static void print_help(int print_usage, int exitval);
28 extern char *__progname;
30 char *path, *terminal = NULL;
32 WMPropList *RMenu, *L1Menu, *L2Menu, *L3Menu, *L4Menu;
34 int main(int argc, char *argv[])
36 char *t;
37 int ch;
39 struct option longopts[] = {
40 { "version", no_argument, NULL, 'v' },
41 { "help", no_argument, NULL, 'h' },
42 { NULL, 0, NULL, 0 }
45 while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1)
46 switch (ch) {
47 case 'v':
48 printf("%s (Window Maker %s)\n", __progname, VERSION);
49 return 0;
50 /* NOTREACHED */
51 case 'h':
52 print_help(1, 0);
53 /* NOTREACHED */
54 default:
55 print_help(0, 1);
56 /* NOTREACHED */
59 argc -= optind;
60 argv += optind;
62 if (argc != 0)
63 print_help(0, 1);
65 path = getenv("PATH");
66 setlocale(LC_ALL, "");
68 #if HAVE_LIBINTL_H && I18N
69 if (getenv("NLSPATH"))
70 bindtextdomain("wmgenmenu", getenv("NLSPATH"));
71 else
72 bindtextdomain("wmgenmenu", LOCALEDIR);
74 bind_textdomain_codeset("wmgenmenu", "UTF-8");
75 textdomain("wmgenmenu");
76 #endif
79 * The menu generated is a five-level hierarchy, of which the
80 * top level (RMenu) is only used to hold the others (a single
81 * PLString, which will be the title of the root menu)
83 * RMenu Window Maker
84 * L1Menu Applications
85 * L2Menu Terminals
86 * L3Menu XTerm
87 * L3Menu RXVT
88 * L2Menu Internet
89 * L3Menu Firefox
90 * L2Menu E-mail
91 * L1Menu Appearance
92 * L2Menu Themes
93 * L2Menu Background
94 * L3Menu Solid
95 * L4Menu Indigo
96 * L1Menu Configure Window Maker
100 /* Root */
101 RMenu = WMCreatePLArray(WMCreatePLString("Window Maker"), NULL);
103 /* Root -> Applications */
104 L1Menu = WMCreatePLArray(WMCreatePLString(_("Applications")), NULL);
106 /* Root -> Applications -> <category> */
107 find_and_write(_("Terminals"), Terminals, 1); /* always keep terminals the top item */
108 find_and_write(_("Internet"), Internet, 0);
109 find_and_write(_("Email"), Email, 0);
110 find_and_write(_("Mathematics"), Mathematics, 0);
111 find_and_write(_("File Managers"), File_managers, 0);
112 find_and_write(_("Graphics"), Graphics, 0);
113 find_and_write(_("Multimedia"), Multimedia, 0);
114 find_and_write(_("Editors"), Editors, 0);
115 find_and_write(_("Development"), Development, 0);
116 find_and_write("Window Maker", WindowMaker, 0);
117 find_and_write(_("Office"), Office, 0);
118 find_and_write(_("Astronomy"), Astronomy, 0);
119 find_and_write(_("Sound"), Sound, 0);
120 find_and_write(_("Comics"), Comics, 0);
121 find_and_write(_("Viewers"), Viewers, 0);
122 find_and_write(_("Utilities"), Utilities, 0);
123 find_and_write(_("System"), System, 0);
124 find_and_write(_("Video"), Video, 0);
125 find_and_write(_("Chat and Talk"), Chat, 0);
126 find_and_write(_("P2P Network"), P2P, 0);
127 find_and_write(_("Games"), Games, 0);
128 find_and_write("OpenSUSE", OpenSUSE, 0);
129 find_and_write("Mandriva", Mandriva, 0);
131 WMAddToPLArray(RMenu, L1Menu);
133 /* Root -> `Run' dialog */
134 L1Menu = WMCreatePLArray(
135 WMCreatePLString(_("Run...")),
136 WMCreatePLString("SHEXEC"),
137 WMCreatePLString(_("%A(Run, Type command:)")),
138 NULL
140 WMAddToPLArray(RMenu, L1Menu);
142 /* Root -> Appearance */
143 L1Menu = WMCreatePLArray(WMCreatePLString(_("Appearance")), NULL);
145 /* Root -> Appearance -> Themes */
146 L2Menu = WMCreatePLArray(
147 WMCreatePLString(_("Themes")),
148 WMCreatePLString("OPEN_MENU"),
149 WMCreatePLString("-noext /usr/local/share/WindowMaker/Themes $HOME/GNUstep/Library/WindowMaker/Themes WITH setstyle"),
150 NULL
152 WMAddToPLArray(L1Menu, L2Menu);
154 /* Root -> Appearance -> Styles */
155 L2Menu = WMCreatePLArray(
156 WMCreatePLString(_("Styles")),
157 WMCreatePLString("OPEN_MENU"),
158 WMCreatePLString("-noext /usr/local/share/WindowMaker/Styles $HOME/GNUstep/Library/WindowMaker/Styles WITH setstyle"),
159 NULL
161 WMAddToPLArray(L1Menu, L2Menu);
163 /* Root -> Appearance -> Icon Sets */
164 L2Menu = WMCreatePLArray(
165 WMCreatePLString(_("Icon Sets")),
166 WMCreatePLString("OPEN_MENU"),
167 WMCreatePLString("-noext /usr/local/share/WindowMaker/IconSets $HOME/GNUstep/Library/WindowMaker/IconSets WITH seticons"),
168 NULL
170 WMAddToPLArray(L1Menu, L2Menu);
172 /* Root -> Appearance -> Background */
173 L2Menu = WMCreatePLArray(WMCreatePLString(_("Background")), NULL);
175 /* Root -> Appearance -> Background -> Solid */
176 L3Menu = WMCreatePLArray(WMCreatePLString(_("Solid")), NULL);
178 #define SOLID_BACK(label, colorspec) \
179 L4Menu = WMCreatePLArray( \
180 WMCreatePLString(label), \
181 WMCreatePLString("EXEC"), \
182 WMCreatePLString("wdwrite WindowMaker WorkspaceBack '(solid, \"" colorspec "\")'"), \
183 NULL \
184 ); \
185 WMAddToPLArray(L3Menu, L4Menu)
187 /* Root -> Appearance -> Background -> Solid -> <color> */
188 SOLID_BACK(_("Black"), "black");
189 SOLID_BACK(_("Blue"), "#505075");
190 SOLID_BACK(_("Indigo"), "#243e6c");
191 SOLID_BACK(_("Bluemarine"), "#243e6c");
192 SOLID_BACK(_("Purple"), "#554466");
193 SOLID_BACK(_("Wheat"), "wheat4");
194 SOLID_BACK(_("Dark Gray"), "#333340");
195 SOLID_BACK(_("Wine"), "#400020");
196 #undef SOLID_BACK
197 WMAddToPLArray(L2Menu, L3Menu);
199 /* Root -> Appearance -> Background -> Gradient */
200 L3Menu = WMCreatePLArray(WMCreatePLString(_("Gradient")), NULL);
202 #define GRADIENT_BACK(label, fcolorspec, tcolorspec) \
203 L4Menu = WMCreatePLArray( \
204 WMCreatePLString(label), \
205 WMCreatePLString("EXEC"), \
206 WMCreatePLString("wdwrite WindowMaker WorkspaceBack '(vgradient, \"" \
207 fcolorspec "\", \"" tcolorspec "\"'"), \
208 NULL \
209 ); \
210 WMAddToPLArray(L3Menu, L4Menu)
212 /* Root -> Appearance -> Background -> Gradient -> <color> */
213 L4Menu = WMCreatePLArray(
214 WMCreatePLString(_("Sunset")),
215 WMCreatePLString("EXEC"),
216 WMCreatePLString("wdwrite WindowMaker WorkspaceBack "
217 "'(mvgradient, deepskyblue4, black, deepskyblue4, tomato4)'"),
218 NULL
220 WMAddToPLArray(L3Menu, L4Menu);
221 GRADIENT_BACK(_("Sky"), "blue4", "white");
222 GRADIENT_BACK(_("Blue Shades"), "#7080a5", "#101020");
223 GRADIENT_BACK(_("Indigo Shades"), "#746ebc", "#242e4c");
224 GRADIENT_BACK(_("Purple Shades"), "#654c66", "#151426");
225 GRADIENT_BACK(_("Wheat Shades"), "#a09060", "#302010");
226 GRADIENT_BACK(_("Grey Shades"), "#636380", "#131318");
227 GRADIENT_BACK(_("Wine Shades"), "#600040", "#180010");
228 #undef GRADIENT_BACK
229 WMAddToPLArray(L2Menu, L3Menu);
231 /* Root -> Appearance -> Background -> Images */
232 L3Menu = WMCreatePLArray(
233 WMCreatePLString(_("Images")),
234 WMCreatePLString("OPEN_MENU"),
235 WMCreatePLString("-noext $HOME/GNUstep/Library/WindowMaker/Backgrounds WITH wmsetbg -u -t"),
236 NULL
238 WMAddToPLArray(L2Menu, L3Menu);
240 WMAddToPLArray(L1Menu, L2Menu);
242 /* Root -> Appearance -> Save Theme */
243 L2Menu = WMCreatePLArray(
244 WMCreatePLString(_("Save Theme")),
245 WMCreatePLString("SHEXEC"),
246 WMCreatePLString("getstyle -p \"%a(Theme name, Name to save theme as)\""),
247 NULL
249 WMAddToPLArray(L1Menu, L2Menu);
251 /* Root -> Appearance -> Save IconSet */
252 L2Menu = WMCreatePLArray(
253 WMCreatePLString(_("Save IconSet")),
254 WMCreatePLString("SHEXEC"),
255 WMCreatePLString("geticonset $HOME/GNUstep/Library/WindowMaker/IconSets/"
256 "\"%a(IconSet name,Name to save icon set as)\""),
257 NULL
259 WMAddToPLArray(L1Menu, L2Menu);
260 WMAddToPLArray(RMenu, L1Menu);
262 /* Root -> Workspaces */
263 L1Menu = WMCreatePLArray(
264 WMCreatePLString(_("Workspaces")),
265 WMCreatePLString("WORKSPACE_MENU"),
266 NULL
268 WMAddToPLArray(RMenu, L1Menu);
270 /* Root -> Workspace */
271 L1Menu = WMCreatePLArray(WMCreatePLString(_("Workspace")), NULL);
272 L2Menu = WMCreatePLArray(
273 WMCreatePLString(_("Hide Others")),
274 WMCreatePLString("HIDE_OTHERS"),
275 NULL
277 WMAddToPLArray(L1Menu, L2Menu);
279 /* Root -> Workspace -> Show All */
280 L2Menu = WMCreatePLArray(
281 WMCreatePLString(_("Show All")),
282 WMCreatePLString("SHOW_ALL"),
283 NULL
285 WMAddToPLArray(L1Menu, L2Menu);
287 /* Root -> Workspace -> Arrange Icons */
288 L2Menu = WMCreatePLArray(
289 WMCreatePLString(_("Arrange Icons")),
290 WMCreatePLString("ARRANGE_ICONS"),
291 NULL
293 WMAddToPLArray(L1Menu, L2Menu);
295 /* Root -> Workspace -> Refresh */
296 L2Menu = WMCreatePLArray(
297 WMCreatePLString(_("Refresh")),
298 WMCreatePLString("REFRESH"),
299 NULL
301 WMAddToPLArray(L1Menu, L2Menu);
303 /* Root -> Workspace -> Save Session */
304 L2Menu = WMCreatePLArray(
305 WMCreatePLString(_("Save Session")),
306 WMCreatePLString("SAVE_SESSION"),
307 NULL
309 WMAddToPLArray(L1Menu, L2Menu);
311 /* Root -> Workspace -> Clear Session */
312 L2Menu = WMCreatePLArray(
313 WMCreatePLString(_("Clear Session")),
314 WMCreatePLString("CLEAR_SESSION"),
315 NULL
317 WMAddToPLArray(L1Menu, L2Menu);
318 WMAddToPLArray(RMenu, L1Menu);
320 /* Root -> Configure Window Maker */
321 L1Menu = WMCreatePLArray(
322 WMCreatePLString(_("Configure Window Maker")),
323 WMCreatePLString("EXEC"),
324 WMCreatePLString("WPrefs"),
325 NULL
327 WMAddToPLArray(RMenu, L1Menu);
329 /* Root -> Info Panel */
330 L1Menu = WMCreatePLArray(
331 WMCreatePLString(_("Info Panel")),
332 WMCreatePLString("INFO_PANEL"),
333 NULL
335 WMAddToPLArray(RMenu, L1Menu);
337 /* Root -> Restart Window Maker */
338 L1Menu = WMCreatePLArray(
339 WMCreatePLString(_("Restart Window Maker")),
340 WMCreatePLString("RESTART"),
341 NULL
343 WMAddToPLArray(RMenu, L1Menu);
345 /* Root -> Other Window Managers [-> <other window manager> ...] */
346 other_window_managers();
348 /* Root -> Lock Screen */
349 t = wfindfile(path, "xlock");
350 if (t) {
351 L1Menu = WMCreatePLArray(
352 WMCreatePLString(_("Lock Screen")),
353 WMCreatePLString("EXEC"),
354 WMCreatePLString("xlock -allowroot -usefirst -mode matrix"),
355 NULL
357 WMAddToPLArray(RMenu, L1Menu);
358 wfree(t);
361 /* Root -> Exit Window Maker */
362 L1Menu = WMCreatePLArray(
363 WMCreatePLString(_("Exit Window Maker")),
364 WMCreatePLString("EXIT"),
365 NULL
367 WMAddToPLArray(RMenu, L1Menu);
369 printf("%s", WMGetPropListDescription(RMenu, True));
370 puts("");
372 return 0;
376 * Creates an L2Menu made of L3Menu items
377 * Attaches to L1Menu
378 * - make sure previous menus of these levels are
379 * attached to their parent before calling
381 static void find_and_write(char *group, char *list[][2], int this_is_terminals)
383 int i, argc;
384 char *t, **argv, buf[PATH_MAX];
386 /* or else pre-existing menus of these levels
387 * will badly disturb empty group detection */
388 L2Menu = NULL;
389 L3Menu = NULL;
391 i = 0;
392 while (list[i][0]) {
393 /* Before checking if app exists, split its options */
394 wtokensplit(list[i][1], &argv, &argc);
395 t = wfindfile(path, argv[0]);
396 if (t) {
397 /* find a terminal to be used for cmnds that need a terminal */
398 if (this_is_terminals && !terminal)
399 terminal = wstrdup(list[i][1]);
400 if (*(argv[argc-1]) != '!') {
401 L3Menu = WMCreatePLArray(
402 WMCreatePLString(_(list[i][0])),
403 WMCreatePLString("EXEC"),
404 WMCreatePLString(list[i][1]),
405 NULL
407 } else {
408 char comm[PATH_MAX], *ptr;
410 strcpy(comm, list[i][1]);
411 /* delete character " !" from the command */
412 ptr = strchr(comm, '!');
413 while (ptr >= comm && (*ptr == '!' || isspace(*ptr)))
414 *ptr-- = '\0';
415 snprintf(buf, sizeof(buf), "%s -e %s", terminal ? terminal : "xterm" , comm);
416 /* Root -> Applications -> <category> -> <application> */
417 L3Menu = WMCreatePLArray(
418 WMCreatePLString(_(list[i][0])),
419 WMCreatePLString("EXEC"),
420 WMCreatePLString(buf),
421 NULL
424 if (!L2Menu)
425 L2Menu = WMCreatePLArray(
426 WMCreatePLString(group),
427 NULL
429 WMAddToPLArray(L2Menu, L3Menu);
430 wfree(t);
432 i++;
434 if (L2Menu)
435 WMAddToPLArray(L1Menu, L2Menu);
439 * Creates an L1Menu made of L2Menu items
440 * - make sure previous menus of these levels are
441 * attached to their parent before calling
442 * Attaches to RMenu
444 static void other_window_managers(void)
446 int i;
447 char *t, buf[PATH_MAX];
449 /* or else pre-existing menus of these levels
450 * will badly disturb empty group detection */
451 L1Menu = NULL;
452 L2Menu = NULL;
454 i = 0;
455 while (other_wm[i][0]) {
456 t = wfindfile(path, other_wm[i][1]);
457 if (t) {
458 snprintf(buf, sizeof(buf), _("Start %s"), _(other_wm[i][0]));
459 /* Root -> Other Window Managers -> <other window manager> */
460 L2Menu = WMCreatePLArray(
461 WMCreatePLString(buf),
462 WMCreatePLString("RESTART"),
463 WMCreatePLString(other_wm[i][1]),
464 NULL
466 if (!L1Menu)
467 L1Menu = WMCreatePLArray(
468 WMCreatePLString(_("Other Window Managers")),
469 NULL
471 WMAddToPLArray(L1Menu, L2Menu);
472 wfree(t);
474 i++;
476 if (L1Menu)
477 WMAddToPLArray(RMenu, L1Menu);
480 void print_help(int print_usage, int exitval)
482 printf("Usage: %s [-h] [-v]\n", __progname);
483 if (print_usage) {
484 puts("Writes a menu structure usable as ~/GNUstep/Defaults/WMRootMenu to stdout");
485 puts("");
486 puts(" -h, --help display this help and exit");
487 puts(" -v, --version output version information and exit");
489 exit(exitval);