📄 x11term.c
字号:
} if (mous_color && XParseColor (XXdisplay, XXColorMap, mous_color, &cdef) && XAllocColor (XXdisplay, XXColorMap, &cdef)) ; else mous_color = "black"; if (brdr_color && XParseColor (XXdisplay, XXColorMap, brdr_color, &cdef) && XAllocColor (XXdisplay, XXColorMap, &cdef)) brdr = cdef.pixel; else { brdr_color = "black"; brdr = BlackPixel (XXdisplay, XXscreen); } } else { fore_color = curs_color = mous_color = brdr_color = "black"; fore = curs = brdr = BlackPixel (XXdisplay, XXscreen); back_color = "white"; back = WhitePixel (XXdisplay, XXscreen); } if (reversevideo) { int tempcolor; char *tempname; brdr = back; brdr_color = back_color; tempcolor = fore; fore = back; back = tempcolor; tempname = fore_color; fore_color = back_color; back_color = tempname; if (curs == WhitePixel (XXdisplay, XXscreen)) { curs = BlackPixel (XXdisplay, XXscreen); curs_color = "black"; } else if (curs == BlackPixel (XXdisplay, XXscreen)) { curs = WhitePixel (XXdisplay, XXscreen); curs_color = "white"; } if (!strcmp (mous_color, "white")) mous_color = "black"; else if (!strcmp (mous_color, "black")) mous_color = "white"; } if (!XXcurrentfont) { XXcurrentfont = (char *) xmalloc (strlen (temp_font) + 1); if (!XXcurrentfont) { fprintf (stderr, "Memory allocation failure.\n"); exit (-150); } strcpy (XXcurrentfont, temp_font); } signal (SIGPIPE, XExitGracefully);#ifndef CANNOT_DUMP if (initialized)#endif /* CANNOT_DUMP */ Vxterm = Qt; Fset (intern ("window-system-version"), make_number (11)); XInitWindow (); keyboard_init_hook = x_init_1;}/* Initialize for keyboard input using X. This is called by init_keyboard via keyboard_init_hook. */static voidx_init_1 (){#ifdef F_SETOWN extern int old_fcntl_owner;#endif dup2 (ConnectionNumber(XXdisplay), 0); close (ConnectionNumber(XXdisplay)); ConnectionNumber(XXdisplay) = 0; /* Looks a little strange? * check the def of the macro; * it is a genuine lvalue */ setpgrp (0,getpid()); #ifdef F_SETOWN old_fcntl_owner = fcntl (0, F_GETOWN, 0);#ifdef F_SETOWN_SOCK_NEG fcntl (0, F_SETOWN, -getpid ()); /* stdin is a socket here */#else fcntl (0, F_SETOWN, getpid ());#endif /* F_SETOWN_SOCK_NEG */#endif /* F_SETOWN */ /* Enable interrupt_input because otherwise we cannot asynchronously detect C-g sent as a keystroke event from the X server. */ Fset_input_mode (Qt, Qnil, Qnil);}XSetFlash (){ ring_bell_hook = XTflash;}XSetFeep (){ ring_bell_hook = XTfeep;}/* ------------------------------------------------------------ * Load a font by name. Return the font pointer, or NULL if * it can't be loaded. Do all appropriate calculations. */static XFontStruct *XT_CalcForFont(fontname) char *fontname;{ XFontStruct *fontp; if ( (fontp = XLoadQueryFont(XXdisplay, fontname)) == (XFontStruct *) 0 ) { return (XFontStruct *) NULL; } XXfid = fontp->fid; XXfonth = fontp->ascent + fontp->descent; XXfontw = fontp->max_bounds.width; XXbase = fontp->ascent; return fontp;}/* ------------------------------------------------------------ */XNewFont (newname) register char *newname;{ XFontStruct *temp; BLOCK_INPUT_DECLARE (); BLOCK_INPUT (); XFlush (XXdisplay); temp = XT_CalcForFont(newname); if (temp == (XFontStruct *) NULL) { UNBLOCK_INPUT (); return -1; } XSetFont (XXdisplay, XXgc_norm, XXfid); XSetFont (XXdisplay, XXgc_rev, XXfid); XSetFont (XXdisplay, XXgc_curs, XXfid); XFreeFont (XXdisplay, fontinfo); fontinfo = temp; XSetWindowSize(screen_height, screen_width); UNBLOCK_INPUT (); return 0;}/* Flip foreground/background colors */XFlipColor (){ int tempcolor; char *tempname; XColor forec, backc; BLOCK_INPUT_DECLARE (); BLOCK_INPUT (); CursorToggle (); XSetWindowBackground(XXdisplay, XXwindow, fore); if (XXborder) XSetWindowBorder(XXdisplay, XXwindow, back); brdr = back; brdr_color = back_color; tempcolor = fore; fore = back; back = tempcolor; tempname = fore_color ; fore_color = back_color; back_color = tempname; XClearArea (XXdisplay, XXwindow, 0, 0, screen_width*XXfontw+2*XXInternalBorder, screen_height*XXfonth+2*XXInternalBorder, 0); XXgc_temp = XXgc_norm; XXgc_norm = XXgc_rev; XXgc_rev = XXgc_temp; if (!strcmp (mous_color, "white")) mous_color = "black"; else if (!strcmp (mous_color, "black")) mous_color = "white"; x_set_cursor_colors (); XRedrawDisplay (); if (curs == WhitePixel (XXdisplay, XXscreen)) { curs = BlackPixel (XXdisplay, XXscreen); curs_color = "black"; } else if (curs == BlackPixel (XXdisplay, XXscreen)) { curs = WhitePixel (XXdisplay, XXscreen); curs_color = "white"; } XSetState (XXdisplay, XXgc_curs, back, curs, GXinvert, AllPlanes); CursorToggle (); XFlush (XXdisplay); UNBLOCK_INPUT ();}/* ------------------------------------------------------------ */#define NO_MANAGER 1/* ------------------------------------------------------------ */static XClassHint class_hint;static intXT_Set_Class_Hints(w) Window w;{ extern char *getenv(); if (XXidentity == (char *) NULL) XXidentity = ""; /* XSCH() doesn't like NULL pointers! */ class_hint.res_name = XXidentity; class_hint.res_class = CLASS; XSetClassHint(XXdisplay, w, &class_hint);}/* ------------------------------------------------------------ */static intXT_Set_Command_Line(w) Window w;{ XSetCommand(XXdisplay, w, xargv, xargc);}/* ------------------------------------------------------------ */static char hostname[100];static intXT_Set_Host(w) Window w;{ gethostname(hostname, 100); hostname[99] = '\0'; XChangeProperty(XXdisplay, w, XA_WM_CLIENT_MACHINE, XA_STRING, 8, PropModeReplace, hostname, strlen(hostname));}/* ------------------------------------------------------------ * Set header title to window-name (from '-wn'), or if none, * "optional-id: class-of-appl @ host" */static intXT_Set_Title(w) Window w;{ char header_info[200]; if (XXheader != (char *) NULL) { strcpy(header_info, XXheader); } else { char *next; next = header_info; if (strlen(class_hint.res_name) != 0) { sprintf(header_info, "%s: ", class_hint.res_name); next += strlen(header_info); } sprintf(next, "%s @ %s", class_hint.res_class, hostname); } XStoreName(XXdisplay, w, header_info);}/* ------------------------------------------------------------ * Set icon title to icon-name (from '-in'), * or if none, to "invocation-or-class @ host". * */static intXT_Set_Icon_Title(w) Window w;{ char title_info[100]; if (XXicon_name != (char *) NULL) { strcpy(title_info, XXicon_name); } else { if (strlen(class_hint.res_name) != 0) { sprintf(title_info, "%s@", class_hint.res_name); } else { sprintf(title_info, "%s@", class_hint.res_class); } strcat(title_info, hostname); } XChangeProperty(XXdisplay, w, XA_WM_ICON_NAME, XA_STRING, 8, PropModeReplace, title_info, strlen(title_info));}/* Arg PR carries value returned by XGeometry at startup, or 0. */static intXT_Set_Size_Hints(w, x, y, width, height, do_resize, pr) int x, y; /* only used at Startup: do_resize == FALSE */ int width, height; Window w; Bool do_resize; int pr;{#ifndef XICCC XSizeHints sizehints; sizehints.flags = (pr & (WidthValue | HeightValue)) ? USSize : PSize; if (!do_resize) sizehints.flags |= (pr & (XValue | YValue)) ? USPosition : PPosition; sizehints.flags |= PResizeInc|PMinSize; sizehints.x = x; sizehints.y = y; sizehints.width = width*XXfontw + 2 * XXInternalBorder; sizehints.height = height*XXfonth + 2 * XXInternalBorder; pixelwidth = sizehints.width; pixelheight = sizehints.height; flexlines = height; change_screen_size (height, width, 0 - (do_resize == False)); sizehints.width_inc = XXfontw; sizehints.height_inc = XXfonth; sizehints.min_width = XXfontw*MINWIDTH+2*XXInternalBorder; sizehints.min_height = XXfonth*MINHEIGHT+2*XXInternalBorder; /* old, broken versions */ sizehints.min_width = 2 * XXInternalBorder; sizehints.min_height = 2 * XXInternalBorder; XSetNormalHints(XXdisplay, w, &sizehints); if (do_resize) { XResizeWindow(XXdisplay, XXwindow, pixelwidth, pixelheight); XFlush(XXdisplay); }#else XSizeHints sizehints; XWindowChanges changes; unsigned int change_mask = 0; sizehints.flags = 0; if (! do_resize) { changes.x = x; changes.y = y; sizehints.flags |= (pr & (XValue | YValue)) ? USPosition : PPosition; change_mask |= CWX | CWY; } sizehints.base_width = 2 * XXInternalBorder; sizehints.base_height = 2 * XXInternalBorder; changes.width = sizehints.base_width + width * XXfontw; changes.height = sizehints.base_height + height * XXfonth; sizehints.flags |= ((pr & (WidthValue | HeightValue)) ? USSize : PSize) | PBaseSize; change_mask |= CWWidth | CWHeight; /* * NOTE: The sizehints.x, sizehints.y, sizehints.width and * sizehints.height fields are OBSOLETE according to the ICCC, and * no window manager should be considering them, even if USSize/PSize * and/or USPosition/PPosition are set. Unfortunately, many * window managers consider them anyway, and programs like xprop * display their values when fetching the normal hints property * from the window. Therefore, I set them here just to make * things a little bit more robust. */ if (! do_resize) { sizehints.x = x; sizehints.y = y; } sizehints.width = changes.width; sizehints.height = changes.height; pixelwidth = sizehints.base_width; pixelheight = sizehints.base_height; flexlines = height; change_screen_size (height, width, 0 - (do_resize == False)); sizehints.min_width = XXfontw * MINWIDTH + 2 * XXInternalBorder; sizehints.min_height = XXfonth * MINHEIGHT + 2 * XXInternalBorder; sizehints.flags |= PMinSize; sizehints.width_inc = XXfontw; sizehints.height_inc = XXfonth; sizehints.flags |= PResizeInc; XSetWMNormalHints(XXdisplay, w, &sizehints); XConfigureWindow(XXdisplay, w, change_mask, &changes);#endif /* XICCC */}/* ------------------------------------------------------------ *//*ARGSUSED*/static intXT_Set_Zoom_Sizes(w) Window w;{}/* ------------------------------------------------------------ * Set our state and icon parameters. */static intXT_Set_WM_Hints(w) Window w;{ XWMHints wmhints; wmhints.flags = InputHint | StateHint; if (XXicon_usebitmap) wmhints.flags |= IconPixmapHint | IconMaskHint; wmhints.input = True; wmhints.initial_state = NormalState; SinkPixmap = XCreateBitmapFromData (XXdisplay, w, sink_bits, sink_width, sink_height); SinkMaskPixmap = XCreateBitmapFromData (XXdisplay, w, sink_mask_bits, sink_mask_width, sink_mask_height); if (XXicon_usebitmap) { wmhints.icon_pixmap = SinkPixmap; wmhints.icon_mask = SinkMaskPixmap; } else { wmhints.icon_pixmap = 0; wmhints.icon_mask = 0; } XSetWMHints(XXdisplay, w, &wmhints);}/* ------------------------------------------------------------ * Change just the size of the window. */XSetWindowSize(rows, cols) int rows, cols;{ XT_Set_Size_Hints(XXwindow, 0, 0, cols, rows, NO_MANAGER, 0);}/* ------------------------------------------------------------ */static intXInitWindow (){ extern int xargc; extern char **xargv; int x, y, width, height, pr; char *dp; Window desktop; XColor forec, backc; if ( (fontinfo = XT_CalcForFont(XXcurrentfont)) == (XFontStruct *) NULL) fatal ("X server unable to find requested font `%s'.\n", (XXcurrentfont == NULL) ? "(null)" : XXcurrentfont); pr = XGeometry (XXdisplay, 0, desiredwindow, default_window, XXborder, XXfontw, XXfonth, XXInternalBorder*2, XXInternalBorder*2, &x, &y, &width, &height); /* Which desktop do we start up on? */ if ( (dp = getenv("WM_DESKTOP")) != (char *) NULL ) { desktop = atoi(dp); } else { desktop = RootWindow(XXdisplay, DefaultScreen(XXdisplay)); } XXwindow = XCreateSimpleWindow(XXdisplay, desktop, x, y, width*XXfontw + 2*XXInternalBorder, height*XXfonth + 2*XXInternalBorder, XXborder, brdr, back); if (!XXwindow) { fprintf (stderr, "Could not create X window!\n"); fflush (stderr); exit (-97); } XXgcv.font = XXfid; XXgcv.foreground = fore; XXgcv.background = back; XXgc_norm = XCreateGC(XXdisplay, XXwindow, GCFont|GCForeground|GCBackground, &XXgcv); XXgcv.foreground = back; XXgcv.background = fore; XXgc_rev = XCreateGC(XXdisplay, XXwindow, GCFont|GCForeground|GCBackground, &XXgcv); XXgcv.foreground = back; XXgcv.background = curs; XXgc_curs = XCreateGC(XXdisplay, XXwindow, GCFont|GCForeground|GCBackground, &XXgcv); EmacsCursor = XCreateFontCursor(XXdisplay, XC_left_ptr); x_set_cursor_colors (); XDefineCursor (XXdisplay, XXwindow, EmacsCursor); CursorExists = 0; CursorOutline = 1; VisibleX = 0; VisibleY = 0; XT_Set_Class_Hints(XXwindow); XT_Set_Command_Line(XXwindow); XT_Set_Host(XXwindow); XT_Set_Title(XXwindow); XT_Set_Icon_Title(XXwindow); XT_Set_Size_Hints(XXwindow, x, y, width, height, False, pr); XT_Set_Zoom_Sizes(XXwindow); XT_Set_WM_Hints(XXwindow); XSelectInput(XXdisplay, XXwindow, KeyPressMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | FocusChangeMask | StructureNotifyMask); XMapWindow (XXdisplay, XXwindow); XFlush (XXdisplay);#ifdef AIX #include "xkeys-aix.h"#endif /* AIX */}#endif /* HAVE_X_WINDOWS *//*#include "xundebug.h"*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -