1 /* Copyright (C) 2010 Carlos R. Mafra */
4 #define _GNU_SOURCE /* getopt_long */
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
[])
39 struct option longopts
[] = {
40 { "version", no_argument
, NULL
, 'v' },
41 { "help", no_argument
, NULL
, 'h' },
45 while ((ch
= getopt_long(argc
, argv
, "hv", longopts
, NULL
)) != -1)
48 printf("%s (Window Maker %s)\n", __progname
, VERSION
);
65 path
= getenv("PATH");
66 setlocale(LC_ALL
, "");
68 #if HAVE_LIBINTL_H && I18N
69 if (getenv("NLSPATH"))
70 bindtextdomain("wmgenmenu", getenv("NLSPATH"));
72 bindtextdomain("wmgenmenu", LOCALEDIR
);
74 bind_textdomain_codeset("wmgenmenu", "UTF-8");
75 textdomain("wmgenmenu");
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)
96 * L1Menu Configure Window Maker
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:)")),
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"),
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"),
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"),
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 "\")'"), \
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");
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 "\"'"), \
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)'"),
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");
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"),
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)\""),
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)\""),
259 WMAddToPLArray(L1Menu
, L2Menu
);
260 WMAddToPLArray(RMenu
, L1Menu
);
262 /* Root -> Workspaces */
263 L1Menu
= WMCreatePLArray(
264 WMCreatePLString(_("Workspaces")),
265 WMCreatePLString("WORKSPACE_MENU"),
268 WMAddToPLArray(RMenu
, L1Menu
);
270 /* Root -> Workspace */
271 L1Menu
= WMCreatePLArray(WMCreatePLString(_("Workspace")), NULL
);
272 L2Menu
= WMCreatePLArray(
273 WMCreatePLString(_("Hide Others")),
274 WMCreatePLString("HIDE_OTHERS"),
277 WMAddToPLArray(L1Menu
, L2Menu
);
279 /* Root -> Workspace -> Show All */
280 L2Menu
= WMCreatePLArray(
281 WMCreatePLString(_("Show All")),
282 WMCreatePLString("SHOW_ALL"),
285 WMAddToPLArray(L1Menu
, L2Menu
);
287 /* Root -> Workspace -> Arrange Icons */
288 L2Menu
= WMCreatePLArray(
289 WMCreatePLString(_("Arrange Icons")),
290 WMCreatePLString("ARRANGE_ICONS"),
293 WMAddToPLArray(L1Menu
, L2Menu
);
295 /* Root -> Workspace -> Refresh */
296 L2Menu
= WMCreatePLArray(
297 WMCreatePLString(_("Refresh")),
298 WMCreatePLString("REFRESH"),
301 WMAddToPLArray(L1Menu
, L2Menu
);
303 /* Root -> Workspace -> Save Session */
304 L2Menu
= WMCreatePLArray(
305 WMCreatePLString(_("Save Session")),
306 WMCreatePLString("SAVE_SESSION"),
309 WMAddToPLArray(L1Menu
, L2Menu
);
311 /* Root -> Workspace -> Clear Session */
312 L2Menu
= WMCreatePLArray(
313 WMCreatePLString(_("Clear Session")),
314 WMCreatePLString("CLEAR_SESSION"),
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"),
327 WMAddToPLArray(RMenu
, L1Menu
);
329 /* Root -> Info Panel */
330 L1Menu
= WMCreatePLArray(
331 WMCreatePLString(_("Info Panel")),
332 WMCreatePLString("INFO_PANEL"),
335 WMAddToPLArray(RMenu
, L1Menu
);
337 /* Root -> Restart Window Maker */
338 L1Menu
= WMCreatePLArray(
339 WMCreatePLString(_("Restart Window Maker")),
340 WMCreatePLString("RESTART"),
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");
351 L1Menu
= WMCreatePLArray(
352 WMCreatePLString(_("Lock Screen")),
353 WMCreatePLString("EXEC"),
354 WMCreatePLString("xlock -allowroot -usefirst -mode matrix"),
357 WMAddToPLArray(RMenu
, L1Menu
);
361 /* Root -> Exit Window Maker */
362 L1Menu
= WMCreatePLArray(
363 WMCreatePLString(_("Exit Window Maker")),
364 WMCreatePLString("EXIT"),
367 WMAddToPLArray(RMenu
, L1Menu
);
369 printf("%s", WMGetPropListDescription(RMenu
, True
));
376 * Creates an L2Menu made of L3Menu items
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
)
384 char *t
, **argv
, buf
[PATH_MAX
];
386 /* or else pre-existing menus of these levels
387 * will badly disturb empty group detection */
393 /* Before checking if app exists, split its options */
394 wtokensplit(list
[i
][1], &argv
, &argc
);
395 t
= wfindfile(path
, argv
[0]);
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]),
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
)))
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
),
425 L2Menu
= WMCreatePLArray(
426 WMCreatePLString(group
),
429 WMAddToPLArray(L2Menu
, L3Menu
);
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
444 static void other_window_managers(void)
447 char *t
, buf
[PATH_MAX
];
449 /* or else pre-existing menus of these levels
450 * will badly disturb empty group detection */
455 while (other_wm
[i
][0]) {
456 t
= wfindfile(path
, other_wm
[i
][1]);
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]),
467 L1Menu
= WMCreatePLArray(
468 WMCreatePLString(_("Other Window Managers")),
471 WMAddToPLArray(L1Menu
, L2Menu
);
477 WMAddToPLArray(RMenu
, L1Menu
);
480 void print_help(int print_usage
, int exitval
)
482 printf("Usage: %s [-h] [-v]\n", __progname
);
484 puts("Writes a menu structure usable as ~/GNUstep/Defaults/WMRootMenu to stdout");
486 puts(" -h, --help display this help and exit");
487 puts(" -v, --version output version information and exit");