📄 main.c
字号:
#endif rxvt_window_calc(r, width, height); XSetWMNormalHints(r->Xdisplay, r->TermWin.parent[0], &r->szHint); if (!ignoreparent) {#ifdef SMART_RESIZE /* * resize by Marius Gedminas <marius.gedminas@uosis.mif.vu.lt> * reposition window on resize depending on placement on screen */ int x, y, x1, y1; int dx, dy; unsigned int unused_w1, unused_h1, unused_b1, unused_d1; Window unused_cr; XTranslateCoordinates(r->Xdisplay, r->TermWin.parent[0], Xroot, 0, 0, &x, &y, &unused_cr); XGetGeometry(r->Xdisplay, r->TermWin.parent[0], &unused_cr, &x1, &y1, &unused_w1, &unused_h1, &unused_b1, &unused_d1); /* * if Xroot isn't the parent window, a WM will probably have offset * our position for handles and decorations. Counter it */ if (x1 != x || y1 != y) { x -= x1; y -= y1; } x1 = (DisplayWidth(r->Xdisplay, Xscreen) - old_width) / 2; y1 = (DisplayHeight(r->Xdisplay, Xscreen) - old_height) / 2; dx = old_width - r->szHint.width; dy = old_height - r->szHint.height; /* Check position of the center of the window */ if (x < x1) /* left half */ dx = 0; else if (x == x1) /* exact center */ dx /= 2; if (y < y1) /* top half */ dy = 0; else if (y == y1) /* exact center */ dy /= 2; XMoveResizeWindow(r->Xdisplay, r->TermWin.parent[0], x + dx, y + dy, r->szHint.width, r->szHint.height);#else XResizeWindow(r->Xdisplay, r->TermWin.parent[0], r->szHint.width, r->szHint.height);#endif } fix_screen = (r->TermWin.ncol != r->h->prev_ncol || r->TermWin.nrow != r->h->prev_nrow); if (fix_screen || width != r->h->old_width || height != r->h->old_height) { if (scrollbar_visible(r)) { XMoveResizeWindow(r->Xdisplay, r->scrollBar.win, r->h->window_sb_x, 0, scrollbar_TotalWidth(), r->szHint.height); rxvt_Resize_scrollBar(r); } if (menubar_visible(r)) XMoveResizeWindow(r->Xdisplay, r->menuBar.win, r->h->window_vt_x, 0, TermWin_TotalWidth(), menuBar_TotalHeight()); XMoveResizeWindow(r->Xdisplay, r->TermWin.vt, r->h->window_vt_x, r->h->window_vt_y, TermWin_TotalWidth(), TermWin_TotalHeight());#ifdef RXVT_GRAPHICS if (r->h->old_height) rxvt_Gr_Resize(r, r->h->old_width - r->szHint.base_width, r->h->old_height - r->szHint.base_height);#endif rxvt_scr_clear(r); rxvt_resize_pixmap(r); } if (fix_screen || r->h->old_height == 0) { int curr_screen = -1; u_int16_t old_ncol = r->h->prev_ncol; /* scr_reset only works on the primary screen */ if (r->h->old_height) /* this is not the first time through */ curr_screen = rxvt_scr_change_screen(r, PRIMARY); rxvt_scr_reset(r); if (curr_screen >= 0) { /* this is not the first time through */ rxvt_scr_change_screen(r, curr_screen); rxvt_selection_check(r, (old_ncol != r->TermWin.ncol ? 4 : 0)); } } r->h->old_width = r->szHint.width; r->h->old_height = r->szHint.height;#ifdef USE_XIM rxvt_IMSetStatusPosition(r);#endif}/* * Set the width/height of the vt window in characters. Units are pixels. * good for toggling 80/132 columns *//* EXTPROTO */voidrxvt_set_widthheight(rxvt_t *r, unsigned int width, unsigned int height){ XWindowAttributes wattr; if (width == 0 || height == 0) { XGetWindowAttributes(r->Xdisplay, Xroot, &wattr); if (width == 0) width = wattr.width - r->szHint.base_width; if (height == 0) height = wattr.height - r->szHint.base_height; } if (width != r->TermWin.width || height != r->TermWin.height) { width += r->szHint.base_width; height += r->szHint.base_height; rxvt_resize_all_windows(r, width, height, 0); }}/* -------------------------------------------------------------------- * * - X INPUT METHOD ROUTINES - * * -------------------------------------------------------------------- */#ifdef USE_XIM/* INTPROTO */voidrxvt_setSize(rxvt_t *r, XRectangle *size){ size->x = r->TermWin.int_bwidth; size->y = r->TermWin.int_bwidth; size->width = Width2Pixel(r->TermWin.ncol); size->height = Height2Pixel(r->TermWin.nrow);}/* INTPROTO */voidrxvt_setColor(rxvt_t *r, unsigned long *fg, unsigned long *bg){ *fg = r->PixColors[Color_fg]; *bg = r->PixColors[Color_bg];}/* Checking whether input method is running. *//* INTPROTO */Boolrxvt_IMisRunning(rxvt_t *r){ char *p; Atom atom; Window win; char server[IMBUFSIZ]; /* get current locale modifier */ if ((p = XSetLocaleModifiers(NULL)) != NULL) { STRCPY(server, "@server="); STRNCAT(server, &(p[4]), IMBUFSIZ - 9); /* skip "@im=" */ if ((p = STRCHR(server + 1, '@')) != NULL) /* first one only */ *p = '\0'; atom = XInternAtom(r->Xdisplay, server, False); win = XGetSelectionOwner(r->Xdisplay, atom); if (win != None) return True; } return False;}/* EXTPROTO */voidrxvt_IMSendSpot(rxvt_t *r){ XPoint spot; XVaNestedList preedit_attr; if (r->h->Input_Context == NULL || !r->TermWin.focus || !(r->h->input_style & XIMPreeditPosition) || !(r->h->event_type == KeyPress || r->h->event_type == Expose || r->h->event_type == NoExpose || r->h->event_type == SelectionNotify || r->h->event_type == ButtonRelease || r->h->event_type == FocusIn) || !rxvt_IMisRunning(r)) return; rxvt_setPosition(r, &spot); preedit_attr = XVaCreateNestedList(0, XNSpotLocation, &spot, NULL); XSetICValues(r->h->Input_Context, XNPreeditAttributes, preedit_attr, NULL); XFree(preedit_attr);}/* EXTPROTO */voidrxvt_setTermFontSet(rxvt_t *r, int idx){ char *string; long length; XFontSet prev_fontset; int success = 0; if (idx < 0 || idx >= MAX_NFONTS) return; D_MAIN((stderr, "rxvt_setTermFontSet()")); prev_fontset = r->TermWin.fontset; r->TermWin.fontset = NULL; length = 0; if (r->h->rs[Rs_font + idx]) length += STRLEN(r->h->rs[Rs_font + idx]) + 1;# ifdef MULTICHAR_SET if (r->h->rs[Rs_mfont + idx]) length += STRLEN(r->h->rs[Rs_mfont + idx]) + 1;# endif if (length == 0 || (string = rxvt_malloc(length + 1)) == NULL) r->TermWin.fontset = NULL; else { int missing_charsetcount; char **missing_charsetlist, *def_string; string[0] = '\0'; if (r->h->rs[Rs_font + idx]) { STRCAT(string, r->h->rs[Rs_font + idx]); STRCAT(string, ","); }# ifdef MULTICHAR_SET if (r->h->rs[Rs_mfont + idx]) { STRCAT(string, r->h->rs[Rs_mfont + idx]); STRCAT(string, ","); }# endif string[STRLEN(string) - 1] = '\0'; r->TermWin.fontset = XCreateFontSet(r->Xdisplay, string, &missing_charsetlist, &missing_charsetcount, &def_string); free(string); if (r->TermWin.fontset != NULL) success = 1; } if (success) { if (prev_fontset != NULL) XFreeFontSet(r->Xdisplay, prev_fontset); } else r->TermWin.fontset = prev_fontset;}/* INTPROTO */voidrxvt_setPreeditArea(rxvt_t *r, XRectangle *preedit_rect, XRectangle *status_rect, XRectangle *needed_rect){ int mbh, vtx = 0; if (scrollbar_visible(r) && !(r->Options & Opt_scrollBar_right)) vtx = scrollbar_TotalWidth(); mbh = menubar_visible(r) ? menuBar_TotalHeight() : 0; mbh -= r->TermWin.lineSpace; preedit_rect->x = needed_rect->width + vtx; preedit_rect->y = Height2Pixel(r->TermWin.nrow - 1) + mbh; preedit_rect->width = Width2Pixel(r->TermWin.ncol + 1) - needed_rect->width + vtx; preedit_rect->height = Height2Pixel(1); status_rect->x = vtx; status_rect->y = Height2Pixel(r->TermWin.nrow - 1) + mbh; status_rect->width = needed_rect->width ? needed_rect->width : Width2Pixel(r->TermWin.ncol + 1); status_rect->height = Height2Pixel(1);}/* ARGSUSED *//* INTPROTO */voidrxvt_IMDestroyCallback(XIM xim __attribute__((unused)), XPointer client_data __attribute__((unused)), XPointer call_data __attribute__((unused))){ rxvt_t *r = rxvt_get_r(); r->h->Input_Context = 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);}/* * X manual pages and include files don't match on some systems: * some think this is an XIDProc and others an XIMProc so we can't * use the first argument - need to update this to be nice for * both types via some sort of configure detection *//* ARGSUSED *//* EXTPROTO */voidrxvt_IMInstantiateCallback(Display *unused __attribute__((unused)), XPointer client_data __attribute__((unused)), XPointer call_data __attribute__((unused))){ int i, found, had_im; const char *p; char **s; rxvt_t *r = rxvt_get_r(); char buf[IMBUFSIZ]; D_MAIN((stderr, "rxvt_IMInstantiateCallback()")); if (r->h->Input_Context) return; found = had_im = 0; p = r->h->rs[Rs_inputMethod]; if (p && *p) { had_im = 1; s = rxvt_splitcommastring(p); for (i = 0; s[i]; i++) { if (*s[i]) { STRCPY(buf, "@im="); STRNCAT(buf, s[i], IMBUFSIZ - 5); if ((p = XSetLocaleModifiers(buf)) != NULL && *p && (rxvt_IM_get_IC(r) == True)) { found = 1; break; } } } for (i = 0; s[i]; i++) free(s[i]); free(s); } if (found) return;/* try with XMODIFIERS env. var. */ if ((p = XSetLocaleModifiers("")) != NULL && *p) { rxvt_IM_get_IC(r); return; }/* try with no modifiers base IF the user didn't specify an IM */ if (!had_im && (p = XSetLocaleModifiers("@im=none")) != NULL && *p && rxvt_IM_get_IC(r) == True) return;}/* * Try to open a XIM with the current modifiers, then see if we can * open a suitable preedit type *//* INTPROTO */Boolrxvt_IM_get_IC(rxvt_t *r){ int i, j, found; XIM xim; XPoint spot; XRectangle rect, status_rect, needed_rect; unsigned long fg, bg; const char *p; char **s; XIMStyles *xim_styles; XVaNestedList preedit_attr, status_attr; XIMCallback ximcallback; struct rxvt_hidden *h = r->h; D_MAIN((stderr, "rxvt_IM_get_IC()")); xim = XOpenIM(r->Xdisplay, NULL, NULL, NULL); if (xim == NULL) return False; xim_styles = NULL; if (XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL) || !xim_styles || !xim_styles->count_styles) { XCloseIM(xim); return False; } p = h->rs[Rs_preeditType] ? h->rs[Rs_preeditType] : "OverTheSpot,OffTheSpot,Root"; s = rxvt_splitcommastring(p); for (i = found = 0; !found && s[i]; i++) { if (!STRCMP(s[i], "OverTheSpot")) h->input_style = (XIMPreeditPosition | XIMStatusNothing); else if (!STRCMP(s[i], "OffTheSpot")) h->input_style = (XIMPreeditArea | XIMStatusArea); else if (!STRCMP(s[i], "Root")) h->input_style = (XIMPreeditNothing | XIMStatusNothing); for (j = 0; j < xim_styles->count_styles; j++) if (h->input_style == xim_styles->supported_styles[j]) { found = 1; break; } } for (i = 0; s[i]; i++) free(s[i]); free(s); XFree(xim_styles); if (!found) { XCloseIM(xim); return False; } ximcallback.callback = rxvt_IMDestroyCallback; /* XXX: not sure why we need this (as well as IC one below) */ XSetIMValues(xim, XNDestroyCallback, &ximcallback, NULL); preedit_attr = status_attr = NULL; if (h->input_style & XIMPreeditPosition) { rxvt_setSize(r, &rect); rxvt_setPosition(r, &spot); rxvt_setColor(r, &fg, &bg); preedit_attr = XVaCreateNestedList(0, XNArea, &rect, XNSpotLocation, &spot, XNForeground, fg, XNBackground, bg, XNFontSet, r->TermWin.fontset, NULL); } else if (h->input_style & XIMPreeditArea) { rxvt_setColor(r, &fg, &bg); /* * The necessary width of preedit area is unknown * until create input context. */ needed_rect.width = 0; rxvt_setPreeditArea(r, &rect, &status_rect, &needed_rect); preedit_attr = XVaCreateNestedList(0, XNArea, &rect, XNForeground, fg, XNBackground, bg, XNFontSet, r->TermWin.fontset, NULL); status_attr = XVaCreateNestedList(0, XNArea, &status_rect, XNForeground, fg, XNBackground, bg, XNFontSet, r->TermWin.fontset, NULL); } h->Input_Context = XCreateIC(xim, XNInputStyle, h->input_style, XNClientWindow, r->TermWin.parent[0], XNFocusWindow, r->TermWin.parent[0], XNDestroyCallback, &ximcallback, preedit_attr ? XNPreeditAttributes : NULL, preedit_attr, status_attr ? XNStatusAttributes : NULL, status_attr, NULL); if (preedit_attr) XFree(preedit_attr); if (status_attr) XFree(status_attr); if (h->Input_Context == NULL) { rxvt_print_error("failed to create input context"); XCloseIM(xim); return False; } if (h->input_style & XIMPreeditArea) rxvt_IMSetStatusPosition(r); D_MAIN((stderr, "rxvt_IM_get_IC() - successful connection")); return True;}/* EXTPROTO */voidrxvt_IMSetStatusPosition(rxvt_t *r){ XRectangle preedit_rect, status_rect, *needed_rect; XVaNestedList preedit_attr, status_attr; if (r->h->Input_Context == NULL || !r->TermWin.focus || !(r->h->input_style & XIMPreeditArea) || !rxvt_IMisRunning(r)) return; /* Getting the necessary width of preedit area */ status_attr = XVaCreateNestedList(0, XNAreaNeeded, &needed_rect, NULL); XGetICValues(r->h->Input_Context, XNStatusAttributes, status_attr, NULL); XFree(status_attr); rxvt_setPreeditArea(r, &preedit_rect, &status_rect, needed_rect); preedit_attr = XVaCreateNestedList(0, XNArea, &preedit_rect, NULL); status_attr = XVaCreateNestedList(0, XNArea, &status_rect, NULL); XSetICValues(r->h->Input_Context, XNPreeditAttributes, preedit_attr, XNStatusAttributes, status_attr, NULL); XFree(preedit_attr); XFree(status_attr);}#endif /* USE_XIM *//*----------------------------------------------------------------------*/static rxvt_t *_rxvt_vars = NULL;/* EXTPROTO */rxvt_t *rxvt_get_r(void){ return _rxvt_vars;}/* INTPROTO */voidrxvt_set_r(rxvt_t *r){ _rxvt_vars = r;}/*----------------------- end-of-file (C source) -----------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -