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

📄 tabbar.c

📁 multi-tabed terminal based on rxvt
💻 C
📖 第 1 页 / 共 5 页
字号:
}/* * Set new title for a tab *//* EXTPROTO */voidrxvt_tabbar_set_title (rxvt_t* r, short page, const unsigned char TAINTED * str){    char UNTAINTED *	    n_title;    assert (str);    assert (page >= 0 && page <= LTAB(r));    assert (PVTS(r, page)->tab_title);    n_title = STRNDUP (str, MAX_TAB_TXT);    /*     * If strdup succeeds, set new title     */    if (NULL != n_title)    {	rxvt_free (PVTS(r, page)->tab_title);	PVTS(r, page)->tab_title = n_title;	/* Compute the new width of the tab */	PVTS(r, page)->tab_width = rxvt_tab_width (r, n_title);    }    /*     * If visible tab's title is changed, refresh tab bar     */    if (page >= FVTAB(r) && page <= LVTAB(r))    {	/* adjust visible tabs */	rxvt_tabbar_set_visible_tabs (r, True);	refresh_tabbar_tab(r, page);    }    /* synchronize terminal title with active tab title */    if (ISSET_OPTION(r, Opt2_syncTabTitle) &&	(page == ATAB(r)))	sync_tab_title( r, ATAB(r) );    /* synchronize icon name to tab title */    if (ISSET_OPTION(r, Opt2_syncTabIcon) &&	(page == ATAB(r)))	rxvt_set_icon_name(r,		(const unsigned char*) PVTS(r, ATAB(r))->tab_title);}/* * Activate a page terminal *//* EXTPROTO */voidrxvt_activate_page (rxvt_t* r, short index){    /* shortcut */    if (/* !r->tabBar.state ||	NOT_WIN(r->tabBar.win) || */	index == ATAB(r))	return;    AVTS(r)->mapped = 0;    r->tabBar.ptab = ATAB(r);    ATAB(r) = index;    AVTS(r)->mapped = 1;    AVTS(r)->highlight = 0; /* clear highlight flag */        /*     * Now the visible tabs may be changed, recompute the visible     * tabs before redrawing.     */    if (index < FVTAB(r) || index > LVTAB(r))    {	/* adjust visible tabs */	rxvt_tabbar_set_visible_tabs (r, True);    }    refresh_tabbar_tab( r, ATAB(r));    refresh_tabbar_tab( r, PTAB(r));    /* Switch VT fg/bg colors */    rxvt_set_vt_colors( r, ATAB(r) );    XMapRaised( r->Xdisplay, AVTS(r)->vt );    /*     * We don't need to touch the screen here. XMapRaised will generate a     * MapNotify and Expose events, which will refresh the screen as needed.     * Touching the screen unnecessarily causes a flicker (and is *horrible*     * under slow connections).     */    /* rxvt_scr_touch (r, ATAB(r), True); */    rxvt_dbgmsg ((DBG_VERBOSE, DBG_TABBAR, "active page is %d\n",ATAB(r)));    /* synchronize terminal title with tab title */    if (ISSET_OPTION(r, Opt2_syncTabTitle))	sync_tab_title( r, ATAB(r) );    /* synchronize icon name to tab title */    if (ISSET_OPTION(r, Opt2_syncTabIcon))	rxvt_set_icon_name (r,		(const unsigned char*) PVTS(r, ATAB(r))->tab_title);}/* * Change the width of the tab bar *//* EXTPROTO */voidrxvt_tabbar_resize (rxvt_t* r){    register int    i;    int		    sx, sy;    sx = 0;    sy = 0;#ifdef HAVE_MENUBAR    sy += rxvt_menubar_height (r);#endif    if (ISSET_OPTION(r, Opt2_bottomTabbar))	sy += VT_HEIGHT(r);    XMoveResizeWindow  (r->Xdisplay, r->tabBar.win,	sx, sy, TWIN_WIDTH(r), rxvt_tabbar_rheight (r));    /* recompute width of each tab */    for (i = 0; i <= LTAB(r); i ++)	PVTS(r, i)->tab_width = rxvt_tab_width (r, PVTS(r, i)->tab_title);    /* adjust visible tabs */    rxvt_tabbar_set_visible_tabs (r, False);    /* redraw the tabs and buttons */    XClearArea( r->Xdisplay, r->tabBar.win,	    0, 0, 0, 0, True);}/* * Determine the position of pointer click and dispatch the event *//* EXTPROTO */voidrxvt_tabbar_dispatcher (rxvt_t* r, XButtonEvent* ev){    register int    x, y, z, but;    x = ev->x;    y = ev->y;    but = -1;    rxvt_dbgmsg ((DBG_DEBUG, DBG_TABBAR, "click in (%d,%d)\n", x, y));    /* Button4/Button5 of wheel mouse activate the left/right tab as       Mozilla firefox */    switch ( ev->button )    {#ifdef HAVE_MENUBAR	case Button3:	    if( r->h->popupMenu[0] )	    {		int	x, y;		Window	unused_cr;		r->h->showingMenu |= POPUP_MENU;		XTranslateCoordinates( r->Xdisplay, ev->window,			r->TermWin.parent, ev->x, ev->y, &x, &y, &unused_cr);		r->h->ActiveMenu = r->h->popupMenu[0];		r->h->ActiveMenu->x = x;		r->h->ActiveMenu->y = y;		XDefineCursor(r->Xdisplay, AVTS(r)->vt, r->h->bar_pointer);		rxvt_menu_show(r);		return;	    }	    break;#endif	case Button4: /* activate left tab */	    if (0 != ATAB(r))		rxvt_activate_page (r, ATAB(r)-1);	    else if (0 != LTAB(r))		rxvt_activate_page (r, LTAB(r));	    return;	case Button5: /* activate right tab */	    if( ATAB(r) != LTAB(r) )		rxvt_activate_page( r, ATAB(r) + 1 );	    else if( 0 != LTAB(r) )		rxvt_activate_page( r, 0 );	    return;	default:	    break;    }    /* let's decode where the user click */    z = TWIN_WIDTH(r) - x;    if (	    NOTSET_OPTION(r, Opt2_hideButtons)	    && z < 4*(BTN_WIDTH+BTN_SPACE)	    && (z%(BTN_WIDTH+BTN_SPACE)) > BTN_SPACE       )    {	but = z/(BTN_WIDTH+BTN_SPACE);	/* we should only handle left-mouse-button clicks */	if ( ev->button != Button1 )	{	    rxvt_dbgmsg ((DBG_VERBOSE, DBG_TABBAR,"skip non-left-mouse-button click\n"));	    return;	}	rxvt_dbgmsg ((DBG_VERBOSE, DBG_TABBAR,"click on button %d\n",but));	switch(but)	{	    case 0 : /* right shift */		if (r->tabBar.atab < LTAB(r))		    rxvt_activate_page (r, r->tabBar.atab+1);		break;	    case 1 : /* left shift */		if (r->tabBar.atab > 0)		    rxvt_activate_page (r, r->tabBar.atab-1);		break;	    case 2 : /* delete the active vt if it's in primary screen */		if(		    NOTSET_OPTION(r, Opt2_protectSecondary) ||		    (		       ISSET_OPTION(r, Opt2_protectSecondary) &&		       PRIMARY == AVTS(r)->current_screen		    )		  )		{		    /*		     * 2006-09-19 gi1242: If user presses the X button, don't		     * hold the tab open, regardless of exit status.		     */		    AVTS(r)->holdOption &= ~(HOLD_NORMALBIT|HOLD_STATUSBIT);		    rxvt_kill_page (r, ATAB(r));		}		break;	    case 3 : /* create a new vt*/		rxvt_append_page (r, 0, NULL, NULL);		break;	    default :		break;	}    }    else if ( x < TAB_SPACE && LTAB(r) >= 0)    {	register int	w = 0;	register int	i;	for ( i = FVTAB(r); w < x && i <= LVTAB(r); i++)	    w += TAB_WIDTH(i);	if( w - TAB_BORDER >= x )	{	    but = i - 1;	    rxvt_dbgmsg ((DBG_DEBUG, DBG_TABBAR,"click on tab %d\n", but));	    switch( ev->button )	    {		case Button1:		    /* activate the selected tab */		    rxvt_activate_page (r, but);		    r->tabClicked = but;		    break;		case Button2:		    /* change tab title on middle click */		    if (NULL != r->selection.text)			rxvt_tabbar_set_title (r, but, r->selection.text);		    break;	    }	}	else	{	    /* change tab title of active tab on middle click */	    if ((Button2 == ev->button) && (NULL != r->selection.text))		rxvt_tabbar_set_title (r, ATAB(r), r->selection.text);	}    }}/* * Check if we're dragging a tab. If yes, then move the tab. * * TODO: Set a different cursor when dragging a tab. *//* EXTPROTO */voidrxvt_tabbar_button_release( rxvt_t *r, XButtonEvent *ev){    int	    w, droppedTab;    do	/* while( 0 ) */    {	if (		ev->button != Button1		    /* Ignore everything except						       left clicks */		|| r->tabClicked == -1		    /* If we're not dragging a						       tab then nothing to do */		|| ev->y < 0		|| ev->y > rxvt_tabbar_rheight( r ) /* If we drag off the						       tabbar. (Coordinates in						       ev are relative to the						       tabbar window) */	   )	    break;	/* Figure out where the user released the mouse */	for (		droppedTab = FVTAB(r), w=0;		w < ev->x && droppedTab <= LVTAB(r);		droppedTab++	    )	    w += TAB_WIDTH( droppedTab );	rxvt_dbgmsg ((DBG_DEBUG, DBG_TABBAR, "Dragged tab %d to %d (%d, %d)\n", r->tabClicked, droppedTab - 1, ev->x, ev->y));	/* Move active tab there */	rxvt_tabbar_move_tab( r, droppedTab - 1 );    } while( 0 );    r->tabClicked = -1;}/* * Is the tabbar visible *//* EXTPROTO */intrxvt_tabbar_visible (rxvt_t* r){    return (IS_WIN(r->tabBar.win) && r->tabBar.state);}/* * Expose handler for tabbar *//* EXTPROTO */voidrxvt_tabbar_expose (rxvt_t* r, XEvent *ev){    Region region;        UNSET_REGION(region);    if( ev && ev->type == Expose)    {	region = XCreateRegion();	do	{	    XRectangle rect;	    rect.x	= ev->xexpose.x;	    rect.y	= ev->xexpose.y;	    rect.width	= ev->xexpose.width;	    rect.height	= ev->xexpose.height;	    XUnionRectWithRegion( &rect, region, region);	} while( XCheckTypedWindowEvent( r->Xdisplay, r->tabBar.win,		    Expose, ev));    }    else XClearWindow (r->Xdisplay, r->tabBar.win);    /* draw the tabs and blank space*/    rxvt_draw_tabs(r, region);    /* draw the buttons */    rxvt_tabbar_draw_buttons (r);    if (IS_REGION(region))	XDestroyRegion( region );}/* * Hide the tabbar *//* EXTPROTO */intrxvt_tabbar_hide (rxvt_t* r){    int	    changed = 0;    assert (IS_WIN(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 (IS_WIN(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);    rxvt_dbgmsg ((DBG_VERBOSE, DBG_TABBAR,"Creating tabbar\n"));    /* initialize the colors */    if (XDEPTH <= 2)    {	r->tabBar.fg = r->pixColorsFocus[Color_fg];	r->tabBar.bg = r->pixColorsFocus[Color_bg];	r->tabBar.ifg = r->pixColorsFocus[Color_fg];	r->tabBar.ibg = r->pixColorsFocus[Color_bg];	r->tabBar.frame = r->pixColorsFocus[Color_bg];	r->tabBar.delimit = r->pixColorsFocus[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;#ifdef XFT_SUPPORT	    if( ISSET_OPTION( r, Opt_xft ) )		rxvt_alloc_xft_color( r, &color, &r->tabBar.xftfg );#endif	}	else	{	    r->tabBar.fg = r->pixColorsFocus[Color_Black];#ifdef XFT_SUPPORT	    if( ISSET_OPTION( r, Opt_xft ) )		r->tabBar.xftfg = r->xftColorsFocus[Color_Black];#endif	}	/*	 * 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 = VTBG(r,0);	}	/* create the tab frame color */	r->tabBar.frame = r->pixColorsFocus[Color_fg];	/* 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;#ifdef XFT_SUPPORT	    if( ISSET_OPTION( r, Opt_xft ) )		rxvt_alloc_xft_color( r, &color, &r->tabBar.xftifg );#endif	}	else	{	    r->tabBar.ifg = r->pixColorsFocus[Color_Black];

⌨️ 快捷键说明

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