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