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 #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
|
424
|
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. */
|
259
|
91
|
|
92 #define STANDARD_EVENT_SET \
|
|
93 (KeyPressMask \
|
|
94 | ExposureMask \
|
|
95 | ButtonPressMask \
|
424
|
96 | ButtonReleaseMask \
|
|
97 | PointerMotionMask \
|
|
98 | PointerMotionHintMask \
|
259
|
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 (x_input_blocked--, (x_input_blocked < 0 ? abort () : 0))
|
|
162
|
|
163 #define TOTALLY_UNBLOCK_INPUT (x_input_blocked = 0)
|
|
164 #define UNBLOCK_INPUT_RESIGNAL UNBLOCK_INPUT
|
|
165
|
|
166 /* This is the X connection that we are using. */
|
|
167
|
|
168 extern Display *x_current_display;
|
|
169
|
|
170 extern struct screen *x_window_to_screen ();
|
|
171
|
|
172 /* The screen (if any) which has the X window that has keyboard focus.
|
|
173 Zero if none. This is examined by Ffocus_screen in xfns.c */
|
|
174
|
|
175 struct screen *x_focus_screen;
|
|
176
|
|
177 #ifdef HAVE_X11
|
|
178 /* Variables associated with the X display screen this emacs is using. */
|
|
179
|
|
180 /* How many screens this X display has. */
|
|
181 extern Lisp_Object x_screen_count;
|
|
182
|
|
183 /* The vendor supporting this X server. */
|
|
184 extern Lisp_Object Vx_vendor;
|
|
185
|
|
186 /* The vendor's release number for this X server. */
|
|
187 extern Lisp_Object x_release;
|
|
188
|
|
189 /* Height of this X screen in pixels. */
|
|
190 extern Lisp_Object x_screen_height;
|
|
191
|
|
192 /* Height of this X screen in millimeters. */
|
|
193 extern Lisp_Object x_screen_height_mm;
|
|
194
|
|
195 /* Width of this X screen in pixels. */
|
|
196 extern Lisp_Object x_screen_width;
|
|
197
|
|
198 /* Width of this X screen in millimeters. */
|
|
199 extern Lisp_Object x_screen_width_mm;
|
|
200
|
|
201 /* Does this X screen do backing store? */
|
|
202 extern Lisp_Object Vx_backing_store;
|
|
203
|
|
204 /* Does this X screen do save-unders? */
|
|
205 extern Lisp_Object x_save_under;
|
|
206
|
|
207 /* Number of planes for this screen. */
|
|
208 extern Lisp_Object x_screen_planes;
|
|
209
|
|
210 /* X Visual type of this screen. */
|
|
211 extern Lisp_Object Vx_screen_visual;
|
|
212
|
|
213 #endif /* HAVE_X11 */
|
|
214
|
|
215 enum text_cursor_kinds {
|
|
216 filled_box_cursor, hollow_box_cursor, bar_cursor
|
|
217 };
|
|
218
|
|
219 #define PIXEL_WIDTH(s) ((s)->display.x->pixel_width)
|
|
220 #define PIXEL_HEIGHT(s) ((s)->display.x->pixel_height)
|
|
221
|
|
222 /* Each X screen object points to its own struct x_display object
|
|
223 in the display.x field. The x_display structure contains all
|
|
224 the information that is specific to X windows. */
|
|
225
|
|
226 struct x_display
|
|
227 {
|
|
228 /* Position of the X window (x and y offsets in root window). */
|
|
229 int left_pos;
|
|
230 int top_pos;
|
|
231
|
|
232 /* Border width of the X window as known by the X window system. */
|
|
233 int border_width;
|
|
234
|
|
235 /* Size of the X window in pixels. */
|
|
236 int pixel_height, pixel_width;
|
|
237
|
|
238 #ifdef HAVE_X11
|
|
239 /* The tiled border used when the mouse is out of the screen. */
|
|
240 Pixmap border_tile;
|
|
241
|
|
242 /* Here are the Graphics Contexts for the default font. */
|
|
243 GC normal_gc; /* Normal video */
|
|
244 GC reverse_gc; /* Reverse video */
|
|
245 GC cursor_gc; /* cursor drawing */
|
|
246 #endif /* HAVE_X11 */
|
|
247
|
|
248 /* Width of the internal border. This is a line of background color
|
|
249 just inside the window's border. When the screen is selected,
|
|
250 a highlighting is displayed inside the internal border. */
|
|
251 int internal_border_width;
|
|
252
|
|
253 /* The X window used for this screen.
|
|
254 May be zero while the screen object is being created
|
|
255 and the X window has not yet been created. */
|
|
256 Window window_desc;
|
|
257
|
|
258 /* The X window used for the bitmap icon;
|
|
259 or 0 if we don't have a bitmap icon. */
|
|
260 Window icon_desc;
|
|
261
|
|
262 /* The X window that is the parent of this X window.
|
|
263 Usually but not always RootWindow. */
|
|
264 Window parent_desc;
|
|
265
|
|
266 /* 1 for bitmap icon, 0 for text icon. */
|
|
267 int icon_bitmap_flag;
|
|
268
|
|
269 FONT_TYPE *font;
|
|
270
|
|
271 /* Pixel values used for various purposes.
|
|
272 border_pixel may be -1 meaning use a gray tile. */
|
|
273 PIX_TYPE background_pixel;
|
|
274 PIX_TYPE foreground_pixel;
|
|
275 PIX_TYPE cursor_pixel;
|
|
276 PIX_TYPE border_pixel;
|
|
277 PIX_TYPE mouse_pixel;
|
|
278
|
|
279 /* Windows for scrollbars */
|
|
280 Window v_scrollbar;
|
|
281 Window v_thumbup;
|
|
282 Window v_thumbdown;
|
|
283 Window v_slider;
|
|
284
|
|
285 Window h_scrollbar;
|
|
286 Window h_thumbleft;
|
|
287 Window h_thumbright;
|
|
288 Window h_slider;
|
|
289
|
|
290 /* Scrollbar info */
|
|
291
|
|
292 int v_scrollbar_width;
|
|
293 int h_scrollbar_height;
|
|
294
|
|
295 /* Descriptor for the cursor in use for this window. */
|
|
296 #ifdef HAVE_X11
|
|
297 Cursor text_cursor;
|
|
298 Cursor nontext_cursor;
|
|
299 Cursor modeline_cursor;
|
|
300 #else
|
|
301 Cursor cursor;
|
|
302 #endif
|
|
303
|
|
304 /* The name that was associated with the icon, the last time
|
|
305 it was refreshed. Usually the same as the name of the
|
|
306 buffer in the currently selected window in the screen */
|
|
307 char *icon_label;
|
|
308
|
|
309 /* Flag to set when the X window needs to be completely repainted. */
|
|
310 int needs_exposure;
|
|
311
|
|
312 /* What kind of text cursor is drawn in this window right now? (If
|
|
313 there is no cursor (phys_cursor_x < 0), then this means nothing. */
|
|
314 enum text_cursor_kinds text_cursor_kind;
|
|
315 };
|
|
316
|
|
317 /* When X windows are used, a glyf may be a 16 bit unsigned datum.
|
|
318 The high order byte is the face number and is used as an index
|
|
319 in the face table. A face is a font plus:
|
|
320 1) the unhighlighted foreground color,
|
|
321 2) the unhighlighted background color.
|
|
322 For highlighting, the two colors are exchanged.
|
|
323 Face number 0 is unused. The low order byte of a glyf gives
|
|
324 the character within the font. All fonts are assumed to be
|
|
325 fixed width, and to have the same height and width. */
|
|
326
|
|
327 #ifdef HAVE_X11
|
|
328 /* Table of GC's used for this screen. */
|
|
329 GC *gc_table;
|
|
330
|
|
331 /* How many GCs are in the table. */
|
|
332 int gcs_in_use;
|
|
333
|
|
334 struct face
|
|
335 {
|
|
336 GC face_gc;
|
|
337 unsigned int foreground;
|
|
338 unsigned int background;
|
|
339 Pixmap stipple;
|
|
340 XFontStruct *font;
|
|
341 };
|
|
342
|
|
343 #else /* X10 */
|
|
344
|
|
345 struct face
|
|
346 {
|
|
347 FONT_TYPE *font; /* Font info for specified font. */
|
|
348 int fg; /* Unhighlighted foreground. */
|
|
349 int bg; /* Unhighlighted background. */
|
|
350 };
|
|
351 #endif /* X10 */
|
|
352
|
|
353 #define MAX_FACES_AND_GLYPHS 256
|
|
354 extern struct face *x_face_table[];
|