⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 multi-tabed terminal based on rxvt
💻 C
📖 第 1 页 / 共 5 页
字号:
    if (xfont)    {	/*	** if the previous font exists, replace it with new font.	** otherwise, keep the old font, and do nothing	*/	if (r->TermWin.font)	    XFreeFont (r->Xdisplay, r->TermWin.font);	r->TermWin.font = xfont;    }    /* set the font sizes */    fw = rxvt_get_font_widest (r->TermWin.font);    fh = r->TermWin.font->ascent + r->TermWin.font->descent;#ifndef NO_LINESPACE    fh += r->TermWin.lineSpace;#endif    if (fw == r->TermWin.font->min_bounds.width)	/* Mono-spaced (fixed width) font */	r->TermWin.propfont &= ~PROPFONT_NORMAL;    else	/* Proportional font */	r->TermWin.propfont |= PROPFONT_NORMAL;#ifndef NO_BOLDFONT    ckfont = !(fw == r->TermWin.fwidth && fh == r->TermWin.fheight);#endif#ifdef XFT_SUPPORT    /* Set font size when XFT is not enabled */    if (!(ISSET_OPTION(r, Opt_xft) && r->TermWin.xftfont))#endif    {#ifdef XFT_SUPPORT	r->TermWin.pwidth  = fw;	r->TermWin.pheight = fh;#endif	r->TermWin.fwidth  = fw;	r->TermWin.fheight = fh;    }#ifndef NO_BOLDFONT    SET_NULL(bfont);    if (ckfont)    {	if (r->TermWin.bfont)	{	    XFreeFont (r->Xdisplay, r->TermWin.bfont);	    SET_NULL(r->TermWin.bfont);	}	/* try to load boldFont, fail silently */	if (IS_NULL(r->TermWin.bfont) &&	    NOT_NULL(r->h->rs[Rs_boldFont+idx]))	{	    rxvt_dbgmsg ((DBG_VERBOSE, DBG_MAIN, " load bfont (%s)\n", r->h->rs[Rs_boldFont+idx]));	    bfont = XLoadQueryFont (r->Xdisplay, r->h->rs[Rs_boldFont+idx]);	}	if (bfont)	{	    /* Loading bold font succeeded */	    fw = rxvt_get_font_widest (bfont);	    fh = bfont->ascent + bfont->descent;#ifndef NO_LINESPACE	    fh += r->TermWin.lineSpace;#endif	    if (fw <= r->TermWin.fwidth && fh <= r->TermWin.fheight)	    {		r->TermWin.bfont = bfont;		if (fw == r->TermWin.fwidth)		    r->TermWin.propfont &= ~PROPFONT_NORMAL;		else		    r->TermWin.propfont |= PROPFONT_NORMAL;	    }	    else	    {		XFreeFont (r->Xdisplay, bfont);	    }	}    }#endif /* NO_BOLDFONT */#ifdef HAVE_MENUBAR    /*     * 2006-01-29 gi1242: We should do something to resize the menubar font.     * However just changing it in the appropriate GC from here doesn't seem to     * work at all.     */    /* Resize the menubar font too. Only needed for X11 font. */    if(#ifdef XFT_SUPPORT	NOTSET_OPTION(r, Opt_xft) &&#endif	IS_WIN(r->menuBar.win))    {	rxvt_dbgmsg ((DBG_VERBOSE, DBG_MAIN, "Resized menubar font\n"));	XSetFont( r->Xdisplay, r->menuBar.gc, r->TermWin.font->fid);    }#endif#ifdef MULTICHAR_SET    /* load font or substitute */    rxvt_dbgmsg ((DBG_VERBOSE, DBG_MAIN, " load mfont (%s)\n", r->h->rs[Rs_mfont+idx]));    xfont = XLoadQueryFont(r->Xdisplay, r->h->rs[Rs_mfont+idx]);    if (!xfont)    {	char*	ptr;	/* failed to load font */	rxvt_msg (DBG_ERROR, DBG_MAIN, msg, r->h->rs[Rs_mfont+idx]);	/* try to load default font */	ptr = rxvt_fallback_mfont_x11 (r);	rxvt_dbgmsg ((DBG_VERBOSE, DBG_MAIN, " load mfont (%s)\n", ptr));	xfont = XLoadQueryFont(r->Xdisplay, ptr);	if (xfont)	    r->h->rs[Rs_mfont+idx] = ptr;	else	{	    /* still failed to load font */	    rxvt_msg (DBG_ERROR, DBG_MAIN, msg, ptr);	    return 0;	}    }    if (xfont)    {	/*	** if the previous font exists, replace it with new font.	** otherwise, keep the old font, and do nothing	*/	if (r->TermWin.mfont)	    XFreeFont (r->Xdisplay, r->TermWin.mfont);	r->TermWin.mfont = xfont;    }#endif	/* MULTICHAR_SET */#ifdef USE_XIM    rxvt_IM_change_fontset(r, idx);#endif    return 1;}/* INTPROTO */voidrxvt_font_up_down(rxvt_t* r, int n, int direction){    const char	 *p;    int		    initial, j;    for (j = 0; j < n; j++)    {	initial = r->h->fnum;	for (;;)	{	    r->h->fnum += direction;	    if (r->h->fnum == MAX_NFONTS || r->h->fnum == -1)	    {		r->h->fnum = initial;		return;	    }	    p = r->h->rs[Rs_font + FNUM2IDX(r->h->fnum)];	    if (NOT_NULL(p) && STRLEN(p) > 1)		break;	}    }}#undef IDX2FNUM#undef FNUM2IDX/* INTPROTO */intrxvt_get_font_widest(XFontStruct *f){    int		    i, cw, fw = 0;    if (f->min_bounds.width == f->max_bounds.width)	return f->min_bounds.width;    if (IS_NULL(f->per_char))	return f->max_bounds.width;    for (i = f->max_char_or_byte2 - f->min_char_or_byte2; --i >= 0;)    {	cw = f->per_char[i].width;	MAX_IT(fw, cw);    }    return fw;}/*----------------------------------------------------------------------*//*----------------------------------------------------------------------*/#ifdef X_HAVE_UTF8_STRING/* INTPROTO */voidrxvt_set_utf8_property (rxvt_t* r, Atom prop, Window win, const char* str){#ifdef HAVE_WCHAR_H# if !defined (OS_FREEBSD) || _FreeBSD_version >= 500000    wchar_t*	ws = rxvt_mbstowcs (str);    char*	s = rxvt_wcstoutf8 (ws);    XChangeProperty (r->Xdisplay, win, prop,	r->h->xa[XA_UTF8_STRING], 8, PropModeReplace,	(unsigned char*) s, STRLEN (s));    rxvt_free (s);    rxvt_free (ws);# endif /* !defined (OS_FREEBSD) ||... */#endif	/* HAVE_WCHAR_H */}#endif	/* X_HAVE_UTF8_STRING *//* xterm sequences - title, iconName, color (exptl) *//* EXTPROTO */voidrxvt_set_win_title (rxvt_t* r, Window win, const char* str){    XChangeProperty (r->Xdisplay, win, XA_WM_NAME,	XA_STRING, 8, PropModeReplace,	(unsigned char*) str, STRLEN (str));#ifdef X_HAVE_UTF8_STRING    rxvt_set_utf8_property (r, r->h->xa[XA_NET_WM_NAME],	r->TermWin.parent, str);#endif}/* EXTPROTO */voidrxvt_set_term_title (rxvt_t* r, const unsigned char *str){#ifdef SMART_WINDOW_TITLE    XTextProperty   prop;    if (XGetWMName (r->Xdisplay, r->TermWin.parent, &prop) == 0)	SET_NULL(prop.value);    if (IS_NULL(prop.value) || STRCMP(prop.value, str))#endif    {	rxvt_set_win_title (r, r->TermWin.parent, (char*) str);    }}/* EXTPROTO */voidrxvt_set_icon_name (rxvt_t* r, const unsigned char *str){    XTextProperty   prop;#ifdef SMART_WINDOW_TITLE    if (XGetWMIconName(r->Xdisplay, r->TermWin.parent, &prop) == 0)	SET_NULL(prop.value);    if (IS_NULL(prop.value) || STRCMP(prop.value, str))#endif    {	XChangeProperty (r->Xdisplay, r->TermWin.parent,	    XA_WM_ICON_NAME, XA_STRING, 8, PropModeReplace,	    (unsigned char*) str, STRLEN (str));#ifdef X_HAVE_UTF8_STRING	rxvt_set_utf8_property (r, r->h->xa[XA_NET_WM_ICON_NAME],	    r->TermWin.parent, (char*) str);#endif    }}#ifdef XTERM_COLOR_CHANGE/* EXTPROTO */voidrxvt_set_window_color(rxvt_t* r, int page, int idx, const char *color){    XColor	    xcol;    int		    color_set;    register int    i;    rxvt_dbgmsg ((DBG_DEBUG, DBG_MAIN, "%s( r, %d, %d, %s), ATAB=%d\n", __func__, page, idx, color, ATAB(r)));    if (IS_NULL(color) || (char) 0 == *color)	return;    /*     * Set the fg/bg colors from this page, just in case the fg/bg is to be     * changed.     */    rxvt_set_fgbg_colors( r, page );    color_set = ISSET_PIXCOLOR(r->h, idx);    /* handle color aliases */    if( isdigit((int) *color) )    {	i = atoi(color);	if (i >= 8 && i <= 15)		/* bright colors */	{	    i -= 8;# ifndef NO_BRIGHTCOLOR	    rxvt_copy_color( r, idx, minBrightCOLOR + i );	    goto Done;# endif	}	if (i >= 0 && i <= 7)		/* normal colors */	{	    rxvt_copy_color( r, idx, minCOLOR + i );	    goto Done;	}    }    if( !rxvt_parse_alloc_color(r, &xcol, color) )	/* Could not alloc color */	return;    /* XStoreColor (r->Xdisplay, XCMAP, XColor*); */    /*     * FIXME: should free colors here, but no idea how to do it so instead,     * so just keep gobbling up the colormap     */# if 0 /*{{{*/    for (i = Color_Black; i <= Color_White; i++)	if (r->pixColors[idx] == r->pixColors[i])	    break;    if (i > Color_White)    {	fprintf (stderr, "XFreeColors: r->pixColors [%d] = %lu\n",		idx, r->pixColors [idx]);	XFreeColors(r->Xdisplay, XCMAP, (r->pixColors + idx), 1,		DisplayPlanes(r->Xdisplay, XSCREEN));    }# endif /*}}}*/    rxvt_set_color( r, idx, &xcol );Done:    if( idx == Color_bg )    {	PVTS( r, page )->p_bg	= r->pixColorsFocus[idx];#ifdef XFT_SUPPORT	if( ISSET_OPTION( r, Opt_xft ) )	    PVTS( r, page )->p_xftbg = r->xftColorsFocus[idx];#endif	if( r->TermWin.fade )	{	    PVTS( r, page )->p_bgfade	= r->pixColorsUnfocus[idx];#ifdef XFT_SUPPORT	    if( ISSET_OPTION( r, Opt_xft ) )		PVTS( r, page )->p_xftbgfade = r->xftColorsUnfocus[idx];#endif	}	/*	 * Update the GC / window background if necessary.	 */	if( page == ATAB(r) )	    r->fgbg_tabnum = -1;    }    else if ( idx == Color_fg )    {	PVTS( r, page )->p_fg	= r->pixColorsFocus[idx];#ifdef XFT_SUPPORT	if( ISSET_OPTION( r, Opt_xft ) )	    PVTS( r, page )->p_xftfg = r->xftColorsFocus[idx];#endif	if( r->TermWin.fade )	{	    PVTS( r, page )->p_fgfade	= r->pixColorsUnfocus[idx];#ifdef XFT_SUPPORT	    if( ISSET_OPTION( r, Opt_xft ) )		PVTS( r, page )->p_xftfgfade = r->xftColorsUnfocus[idx];#endif	}	if( page == ATAB(r) )	    /* Force rxvt_set_vt_colors() to update the GC / background. */	    r->fgbg_tabnum = -1;    }    /* handle Color_BD, scrollbar background, etc. */#if 0 /*{{{*/    /*     * Setting the environment will not propogate to an already running child     * process.     */    rxvt_set_colorfgbg(r);#endif /*}}}*/    if( idx == Color_pointer )	rxvt_recolour_cursor(r);#if defined(TRANSPARENT) || defined(BACKGROUND_IMAGE)# ifdef TINTING_SUPPORT    if (idx == Color_tint)    {#  ifdef TRANSPARENT	if (ISSET_OPTION(r, Opt_transparent))	    /* reset background */	    rxvt_check_our_parents (r);	else#  endif#  ifdef BACKGROUND_IMAGE	{   /* reset background */	    for (i = 0; i <= LTAB(r); i ++)		rxvt_resize_pixmap (r, i);	}#  endif	{   /* empty body to suppress compile error */	}    }# endif	/* TINTING_SUPPORT */#endif	/* TRANSPARENT || BACKGROUND_IMAGE */    /*     * Restore the fg/bg colors from the active tab. Call rxvt_set_vt_colors     * instead of rxvt_set_fgbg_colors, so that the GC fgbg & window background     * will be refreshed if necessary.     */    rxvt_set_vt_colors( r, ATAB(r) );    /*     *  If our palette has changed, the screen must be refreshed.     */    XClearArea( r->Xdisplay, AVTS(r)->vt, 0, 0, 0, 0, True );}#else# define rxvt_set_window_color(r, idx,color)	((void)0)#endif	    /* XTERM_COLOR_CHANGE *//* EXTPROTO */voidrxvt_recolour_cursor(rxvt_t *r){    XColor	    xcol[2];    xcol[0].pixel = r->pixColorsFocus[Color_pointer];    xcol[1].pixel = VTBG(r, 0);    XQueryColors(r->Xdisplay, XCMAP, xcol, 2);    XRecolorCursor(r->Xdisplay, r->term_pointer, &(xcol[0]), &(xcol[1]));    rxvt_dbgmsg ((DBG_DEBUG, DBG_MAIN, "%s(r): fg=%06lx, bg=%06lx\n", __func__, xcol[0].pixel, xcol[1].pixel));}/*----------------------------------------------------------------------*//* * find if fg/bg matches any of the normal (low-intensity) colors *//* INTPROTO */voidrxvt_set_colorfgbg(rxvt_t *r){    unsigned int    i;    const char	 *xpmb = "\0";    char	    fstr[sizeof("default") + 1], bstr[sizeof("default") + 1];    r->h->env_colorfgbg = rxvt_malloc(sizeof("COLORFGBG=default;default;bg")			+ 1);    STRCPY(fstr, "default");    STRCPY(bstr, "default");    for (i = Color_Black; i <= Color_White; i++)	if (r->pixColorsFocus[Color_fg] == r->pixColorsFocus[i])	{	    sprintf(fstr, "%d", (i - Color_Black));	    break;	}    for (i = Color_Black; i <= Color_White; i++)	if (r->pixColorsFocus[Color_bg] == r->pixColorsFocus[i])	{	    sprintf(bstr, "%d", (i - Color_Black));#ifdef BACKGROUND_IMAGE	    xpmb = "default;";#endif	    break;	}    sprintf(r->h->env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr);    putenv(r->h->env_colorfgbg);#ifndef NO_BRIGHTCOLOR    r->h->colorfgbg = DEFAULT_RSTYLE;    for (i = minCOLOR; i <= maxCOLOR; i++)    {	if (		r->pixColorsFocus[Color_fg] == r->pixColorsFocus[i]# ifndef NO_B

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -