*** empty log message ***
[bpt/emacs.git] / src / xterm.h
1 /* Definitions and headers for communication with X protocol.
2 Copyright (C) 1989 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 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 #ifdef HAVE_X11
21 #include <X11/Xlib.h>
22 #include <X11/cursorfont.h>
23 #include <X11/Xutil.h>
24 #include <X11/keysym.h>
25 #include <X11/Xatom.h>
26 #include <X11/Xresource.h>
27 #else
28 #include <X/Xlib.h>
29 #endif /* HAVE_X11 */
30
31 /* Define a queue for X-events. One such queue is used for mouse clicks.
32 Another is used for expose events. */
33
34 #define EVENT_BUFFER_SIZE 64
35
36 #define RES_CLASS "emacs"
37
38 /* Max and Min sizes in character columns. */
39 #define MINWIDTH 10
40 #define MINHEIGHT 10
41 #define MAXWIDTH 300
42 #define MAXHEIGHT 80
43
44 #ifdef HAVE_X11
45 #define PIX_TYPE unsigned long
46 #define XDISPLAY x_current_display,
47 #define XFlushQueue() XFlush(x_current_display)
48 #define BLACK_PIX_DEFAULT BlackPixel (x_current_display, \
49 XDefaultScreen (x_current_display))
50 #define WHITE_PIX_DEFAULT WhitePixel (x_current_display, \
51 XDefaultScreen (x_current_display))
52 #define DISPLAY_SCREEN_ARG x_current_display, \
53 XDefaultScreen (x_current_display)
54 #define DISPLAY_CELLS DisplayCells (x_current_display, XDefaultScreen (x_current_display))
55 #define ROOT_WINDOW RootWindow (x_current_display, XDefaultScreen (x_current_display))
56 #define FONT_TYPE XFontStruct
57 #define Color XColor
58
59 #define XExposeRegionEvent XExposeEvent
60 #define Bitmap Pixmap /* In X11, Bitmaps are are kind of
61 Pixmap. */
62 #define WINDOWINFO_TYPE XWindowAttributes
63 #define XGetWindowInfo(w, i) XGetWindowAttributes (x_current_display, \
64 (w), (i))
65 #define XGetFont(f) XLoadQueryFont (x_current_display, (f))
66 #define XLoseFont(f) XFreeFont (x_current_display, (f))
67 #define XStuffPending() XPending (x_current_display)
68 #define XClear(w) XClearWindow (x_current_display, (w))
69 #define XWarpMousePointer(w,x,y) XWarpPointer (x_current_display, None, w, \
70 0,0,0,0, x, y)
71 #define XHandleError XSetErrorHandler
72 #define XHandleIOError XSetIOErrorHandler
73
74 #define XChangeWindowSize(w,x,y) XResizeWindow(x_current_display,w,x,y)
75
76 #define FONT_WIDTH(f) ((f)->max_bounds.width)
77 #define FONT_HEIGHT(f) ((f)->ascent + (f)->descent)
78 #define FONT_BASE(f) ((f)->ascent)
79
80 /* GC values used for drawing non-standard (other face) text. */
81 extern XGCValues face_gc_values;
82
83 /* The mask of events that text windows always want to receive. This
84 does not include mouse movement events. It is used when the window
85 is created (in x_window) and when we ask/unask for mouse movement
86 events (in XTmouse_tracking_enable).
87
88 We do include ButtonReleases in this set because elisp isn't always
89 fast enough to catch them when it wants them, and they're rare
90 enough that they don't use much processor time. */
91
92 #define STANDARD_EVENT_SET \
93 (KeyPressMask \
94 | ExposureMask \
95 | ButtonPressMask \
96 | ButtonReleaseMask \
97 | PointerMotionMask \
98 | PointerMotionHintMask \
99 | StructureNotifyMask \
100 | FocusChangeMask \
101 | LeaveWindowMask \
102 | EnterWindowMask \
103 | VisibilityChangeMask)
104
105 #else /* X10 */
106
107 #define ConnectionNumber(dpy) dpyno()
108 #define PIX_TYPE int
109 #define XDISPLAY
110 #define XFlushQueue() XFlush()
111 #define BLACK_PIX_DEFAULT BlackPixel
112 #define WHITE_PIX_DEFAULT WhitePixel
113 #define DISPLAY_SCREEN_ARG
114 #define DISPLAY_CELLS DisplayCells ()
115 #define ROOT_WINDOW RootWindow
116 #define XFree free
117 #define FONT_TYPE FontInfo
118
119 #define WINDOWINFO_TYPE WindowInfo
120 #define XGetWindowInfo(w, i) XQueryWindow ((w), (i))
121 #define XGetFont(f) XOpenFont ((f))
122 #define XLoseFont(f) XCloseFont ((f))
123 #define XStuffPending() XPending ()
124 #define XWarpMousePointer(w,x,y) XWarpMouse (w,x,y)
125 #define XHandleError XErrorHandler
126 #define XHandleIOError XIOErrorHandler
127
128 #define FONT_WIDTH(f) ((f)->width)
129 #define FONT_HEIGHT(f) ((f)->height)
130 #define FONT_BASE(f) ((f)->base)
131
132 #define XChangeWindowSize(w,x,y) XChangeWindow(w,x,y)
133
134 #endif /* X10 */
135
136 struct event_queue
137 {
138 int rindex; /* Index at which to fetch next. */
139 int windex; /* Index at which to store next. */
140 XEvent xrep[EVENT_BUFFER_SIZE];
141 };
142
143 /* Queue for mouse clicks. */
144 extern struct event_queue x_mouse_queue;
145
146 /* Mechanism for interlocking between main program level
147 and input interrupt level. */
148
149 /* Nonzero during a critical section. At such a time, an input interrupt
150 does nothing but set `x_pending_input'. */
151 extern int x_input_blocked;
152
153 /* Nonzero means an input interrupt has arrived
154 during the current critical section. */
155 extern int x_pending_input;
156
157 /* Begin critical section. */
158 #define BLOCK_INPUT (x_input_blocked++)
159
160 /* End critical section. */
161 #define UNBLOCK_INPUT \
162 (x_input_blocked--, (x_input_blocked < 0 ? (abort (), 0) : 0))
163
164 #define TOTALLY_UNBLOCK_INPUT (x_input_blocked = 0)
165 #define UNBLOCK_INPUT_RESIGNAL UNBLOCK_INPUT
166
167 /* This is the X connection that we are using. */
168
169 extern Display *x_current_display;
170
171 extern struct screen *x_window_to_screen ();
172
173 /* The screen (if any) which has the X window that has keyboard focus.
174 Zero if none. This is examined by Ffocus_screen in xfns.c */
175
176 struct screen *x_focus_screen;
177
178 #ifdef HAVE_X11
179 /* Variables associated with the X display screen this emacs is using. */
180
181 /* How many screens this X display has. */
182 extern Lisp_Object x_screen_count;
183
184 /* The vendor supporting this X server. */
185 extern Lisp_Object Vx_vendor;
186
187 /* The vendor's release number for this X server. */
188 extern Lisp_Object x_release;
189
190 /* Height of this X screen in pixels. */
191 extern Lisp_Object x_screen_height;
192
193 /* Height of this X screen in millimeters. */
194 extern Lisp_Object x_screen_height_mm;
195
196 /* Width of this X screen in pixels. */
197 extern Lisp_Object x_screen_width;
198
199 /* Width of this X screen in millimeters. */
200 extern Lisp_Object x_screen_width_mm;
201
202 /* Does this X screen do backing store? */
203 extern Lisp_Object Vx_backing_store;
204
205 /* Does this X screen do save-unders? */
206 extern Lisp_Object x_save_under;
207
208 /* Number of planes for this screen. */
209 extern Lisp_Object x_screen_planes;
210
211 /* X Visual type of this screen. */
212 extern Lisp_Object Vx_screen_visual;
213
214 #endif /* HAVE_X11 */
215 \f
216 enum text_cursor_kinds {
217 filled_box_cursor, hollow_box_cursor, bar_cursor
218 };
219
220 #define PIXEL_WIDTH(s) ((s)->display.x->pixel_width)
221 #define PIXEL_HEIGHT(s) ((s)->display.x->pixel_height)
222
223 /* Each X screen object points to its own struct x_display object
224 in the display.x field. The x_display structure contains all
225 the information that is specific to X windows. */
226
227 struct x_display
228 {
229 /* Position of the X window (x and y offsets in root window). */
230 int left_pos;
231 int top_pos;
232
233 /* Border width of the X window as known by the X window system. */
234 int border_width;
235
236 /* Size of the X window in pixels. */
237 int pixel_height, pixel_width;
238
239 #ifdef HAVE_X11
240 /* The tiled border used when the mouse is out of the screen. */
241 Pixmap border_tile;
242
243 /* Here are the Graphics Contexts for the default font. */
244 GC normal_gc; /* Normal video */
245 GC reverse_gc; /* Reverse video */
246 GC cursor_gc; /* cursor drawing */
247 #endif /* HAVE_X11 */
248
249 /* Width of the internal border. This is a line of background color
250 just inside the window's border. When the screen is selected,
251 a highlighting is displayed inside the internal border. */
252 int internal_border_width;
253
254 /* The X window used for this screen.
255 May be zero while the screen object is being created
256 and the X window has not yet been created. */
257 Window window_desc;
258
259 /* The X window used for the bitmap icon;
260 or 0 if we don't have a bitmap icon. */
261 Window icon_desc;
262
263 /* The X window that is the parent of this X window.
264 Usually but not always RootWindow. */
265 Window parent_desc;
266
267 /* 1 for bitmap icon, 0 for text icon. */
268 int icon_bitmap_flag;
269
270 FONT_TYPE *font;
271
272 /* Pixel values used for various purposes.
273 border_pixel may be -1 meaning use a gray tile. */
274 PIX_TYPE background_pixel;
275 PIX_TYPE foreground_pixel;
276 PIX_TYPE cursor_pixel;
277 PIX_TYPE border_pixel;
278 PIX_TYPE mouse_pixel;
279
280 /* Windows for scrollbars */
281 Window v_scrollbar;
282 Window v_thumbup;
283 Window v_thumbdown;
284 Window v_slider;
285
286 Window h_scrollbar;
287 Window h_thumbleft;
288 Window h_thumbright;
289 Window h_slider;
290
291 /* Scrollbar info */
292
293 int v_scrollbar_width;
294 int h_scrollbar_height;
295
296 /* Descriptor for the cursor in use for this window. */
297 #ifdef HAVE_X11
298 Cursor text_cursor;
299 Cursor nontext_cursor;
300 Cursor modeline_cursor;
301 #else
302 Cursor cursor;
303 #endif
304
305 /* The name that was associated with the icon, the last time
306 it was refreshed. Usually the same as the name of the
307 buffer in the currently selected window in the screen */
308 char *icon_label;
309
310 /* Flag to set when the X window needs to be completely repainted. */
311 int needs_exposure;
312
313 /* What kind of text cursor is drawn in this window right now? (If
314 there is no cursor (phys_cursor_x < 0), then this means nothing. */
315 enum text_cursor_kinds text_cursor_kind;
316 };
317 \f
318 /* When X windows are used, a glyf may be a 16 bit unsigned datum.
319 The high order byte is the face number and is used as an index
320 in the face table. A face is a font plus:
321 1) the unhighlighted foreground color,
322 2) the unhighlighted background color.
323 For highlighting, the two colors are exchanged.
324 Face number 0 is unused. The low order byte of a glyf gives
325 the character within the font. All fonts are assumed to be
326 fixed width, and to have the same height and width. */
327
328 #ifdef HAVE_X11
329 /* Table of GC's used for this screen. */
330 GC *gc_table;
331
332 /* How many GCs are in the table. */
333 int gcs_in_use;
334
335 struct face
336 {
337 GC face_gc;
338 unsigned int foreground;
339 unsigned int background;
340 Pixmap stipple;
341 XFontStruct *font;
342 };
343
344 #else /* X10 */
345
346 struct face
347 {
348 FONT_TYPE *font; /* Font info for specified font. */
349 int fg; /* Unhighlighted foreground. */
350 int bg; /* Unhighlighted background. */
351 };
352 #endif /* X10 */
353
354 #define MAX_FACES_AND_GLYPHS 256
355 extern struct face *x_face_table[];