📄 init.c
字号:
if (!rs[Rs_title]) rs[Rs_title] = rxvt_r_basename(cmd_argv[0]); if (!rs[Rs_iconName]) rs[Rs_iconName] = rs[Rs_title]; } else { if (!rs[Rs_title]) rs[Rs_title] = rs[Rs_name]; if (!rs[Rs_iconName]) rs[Rs_iconName] = rs[Rs_name]; } if (rs[Rs_saveLines] && (i = atoi(rs[Rs_saveLines])) >= 0) r->TermWin.saveLines = BOUND_POSITIVE_INT16(i);#ifndef NO_FRILLS if (rs[Rs_int_bwidth] && (i = atoi(rs[Rs_int_bwidth])) >= 0) r->TermWin.int_bwidth = min(i, 100); /* arbitrary limit */ if (rs[Rs_ext_bwidth] && (i = atoi(rs[Rs_ext_bwidth])) >= 0) r->TermWin.ext_bwidth = min(i, 100); /* arbitrary limit */#endif#ifndef NO_LINESPACE if (rs[Rs_lineSpace] && (i = atoi(rs[Rs_lineSpace])) >= 0) r->TermWin.lineSpace = min(i, 100); /* arbitrary limit */#endif/* no point having a scrollbar without having any scrollback! */ if (!r->TermWin.saveLines) r->Options &= ~Opt_scrollBar;#ifdef PRINTPIPE if (!rs[Rs_print_pipe]) rs[Rs_print_pipe] = PRINTPIPE;#endif if (!rs[Rs_cutchars]) rs[Rs_cutchars] = CUTCHARS;#ifndef NO_BACKSPACE_KEY if (!rs[Rs_backspace_key])# ifdef DEFAULT_BACKSPACE r->h->key_backspace = DEFAULT_BACKSPACE;# else r->h->key_backspace = "DEC"; /* can toggle between \033 or \177 */# endif else { val = STRDUP(rs[Rs_backspace_key]); rxvt_Str_trim(val); rxvt_Str_escaped(val); r->h->key_backspace = val; }#endif#ifndef NO_DELETE_KEY if (!rs[Rs_delete_key])# ifdef DEFAULT_DELETE r->h->key_delete = DEFAULT_DELETE;# else r->h->key_delete = "\033[3~";# endif else { val = STRDUP(rs[Rs_delete_key]); rxvt_Str_trim(val); rxvt_Str_escaped(val); r->h->key_delete = val; }#endif if (rs[Rs_answerbackstring]) { rxvt_Str_trim((char *)rs[Rs_answerbackstring]); rxvt_Str_escaped((char *)rs[Rs_answerbackstring]); } if (rs[Rs_selectstyle]) { if (STRNCASECMP(rs[Rs_selectstyle], "oldword", 7) == 0) r->selection_style = OLD_WORD_SELECT;#ifndef NO_OLD_SELECTION else if (STRNCASECMP(rs[Rs_selectstyle], "old", 3) == 0) r->selection_style = OLD_SELECT;#endif }#ifdef HAVE_SCROLLBARS rxvt_setup_scrollbar(r, rs[Rs_scrollBar_align], rs[Rs_scrollstyle], rs[Rs_scrollBar_thickness]);#endif#if 0 /* #ifndef NO_BOLDFONT */ if (rs[Rs_font] == NULL && rs[Rs_boldFont] != NULL) { rs[Rs_font] = rs[Rs_boldFont]; rs[Rs_boldFont] = NULL; }#endif rxvt_set_defaultfont(r, rs);#ifdef XTERM_REVERSE_VIDEO/* this is how xterm implements reverseVideo */ if (r->Options & Opt_reverseVideo) { if (!rs[Rs_color + Color_fg]) rs[Rs_color + Color_fg] = def_colorName[Color_bg]; if (!rs[Rs_color + Color_bg]) rs[Rs_color + Color_bg] = def_colorName[Color_fg]; }#endif for (i = 0; i < NRS_COLORS; i++) if (!rs[Rs_color + i]) rs[Rs_color + i] = def_colorName[i];#ifndef XTERM_REVERSE_VIDEO/* this is how we implement reverseVideo */ if (r->Options & Opt_reverseVideo) SWAP_IT(rs[Rs_color + Color_fg], rs[Rs_color + Color_bg], const char *);#endif/* convenient aliases for setting fg/bg to colors */ rxvt_color_aliases(r, Color_fg); rxvt_color_aliases(r, Color_bg);#ifndef NO_CURSORCOLOR rxvt_color_aliases(r, Color_cursor); rxvt_color_aliases(r, Color_cursor2);#endif /* NO_CURSORCOLOR */ rxvt_color_aliases(r, Color_pointer); rxvt_color_aliases(r, Color_border);#ifndef NO_BOLD_UNDERLINE_REVERSE rxvt_color_aliases(r, Color_BD); rxvt_color_aliases(r, Color_UL); rxvt_color_aliases(r, Color_RV);#endif /* ! NO_BOLD_UNDERLINE_REVERSE */ return cmd_argv;}/*----------------------------------------------------------------------*//* EXTPROTO */voidrxvt_init_env(rxvt_t *r){ int i; unsigned int u; char *val;#ifdef DISPLAY_IS_IP/* Fixup display_name for export over pty to any interested terminal * clients via "ESC[7n" (e.g. shells). Note we use the pure IP number * (for the first non-loopback interface) that we get from * rxvt_network_display(). This is more "name-resolution-portable", if you * will, and probably allows for faster x-client startup if your name * server is beyond a slow link or overloaded at client startup. Of * course that only helps the shell's child processes, not us. * * Giving out the display_name also affords a potential security hole */ val = rxvt_network_display(r->h->rs[Rs_display_name]); r->h->rs[Rs_display_name] = (const char *)val; if (val == NULL)#endif /* DISPLAY_IS_IP */ val = XDisplayString(r->Xdisplay); if (r->h->rs[Rs_display_name] == NULL) r->h->rs[Rs_display_name] = val; /* use broken `:0' value */ i = STRLEN(val); r->h->env_display = rxvt_malloc((i + 9) * sizeof(char)); sprintf(r->h->env_display, "DISPLAY=%s", val); /* avoiding the math library: * i = (int)(ceil(log10((unsigned int)r->TermWin.parent[0]))) */ for (i = 0, u = (unsigned int)r->TermWin.parent[0]; u; u /= 10, i++) ; MAX_IT(i, 1); r->h->env_windowid = rxvt_malloc((i + 10) * sizeof(char)); sprintf(r->h->env_windowid, "WINDOWID=%u", (unsigned int)r->TermWin.parent[0]);/* add entries to the environment: * @ DISPLAY: in case we started with -display * @ WINDOWID: X window id number of the window * @ COLORTERM: terminal sub-name and also indicates its color * @ TERM: terminal name * @ TERMINFO: path to terminfo directory */ putenv(r->h->env_display); putenv(r->h->env_windowid);#ifdef RXVT_TERMINFO putenv("TERMINFO=" RXVT_TERMINFO);#endif if (XDEPTH <= 2) putenv("COLORTERM=" COLORTERMENV "-mono"); else putenv("COLORTERM=" COLORTERMENVFULL); if (r->h->rs[Rs_term_name] != NULL) { r->h->env_term = rxvt_malloc((STRLEN(r->h->rs[Rs_term_name]) + 6) * sizeof(char)); sprintf(r->h->env_term, "TERM=%s", r->h->rs[Rs_term_name]); putenv(r->h->env_term); } else putenv("TERM=" TERMENV);#ifdef HAVE_UNSETENV/* avoid passing old settings and confusing term size */ unsetenv("LINES"); unsetenv("COLUMNS"); unsetenv("TERMCAP"); /* terminfo should be okay */#endif /* HAVE_UNSETENV */}/*----------------------------------------------------------------------*//* * 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 (r->h->locale == NULL) rxvt_print_error("Setting locale failed."); else { Atom wmlocale; wmlocale = XInternAtom(r->Xdisplay, "WM_LOCALE_NAME", False); XChangeProperty(r->Xdisplay, r->TermWin.parent[0], wmlocale, XA_STRING, 8, PropModeReplace, (unsigned char *)r->h->locale, STRLEN(r->h->locale)); if (XSupportsLocale() != True) { rxvt_print_error("The locale is not supported by Xlib"); return; } rxvt_setTermFontSet(r, 0); /* see if we can connect yet */ rxvt_IMInstantiateCallback(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_IMInstantiateCallback, NULL); }#endif}/*----------------------------------------------------------------------*//* EXTPROTO */voidrxvt_init_command(rxvt_t *r, const char *const *argv){/* * Initialize the command connection. * This should be called after the X server connection is established. */ int i; for (i = 0; i < NUM_XA; i++) r->h->xa[i] = XInternAtom(r->Xdisplay, xa_names[i], False);/* Enable delete window protocol */ XSetWMProtocols(r->Xdisplay, r->TermWin.parent[0], &(r->h->xa[XA_WMDELETEWINDOW]), 1);#ifdef USING_W11LIB/* enable W11 callbacks */ W11AddEventHandler(r->Xdisplay, rxvt_W11_process_x_event);#endif/* get number of available file descriptors */#if defined(_POSIX_VERSION) || ! defined(__svr4__) r->num_fds = (int)sysconf(_SC_OPEN_MAX);#else r->num_fds = rxvt_getdtablesize();#endif#ifdef META8_OPTION r->h->meta_char = (r->Options & Opt_meta8 ? 0x80 : C0_ESC);#endif rxvt_get_ourmods(r); if (!(r->Options & Opt_scrollTtyOutput)) r->h->PrivateModes |= PrivMode_TtyOutputInh; if (r->Options & Opt_scrollTtyKeypress) r->h->PrivateModes |= PrivMode_Keypress; if (!(r->Options & Opt_jumpScroll)) r->h->PrivateModes |= PrivMode_smoothScroll;#ifndef NO_BACKSPACE_KEY if (STRCMP(r->h->key_backspace, "DEC") == 0) r->h->PrivateModes |= PrivMode_HaveBackSpace;#endif/* add value for scrollBar */ if (scrollbar_visible(r)) { r->h->PrivateModes |= PrivMode_scrollBar; r->h->SavedModes |= PrivMode_scrollBar; } if (menubar_visible(r)) { r->h->PrivateModes |= PrivMode_menuBar; r->h->SavedModes |= PrivMode_menuBar; } greek_init(); r->Xfd = XConnectionNumber(r->Xdisplay); if ((r->cmd_fd = rxvt_run_command(r, argv)) < 0) { rxvt_print_error("aborting"); exit(EXIT_FAILURE); }}/*----------------------------------------------------------------------*//* INTPROTO */voidrxvt_Get_Colours(rxvt_t *r){ int i; for (i = 0; i < (XDEPTH <= 2 ? 2 : NRS_COLORS); i++) { XColor xcol; if (!r->h->rs[Rs_color + i]) continue; if (!rxvt_rXParseAllocColor(r, &xcol, r->h->rs[Rs_color + i])) {#ifndef XTERM_REVERSE_VIDEO if (i < 2 && (r->Options & Opt_reverseVideo)) { r->h->rs[Rs_color + i] = def_colorName[!i]; } else#endif r->h->rs[Rs_color + i] = def_colorName[i]; if (!r->h->rs[Rs_color + i]) continue; if (!rxvt_rXParseAllocColor(r, &xcol, r->h->rs[Rs_color + i])) { switch (i) { case Color_fg: case Color_bg: /* fatal: need bg/fg color */ rxvt_print_error("aborting"); exit(EXIT_FAILURE); /* NOTREACHED */ break;#ifndef NO_CURSORCOLOR case Color_cursor2: xcol.pixel = r->PixColors[Color_fg]; break;#endif /* ! NO_CURSORCOLOR */ case Color_pointer: xcol.pixel = r->PixColors[Color_fg]; break; default: xcol.pixel = r->PixColors[Color_bg]; /* None */ break; } } } r->PixColors[i] = xcol.pixel; SET_PIXCOLOR(r->h, i); } if (XDEPTH <= 2 || !r->h->rs[Rs_color + Color_pointer]) r->PixColors[Color_pointer] = r->PixColors[Color_fg]; if (XDEPTH <= 2 || !r->h->rs[Rs_color + Color_border]) r->PixColors[Color_border] = r->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 (XDEPTH <= 2) { /* Monochrome */ r->PixColors[Color_scroll] = r->PixColors[Color_fg]; r->PixColors[Color_topShadow] = r->PixColors[Color_bg]; r->PixColors[Color_bottomShadow] = r->PixColors[Color_bg]; } else { XColor xcol[3]; /* xcol[0] == white * xcol[1] == top shadow * xcol[2] == bot shadow */ xcol[1].pixel = r->PixColors[Color_scroll];# ifdef PREFER_24BIT xcol[0].red = xcol[0].green = xcol[0].blue = (unsigned short)~0; rxvt_rXAllocColor(r, &(xcol[0]), "White");/* XFreeColors(r->Xdisplay, XCMAP, &(xcol[0].pixel), 1, ~0); */ XQueryColors(r->Xdisplay, XCMAP, &(xcol[1]), 1);# else xcol[0].pixel = WhitePixel(r->Xdisplay, Xscreen); XQueryColors(r->Xdisplay, XCMAP, xcol, 2);# endif /* bottomShadowColor */ xcol[2].red = xcol[1].red / 2; xcol[2].green = xcol[1].green / 2; xcol[2].blue = xcol[1].blue / 2; if (!rxvt_rXAllocColor(r, &(xcol[2]), "Color_bottomShadow")) xcol[2].pixel = r->PixColors[Color_Black]; r->PixColors[Color_bottomShadow] = xcol[2].pixel; /* topShadowColor */ xcol[1].red = max((xcol[0].red / 5), xcol[1].red); xcol[1].green = max((xcol[0].green / 5), xcol[1].green); xcol[1].blue = max((xcol[0].blue / 5), xcol[1].blue); xcol[1].red = min(xcol[0].red, (xcol[1].red * 7) / 5); xcol[1].green = min(xcol[0].green, (xcol[1].green * 7) / 5); xcol[1].blue = min(xcol[0].blue, (xcol[1].blue * 7) / 5); if (!rxvt_rXAllocColor(r, &(xcol[1]), "Color_topShadow")) xcol[1].pixel = r->PixColors[Color_White]; r->PixColors[Color_topShadow] = xcol[1].pixel; }#endif /* KEEP_SCROLLCOLOR */}/*----------------------------------------------------------------------*//* color aliases, fg/bg bright-bold *//* INTPROTO */voidrxvt_color_aliases(rxvt_t *r, int idx){ if (r->h->rs[Rs_color + idx] && isdigit(*(r->h->rs[Rs_color + idx]))) { int i = atoi(r->h->rs[Rs_color + idx]); if (i >= 8 && i <= 15) { /* bright colors */ i -= 8;#ifndef NO_BRIGHTCOLOR r->h->rs[Rs_color + idx] = r->h->rs[Rs_color + minBrightCOLOR + i]; return;#endif } if (i >= 0 && i <= 7) /* normal colors */ r->h->rs[Rs_color + idx] = r->h->rs[Rs_color + minCOLOR + i]; }}/*----------------------------------------------------------------------*//* * Probe the modifier keymap to get the Meta (Alt) and Num_Lock settings * Use resource ``modifier'' to override the Meta modifier *//* INTPROTO */voidrxvt_get_ourmods(rxvt_t *r){ int i, j, k; int requestedmeta, realmeta, realalt; const char *cm, *rsmod; XModifierKeymap *map; KeyCode *kc; const unsigned int modmasks[] = { Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask }; requestedmeta = realmeta = realalt = 0; rsmod = r->h->rs[Rs_modifier]; if (rsmod && STRCASECMP(rsmod, "mod1") >= 0 && STRCASECMP(rsmod, "mod5") <= 0) requestedmeta = rsmod[3] - '0'; map = XGetModifierMapping(r->Xdisplay); kc = map->modifiermap; for (i = 1; i < 6; i++) { k = (i + 2) * map->max_keypermod; /* skip shift/lock/control */ for (j = map->max_keypermod; j--; k++) { if (kc[k] == 0) break; switch (XKeycodeToKeysym(r->Xdisplay, kc[k], 0)) { case XK_Num_Lock: r->h->ModNumLockMask = modmasks[i - 1]; /* FALLTHROUGH */ default: continue; /* for(;;) */ case XK_Meta_L: case XK_Meta_R: cm = "meta"; realmeta = i; break; case XK_Alt_L: case XK_Alt_R: cm = "alt"; realalt = i; break; case XK_Super_L: case XK_Super_R: cm = "super"; break; case XK_Hyper_L: case XK_Hyper_R: cm = "hyper"; break; } if (rsmod && STRNCASECMP(rsmod, cm, STRLEN(cm)) == 0) requestedmeta = i; } } XFreeModifiermap(map); i = (requestedmeta ? requestedmeta : (realmeta ? realmeta : (realalt ? realalt : 0))); if (i) r->h->ModMetaMask = modmasks[i - 1];}/*----------------------------------------------------------------------*//* rxvt_Create_Windows() - Open and map the window *//* EXTPROTO */voidrxvt_Create_Windows(rxvt_t *r, int argc, const char *const *argv){ XClassHint classHint; XWMHints wmHint; XGCValues gcvalue;#ifdef PREFER_24BIT XSetWindowAttributes attributes; XWindowAttributes gattr; XCMAP = DefaultColormap(r->Xdisplay, Xscreen); XVISUAL = DefaultVisual(r->Xdisplay, Xscreen); if (r->Options & Opt_transparent) { XGetWindowAttributes(r->Xdisplay, RootWindow(r->Xdisplay, Xscreen), &gattr); XDEPTH = gattr.depth; } else { XDEPTH = DefaultDepth(r->Xdisplay, Xscreen);/* * If depth is not 24, look for a 24bit visual. */ if (XDEPTH != 24) { XVisualInfo vinfo; if (XMatchVisualInfo(r->Xdisplay, Xscreen, 24, TrueColor, &vinfo)) { XDEPTH = 24; XVISUAL = vinfo.visual; XCMAP = XCreateColormap(r->Xdisplay, RootWindow(r->Xdisplay, Xscreen), XVISUAL, AllocNone); } } }#endif/* grab colors before netscape does */ rxvt_Get_Colours(r); rxvt_change_font(r, 1, NULL); rxvt_window_calc(r, 0, 0); r->h->old_width = r->szHint.width; r->h->old_height = r->szHint.height;/* parent window - reverse video so we can see placement errors * sub-window placement & size in rxvt_resize_subwindows() */#ifdef PREFER_24BIT attributes.background_pixel = r->PixColors[Color_fg]; attributes.border_pixel = r->PixColors[Color_border]; attributes.colormap = XCMAP; r->TermWin.parent[0] = XCreateWindow(r->Xdisplay, Xroot, r->szHint.x, r->szHint.y, r->szHint.width, r->szHint.height, r->TermWin.ext_bwidth, XDEPTH, InputOutput, XVISUAL, CWBackPixel | CWBorderPixel | CWColormap, &attributes);#else r->TermWin.parent[0] = XCreateSimpleWindow(r->Xdisplay, Xroot, r->szHint.x, r->szHint.y, r->szHint.width, r->szHint.height,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -