ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/main.C
(Generate patch)

Comparing rxvt-unicode/src/main.C (file contents):
Revision 1.142 by root, Sat Feb 19 04:16:49 2005 UTC vs.
Revision 1.148 by root, Wed Nov 30 21:05:39 2005 UTC

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),
252 //if (menuBar.win) 249 //if (menuBar.win)
253 // XDestroyWindow (disp, menuBar.win); 250 // XDestroyWindow (disp, menuBar.win);
254#endif 251#endif
255 delete TermWin.drawable; 252 delete TermWin.drawable;
256 // destroy all windows 253 // destroy all windows
257 if (TermWin.parent[0] 254 if (TermWin.parent[0])
258#if ENABLE_XEMBED
259 && !rs[Rs_embed]
260#endif
261 )
262 XDestroyWindow (disp, TermWin.parent[0]); 255 XDestroyWindow (disp, TermWin.parent[0]);
263 } 256 }
264 257
265 // TODO: free pixcolours, colours should become part of rxvt_display 258 // TODO: free pixcolours, colours should become part of rxvt_display
266 259
267 delete pix_colors_focused; 260 delete pix_colors_focused;
268#ifdef OFF_FOCUS_FADING 261#if OFF_FOCUS_FADING
269 delete pix_colors_unfocused; 262 delete pix_colors_unfocused;
270#endif 263#endif
271 264
272 displays.put (display); 265 displays.put (display);
273 266
421{ 414{
422 if (GET_R->allowedxerror == -1) 415 if (GET_R->allowedxerror == -1)
423 GET_R->allowedxerror = event->error_code; 416 GET_R->allowedxerror = event->error_code;
424 else 417 else
425 { 418 {
426 //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,
427 //TODO: maybe just output the error and continue? 420 // so just output the error and continue
428#if ENABLE_FRILLS 421#if ENABLE_FRILLS
429 print_x_error (display, event); 422 print_x_error (display, event);
430#else 423#else
431 old_xerror_handler (display, event); 424 old_xerror_handler (display, event);
432#endif 425#endif
442 DisplayString (display)); 435 DisplayString (display));
443 rxvt_emergency_cleanup (); 436 rxvt_emergency_cleanup ();
444 _exit (EXIT_FAILURE); 437 _exit (EXIT_FAILURE);
445} 438}
446 439
447/*
448 * Catch a fatal signal and tidy up before quitting
449 */
450void
451rxvt_term::sig_term (sig_watcher &w)
452{
453#ifdef DEBUG_CMD
454 rxvt_warn ("caught signal %d, exiting.\n", w.signum);
455#endif
456 rxvt_emergency_cleanup ();
457 signal (w.signum, SIG_DFL);
458 kill (getpid (), w.signum);
459}
460
461/*----------------------------------------------------------------------*/ 440/*----------------------------------------------------------------------*/
462/* rxvt_init () */
463bool 441bool
464rxvt_term::init (int argc, const char *const *argv) 442rxvt_term::init (int argc, const char *const *argv)
465{ 443{
466 SET_R (this); 444 SET_R (this);
467 445
528 506
529 check_ev.start (); 507 check_ev.start ();
530 508
531 return true; 509 return true;
532} 510}
511
512static 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;
533 551
534void 552void
535rxvt_init () 553rxvt_init ()
536{ 554{
537 /* 555 /*
545 rxvt_privileges (IGNORE); 563 rxvt_privileges (IGNORE);
546 564
547 signal (SIGHUP, SIG_IGN); 565 signal (SIGHUP, SIG_IGN);
548 signal (SIGPIPE, SIG_IGN); 566 signal (SIGPIPE, SIG_IGN);
549 567
568 sig_handlers.sw_chld.start (SIGCHLD);
569 sig_handlers.sw_term.start (SIGTERM);
570 sig_handlers.sw_int.start (SIGINT);
571
550 /* need to trap SIGURG for SVR4 (Unixware) rlogin */ 572 /* need to trap SIGURG for SVR4 (Unixware) rlogin */
551 /* signal (SIGURG, SIG_DFL); */ 573 /* signal (SIGURG, SIG_DFL); */
552 574
553 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 575 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
554 // TODO: handle this with exceptions and tolerate the memory loss 576 // TODO: handle this with exceptions and tolerate the memory loss
555 XSetIOErrorHandler (rxvt_xioerror_handler); 577 XSetIOErrorHandler (rxvt_xioerror_handler);
556}
557
558/* ------------------------------------------------------------------------- *
559 * SIGNAL HANDLING & EXIT HANDLER *
560 * ------------------------------------------------------------------------- */
561/*
562 * Catch a SIGCHLD signal and exit if the direct child has died
563 */
564
565void
566rxvt_term::sig_chld (sig_watcher &w)
567{
568 // we are being called for every SIGCHLD, not just ours
569 int pid;
570
571 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0)
572 for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++)
573 if (pid == (*t)->cmd_pid)
574 {
575 (*t)->destroy ();
576 break;
577 }
578} 578}
579 579
580/* ------------------------------------------------------------------------- * 580/* ------------------------------------------------------------------------- *
581 * MEMORY ALLOCATION WRAPPERS * 581 * MEMORY ALLOCATION WRAPPERS *
582 * ------------------------------------------------------------------------- */ 582 * ------------------------------------------------------------------------- */
589 rxvt_fatal ("memory allocation failure. aborting.\n"); 589 rxvt_fatal ("memory allocation failure. aborting.\n");
590 590
591 return p; 591 return p;
592} 592}
593 593
594void * 594void *
595rxvt_calloc (size_t number, size_t size) 595rxvt_calloc (size_t number, size_t size)
596{ 596{
597 void *p = calloc (number, size); 597 void *p = calloc (number, size);
598 598
599 if (!p) 599 if (!p)
851#endif 851#endif
852} 852}
853 853
854/*----------------------------------------------------------------------*/ 854/*----------------------------------------------------------------------*/
855/* set_fonts () - load and set the various fonts 855/* set_fonts () - load and set the various fonts
856/* 856 *
857 * init = 1 - initialize 857 * init = 1 - initialize
858 * 858 *
859 * fontname == FONT_UP - switch to bigger font 859 * fontname == FONT_UP - switch to bigger font
860 * fontname == FONT_DN - switch to smaller font 860 * fontname == FONT_DN - switch to smaller font
861 */ 861 */
959/* xterm sequences - title, iconName, color (exptl) */ 959/* xterm sequences - title, iconName, color (exptl) */
960void 960void
961rxvt_term::set_title (const char *str) 961rxvt_term::set_title (const char *str)
962{ 962{
963 set_string_property (XA_WM_NAME, str); 963 set_string_property (XA_WM_NAME, str);
964#if ENABLE_FRILLS 964#if ENABLE_EWMH
965 set_utf8_property (xa[XA_NET_WM_NAME], str); 965 set_utf8_property (xa[XA_NET_WM_NAME], str);
966#endif 966#endif
967} 967}
968 968
969void 969void
970rxvt_term::set_icon_name (const char *str) 970rxvt_term::set_icon_name (const char *str)
971{ 971{
972 set_string_property (XA_WM_ICON_NAME, str); 972 set_string_property (XA_WM_ICON_NAME, str);
973#if ENABLE_FRILLS 973#if ENABLE_EWMH
974 set_utf8_property (xa[XA_NET_WM_ICON_NAME], str); 974 set_utf8_property (xa[XA_NET_WM_ICON_NAME], str);
975#endif 975#endif
976} 976}
977 977
978#ifdef XTERM_COLOR_CHANGE 978#ifdef XTERM_COLOR_CHANGE
994 { /* bright colors */ 994 { /* bright colors */
995 i -= 8; 995 i -= 8;
996# ifndef NO_BRIGHTCOLOR 996# ifndef NO_BRIGHTCOLOR
997 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; 997 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i];
998 SET_PIXCOLOR (idx); 998 SET_PIXCOLOR (idx);
999 goto Done; 999 goto done;
1000# endif 1000# endif
1001 } 1001 }
1002 1002
1003 if (i >= 0 && i <= 7) 1003 if (i >= 0 && i <= 7)
1004 { /* normal colors */ 1004 { /* normal colors */
1005 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; 1005 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i];
1006 SET_PIXCOLOR (idx); 1006 SET_PIXCOLOR (idx);
1007 goto Done; 1007 goto done;
1008 } 1008 }
1009 } 1009 }
1010 1010
1011 if (!rXParseAllocColor (&xcol, color)) 1011 if (!rXParseAllocColor (&xcol, color))
1012 return; 1012 return;
1032 pix_colors_focused[idx] = xcol; 1032 pix_colors_focused[idx] = xcol;
1033 SET_PIXCOLOR (idx); 1033 SET_PIXCOLOR (idx);
1034 1034
1035 /* XSetWindowAttributes attr; */ 1035 /* XSetWindowAttributes attr; */
1036 /* Cursor cursor; */ 1036 /* Cursor cursor; */
1037Done: 1037done:
1038
1038#ifdef OFF_FOCUS_FADING 1039#if OFF_FOCUS_FADING
1039 if (rs[Rs_fade]) 1040 if (rs[Rs_fade])
1040 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]);
1041#endif 1042#endif
1042 1043
1043 /*TODO: handle Color_BD, scrollbar background, etc. */ 1044 /*TODO: handle Color_BD, scrollbar background, etc. */
1044 1045
1045 recolour_cursor (); 1046 recolour_cursor ();
1554} 1555}
1555 1556
1556void 1557void
1557rxvt_term::im_cb () 1558rxvt_term::im_cb ()
1558{ 1559{
1559 int i, found, had_im; 1560 int i;
1560 const char *p; 1561 const char *p;
1561 char **s; 1562 char **s;
1562 char buf[IMBUFSIZ]; 1563 char buf[IMBUFSIZ];
1563 1564
1564 SET_R (this); 1565 SET_R (this);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines