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

📄 rxvtlib_main.c

📁 具有IDE功能的编辑器
💻 C
📖 第 1 页 / 共 3 页
字号:
#include "rxvtlib.h"/*--------------------------------*-C-*---------------------------------* * File:	main.c *----------------------------------------------------------------------* * $Id: main.c,v 1.66.2.7 1999/08/17 08:11:03 mason Exp $ * * All portions of code are copyright by their respective author/s. * Copyright (C) 1992      John Bovey, University of Canterbury *				- original version * Copyright (C) 1994      Robert Nation <nation@rocket.sanders.lockheed.com> *				- extensive modifications * Copyright (C) 1995      Garrett D'Amore <garrett@netcom.com> * Copyright (C) 1997      mj olesen <olesen@me.QueensU.CA> *				- extensive modifications * Copyright (C) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> * Copyright (C) 1998      Geoff Wing <gcw@pobox.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *---------------------------------------------------------------------*/int rxvt_get_fontwidest (rxvtlib *o, XFontStruct * f);	/* cursor for vt window *//* low-intensity colors *//* 0: black             (#000000) */#ifndef NO_BRIGHTCOLOR/* 1: red               (#CD0000) *//* 2: green             (#00CD00) *//* 3: yellow            (#CDCD00) *//* 4: blue              (#0000CD) *//* 5: magenta           (#CD00CD) *//* 6: cyan              (#00CDCD) *//* 7: white             (#FAEBD7) *//* high-intensity colors *//* 8: bright black      (#404040) */#endif				/* NO_BRIGHTCOLOR *//* 1/9: bright red      (#FF0000) *//* 2/10: bright green   (#00FF00) *//* 3/11: bright yellow  (#FFFF00) *//* 4/12: bright blue    (#0000FF) *//* 5/13: bright magenta (#FF00FF) *//* 6/14: bright cyan    (#00FFFF) *//* 7/15: bright white   (#FFFFFF) *//* Color_pointer                  *//* Color_border                   */#ifndef NO_BOLDUNDERLINE/* Color_BD                       *//* Color_UL                       */#endif				/* ! NO_BOLDUNDERLINE */#ifdef MULTICHAR_SET/* Multicharacter font names, roman fonts sized to match */#endif				/* MULTICHAR_SET *//*----------------------------------------------------------------------*//* ARGSUSED *//* INTPROTO */#ifdef STANDALONEXErrorHandler   xerror_handler (const Display * display,				const XErrorEvent * event){    print_error ("XError: Request: %d . %d, Error: %d", event->request_code,		 event->minor_code, event->error_code);    return 0;}#endif/* color aliases, fg/bg bright-bold *//* INTPROTO */void            rxvtlib_color_aliases (rxvtlib *o, int idx){    if (o->rs[Rs_color + idx] && isdigit (*(o->rs[Rs_color + idx]))) {	int             i = atoi (o->rs[Rs_color + idx]);	if (i >= 8 && i <= 15) {	/* bright colors */	    i -= 8;#ifndef NO_BRIGHTCOLOR	    o->rs[Rs_color + idx] = o->rs[Rs_color + minBrightCOLOR + i];	    return;#endif	}	if (i >= 0 && i <= 7)	/* normal colors */	    o->rs[Rs_color + idx] = o->rs[Rs_color + minCOLOR + i];    }}/* * find if fg/bg matches any of the normal (low-intensity) colors *//* INTPROTO */void            rxvtlib_set_colorfgbg (rxvtlib *o){    unsigned int    i;    char           *p;    int             fg = -1, bg = -1;    static char     env_colorfgbg[] = "COLORFGBG=default;default;bg";    for (i = Color_Black; i <= Color_White; i++) {	if (o->PixColors[Color_fg] == o->PixColors[i]) {	    fg = (i - Color_Black);	    break;	}    }    for (i = Color_Black; i <= Color_White; i++) {	if (o->PixColors[Color_bg] == o->PixColors[i]) {	    bg = (i - Color_Black);	    break;	}    }    p = strchr (env_colorfgbg, '=');    p++;    if (fg >= 0)	sprintf (p, "%d;", fg);    else	STRCPY (p, "default;");    p = strchr (p, '\0');    if (bg >= 0)	sprintf (p,#ifdef XPM_BACKGROUND		 "default;"#endif		 "%d", bg);    else	STRCPY (p, "default");    putenv (env_colorfgbg);#ifndef NO_BRIGHTCOLOR    o->colorfgbg = DEFAULT_RSTYLE;    for (i = minCOLOR; i <= maxCOLOR; i++) {	if (o->PixColors[Color_fg] == o->PixColors[i]# ifndef NO_BOLDUNDERLINE	    && o->PixColors[Color_fg] == o->PixColors[Color_BD]# endif				/* NO_BOLDUNDERLINE */	    /* if we wanted boldFont to have precedence */# if 0				/* ifndef NO_BOLDFONT */	    && o->TermWin.boldFont == NULL# endif				/* NO_BOLDFONT */	    )	    o->colorfgbg = SET_FGCOLOR (o->colorfgbg, i);	if (o->PixColors[Color_bg] == o->PixColors[i])	    o->colorfgbg = SET_BGCOLOR (o->colorfgbg, i);    }#endif}/* INTPROTO */void            rxvtlib_Get_Colours (rxvtlib *o){    int             i;    for (i = 0; i < (o->Xdepth <= 2 ? 2 : NRS_COLORS); i++) {	const char     *msg = "can't load color \"%s\"";	XColor          xcol;	if (!o->rs[Rs_color + i])	    continue;	if (!XParseColor (o->Xdisplay, o->Xcmap, o->rs[Rs_color + i], &xcol)	    || !XAllocColor (o->Xdisplay, o->Xcmap, &xcol)) {	    print_error (msg, o->rs[Rs_color + i]);#ifndef XTERM_REVERSE_VIDEO	    if (i < 2 && (o->Options & Opt_reverseVideo)) {		o->rs[Rs_color + i] = o->def_colorName[!i];	    } else#endif		o->rs[Rs_color + i] = o->def_colorName[i];	    if (!o->rs[Rs_color + i])		continue;	    if (!XParseColor (o->Xdisplay, o->Xcmap, o->rs[Rs_color + i], &xcol)		|| !XAllocColor (o->Xdisplay, o->Xcmap, &xcol)) {		print_error (msg, o->rs[Rs_color + i]);		switch (i) {		case Color_fg:		case Color_bg:		    /* fatal: need bg/fg color */		    print_error ("aborting");		    o->killed = EXIT_FAILURE | DO_EXIT;		    return;		    /* NOTREACHED */		    break;#ifndef NO_CURSORCOLOR		case Color_cursor2:		    xcol.pixel = o->PixColors[Color_fg];		    break;#endif				/* ! NO_CURSORCOLOR */		case Color_pointer:		    xcol.pixel = o->PixColors[Color_fg];		    break;		default:		    xcol.pixel = o->PixColors[Color_bg];	/* None */		    break;		}	    }	}	o->PixColors[i] = xcol.pixel;    }    if (o->Xdepth <= 2 || !o->rs[Rs_color + Color_pointer])	o->PixColors[Color_pointer] = o->PixColors[Color_fg];    if (o->Xdepth <= 2 || !o->rs[Rs_color + Color_border])	o->PixColors[Color_border] = o->PixColors[Color_fg];/* * get scrollBar/menuBar shadow colors * * The calculations of topShadow/bottomShadow values are adapted * from the fvwm window manager. */#ifdef KEEP_SCROLLCOLOR    if (o->Xdepth <= 2) {		/* Monochrome */	o->PixColors[Color_scroll] = o->PixColors[Color_fg];	o->PixColors[Color_topShadow] = o->PixColors[Color_bg];	o->PixColors[Color_bottomShadow] = o->PixColors[Color_bg];    } else {	XColor          xcol, white;	/* bottomShadowColor */	xcol.pixel = o->PixColors[Color_scroll];	XQueryColor (o->Xdisplay, o->Xcmap, &xcol);	xcol.red = ((xcol.red) / 2);	xcol.green = ((xcol.green) / 2);	xcol.blue = ((xcol.blue) / 2);	if (!XAllocColor (o->Xdisplay, o->Xcmap, &xcol)) {	    print_error ("can't allocate %s", "Color_bottomShadow");	    xcol.pixel = o->PixColors[minCOLOR];	}	o->PixColors[Color_bottomShadow] = xcol.pixel;	/* topShadowColor */# ifdef PREFER_24BIT	white.red = white.green = white.blue = (unsigned short)~0;	XAllocColor (o->Xdisplay, o->Xcmap, &white);/*        XFreeColors(Xdisplay, Xcmap, &white.pixel, 1, ~0); */# else	white.pixel = WhitePixel (o->Xdisplay, Xscreen);	XQueryColor (o->Xdisplay, o->Xcmap, &white);# endif	xcol.pixel = o->PixColors[Color_scroll];	XQueryColor (o->Xdisplay, o->Xcmap, &xcol);	xcol.red = max ((white.red / 5), xcol.red);	xcol.green = max ((white.green / 5), xcol.green);	xcol.blue = max ((white.blue / 5), xcol.blue);	xcol.red = min (white.red, (xcol.red * 7) / 5);	xcol.green = min (white.green, (xcol.green * 7) / 5);	xcol.blue = min (white.blue, (xcol.blue * 7) / 5);	if (!XAllocColor (o->Xdisplay, o->Xcmap, &xcol)) {	    print_error ("can't allocate %s", "Color_topShadow");	    xcol.pixel = o->PixColors[Color_White];	}	o->PixColors[Color_topShadow] = xcol.pixel;    }#endif				/* KEEP_SCROLLCOLOR */}Cursor TermWin_cursor = 0;Cursor Font_cursor = 0;/* Create_Windows() - Open and map the window *//* INTPROTO */void            rxvtlib_Create_Windows (rxvtlib *o, int argc, const char *const *argv){    XClassHint      classHint;    XWMHints        wmHint;#ifdef PREFER_24BIT/* FIXME: free colormap */    XSetWindowAttributes attributes;    o->Xdepth = DefaultDepth (o->Xdisplay, Xscreen);    o->Xcmap = DefaultColormap (o->Xdisplay, Xscreen);    o->Xvisual = DefaultVisual (o->Xdisplay, Xscreen);/* * If depth is not 24, look for a 24bit visual. */    if (o->Xdepth != 24) {	XVisualInfo     vinfo;	if (XMatchVisualInfo (o->Xdisplay, Xscreen, 24, TrueColor, &vinfo)) {	    o->Xdepth = 24;	    o->Xvisual = vinfo.visual;	    o->Xcmap = XCreateColormap (o->Xdisplay, RootWindow (o->Xdisplay, Xscreen),				     o->Xvisual, AllocNone);	}    }#endif/* grab colors before netscape does */    rxvtlib_Get_Colours (o);    if (o->killed)	return;    rxvtlib_change_font (o, 1, NULL);    if (o->killed)	return;    rxvtlib_szhints_set (o);/* parent window - reverse video so we can see placement errors * sub-window placement & size in resize_subwindows() */#if 0#ifndef STANDALONE    o->szHint.x = -2;    o->szHint.y = -2;#endif#endif#ifdef PREFER_24BIT    attributes.background_pixel = o->PixColors[Color_fg];    attributes.border_pixel = o->PixColors[Color_border];    attributes.colormap = o->Xcmap;#ifdef STANDALONE    o->TermWin.parent[0] = XCreateWindow (o->Xdisplay, Xroot,#else    o->TermWin.parent[0] = XCreateWindow (o->Xdisplay, o->parent_window,#endif				       o->szHint.x, o->szHint.y,				       o->szHint.width, o->szHint.height,				       BORDERWIDTH,				       o->Xdepth, InputOutput,				       o->Xvisual,				       CWBackPixel | CWBorderPixel |				       CWColormap, &attributes);#else#ifdef STANDALONE    o->TermWin.parent[0] = XCreateSimpleWindow (o->Xdisplay, o->parent_window,#else    o->TermWin.parent[0] = XCreateSimpleWindow (o->Xdisplay, Xroot,#endif					     o->szHint.x, o->szHint.y,					     o->szHint.width, o->szHint.height,					     BORDERWIDTH,					     o->PixColors[Color_border],					     o->PixColors[Color_fg]);#endif    rxvtlib_xterm_seq (o, XTerm_title, o->rs[Rs_title]);    rxvtlib_xterm_seq (o, XTerm_iconName, o->rs[Rs_iconName]);/* ignore warning about discarded `const' */    classHint.res_name = (char *)o->rs[Rs_name];    classHint.res_class = (char *)APL_CLASS;    wmHint.input = True;    wmHint.initial_state = (o->Options & Opt_iconic ? IconicState : NormalState);    wmHint.window_group = o->TermWin.parent[0];    wmHint.flags = (InputHint | StateHint | WindowGroupHint);    XSetWMProperties (o->Xdisplay, o->TermWin.parent[0], NULL, NULL, (char **)argv,		      argc, &o->szHint, &wmHint, &classHint);    XSelectInput (o->Xdisplay, o->TermWin.parent[0],		  (KeyPressMask | FocusChangeMask | PropertyChangeMask		   | VisibilityChangeMask | StructureNotifyMask));/* vt cursor: Black-on-White is standard, but this is more popular */    if (!TermWin_cursor)	TermWin_cursor = XCreateFontCursor (o->Xdisplay, XC_xterm);    {	XColor          fg, bg;	fg.pixel = o->PixColors[Color_pointer];	XQueryColor (o->Xdisplay, o->Xcmap, &fg);	bg.pixel = o->PixColors[Color_bg];	XQueryColor (o->Xdisplay, o->Xcmap, &bg);	XRecolorCursor (o->Xdisplay, TermWin_cursor, &fg, &bg);    }/* cursor (menuBar/scrollBar): Black-on-White */    if (!Font_cursor)	Font_cursor = XCreateFontCursor (o->Xdisplay, XC_left_ptr);/* the vt window */    o->TermWin.vt = XCreateSimpleWindow (o->Xdisplay, o->TermWin.parent[0],				      0, 0,				      o->szHint.width, o->szHint.height,				      0,				      o->PixColors[Color_fg],				      o->PixColors[Color_bg]);    XDefineCursor (o->Xdisplay, o->TermWin.vt, TermWin_cursor);    XSelectInput (o->Xdisplay, o->TermWin.vt,		  (ExposureMask | ButtonPressMask | ButtonReleaseMask | PropertyChangeMask |		   Button1MotionMask | Button3MotionMask));/* scrollBar: size doesn't matter */    o->scrollBar.win = XCreateSimpleWindow (o->Xdisplay, o->TermWin.parent[0],					 0, 0,					 1, 1,					 0,					 o->PixColors[Color_fg],					 o->PixColors[Color_bg]);    XDefineCursor (o->Xdisplay, o->scrollBar.win, Font_cursor);    XSelectInput (o->Xdisplay, o->scrollBar.win,		  (ExposureMask | ButtonPressMask | ButtonReleaseMask |		   Button1MotionMask | Button2MotionMask | Button3MotionMask));    {				/* ONLYIF MENUBAR */	rxvtlib_create_menuBar (o, Font_cursor);    }#ifdef XPM_BACKGROUND    if (o->rs[Rs_backgroundPixmap] != NULL && !(o->Options & Opt_transparent)) {	const char     *p = o->rs[Rs_backgroundPixmap];	if ((p = strchr (p, ';')) != NULL) {	    p++;	    rxvtlib_scale_pixmap (o, p);	}	rxvtlib_set_bgPixmap (o, o->rs[Rs_backgroundPixmap]);	rxvtlib_scr_touch (o);    }# ifdef XPM_BUFFERING    else {	rxvtlib_set_bgPixmap (o, "");	rxvtlib_scr_touch (o);    }# endif#endif/* graphics context for the vt window */    {	XGCValues       gcvalue;	gcvalue.font = o->TermWin.font->fid;	gcvalue.foreground = o->PixColors[Color_fg];	gcvalue.background = o->PixColors[Color_bg];	gcvalue.graphics_exposures = 0;	o->TermWin.gc = XCreateGC (o->Xdisplay, o->TermWin.vt,				GCForeground | GCBackground |				GCFont | GCGraphicsExposures, &gcvalue);    }}/* window resizing - assuming the parent window is the correct size *//* INTPROTO */void            rxvtlib_resize_subwindows (rxvtlib *o, int width, int height){    int             x = 0, y = 0;    int             old_width = o->TermWin.width, old_height = o->TermWin.height;    o->TermWin.width = o->TermWin.ncol * o->TermWin.fwidth;    o->TermWin.height = o->TermWin.nrow * o->TermWin.fheight;    o->szHint.width = width;    o->szHint.height = height;/* size and placement */    if (scrollbar_visible ()) {	o->scrollBar.beg = 0;	o->scrollBar.end = height;#ifndef XTERM_SCROLLBAR	/* arrows are as high as wide - leave 1 pixel gap */# ifdef NEXT_SCROLLBAR	o->scrollBar.end -= SB_BUTTON_TOTAL_HEIGHT + SB_PADDING;# else	o->scrollBar.beg += (SB_WIDTH + 1) + o->sb_shadow;	o->scrollBar.end -= (SB_WIDTH + 1) + o->sb_shadow;

⌨️ 快捷键说明

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