… | |
… | |
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 = (unsigned char *) 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 = (char *)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 = (char *)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 = (unsigned char *)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 = (char *)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(Xdisplay, 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(Xdisplay, 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(Xdisplay, 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(Xdisplay); |
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(Xdisplay, 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(Xdisplay, ActiveMenu->win); |
933 | XMapWindow (display->display, ActiveMenu->win); |
934 | } |
934 | } |
935 | rxvt_Draw_Shadow(Xdisplay, 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(Xdisplay, 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 | { |
|
|
1009 | #ifdef USE_XIM |
|
|
1010 | if (TermWin.fontset) |
|
|
1011 | XmbDrawString(Xdisplay, |
|
|
1012 | ActiveMenu->win, TermWin.fontset, |
|
|
1013 | gc, xoff, |
|
|
1014 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
|
|
1015 | name, len); |
|
|
1016 | else |
|
|
1017 | #endif |
|
|
1018 | XDrawString(Xdisplay, ActiveMenu->win, gc, xoff, |
1008 | draw_string (display->display, ActiveMenu->win, gc, xoff, |
1019 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
1009 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
1020 | name, len); |
1010 | name, len); |
1021 | } |
|
|
1022 | |
1011 | |
1023 | len = item->len2; |
1012 | len = item->len2; |
1024 | name = item->name2; |
1013 | name = item->name2; |
|
|
1014 | |
1025 | if (len && name) |
1015 | if (len && name) |
1026 | { |
|
|
1027 | #ifdef USE_XIM |
|
|
1028 | if (TermWin.fontset) |
|
|
1029 | XmbDrawString(Xdisplay, |
|
|
1030 | ActiveMenu->win, TermWin.fontset, |
|
|
1031 | gc, |
|
|
1032 | ActiveMenu->w - (xoff + Width2Pixel(xright)), |
|
|
1033 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
|
|
1034 | name, len); |
|
|
1035 | else |
|
|
1036 | #endif |
|
|
1037 | XDrawString(Xdisplay, ActiveMenu->win, gc, |
1016 | draw_string (display->display, ActiveMenu->win, gc, |
1038 | ActiveMenu->w - (xoff + Width2Pixel(xright)), |
1017 | ActiveMenu->w - (xoff + Width2Pixel (xright)), |
1039 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
1018 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
1040 | name, len); |
1019 | name, len); |
1041 | } |
1020 | |
1042 | h = HEIGHT_TEXT + 2 * SHADOW; |
1021 | h = HEIGHT_TEXT + 2 * SHADOW; |
1043 | } |
1022 | } |
1044 | y += h; |
1023 | y += h; |
1045 | } |
1024 | } |
1046 | } |
1025 | } |
1047 | |
1026 | |
1048 | void |
1027 | void |
1049 | rxvt_term::menu_display (void (*update)(rxvt_t *)) |
1028 | rxvt_term::menu_display (void (rxvt_term::*update) ()) |
1050 | { |
1029 | { |
1051 | menu_t *ActiveMenu = ActiveMenu; |
1030 | menu_t *ActiveMenu = ActiveMenu; |
1052 | |
1031 | |
1053 | if (ActiveMenu == NULL) |
1032 | if (ActiveMenu == NULL) |
1054 | return; |
1033 | return; |
1055 | if (ActiveMenu->win != None) |
1034 | if (ActiveMenu->win != None) |
1056 | XDestroyWindow(Xdisplay, ActiveMenu->win); |
1035 | XDestroyWindow (display->display, ActiveMenu->win); |
1057 | ActiveMenu->win = None; |
1036 | ActiveMenu->win = None; |
1058 | ActiveMenu->item = NULL; |
1037 | ActiveMenu->item = NULL; |
1059 | |
1038 | |
1060 | if (ActiveMenu->parent == NULL) |
1039 | if (ActiveMenu->parent == NULL) |
1061 | drawbox_menubar (ActiveMenu->x, ActiveMenu->len, +1); |
1040 | drawbox_menubar (ActiveMenu->x, ActiveMenu->len, +1); |
1062 | ActiveMenu = ActiveMenu->parent; |
1041 | ActiveMenu = ActiveMenu->parent; |
1063 | update(r); |
1042 | (this->*update) (); |
1064 | } |
1043 | } |
1065 | |
1044 | |
1066 | void |
1045 | void |
1067 | rxvt_term::menu_hide_all () |
1046 | rxvt_term::menu_hide_all () |
1068 | { |
1047 | { |
1069 | menu_display (rxvt_menu_hide_all); |
1048 | menu_display (&rxvt_term::menu_hide_all); |
1070 | } |
1049 | } |
1071 | |
1050 | |
1072 | void |
1051 | void |
1073 | rxvt_term::menu_hide () |
1052 | rxvt_term::menu_hide () |
1074 | { |
1053 | { |
1075 | menu_display (rxvt_menu_show); |
1054 | menu_display (&rxvt_term::menu_show); |
1076 | } |
1055 | } |
1077 | |
1056 | |
1078 | void |
1057 | void |
1079 | rxvt_term::menu_clear (menu_t *menu) |
1058 | rxvt_term::menu_clear (menu_t *menu) |
1080 | { |
1059 | { |
… | |
… | |
1112 | } |
1091 | } |
1113 | CurrentBar->head = CurrentBar->tail = NULL; |
1092 | CurrentBar->head = CurrentBar->tail = NULL; |
1114 | |
1093 | |
1115 | if (CurrentBar->title) |
1094 | if (CurrentBar->title) |
1116 | { |
1095 | { |
1117 | free(CurrentBar->title); |
1096 | free (CurrentBar->title); |
1118 | CurrentBar->title = NULL; |
1097 | CurrentBar->title = NULL; |
1119 | } |
1098 | } |
1120 | menuarrow_free (0); /* remove all arrow functions */ |
1099 | menuarrow_free (0); /* remove all arrow functions */ |
1121 | } |
1100 | } |
1122 | ActiveMenu = NULL; |
1101 | ActiveMenu = NULL; |
… | |
… | |
1128 | rxvt_term::menubar_find (const char *name) |
1107 | rxvt_term::menubar_find (const char *name) |
1129 | { |
1108 | { |
1130 | bar_t *bar = CurrentBar; |
1109 | bar_t *bar = CurrentBar; |
1131 | |
1110 | |
1132 | #ifdef DEBUG_MENUBAR_STACKING |
1111 | #ifdef DEBUG_MENUBAR_STACKING |
1133 | fprintf(stderr, "looking for [menu:%s] ...", name ? name : "(nil)"); |
1112 | fprintf (stderr, "looking for [menu:%s] ...", name ? name : " (nil)"); |
1134 | #endif |
1113 | #endif |
1135 | if (bar == NULL || name == NULL) |
1114 | if (bar == NULL || name == NULL) |
1136 | return NULL; |
1115 | return NULL; |
1137 | |
1116 | |
1138 | if (STRLEN(name) && STRCMP(name, "*")) |
1117 | if (STRLEN (name) && STRCMP (name, "*")) |
1139 | { |
1118 | { |
1140 | do |
1119 | do |
1141 | { |
1120 | { |
1142 | if (!STRCMP(bar->name, name)) |
1121 | if (!STRCMP (bar->name, name)) |
1143 | { |
1122 | { |
1144 | #ifdef DEBUG_MENUBAR_STACKING |
1123 | #ifdef DEBUG_MENUBAR_STACKING |
1145 | fprintf(stderr, " found!\n"); |
1124 | fprintf (stderr, " found!\n"); |
1146 | #endif |
1125 | #endif |
1147 | return bar; |
1126 | return bar; |
1148 | } |
1127 | } |
1149 | bar = bar->next; |
1128 | bar = bar->next; |
1150 | } |
1129 | } |
1151 | while (bar != CurrentBar); |
1130 | while (bar != CurrentBar); |
1152 | bar = NULL; |
1131 | bar = NULL; |
1153 | } |
1132 | } |
1154 | #ifdef DEBUG_MENUBAR_STACKING |
1133 | #ifdef DEBUG_MENUBAR_STACKING |
1155 | fprintf(stderr, "%s found!\n", (bar ? "" : " NOT")); |
1134 | fprintf (stderr, "%s found!\n", (bar ? "" : " NOT")); |
1156 | #endif |
1135 | #endif |
1157 | |
1136 | |
1158 | return bar; |
1137 | return bar; |
1159 | } |
1138 | } |
1160 | |
1139 | |
… | |
… | |
1165 | bar_t *bar; |
1144 | bar_t *bar; |
1166 | |
1145 | |
1167 | if (CurrentBar == NULL) |
1146 | if (CurrentBar == NULL) |
1168 | { |
1147 | { |
1169 | /* allocate first one */ |
1148 | /* allocate first one */ |
1170 | bar = (bar_t *) rxvt_malloc(sizeof(bar_t)); |
1149 | bar = (bar_t *) rxvt_malloc (sizeof (bar_t)); |
1171 | |
1150 | |
1172 | MEMSET(bar, 0, sizeof(bar_t)); |
1151 | MEMSET (bar, 0, sizeof (bar_t)); |
1173 | /* circular linked-list */ |
1152 | /* circular linked-list */ |
1174 | bar->next = bar->prev = bar; |
1153 | bar->next = bar->prev = bar; |
1175 | bar->head = bar->tail = NULL; |
1154 | bar->head = bar->tail = NULL; |
1176 | bar->title = NULL; |
1155 | bar->title = NULL; |
1177 | CurrentBar = bar; |
1156 | CurrentBar = bar; |
… | |
… | |
1193 | /* create if needed, or reuse the existing empty menubar */ |
1172 | /* create if needed, or reuse the existing empty menubar */ |
1194 | if (CurrentBar->head != NULL) |
1173 | if (CurrentBar->head != NULL) |
1195 | { |
1174 | { |
1196 | /* need to malloc another one */ |
1175 | /* need to malloc another one */ |
1197 | if (Nbars < MENUBAR_MAX) |
1176 | if (Nbars < MENUBAR_MAX) |
1198 | bar = (bar_t *) rxvt_malloc(sizeof(bar_t)); |
1177 | bar = (bar_t *) rxvt_malloc (sizeof (bar_t)); |
1199 | else |
1178 | else |
1200 | bar = NULL; |
1179 | bar = NULL; |
1201 | |
1180 | |
1202 | /* malloc failed or too many menubars, reuse another */ |
1181 | /* malloc failed or too many menubars, reuse another */ |
1203 | if (bar == NULL) |
1182 | if (bar == NULL) |
… | |
… | |
1223 | menubar_clear (); |
1202 | menubar_clear (); |
1224 | } |
1203 | } |
1225 | } |
1204 | } |
1226 | |
1205 | |
1227 | /* give menubar this name */ |
1206 | /* give menubar this name */ |
1228 | STRNCPY(CurrentBar->name, name, MAXNAME); |
1207 | STRNCPY (CurrentBar->name, name, MAXNAME); |
1229 | CurrentBar->name[MAXNAME - 1] = '\0'; |
1208 | CurrentBar->name[MAXNAME - 1] = '\0'; |
1230 | |
1209 | |
1231 | return ret; |
1210 | return ret; |
1232 | } |
1211 | } |
1233 | |
1212 | |
… | |
… | |
1262 | next->prev = prev; |
1241 | next->prev = prev; |
1263 | prev->next = next; |
1242 | prev->next = next; |
1264 | Nbars--; |
1243 | Nbars--; |
1265 | } |
1244 | } |
1266 | |
1245 | |
1267 | free(CurrentBar); |
1246 | free (CurrentBar); |
1268 | CurrentBar = prev; |
1247 | CurrentBar = prev; |
1269 | } |
1248 | } |
1270 | } |
1249 | } |
1271 | while (CurrentBar && !STRCMP(name, "*")); |
1250 | while (CurrentBar && !STRCMP (name, "*")); |
1272 | } |
1251 | } |
1273 | |
1252 | |
1274 | void |
1253 | void |
1275 | rxvt_action_decode(FILE *fp, action_t *act) |
1254 | rxvt_action_decode (FILE *fp, action_t *act) |
1276 | { |
1255 | { |
1277 | unsigned char *str; |
1256 | unsigned char *str; |
1278 | short len; |
1257 | short len; |
1279 | |
1258 | |
1280 | if (act == NULL || (len = act->len) == 0 || (str = act->str) == NULL) |
1259 | if (act == NULL || (len = act->len) == 0 || (str = act->str) == NULL) |
1281 | return; |
1260 | return; |
1282 | |
1261 | |
1283 | if (act->type == MenuTerminalAction) |
1262 | if (act->type == MenuTerminalAction) |
1284 | { |
1263 | { |
1285 | fprintf(fp, "^@"); |
1264 | fprintf (fp, "^@"); |
1286 | /* can strip trailing ^G from XTerm sequence */ |
1265 | /* can strip trailing ^G from XTerm sequence */ |
1287 | if (str[0] == C0_ESC && str[1] == ']' && str[len - 1] == C0_BEL) |
1266 | if (str[0] == C0_ESC && str[1] == ']' && str[len - 1] == C0_BEL) |
1288 | len--; |
1267 | len--; |
1289 | } |
1268 | } |
1290 | else if (str[0] == C0_ESC) |
1269 | else if (str[0] == C0_ESC) |
… | |
… | |
1300 | if (str[len - 1] == '\r') |
1279 | if (str[len - 1] == '\r') |
1301 | len--; |
1280 | len--; |
1302 | /* FALLTHROUGH */ |
1281 | /* FALLTHROUGH */ |
1303 | |
1282 | |
1304 | default: |
1283 | default: |
1305 | fprintf(fp, "M-"); /* meta prefix */ |
1284 | fprintf (fp, "M-"); /* meta prefix */ |
1306 | str++; |
1285 | str++; |
1307 | len--; |
1286 | len--; |
1308 | break; |
1287 | break; |
1309 | } |
1288 | } |
1310 | } |
1289 | } |
… | |
… | |
1319 | unsigned char ch = *str++; |
1298 | unsigned char ch = *str++; |
1320 | |
1299 | |
1321 | switch (ch) |
1300 | switch (ch) |
1322 | { |
1301 | { |
1323 | case C0_ESC: |
1302 | case C0_ESC: |
1324 | fprintf(fp, "\\E"); |
1303 | fprintf (fp, "\\E"); |
1325 | break; /* escape */ |
1304 | break; /* escape */ |
1326 | case '\r': |
1305 | case '\r': |
1327 | fprintf(fp, "\\r"); |
1306 | fprintf (fp, "\\r"); |
1328 | break; /* carriage-return */ |
1307 | break; /* carriage-return */ |
1329 | case '\\': |
1308 | case '\\': |
1330 | fprintf(fp, "\\\\"); |
1309 | fprintf (fp, "\\\\"); |
1331 | break; /* backslash */ |
1310 | break; /* backslash */ |
1332 | case '^': |
1311 | case '^': |
1333 | fprintf(fp, "\\^"); |
1312 | fprintf (fp, "\\^"); |
1334 | break; /* caret */ |
1313 | break; /* caret */ |
1335 | case 127: |
1314 | case 127: |
1336 | fprintf(fp, "^?"); |
1315 | fprintf (fp, "^?"); |
1337 | default: |
1316 | default: |
1338 | if (ch <= 31) |
1317 | if (ch <= 31) |
1339 | fprintf(fp, "^%c", ('@' + ch)); |
1318 | fprintf (fp, "^%c", ('@' + ch)); |
1340 | else if (ch > 127) |
1319 | else if (ch > 127) |
1341 | fprintf(fp, "\\%o", ch); |
1320 | fprintf (fp, "\\%o", ch); |
1342 | else |
1321 | else |
1343 | fprintf(fp, "%c", ch); |
1322 | fprintf (fp, "%c", ch); |
1344 | break; |
1323 | break; |
1345 | } |
1324 | } |
1346 | len--; |
1325 | len--; |
1347 | } |
1326 | } |
1348 | fprintf(fp, "\n"); |
1327 | fprintf (fp, "\n"); |
1349 | } |
1328 | } |
1350 | |
1329 | |
1351 | void |
1330 | void |
1352 | rxvt_menu_dump(FILE *fp, menu_t *menu) |
1331 | rxvt_menu_dump (FILE *fp, menu_t *menu) |
1353 | { |
1332 | { |
1354 | menuitem_t *item; |
1333 | menuitem_t *item; |
1355 | |
1334 | |
1356 | /* create a new menu and clear it */ |
1335 | /* create a new menu and clear it */ |
1357 | fprintf(fp, (menu->parent ? "./%s/*\n" : "/%s/*\n"), menu->name); |
1336 | fprintf (fp, (menu->parent ? "./%s/*\n" : "/%s/*\n"), menu->name); |
1358 | |
1337 | |
1359 | for (item = menu->head; item != NULL; item = item->next) |
1338 | for (item = menu->head; item != NULL; item = item->next) |
1360 | { |
1339 | { |
1361 | switch (item->entry.type) |
1340 | switch (item->entry.type) |
1362 | { |
1341 | { |
1363 | case MenuSubMenu: |
1342 | case MenuSubMenu: |
1364 | if (item->entry.submenu.menu == NULL) |
1343 | if (item->entry.submenu.menu == NULL) |
1365 | fprintf(fp, "> %s == NULL\n", item->name); |
1344 | fprintf (fp, "> %s == NULL\n", item->name); |
1366 | else |
1345 | else |
1367 | rxvt_menu_dump(fp, item->entry.submenu.menu); |
1346 | rxvt_menu_dump (fp, item->entry.submenu.menu); |
1368 | break; |
1347 | break; |
1369 | |
1348 | |
1370 | case MenuLabel: |
1349 | case MenuLabel: |
1371 | fprintf(fp, "{%s}\n", (STRLEN(item->name) ? item->name : "-")); |
1350 | fprintf (fp, "{%s}\n", (STRLEN (item->name) ? item->name : "-")); |
1372 | break; |
1351 | break; |
1373 | |
1352 | |
1374 | case MenuTerminalAction: |
1353 | case MenuTerminalAction: |
1375 | case MenuAction: |
1354 | case MenuAction: |
1376 | fprintf(fp, "{%s}", item->name); |
1355 | fprintf (fp, "{%s}", item->name); |
1377 | if (item->name2 != NULL && STRLEN(item->name2)) |
1356 | if (item->name2 != NULL && STRLEN (item->name2)) |
1378 | fprintf(fp, "{%s}", item->name2); |
1357 | fprintf (fp, "{%s}", item->name2); |
1379 | fprintf(fp, "\t"); |
1358 | fprintf (fp, "\t"); |
1380 | rxvt_action_decode(fp, &(item->entry.action)); |
1359 | rxvt_action_decode (fp, & (item->entry.action)); |
1381 | break; |
1360 | break; |
1382 | } |
1361 | } |
1383 | } |
1362 | } |
1384 | |
1363 | |
1385 | fprintf(fp, (menu->parent ? "../\n" : "/\n\n")); |
1364 | fprintf (fp, (menu->parent ? "../\n" : "/\n\n")); |
1386 | } |
1365 | } |
1387 | |
1366 | |
1388 | void |
1367 | void |
1389 | rxvt_term::menubar_dump (FILE *fp) |
1368 | rxvt_term::menubar_dump (FILE *fp) |
1390 | { |
1369 | { |
1391 | bar_t *bar = CurrentBar; |
1370 | bar_t *bar = CurrentBar; |
1392 | time_t t; |
1371 | time_t t; |
1393 | |
1372 | |
1394 | if (bar == NULL || fp == NULL) |
1373 | if (bar == NULL || fp == NULL) |
1395 | return; |
1374 | return; |
1396 | time(&t); |
1375 | time (&t); |
1397 | |
1376 | |
1398 | fprintf(fp, |
1377 | fprintf (fp, |
1399 | "# " APL_SUBCLASS " (%s) Pid: %u\n# Date: %s\n\n", |
1378 | "# " APL_SUBCLASS " (%s) Pid: %u\n# Date: %s\n\n", |
1400 | rs[Rs_name], (unsigned int)getpid(), ctime(&t)); |
1379 | rs[Rs_name], (unsigned int)getpid (), ctime (&t)); |
1401 | |
1380 | |
1402 | /* dump in reverse order */ |
1381 | /* dump in reverse order */ |
1403 | bar = CurrentBar->prev; |
1382 | bar = CurrentBar->prev; |
1404 | do |
1383 | do |
1405 | { |
1384 | { |
1406 | menu_t *menu; |
1385 | menu_t *menu; |
1407 | int i; |
1386 | int i; |
1408 | |
1387 | |
1409 | fprintf(fp, "[menu:%s]\n", bar->name); |
1388 | fprintf (fp, "[menu:%s]\n", bar->name); |
1410 | |
1389 | |
1411 | if (bar->title != NULL) |
1390 | if (bar->title != NULL) |
1412 | fprintf(fp, "[title:%s]\n", bar->title); |
1391 | fprintf (fp, "[title:%s]\n", bar->title); |
1413 | |
1392 | |
1414 | for (i = 0; i < NARROWS; i++) |
1393 | for (i = 0; i < NARROWS; i++) |
1415 | { |
1394 | { |
1416 | switch (bar->arrows[i].type) |
1395 | switch (bar->arrows[i].type) |
1417 | { |
1396 | { |
1418 | case MenuTerminalAction: |
1397 | case MenuTerminalAction: |
1419 | case MenuAction: |
1398 | case MenuAction: |
1420 | fprintf(fp, "<%c>", Arrows[i].name); |
1399 | fprintf (fp, "<%c>", Arrows[i].name); |
1421 | rxvt_action_decode(fp, &(bar->arrows[i])); |
1400 | rxvt_action_decode (fp, & (bar->arrows[i])); |
1422 | break; |
1401 | break; |
1423 | } |
1402 | } |
1424 | } |
1403 | } |
1425 | fprintf(fp, "\n"); |
1404 | fprintf (fp, "\n"); |
1426 | |
1405 | |
1427 | for (menu = bar->head; menu != NULL; menu = menu->next) |
1406 | for (menu = bar->head; menu != NULL; menu = menu->next) |
1428 | rxvt_menu_dump(fp, menu); |
1407 | rxvt_menu_dump (fp, menu); |
1429 | |
1408 | |
1430 | fprintf(fp, "\n[done:%s]\n\n", bar->name); |
1409 | fprintf (fp, "\n[done:%s]\n\n", bar->name); |
1431 | bar = bar->prev; |
1410 | bar = bar->prev; |
1432 | } |
1411 | } |
1433 | while (bar != CurrentBar->prev); |
1412 | while (bar != CurrentBar->prev); |
1434 | } |
1413 | } |
1435 | #endif /* (MENUBAR_MAX > 1) */ |
1414 | #endif /* (MENUBAR_MAX > 1) */ |
… | |
… | |
1455 | /* read in a menu from a file */ |
1434 | /* read in a menu from a file */ |
1456 | FILE *fp; |
1435 | FILE *fp; |
1457 | char buffer[256]; |
1436 | char buffer[256]; |
1458 | char *p, *file, *tag = NULL; |
1437 | char *p, *file, *tag = NULL; |
1459 | |
1438 | |
1460 | file = (char *)rxvt_File_find(filename, ".menu", rs[Rs_path]); |
1439 | file = (char *)rxvt_File_find (filename, ".menu", rs[Rs_path]); |
1461 | if (file == NULL) |
1440 | if (file == NULL) |
1462 | return; |
1441 | return; |
1463 | fp = fopen(file, "rb"); |
1442 | fp = fopen (file, "rb"); |
1464 | free(file); |
1443 | free (file); |
1465 | if (fp == NULL) |
1444 | if (fp == NULL) |
1466 | return; |
1445 | return; |
1467 | |
1446 | |
1468 | #if (MENUBAR_MAX > 1) |
1447 | #if (MENUBAR_MAX > 1) |
1469 | /* semi-colon delimited */ |
1448 | /* semi-colon delimited */ |
1470 | if ((tag = STRCHR(filename, ';')) != NULL) |
1449 | if ((tag = STRCHR (filename, ';')) != NULL) |
1471 | { |
1450 | { |
1472 | tag++; |
1451 | tag++; |
1473 | if (*tag == '\0') |
1452 | if (*tag == '\0') |
1474 | tag = NULL; |
1453 | tag = NULL; |
1475 | } |
1454 | } |
1476 | #endif /* (MENUBAR_MAX > 1) */ |
1455 | #endif /* (MENUBAR_MAX > 1) */ |
1477 | #ifdef DEBUG_MENU |
1456 | #ifdef DEBUG_MENU |
1478 | fprintf(stderr, "[read:%s]\n", p); |
1457 | fprintf (stderr, "[read:%s]\n", p); |
1479 | if (tag) |
1458 | if (tag) |
1480 | fprintf(stderr, "looking for [menu:%s]\n", tag); |
1459 | fprintf (stderr, "looking for [menu:%s]\n", tag); |
1481 | #endif |
1460 | #endif |
1482 | |
1461 | |
1483 | while ((p = fgets(buffer, sizeof(buffer), fp)) != NULL) |
1462 | while ((p = fgets (buffer, sizeof (buffer), fp)) != NULL) |
1484 | { |
1463 | { |
1485 | int n; |
1464 | int n; |
1486 | |
1465 | |
1487 | if ((n = rxvt_Str_match(p, "[menu")) != 0) |
1466 | if ((n = rxvt_Str_match (p, "[menu")) != 0) |
1488 | { |
1467 | { |
1489 | if (tag) |
1468 | if (tag) |
1490 | { |
1469 | { |
1491 | /* looking for [menu:tag] */ |
1470 | /* looking for [menu:tag] */ |
1492 | if (p[n] == ':' && p[n + 1] != ']') |
1471 | if (p[n] == ':' && p[n + 1] != ']') |
1493 | { |
1472 | { |
1494 | n++; |
1473 | n++; |
1495 | n += rxvt_Str_match(p + n, tag); |
1474 | n += rxvt_Str_match (p + n, tag); |
1496 | if (p[n] == ']') |
1475 | if (p[n] == ']') |
1497 | { |
1476 | { |
1498 | #ifdef DEBUG_MENU |
1477 | #ifdef DEBUG_MENU |
1499 | fprintf(stderr, "[menu:%s]\n", tag); |
1478 | fprintf (stderr, "[menu:%s]\n", tag); |
1500 | #endif |
1479 | #endif |
1501 | break; |
1480 | break; |
1502 | } |
1481 | } |
1503 | } |
1482 | } |
1504 | } |
1483 | } |
… | |
… | |
1511 | while (p != NULL) |
1490 | while (p != NULL) |
1512 | { |
1491 | { |
1513 | int n; |
1492 | int n; |
1514 | |
1493 | |
1515 | #ifdef DEBUG_MENU |
1494 | #ifdef DEBUG_MENU |
1516 | fprintf(stderr, "read line = %s\n", p); |
1495 | fprintf (stderr, "read line = %s\n", p); |
1517 | #endif |
1496 | #endif |
1518 | |
1497 | |
1519 | /* looking for [done:tag] or [done:] */ |
1498 | /* looking for [done:tag] or [done:] */ |
1520 | if ((n = rxvt_Str_match(p, "[done")) != 0) |
1499 | if ((n = rxvt_Str_match (p, "[done")) != 0) |
1521 | { |
1500 | { |
1522 | if (p[n] == ']') |
1501 | if (p[n] == ']') |
1523 | { |
1502 | { |
1524 | menu_readonly = 1; |
1503 | menu_readonly = 1; |
1525 | break; |
1504 | break; |
… | |
… | |
1532 | menu_readonly = 1; |
1511 | menu_readonly = 1; |
1533 | break; |
1512 | break; |
1534 | } |
1513 | } |
1535 | else if (tag) |
1514 | else if (tag) |
1536 | { |
1515 | { |
1537 | n += rxvt_Str_match(p + n, tag); |
1516 | n += rxvt_Str_match (p + n, tag); |
1538 | if (p[n] == ']') |
1517 | if (p[n] == ']') |
1539 | { |
1518 | { |
1540 | #ifdef DEBUG_MENU |
1519 | #ifdef DEBUG_MENU |
1541 | fprintf(stderr, "[done:%s]\n", tag); |
1520 | fprintf (stderr, "[done:%s]\n", tag); |
1542 | #endif |
1521 | #endif |
1543 | menu_readonly = 1; |
1522 | menu_readonly = 1; |
1544 | break; |
1523 | break; |
1545 | } |
1524 | } |
1546 | } |
1525 | } |
… | |
… | |
1554 | /* |
1533 | /* |
1555 | * remove leading/trailing space |
1534 | * remove leading/trailing space |
1556 | * and strip-off leading/trailing quotes |
1535 | * and strip-off leading/trailing quotes |
1557 | * skip blank or comment lines |
1536 | * skip blank or comment lines |
1558 | */ |
1537 | */ |
1559 | rxvt_Str_trim(p); |
1538 | rxvt_Str_trim (p); |
1560 | if (*p && *p != '#') |
1539 | if (*p && *p != '#') |
1561 | { |
1540 | { |
1562 | menu_readonly = 0; /* if case we read another file */ |
1541 | menu_readonly = 0; /* if case we read another file */ |
1563 | menubar_dispatch (p); |
1542 | menubar_dispatch (p); |
1564 | } |
1543 | } |
1565 | /* get another line */ |
1544 | /* get another line */ |
1566 | p = fgets(buffer, sizeof(buffer), fp); |
1545 | p = fgets (buffer, sizeof (buffer), fp); |
1567 | } |
1546 | } |
1568 | |
1547 | |
1569 | fclose(fp); |
1548 | fclose (fp); |
1570 | } |
1549 | } |
1571 | |
1550 | |
1572 | /* |
1551 | /* |
1573 | * user interface for building/deleting and otherwise managing menus |
1552 | * user interface for building/deleting and otherwise managing menus |
1574 | */ |
1553 | */ |
… | |
… | |
1576 | rxvt_term::menubar_dispatch (char *str) |
1555 | rxvt_term::menubar_dispatch (char *str) |
1577 | { |
1556 | { |
1578 | int n, cmd; |
1557 | int n, cmd; |
1579 | char *path, *name, *name2; |
1558 | char *path, *name, *name2; |
1580 | |
1559 | |
1581 | if (menubar_visible(r) && ActiveMenu != NULL) |
1560 | if (menubar_visible () && ActiveMenu != NULL) |
1582 | menubar_expose (); |
1561 | menubar_expose (); |
1583 | else |
1562 | else |
1584 | ActiveMenu = NULL; |
1563 | ActiveMenu = NULL; |
1585 | |
1564 | |
1586 | cmd = *str; |
1565 | cmd = *str; |
… | |
… | |
1615 | if (str[0] == ':') |
1594 | if (str[0] == ':') |
1616 | { /* [:command:] */ |
1595 | { /* [:command:] */ |
1617 | do |
1596 | do |
1618 | { |
1597 | { |
1619 | next++; |
1598 | next++; |
1620 | if ((next = STRCHR(next, ':')) == NULL) |
1599 | if ((next = STRCHR (next, ':')) == NULL) |
1621 | return; /* parse error */ |
1600 | return; /* parse error */ |
1622 | } |
1601 | } |
1623 | while (next[1] != ']'); |
1602 | while (next[1] != ']'); |
1624 | /* remove and skip ':]' */ |
1603 | /* remove and skip ':]' */ |
1625 | *next = '\0'; |
1604 | *next = '\0'; |
1626 | next += 2; |
1605 | next += 2; |
1627 | } |
1606 | } |
1628 | else |
1607 | else |
1629 | { |
1608 | { |
1630 | if ((next = STRCHR(next, ']')) == NULL) |
1609 | if ((next = STRCHR (next, ']')) == NULL) |
1631 | return; /* parse error */ |
1610 | return; /* parse error */ |
1632 | /* remove and skip ']' */ |
1611 | /* remove and skip ']' */ |
1633 | *next = '\0'; |
1612 | *next = '\0'; |
1634 | next++; |
1613 | next++; |
1635 | } |
1614 | } |
… | |
… | |
1643 | menu_readonly = 0; |
1622 | menu_readonly = 0; |
1644 | menubar_dispatch (str + 1); |
1623 | menubar_dispatch (str + 1); |
1645 | menu_readonly = saved; |
1624 | menu_readonly = saved; |
1646 | } |
1625 | } |
1647 | /* these ones don't require menu stacking */ |
1626 | /* these ones don't require menu stacking */ |
1648 | else if (!STRCMP(str, "clear")) |
1627 | else if (!STRCMP (str, "clear")) |
1649 | { |
1628 | { |
1650 | menubar_clear (); |
1629 | menubar_clear (); |
1651 | } |
1630 | } |
1652 | else if (!STRCMP(str, "done") || rxvt_Str_match(str, "done:")) |
1631 | else if (!STRCMP (str, "done") || rxvt_Str_match (str, "done:")) |
1653 | { |
1632 | { |
1654 | menu_readonly = 1; |
1633 | menu_readonly = 1; |
1655 | } |
1634 | } |
1656 | else if (!STRCMP(str, "show")) |
1635 | else if (!STRCMP (str, "show")) |
1657 | { |
1636 | { |
1658 | map_menuBar (1); |
1637 | map_menuBar (1); |
1659 | menu_readonly = 1; |
1638 | menu_readonly = 1; |
1660 | } |
1639 | } |
1661 | else if (!STRCMP(str, "hide")) |
1640 | else if (!STRCMP (str, "hide")) |
1662 | { |
1641 | { |
1663 | map_menuBar (0); |
1642 | map_menuBar (0); |
1664 | menu_readonly = 1; |
1643 | menu_readonly = 1; |
1665 | } |
1644 | } |
1666 | else if ((n = rxvt_Str_match(str, "read:")) != 0) |
1645 | else if ((n = rxvt_Str_match (str, "read:")) != 0) |
1667 | { |
1646 | { |
1668 | /* read in a menu from a file */ |
1647 | /* read in a menu from a file */ |
1669 | str += n; |
1648 | str += n; |
1670 | menubar_read (str); |
1649 | menubar_read (str); |
1671 | } |
1650 | } |
1672 | else if ((n = rxvt_Str_match(str, "title:")) != 0) |
1651 | else if ((n = rxvt_Str_match (str, "title:")) != 0) |
1673 | { |
1652 | { |
1674 | str += n; |
1653 | str += n; |
1675 | if (CurrentBar != NULL && !menu_readonly) |
1654 | if (CurrentBar != NULL && !menu_readonly) |
1676 | { |
1655 | { |
1677 | if (*str) |
1656 | if (*str) |
1678 | { |
1657 | { |
1679 | name = rxvt_realloc(CurrentBar->title, |
1658 | name = (char *)rxvt_realloc (CurrentBar->title, STRLEN (str) + 1); |
1680 | STRLEN(str) + 1); |
|
|
1681 | if (name != NULL) |
1659 | if (name != NULL) |
1682 | { |
1660 | { |
1683 | STRCPY(name, str); |
1661 | STRCPY (name, str); |
1684 | CurrentBar->title = name; |
1662 | CurrentBar->title = name; |
1685 | } |
1663 | } |
1686 | menubar_expose (); |
1664 | menubar_expose (); |
1687 | } |
1665 | } |
1688 | else |
1666 | else |
1689 | { |
1667 | { |
1690 | free(CurrentBar->title); |
1668 | free (CurrentBar->title); |
1691 | CurrentBar->title = NULL; |
1669 | CurrentBar->title = NULL; |
1692 | } |
1670 | } |
1693 | } |
1671 | } |
1694 | } |
1672 | } |
1695 | else if ((n = rxvt_Str_match(str, "pixmap:")) != 0) |
1673 | else if ((n = rxvt_Str_match (str, "pixmap:")) != 0) |
1696 | { |
1674 | { |
1697 | str += n; |
1675 | str += n; |
1698 | xterm_seq (XTerm_Pixmap, str, CHAR_ST); |
1676 | xterm_seq (XTerm_Pixmap, str, CHAR_ST); |
1699 | } |
1677 | } |
1700 | #if (MENUBAR_MAX > 1) |
1678 | #if (MENUBAR_MAX > 1) |
1701 | else if ((n = rxvt_Str_match(str, "rm")) != 0) |
1679 | else if ((n = rxvt_Str_match (str, "rm")) != 0) |
1702 | { |
1680 | { |
1703 | str += n; |
1681 | str += n; |
1704 | switch (str[0]) |
1682 | switch (str[0]) |
1705 | { |
1683 | { |
1706 | case ':': |
1684 | case ':': |
… | |
… | |
1712 | menubar_remove (str); |
1690 | menubar_remove (str); |
1713 | break; |
1691 | break; |
1714 | } |
1692 | } |
1715 | menu_readonly = 1; |
1693 | menu_readonly = 1; |
1716 | } |
1694 | } |
1717 | else if ((n = rxvt_Str_match(str, "menu")) != 0) |
1695 | else if ((n = rxvt_Str_match (str, "menu")) != 0) |
1718 | { |
1696 | { |
1719 | str += n; |
1697 | str += n; |
1720 | switch (str[0]) |
1698 | switch (str[0]) |
1721 | { |
1699 | { |
1722 | case ':': |
1700 | case ':': |
… | |
… | |
1733 | } |
1711 | } |
1734 | |
1712 | |
1735 | if (CurrentBar != NULL) |
1713 | if (CurrentBar != NULL) |
1736 | menu_readonly = 0; /* allow menu build commands */ |
1714 | menu_readonly = 0; /* allow menu build commands */ |
1737 | } |
1715 | } |
1738 | else if (!STRCMP(str, "dump")) |
1716 | else if (!STRCMP (str, "dump")) |
1739 | { |
1717 | { |
1740 | /* dump current menubars to a file */ |
1718 | /* dump current menubars to a file */ |
1741 | FILE *fp; |
1719 | FILE *fp; |
1742 | |
1720 | |
1743 | /* enough space to hold the results */ |
1721 | /* enough space to hold the results */ |
1744 | char buffer[32]; |
1722 | char buffer[32]; |
1745 | |
1723 | |
1746 | sprintf(buffer, "/tmp/" APL_SUBCLASS "-%u", |
1724 | sprintf (buffer, "/tmp/" APL_SUBCLASS "-%u", |
1747 | (unsigned int)getpid()); |
1725 | (unsigned int)getpid ()); |
1748 | |
1726 | |
1749 | if ((fp = fopen(buffer, "wb")) != NULL) |
1727 | if ((fp = fopen (buffer, "wb")) != NULL) |
1750 | { |
1728 | { |
1751 | xterm_seq (XTerm_title, buffer, CHAR_ST); |
1729 | xterm_seq (XTerm_title, buffer, CHAR_ST); |
1752 | menubar_dump (fp); |
1730 | menubar_dump (fp); |
1753 | fclose(fp); |
1731 | fclose (fp); |
1754 | } |
1732 | } |
1755 | } |
1733 | } |
1756 | else if (!STRCMP(str, "next")) |
1734 | else if (!STRCMP (str, "next")) |
1757 | { |
1735 | { |
1758 | if (CurrentBar) |
1736 | if (CurrentBar) |
1759 | { |
1737 | { |
1760 | CurrentBar = CurrentBar->next; |
1738 | CurrentBar = CurrentBar->next; |
1761 | menu_readonly = 1; |
1739 | menu_readonly = 1; |
1762 | } |
1740 | } |
1763 | } |
1741 | } |
1764 | else if (!STRCMP(str, "prev")) |
1742 | else if (!STRCMP (str, "prev")) |
1765 | { |
1743 | { |
1766 | if (CurrentBar) |
1744 | if (CurrentBar) |
1767 | { |
1745 | { |
1768 | CurrentBar = CurrentBar->prev; |
1746 | CurrentBar = CurrentBar->prev; |
1769 | menu_readonly = 1; |
1747 | menu_readonly = 1; |
1770 | } |
1748 | } |
1771 | } |
1749 | } |
1772 | else if (!STRCMP(str, "swap")) |
1750 | else if (!STRCMP (str, "swap")) |
1773 | { |
1751 | { |
1774 | /* swap the top 2 menus */ |
1752 | /* swap the top 2 menus */ |
1775 | if (CurrentBar) |
1753 | if (CurrentBar) |
1776 | { |
1754 | { |
1777 | bar_t *cbprev = CurrentBar->prev; |
1755 | bar_t *cbprev = CurrentBar->prev; |
… | |
… | |
1794 | str = next; |
1772 | str = next; |
1795 | |
1773 | |
1796 | BuildMenu = ActiveMenu = NULL; |
1774 | BuildMenu = ActiveMenu = NULL; |
1797 | menubar_expose (); |
1775 | menubar_expose (); |
1798 | #ifdef DEBUG_MENUBAR_STACKING |
1776 | #ifdef DEBUG_MENUBAR_STACKING |
1799 | fprintf(stderr, "menus are read%s\n", |
1777 | fprintf (stderr, "menus are read%s\n", |
1800 | menu_readonly ? "only" : "/write"); |
1778 | menu_readonly ? "only" : "/write"); |
1801 | #endif |
1779 | #endif |
1802 | |
1780 | |
1803 | } |
1781 | } |
1804 | return; |
1782 | return; |
… | |
… | |
1809 | if (CurrentBar == NULL) |
1787 | if (CurrentBar == NULL) |
1810 | return; |
1788 | return; |
1811 | if (menu_readonly) |
1789 | if (menu_readonly) |
1812 | { |
1790 | { |
1813 | #ifdef DEBUG_MENUBAR_STACKING |
1791 | #ifdef DEBUG_MENUBAR_STACKING |
1814 | fprintf(stderr, "menus are read%s\n", |
1792 | fprintf (stderr, "menus are read%s\n", |
1815 | menu_readonly ? "only" : "/write"); |
1793 | menu_readonly ? "only" : "/write"); |
1816 | #endif |
1794 | #endif |
1817 | return; |
1795 | return; |
1818 | } |
1796 | } |
1819 | #endif /* (MENUBAR_MAX > 1) */ |
1797 | #endif /* (MENUBAR_MAX > 1) */ |
… | |
… | |
1826 | |
1804 | |
1827 | name2 = NULL; |
1805 | name2 = NULL; |
1828 | /* parse STR, allow spaces inside (name) */ |
1806 | /* parse STR, allow spaces inside (name) */ |
1829 | if (path[0] != '\0') |
1807 | if (path[0] != '\0') |
1830 | { |
1808 | { |
1831 | name = STRCHR(path, MENUITEM_BEG); |
1809 | name = STRCHR (path, MENUITEM_BEG); |
1832 | str = STRCHR(path, MENUITEM_END); |
1810 | str = STRCHR (path, MENUITEM_END); |
1833 | if (name != NULL || str != NULL) |
1811 | if (name != NULL || str != NULL) |
1834 | { |
1812 | { |
1835 | if (name == NULL || str == NULL || str <= (name + 1) |
1813 | if (name == NULL || str == NULL || str <= (name + 1) |
1836 | || (name > path && name[-1] != '/')) |
1814 | || (name > path && name[-1] != '/')) |
1837 | { |
1815 | { |
1838 | rxvt_print_error("menu error <%s>\n", path); |
1816 | rxvt_print_error ("menu error <%s>\n", path); |
1839 | break; |
1817 | break; |
1840 | } |
1818 | } |
1841 | if (str[1] == MENUITEM_BEG) |
1819 | if (str[1] == MENUITEM_BEG) |
1842 | { |
1820 | { |
1843 | name2 = (str + 2); |
1821 | name2 = (str + 2); |
1844 | str = STRCHR(name2, MENUITEM_END); |
1822 | str = STRCHR (name2, MENUITEM_END); |
1845 | |
1823 | |
1846 | if (str == NULL) |
1824 | if (str == NULL) |
1847 | { |
1825 | { |
1848 | rxvt_print_error("menu error <%s>\n", path); |
1826 | rxvt_print_error ("menu error <%s>\n", path); |
1849 | break; |
1827 | break; |
1850 | } |
1828 | } |
1851 | name2[-2] = '\0'; /* remove prev MENUITEM_END */ |
1829 | name2[-2] = '\0'; /* remove prev MENUITEM_END */ |
1852 | } |
1830 | } |
1853 | if (name > path && name[-1] == '/') |
1831 | if (name > path && name[-1] == '/') |
1854 | name[-1] = '\0'; |
1832 | name[-1] = '\0'; |
1855 | |
1833 | |
1856 | *name++ = '\0'; /* delimit */ |
1834 | *name++ = '\0'; /* delimit */ |
1857 | *str++ = '\0'; /* delimit */ |
1835 | *str++ = '\0'; /* delimit */ |
1858 | |
1836 | |
1859 | while (isspace(*str)) |
1837 | while (isspace (*str)) |
1860 | str++; /* skip space */ |
1838 | str++; /* skip space */ |
1861 | } |
1839 | } |
1862 | #ifdef DEBUG_MENU |
1840 | #ifdef DEBUG_MENU |
1863 | fprintf(stderr, |
1841 | fprintf (stderr, |
1864 | "`%c' path = <%s>, name = <%s>, name2 = <%s>, action = <%s>\n", |
1842 | "`%c' path = <%s>, name = <%s>, name2 = <%s>, action = <%s>\n", |
1865 | cmd, (path ? path : "(nil)"), (name ? name : "(nil)"), |
1843 | cmd, (path ? path : " (nil)"), (name ? name : " (nil)"), |
1866 | (name2 ? name2 : "(nil)"), (str ? str : "(nil)") |
1844 | (name2 ? name2 : " (nil)"), (str ? str : " (nil)") |
1867 | ); |
1845 | ); |
1868 | #endif |
1846 | #endif |
1869 | |
1847 | |
1870 | } |
1848 | } |
1871 | /* process the different commands */ |
1849 | /* process the different commands */ |
… | |
… | |
1874 | case '+': /* add/replace existing menu or menuitem */ |
1852 | case '+': /* add/replace existing menu or menuitem */ |
1875 | if (path[0] != '\0') |
1853 | if (path[0] != '\0') |
1876 | { |
1854 | { |
1877 | int len; |
1855 | int len; |
1878 | |
1856 | |
1879 | path = menu_find_base (&(BuildMenu), path); |
1857 | path = menu_find_base (& (BuildMenu), path); |
1880 | len = STRLEN(path); |
1858 | len = STRLEN (path); |
1881 | |
1859 | |
1882 | /* don't allow menus called `*' */ |
1860 | /* don't allow menus called `*' */ |
1883 | if (path[0] == '*') |
1861 | if (path[0] == '*') |
1884 | { |
1862 | { |
1885 | menu_clear (BuildMenu); |
1863 | menu_clear (BuildMenu); |
1886 | break; |
1864 | break; |
1887 | } |
1865 | } |
1888 | else if (len >= 2 && !STRCMP((path + len - 2), "/*")) |
1866 | else if (len >= 2 && !STRCMP ((path + len - 2), "/*")) |
1889 | { |
1867 | { |
1890 | path[len - 2] = '\0'; |
1868 | path[len - 2] = '\0'; |
1891 | } |
1869 | } |
1892 | if (path[0] != '\0') |
1870 | if (path[0] != '\0') |
1893 | BuildMenu = menu_add (BuildMenu, path); |
1871 | BuildMenu = menu_add (BuildMenu, path); |
1894 | } |
1872 | } |
1895 | if (name != NULL && name[0] != '\0') |
1873 | if (name != NULL && name[0] != '\0') |
1896 | rxvt_menuitem_add(BuildMenu, |
1874 | rxvt_menuitem_add (BuildMenu, |
1897 | (STRCMP(name, SEPARATOR_NAME) ? name : ""), |
1875 | (STRCMP (name, SEPARATOR_NAME) ? name : ""), |
1898 | name2, str); |
1876 | name2, str); |
1899 | break; |
1877 | break; |
1900 | |
1878 | |
1901 | case '-': /* delete menu entry */ |
1879 | case '-': /* delete menu entry */ |
1902 | if (!STRCMP(path, "/*") && (name == NULL || name[0] == '\0')) |
1880 | if (!STRCMP (path, "/*") && (name == NULL || name[0] == '\0')) |
1903 | { |
1881 | { |
1904 | menubar_clear (); |
1882 | menubar_clear (); |
1905 | BuildMenu = NULL; |
1883 | BuildMenu = NULL; |
1906 | menubar_expose (); |
1884 | menubar_expose (); |
1907 | break; |
1885 | break; |
… | |
… | |
1910 | { |
1888 | { |
1911 | int len; |
1889 | int len; |
1912 | menu_t *menu = BuildMenu; |
1890 | menu_t *menu = BuildMenu; |
1913 | |
1891 | |
1914 | path = menu_find_base (&menu, path); |
1892 | path = menu_find_base (&menu, path); |
1915 | len = STRLEN(path); |
1893 | len = STRLEN (path); |
1916 | |
1894 | |
1917 | /* submenu called `*' clears all menu items */ |
1895 | /* submenu called `*' clears all menu items */ |
1918 | if (path[0] == '*') |
1896 | if (path[0] == '*') |
1919 | { |
1897 | { |
1920 | menu_clear (menu); |
1898 | menu_clear (menu); |
1921 | break; /* done */ |
1899 | break; /* done */ |
1922 | } |
1900 | } |
1923 | else if (len >= 2 && !STRCMP(&path[len - 2], "/*")) |
1901 | else if (len >= 2 && !STRCMP (&path[len - 2], "/*")) |
1924 | { |
1902 | { |
1925 | /* done */ |
1903 | /* done */ |
1926 | break; |
1904 | break; |
1927 | } |
1905 | } |
1928 | else if (path[0] != '\0') |
1906 | else if (path[0] != '\0') |
… | |
… | |
1941 | { |
1919 | { |
1942 | const char *n1; |
1920 | const char *n1; |
1943 | menuitem_t *item; |
1921 | menuitem_t *item; |
1944 | menu_t *BuildMenu = BuildMenu; |
1922 | menu_t *BuildMenu = BuildMenu; |
1945 | |
1923 | |
1946 | n1 = STRCMP(name, SEPARATOR_NAME) ? name : ""; |
1924 | n1 = STRCMP (name, SEPARATOR_NAME) ? name : ""; |
1947 | item = rxvt_menuitem_find(BuildMenu, n1); |
1925 | item = rxvt_menuitem_find (BuildMenu, n1); |
1948 | if (item != NULL && item->entry.type != MenuSubMenu) |
1926 | if (item != NULL && item->entry.type != MenuSubMenu) |
1949 | { |
1927 | { |
1950 | menuitem_free (BuildMenu, item); |
1928 | menuitem_free (BuildMenu, item); |
1951 | |
1929 | |
1952 | /* fix up the width */ |
1930 | /* fix up the width */ |
… | |
… | |
1954 | for (item = BuildMenu->head; item != NULL; |
1932 | for (item = BuildMenu->head; item != NULL; |
1955 | item = item->next) |
1933 | item = item->next) |
1956 | { |
1934 | { |
1957 | short l = item->len + item->len2; |
1935 | short l = item->len + item->len2; |
1958 | |
1936 | |
1959 | MAX_IT(BuildMenu->width, l); |
1937 | MAX_IT (BuildMenu->width, l); |
1960 | } |
1938 | } |
1961 | } |
1939 | } |
1962 | } |
1940 | } |
1963 | menubar_expose (); |
1941 | menubar_expose (); |
1964 | } |
1942 | } |
… | |
… | |
1996 | if (!Arrows_x) |
1974 | if (!Arrows_x) |
1997 | return; |
1975 | return; |
1998 | |
1976 | |
1999 | for (i = 0; i < NARROWS; i++) |
1977 | for (i = 0; i < NARROWS; i++) |
2000 | { |
1978 | { |
2001 | const int w = Width2Pixel(1); |
1979 | const int w = Width2Pixel (1); |
2002 | const int y = (menuBar_TotalHeight() - w) / 2; |
1980 | const int y = (menuBar_TotalHeight () - w) / 2; |
2003 | int x = Arrows_x + (5 * Width2Pixel(i)) / 4; |
1981 | int x = Arrows_x + (5 * Width2Pixel (i)) / 4; |
2004 | |
1982 | |
2005 | if (!name || name == Arrows[i].name) |
1983 | if (!name || name == Arrows[i].name) |
2006 | rxvt_Draw_Triangle(Xdisplay, menuBar.win, top, bot, x, y, w, |
1984 | rxvt_Draw_Triangle (display->display, menuBar.win, top, bot, x, y, w, |
2007 | Arrows[i].name); |
1985 | Arrows[i].name); |
2008 | } |
1986 | } |
2009 | XFlush(Xdisplay); |
1987 | XFlush (display->display); |
2010 | } |
1988 | } |
2011 | |
1989 | |
2012 | void |
1990 | void |
2013 | rxvt_term::menubar_expose () |
1991 | rxvt_term::menubar_expose () |
2014 | { |
1992 | { |
2015 | menu_t *menu; |
1993 | menu_t *menu; |
2016 | int x; |
1994 | int x; |
2017 | |
1995 | |
2018 | if (!menubar_visible(r) || menuBar.win == 0) |
1996 | if (!menubar_visible () || menuBar.win == 0) |
2019 | return; |
1997 | return; |
2020 | |
1998 | |
2021 | if (menubarGC == None) |
1999 | if (menubarGC == None) |
2022 | { |
2000 | { |
2023 | /* Create the graphics context */ |
2001 | /* Create the graphics context */ |
… | |
… | |
2025 | |
2003 | |
2026 | gcvalue.font = TermWin.font->fid; |
2004 | gcvalue.font = TermWin.font->fid; |
2027 | |
2005 | |
2028 | gcvalue.foreground = (XDEPTH <= 2 ? PixColors[Color_fg] |
2006 | gcvalue.foreground = (XDEPTH <= 2 ? PixColors[Color_fg] |
2029 | : PixColors[Color_Black]); |
2007 | : PixColors[Color_Black]); |
2030 | menubarGC = XCreateGC(Xdisplay, menuBar.win, |
2008 | menubarGC = XCreateGC (display->display, menuBar.win, |
2031 | GCForeground | GCFont, &gcvalue); |
2009 | GCForeground | GCFont, &gcvalue); |
2032 | |
2010 | |
2033 | } |
2011 | } |
2034 | /* make sure the font is correct */ |
2012 | /* make sure the font is correct */ |
2035 | XSetFont(Xdisplay, menubarGC, TermWin.font->fid); |
2013 | XSetFont (display->display, menubarGC, TermWin.font->fid); |
2036 | XSetFont(Xdisplay, botShadowGC, TermWin.font->fid); |
2014 | XSetFont (display->display, botShadowGC, TermWin.font->fid); |
2037 | XClearWindow(Xdisplay, menuBar.win); |
2015 | XClearWindow (display->display, menuBar.win); |
2038 | |
2016 | |
2039 | menu_hide_all (); |
2017 | menu_hide_all (); |
2040 | |
2018 | |
2041 | x = 0; |
2019 | x = 0; |
2042 | if (CurrentBar != NULL) |
2020 | if (CurrentBar != NULL) |
… | |
… | |
2046 | int len = menu->len; |
2024 | int len = menu->len; |
2047 | |
2025 | |
2048 | x = (menu->x + menu->len + HSPACE); |
2026 | x = (menu->x + menu->len + HSPACE); |
2049 | |
2027 | |
2050 | #ifdef DEBUG_MENU_LAYOUT |
2028 | #ifdef DEBUG_MENU_LAYOUT |
2051 | rxvt_print_menu_descendants(menu); |
2029 | rxvt_print_menu_descendants (menu); |
2052 | #endif |
2030 | #endif |
2053 | |
2031 | |
2054 | if (x >= TermWin.ncol) |
2032 | if (x >= TermWin.ncol) |
2055 | len = (TermWin.ncol - (menu->x + HSPACE)); |
2033 | len = (TermWin.ncol - (menu->x + HSPACE)); |
2056 | |
2034 | |
2057 | drawbox_menubar (menu->x, len, +1); |
2035 | drawbox_menubar (menu->x, len, +1); |
2058 | #ifdef USE_XIM |
|
|
2059 | if (TermWin.fontset) |
|
|
2060 | XmbDrawString(Xdisplay, |
|
|
2061 | menuBar.win, TermWin.fontset, |
|
|
2062 | menubarGC, |
|
|
2063 | (Width2Pixel(menu->x) + Width2Pixel(HSPACE) / 2), |
|
|
2064 | menuBar_height() - SHADOW, menu->name, len); |
|
|
2065 | else |
|
|
2066 | #endif |
|
|
2067 | XDrawString(Xdisplay, menuBar.win, menubarGC, |
2036 | draw_string (display->display, menuBar.win, menubarGC, |
2068 | (Width2Pixel(menu->x) + Width2Pixel(HSPACE) / 2), |
2037 | (Width2Pixel (menu->x) + Width2Pixel (HSPACE) / 2), |
2069 | menuBar_height() - SHADOW, menu->name, len); |
2038 | menuBar_height () - SHADOW, menu->name, len); |
2070 | |
2039 | |
2071 | if (x >= TermWin.ncol) |
2040 | if (x >= TermWin.ncol) |
2072 | break; |
2041 | break; |
2073 | } |
2042 | } |
2074 | } |
2043 | } |
… | |
… | |
2085 | |
2054 | |
2086 | ncol = (int)TermWin.ncol; |
2055 | ncol = (int)TermWin.ncol; |
2087 | if (x < (ncol - (NARROWS + 1))) |
2056 | if (x < (ncol - (NARROWS + 1))) |
2088 | { |
2057 | { |
2089 | ncol -= (NARROWS + 1); |
2058 | ncol -= (NARROWS + 1); |
2090 | Arrows_x = Width2Pixel(ncol); |
2059 | Arrows_x = Width2Pixel (ncol); |
2091 | } |
2060 | } |
2092 | draw_Arrows (0, +1); |
2061 | draw_Arrows (0, +1); |
2093 | |
2062 | |
2094 | str = (CurrentBar |
2063 | str = (CurrentBar |
2095 | && CurrentBar->title) ? CurrentBar->title : "%n-%v"; |
2064 | && CurrentBar->title) ? CurrentBar->title : "%n-%v"; |
2096 | for (len = 0; str[0] && len < sizeof(title) - 1; str++) |
2065 | for (len = 0; str[0] && len < sizeof (title) - 1; str++) |
2097 | { |
2066 | { |
2098 | const char *s = NULL; |
2067 | const char *s = NULL; |
2099 | |
2068 | |
2100 | switch (str[0]) |
2069 | switch (str[0]) |
2101 | { |
2070 | { |
… | |
… | |
2112 | case '%': |
2081 | case '%': |
2113 | s = "%"; |
2082 | s = "%"; |
2114 | break; /* literal '%' */ |
2083 | break; /* literal '%' */ |
2115 | } |
2084 | } |
2116 | if (s != NULL) |
2085 | if (s != NULL) |
2117 | while (*s && len < sizeof(title) - 1) |
2086 | while (*s && len < sizeof (title) - 1) |
2118 | title[len++] = *s++; |
2087 | title[len++] = *s++; |
2119 | break; |
2088 | break; |
2120 | |
2089 | |
2121 | default: |
2090 | default: |
2122 | title[len++] = str[0]; |
2091 | title[len++] = str[0]; |
… | |
… | |
2125 | } |
2094 | } |
2126 | title[len] = '\0'; |
2095 | title[len] = '\0'; |
2127 | |
2096 | |
2128 | ncol -= (x + len + HSPACE); |
2097 | ncol -= (x + len + HSPACE); |
2129 | if (len > 0 && ncol >= 0) |
2098 | if (len > 0 && ncol >= 0) |
2130 | { |
|
|
2131 | #ifdef USE_XIM |
|
|
2132 | if (TermWin.fontset) |
|
|
2133 | XmbDrawString(Xdisplay, |
|
|
2134 | menuBar.win, TermWin.fontset, |
|
|
2135 | menubarGC, |
|
|
2136 | Width2Pixel(x) + Width2Pixel(ncol + HSPACE) / 2, |
|
|
2137 | menuBar_height() - SHADOW, title, len); |
|
|
2138 | else |
|
|
2139 | #endif |
|
|
2140 | XDrawString(Xdisplay, menuBar.win, menubarGC, |
2099 | draw_string (display->display, menuBar.win, menubarGC, |
2141 | Width2Pixel(x) + Width2Pixel(ncol + HSPACE) / 2, |
2100 | Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2, |
2142 | menuBar_height() - SHADOW, title, len); |
2101 | menuBar_height () - SHADOW, title, len); |
2143 | } |
|
|
2144 | } |
2102 | } |
2145 | } |
2103 | } |
2146 | |
2104 | |
2147 | int |
2105 | int |
2148 | rxvt_term::menubar_mapping (int map) |
2106 | rxvt_term::menubar_mapping (int map) |
2149 | { |
2107 | { |
2150 | int change = 0; |
2108 | int change = 0; |
2151 | |
2109 | |
2152 | if (map && !menubar_visible(r)) |
2110 | if (map && !menubar_visible ()) |
2153 | { |
2111 | { |
2154 | menuBar.state = 1; |
2112 | menuBar.state = 1; |
2155 | if (menuBar.win == 0) |
2113 | if (menuBar.win == 0) |
2156 | return 0; |
2114 | return 0; |
2157 | XMapWindow(Xdisplay, menuBar.win); |
2115 | XMapWindow (display->display, menuBar.win); |
2158 | change = 1; |
2116 | change = 1; |
2159 | } |
2117 | } |
2160 | else if (!map && menubar_visible(r)) |
2118 | else if (!map && menubar_visible ()) |
2161 | { |
2119 | { |
2162 | menubar_expose (); |
2120 | menubar_expose (); |
2163 | menuBar.state = 0; |
2121 | menuBar.state = 0; |
2164 | XUnmapWindow(Xdisplay, menuBar.win); |
2122 | XUnmapWindow (display->display, menuBar.win); |
2165 | change = 1; |
2123 | change = 1; |
2166 | } |
2124 | } |
2167 | else |
2125 | else |
2168 | menubar_expose (); |
2126 | menubar_expose (); |
2169 | |
2127 | |
2170 | return change; |
2128 | return change; |
2171 | } |
2129 | } |
2172 | |
2130 | |
2173 | int |
2131 | int |
2174 | rxvt_term::menu_select (XButtonEvent *ev) |
2132 | rxvt_term::menu_select (XButtonEvent &ev) |
2175 | { |
2133 | { |
2176 | menuitem_t *thisitem, *item = NULL; |
2134 | menuitem_t *thisitem, *item = NULL; |
2177 | int this_y, y; |
2135 | int this_y, y; |
2178 | menu_t *ActiveMenu = ActiveMenu; |
2136 | menu_t *ActiveMenu = ActiveMenu; |
2179 | |
2137 | |
… | |
… | |
2182 | unsigned int unused_mask; |
2140 | unsigned int unused_mask; |
2183 | |
2141 | |
2184 | if (ActiveMenu == NULL) |
2142 | if (ActiveMenu == NULL) |
2185 | return 0; |
2143 | return 0; |
2186 | |
2144 | |
2187 | XQueryPointer(Xdisplay, ActiveMenu->win, |
2145 | XQueryPointer (display->display, ActiveMenu->win, |
2188 | &unused_root, &unused_child, |
2146 | &unused_root, &unused_child, |
2189 | &unused_root_x, &unused_root_y, |
2147 | &unused_root_x, &unused_root_y, |
2190 | &(ev->x), &(ev->y), &unused_mask); |
2148 | &ev.x, &ev.y, &unused_mask); |
2191 | |
2149 | |
2192 | if (ActiveMenu->parent != NULL && (ev->x < 0 || ev->y < 0)) |
2150 | if (ActiveMenu->parent != NULL && (ev.x < 0 || ev.y < 0)) |
2193 | { |
2151 | { |
2194 | menu_hide (); |
2152 | menu_hide (); |
2195 | return 1; |
2153 | return 1; |
2196 | } |
2154 | } |
2197 | /* determine the menu item corresponding to the Y index */ |
2155 | /* determine the menu item corresponding to the Y index */ |
2198 | y = SHADOW; |
2156 | y = SHADOW; |
2199 | if (ev->x >= 0 && ev->x <= (ActiveMenu->w - SHADOW)) |
2157 | if (ev.x >= 0 && ev.x <= (ActiveMenu->w - SHADOW)) |
2200 | { |
2158 | { |
2201 | for (item = ActiveMenu->head; item != NULL; item = item->next) |
2159 | for (item = ActiveMenu->head; item != NULL; item = item->next) |
2202 | { |
2160 | { |
2203 | int h = HEIGHT_TEXT + 2 * SHADOW; |
2161 | int h = HEIGHT_TEXT + 2 * SHADOW; |
2204 | |
2162 | |
2205 | if (isSeparator(item->name)) |
2163 | if (isSeparator (item->name)) |
2206 | h = HEIGHT_SEPARATOR; |
2164 | h = HEIGHT_SEPARATOR; |
2207 | else if (ev->y >= y && ev->y < (y + h)) |
2165 | else if (ev.y >= y && ev.y < (y + h)) |
2208 | break; |
2166 | break; |
2209 | y += h; |
2167 | y += h; |
2210 | } |
2168 | } |
2211 | } |
2169 | } |
2212 | if (item == NULL && ev->type == ButtonRelease) |
2170 | if (item == NULL && ev.type == ButtonRelease) |
2213 | { |
2171 | { |
2214 | menu_hide_all (); |
2172 | menu_hide_all (); |
2215 | return 0; |
2173 | return 0; |
2216 | } |
2174 | } |
2217 | thisitem = item; |
2175 | thisitem = item; |
… | |
… | |
2225 | for (y = 0, item = ActiveMenu->head; item != NULL; |
2183 | for (y = 0, item = ActiveMenu->head; item != NULL; |
2226 | item = item->next) |
2184 | item = item->next) |
2227 | { |
2185 | { |
2228 | int h; |
2186 | int h; |
2229 | |
2187 | |
2230 | if (isSeparator(item->name)) |
2188 | if (isSeparator (item->name)) |
2231 | h = HEIGHT_SEPARATOR; |
2189 | h = HEIGHT_SEPARATOR; |
2232 | else if (item == ActiveMenu->item) |
2190 | else if (item == ActiveMenu->item) |
2233 | { |
2191 | { |
2234 | /* erase old menuitem */ |
2192 | /* erase old menuitem */ |
2235 | drawbox_menuitem (y, 0); /* No Shadow */ |
2193 | drawbox_menuitem (y, 0); /* No Shadow */ |
… | |
… | |
2242 | y += h; |
2200 | y += h; |
2243 | } |
2201 | } |
2244 | } |
2202 | } |
2245 | else |
2203 | else |
2246 | { |
2204 | { |
2247 | switch (ev->type) |
2205 | switch (ev.type) |
2248 | { |
2206 | { |
2249 | case ButtonRelease: |
2207 | case ButtonRelease: |
2250 | switch (item->entry.type) |
2208 | switch (item->entry.type) |
2251 | { |
2209 | { |
2252 | case MenuLabel: |
2210 | case MenuLabel: |
… | |
… | |
2254 | menu_hide_all (); |
2212 | menu_hide_all (); |
2255 | break; |
2213 | break; |
2256 | |
2214 | |
2257 | case MenuAction: |
2215 | case MenuAction: |
2258 | case MenuTerminalAction: |
2216 | case MenuTerminalAction: |
2259 | drawbox_menuitem (_y, -1); |
2217 | drawbox_menuitem (this_y, -1); |
2260 | { |
2218 | { |
2261 | #ifdef HAVE_NANOSLEEP |
2219 | #ifdef HAVE_NANOSLEEP |
2262 | struct timespec rqt; |
2220 | struct timespec rqt; |
2263 | |
2221 | |
2264 | rqt.tv_sec = 0; |
2222 | rqt.tv_sec = 0; |
2265 | rqt.tv_nsec = MENU_DELAY_USEC * 1000; |
2223 | rqt.tv_nsec = MENU_DELAY_USEC * 1000; |
2266 | nanosleep(&rqt, NULL); |
2224 | nanosleep (&rqt, NULL); |
2267 | #else |
2225 | #else |
2268 | /* use select for timing */ |
2226 | /* use select for timing */ |
2269 | struct timeval tv; |
2227 | struct timeval tv; |
2270 | |
2228 | |
2271 | tv.tv_sec = 0; |
2229 | tv.tv_sec = 0; |
2272 | tv.tv_usec = MENU_DELAY_USEC; |
2230 | tv.tv_usec = MENU_DELAY_USEC; |
2273 | select(0, NULL, NULL, NULL, &tv); |
2231 | select (0, NULL, NULL, NULL, &tv); |
2274 | #endif |
2232 | #endif |
2275 | |
2233 | |
2276 | } |
2234 | } |
2277 | /* remove menu before sending keys to the application */ |
2235 | /* remove menu before sending keys to the application */ |
2278 | menu_hide_all (); |
2236 | menu_hide_all (); |
2279 | #ifndef DEBUG_MENU |
2237 | #ifndef DEBUG_MENU |
2280 | action_dispatch (&(item->entry.action)); |
2238 | action_dispatch (& (item->entry.action)); |
2281 | #else /* DEBUG_MENU */ |
2239 | #else /* DEBUG_MENU */ |
2282 | fprintf(stderr, "%s: %s\n", item->name, |
2240 | fprintf (stderr, "%s: %s\n", item->name, |
2283 | item->entry.action.str); |
2241 | item->entry.action.str); |
2284 | #endif /* DEBUG_MENU */ |
2242 | #endif /* DEBUG_MENU */ |
2285 | break; |
2243 | break; |
2286 | } |
2244 | } |
2287 | break; |
2245 | break; |
… | |
… | |
2306 | { |
2264 | { |
2307 | int x; |
2265 | int x; |
2308 | |
2266 | |
2309 | drawtriangle (ActiveMenu->w, y, -1); |
2267 | drawtriangle (ActiveMenu->w, y, -1); |
2310 | |
2268 | |
2311 | x = ev->x + (ActiveMenu->parent |
2269 | x = ev.x + (ActiveMenu->parent |
2312 | ? ActiveMenu->x |
2270 | ? ActiveMenu->x |
2313 | : Width2Pixel(ActiveMenu->x)); |
2271 | : Width2Pixel (ActiveMenu->x)); |
2314 | |
2272 | |
2315 | if (x >= item->entry.submenu.menu->x) |
2273 | if (x >= item->entry.submenu.menu->x) |
2316 | { |
2274 | { |
2317 | ActiveMenu = item->entry.submenu.menu; |
2275 | ActiveMenu = item->entry.submenu.menu; |
2318 | menu_show (); |
2276 | menu_show (); |
… | |
… | |
2322 | } |
2280 | } |
2323 | return 0; |
2281 | return 0; |
2324 | } |
2282 | } |
2325 | |
2283 | |
2326 | void |
2284 | void |
2327 | rxvt_term::menubar_select (XButtonEvent *ev) |
2285 | rxvt_term::menubar_select (XButtonEvent &ev) |
2328 | { |
2286 | { |
2329 | menu_t *menu = NULL; |
2287 | menu_t *menu = NULL; |
2330 | |
2288 | |
2331 | /* determine the pulldown menu corresponding to the X index */ |
2289 | /* determine the pulldown menu corresponding to the X index */ |
2332 | if (ev->y >= 0 && ev->y <= menuBar_height() && CurrentBar != NULL) |
2290 | if (ev.y >= 0 && ev.y <= menuBar_height () && CurrentBar != NULL) |
2333 | { |
2291 | { |
2334 | for (menu = CurrentBar->head; menu != NULL; menu = menu->next) |
2292 | for (menu = CurrentBar->head; menu != NULL; menu = menu->next) |
2335 | { |
2293 | { |
2336 | int x = Width2Pixel(menu->x); |
2294 | int x = Width2Pixel (menu->x); |
2337 | int w = Width2Pixel(menu->len + HSPACE); |
2295 | int w = Width2Pixel (menu->len + HSPACE); |
2338 | |
2296 | |
2339 | if ((ev->x >= x && ev->x < x + w)) |
2297 | if ((ev.x >= x && ev.x < x + w)) |
2340 | break; |
2298 | break; |
2341 | } |
2299 | } |
2342 | } |
2300 | } |
2343 | switch (ev->type) |
2301 | switch (ev.type) |
2344 | { |
2302 | { |
2345 | case ButtonRelease: |
2303 | case ButtonRelease: |
2346 | menu_hide_all (); |
2304 | menu_hide_all (); |
2347 | break; |
2305 | break; |
2348 | |
2306 | |
2349 | case ButtonPress: |
2307 | case ButtonPress: |
2350 | if (menu == NULL && Arrows_x && ev->x >= Arrows_x) |
2308 | if (menu == NULL && Arrows_x && ev.x >= Arrows_x) |
2351 | { |
2309 | { |
2352 | int i; |
2310 | int i; |
2353 | |
2311 | |
2354 | for (i = 0; i < NARROWS; i++) |
2312 | for (i = 0; i < NARROWS; i++) |
2355 | { |
2313 | { |
2356 | if (ev->x >= (Arrows_x + (Width2Pixel(4 * i + i)) / 4) |
2314 | if (ev.x >= (Arrows_x + (Width2Pixel (4 * i + i)) / 4) |
2357 | && ev->x < (Arrows_x |
2315 | && ev.x < (Arrows_x |
2358 | + (Width2Pixel(4 * i + i + 4)) / 4)) |
2316 | + (Width2Pixel (4 * i + i + 4)) / 4)) |
2359 | { |
2317 | { |
2360 | draw_Arrows (Arrows[i].name, -1); |
2318 | draw_Arrows (Arrows[i].name, -1); |
2361 | { |
2319 | { |
2362 | #ifdef HAVE_NANOSLEEP |
2320 | #ifdef HAVE_NANOSLEEP |
2363 | struct timespec rqt; |
2321 | struct timespec rqt; |
2364 | |
2322 | |
2365 | rqt.tv_sec = 0; |
2323 | rqt.tv_sec = 0; |
2366 | rqt.tv_nsec = MENU_DELAY_USEC * 1000; |
2324 | rqt.tv_nsec = MENU_DELAY_USEC * 1000; |
2367 | nanosleep(&rqt, NULL); |
2325 | nanosleep (&rqt, NULL); |
2368 | #else |
2326 | #else |
2369 | /* use select for timing */ |
2327 | /* use select for timing */ |
2370 | struct timeval tv; |
2328 | struct timeval tv; |
2371 | |
2329 | |
2372 | tv.tv_sec = 0; |
2330 | tv.tv_sec = 0; |
2373 | tv.tv_usec = MENU_DELAY_USEC; |
2331 | tv.tv_usec = MENU_DELAY_USEC; |
2374 | select(0, NULL, NULL, NULL, &tv); |
2332 | select (0, NULL, NULL, NULL, &tv); |
2375 | #endif |
2333 | #endif |
2376 | |
2334 | |
2377 | } |
2335 | } |
2378 | draw_Arrows (Arrows[i].name, +1); |
2336 | draw_Arrows (Arrows[i].name, +1); |
2379 | #ifdef DEBUG_MENUARROWS |
2337 | #ifdef DEBUG_MENUARROWS |
2380 | fprintf(stderr, "'%c': ", Arrows[i].name); |
2338 | fprintf (stderr, "'%c': ", Arrows[i].name); |
2381 | |
2339 | |
2382 | if (CurrentBar == NULL |
2340 | if (CurrentBar == NULL |
2383 | || (CurrentBar->arrows[i].type != MenuAction |
2341 | || (CurrentBar->arrows[i].type != MenuAction |
2384 | && CurrentBar->arrows[i].type != |
2342 | && CurrentBar->arrows[i].type != |
2385 | MenuTerminalAction)) |
2343 | MenuTerminalAction)) |
2386 | { |
2344 | { |
2387 | if (Arrows[i].str != NULL && Arrows[i].str[0]) |
2345 | if (Arrows[i].str != NULL && Arrows[i].str[0]) |
2388 | fprintf(stderr, "(default) \\033%s\n", |
2346 | fprintf (stderr, " (default) \\033%s\n", |
2389 | &(Arrows[i].str[2])); |
2347 | & (Arrows[i].str[2])); |
2390 | } |
2348 | } |
2391 | else |
2349 | else |
2392 | { |
2350 | { |
2393 | fprintf(stderr, "%s\n", |
2351 | fprintf (stderr, "%s\n", |
2394 | CurrentBar->arrows[i].str); |
2352 | CurrentBar->arrows[i].str); |
2395 | } |
2353 | } |
2396 | #else /* DEBUG_MENUARROWS */ |
2354 | #else /* DEBUG_MENUARROWS */ |
2397 | if (CurrentBar == NULL |
2355 | if (CurrentBar == NULL || action_dispatch (&CurrentBar->arrows[i])) |
2398 | || rxvt_action_dispatch(r, |
|
|
2399 | &(CurrentBar->arrows[i])) |
|
|
2400 | ) |
|
|
2401 | { |
2356 | { |
2402 | if (Arrows[i].str != NULL && Arrows[i].str[0] != 0) |
2357 | if (Arrows[i].str != NULL && Arrows[i].str[0] != 0) |
2403 | tt_write ((Arrows[i].str + 1), |
2358 | tt_write ((Arrows[i].str + 1), |
2404 | Arrows[i].str[0]); |
2359 | Arrows[i].str[0]); |
2405 | } |
2360 | } |
… | |
… | |
2427 | /* |
2382 | /* |
2428 | * general dispatch routine, |
2383 | * general dispatch routine, |
2429 | * it would be nice to have `sticky' menus |
2384 | * it would be nice to have `sticky' menus |
2430 | */ |
2385 | */ |
2431 | void |
2386 | void |
2432 | rxvt_term::menubar_control (XButtonEvent *ev) |
2387 | rxvt_term::menubar_control (XButtonEvent &ev) |
2433 | { |
2388 | { |
2434 | switch (ev->type) |
2389 | switch (ev.type) |
2435 | { |
2390 | { |
2436 | case ButtonPress: |
2391 | case ButtonPress: |
2437 | if (ev->button == Button1) |
2392 | if (ev.button == Button1) |
2438 | menubar_select (ev); |
2393 | menubar_select (ev); |
2439 | break; |
2394 | break; |
2440 | |
2395 | |
2441 | case ButtonRelease: |
2396 | case ButtonRelease: |
2442 | if (ev->button == Button1) |
2397 | if (ev.button == Button1) |
2443 | menu_select (ev); |
2398 | menu_select (ev); |
2444 | break; |
2399 | break; |
2445 | |
2400 | |
2446 | case MotionNotify: |
2401 | case MotionNotify: |
2447 | while (XCheckTypedWindowEvent(Xdisplay, TermWin.parent[0], |
2402 | while (XCheckTypedWindowEvent (display->display, TermWin.parent[0], |
2448 | MotionNotify, (XEvent *) ev)) ; |
2403 | MotionNotify, (XEvent *)&ev)) ; |
2449 | |
2404 | |
2450 | if (ActiveMenu) |
2405 | if (ActiveMenu) |
2451 | while (menu_select (ev)) ; |
2406 | while (menu_select (ev)) ; |
2452 | else |
2407 | else |
2453 | ev->y = -1; |
2408 | ev.y = -1; |
2454 | if (ev->y < 0) |
2409 | if (ev.y < 0) |
2455 | { |
2410 | { |
2456 | Window unused_root, unused_child; |
2411 | Window unused_root, unused_child; |
2457 | int unused_root_x, unused_root_y; |
2412 | int unused_root_x, unused_root_y; |
2458 | unsigned int unused_mask; |
2413 | unsigned int unused_mask; |
2459 | |
2414 | |
2460 | XQueryPointer(Xdisplay, menuBar.win, |
2415 | XQueryPointer (display->display, menuBar.win, |
2461 | &unused_root, &unused_child, |
2416 | &unused_root, &unused_child, |
2462 | &unused_root_x, &unused_root_y, |
2417 | &unused_root_x, &unused_root_y, |
2463 | &(ev->x), &(ev->y), &unused_mask); |
2418 | &ev.x, &ev.y, &unused_mask); |
2464 | menubar_select (ev); |
2419 | menubar_select (ev); |
2465 | } |
2420 | } |
2466 | break; |
2421 | break; |
2467 | } |
2422 | } |
2468 | } |
2423 | } |