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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines