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.13 by pcg, Sat Mar 6 00:05:01 2004 UTC vs.
Revision 1.25 by root, Wed Nov 30 14:23:29 2005 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 * 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 unsigned 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
152rxvt_action_type (action_t *action, unsigned char *str) 152rxvt_action_type (action_t *action, unsigned 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
263 beg = { NULL, 0 }, 263 beg = { NULL, 0 },
264 end = { NULL, 0 }, 264 end = { NULL, 0 },
265 *cur, 265 *cur,
266 parse[NARROWS]; 266 parse[NARROWS];
267 267
268 MEMSET (parse, 0, sizeof (parse)); 268 memset (parse, 0, sizeof (parse));
269 269
270 /* fprintf (stderr, "add arrows = `%s'\n", string); */ 270 /* fprintf (stderr, "add arrows = `%s'\n", string); */
271 for (p = string; p != NULL && *p; string = p) 271 for (p = string; p != NULL && *p; string = p)
272 { 272 {
273 p = (string + 3); 273 p = (string + 3);
294 cur->str = string; 294 cur->str = string;
295 cur->len = 0; 295 cur->len = 0;
296 296
297 if (cur == &end) 297 if (cur == &end)
298 { 298 {
299 p = STRCHR (string, '\0'); 299 p = strchr (string, '\0');
300 } 300 }
301 else 301 else
302 { 302 {
303 char *next = string; 303 char *next = string;
304 304
305 while (1) 305 while (1)
306 { 306 {
307 p = STRCHR (next, '<'); 307 p = strchr (next, '<');
308 if (p != NULL) 308 if (p != NULL)
309 { 309 {
310 if (p[1] && p[2] == '>') 310 if (p[1] && p[2] == '>')
311 break; 311 break;
312 /* parsed */ 312 /* parsed */
313 } 313 }
314 else 314 else
315 { 315 {
316 if (beg.str == NULL) /* no end needed */ 316 if (beg.str == NULL) /* no end needed */
317 p = STRCHR (next, '\0'); 317 p = strchr (next, '\0');
318 break; 318 break;
319 } 319 }
320 next = (p + 1); 320 next = (p + 1);
321 } 321 }
322 } 322 }
360 str = (unsigned char *) rxvt_malloc (parse[i].len + xtra_len + 1); 360 str = (unsigned char *) rxvt_malloc (parse[i].len + xtra_len + 1);
361 361
362 len = 0; 362 len = 0;
363 if (beg.len) 363 if (beg.len)
364 { 364 {
365 STRNCPY (str + len, beg.str, beg.len); 365 strncpy (str + len, beg.str, beg.len);
366 len += beg.len; 366 len += beg.len;
367 } 367 }
368 STRNCPY (str + len, parse[i].str, parse[i].len); 368 strncpy (str + len, parse[i].str, parse[i].len);
369 len += parse[i].len; 369 len += parse[i].len;
370 370
371 if (end.len) 371 if (end.len)
372 { 372 {
373 STRNCPY (str + len, end.str, end.len); 373 strncpy (str + len, end.str, end.len);
374 len += end.len; 374 len += end.len;
375 } 375 }
376 str[len] = '\0'; 376 str[len] = '\0';
377 377
378#ifdef DEBUG_MENUARROWS 378#ifdef DEBUG_MENUARROWS
432 item = (menuitem_t *) rxvt_malloc (sizeof (menuitem_t)); 432 item = (menuitem_t *) rxvt_malloc (sizeof (menuitem_t));
433 433
434 item->len2 = 0; 434 item->len2 = 0;
435 item->name2 = NULL; 435 item->name2 = NULL;
436 436
437 len = STRLEN (name); 437 len = strlen (name);
438 item->name = (char *)rxvt_malloc (len + 1); 438 item->name = (char *)rxvt_malloc (len + 1);
439 STRCPY (item->name, name); 439 strcpy (item->name, name);
440 if (name[0] == '.' && name[1] != '.') 440 if (name[0] == '.' && name[1] != '.')
441 len = 0; /* hidden menu name */ 441 len = 0; /* hidden menu name */
442 item->len = len; 442 item->len = len;
443 443
444 /* add to tail of list */ 444 /* add to tail of list */
456 * add action 456 * add action
457 */ 457 */
458Item_Found: 458Item_Found:
459 if (name2 != NULL && item->name2 == NULL) 459 if (name2 != NULL && item->name2 == NULL)
460 { 460 {
461 len = STRLEN (name2); 461 len = strlen (name2);
462 if (len == 0) 462 if (len == 0)
463 item->name2 = NULL; 463 item->name2 = NULL;
464 else 464 else
465 { 465 {
466 item->name2 = (char *)rxvt_malloc (len + 1); 466 item->name2 = (char *)rxvt_malloc (len + 1);
467 STRCPY (item->name2, name2); 467 strcpy (item->name2, name2);
468 } 468 }
469 item->len2 = len; 469 item->len2 = len;
470 } 470 }
471 item->entry.type = MenuLabel; 471 item->entry.type = MenuLabel;
472 len = STRLEN (action); 472 len = strlen (action);
473 473
474 if (len == 0 && item->name2 != NULL) 474 if (len == 0 && item->name2 != NULL)
475 { 475 {
476 action = item->name2; 476 action = item->name2;
477 len = item->len2; 477 len = item->len2;
478 } 478 }
479 if (len) 479 if (len)
480 { 480 {
481 unsigned char *str = (unsigned char *)rxvt_malloc (len + 1); 481 unsigned char *str = (unsigned char *)rxvt_malloc (len + 1);
482 482
483 STRCPY (str, action); 483 strcpy (str, action);
484 484
485 if (rxvt_action_type (& (item->entry.action), str) < 0) 485 if (rxvt_action_type (& (item->entry.action), str) < 0)
486 free (str); 486 free (str);
487 } 487 }
488 /* new item and a possible increase in width */ 488 /* new item and a possible increase in width */
508#endif 508#endif
509 509
510 if (path[0] == '\0') 510 if (path[0] == '\0')
511 return path; 511 return path;
512 512
513 if (STRCHR (path, '/') != NULL) 513 if (strchr (path, '/') != NULL)
514 { 514 {
515 char *p = path; 515 char *p = path;
516 516
517 while ((p = STRCHR (p, '/')) != NULL) 517 while ((p = strchr (p, '/')) != NULL)
518 { 518 {
519 p++; 519 p++;
520 if (*p == '/') 520 if (*p == '/')
521 path = p; 521 path = p;
522 } 522 }
525 { 525 {
526 path++; 526 path++;
527 *menu = NULL; 527 *menu = NULL;
528 } 528 }
529 529
530 while ((p = STRCHR (path, '/')) != NULL) 530 while ((p = strchr (path, '/')) != NULL)
531 { 531 {
532 p[0] = '\0'; 532 p[0] = '\0';
533 if (path[0] == '\0') 533 if (path[0] == '\0')
534 return NULL; 534 return NULL;
535 535
536 if (!STRCMP (path, DOT)) 536 if (!strcmp (path, DOT))
537 { 537 {
538 /* nothing to do */ 538 /* nothing to do */
539 } 539 }
540 else if (!STRCMP (path, DOTS)) 540 else if (!strcmp (path, DOTS))
541 { 541 {
542 if (*menu != NULL) 542 if (*menu != NULL)
543 *menu = (*menu)->parent; 543 *menu = (*menu)->parent;
544 } 544 }
545 else 545 else
554 554
555 path = (p + 1); 555 path = (p + 1);
556 } 556 }
557 } 557 }
558 558
559 if (!STRCMP (path, DOTS)) 559 if (!strcmp (path, DOTS))
560 { 560 {
561 path += STRLEN (DOTS); 561 path += strlen (DOTS);
562 if (*menu != NULL) 562 if (*menu != NULL)
563 *menu = (*menu)->parent; 563 *menu = (*menu)->parent;
564 return path; 564 return path;
565 } 565 }
566 566
567 /* find this menu */ 567 /* find this menu */
568 if (*menu == NULL) 568 if (*menu == NULL)
569 { 569 {
570 for (m = CurrentBar->tail; m != NULL; m = m->prev) 570 for (m = CurrentBar->tail; m != NULL; m = m->prev)
571 if (!STRCMP (path, m->name)) 571 if (!strcmp (path, m->name))
572 break; 572 break;
573 } 573 }
574 else 574 else
575 { 575 {
576 /* find this menu */ 576 /* find this menu */
577 for (item = (*menu)->tail; item != NULL; item = item->prev) 577 for (item = (*menu)->tail; item != NULL; item = item->prev)
578 { 578 {
579 if (item->entry.type == MenuSubMenu 579 if (item->entry.type == MenuSubMenu
580 && !STRCMP (path, (item->entry.submenu.menu)->name)) 580 && !strcmp (path, (item->entry.submenu.menu)->name))
581 { 581 {
582 m = (item->entry.submenu.menu); 582 m = (item->entry.submenu.menu);
583 break; 583 break;
584 } 584 }
585 } 585 }
586 } 586 }
587 587
588 if (m != NULL) 588 if (m != NULL)
589 { 589 {
590 *menu = m; 590 *menu = m;
591 path += STRLEN (path); 591 path += strlen (path);
592 } 592 }
593 593
594 return path; 594 return path;
595} 595}
596 596
670 670
671#ifdef DEBUG_STRICT 671#ifdef DEBUG_STRICT
672 assert (CurrentBar != NULL); 672 assert (CurrentBar != NULL);
673#endif 673#endif
674 674
675 if (STRCHR (path, '/') != NULL) 675 if (strchr (path, '/') != NULL)
676 { 676 {
677 char *p; 677 char *p;
678 678
679 if (path[0] == '/') 679 if (path[0] == '/')
680 { 680 {
681 /* shouldn't happen */ 681 /* shouldn't happen */
682 path++; 682 path++;
683 parent = NULL; 683 parent = NULL;
684 } 684 }
685 while ((p = STRCHR (path, '/')) != NULL) 685 while ((p = strchr (path, '/')) != NULL)
686 { 686 {
687 p[0] = '\0'; 687 p[0] = '\0';
688 if (path[0] == '\0') 688 if (path[0] == '\0')
689 return NULL; 689 return NULL;
690 690
691 parent = menu_add (parent, path); 691 parent = menu_add (parent, path);
692 path = (p + 1); 692 path = (p + 1);
693 } 693 }
694 } 694 }
695 if (!STRCMP (path, DOTS)) 695 if (!strcmp (path, DOTS))
696 return (parent != NULL ? parent->parent : parent); 696 return (parent != NULL ? parent->parent : parent);
697 697
698 if (!STRCMP (path, DOT) || path[0] == '\0') 698 if (!strcmp (path, DOT) || path[0] == '\0')
699 return parent; 699 return parent;
700 700
701 /* allocate a new menu */ 701 /* allocate a new menu */
702 menu = (menu_t *) rxvt_malloc (sizeof (menu_t)); 702 menu = (menu_t *) rxvt_malloc (sizeof (menu_t));
703 703
704 menu->width = 0; 704 menu->width = 0;
705 menu->parent = parent; 705 menu->parent = parent;
706 menu->len = STRLEN (path); 706 menu->len = strlen (path);
707 menu->name = (char *)rxvt_malloc ((menu->len + 1)); 707 menu->name = (char *)rxvt_malloc ((menu->len + 1));
708 STRCPY (menu->name, path); 708 strcpy (menu->name, path);
709 709
710 /* initialize head/tail */ 710 /* initialize head/tail */
711 menu->head = menu->tail = NULL; 711 menu->head = menu->tail = NULL;
712 menu->prev = menu->next = NULL; 712 menu->prev = menu->next = NULL;
713 713
955 } 955 }
956 956
957 if (ActiveMenu->win == None) 957 if (ActiveMenu->win == None)
958 { 958 {
959 ActiveMenu->win = XCreateSimpleWindow (display->display, TermWin.vt, 959 ActiveMenu->win = XCreateSimpleWindow (display->display, TermWin.vt,
960 x, ActiveMenu->y, 960 x, ActiveMenu->y,
961 ActiveMenu->w, ActiveMenu->h, 961 ActiveMenu->w, ActiveMenu->h,
962 0, 962 0,
963 PixColors[Color_fg], 963 pix_colors[Color_fg],
964 PixColors[Color_scroll]); 964 pix_colors[Color_scroll]);
965 ActiveMenu->drawable = new rxvt_drawable (display, ActiveMenu->win); 965 ActiveMenu->drawable = new rxvt_drawable (display, ActiveMenu->win);
966 XMapWindow (display->display, ActiveMenu->win); 966 XMapWindow (display->display, ActiveMenu->win);
967 } 967 }
968 968
969 rxvt_Draw_Shadow (display->display, ActiveMenu->win, 969 rxvt_Draw_Shadow (display->display, ActiveMenu->win,
982 GC gc = menubarGC; 982 GC gc = menubarGC;
983 983
984 if (isSeparator (item->name)) 984 if (isSeparator (item->name))
985 { 985 {
986 rxvt_Draw_Shadow (display->display, ActiveMenu->win, 986 rxvt_Draw_Shadow (display->display, ActiveMenu->win,
987 topShadowGC, botShadowGC, 987 topShadowGC, botShadowGC,
988 SHADOW, y + SHADOW + 1, 988 SHADOW, y + SHADOW + 1,
989 ActiveMenu->w - 2 * SHADOW, 0); 989 ActiveMenu->w - 2 * SHADOW, 0);
990 h = HEIGHT_SEPARATOR; 990 h = HEIGHT_SEPARATOR;
991 } 991 }
992 else 992 else
993 { 993 {
994 char *name = item->name; 994 char *name = item->name;
1031 y1 = (TermWin_TotalHeight () - menu->h); 1031 y1 = (TermWin_TotalHeight () - menu->h);
1032 1032
1033 menu->x = (x1 < 0 ? 0 : x1); 1033 menu->x = (x1 < 0 ? 0 : x1);
1034 menu->y = (y1 < 0 ? 0 : y1); 1034 menu->y = (y1 < 0 ? 0 : y1);
1035 } 1035 }
1036 else if (item->name2 && !STRCMP (name, item->name2)) 1036 else if (item->name2 && !strcmp (name, item->name2))
1037 name = NULL; 1037 name = NULL;
1038 1038
1039 if (len && name) 1039 if (len && name)
1040 draw_string (*ActiveMenu->drawable, gc, TermWin.fontset, 1040 draw_string (*ActiveMenu->drawable, gc, TermWin.fontset[0],
1041 xoff, 2 * SHADOW + y, name, len); 1041 xoff, 2 * SHADOW + y, name, len);
1042 1042
1043 len = item->len2; 1043 len = item->len2;
1044 name = item->name2; 1044 name = item->name2;
1045 1045
1046 if (len && name) 1046 if (len && name)
1047 draw_string (*ActiveMenu->drawable, gc, TermWin.fontset, 1047 draw_string (*ActiveMenu->drawable, gc, TermWin.fontset[0],
1048 ActiveMenu->w - (xoff + Width2Pixel (xright)), 2 * SHADOW + y, name, len); 1048 ActiveMenu->w - (xoff + Width2Pixel (xright)), 2 * SHADOW + y, name, len);
1049 1049
1050 h = HEIGHT_TEXT + 2 * SHADOW; 1050 h = HEIGHT_TEXT + 2 * SHADOW;
1051 } 1051 }
1052 y += h; 1052 y += h;
1142 fprintf (stderr, "looking for [menu:%s] ...", name ? name : " (nil)"); 1142 fprintf (stderr, "looking for [menu:%s] ...", name ? name : " (nil)");
1143#endif 1143#endif
1144 if (bar == NULL || name == NULL) 1144 if (bar == NULL || name == NULL)
1145 return NULL; 1145 return NULL;
1146 1146
1147 if (STRLEN (name) && STRCMP (name, "*")) 1147 if (strlen (name) && strcmp (name, "*"))
1148 { 1148 {
1149 do 1149 do
1150 { 1150 {
1151 if (!STRCMP (bar->name, name)) 1151 if (!strcmp (bar->name, name))
1152 { 1152 {
1153#ifdef DEBUG_MENUBAR_STACKING 1153#ifdef DEBUG_MENUBAR_STACKING
1154 fprintf (stderr, " found!\n"); 1154 fprintf (stderr, " found!\n");
1155#endif 1155#endif
1156 return bar; 1156 return bar;
1176 if (CurrentBar == NULL) 1176 if (CurrentBar == NULL)
1177 { 1177 {
1178 /* allocate first one */ 1178 /* allocate first one */
1179 bar = (bar_t *) rxvt_malloc (sizeof (bar_t)); 1179 bar = (bar_t *) rxvt_malloc (sizeof (bar_t));
1180 1180
1181 MEMSET (bar, 0, sizeof (bar_t)); 1181 memset (bar, 0, sizeof (bar_t));
1182 /* circular linked-list */ 1182 /* circular linked-list */
1183 bar->next = bar->prev = bar; 1183 bar->next = bar->prev = bar;
1184 bar->head = bar->tail = NULL; 1184 bar->head = bar->tail = NULL;
1185 bar->title = NULL; 1185 bar->title = NULL;
1186 CurrentBar = bar; 1186 CurrentBar = bar;
1233 menubar_clear (); 1233 menubar_clear ();
1234 } 1234 }
1235 } 1235 }
1236 1236
1237 /* give menubar this name */ 1237 /* give menubar this name */
1238 STRNCPY (CurrentBar->name, name, MAXNAME); 1238 strncpy (CurrentBar->name, name, MAXNAME);
1239 CurrentBar->name[MAXNAME - 1] = '\0'; 1239 CurrentBar->name[MAXNAME - 1] = '\0';
1240 1240
1241 return ret; 1241 return ret;
1242} 1242}
1243 1243
1276 1276
1277 free (CurrentBar); 1277 free (CurrentBar);
1278 CurrentBar = prev; 1278 CurrentBar = prev;
1279 } 1279 }
1280 } 1280 }
1281 while (CurrentBar && !STRCMP (name, "*")); 1281 while (CurrentBar && !strcmp (name, "*"));
1282} 1282}
1283 1283
1284void 1284void
1285rxvt_action_decode (FILE *fp, action_t *act) 1285rxvt_action_decode (FILE *fp, action_t *act)
1286{ 1286{
1379 else 1379 else
1380 rxvt_menu_dump (fp, item->entry.submenu.menu); 1380 rxvt_menu_dump (fp, item->entry.submenu.menu);
1381 break; 1381 break;
1382 1382
1383 case MenuLabel: 1383 case MenuLabel:
1384 fprintf (fp, "{%s}\n", (STRLEN (item->name) ? item->name : "-")); 1384 fprintf (fp, "{%s}\n", (strlen (item->name) ? item->name : "-"));
1385 break; 1385 break;
1386 1386
1387 case MenuTerminalAction: 1387 case MenuTerminalAction:
1388 case MenuAction: 1388 case MenuAction:
1389 fprintf (fp, "{%s}", item->name); 1389 fprintf (fp, "{%s}", item->name);
1390 if (item->name2 != NULL && STRLEN (item->name2)) 1390 if (item->name2 != NULL && strlen (item->name2))
1391 fprintf (fp, "{%s}", item->name2); 1391 fprintf (fp, "{%s}", item->name2);
1392 fprintf (fp, "\t"); 1392 fprintf (fp, "\t");
1393 rxvt_action_decode (fp, & (item->entry.action)); 1393 rxvt_action_decode (fp, & (item->entry.action));
1394 break; 1394 break;
1395 } 1395 }
1479 if (fp == NULL) 1479 if (fp == NULL)
1480 return; 1480 return;
1481 1481
1482#if (MENUBAR_MAX > 1) 1482#if (MENUBAR_MAX > 1)
1483 /* semi-colon delimited */ 1483 /* semi-colon delimited */
1484 if ((tag = STRCHR (filename, ';')) != NULL) 1484 if ((tag = strchr (filename, ';')) != NULL)
1485 { 1485 {
1486 tag++; 1486 tag++;
1487 if (*tag == '\0') 1487 if (*tag == '\0')
1488 tag = NULL; 1488 tag = NULL;
1489 } 1489 }
1563 /* what? ... skip this line */ 1563 /* what? ... skip this line */
1564 p[0] = COMMENT_CHAR; 1564 p[0] = COMMENT_CHAR;
1565 } 1565 }
1566 } 1566 }
1567 } 1567 }
1568
1568 /* 1569 /*
1569 * remove leading/trailing space 1570 * remove leading/trailing space
1570 * and strip-off leading/trailing quotes
1571 * skip blank or comment lines 1571 * skip blank or comment lines
1572 */ 1572 */
1573 rxvt_Str_trim (p); 1573 rxvt_Str_trim (p);
1574 if (*p && *p != '#') 1574 if (*p && *p != '#')
1575 { 1575 {
1629 if (str[0] == ':') 1629 if (str[0] == ':')
1630 { /* [:command:] */ 1630 { /* [:command:] */
1631 do 1631 do
1632 { 1632 {
1633 next++; 1633 next++;
1634 if ((next = STRCHR (next, ':')) == NULL) 1634 if ((next = strchr (next, ':')) == NULL)
1635 return; /* parse error */ 1635 return; /* parse error */
1636 } 1636 }
1637 while (next[1] != ']'); 1637 while (next[1] != ']');
1638 /* remove and skip ':]' */ 1638 /* remove and skip ':]' */
1639 *next = '\0'; 1639 *next = '\0';
1640 next += 2; 1640 next += 2;
1641 } 1641 }
1642 else 1642 else
1643 { 1643 {
1644 if ((next = STRCHR (next, ']')) == NULL) 1644 if ((next = strchr (next, ']')) == NULL)
1645 return; /* parse error */ 1645 return; /* parse error */
1646 /* remove and skip ']' */ 1646 /* remove and skip ']' */
1647 *next = '\0'; 1647 *next = '\0';
1648 next++; 1648 next++;
1649 } 1649 }
1657 menu_readonly = 0; 1657 menu_readonly = 0;
1658 menubar_dispatch (str + 1); 1658 menubar_dispatch (str + 1);
1659 menu_readonly = saved; 1659 menu_readonly = saved;
1660 } 1660 }
1661 /* these ones don't require menu stacking */ 1661 /* these ones don't require menu stacking */
1662 else if (!STRCMP (str, "clear")) 1662 else if (!strcmp (str, "clear"))
1663 { 1663 {
1664 menubar_clear (); 1664 menubar_clear ();
1665 } 1665 }
1666 else if (!STRCMP (str, "done") || rxvt_Str_match (str, "done:")) 1666 else if (!strcmp (str, "done") || rxvt_Str_match (str, "done:"))
1667 { 1667 {
1668 menu_readonly = 1; 1668 menu_readonly = 1;
1669 } 1669 }
1670 else if (!STRCMP (str, "show")) 1670 else if (!strcmp (str, "show"))
1671 { 1671 {
1672 map_menuBar (1); 1672 map_menuBar (1);
1673 menu_readonly = 1; 1673 menu_readonly = 1;
1674 } 1674 }
1675 else if (!STRCMP (str, "hide")) 1675 else if (!strcmp (str, "hide"))
1676 { 1676 {
1677 map_menuBar (0); 1677 map_menuBar (0);
1678 menu_readonly = 1; 1678 menu_readonly = 1;
1679 } 1679 }
1680 else if ((n = rxvt_Str_match (str, "read:")) != 0) 1680 else if ((n = rxvt_Str_match (str, "read:")) != 0)
1688 str += n; 1688 str += n;
1689 if (CurrentBar != NULL && !menu_readonly) 1689 if (CurrentBar != NULL && !menu_readonly)
1690 { 1690 {
1691 if (*str) 1691 if (*str)
1692 { 1692 {
1693 name = (char *)rxvt_realloc (CurrentBar->title, STRLEN (str) + 1); 1693 name = (char *)rxvt_realloc (CurrentBar->title, strlen (str) + 1);
1694 if (name != NULL) 1694 if (name != NULL)
1695 { 1695 {
1696 STRCPY (name, str); 1696 strcpy (name, str);
1697 CurrentBar->title = name; 1697 CurrentBar->title = name;
1698 } 1698 }
1699 menubar_expose (); 1699 menubar_expose ();
1700 } 1700 }
1701 else 1701 else
1706 } 1706 }
1707 } 1707 }
1708 else if ((n = rxvt_Str_match (str, "pixmap:")) != 0) 1708 else if ((n = rxvt_Str_match (str, "pixmap:")) != 0)
1709 { 1709 {
1710 str += n; 1710 str += n;
1711 xterm_seq (XTerm_Pixmap, str, CHAR_ST); 1711 process_xterm_seq (XTerm_Pixmap, str, CHAR_ST);
1712 } 1712 }
1713#if (MENUBAR_MAX > 1) 1713#if (MENUBAR_MAX > 1)
1714 else if ((n = rxvt_Str_match (str, "rm")) != 0) 1714 else if ((n = rxvt_Str_match (str, "rm")) != 0)
1715 { 1715 {
1716 str += n; 1716 str += n;
1746 } 1746 }
1747 1747
1748 if (CurrentBar != NULL) 1748 if (CurrentBar != NULL)
1749 menu_readonly = 0; /* allow menu build commands */ 1749 menu_readonly = 0; /* allow menu build commands */
1750 } 1750 }
1751 else if (!STRCMP (str, "dump")) 1751 else if (!strcmp (str, "dump"))
1752 { 1752 {
1753 /* dump current menubars to a file */ 1753 /* dump current menubars to a file */
1754 FILE *fp; 1754 FILE *fp;
1755 1755
1756 /* enough space to hold the results */ 1756 /* enough space to hold the results */
1759 sprintf (buffer, "/tmp/" RESCLASS "-%u", 1759 sprintf (buffer, "/tmp/" RESCLASS "-%u",
1760 (unsigned int)getpid ()); 1760 (unsigned int)getpid ());
1761 1761
1762 if ((fp = fopen (buffer, "wb")) != NULL) 1762 if ((fp = fopen (buffer, "wb")) != NULL)
1763 { 1763 {
1764 xterm_seq (XTerm_title, buffer, CHAR_ST); 1764 process_xterm_seq (XTerm_title, buffer, CHAR_ST);
1765 menubar_dump (fp); 1765 menubar_dump (fp);
1766 fclose (fp); 1766 fclose (fp);
1767 } 1767 }
1768 } 1768 }
1769 else if (!STRCMP (str, "next")) 1769 else if (!strcmp (str, "next"))
1770 { 1770 {
1771 if (CurrentBar) 1771 if (CurrentBar)
1772 { 1772 {
1773 CurrentBar = CurrentBar->next; 1773 CurrentBar = CurrentBar->next;
1774 menu_readonly = 1; 1774 menu_readonly = 1;
1775 } 1775 }
1776 } 1776 }
1777 else if (!STRCMP (str, "prev")) 1777 else if (!strcmp (str, "prev"))
1778 { 1778 {
1779 if (CurrentBar) 1779 if (CurrentBar)
1780 { 1780 {
1781 CurrentBar = CurrentBar->prev; 1781 CurrentBar = CurrentBar->prev;
1782 menu_readonly = 1; 1782 menu_readonly = 1;
1783 } 1783 }
1784 } 1784 }
1785 else if (!STRCMP (str, "swap")) 1785 else if (!strcmp (str, "swap"))
1786 { 1786 {
1787 /* swap the top 2 menus */ 1787 /* swap the top 2 menus */
1788 if (CurrentBar) 1788 if (CurrentBar)
1789 { 1789 {
1790 bar_t *cbprev = CurrentBar->prev; 1790 bar_t *cbprev = CurrentBar->prev;
1839 1839
1840 name2 = NULL; 1840 name2 = NULL;
1841 /* parse STR, allow spaces inside (name) */ 1841 /* parse STR, allow spaces inside (name) */
1842 if (path[0] != '\0') 1842 if (path[0] != '\0')
1843 { 1843 {
1844 name = STRCHR (path, MENUITEM_BEG); 1844 name = strchr (path, MENUITEM_BEG);
1845 str = STRCHR (path, MENUITEM_END); 1845 str = strchr (path, MENUITEM_END);
1846 if (name != NULL || str != NULL) 1846 if (name != NULL || str != NULL)
1847 { 1847 {
1848 if (name == NULL || str == NULL || str <= (name + 1) 1848 if (name == NULL || str == NULL || str <= (name + 1)
1849 || (name > path && name[-1] != '/')) 1849 || (name > path && name[-1] != '/'))
1850 { 1850 {
1851 rxvt_print_error ("menu error <%s>\n", path); 1851 rxvt_warn ("menu error A<%s>, continuing.\n", path);
1852 break; 1852 break;
1853 } 1853 }
1854 if (str[1] == MENUITEM_BEG) 1854 if (str[1] == MENUITEM_BEG)
1855 { 1855 {
1856 name2 = (str + 2); 1856 name2 = (str + 2);
1857 str = STRCHR (name2, MENUITEM_END); 1857 str = strchr (name2, MENUITEM_END);
1858 1858
1859 if (str == NULL) 1859 if (str == NULL)
1860 { 1860 {
1861 rxvt_print_error ("menu error <%s>\n", path); 1861 rxvt_warn ("menu error B<%s>, continuing.\n", path);
1862 break; 1862 break;
1863 } 1863 }
1864 name2[-2] = '\0'; /* remove prev MENUITEM_END */ 1864 name2[-2] = '\0'; /* remove prev MENUITEM_END */
1865 } 1865 }
1866 if (name > path && name[-1] == '/') 1866 if (name > path && name[-1] == '/')
1888 if (path[0] != '\0') 1888 if (path[0] != '\0')
1889 { 1889 {
1890 int len; 1890 int len;
1891 1891
1892 path = menu_find_base (& (BuildMenu), path); 1892 path = menu_find_base (& (BuildMenu), path);
1893 len = STRLEN (path); 1893 len = strlen (path);
1894 1894
1895 /* don't allow menus called `*' */ 1895 /* don't allow menus called `*' */
1896 if (path[0] == '*') 1896 if (path[0] == '*')
1897 { 1897 {
1898 menu_clear (BuildMenu); 1898 menu_clear (BuildMenu);
1899 break; 1899 break;
1900 } 1900 }
1901 else if (len >= 2 && !STRCMP ((path + len - 2), "/*")) 1901 else if (len >= 2 && !strcmp ((path + len - 2), "/*"))
1902 { 1902 {
1903 path[len - 2] = '\0'; 1903 path[len - 2] = '\0';
1904 } 1904 }
1905 if (path[0] != '\0') 1905 if (path[0] != '\0')
1906 BuildMenu = menu_add (BuildMenu, path); 1906 BuildMenu = menu_add (BuildMenu, path);
1907 } 1907 }
1908 if (name != NULL && name[0] != '\0') 1908 if (name != NULL && name[0] != '\0')
1909 rxvt_menuitem_add (BuildMenu, 1909 rxvt_menuitem_add (BuildMenu,
1910 (STRCMP (name, SEPARATOR_NAME) ? name : ""), 1910 (strcmp (name, SEPARATOR_NAME) ? name : ""),
1911 name2, str); 1911 name2, str);
1912 break; 1912 break;
1913 1913
1914 case '-': /* delete menu entry */ 1914 case '-': /* delete menu entry */
1915 if (!STRCMP (path, "/*") && (name == NULL || name[0] == '\0')) 1915 if (!strcmp (path, "/*") && (name == NULL || name[0] == '\0'))
1916 { 1916 {
1917 menubar_clear (); 1917 menubar_clear ();
1918 BuildMenu = NULL; 1918 BuildMenu = NULL;
1919 menubar_expose (); 1919 menubar_expose ();
1920 break; 1920 break;
1923 { 1923 {
1924 int len; 1924 int len;
1925 menu_t *menu = BuildMenu; 1925 menu_t *menu = BuildMenu;
1926 1926
1927 path = menu_find_base (&menu, path); 1927 path = menu_find_base (&menu, path);
1928 len = STRLEN (path); 1928 len = strlen (path);
1929 1929
1930 /* submenu called `*' clears all menu items */ 1930 /* submenu called `*' clears all menu items */
1931 if (path[0] == '*') 1931 if (path[0] == '*')
1932 { 1932 {
1933 menu_clear (menu); 1933 menu_clear (menu);
1934 break; /* done */ 1934 break; /* done */
1935 } 1935 }
1936 else if (len >= 2 && !STRCMP (&path[len - 2], "/*")) 1936 else if (len >= 2 && !strcmp (&path[len - 2], "/*"))
1937 { 1937 {
1938 /* done */ 1938 /* done */
1939 break; 1939 break;
1940 } 1940 }
1941 else if (path[0] != '\0') 1941 else if (path[0] != '\0')
1944 break; 1944 break;
1945 } 1945 }
1946 else 1946 else
1947 BuildMenu = menu; 1947 BuildMenu = menu;
1948 } 1948 }
1949
1949 if (BuildMenu != NULL) 1950 if (BuildMenu != NULL)
1950 { 1951 {
1951 if (name == NULL || name[0] == '\0') 1952 if (name == NULL || name[0] == '\0')
1952 BuildMenu = menu_delete (BuildMenu); 1953 BuildMenu = menu_delete (BuildMenu);
1953 else 1954 else
1954 { 1955 {
1955 const char *n1; 1956 const char *n1;
1956 menuitem_t *item; 1957 menuitem_t *item;
1957 menu_t *BuildMenu = BuildMenu;
1958 1958
1959 n1 = STRCMP (name, SEPARATOR_NAME) ? name : ""; 1959 n1 = strcmp (name, SEPARATOR_NAME) ? name : "";
1960 item = rxvt_menuitem_find (BuildMenu, n1); 1960 item = rxvt_menuitem_find (BuildMenu, n1);
1961 if (item != NULL && item->entry.type != MenuSubMenu) 1961 if (item != NULL && item->entry.type != MenuSubMenu)
1962 { 1962 {
1963 menuitem_free (BuildMenu, item); 1963 menuitem_free (BuildMenu, item);
1964 1964
1971 1971
1972 MAX_IT (BuildMenu->width, l); 1972 MAX_IT (BuildMenu->width, l);
1973 } 1973 }
1974 } 1974 }
1975 } 1975 }
1976
1976 menubar_expose (); 1977 menubar_expose ();
1977 } 1978 }
1978 break; 1979 break;
1979 } 1980 }
1980 break; 1981 break;
2015 const int y = (menuBar_TotalHeight () - w) / 2; 2016 const int y = (menuBar_TotalHeight () - w) / 2;
2016 int x = Arrows_x + (5 * Width2Pixel (i)) / 4; 2017 int x = Arrows_x + (5 * Width2Pixel (i)) / 4;
2017 2018
2018 if (!name || name == Arrows[i].name) 2019 if (!name || name == Arrows[i].name)
2019 rxvt_Draw_Triangle (display->display, menuBar.win, top, bot, x, y, w, 2020 rxvt_Draw_Triangle (display->display, menuBar.win, top, bot, x, y, w,
2020 Arrows[i].name); 2021 Arrows[i].name);
2021 } 2022 }
2022 XFlush (display->display); 2023 XFlush (display->display);
2023} 2024}
2024 2025
2025void 2026void
2034 if (menubarGC == None) 2035 if (menubarGC == None)
2035 { 2036 {
2036 /* Create the graphics context */ 2037 /* Create the graphics context */
2037 XGCValues gcvalue; 2038 XGCValues gcvalue;
2038 2039
2039 gcvalue.foreground = (XDEPTH <= 2 ? PixColors[Color_fg] 2040 gcvalue.foreground = (display->depth <= 2 ? pix_colors[Color_fg]
2040 : PixColors[Color_Black]); 2041 : pix_colors[Color_Black]);
2041 menubarGC = XCreateGC (display->display, menuBar.win, 2042 menubarGC = XCreateGC (display->display, menuBar.win,
2042 GCForeground, &gcvalue); 2043 GCForeground, &gcvalue);
2043 2044
2044 } 2045 }
2045 /* make sure the font is correct */ 2046 /* make sure the font is correct */
2062 2063
2063 if (x >= TermWin.ncol) 2064 if (x >= TermWin.ncol)
2064 len = (TermWin.ncol - (menu->x + HSPACE)); 2065 len = (TermWin.ncol - (menu->x + HSPACE));
2065 2066
2066 drawbox_menubar (menu->x, len, +1); 2067 drawbox_menubar (menu->x, len, +1);
2067 draw_string (*menuBar.drawable, menubarGC, TermWin.fontset, 2068 draw_string (*menuBar.drawable, menubarGC, TermWin.fontset[0],
2068 (Width2Pixel (menu->x) + Width2Pixel (HSPACE) / 2), 2069 (Width2Pixel (menu->x) + Width2Pixel (HSPACE) / 2),
2069 SHADOW, menu->name, len); 2070 SHADOW, menu->name, len);
2070 2071
2071 if (x >= TermWin.ncol) 2072 if (x >= TermWin.ncol)
2072 break; 2073 break;
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, TermWin.fontset[0],
2131 Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2, 2132 Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2,
2132 SHADOW, title, len); 2133 SHADOW, title, len);
2133 } 2134 }
2134} 2135}
2135 2136
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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines