… | |
… | |
157 | pointer_ev (this, &rxvt_term::pointer_cb), |
157 | pointer_ev (this, &rxvt_term::pointer_cb), |
158 | #endif |
158 | #endif |
159 | #ifdef USE_XIM |
159 | #ifdef USE_XIM |
160 | im_ev (this, &rxvt_term::im_cb), |
160 | im_ev (this, &rxvt_term::im_cb), |
161 | #endif |
161 | #endif |
162 | sw_term (this, &rxvt_term::sig_term), |
|
|
163 | sw_int (this, &rxvt_term::sig_term), |
|
|
164 | sw_chld (this, &rxvt_term::sig_chld), |
|
|
165 | termwin_ev (this, &rxvt_term::x_cb), |
162 | termwin_ev (this, &rxvt_term::x_cb), |
166 | vt_ev (this, &rxvt_term::x_cb), |
163 | vt_ev (this, &rxvt_term::x_cb), |
167 | check_ev (this, &rxvt_term::check_cb), |
164 | check_ev (this, &rxvt_term::check_cb), |
168 | flush_ev (this, &rxvt_term::flush_cb), |
165 | flush_ev (this, &rxvt_term::flush_cb), |
169 | destroy_ev (this, &rxvt_term::destroy_cb), |
166 | destroy_ev (this, &rxvt_term::destroy_cb), |
… | |
… | |
259 | } |
256 | } |
260 | |
257 | |
261 | // TODO: free pixcolours, colours should become part of rxvt_display |
258 | // TODO: free pixcolours, colours should become part of rxvt_display |
262 | |
259 | |
263 | delete pix_colors_focused; |
260 | delete pix_colors_focused; |
264 | #ifdef OFF_FOCUS_FADING |
261 | #if OFF_FOCUS_FADING |
265 | delete pix_colors_unfocused; |
262 | delete pix_colors_unfocused; |
266 | #endif |
263 | #endif |
267 | |
264 | |
268 | displays.put (display); |
265 | displays.put (display); |
269 | |
266 | |
… | |
… | |
417 | { |
414 | { |
418 | if (GET_R->allowedxerror == -1) |
415 | if (GET_R->allowedxerror == -1) |
419 | GET_R->allowedxerror = event->error_code; |
416 | GET_R->allowedxerror = event->error_code; |
420 | else |
417 | else |
421 | { |
418 | { |
422 | //TODO: GET_R is most likely not the terminal which caused the error |
419 | // GET_R is most likely not the terminal which caused the error, |
423 | //TODO: maybe just output the error and continue? |
420 | // so just output the error and continue |
424 | #if ENABLE_FRILLS |
421 | #if ENABLE_FRILLS |
425 | print_x_error (display, event); |
422 | print_x_error (display, event); |
426 | #else |
423 | #else |
427 | old_xerror_handler (display, event); |
424 | old_xerror_handler (display, event); |
428 | #endif |
425 | #endif |
… | |
… | |
438 | DisplayString (display)); |
435 | DisplayString (display)); |
439 | rxvt_emergency_cleanup (); |
436 | rxvt_emergency_cleanup (); |
440 | _exit (EXIT_FAILURE); |
437 | _exit (EXIT_FAILURE); |
441 | } |
438 | } |
442 | |
439 | |
443 | /* |
|
|
444 | * Catch a fatal signal and tidy up before quitting |
|
|
445 | */ |
|
|
446 | void |
|
|
447 | rxvt_term::sig_term (sig_watcher &w) |
|
|
448 | { |
|
|
449 | #ifdef DEBUG_CMD |
|
|
450 | rxvt_warn ("caught signal %d, exiting.\n", w.signum); |
|
|
451 | #endif |
|
|
452 | rxvt_emergency_cleanup (); |
|
|
453 | signal (w.signum, SIG_DFL); |
|
|
454 | kill (getpid (), w.signum); |
|
|
455 | } |
|
|
456 | |
|
|
457 | /*----------------------------------------------------------------------*/ |
440 | /*----------------------------------------------------------------------*/ |
458 | /* rxvt_init () */ |
|
|
459 | bool |
441 | bool |
460 | rxvt_term::init (int argc, const char *const *argv) |
442 | rxvt_term::init (int argc, const char *const *argv) |
461 | { |
443 | { |
462 | SET_R (this); |
444 | SET_R (this); |
463 | |
445 | |
… | |
… | |
524 | |
506 | |
525 | check_ev.start (); |
507 | check_ev.start (); |
526 | |
508 | |
527 | return true; |
509 | return true; |
528 | } |
510 | } |
|
|
511 | |
|
|
512 | static struct sig_handlers |
|
|
513 | { |
|
|
514 | sig_watcher sw_chld, sw_term, sw_int; |
|
|
515 | |
|
|
516 | void sig_chld (sig_watcher &w) |
|
|
517 | { |
|
|
518 | // we are being called for every SIGCHLD, find the corresponding term |
|
|
519 | int pid; |
|
|
520 | |
|
|
521 | while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) |
|
|
522 | for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) |
|
|
523 | if (pid == (*t)->cmd_pid) |
|
|
524 | { |
|
|
525 | (*t)->destroy (); |
|
|
526 | break; |
|
|
527 | } |
|
|
528 | } |
|
|
529 | |
|
|
530 | /* |
|
|
531 | * Catch a fatal signal and tidy up before quitting |
|
|
532 | */ |
|
|
533 | void |
|
|
534 | sig_term (sig_watcher &w) |
|
|
535 | { |
|
|
536 | #ifdef DEBUG_CMD |
|
|
537 | rxvt_warn ("caught signal %d, exiting.\n", w.signum); |
|
|
538 | #endif |
|
|
539 | rxvt_emergency_cleanup (); |
|
|
540 | signal (w.signum, SIG_DFL); |
|
|
541 | kill (getpid (), w.signum); |
|
|
542 | } |
|
|
543 | |
|
|
544 | sig_handlers () |
|
|
545 | : sw_chld (this, &sig_handlers::sig_chld), |
|
|
546 | sw_term (this, &sig_handlers::sig_term), |
|
|
547 | sw_int (this, &sig_handlers::sig_term) |
|
|
548 | { |
|
|
549 | } |
|
|
550 | } sig_handlers; |
529 | |
551 | |
530 | void |
552 | void |
531 | rxvt_init () |
553 | rxvt_init () |
532 | { |
554 | { |
533 | /* |
555 | /* |
… | |
… | |
541 | rxvt_privileges (IGNORE); |
563 | rxvt_privileges (IGNORE); |
542 | |
564 | |
543 | signal (SIGHUP, SIG_IGN); |
565 | signal (SIGHUP, SIG_IGN); |
544 | signal (SIGPIPE, SIG_IGN); |
566 | signal (SIGPIPE, SIG_IGN); |
545 | |
567 | |
|
|
568 | sig_handlers.sw_chld.start (SIGCHLD); |
|
|
569 | sig_handlers.sw_term.start (SIGTERM); |
|
|
570 | sig_handlers.sw_int.start (SIGINT); |
|
|
571 | |
546 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
572 | /* need to trap SIGURG for SVR4 (Unixware) rlogin */ |
547 | /* signal (SIGURG, SIG_DFL); */ |
573 | /* signal (SIGURG, SIG_DFL); */ |
548 | |
574 | |
549 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
575 | old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); |
550 | // TODO: handle this with exceptions and tolerate the memory loss |
576 | // TODO: handle this with exceptions and tolerate the memory loss |
551 | XSetIOErrorHandler (rxvt_xioerror_handler); |
577 | XSetIOErrorHandler (rxvt_xioerror_handler); |
552 | } |
|
|
553 | |
|
|
554 | /* ------------------------------------------------------------------------- * |
|
|
555 | * SIGNAL HANDLING & EXIT HANDLER * |
|
|
556 | * ------------------------------------------------------------------------- */ |
|
|
557 | /* |
|
|
558 | * Catch a SIGCHLD signal and exit if the direct child has died |
|
|
559 | */ |
|
|
560 | |
|
|
561 | void |
|
|
562 | rxvt_term::sig_chld (sig_watcher &w) |
|
|
563 | { |
|
|
564 | // we are being called for every SIGCHLD, not just ours |
|
|
565 | int pid; |
|
|
566 | |
|
|
567 | while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) |
|
|
568 | for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) |
|
|
569 | if (pid == (*t)->cmd_pid) |
|
|
570 | { |
|
|
571 | (*t)->destroy (); |
|
|
572 | break; |
|
|
573 | } |
|
|
574 | } |
578 | } |
575 | |
579 | |
576 | /* ------------------------------------------------------------------------- * |
580 | /* ------------------------------------------------------------------------- * |
577 | * MEMORY ALLOCATION WRAPPERS * |
581 | * MEMORY ALLOCATION WRAPPERS * |
578 | * ------------------------------------------------------------------------- */ |
582 | * ------------------------------------------------------------------------- */ |
… | |
… | |
585 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
589 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
586 | |
590 | |
587 | return p; |
591 | return p; |
588 | } |
592 | } |
589 | |
593 | |
590 | void * |
594 | void * |
591 | rxvt_calloc (size_t number, size_t size) |
595 | rxvt_calloc (size_t number, size_t size) |
592 | { |
596 | { |
593 | void *p = calloc (number, size); |
597 | void *p = calloc (number, size); |
594 | |
598 | |
595 | if (!p) |
599 | if (!p) |
… | |
… | |
847 | #endif |
851 | #endif |
848 | } |
852 | } |
849 | |
853 | |
850 | /*----------------------------------------------------------------------*/ |
854 | /*----------------------------------------------------------------------*/ |
851 | /* set_fonts () - load and set the various fonts |
855 | /* set_fonts () - load and set the various fonts |
852 | /* |
856 | * |
853 | * init = 1 - initialize |
857 | * init = 1 - initialize |
854 | * |
858 | * |
855 | * fontname == FONT_UP - switch to bigger font |
859 | * fontname == FONT_UP - switch to bigger font |
856 | * fontname == FONT_DN - switch to smaller font |
860 | * fontname == FONT_DN - switch to smaller font |
857 | */ |
861 | */ |
… | |
… | |
990 | { /* bright colors */ |
994 | { /* bright colors */ |
991 | i -= 8; |
995 | i -= 8; |
992 | # ifndef NO_BRIGHTCOLOR |
996 | # ifndef NO_BRIGHTCOLOR |
993 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
997 | pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; |
994 | SET_PIXCOLOR (idx); |
998 | SET_PIXCOLOR (idx); |
995 | goto Done; |
999 | goto done; |
996 | # endif |
1000 | # endif |
997 | } |
1001 | } |
998 | |
1002 | |
999 | if (i >= 0 && i <= 7) |
1003 | if (i >= 0 && i <= 7) |
1000 | { /* normal colors */ |
1004 | { /* normal colors */ |
1001 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
1005 | pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; |
1002 | SET_PIXCOLOR (idx); |
1006 | SET_PIXCOLOR (idx); |
1003 | goto Done; |
1007 | goto done; |
1004 | } |
1008 | } |
1005 | } |
1009 | } |
1006 | |
1010 | |
1007 | if (!rXParseAllocColor (&xcol, color)) |
1011 | if (!rXParseAllocColor (&xcol, color)) |
1008 | return; |
1012 | return; |
… | |
… | |
1028 | pix_colors_focused[idx] = xcol; |
1032 | pix_colors_focused[idx] = xcol; |
1029 | SET_PIXCOLOR (idx); |
1033 | SET_PIXCOLOR (idx); |
1030 | |
1034 | |
1031 | /* XSetWindowAttributes attr; */ |
1035 | /* XSetWindowAttributes attr; */ |
1032 | /* Cursor cursor; */ |
1036 | /* Cursor cursor; */ |
1033 | Done: |
1037 | done: |
|
|
1038 | |
1034 | #ifdef OFF_FOCUS_FADING |
1039 | #if OFF_FOCUS_FADING |
1035 | if (rs[Rs_fade]) |
1040 | if (rs[Rs_fade]) |
1036 | pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade])); |
1041 | pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade]), pix_colors[Color_fade]); |
1037 | #endif |
1042 | #endif |
1038 | |
1043 | |
1039 | /*TODO: handle Color_BD, scrollbar background, etc. */ |
1044 | /*TODO: handle Color_BD, scrollbar background, etc. */ |
1040 | |
1045 | |
1041 | recolour_cursor (); |
1046 | recolour_cursor (); |
… | |
… | |
1550 | } |
1555 | } |
1551 | |
1556 | |
1552 | void |
1557 | void |
1553 | rxvt_term::im_cb () |
1558 | rxvt_term::im_cb () |
1554 | { |
1559 | { |
1555 | int i, found, had_im; |
1560 | int i; |
1556 | const char *p; |
1561 | const char *p; |
1557 | char **s; |
1562 | char **s; |
1558 | char buf[IMBUFSIZ]; |
1563 | char buf[IMBUFSIZ]; |
1559 | |
1564 | |
1560 | SET_R (this); |
1565 | SET_R (this); |