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

📄 tabbar.c

📁 Mrxvt是一个小巧
💻 C
📖 第 1 页 / 共 4 页
字号:
	assert (None != r->tabBar.win);	changed = r->tabBar.state;	XUnmapWindow  (r->Xdisplay, r->tabBar.win);	r->tabBar.state = 0;	return (changed);}/* * Show the tabbar *//* EXTPROTO */intrxvt_tabbar_show (rxvt_t* r){	int		changed = 0;	assert (None != r->tabBar.win);	changed = !r->tabBar.state;	XMapWindow  (r->Xdisplay, r->tabBar.win);	r->tabBar.state = 1;	return (changed);}/* * Create the tab bar window *//* EXTPROTO */voidrxvt_tabbar_create (rxvt_t* r){	XColor			color, bgcolor;	XGCValues		gcvalue;	unsigned long	gcmask;	register int	i;	int				sx, sy;#ifdef HAVE_LIBXPM	XpmAttributes	xpm_attr;	/*	 * Make sure symbol `background' exists in all .xpm files! This elimate the	 * background color so that the buttons look transparent.	 */	XpmColorSymbol	xpm_color_sym = {"background", NULL, 0};#endif	init_tabbar (r);	DBG_MSG(1,(stderr,"Creating tabbar\n"));	/* initialize the colors */	if (XDEPTH <= 2)	{		r->tabBar.fg = r->PixColors[Color_fg];		r->tabBar.bg = r->PixColors[Color_bg];		r->tabBar.ifg = r->PixColors[Color_fg];		r->tabBar.ibg = r->PixColors[Color_bg];		r->tabBar.frame = r->PixColors[Color_bg];		r->tabBar.delimit = r->PixColors[Color_fg];	}	else 	{		/* create the foreground color */		if (r->h->rs[Rs_tabfg] && 			rxvt_parse_alloc_color (r, &color, r->h->rs[Rs_tabfg]))			r->tabBar.fg = color.pixel;		else			r->tabBar.fg = r->PixColors[Color_Black];		/* create the background color */		if (r->h->rs[Rs_tabbg]	&&			rxvt_parse_alloc_color (r, &color, r->h->rs[Rs_tabbg]))			r->tabBar.bg = color.pixel;		else		{			color.red = 0xd300;			color.green = 0xd300;			color.blue = 0xdd00;			if (rxvt_alloc_color (r, &color, "Active_Tab"))				r->tabBar.bg = color.pixel;			else				r->tabBar.bg = r->PixColors[Color_bg];		}		/* create the tab frame color */		r->tabBar.frame = r->PixColors[Color_fg];		/* Create the tab delimit color */		/* r->tabBar.delimit = r->PixColors[Color_Grey25]; */		/* create the inactive tab foreground color */		if(			 r->h->rs[Rs_itabfg]			 && rxvt_parse_alloc_color (r, &color, r->h->rs[Rs_itabfg])		  )			r->tabBar.ifg = color.pixel;		else			r->tabBar.ifg = r->PixColors[Color_Black];		/* create the inactive tab background color */		if(			 r->h->rs[Rs_itabbg]			 && rxvt_parse_alloc_color( r, &color, r->h->rs[Rs_itabbg] )		  )			r->tabBar.ibg = color.pixel;		else		{			color.red	= 0xa100;			color.green = 0xa100;			color.blue	= 0xac00;			if( rxvt_alloc_color( r, &color, "Inactive_Tab_Bg" ) )				r->tabBar.ibg = color.pixel;			else				r->tabBar.ibg = r->PixColors[Color_bg];		}		/* create the delimit color (average of 3*fg & bg) */		color.pixel		= r->PixColors[Color_fg];		XQueryColor( r->Xdisplay, XCMAP, &color );		bgcolor.pixel	= r->PixColors[Color_bg];		XQueryColor( r->Xdisplay, XCMAP, &bgcolor );		color.red	= ( bgcolor.red		+ 3 * color.red		) / 4;		color.green = ( bgcolor.green	+ 3 * color.green	) / 4;		color.blue	= ( bgcolor.blue	+ 3 * color.blue	) / 4;		if( rxvt_alloc_color( r, &color, "Tab_Delimit" ) )			r->tabBar.delimit = color.pixel;		else			r->tabBar.delimit = r->PixColors[Color_fg];		DBG_MSG( 2, (stderr, "Delimit color: %hx, %hx, %hx (#%lx)\n",				color.red, color.green, color.blue, r->tabBar.delimit));	}#ifdef XFT_SUPPORT	if (r->Options & Opt_xft)	{		rxvt_alloc_xft_color (r, r->tabBar.fg, &(r->tabBar.xftfg));		rxvt_alloc_xft_color (r, r->tabBar.ifg, &(r->tabBar.xftifg));	}#endif	sx = 0;	sy = 0;#ifdef HAVE_MENUBAR	sy += rxvt_menubar_height (r);#endif	if (r->Options2 & Opt2_bottomTabbar)		sy += VT_HEIGHT(r);	/*	 * create the window of the tabbar. Use ifg and ibg for the background of	 * the tabBar so that the active tab stands out better.	 */	r->tabBar.win = XCreateSimpleWindow( r->Xdisplay, r->TermWin.parent,						sx, sy, TWIN_WIDTH(r), rxvt_tabbar_rheight( r ),						0, r->tabBar.ifg, r->tabBar.ibg );	assert( None != r->tabBar.win );#ifdef XFT_SUPPORT	if( r->Options & Opt_xft )	{		r->tabBar.xftwin = XftDrawCreate (r->Xdisplay, r->tabBar.win,								XVISUAL, XCMAP);	}#endif#ifdef DEBUG_X	rxvt_set_win_title (r, r->tabBar.win, "tabbar");#endif#ifdef BACKGROUND_IMAGE	r->tabBar.hasPixmap = False;	/* initialize it to None */	if (#ifdef TRANSPARENT			/* Transparency overrides background */			!(				(r->Options & Opt_transparent)				&& (r->Options & Opt_transparent_tabbar)			 )			&&#endif			r->h->rs[Rs_tabbarPixmap]	   )	{		long	w = 0, h = 0;		Pixmap	pmap;		pmap = rxvt_load_pixmap (r, r->h->rs[Rs_tabbarPixmap], &w, &h);		if( pmap != None)		{			XSetWindowBackgroundPixmap (r->Xdisplay, r->tabBar.win, pmap);			XFreePixmap( r->Xdisplay, pmap);			r->tabBar.hasPixmap = True;		}		else r->tabBar.hasPixmap = False;	}#endif#ifdef TRANSPARENT	if (			(r->Options & Opt_transparent)			&& (r->Options & Opt_transparent_tabbar)	   )		XSetWindowBackgroundPixmap( r->Xdisplay, r->tabBar.win, ParentRelative);#endif	/* create the GC for the tab window */	gcvalue.foreground	= r->tabBar.fg;	gcvalue.line_width	= 0;	gcvalue.line_style	= LineSolid;	gcvalue.cap_style	= CapButt;	gcvalue.join_style	= JoinMiter;	gcvalue.arc_mode	= ArcChord;		/* For coloring ATAB */	gcvalue.fill_style	= FillSolid;	/* Probably default ... */	gcmask = GCForeground | GCLineWidth				| GCLineStyle | GCCapStyle | GCJoinStyle				| GCArcMode | GCFillStyle;#ifdef TRANSPARENT	/* set background color when there's no transparent */	if (!(( r->h->am_transparent || r->h->am_pixmap_trans) &&		(r->Options & Opt_transparent_tabbar)))#endif#ifdef BACKGROUND_IMAGE		/* set background color when there's no bg image */		if ( ! r->tabBar.hasPixmap )#endif		{			gcvalue.background = r->tabBar.bg;			gcmask |= GCBackground;		}	r->tabBar.gc = XCreateGC (r->Xdisplay, r->tabBar.win,		gcmask, &gcvalue);	assert (None != r->tabBar.gc);	XDefineCursor (r->Xdisplay, r->tabBar.win, r->h->bar_pointer);	XSelectInput (r->Xdisplay, r->tabBar.win,			ExposureMask | ButtonPressMask | ButtonReleaseMask#ifdef HAVE_MENUBAR				| Button3MotionMask#endif		);#ifdef XFT_SUPPORT	if (!(r->Options & Opt_xft))#endif	XSetFont (r->Xdisplay, r->tabBar.gc, r->TermWin.font->fid);#ifdef HAVE_LIBXPM	xpm_color_sym.pixel = r->tabBar.bg;	xpm_attr.colorsymbols = &xpm_color_sym;	xpm_attr.numsymbols = 1;	xpm_attr.visual = XVISUAL;	xpm_attr.colormap = XCMAP;	xpm_attr.depth = XDEPTH;	xpm_attr.closeness = 65535;	xpm_attr.valuemask = XpmVisual | XpmColormap | XpmDepth |		XpmCloseness | XpmReturnPixels | XpmColorSymbols;#endif	/* now, create the buttons */	for (i = 0; i < NB_XPM; i++)	{#ifdef HAVE_LIBXPM		XpmCreatePixmapFromData (r->Xdisplay, r->tabBar.win,			xpm_name[i], &img_e[i], &img_emask[i], &xpm_attr);		assert (None != img_e[i]);		XpmCreatePixmapFromData (r->Xdisplay, r->tabBar.win,			xpm_d_name[i], &img_d[i], &img_dmask[i], &xpm_attr);		assert (None != img_d[i]);#else		img[i] = XCreatePixmapFromBitmapData (r->Xdisplay,			r->tabBar.win, xpm_name[i], BTN_WIDTH, BTN_HEIGHT,			r->tabBar.fg, r->tabBar.bg, XDEPTH);		assert (None != img[i]);#endif	}	DBG_MSG( 3, ( stderr,				"TXT_XOFF=%d, TXT_YOFF=%d, ATAB_EXTRA=%d, TAB_RADIUS=%d\n",				TXT_XOFF, TXT_YOFF, ATAB_EXTRA, TAB_RADIUS) );}/* * Create the tab bar window *//* EXTPROTO */voidrxvt_tabbar_clean_exit (rxvt_t* r){	register int	i;	r->tabBar.win = None;	/* destroyed by XDestroySubwindows */	/* free resource strings */	if (r->tabBar.rsfg)		free ((void*) r->h->rs[Rs_tabfg]);	if (r->tabBar.rsbg)		free ((void*) r->h->rs[Rs_tabbg]);	if (r->tabBar.rsifg)		free ((void*) r->h->rs[Rs_itabfg]);	if (r->tabBar.rsibg)		free ((void*) r->h->rs[Rs_itabbg]);	if (None != r->tabBar.gc)	{		XFreeGC (r->Xdisplay, r->tabBar.gc);		r->tabBar.gc = None;	}	for (i = 0; i < NB_XPM; i ++)	{#ifdef HAVE_LIBXPM		if (None != img_e[i])		{			XFreePixmap (r->Xdisplay, img_e[i]);			img_e[i] = None;		}		if (None != img_emask[i])		{			XFreePixmap (r->Xdisplay, img_emask[i]);			img_emask[i] = None;		}		if (None != img_d[i])		{			XFreePixmap (r->Xdisplay, img_d[i]);			img_d[i] = None;		}		if (None != img_dmask[i])		{			XFreePixmap (r->Xdisplay, img_dmask[i]);			img_dmask[i] = None;		}#else		if (None != img[i])			XFreePixmap (r->Xdisplay, img[i]);#endif		img[i] = None;	}	/* for */}/* EXTPROTO */unsigned shortrxvt_tabbar_height (rxvt_t* r){	if (None == r->tabBar.win || !r->tabBar.state)		return 0;	return (rxvt_tabbar_rheight(r));}/* EXTPROTO */unsigned shortrxvt_tabbar_rheight (rxvt_t* r){	return (r->TermWin.FHEIGHT + 2*TXT_MARGIN + 2*TAB_BORDER + ATAB_EXTRA);}/* EXTPROTO */unsigned intrxvt_tab_width (rxvt_t *r, const char *str){#ifdef XFT_SUPPORT	if ( (r->Options & Opt_xft) && r->TermWin.xftpfont)	{		/*		 * With a proportionally spaced font defined, let's try and make the		 * tabs look like firefox. All tabs have the same width. The more tabs		 * there are, the narrower the width becomes. The width does not depend		 * on the tab title.		 */		if( LTAB(r) >= 0 )		{			int twidth = (TAB_SPACE - TAB_BORDER)							/ min( LTAB(r) + 1, r->TermWin.minVisibleTabs )							- TAB_BORDER;			return min( twidth, MAX_TAB_PIXEL_WIDTH);		}		else return MAX_TAB_PIXEL_WIDTH;	}	else#endif	{		int			len;		RUINT16T	maxw = r->TermWin.maxTabWidth;		assert (str);		len = STRLEN (str);		if (len > maxw)			len = maxw;#ifdef XFT_SUPPORT		if ((r->Options & Opt_xft) && (NULL != r->tabBar.xftwin))		{			return (2 * TXT_XOFF + Width2Pixel(len));		}		else#endif	/* XFT_SUPPORT */		return (2 * TXT_XOFF + XTextWidth (r->TermWin.font, str, len));	}}/* EXTPROTO */intrxvt_is_tabbar_win (rxvt_t* r, Window w){	return (w == r->tabBar.win);}/* EXTPROTO */voidrxvt_tabbar_change_color (rxvt_t* r, int item, const char* str){	XColor		xcol;	int			changed = 0;	switch (item)	{		case MRxvt_tabfg:			if (r->h->rs[Rs_tabfg] &&				!STRCASECMP(str, r->h->rs[Rs_tabfg]))				break;	/* no color change */			if (rxvt_parse_alloc_color (r, &xcol, str))			{				r->tabBar.fg = xcol.pixel;#ifdef XFT_SUPPORT				rxvt_alloc_xft_color (r, xcol.pixel, &(r->tabBar.xftfg));#endif				if (r->tabBar.rsfg)		/* free previous string */					free ((void*) r->h->rs[Rs_tabfg]);				r->h->rs[Rs_tabfg] = STRDUP(str);				r->tabBar.rsfg = 1;		/* free resource string later */				changed = 1;			}			break;		case MRxvt_tabbg:			if (r->h->rs[Rs_tabbg] &&				!STRCASECMP(str, r->h->rs[Rs_tabbg]))				break;	/* no color change */			if (rxvt_parse_alloc_color (r, &xcol, str))			{				r->tabBar.bg = xcol.pixel;				if (r->tabBar.rsbg)		/* free previous string */					free ((void*) r->h->rs[Rs_tabbg]);				r->h->rs[Rs_tabbg] = STRDUP(str);				r->tabBar.rsbg = 1;		/* free resource string later */				changed = 1;			}			break;		case MRxvt_itabfg:			if (r->h->rs[Rs_itabfg] &&				!STRCASECMP(str, r->h->rs[Rs_itabfg]))				break;	/* no color change */			if (rxvt_parse_alloc_color (r, &xcol, str))			{				r->tabBar.ifg = xcol.pixel;#ifdef XFT_SUPPORT				rxvt_alloc_xft_color (r, xcol.pixel, &(r->tabBar.xftifg));#endif				if (r->tabBar.rsifg)	/* free previous string */					free ((void*) r->h->rs[Rs_itabfg]);				r->h->rs[Rs_itabfg] = STRDUP(str);				r->tabBar.rsifg = 1;	/* free resource string later */				changed = 1;			}			break;		case MRxvt_itabbg:			if (r->h->rs[Rs_itabbg] && !STRCASECMP(str, r->h->rs[Rs_itabbg]))				break;			if (rxvt_parse_alloc_color (r, &xcol, str))			{				r->tabBar.ibg = xcol.pixel;				if (r->tabBar.rsibg)	/* free previous string */					free ((void*) r->h->rs[Rs_itabbg]);				r->h->rs[Rs_itabbg] = STRDUP(str);				r->tabBar.rsibg = 1;	/* free resource string later */				changed = 1;			}			break;				default:			break;	}	if (changed)	{		if (MRxvt_itabbg == item)		{#if defined(TRANSPARENT) || defined(BACKGROUND_IMAGE)			if (# ifdef TRANSPARENT					(					 (r->h->am_transparent || r->h->am_pixmap_trans)					 && (r->Options & Opt_transparent_tabbar)					)# endif# if defined(TRANSPARENT) && defined(BACKGROUND_IMAGE)				||# endif# ifdef BACKGROUND_IMAGE				( r->tabBar.hasPixmap )# endif			   )			{# ifdef HAVE_LIBXRENDER				/* Background image needs to be regrabed */				rxvt_refresh_bg_image(r, ATAB(r), False);# endif			}			else#endif			{				XSetWindowBackground (r->Xdisplay, r->tabBar.win,						r->tabBar.ibg);			}		}		/*		 * Better to put the expose event on the queue, than expose immediately.		 * Expose events can be expensive when using XRender transparency.		 */		XClearArea( r->Xdisplay, r->tabBar.win, 0, 0, 0, 0, True);	}}/* * Move active tab to position newPage. *//* EXTPROTO */voidrxvt_tabbar_move_tab (rxvt_t* r, short newPage){	short	curPage		= ATAB(r);	short	i;		if (			0 == LTAB(r) ||						/* Only one tab (no move												   possible) */			newPage == curPage ||				/* Move to itself */			newPage < 0 || newPage > LTAB(r)	/* Out of range */	   )		return;	if( newPage < curPage )	{		term_t* temp_vt = r->vts[curPage];		/* Shift pages newPage .. curPage-1 one to the right. */		for( i = curPage; i > newPage; i--)			r->vts[i] = r->vts[i-1];		r->vts[newPage] = temp_vt;		/* Update selection */		if( r->selection.vt >= newPage && r->selection.vt < curPage )			r->selection.vt++;		else if( r->selection.vt == curPage )			r->selection.vt = newPage;	}	else	{		term_t* temp_vt = r->vts[curPage];		/* Shift pages curPage+1 .. newPage one to the left. */		for( i = curPage; i < newPage; i++)			r->vts[i] = r->vts[i+1];		r->vts[newPage] = temp_vt;		/* Update selection */		if( r->selection.vt > curPage && r->selection.vt <= newPage)			r->selection.vt--;		else if( r->selection.vt == curPage )			r->selection.vt = newPage;	}	/* adjust active tab */	ATAB(r) = newPage;	/* adjust previous active tab */	if (PTAB(r) == newPage) PTAB(r) = curPage;	/* refresh tabbar */	if (newPage < FVTAB(r) || newPage > LVTAB(r))		rxvt_tabbar_set_visible_tabs (r, True);	else	{		/*		 * If the width of newPage is different from that of curPage, then all		 * tabs in between newPage and curPage will have to be refreshed.		 */		for( i = min( newPage, curPage ); i <= max( newPage, curPage ); i++ )			refresh_tabbar_tab( r, i);	}}/*----------------------- end-of-file (C source) -----------------------*/

⌨️ 快捷键说明

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