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.136 by root, Mon Feb 14 18:47:54 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),
253 //if (menuBar.win) 249 //if (menuBar.win)
254 // XDestroyWindow (disp, menuBar.win); 250 // XDestroyWindow (disp, menuBar.win);
255#endif 251#endif
256 delete TermWin.drawable; 252 delete TermWin.drawable;
257 // destroy all windows 253 // destroy all windows
258 if (TermWin.parent[0] && !rs[Rs_embed]) 254 if (TermWin.parent[0])
259 XDestroyWindow (disp, TermWin.parent[0]); 255 XDestroyWindow (disp, TermWin.parent[0]);
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
418{ 414{
419 if (GET_R->allowedxerror == -1) 415 if (GET_R->allowedxerror == -1)
420 GET_R->allowedxerror = event->error_code; 416 GET_R->allowedxerror = event->error_code;
421 else 417 else
422 { 418 {
423 //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,
424 //TODO: maybe just output the error and continue? 420 // so just output the error and continue
425#if ENABLE_FRILLS 421#if ENABLE_FRILLS
426 print_x_error (display, event); 422 print_x_error (display, event);
427#else 423#else
428 old_xerror_handler (display, event); 424 old_xerror_handler (display, event);
429#endif 425#endif
439 DisplayString (display)); 435 DisplayString (display));
440 rxvt_emergency_cleanup (); 436 rxvt_emergency_cleanup ();
441 _exit (EXIT_FAILURE); 437 _exit (EXIT_FAILURE);
442} 438}
443 439
444/*
445 * Catch a fatal signal and tidy up before quitting
446 */
447void
448rxvt_term::sig_term (sig_watcher &w)
449{
450#ifdef DEBUG_CMD
451 rxvt_warn ("caught signal %d, exiting.\n", w.signum);
452#endif
453 rxvt_emergency_cleanup ();
454 signal (w.signum, SIG_DFL);
455 kill (getpid (), w.signum);
456}
457
458/*----------------------------------------------------------------------*/ 440/*----------------------------------------------------------------------*/
459/* rxvt_init () */
460bool 441bool
461rxvt_term::init (int argc, const char *const *argv) 442rxvt_term::init (int argc, const char *const *argv)
462{ 443{
463 SET_R (this); 444 SET_R (this);
464 445
525 506
526 check_ev.start (); 507 check_ev.start ();
527 508
528 return true; 509 return true;
529} 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;
530 551
531void 552void
532rxvt_init () 553rxvt_init ()
533{ 554{
534 /* 555 /*
542 rxvt_privileges (IGNORE); 563 rxvt_privileges (IGNORE);
543 564
544 signal (SIGHUP, SIG_IGN); 565 signal (SIGHUP, SIG_IGN);
545 signal (SIGPIPE, SIG_IGN); 566 signal (SIGPIPE, SIG_IGN);
546 567
568 sig_handlers.sw_chld.start (SIGCHLD);
569 sig_handlers.sw_term.start (SIGTERM);
570 sig_handlers.sw_int.start (SIGINT);
571
547 /* need to trap SIGURG for SVR4 (Unixware) rlogin */ 572 /* need to trap SIGURG for SVR4 (Unixware) rlogin */
548 /* signal (SIGURG, SIG_DFL); */ 573 /* signal (SIGURG, SIG_DFL); */
549 574
550 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); 575 old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler);
551 // TODO: handle this with exceptions and tolerate the memory loss 576 // TODO: handle this with exceptions and tolerate the memory loss
552 XSetIOErrorHandler (rxvt_xioerror_handler); 577 XSetIOErrorHandler (rxvt_xioerror_handler);
553}
554
555/* ------------------------------------------------------------------------- *
556 * SIGNAL HANDLING & EXIT HANDLER *
557 * ------------------------------------------------------------------------- */
558/*
559 * Catch a SIGCHLD signal and exit if the direct child has died
560 */
561
562void
563rxvt_term::sig_chld (sig_watcher &w)
564{
565 // we are being called for every SIGCHLD, not just ours
566 int pid;
567
568 while ((pid = waitpid (-1, NULL, WNOHANG)) > 0)
569 for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++)
570 if (pid == (*t)->cmd_pid)
571 {
572 (*t)->destroy ();
573 break;
574 }
575} 578}
576 579
577/* ------------------------------------------------------------------------- * 580/* ------------------------------------------------------------------------- *
578 * MEMORY ALLOCATION WRAPPERS * 581 * MEMORY ALLOCATION WRAPPERS *
579 * ------------------------------------------------------------------------- */ 582 * ------------------------------------------------------------------------- */
586 rxvt_fatal ("memory allocation failure. aborting.\n"); 589 rxvt_fatal ("memory allocation failure. aborting.\n");
587 590
588 return p; 591 return p;
589} 592}
590 593
591/* INTPROTO */ 594void *
592void *
593rxvt_calloc (size_t number, size_t size) 595rxvt_calloc (size_t number, size_t size)
594{ 596{
595 void *p = calloc (number, size); 597 void *p = calloc (number, size);
596 598
597 if (!p) 599 if (!p)
598 rxvt_fatal ("memory allocation failure. aborting.\n"); 600 rxvt_fatal ("memory allocation failure. aborting.\n");
599 601
600 return p; 602 return p;
601} 603}
602 604
603/* INTPROTO */
604void * 605void *
605rxvt_realloc (void *ptr, size_t size) 606rxvt_realloc (void *ptr, size_t size)
606{ 607{
607 void *p = realloc (ptr, size); 608 void *p = realloc (ptr, size);
608 609
844 (void)ioctl (pty.pty, TIOCSWINSZ, &ws); 845 (void)ioctl (pty.pty, TIOCSWINSZ, &ws);
845 846
846#if 0 847#if 0
847 // TIOCSWINSZ⎈ is supposed to do this automatically and correctly 848 // TIOCSWINSZ⎈ is supposed to do this automatically and correctly
848 if (cmd_pid) /* force through to the command */ 849 if (cmd_pid) /* force through to the command */
849 kill (cmd_pid, SIGWINCH); 850 kill (-cmd_pid, SIGWINCH);
850#endif 851#endif
851} 852}
852 853
853/*----------------------------------------------------------------------*/ 854/*----------------------------------------------------------------------*/
854/* set_fonts () - load and set the various fonts 855/* set_fonts () - load and set the various fonts
855/* 856 *
856 * init = 1 - initialize 857 * init = 1 - initialize
857 * 858 *
858 * fontname == FONT_UP - switch to bigger font 859 * fontname == FONT_UP - switch to bigger font
859 * fontname == FONT_DN - switch to smaller font 860 * fontname == FONT_DN - switch to smaller font
860 */ 861 */
958/* xterm sequences - title, iconName, color (exptl) */ 959/* xterm sequences - title, iconName, color (exptl) */
959void 960void
960rxvt_term::set_title (const char *str) 961rxvt_term::set_title (const char *str)
961{ 962{
962 set_string_property (XA_WM_NAME, str); 963 set_string_property (XA_WM_NAME, str);
963#if ENABLE_FRILLS 964#if ENABLE_EWMH
964 set_utf8_property (xa[XA_NET_WM_NAME], str); 965 set_utf8_property (xa[XA_NET_WM_NAME], str);
965#endif 966#endif
966} 967}
967 968
968void 969void
969rxvt_term::set_icon_name (const char *str) 970rxvt_term::set_icon_name (const char *str)
970{ 971{
971 set_string_property (XA_WM_ICON_NAME, str); 972 set_string_property (XA_WM_ICON_NAME, str);
972#if ENABLE_FRILLS 973#if ENABLE_EWMH
973 set_utf8_property (xa[XA_NET_WM_ICON_NAME], str); 974 set_utf8_property (xa[XA_NET_WM_ICON_NAME], str);
974#endif 975#endif
975} 976}
976 977
977#ifdef XTERM_COLOR_CHANGE 978#ifdef XTERM_COLOR_CHANGE
993 { /* bright colors */ 994 { /* bright colors */
994 i -= 8; 995 i -= 8;
995# ifndef NO_BRIGHTCOLOR 996# ifndef NO_BRIGHTCOLOR
996 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; 997 pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i];
997 SET_PIXCOLOR (idx); 998 SET_PIXCOLOR (idx);
998 goto Done; 999 goto done;
999# endif 1000# endif
1000 } 1001 }
1001 1002
1002 if (i >= 0 && i <= 7) 1003 if (i >= 0 && i <= 7)
1003 { /* normal colors */ 1004 { /* normal colors */
1004 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; 1005 pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i];
1005 SET_PIXCOLOR (idx); 1006 SET_PIXCOLOR (idx);
1006 goto Done; 1007 goto done;
1007 } 1008 }
1008 } 1009 }
1009 1010
1010 if (!rXParseAllocColor (&xcol, color)) 1011 if (!rXParseAllocColor (&xcol, color))
1011 return; 1012 return;
1031 pix_colors_focused[idx] = xcol; 1032 pix_colors_focused[idx] = xcol;
1032 SET_PIXCOLOR (idx); 1033 SET_PIXCOLOR (idx);
1033 1034
1034 /* XSetWindowAttributes attr; */ 1035 /* XSetWindowAttributes attr; */
1035 /* Cursor cursor; */ 1036 /* Cursor cursor; */
1036Done: 1037done:
1038
1037#ifdef OFF_FOCUS_FADING 1039#if OFF_FOCUS_FADING
1038 if (rs[Rs_fade]) 1040 if (rs[Rs_fade])
1039 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]);
1040#endif 1042#endif
1041 1043
1042 /*TODO: handle Color_BD, scrollbar background, etc. */ 1044 /*TODO: handle Color_BD, scrollbar background, etc. */
1043 1045
1044 recolour_cursor (); 1046 recolour_cursor ();
1249 XWindowAttributes wattr; 1251 XWindowAttributes wattr;
1250 1252
1251 if (width == 0 || height == 0) 1253 if (width == 0 || height == 0)
1252 { 1254 {
1253 XGetWindowAttributes (display->display, display->root, &wattr); 1255 XGetWindowAttributes (display->display, display->root, &wattr);
1256
1254 if (width == 0) 1257 if (width == 0)
1255 width = wattr.width - szHint.base_width; 1258 width = wattr.width - szHint.base_width;
1256 if (height == 0) 1259 if (height == 0)
1257 height = wattr.height - szHint.base_height; 1260 height = wattr.height - szHint.base_height;
1258 } 1261 }
1552} 1555}
1553 1556
1554void 1557void
1555rxvt_term::im_cb () 1558rxvt_term::im_cb ()
1556{ 1559{
1557 int i, found, had_im; 1560 int i;
1558 const char *p; 1561 const char *p;
1559 char **s; 1562 char **s;
1560 char buf[IMBUFSIZ]; 1563 char buf[IMBUFSIZ];
1561 1564
1562 SET_R (this); 1565 SET_R (this);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines