… | |
… | |
31 | #ifdef MENUBAR |
31 | #ifdef MENUBAR |
32 | #include "version.h" |
32 | #include "version.h" |
33 | #include "menubar.h" |
33 | #include "menubar.h" |
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 | |
38 | static const struct |
38 | static 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 | } |
43 | Arrows[NARROWS] = { |
43 | Arrows[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" }, |
… | |
… | |
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 | */ |
151 | int |
151 | int |
152 | rxvt_action_type (action_t *action, unsigned char *str) |
152 | rxvt_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); |
… | |
… | |
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 | } |
… | |
… | |
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); |
… | |
… | |
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); |
… | |
… | |
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 | |
817 | void |
818 | void |
… | |
… | |
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 |
848 | void |
849 | void |
… | |
… | |
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 | pix_colors[Color_fg], |
964 | pix_colors[Color_fg], |
964 | pix_colors[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 | |
… | |
… | |
1282 | } |
1283 | } |
1283 | |
1284 | |
1284 | void |
1285 | void |
1285 | rxvt_action_decode (FILE *fp, action_t *act) |
1286 | rxvt_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 | } |
… | |
… | |
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 | { |
… | |
… | |
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 | process_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; |
… | |
… | |
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 | { |
… | |
… | |
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 | |
2025 | void |
2027 | void |
… | |
… | |
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 | |
2136 | int |
2137 | int |
2137 | rxvt_term::menubar_mapping (int map) |
2138 | rxvt_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; |