📄 init.c
字号:
** allocate environment variable for MRXVT_TABTITLE, we will ** use it in rxvt_create_termwin later for each tab terminal */ r->h->env_tabtitle = rxvt_malloc(sizeof(TABTITLEENV) + MAX_TAB_TXT + 1);}/*----------------------------------------------------------------------*//* * This is more or less stolen straight from XFree86 xterm. * This should support all European type languages. *//* EXTPROTO */voidrxvt_init_xlocale(rxvt_t *r){#ifdef USE_XIM if (IS_NULL(r->h->locale)) rxvt_msg (DBG_ERROR, DBG_INIT, "Setting locale failed."); else { XChangeProperty(r->Xdisplay, r->TermWin.parent, r->h->xa[XA_WM_LOCALE_NAME], XA_STRING, 8, PropModeReplace, (unsigned char *)r->h->locale, STRLEN(r->h->locale)); if (XSupportsLocale() != True) { rxvt_msg (DBG_ERROR, DBG_INIT, "The locale is not supported by Xlib"); return; } rxvt_IM_set_fontset (r, 0); /* see if we can connect yet */ rxvt_IM_init_callback (r->Xdisplay, NULL, NULL); /* To avoid Segmentation Fault in C locale: Solaris only? */ if (STRCMP(r->h->locale, "C")) XRegisterIMInstantiateCallback(r->Xdisplay, NULL, NULL, NULL, rxvt_IM_init_callback, NULL); }#endif}/*----------------------------------------------------------------------*//* EXTPROTO */#ifdef USE_FIFOvoidrxvt_init_fifo( rxvt_t *r ){ unlink( r->fifo_name ); mkfifo( r->fifo_name, 0600 ); /* * Create the fifo in read write mode. If not, when no clients have the * fifo open, select() will claim our fifo has data pending and return. */ r->fifo_fd = open( r->fifo_name, O_RDONLY|O_NDELAY ); if( r->fifo_fd == -1 ) UNSET_OPTION( r, Opt_useFifo ); else MAX_IT( r->num_fds, r->fifo_fd + 1); /* Reset the fifo buffer */ r->fbuf_ptr = r->fifo_buf;}#endif/* EXTPROTO */voidrxvt_init_command(rxvt_t* r){ /* * Initialize the command connection. This should be called after the X * server connection is established. */ struct sigaction act; rxvt_dbgmsg ((DBG_DEBUG, DBG_INIT, "%s()\n", __func__)); /* * Enable delete window protocol so that if the top-level window of the * terminal is destroyed by the Session Manager, we can receive a * ClientMessage event and do something gracefully. */ XSetWMProtocols (r->Xdisplay, r->TermWin.parent, &(r->h->xa[XA_WMDELETEWINDOW]), 1);#ifdef META8_OPTION r->h->meta_char = (ISSET_OPTION(r, Opt_meta8) ? 0x80 : C0_ESC);#endif rxvt_get_ourmods(r);#ifdef GREEK_SUPPORT greek_init();#endif r->Xfd = XConnectionNumber(r->Xdisplay);#ifdef USE_FIFO if( ISSET_OPTION( r, Opt_useFifo ) ) rxvt_init_fifo( r ); else r->fifo_fd = -1;#endif#ifdef CURSOR_BLINK if (ISSET_OPTION(r, Opt_cursorBlink)) (void)gettimeofday(&r->h->lastcursorchange, NULL);#endif /* * Gracefully exit on term signals. */ act.sa_handler = rxvt_Exit_signal; act.sa_flags = 0; sigemptyset (&act.sa_mask);#ifndef OS_SVR4 sigaction( SIGINT , &act, NULL);#endif sigaction( SIGQUIT, &act, NULL); sigaction( SIGTERM, &act, NULL); /* * 2006-04-28 gi1242: Ignore HUP signals. We sometimes receive this if bash * is killed. Chances are that we don't have to exit ... */ act.sa_handler = SIG_IGN; sigaction( SIGHUP, &act, NULL);#ifdef PRINTPIPE /* * 2006-04-28 gi1242: If there is an error opening the printer command, then * we'll get SIGPIPE. If not handled, mrxvt will exit. * * There's nothing we really need to do on broken pipes, so just ignore * SIGPIPE for now. */ sigaction( SIGPIPE, &act, NULL);#endif act.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &act, NULL);}/* EXTPROTO */voidrxvt_fade_color( rxvt_t* r, const XColor *xcol, unsigned long *pix_return,# ifdef XFT_SUPPORT XftColor *xft_return# else void *xft_return# endif ){ if( r->TermWin.fade ) { XColor faded_xcol; faded_xcol.red = (xcol->red / 100) * r->TermWin.fade; faded_xcol.green = (xcol->green / 100) * r->TermWin.fade; faded_xcol.blue = (xcol->blue / 100) * r->TermWin.fade; rxvt_alloc_color( r, &faded_xcol, "Faded" ); *pix_return = faded_xcol.pixel;# ifdef XFT_SUPPORT if( NOT_NULL( xft_return ) ) rxvt_alloc_xft_color( r, &faded_xcol, xft_return );# endif }}#define setChanged( a, b ) \ if( (a) != (b) ) {(a) = (b); changed = 1;}#define setChangedXft( a, b ) \ if( (a).pixel != (b).pixel ) { (a) = (b); changed = 1;}/* * Sets r->pixColors[Color_fg] / etc to the correct color (depending on the ufbg * color, off focus fading and weather we have focus or not). *//* EXTPROTO */intrxvt_set_fgbg_colors( rxvt_t *r, int page ){ int changed = 0; rxvt_dbgmsg(( DBG_DEBUG, DBG_INIT, "%s(r, page=%d)" ": fgbg_tabnum=%d, globalTabNum=%d\n", __func__, page, r->fgbg_tabnum, PVTS(r, page)->globalTabNum)); if( r->fgbg_tabnum == PVTS(r, page)->globalTabNum && ( r->TermWin.fade || !ISSET_PIXCOLOR( r->h, Color_ufbg ) || ( /* * If we dont have fading, but have ufbg, then make sure that * Color_bg points to the correct color. */ r->TermWin.focus ? ( r->pixColors[Color_bg] == PVTS(r, page)->p_bg ) : ( r->pixColors[Color_bg] == r->pixColors[Color_ufbg] ) ) ) ) return 0; /* No change */ setChanged( r->pixColorsFocus[Color_fg], PVTS( r, page)->p_fg );#ifdef XFT_SUPPORT if( ISSET_OPTION( r, Opt_xft ) ) setChangedXft( r->xftColorsFocus[Color_fg], PVTS(r, page)->p_xftfg );#endif if( r->TermWin.fade ) { /* Ignore ufbg, and use faded colors */ setChanged( r->pixColorsFocus[Color_bg], PVTS(r, page)->p_bg ); setChanged( r->pixColorsUnfocus[Color_fg], PVTS(r, page)->p_fgfade ); setChanged( r->pixColorsUnfocus[Color_bg], PVTS(r, page)->p_bgfade );#ifdef XFT_SUPPORT if( ISSET_OPTION( r, Opt_xft ) ) { setChangedXft( r->xftColorsFocus[Color_bg], PVTS(r, page)->p_xftbg ); setChangedXft( r->xftColorsUnfocus[Color_fg], PVTS(r, page)->p_xftfgfade ); setChangedXft( r->xftColorsUnfocus[Color_bg], PVTS(r, page)->p_xftbgfade ); }#endif } else if( ISSET_PIXCOLOR( r->h, Color_ufbg ) && !r->TermWin.focus ) { /* No fading. But use Color_ufbg */ setChanged( r->pixColorsFocus[Color_bg], r->pixColorsFocus[Color_ufbg] );#ifdef XFT_SUPPORT if( ISSET_OPTION( r, Opt_xft ) ) setChangedXft( r->xftColorsFocus[Color_bg], r->xftColorsFocus[Color_ufbg] );#endif } else { /* Use fgbg from profile */ setChanged( r->pixColorsFocus[Color_bg], PVTS(r, page)->p_bg );#ifdef XFT_SUPPORT if( ISSET_OPTION( r, Opt_xft ) ) setChangedXft( r->xftColorsFocus[Color_bg], PVTS(r, page)->p_xftbg );#endif } r->fgbg_tabnum = PVTS( r, page )->globalTabNum; rxvt_dbgmsg(( DBG_DEBUG, DBG_INIT, "%s(r, page=%d) returning %d\n", __func__, page, changed )); return changed; /* Changed */}#undef setChanged#undef setChangedXftvoidrxvt_copy_color( rxvt_t *r, int dst_index, int src_index ){ r->pixColorsFocus[ dst_index ] = r->pixColorsFocus[ src_index ]; if( r->TermWin.fade ) r->pixColorsUnfocus[ dst_index ] = r->pixColorsUnfocus[ src_index ];#ifdef XFT_SUPPORT if( ISSET_OPTION( r, Opt_xft ) ) { r->xftColorsFocus[ dst_index ] = r->xftColorsFocus[ src_index ]; if( r->TermWin.fade ) r->xftColorsUnfocus[ dst_index ] = r->xftColorsUnfocus[ src_index ]; }#endif SET_PIXCOLOR( r->h, dst_index );}voidrxvt_set_color( rxvt_t *r, int cIndex, const XColor *xcol ){ /* xcol must contain an ALLOCATED color */ r->pixColorsFocus[cIndex] = xcol->pixel;#ifdef XFT_SUPPORT if( ISSET_OPTION( r, Opt_xft ) ) rxvt_alloc_xft_color( r, xcol, &r->xftColorsFocus[cIndex] );#endif if( r->TermWin.fade ) { if( cIndex == Color_pointer ) { /* Don't fade these colors */ r->pixColorsUnfocus[cIndex] = r->pixColorsFocus[cIndex];#ifdef XFT_SUPPORT if( ISSET_OPTION( r, Opt_xft ) ) r->xftColorsUnfocus[cIndex] = r->xftColorsFocus[cIndex];#endif } else rxvt_fade_color( r, xcol, &r->pixColorsUnfocus[cIndex],#ifdef XFT_SUPPORT ISSET_OPTION(r, Opt_xft) ? &r->xftColorsUnfocus[cIndex] : NULL#else NULL#endif ); } SET_PIXCOLOR( r->h, cIndex );}/* * XXX 2006-05-24 gi1242: Should allocate Xft colors only if Opt_xft is set. In * that case we should avoid allocating XColors, since we can always access them * through xftcolor.pixel. *//* INTPROTO */voidrxvt_init_colors( rxvt_t *r ){ register int i; rxvt_dbgmsg ((DBG_DEBUG, DBG_INIT, "%s()\n", __func__)); /* Initialize fg/bg colors for each profile */ for (i = 0; i < MAX_PROFILES; i++) { XColor xcol; int vtfg = Rs_foreground + i; int vtbg = Rs_background + i; if( !ISSET_VTFG( r, i ) ) r->h->rs[vtfg] = ISSET_VTFG( r, 0 ) ? r->h->rs[Rs_foreground] : def_colorName[ Color_fg ]; if( !ISSET_VTBG( r, i ) ) r->h->rs[vtbg] = ISSET_VTBG( r, 0 ) ? r->h->rs[Rs_background] : def_colorName[ Color_bg ]; /* foreground color of i terminal */ if( rxvt_parse_alloc_color(r, &xcol, r->h->rs[vtfg]) ) { VTFG(r, i) = xcol.pixel;#ifdef XFT_SUPPORT rxvt_alloc_xft_color( r, &xcol, &(VTXFTFG(r, i)) ); rxvt_fade_color( r, &xcol, &VTFG_FADE(r, i), &VTXFTFG_FADE(r, i) );#else rxvt_fade_color( r, &xcol, &VTFG_FADE(r, i), NULL );#endif /* XFT_SUPPORT */ } else { rxvt_msg (DBG_ERROR, DBG_INIT, "Could not alloc foreground color of profile %d", i ); if( i == 0 ) /* Need default fg/bg */ exit( EXIT_FAILURE ); /* Use foreground from profie 0 */ VTFG( r, i ) = VTFG( r, 0 ); VTFG_FADE( r, i ) = VTFG_FADE( r, 0 );#ifdef XFT_SUPPORT VTXFTFG( r, i ) = VTXFTFG( r, 0 ); VTXFTFG_FADE( r, i ) = VTXFTFG_FADE( r, 0 );#endif } /* background color of i terminal */ if( rxvt_parse_alloc_color(r, &xcol, r->h->rs[vtbg]) ) { VTBG(r, i) = xcol.pixel;#ifdef XFT_SUPPORT rxvt_alloc_xft_color( r, &xcol, &(VTXFTBG(r, i)) ); rxvt_fade_color( r, &xcol, &VTBG_FADE(r, i), &VTXFTBG_FADE(r, i) );#else rxvt_fade_color( r, &xcol, &VTBG_FADE(r, i), NULL );#endif /* XFT_SUPPORT */ } else { rxvt_msg (DBG_ERROR, DBG_INIT, "Could not alloc background color of profile %d", i ); if( i == 0 ) /* Need default fg/bg */ exit( EXIT_FAILURE ); /* Use background from profie 0 */ VTBG( r, i ) = VTBG( r, 0 ); VTBG_FADE( r, i ) = VTBG_FADE( r, 0 );#ifdef XFT_SUPPORT VTXFTBG( r, i ) = VTXFTBG( r, 0 ); VTXFTBG_FADE( r, i ) = VTXFTBG_FADE( r, 0 );#endif } } /* Set foreground / background colors */ r->pixColorsFocus[ Color_fg ] = VTFG( r, 0 ); r->pixColorsFocus[ Color_bg ] = VTBG( r, 0 ); if( r->TermWin.fade ) { r->pixColorsUnfocus[ Color_fg ] = VTFG_FADE( r, 0 ); r->pixColorsUnfocus[ Color_bg ] = VTBG_FADE( r, 0 ); }#ifdef XFT_SUPPORT if( ISSET_OPTION( r, Opt_xft ) ) { r->xftColorsFocus[ Color_fg ] = VTXFTFG( r, 0 ); r->xftColorsFocus[ Color_bg ] = VTXFTBG( r, 0 ); if( r->TermWin.fade ) { r->xftColorsUnfocus[ Color_fg ] = VTXFTFG( r, 0 ); r->xftColorsUnfocus[ Color_bg ] = VTXFTBG( r, 0 ); } }#endif r->fgbg_tabnum = -1; /* fg/bg corresponds to profile 0, not any particular tab during initialization. */ /* * Allocate generic colors. */ for (i = minCOLOR; i < (XDEPTH <= 2 ? 2 : NRS_COLORS); i++) { XColor xcol; if( IS_NULL(r->h->rs[Rs_color + i]) ) continue; if( !rxvt_parse_alloc_color(r, &xcol, r->h->rs[Rs_color + i]) ) { if( r->h->rs[Rs_color+i] != def_colorName[i] ) { rxvt_msg (DBG_ERROR, DBG_INIT, "Could not allocate color '%s'\n", r->h->rs[Rs_color + i] ); /* Try again with default color */ r->h->rs[Rs_color + i] = def_colorName[i]; i--; continue; } /* * Unable to alloc even the default color. Fall back to fg/bg. */ switch( i ) {#ifndef NO_CURSORCOLOR case Color_cursor2:#endif /* !NO_CURSORCOLOR */ case Color_pointer: rxvt_copy_color( r, i, Color_fg ); break; default: rxvt_copy_color( r, i, Color_bg ); break; } } else { /* * Succeeded allocating the color. Store it in pixColors. */ rxvt_set_color( r, i, &xcol ); } } /* for(i) */ /* * Allocate colors which are essential if they have not been allocated. */ if( XDEPTH <= 2 || !ISSET_PIXCOLOR( r->h, Color_pointer ) ) { /* * NOTE: Fading should be disabled for low depths. And the pointer color * should not be faded. */ r->pixColorsFocus[Color_pointer] = VTFG(r, 0); if( r->TermWin.fade ) r->pixColorsUnfocus[Color_pointer] = VTFG(r, 0);#ifdef XFT_SUPPORT if( ISSET_OPTION( r, Opt_xft ) ) { r->xftColorsFocus[Color_pointer] = VTXFTFG(r, 0); if( r->TermWin.fade ) r->xftColorsUnfocus[Color_pointer] = VTXFTFG(r, 0); }#endif SET_PIXCOLOR( r->h, Color_pointer ); } if( XDEPTH <= 2 || !ISSET_PIXCOLOR( r->h, Color_border ) ) rxvt_copy_color( r, Color_border, Color_fg );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -