xvig.c.16

来自「gsac程序包」· 16 代码 · 共 1,146 行 · 第 1/3 页

16
1,146
字号
/* File>>> xvig.c---- %M% -- version %I% (IMEC)            last updated: %E%---- Copyright (c) 1993-- IMEC vzw-- Kapeldreef 75-- B-3001 LEUVEN-- BELGIUM---- Author   : A. Demaree---- Date     : February 1, 1993---- Function : The client program for the `XviG' system that opens the--            graphics window, and processes the events.---- Usage    : xvig <version> <win_name> <win_id> <x> <y> <width> <height>---- Comment  : version   = a string to identify the version--            win_name  = the name of the window--            win_id    = the dummy window X-identifier from the parent process--            x         = the initial x-position of the window--            y         = the initial y-position of the window--            width     = the initial width of the window--            height    = the initial height of the window----            If the x-position value and/or the y-position value are negative,--            then the placement of the window is left to the window manager.---- Review   :--*//*-------------------------------------------------------------------------------- Global include files------------------------------------------------------------------------------*/#include <stdlib.h>#include <stdio.h>#include <string.h>#include <X11/Xlib.h>#include <X11/Xutil.h>#include <X11/Xatom.h>#include <X11/cursorfont.h>#define XK_MISCELLANY#include <X11/keysymdef.h>/*-------------------------------------------------------------------------------- Local include files------------------------------------------------------------------------------*/#include "commondata.h"#include "calxvig.xbm"#include "empty.xbm"/*-------------------------------------------------------------------------------- Some general macro definitions------------------------------------------------------------------------------*/#define ABS(n)    ((n) < 0 ? -(n) : (n))#define MAX(a,b)  ((a) > (b) ? (a) : (b))#define Min(a,b)  ((a) < (b) ? (a) : (b))/*-------------------------------------------------------------------------------- Static variable declarations------------------------------------------------------------------------------*/static Display *display;static int screen_nr;static Window dummy_window, window;static Cursor arrow_cursor, empty_cursor;static Pixmap pixmap, border_select, border_noselect, icon_pixmap;static GC gc;static XEvent event;static unsigned int window_width, window_height;static Atom wm_protocols_atom, wm_delete_window_atom;/*-- The Atoms for the ClientMessage events*/static Atom MESSAGE_INIT_atom,            MESSAGE_KEY_atom,            MESSAGE_BUTTON_atom,            MESSAGE_KEY_BUTTON_atom,            MESSAGE_SIZE_atom,            MESSAGE_SENSEKBD_ON_atom,            MESSAGE_SENSEKBD_OFF_atom,            MESSAGE_SENSEKBD_atom,            MESSAGE_CURSOR_atom,            MESSAGE_QUIT_atom;/* rbh extension */static Atom MESSAGE_CLIP_atom,            MESSAGE_REVERSE_atom,            MESSAGE_TOGRAY_atom,            MESSAGE_LCMAP_SIZE_atom,            MESSAGE_LCMAP_ENTRY_atom,            MESSAGE_LCMAP_RESET_atom,            MESSAGE_BOUNDS_atom;static int  title=0, border=0;static int Ldc_top, Ldc_right, Ldc_bottom, Ldc_left;static int dc_top, dc_right, dc_bottom, dc_left;static int dc_ClipRight, dc_ClipTop, dc_ClipBottom, dc_ClipLeft;static int curstype = 0;static int old_curstype = 0;static int cur_x = -1;	/* coordinates of last call to di_cross */static int cur_y = -1;static int user_curstype;/*-------------------------------------------------------------------------------- Local function declarations------------------------------------------------------------------------------*/static void Parse_Commandline(int argc,                              char *argv[],                              int *x,                              int *y,                              unsigned int *width,                              unsigned int *height);static void Set_WMproperties(char *window_name,                             int x,                             int y,                             unsigned int width,                             unsigned int height);static void Create_Cursors(void);static Pixmap New_Pixmap(unsigned int width,                         unsigned int height,                         unsigned int depth);static void Border_Pixmaps(unsigned int depth);static void Refresh_Screen(void);static void Window_Size(void);static void Cleanup(void);/* begin rbh extension */static void draw_cursor(int curstyp, int xc, int yc, 		int xl, int yl, int xh, int yh);static int inclipregion(int xpos, int ypos);static int cmap_size;static Colormap colormap;static XColor *color;#define YES 1#define NO 0static int DoGrabKeyboard = NO;static Bool keyboard_active = False;static Bool focus;/* end   rbh extension *//*------------------------------------------------------------------------------------------------------------------------------------------------------------------*/unsigned int cursor_width, cursor_height;int cursor_hot_x, cursor_hot_y;long cursor_type = DATA_CURSOR_ARROW;main(int argc, char *argv[]){  int init_x, init_y;  unsigned int init_width, init_height;  Window root_rtn;  int x_rtn, y_rtn;  unsigned int width_rtn, height_rtn, bwidth_rtn, depth_rtn;  KeySym keysym;  Bool sense_kbd_set = False,       sense_kbd_save = False,       sense_kbd = False;  char sense_char, tmpstr[8];  Bool cursor_on, cursor_drawn;  int prev_cursor_x, prev_cursor_y;  unsigned long xhair_color;  unsigned int xhair_width, xhair_height;  Bool do_event_loop = True;  /*  -- Parsing the command line options  */  Parse_Commandline(argc, argv, &init_x, &init_y, &init_width, &init_height);  /*  -- Open the display  */  if (!(display = XOpenDisplay(NULL)))  {    char *dname;    if (!(dname = getenv("DISPLAY")))      fprintf(stderr,       "ERROR (XviG) : Environment variable 'DISPLAY' has not been defined.\n");    else      fprintf(stderr,              "ERROR (XviG) : Cannot open display '%s'.\n", dname);    exit(1);  }  screen_nr = DefaultScreen(display);  /*  -- Take the default Graphic Context and set the GraphicsExposures off  */  gc = DefaultGC(display, screen_nr);  XSetGraphicsExposures(display, gc, False);  /*  -- Create the real window, and set the 'Window Manager' properties  */  if (!(window = XCreateSimpleWindow(display, RootWindow(display, screen_nr),                                     init_x < 0 ? 0 : init_x,                                     init_y < 0 ? 0 : init_y,                                     init_width, init_height, BORDER_WIDTH,                                     WhitePixel(display, screen_nr),                                     BlackPixel(display, screen_nr))))  {    fprintf(stderr, "ERROR (XviG) : Cannot create window.\n");    XCloseDisplay(display);    exit(1);  }  Set_WMproperties(argv[2], init_x, init_y, init_width, init_height);  /*  -- Map the window and wait for the event that it is  -- actually mapped (e.g. by the window manager),  -- taking care of the appropriate event mask  */  XSelectInput(display, window, ExposureMask | StructureNotifyMask);  XMapWindow(display, window);  while (1)  {    XNextEvent(display, &event);    if (event.type == MapNotify)      break;  }  XSelectInput(display, window, ExposureMask);  /*  -- Set the default cursor for the window to an arrow  -- and create an empty cursor  */  Create_Cursors();  /*  -- Create a pixmap with the same size as the window  -- and set the Xhair cursor size  */  if (XGetGeometry(display, window, &root_rtn, &x_rtn, &y_rtn,                   &width_rtn, &height_rtn, &bwidth_rtn, &depth_rtn))  {    pixmap = New_Pixmap(width_rtn, height_rtn, depth_rtn);    window_width  = xhair_width  = width_rtn;    window_height = xhair_height = height_rtn;  }  else  {    printf("WARNING (XviG) : Cannot get size of initial window.\n");    pixmap = New_Pixmap(1, 1, DefaultDepth(display, screen_nr));    window_width  = xhair_width  = 1;    window_height = xhair_height = 1;  }  /*  -- Create the border pixmaps and set the window border to 'no cursor input'  */  Border_Pixmaps(DefaultDepth(display, screen_nr));  XSetWindowBorderPixmap(display, window, border_noselect);  /*  -- Create the Atoms (unique numbers) for the ClientMessage events  */  MESSAGE_INIT_atom = XInternAtom(display, MESSAGE_INIT, False);  MESSAGE_KEY_atom = XInternAtom(display, MESSAGE_KEY, False);  MESSAGE_BUTTON_atom = XInternAtom(display, MESSAGE_BUTTON, False);  MESSAGE_KEY_BUTTON_atom = XInternAtom(display, MESSAGE_KEY_BUTTON, False);  MESSAGE_SIZE_atom = XInternAtom(display, MESSAGE_SIZE, False);  MESSAGE_SENSEKBD_ON_atom = XInternAtom(display, MESSAGE_SENSEKBD_ON, False);  MESSAGE_SENSEKBD_OFF_atom = XInternAtom(display, MESSAGE_SENSEKBD_OFF, False);  MESSAGE_SENSEKBD_atom = XInternAtom(display, MESSAGE_SENSEKBD, False);  MESSAGE_CURSOR_atom = XInternAtom(display, MESSAGE_CURSOR, False);  MESSAGE_QUIT_atom = XInternAtom(display, MESSAGE_QUIT, False);/* extension rbh */  MESSAGE_CLIP_atom = XInternAtom(display, MESSAGE_CLIP, False);  MESSAGE_REVERSE_atom = XInternAtom(display, MESSAGE_REVERSE, False);  MESSAGE_TOGRAY_atom = XInternAtom(display, MESSAGE_TOGRAY, False);  MESSAGE_LCMAP_SIZE_atom = XInternAtom(display, MESSAGE_LCMAP_SIZE, False);  MESSAGE_LCMAP_ENTRY_atom = XInternAtom(display, MESSAGE_LCMAP_ENTRY, False);  MESSAGE_LCMAP_RESET_atom = XInternAtom(display, MESSAGE_LCMAP_RESET, False);  MESSAGE_BOUNDS_atom = XInternAtom(display, MESSAGE_BOUNDS, False);  /*  -- Send a ClientMessage to the dummy window with  -- the real window ID, the pixmap ID and the window size  */  event.xclient.message_type = MESSAGE_INIT_atom;  event.xclient.window = window;  event.xclient.format = 32;  event.xclient.data.l[0] = (long) pixmap;  event.xclient.data.l[1] = (long) window_width;  event.xclient.data.l[2] = (long) window_height;  event.type = ClientMessage;  if (!XSendEvent(display, dummy_window, False, NoEventMask, &event))    fprintf(stderr, "ERROR (XviG) : Cannot send ClientMessage 'init'.\n");/* begin rbh extension */	Ldc_left = 0;	Ldc_bottom = 0;	Ldc_right = window_width -1 ;	Ldc_top  = window_height -1 ;	dc_left = Ldc_left;	dc_right = Ldc_right;	dc_top = Ldc_top;	dc_bottom = Ldc_bottom;	/* define initial cursor position */	prev_cursor_x = (dc_right + dc_left)/2;	prev_cursor_y = (dc_top + dc_bottom)/2;/* end   rbh extension */  /*  -- Event loop for a keypress or a buttonpress  */  while (do_event_loop)  {    XNextEvent(display, &event);    switch (event.type)    {      case KeyPress:          /* printf("INFO (XviG) : KeyPress event ...\n"); */          keysym = XLookupKeysym(&event.xkey, 0);          if (IsModifierKey(keysym) == True)            continue;          if (sense_kbd_set)          {            if (XLookupString(&event.xkey, tmpstr, 8,                              (KeySym *) NULL, (XComposeStatus *) NULL) == 1)              if (tmpstr[0] == sense_char)                sense_kbd = True;            break;          }      case ButtonPress:          /* printf("INFO (XviG) : ButtonPress event ...\n"); */          if (cursor_on)          {            if (cursor_drawn)            {              XSetFunction(display, gc, GXxor);                XSetForeground(display, gc, xhair_color);		draw_cursor( curstype,  prev_cursor_x,  prev_cursor_y, 			border+dc_ClipLeft, Ldc_top-border-dc_ClipTop, 			border+dc_ClipRight, Ldc_top-border-dc_ClipBottom);		              cursor_drawn = False;            }            cursor_on = False;          }          /* do bounds check */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?