Remove unused function raiseMenus()
[wmaker-crm.git] / src / rootmenu.c
blobbe8c7d55847f94a225a9a94de4a989a60580bcd3
1 /* rootmenu.c- user defined menu
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * Copyright (c) 1998-2003 Dan Pascu
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 * USA.
24 #include "wconfig.h"
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <sys/stat.h>
30 #include <sys/wait.h>
31 #include <sys/types.h>
32 #include <string.h>
33 #include <ctype.h>
34 #include <time.h>
35 #include <dirent.h>
37 #include <X11/Xlib.h>
38 #include <X11/Xutil.h>
39 #include <X11/Xatom.h>
41 #include "WindowMaker.h"
42 #include "actions.h"
43 #include "menu.h"
44 #include "funcs.h"
45 #include "dialog.h"
46 #include "keybind.h"
47 #include "stacking.h"
48 #include "workspace.h"
49 #include "defaults.h"
50 #include "framewin.h"
51 #include "session.h"
52 #include "xmodifier.h"
54 #include <WINGs/WUtil.h>
56 #define MAX_SHORTCUT_LENGTH 32
58 extern char *Locale;
60 extern WDDomain *WDRootMenu;
62 extern Cursor wCursor[WCUR_LAST];
64 extern Time LastTimestamp;
66 extern WPreferences wPreferences;
68 extern int wScreenCount;
70 static WMenu *readMenuPipe(WScreen * scr, char **file_name);
71 static WMenu *readMenuFile(WScreen * scr, char *file_name);
72 static WMenu *readMenuDirectory(WScreen * scr, char *title, char **file_name, char *command);
74 typedef struct Shortcut {
75 struct Shortcut *next;
77 int modifier;
78 KeyCode keycode;
79 WMenuEntry *entry;
80 WMenu *menu;
81 } Shortcut;
83 static Shortcut *shortcutList = NULL;
86 * Syntax:
87 * # main menu
88 * "Menu Name" MENU
89 * "Title" EXEC command_to_exec -params
90 * "Submenu" MENU
91 * "Title" EXEC command_to_exec -params
92 * "Submenu" END
93 * "Workspaces" WORKSPACE_MENU
94 * "Title" built_in_command
95 * "Quit" EXIT
96 * "Quick Quit" EXIT QUICK
97 * "Menu Name" END
99 * Commands may be preceded by SHORTCUT key
101 * Built-in commands:
103 * INFO_PANEL - shows the Info Panel
104 * LEGAL_PANEL - shows the Legal info panel
105 * SHUTDOWN [QUICK] - closes the X server [without confirmation]
106 * REFRESH - forces the desktop to be repainted
107 * EXIT [QUICK] - exit the window manager [without confirmation]
108 * EXEC <program> - execute an external program
109 * SHEXEC <command> - execute a shell command
110 * WORKSPACE_MENU - places the workspace submenu
111 * ARRANGE_ICONS
112 * RESTART [<window manager>] - restarts the window manager
113 * SHOW_ALL - unhide all windows on workspace
114 * HIDE_OTHERS - hides all windows excep the focused one
115 * OPEN_MENU file - read menu data from file which must be a valid menu file.
116 * OPEN_MENU /some/dir [/some/other/dir ...] [WITH command -options]
117 * - read menu data from directory(ies) and
118 * eventually precede each with a command.
119 * OPEN_MENU | command
120 * - opens command and uses its stdout to construct and insert
121 * the resulting menu in current position. The output of
122 * command must be a valid menu description.
123 * The space between '|' and command is optional.
124 * || will do the same, but will not cache the contents.
125 * SAVE_SESSION - saves the current state of the desktop, which include
126 * all running applications, all their hints (geometry,
127 * position on screen, workspace they live on, the dock
128 * or clip from where they were launched, and
129 * if minimized, shaded or hidden. Also saves the current
130 * workspace the user is on. All will be restored on every
131 * start of windowmaker until another SAVE_SESSION or
132 * CLEAR_SESSION is used. If SaveSessionOnExit = Yes; in
133 * WindowMaker domain file, then saving is automatically
134 * done on every windowmaker exit, overwriting any
135 * SAVE_SESSION or CLEAR_SESSION (see below). Also save
136 * dock state now.
137 * CLEAR_SESSION - clears any previous saved session. This will not have
138 * any effect if SaveSessionOnExit is True.
142 #define M_QUICK 1
144 /* menu commands */
146 static void execCommand(WMenu * menu, WMenuEntry * entry)
148 char *cmdline;
150 cmdline = ExpandOptions(menu->frame->screen_ptr, (char *)entry->clientdata);
152 XGrabPointer(dpy, menu->frame->screen_ptr->root_win, True, 0,
153 GrabModeAsync, GrabModeAsync, None, wCursor[WCUR_WAIT], CurrentTime);
154 XSync(dpy, 0);
156 if (cmdline) {
157 ExecuteShellCommand(menu->frame->screen_ptr, cmdline);
158 wfree(cmdline);
160 XUngrabPointer(dpy, CurrentTime);
161 XSync(dpy, 0);
164 static void exitCommand(WMenu * menu, WMenuEntry * entry)
166 static int inside = 0;
167 int result;
169 /* prevent reentrant calls */
170 if (inside)
171 return;
172 inside = 1;
174 #define R_CANCEL 0
175 #define R_EXIT 1
177 result = R_CANCEL;
179 if ((long)entry->clientdata == M_QUICK) {
180 result = R_EXIT;
181 } else {
182 int r, oldSaveSessionFlag;
184 oldSaveSessionFlag = wPreferences.save_session_on_exit;
185 r = wExitDialog(menu->frame->screen_ptr, _("Exit"),
186 _("Exit window manager?"), _("Exit"), _("Cancel"), NULL);
188 if (r == WAPRDefault) {
189 result = R_EXIT;
190 } else if (r == WAPRAlternate) {
191 /* Don't modify the "save session on exit" flag if the
192 * user canceled the operation. */
193 wPreferences.save_session_on_exit = oldSaveSessionFlag;
196 if (result == R_EXIT) {
197 #ifdef DEBUG
198 printf("Exiting WindowMaker.\n");
199 #endif
200 Shutdown(WSExitMode);
202 #undef R_EXIT
203 #undef R_CANCEL
204 inside = 0;
207 static void shutdownCommand(WMenu * menu, WMenuEntry * entry)
209 static int inside = 0;
210 int result;
212 /* prevent reentrant calls */
213 if (inside)
214 return;
215 inside = 1;
217 #define R_CANCEL 0
218 #define R_CLOSE 1
219 #define R_KILL 2
221 result = R_CANCEL;
222 if ((long)entry->clientdata == M_QUICK)
223 result = R_CLOSE;
224 else {
226 int r, oldSaveSessionFlag;
228 oldSaveSessionFlag = wPreferences.save_session_on_exit;
230 r = wExitDialog(menu->frame->screen_ptr,
231 _("Kill X session"),
232 _("Kill Window System session?\n"
233 "(all applications will be closed)"), _("Kill"), _("Cancel"), NULL);
234 if (r == WAPRDefault) {
235 result = R_KILL;
236 } else if (r == WAPRAlternate) {
237 /* Don't modify the "save session on exit" flag if the
238 * user canceled the operation. */
239 wPreferences.save_session_on_exit = oldSaveSessionFlag;
244 if (result != R_CANCEL) {
246 Shutdown(WSKillMode);
249 #undef R_CLOSE
250 #undef R_CANCEL
251 #undef R_KILL
252 inside = 0;
255 static void restartCommand(WMenu * menu, WMenuEntry * entry)
257 Shutdown(WSRestartPreparationMode);
258 Restart((char *)entry->clientdata, False);
259 Restart(NULL, True);
262 static void refreshCommand(WMenu * menu, WMenuEntry * entry)
264 wRefreshDesktop(menu->frame->screen_ptr);
267 static void arrangeIconsCommand(WMenu * menu, WMenuEntry * entry)
269 wArrangeIcons(menu->frame->screen_ptr, True);
272 static void showAllCommand(WMenu * menu, WMenuEntry * entry)
274 wShowAllWindows(menu->frame->screen_ptr);
277 static void hideOthersCommand(WMenu * menu, WMenuEntry * entry)
279 wHideOtherApplications(menu->frame->screen_ptr->focused_window);
282 static void saveSessionCommand(WMenu * menu, WMenuEntry * entry)
284 if (!wPreferences.save_session_on_exit)
285 wSessionSaveState(menu->frame->screen_ptr);
287 wScreenSaveState(menu->frame->screen_ptr);
290 static void clearSessionCommand(WMenu * menu, WMenuEntry * entry)
292 wSessionClearState(menu->frame->screen_ptr);
293 wScreenSaveState(menu->frame->screen_ptr);
296 static void infoPanelCommand(WMenu * menu, WMenuEntry * entry)
298 wShowInfoPanel(menu->frame->screen_ptr);
301 static void legalPanelCommand(WMenu * menu, WMenuEntry * entry)
303 wShowLegalPanel(menu->frame->screen_ptr);
306 /********************************************************************/
308 static char *getLocalizedMenuFile(char *menu)
310 char *buffer, *ptr, *locale;
311 int len;
313 if (!Locale)
314 return NULL;
316 len = strlen(menu) + strlen(Locale) + 8;
317 buffer = wmalloc(len);
319 /* try menu.locale_name */
320 snprintf(buffer, len, "%s.%s", menu, Locale);
321 if (access(buffer, F_OK) == 0) {
322 return buffer;
325 /* position of locale in our buffer */
326 locale = buffer + strlen(menu) + 1;
328 /* check if it is in the form aa_bb.encoding and check for aa_bb */
329 ptr = strchr(locale, '.');
330 if (ptr) {
331 *ptr = 0;
332 if (access(buffer, F_OK) == 0) {
333 return buffer;
336 /* now check for aa */
337 ptr = strchr(locale, '_');
338 if (ptr) {
339 *ptr = 0;
340 if (access(buffer, F_OK) == 0) {
341 return buffer;
345 wfree(buffer);
347 return NULL;
350 Bool wRootMenuPerformShortcut(XEvent * event)
352 WScreen *scr = wScreenForRootWindow(event->xkey.root);
353 Shortcut *ptr;
354 int modifiers;
355 int done = 0;
357 /* ignore CapsLock */
358 modifiers = event->xkey.state & ValidModMask;
360 for (ptr = shortcutList; ptr != NULL; ptr = ptr->next) {
361 if (ptr->keycode == 0 || ptr->menu->menu->screen_ptr != scr)
362 continue;
364 if (ptr->keycode == event->xkey.keycode && ptr->modifier == modifiers) {
365 (*ptr->entry->callback) (ptr->menu, ptr->entry);
366 done = True;
370 return done;
373 void wRootMenuBindShortcuts(Window window)
375 Shortcut *ptr;
377 ptr = shortcutList;
378 while (ptr) {
379 if (ptr->modifier != AnyModifier) {
380 XGrabKey(dpy, ptr->keycode, ptr->modifier | LockMask,
381 window, True, GrabModeAsync, GrabModeAsync);
382 #ifdef NUMLOCK_HACK
383 wHackedGrabKey(ptr->keycode, ptr->modifier, window, True, GrabModeAsync, GrabModeAsync);
384 #endif
386 XGrabKey(dpy, ptr->keycode, ptr->modifier, window, True, GrabModeAsync, GrabModeAsync);
387 ptr = ptr->next;
391 static void rebindKeygrabs(WScreen * scr)
393 WWindow *wwin;
395 wwin = scr->focused_window;
397 while (wwin != NULL) {
398 XUngrabKey(dpy, AnyKey, AnyModifier, wwin->frame->core->window);
400 if (!WFLAGP(wwin, no_bind_keys)) {
401 wWindowSetKeyGrabs(wwin);
403 wwin = wwin->prev;
407 static void removeShortcutsForMenu(WMenu * menu)
409 Shortcut *ptr, *tmp;
410 Shortcut *newList = NULL;
412 ptr = shortcutList;
413 while (ptr != NULL) {
414 tmp = ptr->next;
415 if (ptr->menu == menu) {
416 wfree(ptr);
417 } else {
418 ptr->next = newList;
419 newList = ptr;
421 ptr = tmp;
423 shortcutList = newList;
424 menu->menu->screen_ptr->flags.root_menu_changed_shortcuts = 1;
427 static Bool addShortcut(char *file, char *shortcutDefinition, WMenu * menu, WMenuEntry * entry)
429 Shortcut *ptr;
430 KeySym ksym;
431 char *k;
432 char buf[MAX_SHORTCUT_LENGTH], *b;
434 ptr = wmalloc(sizeof(Shortcut));
436 strncpy(buf, shortcutDefinition, MAX_SHORTCUT_LENGTH);
437 b = (char *)buf;
439 /* get modifiers */
440 ptr->modifier = 0;
441 while ((k = strchr(b, '+')) != NULL) {
442 int mod;
444 *k = 0;
445 mod = wXModifierFromKey(b);
446 if (mod < 0) {
447 wwarning(_("%s: invalid key modifier \"%s\""), file, b);
448 wfree(ptr);
449 return False;
451 ptr->modifier |= mod;
453 b = k + 1;
456 /* get key */
457 ksym = XStringToKeysym(b);
459 if (ksym == NoSymbol) {
460 wwarning(_("%s:invalid kbd shortcut specification \"%s\" for entry %s"),
461 file, shortcutDefinition, entry->text);
462 wfree(ptr);
463 return False;
466 ptr->keycode = XKeysymToKeycode(dpy, ksym);
467 if (ptr->keycode == 0) {
468 wwarning(_("%s:invalid key in shortcut \"%s\" for entry %s"), file,
469 shortcutDefinition, entry->text);
470 wfree(ptr);
471 return False;
474 ptr->menu = menu;
475 ptr->entry = entry;
477 ptr->next = shortcutList;
478 shortcutList = ptr;
480 menu->menu->screen_ptr->flags.root_menu_changed_shortcuts = 1;
482 return True;
485 /*******************************/
487 static char *cropline(char *line)
489 char *end;
491 if (strlen(line) == 0)
492 return line;
494 end = &(line[strlen(line)]) - 1;
495 while (isspace(*line) && *line != 0)
496 line++;
497 while (end > line && isspace(*end)) {
498 *end = 0;
499 end--;
501 return line;
504 static char *next_token(char *line, char **next)
506 char *tmp, c;
507 char *ret;
509 *next = NULL;
510 while (*line == ' ' || *line == '\t')
511 line++;
513 tmp = line;
515 if (*tmp == '"') {
516 tmp++;
517 line++;
518 while (*tmp != 0 && *tmp != '"')
519 tmp++;
520 if (*tmp != '"') {
521 wwarning(_("%s: unmatched '\"' in menu file"), line);
522 return NULL;
524 } else {
525 do {
526 if (*tmp == '\\')
527 tmp++;
529 if (*tmp != 0)
530 tmp++;
532 } while (*tmp != 0 && *tmp != ' ' && *tmp != '\t');
535 c = *tmp;
536 *tmp = 0;
537 ret = wstrdup(line);
538 *tmp = c;
540 if (c == 0)
541 return ret;
542 else
543 tmp++;
545 /* skip blanks */
546 while (*tmp == ' ' || *tmp == '\t')
547 tmp++;
549 if (*tmp != 0)
550 *next = tmp;
552 return ret;
555 static void separateCommand(char *line, char ***file, char **command)
557 char *token, *tmp = line;
558 WMArray *array = WMCreateArray(4);
559 int count, i;
561 *file = NULL;
562 *command = NULL;
563 do {
564 token = next_token(tmp, &tmp);
565 if (token) {
566 if (strcmp(token, "WITH") == 0) {
567 if (tmp != NULL && *tmp != 0)
568 *command = wstrdup(tmp);
569 else
570 wwarning(_("%s: missing command"), line);
571 break;
573 WMAddToArray(array, token);
575 } while (token != NULL && tmp != NULL);
577 count = WMGetArrayItemCount(array);
578 if (count > 0) {
579 *file = wmalloc(sizeof(char *) * (count + 1));
580 (*file)[count] = NULL;
581 for (i = 0; i < count; i++) {
582 (*file)[i] = WMGetFromArray(array, i);
585 WMFreeArray(array);
588 static void constructMenu(WMenu * menu, WMenuEntry * entry)
590 WMenu *submenu;
591 struct stat stat_buf;
592 char **path;
593 char *cmd;
594 char *lpath = NULL;
595 int i, first = -1;
596 time_t last = 0;
598 separateCommand((char *)entry->clientdata, &path, &cmd);
599 if (path == NULL || *path == NULL || **path == 0) {
600 wwarning(_("invalid OPEN_MENU specification: %s"), (char *)entry->clientdata);
601 return;
604 if (path[0][0] == '|') {
605 /* pipe menu */
607 if (!menu->cascades[entry->cascade] || menu->cascades[entry->cascade]->timestamp == 0) {
608 /* parse pipe */
610 submenu = readMenuPipe(menu->frame->screen_ptr, path);
612 if (submenu != NULL) {
613 if (path[0][1] == '|')
614 submenu->timestamp = 0;
615 else
616 submenu->timestamp = 1; /* there's no automatic reloading */
618 } else {
619 submenu = NULL;
622 } else {
623 i = 0;
624 while (path[i] != NULL) {
625 char *tmp;
627 if (strcmp(path[i], "-noext") == 0) {
628 i++;
629 continue;
632 tmp = wexpandpath(path[i]);
633 wfree(path[i]);
634 lpath = getLocalizedMenuFile(tmp);
635 if (lpath) {
636 wfree(tmp);
637 path[i] = lpath;
638 lpath = NULL;
639 } else {
640 path[i] = tmp;
643 if (stat(path[i], &stat_buf) == 0) {
644 if (last < stat_buf.st_mtime)
645 last = stat_buf.st_mtime;
646 if (first < 0)
647 first = i;
648 } else {
649 wsyserror(_("%s:could not stat menu"), path[i]);
650 /*goto finish; */
653 i++;
656 if (first < 0) {
657 wsyserror(_("%s:could not stat menu:%s"), "OPEN_MENU", (char *)entry->clientdata);
658 goto finish;
660 stat(path[first], &stat_buf);
661 if (!menu->cascades[entry->cascade]
662 || menu->cascades[entry->cascade]->timestamp < last) {
664 if (S_ISDIR(stat_buf.st_mode)) {
665 /* menu directory */
666 submenu = readMenuDirectory(menu->frame->screen_ptr, entry->text, path, cmd);
667 if (submenu)
668 submenu->timestamp = last;
669 } else if (S_ISREG(stat_buf.st_mode)) {
670 /* menu file */
672 if (cmd || path[1])
673 wwarning(_("too many parameters in OPEN_MENU: %s"),
674 (char *)entry->clientdata);
676 submenu = readMenuFile(menu->frame->screen_ptr, path[first]);
677 if (submenu)
678 submenu->timestamp = stat_buf.st_mtime;
679 } else {
680 submenu = NULL;
682 } else {
683 submenu = NULL;
687 if (submenu) {
688 wMenuEntryRemoveCascade(menu, entry);
689 wMenuEntrySetCascade(menu, entry, submenu);
692 finish:
693 i = 0;
694 while (path[i] != NULL)
695 wfree(path[i++]);
696 wfree(path);
697 if (cmd)
698 wfree(cmd);
701 static void cleanupWorkspaceMenu(WMenu * menu)
703 if (menu->frame->screen_ptr->workspace_menu == menu)
704 menu->frame->screen_ptr->workspace_menu = NULL;
707 static WMenuEntry *addWorkspaceMenu(WScreen * scr, WMenu * menu, char *title)
709 WMenu *wsmenu;
710 WMenuEntry *entry;
712 if (scr->flags.added_workspace_menu) {
713 wwarning(_
714 ("There are more than one WORKSPACE_MENU commands in the applications menu. Only one is allowed."));
715 return NULL;
716 } else {
717 scr->flags.added_workspace_menu = 1;
719 wsmenu = wWorkspaceMenuMake(scr, True);
720 wsmenu->on_destroy = cleanupWorkspaceMenu;
722 scr->workspace_menu = wsmenu;
723 entry = wMenuAddCallback(menu, title, NULL, NULL);
724 wMenuEntrySetCascade(menu, entry, wsmenu);
726 wWorkspaceMenuUpdate(scr, wsmenu);
728 return entry;
731 static void cleanupWindowsMenu(WMenu * menu)
733 if (menu->frame->screen_ptr->switch_menu == menu)
734 menu->frame->screen_ptr->switch_menu = NULL;
737 static WMenuEntry *addWindowsMenu(WScreen * scr, WMenu * menu, char *title)
739 WMenu *wwmenu;
740 WWindow *wwin;
741 WMenuEntry *entry;
743 if (scr->flags.added_windows_menu) {
744 wwarning(_
745 ("There are more than one WINDOWS_MENU commands in the applications menu. Only one is allowed."));
746 return NULL;
747 } else {
748 scr->flags.added_windows_menu = 1;
750 wwmenu = wMenuCreate(scr, _("Window List"), False);
751 wwmenu->on_destroy = cleanupWindowsMenu;
752 scr->switch_menu = wwmenu;
753 wwin = scr->focused_window;
754 while (wwin) {
755 UpdateSwitchMenu(scr, wwin, ACTION_ADD);
757 wwin = wwin->prev;
759 entry = wMenuAddCallback(menu, title, NULL, NULL);
760 wMenuEntrySetCascade(menu, entry, wwmenu);
762 return entry;
765 static WMenuEntry *addMenuEntry(WMenu * menu, char *title, char *shortcut, char *command,
766 char *params, char *file_name)
768 WScreen *scr;
769 WMenuEntry *entry = NULL;
770 Bool shortcutOk = False;
772 if (!menu)
773 return NULL;
774 scr = menu->frame->screen_ptr;
775 if (strcmp(command, "OPEN_MENU") == 0) {
776 if (!params) {
777 wwarning(_("%s:missing parameter for menu command \"%s\""), file_name, command);
778 } else {
779 WMenu *dummy;
780 char *path;
782 path = wfindfile(DEF_CONFIG_PATHS, params);
783 if (!path) {
784 path = wstrdup(params);
786 dummy = wMenuCreate(scr, title, False);
787 dummy->on_destroy = removeShortcutsForMenu;
788 entry = wMenuAddCallback(menu, title, constructMenu, path);
789 entry->free_cdata = free;
790 wMenuEntrySetCascade(menu, entry, dummy);
792 } else if (strcmp(command, "EXEC") == 0) {
793 if (!params)
794 wwarning(_("%s:missing parameter for menu command \"%s\""), file_name, command);
795 else {
796 entry = wMenuAddCallback(menu, title, execCommand, wstrconcat("exec ", params));
797 entry->free_cdata = free;
798 shortcutOk = True;
800 } else if (strcmp(command, "SHEXEC") == 0) {
801 if (!params)
802 wwarning(_("%s:missing parameter for menu command \"%s\""), file_name, command);
803 else {
804 entry = wMenuAddCallback(menu, title, execCommand, wstrdup(params));
805 entry->free_cdata = free;
806 shortcutOk = True;
808 } else if (strcmp(command, "EXIT") == 0) {
810 if (params && strcmp(params, "QUICK") == 0)
811 entry = wMenuAddCallback(menu, title, exitCommand, (void *)M_QUICK);
812 else
813 entry = wMenuAddCallback(menu, title, exitCommand, NULL);
815 shortcutOk = True;
816 } else if (strcmp(command, "SHUTDOWN") == 0) {
818 if (params && strcmp(params, "QUICK") == 0)
819 entry = wMenuAddCallback(menu, title, shutdownCommand, (void *)M_QUICK);
820 else
821 entry = wMenuAddCallback(menu, title, shutdownCommand, NULL);
823 shortcutOk = True;
824 } else if (strcmp(command, "REFRESH") == 0) {
825 entry = wMenuAddCallback(menu, title, refreshCommand, NULL);
827 shortcutOk = True;
828 } else if (strcmp(command, "WORKSPACE_MENU") == 0) {
829 entry = addWorkspaceMenu(scr, menu, title);
831 shortcutOk = True;
832 } else if (strcmp(command, "WINDOWS_MENU") == 0) {
833 entry = addWindowsMenu(scr, menu, title);
835 shortcutOk = True;
836 } else if (strcmp(command, "ARRANGE_ICONS") == 0) {
837 entry = wMenuAddCallback(menu, title, arrangeIconsCommand, NULL);
839 shortcutOk = True;
840 } else if (strcmp(command, "HIDE_OTHERS") == 0) {
841 entry = wMenuAddCallback(menu, title, hideOthersCommand, NULL);
843 shortcutOk = True;
844 } else if (strcmp(command, "SHOW_ALL") == 0) {
845 entry = wMenuAddCallback(menu, title, showAllCommand, NULL);
847 shortcutOk = True;
848 } else if (strcmp(command, "RESTART") == 0) {
849 entry = wMenuAddCallback(menu, title, restartCommand, params ? wstrdup(params) : NULL);
850 entry->free_cdata = free;
851 shortcutOk = True;
852 } else if (strcmp(command, "SAVE_SESSION") == 0) {
853 entry = wMenuAddCallback(menu, title, saveSessionCommand, NULL);
855 shortcutOk = True;
856 } else if (strcmp(command, "CLEAR_SESSION") == 0) {
857 entry = wMenuAddCallback(menu, title, clearSessionCommand, NULL);
858 shortcutOk = True;
859 } else if (strcmp(command, "INFO_PANEL") == 0) {
860 entry = wMenuAddCallback(menu, title, infoPanelCommand, NULL);
861 shortcutOk = True;
862 } else if (strcmp(command, "LEGAL_PANEL") == 0) {
863 entry = wMenuAddCallback(menu, title, legalPanelCommand, NULL);
864 shortcutOk = True;
865 } else {
866 wwarning(_("%s:unknown command \"%s\" in menu config."), file_name, command);
868 return NULL;
871 if (shortcut && entry) {
872 if (!shortcutOk) {
873 wwarning(_("%s:can't add shortcut for entry \"%s\""), file_name, title);
874 } else {
875 if (addShortcut(file_name, shortcut, menu, entry)) {
877 entry->rtext = GetShortcutString(shortcut);
879 entry->rtext = wstrdup(shortcut);
885 return entry;
888 /******************* Menu Configuration From File *******************/
890 static void separateline(char *line, char *title, char *command, char *parameter, char *shortcut)
892 int l, i;
894 l = strlen(line);
896 *title = 0;
897 *command = 0;
898 *parameter = 0;
899 *shortcut = 0;
900 /* get the title */
901 while (isspace(*line) && (*line != 0))
902 line++;
903 if (*line == '"') {
904 line++;
905 i = 0;
906 while (line[i] != '"' && (line[i] != 0))
907 i++;
908 if (line[i] != '"')
909 return;
910 } else {
911 i = 0;
912 while (!isspace(line[i]) && (line[i] != 0))
913 i++;
915 strncpy(title, line, i);
916 title[i++] = 0;
917 line += i;
919 /* get the command or shortcut keyword */
920 while (isspace(*line) && (*line != 0))
921 line++;
922 if (*line == 0)
923 return;
924 i = 0;
925 while (!isspace(line[i]) && (line[i] != 0))
926 i++;
927 strncpy(command, line, i);
928 command[i++] = 0;
929 line += i;
931 if (strcmp(command, "SHORTCUT") == 0) {
932 /* get the shortcut key */
933 while (isspace(*line) && (*line != 0))
934 line++;
935 if (*line == '"') {
936 line++;
937 i = 0;
938 while (line[i] != '"' && (line[i] != 0))
939 i++;
940 if (line[i] != '"')
941 return;
942 } else {
943 i = 0;
944 while (!isspace(line[i]) && (line[i] != 0))
945 i++;
947 strncpy(shortcut, line, i);
948 shortcut[i++] = 0;
949 line += i;
951 *command = 0;
953 /* get the command */
954 while (isspace(*line) && (*line != 0))
955 line++;
956 if (*line == 0)
957 return;
958 i = 0;
959 while (!isspace(line[i]) && (line[i] != 0))
960 i++;
961 strncpy(command, line, i);
962 command[i++] = 0;
963 line += i;
966 /* get the parameters */
967 while (isspace(*line) && (*line != 0))
968 line++;
969 if (*line == 0)
970 return;
972 if (*line == '"') {
973 line++;
974 l = 0;
975 while (line[l] != 0 && line[l] != '"') {
976 parameter[l] = line[l];
977 l++;
979 parameter[l] = 0;
980 return;
983 l = strlen(line);
984 while (isspace(line[l]) && (l > 0))
985 l--;
986 strncpy(parameter, line, l);
987 parameter[l] = 0;
990 static WMenu *parseCascade(WScreen * scr, WMenu * menu, FILE * file, char *file_name)
992 char linebuf[MAXLINE];
993 char elinebuf[MAXLINE];
994 char title[MAXLINE];
995 char command[MAXLINE];
996 char shortcut[MAXLINE];
997 char params[MAXLINE];
998 char *line;
1000 while (!feof(file)) {
1001 int lsize, ok;
1003 ok = 0;
1004 fgets(linebuf, MAXLINE, file);
1005 line = cropline(linebuf);
1006 lsize = strlen(line);
1007 do {
1008 if (line[lsize - 1] == '\\') {
1009 char *line2;
1010 int lsize2;
1011 fgets(elinebuf, MAXLINE, file);
1012 line2 = cropline(elinebuf);
1013 lsize2 = strlen(line2);
1014 if (lsize2 + lsize > MAXLINE) {
1015 wwarning(_("%s:maximal line size exceeded in menu config: %s"),
1016 file_name, line);
1017 ok = 2;
1018 } else {
1019 line[lsize - 1] = 0;
1020 lsize += lsize2 - 1;
1021 strcat(line, line2);
1023 } else {
1024 ok = 1;
1026 } while (!ok && !feof(file));
1027 if (ok == 2)
1028 continue;
1030 if (line[0] == 0 || line[0] == '#' || (line[0] == '/' && line[1] == '/'))
1031 continue;
1033 separateline(line, title, command, params, shortcut);
1035 if (!command[0]) {
1036 wwarning(_("%s:missing command in menu config: %s"), file_name, line);
1037 goto error;
1040 if (strcasecmp(command, "MENU") == 0) {
1041 WMenu *cascade;
1043 /* start submenu */
1045 cascade = wMenuCreate(scr, title, False);
1046 cascade->on_destroy = removeShortcutsForMenu;
1047 if (parseCascade(scr, cascade, file, file_name) == NULL) {
1048 wMenuDestroy(cascade, True);
1049 } else {
1050 wMenuEntrySetCascade(menu, wMenuAddCallback(menu, title, NULL, NULL), cascade);
1052 } else if (strcasecmp(command, "END") == 0) {
1053 /* end of menu */
1054 return menu;
1056 } else {
1057 /* normal items */
1058 addMenuEntry(menu, title, shortcut[0] ? shortcut : NULL, command,
1059 params[0] ? params : NULL, file_name);
1063 wwarning(_("%s:syntax error in menu file:END declaration missing"), file_name);
1064 return menu;
1066 error:
1067 return menu;
1070 static WMenu *readMenuFile(WScreen * scr, char *file_name)
1072 WMenu *menu = NULL;
1073 FILE *file = NULL;
1074 char linebuf[MAXLINE];
1075 char title[MAXLINE];
1076 char shortcut[MAXLINE];
1077 char command[MAXLINE];
1078 char params[MAXLINE];
1079 char *line;
1080 #ifdef USECPP
1081 char *args;
1082 int cpp = 0;
1083 #endif
1085 #ifdef USECPP
1086 if (!wPreferences.flags.nocpp) {
1087 args = MakeCPPArgs(file_name);
1088 if (!args) {
1089 wwarning(_("could not make arguments for menu file preprocessor"));
1090 } else {
1091 snprintf(command, sizeof(command), "%s %s %s", CPP_PATH, args, file_name);
1092 wfree(args);
1093 file = popen(command, "r");
1094 if (!file) {
1095 wsyserror(_("%s:could not open/preprocess menu file"), file_name);
1096 } else {
1097 cpp = 1;
1101 #endif /* USECPP */
1103 if (!file) {
1104 file = fopen(file_name, "rb");
1105 if (!file) {
1106 wsyserror(_("%s:could not open menu file"), file_name);
1107 return NULL;
1111 while (!feof(file)) {
1112 if (!fgets(linebuf, MAXLINE, file))
1113 break;
1114 line = cropline(linebuf);
1115 if (line[0] == 0 || line[0] == '#' || (line[0] == '/' && line[1] == '/'))
1116 continue;
1118 separateline(line, title, command, params, shortcut);
1120 if (!command[0]) {
1121 wwarning(_("%s:missing command in menu config: %s"), file_name, line);
1122 break;
1124 if (strcasecmp(command, "MENU") == 0) {
1125 menu = wMenuCreate(scr, title, True);
1126 menu->on_destroy = removeShortcutsForMenu;
1127 if (!parseCascade(scr, menu, file, file_name)) {
1128 wMenuDestroy(menu, True);
1130 break;
1131 } else {
1132 wwarning(_("%s:invalid menu file. MENU command is missing"), file_name);
1133 break;
1137 #ifdef CPP
1138 if (cpp) {
1139 if (pclose(file) == -1) {
1140 wsyserror(_("error reading preprocessed menu data"));
1142 } else {
1143 fclose(file);
1145 #else
1146 fclose(file);
1147 #endif
1149 return menu;
1152 /************ Menu Configuration From Pipe *************/
1154 static WMenu *readMenuPipe(WScreen * scr, char **file_name)
1156 WMenu *menu = NULL;
1157 FILE *file = NULL;
1158 char linebuf[MAXLINE];
1159 char title[MAXLINE];
1160 char command[MAXLINE];
1161 char params[MAXLINE];
1162 char shortcut[MAXLINE];
1163 char *line;
1164 char *filename;
1165 char flat_file[MAXLINE];
1166 int i;
1167 #ifdef USECPP
1168 char *args;
1169 int cpp = 0;
1170 #endif
1172 flat_file[0] = '\0';
1174 for (i = 0; file_name[i] != NULL; i++) {
1175 strcat(flat_file, file_name[i]);
1176 strcat(flat_file, " ");
1178 filename = flat_file + (flat_file[1] == '|' ? 2 : 1);
1180 #ifdef USECPP
1181 if (!wPreferences.flags.nocpp) {
1182 args = MakeCPPArgs(filename);
1183 if (!args) {
1184 wwarning(_("could not make arguments for menu file preprocessor"));
1185 } else {
1186 snprintf(command, sizeof(command), "%s | %s %s", filename, CPP_PATH, args);
1188 wfree(args);
1189 file = popen(command, "r");
1190 if (!file) {
1191 wsyserror(_("%s:could not open/preprocess menu file"), filename);
1192 } else {
1193 cpp = 1;
1197 #endif /* USECPP */
1199 if (!file) {
1200 file = popen(filename, "rb");
1202 if (!file) {
1203 wsyserror(_("%s:could not open menu file"), filename);
1204 return NULL;
1208 while (!feof(file)) {
1209 if (!fgets(linebuf, MAXLINE, file))
1210 break;
1211 line = cropline(linebuf);
1212 if (line[0] == 0 || line[0] == '#' || (line[0] == '/' && line[1] == '/'))
1213 continue;
1215 separateline(line, title, command, params, shortcut);
1217 if (!command[0]) {
1218 wwarning(_("%s:missing command in menu config: %s"), file_name, line);
1219 break;
1221 if (strcasecmp(command, "MENU") == 0) {
1222 menu = wMenuCreate(scr, title, True);
1223 menu->on_destroy = removeShortcutsForMenu;
1224 if (!parseCascade(scr, menu, file, filename)) {
1225 wMenuDestroy(menu, True);
1227 break;
1228 } else {
1229 wwarning(_("%s:no title given for the root menu"), filename);
1230 break;
1234 pclose(file);
1236 return menu;
1239 typedef struct {
1240 char *name;
1241 int index;
1242 } dir_data;
1244 static int myCompare(const void *d1, const void *d2)
1246 dir_data *p1 = *(dir_data **) d1;
1247 dir_data *p2 = *(dir_data **) d2;
1249 return strcmp(p1->name, p2->name);
1252 /************ Menu Configuration From Directory *************/
1254 static Bool isFilePackage(char *file)
1256 int l;
1258 /* check if the extension indicates this file is a
1259 * file package. For now, only recognize .themed */
1261 l = strlen(file);
1263 if (l > 7 && strcmp(&(file[l - 7]), ".themed") == 0) {
1264 return True;
1265 } else {
1266 return False;
1270 static WMenu *readMenuDirectory(WScreen * scr, char *title, char **path, char *command)
1272 DIR *dir;
1273 struct dirent *dentry;
1274 struct stat stat_buf;
1275 WMenu *menu = NULL;
1276 char *buffer;
1277 WMArray *dirs = NULL, *files = NULL;
1278 WMArrayIterator iter;
1279 int length, i, have_space = 0;
1280 dir_data *data;
1281 int stripExtension = 0;
1283 dirs = WMCreateArray(16);
1284 files = WMCreateArray(16);
1286 i = 0;
1287 while (path[i] != NULL) {
1288 if (strcmp(path[i], "-noext") == 0) {
1289 stripExtension = 1;
1290 i++;
1291 continue;
1294 dir = opendir(path[i]);
1295 if (!dir) {
1296 i++;
1297 continue;
1300 while ((dentry = readdir(dir))) {
1302 if (strcmp(dentry->d_name, ".") == 0 || strcmp(dentry->d_name, "..") == 0)
1303 continue;
1305 if (dentry->d_name[0] == '.')
1306 continue;
1308 buffer = malloc(strlen(path[i]) + strlen(dentry->d_name) + 4);
1309 if (!buffer) {
1310 wsyserror(_("out of memory while constructing directory menu %s"), path[i]);
1311 break;
1314 strcpy(buffer, path[i]);
1315 strcat(buffer, "/");
1316 strcat(buffer, dentry->d_name);
1318 if (stat(buffer, &stat_buf) != 0) {
1319 wsyserror(_("%s:could not stat file \"%s\" in menu directory"),
1320 path[i], dentry->d_name);
1321 } else {
1322 Bool isFilePack = False;
1324 data = NULL;
1325 if (S_ISDIR(stat_buf.st_mode)
1326 && !(isFilePack = isFilePackage(dentry->d_name))) {
1328 /* access always returns success for user root */
1329 if (access(buffer, X_OK) == 0) {
1330 /* Directory is accesible. Add to directory list */
1332 data = (dir_data *) wmalloc(sizeof(dir_data));
1333 data->name = wstrdup(dentry->d_name);
1334 data->index = i;
1336 WMAddToArray(dirs, data);
1338 } else if (S_ISREG(stat_buf.st_mode) || isFilePack) {
1339 /* Hack because access always returns X_OK success for user root */
1340 #define S_IXANY (S_IXUSR | S_IXGRP | S_IXOTH)
1341 if ((command != NULL && access(buffer, R_OK) == 0) ||
1342 (command == NULL && access(buffer, X_OK) == 0 &&
1343 (stat_buf.st_mode & S_IXANY))) {
1345 data = (dir_data *) wmalloc(sizeof(dir_data));
1346 data->name = wstrdup(dentry->d_name);
1347 data->index = i;
1349 WMAddToArray(files, data);
1353 wfree(buffer);
1356 closedir(dir);
1357 i++;
1360 if (!WMGetArrayItemCount(dirs) && !WMGetArrayItemCount(files)) {
1361 WMFreeArray(dirs);
1362 WMFreeArray(files);
1363 return NULL;
1366 WMSortArray(dirs, myCompare);
1367 WMSortArray(files, myCompare);
1369 menu = wMenuCreate(scr, title, False);
1370 menu->on_destroy = removeShortcutsForMenu;
1372 WM_ITERATE_ARRAY(dirs, data, iter) {
1373 /* New directory. Use same OPEN_MENU command that was used
1374 * for the current directory. */
1375 length = strlen(path[data->index]) + strlen(data->name) + 6;
1376 if (stripExtension)
1377 length += 7;
1378 if (command)
1379 length += strlen(command) + 6;
1380 buffer = malloc(length);
1381 if (!buffer) {
1382 wsyserror(_("out of memory while constructing directory menu %s"), path[data->index]);
1383 break;
1386 buffer[0] = '\0';
1387 if (stripExtension)
1388 strcat(buffer, "-noext ");
1390 have_space = strchr(path[data->index], ' ') != NULL || strchr(data->name, ' ') != NULL;
1392 if (have_space)
1393 strcat(buffer, "\"");
1394 strcat(buffer, path[data->index]);
1396 strcat(buffer, "/");
1397 strcat(buffer, data->name);
1398 if (have_space)
1399 strcat(buffer, "\"");
1400 if (command) {
1401 strcat(buffer, " WITH ");
1402 strcat(buffer, command);
1405 addMenuEntry(menu, data->name, NULL, "OPEN_MENU", buffer, path[data->index]);
1407 wfree(buffer);
1408 if (data->name)
1409 wfree(data->name);
1410 wfree(data);
1413 WM_ITERATE_ARRAY(files, data, iter) {
1414 /* executable: add as entry */
1415 length = strlen(path[data->index]) + strlen(data->name) + 6;
1416 if (command)
1417 length += strlen(command);
1419 buffer = malloc(length);
1420 if (!buffer) {
1421 wsyserror(_("out of memory while constructing directory menu %s"), path[data->index]);
1422 break;
1425 have_space = strchr(path[data->index], ' ') != NULL || strchr(data->name, ' ') != NULL;
1426 if (command != NULL) {
1427 strcpy(buffer, command);
1428 strcat(buffer, " ");
1429 if (have_space)
1430 strcat(buffer, "\"");
1431 strcat(buffer, path[data->index]);
1432 } else {
1433 if (have_space) {
1434 buffer[0] = '"';
1435 buffer[1] = 0;
1436 strcat(buffer, path[data->index]);
1437 } else {
1438 strcpy(buffer, path[data->index]);
1441 strcat(buffer, "/");
1442 strcat(buffer, data->name);
1443 if (have_space)
1444 strcat(buffer, "\"");
1446 if (stripExtension) {
1447 char *ptr = strrchr(data->name, '.');
1448 if (ptr && ptr != data->name)
1449 *ptr = 0;
1451 addMenuEntry(menu, data->name, NULL, "SHEXEC", buffer, path[data->index]);
1453 wfree(buffer);
1454 if (data->name)
1455 wfree(data->name);
1456 wfree(data);
1459 WMFreeArray(files);
1460 WMFreeArray(dirs);
1462 return menu;
1465 /************ Menu Configuration From WMRootMenu *************/
1467 static WMenu *makeDefaultMenu(WScreen * scr)
1469 WMenu *menu = NULL;
1471 menu = wMenuCreate(scr, _("Commands"), True);
1472 wMenuAddCallback(menu, "XTerm", execCommand, "xterm");
1473 wMenuAddCallback(menu, "rxvt", execCommand, "rxvt");
1474 wMenuAddCallback(menu, _("Restart"), restartCommand, NULL);
1475 wMenuAddCallback(menu, _("Exit..."), exitCommand, NULL);
1476 return menu;
1480 *----------------------------------------------------------------------
1481 * configureMenu--
1482 * Reads root menu configuration from defaults database.
1484 *----------------------------------------------------------------------
1486 static WMenu *configureMenu(WScreen * scr, WMPropList * definition)
1488 WMenu *menu = NULL;
1489 WMPropList *elem;
1490 int i, count;
1491 WMPropList *title, *command, *params;
1492 char *tmp, *mtitle;
1494 if (WMIsPLString(definition)) {
1495 struct stat stat_buf;
1496 char *path = NULL;
1497 Bool menu_is_default = False;
1499 /* menu definition is a string. Probably a path, so parse the file */
1501 tmp = wexpandpath(WMGetFromPLString(definition));
1503 path = getLocalizedMenuFile(tmp);
1505 if (!path)
1506 path = wfindfile(DEF_CONFIG_PATHS, tmp);
1508 if (!path) {
1509 path = wfindfile(DEF_CONFIG_PATHS, DEF_MENU_FILE);
1510 menu_is_default = True;
1513 if (!path) {
1514 wsyserror(_("could not find menu file \"%s\" referenced in WMRootMenu"), tmp);
1515 wfree(tmp);
1516 return NULL;
1519 if (stat(path, &stat_buf) < 0) {
1520 wsyserror(_("could not access menu \"%s\" referenced in WMRootMenu"), path);
1521 wfree(path);
1522 wfree(tmp);
1523 return NULL;
1526 if (!scr->root_menu || stat_buf.st_mtime > scr->root_menu->timestamp
1527 /* if the pointer in WMRootMenu has changed */
1528 || WDRootMenu->timestamp > scr->root_menu->timestamp) {
1530 if (menu_is_default) {
1531 wwarning(_
1532 ("using default menu file \"%s\" as the menu referenced in WMRootMenu could not be found "),
1533 path);
1536 menu = readMenuFile(scr, path);
1537 if (menu)
1538 menu->timestamp = WMAX(stat_buf.st_mtime, WDRootMenu->timestamp);
1539 } else {
1540 menu = NULL;
1542 wfree(path);
1543 wfree(tmp);
1545 return menu;
1548 count = WMGetPropListItemCount(definition);
1549 if (count == 0)
1550 return NULL;
1552 elem = WMGetFromPLArray(definition, 0);
1553 if (!WMIsPLString(elem)) {
1554 tmp = WMGetPropListDescription(elem, False);
1555 wwarning(_("%s:format error in root menu configuration \"%s\""), "WMRootMenu", tmp);
1556 wfree(tmp);
1557 return NULL;
1559 mtitle = WMGetFromPLString(elem);
1561 menu = wMenuCreate(scr, mtitle, False);
1562 menu->on_destroy = removeShortcutsForMenu;
1564 #ifdef GLOBAL_SUBMENU_FILE
1566 WMenu *submenu;
1567 WMenuEntry *mentry;
1569 submenu = readMenuFile(scr, GLOBAL_SUBMENU_FILE);
1571 if (submenu) {
1572 mentry = wMenuAddCallback(menu, submenu->frame->title, NULL, NULL);
1573 wMenuEntrySetCascade(menu, mentry, submenu);
1576 #endif
1578 for (i = 1; i < count; i++) {
1579 elem = WMGetFromPLArray(definition, i);
1580 #if 0
1581 if (WMIsPLString(elem)) {
1582 char *file;
1584 file = WMGetFromPLString(elem);
1587 #endif
1588 if (!WMIsPLArray(elem) || WMGetPropListItemCount(elem) < 2)
1589 goto error;
1591 if (WMIsPLArray(WMGetFromPLArray(elem, 1))) {
1592 WMenu *submenu;
1593 WMenuEntry *mentry;
1595 /* submenu */
1596 submenu = configureMenu(scr, elem);
1597 if (submenu) {
1598 mentry = wMenuAddCallback(menu, submenu->frame->title, NULL, NULL);
1599 wMenuEntrySetCascade(menu, mentry, submenu);
1601 } else {
1602 int idx = 0;
1603 WMPropList *shortcut;
1604 /* normal entry */
1606 title = WMGetFromPLArray(elem, idx++);
1607 shortcut = WMGetFromPLArray(elem, idx++);
1608 if (strcmp(WMGetFromPLString(shortcut), "SHORTCUT") == 0) {
1609 shortcut = WMGetFromPLArray(elem, idx++);
1610 command = WMGetFromPLArray(elem, idx++);
1611 } else {
1612 command = shortcut;
1613 shortcut = NULL;
1615 params = WMGetFromPLArray(elem, idx++);
1617 if (!title || !command)
1618 goto error;
1620 addMenuEntry(menu, WMGetFromPLString(title),
1621 shortcut ? WMGetFromPLString(shortcut) : NULL,
1622 WMGetFromPLString(command),
1623 params ? WMGetFromPLString(params) : NULL, "WMRootMenu");
1625 continue;
1627 error:
1628 tmp = WMGetPropListDescription(elem, False);
1629 wwarning(_("%s:format error in root menu configuration \"%s\""), "WMRootMenu", tmp);
1630 wfree(tmp);
1633 return menu;
1637 *----------------------------------------------------------------------
1638 * OpenRootMenu--
1639 * Opens the root menu, parsing the menu configuration from the
1640 * defaults database.
1641 * If the menu is already mapped and is not sticked to the
1642 * root window, it will be unmapped.
1644 * Side effects:
1645 * The menu may be remade.
1647 * Notes:
1648 * Construction of OPEN_MENU entries are delayed to the moment the
1649 * user map's them.
1650 *----------------------------------------------------------------------
1652 void OpenRootMenu(WScreen * scr, int x, int y, int keyboard)
1654 WMenu *menu = NULL;
1655 WMPropList *definition;
1657 static WMPropList *domain=NULL;
1659 if (!domain) {
1660 domain = WMCreatePLString("WMRootMenu");
1664 scr->flags.root_menu_changed_shortcuts = 0;
1665 scr->flags.added_workspace_menu = 0;
1666 scr->flags.added_windows_menu = 0;
1668 if (scr->root_menu && scr->root_menu->flags.mapped) {
1669 menu = scr->root_menu;
1670 if (!menu->flags.buttoned) {
1671 wMenuUnmap(menu);
1672 } else {
1673 wRaiseFrame(menu->frame->core);
1675 if (keyboard)
1676 wMenuMapAt(menu, 0, 0, True);
1677 else
1678 wMenuMapCopyAt(menu, x - menu->frame->core->width / 2, y);
1680 return;
1683 definition = WDRootMenu->dictionary;
1686 definition = PLGetDomain(domain);
1688 if (definition) {
1689 if (WMIsPLArray(definition)) {
1690 if (!scr->root_menu || WDRootMenu->timestamp > scr->root_menu->timestamp) {
1691 menu = configureMenu(scr, definition);
1692 if (menu)
1693 menu->timestamp = WDRootMenu->timestamp;
1695 } else
1696 menu = NULL;
1697 } else {
1698 menu = configureMenu(scr, definition);
1702 if (!menu) {
1703 /* menu hasn't changed or could not be read */
1704 if (!scr->root_menu) {
1705 wMessageDialog(scr, _("Error"),
1706 _("The applications menu could not be loaded. "
1707 "Look at the console output for a detailed "
1708 "description of the errors."), _("OK"), NULL, NULL);
1710 menu = makeDefaultMenu(scr);
1711 scr->root_menu = menu;
1713 menu = scr->root_menu;
1714 } else {
1715 /* new root menu */
1716 if (scr->root_menu) {
1717 wMenuDestroy(scr->root_menu, True);
1719 scr->root_menu = menu;
1721 if (menu) {
1722 int newx, newy;
1724 if (keyboard && x == 0 && y == 0) {
1725 newx = newy = 0;
1726 } else if (keyboard && x == scr->scr_width / 2 && y == scr->scr_height / 2) {
1727 newx = x - menu->frame->core->width / 2;
1728 newy = y - menu->frame->core->height / 2;
1729 } else {
1730 newx = x - menu->frame->core->width / 2;
1731 newy = y;
1733 wMenuMapAt(menu, newx, newy, keyboard);
1736 if (scr->flags.root_menu_changed_shortcuts)
1737 rebindKeygrabs(scr);