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.134 by root, Fri Feb 4 11:41:23 2005 UTC vs.
Revision 1.148 by root, Wed Nov 30 21:05:39 2005 UTC

30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 *---------------------------------------------------------------------*/ 31 *---------------------------------------------------------------------*/
32 32
33#include "../config.h" /* NECESSARY */ 33#include "../config.h" /* NECESSARY */
34#include "rxvt.h" /* NECESSARY */ 34#include "rxvt.h" /* NECESSARY */
35#include "main.intpro" /* PROTOS for internal routines */
36 35
37#include <csignal> 36#include <csignal>
38#include <cstring> 37#include <cstring>
39 38
40#ifdef TTY_GID_SUPPORT 39#ifdef TTY_GID_SUPPORT
158 pointer_ev (this, &rxvt_term::pointer_cb), 157 pointer_ev (this, &rxvt_term::pointer_cb),
159#endif 158#endif
160#ifdef USE_XIM 159#ifdef USE_XIM
161 im_ev (this, &rxvt_term::im_cb), 160 im_ev (this, &rxvt_term::im_cb),
162#endif 161#endif
163 sw_term (this, &rxvt_term::sig_term),
164 sw_int (this, &rxvt_term::sig_term),
165 sw_chld (this, &rxvt_term::sig_chld),
166 termwin_ev (this, &rxvt_term::x_cb), 162 termwin_ev (this, &rxvt_term::x_cb),
167 vt_ev (this, &rxvt_term::x_cb), 163 vt_ev (this, &rxvt_term::x_cb),
168 check_ev (this, &rxvt_term::check_cb), 164 check_ev (this, &rxvt_term::check_cb),
169 flush_ev (this, &rxvt_term::flush_cb), 165 flush_ev (this, &rxvt_term::flush_cb),
170 destroy_ev (this, &rxvt_term::destroy_cb), 166 destroy_ev (this, &rxvt_term::destroy_cb),
260 } 256 }
261 257
262 // TODO: free pixcolours, colours should become part of rxvt_display 258 // TODO: free pixcolours, colours should become part of rxvt_display
263 259
264 delete pix_colors_focused; 260 delete pix_colors_focused;
265#ifdef OFF_FOCUS_FADING 261#if OFF_FOCUS_FADING
266 delete pix_colors_unfocused; 262 delete pix_colors_unfocused;
267#endif 263#endif
268 264
269 displays.put (display); 265 displays.put (display);
270 266
362{ 358{
363 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) 359 for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++)
364 (*t)->emergency_cleanup (); 360 (*t)->emergency_cleanup ();
365} 361}
366 362
363#if ENABLE_FRILLS
364static void
365print_x_error (Display *dpy, XErrorEvent *event)
366{
367 char buffer[BUFSIZ];
368 char mesg[BUFSIZ];
369 char number[32];
370 char *mtype = "XlibMessage";
371 XGetErrorText(dpy, event->error_code, buffer, BUFSIZ);
372 XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ);
373 rxvt_warn ("An X Error occured, trying to continue after report.\n");
374 rxvt_warn ("%s: %s\n", mesg, buffer);
375 XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", mesg, BUFSIZ);
376 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->request_code);
377 sprintf(number, "%d", event->request_code);
378 XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ);
379 rxvt_warn ("(which is %s)\n", buffer);
380 if (event->request_code >= 128) {
381 XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d",
382 mesg, BUFSIZ);
383 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->minor_code);
384 }
385 if ((event->error_code == BadWindow) ||
386 (event->error_code == BadPixmap) ||
387 (event->error_code == BadCursor) ||
388 (event->error_code == BadFont) ||
389 (event->error_code == BadDrawable) ||
390 (event->error_code == BadColor) ||
391 (event->error_code == BadGC) ||
392 (event->error_code == BadIDChoice) ||
393 (event->error_code == BadValue) ||
394 (event->error_code == BadAtom)) {
395 if (event->error_code == BadValue)
396 XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x",
397 mesg, BUFSIZ);
398 else if (event->error_code == BadAtom)
399 XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x",
400 mesg, BUFSIZ);
401 else
402 XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x",
403 mesg, BUFSIZ);
404 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->resourceid);
405 }
406 XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d",
407 mesg, BUFSIZ);
408 rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->serial);
409}
410#endif
411
367int 412int
368rxvt_xerror_handler (Display *display, XErrorEvent *event) 413rxvt_xerror_handler (Display *display, XErrorEvent *event)
369{ 414{
370 if (GET_R->allowedxerror == -1) 415 if (GET_R->allowedxerror == -1)
371 GET_R->allowedxerror = event->error_code; 416 GET_R->allowedxerror = event->error_code;
372 else 417 else
373 { 418 {
374 //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,
375 //TODO: maybe just output the error and continue? 420 // so just output the error and continue
421#if ENABLE_FRILLS
422 print_x_error (display, event);
423#else
376 old_xerror_handler (display, event); 424 old_xerror_handler (display, event);
377 GET_R->destroy (); 425#endif
378 } 426 }
379 427
380 return 0; 428 return 0;
381} 429}
382 430
387 DisplayString (display)); 435 DisplayString (display));
388 rxvt_emergency_cleanup (); 436 rxvt_emergency_cleanup ();
389 _exit (EXIT_FAILURE); 437 _exit (EXIT_FAILURE);
390} 438}
391 439
392/*
393 * Catch a fatal signal and tidy up before quitting
394 */
395void
396rxvt_term::sig_term (sig_watcher &w)
397{
398#ifdef DEBUG_CMD
399 rxvt_warn ("caught signal %d, exiting.\n", w.signum);
400#endif
401 rxvt_emergency_cleanup ();
402 signal (w.signum, SIG_DFL);
403 kill (getpid (), w.signum);
404}
405
406/*----------------------------------------------------------------------*/ 440/*----------------------------------------------------------------------*/
407/* rxvt_init () */
408bool 441bool
409rxvt_term::init (int argc, const char *const *argv) 442rxvt_term::init (int argc, const char *const *argv)
410{ 443{
411 SET_R (this); 444 SET_R (this);
412 445
473 506
474 check_ev.start (); 507 check_ev.start ();
475 508
476 return true; 509 return true;
477} 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;
478 551
479void 552void
480rxvt_init () 553rxvt_init ()
481{ 554{
482 /* 555 /*
490 rxvt_privileges (IGNORE); 563 rxvt_privileges (IGNORE);
491 564
492 signal (SIGHUP, SIG_IGN); 565 signal (SIGHUP, SIG_IGN);
493 signal (SIGPIPE, SIG_IGN); 566 signal (SIGPIPE, SIG_IGN);
494 567
568 sig_handlers.sw_chld.start (SIGCHLD);
569 sig_handlers.sw_term.start (SIGTERM);
570 sig_handlers.sw_int.start (SIGINT);
571
495 /* need to trap SIGURG for SVR4 (Unixware) rlogin */ 572 /* need to trap SIGURG for SVR4 (Unixware) rlogin */
496 /* signal (SIGURG, SIG_DFL); */ 573 /* signal (SIGURG, SIG_DFL); */
497 574
498 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 575 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
499 // TODO: handle this with exceptions and tolerate the memory loss 576 // TODO: handle this with exceptions and tolerate the memory loss
500 XSetIOErrorHandler (rxvt_xioerror_handler); 577 XSetIOErrorHandler (rxvt_xioerror_handler);
501}
502
503/* ------------------------------------------------------------------------- *
504 * SIGNAL HANDLING & EXIT HANDLER *
505 * ------------------------------------------------------------------------- */
506/*
507 * Catch a SIGCHLD signal and exit if the direct child has died
508 */
509
510void
511rxvt_term::sig_chld (sig_watcher &w)
512{
513 // we are being called for every SIGCHLD, not just ours
514 int pid;
515
516 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0)
517 for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++)
518 if (pid == (*t)->cmd_pid)
519 {
520 (*t)->destroy ();
521 break;
522 }
523} 578}
524 579
525/* ------------------------------------------------------------------------- * 580/* ------------------------------------------------------------------------- *
526 * MEMORY ALLOCATION WRAPPERS * 581 * MEMORY ALLOCATION WRAPPERS *
527 * ------------------------------------------------------------------------- */ 582 * ------------------------------------------------------------------------- */
534 rxvt_fatal ("memory allocation failure. aborting.\n"); 589 rxvt_fatal ("memory allocation failure. aborting.\n");
535 590
536 return p; 591 return p;
537} 592}
538 593
539/* INTPROTO */ 594void *
540void *
541rxvt_calloc (size_t number, size_t size) 595rxvt_calloc (size_t number, size_t size)
542{ 596{
543 void *p = calloc (number, size); 597 void *p = calloc (number, size);
544 598
545 if (!p) 599 if (!p)
546 rxvt_fatal ("memory allocation failure. aborting.\n"); 600 rxvt_fatal ("memory allocation failure. aborting.\n");
547 601
548 return p; 602 return p;
549} 603}
550 604
551/* INTPROTO */
552void * 605void *
553rxvt_realloc (void *ptr, size_t size) 606rxvt_realloc (void *ptr, size_t size)
554{ 607{
555 void *p = realloc (ptr, size); 608 void *p = realloc (ptr, size);
556 609
660 if (!parsed_geometry) 713 if (!parsed_geometry)
661 { 714 {
662 parsed_geometry = 1; 715 parsed_geometry = 1;
663 if (rs[Rs_geometry]) 716 if (rs[Rs_geometry])
664 flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h); 717 flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h);
718
665 if (flags & WidthValue) 719 if (flags & WidthValue)
666 { 720 {
667 TermWin.ncol = BOUND_POSITIVE_INT16 (w); 721 TermWin.ncol = BOUND_POSITIVE_INT16 (w);
668 szHint.flags |= USSize; 722 szHint.flags |= USSize;
669 } 723 }
724
670 if (flags & HeightValue) 725 if (flags & HeightValue)
671 { 726 {
672 TermWin.nrow = BOUND_POSITIVE_INT16 (h); 727 TermWin.nrow = BOUND_POSITIVE_INT16 (h);
673 szHint.flags |= USSize; 728 szHint.flags |= USSize;
674 } 729 }
730
675 if (flags & XValue) 731 if (flags & XValue)
676 { 732 {
677 szHint.x = x; 733 szHint.x = x;
678 szHint.flags |= USPosition; 734 szHint.flags |= USPosition;
679 if (flags & XNegative) 735 if (flags & XNegative)
680 { 736 {
681 recalc_x = 1; 737 recalc_x = 1;
682 szHint.win_gravity = NorthEastGravity; 738 szHint.win_gravity = NorthEastGravity;
683 } 739 }
684 } 740 }
741
685 if (flags & YValue) 742 if (flags & YValue)
686 { 743 {
687 szHint.y = y; 744 szHint.y = y;
688 szHint.flags |= USPosition; 745 szHint.flags |= USPosition;
689 if (flags & YNegative) 746 if (flags & YNegative)
788 (void)ioctl (pty.pty, TIOCSWINSZ, &ws); 845 (void)ioctl (pty.pty, TIOCSWINSZ, &ws);
789 846
790#if 0 847#if 0
791 // TIOCSWINSZ⎈ is supposed to do this automatically and correctly 848 // TIOCSWINSZ⎈ is supposed to do this automatically and correctly
792 if (cmd_pid) /* force through to the command */ 849 if (cmd_pid) /* force through to the command */
793 kill (cmd_pid, SIGWINCH); 850 kill (-cmd_pid, SIGWINCH);
794#endif 851#endif
795} 852}
796 853
797/*----------------------------------------------------------------------*/ 854/*----------------------------------------------------------------------*/
798/* set_fonts () - load and set the various fonts 855/* set_fonts () - load and set the various fonts
799/* 856 *
800 * init = 1 - initialize 857 * init = 1 - initialize
801 * 858 *
802 * fontname == FONT_UP - switch to bigger font 859 * fontname == FONT_UP - switch to bigger font
803 * fontname == FONT_DN - switch to smaller font 860 * fontname == FONT_DN - switch to smaller font
804 */ 861 */
902/* xterm sequences - title, iconName, color (exptl) */ 959/* xterm sequences - title, iconName, color (exptl) */
903void 960void
904rxvt_term::set_title (const char *str) 961rxvt_term::set_title (const char *str)
905{ 962{
906 set_string_property (XA_WM_NAME, str); 963 set_string_property (XA_WM_NAME, str);
907#if ENABLE_FRILLS 964#if ENABLE_EWMH
908 set_utf8_property (xa[XA_NET_WM_NAME], str); 965 set_utf8_property (xa[XA_NET_WM_NAME], str);
909#endif 966#endif
910} 967}
911 968
912void 969void
913rxvt_term::set_icon_name (const char *str) 970rxvt_term::set_icon_name (const char *str)
914{ 971{
915 set_string_property (XA_WM_ICON_NAME, str); 972 set_string_property (XA_WM_ICON_NAME, str);
916#if ENABLE_FRILLS 973#if ENABLE_EWMH
917 set_utf8_property (xa[XA_NET_WM_ICON_NAME], str); 974 set_utf8_property (xa[XA_NET_WM_ICON_NAME], str);
918#endif 975#endif
919} 976}
920 977
921#ifdef XTERM_COLOR_CHANGE 978#ifdef XTERM_COLOR_CHANGE
937 { /* bright colors */ 994 { /* bright colors */
938 i -= 8; 995 i -= 8;
939# ifndef NO_BRIGHTCOLOR 996# ifndef NO_BRIGHTCOLOR
940 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; 997 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i];
941 SET_PIXCOLOR (idx); 998 SET_PIXCOLOR (idx);
942 goto Done; 999 goto done;
943# endif 1000# endif
944 } 1001 }
945 1002
946 if (i >= 0 && i <= 7) 1003 if (i >= 0 && i <= 7)
947 { /* normal colors */ 1004 { /* normal colors */
948 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; 1005 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i];
949 SET_PIXCOLOR (idx); 1006 SET_PIXCOLOR (idx);
950 goto Done; 1007 goto done;
951 } 1008 }
952 } 1009 }
953 1010
954 if (!rXParseAllocColor (&xcol, color)) 1011 if (!rXParseAllocColor (&xcol, color))
955 return; 1012 return;
975 pix_colors_focused[idx] = xcol; 1032 pix_colors_focused[idx] = xcol;
976 SET_PIXCOLOR (idx); 1033 SET_PIXCOLOR (idx);
977 1034
978 /* XSetWindowAttributes attr; */ 1035 /* XSetWindowAttributes attr; */
979 /* Cursor cursor; */ 1036 /* Cursor cursor; */
980Done: 1037done:
1038
981#ifdef OFF_FOCUS_FADING 1039#if OFF_FOCUS_FADING
982 if (rs[Rs_fade]) 1040 if (rs[Rs_fade])
983 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]);
984#endif 1042#endif
985 1043
986 /*TODO: handle Color_BD, scrollbar background, etc. */ 1044 /*TODO: handle Color_BD, scrollbar background, etc. */
987 1045
988 recolour_cursor (); 1046 recolour_cursor ();
1193 XWindowAttributes wattr; 1251 XWindowAttributes wattr;
1194 1252
1195 if (width == 0 || height == 0) 1253 if (width == 0 || height == 0)
1196 { 1254 {
1197 XGetWindowAttributes (display->display, display->root, &wattr); 1255 XGetWindowAttributes (display->display, display->root, &wattr);
1256
1198 if (width == 0) 1257 if (width == 0)
1199 width = wattr.width - szHint.base_width; 1258 width = wattr.width - szHint.base_width;
1200 if (height == 0) 1259 if (height == 0)
1201 height = wattr.height - szHint.base_height; 1260 height = wattr.height - szHint.base_height;
1202 } 1261 }
1496} 1555}
1497 1556
1498void 1557void
1499rxvt_term::im_cb () 1558rxvt_term::im_cb ()
1500{ 1559{
1501 int i, found, had_im; 1560 int i;
1502 const char *p; 1561 const char *p;
1503 char **s; 1562 char **s;
1504 char buf[IMBUFSIZ]; 1563 char buf[IMBUFSIZ];
1564
1565 SET_R (this);
1505 1566
1506 im_destroy (); 1567 im_destroy ();
1507 1568
1508 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()")); 1569 D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()"));
1509 if (Input_Context) 1570 if (Input_Context)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines