ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/menubar.C
(Generate patch)

Comparing rxvt-unicode/src/menubar.C (file contents):
Revision 1.14 by pcg, Wed Mar 17 03:47:12 2004 UTC vs.
Revision 1.31 by root, Wed Jan 11 05:29:40 2006 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: menubar.c 2 * File: menubar.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * Copyright (c) 1997,1998 mj olesen <olesen@me.QueensU.CA> 5 * Copyright (c) 1997,1998 mj olesen <olesen@me.QueensU.CA>
6 * Copyright (c) 2004 Marc Lehmann <pcg@goof.com>
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version. 11 * (at your option) any later version.
28 29
29#include "rxvt.h" /* NECESSARY */ 30#include "rxvt.h" /* NECESSARY */
30#ifdef MENUBAR 31#ifdef MENUBAR
31#include "version.h" 32#include "version.h"
32#include "menubar.h" 33#include "menubar.h"
33#include "menubar.intpro" /* PROTOS for internal routines */
34 34
35#define Menu_PixelWidth(menu) \ 35#define Menu_PixelWidth(menu) \
36 (2 * SHADOW + Width2Pixel ((menu)->width + 3 * HSPACE)) 36 (2 * MENU_SHADOW + Width2Pixel ((menu)->width + 3 * HSPACE))
37 37
38static const struct 38static const struct
39 { 39 {
40 const char name; /* (l)eft, (u)p, (d)own, (r)ight */ 40 const char name; /* (l)eft, (u)p, (d)own, (r)ight */
41 const unsigned char str[5]; /* str[0] = STRLEN (str+1) */ 41 const char str[5]; /* str[0] = strlen (str+1) */
42 } 42 }
43Arrows[NARROWS] = { 43Arrows[NARROWS] = {
44 { 'l', "\003\033[D" }, 44 { 'l', "\003\033[D" },
45 { 'u', "\003\033[A" }, 45 { 'u', "\003\033[A" },
46 { 'd', "\003\033[B" }, 46 { 'd', "\003\033[B" },
89 /* find the last item in the menu, this is good for separators */ 89 /* find the last item in the menu, this is good for separators */
90 for (item = menu->tail; item != NULL; item = item->prev) 90 for (item = menu->tail; item != NULL; item = item->prev)
91 { 91 {
92 if (item->entry.type == MenuSubMenu) 92 if (item->entry.type == MenuSubMenu)
93 { 93 {
94 if (!STRCMP (name, (item->entry.submenu.menu)->name)) 94 if (!strcmp (name, (item->entry.submenu.menu)->name))
95 break; 95 break;
96 } 96 }
97 else if ((isSeparator (name) && isSeparator (item->name)) 97 else if ((isSeparator (name) && isSeparator (item->name))
98 || !STRCMP (name, item->name)) 98 || !strcmp (name, item->name))
99 break; 99 break;
100 } 100 }
101 return item; 101 return item;
102} 102}
103 103
147/* 147/*
148 * sort command vs. terminal actions and 148 * sort command vs. terminal actions and
149 * remove the first character of STR if it's '\0' 149 * remove the first character of STR if it's '\0'
150 */ 150 */
151int 151int
152rxvt_action_type (action_t *action, unsigned char *str) 152rxvt_action_type (action_t *action, char *str)
153{ 153{
154 unsigned int len; 154 unsigned int len;
155 155
156#if defined (DEBUG_MENU) || defined (DEBUG_MENUARROWS) 156#if defined (DEBUG_MENU) || defined (DEBUG_MENUARROWS)
157 len = STRLEN (str); 157 len = strlen (str);
158 fprintf (stderr, " (len %d) = %s\n", len, str); 158 fprintf (stderr, " (len %d) = %s\n", len, str);
159#else 159#else
160 len = rxvt_Str_escaped ((char *)str); 160 len = rxvt_Str_escaped ((char *)str);
161#endif 161#endif
162 162
166 /* sort command vs. terminal actions */ 166 /* sort command vs. terminal actions */
167 action->type = MenuAction; 167 action->type = MenuAction;
168 if (str[0] == '\0') 168 if (str[0] == '\0')
169 { 169 {
170 /* the functional equivalent: memmove (str, str+1, len); */ 170 /* the functional equivalent: memmove (str, str+1, len); */
171 unsigned char *dst = (str); 171 char *dst = (str);
172 unsigned char *src = (str + 1); 172 char *src = (str + 1);
173 unsigned char *end = (str + len); 173 char *end = (str + len);
174 174
175 while (src <= end) 175 while (src <= end)
176 *dst++ = *src++; 176 *dst++ = *src++;
177 177
178 len--; /* decrement length */ 178 len--; /* decrement length */
179 if (str[0] != '\0') 179 if (str[0] != '\0')
180 action->type = MenuTerminalAction; 180 action->type = MenuTerminalAction;
181 } 181 }
182
182 action->str = str; 183 action->str = str;
183 action->len = len; 184 action->len = len;
184 185
185 return 0; 186 return 0;
186} 187}
263 beg = { NULL, 0 }, 264 beg = { NULL, 0 },
264 end = { NULL, 0 }, 265 end = { NULL, 0 },
265 *cur, 266 *cur,
266 parse[NARROWS]; 267 parse[NARROWS];
267 268
268 MEMSET (parse, 0, sizeof (parse)); 269 memset (parse, 0, sizeof (parse));
269 270
270 /* fprintf (stderr, "add arrows = `%s'\n", string); */ 271 /* fprintf (stderr, "add arrows = `%s'\n", string); */
271 for (p = string; p != NULL && *p; string = p) 272 for (p = string; p != NULL && *p; string = p)
272 { 273 {
273 p = (string + 3); 274 p = (string + 3);
294 cur->str = string; 295 cur->str = string;
295 cur->len = 0; 296 cur->len = 0;
296 297
297 if (cur == &end) 298 if (cur == &end)
298 { 299 {
299 p = STRCHR (string, '\0'); 300 p = strchr (string, '\0');
300 } 301 }
301 else 302 else
302 { 303 {
303 char *next = string; 304 char *next = string;
304 305
305 while (1) 306 while (1)
306 { 307 {
307 p = STRCHR (next, '<'); 308 p = strchr (next, '<');
308 if (p != NULL) 309 if (p != NULL)
309 { 310 {
310 if (p[1] && p[2] == '>') 311 if (p[1] && p[2] == '>')
311 break; 312 break;
312 /* parsed */ 313 /* parsed */
313 } 314 }
314 else 315 else
315 { 316 {
316 if (beg.str == NULL) /* no end needed */ 317 if (beg.str == NULL) /* no end needed */
317 p = STRCHR (next, '\0'); 318 p = strchr (next, '\0');
318 break; 319 break;
319 } 320 }
320 next = (p + 1); 321 next = (p + 1);
321 } 322 }
322 } 323 }
349 menuarrow_free (Arrows[i].name); 350 menuarrow_free (Arrows[i].name);
350 } 351 }
351 352
352 for (i = 0; i < NARROWS; i++) 353 for (i = 0; i < NARROWS; i++)
353 { 354 {
354 unsigned char *str; 355 char *str;
355 unsigned int len; 356 unsigned int len;
356 357
357 if (!parse[i].len) 358 if (!parse[i].len)
358 continue; 359 continue;
359 360
360 str = (unsigned char *) rxvt_malloc (parse[i].len + xtra_len + 1); 361 str = (char *)rxvt_malloc (parse[i].len + xtra_len + 1);
361 362
362 len = 0; 363 len = 0;
363 if (beg.len) 364 if (beg.len)
364 { 365 {
365 STRNCPY (str + len, beg.str, beg.len); 366 strncpy (str + len, beg.str, beg.len);
366 len += beg.len; 367 len += beg.len;
367 } 368 }
368 STRNCPY (str + len, parse[i].str, parse[i].len); 369 strncpy (str + len, parse[i].str, parse[i].len);
369 len += parse[i].len; 370 len += parse[i].len;
370 371
371 if (end.len) 372 if (end.len)
372 { 373 {
373 STRNCPY (str + len, end.str, end.len); 374 strncpy (str + len, end.str, end.len);
374 len += end.len; 375 len += end.len;
375 } 376 }
376 str[len] = '\0'; 377 str[len] = '\0';
377 378
378#ifdef DEBUG_MENUARROWS 379#ifdef DEBUG_MENUARROWS
432 item = (menuitem_t *) rxvt_malloc (sizeof (menuitem_t)); 433 item = (menuitem_t *) rxvt_malloc (sizeof (menuitem_t));
433 434
434 item->len2 = 0; 435 item->len2 = 0;
435 item->name2 = NULL; 436 item->name2 = NULL;
436 437
437 len = STRLEN (name); 438 len = strlen (name);
438 item->name = (char *)rxvt_malloc (len + 1); 439 item->name = (char *)rxvt_malloc (len + 1);
439 STRCPY (item->name, name); 440 strcpy (item->name, name);
440 if (name[0] == '.' && name[1] != '.') 441 if (name[0] == '.' && name[1] != '.')
441 len = 0; /* hidden menu name */ 442 len = 0; /* hidden menu name */
442 item->len = len; 443 item->len = len;
443 444
444 /* add to tail of list */ 445 /* add to tail of list */
456 * add action 457 * add action
457 */ 458 */
458Item_Found: 459Item_Found:
459 if (name2 != NULL && item->name2 == NULL) 460 if (name2 != NULL && item->name2 == NULL)
460 { 461 {
461 len = STRLEN (name2); 462 len = strlen (name2);
462 if (len == 0) 463 if (len == 0)
463 item->name2 = NULL; 464 item->name2 = NULL;
464 else 465 else
465 { 466 {
466 item->name2 = (char *)rxvt_malloc (len + 1); 467 item->name2 = (char *)rxvt_malloc (len + 1);
467 STRCPY (item->name2, name2); 468 strcpy (item->name2, name2);
468 } 469 }
469 item->len2 = len; 470 item->len2 = len;
470 } 471 }
471 item->entry.type = MenuLabel; 472 item->entry.type = MenuLabel;
472 len = STRLEN (action); 473 len = strlen (action);
473 474
474 if (len == 0 && item->name2 != NULL) 475 if (len == 0 && item->name2 != NULL)
475 { 476 {
476 action = item->name2; 477 action = item->name2;
477 len = item->len2; 478 len = item->len2;
478 } 479 }
479 if (len) 480 if (len)
480 { 481 {
481 unsigned char *str = (unsigned char *)rxvt_malloc (len + 1); 482 char *str = (char *)rxvt_malloc (len + 1);
482 483
483 STRCPY (str, action); 484 strcpy (str, action);
484 485
485 if (rxvt_action_type (& (item->entry.action), str) < 0) 486 if (rxvt_action_type (& (item->entry.action), str) < 0)
486 free (str); 487 free (str);
487 } 488 }
488 /* new item and a possible increase in width */ 489 /* new item and a possible increase in width */
508#endif 509#endif
509 510
510 if (path[0] == '\0') 511 if (path[0] == '\0')
511 return path; 512 return path;
512 513
513 if (STRCHR (path, '/') != NULL) 514 if (strchr (path, '/') != NULL)
514 { 515 {
515 char *p = path; 516 char *p = path;
516 517
517 while ((p = STRCHR (p, '/')) != NULL) 518 while ((p = strchr (p, '/')) != NULL)
518 { 519 {
519 p++; 520 p++;
520 if (*p == '/') 521 if (*p == '/')
521 path = p; 522 path = p;
522 } 523 }
525 { 526 {
526 path++; 527 path++;
527 *menu = NULL; 528 *menu = NULL;
528 } 529 }
529 530
530 while ((p = STRCHR (path, '/')) != NULL) 531 while ((p = strchr (path, '/')) != NULL)
531 { 532 {
532 p[0] = '\0'; 533 p[0] = '\0';
533 if (path[0] == '\0') 534 if (path[0] == '\0')
534 return NULL; 535 return NULL;
535 536
536 if (!STRCMP (path, DOT)) 537 if (!strcmp (path, DOT))
537 { 538 {
538 /* nothing to do */ 539 /* nothing to do */
539 } 540 }
540 else if (!STRCMP (path, DOTS)) 541 else if (!strcmp (path, DOTS))
541 { 542 {
542 if (*menu != NULL) 543 if (*menu != NULL)
543 *menu = (*menu)->parent; 544 *menu = (*menu)->parent;
544 } 545 }
545 else 546 else
554 555
555 path = (p + 1); 556 path = (p + 1);
556 } 557 }
557 } 558 }
558 559
559 if (!STRCMP (path, DOTS)) 560 if (!strcmp (path, DOTS))
560 { 561 {
561 path += STRLEN (DOTS); 562 path += strlen (DOTS);
562 if (*menu != NULL) 563 if (*menu != NULL)
563 *menu = (*menu)->parent; 564 *menu = (*menu)->parent;
564 return path; 565 return path;
565 } 566 }
566 567
567 /* find this menu */ 568 /* find this menu */
568 if (*menu == NULL) 569 if (*menu == NULL)
569 { 570 {
570 for (m = CurrentBar->tail; m != NULL; m = m->prev) 571 for (m = CurrentBar->tail; m != NULL; m = m->prev)
571 if (!STRCMP (path, m->name)) 572 if (!strcmp (path, m->name))
572 break; 573 break;
573 } 574 }
574 else 575 else
575 { 576 {
576 /* find this menu */ 577 /* find this menu */
577 for (item = (*menu)->tail; item != NULL; item = item->prev) 578 for (item = (*menu)->tail; item != NULL; item = item->prev)
578 { 579 {
579 if (item->entry.type == MenuSubMenu 580 if (item->entry.type == MenuSubMenu
580 && !STRCMP (path, (item->entry.submenu.menu)->name)) 581 && !strcmp (path, (item->entry.submenu.menu)->name))
581 { 582 {
582 m = (item->entry.submenu.menu); 583 m = (item->entry.submenu.menu);
583 break; 584 break;
584 } 585 }
585 } 586 }
586 } 587 }
587 588
588 if (m != NULL) 589 if (m != NULL)
589 { 590 {
590 *menu = m; 591 *menu = m;
591 path += STRLEN (path); 592 path += strlen (path);
592 } 593 }
593 594
594 return path; 595 return path;
595} 596}
596 597
670 671
671#ifdef DEBUG_STRICT 672#ifdef DEBUG_STRICT
672 assert (CurrentBar != NULL); 673 assert (CurrentBar != NULL);
673#endif 674#endif
674 675
675 if (STRCHR (path, '/') != NULL) 676 if (strchr (path, '/') != NULL)
676 { 677 {
677 char *p; 678 char *p;
678 679
679 if (path[0] == '/') 680 if (path[0] == '/')
680 { 681 {
681 /* shouldn't happen */ 682 /* shouldn't happen */
682 path++; 683 path++;
683 parent = NULL; 684 parent = NULL;
684 } 685 }
685 while ((p = STRCHR (path, '/')) != NULL) 686 while ((p = strchr (path, '/')) != NULL)
686 { 687 {
687 p[0] = '\0'; 688 p[0] = '\0';
688 if (path[0] == '\0') 689 if (path[0] == '\0')
689 return NULL; 690 return NULL;
690 691
691 parent = menu_add (parent, path); 692 parent = menu_add (parent, path);
692 path = (p + 1); 693 path = (p + 1);
693 } 694 }
694 } 695 }
695 if (!STRCMP (path, DOTS)) 696 if (!strcmp (path, DOTS))
696 return (parent != NULL ? parent->parent : parent); 697 return (parent != NULL ? parent->parent : parent);
697 698
698 if (!STRCMP (path, DOT) || path[0] == '\0') 699 if (!strcmp (path, DOT) || path[0] == '\0')
699 return parent; 700 return parent;
700 701
701 /* allocate a new menu */ 702 /* allocate a new menu */
702 menu = (menu_t *) rxvt_malloc (sizeof (menu_t)); 703 menu = (menu_t *) rxvt_malloc (sizeof (menu_t));
703 704
704 menu->width = 0; 705 menu->width = 0;
705 menu->parent = parent; 706 menu->parent = parent;
706 menu->len = STRLEN (path); 707 menu->len = strlen (path);
707 menu->name = (char *)rxvt_malloc ((menu->len + 1)); 708 menu->name = (char *)rxvt_malloc ((menu->len + 1));
708 STRCPY (menu->name, path); 709 strcpy (menu->name, path);
709 710
710 /* initialize head/tail */ 711 /* initialize head/tail */
711 menu->head = menu->tail = NULL; 712 menu->head = menu->tail = NULL;
712 menu->prev = menu->next = NULL; 713 menu->prev = menu->next = NULL;
713 714
753{ 754{
754 GC top, bot; 755 GC top, bot;
755 756
756 x = Width2Pixel (x); 757 x = Width2Pixel (x);
757 len = Width2Pixel (len + HSPACE); 758 len = Width2Pixel (len + HSPACE);
758 if (x >= TermWin.width) 759 if (x >= width)
759 return; 760 return;
760 else if (x + len >= TermWin.width) 761 else if (x + len >= width)
761 len = (TermWin_TotalWidth () - x); 762 len = (this->width - x);
762 763
763#ifdef MENUBAR_SHADOW_IN 764#ifdef MENUBAR_SHADOW_IN
764 state = -state; 765 state = -state;
765#endif 766#endif
766 switch (state) 767 switch (state)
804 default: 805 default:
805 top = bot = scrollbarGC; 806 top = bot = scrollbarGC;
806 break; /* neutral */ 807 break; /* neutral */
807 } 808 }
808 809
809 w = Height2Pixel (1) - 2 * SHADOW; 810 w = Height2Pixel (1) - 2 * MENU_SHADOW;
810 811
811 x -= SHADOW + (3 * w / 2); 812 x -= MENU_SHADOW + (3 * w / 2);
812 y += SHADOW * 3; 813 y += MENU_SHADOW * 3;
813 814
814 rxvt_Draw_Triangle (display->display, ActiveMenu->win, top, bot, x, y, w, 'r'); 815 rxvt_Draw_Triangle (display->display, ActiveMenu->win, top, bot, x, y, w, 'r');
815} 816}
816 817
817void 818void
836 top = bot = scrollbarGC; 837 top = bot = scrollbarGC;
837 break; /* neutral */ 838 break; /* neutral */
838 } 839 }
839 840
840 rxvt_Draw_Shadow (display->display, ActiveMenu->win, top, bot, 841 rxvt_Draw_Shadow (display->display, ActiveMenu->win, top, bot,
841 SHADOW + 0, SHADOW + y, 842 MENU_SHADOW + 0, MENU_SHADOW + y,
842 ActiveMenu->w - 2 * (SHADOW), 843 ActiveMenu->w - 2 * (MENU_SHADOW),
843 HEIGHT_TEXT + 2 * SHADOW); 844 HEIGHT_TEXT + 2 * MENU_SHADOW);
844 XFlush (display->display); 845 XFlush (display->display);
845} 846}
846 847
847#ifdef DEBUG_MENU_LAYOUT 848#ifdef DEBUG_MENU_LAYOUT
848void 849void
942 x = Width2Pixel (x); 943 x = Width2Pixel (x);
943 944
944 ActiveMenu->y = 1; 945 ActiveMenu->y = 1;
945 ActiveMenu->w = Menu_PixelWidth (ActiveMenu); 946 ActiveMenu->w = Menu_PixelWidth (ActiveMenu);
946 947
947 if ((x + ActiveMenu->w) >= TermWin.width) 948 if ((x + ActiveMenu->w) >= width)
948 x = (TermWin_TotalWidth () - ActiveMenu->w); 949 x = (this->width - ActiveMenu->w);
949 950
950 /* find the height */ 951 /* find the height */
951 for (h = 0, item = ActiveMenu->head; item != NULL; item = item->next) 952 for (h = 0, item = ActiveMenu->head; item != NULL; item = item->next)
952 h += isSeparator (item->name) ? HEIGHT_SEPARATOR 953 h += isSeparator (item->name) ? HEIGHT_SEPARATOR
953 : HEIGHT_TEXT + 2 * SHADOW; 954 : HEIGHT_TEXT + 2 * MENU_SHADOW;
954 ActiveMenu->h = h + 2 * SHADOW; 955 ActiveMenu->h = h + 2 * MENU_SHADOW;
955 } 956 }
956 957
957 if (ActiveMenu->win == None) 958 if (ActiveMenu->win == None)
958 { 959 {
959 ActiveMenu->win = XCreateSimpleWindow (display->display, TermWin.vt, 960 ActiveMenu->win = XCreateSimpleWindow (display->display, vt,
960 x, ActiveMenu->y, 961 x, ActiveMenu->y,
961 ActiveMenu->w, ActiveMenu->h, 962 ActiveMenu->w, ActiveMenu->h,
962 0, 963 0,
963 PixColors[Color_fg], 964 pix_colors[Color_fg],
964 PixColors[Color_scroll]); 965 pix_colors[Color_scroll]);
965 ActiveMenu->drawable = new rxvt_drawable (display, ActiveMenu->win); 966 ActiveMenu->drawable = new rxvt_drawable (display, ActiveMenu->win);
966 XMapWindow (display->display, ActiveMenu->win); 967 XMapWindow (display->display, ActiveMenu->win);
967 } 968 }
968 969
969 rxvt_Draw_Shadow (display->display, ActiveMenu->win, 970 rxvt_Draw_Shadow (display->display, ActiveMenu->win,
975 if (item->len2 > xright) 976 if (item->len2 > xright)
976 xright = item->len2; 977 xright = item->len2;
977 978
978 for (y = 0, item = ActiveMenu->head; item != NULL; item = item->next) 979 for (y = 0, item = ActiveMenu->head; item != NULL; item = item->next)
979 { 980 {
980 const int xoff = (SHADOW + Width2Pixel (HSPACE) / 2); 981 const int xoff = (MENU_SHADOW + Width2Pixel (HSPACE) / 2);
981 register int h; 982 register int h;
982 GC gc = menubarGC; 983 GC gc = menubarGC;
983 984
984 if (isSeparator (item->name)) 985 if (isSeparator (item->name))
985 { 986 {
986 rxvt_Draw_Shadow (display->display, ActiveMenu->win, 987 rxvt_Draw_Shadow (display->display, ActiveMenu->win,
987 topShadowGC, botShadowGC, 988 topShadowGC, botShadowGC,
988 SHADOW, y + SHADOW + 1, 989 MENU_SHADOW, y + MENU_SHADOW + 1,
989 ActiveMenu->w - 2 * SHADOW, 0); 990 ActiveMenu->w - 2 * MENU_SHADOW, 0);
990 h = HEIGHT_SEPARATOR; 991 h = HEIGHT_SEPARATOR;
991 } 992 }
992 else 993 else
993 { 994 {
994 char *name = item->name; 995 char *name = item->name;
1018 x1 += x; 1019 x1 += x;
1019 1020
1020 /* find the height of this submenu */ 1021 /* find the height of this submenu */
1021 for (h = 0, it = menu->head; it != NULL; it = it->next) 1022 for (h = 0, it = menu->head; it != NULL; it = it->next)
1022 h += isSeparator (it->name) ? HEIGHT_SEPARATOR 1023 h += isSeparator (it->name) ? HEIGHT_SEPARATOR
1023 : HEIGHT_TEXT + 2 * SHADOW; 1024 : HEIGHT_TEXT + 2 * MENU_SHADOW;
1024 menu->h = h + 2 * SHADOW; 1025 menu->h = h + 2 * MENU_SHADOW;
1025 1026
1026 /* ensure menu is in window limits */ 1027 /* ensure menu is in window limits */
1027 if ((x1 + menu->w) >= TermWin.width) 1028 if ((x1 + menu->w) >= width)
1028 x1 = (TermWin_TotalWidth () - menu->w); 1029 x1 = (this->width - menu->w);
1029 1030
1030 if ((y1 + menu->h) >= TermWin.height) 1031 if ((y1 + menu->h) >= height)
1031 y1 = (TermWin_TotalHeight () - menu->h); 1032 y1 = (this->height - menu->h);
1032 1033
1033 menu->x = (x1 < 0 ? 0 : x1); 1034 menu->x = (x1 < 0 ? 0 : x1);
1034 menu->y = (y1 < 0 ? 0 : y1); 1035 menu->y = (y1 < 0 ? 0 : y1);
1035 } 1036 }
1036 else if (item->name2 && !STRCMP (name, item->name2)) 1037 else if (item->name2 && !strcmp (name, item->name2))
1037 name = NULL; 1038 name = NULL;
1038 1039
1039 if (len && name) 1040 if (len && name)
1040 draw_string (*ActiveMenu->drawable, gc, TermWin.fontset, 1041 draw_string (*ActiveMenu->drawable, gc, fontset[0],
1041 xoff, 2 * SHADOW + y, name, len); 1042 xoff, 2 * MENU_SHADOW + y, name, len);
1042 1043
1043 len = item->len2; 1044 len = item->len2;
1044 name = item->name2; 1045 name = item->name2;
1045 1046
1046 if (len && name) 1047 if (len && name)
1047 draw_string (*ActiveMenu->drawable, gc, TermWin.fontset, 1048 draw_string (*ActiveMenu->drawable, gc, fontset[0],
1048 ActiveMenu->w - (xoff + Width2Pixel (xright)), 2 * SHADOW + y, name, len); 1049 ActiveMenu->w - (xoff + Width2Pixel (xright)), 2 * MENU_SHADOW + y, name, len);
1049 1050
1050 h = HEIGHT_TEXT + 2 * SHADOW; 1051 h = HEIGHT_TEXT + 2 * MENU_SHADOW;
1051 } 1052 }
1052 y += h; 1053 y += h;
1053 } 1054 }
1054} 1055}
1055 1056
1142 fprintf (stderr, "looking for [menu:%s] ...", name ? name : " (nil)"); 1143 fprintf (stderr, "looking for [menu:%s] ...", name ? name : " (nil)");
1143#endif 1144#endif
1144 if (bar == NULL || name == NULL) 1145 if (bar == NULL || name == NULL)
1145 return NULL; 1146 return NULL;
1146 1147
1147 if (STRLEN (name) && STRCMP (name, "*")) 1148 if (strlen (name) && strcmp (name, "*"))
1148 { 1149 {
1149 do 1150 do
1150 { 1151 {
1151 if (!STRCMP (bar->name, name)) 1152 if (!strcmp (bar->name, name))
1152 { 1153 {
1153#ifdef DEBUG_MENUBAR_STACKING 1154#ifdef DEBUG_MENUBAR_STACKING
1154 fprintf (stderr, " found!\n"); 1155 fprintf (stderr, " found!\n");
1155#endif 1156#endif
1156 return bar; 1157 return bar;
1176 if (CurrentBar == NULL) 1177 if (CurrentBar == NULL)
1177 { 1178 {
1178 /* allocate first one */ 1179 /* allocate first one */
1179 bar = (bar_t *) rxvt_malloc (sizeof (bar_t)); 1180 bar = (bar_t *) rxvt_malloc (sizeof (bar_t));
1180 1181
1181 MEMSET (bar, 0, sizeof (bar_t)); 1182 memset (bar, 0, sizeof (bar_t));
1182 /* circular linked-list */ 1183 /* circular linked-list */
1183 bar->next = bar->prev = bar; 1184 bar->next = bar->prev = bar;
1184 bar->head = bar->tail = NULL; 1185 bar->head = bar->tail = NULL;
1185 bar->title = NULL; 1186 bar->title = NULL;
1186 CurrentBar = bar; 1187 CurrentBar = bar;
1233 menubar_clear (); 1234 menubar_clear ();
1234 } 1235 }
1235 } 1236 }
1236 1237
1237 /* give menubar this name */ 1238 /* give menubar this name */
1238 STRNCPY (CurrentBar->name, name, MAXNAME); 1239 strncpy (CurrentBar->name, name, MAXNAME);
1239 CurrentBar->name[MAXNAME - 1] = '\0'; 1240 CurrentBar->name[MAXNAME - 1] = '\0';
1240 1241
1241 return ret; 1242 return ret;
1242} 1243}
1243 1244
1276 1277
1277 free (CurrentBar); 1278 free (CurrentBar);
1278 CurrentBar = prev; 1279 CurrentBar = prev;
1279 } 1280 }
1280 } 1281 }
1281 while (CurrentBar && !STRCMP (name, "*")); 1282 while (CurrentBar && !strcmp (name, "*"));
1282} 1283}
1283 1284
1284void 1285void
1285rxvt_action_decode (FILE *fp, action_t *act) 1286rxvt_action_decode (FILE *fp, action_t *act)
1286{ 1287{
1287 unsigned char *str; 1288 char *str;
1288 short len; 1289 short len;
1289 1290
1290 if (act == NULL || (len = act->len) == 0 || (str = act->str) == NULL) 1291 if (act == NULL || (len = act->len) == 0 || (str = act->str) == NULL)
1291 return; 1292 return;
1292 1293
1325 * have to be escaped to avoid Shell (or whatever scripting 1326 * have to be escaped to avoid Shell (or whatever scripting
1326 * language) interpretation 1327 * language) interpretation
1327 */ 1328 */
1328 while (len > 0) 1329 while (len > 0)
1329 { 1330 {
1330 unsigned char ch = *str++; 1331 char ch = *str++;
1331 1332
1332 switch (ch) 1333 switch (ch)
1333 { 1334 {
1334 case C0_ESC: 1335 case C0_ESC:
1335 fprintf (fp, "\\E"); 1336 fprintf (fp, "\\E");
1346 case 127: 1347 case 127:
1347 fprintf (fp, "^?"); 1348 fprintf (fp, "^?");
1348 default: 1349 default:
1349 if (ch <= 31) 1350 if (ch <= 31)
1350 fprintf (fp, "^%c", ('@' + ch)); 1351 fprintf (fp, "^%c", ('@' + ch));
1351 else if (ch > 127) 1352 else if ((unsigned char)ch > 127)
1352 fprintf (fp, "\\%o", ch); 1353 fprintf (fp, "\\%o", ch);
1353 else 1354 else
1354 fprintf (fp, "%c", ch); 1355 fprintf (fp, "%c", ch);
1355 break; 1356 break;
1356 } 1357 }
1379 else 1380 else
1380 rxvt_menu_dump (fp, item->entry.submenu.menu); 1381 rxvt_menu_dump (fp, item->entry.submenu.menu);
1381 break; 1382 break;
1382 1383
1383 case MenuLabel: 1384 case MenuLabel:
1384 fprintf (fp, "{%s}\n", (STRLEN (item->name) ? item->name : "-")); 1385 fprintf (fp, "{%s}\n", (strlen (item->name) ? item->name : "-"));
1385 break; 1386 break;
1386 1387
1387 case MenuTerminalAction: 1388 case MenuTerminalAction:
1388 case MenuAction: 1389 case MenuAction:
1389 fprintf (fp, "{%s}", item->name); 1390 fprintf (fp, "{%s}", item->name);
1390 if (item->name2 != NULL && STRLEN (item->name2)) 1391 if (item->name2 != NULL && strlen (item->name2))
1391 fprintf (fp, "{%s}", item->name2); 1392 fprintf (fp, "{%s}", item->name2);
1392 fprintf (fp, "\t"); 1393 fprintf (fp, "\t");
1393 rxvt_action_decode (fp, & (item->entry.action)); 1394 rxvt_action_decode (fp, & (item->entry.action));
1394 break; 1395 break;
1395 } 1396 }
1479 if (fp == NULL) 1480 if (fp == NULL)
1480 return; 1481 return;
1481 1482
1482#if (MENUBAR_MAX > 1) 1483#if (MENUBAR_MAX > 1)
1483 /* semi-colon delimited */ 1484 /* semi-colon delimited */
1484 if ((tag = STRCHR (filename, ';')) != NULL) 1485 if ((tag = strchr (filename, ';')) != NULL)
1485 { 1486 {
1486 tag++; 1487 tag++;
1487 if (*tag == '\0') 1488 if (*tag == '\0')
1488 tag = NULL; 1489 tag = NULL;
1489 } 1490 }
1563 /* what? ... skip this line */ 1564 /* what? ... skip this line */
1564 p[0] = COMMENT_CHAR; 1565 p[0] = COMMENT_CHAR;
1565 } 1566 }
1566 } 1567 }
1567 } 1568 }
1569
1568 /* 1570 /*
1569 * remove leading/trailing space 1571 * remove leading/trailing space
1570 * and strip-off leading/trailing quotes
1571 * skip blank or comment lines 1572 * skip blank or comment lines
1572 */ 1573 */
1573 rxvt_Str_trim (p); 1574 rxvt_Str_trim (p);
1574 if (*p && *p != '#') 1575 if (*p && *p != '#')
1575 { 1576 {
1629 if (str[0] == ':') 1630 if (str[0] == ':')
1630 { /* [:command:] */ 1631 { /* [:command:] */
1631 do 1632 do
1632 { 1633 {
1633 next++; 1634 next++;
1634 if ((next = STRCHR (next, ':')) == NULL) 1635 if ((next = strchr (next, ':')) == NULL)
1635 return; /* parse error */ 1636 return; /* parse error */
1636 } 1637 }
1637 while (next[1] != ']'); 1638 while (next[1] != ']');
1638 /* remove and skip ':]' */ 1639 /* remove and skip ':]' */
1639 *next = '\0'; 1640 *next = '\0';
1640 next += 2; 1641 next += 2;
1641 } 1642 }
1642 else 1643 else
1643 { 1644 {
1644 if ((next = STRCHR (next, ']')) == NULL) 1645 if ((next = strchr (next, ']')) == NULL)
1645 return; /* parse error */ 1646 return; /* parse error */
1646 /* remove and skip ']' */ 1647 /* remove and skip ']' */
1647 *next = '\0'; 1648 *next = '\0';
1648 next++; 1649 next++;
1649 } 1650 }
1657 menu_readonly = 0; 1658 menu_readonly = 0;
1658 menubar_dispatch (str + 1); 1659 menubar_dispatch (str + 1);
1659 menu_readonly = saved; 1660 menu_readonly = saved;
1660 } 1661 }
1661 /* these ones don't require menu stacking */ 1662 /* these ones don't require menu stacking */
1662 else if (!STRCMP (str, "clear")) 1663 else if (!strcmp (str, "clear"))
1663 { 1664 {
1664 menubar_clear (); 1665 menubar_clear ();
1665 } 1666 }
1666 else if (!STRCMP (str, "done") || rxvt_Str_match (str, "done:")) 1667 else if (!strcmp (str, "done") || rxvt_Str_match (str, "done:"))
1667 { 1668 {
1668 menu_readonly = 1; 1669 menu_readonly = 1;
1669 } 1670 }
1670 else if (!STRCMP (str, "show")) 1671 else if (!strcmp (str, "show"))
1671 { 1672 {
1672 map_menuBar (1); 1673 map_menuBar (1);
1673 menu_readonly = 1; 1674 menu_readonly = 1;
1674 } 1675 }
1675 else if (!STRCMP (str, "hide")) 1676 else if (!strcmp (str, "hide"))
1676 { 1677 {
1677 map_menuBar (0); 1678 map_menuBar (0);
1678 menu_readonly = 1; 1679 menu_readonly = 1;
1679 } 1680 }
1680 else if ((n = rxvt_Str_match (str, "read:")) != 0) 1681 else if ((n = rxvt_Str_match (str, "read:")) != 0)
1688 str += n; 1689 str += n;
1689 if (CurrentBar != NULL && !menu_readonly) 1690 if (CurrentBar != NULL && !menu_readonly)
1690 { 1691 {
1691 if (*str) 1692 if (*str)
1692 { 1693 {
1693 name = (char *)rxvt_realloc (CurrentBar->title, STRLEN (str) + 1); 1694 name = (char *)rxvt_realloc (CurrentBar->title, strlen (str) + 1);
1694 if (name != NULL) 1695 if (name != NULL)
1695 { 1696 {
1696 STRCPY (name, str); 1697 strcpy (name, str);
1697 CurrentBar->title = name; 1698 CurrentBar->title = name;
1698 } 1699 }
1699 menubar_expose (); 1700 menubar_expose ();
1700 } 1701 }
1701 else 1702 else
1706 } 1707 }
1707 } 1708 }
1708 else if ((n = rxvt_Str_match (str, "pixmap:")) != 0) 1709 else if ((n = rxvt_Str_match (str, "pixmap:")) != 0)
1709 { 1710 {
1710 str += n; 1711 str += n;
1711 xterm_seq (XTerm_Pixmap, str, CHAR_ST); 1712 process_xterm_seq (Rxvt_Pixmap, str, CHAR_ST);
1712 } 1713 }
1713#if (MENUBAR_MAX > 1) 1714#if (MENUBAR_MAX > 1)
1714 else if ((n = rxvt_Str_match (str, "rm")) != 0) 1715 else if ((n = rxvt_Str_match (str, "rm")) != 0)
1715 { 1716 {
1716 str += n; 1717 str += n;
1746 } 1747 }
1747 1748
1748 if (CurrentBar != NULL) 1749 if (CurrentBar != NULL)
1749 menu_readonly = 0; /* allow menu build commands */ 1750 menu_readonly = 0; /* allow menu build commands */
1750 } 1751 }
1751 else if (!STRCMP (str, "dump")) 1752 else if (!strcmp (str, "dump"))
1752 { 1753 {
1753 /* dump current menubars to a file */ 1754 /* dump current menubars to a file */
1754 FILE *fp; 1755 FILE *fp;
1755 1756
1756 /* enough space to hold the results */ 1757 /* enough space to hold the results */
1759 sprintf (buffer, "/tmp/" RESCLASS "-%u", 1760 sprintf (buffer, "/tmp/" RESCLASS "-%u",
1760 (unsigned int)getpid ()); 1761 (unsigned int)getpid ());
1761 1762
1762 if ((fp = fopen (buffer, "wb")) != NULL) 1763 if ((fp = fopen (buffer, "wb")) != NULL)
1763 { 1764 {
1764 xterm_seq (XTerm_title, buffer, CHAR_ST); 1765 process_xterm_seq (XTerm_title, buffer, CHAR_ST);
1765 menubar_dump (fp); 1766 menubar_dump (fp);
1766 fclose (fp); 1767 fclose (fp);
1767 } 1768 }
1768 } 1769 }
1769 else if (!STRCMP (str, "next")) 1770 else if (!strcmp (str, "next"))
1770 { 1771 {
1771 if (CurrentBar) 1772 if (CurrentBar)
1772 { 1773 {
1773 CurrentBar = CurrentBar->next; 1774 CurrentBar = CurrentBar->next;
1774 menu_readonly = 1; 1775 menu_readonly = 1;
1775 } 1776 }
1776 } 1777 }
1777 else if (!STRCMP (str, "prev")) 1778 else if (!strcmp (str, "prev"))
1778 { 1779 {
1779 if (CurrentBar) 1780 if (CurrentBar)
1780 { 1781 {
1781 CurrentBar = CurrentBar->prev; 1782 CurrentBar = CurrentBar->prev;
1782 menu_readonly = 1; 1783 menu_readonly = 1;
1783 } 1784 }
1784 } 1785 }
1785 else if (!STRCMP (str, "swap")) 1786 else if (!strcmp (str, "swap"))
1786 { 1787 {
1787 /* swap the top 2 menus */ 1788 /* swap the top 2 menus */
1788 if (CurrentBar) 1789 if (CurrentBar)
1789 { 1790 {
1790 bar_t *cbprev = CurrentBar->prev; 1791 bar_t *cbprev = CurrentBar->prev;
1839 1840
1840 name2 = NULL; 1841 name2 = NULL;
1841 /* parse STR, allow spaces inside (name) */ 1842 /* parse STR, allow spaces inside (name) */
1842 if (path[0] != '\0') 1843 if (path[0] != '\0')
1843 { 1844 {
1844 name = STRCHR (path, MENUITEM_BEG); 1845 name = strchr (path, MENUITEM_BEG);
1845 str = STRCHR (path, MENUITEM_END); 1846 str = strchr (path, MENUITEM_END);
1846 if (name != NULL || str != NULL) 1847 if (name != NULL || str != NULL)
1847 { 1848 {
1848 if (name == NULL || str == NULL || str <= (name + 1) 1849 if (name == NULL || str == NULL || str <= (name + 1)
1849 || (name > path && name[-1] != '/')) 1850 || (name > path && name[-1] != '/'))
1850 { 1851 {
1852 break; 1853 break;
1853 } 1854 }
1854 if (str[1] == MENUITEM_BEG) 1855 if (str[1] == MENUITEM_BEG)
1855 { 1856 {
1856 name2 = (str + 2); 1857 name2 = (str + 2);
1857 str = STRCHR (name2, MENUITEM_END); 1858 str = strchr (name2, MENUITEM_END);
1858 1859
1859 if (str == NULL) 1860 if (str == NULL)
1860 { 1861 {
1861 rxvt_warn ("menu error B<%s>, continuing.\n", path); 1862 rxvt_warn ("menu error B<%s>, continuing.\n", path);
1862 break; 1863 break;
1888 if (path[0] != '\0') 1889 if (path[0] != '\0')
1889 { 1890 {
1890 int len; 1891 int len;
1891 1892
1892 path = menu_find_base (& (BuildMenu), path); 1893 path = menu_find_base (& (BuildMenu), path);
1893 len = STRLEN (path); 1894 len = strlen (path);
1894 1895
1895 /* don't allow menus called `*' */ 1896 /* don't allow menus called `*' */
1896 if (path[0] == '*') 1897 if (path[0] == '*')
1897 { 1898 {
1898 menu_clear (BuildMenu); 1899 menu_clear (BuildMenu);
1899 break; 1900 break;
1900 } 1901 }
1901 else if (len >= 2 && !STRCMP ((path + len - 2), "/*")) 1902 else if (len >= 2 && !strcmp ((path + len - 2), "/*"))
1902 { 1903 {
1903 path[len - 2] = '\0'; 1904 path[len - 2] = '\0';
1904 } 1905 }
1905 if (path[0] != '\0') 1906 if (path[0] != '\0')
1906 BuildMenu = menu_add (BuildMenu, path); 1907 BuildMenu = menu_add (BuildMenu, path);
1907 } 1908 }
1908 if (name != NULL && name[0] != '\0') 1909 if (name != NULL && name[0] != '\0')
1909 rxvt_menuitem_add (BuildMenu, 1910 rxvt_menuitem_add (BuildMenu,
1910 (STRCMP (name, SEPARATOR_NAME) ? name : ""), 1911 (strcmp (name, SEPARATOR_NAME) ? name : ""),
1911 name2, str); 1912 name2, str);
1912 break; 1913 break;
1913 1914
1914 case '-': /* delete menu entry */ 1915 case '-': /* delete menu entry */
1915 if (!STRCMP (path, "/*") && (name == NULL || name[0] == '\0')) 1916 if (!strcmp (path, "/*") && (name == NULL || name[0] == '\0'))
1916 { 1917 {
1917 menubar_clear (); 1918 menubar_clear ();
1918 BuildMenu = NULL; 1919 BuildMenu = NULL;
1919 menubar_expose (); 1920 menubar_expose ();
1920 break; 1921 break;
1923 { 1924 {
1924 int len; 1925 int len;
1925 menu_t *menu = BuildMenu; 1926 menu_t *menu = BuildMenu;
1926 1927
1927 path = menu_find_base (&menu, path); 1928 path = menu_find_base (&menu, path);
1928 len = STRLEN (path); 1929 len = strlen (path);
1929 1930
1930 /* submenu called `*' clears all menu items */ 1931 /* submenu called `*' clears all menu items */
1931 if (path[0] == '*') 1932 if (path[0] == '*')
1932 { 1933 {
1933 menu_clear (menu); 1934 menu_clear (menu);
1934 break; /* done */ 1935 break; /* done */
1935 } 1936 }
1936 else if (len >= 2 && !STRCMP (&path[len - 2], "/*")) 1937 else if (len >= 2 && !strcmp (&path[len - 2], "/*"))
1937 { 1938 {
1938 /* done */ 1939 /* done */
1939 break; 1940 break;
1940 } 1941 }
1941 else if (path[0] != '\0') 1942 else if (path[0] != '\0')
1944 break; 1945 break;
1945 } 1946 }
1946 else 1947 else
1947 BuildMenu = menu; 1948 BuildMenu = menu;
1948 } 1949 }
1950
1949 if (BuildMenu != NULL) 1951 if (BuildMenu != NULL)
1950 { 1952 {
1951 if (name == NULL || name[0] == '\0') 1953 if (name == NULL || name[0] == '\0')
1952 BuildMenu = menu_delete (BuildMenu); 1954 BuildMenu = menu_delete (BuildMenu);
1953 else 1955 else
1954 { 1956 {
1955 const char *n1; 1957 const char *n1;
1956 menuitem_t *item; 1958 menuitem_t *item;
1957 menu_t *BuildMenu = BuildMenu;
1958 1959
1959 n1 = STRCMP (name, SEPARATOR_NAME) ? name : ""; 1960 n1 = strcmp (name, SEPARATOR_NAME) ? name : "";
1960 item = rxvt_menuitem_find (BuildMenu, n1); 1961 item = rxvt_menuitem_find (BuildMenu, n1);
1961 if (item != NULL && item->entry.type != MenuSubMenu) 1962 if (item != NULL && item->entry.type != MenuSubMenu)
1962 { 1963 {
1963 menuitem_free (BuildMenu, item); 1964 menuitem_free (BuildMenu, item);
1964 1965
1967 for (item = BuildMenu->head; item != NULL; 1968 for (item = BuildMenu->head; item != NULL;
1968 item = item->next) 1969 item = item->next)
1969 { 1970 {
1970 short l = item->len + item->len2; 1971 short l = item->len + item->len2;
1971 1972
1972 MAX_IT (BuildMenu->width, l); 1973 max_it (BuildMenu->width, l);
1973 } 1974 }
1974 } 1975 }
1975 } 1976 }
1977
1976 menubar_expose (); 1978 menubar_expose ();
1977 } 1979 }
1978 break; 1980 break;
1979 } 1981 }
1980 break; 1982 break;
2015 const int y = (menuBar_TotalHeight () - w) / 2; 2017 const int y = (menuBar_TotalHeight () - w) / 2;
2016 int x = Arrows_x + (5 * Width2Pixel (i)) / 4; 2018 int x = Arrows_x + (5 * Width2Pixel (i)) / 4;
2017 2019
2018 if (!name || name == Arrows[i].name) 2020 if (!name || name == Arrows[i].name)
2019 rxvt_Draw_Triangle (display->display, menuBar.win, top, bot, x, y, w, 2021 rxvt_Draw_Triangle (display->display, menuBar.win, top, bot, x, y, w,
2020 Arrows[i].name); 2022 Arrows[i].name);
2021 } 2023 }
2022 XFlush (display->display); 2024 XFlush (display->display);
2023} 2025}
2024 2026
2025void 2027void
2034 if (menubarGC == None) 2036 if (menubarGC == None)
2035 { 2037 {
2036 /* Create the graphics context */ 2038 /* Create the graphics context */
2037 XGCValues gcvalue; 2039 XGCValues gcvalue;
2038 2040
2039 gcvalue.foreground = (XDEPTH <= 2 ? PixColors[Color_fg] 2041 gcvalue.foreground = (display->depth <= 2 ? pix_colors[Color_fg]
2040 : PixColors[Color_Black]); 2042 : pix_colors[Color_Black]);
2041 menubarGC = XCreateGC (display->display, menuBar.win, 2043 menubarGC = XCreateGC (display->display, menuBar.win,
2042 GCForeground, &gcvalue); 2044 GCForeground, &gcvalue);
2043 2045
2044 } 2046 }
2045 /* make sure the font is correct */ 2047 /* make sure the font is correct */
2058 2060
2059#ifdef DEBUG_MENU_LAYOUT 2061#ifdef DEBUG_MENU_LAYOUT
2060 rxvt_print_menu_descendants (menu); 2062 rxvt_print_menu_descendants (menu);
2061#endif 2063#endif
2062 2064
2063 if (x >= TermWin.ncol) 2065 if (x >= ncol)
2064 len = (TermWin.ncol - (menu->x + HSPACE)); 2066 len = (ncol - (menu->x + HSPACE));
2065 2067
2066 drawbox_menubar (menu->x, len, +1); 2068 drawbox_menubar (menu->x, len, +1);
2067 draw_string (*menuBar.drawable, menubarGC, TermWin.fontset, 2069 draw_string (*menuBar.drawable, menubarGC, fontset[0],
2068 (Width2Pixel (menu->x) + Width2Pixel (HSPACE) / 2), 2070 (Width2Pixel (menu->x) + Width2Pixel (HSPACE) / 2),
2069 SHADOW, menu->name, len); 2071 MENU_SHADOW, menu->name, len);
2070 2072
2071 if (x >= TermWin.ncol) 2073 if (x >= ncol)
2072 break; 2074 break;
2073 } 2075 }
2074 } 2076 }
2075 drawbox_menubar (x, TermWin.ncol, (CurrentBar ? +1 : -1)); 2077 drawbox_menubar (x, ncol, (CurrentBar ? +1 : -1));
2076 2078
2077 /* add the menuBar title, if it exists and there's plenty of room */ 2079 /* add the menuBar title, if it exists and there's plenty of room */
2078 Arrows_x = 0; 2080 Arrows_x = 0;
2079 if (x < TermWin.ncol) 2081 if (x < ncol)
2080 { 2082 {
2081 const char *str; 2083 const char *str;
2082 int ncol;
2083 unsigned int len; 2084 unsigned int len;
2084 char title[256]; 2085 char title[256];
2085 2086
2086 ncol = (int)TermWin.ncol;
2087 if (x < (ncol - (NARROWS + 1))) 2087 if (x < (ncol - (NARROWS + 1)))
2088 { 2088 {
2089 ncol -= (NARROWS + 1); 2089 ncol -= (NARROWS + 1);
2090 Arrows_x = Width2Pixel (ncol); 2090 Arrows_x = Width2Pixel (ncol);
2091 } 2091 }
2092
2092 draw_Arrows (0, +1); 2093 draw_Arrows (0, +1);
2093 2094
2094 str = (CurrentBar 2095 str = (CurrentBar
2095 && CurrentBar->title) ? CurrentBar->title : "%n-%v"; 2096 && CurrentBar->title) ? CurrentBar->title : "%n-%v";
2096 for (len = 0; str[0] && len < sizeof (title) - 1; str++) 2097 for (len = 0; str[0] && len < sizeof (title) - 1; str++)
2125 } 2126 }
2126 title[len] = '\0'; 2127 title[len] = '\0';
2127 2128
2128 ncol -= (x + len + HSPACE); 2129 ncol -= (x + len + HSPACE);
2129 if (len > 0 && ncol >= 0) 2130 if (len > 0 && ncol >= 0)
2130 draw_string (*menuBar.drawable, menubarGC, TermWin.fontset, 2131 draw_string (*menuBar.drawable, menubarGC, fontset[0],
2131 Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2, 2132 Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2,
2132 SHADOW, title, len); 2133 MENU_SHADOW, title, len);
2133 } 2134 }
2134} 2135}
2135 2136
2136int 2137int
2137rxvt_term::menubar_mapping (int map) 2138rxvt_term::menubar_mapping (int map)
2182 menu_hide (); 2183 menu_hide ();
2183 return 1; 2184 return 1;
2184 } 2185 }
2185 2186
2186 /* determine the menu item corresponding to the Y index */ 2187 /* determine the menu item corresponding to the Y index */
2187 y = SHADOW; 2188 y = MENU_SHADOW;
2188 if (ev.x >= 0 && ev.x <= (ActiveMenu->w - SHADOW)) 2189 if (ev.x >= 0 && ev.x <= (ActiveMenu->w - MENU_SHADOW))
2189 { 2190 {
2190 for (item = ActiveMenu->head; item != NULL; item = item->next) 2191 for (item = ActiveMenu->head; item != NULL; item = item->next)
2191 { 2192 {
2192 int h = HEIGHT_TEXT + 2 * SHADOW; 2193 int h = HEIGHT_TEXT + 2 * MENU_SHADOW;
2193 2194
2194 if (isSeparator (item->name)) 2195 if (isSeparator (item->name))
2195 h = HEIGHT_SEPARATOR; 2196 h = HEIGHT_SEPARATOR;
2196 else if (ev.y >= y && ev.y < (y + h)) 2197 else if (ev.y >= y && ev.y < (y + h))
2197 break; 2198 break;
2205 menu_hide_all (); 2206 menu_hide_all ();
2206 return 0; 2207 return 0;
2207 } 2208 }
2208 2209
2209 thisitem = item; 2210 thisitem = item;
2210 this_y = y - SHADOW; 2211 this_y = y - MENU_SHADOW;
2211 2212
2212 /* erase the last item */ 2213 /* erase the last item */
2213 if (ActiveMenu->item != NULL) 2214 if (ActiveMenu->item != NULL)
2214 { 2215 {
2215 if (ActiveMenu->item != thisitem) 2216 if (ActiveMenu->item != thisitem)
2228 drawtriangle (ActiveMenu->w, y, +1); 2229 drawtriangle (ActiveMenu->w, y, +1);
2229 2230
2230 break; 2231 break;
2231 } 2232 }
2232 else 2233 else
2233 h = HEIGHT_TEXT + 2 * SHADOW; 2234 h = HEIGHT_TEXT + 2 * MENU_SHADOW;
2234 2235
2235 y += h; 2236 y += h;
2236 } 2237 }
2237 } 2238 }
2238 else 2239 else
2248 break; 2249 break;
2249 2250
2250 case MenuAction: 2251 case MenuAction:
2251 case MenuTerminalAction: 2252 case MenuTerminalAction:
2252 drawbox_menuitem (this_y, -1); 2253 drawbox_menuitem (this_y, -1);
2253#ifdef HAVE_NANOSLEEP
2254 struct timespec rqt;
2255
2256 rqt.tv_sec = 0;
2257 rqt.tv_nsec = MENU_DELAY_USEC * 1000;
2258 nanosleep (&rqt, NULL);
2259#else
2260 /* use select for timing */
2261 struct timeval tv;
2262
2263 tv.tv_sec = 0;
2264 tv.tv_usec = MENU_DELAY_USEC; 2254 rxvt_usleep (MENU_DELAY_USEC);
2265 select (0, NULL, NULL, NULL, &tv);
2266#endif
2267 /* remove menu before sending keys to the application */ 2255 /* remove menu before sending keys to the application */
2268 menu_hide_all (); 2256 menu_hide_all ();
2269#ifndef DEBUG_MENU 2257#ifndef DEBUG_MENU
2270 action_dispatch (& (item->entry.action)); 2258 action_dispatch (& (item->entry.action));
2271#else /* DEBUG_MENU */ 2259#else /* DEBUG_MENU */
2349 if (ev.x >= (Arrows_x + (Width2Pixel (4 * i + i)) / 4) 2337 if (ev.x >= (Arrows_x + (Width2Pixel (4 * i + i)) / 4)
2350 && ev.x < (Arrows_x 2338 && ev.x < (Arrows_x
2351 + (Width2Pixel (4 * i + i + 4)) / 4)) 2339 + (Width2Pixel (4 * i + i + 4)) / 4))
2352 { 2340 {
2353 draw_Arrows (Arrows[i].name, -1); 2341 draw_Arrows (Arrows[i].name, -1);
2354 {
2355#ifdef HAVE_NANOSLEEP
2356 struct timespec rqt;
2357
2358 rqt.tv_sec = 0;
2359 rqt.tv_nsec = MENU_DELAY_USEC * 1000;
2360 nanosleep (&rqt, NULL);
2361#else
2362 /* use select for timing */
2363 struct timeval tv;
2364
2365 tv.tv_sec = 0;
2366 tv.tv_usec = MENU_DELAY_USEC; 2342 rxvt_usleep (MENU_DELAY_USEC);
2367 select (0, NULL, NULL, NULL, &tv);
2368#endif
2369
2370 }
2371 draw_Arrows (Arrows[i].name, +1); 2343 draw_Arrows (Arrows[i].name, +1);
2372#ifdef DEBUG_MENUARROWS 2344#ifdef DEBUG_MENUARROWS
2373 fprintf (stderr, "'%c': ", Arrows[i].name); 2345 fprintf (stderr, "'%c': ", Arrows[i].name);
2374 2346
2375 if (CurrentBar == NULL 2347 if (CurrentBar == NULL
2432 if (ev.button == Button1) 2404 if (ev.button == Button1)
2433 menu_select (ev); 2405 menu_select (ev);
2434 break; 2406 break;
2435 2407
2436 case MotionNotify: 2408 case MotionNotify:
2437 while (XCheckTypedWindowEvent (display->display, TermWin.parent[0], 2409 while (XCheckTypedWindowEvent (display->display, parent[0],
2438 MotionNotify, (XEvent *)&ev)) ; 2410 MotionNotify, (XEvent *)&ev));
2439 2411
2440 if (ActiveMenu) 2412 if (ActiveMenu)
2441 while (menu_select (ev)) ; 2413 while (menu_select (ev)) ;
2442 else 2414 else
2443 ev.y = -1; 2415 ev.y = -1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines