📄 init.c
字号:
/* * 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 */ { rxvt_copy_color( r, Color_scroll, Color_fg ); rxvt_copy_color( r, Color_topShadow, Color_bg ); rxvt_copy_color( r, Color_bottomShadow, Color_bg ); } else { XColor xcol[3]; /* * xcol[0] == white * xcol[1] == top shadow * xcol[2] == bot shadow */ xcol[1].pixel = r->pixColorsFocus[Color_scroll];# ifdef PREFER_24BIT xcol[0].red = xcol[0].green = xcol[0].blue = 0xffffu; rxvt_alloc_color( r, &(xcol[0]), "White" ); 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_alloc_color( r, &(xcol[2]), "Color_bottomShadow" ) ) rxvt_copy_color( r, Color_bottomShadow, Color_Black ); else rxvt_set_color( r, Color_bottomShadow, &xcol[2] ); /* 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_alloc_color(r, &(xcol[1]), "Color_topShadow") ) rxvt_copy_color( r, Color_topShadow, Color_White ); else rxvt_set_color( r, Color_topShadow, &xcol[1] ); }#endif /* KEEP_SCROLLCOLOR */#ifdef TEXT_SHADOW if (r->h->rs[Rs_textShadow]) { XColor xcol; if( rxvt_parse_alloc_color( r, &xcol, r->h->rs[Rs_textShadow] ) ) { r->TermWin.shadow = xcol.pixel;# ifdef XFT_SUPPORT rxvt_alloc_xft_color( r, &xcol, &(r->TermWin.xftshadow));# endif } else { r->TermWin.shadow = r->pixColorsFocus[Color_Black];# ifdef XFT_SUPPORT r->TermWin.xftshadow = r->xftColorsFocus[Color_Black];# endif } }#endif}/*----------------------------------------------------------------------*//* color aliases, fg/bg bright-bold *//* INTPROTO */voidrxvt_color_aliases( rxvt_t *r, int idx ){ if (r->h->rs[Rs_color + idx] && isdigit((int) *(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]; }}/* INTPROTO */voidrxvt_init_win_size( rxvt_t *r ){ int flags = 0; /* must initialize to 0!!! */ short recalc_x = 0, recalc_y = 0, recalc_width = 1, recalc_height = 1; int x, y; unsigned int w, h; r->szHint.flags = PMinSize | PResizeInc | PBaseSize | PWinGravity; r->szHint.win_gravity = NorthWestGravity; /* Set default terminal columns and rows */ r->TermWin.ncol = 80; r->TermWin.nrow = 24; r->szHint.x = 0; r->szHint.y = 0;#ifdef TRANSPARENT refreshRootBGVars( r );#endif /* Get geometry in x, y, w, h */ if (r->h->rs[Rs_geometry]) flags = XParseGeometry(r->h->rs[Rs_geometry], &x, &y, &w, &h); /* Calculate the terminal increment width and height */#ifndef NO_FRILLS if( ISSET_OPTION(r, Opt2_smoothResize)) { r->szHint.width_inc = 1; r->szHint.height_inc = 1; } else#endif { r->szHint.width_inc = r->TermWin.fwidth; r->szHint.height_inc = r->TermWin.fheight; } /* Calculate the base width and height */ r->szHint.base_width = 2 * r->TermWin.int_bwidth; r->szHint.base_height = 2 * r->TermWin.int_bwidth;#ifdef HAVE_SCROLLBARS if (ISSET_OPTION(r, Opt_scrollBar)) r->szHint.base_width += rxvt_scrollbar_rwidth (r);#endif#ifdef HAVE_MENUBAR if (ISSET_OPTION(r, Opt_showMenu)) r->szHint.base_height += rxvt_menubar_rheight (r);#endif if (NOTSET_OPTION(r, Opt2_hideTabbar)) r->szHint.base_height += rxvt_tabbar_rheight (r); /* Set the terminal minimal width and height */ r->szHint.min_width = r->szHint.base_width + r->TermWin.fwidth; r->szHint.min_height = r->szHint.base_height + r->TermWin.fheight; /* Parse Geometry */ if (flags & WidthValue) { r->TermWin.ncol = BOUND_POSITIVE_INT16(w);#ifndef NO_FRILLS if( ISSET_OPTION(r, Opt2_smoothResize) ) { /* For smoothResize, w as a pixel width (if large enough) */ if(r->TermWin.ncol > r->szHint.base_width + r->TermWin.fwidth) { r->szHint.width = r->TermWin.ncol; r->TermWin.ncol = (r->TermWin.ncol - r->szHint.base_width) / r->TermWin.fwidth; recalc_width = 0; } else r->TermWin.ncol = 1; }#endif r->szHint.flags |= USSize; } if (flags & HeightValue) { r->TermWin.nrow = BOUND_POSITIVE_INT16(h);#ifndef NO_FRILLS if(ISSET_OPTION(r, Opt2_smoothResize)) { /* For smoothResize, w as a pixel height (if large enough) */ if(r->TermWin.nrow > r->szHint.base_height + r->TermWin.fheight) { r->szHint.height = r->TermWin.nrow; r->TermWin.nrow = (r->TermWin.nrow - r->szHint.base_height) / r->TermWin.fheight; recalc_height = 0; } else r->TermWin.nrow = 1; }#endif r->szHint.flags |= USSize; } if (flags & XValue) { r->szHint.x = x; r->szHint.flags |= USPosition; if (flags & XNegative) { recalc_x = 1; r->szHint.win_gravity = NorthEastGravity; } } if (flags & YValue) { r->szHint.y = y; r->szHint.flags |= USPosition; if (flags & YNegative) { recalc_y = 1; if (r->szHint.win_gravity == NorthEastGravity) r->szHint.win_gravity = SouthEastGravity; else r->szHint.win_gravity = SouthWestGravity; } } /* Set the terminal width and height */ if( recalc_width) r->szHint.width = r->szHint.base_width + Width2Pixel (r->TermWin.ncol); if( recalc_height) r->szHint.height = r->szHint.base_height + Height2Pixel (r->TermWin.nrow); /* Recalculate the starting position */ if (recalc_x) r->szHint.x += (DisplayWidth(r->Xdisplay, XSCREEN) - r->szHint.width - 2 * r->TermWin.ext_bwidth); if (recalc_y) r->szHint.y += (DisplayHeight(r->Xdisplay, XSCREEN) - r->szHint.height - 2 * r->TermWin.ext_bwidth); /* Set the terminal window starting position */ r->h->window_vt_x = (ISSET_OPTION(r, Opt_scrollBar_right)) ? 0 : r->szHint.base_width - 2*r->TermWin.int_bwidth; r->h->window_vt_y = r->szHint.base_height - 2*r->TermWin.int_bwidth; if (ISSET_OPTION(r, Opt2_bottomTabbar) && NOTSET_OPTION(r, Opt2_hideTabbar)) r->h->window_vt_y -= rxvt_tabbar_rheight (r);}/*----------------------------------------------------------------------*//* * 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; const char* 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];}/* EXTPROTO */char**rxvt_string_to_argv( const char *string, int *argc ){ int i = 0; char** pret; const char* pcur;#ifdef INTERNAL_ARGV_SPLIT const char* pbeg;#endif *argc = 0; if( IS_NULL(string) || *string == '\0' ) { *argc = 0; return NULL; }#define MAX_ARGV (1024) /* Up to 64 argv. * * 2006-02-23 gi1242: Use calloc instead of malloc. Thus when freeing pret, * we can safely free all elements till we encounter a NULL pointer. */ pret = (char**) rxvt_calloc (MAX_ARGV, sizeof (char*)); rxvt_dbgmsg ((DBG_DEBUG, DBG_INIT, "fetch command argv for the tab\n"));#ifdef INTERNAL_ARGV_SPLIT /*{{{*/ /* * 2006-02-23 gi1242: Remember to leave space for a NULL terminated pointer * at the end */ pbeg = pcur = string; for (i = 0; i < MAX_ARGV-2; i ++) { int dq = 0; /* double quote */ int sq = 0; /* single quote */ /* set default argument to NULL */ SET_NULL(pret[i]); /* skip any spaces and non-printable */ while (*pcur && (isspace ((int) *pcur) || !isprint ((int) *pcur))) pcur ++; /* stop if reach end of string */ if (!*pcur) break; /* beginning of the token */ if (isalnum ((int) *pcur) || ispunct ((int) *pcur)) { if ('\"' == *pcur) { /* beginning of double quote */ dq = 1; pbeg = pcur + 1; pcur ++; } else if ('\'' == *pcur) { /* beginning of single quote */ sq = 1; pbeg = pcur + 1; pcur ++; } else /* normal characters */ pbeg = pcur; }#ifdef DEBUG else /* shouldn't happen */ assert (0);#endif /* move forward one character */ pcur ++; /* now fetch the new token */ while( *pcur && /* not end of string */ ( (dq && *pcur != '\"') || /* not end of double quote */ (sq && *pcur != '\'') || /* not end of single quote */ (!dq && !sq && !isspace ((int) *pcur)) ) ) { pcur ++; } if (!*pcur && /* end of string */ (dq || sq)) /* no match of quote is found */ goto NotMatch; if (!*pcur) /* end of string */ { pret[i] = STRDUP (pbeg); rxvt_dbgmsg ((DBG_DEBUG, DBG_INIT, " argv[%d] = %s\n", i, pret[i])); break; /* ready to return */ } if ( (dq && *pcur == '\"') /* end of double quote */ || (sq && *pcur == '\'') /* end of single quote */ || (!dq && !sq && isspace ((int) *pcur)) /* space */ ) { int len = sizeof (char) * (pcur - pbeg) + 1; assert (len > 0); /* possible integer overflow? */ pret[i] = (char*) rxvt_malloc (len * sizeof(char)); MEMCPY (pret[i], pbeg, len-1); pret[i][len-1] = (char) 0; rxvt_dbgmsg ((DBG_DEBUG, DBG_INIT, " argv[%d] = %s\n", i, pret[i])); /* forward to next character */ pcur ++; /* fetch next token */ continue; } /* shouldn't get here */ assert (0); } /*}}}*/#else /* !INTERNAL_ARGV_SPLIT */ /* * Pass strings beginning with "!" but not "!!" to /bin/sh -c */ if( *string == '!' && *(++string) != '!' ) { /* Pass command to the shell for word splitting */ pret[i++] = STRDUP( "/bin/sh" ); pret[i++] = STRDUP( "-c" ); pret[i++] = STRDUP( string ); } else { /* * Split command into words at spaces. White spaces can be quoted with * a backslash. However we don't processes chains of "\\" which don't * end in a space or tab. That is "\\a" expands to "\\a" however "\\ " * expands to "\ ", and "\ " expands to a " " which does not split * words. */ pcur = string; for( ; i < MAX_ARGV && *pcur; i++ ) { const int max_argv_len = 1024; char argval[max_argv_len]; int j = 0; /* Skip leading spaces */ while( *pcur == ' ' || *pcur == '\t' ) pcur++; while( *pcur && *pcur != ' ' && *pcur != '\t' && j < max_argv_len - 1 ) { if( *pcur == '\\' ) { const char *s = pcur + 1; /* Count backslashes */ while( *s == '\\' ) s++; if( *s == ' ' || *s == '\t' ) { int nbslashs = s - pcur; int nbytes = min( nbslashs / 2, max_argv_len - j - 1); /* Halve # backslashes */ MEMSET( &argval[j], '\\', nbytes ); pcur = s; j += nbytes; if( nbslashs % 2 == 0 ) break; /* Split word here */ } else { /* Copy backslashes over verbatim */ int nbytes = min( s - pcur, max_argv_len -j -1 ); MEMCPY( &argval[j], pcur, nbytes ); j += nbytes; pcur = s
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -