Annotation of GNUtools/emacs/src/xfns.c, revision 1.1.1.1

1.1       root        1: /* Functions for the X window system.
                      2:    Copyright (C) 1985, 1986, 1987 Free Software Foundation.
                      3: 
                      4: This file is part of GNU Emacs.
                      5: 
                      6: GNU Emacs is free software; you can redistribute it and/or modify
                      7: it under the terms of the GNU General Public License as published by
                      8: the Free Software Foundation; either version 1, or (at your option)
                      9: any later version.
                     10: 
                     11: GNU Emacs is distributed in the hope that it will be useful,
                     12: but WITHOUT ANY WARRANTY; without even the implied warranty of
                     13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     14: GNU General Public License for more details.
                     15: 
                     16: You should have received a copy of the GNU General Public License
                     17: along with GNU Emacs; see the file COPYING.  If not, write to
                     18: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
                     19: 
                     20: /* Written by Yakim Martillo; rearranged by Richard Stallman.  */
                     21: /* Color and other features added by Robert Krawitz*/
                     22: 
                     23: /*#include <stdio.h>*/
                     24: #include <signal.h>
                     25: #include "config.h"
                     26: #include "lisp.h"
                     27: #include "window.h"
                     28: #include "xterm.h"
                     29: #include "dispextern.h"
                     30: #include "termchar.h"
                     31: #include <fcntl.h>
                     32: #include <setjmp.h>
                     33: 
                     34: #ifdef HAVE_TIMEVAL
                     35: #ifndef USG
                     36: #include <sys/time.h>
                     37: #else
                     38: #include <time.h>
                     39: #endif /* USG */
                     40: #endif
                     41: 
                     42: #ifdef HAVE_X_WINDOWS
                     43: 
                     44: #define abs(x) ((x < 0) ? ((x)) : (x))
                     45: #define sgn(x) ((x < 0) ? (-1) : (1))
                     46: #define min(a,b) ((a) < (b) ? (a) : (b))
                     47: #define max(a,b) ((a) > (b) ? (a) : (b))
                     48:   
                     49: #define CROSS_WIDTH 16
                     50: #define CROSS_HEIGHT 16
                     51: 
                     52: static short cross_bits[] =
                     53:   {
                     54:     0x0000, 0x0180, 0x0180, 0x0180,
                     55:     0x0180, 0x0180, 0x0180, 0x7ffe,
                     56:     0x7ffe, 0x0180, 0x0180, 0x0180,
                     57:     0x0180, 0x0180, 0x0180, 0x0000,
                     58:   };
                     59: 
                     60: static short gray_bits[] = {
                     61:     0xaaaa, 0x5555, 0xaaaa, 0x5555,
                     62:     0xaaaa, 0x5555, 0xaaaa, 0x5555,
                     63:     0xaaaa, 0x5555, 0xaaaa, 0x5555,
                     64:     0xaaaa, 0x5555, 0xaaaa, 0x5555};
                     65: 
                     66: #define CROSS_MASK_WIDTH 16
                     67: #define CROSS_MASK_HEIGHT 16
                     68: static short cross_mask_bits[] =
                     69:   {
                     70:     0x03c0, 0x03c0, 0x03c0, 0x03c0,
                     71:     0x03c0, 0x03c0, 0xffff, 0xffff,
                     72:     0xffff, 0xffff, 0x03c0, 0x03c0,
                     73:     0x03c0, 0x03c0, 0x03c0, 0x03c0,
                     74:   };
                     75: 
                     76: extern short sink_bits[];
                     77: extern short sink_mask_bits[];
                     78: #define sink_width 48
                     79: #define sink_height 48
                     80: #define sink_mask_width 48
                     81: #define sink_mask_height 48
                     82: 
                     83: extern XREPBUFFER Xxrepbuffer;
                     84: 
                     85: /* Non-nil if Emacs is running with an X window for display.
                     86:    Nil if Emacs is run on an ordinary terminal.
                     87:    Initialized in dispnew.c.  */
                     88: 
                     89: Lisp_Object Vxterm;
                     90: 
                     91: Lisp_Object Vx_mouse_pos, Vx_mouse_abs_pos;
                     92: 
                     93: Lisp_Object Vx_mouse_item;
                     94: 
                     95: extern struct Lisp_Vector *MouseMap;
                     96: 
                     97: extern char *fore_color;
                     98: extern char *back_color;
                     99: extern char *brdr_color;
                    100: extern char *mous_color;
                    101: extern char *curs_color;
                    102: 
                    103: extern int fore;
                    104: extern int back;
                    105: extern int brdr;
                    106: extern int mous;
                    107: extern int curs;
                    108: 
                    109: extern int XXborder;
                    110: extern int XXInternalBorder;
                    111: 
                    112: extern int (*handler) ();
                    113: 
                    114: extern FontInfo *fontinfo;
                    115: 
                    116: extern int PendingExposure;
                    117: extern char *default_window;
                    118: 
                    119: extern Window XXwindow;
                    120: extern Cursor EmacsCursor;
                    121: extern short MouseCursor[], MouseMask[];
                    122: extern char *XXcurrentfont;
                    123: extern int informflag;
                    124: 
                    125: extern int WindowMapped;
                    126: extern char iconidentity[];
                    127: extern int CurHL;
                    128: extern int pixelwidth, pixelheight;
                    129: extern int XXxoffset, XXyoffset;
                    130: extern int XXpid;
                    131: 
                    132: extern Display *XXdisplay;
                    133: extern Window XXIconWindow;
                    134: extern int IconWindow;
                    135: extern Bitmap XXIconMask;
                    136: extern int bitblt, CursorExists, VisibleX, VisibleY;
                    137: extern WindowInfo rootwindowinfo;
                    138: 
                    139: extern void x_init_1 ();
                    140: 
                    141: /* Nonzero if x-set-window-edges has been called
                    142:    or x-rubber-band has been called.
                    143:    If it is zero when x-pop-up-window is called,
                    144:    x-rubber-band is called at that point.  */
                    145: 
                    146: int x_edges_specified;
                    147: 
                    148: check_xterm ()
                    149: {
                    150:   if (NULL (Vxterm))
                    151:     error ("Terminal does not understand X protocol.");
                    152: }
                    153: 
                    154: DEFUN ("x-pop-up-window", Fx_pop_up_window, Sx_pop_up_window, 0, 0, 0,
                    155:   "Make the X window appear on the screen.")
                    156:   ()
                    157: {
                    158:   check_xterm ();
                    159:   XPopUpWindow ();
                    160:   return Qnil;
                    161: }
                    162: 
                    163: DEFUN ("x-set-bell", Fx_set_bell, Sx_set_bell, 1, 1, "P",
                    164:   "For X window system, set audible vs visible bell.\n\
                    165: With non-nil argument (prefix arg), use visible bell; otherwise, audible bell.")
                    166:   (arg)
                    167:      Lisp_Object arg;
                    168: {
                    169:   BLOCK_INPUT_DECLARE ()
                    170: 
                    171:   check_xterm ();
                    172:   BLOCK_INPUT ();
                    173:   if (!NULL (arg))
                    174:     XSetFlash ();
                    175:   else
                    176:     XSetFeep ();
                    177:   UNBLOCK_INPUT ();
                    178:   return arg;
                    179: }
                    180: 
                    181: DEFUN ("x-flip-color", Fx_flip_color, Sx_flip_color, 0, 0, "",
                    182:   "Toggle the background and foreground colors")
                    183:   ()
                    184: {
                    185:   check_xterm ();
                    186:   XFlipColor ();
                    187:   return Qt;
                    188: }
                    189: 
                    190: DEFUN ("x-set-foreground-color", Fx_set_foreground_color,
                    191:        Sx_set_foreground_color, 1, 1, "sSet foregroud color:  ",
                    192:        "Set foreground (text) color to COLOR.")
                    193:   (arg)
                    194:      Lisp_Object arg;
                    195: {
                    196:   Color cdef;
                    197:   BLOCK_INPUT_DECLARE ()
                    198:   char *save_color;
                    199: 
                    200:   save_color = fore_color;
                    201:   check_xterm ();
                    202:   CHECK_STRING (arg,1);
                    203:   fore_color = (char *) xmalloc (XSTRING (arg)->size + 1);
                    204:   BLOCK_INPUT ();
                    205:   bcopy (XSTRING (arg)->data, fore_color, XSTRING (arg)->size + 1);
                    206:   if (fore_color && DisplayCells () > 2 &&
                    207:       XParseColor (fore_color, &cdef) && XGetHardwareColor (&cdef))
                    208:     {
                    209:       fore = cdef.pixel;
                    210:     }
                    211:   else if (fore_color && strcmp (fore_color, "black") == 0)
                    212:     {
                    213:       fore = BlackPixel;
                    214:     }
                    215:   else if (fore_color && strcmp (fore_color, "white") == 0)
                    216:     {
                    217:       fore = WhitePixel;
                    218:     }
                    219:   else
                    220:     {
                    221:       fore_color = save_color;
                    222:     }
                    223:   /*    XPixFill (XXwindow, 0, 0, screen_width * fontinfo->width,
                    224:        screen_height * fontinfo->height, back, ClipModeClipped,
                    225:        GXcopy, AllPlanes);*/
                    226:   Fredraw_display ();
                    227:   /*    dumprectangle (0, 0, screen_height * fontinfo->height,
                    228:        screen_width * fontinfo -> width);*/
                    229:   /*    PendingExposure = 1;
                    230:        xfixscreen ();*/
                    231:   UNBLOCK_INPUT ();
                    232:   XFlush ();
                    233:   return Qt;
                    234: }
                    235: 
                    236: DEFUN ("x-set-background-color", Fx_set_background_color,
                    237:        Sx_set_background_color, 1, 1, "sSet background color: ",
                    238:        "Set background color to COLOR.")
                    239:   (arg)
                    240:      Lisp_Object arg;
                    241: {
                    242:   Color cdef;
                    243:   Pixmap temp;
                    244:   BLOCK_INPUT_DECLARE ()
                    245:   char *save_color;
                    246: 
                    247:   check_xterm ();
                    248:   CHECK_STRING (arg,1);
                    249:   save_color = back_color;
                    250:   back_color = (char *) xmalloc (XSTRING (arg)->size + 1);
                    251:   bcopy (XSTRING (arg)->data, back_color, XSTRING (arg)->size + 1);
                    252:   BLOCK_INPUT ();
                    253:   if (back_color && DisplayCells () > 2 &&
                    254:       XParseColor (back_color, &cdef) && XGetHardwareColor (&cdef))
                    255:     {
                    256:       back = cdef.pixel;
                    257:     }
                    258:   else if (back_color && strcmp (back_color, "white") == 0)
                    259:     {
                    260:       back = WhitePixel;
                    261:     }
                    262:   else if (back_color && strcmp (back_color, "black") == 0)
                    263:     {
                    264:       back = BlackPixel;
                    265:     }
                    266:   else
                    267:     {
                    268:       back_color = save_color;
                    269:     }
                    270:   temp = XMakeTile (back);
                    271:   XChangeBackground (XXwindow, temp);
                    272:   /*    XPixFill (XXwindow, 0, 0, screen_width * fontinfo->width,
                    273:        screen_height * fontinfo->height, back, ClipModeClipped,
                    274:        GXcopy, AllPlanes);*/
                    275:   UNBLOCK_INPUT ();
                    276:   Fredraw_display ();
                    277:   /*    dumprectangle (0, 0, screen_height * fontinfo->height,
                    278:        screen_width * fontinfo -> width);*/
                    279:   /*    PendingExposure = 1;
                    280:        xfixscreen ();*/
                    281:   XFlush ();
                    282:   XFreePixmap (temp);
                    283:   return Qt;
                    284: }
                    285: 
                    286: DEFUN ("x-set-border-color", Fx_set_border_color, Sx_set_border_color, 1, 1,
                    287:        "sSet border color: ",
                    288:        "Set border color to COLOR.")
                    289:   (arg)
                    290:      Lisp_Object arg;
                    291: {
                    292:   Color cdef;
                    293:   Pixmap temp;
                    294:   BLOCK_INPUT_DECLARE ()
                    295: 
                    296:   check_xterm ();
                    297:   CHECK_STRING (arg,1);
                    298:   brdr_color= (char *) xmalloc (XSTRING (arg)->size + 1);
                    299:   bcopy (XSTRING (arg)->data, brdr_color, XSTRING (arg)->size + 1);
                    300:   BLOCK_INPUT ();
                    301:   if (brdr_color && DisplayCells () > 2 &&
                    302:       XParseColor (brdr_color, &cdef) && XGetHardwareColor (&cdef))
                    303:     {
                    304:       temp = XMakeTile (cdef.pixel);
                    305:       brdr = cdef.pixel;
                    306:     }
                    307:   else if (brdr_color && strcmp (brdr_color, "black") == 0)
                    308:     {
                    309:       temp = BlackPixmap;
                    310:       brdr = BlackPixel;
                    311:     }
                    312:   else if (brdr_color && strcmp (brdr_color, "white") == 0)
                    313:     {
                    314:       temp = WhitePixmap;
                    315:       brdr = WhitePixel;
                    316:     }
                    317:   else
                    318:     {
                    319:       temp = XMakePixmap ((Bitmap) XStoreBitmap (16, 16, gray_bits),
                    320:                          BlackPixel, WhitePixel);
                    321:       brdr = BlackPixel;
                    322:       brdr_color = "gray";
                    323:     }
                    324:   if (XXborder)
                    325:     XChangeBorder (XXwindow, temp);
                    326:   UNBLOCK_INPUT ();
                    327:   XFreePixmap (temp);
                    328:   return Qt;
                    329: }
                    330: 
                    331: DEFUN ("x-set-cursor-color", Fx_set_cursor_color, Sx_set_cursor_color, 1, 1,
                    332:        "sSet text cursor color: ",
                    333:        "Set text cursor color to COLOR.")
                    334:   (arg)
                    335:      Lisp_Object arg;
                    336: {
                    337:   Color cdef;
                    338:   BLOCK_INPUT_DECLARE ()
                    339:   char *save_color;
                    340: 
                    341:   check_xterm ();
                    342:   CHECK_STRING (arg,1);
                    343:   save_color = curs_color;
                    344:   curs_color = (char *) xmalloc (XSTRING (arg)->size + 1);
                    345:   BLOCK_INPUT ();
                    346:   bcopy (XSTRING (arg)->data, curs_color, XSTRING (arg)->size + 1);
                    347:   if (curs_color && DisplayCells () > 2 &&
                    348:       XParseColor (curs_color, &cdef) && XGetHardwareColor (&cdef))
                    349:     {
                    350:       curs = cdef.pixel;
                    351:     }
                    352:   else if (curs_color && strcmp (curs_color, "black") == 0)
                    353:     {
                    354:       curs = BlackPixel;
                    355:     }
                    356:   else if (curs_color && strcmp (curs_color, "white") == 0)
                    357:     {
                    358:       curs = WhitePixel;
                    359:     }
                    360:   else
                    361:     {
                    362:       curs_color = save_color;
                    363:     }
                    364:   CursorToggle ();
                    365:   CursorToggle ();
                    366:   UNBLOCK_INPUT ();
                    367:   return Qt;
                    368: }
                    369: 
                    370: DEFUN ("x-set-mouse-color", Fx_set_mouse_color, Sx_set_mouse_color, 1, 1,
                    371:        "sSet mouse cursor color: ",
                    372:        "Set mouse cursor color to COLOR.")
                    373:   (arg)
                    374:      Lisp_Object arg;
                    375: {
                    376:   Cursor temp;
                    377:   BLOCK_INPUT_DECLARE ()
                    378:   Color cdef;
                    379:   char *save_color;
                    380: 
                    381:   check_xterm ();
                    382:   CHECK_STRING (arg,1);
                    383:   save_color = mous_color;
                    384:   mous_color = (char *) xmalloc (XSTRING (arg)->size + 1);
                    385:   BLOCK_INPUT ();
                    386:   bcopy (XSTRING (arg)->data, mous_color, XSTRING (arg)->size + 1);
                    387: 
                    388:   if (mous_color && DisplayCells () > 2
                    389:       && XParseColor (mous_color, &cdef) && XGetHardwareColor (&cdef))
                    390:     {
                    391:       mous = cdef.pixel;
                    392:     }
                    393:   else if (mous_color && strcmp (mous_color, "black") == 0)
                    394:     {
                    395:       mous = BlackPixel;
                    396:     }
                    397:   else if (mous_color && strcmp (mous_color, "white") == 0)
                    398:     {
                    399:       mous = WhitePixel;
                    400:     }
                    401:   else
                    402:     {
                    403:       mous_color = save_color;
                    404:     }
                    405:   temp = XCreateCursor (16, 16, MouseCursor, MouseMask, 0, 0,
                    406:                        mous, back, GXcopy);
                    407:   XDefineCursor (XXwindow, temp);
                    408:   XFreeCursor (EmacsCursor);
                    409:   UNBLOCK_INPUT ();
                    410:   bcopy (&temp, &EmacsCursor, sizeof (Cursor));
                    411:   return Qt;
                    412: }   
                    413: 
                    414: DEFUN ("x-color-p", Fx_color_p, Sx_color_p, 0, 0, 0,
                    415:        "Returns t if the display is a color X terminal.")
                    416:   ()
                    417: {
                    418:   check_xterm ();
                    419:   if (DisplayCells () > 2)
                    420:     return Qt;
                    421:   else
                    422:     return Qnil;
                    423: }
                    424:        
                    425: DEFUN ("x-get-foreground-color", Fx_get_foreground_color,
                    426:        Sx_get_foreground_color, 0, 0, 0,
                    427:        "Returns the color of the foreground, as a string.")
                    428:   ()
                    429: {
                    430:   Lisp_Object string;
                    431:   string = build_string (fore_color);
                    432:   return string;
                    433: }
                    434: 
                    435: DEFUN ("x-get-background-color", Fx_get_background_color,
                    436:        Sx_get_background_color, 0, 0, 0,
                    437:        "Returns the color of the background, as a string.")
                    438:   ()
                    439: {
                    440:   Lisp_Object string;
                    441:   string = build_string (back_color);
                    442:   return string;
                    443: }
                    444: 
                    445: DEFUN ("x-get-border-color", Fx_get_border_color,
                    446:        Sx_get_border_color, 0, 0, 0,
                    447:        "Returns the color of the border, as a string.")
                    448:   ()
                    449: {
                    450:   Lisp_Object string;
                    451:   string = build_string (brdr_color);
                    452:   return string;
                    453: }
                    454: 
                    455: DEFUN ("x-get-cursor-color", Fx_get_cursor_color,
                    456:        Sx_get_cursor_color, 0, 0, 0,
                    457:        "Returns the color of the cursor, as a string.")
                    458:   ()
                    459: {
                    460:   Lisp_Object string;
                    461:   string = build_string (curs_color);
                    462:   return string;
                    463: }
                    464: 
                    465: DEFUN ("x-get-mouse-color", Fx_get_mouse_color,
                    466:        Sx_get_mouse_color, 0, 0, 0,
                    467:        "Returns the color of the mouse cursor, as a string.")
                    468:   ()
                    469: {
                    470:   Lisp_Object string;
                    471:   string = build_string (mous_color);
                    472:   return string;
                    473: }
                    474: 
                    475: DEFUN ("x-get-default", Fx_get_default, Sx_get_default, 1, 1, 0,
                    476:        "Get X default ATTRIBUTE from the system.  Returns nil if\n\
                    477: attribute does not exist.")
                    478:   (arg)
                    479:      Lisp_Object arg;
                    480: {
                    481:   unsigned char *default_name, *value;
                    482: 
                    483:   CHECK_STRING (arg, 1);
                    484:   default_name = XSTRING (arg)->data;
                    485: 
                    486:   value = (unsigned char *) XGetDefault ("emacs", default_name);
                    487:   /* if (value == 0)
                    488:      value = XGetDefault ("", default_name); */
                    489:   if (value)
                    490:     return build_string (value);
                    491:   else
                    492:     return (Qnil);
                    493: }
                    494: 
                    495: DEFUN ("x-set-icon", Fx_set_icon, Sx_set_icon, 1, 1, "P",
                    496:   "Set type of icon used by X for Emacs's window.\n\
                    497: ARG non-nil means use kitchen-sink icon;\n\
                    498: nil means use generic window manager icon.")
                    499:   (arg)
                    500:      Lisp_Object arg;
                    501: {
                    502:   check_xterm ();
                    503:   if (NULL (arg))
                    504:     XTextIcon ();
                    505:   else
                    506:     XBitmapIcon ();
                    507:   return arg;
                    508: }
                    509: 
                    510: DEFUN ("x-set-font", Fx_set_font, Sx_set_font, 1, 1, "sFont Name: ",
                    511:       "At initialization sets the font to be used for the X window.")
                    512:   (arg)
                    513:      Lisp_Object arg;
                    514: {
                    515:   register char *newfontname;
                    516:        
                    517:   CHECK_STRING (arg, 1);
                    518:   check_xterm ();
                    519: 
                    520:   newfontname = (char *) xmalloc (XSTRING (arg)->size + 1);
                    521:   bcopy (XSTRING (arg)->data, newfontname, XSTRING (arg)->size + 1);
                    522:   if (XSTRING (arg)->size == 0)
                    523:     /* XOpenFont ("") gets a badarg error rather than a badfont error.
                    524:        I believe this is an X bug.
                    525:        In emacs, badarg errors cause emacs to die, whilst badfont errors
                    526:        are caught.  This kludge prevents us from dying.
                    527:      */
                    528:     goto badfont;
                    529: 
                    530:   if (!XNewFont (newfontname))
                    531:     {
                    532:       free (XXcurrentfont);
                    533:       XXcurrentfont = newfontname;
                    534:       return Qt;
                    535:     }
                    536:   else
                    537:     {
                    538:     badfont:
                    539:       error ("Font \"%s\" is not defined", newfontname);
                    540:       free (newfontname);
                    541:     }
                    542: 
                    543:   return Qnil;
                    544: }
                    545: 
                    546: DEFUN ("x-set-window-edges", Fx_set_window_edges, Sx_set_window_edges, 4, 4,
                    547:   "nNumber of Columns: \nnNumber of Rows: \nnX Offset in Pixels: \n\
                    548: nY Offset in Pixels: ",
                    549:   "Sets X window size/position: size COLS by ROWS, positions XOFF and YOFF.\n\
                    550: To get \"minus zero\" for XOFF or YOFF, supply -1.")
                    551:   (cols, rows, xoffset, yoffset)
                    552:      Lisp_Object rows, cols, xoffset, yoffset;
                    553: {
                    554:   BLOCK_INPUT_DECLARE ()
                    555: 
                    556:   CHECK_NUMBER (rows, 1);
                    557:   CHECK_NUMBER (cols, 2);
                    558:   CHECK_NUMBER (xoffset, 3);
                    559:   CHECK_NUMBER (yoffset, 4);
                    560:   check_xterm ();
                    561: 
                    562:   BLOCK_INPUT ();
                    563:   x_edges_specified = 1;
                    564:   if (XINT (rows) != screen_width || XINT (cols) != screen_height) 
                    565:     {
                    566:       XSetWindowSize (XINT (rows), XINT (cols));
                    567:     }
                    568:   XSetOffset (XINT (xoffset), XINT (yoffset));
                    569:   XFlush ();
                    570:   UNBLOCK_INPUT ();
                    571:   return Qt;
                    572: }
                    573: 
                    574: DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p,
                    575:   Scoordinates_in_window_p, 2, 2, 0,
                    576:   "Return non-nil if POSITIONS (a list, (SCREEN-X SCREEN-Y)) is in WINDOW.\n\
                    577: Returned value is list of positions expressed\n\
                    578: relative to window upper left corner.")
                    579:   (coordinate, window)
                    580:      register Lisp_Object coordinate, window;
                    581: {
                    582:   register Lisp_Object xcoord, ycoord;
                    583:        
                    584:   if (!CONSP (coordinate)) wrong_type_argument (Qlistp, coordinate);
                    585:   CHECK_WINDOW (window, 2);
                    586:   xcoord = Fcar (coordinate);
                    587:   ycoord = Fcar (Fcdr (coordinate));
                    588:   CHECK_NUMBER (xcoord, 0);
                    589:   CHECK_NUMBER (ycoord, 1);
                    590:   if ((XINT (xcoord) < XINT (XWINDOW (window)->left)) ||
                    591:       (XINT (xcoord) >= (XINT (XWINDOW (window)->left) +
                    592:                         XINT (XWINDOW (window)->width))))
                    593:     {
                    594:       return Qnil;
                    595:     } 
                    596:   XFASTINT (xcoord) -= XFASTINT (XWINDOW (window)->left);
                    597:   if (XINT (ycoord) == (screen_height - 1))
                    598:     return Qnil;
                    599:   if ((XINT (ycoord) < XINT (XWINDOW (window)->top)) ||
                    600:       (XINT (ycoord) >= (XINT (XWINDOW (window)->top) +
                    601:                         XINT (XWINDOW (window)->height)) - 1))
                    602:     {
                    603:       return Qnil;
                    604:     }
                    605:   XFASTINT (ycoord) -= XFASTINT (XWINDOW (window)->top);
                    606:   return Fcons (xcoord, Fcons (ycoord, Qnil));
                    607: }
                    608: 
                    609: DEFUN ("x-mouse-events", Fx_mouse_events, Sx_mouse_events, 0, 0, 0,
                    610:   "Return number of pending mouse events from X window system.")
                    611:   ()
                    612: {
                    613:   register Lisp_Object tem;
                    614:   register int windex, rindex, mindex;
                    615: 
                    616:   check_xterm ();
                    617:   windex = Xxrepbuffer.windex;
                    618:   rindex = Xxrepbuffer.rindex;
                    619:   mindex = Xxrepbuffer.mindex;
                    620: 
                    621:   if (windex >= rindex) 
                    622:     {
                    623:       XSET (tem, Lisp_Int, windex - rindex);
                    624:     }
                    625:   else
                    626:     {
                    627:       XSET (tem, Lisp_Int, mindex + 1 - (rindex - windex));
                    628:     }
                    629:   return tem;
                    630: }
                    631: 
                    632: DEFUN ("x-proc-mouse-event", Fx_proc_mouse_event, Sx_proc_mouse_event,
                    633:   0, 0, 0,
                    634:   "Pulls a mouse event out of the mouse event buffer and dispatches\n\
                    635: the appropriate function to act upon this event.")
                    636:   ()
                    637: {
                    638:   XButtonEvent xrep;
                    639:   register Lisp_Object Mouse_Cmd;
                    640:   register char com_letter;
                    641:   register char key_mask;
                    642:   register Lisp_Object tempx;
                    643:   register Lisp_Object tempy;
                    644:   extern Lisp_Object get_keyelt ();
                    645: 
                    646:   check_xterm ();
                    647:   if (unloadxrepbuffer (&xrep, &Xxrepbuffer) == 0) 
                    648:     {
                    649:       com_letter = xrep.detail & 3;
                    650:       key_mask = (xrep.detail >> 8) & 0xf0;
                    651:       com_letter |= key_mask;
                    652: #ifndef HPUX
                    653:       if (xrep.type == ButtonReleased) com_letter |= 0x04;
                    654: #endif
                    655:       XSET (tempx, Lisp_Int, min (screen_width-1, max (0, (xrep.x - XXInternalBorder)/fontinfo->width)));
                    656:       XSET (tempy, Lisp_Int, min (screen_height-1, max (0, (xrep.y - XXInternalBorder)/fontinfo->height)));
                    657:       Vx_mouse_pos = Fcons (tempx, Fcons (tempy, Qnil));
                    658:       XSET (tempx, Lisp_Int, xrep.x + XXxoffset);
                    659:       XSET (tempy, Lisp_Int, xrep.y + XXyoffset);
                    660:       Vx_mouse_abs_pos = Fcons (tempx, Fcons (tempy, Qnil));
                    661:       Vx_mouse_item = make_number (com_letter);
                    662:       Mouse_Cmd = get_keyelt (access_keymap (MouseMap, com_letter));
                    663:       if (NULL (Mouse_Cmd)) 
                    664:        {
                    665: #ifndef HPUX
                    666:          if (xrep.type != ButtonReleased)
                    667:            bell ();
                    668: #endif
                    669:          Vx_mouse_pos = Qnil;
                    670:          Vx_mouse_abs_pos = Qnil;
                    671:        }
                    672:       else
                    673:        {
                    674:          return call1 (Mouse_Cmd, Vx_mouse_pos);
                    675:        }
                    676:     }
                    677:   return Qnil;
                    678: }
                    679: 
                    680: DEFUN ("x-get-mouse-event", Fx_get_mouse_event, Sx_get_mouse_event,
                    681:   1, 1, 0,
                    682:   "Get next mouse event out of mouse event buffer (com-letter (x y)).\n\
                    683: ARG non-nil means return nil immediately if no pending event;\n\
                    684: otherwise, wait for an event.")
                    685:   (arg)
                    686:      Lisp_Object arg;
                    687: {
                    688:   XButtonEvent xrep;
                    689:   register Lisp_Object Mouse_Cmd;
                    690:   register char com_letter;
                    691:   register char key_mask;
                    692: 
                    693:   register Lisp_Object tempx;
                    694:   register Lisp_Object tempy;
                    695:   extern Lisp_Object get_keyelt ();
                    696: 
                    697:   check_xterm ();
                    698: 
                    699:   if (NULL (arg))
                    700:     while (Xxrepbuffer.windex == Xxrepbuffer.rindex);
                    701: /*** ??? Surely you don't mean to busy wait??? */
                    702:   if (unloadxrepbuffer (&xrep, &Xxrepbuffer) == 0) 
                    703:     {
                    704:       com_letter = *((char *)&xrep.detail);
                    705:       com_letter &= 3;
                    706:       key_mask = *((char *)&xrep.detail + 1);
                    707:       key_mask &= 0xf0;
                    708:       com_letter |= key_mask;
                    709: #ifndef HPUX
                    710:       if (xrep.type == ButtonReleased) com_letter |= 0x04;
                    711: #endif
                    712:       XSET (tempx, Lisp_Int, min (screen_width, max (0, (xrep.x - XXInternalBorder)/fontinfo->width)));
                    713:       XSET (tempy, Lisp_Int, min (screen_height, max (0, (xrep.y - XXInternalBorder)/fontinfo->height)));
                    714:       Vx_mouse_pos = Fcons (tempx, Fcons (tempy, Qnil));
                    715:       XSET (tempx, Lisp_Int, xrep.x + XXxoffset);
                    716:       XSET (tempy, Lisp_Int, xrep.y + XXyoffset);
                    717:       Vx_mouse_abs_pos = Fcons (tempx, Fcons (tempy, Qnil));
                    718:       return Fcons (com_letter, Fcons (Vx_mouse_pos, Qnil));
                    719:     }
                    720:   return Qnil;
                    721: }
                    722: 
                    723: DEFUN ("x-set-keyboard-enable", Fx_set_keyboard_enable,
                    724:   Sx_set_keyboard_enable, 1, 1, 0,
                    725:   "In the X window system, set the flag that permite keyboard input.\n\
                    726: Permit input if ARG is non-nil.")
                    727:   (arg)
                    728:      Lisp_Object arg;
                    729: {
                    730:   BLOCK_INPUT_DECLARE ()
                    731: 
                    732:   check_xterm ();
                    733: 
                    734:   BLOCK_INPUT ();
                    735:   XSelectInput (XXwindow,
                    736:                ExposeWindow | ButtonPressed
                    737: #ifndef HPUX
                    738:                | ButtonReleased
                    739: #endif
                    740:                | ExposeRegion | ExposeCopy | (!NULL (arg) ? KeyPressed : 0));
                    741:   UNBLOCK_INPUT ();
                    742:   return arg;
                    743: }
                    744: 
                    745: DEFUN ("x-set-mouse-inform-flag", Fx_set_mouse_inform_flag,
                    746:   Sx_set_mouse_inform_flag, 1, 1, 0,
                    747:   "Set inform-of-mouse-events flag in X window system on if ARG is non-nil.")
                    748:   (arg)
                    749:      Lisp_Object arg;
                    750: {
                    751:   informflag = !NULL (arg);
                    752:   return arg;
                    753: }
                    754: 
                    755: DEFUN ("x-store-cut-buffer", Fx_store_cut_buffer, Sx_store_cut_buffer,
                    756:   1, 1, "sSend string to X:",
                    757:   "Store contents of STRING into the cut buffer of the X window system.")
                    758:   (string)
                    759:      register Lisp_Object string;
                    760: {
                    761:   BLOCK_INPUT_DECLARE ()
                    762: 
                    763:   CHECK_STRING (string, 1);
                    764:   check_xterm ();
                    765: 
                    766:   BLOCK_INPUT ();
                    767:   XStoreBytes (XSTRING (string)->data, XSTRING (string)->size);
                    768:   UNBLOCK_INPUT ();
                    769: 
                    770:   return Qnil;
                    771: }
                    772: 
                    773: DEFUN ("x-get-cut-buffer", Fx_get_cut_buffer, Sx_get_cut_buffer, 0, 0, 0,
                    774:   "Return contents of cut buffer of the X window system, as a string.")
                    775:   ()
                    776: {
                    777:   int len;
                    778:   register Lisp_Object string;
                    779:   BLOCK_INPUT_DECLARE ()
                    780:   register char *d;
                    781: 
                    782:   BLOCK_INPUT ();
                    783:   d = XFetchBytes (&len);
                    784:   string = make_string (d, len);
                    785:   UNBLOCK_INPUT ();
                    786:   return string;
                    787: }
                    788: 
                    789: DEFUN ("x-rubber-band", Fx_rubber_band, Sx_rubber_band, 0, 0, "",
                    790:   "Ask user to specify Emacs window position and size with mouse.\n\
                    791: This is done automatically if the data has not been specified\n\
                    792: when Emacs needs the window to be displayed.")
                    793:   ()
                    794: {
                    795:   int x, y, width, height;
                    796:   BLOCK_INPUT_DECLARE ()
                    797: 
                    798:   x_edges_specified = 1;
                    799: 
                    800:   check_xterm ();
                    801:   BLOCK_INPUT ();
                    802:   window_fetch (fontinfo->id, &x, &y, &width, &height, "", default_window,
                    803:                XXborder, "GNU Emacs");
                    804:   XSetWindowSize (height, width);
                    805:   XSetOffset (x, y);
                    806:   XFlush ();
                    807:   ++screen_garbaged;
                    808:   UNBLOCK_INPUT ();
                    809:   return Qnil;
                    810: }
                    811: 
                    812: DEFUN ("x-create-x-window", Fx_create_x_window, Sx_create_x_window,
                    813:        1, 1, 0,
                    814:        "Create window for GNU Emacs from a valid GEOMETRY specification.")
                    815:      (arg)
                    816:      Lisp_Object arg;
                    817: {
                    818:   int x, y, width, height;
                    819:   char *geometry;
                    820:   BLOCK_INPUT_DECLARE ()
                    821: 
                    822:   x_edges_specified = 1;
                    823: 
                    824:   check_xterm ();
                    825:   CHECK_STRING (arg, 1);
                    826:   geometry= (char *) xmalloc (XSTRING (arg)->size + 1);
                    827:   bcopy (XSTRING (arg)->data, geometry, XSTRING (arg)->size + 1);
                    828:   BLOCK_INPUT ();
                    829:   window_fetch (fontinfo->id, &x, &y, &width, &height, geometry,
                    830:                default_window, XXborder, "GNU Emacs");
                    831:   XSetWindowSize (height, width);
                    832: /*  XSetWindowSize ((height - (2 * XXborder))/fontinfo -> height,
                    833:     (width - (2 * XXborder))/fontinfo -> width);*/
                    834:   XSetOffset (x, y);
                    835:   XMapWindow (XXwindow);
                    836:   XFlush ();
                    837:   UNBLOCK_INPUT ();
                    838:   return Qnil;
                    839: }
                    840: 
                    841: 
                    842: static int
                    843: grey_p (colour)
                    844:      char *colour;
                    845: {
                    846:   return (!strcmp (colour, "grey") || !strcmp (colour, "Grey") ||
                    847:          !strcmp (colour, "gray") || !strcmp (colour, "Gray"));
                    848: }
                    849: 
                    850: DEFUN ("x-set-border-width", Fx_set_border_width, Sx_set_border_width,
                    851:   1, 1, "NSet border width: ",
                    852:   "Set width of border to WIDTH, in the X window system.")
                    853:   (borderwidth)
                    854:      register Lisp_Object borderwidth;
                    855: {
                    856:   WindowInfo WinInfo;
                    857:   BLOCK_INPUT_DECLARE ()
                    858:   Window tempwindow;
                    859:   register int temppixelwidth;
                    860:   register int temppixelheight;
                    861:   register int tempx;
                    862:   register int tempy;
                    863:   Pixmap temp_brdr, temp_back;
                    864: 
                    865:   CHECK_NUMBER (borderwidth, 0);
                    866: 
                    867:   check_xterm ();
                    868:   
                    869:   if (XINT (borderwidth) < 0) XSETINT (borderwidth, 0);
                    870:   
                    871:   temppixelwidth = screen_width * fontinfo->width + 2 * XXInternalBorder;
                    872:   temppixelheight = screen_height * fontinfo->height + 2 * XXInternalBorder;
                    873:   BLOCK_INPUT ();
                    874:   XQueryWindow (XXwindow, &WinInfo);
                    875:   tempx = WinInfo.x;
                    876:   tempy = WinInfo.y;
                    877:   if (grey_p (brdr_color))
                    878:     temp_brdr = XMakePixmap ((Bitmap) XStoreBitmap (16, 16, gray_bits),
                    879:                             BlackPixel, WhitePixel);
                    880:   else
                    881:     temp_brdr = XMakeTile (brdr);
                    882:   temp_back = XMakeTile (back);
                    883:   tempwindow = XCreateWindow (RootWindow,
                    884:                              tempx /* Absolute horizontal offset */,
                    885:                              tempy /* Absolute Vertical offset */,
                    886:                              temppixelwidth, temppixelheight,
                    887:                              XINT (borderwidth),
                    888:                              temp_brdr, temp_back);
                    889:   if (tempwindow) 
                    890:     {
                    891:       XDestroyWindow (XXwindow);
                    892:       XXwindow = tempwindow;
                    893:       pixelwidth = temppixelwidth;
                    894:       pixelheight = temppixelheight;
                    895:       XXborder = XINT (borderwidth);
                    896:       XSelectInput (XXwindow, NoEvent);
                    897:       XSetResizeHint (XXwindow, 2 * XXInternalBorder, 2 * XXInternalBorder,
                    898:                      /* fontinfo->width * 1, fontinfo->height * 1, */
                    899:                      fontinfo->width, fontinfo->height);
                    900:       XStoreName (XXwindow, &iconidentity[0]);
                    901:       XDefineCursor (XXwindow, EmacsCursor);
                    902:       XFreePixmap (temp_brdr);
                    903:       XFreePixmap (temp_back);
                    904:       UNBLOCK_INPUT_RESIGNAL ();
                    905:       if (WindowMapped)
                    906:        {
                    907:          XMapWindow (XXwindow);
                    908:          XSelectInput (XXwindow, KeyPressed | ExposeWindow | ButtonPressed
                    909: #ifndef HPUX
                    910:                        | ButtonReleased
                    911: #endif
                    912:                        | ExposeRegion | ExposeCopy);
                    913:          ++screen_garbaged;
                    914:          XFlush ();
                    915:        }
                    916:       return Qt;
                    917:     }
                    918:   else
                    919:     {
                    920:       UNBLOCK_INPUT_RESIGNAL ();
                    921:       message ("Could not recreate window.");
                    922:       return Qnil;
                    923:     }
                    924: }
                    925: 
                    926: 
                    927: DEFUN ("x-set-internal-border-width", Fx_set_internal_border_width,
                    928:        Sx_set_internal_border_width, 1, 1, "NSet internal border width: ",
                    929:   "Set width of internal border to WIDTH, in the X window system.")
                    930:   (internalborderwidth)
                    931:      register Lisp_Object internalborderwidth;
                    932: {
                    933:   WindowInfo WinInfo;
                    934:   BLOCK_INPUT_DECLARE ()
                    935:   Window tempwindow;
                    936:   register int temppixelwidth;
                    937:   register int temppixelheight;
                    938:   register int tempx;
                    939:   register int tempy;
                    940:   register int intbord;
                    941:   Pixmap temp_brdr, temp_back;
                    942: 
                    943:   CHECK_NUMBER (internalborderwidth, 0);
                    944: 
                    945:   check_xterm ();
                    946:   
                    947:   if (XINT (internalborderwidth) < 0) XSETINT (internalborderwidth, 0);
                    948:   intbord = XINT (internalborderwidth);
                    949:   temppixelwidth = screen_width * fontinfo->width + 2 * intbord;
                    950:   temppixelheight = screen_height * fontinfo->height + 2 * intbord;
                    951:   BLOCK_INPUT ();
                    952:   XQueryWindow (XXwindow, &WinInfo);
                    953:   tempx = WinInfo.x;
                    954:   tempy = WinInfo.y;
                    955:   if (grey_p (brdr_color))
                    956:     temp_brdr = XMakePixmap ((Bitmap) XStoreBitmap (16, 16, gray_bits),
                    957:                             BlackPixel, WhitePixel);
                    958:   else
                    959:     temp_brdr = XMakeTile (brdr);
                    960:   temp_back = XMakeTile (back);
                    961:   tempwindow = XCreateWindow (RootWindow,
                    962:                              tempx /* Absolute horizontal offset */,
                    963:                              tempy /* Absolute Vertical offset */,
                    964:                              temppixelwidth, temppixelheight,
                    965:                              XXborder,
                    966:                              temp_brdr, temp_back);
                    967:   if (tempwindow) 
                    968:     {
                    969:       XDestroyWindow (XXwindow);
                    970:       XXwindow = tempwindow;
                    971:       pixelwidth = temppixelwidth;
                    972:       pixelheight = temppixelheight;
                    973:       XXInternalBorder = intbord;
                    974:       XSelectInput (XXwindow, NoEvent);
                    975:       XSetResizeHint (XXwindow, 2 * XXInternalBorder, 2 * XXInternalBorder,
                    976:                      /* fontinfo->width * 1, fontinfo->height * 1, */
                    977:                      fontinfo->width, fontinfo->height);
                    978:       XStoreName (XXwindow, &iconidentity[0]);
                    979:       XDefineCursor (XXwindow, EmacsCursor);
                    980:       XFreePixmap (temp_brdr);
                    981:       XFreePixmap (temp_back);
                    982:       UNBLOCK_INPUT_RESIGNAL ();
                    983:       if (WindowMapped)
                    984:        {
                    985:          XMapWindow (XXwindow);
                    986:          XSelectInput (XXwindow, KeyPressed | ExposeWindow | ButtonPressed
                    987: #ifndef HPUX
                    988:                        | ButtonReleased
                    989: #endif
                    990:                        | ExposeRegion | ExposeCopy);
                    991:          ++screen_garbaged;
                    992:          XFlush ();
                    993:        }
                    994:       return Qt;
                    995:     }
                    996:   else
                    997:     {
                    998:       UNBLOCK_INPUT_RESIGNAL ();
                    999:       message ("Could not recreate window.");
                   1000:       return Qnil;
                   1001:     }
                   1002: }
                   1003: 
                   1004: jmp_buf dispenv;
                   1005: Display *OldDisplay;
                   1006: FontInfo *OldFontInfo;
                   1007: Window OldWindow;
                   1008: 
                   1009: XRestoreDisplay ()
                   1010: {
                   1011:   longjmp (dispenv, "Unable to access display (probably)");
                   1012: }
                   1013: 
                   1014: DEFUN ("x-change-display", Fx_change_display, Sx_change_display, 1, 1,
                   1015:   "sNew display name: ", 
                   1016:   "This function takes one argument, the display where you wish to\n\
                   1017: continue your editing session.  Your current window will be unmapped and\n\
                   1018: the current display will be closed.  The new X display will be opened and\n\
                   1019: the rubber-band outline of the new window will appear on the new X display.\n\
                   1020: This function does not look at your .Xdefaults file, so you should use the\n\
                   1021: function x-new-display instead.")
                   1022:   (new_display)
                   1023:      register Lisp_Object new_display;
                   1024: {
                   1025:   Cursor OldEmacsCursor;
                   1026:   BLOCK_INPUT_DECLARE ()
                   1027:   register int (*pipefunc) ();
                   1028:   register char *newdisplayname = 0;
                   1029:   int x, y, width, height;
                   1030:   int temp_icon;
                   1031:   int XRestoreDisplay ();
                   1032:   Pixmap temp_brdr, temp_back;
                   1033:   register char *XXerrorcode;
                   1034: 
                   1035:   CHECK_STRING (new_display, 1);
                   1036:   check_xterm ();
                   1037: 
                   1038: /*  newdisplayname = xmalloc (XSTRING (new_display)->size + 1); */
                   1039: /*  bcopy (XSTRING (new_display)->data, newdisplayname, */
                   1040: /*      XSTRING (new_display)->size + 1);  */
                   1041:   /* Since this was freed at the end, why not just use the original? */
                   1042:   newdisplayname = (char *) XSTRING (new_display)->data;
                   1043:   BLOCK_INPUT ();
                   1044:   XIOErrorHandler (XRestoreDisplay);
                   1045:    if (XXerrorcode = (char *) setjmp (dispenv))
                   1046:      {
                   1047:  /*       free (&newdisplayname[0]); */
                   1048:        if (fontinfo)
                   1049:         XCloseFont (fontinfo);
                   1050:        if (XXwindow)
                   1051:         XDestroyWindow (XXwindow);
                   1052:        if (XXdisplay)
                   1053:         XCloseDisplay (XXdisplay);
                   1054:        XXdisplay = OldDisplay;
                   1055:        fontinfo = OldFontInfo;
                   1056:        XXwindow = OldWindow;
                   1057:        EmacsCursor = OldEmacsCursor;
                   1058:        XIOErrorHandler (handler);
                   1059:        XSetDisplay (XXdisplay);
                   1060:        UNBLOCK_INPUT_RESIGNAL ();
                   1061:        error ("Display change problem: %s", XXerrorcode);
                   1062:      }
                   1063:    else
                   1064:      {
                   1065:        OldEmacsCursor = EmacsCursor;
                   1066:        OldDisplay = XXdisplay;
                   1067:        OldFontInfo = fontinfo;
                   1068:        OldWindow = XXwindow;
                   1069:        XXwindow = 0;
                   1070:        fontinfo = 0;
                   1071:        XXdisplay = 0;
                   1072:      }
                   1073:    XXdisplay = XOpenDisplay (newdisplayname);
                   1074:    if (!XXdisplay)
                   1075:      {
                   1076:        longjmp (dispenv, "Probably nonexistant display");
                   1077:      }
                   1078:    XQueryWindow (RootWindow, &rootwindowinfo);
                   1079:    fontinfo = XOpenFont (XXcurrentfont);
                   1080:    if (!fontinfo)
                   1081:      {
                   1082:        longjmp (dispenv, "Bad font");
                   1083:      }
                   1084:    /* pixelwidth and pixelheight are correct*/
                   1085:    XXwindow = XCreateWindow (RootWindow,
                   1086:                             XXxoffset,
                   1087:                             XXyoffset,
                   1088:                             pixelwidth, pixelheight,
                   1089:                             XXborder, BlackPixmap, WhitePixmap);
                   1090:    if (!XXwindow)
                   1091:      {
                   1092:        longjmp (dispenv, "Could not create window");
                   1093:      }
                   1094:    fore = BlackPixel;
                   1095:    back = WhitePixel;
                   1096:    brdr = BlackPixel;
                   1097:    mous = BlackPixel;
                   1098:    curs = BlackPixel;
                   1099: 
                   1100:    fore_color = "black";
                   1101:    back_color = "white";
                   1102:    brdr_color = "black";
                   1103:    mous_color = "black";
                   1104:    curs_color = "black";
                   1105: 
                   1106:    XSelectInput (XXwindow, NoEvent);
                   1107:    EmacsCursor = XCreateCursor (16, 16, MouseCursor, MouseMask,
                   1108:                                0, 0, mous, back, GXcopy);
                   1109:   XDefineCursor (XXwindow, EmacsCursor);
                   1110:   XSetResizeHint (XXwindow, 2 * XXInternalBorder, 2 * XXInternalBorder,
                   1111:                  /* fontinfo->width * 1, fontinfo->height * 1, */
                   1112:                  fontinfo->width, fontinfo->height);
                   1113:    XStoreName (XXwindow, iconidentity);
                   1114: /*  WindowMapped = 0;*/
                   1115:   x_edges_specified = 0;
                   1116:   bitblt = 0;
                   1117:   CursorExists = 0;
                   1118:   VisibleX = 0;
                   1119:   VisibleY = 0;
                   1120:   XSetDisplay (XXdisplay);
                   1121: /*  XQueryWindow (RootWindow, &rootwindowinfo);*/
                   1122: /*  if (WindowMapped)
                   1123:     {*/
                   1124:   XXIconWindow = XCreateWindow (RootWindow, 0, 0, sink_width, sink_height,
                   1125:                                2, WhitePixmap, BlackPixmap);
                   1126:   XXIconMask = XStoreBitmap (sink_mask_width, sink_mask_height, sink_mask_bits);
                   1127:   WindowMapped = 0;
                   1128:   XPopUpWindow ();
                   1129: /*  }*/
                   1130:   WindowMapped = 1;
                   1131:   XSetDisplay (OldDisplay);
                   1132:   XCloseFont (OldFontInfo);
                   1133:   XFreeCursor (OldEmacsCursor);
                   1134:   XDestroyWindow (OldWindow);
                   1135:   XSetDisplay (XXdisplay);
                   1136:   XCloseDisplay (OldDisplay);
                   1137: 
                   1138:   x_init_1 (0);
                   1139:   UNBLOCK_INPUT_RESIGNAL ();
                   1140: /*  free (newdisplayname); */
                   1141: /*  x_edges_specified = 0;*/
                   1142:   ++screen_garbaged;
                   1143:   Fredraw_display ();
                   1144:   return Qt;
                   1145: }
                   1146: 
                   1147: /*
                   1148:    Grabs mouse, outlines a window, etc.
                   1149:    if left button pressed, sizes a wd x hd window (in characters)
                   1150:    if right button pressed, sizes wd x what will fit window (in characters)
                   1151:    if middle button pressed, allows user to size window in font increments
                   1152:        (+ border * 2 for inner border);
                   1153:    While sizing, dimensions of window are displayed in upper left of root.
                   1154:    str is also displayed there.
                   1155:    In all cases, x and y are the desired coordinates for the upper lefthand
                   1156:        corner, *width = width desired, *height = height desired
                   1157:        (min for both is 1 font char).
                   1158: 
                   1159:        */
                   1160: /*
                   1161:   This routine is a total crock.  It makes a window using XCreateTerm
                   1162:   purely for return value, destroying the temporary window created in
                   1163:   the process.  If XCreateTerm were broken into smaller, more easily
                   1164:   digestible pieces, it would be useful.  As such, the constraints of
                   1165:   time, emacs, and X conventions force me into this crock. --rlk
                   1166:   */
                   1167: 
                   1168: window_fetch (font, x, y, width, height, geo, deflt, border, str)
                   1169:      Font font;
                   1170:      int *x, *y, *width, *height;
                   1171:      char *geo, *deflt;
                   1172:      int border;
                   1173:      char *str;
                   1174: {
                   1175:   OpaqueFrame frame;
                   1176:   Window tempwindow;
                   1177:   WindowInfo WinInfo;
                   1178:   register int temppixelwidth;
                   1179:   register int temppixelheight;
                   1180:   Pixmap temp_brdr, temp_back;
                   1181: 
                   1182:   temp_brdr = XMakeTile (brdr);
                   1183:   temp_back = XMakeTile (back);
                   1184:   frame.bdrwidth = border;
                   1185:   if (grey_p (brdr_color))
                   1186:     frame.border = XMakePixmap ((Bitmap) XStoreBitmap (16, 16, gray_bits),
                   1187:                                BlackPixel, WhitePixel);
                   1188:   else
                   1189:     frame.border = XMakeTile (brdr);
                   1190:   frame.background = XMakeTile (back);
                   1191:   tempwindow = XCreateTerm (str, "emacs", geo, deflt, &frame, 10, 5,
                   1192:                            2 * XXInternalBorder, 2 * XXInternalBorder,
                   1193:                            width, height, fontinfo, fontinfo->width,
                   1194:                            fontinfo->height);
                   1195:   if (tempwindow) 
                   1196:     {
                   1197:       XDestroyWindow (XXwindow);
                   1198:       XXwindow = tempwindow;
                   1199:       XSelectInput (XXwindow, NoEvent);
                   1200:       XSetResizeHint (XXwindow, 2 * XXInternalBorder, 2 * XXInternalBorder,
                   1201:                      /* fontinfo->width * 1, fontinfo->height * 1, */
                   1202:                      fontinfo->width, fontinfo->height);
                   1203:       XStoreName (XXwindow, &iconidentity[0]);
                   1204:       XDefineCursor (XXwindow, EmacsCursor);
                   1205:       XQueryWindow (XXwindow, &WinInfo);
                   1206:       *x = WinInfo.x;
                   1207:       *y = WinInfo.y;
                   1208:       XFreePixmap (temp_brdr);
                   1209:       XFreePixmap (temp_back);
                   1210:       RESIGNAL_INPUT ();
                   1211:       if (WindowMapped)
                   1212:        {
                   1213:          XMapWindow (XXwindow);
                   1214:          XSelectInput (XXwindow, KeyPressed | ExposeWindow | ButtonPressed
                   1215: #ifndef HPUX
                   1216:                        | ButtonReleased
                   1217: #endif
                   1218:                        | ExposeRegion | ExposeCopy);
                   1219:          ++screen_garbaged;
                   1220:          XFlush ();
                   1221:        }
                   1222:       return Qt;
                   1223:     }
                   1224:   else
                   1225:     {
                   1226:       RESIGNAL_INPUT ();
                   1227:       message ("Could not recreate window.");
                   1228:       return Qnil;
                   1229:     }
                   1230: }
                   1231: 
                   1232: DEFUN ("x-rebind-key", Fx_rebind_key, Sx_rebind_key, 3, 3, 0,
                   1233:   "Rebind KEYCODE, with shift bits SHIFT-MASK, to new string NEWSTRING.\n\
                   1234: KEYCODE and SHIFT-MASK should be numbers representing the X keyboard code\n\
                   1235: and shift mask respectively.  NEWSTRING is an arbitrary string of keystrokes.\n\
                   1236: If SHIFT-MASK is nil, then KEYCODE's key will be bound to NEWSTRING for\n\
                   1237: all shift combinations.\n\
                   1238: Shift Lock  1     Shift    2\n\
                   1239: Meta       4      Control  8\n\
                   1240: \n\
                   1241: For values of KEYCODE, see /usr/lib/Xkeymap.txt (remember that the codes\n\
                   1242: in that file are in octal!)\n\
                   1243: \n\
                   1244: NOTE: due to an X bug, this function will not take effect unless one has\n\
                   1245: a ~/.Xkeymap file.  (See the documentation for the \"keycomp\" program.)\n\
                   1246: This problem will be fixed in X version 11.")
                   1247: 
                   1248:   (keycode, shift_mask, newstring)
                   1249:      register Lisp_Object keycode;
                   1250:      register Lisp_Object shift_mask;
                   1251:      register Lisp_Object newstring;
                   1252: {
                   1253:   char *rawstring;
                   1254:   int rawkey, rawshift;
                   1255:   int i;
                   1256:   int strsize;
                   1257: 
                   1258:   CHECK_NUMBER (keycode, 1);
                   1259:   if (!NULL (shift_mask))
                   1260:     CHECK_NUMBER (shift_mask, 2);
                   1261:   CHECK_STRING (newstring, 3);
                   1262:   strsize = XSTRING (newstring) ->size;
                   1263:   rawstring = (char *) xmalloc (strsize);
                   1264:   bcopy (XSTRING (newstring)->data, rawstring, strsize);
                   1265:   rawkey = ((unsigned) (XINT (keycode))) & 255;
                   1266:   if (NULL (shift_mask))
                   1267:     for (i = 0; i <= 15; i++)
                   1268:       XRebindCode (rawkey, i<<11, rawstring, strsize);
                   1269:   else
                   1270:     {
                   1271:       rawshift = (((unsigned) (XINT (shift_mask))) & 15) << 11;
                   1272:       XRebindCode (rawkey, rawshift, rawstring, strsize);
                   1273:     }
                   1274:   return Qnil;
                   1275: }
                   1276:   
                   1277: DEFUN ("x-rebind-keys", Fx_rebind_keys, Sx_rebind_keys, 2, 2, 0,
                   1278:   "Rebind KEYCODE to list of strings STRINGS.\n\
                   1279: STRINGS should be a list of 16 elements, one for each all shift combination.\n\
                   1280: nil as element means don't change.\n\
                   1281: See the documentation of x-rebind-key for more information.")
                   1282:   (keycode, strings)
                   1283:      register Lisp_Object keycode;
                   1284:      register Lisp_Object strings;
                   1285: {
                   1286:   register Lisp_Object item;
                   1287:   register char *rawstring;
                   1288:   int rawkey, strsize;
                   1289:   register unsigned i;
                   1290: 
                   1291:   CHECK_NUMBER (keycode, 1);
                   1292:   CHECK_CONS (strings, 2);
                   1293:   rawkey = ((unsigned) (XINT (keycode))) & 255;
                   1294:   for (i = 0; i <= 15; strings = Fcdr (strings), i++)
                   1295:     {
                   1296:       item = Fcar (strings);
                   1297:       if (!NULL (item))
                   1298:        {
                   1299:          CHECK_STRING (item, 2);
                   1300:          strsize = XSTRING (item)->size;
                   1301:          rawstring = (char *) xmalloc (strsize);
                   1302:          bcopy (XSTRING (item)->data, rawstring, strsize);
                   1303:          XRebindCode (rawkey, i << 11, rawstring, strsize);
                   1304:        }
                   1305:     }
                   1306:   return Qnil;
                   1307: }
                   1308: 
                   1309: XExitWithCoreDump (Disp, Event)
                   1310:      Display *Disp;
                   1311:      XErrorEvent *Event;
                   1312: {
                   1313:   XCleanUp ();
                   1314:   abort ();
                   1315: }
                   1316: 
                   1317: DEFUN ("x-debug", Fx_debug, Sx_debug, 1, 1, 0,
                   1318:   "ARG non-nil means that X errors should generate a coredump.")
                   1319:   (arg)
                   1320:      register Lisp_Object arg;
                   1321: {
                   1322:   if (!NULL (arg))
                   1323:     handler = XExitWithCoreDump;
                   1324:   else
                   1325:     {
                   1326:       extern int XExitGracefully ();
                   1327:       handler = XExitGracefully;
                   1328:     }
                   1329:   XErrorHandler (handler);
                   1330:   XIOErrorHandler (handler);
                   1331:   return (Qnil);
                   1332: }
                   1333: 
                   1334: XRedrawDisplay ()
                   1335: {
                   1336:   Fredraw_display ();
                   1337: }
                   1338: 
                   1339: XCleanUp ()
                   1340: {
                   1341:   Fdo_auto_save (Qt);
                   1342: #ifdef subprocesses
                   1343:   kill_buffer_processes (Qnil);
                   1344: #endif /* subprocesses */
                   1345: }
                   1346: 
                   1347: 
                   1348: syms_of_xfns ()
                   1349: {
                   1350:   x_edges_specified = 0;
                   1351: 
                   1352:   DEFVAR_LISP ("x-mouse-item", &Vx_mouse_item,
                   1353:      "Encoded representation of last mouse click, corresponding to\n\
                   1354: numerical entries in x-mouse-map.");
                   1355:   Vx_mouse_item = Qnil;
                   1356:   DEFVAR_LISP ("x-mouse-pos", &Vx_mouse_pos,
                   1357:      "Current x-y position of mouse by row, column as specified by font.");
                   1358:   Vx_mouse_pos = Qnil;
                   1359:   DEFVAR_LISP ("x-mouse-abs-pos", &Vx_mouse_abs_pos,
                   1360:      "Current x-y position of mouse by row, column in pixels, wrt root window.");
                   1361:   Vx_mouse_abs_pos = Qnil;
                   1362: 
                   1363:   defsubr (&Sx_pop_up_window);
                   1364:   defsubr (&Sx_set_bell);
                   1365:   defsubr (&Sx_flip_color);
                   1366:   defsubr (&Sx_set_icon);
                   1367:   defsubr (&Sx_set_font);
                   1368:   defsubr (&Sx_set_window_edges);
                   1369:   defsubr (&Scoordinates_in_window_p);
                   1370:   defsubr (&Sx_mouse_events);
                   1371:   defsubr (&Sx_proc_mouse_event);
                   1372:   defsubr (&Sx_get_mouse_event);
                   1373:   defsubr (&Sx_set_keyboard_enable);
                   1374:   defsubr (&Sx_set_mouse_inform_flag);
                   1375:   defsubr (&Sx_store_cut_buffer);
                   1376:   defsubr (&Sx_get_cut_buffer);
                   1377:   defsubr (&Sx_rubber_band);
                   1378:   defsubr (&Sx_create_x_window);
                   1379:   defsubr (&Sx_set_border_width);
                   1380:   defsubr (&Sx_set_internal_border_width);
                   1381:   defsubr (&Sx_change_display);
                   1382:   defsubr (&Sx_set_foreground_color);
                   1383:   defsubr (&Sx_set_background_color);
                   1384:   defsubr (&Sx_set_border_color);
                   1385:   defsubr (&Sx_set_cursor_color);
                   1386:   defsubr (&Sx_set_mouse_color);
                   1387:   defsubr (&Sx_get_foreground_color);
                   1388:   defsubr (&Sx_get_background_color);
                   1389:   defsubr (&Sx_get_border_color);
                   1390:   defsubr (&Sx_get_cursor_color);
                   1391:   defsubr (&Sx_get_mouse_color);
                   1392:   defsubr (&Sx_color_p);
                   1393:   defsubr (&Sx_get_default);
                   1394:   defsubr (&Sx_rebind_key);
                   1395:   defsubr (&Sx_rebind_keys);
                   1396:   defsubr (&Sx_debug);
                   1397: }
                   1398: 
                   1399: #endif /* HAVE_X_WINDOWS */
                   1400: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.