--- rxvt-unicode/src/main.C 2004/03/15 00:08:11 1.54 +++ rxvt-unicode/src/main.C 2004/08/04 03:29:28 1.76 @@ -1,5 +1,5 @@ -/*--------------------------------*-C-*---------------------------------*; - * File: main.c +/*--------------------------------*-C-*---------------------------------* + * File: main.C *----------------------------------------------------------------------* * * All portions of code are copyright by their respective author/s. @@ -46,16 +46,19 @@ #include +vector rxvt_term::termlist; + static char curlocale[128]; -void +bool rxvt_set_locale (const char *locale) { - if (locale && STRNCMP (locale, curlocale, 128)) - { - STRNCPY (curlocale, locale, 128); - setlocale (LC_CTYPE, curlocale); - } + if (!locale || !STRNCMP (locale, curlocale, 128)) + return false; + + STRNCPY (curlocale, locale, 128); + setlocale (LC_CTYPE, curlocale); + return true; } #if ENABLE_COMBINING @@ -154,6 +157,15 @@ #ifdef TEXT_BLINK text_blink_ev (this, &rxvt_term::text_blink_cb), #endif +#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING + cont_scroll_ev (this, &rxvt_term::cont_scroll_cb), +#endif +#ifdef SELECTION_SCROLLING + sel_scroll_ev (this, &rxvt_term::sel_scroll_cb), +#endif +#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) + slip_wheel_ev (this, &rxvt_term::slip_wheel_cb), +#endif #ifdef POINTER_BLANK pointer_ev (this, &rxvt_term::pointer_cb), #endif @@ -161,15 +173,20 @@ im_ev (this, &rxvt_term::im_cb), #endif check_ev (this, &rxvt_term::check_cb), + flush_ev (this, &rxvt_term::flush_cb), destroy_ev (this, &rxvt_term::destroy_cb), pty_ev (this, &rxvt_term::pty_cb), incr_ev (this, &rxvt_term::incr_cb) { cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; + + termlist.push_back (this); } rxvt_term::~rxvt_term () { + termlist.erase (find (termlist.begin (), termlist.end(), this)); + if (cmd_fd >= 0) close (cmd_fd); @@ -184,6 +201,37 @@ if (display) { + selection_clear (); + +#ifdef MENUBAR + if (menubarGC) XFreeGC (display->display, menubarGC); +#endif +#ifdef XTERM_SCROLLBAR + if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC); + if (ShadowGC) XFreeGC (display->display, ShadowGC); +#endif +#ifdef PLAIN_SCROLLBAR + if (pscrollbarGC) XFreeGC (display->display, pscrollbarGC); +#endif +#ifdef NEXT_SCROLLBAR + if (blackGC) XFreeGC (display->display, blackGC); + if (whiteGC) XFreeGC (display->display, whiteGC); + if (grayGC) XFreeGC (display->display, grayGC); + if (darkGC) XFreeGC (display->display, darkGC); + if (stippleGC) XFreeGC (display->display, stippleGC); + if (dimple) XFreePixmap (display->display, dimple); + if (upArrow) XFreePixmap (display->display, upArrow); + if (downArrow) XFreePixmap (display->display, downArrow); + if (upArrowHi) XFreePixmap (display->display, upArrowHi); + if (downArrowHi) XFreePixmap (display->display, downArrowHi); +#endif +#if defined(MENUBAR) || defined(RXVT_SCROLLBAR) + if (topShadowGC) XFreeGC (display->display, topShadowGC); + if (botShadowGC) XFreeGC (display->display, botShadowGC); + if (scrollbarGC) XFreeGC (display->display, scrollbarGC); +#endif + if (TermWin.gc) XFreeGC (display->display, TermWin.gc); + #if defined(MENUBAR) && (MENUBAR_MAX > 1) delete menuBar.drawable; //if (menuBar.win) @@ -197,18 +245,29 @@ // TODO: free pixcolours, colours should become part of rxvt_display - delete PixColors; + delete PixColorsFocused; +#ifdef OFF_FOCUS_FADING + delete PixColorsUnFocused; +#endif displays.put (display); scr_release (); + /* clear all resources */ + for (int i = 0; i < allocated.size (); i++) + free (allocated[i]); + + free (selection.text); + // TODO: manage env vars in child only(!) free (env_windowid); free (env_display); free (env_term); free (env_colorfgbg); free (locale); +#if 0 free (codeset); +#endif delete envv; delete argv; @@ -242,6 +301,12 @@ #ifdef TEXT_BLINK text_blink_ev.stop (); #endif +#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING + cont_scroll_ev.stop (); +#endif +#ifdef SELECTION_SCROLLING + sel_scroll_ev.stop (); +#endif #ifdef POINTER_BLANK pointer_ev.stop (); #endif @@ -259,55 +324,14 @@ /*----------------------------------------------------------------------*/ /* rxvt_init () */ -/* LIBPROTO */ -rxvt_t -rxvt_init (int argc, const char *const *argv) -{ - SET_R (new rxvt_term); - - if (!GET_R->init_vars () || !GET_R->init (argc, argv)) - { - delete GET_R; - SET_R (0); - } - - return GET_R; -} - -static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event); - -void -rxvt_init_signals () -{ - /* install exit handler for cleanup */ -#if 0 -#ifdef HAVE_ATEXIT - atexit (rxvt_clean_exit); -#else -#endif -#endif - - struct sigaction sa; - - sigfillset (&sa.sa_mask); - sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; - sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0); - sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0); - sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0); - sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0); - sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0); - sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0); - - /* need to trap SIGURG for SVR4 (Unixware) rlogin */ - /* signal (SIGURG, SIG_DFL); */ - - old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); - //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); -} - bool rxvt_term::init (int argc, const char *const *argv) { + SET_R (this); + + if (!init_vars ()) + return false; + /* * Save and then give up any super-user privileges * If we need privileges in any area then we must specifically request it. @@ -372,26 +396,65 @@ return true; } +static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event); + +void +rxvt_init_signals () +{ + /* install exit handler for cleanup */ +#if 0 +#ifdef HAVE_ATEXIT + atexit (rxvt_clean_exit); +#else +#endif +#endif + + struct sigaction sa; + + sigfillset (&sa.sa_mask); + sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; + sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0); + sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0); + sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0); + sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0); + sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0); + sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0); + + /* need to trap SIGURG for SVR4 (Unixware) rlogin */ + /* signal (SIGURG, SIG_DFL); */ + + old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); + //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); +} + /* ------------------------------------------------------------------------- * * SIGNAL HANDLING & EXIT HANDLER * * ------------------------------------------------------------------------- */ /* * Catch a SIGCHLD signal and exit if the direct child has died */ + +void rxvt_term::child_exited (int pid) +{ + for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) + if (pid == (*t)->cmd_pid) + { + (*t)->destroy (); + break; + } +} + /* ARGSUSED */ /* EXTPROTO */ RETSIGTYPE rxvt_Child_signal (int sig __attribute__ ((unused))) { int pid, save_errno = errno; - while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR) - ; - errno = save_errno; -#if 0 - if (pid == cmd_pid) - exit (EXIT_SUCCESS); -#endif + while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) + rxvt_term::child_exited (pid); + + errno = save_errno; } /* @@ -403,7 +466,7 @@ { signal (sig, SIG_DFL); #ifdef DEBUG_CMD - rxvt_print_error ("signal %d", sig); + rxvt_warn ("caught signal %d, exiting.\n", sig); #endif rxvt_clean_exit (); kill (getpid (), sig); @@ -698,20 +761,23 @@ szHint.base_width = szHint.base_height = 2 * TermWin.int_bwidth; sb_w = mb_h = 0; - window_vt_x = window_vt_y = 0; + window_vt_x = window_vt_y = TermWin.int_bwidth; + if (scrollbar_visible ()) { sb_w = scrollbar_TotalWidth (); szHint.base_width += sb_w; - if (! (Options & Opt_scrollBar_right)) - window_vt_x = sb_w; + if (!(Options & Opt_scrollBar_right)) + window_vt_x += sb_w; } + if (menubar_visible ()) { mb_h = menuBar_TotalHeight (); szHint.base_height += mb_h; - window_vt_y = mb_h; + window_vt_y += mb_h; } + szHint.width_inc = TermWin.fwidth; szHint.height_inc = TermWin.fheight; szHint.min_width = szHint.base_width + szHint.width_inc; @@ -727,6 +793,7 @@ MIN_IT (TermWin.width, max_width); szHint.width = szHint.base_width + TermWin.width; } + if (height && height - szHint.base_height < max_height) { szHint.height = height; @@ -737,6 +804,7 @@ MIN_IT (TermWin.height, max_height); szHint.height = szHint.base_height + TermWin.height; } + if (scrollbar_visible () && (Options & Opt_scrollBar_right)) window_sb_x = szHint.width - sb_w; @@ -821,6 +889,9 @@ scr_touch (true); } + for (unicode_t ch = 0x20; ch <= 0x7f; ch++) + TermWin.ascii_map [ch - 0x20] = fs->find_font (ch); + return true; } } @@ -840,32 +911,36 @@ void rxvt_term::set_title (const char *str) { -#ifndef SMART_WINDOW_TITLE - XStoreName (display->display, TermWin.parent[0], str); -#else +#ifdef SMART_WINDOW_TITLE char *name; - if (XFetchName (display->display, TermWin.parent[0], &name) == 0) + if (!XFetchName (display->display, TermWin.parent[0], &name)) name = NULL; + if (name == NULL || STRCMP (name, str)) +#endif XStoreName (display->display, TermWin.parent[0], str); + +#ifdef SMART_WINDOW_TITLE if (name) XFree (name); #endif } void -rxvt_term::set_iconName (const char *str) +rxvt_term::set_icon_name (const char *str) { -#ifndef SMART_WINDOW_TITLE - XSetIconName (display->display, TermWin.parent[0], str); -#else +#ifdef SMART_WINDOW_TITLE char *name; - if (XGetIconName (display->display, TermWin.parent[0], &name)) + if (!XGetIconName (display->display, TermWin.parent[0], &name)) name = NULL; + if (name == NULL || STRCMP (name, str)) +#endif XSetIconName (display->display, TermWin.parent[0], str); + +#ifdef SMART_WINDOW_TITLE if (name) XFree (name); #endif @@ -889,7 +964,7 @@ { /* bright colors */ i -= 8; # ifndef NO_BRIGHTCOLOR - PixColors[idx] = PixColors[minBrightCOLOR + i]; + PixColorsFocused[idx] = PixColorsFocused[minBrightCOLOR + i]; SET_PIXCOLOR (idx); goto Done; # endif @@ -897,14 +972,16 @@ } if (i >= 0 && i <= 7) { /* normal colors */ - PixColors[idx] = PixColors[minCOLOR + i]; + PixColorsFocused[idx] = PixColorsFocused[minCOLOR + i]; SET_PIXCOLOR (idx); goto Done; } } + if (!rXParseAllocColor (& xcol, color)) return; - /* XStoreColor (display->display, XCMAP, XColor*); */ + + /* XStoreColor (display->display, display->cmap, XColor*); */ /* * FIXME: should free colors here, but no idea how to do it so instead, @@ -917,27 +994,28 @@ if (i > Color_White) { /* fprintf (stderr, "XFreeColors: PixColors [%d] = %lu\n", idx, PixColors [idx]); */ - XFreeColors (display->display, XCMAP, (PixColors + idx), 1, + XFreeColors (display->display, display->cmap, (PixColors + idx), 1, DisplayPlanes (display->display, display->screen)); } # endif - PixColors[idx] = xcol; + PixColorsFocused[idx] = xcol; SET_PIXCOLOR (idx); /* XSetWindowAttributes attr; */ /* Cursor cursor; */ Done: +#ifdef OFF_FOCUS_FADING + PixColorsUnFocused[idx] = PixColorsFocused[idx].fade (display, atoi (rs[Rs_fade])); +#endif if (idx == Color_bg && ! (Options & Opt_transparent)) - XSetWindowBackground (display->display, TermWin.vt, - PixColors[Color_bg]); + XSetWindowBackground (display->display, TermWin.vt, PixColors[Color_bg]); /* handle Color_BD, scrollbar background, etc. */ set_colorfgbg (); recolour_cursor (); - /* the only reasonable way to enforce a clean update */ - scr_poweron (); + scr_touch (true); } #else @@ -947,14 +1025,12 @@ void rxvt_term::recolour_cursor () { -#if TODO - rxvt_color xcol[2]; + XColor xcol[2]; - xcol[0] = PixColors[Color_pointer]; - xcol[1] = PixColors[Color_bg]; - XQueryColors (display->display, XCMAP, xcol, 2); - XRecolorCursor (display->display, TermWin_cursor, & (xcol[0]), & (xcol[1])); -#endif + xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? PixColorsFocused[Color_pointer_fg] : PixColorsFocused[Color_fg]; + xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? PixColorsFocused[Color_pointer_bg] : PixColorsFocused[Color_bg]; + XQueryColors (display->display, display->cmap, xcol, 2); + XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1); } /*----------------------------------------------------------------------*/ @@ -1013,7 +1089,7 @@ { if (!screen_in_out->set (display, colour)) { - rxvt_print_error ("can't allocate colour: %s", colour); + rxvt_warn ("can't get colour '%s', continuing without.\n", colour); return false; } @@ -1034,6 +1110,7 @@ window_calc (width, height); XSetWMNormalHints (display->display, TermWin.parent[0], &szHint); + if (!ignoreparent) { #ifdef SMART_RESIZE @@ -1078,36 +1155,34 @@ XMoveResizeWindow (display->display, TermWin.parent[0], x + dx, y + dy, szHint.width, szHint.height); #else - XResizeWindow (display->display, TermWin.parent[0], szHint.width, - szHint.height); + XResizeWindow (display->display, TermWin.parent[0], szHint.width, szHint.height); #endif - } - fix_screen = (TermWin.ncol != prev_ncol - || TermWin.nrow != prev_nrow); + fix_screen = TermWin.ncol != prev_ncol || TermWin.nrow != prev_nrow; if (fix_screen || width != old_width || height != old_height) { if (scrollbar_visible ()) { - XMoveResizeWindow (display->display, scrollBar.win, window_sb_x, - 0, scrollbar_TotalWidth (), szHint.height); + XMoveResizeWindow (display->display, scrollBar.win, + window_sb_x, 0, + scrollbar_TotalWidth (), szHint.height); resize_scrollbar (); } if (menubar_visible ()) - XMoveResizeWindow (display->display, menuBar.win, window_vt_x, - 0, TermWin_TotalWidth (), menuBar_TotalHeight ()); - - XMoveResizeWindow (display->display, TermWin.vt, window_vt_x, - window_vt_y, TermWin_TotalWidth (), - TermWin_TotalHeight ()); - scr_clear (height != old_height); + XMoveResizeWindow (display->display, menuBar.win, + window_vt_x, 0, + TermWin_TotalWidth (), menuBar_TotalHeight ()); + + XMoveResizeWindow (display->display, TermWin.vt, + window_vt_x, window_vt_y, + TermWin_TotalWidth (), TermWin_TotalHeight ()); + scr_clear (); #ifdef XPM_BACKGROUND resize_pixmap (); #endif - } if (fix_screen || old_height == 0) @@ -1390,7 +1465,7 @@ if (Input_Context == NULL) { - rxvt_print_error ("failed to create input context"); + rxvt_warn ("failed to create input context, continuing without XIM.\n"); display->put_xim (input_method); return false; }