📄 xfns.c
字号:
/* Functions for the X window system. Copyright (C) 1985, 1986, 1987 Free Software Foundation.This file is part of GNU Emacs.GNU Emacs is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 1, or (at your option)any later version.GNU Emacs is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Emacs; see the file COPYING. If not, write tothe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. *//* Written by Yakim Martillo; rearranged by Richard Stallman. *//* Color and other features added by Robert Krawitz*//*#include <stdio.h>*/#include <signal.h>#include "config.h"#include "lisp.h"#include "window.h"#include "xterm.h"#include "dispextern.h"#include "termchar.h"#include <fcntl.h>#include <setjmp.h>#ifdef HAVE_TIMEVAL#ifndef USG#include <sys/time.h>#else#include <time.h>#endif /* USG */#endif#ifdef HAVE_X_WINDOWS#define abs(x) ((x < 0) ? ((x)) : (x))#define sgn(x) ((x < 0) ? (-1) : (1))#define min(a,b) ((a) < (b) ? (a) : (b))#define max(a,b) ((a) > (b) ? (a) : (b)) #define CROSS_WIDTH 16#define CROSS_HEIGHT 16static short cross_bits[] = { 0x0000, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x7ffe, 0x7ffe, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0000, };static short gray_bits[] = { 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555};#define CROSS_MASK_WIDTH 16#define CROSS_MASK_HEIGHT 16static short cross_mask_bits[] = { 0x03c0, 0x03c0, 0x03c0, 0x03c0, 0x03c0, 0x03c0, 0xffff, 0xffff, 0xffff, 0xffff, 0x03c0, 0x03c0, 0x03c0, 0x03c0, 0x03c0, 0x03c0, };extern short sink_bits[];extern short sink_mask_bits[];#define sink_width 48#define sink_height 48#define sink_mask_width 48#define sink_mask_height 48extern XREPBUFFER Xxrepbuffer;/* Non-nil if Emacs is running with an X window for display. Nil if Emacs is run on an ordinary terminal. Initialized in dispnew.c. */Lisp_Object Vxterm;Lisp_Object Vx_mouse_pos, Vx_mouse_abs_pos;Lisp_Object Vx_mouse_item;extern struct Lisp_Vector *MouseMap;extern char *fore_color;extern char *back_color;extern char *brdr_color;extern char *mous_color;extern char *curs_color;extern int fore;extern int back;extern int brdr;extern int mous;extern int curs;extern int XXborder;extern int XXInternalBorder;extern int (*handler) ();extern FontInfo *fontinfo;extern int PendingExposure;extern char *default_window;extern Window XXwindow;extern Cursor EmacsCursor;extern short MouseCursor[], MouseMask[];extern char *XXcurrentfont;extern int informflag;extern int WindowMapped;extern char iconidentity[];extern int CurHL;extern int pixelwidth, pixelheight;extern int XXxoffset, XXyoffset;extern int XXpid;extern Display *XXdisplay;extern Window XXIconWindow;extern int IconWindow;extern Bitmap XXIconMask;extern int bitblt, CursorExists, VisibleX, VisibleY;extern WindowInfo rootwindowinfo;extern void x_init_1 ();/* Nonzero if x-set-window-edges has been called or x-rubber-band has been called. If it is zero when x-pop-up-window is called, x-rubber-band is called at that point. */int x_edges_specified;check_xterm (){ if (NULL (Vxterm)) error ("Terminal does not understand X protocol.");}DEFUN ("x-pop-up-window", Fx_pop_up_window, Sx_pop_up_window, 0, 0, 0, "Make the X window appear on the screen.") (){ check_xterm (); XPopUpWindow (); return Qnil;}DEFUN ("x-set-bell", Fx_set_bell, Sx_set_bell, 1, 1, "P", "For X window system, set audible vs visible bell.\n\With non-nil argument (prefix arg), use visible bell; otherwise, audible bell.") (arg) Lisp_Object arg;{ BLOCK_INPUT_DECLARE () check_xterm (); BLOCK_INPUT (); if (!NULL (arg)) XSetFlash (); else XSetFeep (); UNBLOCK_INPUT (); return arg;}DEFUN ("x-flip-color", Fx_flip_color, Sx_flip_color, 0, 0, "", "Toggle the background and foreground colors") (){ check_xterm (); XFlipColor (); return Qt;}DEFUN ("x-set-foreground-color", Fx_set_foreground_color, Sx_set_foreground_color, 1, 1, "sSet foregroud color: ", "Set foreground (text) color to COLOR.") (arg) Lisp_Object arg;{ Color cdef; BLOCK_INPUT_DECLARE () char *save_color; save_color = fore_color; check_xterm (); CHECK_STRING (arg,1); fore_color = (char *) xmalloc (XSTRING (arg)->size + 1); BLOCK_INPUT (); bcopy (XSTRING (arg)->data, fore_color, XSTRING (arg)->size + 1); if (fore_color && DisplayCells () > 2 && XParseColor (fore_color, &cdef) && XGetHardwareColor (&cdef)) { fore = cdef.pixel; } else if (fore_color && strcmp (fore_color, "black") == 0) { fore = BlackPixel; } else if (fore_color && strcmp (fore_color, "white") == 0) { fore = WhitePixel; } else { fore_color = save_color; } /* XPixFill (XXwindow, 0, 0, screen_width * fontinfo->width, screen_height * fontinfo->height, back, ClipModeClipped, GXcopy, AllPlanes);*/ Fredraw_display (); /* dumprectangle (0, 0, screen_height * fontinfo->height, screen_width * fontinfo -> width);*/ /* PendingExposure = 1; xfixscreen ();*/ UNBLOCK_INPUT (); XFlush (); return Qt;}DEFUN ("x-set-background-color", Fx_set_background_color, Sx_set_background_color, 1, 1, "sSet background color: ", "Set background color to COLOR.") (arg) Lisp_Object arg;{ Color cdef; Pixmap temp; BLOCK_INPUT_DECLARE () char *save_color; check_xterm (); CHECK_STRING (arg,1); save_color = back_color; back_color = (char *) xmalloc (XSTRING (arg)->size + 1); bcopy (XSTRING (arg)->data, back_color, XSTRING (arg)->size + 1); BLOCK_INPUT (); if (back_color && DisplayCells () > 2 && XParseColor (back_color, &cdef) && XGetHardwareColor (&cdef)) { back = cdef.pixel; } else if (back_color && strcmp (back_color, "white") == 0) { back = WhitePixel; } else if (back_color && strcmp (back_color, "black") == 0) { back = BlackPixel; } else { back_color = save_color; } temp = XMakeTile (back); XChangeBackground (XXwindow, temp); /* XPixFill (XXwindow, 0, 0, screen_width * fontinfo->width, screen_height * fontinfo->height, back, ClipModeClipped, GXcopy, AllPlanes);*/ UNBLOCK_INPUT (); Fredraw_display (); /* dumprectangle (0, 0, screen_height * fontinfo->height, screen_width * fontinfo -> width);*/ /* PendingExposure = 1; xfixscreen ();*/ XFlush (); XFreePixmap (temp); return Qt;}DEFUN ("x-set-border-color", Fx_set_border_color, Sx_set_border_color, 1, 1, "sSet border color: ", "Set border color to COLOR.") (arg) Lisp_Object arg;{ Color cdef; Pixmap temp; BLOCK_INPUT_DECLARE () check_xterm (); CHECK_STRING (arg,1); brdr_color= (char *) xmalloc (XSTRING (arg)->size + 1); bcopy (XSTRING (arg)->data, brdr_color, XSTRING (arg)->size + 1); BLOCK_INPUT (); if (brdr_color && DisplayCells () > 2 && XParseColor (brdr_color, &cdef) && XGetHardwareColor (&cdef)) { temp = XMakeTile (cdef.pixel); brdr = cdef.pixel; } else if (brdr_color && strcmp (brdr_color, "black") == 0) { temp = BlackPixmap; brdr = BlackPixel; } else if (brdr_color && strcmp (brdr_color, "white") == 0) { temp = WhitePixmap; brdr = WhitePixel; } else { temp = XMakePixmap ((Bitmap) XStoreBitmap (16, 16, gray_bits), BlackPixel, WhitePixel); brdr = BlackPixel; brdr_color = "gray"; } if (XXborder) XChangeBorder (XXwindow, temp); UNBLOCK_INPUT (); XFreePixmap (temp); return Qt;}DEFUN ("x-set-cursor-color", Fx_set_cursor_color, Sx_set_cursor_color, 1, 1, "sSet text cursor color: ", "Set text cursor color to COLOR.") (arg) Lisp_Object arg;{ Color cdef; BLOCK_INPUT_DECLARE () char *save_color; check_xterm (); CHECK_STRING (arg,1); save_color = curs_color; curs_color = (char *) xmalloc (XSTRING (arg)->size + 1); BLOCK_INPUT (); bcopy (XSTRING (arg)->data, curs_color, XSTRING (arg)->size + 1); if (curs_color && DisplayCells () > 2 && XParseColor (curs_color, &cdef) && XGetHardwareColor (&cdef)) { curs = cdef.pixel; } else if (curs_color && strcmp (curs_color, "black") == 0) { curs = BlackPixel; } else if (curs_color && strcmp (curs_color, "white") == 0) { curs = WhitePixel; } else { curs_color = save_color; } CursorToggle (); CursorToggle (); UNBLOCK_INPUT (); return Qt;}DEFUN ("x-set-mouse-color", Fx_set_mouse_color, Sx_set_mouse_color, 1, 1, "sSet mouse cursor color: ", "Set mouse cursor color to COLOR.") (arg) Lisp_Object arg;{ Cursor temp; BLOCK_INPUT_DECLARE () Color cdef; char *save_color; check_xterm (); CHECK_STRING (arg,1); save_color = mous_color; mous_color = (char *) xmalloc (XSTRING (arg)->size + 1); BLOCK_INPUT (); bcopy (XSTRING (arg)->data, mous_color, XSTRING (arg)->size + 1); if (mous_color && DisplayCells () > 2 && XParseColor (mous_color, &cdef) && XGetHardwareColor (&cdef)) { mous = cdef.pixel; } else if (mous_color && strcmp (mous_color, "black") == 0) { mous = BlackPixel; } else if (mous_color && strcmp (mous_color, "white") == 0) { mous = WhitePixel; } else { mous_color = save_color; } temp = XCreateCursor (16, 16, MouseCursor, MouseMask, 0, 0, mous, back, GXcopy); XDefineCursor (XXwindow, temp); XFreeCursor (EmacsCursor); UNBLOCK_INPUT (); bcopy (&temp, &EmacsCursor, sizeof (Cursor)); return Qt;} DEFUN ("x-color-p", Fx_color_p, Sx_color_p, 0, 0, 0, "Returns t if the display is a color X terminal.") (){ check_xterm (); if (DisplayCells () > 2) return Qt; else return Qnil;} DEFUN ("x-get-foreground-color", Fx_get_foreground_color, Sx_get_foreground_color, 0, 0, 0, "Returns the color of the foreground, as a string.") (){ Lisp_Object string; string = build_string (fore_color); return string;}DEFUN ("x-get-background-color", Fx_get_background_color, Sx_get_background_color, 0, 0, 0, "Returns the color of the background, as a string.") (){ Lisp_Object string; string = build_string (back_color); return string;}DEFUN ("x-get-border-color", Fx_get_border_color, Sx_get_border_color, 0, 0, 0, "Returns the color of the border, as a string.") (){ Lisp_Object string; string = build_string (brdr_color); return string;}DEFUN ("x-get-cursor-color", Fx_get_cursor_color, Sx_get_cursor_color, 0, 0, 0, "Returns the color of the cursor, as a string.") (){ Lisp_Object string; string = build_string (curs_color); return string;}DEFUN ("x-get-mouse-color", Fx_get_mouse_color, Sx_get_mouse_color, 0, 0, 0, "Returns the color of the mouse cursor, as a string.")
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -