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