home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / lucid / lemacs-19.6 / src / xutils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-28  |  2.4 KB  |  86 lines

  1. /* Random utilities used by X.
  2.    Copyright (C) 1991, 1992 Free Software Foundation, Inc.
  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 2, 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. #include "config.h"
  21. #include "lisp.h"
  22. #include "xterm.h"
  23. #include "dispextern.h"
  24. #include "screen.h"
  25.  
  26. #define NO_CHAR_INFO(ch) (((ch)->width == 0) &&    \
  27.               ((ch)->rbearing == 0) && \
  28.               ((ch)->lbearing == 0))
  29.  
  30. XCharStruct *
  31. x_char_info (font, ch)
  32.      XFontStruct *font;
  33.      unsigned ch;
  34. {
  35.   if (ch >= font->min_char_or_byte2 && ch <= font->max_char_or_byte2)
  36.     {
  37.       XCharStruct *info = &font->per_char[(ch - font->min_char_or_byte2)];
  38.       
  39.       if (!NO_CHAR_INFO (info))
  40.     return info;
  41.     }
  42.   {
  43.     int default_index = font->default_char;
  44.     int limit_index = font->max_char_or_byte2 - font->min_char_or_byte2;
  45.  
  46.     /* Lucid fix? */
  47.     if ((default_index >= 0) && (default_index < limit_index))
  48.       return &font->per_char[default_index];
  49.     return &font->per_char[0];
  50.   }
  51. }
  52.  
  53. void
  54. x_read_mouse_position (s, x, y)
  55.      struct screen *s;
  56.      int *x, *y;
  57. {
  58.   Window w;
  59.   int ix, iy;
  60.   int ibw = s->display.x->internal_border_width;
  61. #ifdef LINE_INFO_COLUMN
  62.   int licw = s->display.x->line_info_column_width;
  63. #endif
  64.  
  65.   Window root_window;
  66.   int root_x, root_y;
  67.   unsigned int keys_and_buttons;
  68.  
  69.   BLOCK_INPUT;
  70.   if (XQueryPointer (x_current_display, XtWindow (s->display.x->edit_widget),
  71.                  &root_window, &w, &root_x, &root_y, &ix, &iy,
  72.                  &keys_and_buttons) == False)
  73.     {
  74.       UNBLOCK_INPUT;
  75.       error ("Pointer not on same screen as window.");
  76.     }
  77.   UNBLOCK_INPUT;
  78.  
  79. #ifdef LINE_INFO_COLUMN
  80.   *x = (ix - (ibw + licw)) / FONT_WIDTH (SCREEN_NORMAL_FACE (s).font);
  81. #else
  82.   *x = (ix - ibw) / FONT_WIDTH (SCREEN_NORMAL_FACE (s).font);
  83. #endif
  84.   *y = (iy - ibw) / (s->display.x->text_height + x_interline_space);
  85. }
  86.