1 /*--------------------------------*-C-*---------------------------------*
3 *----------------------------------------------------------------------*
4 * $Id: menubar.C,v 1.2 2003-11-24 17:31:27 pcg Exp $
6 * Copyright (c) 1997,1998 mj olesen <olesen@me.QueensU.CA>
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., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *----------------------------------------------------------------------*
22 * refer.html (or refer.txt) contains up-to-date documentation. The
23 * summary that appears at the end of this file was taken from there.
24 *----------------------------------------------------------------------*/
26 #include "../config.h" /* NECESSARY */
27 #include "rxvt.h" /* NECESSARY */
31 #include "menubar.intpro" /* PROTOS for internal routines */
33 #define Menu_PixelWidth(menu) \
34 (2 * SHADOW + Width2Pixel ((menu)->width + 3 * HSPACE))
37 const char name; /* (l)eft, (u)p, (d)own, (r)ight */
38 const unsigned char str[5]; /* str[0] = STRLEN (str+1) */
40 { 'l', "\003\033[D" },
41 { 'u', "\003\033[A" },
42 { 'd', "\003\033[B" },
49 * find an item called NAME in MENU
53 rxvt_menuitem_find(const menu_t *menu, const char *name)
62 /* find the last item in the menu, this is good for separators */
63 for (item = menu->tail; item != NULL; item = item->prev) {
64 if (item->entry.type == MenuSubMenu) {
65 if (!STRCMP(name, (item->entry.submenu.menu)->name))
67 } else if ((isSeparator(name) && isSeparator(item->name))
68 || !STRCMP(name, item->name))
75 * unlink ITEM from its MENU and free its memory
79 rxvt_menuitem_free(pR_ menu_t *menu, menuitem_t *item)
82 menuitem_t *prev, *next;
96 if (menu->tail == item)
98 if (menu->head == item)
101 switch (item->entry.type) {
103 case MenuTerminalAction:
104 free(item->entry.action.str);
107 rxvt_menu_delete(aR_ item->entry.submenu.menu);
110 if (item->name != NULL)
112 if (item->name2 != NULL)
118 * sort command vs. terminal actions and
119 * remove the first character of STR if it's '\0'
123 rxvt_action_type(action_t *action, unsigned char *str)
127 #if defined (DEBUG_MENU) || defined (DEBUG_MENUARROWS)
129 fprintf(stderr, "(len %d) = %s\n", len, str);
131 len = rxvt_Str_escaped((char *)str);
137 /* sort command vs. terminal actions */
138 action->type = MenuAction;
139 if (str[0] == '\0') {
140 /* the functional equivalent: memmove (str, str+1, len); */
141 unsigned char *dst = (str);
142 unsigned char *src = (str + 1);
143 unsigned char *end = (str + len);
148 len--; /* decrement length */
150 action->type = MenuTerminalAction;
160 rxvt_action_dispatch(pR_ action_t *action)
162 switch (action->type) {
163 case MenuTerminalAction:
164 rxvt_cmd_write(aR_ action->str, action->len);
168 rxvt_tt_write(aR_ action->str, action->len);
178 /* return the arrow index corresponding to NAME */
181 rxvt_menuarrow_find(char name)
185 for (i = 0; i < NARROWS; i++)
186 if (name == Arrows[i].name)
191 /* free the memory associated with arrow NAME of the current menubar */
194 rxvt_menuarrow_free(pR_ char name)
199 i = rxvt_menuarrow_find(name);
201 action_t *act = &(R->h->CurrentBar->arrows[i]);
205 case MenuTerminalAction:
211 act->type = MenuLabel;
214 for (i = 0; i < NARROWS; i++)
215 rxvt_menuarrow_free(aR_ Arrows[i].name);
221 rxvt_menuarrow_add(pR_ char *string)
235 MEMSET(parse, 0, sizeof(parse));
237 /* fprintf(stderr, "add arrows = `%s'\n", string); */
238 for (p = string; p != NULL && *p; string = p) {
240 /* fprintf(stderr, "parsing at %s\n", string); */
250 i = rxvt_menuarrow_find(string[1]);
254 continue; /* not found */
263 p = STRCHR(string, '\0');
268 p = STRCHR(next, '<');
270 if (p[1] && p[2] == '>')
274 if (beg.str == NULL) /* no end needed */
275 p = STRCHR(next, '\0');
284 cur->len = (p - string);
287 #ifdef DEBUG_MENUARROWS
289 fprintf(stderr, "<b>(len %d) = %.*s\n",
290 cur->len, cur->len, (cur->str ? cur->str : ""));
291 for (i = 0; i < NARROWS; i++) {
293 fprintf(stderr, "<%c>(len %d) = %.*s\n",
295 cur->len, cur->len, (cur->str ? cur->str : ""));
298 fprintf(stderr, "<e>(len %d) = %.*s\n",
299 cur->len, cur->len, (cur->str ? cur->str : ""));
302 xtra_len = (beg.len + end.len);
303 for (i = 0; i < NARROWS; i++) {
304 if (xtra_len || parse[i].len)
305 rxvt_menuarrow_free(aR_ Arrows[i].name);
308 for (i = 0; i < NARROWS; i++) {
315 str = rxvt_malloc(parse[i].len + xtra_len + 1);
319 STRNCPY(str + len, beg.str, beg.len);
322 STRNCPY(str + len, parse[i].str, parse[i].len);
326 STRNCPY(str + len, end.str, end.len);
331 #ifdef DEBUG_MENUARROWS
332 fprintf(stderr, "<%c>(len %d) = %s\n", Arrows[i].name, len, str);
334 if (rxvt_action_type(&(R->h->CurrentBar->arrows[i]), str) < 0)
341 rxvt_menuitem_add(menu_t *menu, const char *name, const char *name2, const char *action)
347 assert(name != NULL);
348 assert(action != NULL);
354 if (isSeparator(name)) {
355 /* add separator, no action */
360 * add/replace existing menu item
362 item = rxvt_menuitem_find(menu, name);
364 if (item->name2 != NULL && name2 != NULL) {
369 switch (item->entry.type) {
371 case MenuTerminalAction:
372 free(item->entry.action.str);
373 item->entry.action.str = NULL;
379 /* allocate a new itemect */
380 item = (menuitem_t *) rxvt_malloc(sizeof(menuitem_t));
386 item->name = rxvt_malloc(len + 1);
387 STRCPY(item->name, name);
388 if (name[0] == '.' && name[1] != '.')
389 len = 0; /* hidden menu name */
392 /* add to tail of list */
393 item->prev = menu->tail;
396 if (menu->tail != NULL)
397 (menu->tail)->next = item;
400 if (menu->head == NULL)
407 if (name2 != NULL && item->name2 == NULL) {
412 item->name2 = rxvt_malloc(len + 1);
413 STRCPY(item->name2, name2);
417 item->entry.type = MenuLabel;
418 len = STRLEN(action);
420 if (len == 0 && item->name2 != NULL) {
421 action = item->name2;
425 unsigned char *str = rxvt_malloc(len + 1);
429 if (rxvt_action_type(&(item->entry.action), str) < 0)
432 /* new item and a possible increase in width */
433 if (menu->width < (item->len + item->len2))
434 menu->width = (item->len + item->len2);
440 * search for the base starting menu for NAME.
441 * return a pointer to the portion of NAME that remains
445 rxvt_menu_find_base(pR_ menu_t **menu, char *path)
451 assert(menu != NULL);
452 assert(R->h->CurrentBar != NULL);
458 if (STRCHR(path, '/') != NULL) {
461 while ((p = STRCHR(p, '/')) != NULL) {
466 if (path[0] == '/') {
470 while ((p = STRCHR(path, '/')) != NULL) {
474 if (!STRCMP(path, DOT)) {
476 } else if (!STRCMP(path, DOTS)) {
478 *menu = (*menu)->parent;
480 path = rxvt_menu_find_base(aR_ menu, path);
481 if (path[0] != '\0') { /* not found */
482 p[0] = '/'; /* fix-up name again */
490 if (!STRCMP(path, DOTS)) {
491 path += STRLEN(DOTS);
493 *menu = (*menu)->parent;
498 for (m = R->h->CurrentBar->tail; m != NULL; m = m->prev) {
499 if (!STRCMP(path, m->name))
504 for (item = (*menu)->tail; item != NULL; item = item->prev) {
505 if (item->entry.type == MenuSubMenu
506 && !STRCMP(path, (item->entry.submenu.menu)->name)) {
507 m = (item->entry.submenu.menu);
514 path += STRLEN(path);
520 * delete this entire menu
524 rxvt_menu_delete(pR_ menu_t *menu)
526 menu_t *parent = NULL, *prev, *next;
528 bar_t *CurrentBar = R->h->CurrentBar;
531 assert(CurrentBar != NULL);
534 /* delete the entire menu */
538 parent = menu->parent;
549 if (parent == NULL) {
550 const int len = (menu->len + HSPACE);
552 if (CurrentBar->tail == menu)
553 CurrentBar->tail = prev;
554 if (CurrentBar->head == menu)
555 CurrentBar->head = next;
557 for (next = menu->next; next != NULL; next = next->next)
560 for (item = parent->tail; item != NULL; item = item->prev) {
561 if (item->entry.type == MenuSubMenu
562 && item->entry.submenu.menu == menu) {
563 item->entry.submenu.menu = NULL;
564 rxvt_menuitem_free(aR_ menu->parent, item);
571 while (item != NULL) {
572 menuitem_t *p = item->prev;
574 rxvt_menuitem_free(aR_ menu, item);
578 if (menu->name != NULL)
587 rxvt_menu_add(pR_ menu_t *parent, char *path)
590 bar_t *CurrentBar = R->h->CurrentBar;
593 assert(CurrentBar != NULL);
596 if (STRCHR(path, '/') != NULL) {
599 if (path[0] == '/') {
600 /* shouldn't happen */
604 while ((p = STRCHR(path, '/')) != NULL) {
609 parent = rxvt_menu_add(aR_ parent, path);
613 if (!STRCMP(path, DOTS))
614 return (parent != NULL ? parent->parent : parent);
616 if (!STRCMP(path, DOT) || path[0] == '\0')
619 /* allocate a new menu */
620 menu = (menu_t *) rxvt_malloc(sizeof(menu_t));
623 menu->parent = parent;
624 menu->len = STRLEN(path);
625 menu->name = rxvt_malloc((menu->len + 1));
626 STRCPY(menu->name, path);
628 /* initialize head/tail */
629 menu->head = menu->tail = NULL;
630 menu->prev = menu->next = NULL;
633 menu->x = menu->y = menu->w = menu->h = 0;
636 /* add to tail of list */
637 if (parent == NULL) {
638 menu->prev = CurrentBar->tail;
639 if (CurrentBar->tail != NULL)
640 CurrentBar->tail->next = menu;
641 CurrentBar->tail = menu;
642 if (CurrentBar->head == NULL)
643 CurrentBar->head = menu; /* fix head */
645 menu->x = (menu->prev->x + menu->prev->len + HSPACE);
649 item = rxvt_menuitem_add(parent, path, "", "");
655 assert(item->entry.type == MenuLabel);
657 item->entry.type = MenuSubMenu;
658 item->entry.submenu.menu = menu;
666 rxvt_drawbox_menubar(pR_ int x, int len, int state)
671 len = Width2Pixel(len + HSPACE);
672 if (x >= R->TermWin.width)
674 else if (x + len >= R->TermWin.width)
675 len = (TermWin_TotalWidth() - x);
677 #ifdef MENUBAR_SHADOW_IN
682 top = R->h->topShadowGC;
683 bot = R->h->botShadowGC;
684 break; /* SHADOW_OUT */
686 top = R->h->botShadowGC;
687 bot = R->h->topShadowGC;
688 break; /* SHADOW_IN */
690 top = bot = R->h->scrollbarGC;
694 rxvt_Draw_Shadow(R->Xdisplay, R->menuBar.win, top, bot,
695 x, 0, len, menuBar_TotalHeight());
700 rxvt_drawtriangle(pR_ int x, int y, int state)
705 #ifdef MENU_SHADOW_IN
710 top = R->h->topShadowGC;
711 bot = R->h->botShadowGC;
712 break; /* SHADOW_OUT */
714 top = R->h->botShadowGC;
715 bot = R->h->topShadowGC;
716 break; /* SHADOW_IN */
718 top = bot = R->h->scrollbarGC;
722 w = Height2Pixel(1) - 2 * SHADOW;
724 x -= SHADOW + (3 * w / 2);
727 rxvt_Draw_Triangle(R->Xdisplay, R->h->ActiveMenu->win, top, bot, x, y, w,
733 rxvt_drawbox_menuitem(pR_ int y, int state)
737 #ifdef MENU_SHADOW_IN
742 top = R->h->topShadowGC;
743 bot = R->h->botShadowGC;
744 break; /* SHADOW_OUT */
746 top = R->h->botShadowGC;
747 bot = R->h->topShadowGC;
748 break; /* SHADOW_IN */
750 top = bot = R->h->scrollbarGC;
754 rxvt_Draw_Shadow(R->Xdisplay, R->h->ActiveMenu->win, top, bot,
755 SHADOW + 0, SHADOW + y,
756 R->h->ActiveMenu->w - 2 * (SHADOW),
757 HEIGHT_TEXT + 2 * SHADOW);
761 #ifdef DEBUG_MENU_LAYOUT
764 rxvt_print_menu_ancestors(menu_t *menu)
767 fprintf(stderr, "Top Level menu\n");
770 fprintf(stderr, "menu %s ", menu->name);
771 if (menu->parent != NULL) {
774 for (item = menu->parent->head; item != NULL; item = item->next) {
775 if (item->entry.type == MenuSubMenu
776 && item->entry.submenu.menu == menu) {
781 fprintf(stderr, "is an orphan!\n");
785 fprintf(stderr, "\n");
786 rxvt_print_menu_ancestors(menu->parent);
791 rxvt_print_menu_descendants(menu_t *menu)
800 parent = parent->parent;
802 while (parent != NULL);
804 for (i = 0; i < level; i++)
805 fprintf(stderr, ">");
806 fprintf(stderr, "%s\n", menu->name);
808 for (item = menu->head; item != NULL; item = item->next) {
809 if (item->entry.type == MenuSubMenu) {
810 if (item->entry.submenu.menu == NULL)
811 fprintf(stderr, "> %s == NULL\n", item->name);
813 rxvt_print_menu_descendants(item->entry.submenu.menu);
815 for (i = 0; i < level; i++)
816 fprintf(stderr, "+");
817 if (item->entry.type == MenuLabel)
818 fprintf(stderr, "label: ");
819 fprintf(stderr, "%s\n", item->name);
823 for (i = 0; i < level; i++)
824 fprintf(stderr, "<");
825 fprintf(stderr, "\n");
829 /* pop up/down the current menu and redraw the menuBar button */
835 menu_t *ActiveMenu = R->h->ActiveMenu;
838 if (ActiveMenu == NULL)
842 if (ActiveMenu->parent == NULL) {
845 rxvt_drawbox_menubar(aR_ x, ActiveMenu->len, -1);
849 ActiveMenu->w = Menu_PixelWidth(ActiveMenu);
851 if ((x + ActiveMenu->w) >= R->TermWin.width)
852 x = (TermWin_TotalWidth() - ActiveMenu->w);
854 /* find the height */
855 for (h = 0, item = ActiveMenu->head; item != NULL; item = item->next)
856 h += isSeparator(item->name) ? HEIGHT_SEPARATOR
857 : HEIGHT_TEXT + 2 * SHADOW;
858 ActiveMenu->h = h + 2 * SHADOW;
860 if (ActiveMenu->win == None) {
861 ActiveMenu->win = XCreateSimpleWindow(R->Xdisplay, R->TermWin.vt,
863 ActiveMenu->w, ActiveMenu->h,
865 R->PixColors[Color_fg],
866 R->PixColors[Color_scroll]);
867 XMapWindow(R->Xdisplay, ActiveMenu->win);
869 rxvt_Draw_Shadow(R->Xdisplay, ActiveMenu->win,
870 R->h->topShadowGC, R->h->botShadowGC,
871 0, 0, ActiveMenu->w, ActiveMenu->h);
873 /* determine the correct right-alignment */
874 for (xright = 0, item = ActiveMenu->head; item != NULL; item = item->next)
875 if (item->len2 > xright)
878 for (y = 0, item = ActiveMenu->head; item != NULL; item = item->next) {
879 const int xoff = (SHADOW + Width2Pixel(HSPACE) / 2);
881 GC gc = R->h->menubarGC;
883 if (isSeparator(item->name)) {
884 rxvt_Draw_Shadow(R->Xdisplay, ActiveMenu->win,
885 R->h->topShadowGC, R->h->botShadowGC,
886 SHADOW, y + SHADOW + 1,
887 ActiveMenu->w - 2 * SHADOW, 0);
888 h = HEIGHT_SEPARATOR;
890 char *name = item->name;
893 if (item->entry.type == MenuLabel) {
894 gc = R->h->botShadowGC;
895 } else if (item->entry.type == MenuSubMenu) {
898 menu_t *menu = item->entry.submenu.menu;
900 rxvt_drawtriangle(aR_ ActiveMenu->w, y, +1);
905 y1 = ActiveMenu->y + y;
907 menu->w = Menu_PixelWidth(menu);
909 /* place sub-menu at midpoint of parent menu */
910 x1 = ActiveMenu->w / 2;
911 if (x1 > menu->w) /* right-flush menu if too small */
912 x1 += (x1 - menu->w);
915 /* find the height of this submenu */
916 for (h = 0, it = menu->head; it != NULL; it = it->next)
917 h += isSeparator(it->name) ? HEIGHT_SEPARATOR
918 : HEIGHT_TEXT + 2 * SHADOW;
919 menu->h = h + 2 * SHADOW;
921 /* ensure menu is in window limits */
922 if ((x1 + menu->w) >= R->TermWin.width)
923 x1 = (TermWin_TotalWidth() - menu->w);
925 if ((y1 + menu->h) >= R->TermWin.height)
926 y1 = (TermWin_TotalHeight() - menu->h);
928 menu->x = (x1 < 0 ? 0 : x1);
929 menu->y = (y1 < 0 ? 0 : y1);
930 } else if (item->name2 && !STRCMP(name, item->name2))
935 if (R->TermWin.fontset)
936 XmbDrawString(R->Xdisplay,
937 ActiveMenu->win, R->TermWin.fontset,
939 2 * SHADOW + y + R->TermWin.font->ascent + 1,
943 XDrawString(R->Xdisplay, ActiveMenu->win, gc, xoff,
944 2 * SHADOW + y + R->TermWin.font->ascent + 1,
952 if (R->TermWin.fontset)
953 XmbDrawString(R->Xdisplay,
954 ActiveMenu->win, R->TermWin.fontset,
956 ActiveMenu->w - (xoff + Width2Pixel(xright)),
957 2 * SHADOW + y + R->TermWin.font->ascent + 1,
961 XDrawString(R->Xdisplay, ActiveMenu->win, gc,
962 ActiveMenu->w - (xoff + Width2Pixel(xright)),
963 2 * SHADOW + y + R->TermWin.font->ascent + 1,
966 h = HEIGHT_TEXT + 2 * SHADOW;
974 rxvt_menu_display(pR_ void (*update)(rxvt_t *))
976 menu_t *ActiveMenu = R->h->ActiveMenu;
978 if (ActiveMenu == NULL)
980 if (ActiveMenu->win != None)
981 XDestroyWindow(R->Xdisplay, ActiveMenu->win);
982 ActiveMenu->win = None;
983 ActiveMenu->item = NULL;
985 if (ActiveMenu->parent == NULL)
986 rxvt_drawbox_menubar(aR_ ActiveMenu->x, ActiveMenu->len, +1);
987 R->h->ActiveMenu = ActiveMenu->parent;
993 rxvt_menu_hide_all(pR)
995 rxvt_menu_display(aR_ rxvt_menu_hide_all);
1002 rxvt_menu_display(aR_ rxvt_menu_show);
1007 rxvt_menu_clear(pR_ menu_t *menu)
1010 menuitem_t *item = menu->tail;
1012 while (item != NULL) {
1013 rxvt_menuitem_free(aR_ menu, item);
1014 /* it didn't get freed ... why? */
1015 if (item == menu->tail)
1025 rxvt_menubar_clear(pR)
1027 bar_t *CurrentBar = R->h->CurrentBar;
1029 if (CurrentBar != NULL) {
1030 menu_t *menu = CurrentBar->tail;
1032 while (menu != NULL) {
1033 menu_t *prev = menu->prev;
1035 rxvt_menu_delete(aR_ menu);
1038 CurrentBar->head = CurrentBar->tail = NULL;
1040 if (CurrentBar->title) {
1041 free(CurrentBar->title);
1042 CurrentBar->title = NULL;
1044 rxvt_menuarrow_free(aR_ 0); /* remove all arrow functions */
1046 R->h->ActiveMenu = NULL;
1049 #if (MENUBAR_MAX > 1)
1050 /* find if menu already exists */
1053 rxvt_menubar_find(pR_ const char *name)
1055 bar_t *bar = R->h->CurrentBar;
1057 #ifdef DEBUG_MENUBAR_STACKING
1058 fprintf(stderr, "looking for [menu:%s] ...", name ? name : "(nil)");
1060 if (bar == NULL || name == NULL)
1063 if (STRLEN(name) && STRCMP(name, "*")) {
1065 if (!STRCMP(bar->name, name)) {
1066 #ifdef DEBUG_MENUBAR_STACKING
1067 fprintf(stderr, " found!\n");
1073 while (bar != R->h->CurrentBar);
1076 #ifdef DEBUG_MENUBAR_STACKING
1077 fprintf(stderr, "%s found!\n", (bar ? "" : " NOT"));
1085 rxvt_menubar_push(pR_ const char *name)
1090 if (R->h->CurrentBar == NULL) {
1091 /* allocate first one */
1092 bar = (bar_t *) rxvt_malloc(sizeof(bar_t));
1094 MEMSET(bar, 0, sizeof(bar_t));
1095 /* circular linked-list */
1096 bar->next = bar->prev = bar;
1097 bar->head = bar->tail = NULL;
1099 R->h->CurrentBar = bar;
1102 rxvt_menubar_clear(aR);
1104 /* find if menu already exists */
1105 bar = rxvt_menubar_find(aR_ name);
1107 /* found it, use it */
1108 R->h->CurrentBar = bar;
1110 /* create if needed, or reuse the existing empty menubar */
1111 if (R->h->CurrentBar->head != NULL) {
1112 /* need to malloc another one */
1113 if (R->h->Nbars < MENUBAR_MAX)
1114 bar = (bar_t *) rxvt_malloc(sizeof(bar_t));
1118 /* malloc failed or too many menubars, reuse another */
1120 bar = R->h->CurrentBar->next;
1123 bar->head = bar->tail = NULL;
1126 bar->next = R->h->CurrentBar->next;
1127 R->h->CurrentBar->next = bar;
1128 bar->prev = R->h->CurrentBar;
1129 bar->next->prev = bar;
1133 R->h->CurrentBar = bar;
1136 rxvt_menubar_clear(aR);
1140 /* give menubar this name */
1141 STRNCPY(R->h->CurrentBar->name, name, MAXNAME);
1142 R->h->CurrentBar->name[MAXNAME - 1] = '\0';
1147 /* switch to a menu called NAME and remove it */
1150 rxvt_menubar_remove(pR_ const char *name)
1154 if ((bar = rxvt_menubar_find(aR_ name)) == NULL)
1156 R->h->CurrentBar = bar;
1159 rxvt_menubar_clear(aR);
1161 * pop a menubar, clean it up first
1163 if (R->h->CurrentBar != NULL) {
1164 bar_t *prev = R->h->CurrentBar->prev;
1165 bar_t *next = R->h->CurrentBar->next;
1167 if (prev == next && prev == R->h->CurrentBar) { /* only 1 left */
1169 R->h->Nbars = 0; /* safety */
1176 free(R->h->CurrentBar);
1177 R->h->CurrentBar = prev;
1180 while (R->h->CurrentBar && !STRCMP(name, "*"));
1185 rxvt_action_decode(FILE *fp, action_t *act)
1190 if (act == NULL || (len = act->len) == 0 || (str = act->str) == NULL)
1193 if (act->type == MenuTerminalAction) {
1195 /* can strip trailing ^G from XTerm sequence */
1196 if (str[0] == C0_ESC && str[1] == ']' && str[len - 1] == C0_BEL)
1198 } else if (str[0] == C0_ESC) {
1205 /* can strip trailing '\r' from M-x sequence */
1206 if (str[len - 1] == '\r')
1211 fprintf(fp, "M-"); /* meta prefix */
1218 * control character form is preferred, since backslash-escaping
1219 * can be really ugly looking when the backslashes themselves also
1220 * have to be escaped to avoid Shell (or whatever scripting
1221 * language) interpretation
1224 unsigned char ch = *str++;
1232 break; /* carriage-return */
1234 fprintf(fp, "\\\\");
1235 break; /* backslash */
1243 fprintf(fp, "^%c", ('@' + ch));
1245 fprintf(fp, "\\%o", ch);
1247 fprintf(fp, "%c", ch);
1257 rxvt_menu_dump(FILE *fp, menu_t *menu)
1261 /* create a new menu and clear it */
1262 fprintf(fp, (menu->parent ? "./%s/*\n" : "/%s/*\n"), menu->name);
1264 for (item = menu->head; item != NULL; item = item->next) {
1265 switch (item->entry.type) {
1267 if (item->entry.submenu.menu == NULL)
1268 fprintf(fp, "> %s == NULL\n", item->name);
1270 rxvt_menu_dump(fp, item->entry.submenu.menu);
1274 fprintf(fp, "{%s}\n", (STRLEN(item->name) ? item->name : "-"));
1277 case MenuTerminalAction:
1279 fprintf(fp, "{%s}", item->name);
1280 if (item->name2 != NULL && STRLEN(item->name2))
1281 fprintf(fp, "{%s}", item->name2);
1283 rxvt_action_decode(fp, &(item->entry.action));
1288 fprintf(fp, (menu->parent ? "../\n" : "/\n\n"));
1293 rxvt_menubar_dump(pR_ FILE *fp)
1295 bar_t *bar = R->h->CurrentBar;
1298 if (bar == NULL || fp == NULL)
1303 "# " APL_SUBCLASS " (%s) Pid: %u\n# Date: %s\n\n",
1304 R->h->rs[Rs_name], (unsigned int)getpid(), ctime(&t));
1306 /* dump in reverse order */
1307 bar = R->h->CurrentBar->prev;
1312 fprintf(fp, "[menu:%s]\n", bar->name);
1314 if (bar->title != NULL)
1315 fprintf(fp, "[title:%s]\n", bar->title);
1317 for (i = 0; i < NARROWS; i++) {
1318 switch (bar->arrows[i].type) {
1319 case MenuTerminalAction:
1321 fprintf(fp, "<%c>", Arrows[i].name);
1322 rxvt_action_decode(fp, &(bar->arrows[i]));
1328 for (menu = bar->head; menu != NULL; menu = menu->next)
1329 rxvt_menu_dump(fp, menu);
1331 fprintf(fp, "\n[done:%s]\n\n", bar->name);
1334 while (bar != R->h->CurrentBar->prev);
1336 #endif /* (MENUBAR_MAX > 1) */
1339 * read in menubar commands from FILENAME
1340 * ignore all input before the tag line [menu] or [menu:???]
1342 * Note that since File_find () is used, FILENAME can be semi-colon
1343 * delimited such that the second part can refer to a tag
1344 * so that a large `database' of menus can be collected together
1347 * FILENAME = "file;"
1348 * read `file' starting with first [menu] or [menu:???] line
1350 * FILENAME = "file;tag"
1351 * read `file' starting with [menu:tag]
1355 rxvt_menubar_read(pR_ const char *filename)
1357 /* read in a menu from a file */
1360 char *p, *file, *tag = NULL;
1362 file = (char *)rxvt_File_find(filename, ".menu", R->h->rs[Rs_path]);
1365 fp = fopen(file, "rb");
1370 #if (MENUBAR_MAX > 1)
1371 /* semi-colon delimited */
1372 if ((tag = STRCHR(filename, ';')) != NULL) {
1377 #endif /* (MENUBAR_MAX > 1) */
1379 fprintf(stderr, "[read:%s]\n", p);
1381 fprintf(stderr, "looking for [menu:%s]\n", tag);
1384 while ((p = fgets(buffer, sizeof(buffer), fp)) != NULL) {
1387 if ((n = rxvt_Str_match(p, "[menu")) != 0) {
1389 /* looking for [menu:tag] */
1390 if (p[n] == ':' && p[n + 1] != ']') {
1392 n += rxvt_Str_match(p + n, tag);
1395 fprintf(stderr, "[menu:%s]\n", tag);
1400 } else if (p[n] == ':' || p[n] == ']')
1405 /* found [menu], [menu:???] tag */
1410 fprintf(stderr, "read line = %s\n", p);
1413 /* looking for [done:tag] or [done:] */
1414 if ((n = rxvt_Str_match(p, "[done")) != 0) {
1416 R->h->menu_readonly = 1;
1418 } else if (p[n] == ':') {
1421 R->h->menu_readonly = 1;
1424 n += rxvt_Str_match(p + n, tag);
1427 fprintf(stderr, "[done:%s]\n", tag);
1429 R->h->menu_readonly = 1;
1433 /* what? ... skip this line */
1434 p[0] = COMMENT_CHAR;
1439 * remove leading/trailing space
1440 * and strip-off leading/trailing quotes
1441 * skip blank or comment lines
1444 if (*p && *p != '#') {
1445 R->h->menu_readonly = 0; /* if case we read another file */
1446 rxvt_menubar_dispatch(aR_ p);
1448 /* get another line */
1449 p = fgets(buffer, sizeof(buffer), fp);
1456 * user interface for building/deleting and otherwise managing menus
1460 rxvt_menubar_dispatch(pR_ char *str)
1463 char *path, *name, *name2;
1465 if (menubar_visible(r) && R->h->ActiveMenu != NULL)
1466 rxvt_menubar_expose(aR);
1468 R->h->ActiveMenu = NULL;
1473 case '/': /* absolute & relative path */
1474 case MENUITEM_BEG: /* menuitem */
1475 /* add `+' prefix for these cases */
1481 str++; /* skip cmd character */
1485 #if (MENUBAR_MAX > 1)
1486 if (R->h->CurrentBar == NULL)
1488 #endif /* (MENUBAR_MAX > 1) */
1489 if (str[1] && str[2] == '>') /* arrow commands */
1490 rxvt_menuarrow_add(aR_ str);
1493 case '[': /* extended command */
1494 while (str[0] == '[') {
1495 char *next = (++str); /* skip leading '[' */
1497 if (str[0] == ':') { /* [:command:] */
1500 if ((next = STRCHR(next, ':')) == NULL)
1501 return; /* parse error */
1503 while (next[1] != ']');
1504 /* remove and skip ':]' */
1508 if ((next = STRCHR(next, ']')) == NULL)
1509 return; /* parse error */
1510 /* remove and skip ']' */
1515 if (str[0] == ':') {
1518 /* try and dispatch it, regardless of read/write status */
1519 saved = R->h->menu_readonly;
1520 R->h->menu_readonly = 0;
1521 rxvt_menubar_dispatch(aR_ str + 1);
1522 R->h->menu_readonly = saved;
1524 /* these ones don't require menu stacking */
1525 else if (!STRCMP(str, "clear")) {
1526 rxvt_menubar_clear(aR);
1527 } else if (!STRCMP(str, "done") || rxvt_Str_match(str, "done:")) {
1528 R->h->menu_readonly = 1;
1529 } else if (!STRCMP(str, "show")) {
1530 rxvt_map_menuBar(aR_ 1);
1531 R->h->menu_readonly = 1;
1532 } else if (!STRCMP(str, "hide")) {
1533 rxvt_map_menuBar(aR_ 0);
1534 R->h->menu_readonly = 1;
1535 } else if ((n = rxvt_Str_match(str, "read:")) != 0) {
1536 /* read in a menu from a file */
1538 rxvt_menubar_read(aR_ str);
1539 } else if ((n = rxvt_Str_match(str, "title:")) != 0) {
1541 if (R->h->CurrentBar != NULL && !R->h->menu_readonly) {
1543 name = rxvt_realloc(R->h->CurrentBar->title,
1547 R->h->CurrentBar->title = name;
1549 rxvt_menubar_expose(aR);
1551 free(R->h->CurrentBar->title);
1552 R->h->CurrentBar->title = NULL;
1555 } else if ((n = rxvt_Str_match(str, "pixmap:")) != 0) {
1557 rxvt_xterm_seq(aR_ XTerm_Pixmap, str, CHAR_ST);
1559 #if (MENUBAR_MAX > 1)
1560 else if ((n = rxvt_Str_match(str, "rm")) != 0) {
1569 rxvt_menubar_remove(aR_ str);
1572 R->h->menu_readonly = 1;
1573 } else if ((n = rxvt_Str_match(str, "menu")) != 0) {
1578 /* add/access menuBar */
1579 if (*str != '\0' && *str != '*')
1580 rxvt_menubar_push(aR_ str);
1583 if (R->h->CurrentBar == NULL) {
1584 rxvt_menubar_push(aR_ "default");
1588 if (R->h->CurrentBar != NULL)
1589 R->h->menu_readonly = 0; /* allow menu build commands */
1590 } else if (!STRCMP(str, "dump")) {
1591 /* dump current menubars to a file */
1594 /* enough space to hold the results */
1597 sprintf(buffer, "/tmp/" APL_SUBCLASS "-%u",
1598 (unsigned int)getpid());
1600 if ((fp = fopen(buffer, "wb")) != NULL) {
1601 rxvt_xterm_seq(aR_ XTerm_title, buffer, CHAR_ST);
1602 rxvt_menubar_dump(aR_ fp);
1605 } else if (!STRCMP(str, "next")) {
1606 if (R->h->CurrentBar) {
1607 R->h->CurrentBar = R->h->CurrentBar->next;
1608 R->h->menu_readonly = 1;
1610 } else if (!STRCMP(str, "prev")) {
1611 if (R->h->CurrentBar) {
1612 R->h->CurrentBar = R->h->CurrentBar->prev;
1613 R->h->menu_readonly = 1;
1615 } else if (!STRCMP(str, "swap")) {
1616 /* swap the top 2 menus */
1617 if (R->h->CurrentBar) {
1618 bar_t *cbprev = R->h->CurrentBar->prev;
1619 bar_t *cbnext = R->h->CurrentBar->next;
1621 cbprev->next = cbnext;
1622 cbnext->prev = cbprev;
1624 R->h->CurrentBar->next = cbprev;
1625 R->h->CurrentBar->prev = cbprev->prev;
1627 cbprev->prev->next = R->h->CurrentBar;
1628 cbprev->prev = R->h->CurrentBar;
1630 R->h->CurrentBar = cbprev;
1631 R->h->menu_readonly = 1;
1634 #endif /* (MENUBAR_MAX > 1) */
1637 R->h->BuildMenu = R->h->ActiveMenu = NULL;
1638 rxvt_menubar_expose(aR);
1639 #ifdef DEBUG_MENUBAR_STACKING
1640 fprintf(stderr, "menus are read%s\n",
1641 R->h->menu_readonly ? "only" : "/write");
1648 #if (MENUBAR_MAX > 1)
1649 if (R->h->CurrentBar == NULL)
1651 if (R->h->menu_readonly) {
1652 #ifdef DEBUG_MENUBAR_STACKING
1653 fprintf(stderr, "menus are read%s\n",
1654 R->h->menu_readonly ? "only" : "/write");
1658 #endif /* (MENUBAR_MAX > 1) */
1666 /* parse STR, allow spaces inside (name) */
1667 if (path[0] != '\0') {
1668 name = STRCHR(path, MENUITEM_BEG);
1669 str = STRCHR(path, MENUITEM_END);
1670 if (name != NULL || str != NULL) {
1671 if (name == NULL || str == NULL || str <= (name + 1)
1672 || (name > path && name[-1] != '/')) {
1673 rxvt_print_error("menu error <%s>\n", path);
1676 if (str[1] == MENUITEM_BEG) {
1678 str = STRCHR(name2, MENUITEM_END);
1681 rxvt_print_error("menu error <%s>\n", path);
1684 name2[-2] = '\0'; /* remove prev MENUITEM_END */
1686 if (name > path && name[-1] == '/')
1689 *name++ = '\0'; /* delimit */
1690 *str++ = '\0'; /* delimit */
1692 while (isspace(*str))
1693 str++; /* skip space */
1697 "`%c' path = <%s>, name = <%s>, name2 = <%s>, action = <%s>\n",
1698 cmd, (path ? path : "(nil)"), (name ? name : "(nil)"),
1699 (name2 ? name2 : "(nil)"), (str ? str : "(nil)")
1703 /* process the different commands */
1705 case '+': /* add/replace existing menu or menuitem */
1706 if (path[0] != '\0') {
1709 path = rxvt_menu_find_base(aR_ &(R->h->BuildMenu), path);
1712 /* don't allow menus called `*' */
1713 if (path[0] == '*') {
1714 rxvt_menu_clear(aR_ R->h->BuildMenu);
1716 } else if (len >= 2 && !STRCMP((path + len - 2), "/*")) {
1717 path[len - 2] = '\0';
1719 if (path[0] != '\0')
1720 R->h->BuildMenu = rxvt_menu_add(aR_ R->h->BuildMenu, path);
1722 if (name != NULL && name[0] != '\0')
1723 rxvt_menuitem_add(R->h->BuildMenu,
1724 (STRCMP(name, SEPARATOR_NAME) ? name : ""),
1728 case '-': /* delete menu entry */
1729 if (!STRCMP(path, "/*") && (name == NULL || name[0] == '\0')) {
1730 rxvt_menubar_clear(aR);
1731 R->h->BuildMenu = NULL;
1732 rxvt_menubar_expose(aR);
1734 } else if (path[0] != '\0') {
1736 menu_t *menu = R->h->BuildMenu;
1738 path = rxvt_menu_find_base(aR_ &menu, path);
1741 /* submenu called `*' clears all menu items */
1742 if (path[0] == '*') {
1743 rxvt_menu_clear(aR_ menu);
1745 } else if (len >= 2 && !STRCMP(&path[len - 2], "/*")) {
1748 } else if (path[0] != '\0') {
1749 R->h->BuildMenu = NULL;
1752 R->h->BuildMenu = menu;
1754 if (R->h->BuildMenu != NULL) {
1755 if (name == NULL || name[0] == '\0')
1756 R->h->BuildMenu = rxvt_menu_delete(aR_ R->h->BuildMenu);
1760 menu_t *BuildMenu = R->h->BuildMenu;
1762 n1 = STRCMP(name, SEPARATOR_NAME) ? name : "";
1763 item = rxvt_menuitem_find(BuildMenu, n1);
1764 if (item != NULL && item->entry.type != MenuSubMenu) {
1765 rxvt_menuitem_free(aR_ BuildMenu, item);
1767 /* fix up the width */
1768 BuildMenu->width = 0;
1769 for (item = BuildMenu->head; item != NULL;
1770 item = item->next) {
1771 short l = item->len + item->len2;
1773 MAX_IT(BuildMenu->width, l);
1777 rxvt_menubar_expose(aR);
1787 rxvt_draw_Arrows(pR_ int name, int state)
1793 #ifdef MENU_SHADOW_IN
1798 top = R->h->topShadowGC;
1799 bot = R->h->botShadowGC;
1800 break; /* SHADOW_OUT */
1802 top = R->h->botShadowGC;
1803 bot = R->h->topShadowGC;
1804 break; /* SHADOW_IN */
1806 top = bot = R->h->scrollbarGC;
1807 break; /* neutral */
1810 if (!R->h->Arrows_x)
1813 for (i = 0; i < NARROWS; i++) {
1814 const int w = Width2Pixel(1);
1815 const int y = (menuBar_TotalHeight() - w) / 2;
1816 int x = R->h->Arrows_x + (5 * Width2Pixel(i)) / 4;
1818 if (!name || name == Arrows[i].name)
1819 rxvt_Draw_Triangle(R->Xdisplay, R->menuBar.win, top, bot, x, y, w,
1822 XFlush(R->Xdisplay);
1827 rxvt_menubar_expose(pR)
1832 if (!menubar_visible(r) || R->menuBar.win == 0)
1835 if (R->h->menubarGC == None) {
1836 /* Create the graphics context */
1839 gcvalue.font = R->TermWin.font->fid;
1841 gcvalue.foreground = (XDEPTH <= 2 ? R->PixColors[Color_fg]
1842 : R->PixColors[Color_Black]);
1843 R->h->menubarGC = XCreateGC(R->Xdisplay, R->menuBar.win,
1844 GCForeground | GCFont, &gcvalue);
1847 /* make sure the font is correct */
1848 XSetFont(R->Xdisplay, R->h->menubarGC, R->TermWin.font->fid);
1849 XSetFont(R->Xdisplay, R->h->botShadowGC, R->TermWin.font->fid);
1850 XClearWindow(R->Xdisplay, R->menuBar.win);
1852 rxvt_menu_hide_all(aR);
1855 if (R->h->CurrentBar != NULL) {
1856 for (menu = R->h->CurrentBar->head; menu != NULL; menu = menu->next) {
1857 int len = menu->len;
1859 x = (menu->x + menu->len + HSPACE);
1861 #ifdef DEBUG_MENU_LAYOUT
1862 rxvt_print_menu_descendants(menu);
1865 if (x >= R->TermWin.ncol)
1866 len = (R->TermWin.ncol - (menu->x + HSPACE));
1868 rxvt_drawbox_menubar(aR_ menu->x, len, +1);
1870 if (R->TermWin.fontset)
1871 XmbDrawString(R->Xdisplay,
1872 R->menuBar.win, R->TermWin.fontset,
1874 (Width2Pixel(menu->x) + Width2Pixel(HSPACE) / 2),
1875 menuBar_height() - SHADOW, menu->name, len);
1878 XDrawString(R->Xdisplay, R->menuBar.win, R->h->menubarGC,
1879 (Width2Pixel(menu->x) + Width2Pixel(HSPACE) / 2),
1880 menuBar_height() - SHADOW, menu->name, len);
1882 if (x >= R->TermWin.ncol)
1886 rxvt_drawbox_menubar(aR_ x, R->TermWin.ncol, (R->h->CurrentBar ? +1 : -1));
1888 /* add the menuBar title, if it exists and there's plenty of room */
1890 if (x < R->TermWin.ncol) {
1896 ncol = (int)R->TermWin.ncol;
1897 if (x < (ncol - (NARROWS + 1))) {
1898 ncol -= (NARROWS + 1);
1899 R->h->Arrows_x = Width2Pixel(ncol);
1901 rxvt_draw_Arrows(aR_ 0, +1);
1903 str = (R->h->CurrentBar
1904 && R->h->CurrentBar->title) ? R->h->CurrentBar->title : "%n-%v";
1905 for (len = 0; str[0] && len < sizeof(title) - 1; str++) {
1906 const char *s = NULL;
1913 s = R->h->rs[Rs_name];
1914 break; /* resource name */
1917 break; /* version number */
1920 break; /* literal '%' */
1923 while (*s && len < sizeof(title) - 1)
1924 title[len++] = *s++;
1928 title[len++] = str[0];
1934 ncol -= (x + len + HSPACE);
1935 if (len > 0 && ncol >= 0) {
1937 if (R->TermWin.fontset)
1938 XmbDrawString(R->Xdisplay,
1939 R->menuBar.win, R->TermWin.fontset,
1941 Width2Pixel(x) + Width2Pixel(ncol + HSPACE) / 2,
1942 menuBar_height() - SHADOW, title, len);
1945 XDrawString(R->Xdisplay, R->menuBar.win, R->h->menubarGC,
1946 Width2Pixel(x) + Width2Pixel(ncol + HSPACE) / 2,
1947 menuBar_height() - SHADOW, title, len);
1954 rxvt_menubar_mapping(pR_ int map)
1958 if (map && !menubar_visible(r)) {
1959 R->menuBar.state = 1;
1960 if (R->menuBar.win == 0)
1962 XMapWindow(R->Xdisplay, R->menuBar.win);
1964 } else if (!map && menubar_visible(r)) {
1965 rxvt_menubar_expose(aR);
1966 R->menuBar.state = 0;
1967 XUnmapWindow(R->Xdisplay, R->menuBar.win);
1970 rxvt_menubar_expose(aR);
1977 rxvt_menu_select(pR_ XButtonEvent *ev)
1979 menuitem_t *thisitem, *item = NULL;
1981 menu_t *ActiveMenu = R->h->ActiveMenu;
1983 Window unused_root, unused_child;
1984 int unused_root_x, unused_root_y;
1985 unsigned int unused_mask;
1987 if (ActiveMenu == NULL)
1990 XQueryPointer(R->Xdisplay, ActiveMenu->win,
1991 &unused_root, &unused_child,
1992 &unused_root_x, &unused_root_y,
1993 &(ev->x), &(ev->y), &unused_mask);
1995 if (ActiveMenu->parent != NULL && (ev->x < 0 || ev->y < 0)) {
1999 /* determine the menu item corresponding to the Y index */
2001 if (ev->x >= 0 && ev->x <= (ActiveMenu->w - SHADOW)) {
2002 for (item = ActiveMenu->head; item != NULL; item = item->next) {
2003 int h = HEIGHT_TEXT + 2 * SHADOW;
2005 if (isSeparator(item->name))
2006 h = HEIGHT_SEPARATOR;
2007 else if (ev->y >= y && ev->y < (y + h))
2012 if (item == NULL && ev->type == ButtonRelease) {
2013 rxvt_menu_hide_all(aR);
2017 this_y = y - SHADOW;
2019 /* erase the last item */
2020 if (ActiveMenu->item != NULL) {
2021 if (ActiveMenu->item != thisitem) {
2022 for (y = 0, item = ActiveMenu->head; item != NULL;
2023 item = item->next) {
2026 if (isSeparator(item->name))
2027 h = HEIGHT_SEPARATOR;
2028 else if (item == ActiveMenu->item) {
2029 /* erase old menuitem */
2030 rxvt_drawbox_menuitem(aR_ y, 0); /* No Shadow */
2031 if (item->entry.type == MenuSubMenu)
2032 rxvt_drawtriangle(aR_ ActiveMenu->w, y, +1);
2035 h = HEIGHT_TEXT + 2 * SHADOW;
2041 switch (item->entry.type) {
2044 rxvt_menu_hide_all(aR);
2048 case MenuTerminalAction:
2049 rxvt_drawbox_menuitem(aR_ this_y, -1);
2051 #ifdef HAVE_NANOSLEEP
2052 struct timespec rqt;
2055 rqt.tv_nsec = MENU_DELAY_USEC * 1000;
2056 nanosleep(&rqt, NULL);
2058 /* use select for timing */
2062 tv.tv_usec = MENU_DELAY_USEC;
2063 select(0, NULL, NULL, NULL, &tv);
2066 /* remove menu before sending keys to the application */
2067 rxvt_menu_hide_all(aR);
2069 rxvt_action_dispatch(aR_ &(item->entry.action));
2070 #else /* DEBUG_MENU */
2071 fprintf(stderr, "%s: %s\n", item->name,
2072 item->entry.action.str);
2073 #endif /* DEBUG_MENU */
2079 if (item->entry.type == MenuSubMenu)
2087 ActiveMenu->item = thisitem;
2089 if (thisitem != NULL) {
2090 item = ActiveMenu->item;
2091 if (item->entry.type != MenuLabel)
2092 rxvt_drawbox_menuitem(aR_ y, +1);
2093 if (item->entry.type == MenuSubMenu) {
2096 rxvt_drawtriangle(aR_ ActiveMenu->w, y, -1);
2098 x = ev->x + (ActiveMenu->parent
2100 : Width2Pixel(ActiveMenu->x));
2102 if (x >= item->entry.submenu.menu->x) {
2103 R->h->ActiveMenu = item->entry.submenu.menu;
2114 rxvt_menubar_select(pR_ XButtonEvent *ev)
2116 menu_t *menu = NULL;
2118 /* determine the pulldown menu corresponding to the X index */
2119 if (ev->y >= 0 && ev->y <= menuBar_height() && R->h->CurrentBar != NULL) {
2120 for (menu = R->h->CurrentBar->head; menu != NULL; menu = menu->next) {
2121 int x = Width2Pixel(menu->x);
2122 int w = Width2Pixel(menu->len + HSPACE);
2124 if ((ev->x >= x && ev->x < x + w))
2130 rxvt_menu_hide_all(aR);
2134 if (menu == NULL && R->h->Arrows_x && ev->x >= R->h->Arrows_x) {
2137 for (i = 0; i < NARROWS; i++) {
2138 if (ev->x >= (R->h->Arrows_x + (Width2Pixel(4 * i + i)) / 4)
2139 && ev->x < (R->h->Arrows_x
2140 + (Width2Pixel(4 * i + i + 4)) / 4)) {
2141 rxvt_draw_Arrows(aR_ Arrows[i].name, -1);
2143 #ifdef HAVE_NANOSLEEP
2144 struct timespec rqt;
2147 rqt.tv_nsec = MENU_DELAY_USEC * 1000;
2148 nanosleep(&rqt, NULL);
2150 /* use select for timing */
2154 tv.tv_usec = MENU_DELAY_USEC;
2155 select(0, NULL, NULL, NULL, &tv);
2158 rxvt_draw_Arrows(aR_ Arrows[i].name, +1);
2159 #ifdef DEBUG_MENUARROWS
2160 fprintf(stderr, "'%c': ", Arrows[i].name);
2162 if (R->h->CurrentBar == NULL
2163 || (R->h->CurrentBar->arrows[i].type != MenuAction
2164 && R->h->CurrentBar->arrows[i].type !=
2165 MenuTerminalAction)) {
2166 if (Arrows[i].str != NULL && Arrows[i].str[0])
2167 fprintf(stderr, "(default) \\033%s\n",
2168 &(Arrows[i].str[2]));
2170 fprintf(stderr, "%s\n",
2171 R->h->CurrentBar->arrows[i].str);
2173 #else /* DEBUG_MENUARROWS */
2174 if (R->h->CurrentBar == NULL
2175 || rxvt_action_dispatch(r,
2176 &(R->h->CurrentBar->arrows[i]))
2178 if (Arrows[i].str != NULL && Arrows[i].str[0] != 0)
2179 rxvt_tt_write(aR_ (Arrows[i].str + 1),
2182 #endif /* DEBUG_MENUARROWS */
2191 * press menubar or move to a new entry
2193 if (menu != NULL && menu != R->h->ActiveMenu) {
2194 rxvt_menu_hide_all(aR); /* pop down old menu */
2195 R->h->ActiveMenu = menu;
2196 rxvt_menu_show(aR); /* pop up new menu */
2203 * general dispatch routine,
2204 * it would be nice to have `sticky' menus
2208 rxvt_menubar_control(pR_ XButtonEvent *ev)
2212 if (ev->button == Button1)
2213 rxvt_menubar_select(aR_ ev);
2217 if (ev->button == Button1)
2218 rxvt_menu_select(aR_ ev);
2222 while (XCheckTypedWindowEvent(R->Xdisplay, R->TermWin.parent[0],
2223 MotionNotify, (XEvent *) ev)) ;
2225 if (R->h->ActiveMenu)
2226 while (rxvt_menu_select(aR_ ev)) ;
2230 Window unused_root, unused_child;
2231 int unused_root_x, unused_root_y;
2232 unsigned int unused_mask;
2234 XQueryPointer(R->Xdisplay, R->menuBar.win,
2235 &unused_root, &unused_child,
2236 &unused_root_x, &unused_root_y,
2237 &(ev->x), &(ev->y), &unused_mask);
2238 rxvt_menubar_select(aR_ ev);
2246 rxvt_map_menuBar(pR_ int map)
2248 if (rxvt_menubar_mapping(aR_ map))
2249 rxvt_resize_all_windows(aR_ 0, 0, 0);
2252 /*----------------------- end-of-file (C source) -----------------------*/