… | |
… | |
48 | |
48 | |
49 | /* |
49 | /* |
50 | * find an item called NAME in MENU |
50 | * find an item called NAME in MENU |
51 | */ |
51 | */ |
52 | menuitem_t * |
52 | menuitem_t * |
53 | rxvt_menuitem_find(const menu_t *menu, const char *name) |
53 | rxvt_menuitem_find (const menu_t *menu, const char *name) |
54 | { |
54 | { |
55 | menuitem_t *item; |
55 | menuitem_t *item; |
56 | |
56 | |
57 | #ifdef DEBUG_STRICT |
57 | #ifdef DEBUG_STRICT |
58 | assert(name != NULL); |
58 | assert (name != NULL); |
59 | assert(menu != NULL); |
59 | assert (menu != NULL); |
60 | #endif |
60 | #endif |
61 | |
61 | |
62 | /* find the last item in the menu, this is good for separators */ |
62 | /* find the last item in the menu, this is good for separators */ |
63 | for (item = menu->tail; item != NULL; item = item->prev) |
63 | for (item = menu->tail; item != NULL; item = item->prev) |
64 | { |
64 | { |
65 | if (item->entry.type == MenuSubMenu) |
65 | if (item->entry.type == MenuSubMenu) |
66 | { |
66 | { |
67 | if (!STRCMP(name, (item->entry.submenu.menu)->name)) |
67 | if (!STRCMP (name, (item->entry.submenu.menu)->name)) |
68 | break; |
68 | break; |
69 | } |
69 | } |
70 | else if ((isSeparator(name) && isSeparator(item->name)) |
70 | else if ((isSeparator (name) && isSeparator (item->name)) |
71 | || !STRCMP(name, item->name)) |
71 | || !STRCMP (name, item->name)) |
72 | break; |
72 | break; |
73 | } |
73 | } |
74 | return item; |
74 | return item; |
75 | } |
75 | } |
76 | |
76 | |
… | |
… | |
82 | { |
82 | { |
83 | /* disconnect */ |
83 | /* disconnect */ |
84 | menuitem_t *prev, *next; |
84 | menuitem_t *prev, *next; |
85 | |
85 | |
86 | #ifdef DEBUG_STRICT |
86 | #ifdef DEBUG_STRICT |
87 | assert(menu != NULL); |
87 | assert (menu != NULL); |
88 | #endif |
88 | #endif |
89 | |
89 | |
90 | prev = item->prev; |
90 | prev = item->prev; |
91 | next = item->next; |
91 | next = item->next; |
92 | if (prev != NULL) |
92 | if (prev != NULL) |
… | |
… | |
102 | |
102 | |
103 | switch (item->entry.type) |
103 | switch (item->entry.type) |
104 | { |
104 | { |
105 | case MenuAction: |
105 | case MenuAction: |
106 | case MenuTerminalAction: |
106 | case MenuTerminalAction: |
107 | free(item->entry.action.str); |
107 | free (item->entry.action.str); |
108 | break; |
108 | break; |
109 | case MenuSubMenu: |
109 | case MenuSubMenu: |
110 | menu_delete (item->entry.submenu.menu); |
110 | menu_delete (item->entry.submenu.menu); |
111 | break; |
111 | break; |
112 | } |
112 | } |
113 | if (item->name != NULL) |
113 | if (item->name != NULL) |
114 | free(item->name); |
114 | free (item->name); |
115 | if (item->name2 != NULL) |
115 | if (item->name2 != NULL) |
116 | free(item->name2); |
116 | free (item->name2); |
117 | free(item); |
117 | free (item); |
118 | } |
118 | } |
119 | |
119 | |
120 | /* |
120 | /* |
121 | * sort command vs. terminal actions and |
121 | * sort command vs. terminal actions and |
122 | * remove the first character of STR if it's '\0' |
122 | * remove the first character of STR if it's '\0' |
123 | */ |
123 | */ |
124 | int |
124 | int |
125 | rxvt_action_type(action_t *action, unsigned char *str) |
125 | rxvt_action_type (action_t *action, unsigned char *str) |
126 | { |
126 | { |
127 | unsigned int len; |
127 | unsigned int len; |
128 | |
128 | |
129 | #if defined (DEBUG_MENU) || defined (DEBUG_MENUARROWS) |
129 | #if defined (DEBUG_MENU) || defined (DEBUG_MENUARROWS) |
130 | len = STRLEN(str); |
130 | len = STRLEN (str); |
131 | fprintf(stderr, "(len %d) = %s\n", len, str); |
131 | fprintf (stderr, " (len %d) = %s\n", len, str); |
132 | #else |
132 | #else |
133 | len = rxvt_Str_escaped((char *)str); |
133 | len = rxvt_Str_escaped ((char *)str); |
134 | #endif |
134 | #endif |
135 | |
135 | |
136 | if (!len) |
136 | if (!len) |
137 | return -1; |
137 | return -1; |
138 | |
138 | |
… | |
… | |
178 | return 0; |
178 | return 0; |
179 | } |
179 | } |
180 | |
180 | |
181 | /* return the arrow index corresponding to NAME */ |
181 | /* return the arrow index corresponding to NAME */ |
182 | int |
182 | int |
183 | rxvt_menuarrow_find(char name) |
183 | rxvt_menuarrow_find (char name) |
184 | { |
184 | { |
185 | int i; |
185 | int i; |
186 | |
186 | |
187 | for (i = 0; i < NARROWS; i++) |
187 | for (i = 0; i < NARROWS; i++) |
188 | if (name == Arrows[i].name) |
188 | if (name == Arrows[i].name) |
… | |
… | |
196 | { |
196 | { |
197 | int i; |
197 | int i; |
198 | |
198 | |
199 | if (name) |
199 | if (name) |
200 | { |
200 | { |
201 | i = rxvt_menuarrow_find(name); |
201 | i = rxvt_menuarrow_find (name); |
202 | if (i >= 0) |
202 | if (i >= 0) |
203 | { |
203 | { |
204 | action_t *act = &(CurrentBar->arrows[i]); |
204 | action_t *act = & (CurrentBar->arrows[i]); |
205 | |
205 | |
206 | switch (act->type) |
206 | switch (act->type) |
207 | { |
207 | { |
208 | case MenuAction: |
208 | case MenuAction: |
209 | case MenuTerminalAction: |
209 | case MenuTerminalAction: |
210 | free(act->str); |
210 | free (act->str); |
211 | act->str = NULL; |
211 | act->str = NULL; |
212 | act->len = 0; |
212 | act->len = 0; |
213 | break; |
213 | break; |
214 | } |
214 | } |
215 | act->type = MenuLabel; |
215 | act->type = MenuLabel; |
… | |
… | |
236 | beg = { NULL, 0 }, |
236 | beg = { NULL, 0 }, |
237 | end = { NULL, 0 }, |
237 | end = { NULL, 0 }, |
238 | *cur, |
238 | *cur, |
239 | parse[NARROWS]; |
239 | parse[NARROWS]; |
240 | |
240 | |
241 | MEMSET(parse, 0, sizeof(parse)); |
241 | MEMSET (parse, 0, sizeof (parse)); |
242 | |
242 | |
243 | /* fprintf(stderr, "add arrows = `%s'\n", string); */ |
243 | /* fprintf (stderr, "add arrows = `%s'\n", string); */ |
244 | for (p = string; p != NULL && *p; string = p) |
244 | for (p = string; p != NULL && *p; string = p) |
245 | { |
245 | { |
246 | p = (string + 3); |
246 | p = (string + 3); |
247 | /* fprintf(stderr, "parsing at %s\n", string); */ |
247 | /* fprintf (stderr, "parsing at %s\n", string); */ |
248 | switch (string[1]) |
248 | switch (string[1]) |
249 | { |
249 | { |
250 | case 'b': |
250 | case 'b': |
251 | cur = &beg; |
251 | cur = &beg; |
252 | break; |
252 | break; |
253 | case 'e': |
253 | case 'e': |
254 | cur = &end; |
254 | cur = &end; |
255 | break; |
255 | break; |
256 | |
256 | |
257 | default: |
257 | default: |
258 | i = rxvt_menuarrow_find(string[1]); |
258 | i = rxvt_menuarrow_find (string[1]); |
259 | if (i >= 0) |
259 | if (i >= 0) |
260 | cur = &(parse[i]); |
260 | cur = & (parse[i]); |
261 | else |
261 | else |
262 | continue; /* not found */ |
262 | continue; /* not found */ |
263 | break; |
263 | break; |
264 | } |
264 | } |
265 | |
265 | |
… | |
… | |
267 | cur->str = string; |
267 | cur->str = string; |
268 | cur->len = 0; |
268 | cur->len = 0; |
269 | |
269 | |
270 | if (cur == &end) |
270 | if (cur == &end) |
271 | { |
271 | { |
272 | p = STRCHR(string, '\0'); |
272 | p = STRCHR (string, '\0'); |
273 | } |
273 | } |
274 | else |
274 | else |
275 | { |
275 | { |
276 | char *next = string; |
276 | char *next = string; |
277 | |
277 | |
278 | while (1) |
278 | while (1) |
279 | { |
279 | { |
280 | p = STRCHR(next, '<'); |
280 | p = STRCHR (next, '<'); |
281 | if (p != NULL) |
281 | if (p != NULL) |
282 | { |
282 | { |
283 | if (p[1] && p[2] == '>') |
283 | if (p[1] && p[2] == '>') |
284 | break; |
284 | break; |
285 | /* parsed */ |
285 | /* parsed */ |
286 | } |
286 | } |
287 | else |
287 | else |
288 | { |
288 | { |
289 | if (beg.str == NULL) /* no end needed */ |
289 | if (beg.str == NULL) /* no end needed */ |
290 | p = STRCHR(next, '\0'); |
290 | p = STRCHR (next, '\0'); |
291 | break; |
291 | break; |
292 | } |
292 | } |
293 | next = (p + 1); |
293 | next = (p + 1); |
294 | } |
294 | } |
295 | } |
295 | } |
… | |
… | |
299 | cur->len = (p - string); |
299 | cur->len = (p - string); |
300 | } |
300 | } |
301 | |
301 | |
302 | #ifdef DEBUG_MENUARROWS |
302 | #ifdef DEBUG_MENUARROWS |
303 | cur = &beg; |
303 | cur = &beg; |
304 | fprintf(stderr, "<b>(len %d) = %.*s\n", |
304 | fprintf (stderr, "<b> (len %d) = %.*s\n", |
305 | cur->len, cur->len, (cur->str ? cur->str : "")); |
305 | cur->len, cur->len, (cur->str ? cur->str : "")); |
306 | for (i = 0; i < NARROWS; i++) |
306 | for (i = 0; i < NARROWS; i++) |
307 | { |
307 | { |
308 | cur = &(parse[i]); |
308 | cur = & (parse[i]); |
309 | fprintf(stderr, "<%c>(len %d) = %.*s\n", |
309 | fprintf (stderr, "<%c> (len %d) = %.*s\n", |
310 | Arrows[i].name, |
310 | Arrows[i].name, |
311 | cur->len, cur->len, (cur->str ? cur->str : "")); |
311 | cur->len, cur->len, (cur->str ? cur->str : "")); |
312 | } |
312 | } |
313 | cur = &end; |
313 | cur = &end; |
314 | fprintf(stderr, "<e>(len %d) = %.*s\n", |
314 | fprintf (stderr, "<e> (len %d) = %.*s\n", |
315 | cur->len, cur->len, (cur->str ? cur->str : "")); |
315 | cur->len, cur->len, (cur->str ? cur->str : "")); |
316 | #endif |
316 | #endif |
317 | |
317 | |
318 | xtra_len = (beg.len + end.len); |
318 | xtra_len = (beg.len + end.len); |
319 | for (i = 0; i < NARROWS; i++) |
319 | for (i = 0; i < NARROWS; i++) |
… | |
… | |
328 | unsigned int len; |
328 | unsigned int len; |
329 | |
329 | |
330 | if (!parse[i].len) |
330 | if (!parse[i].len) |
331 | continue; |
331 | continue; |
332 | |
332 | |
333 | str = rxvt_malloc(parse[i].len + xtra_len + 1); |
333 | str = rxvt_malloc (parse[i].len + xtra_len + 1); |
334 | |
334 | |
335 | len = 0; |
335 | len = 0; |
336 | if (beg.len) |
336 | if (beg.len) |
337 | { |
337 | { |
338 | STRNCPY(str + len, beg.str, beg.len); |
338 | STRNCPY (str + len, beg.str, beg.len); |
339 | len += beg.len; |
339 | len += beg.len; |
340 | } |
340 | } |
341 | STRNCPY(str + len, parse[i].str, parse[i].len); |
341 | STRNCPY (str + len, parse[i].str, parse[i].len); |
342 | len += parse[i].len; |
342 | len += parse[i].len; |
343 | |
343 | |
344 | if (end.len) |
344 | if (end.len) |
345 | { |
345 | { |
346 | STRNCPY(str + len, end.str, end.len); |
346 | STRNCPY (str + len, end.str, end.len); |
347 | len += end.len; |
347 | len += end.len; |
348 | } |
348 | } |
349 | str[len] = '\0'; |
349 | str[len] = '\0'; |
350 | |
350 | |
351 | #ifdef DEBUG_MENUARROWS |
351 | #ifdef DEBUG_MENUARROWS |
352 | fprintf(stderr, "<%c>(len %d) = %s\n", Arrows[i].name, len, str); |
352 | fprintf (stderr, "<%c> (len %d) = %s\n", Arrows[i].name, len, str); |
353 | #endif |
353 | #endif |
354 | if (rxvt_action_type(&(CurrentBar->arrows[i]), str) < 0) |
354 | if (rxvt_action_type (& (CurrentBar->arrows[i]), str) < 0) |
355 | free(str); |
355 | free (str); |
356 | } |
356 | } |
357 | } |
357 | } |
358 | |
358 | |
359 | menuitem_t * |
359 | menuitem_t * |
360 | rxvt_menuitem_add(menu_t *menu, const char *name, const char *name2, const char *action) |
360 | rxvt_menuitem_add (menu_t *menu, const char *name, const char *name2, const char *action) |
361 | { |
361 | { |
362 | menuitem_t *item; |
362 | menuitem_t *item; |
363 | unsigned int len; |
363 | unsigned int len; |
364 | |
364 | |
365 | #ifdef DEBUG_STRICT |
365 | #ifdef DEBUG_STRICT |
366 | assert(name != NULL); |
366 | assert (name != NULL); |
367 | assert(action != NULL); |
367 | assert (action != NULL); |
368 | #endif |
368 | #endif |
369 | |
369 | |
370 | if (menu == NULL) |
370 | if (menu == NULL) |
371 | return NULL; |
371 | return NULL; |
372 | |
372 | |
373 | if (isSeparator(name)) |
373 | if (isSeparator (name)) |
374 | { |
374 | { |
375 | /* add separator, no action */ |
375 | /* add separator, no action */ |
376 | name = ""; |
376 | name = ""; |
377 | action = ""; |
377 | action = ""; |
378 | } |
378 | } |
379 | else |
379 | else |
380 | { |
380 | { |
381 | /* |
381 | /* |
382 | * add/replace existing menu item |
382 | * add/replace existing menu item |
383 | */ |
383 | */ |
384 | item = rxvt_menuitem_find(menu, name); |
384 | item = rxvt_menuitem_find (menu, name); |
385 | if (item != NULL) |
385 | if (item != NULL) |
386 | { |
386 | { |
387 | if (item->name2 != NULL && name2 != NULL) |
387 | if (item->name2 != NULL && name2 != NULL) |
388 | { |
388 | { |
389 | free(item->name2); |
389 | free (item->name2); |
390 | item->len2 = 0; |
390 | item->len2 = 0; |
391 | item->name2 = NULL; |
391 | item->name2 = NULL; |
392 | } |
392 | } |
393 | switch (item->entry.type) |
393 | switch (item->entry.type) |
394 | { |
394 | { |
395 | case MenuAction: |
395 | case MenuAction: |
396 | case MenuTerminalAction: |
396 | case MenuTerminalAction: |
397 | free(item->entry.action.str); |
397 | free (item->entry.action.str); |
398 | item->entry.action.str = NULL; |
398 | item->entry.action.str = NULL; |
399 | break; |
399 | break; |
400 | } |
400 | } |
401 | goto Item_Found; |
401 | goto Item_Found; |
402 | } |
402 | } |
403 | } |
403 | } |
404 | /* allocate a new itemect */ |
404 | /* allocate a new itemect */ |
405 | item = (menuitem_t *) rxvt_malloc(sizeof(menuitem_t)); |
405 | item = (menuitem_t *) rxvt_malloc (sizeof (menuitem_t)); |
406 | |
406 | |
407 | item->len2 = 0; |
407 | item->len2 = 0; |
408 | item->name2 = NULL; |
408 | item->name2 = NULL; |
409 | |
409 | |
410 | len = STRLEN(name); |
410 | len = STRLEN (name); |
411 | item->name = rxvt_malloc(len + 1); |
411 | item->name = rxvt_malloc (len + 1); |
412 | STRCPY(item->name, name); |
412 | STRCPY (item->name, name); |
413 | if (name[0] == '.' && name[1] != '.') |
413 | if (name[0] == '.' && name[1] != '.') |
414 | len = 0; /* hidden menu name */ |
414 | len = 0; /* hidden menu name */ |
415 | item->len = len; |
415 | item->len = len; |
416 | |
416 | |
417 | /* add to tail of list */ |
417 | /* add to tail of list */ |
… | |
… | |
429 | * add action |
429 | * add action |
430 | */ |
430 | */ |
431 | Item_Found: |
431 | Item_Found: |
432 | if (name2 != NULL && item->name2 == NULL) |
432 | if (name2 != NULL && item->name2 == NULL) |
433 | { |
433 | { |
434 | len = STRLEN(name2); |
434 | len = STRLEN (name2); |
435 | if (len == 0) |
435 | if (len == 0) |
436 | item->name2 = NULL; |
436 | item->name2 = NULL; |
437 | else |
437 | else |
438 | { |
438 | { |
439 | item->name2 = rxvt_malloc(len + 1); |
439 | item->name2 = rxvt_malloc (len + 1); |
440 | STRCPY(item->name2, name2); |
440 | STRCPY (item->name2, name2); |
441 | } |
441 | } |
442 | item->len2 = len; |
442 | item->len2 = len; |
443 | } |
443 | } |
444 | item->entry.type = MenuLabel; |
444 | item->entry.type = MenuLabel; |
445 | len = STRLEN(action); |
445 | len = STRLEN (action); |
446 | |
446 | |
447 | if (len == 0 && item->name2 != NULL) |
447 | if (len == 0 && item->name2 != NULL) |
448 | { |
448 | { |
449 | action = item->name2; |
449 | action = item->name2; |
450 | len = item->len2; |
450 | len = item->len2; |
451 | } |
451 | } |
452 | if (len) |
452 | if (len) |
453 | { |
453 | { |
454 | unsigned char *str = rxvt_malloc(len + 1); |
454 | unsigned char *str = rxvt_malloc (len + 1); |
455 | |
455 | |
456 | STRCPY(str, action); |
456 | STRCPY (str, action); |
457 | |
457 | |
458 | if (rxvt_action_type(&(item->entry.action), str) < 0) |
458 | if (rxvt_action_type (& (item->entry.action), str) < 0) |
459 | free(str); |
459 | free (str); |
460 | } |
460 | } |
461 | /* new item and a possible increase in width */ |
461 | /* new item and a possible increase in width */ |
462 | if (menu->width < (item->len + item->len2)) |
462 | if (menu->width < (item->len + item->len2)) |
463 | menu->width = (item->len + item->len2); |
463 | menu->width = (item->len + item->len2); |
464 | |
464 | |
… | |
… | |
474 | { |
474 | { |
475 | menu_t *m = NULL; |
475 | menu_t *m = NULL; |
476 | menuitem_t *item; |
476 | menuitem_t *item; |
477 | |
477 | |
478 | #ifdef DEBUG_STRICT |
478 | #ifdef DEBUG_STRICT |
479 | assert(menu != NULL); |
479 | assert (menu != NULL); |
480 | assert(CurrentBar != NULL); |
480 | assert (CurrentBar != NULL); |
481 | #endif |
481 | #endif |
482 | |
482 | |
483 | if (path[0] == '\0') |
483 | if (path[0] == '\0') |
484 | return path; |
484 | return path; |
485 | |
485 | |
486 | if (STRCHR(path, '/') != NULL) |
486 | if (STRCHR (path, '/') != NULL) |
487 | { |
487 | { |
488 | char *p = path; |
488 | char *p = path; |
489 | |
489 | |
490 | while ((p = STRCHR(p, '/')) != NULL) |
490 | while ((p = STRCHR (p, '/')) != NULL) |
491 | { |
491 | { |
492 | p++; |
492 | p++; |
493 | if (*p == '/') |
493 | if (*p == '/') |
494 | path = p; |
494 | path = p; |
495 | } |
495 | } |
496 | if (path[0] == '/') |
496 | if (path[0] == '/') |
497 | { |
497 | { |
498 | path++; |
498 | path++; |
499 | *menu = NULL; |
499 | *menu = NULL; |
500 | } |
500 | } |
501 | while ((p = STRCHR(path, '/')) != NULL) |
501 | while ((p = STRCHR (path, '/')) != NULL) |
502 | { |
502 | { |
503 | p[0] = '\0'; |
503 | p[0] = '\0'; |
504 | if (path[0] == '\0') |
504 | if (path[0] == '\0') |
505 | return NULL; |
505 | return NULL; |
506 | if (!STRCMP(path, DOT)) |
506 | if (!STRCMP (path, DOT)) |
507 | { |
507 | { |
508 | /* nothing to do */ |
508 | /* nothing to do */ |
509 | } |
509 | } |
510 | else if (!STRCMP(path, DOTS)) |
510 | else if (!STRCMP (path, DOTS)) |
511 | { |
511 | { |
512 | if (*menu != NULL) |
512 | if (*menu != NULL) |
513 | *menu = (*menu)->parent; |
513 | *menu = (*menu)->parent; |
514 | } |
514 | } |
515 | else |
515 | else |
… | |
… | |
523 | } |
523 | } |
524 | |
524 | |
525 | path = (p + 1); |
525 | path = (p + 1); |
526 | } |
526 | } |
527 | } |
527 | } |
528 | if (!STRCMP(path, DOTS)) |
528 | if (!STRCMP (path, DOTS)) |
529 | { |
529 | { |
530 | path += STRLEN(DOTS); |
530 | path += STRLEN (DOTS); |
531 | if (*menu != NULL) |
531 | if (*menu != NULL) |
532 | *menu = (*menu)->parent; |
532 | *menu = (*menu)->parent; |
533 | return path; |
533 | return path; |
534 | } |
534 | } |
535 | /* find this menu */ |
535 | /* find this menu */ |
536 | if (*menu == NULL) |
536 | if (*menu == NULL) |
537 | { |
537 | { |
538 | for (m = CurrentBar->tail; m != NULL; m = m->prev) |
538 | for (m = CurrentBar->tail; m != NULL; m = m->prev) |
539 | { |
539 | { |
540 | if (!STRCMP(path, m->name)) |
540 | if (!STRCMP (path, m->name)) |
541 | break; |
541 | break; |
542 | } |
542 | } |
543 | } |
543 | } |
544 | else |
544 | else |
545 | { |
545 | { |
546 | /* find this menu */ |
546 | /* find this menu */ |
547 | for (item = (*menu)->tail; item != NULL; item = item->prev) |
547 | for (item = (*menu)->tail; item != NULL; item = item->prev) |
548 | { |
548 | { |
549 | if (item->entry.type == MenuSubMenu |
549 | if (item->entry.type == MenuSubMenu |
550 | && !STRCMP(path, (item->entry.submenu.menu)->name)) |
550 | && !STRCMP (path, (item->entry.submenu.menu)->name)) |
551 | { |
551 | { |
552 | m = (item->entry.submenu.menu); |
552 | m = (item->entry.submenu.menu); |
553 | break; |
553 | break; |
554 | } |
554 | } |
555 | } |
555 | } |
556 | } |
556 | } |
557 | if (m != NULL) |
557 | if (m != NULL) |
558 | { |
558 | { |
559 | *menu = m; |
559 | *menu = m; |
560 | path += STRLEN(path); |
560 | path += STRLEN (path); |
561 | } |
561 | } |
562 | return path; |
562 | return path; |
563 | } |
563 | } |
564 | |
564 | |
565 | /* |
565 | /* |
… | |
… | |
571 | menu_t *parent = NULL, *prev, *next; |
571 | menu_t *parent = NULL, *prev, *next; |
572 | menuitem_t *item; |
572 | menuitem_t *item; |
573 | bar_t *CurrentBar = CurrentBar; |
573 | bar_t *CurrentBar = CurrentBar; |
574 | |
574 | |
575 | #ifdef DEBUG_STRICT |
575 | #ifdef DEBUG_STRICT |
576 | assert(CurrentBar != NULL); |
576 | assert (CurrentBar != NULL); |
577 | #endif |
577 | #endif |
578 | |
578 | |
579 | /* delete the entire menu */ |
579 | /* delete the entire menu */ |
580 | if (menu == NULL) |
580 | if (menu == NULL) |
581 | return NULL; |
581 | return NULL; |
… | |
… | |
625 | menuitem_free (menu, item); |
625 | menuitem_free (menu, item); |
626 | item = p; |
626 | item = p; |
627 | } |
627 | } |
628 | |
628 | |
629 | if (menu->name != NULL) |
629 | if (menu->name != NULL) |
630 | free(menu->name); |
630 | free (menu->name); |
631 | free(menu); |
631 | free (menu); |
632 | |
632 | |
633 | return parent; |
633 | return parent; |
634 | } |
634 | } |
635 | |
635 | |
636 | menu_t * |
636 | menu_t * |
… | |
… | |
638 | { |
638 | { |
639 | menu_t *menu; |
639 | menu_t *menu; |
640 | bar_t *CurrentBar = CurrentBar; |
640 | bar_t *CurrentBar = CurrentBar; |
641 | |
641 | |
642 | #ifdef DEBUG_STRICT |
642 | #ifdef DEBUG_STRICT |
643 | assert(CurrentBar != NULL); |
643 | assert (CurrentBar != NULL); |
644 | #endif |
644 | #endif |
645 | |
645 | |
646 | if (STRCHR(path, '/') != NULL) |
646 | if (STRCHR (path, '/') != NULL) |
647 | { |
647 | { |
648 | char *p; |
648 | char *p; |
649 | |
649 | |
650 | if (path[0] == '/') |
650 | if (path[0] == '/') |
651 | { |
651 | { |
652 | /* shouldn't happen */ |
652 | /* shouldn't happen */ |
653 | path++; |
653 | path++; |
654 | parent = NULL; |
654 | parent = NULL; |
655 | } |
655 | } |
656 | while ((p = STRCHR(path, '/')) != NULL) |
656 | while ((p = STRCHR (path, '/')) != NULL) |
657 | { |
657 | { |
658 | p[0] = '\0'; |
658 | p[0] = '\0'; |
659 | if (path[0] == '\0') |
659 | if (path[0] == '\0') |
660 | return NULL; |
660 | return NULL; |
661 | |
661 | |
662 | parent = menu_add (parent, path); |
662 | parent = menu_add (parent, path); |
663 | path = (p + 1); |
663 | path = (p + 1); |
664 | } |
664 | } |
665 | } |
665 | } |
666 | if (!STRCMP(path, DOTS)) |
666 | if (!STRCMP (path, DOTS)) |
667 | return (parent != NULL ? parent->parent : parent); |
667 | return (parent != NULL ? parent->parent : parent); |
668 | |
668 | |
669 | if (!STRCMP(path, DOT) || path[0] == '\0') |
669 | if (!STRCMP (path, DOT) || path[0] == '\0') |
670 | return parent; |
670 | return parent; |
671 | |
671 | |
672 | /* allocate a new menu */ |
672 | /* allocate a new menu */ |
673 | menu = (menu_t *) rxvt_malloc(sizeof(menu_t)); |
673 | menu = (menu_t *) rxvt_malloc (sizeof (menu_t)); |
674 | |
674 | |
675 | menu->width = 0; |
675 | menu->width = 0; |
676 | menu->parent = parent; |
676 | menu->parent = parent; |
677 | menu->len = STRLEN(path); |
677 | menu->len = STRLEN (path); |
678 | menu->name = rxvt_malloc((menu->len + 1)); |
678 | menu->name = rxvt_malloc ((menu->len + 1)); |
679 | STRCPY(menu->name, path); |
679 | STRCPY (menu->name, path); |
680 | |
680 | |
681 | /* initialize head/tail */ |
681 | /* initialize head/tail */ |
682 | menu->head = menu->tail = NULL; |
682 | menu->head = menu->tail = NULL; |
683 | menu->prev = menu->next = NULL; |
683 | menu->prev = menu->next = NULL; |
684 | |
684 | |
… | |
… | |
700 | } |
700 | } |
701 | else |
701 | else |
702 | { |
702 | { |
703 | menuitem_t *item; |
703 | menuitem_t *item; |
704 | |
704 | |
705 | item = rxvt_menuitem_add(parent, path, "", ""); |
705 | item = rxvt_menuitem_add (parent, path, "", ""); |
706 | if (item == NULL) |
706 | if (item == NULL) |
707 | { |
707 | { |
708 | free(menu); |
708 | free (menu); |
709 | return parent; |
709 | return parent; |
710 | } |
710 | } |
711 | #ifdef DEBUG_STRICT |
711 | #ifdef DEBUG_STRICT |
712 | assert(item->entry.type == MenuLabel); |
712 | assert (item->entry.type == MenuLabel); |
713 | #endif |
713 | #endif |
714 | item->entry.type = MenuSubMenu; |
714 | item->entry.type = MenuSubMenu; |
715 | item->entry.submenu.menu = menu; |
715 | item->entry.submenu.menu = menu; |
716 | } |
716 | } |
717 | |
717 | |
… | |
… | |
721 | void |
721 | void |
722 | rxvt_term::drawbox_menubar (int x, int len, int state) |
722 | rxvt_term::drawbox_menubar (int x, int len, int state) |
723 | { |
723 | { |
724 | GC top, bot; |
724 | GC top, bot; |
725 | |
725 | |
726 | x = Width2Pixel(x); |
726 | x = Width2Pixel (x); |
727 | len = Width2Pixel(len + HSPACE); |
727 | len = Width2Pixel (len + HSPACE); |
728 | if (x >= TermWin.width) |
728 | if (x >= TermWin.width) |
729 | return; |
729 | return; |
730 | else if (x + len >= TermWin.width) |
730 | else if (x + len >= TermWin.width) |
731 | len = (TermWin_TotalWidth() - x); |
731 | len = (TermWin_TotalWidth () - x); |
732 | |
732 | |
733 | #ifdef MENUBAR_SHADOW_IN |
733 | #ifdef MENUBAR_SHADOW_IN |
734 | state = -state; |
734 | state = -state; |
735 | #endif |
735 | #endif |
736 | switch (state) |
736 | switch (state) |
… | |
… | |
746 | default: |
746 | default: |
747 | top = bot = scrollbarGC; |
747 | top = bot = scrollbarGC; |
748 | break; /* neutral */ |
748 | break; /* neutral */ |
749 | } |
749 | } |
750 | |
750 | |
751 | rxvt_Draw_Shadow(display->display, menuBar.win, top, bot, |
751 | rxvt_Draw_Shadow (display->display, menuBar.win, top, bot, |
752 | x, 0, len, menuBar_TotalHeight()); |
752 | x, 0, len, menuBar_TotalHeight ()); |
753 | } |
753 | } |
754 | |
754 | |
755 | void |
755 | void |
756 | rxvt_term::drawtriangle (int x, int y, int state) |
756 | rxvt_term::drawtriangle (int x, int y, int state) |
757 | { |
757 | { |
… | |
… | |
774 | default: |
774 | default: |
775 | top = bot = scrollbarGC; |
775 | top = bot = scrollbarGC; |
776 | break; /* neutral */ |
776 | break; /* neutral */ |
777 | } |
777 | } |
778 | |
778 | |
779 | w = Height2Pixel(1) - 2 * SHADOW; |
779 | w = Height2Pixel (1) - 2 * SHADOW; |
780 | |
780 | |
781 | x -= SHADOW + (3 * w / 2); |
781 | x -= SHADOW + (3 * w / 2); |
782 | y += SHADOW * 3; |
782 | y += SHADOW * 3; |
783 | |
783 | |
784 | rxvt_Draw_Triangle(display->display, ActiveMenu->win, top, bot, x, y, w, |
784 | rxvt_Draw_Triangle (display->display, ActiveMenu->win, top, bot, x, y, w, |
785 | 'r'); |
785 | 'r'); |
786 | } |
786 | } |
787 | |
787 | |
788 | void |
788 | void |
789 | rxvt_term::drawbox_menuitem (int y, int state) |
789 | rxvt_term::drawbox_menuitem (int y, int state) |
… | |
… | |
806 | default: |
806 | default: |
807 | top = bot = scrollbarGC; |
807 | top = bot = scrollbarGC; |
808 | break; /* neutral */ |
808 | break; /* neutral */ |
809 | } |
809 | } |
810 | |
810 | |
811 | rxvt_Draw_Shadow(display->display, ActiveMenu->win, top, bot, |
811 | rxvt_Draw_Shadow (display->display, ActiveMenu->win, top, bot, |
812 | SHADOW + 0, SHADOW + y, |
812 | SHADOW + 0, SHADOW + y, |
813 | ActiveMenu->w - 2 * (SHADOW), |
813 | ActiveMenu->w - 2 * (SHADOW), |
814 | HEIGHT_TEXT + 2 * SHADOW); |
814 | HEIGHT_TEXT + 2 * SHADOW); |
815 | XFlush(display->display); |
815 | XFlush (display->display); |
816 | } |
816 | } |
817 | |
817 | |
818 | #ifdef DEBUG_MENU_LAYOUT |
818 | #ifdef DEBUG_MENU_LAYOUT |
819 | void |
819 | void |
820 | rxvt_print_menu_ancestors(menu_t *menu) |
820 | rxvt_print_menu_ancestors (menu_t *menu) |
821 | { |
821 | { |
822 | if (menu == NULL) |
822 | if (menu == NULL) |
823 | { |
823 | { |
824 | fprintf(stderr, "Top Level menu\n"); |
824 | fprintf (stderr, "Top Level menu\n"); |
825 | return; |
825 | return; |
826 | } |
826 | } |
827 | fprintf(stderr, "menu %s ", menu->name); |
827 | fprintf (stderr, "menu %s ", menu->name); |
828 | if (menu->parent != NULL) |
828 | if (menu->parent != NULL) |
829 | { |
829 | { |
830 | menuitem_t *item; |
830 | menuitem_t *item; |
831 | |
831 | |
832 | for (item = menu->parent->head; item != NULL; item = item->next) |
832 | for (item = menu->parent->head; item != NULL; item = item->next) |
… | |
… | |
837 | break; |
837 | break; |
838 | } |
838 | } |
839 | } |
839 | } |
840 | if (item == NULL) |
840 | if (item == NULL) |
841 | { |
841 | { |
842 | fprintf(stderr, "is an orphan!\n"); |
842 | fprintf (stderr, "is an orphan!\n"); |
843 | return; |
843 | return; |
844 | } |
844 | } |
845 | } |
845 | } |
846 | fprintf(stderr, "\n"); |
846 | fprintf (stderr, "\n"); |
847 | rxvt_print_menu_ancestors(menu->parent); |
847 | rxvt_print_menu_ancestors (menu->parent); |
848 | } |
848 | } |
849 | |
849 | |
850 | void |
850 | void |
851 | rxvt_print_menu_descendants(menu_t *menu) |
851 | rxvt_print_menu_descendants (menu_t *menu) |
852 | { |
852 | { |
853 | menuitem_t *item; |
853 | menuitem_t *item; |
854 | menu_t *parent; |
854 | menu_t *parent; |
855 | int i, level = 0; |
855 | int i, level = 0; |
856 | |
856 | |
… | |
… | |
861 | parent = parent->parent; |
861 | parent = parent->parent; |
862 | } |
862 | } |
863 | while (parent != NULL); |
863 | while (parent != NULL); |
864 | |
864 | |
865 | for (i = 0; i < level; i++) |
865 | for (i = 0; i < level; i++) |
866 | fprintf(stderr, ">"); |
866 | fprintf (stderr, ">"); |
867 | fprintf(stderr, "%s\n", menu->name); |
867 | fprintf (stderr, "%s\n", menu->name); |
868 | |
868 | |
869 | for (item = menu->head; item != NULL; item = item->next) |
869 | for (item = menu->head; item != NULL; item = item->next) |
870 | { |
870 | { |
871 | if (item->entry.type == MenuSubMenu) |
871 | if (item->entry.type == MenuSubMenu) |
872 | { |
872 | { |
873 | if (item->entry.submenu.menu == NULL) |
873 | if (item->entry.submenu.menu == NULL) |
874 | fprintf(stderr, "> %s == NULL\n", item->name); |
874 | fprintf (stderr, "> %s == NULL\n", item->name); |
875 | else |
875 | else |
876 | rxvt_print_menu_descendants(item->entry.submenu.menu); |
876 | rxvt_print_menu_descendants (item->entry.submenu.menu); |
877 | } |
877 | } |
878 | else |
878 | else |
879 | { |
879 | { |
880 | for (i = 0; i < level; i++) |
880 | for (i = 0; i < level; i++) |
881 | fprintf(stderr, "+"); |
881 | fprintf (stderr, "+"); |
882 | if (item->entry.type == MenuLabel) |
882 | if (item->entry.type == MenuLabel) |
883 | fprintf(stderr, "label: "); |
883 | fprintf (stderr, "label: "); |
884 | fprintf(stderr, "%s\n", item->name); |
884 | fprintf (stderr, "%s\n", item->name); |
885 | } |
885 | } |
886 | } |
886 | } |
887 | |
887 | |
888 | for (i = 0; i < level; i++) |
888 | for (i = 0; i < level; i++) |
889 | fprintf(stderr, "<"); |
889 | fprintf (stderr, "<"); |
890 | fprintf(stderr, "\n"); |
890 | fprintf (stderr, "\n"); |
891 | } |
891 | } |
892 | #endif |
892 | #endif |
893 | |
893 | |
894 | /* pop up/down the current menu and redraw the menuBar button */ |
894 | /* pop up/down the current menu and redraw the menuBar button */ |
895 | void |
895 | void |
… | |
… | |
906 | if (ActiveMenu->parent == NULL) |
906 | if (ActiveMenu->parent == NULL) |
907 | { |
907 | { |
908 | register int h; |
908 | register int h; |
909 | |
909 | |
910 | drawbox_menubar (x, ActiveMenu->len, -1); |
910 | drawbox_menubar (x, ActiveMenu->len, -1); |
911 | x = Width2Pixel(x); |
911 | x = Width2Pixel (x); |
912 | |
912 | |
913 | ActiveMenu->y = 1; |
913 | ActiveMenu->y = 1; |
914 | ActiveMenu->w = Menu_PixelWidth(ActiveMenu); |
914 | ActiveMenu->w = Menu_PixelWidth (ActiveMenu); |
915 | |
915 | |
916 | if ((x + ActiveMenu->w) >= TermWin.width) |
916 | if ((x + ActiveMenu->w) >= TermWin.width) |
917 | x = (TermWin_TotalWidth() - ActiveMenu->w); |
917 | x = (TermWin_TotalWidth () - ActiveMenu->w); |
918 | |
918 | |
919 | /* find the height */ |
919 | /* find the height */ |
920 | for (h = 0, item = ActiveMenu->head; item != NULL; item = item->next) |
920 | for (h = 0, item = ActiveMenu->head; item != NULL; item = item->next) |
921 | h += isSeparator(item->name) ? HEIGHT_SEPARATOR |
921 | h += isSeparator (item->name) ? HEIGHT_SEPARATOR |
922 | : HEIGHT_TEXT + 2 * SHADOW; |
922 | : HEIGHT_TEXT + 2 * SHADOW; |
923 | ActiveMenu->h = h + 2 * SHADOW; |
923 | ActiveMenu->h = h + 2 * SHADOW; |
924 | } |
924 | } |
925 | if (ActiveMenu->win == None) |
925 | if (ActiveMenu->win == None) |
926 | { |
926 | { |
927 | ActiveMenu->win = XCreateSimpleWindow(display->display, TermWin.vt, |
927 | ActiveMenu->win = XCreateSimpleWindow (display->display, TermWin.vt, |
928 | x, ActiveMenu->y, |
928 | x, ActiveMenu->y, |
929 | ActiveMenu->w, ActiveMenu->h, |
929 | ActiveMenu->w, ActiveMenu->h, |
930 | 0, |
930 | 0, |
931 | PixColors[Color_fg], |
931 | PixColors[Color_fg], |
932 | PixColors[Color_scroll]); |
932 | PixColors[Color_scroll]); |
933 | XMapWindow(display->display, ActiveMenu->win); |
933 | XMapWindow (display->display, ActiveMenu->win); |
934 | } |
934 | } |
935 | rxvt_Draw_Shadow(display->display, ActiveMenu->win, |
935 | rxvt_Draw_Shadow (display->display, ActiveMenu->win, |
936 | topShadowGC, botShadowGC, |
936 | topShadowGC, botShadowGC, |
937 | 0, 0, ActiveMenu->w, ActiveMenu->h); |
937 | 0, 0, ActiveMenu->w, ActiveMenu->h); |
938 | |
938 | |
939 | /* determine the correct right-alignment */ |
939 | /* determine the correct right-alignment */ |
940 | for (xright = 0, item = ActiveMenu->head; item != NULL; item = item->next) |
940 | for (xright = 0, item = ActiveMenu->head; item != NULL; item = item->next) |
941 | if (item->len2 > xright) |
941 | if (item->len2 > xright) |
942 | xright = item->len2; |
942 | xright = item->len2; |
943 | |
943 | |
944 | for (y = 0, item = ActiveMenu->head; item != NULL; item = item->next) |
944 | for (y = 0, item = ActiveMenu->head; item != NULL; item = item->next) |
945 | { |
945 | { |
946 | const int xoff = (SHADOW + Width2Pixel(HSPACE) / 2); |
946 | const int xoff = (SHADOW + Width2Pixel (HSPACE) / 2); |
947 | register int h; |
947 | register int h; |
948 | GC gc = menubarGC; |
948 | GC gc = menubarGC; |
949 | |
949 | |
950 | if (isSeparator(item->name)) |
950 | if (isSeparator (item->name)) |
951 | { |
951 | { |
952 | rxvt_Draw_Shadow(display->display, ActiveMenu->win, |
952 | rxvt_Draw_Shadow (display->display, ActiveMenu->win, |
953 | topShadowGC, botShadowGC, |
953 | topShadowGC, botShadowGC, |
954 | SHADOW, y + SHADOW + 1, |
954 | SHADOW, y + SHADOW + 1, |
955 | ActiveMenu->w - 2 * SHADOW, 0); |
955 | ActiveMenu->w - 2 * SHADOW, 0); |
956 | h = HEIGHT_SEPARATOR; |
956 | h = HEIGHT_SEPARATOR; |
957 | } |
957 | } |
… | |
… | |
975 | name = menu->name; |
975 | name = menu->name; |
976 | len = menu->len; |
976 | len = menu->len; |
977 | |
977 | |
978 | y1 = ActiveMenu->y + y; |
978 | y1 = ActiveMenu->y + y; |
979 | |
979 | |
980 | menu->w = Menu_PixelWidth(menu); |
980 | menu->w = Menu_PixelWidth (menu); |
981 | |
981 | |
982 | /* place sub-menu at midpoint of parent menu */ |
982 | /* place sub-menu at midpoint of parent menu */ |
983 | x1 = ActiveMenu->w / 2; |
983 | x1 = ActiveMenu->w / 2; |
984 | if (x1 > menu->w) /* right-flush menu if too small */ |
984 | if (x1 > menu->w) /* right-flush menu if too small */ |
985 | x1 += (x1 - menu->w); |
985 | x1 += (x1 - menu->w); |
986 | x1 += x; |
986 | x1 += x; |
987 | |
987 | |
988 | /* find the height of this submenu */ |
988 | /* find the height of this submenu */ |
989 | for (h = 0, it = menu->head; it != NULL; it = it->next) |
989 | for (h = 0, it = menu->head; it != NULL; it = it->next) |
990 | h += isSeparator(it->name) ? HEIGHT_SEPARATOR |
990 | h += isSeparator (it->name) ? HEIGHT_SEPARATOR |
991 | : HEIGHT_TEXT + 2 * SHADOW; |
991 | : HEIGHT_TEXT + 2 * SHADOW; |
992 | menu->h = h + 2 * SHADOW; |
992 | menu->h = h + 2 * SHADOW; |
993 | |
993 | |
994 | /* ensure menu is in window limits */ |
994 | /* ensure menu is in window limits */ |
995 | if ((x1 + menu->w) >= TermWin.width) |
995 | if ((x1 + menu->w) >= TermWin.width) |
996 | x1 = (TermWin_TotalWidth() - menu->w); |
996 | x1 = (TermWin_TotalWidth () - menu->w); |
997 | |
997 | |
998 | if ((y1 + menu->h) >= TermWin.height) |
998 | if ((y1 + menu->h) >= TermWin.height) |
999 | y1 = (TermWin_TotalHeight() - menu->h); |
999 | y1 = (TermWin_TotalHeight () - menu->h); |
1000 | |
1000 | |
1001 | menu->x = (x1 < 0 ? 0 : x1); |
1001 | menu->x = (x1 < 0 ? 0 : x1); |
1002 | menu->y = (y1 < 0 ? 0 : y1); |
1002 | menu->y = (y1 < 0 ? 0 : y1); |
1003 | } |
1003 | } |
1004 | else if (item->name2 && !STRCMP(name, item->name2)) |
1004 | else if (item->name2 && !STRCMP (name, item->name2)) |
1005 | name = NULL; |
1005 | name = NULL; |
1006 | |
1006 | |
1007 | if (len && name) |
1007 | if (len && name) |
1008 | { |
1008 | { |
1009 | #ifdef USE_XIM |
1009 | #ifdef USE_XIM |
1010 | if (TermWin.fontset) |
1010 | if (TermWin.fontset) |
1011 | XmbDrawString(display->display, |
1011 | XmbDrawString (display->display, |
1012 | ActiveMenu->win, TermWin.fontset, |
1012 | ActiveMenu->win, TermWin.fontset, |
1013 | gc, xoff, |
1013 | gc, xoff, |
1014 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
1014 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
1015 | name, len); |
1015 | name, len); |
1016 | else |
1016 | else |
1017 | #endif |
1017 | #endif |
1018 | XDrawString(display->display, ActiveMenu->win, gc, xoff, |
1018 | XDrawString (display->display, ActiveMenu->win, gc, xoff, |
1019 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
1019 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
1020 | name, len); |
1020 | name, len); |
1021 | } |
1021 | } |
1022 | |
1022 | |
1023 | len = item->len2; |
1023 | len = item->len2; |
1024 | name = item->name2; |
1024 | name = item->name2; |
1025 | if (len && name) |
1025 | if (len && name) |
1026 | { |
1026 | { |
1027 | #ifdef USE_XIM |
1027 | #ifdef USE_XIM |
1028 | if (TermWin.fontset) |
1028 | if (TermWin.fontset) |
1029 | XmbDrawString(display->display, |
1029 | XmbDrawString (display->display, |
1030 | ActiveMenu->win, TermWin.fontset, |
1030 | ActiveMenu->win, TermWin.fontset, |
1031 | gc, |
1031 | gc, |
1032 | ActiveMenu->w - (xoff + Width2Pixel(xright)), |
1032 | ActiveMenu->w - (xoff + Width2Pixel (xright)), |
1033 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
1033 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
1034 | name, len); |
1034 | name, len); |
1035 | else |
1035 | else |
1036 | #endif |
1036 | #endif |
1037 | XDrawString(display->display, ActiveMenu->win, gc, |
1037 | XDrawString (display->display, ActiveMenu->win, gc, |
1038 | ActiveMenu->w - (xoff + Width2Pixel(xright)), |
1038 | ActiveMenu->w - (xoff + Width2Pixel (xright)), |
1039 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
1039 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
1040 | name, len); |
1040 | name, len); |
1041 | } |
1041 | } |
1042 | h = HEIGHT_TEXT + 2 * SHADOW; |
1042 | h = HEIGHT_TEXT + 2 * SHADOW; |
1043 | } |
1043 | } |
1044 | y += h; |
1044 | y += h; |
1045 | } |
1045 | } |
1046 | } |
1046 | } |
1047 | |
1047 | |
1048 | void |
1048 | void |
1049 | rxvt_term::menu_display (void (*update)(rxvt_t *)) |
1049 | rxvt_term::menu_display (void (*update) (rxvt_t *)) |
1050 | { |
1050 | { |
1051 | menu_t *ActiveMenu = ActiveMenu; |
1051 | menu_t *ActiveMenu = ActiveMenu; |
1052 | |
1052 | |
1053 | if (ActiveMenu == NULL) |
1053 | if (ActiveMenu == NULL) |
1054 | return; |
1054 | return; |
1055 | if (ActiveMenu->win != None) |
1055 | if (ActiveMenu->win != None) |
1056 | XDestroyWindow(display->display, ActiveMenu->win); |
1056 | XDestroyWindow (display->display, ActiveMenu->win); |
1057 | ActiveMenu->win = None; |
1057 | ActiveMenu->win = None; |
1058 | ActiveMenu->item = NULL; |
1058 | ActiveMenu->item = NULL; |
1059 | |
1059 | |
1060 | if (ActiveMenu->parent == NULL) |
1060 | if (ActiveMenu->parent == NULL) |
1061 | drawbox_menubar (ActiveMenu->x, ActiveMenu->len, +1); |
1061 | drawbox_menubar (ActiveMenu->x, ActiveMenu->len, +1); |
1062 | ActiveMenu = ActiveMenu->parent; |
1062 | ActiveMenu = ActiveMenu->parent; |
1063 | update(r); |
1063 | update (r); |
1064 | } |
1064 | } |
1065 | |
1065 | |
1066 | void |
1066 | void |
1067 | rxvt_term::menu_hide_all () |
1067 | rxvt_term::menu_hide_all () |
1068 | { |
1068 | { |
… | |
… | |
1112 | } |
1112 | } |
1113 | CurrentBar->head = CurrentBar->tail = NULL; |
1113 | CurrentBar->head = CurrentBar->tail = NULL; |
1114 | |
1114 | |
1115 | if (CurrentBar->title) |
1115 | if (CurrentBar->title) |
1116 | { |
1116 | { |
1117 | free(CurrentBar->title); |
1117 | free (CurrentBar->title); |
1118 | CurrentBar->title = NULL; |
1118 | CurrentBar->title = NULL; |
1119 | } |
1119 | } |
1120 | menuarrow_free (0); /* remove all arrow functions */ |
1120 | menuarrow_free (0); /* remove all arrow functions */ |
1121 | } |
1121 | } |
1122 | ActiveMenu = NULL; |
1122 | ActiveMenu = NULL; |
… | |
… | |
1128 | rxvt_term::menubar_find (const char *name) |
1128 | rxvt_term::menubar_find (const char *name) |
1129 | { |
1129 | { |
1130 | bar_t *bar = CurrentBar; |
1130 | bar_t *bar = CurrentBar; |
1131 | |
1131 | |
1132 | #ifdef DEBUG_MENUBAR_STACKING |
1132 | #ifdef DEBUG_MENUBAR_STACKING |
1133 | fprintf(stderr, "looking for [menu:%s] ...", name ? name : "(nil)"); |
1133 | fprintf (stderr, "looking for [menu:%s] ...", name ? name : " (nil)"); |
1134 | #endif |
1134 | #endif |
1135 | if (bar == NULL || name == NULL) |
1135 | if (bar == NULL || name == NULL) |
1136 | return NULL; |
1136 | return NULL; |
1137 | |
1137 | |
1138 | if (STRLEN(name) && STRCMP(name, "*")) |
1138 | if (STRLEN (name) && STRCMP (name, "*")) |
1139 | { |
1139 | { |
1140 | do |
1140 | do |
1141 | { |
1141 | { |
1142 | if (!STRCMP(bar->name, name)) |
1142 | if (!STRCMP (bar->name, name)) |
1143 | { |
1143 | { |
1144 | #ifdef DEBUG_MENUBAR_STACKING |
1144 | #ifdef DEBUG_MENUBAR_STACKING |
1145 | fprintf(stderr, " found!\n"); |
1145 | fprintf (stderr, " found!\n"); |
1146 | #endif |
1146 | #endif |
1147 | return bar; |
1147 | return bar; |
1148 | } |
1148 | } |
1149 | bar = bar->next; |
1149 | bar = bar->next; |
1150 | } |
1150 | } |
1151 | while (bar != CurrentBar); |
1151 | while (bar != CurrentBar); |
1152 | bar = NULL; |
1152 | bar = NULL; |
1153 | } |
1153 | } |
1154 | #ifdef DEBUG_MENUBAR_STACKING |
1154 | #ifdef DEBUG_MENUBAR_STACKING |
1155 | fprintf(stderr, "%s found!\n", (bar ? "" : " NOT")); |
1155 | fprintf (stderr, "%s found!\n", (bar ? "" : " NOT")); |
1156 | #endif |
1156 | #endif |
1157 | |
1157 | |
1158 | return bar; |
1158 | return bar; |
1159 | } |
1159 | } |
1160 | |
1160 | |
… | |
… | |
1165 | bar_t *bar; |
1165 | bar_t *bar; |
1166 | |
1166 | |
1167 | if (CurrentBar == NULL) |
1167 | if (CurrentBar == NULL) |
1168 | { |
1168 | { |
1169 | /* allocate first one */ |
1169 | /* allocate first one */ |
1170 | bar = (bar_t *) rxvt_malloc(sizeof(bar_t)); |
1170 | bar = (bar_t *) rxvt_malloc (sizeof (bar_t)); |
1171 | |
1171 | |
1172 | MEMSET(bar, 0, sizeof(bar_t)); |
1172 | MEMSET (bar, 0, sizeof (bar_t)); |
1173 | /* circular linked-list */ |
1173 | /* circular linked-list */ |
1174 | bar->next = bar->prev = bar; |
1174 | bar->next = bar->prev = bar; |
1175 | bar->head = bar->tail = NULL; |
1175 | bar->head = bar->tail = NULL; |
1176 | bar->title = NULL; |
1176 | bar->title = NULL; |
1177 | CurrentBar = bar; |
1177 | CurrentBar = bar; |
… | |
… | |
1193 | /* create if needed, or reuse the existing empty menubar */ |
1193 | /* create if needed, or reuse the existing empty menubar */ |
1194 | if (CurrentBar->head != NULL) |
1194 | if (CurrentBar->head != NULL) |
1195 | { |
1195 | { |
1196 | /* need to malloc another one */ |
1196 | /* need to malloc another one */ |
1197 | if (Nbars < MENUBAR_MAX) |
1197 | if (Nbars < MENUBAR_MAX) |
1198 | bar = (bar_t *) rxvt_malloc(sizeof(bar_t)); |
1198 | bar = (bar_t *) rxvt_malloc (sizeof (bar_t)); |
1199 | else |
1199 | else |
1200 | bar = NULL; |
1200 | bar = NULL; |
1201 | |
1201 | |
1202 | /* malloc failed or too many menubars, reuse another */ |
1202 | /* malloc failed or too many menubars, reuse another */ |
1203 | if (bar == NULL) |
1203 | if (bar == NULL) |
… | |
… | |
1223 | menubar_clear (); |
1223 | menubar_clear (); |
1224 | } |
1224 | } |
1225 | } |
1225 | } |
1226 | |
1226 | |
1227 | /* give menubar this name */ |
1227 | /* give menubar this name */ |
1228 | STRNCPY(CurrentBar->name, name, MAXNAME); |
1228 | STRNCPY (CurrentBar->name, name, MAXNAME); |
1229 | CurrentBar->name[MAXNAME - 1] = '\0'; |
1229 | CurrentBar->name[MAXNAME - 1] = '\0'; |
1230 | |
1230 | |
1231 | return ret; |
1231 | return ret; |
1232 | } |
1232 | } |
1233 | |
1233 | |
… | |
… | |
1262 | next->prev = prev; |
1262 | next->prev = prev; |
1263 | prev->next = next; |
1263 | prev->next = next; |
1264 | Nbars--; |
1264 | Nbars--; |
1265 | } |
1265 | } |
1266 | |
1266 | |
1267 | free(CurrentBar); |
1267 | free (CurrentBar); |
1268 | CurrentBar = prev; |
1268 | CurrentBar = prev; |
1269 | } |
1269 | } |
1270 | } |
1270 | } |
1271 | while (CurrentBar && !STRCMP(name, "*")); |
1271 | while (CurrentBar && !STRCMP (name, "*")); |
1272 | } |
1272 | } |
1273 | |
1273 | |
1274 | void |
1274 | void |
1275 | rxvt_action_decode(FILE *fp, action_t *act) |
1275 | rxvt_action_decode (FILE *fp, action_t *act) |
1276 | { |
1276 | { |
1277 | unsigned char *str; |
1277 | unsigned char *str; |
1278 | short len; |
1278 | short len; |
1279 | |
1279 | |
1280 | if (act == NULL || (len = act->len) == 0 || (str = act->str) == NULL) |
1280 | if (act == NULL || (len = act->len) == 0 || (str = act->str) == NULL) |
1281 | return; |
1281 | return; |
1282 | |
1282 | |
1283 | if (act->type == MenuTerminalAction) |
1283 | if (act->type == MenuTerminalAction) |
1284 | { |
1284 | { |
1285 | fprintf(fp, "^@"); |
1285 | fprintf (fp, "^@"); |
1286 | /* can strip trailing ^G from XTerm sequence */ |
1286 | /* can strip trailing ^G from XTerm sequence */ |
1287 | if (str[0] == C0_ESC && str[1] == ']' && str[len - 1] == C0_BEL) |
1287 | if (str[0] == C0_ESC && str[1] == ']' && str[len - 1] == C0_BEL) |
1288 | len--; |
1288 | len--; |
1289 | } |
1289 | } |
1290 | else if (str[0] == C0_ESC) |
1290 | else if (str[0] == C0_ESC) |
… | |
… | |
1300 | if (str[len - 1] == '\r') |
1300 | if (str[len - 1] == '\r') |
1301 | len--; |
1301 | len--; |
1302 | /* FALLTHROUGH */ |
1302 | /* FALLTHROUGH */ |
1303 | |
1303 | |
1304 | default: |
1304 | default: |
1305 | fprintf(fp, "M-"); /* meta prefix */ |
1305 | fprintf (fp, "M-"); /* meta prefix */ |
1306 | str++; |
1306 | str++; |
1307 | len--; |
1307 | len--; |
1308 | break; |
1308 | break; |
1309 | } |
1309 | } |
1310 | } |
1310 | } |
… | |
… | |
1319 | unsigned char ch = *str++; |
1319 | unsigned char ch = *str++; |
1320 | |
1320 | |
1321 | switch (ch) |
1321 | switch (ch) |
1322 | { |
1322 | { |
1323 | case C0_ESC: |
1323 | case C0_ESC: |
1324 | fprintf(fp, "\\E"); |
1324 | fprintf (fp, "\\E"); |
1325 | break; /* escape */ |
1325 | break; /* escape */ |
1326 | case '\r': |
1326 | case '\r': |
1327 | fprintf(fp, "\\r"); |
1327 | fprintf (fp, "\\r"); |
1328 | break; /* carriage-return */ |
1328 | break; /* carriage-return */ |
1329 | case '\\': |
1329 | case '\\': |
1330 | fprintf(fp, "\\\\"); |
1330 | fprintf (fp, "\\\\"); |
1331 | break; /* backslash */ |
1331 | break; /* backslash */ |
1332 | case '^': |
1332 | case '^': |
1333 | fprintf(fp, "\\^"); |
1333 | fprintf (fp, "\\^"); |
1334 | break; /* caret */ |
1334 | break; /* caret */ |
1335 | case 127: |
1335 | case 127: |
1336 | fprintf(fp, "^?"); |
1336 | fprintf (fp, "^?"); |
1337 | default: |
1337 | default: |
1338 | if (ch <= 31) |
1338 | if (ch <= 31) |
1339 | fprintf(fp, "^%c", ('@' + ch)); |
1339 | fprintf (fp, "^%c", ('@' + ch)); |
1340 | else if (ch > 127) |
1340 | else if (ch > 127) |
1341 | fprintf(fp, "\\%o", ch); |
1341 | fprintf (fp, "\\%o", ch); |
1342 | else |
1342 | else |
1343 | fprintf(fp, "%c", ch); |
1343 | fprintf (fp, "%c", ch); |
1344 | break; |
1344 | break; |
1345 | } |
1345 | } |
1346 | len--; |
1346 | len--; |
1347 | } |
1347 | } |
1348 | fprintf(fp, "\n"); |
1348 | fprintf (fp, "\n"); |
1349 | } |
1349 | } |
1350 | |
1350 | |
1351 | void |
1351 | void |
1352 | rxvt_menu_dump(FILE *fp, menu_t *menu) |
1352 | rxvt_menu_dump (FILE *fp, menu_t *menu) |
1353 | { |
1353 | { |
1354 | menuitem_t *item; |
1354 | menuitem_t *item; |
1355 | |
1355 | |
1356 | /* create a new menu and clear it */ |
1356 | /* create a new menu and clear it */ |
1357 | fprintf(fp, (menu->parent ? "./%s/*\n" : "/%s/*\n"), menu->name); |
1357 | fprintf (fp, (menu->parent ? "./%s/*\n" : "/%s/*\n"), menu->name); |
1358 | |
1358 | |
1359 | for (item = menu->head; item != NULL; item = item->next) |
1359 | for (item = menu->head; item != NULL; item = item->next) |
1360 | { |
1360 | { |
1361 | switch (item->entry.type) |
1361 | switch (item->entry.type) |
1362 | { |
1362 | { |
1363 | case MenuSubMenu: |
1363 | case MenuSubMenu: |
1364 | if (item->entry.submenu.menu == NULL) |
1364 | if (item->entry.submenu.menu == NULL) |
1365 | fprintf(fp, "> %s == NULL\n", item->name); |
1365 | fprintf (fp, "> %s == NULL\n", item->name); |
1366 | else |
1366 | else |
1367 | rxvt_menu_dump(fp, item->entry.submenu.menu); |
1367 | rxvt_menu_dump (fp, item->entry.submenu.menu); |
1368 | break; |
1368 | break; |
1369 | |
1369 | |
1370 | case MenuLabel: |
1370 | case MenuLabel: |
1371 | fprintf(fp, "{%s}\n", (STRLEN(item->name) ? item->name : "-")); |
1371 | fprintf (fp, "{%s}\n", (STRLEN (item->name) ? item->name : "-")); |
1372 | break; |
1372 | break; |
1373 | |
1373 | |
1374 | case MenuTerminalAction: |
1374 | case MenuTerminalAction: |
1375 | case MenuAction: |
1375 | case MenuAction: |
1376 | fprintf(fp, "{%s}", item->name); |
1376 | fprintf (fp, "{%s}", item->name); |
1377 | if (item->name2 != NULL && STRLEN(item->name2)) |
1377 | if (item->name2 != NULL && STRLEN (item->name2)) |
1378 | fprintf(fp, "{%s}", item->name2); |
1378 | fprintf (fp, "{%s}", item->name2); |
1379 | fprintf(fp, "\t"); |
1379 | fprintf (fp, "\t"); |
1380 | rxvt_action_decode(fp, &(item->entry.action)); |
1380 | rxvt_action_decode (fp, & (item->entry.action)); |
1381 | break; |
1381 | break; |
1382 | } |
1382 | } |
1383 | } |
1383 | } |
1384 | |
1384 | |
1385 | fprintf(fp, (menu->parent ? "../\n" : "/\n\n")); |
1385 | fprintf (fp, (menu->parent ? "../\n" : "/\n\n")); |
1386 | } |
1386 | } |
1387 | |
1387 | |
1388 | void |
1388 | void |
1389 | rxvt_term::menubar_dump (FILE *fp) |
1389 | rxvt_term::menubar_dump (FILE *fp) |
1390 | { |
1390 | { |
1391 | bar_t *bar = CurrentBar; |
1391 | bar_t *bar = CurrentBar; |
1392 | time_t t; |
1392 | time_t t; |
1393 | |
1393 | |
1394 | if (bar == NULL || fp == NULL) |
1394 | if (bar == NULL || fp == NULL) |
1395 | return; |
1395 | return; |
1396 | time(&t); |
1396 | time (&t); |
1397 | |
1397 | |
1398 | fprintf(fp, |
1398 | fprintf (fp, |
1399 | "# " APL_SUBCLASS " (%s) Pid: %u\n# Date: %s\n\n", |
1399 | "# " APL_SUBCLASS " (%s) Pid: %u\n# Date: %s\n\n", |
1400 | rs[Rs_name], (unsigned int)getpid(), ctime(&t)); |
1400 | rs[Rs_name], (unsigned int)getpid (), ctime (&t)); |
1401 | |
1401 | |
1402 | /* dump in reverse order */ |
1402 | /* dump in reverse order */ |
1403 | bar = CurrentBar->prev; |
1403 | bar = CurrentBar->prev; |
1404 | do |
1404 | do |
1405 | { |
1405 | { |
1406 | menu_t *menu; |
1406 | menu_t *menu; |
1407 | int i; |
1407 | int i; |
1408 | |
1408 | |
1409 | fprintf(fp, "[menu:%s]\n", bar->name); |
1409 | fprintf (fp, "[menu:%s]\n", bar->name); |
1410 | |
1410 | |
1411 | if (bar->title != NULL) |
1411 | if (bar->title != NULL) |
1412 | fprintf(fp, "[title:%s]\n", bar->title); |
1412 | fprintf (fp, "[title:%s]\n", bar->title); |
1413 | |
1413 | |
1414 | for (i = 0; i < NARROWS; i++) |
1414 | for (i = 0; i < NARROWS; i++) |
1415 | { |
1415 | { |
1416 | switch (bar->arrows[i].type) |
1416 | switch (bar->arrows[i].type) |
1417 | { |
1417 | { |
1418 | case MenuTerminalAction: |
1418 | case MenuTerminalAction: |
1419 | case MenuAction: |
1419 | case MenuAction: |
1420 | fprintf(fp, "<%c>", Arrows[i].name); |
1420 | fprintf (fp, "<%c>", Arrows[i].name); |
1421 | rxvt_action_decode(fp, &(bar->arrows[i])); |
1421 | rxvt_action_decode (fp, & (bar->arrows[i])); |
1422 | break; |
1422 | break; |
1423 | } |
1423 | } |
1424 | } |
1424 | } |
1425 | fprintf(fp, "\n"); |
1425 | fprintf (fp, "\n"); |
1426 | |
1426 | |
1427 | for (menu = bar->head; menu != NULL; menu = menu->next) |
1427 | for (menu = bar->head; menu != NULL; menu = menu->next) |
1428 | rxvt_menu_dump(fp, menu); |
1428 | rxvt_menu_dump (fp, menu); |
1429 | |
1429 | |
1430 | fprintf(fp, "\n[done:%s]\n\n", bar->name); |
1430 | fprintf (fp, "\n[done:%s]\n\n", bar->name); |
1431 | bar = bar->prev; |
1431 | bar = bar->prev; |
1432 | } |
1432 | } |
1433 | while (bar != CurrentBar->prev); |
1433 | while (bar != CurrentBar->prev); |
1434 | } |
1434 | } |
1435 | #endif /* (MENUBAR_MAX > 1) */ |
1435 | #endif /* (MENUBAR_MAX > 1) */ |
… | |
… | |
1455 | /* read in a menu from a file */ |
1455 | /* read in a menu from a file */ |
1456 | FILE *fp; |
1456 | FILE *fp; |
1457 | char buffer[256]; |
1457 | char buffer[256]; |
1458 | char *p, *file, *tag = NULL; |
1458 | char *p, *file, *tag = NULL; |
1459 | |
1459 | |
1460 | file = (char *)rxvt_File_find(filename, ".menu", rs[Rs_path]); |
1460 | file = (char *)rxvt_File_find (filename, ".menu", rs[Rs_path]); |
1461 | if (file == NULL) |
1461 | if (file == NULL) |
1462 | return; |
1462 | return; |
1463 | fp = fopen(file, "rb"); |
1463 | fp = fopen (file, "rb"); |
1464 | free(file); |
1464 | free (file); |
1465 | if (fp == NULL) |
1465 | if (fp == NULL) |
1466 | return; |
1466 | return; |
1467 | |
1467 | |
1468 | #if (MENUBAR_MAX > 1) |
1468 | #if (MENUBAR_MAX > 1) |
1469 | /* semi-colon delimited */ |
1469 | /* semi-colon delimited */ |
1470 | if ((tag = STRCHR(filename, ';')) != NULL) |
1470 | if ((tag = STRCHR (filename, ';')) != NULL) |
1471 | { |
1471 | { |
1472 | tag++; |
1472 | tag++; |
1473 | if (*tag == '\0') |
1473 | if (*tag == '\0') |
1474 | tag = NULL; |
1474 | tag = NULL; |
1475 | } |
1475 | } |
1476 | #endif /* (MENUBAR_MAX > 1) */ |
1476 | #endif /* (MENUBAR_MAX > 1) */ |
1477 | #ifdef DEBUG_MENU |
1477 | #ifdef DEBUG_MENU |
1478 | fprintf(stderr, "[read:%s]\n", p); |
1478 | fprintf (stderr, "[read:%s]\n", p); |
1479 | if (tag) |
1479 | if (tag) |
1480 | fprintf(stderr, "looking for [menu:%s]\n", tag); |
1480 | fprintf (stderr, "looking for [menu:%s]\n", tag); |
1481 | #endif |
1481 | #endif |
1482 | |
1482 | |
1483 | while ((p = fgets(buffer, sizeof(buffer), fp)) != NULL) |
1483 | while ((p = fgets (buffer, sizeof (buffer), fp)) != NULL) |
1484 | { |
1484 | { |
1485 | int n; |
1485 | int n; |
1486 | |
1486 | |
1487 | if ((n = rxvt_Str_match(p, "[menu")) != 0) |
1487 | if ((n = rxvt_Str_match (p, "[menu")) != 0) |
1488 | { |
1488 | { |
1489 | if (tag) |
1489 | if (tag) |
1490 | { |
1490 | { |
1491 | /* looking for [menu:tag] */ |
1491 | /* looking for [menu:tag] */ |
1492 | if (p[n] == ':' && p[n + 1] != ']') |
1492 | if (p[n] == ':' && p[n + 1] != ']') |
1493 | { |
1493 | { |
1494 | n++; |
1494 | n++; |
1495 | n += rxvt_Str_match(p + n, tag); |
1495 | n += rxvt_Str_match (p + n, tag); |
1496 | if (p[n] == ']') |
1496 | if (p[n] == ']') |
1497 | { |
1497 | { |
1498 | #ifdef DEBUG_MENU |
1498 | #ifdef DEBUG_MENU |
1499 | fprintf(stderr, "[menu:%s]\n", tag); |
1499 | fprintf (stderr, "[menu:%s]\n", tag); |
1500 | #endif |
1500 | #endif |
1501 | break; |
1501 | break; |
1502 | } |
1502 | } |
1503 | } |
1503 | } |
1504 | } |
1504 | } |
… | |
… | |
1511 | while (p != NULL) |
1511 | while (p != NULL) |
1512 | { |
1512 | { |
1513 | int n; |
1513 | int n; |
1514 | |
1514 | |
1515 | #ifdef DEBUG_MENU |
1515 | #ifdef DEBUG_MENU |
1516 | fprintf(stderr, "read line = %s\n", p); |
1516 | fprintf (stderr, "read line = %s\n", p); |
1517 | #endif |
1517 | #endif |
1518 | |
1518 | |
1519 | /* looking for [done:tag] or [done:] */ |
1519 | /* looking for [done:tag] or [done:] */ |
1520 | if ((n = rxvt_Str_match(p, "[done")) != 0) |
1520 | if ((n = rxvt_Str_match (p, "[done")) != 0) |
1521 | { |
1521 | { |
1522 | if (p[n] == ']') |
1522 | if (p[n] == ']') |
1523 | { |
1523 | { |
1524 | menu_readonly = 1; |
1524 | menu_readonly = 1; |
1525 | break; |
1525 | break; |
… | |
… | |
1532 | menu_readonly = 1; |
1532 | menu_readonly = 1; |
1533 | break; |
1533 | break; |
1534 | } |
1534 | } |
1535 | else if (tag) |
1535 | else if (tag) |
1536 | { |
1536 | { |
1537 | n += rxvt_Str_match(p + n, tag); |
1537 | n += rxvt_Str_match (p + n, tag); |
1538 | if (p[n] == ']') |
1538 | if (p[n] == ']') |
1539 | { |
1539 | { |
1540 | #ifdef DEBUG_MENU |
1540 | #ifdef DEBUG_MENU |
1541 | fprintf(stderr, "[done:%s]\n", tag); |
1541 | fprintf (stderr, "[done:%s]\n", tag); |
1542 | #endif |
1542 | #endif |
1543 | menu_readonly = 1; |
1543 | menu_readonly = 1; |
1544 | break; |
1544 | break; |
1545 | } |
1545 | } |
1546 | } |
1546 | } |
… | |
… | |
1554 | /* |
1554 | /* |
1555 | * remove leading/trailing space |
1555 | * remove leading/trailing space |
1556 | * and strip-off leading/trailing quotes |
1556 | * and strip-off leading/trailing quotes |
1557 | * skip blank or comment lines |
1557 | * skip blank or comment lines |
1558 | */ |
1558 | */ |
1559 | rxvt_Str_trim(p); |
1559 | rxvt_Str_trim (p); |
1560 | if (*p && *p != '#') |
1560 | if (*p && *p != '#') |
1561 | { |
1561 | { |
1562 | menu_readonly = 0; /* if case we read another file */ |
1562 | menu_readonly = 0; /* if case we read another file */ |
1563 | menubar_dispatch (p); |
1563 | menubar_dispatch (p); |
1564 | } |
1564 | } |
1565 | /* get another line */ |
1565 | /* get another line */ |
1566 | p = fgets(buffer, sizeof(buffer), fp); |
1566 | p = fgets (buffer, sizeof (buffer), fp); |
1567 | } |
1567 | } |
1568 | |
1568 | |
1569 | fclose(fp); |
1569 | fclose (fp); |
1570 | } |
1570 | } |
1571 | |
1571 | |
1572 | /* |
1572 | /* |
1573 | * user interface for building/deleting and otherwise managing menus |
1573 | * user interface for building/deleting and otherwise managing menus |
1574 | */ |
1574 | */ |
… | |
… | |
1576 | rxvt_term::menubar_dispatch (char *str) |
1576 | rxvt_term::menubar_dispatch (char *str) |
1577 | { |
1577 | { |
1578 | int n, cmd; |
1578 | int n, cmd; |
1579 | char *path, *name, *name2; |
1579 | char *path, *name, *name2; |
1580 | |
1580 | |
1581 | if (menubar_visible(r) && ActiveMenu != NULL) |
1581 | if (menubar_visible (r) && ActiveMenu != NULL) |
1582 | menubar_expose (); |
1582 | menubar_expose (); |
1583 | else |
1583 | else |
1584 | ActiveMenu = NULL; |
1584 | ActiveMenu = NULL; |
1585 | |
1585 | |
1586 | cmd = *str; |
1586 | cmd = *str; |
… | |
… | |
1615 | if (str[0] == ':') |
1615 | if (str[0] == ':') |
1616 | { /* [:command:] */ |
1616 | { /* [:command:] */ |
1617 | do |
1617 | do |
1618 | { |
1618 | { |
1619 | next++; |
1619 | next++; |
1620 | if ((next = STRCHR(next, ':')) == NULL) |
1620 | if ((next = STRCHR (next, ':')) == NULL) |
1621 | return; /* parse error */ |
1621 | return; /* parse error */ |
1622 | } |
1622 | } |
1623 | while (next[1] != ']'); |
1623 | while (next[1] != ']'); |
1624 | /* remove and skip ':]' */ |
1624 | /* remove and skip ':]' */ |
1625 | *next = '\0'; |
1625 | *next = '\0'; |
1626 | next += 2; |
1626 | next += 2; |
1627 | } |
1627 | } |
1628 | else |
1628 | else |
1629 | { |
1629 | { |
1630 | if ((next = STRCHR(next, ']')) == NULL) |
1630 | if ((next = STRCHR (next, ']')) == NULL) |
1631 | return; /* parse error */ |
1631 | return; /* parse error */ |
1632 | /* remove and skip ']' */ |
1632 | /* remove and skip ']' */ |
1633 | *next = '\0'; |
1633 | *next = '\0'; |
1634 | next++; |
1634 | next++; |
1635 | } |
1635 | } |
… | |
… | |
1643 | menu_readonly = 0; |
1643 | menu_readonly = 0; |
1644 | menubar_dispatch (str + 1); |
1644 | menubar_dispatch (str + 1); |
1645 | menu_readonly = saved; |
1645 | menu_readonly = saved; |
1646 | } |
1646 | } |
1647 | /* these ones don't require menu stacking */ |
1647 | /* these ones don't require menu stacking */ |
1648 | else if (!STRCMP(str, "clear")) |
1648 | else if (!STRCMP (str, "clear")) |
1649 | { |
1649 | { |
1650 | menubar_clear (); |
1650 | menubar_clear (); |
1651 | } |
1651 | } |
1652 | else if (!STRCMP(str, "done") || rxvt_Str_match(str, "done:")) |
1652 | else if (!STRCMP (str, "done") || rxvt_Str_match (str, "done:")) |
1653 | { |
1653 | { |
1654 | menu_readonly = 1; |
1654 | menu_readonly = 1; |
1655 | } |
1655 | } |
1656 | else if (!STRCMP(str, "show")) |
1656 | else if (!STRCMP (str, "show")) |
1657 | { |
1657 | { |
1658 | map_menuBar (1); |
1658 | map_menuBar (1); |
1659 | menu_readonly = 1; |
1659 | menu_readonly = 1; |
1660 | } |
1660 | } |
1661 | else if (!STRCMP(str, "hide")) |
1661 | else if (!STRCMP (str, "hide")) |
1662 | { |
1662 | { |
1663 | map_menuBar (0); |
1663 | map_menuBar (0); |
1664 | menu_readonly = 1; |
1664 | menu_readonly = 1; |
1665 | } |
1665 | } |
1666 | else if ((n = rxvt_Str_match(str, "read:")) != 0) |
1666 | else if ((n = rxvt_Str_match (str, "read:")) != 0) |
1667 | { |
1667 | { |
1668 | /* read in a menu from a file */ |
1668 | /* read in a menu from a file */ |
1669 | str += n; |
1669 | str += n; |
1670 | menubar_read (str); |
1670 | menubar_read (str); |
1671 | } |
1671 | } |
1672 | else if ((n = rxvt_Str_match(str, "title:")) != 0) |
1672 | else if ((n = rxvt_Str_match (str, "title:")) != 0) |
1673 | { |
1673 | { |
1674 | str += n; |
1674 | str += n; |
1675 | if (CurrentBar != NULL && !menu_readonly) |
1675 | if (CurrentBar != NULL && !menu_readonly) |
1676 | { |
1676 | { |
1677 | if (*str) |
1677 | if (*str) |
1678 | { |
1678 | { |
1679 | name = rxvt_realloc(CurrentBar->title, |
1679 | name = rxvt_realloc (CurrentBar->title, |
1680 | STRLEN(str) + 1); |
1680 | STRLEN (str) + 1); |
1681 | if (name != NULL) |
1681 | if (name != NULL) |
1682 | { |
1682 | { |
1683 | STRCPY(name, str); |
1683 | STRCPY (name, str); |
1684 | CurrentBar->title = name; |
1684 | CurrentBar->title = name; |
1685 | } |
1685 | } |
1686 | menubar_expose (); |
1686 | menubar_expose (); |
1687 | } |
1687 | } |
1688 | else |
1688 | else |
1689 | { |
1689 | { |
1690 | free(CurrentBar->title); |
1690 | free (CurrentBar->title); |
1691 | CurrentBar->title = NULL; |
1691 | CurrentBar->title = NULL; |
1692 | } |
1692 | } |
1693 | } |
1693 | } |
1694 | } |
1694 | } |
1695 | else if ((n = rxvt_Str_match(str, "pixmap:")) != 0) |
1695 | else if ((n = rxvt_Str_match (str, "pixmap:")) != 0) |
1696 | { |
1696 | { |
1697 | str += n; |
1697 | str += n; |
1698 | xterm_seq (XTerm_Pixmap, str, CHAR_ST); |
1698 | xterm_seq (XTerm_Pixmap, str, CHAR_ST); |
1699 | } |
1699 | } |
1700 | #if (MENUBAR_MAX > 1) |
1700 | #if (MENUBAR_MAX > 1) |
1701 | else if ((n = rxvt_Str_match(str, "rm")) != 0) |
1701 | else if ((n = rxvt_Str_match (str, "rm")) != 0) |
1702 | { |
1702 | { |
1703 | str += n; |
1703 | str += n; |
1704 | switch (str[0]) |
1704 | switch (str[0]) |
1705 | { |
1705 | { |
1706 | case ':': |
1706 | case ':': |
… | |
… | |
1712 | menubar_remove (str); |
1712 | menubar_remove (str); |
1713 | break; |
1713 | break; |
1714 | } |
1714 | } |
1715 | menu_readonly = 1; |
1715 | menu_readonly = 1; |
1716 | } |
1716 | } |
1717 | else if ((n = rxvt_Str_match(str, "menu")) != 0) |
1717 | else if ((n = rxvt_Str_match (str, "menu")) != 0) |
1718 | { |
1718 | { |
1719 | str += n; |
1719 | str += n; |
1720 | switch (str[0]) |
1720 | switch (str[0]) |
1721 | { |
1721 | { |
1722 | case ':': |
1722 | case ':': |
… | |
… | |
1733 | } |
1733 | } |
1734 | |
1734 | |
1735 | if (CurrentBar != NULL) |
1735 | if (CurrentBar != NULL) |
1736 | menu_readonly = 0; /* allow menu build commands */ |
1736 | menu_readonly = 0; /* allow menu build commands */ |
1737 | } |
1737 | } |
1738 | else if (!STRCMP(str, "dump")) |
1738 | else if (!STRCMP (str, "dump")) |
1739 | { |
1739 | { |
1740 | /* dump current menubars to a file */ |
1740 | /* dump current menubars to a file */ |
1741 | FILE *fp; |
1741 | FILE *fp; |
1742 | |
1742 | |
1743 | /* enough space to hold the results */ |
1743 | /* enough space to hold the results */ |
1744 | char buffer[32]; |
1744 | char buffer[32]; |
1745 | |
1745 | |
1746 | sprintf(buffer, "/tmp/" APL_SUBCLASS "-%u", |
1746 | sprintf (buffer, "/tmp/" APL_SUBCLASS "-%u", |
1747 | (unsigned int)getpid()); |
1747 | (unsigned int)getpid ()); |
1748 | |
1748 | |
1749 | if ((fp = fopen(buffer, "wb")) != NULL) |
1749 | if ((fp = fopen (buffer, "wb")) != NULL) |
1750 | { |
1750 | { |
1751 | xterm_seq (XTerm_title, buffer, CHAR_ST); |
1751 | xterm_seq (XTerm_title, buffer, CHAR_ST); |
1752 | menubar_dump (fp); |
1752 | menubar_dump (fp); |
1753 | fclose(fp); |
1753 | fclose (fp); |
1754 | } |
1754 | } |
1755 | } |
1755 | } |
1756 | else if (!STRCMP(str, "next")) |
1756 | else if (!STRCMP (str, "next")) |
1757 | { |
1757 | { |
1758 | if (CurrentBar) |
1758 | if (CurrentBar) |
1759 | { |
1759 | { |
1760 | CurrentBar = CurrentBar->next; |
1760 | CurrentBar = CurrentBar->next; |
1761 | menu_readonly = 1; |
1761 | menu_readonly = 1; |
1762 | } |
1762 | } |
1763 | } |
1763 | } |
1764 | else if (!STRCMP(str, "prev")) |
1764 | else if (!STRCMP (str, "prev")) |
1765 | { |
1765 | { |
1766 | if (CurrentBar) |
1766 | if (CurrentBar) |
1767 | { |
1767 | { |
1768 | CurrentBar = CurrentBar->prev; |
1768 | CurrentBar = CurrentBar->prev; |
1769 | menu_readonly = 1; |
1769 | menu_readonly = 1; |
1770 | } |
1770 | } |
1771 | } |
1771 | } |
1772 | else if (!STRCMP(str, "swap")) |
1772 | else if (!STRCMP (str, "swap")) |
1773 | { |
1773 | { |
1774 | /* swap the top 2 menus */ |
1774 | /* swap the top 2 menus */ |
1775 | if (CurrentBar) |
1775 | if (CurrentBar) |
1776 | { |
1776 | { |
1777 | bar_t *cbprev = CurrentBar->prev; |
1777 | bar_t *cbprev = CurrentBar->prev; |
… | |
… | |
1794 | str = next; |
1794 | str = next; |
1795 | |
1795 | |
1796 | BuildMenu = ActiveMenu = NULL; |
1796 | BuildMenu = ActiveMenu = NULL; |
1797 | menubar_expose (); |
1797 | menubar_expose (); |
1798 | #ifdef DEBUG_MENUBAR_STACKING |
1798 | #ifdef DEBUG_MENUBAR_STACKING |
1799 | fprintf(stderr, "menus are read%s\n", |
1799 | fprintf (stderr, "menus are read%s\n", |
1800 | menu_readonly ? "only" : "/write"); |
1800 | menu_readonly ? "only" : "/write"); |
1801 | #endif |
1801 | #endif |
1802 | |
1802 | |
1803 | } |
1803 | } |
1804 | return; |
1804 | return; |
… | |
… | |
1809 | if (CurrentBar == NULL) |
1809 | if (CurrentBar == NULL) |
1810 | return; |
1810 | return; |
1811 | if (menu_readonly) |
1811 | if (menu_readonly) |
1812 | { |
1812 | { |
1813 | #ifdef DEBUG_MENUBAR_STACKING |
1813 | #ifdef DEBUG_MENUBAR_STACKING |
1814 | fprintf(stderr, "menus are read%s\n", |
1814 | fprintf (stderr, "menus are read%s\n", |
1815 | menu_readonly ? "only" : "/write"); |
1815 | menu_readonly ? "only" : "/write"); |
1816 | #endif |
1816 | #endif |
1817 | return; |
1817 | return; |
1818 | } |
1818 | } |
1819 | #endif /* (MENUBAR_MAX > 1) */ |
1819 | #endif /* (MENUBAR_MAX > 1) */ |
… | |
… | |
1826 | |
1826 | |
1827 | name2 = NULL; |
1827 | name2 = NULL; |
1828 | /* parse STR, allow spaces inside (name) */ |
1828 | /* parse STR, allow spaces inside (name) */ |
1829 | if (path[0] != '\0') |
1829 | if (path[0] != '\0') |
1830 | { |
1830 | { |
1831 | name = STRCHR(path, MENUITEM_BEG); |
1831 | name = STRCHR (path, MENUITEM_BEG); |
1832 | str = STRCHR(path, MENUITEM_END); |
1832 | str = STRCHR (path, MENUITEM_END); |
1833 | if (name != NULL || str != NULL) |
1833 | if (name != NULL || str != NULL) |
1834 | { |
1834 | { |
1835 | if (name == NULL || str == NULL || str <= (name + 1) |
1835 | if (name == NULL || str == NULL || str <= (name + 1) |
1836 | || (name > path && name[-1] != '/')) |
1836 | || (name > path && name[-1] != '/')) |
1837 | { |
1837 | { |
1838 | rxvt_print_error("menu error <%s>\n", path); |
1838 | rxvt_print_error ("menu error <%s>\n", path); |
1839 | break; |
1839 | break; |
1840 | } |
1840 | } |
1841 | if (str[1] == MENUITEM_BEG) |
1841 | if (str[1] == MENUITEM_BEG) |
1842 | { |
1842 | { |
1843 | name2 = (str + 2); |
1843 | name2 = (str + 2); |
1844 | str = STRCHR(name2, MENUITEM_END); |
1844 | str = STRCHR (name2, MENUITEM_END); |
1845 | |
1845 | |
1846 | if (str == NULL) |
1846 | if (str == NULL) |
1847 | { |
1847 | { |
1848 | rxvt_print_error("menu error <%s>\n", path); |
1848 | rxvt_print_error ("menu error <%s>\n", path); |
1849 | break; |
1849 | break; |
1850 | } |
1850 | } |
1851 | name2[-2] = '\0'; /* remove prev MENUITEM_END */ |
1851 | name2[-2] = '\0'; /* remove prev MENUITEM_END */ |
1852 | } |
1852 | } |
1853 | if (name > path && name[-1] == '/') |
1853 | if (name > path && name[-1] == '/') |
1854 | name[-1] = '\0'; |
1854 | name[-1] = '\0'; |
1855 | |
1855 | |
1856 | *name++ = '\0'; /* delimit */ |
1856 | *name++ = '\0'; /* delimit */ |
1857 | *str++ = '\0'; /* delimit */ |
1857 | *str++ = '\0'; /* delimit */ |
1858 | |
1858 | |
1859 | while (isspace(*str)) |
1859 | while (isspace (*str)) |
1860 | str++; /* skip space */ |
1860 | str++; /* skip space */ |
1861 | } |
1861 | } |
1862 | #ifdef DEBUG_MENU |
1862 | #ifdef DEBUG_MENU |
1863 | fprintf(stderr, |
1863 | fprintf (stderr, |
1864 | "`%c' path = <%s>, name = <%s>, name2 = <%s>, action = <%s>\n", |
1864 | "`%c' path = <%s>, name = <%s>, name2 = <%s>, action = <%s>\n", |
1865 | cmd, (path ? path : "(nil)"), (name ? name : "(nil)"), |
1865 | cmd, (path ? path : " (nil)"), (name ? name : " (nil)"), |
1866 | (name2 ? name2 : "(nil)"), (str ? str : "(nil)") |
1866 | (name2 ? name2 : " (nil)"), (str ? str : " (nil)") |
1867 | ); |
1867 | ); |
1868 | #endif |
1868 | #endif |
1869 | |
1869 | |
1870 | } |
1870 | } |
1871 | /* process the different commands */ |
1871 | /* process the different commands */ |
… | |
… | |
1874 | case '+': /* add/replace existing menu or menuitem */ |
1874 | case '+': /* add/replace existing menu or menuitem */ |
1875 | if (path[0] != '\0') |
1875 | if (path[0] != '\0') |
1876 | { |
1876 | { |
1877 | int len; |
1877 | int len; |
1878 | |
1878 | |
1879 | path = menu_find_base (&(BuildMenu), path); |
1879 | path = menu_find_base (& (BuildMenu), path); |
1880 | len = STRLEN(path); |
1880 | len = STRLEN (path); |
1881 | |
1881 | |
1882 | /* don't allow menus called `*' */ |
1882 | /* don't allow menus called `*' */ |
1883 | if (path[0] == '*') |
1883 | if (path[0] == '*') |
1884 | { |
1884 | { |
1885 | menu_clear (BuildMenu); |
1885 | menu_clear (BuildMenu); |
1886 | break; |
1886 | break; |
1887 | } |
1887 | } |
1888 | else if (len >= 2 && !STRCMP((path + len - 2), "/*")) |
1888 | else if (len >= 2 && !STRCMP ((path + len - 2), "/*")) |
1889 | { |
1889 | { |
1890 | path[len - 2] = '\0'; |
1890 | path[len - 2] = '\0'; |
1891 | } |
1891 | } |
1892 | if (path[0] != '\0') |
1892 | if (path[0] != '\0') |
1893 | BuildMenu = menu_add (BuildMenu, path); |
1893 | BuildMenu = menu_add (BuildMenu, path); |
1894 | } |
1894 | } |
1895 | if (name != NULL && name[0] != '\0') |
1895 | if (name != NULL && name[0] != '\0') |
1896 | rxvt_menuitem_add(BuildMenu, |
1896 | rxvt_menuitem_add (BuildMenu, |
1897 | (STRCMP(name, SEPARATOR_NAME) ? name : ""), |
1897 | (STRCMP (name, SEPARATOR_NAME) ? name : ""), |
1898 | name2, str); |
1898 | name2, str); |
1899 | break; |
1899 | break; |
1900 | |
1900 | |
1901 | case '-': /* delete menu entry */ |
1901 | case '-': /* delete menu entry */ |
1902 | if (!STRCMP(path, "/*") && (name == NULL || name[0] == '\0')) |
1902 | if (!STRCMP (path, "/*") && (name == NULL || name[0] == '\0')) |
1903 | { |
1903 | { |
1904 | menubar_clear (); |
1904 | menubar_clear (); |
1905 | BuildMenu = NULL; |
1905 | BuildMenu = NULL; |
1906 | menubar_expose (); |
1906 | menubar_expose (); |
1907 | break; |
1907 | break; |
… | |
… | |
1910 | { |
1910 | { |
1911 | int len; |
1911 | int len; |
1912 | menu_t *menu = BuildMenu; |
1912 | menu_t *menu = BuildMenu; |
1913 | |
1913 | |
1914 | path = menu_find_base (&menu, path); |
1914 | path = menu_find_base (&menu, path); |
1915 | len = STRLEN(path); |
1915 | len = STRLEN (path); |
1916 | |
1916 | |
1917 | /* submenu called `*' clears all menu items */ |
1917 | /* submenu called `*' clears all menu items */ |
1918 | if (path[0] == '*') |
1918 | if (path[0] == '*') |
1919 | { |
1919 | { |
1920 | menu_clear (menu); |
1920 | menu_clear (menu); |
1921 | break; /* done */ |
1921 | break; /* done */ |
1922 | } |
1922 | } |
1923 | else if (len >= 2 && !STRCMP(&path[len - 2], "/*")) |
1923 | else if (len >= 2 && !STRCMP (&path[len - 2], "/*")) |
1924 | { |
1924 | { |
1925 | /* done */ |
1925 | /* done */ |
1926 | break; |
1926 | break; |
1927 | } |
1927 | } |
1928 | else if (path[0] != '\0') |
1928 | else if (path[0] != '\0') |
… | |
… | |
1941 | { |
1941 | { |
1942 | const char *n1; |
1942 | const char *n1; |
1943 | menuitem_t *item; |
1943 | menuitem_t *item; |
1944 | menu_t *BuildMenu = BuildMenu; |
1944 | menu_t *BuildMenu = BuildMenu; |
1945 | |
1945 | |
1946 | n1 = STRCMP(name, SEPARATOR_NAME) ? name : ""; |
1946 | n1 = STRCMP (name, SEPARATOR_NAME) ? name : ""; |
1947 | item = rxvt_menuitem_find(BuildMenu, n1); |
1947 | item = rxvt_menuitem_find (BuildMenu, n1); |
1948 | if (item != NULL && item->entry.type != MenuSubMenu) |
1948 | if (item != NULL && item->entry.type != MenuSubMenu) |
1949 | { |
1949 | { |
1950 | menuitem_free (BuildMenu, item); |
1950 | menuitem_free (BuildMenu, item); |
1951 | |
1951 | |
1952 | /* fix up the width */ |
1952 | /* fix up the width */ |
… | |
… | |
1954 | for (item = BuildMenu->head; item != NULL; |
1954 | for (item = BuildMenu->head; item != NULL; |
1955 | item = item->next) |
1955 | item = item->next) |
1956 | { |
1956 | { |
1957 | short l = item->len + item->len2; |
1957 | short l = item->len + item->len2; |
1958 | |
1958 | |
1959 | MAX_IT(BuildMenu->width, l); |
1959 | MAX_IT (BuildMenu->width, l); |
1960 | } |
1960 | } |
1961 | } |
1961 | } |
1962 | } |
1962 | } |
1963 | menubar_expose (); |
1963 | menubar_expose (); |
1964 | } |
1964 | } |
… | |
… | |
1996 | if (!Arrows_x) |
1996 | if (!Arrows_x) |
1997 | return; |
1997 | return; |
1998 | |
1998 | |
1999 | for (i = 0; i < NARROWS; i++) |
1999 | for (i = 0; i < NARROWS; i++) |
2000 | { |
2000 | { |
2001 | const int w = Width2Pixel(1); |
2001 | const int w = Width2Pixel (1); |
2002 | const int y = (menuBar_TotalHeight() - w) / 2; |
2002 | const int y = (menuBar_TotalHeight () - w) / 2; |
2003 | int x = Arrows_x + (5 * Width2Pixel(i)) / 4; |
2003 | int x = Arrows_x + (5 * Width2Pixel (i)) / 4; |
2004 | |
2004 | |
2005 | if (!name || name == Arrows[i].name) |
2005 | if (!name || name == Arrows[i].name) |
2006 | rxvt_Draw_Triangle(display->display, menuBar.win, top, bot, x, y, w, |
2006 | rxvt_Draw_Triangle (display->display, menuBar.win, top, bot, x, y, w, |
2007 | Arrows[i].name); |
2007 | Arrows[i].name); |
2008 | } |
2008 | } |
2009 | XFlush(display->display); |
2009 | XFlush (display->display); |
2010 | } |
2010 | } |
2011 | |
2011 | |
2012 | void |
2012 | void |
2013 | rxvt_term::menubar_expose () |
2013 | rxvt_term::menubar_expose () |
2014 | { |
2014 | { |
2015 | menu_t *menu; |
2015 | menu_t *menu; |
2016 | int x; |
2016 | int x; |
2017 | |
2017 | |
2018 | if (!menubar_visible(r) || menuBar.win == 0) |
2018 | if (!menubar_visible (r) || menuBar.win == 0) |
2019 | return; |
2019 | return; |
2020 | |
2020 | |
2021 | if (menubarGC == None) |
2021 | if (menubarGC == None) |
2022 | { |
2022 | { |
2023 | /* Create the graphics context */ |
2023 | /* Create the graphics context */ |
… | |
… | |
2025 | |
2025 | |
2026 | gcvalue.font = TermWin.font->fid; |
2026 | gcvalue.font = TermWin.font->fid; |
2027 | |
2027 | |
2028 | gcvalue.foreground = (XDEPTH <= 2 ? PixColors[Color_fg] |
2028 | gcvalue.foreground = (XDEPTH <= 2 ? PixColors[Color_fg] |
2029 | : PixColors[Color_Black]); |
2029 | : PixColors[Color_Black]); |
2030 | menubarGC = XCreateGC(display->display, menuBar.win, |
2030 | menubarGC = XCreateGC (display->display, menuBar.win, |
2031 | GCForeground | GCFont, &gcvalue); |
2031 | GCForeground | GCFont, &gcvalue); |
2032 | |
2032 | |
2033 | } |
2033 | } |
2034 | /* make sure the font is correct */ |
2034 | /* make sure the font is correct */ |
2035 | XSetFont(display->display, menubarGC, TermWin.font->fid); |
2035 | XSetFont (display->display, menubarGC, TermWin.font->fid); |
2036 | XSetFont(display->display, botShadowGC, TermWin.font->fid); |
2036 | XSetFont (display->display, botShadowGC, TermWin.font->fid); |
2037 | XClearWindow(display->display, menuBar.win); |
2037 | XClearWindow (display->display, menuBar.win); |
2038 | |
2038 | |
2039 | menu_hide_all (); |
2039 | menu_hide_all (); |
2040 | |
2040 | |
2041 | x = 0; |
2041 | x = 0; |
2042 | if (CurrentBar != NULL) |
2042 | if (CurrentBar != NULL) |
… | |
… | |
2046 | int len = menu->len; |
2046 | int len = menu->len; |
2047 | |
2047 | |
2048 | x = (menu->x + menu->len + HSPACE); |
2048 | x = (menu->x + menu->len + HSPACE); |
2049 | |
2049 | |
2050 | #ifdef DEBUG_MENU_LAYOUT |
2050 | #ifdef DEBUG_MENU_LAYOUT |
2051 | rxvt_print_menu_descendants(menu); |
2051 | rxvt_print_menu_descendants (menu); |
2052 | #endif |
2052 | #endif |
2053 | |
2053 | |
2054 | if (x >= TermWin.ncol) |
2054 | if (x >= TermWin.ncol) |
2055 | len = (TermWin.ncol - (menu->x + HSPACE)); |
2055 | len = (TermWin.ncol - (menu->x + HSPACE)); |
2056 | |
2056 | |
2057 | drawbox_menubar (menu->x, len, +1); |
2057 | drawbox_menubar (menu->x, len, +1); |
2058 | #ifdef USE_XIM |
2058 | #ifdef USE_XIM |
2059 | if (TermWin.fontset) |
2059 | if (TermWin.fontset) |
2060 | XmbDrawString(display->display, |
2060 | XmbDrawString (display->display, |
2061 | menuBar.win, TermWin.fontset, |
2061 | menuBar.win, TermWin.fontset, |
2062 | menubarGC, |
2062 | menubarGC, |
2063 | (Width2Pixel(menu->x) + Width2Pixel(HSPACE) / 2), |
2063 | (Width2Pixel (menu->x) + Width2Pixel (HSPACE) / 2), |
2064 | menuBar_height() - SHADOW, menu->name, len); |
2064 | menuBar_height () - SHADOW, menu->name, len); |
2065 | else |
2065 | else |
2066 | #endif |
2066 | #endif |
2067 | XDrawString(display->display, menuBar.win, menubarGC, |
2067 | XDrawString (display->display, menuBar.win, menubarGC, |
2068 | (Width2Pixel(menu->x) + Width2Pixel(HSPACE) / 2), |
2068 | (Width2Pixel (menu->x) + Width2Pixel (HSPACE) / 2), |
2069 | menuBar_height() - SHADOW, menu->name, len); |
2069 | menuBar_height () - SHADOW, menu->name, len); |
2070 | |
2070 | |
2071 | if (x >= TermWin.ncol) |
2071 | if (x >= TermWin.ncol) |
2072 | break; |
2072 | break; |
2073 | } |
2073 | } |
2074 | } |
2074 | } |
… | |
… | |
2085 | |
2085 | |
2086 | ncol = (int)TermWin.ncol; |
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 | draw_Arrows (0, +1); |
2092 | draw_Arrows (0, +1); |
2093 | |
2093 | |
2094 | str = (CurrentBar |
2094 | str = (CurrentBar |
2095 | && CurrentBar->title) ? CurrentBar->title : "%n-%v"; |
2095 | && CurrentBar->title) ? CurrentBar->title : "%n-%v"; |
2096 | for (len = 0; str[0] && len < sizeof(title) - 1; str++) |
2096 | for (len = 0; str[0] && len < sizeof (title) - 1; str++) |
2097 | { |
2097 | { |
2098 | const char *s = NULL; |
2098 | const char *s = NULL; |
2099 | |
2099 | |
2100 | switch (str[0]) |
2100 | switch (str[0]) |
2101 | { |
2101 | { |
… | |
… | |
2112 | case '%': |
2112 | case '%': |
2113 | s = "%"; |
2113 | s = "%"; |
2114 | break; /* literal '%' */ |
2114 | break; /* literal '%' */ |
2115 | } |
2115 | } |
2116 | if (s != NULL) |
2116 | if (s != NULL) |
2117 | while (*s && len < sizeof(title) - 1) |
2117 | while (*s && len < sizeof (title) - 1) |
2118 | title[len++] = *s++; |
2118 | title[len++] = *s++; |
2119 | break; |
2119 | break; |
2120 | |
2120 | |
2121 | default: |
2121 | default: |
2122 | title[len++] = str[0]; |
2122 | title[len++] = str[0]; |
… | |
… | |
2128 | ncol -= (x + len + HSPACE); |
2128 | ncol -= (x + len + HSPACE); |
2129 | if (len > 0 && ncol >= 0) |
2129 | if (len > 0 && ncol >= 0) |
2130 | { |
2130 | { |
2131 | #ifdef USE_XIM |
2131 | #ifdef USE_XIM |
2132 | if (TermWin.fontset) |
2132 | if (TermWin.fontset) |
2133 | XmbDrawString(display->display, |
2133 | XmbDrawString (display->display, |
2134 | menuBar.win, TermWin.fontset, |
2134 | menuBar.win, TermWin.fontset, |
2135 | menubarGC, |
2135 | menubarGC, |
2136 | Width2Pixel(x) + Width2Pixel(ncol + HSPACE) / 2, |
2136 | Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2, |
2137 | menuBar_height() - SHADOW, title, len); |
2137 | menuBar_height () - SHADOW, title, len); |
2138 | else |
2138 | else |
2139 | #endif |
2139 | #endif |
2140 | XDrawString(display->display, menuBar.win, menubarGC, |
2140 | XDrawString (display->display, menuBar.win, menubarGC, |
2141 | Width2Pixel(x) + Width2Pixel(ncol + HSPACE) / 2, |
2141 | Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2, |
2142 | menuBar_height() - SHADOW, title, len); |
2142 | menuBar_height () - SHADOW, title, len); |
2143 | } |
2143 | } |
2144 | } |
2144 | } |
2145 | } |
2145 | } |
2146 | |
2146 | |
2147 | int |
2147 | int |
2148 | rxvt_term::menubar_mapping (int map) |
2148 | rxvt_term::menubar_mapping (int map) |
2149 | { |
2149 | { |
2150 | int change = 0; |
2150 | int change = 0; |
2151 | |
2151 | |
2152 | if (map && !menubar_visible(r)) |
2152 | if (map && !menubar_visible (r)) |
2153 | { |
2153 | { |
2154 | menuBar.state = 1; |
2154 | menuBar.state = 1; |
2155 | if (menuBar.win == 0) |
2155 | if (menuBar.win == 0) |
2156 | return 0; |
2156 | return 0; |
2157 | XMapWindow(display->display, menuBar.win); |
2157 | XMapWindow (display->display, menuBar.win); |
2158 | change = 1; |
2158 | change = 1; |
2159 | } |
2159 | } |
2160 | else if (!map && menubar_visible(r)) |
2160 | else if (!map && menubar_visible (r)) |
2161 | { |
2161 | { |
2162 | menubar_expose (); |
2162 | menubar_expose (); |
2163 | menuBar.state = 0; |
2163 | menuBar.state = 0; |
2164 | XUnmapWindow(display->display, menuBar.win); |
2164 | XUnmapWindow (display->display, menuBar.win); |
2165 | change = 1; |
2165 | change = 1; |
2166 | } |
2166 | } |
2167 | else |
2167 | else |
2168 | menubar_expose (); |
2168 | menubar_expose (); |
2169 | |
2169 | |
… | |
… | |
2182 | unsigned int unused_mask; |
2182 | unsigned int unused_mask; |
2183 | |
2183 | |
2184 | if (ActiveMenu == NULL) |
2184 | if (ActiveMenu == NULL) |
2185 | return 0; |
2185 | return 0; |
2186 | |
2186 | |
2187 | XQueryPointer(display->display, ActiveMenu->win, |
2187 | XQueryPointer (display->display, ActiveMenu->win, |
2188 | &unused_root, &unused_child, |
2188 | &unused_root, &unused_child, |
2189 | &unused_root_x, &unused_root_y, |
2189 | &unused_root_x, &unused_root_y, |
2190 | &(ev->x), &(ev->y), &unused_mask); |
2190 | & (ev->x), & (ev->y), &unused_mask); |
2191 | |
2191 | |
2192 | if (ActiveMenu->parent != NULL && (ev->x < 0 || ev->y < 0)) |
2192 | if (ActiveMenu->parent != NULL && (ev->x < 0 || ev->y < 0)) |
2193 | { |
2193 | { |
2194 | menu_hide (); |
2194 | menu_hide (); |
2195 | return 1; |
2195 | return 1; |
… | |
… | |
2200 | { |
2200 | { |
2201 | for (item = ActiveMenu->head; item != NULL; item = item->next) |
2201 | for (item = ActiveMenu->head; item != NULL; item = item->next) |
2202 | { |
2202 | { |
2203 | int h = HEIGHT_TEXT + 2 * SHADOW; |
2203 | int h = HEIGHT_TEXT + 2 * SHADOW; |
2204 | |
2204 | |
2205 | if (isSeparator(item->name)) |
2205 | if (isSeparator (item->name)) |
2206 | h = HEIGHT_SEPARATOR; |
2206 | h = HEIGHT_SEPARATOR; |
2207 | else if (ev->y >= y && ev->y < (y + h)) |
2207 | else if (ev->y >= y && ev->y < (y + h)) |
2208 | break; |
2208 | break; |
2209 | y += h; |
2209 | y += h; |
2210 | } |
2210 | } |
… | |
… | |
2225 | for (y = 0, item = ActiveMenu->head; item != NULL; |
2225 | for (y = 0, item = ActiveMenu->head; item != NULL; |
2226 | item = item->next) |
2226 | item = item->next) |
2227 | { |
2227 | { |
2228 | int h; |
2228 | int h; |
2229 | |
2229 | |
2230 | if (isSeparator(item->name)) |
2230 | if (isSeparator (item->name)) |
2231 | h = HEIGHT_SEPARATOR; |
2231 | h = HEIGHT_SEPARATOR; |
2232 | else if (item == ActiveMenu->item) |
2232 | else if (item == ActiveMenu->item) |
2233 | { |
2233 | { |
2234 | /* erase old menuitem */ |
2234 | /* erase old menuitem */ |
2235 | drawbox_menuitem (y, 0); /* No Shadow */ |
2235 | drawbox_menuitem (y, 0); /* No Shadow */ |
… | |
… | |
2261 | #ifdef HAVE_NANOSLEEP |
2261 | #ifdef HAVE_NANOSLEEP |
2262 | struct timespec rqt; |
2262 | struct timespec rqt; |
2263 | |
2263 | |
2264 | rqt.tv_sec = 0; |
2264 | rqt.tv_sec = 0; |
2265 | rqt.tv_nsec = MENU_DELAY_USEC * 1000; |
2265 | rqt.tv_nsec = MENU_DELAY_USEC * 1000; |
2266 | nanosleep(&rqt, NULL); |
2266 | nanosleep (&rqt, NULL); |
2267 | #else |
2267 | #else |
2268 | /* use select for timing */ |
2268 | /* use select for timing */ |
2269 | struct timeval tv; |
2269 | struct timeval tv; |
2270 | |
2270 | |
2271 | tv.tv_sec = 0; |
2271 | tv.tv_sec = 0; |
2272 | tv.tv_usec = MENU_DELAY_USEC; |
2272 | tv.tv_usec = MENU_DELAY_USEC; |
2273 | select(0, NULL, NULL, NULL, &tv); |
2273 | select (0, NULL, NULL, NULL, &tv); |
2274 | #endif |
2274 | #endif |
2275 | |
2275 | |
2276 | } |
2276 | } |
2277 | /* remove menu before sending keys to the application */ |
2277 | /* remove menu before sending keys to the application */ |
2278 | menu_hide_all (); |
2278 | menu_hide_all (); |
2279 | #ifndef DEBUG_MENU |
2279 | #ifndef DEBUG_MENU |
2280 | action_dispatch (&(item->entry.action)); |
2280 | action_dispatch (& (item->entry.action)); |
2281 | #else /* DEBUG_MENU */ |
2281 | #else /* DEBUG_MENU */ |
2282 | fprintf(stderr, "%s: %s\n", item->name, |
2282 | fprintf (stderr, "%s: %s\n", item->name, |
2283 | item->entry.action.str); |
2283 | item->entry.action.str); |
2284 | #endif /* DEBUG_MENU */ |
2284 | #endif /* DEBUG_MENU */ |
2285 | break; |
2285 | break; |
2286 | } |
2286 | } |
2287 | break; |
2287 | break; |
… | |
… | |
2308 | |
2308 | |
2309 | drawtriangle (ActiveMenu->w, y, -1); |
2309 | drawtriangle (ActiveMenu->w, y, -1); |
2310 | |
2310 | |
2311 | x = ev->x + (ActiveMenu->parent |
2311 | x = ev->x + (ActiveMenu->parent |
2312 | ? ActiveMenu->x |
2312 | ? ActiveMenu->x |
2313 | : Width2Pixel(ActiveMenu->x)); |
2313 | : Width2Pixel (ActiveMenu->x)); |
2314 | |
2314 | |
2315 | if (x >= item->entry.submenu.menu->x) |
2315 | if (x >= item->entry.submenu.menu->x) |
2316 | { |
2316 | { |
2317 | ActiveMenu = item->entry.submenu.menu; |
2317 | ActiveMenu = item->entry.submenu.menu; |
2318 | menu_show (); |
2318 | menu_show (); |
… | |
… | |
2327 | rxvt_term::menubar_select (XButtonEvent *ev) |
2327 | rxvt_term::menubar_select (XButtonEvent *ev) |
2328 | { |
2328 | { |
2329 | menu_t *menu = NULL; |
2329 | menu_t *menu = NULL; |
2330 | |
2330 | |
2331 | /* determine the pulldown menu corresponding to the X index */ |
2331 | /* determine the pulldown menu corresponding to the X index */ |
2332 | if (ev->y >= 0 && ev->y <= menuBar_height() && CurrentBar != NULL) |
2332 | if (ev->y >= 0 && ev->y <= menuBar_height () && CurrentBar != NULL) |
2333 | { |
2333 | { |
2334 | for (menu = CurrentBar->head; menu != NULL; menu = menu->next) |
2334 | for (menu = CurrentBar->head; menu != NULL; menu = menu->next) |
2335 | { |
2335 | { |
2336 | int x = Width2Pixel(menu->x); |
2336 | int x = Width2Pixel (menu->x); |
2337 | int w = Width2Pixel(menu->len + HSPACE); |
2337 | int w = Width2Pixel (menu->len + HSPACE); |
2338 | |
2338 | |
2339 | if ((ev->x >= x && ev->x < x + w)) |
2339 | if ((ev->x >= x && ev->x < x + w)) |
2340 | break; |
2340 | break; |
2341 | } |
2341 | } |
2342 | } |
2342 | } |
… | |
… | |
2351 | { |
2351 | { |
2352 | int i; |
2352 | int i; |
2353 | |
2353 | |
2354 | for (i = 0; i < NARROWS; i++) |
2354 | for (i = 0; i < NARROWS; i++) |
2355 | { |
2355 | { |
2356 | if (ev->x >= (Arrows_x + (Width2Pixel(4 * i + i)) / 4) |
2356 | if (ev->x >= (Arrows_x + (Width2Pixel (4 * i + i)) / 4) |
2357 | && ev->x < (Arrows_x |
2357 | && ev->x < (Arrows_x |
2358 | + (Width2Pixel(4 * i + i + 4)) / 4)) |
2358 | + (Width2Pixel (4 * i + i + 4)) / 4)) |
2359 | { |
2359 | { |
2360 | draw_Arrows (Arrows[i].name, -1); |
2360 | draw_Arrows (Arrows[i].name, -1); |
2361 | { |
2361 | { |
2362 | #ifdef HAVE_NANOSLEEP |
2362 | #ifdef HAVE_NANOSLEEP |
2363 | struct timespec rqt; |
2363 | struct timespec rqt; |
2364 | |
2364 | |
2365 | rqt.tv_sec = 0; |
2365 | rqt.tv_sec = 0; |
2366 | rqt.tv_nsec = MENU_DELAY_USEC * 1000; |
2366 | rqt.tv_nsec = MENU_DELAY_USEC * 1000; |
2367 | nanosleep(&rqt, NULL); |
2367 | nanosleep (&rqt, NULL); |
2368 | #else |
2368 | #else |
2369 | /* use select for timing */ |
2369 | /* use select for timing */ |
2370 | struct timeval tv; |
2370 | struct timeval tv; |
2371 | |
2371 | |
2372 | tv.tv_sec = 0; |
2372 | tv.tv_sec = 0; |
2373 | tv.tv_usec = MENU_DELAY_USEC; |
2373 | tv.tv_usec = MENU_DELAY_USEC; |
2374 | select(0, NULL, NULL, NULL, &tv); |
2374 | select (0, NULL, NULL, NULL, &tv); |
2375 | #endif |
2375 | #endif |
2376 | |
2376 | |
2377 | } |
2377 | } |
2378 | draw_Arrows (Arrows[i].name, +1); |
2378 | draw_Arrows (Arrows[i].name, +1); |
2379 | #ifdef DEBUG_MENUARROWS |
2379 | #ifdef DEBUG_MENUARROWS |
2380 | fprintf(stderr, "'%c': ", Arrows[i].name); |
2380 | fprintf (stderr, "'%c': ", Arrows[i].name); |
2381 | |
2381 | |
2382 | if (CurrentBar == NULL |
2382 | if (CurrentBar == NULL |
2383 | || (CurrentBar->arrows[i].type != MenuAction |
2383 | || (CurrentBar->arrows[i].type != MenuAction |
2384 | && CurrentBar->arrows[i].type != |
2384 | && CurrentBar->arrows[i].type != |
2385 | MenuTerminalAction)) |
2385 | MenuTerminalAction)) |
2386 | { |
2386 | { |
2387 | if (Arrows[i].str != NULL && Arrows[i].str[0]) |
2387 | if (Arrows[i].str != NULL && Arrows[i].str[0]) |
2388 | fprintf(stderr, "(default) \\033%s\n", |
2388 | fprintf (stderr, " (default) \\033%s\n", |
2389 | &(Arrows[i].str[2])); |
2389 | & (Arrows[i].str[2])); |
2390 | } |
2390 | } |
2391 | else |
2391 | else |
2392 | { |
2392 | { |
2393 | fprintf(stderr, "%s\n", |
2393 | fprintf (stderr, "%s\n", |
2394 | CurrentBar->arrows[i].str); |
2394 | CurrentBar->arrows[i].str); |
2395 | } |
2395 | } |
2396 | #else /* DEBUG_MENUARROWS */ |
2396 | #else /* DEBUG_MENUARROWS */ |
2397 | if (CurrentBar == NULL |
2397 | if (CurrentBar == NULL |
2398 | || rxvt_action_dispatch(r, |
2398 | || rxvt_action_dispatch (r, |
2399 | &(CurrentBar->arrows[i])) |
2399 | & (CurrentBar->arrows[i])) |
2400 | ) |
2400 | ) |
2401 | { |
2401 | { |
2402 | if (Arrows[i].str != NULL && Arrows[i].str[0] != 0) |
2402 | if (Arrows[i].str != NULL && Arrows[i].str[0] != 0) |
2403 | tt_write ((Arrows[i].str + 1), |
2403 | tt_write ((Arrows[i].str + 1), |
2404 | Arrows[i].str[0]); |
2404 | Arrows[i].str[0]); |
… | |
… | |
2442 | if (ev->button == Button1) |
2442 | if (ev->button == Button1) |
2443 | menu_select (ev); |
2443 | menu_select (ev); |
2444 | break; |
2444 | break; |
2445 | |
2445 | |
2446 | case MotionNotify: |
2446 | case MotionNotify: |
2447 | while (XCheckTypedWindowEvent(display->display, TermWin.parent[0], |
2447 | while (XCheckTypedWindowEvent (display->display, TermWin.parent[0], |
2448 | MotionNotify, (XEvent *) ev)) ; |
2448 | MotionNotify, (XEvent *) ev)) ; |
2449 | |
2449 | |
2450 | if (ActiveMenu) |
2450 | if (ActiveMenu) |
2451 | while (menu_select (ev)) ; |
2451 | while (menu_select (ev)) ; |
2452 | else |
2452 | else |
… | |
… | |
2455 | { |
2455 | { |
2456 | Window unused_root, unused_child; |
2456 | Window unused_root, unused_child; |
2457 | int unused_root_x, unused_root_y; |
2457 | int unused_root_x, unused_root_y; |
2458 | unsigned int unused_mask; |
2458 | unsigned int unused_mask; |
2459 | |
2459 | |
2460 | XQueryPointer(display->display, menuBar.win, |
2460 | XQueryPointer (display->display, menuBar.win, |
2461 | &unused_root, &unused_child, |
2461 | &unused_root, &unused_child, |
2462 | &unused_root_x, &unused_root_y, |
2462 | &unused_root_x, &unused_root_y, |
2463 | &(ev->x), &(ev->y), &unused_mask); |
2463 | & (ev->x), & (ev->y), &unused_mask); |
2464 | menubar_select (ev); |
2464 | menubar_select (ev); |
2465 | } |
2465 | } |
2466 | break; |
2466 | break; |
2467 | } |
2467 | } |
2468 | } |
2468 | } |