/* sqXWindow.c -- support for the X Window System. * * Author: Ian Piumarta * * Last edited: Wed Oct 20 17:18:21 1999 by piumarta (Ian Piumarta) on pingu * * Code to support displays deeper than 8 bits contributed by: Kazuki YASUMATSU * * * Support for cursor and keypad editing keys based on code contributed by: * Stefan Matthias Aust * * Support for intelligent visual class selection contributed by: * Bill Cattey * * Support European accented characters in selections contributed by: * Bert Freudenberg * * Support for OSProcess plugin contributed by: * Dave Lewis Mon Oct 18 20:36:54 EDT 1999 * * BUGS: this file is too long; it should be split into two. * icon stuff should be removed (window manager's responsibility). * RCS stuff has been removed. */ #include "sq.h" #ifdef HAVE_LIBXEXT # define USE_XSHM #endif #ifdef UNIX static char os_generic_name[] = "unix"; /* Any unix-like OS */ #endif #include #include #include #include #include #include #include #include #include #ifdef HAVE_SYS_SELECT_H # include #endif #ifndef HEADLESS # include # include # include # define XK_MISCELLANY # define XK_XKB_KEYS # include # ifdef USE_XSHM # include # include # include # endif # ifndef NO_ICON # include "squeakIcon.bitmap" # endif #endif /*** Variables -- Imported from Virtual Machine ***/ extern unsigned char *memory; extern int interruptKeycode; extern int interruptPending; extern int interruptCheckCounter; extern int savedWindowSize; /*** Variables -- image and path names ***/ #define IMAGE_NAME_SIZE MAXPATHLEN char imageName[MAXPATHLEN+1]; /* full path to image */ char shortImageName[MAXPATHLEN+1]; /* just the base name */ char vmPath[MAXPATHLEN+1]; /* full path to interpreter's directory */ #define DefaultHeapSize 20 /* megabytes */ int initialHeapSize; int initialArgc; char **initialArgv; /*** Variables -- globals for access from pluggable primitives ***/ int argCnt; char **argVec; char **envVec; /* Pointers to arguments for VM. Used by getAttributeIntoLength(). */ int vmArgCnt= 0; char **vmArgVec; /* Pointers to arguments for Squeak. Used by getAttributeIntoLength(). */ int squeakArgCnt= 0; char **squeakArgVec; #undef USE_ITIMER /* severely confuses GNU's profil() */ #ifdef USE_ITIMER unsigned int lowResMSecs= 0; #define LOW_RES_TICK_MSECS 20 /* 1/50 second resolution */ #endif #ifndef HEADLESS /*** Variables -- X11 Related ***/ /* name of Squeak windows in Xrm and the WM */ #define xClassName "Squeak" char *displayName= 0; /* name of display, or 0 for $DISPLAY */ Display *stDisplay= null; /* Squeak display */ int isConnectedToXServer= 0; /* True when connected to an X server */ int stXfd= 0; /* X connection file descriptor */ Window stWindow= null; /* Squeak window */ Visual *stVisual; /* the default visual */ GC stGC; /* graphics context used for rendering */ Colormap stColormap= null; /* Squeak color map */ int stDisplayBitsIndex= 0; /* last known oop of the VM's Display */ XImage *stImage= 0; /* ...and it's client-side pixmap */ char *stPrimarySelection; /* buffer holding selection */ char *stEmptySelection= ""; /* immutable "empty string" value */ int stPrimarySelectionSize;/* size of buffer holding selection */ int stOwnsSelection= 0; /* true if we own the X selection */ XColor stColorBlack; /* black pixel value in stColormap */ XColor stColorWhite; /* white pixel value in stColormap */ int savedWindowOrigin= -1; /* initial origin of window */ XPoint mousePosition; /* position at last PointerMotion event */ Time stButtonTime; /* time of last ButtonRelease (for SetSeln) */ # ifdef USE_XSHM XShmSegmentInfo stShmInfo; /* shared memory descriptor */ int completions= 0; /* outstanding completion events */ int completionType; /* the type of XShmCompletionEvent */ int useXshm= 0; /* 1 if shared memory is in use */ int asyncUpdate= 0; /* 1 for asynchronous screen updates */ # endif int stDepth= 0; int stBitsPerPixel= 0; unsigned int stColors[256]; unsigned int stDownGradingColors[256]; int stHasSameRGBMask16; int stHasSameRGBMask32; int stRNMask, stGNMask, stBNMask; int stRShift, stGShift, stBShift; char *stDisplayBitmap= 0; #endif #define SqueakWhite 0 #define SqueakBlack 1 int asmAlign= 1; int sleepWhenUnmapped= 0; int noJitter= 0; int withSpy= 0; int noTitle= 0; int fullScreen= 0; struct timeval startUpTime; /* maximum input polling frequency */ #define MAXPOLLSPERSEC 33 #ifndef HEADLESS /* we are interested in these events */ #define EVENTMASK ButtonPressMask | ButtonReleaseMask | \ KeyPressMask | PointerMotionMask | \ ExposureMask | StructureNotifyMask /* largest X selection that we will attempt to handle (bytes) */ #define MAX_SELECTION_SIZE 100*1024 /* longest we're prepared to wait for the selection owner to convert it (seconds) */ #define SELECTION_TIMEOUT 3 /*** Variables -- Event Recording ***/ #define KEYBUF_SIZE 64 int keyBuf[KEYBUF_SIZE]; /* circular buffer */ int keyBufGet= 0; /* index of next item of keyBuf to read */ int keyBufPut= 0; /* index of next item of keyBuf to write */ int keyBufOverflows= 0; /* number of characters dropped */ int buttonState= 0; /* mouse button and modifier state when mouse button went down or 0 if not pressed */ /* This table maps the X modifier key bits to 4 Squeak modifier bits. (The X caps lock key is mapped as shift, meta is mapped to command, and ctrl+meta is mapped to option. X bits: Squeak bits: