Commit | Line | Data |
---|---|---|
3f930d20 | 1 | /* Definitions and headers for communication with X protocol. |
3a22ee35 | 2 | Copyright (C) 1989, 1993, 1994 Free Software Foundation, Inc. |
3f930d20 JB |
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 | |
4e027793 | 8 | the Free Software Foundation; either version 2, or (at your option) |
3f930d20 JB |
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 | |
3b7ad313 EN |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. */ | |
3f930d20 | 20 | |
3f930d20 JB |
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> | |
3f930d20 | 27 | |
0be31d57 RS |
28 | #ifdef USE_X_TOOLKIT |
29 | #include <X11/StringDefs.h> | |
30 | #include <X11/IntrinsicP.h> /* CoreP.h needs this */ | |
31 | #include <X11/CoreP.h> /* foul, but we need this to use our own | |
32 | window inside a widget instead of one | |
33 | that Xt creates... */ | |
34 | #include <X11/StringDefs.h> | |
0be31d57 RS |
35 | #endif |
36 | ||
579dd4be RS |
37 | /* The class of this X application. */ |
38 | #define EMACS_CLASS "Emacs" | |
39 | \f | |
40 | /* Bookkeeping to distinguish X versions. */ | |
ef15f270 | 41 | |
d2729198 JB |
42 | /* HAVE_X11R4 is defined if we have the features of X11R4. It should |
43 | be defined when we're using X11R5, since X11R5 has the features of | |
44 | X11R4. If, in the future, we find we need more of these flags | |
45 | (HAVE_X11R5, for example), code should always be written to test | |
46 | the most recent flag first: | |
47 | ||
48 | #ifdef HAVE_X11R5 | |
49 | ... | |
50 | #elif HAVE_X11R4 | |
51 | ... | |
52 | #elif HAVE_X11 | |
53 | ... | |
54 | #endif | |
55 | ||
56 | If you ever find yourself writing a "#ifdef HAVE_FOO" clause that | |
57 | looks a lot like another one, consider moving the text into a macro | |
58 | whose definition is configuration-dependent, but whose usage is | |
59 | universal - like the stuff in systime.h. | |
60 | ||
61 | It turns out that we can auto-detect whether we're being compiled | |
ef15f270 JB |
62 | with X11R3 or X11R4 by looking for the flag macros for R4 structure |
63 | members that R3 doesn't have. */ | |
64 | #ifdef PBaseSize | |
3fe53836 RS |
65 | /* AIX 3.1's X is somewhere between X11R3 and X11R4. It has |
66 | PBaseSize, but not XWithdrawWindow, XSetWMName, XSetWMNormalHints, | |
48508a3a FP |
67 | XSetWMIconName. |
68 | AIX 3.2 is at least X11R4. */ | |
69 | #if (!defined AIX) || (defined AIX3_2) | |
ef15f270 JB |
70 | #define HAVE_X11R4 |
71 | #endif | |
3fe53836 | 72 | #endif |
ef15f270 | 73 | |
6bde6341 JB |
74 | #ifdef XlibSpecificationRelease |
75 | #if XlibSpecificationRelease >= 5 | |
76 | #define HAVE_X11R5 | |
673fea7a RS |
77 | /* In case someone has X11R5 on AIX 3.1, |
78 | make sure HAVE_X11R4 is defined as well as HAVE_X11R5. */ | |
79 | #define HAVE_X11R4 | |
6bde6341 JB |
80 | #endif |
81 | #endif | |
cfc57cea RS |
82 | |
83 | #ifdef HAVE_X11R5 | |
84 | #define HAVE_X_I18N | |
85 | #include <X11/Xlocale.h> | |
86 | #endif | |
579dd4be RS |
87 | \f |
88 | #define BLACK_PIX_DEFAULT(f) BlackPixel (FRAME_X_DISPLAY (f), \ | |
89 | XScreenNumberOfScreen (FRAME_X_SCREEN (f))) | |
90 | #define WHITE_PIX_DEFAULT(f) WhitePixel (FRAME_X_DISPLAY (f), \ | |
91 | XScreenNumberOfScreen (FRAME_X_SCREEN (f))) | |
3f930d20 JB |
92 | |
93 | #define FONT_WIDTH(f) ((f)->max_bounds.width) | |
94 | #define FONT_HEIGHT(f) ((f)->ascent + (f)->descent) | |
95 | #define FONT_BASE(f) ((f)->ascent) | |
96 | ||
3f930d20 | 97 | /* The mask of events that text windows always want to receive. This |
d2f764d0 RS |
98 | includes mouse movement events, since handling the mouse-font text property |
99 | means that we must track mouse motion all the time. */ | |
3f930d20 JB |
100 | |
101 | #define STANDARD_EVENT_SET \ | |
102 | (KeyPressMask \ | |
103 | | ExposureMask \ | |
104 | | ButtonPressMask \ | |
8828b393 JB |
105 | | ButtonReleaseMask \ |
106 | | PointerMotionMask \ | |
3f930d20 JB |
107 | | StructureNotifyMask \ |
108 | | FocusChangeMask \ | |
109 | | LeaveWindowMask \ | |
110 | | EnterWindowMask \ | |
111 | | VisibilityChangeMask) | |
112 | ||
3868b9ec KH |
113 | /* This checks to make sure we have a display. */ |
114 | extern void check_x (); | |
115 | ||
f676886a | 116 | extern struct frame *x_window_to_frame (); |
3f930d20 | 117 | |
0be31d57 RS |
118 | #ifdef USE_X_TOOLKIT |
119 | extern struct frame *x_any_window_to_frame (); | |
72de3c00 | 120 | extern struct frame *x_non_menubar_window_to_frame (); |
090cebb5 | 121 | extern struct frame *x_top_window_to_frame (); |
0be31d57 RS |
122 | #endif |
123 | ||
579dd4be | 124 | extern Visual *select_visual (); |
b242af88 | 125 | |
3f930d20 JB |
126 | enum text_cursor_kinds { |
127 | filled_box_cursor, hollow_box_cursor, bar_cursor | |
128 | }; | |
e964ed22 RS |
129 | |
130 | /* This data type is used for the font_table field | |
131 | of struct x_display_info. */ | |
132 | ||
133 | struct font_info | |
134 | { | |
135 | XFontStruct *font; | |
136 | char *name; | |
137 | char *full_name; | |
138 | }; | |
139 | ||
140 | /* Structure recording X pixmap and reference count. | |
141 | If REFCOUNT is 0 then this record is free to be reused. */ | |
142 | ||
143 | struct x_bitmap_record | |
144 | { | |
145 | Pixmap pixmap; | |
146 | char *file; | |
147 | int refcount; | |
148 | /* Record some info about this pixmap. */ | |
149 | int height, width, depth; | |
150 | }; | |
b242af88 RS |
151 | \f |
152 | /* For each X display, we have a structure that records | |
153 | information about it. */ | |
3f930d20 | 154 | |
579dd4be | 155 | struct x_display_info |
b242af88 | 156 | { |
e964ed22 | 157 | /* Chain of all x_display_info structures. */ |
579dd4be RS |
158 | struct x_display_info *next; |
159 | /* Connection number (normally a file descriptor number). */ | |
160 | int connection; | |
b242af88 | 161 | /* This says how to access this display in Xlib. */ |
579dd4be | 162 | Display *display; |
e964ed22 RS |
163 | /* This is a cons cell of the form (NAME . FONT-LIST-CACHE). |
164 | The same cons cell also appears in x_display_name_list. */ | |
165 | Lisp_Object name_list_element; | |
b242af88 RS |
166 | /* Number of frames that are on this display. */ |
167 | int reference_count; | |
579dd4be RS |
168 | /* The Screen this connection is connected to. */ |
169 | Screen *screen; | |
170 | /* The Visual being used for this display. */ | |
171 | Visual *visual; | |
172 | /* Number of panes on this screen. */ | |
173 | int n_planes; | |
174 | /* Dimensions of this screen. */ | |
175 | int height, width; | |
176 | /* Mask of things that cause the mouse to be grabbed. */ | |
177 | int grabbed; | |
178 | /* Emacs bitmap-id of the default icon bitmap for this frame. | |
179 | Or -1 if none has been allocated yet. */ | |
180 | int icon_bitmap_id; | |
181 | /* The root window of this screen. */ | |
182 | Window root_window; | |
e964ed22 RS |
183 | /* The cursor to use for vertical scroll bars. */ |
184 | Cursor vertical_scroll_bar_cursor; | |
579dd4be RS |
185 | /* X Resource data base */ |
186 | XrmDatabase xrdb; | |
187 | ||
e964ed22 RS |
188 | /* A table of all the fonts we have already loaded. */ |
189 | struct font_info *font_table; | |
190 | ||
191 | /* The current capacity of x_font_table. */ | |
192 | int font_table_size; | |
193 | ||
194 | /* Reusable Graphics Context for drawing a cursor in a non-default face. */ | |
195 | GC scratch_cursor_gc; | |
196 | ||
197 | /* These variables describe the range of text currently shown | |
198 | in its mouse-face, together with the window they apply to. | |
199 | As long as the mouse stays within this range, we need not | |
200 | redraw anything on its account. */ | |
201 | int mouse_face_beg_row, mouse_face_beg_col; | |
202 | int mouse_face_end_row, mouse_face_end_col; | |
203 | int mouse_face_past_end; | |
204 | Lisp_Object mouse_face_window; | |
205 | int mouse_face_face_id; | |
206 | ||
207 | /* 1 if a mouse motion event came and we didn't handle it right away because | |
208 | gc was in progress. */ | |
209 | int mouse_face_deferred_gc; | |
210 | ||
211 | /* FRAME and X, Y position of mouse when last checked for | |
212 | highlighting. X and Y can be negative or out of range for the frame. */ | |
213 | struct frame *mouse_face_mouse_frame; | |
214 | int mouse_face_mouse_x, mouse_face_mouse_y; | |
215 | ||
216 | /* Nonzero means defer mouse-motion highlighting. */ | |
217 | int mouse_face_defer; | |
218 | ||
219 | char *x_id_name; | |
220 | ||
221 | /* The number of fonts actually stored in x_font_table. | |
222 | font_table[n] is used and valid iff 0 <= n < n_fonts. | |
223 | 0 <= n_fonts <= font_table_size. */ | |
224 | int n_fonts; | |
225 | ||
226 | /* Pointer to bitmap records. */ | |
227 | struct x_bitmap_record *bitmaps; | |
228 | ||
229 | /* Allocated size of bitmaps field. */ | |
230 | int bitmaps_size; | |
231 | ||
232 | /* Last used bitmap index. */ | |
233 | int bitmaps_last; | |
234 | ||
579dd4be RS |
235 | /* Which modifier keys are on which modifier bits? |
236 | ||
237 | With each keystroke, X returns eight bits indicating which modifier | |
238 | keys were held down when the key was pressed. The interpretation | |
239 | of the top five modifier bits depends on what keys are attached | |
240 | to them. If the Meta_L and Meta_R keysyms are on mod5, then mod5 | |
241 | is the meta bit. | |
242 | ||
243 | meta_mod_mask is a mask containing the bits used for the meta key. | |
244 | It may have more than one bit set, if more than one modifier bit | |
245 | has meta keys on it. Basically, if EVENT is a KeyPress event, | |
246 | the meta key is pressed if (EVENT.state & meta_mod_mask) != 0. | |
247 | ||
248 | shift_lock_mask is LockMask if the XK_Shift_Lock keysym is on the | |
249 | lock modifier bit, or zero otherwise. Non-alphabetic keys should | |
250 | only be affected by the lock modifier bit if XK_Shift_Lock is in | |
251 | use; XK_Caps_Lock should only affect alphabetic keys. With this | |
252 | arrangement, the lock modifier should shift the character if | |
253 | (EVENT.state & shift_lock_mask) != 0. */ | |
254 | int meta_mod_mask, shift_lock_mask; | |
255 | ||
256 | /* These are like meta_mod_mask, but for different modifiers. */ | |
257 | int alt_mod_mask, super_mod_mask, hyper_mod_mask; | |
258 | ||
259 | /* Communication with window managers. */ | |
260 | Atom Xatom_wm_protocols; | |
261 | /* Kinds of protocol things we may receive. */ | |
262 | Atom Xatom_wm_take_focus; | |
263 | Atom Xatom_wm_save_yourself; | |
264 | Atom Xatom_wm_delete_window; | |
265 | /* Atom for indicating window state to the window manager. */ | |
266 | Atom Xatom_wm_change_state; | |
267 | /* Other WM communication */ | |
268 | Atom Xatom_wm_configure_denied; /* When our config request is denied */ | |
269 | Atom Xatom_wm_window_moved; /* When the WM moves us. */ | |
270 | /* EditRes protocol */ | |
271 | Atom Xatom_editres; | |
272 | ||
273 | /* More atoms, which are selection types. */ | |
274 | Atom Xatom_CLIPBOARD, Xatom_TIMESTAMP, Xatom_TEXT, Xatom_DELETE, | |
275 | Xatom_MULTIPLE, Xatom_INCR, Xatom_EMACS_TMP, Xatom_TARGETS, Xatom_NULL, | |
276 | Xatom_ATOM_PAIR; | |
6909e850 | 277 | #ifdef MULTI_KBOARD |
e47a168b | 278 | struct kboard *kboard; |
6909e850 | 279 | #endif |
256d5bf6 | 280 | int cut_buffers_initialized; /* Whether we're sure they all exist */ |
2820e308 KH |
281 | |
282 | /* The frame (if any) which has the X window that has keyboard focus. | |
283 | Zero if none. This is examined by Ffocus_frame in xfns.c. Note | |
284 | that a mere EnterNotify event can set this; if you need to know the | |
285 | last frame specified in a FocusIn or FocusOut event, use | |
286 | x_focus_event_frame. */ | |
287 | struct frame *x_focus_frame; | |
288 | ||
289 | /* The last frame mentioned in a FocusIn or FocusOut event. This is | |
290 | separate from x_focus_frame, because whether or not LeaveNotify | |
291 | events cause us to lose focus depends on whether or not we have | |
292 | received a FocusIn event for it. */ | |
293 | struct frame *x_focus_event_frame; | |
294 | ||
295 | /* The frame which currently has the visual highlight, and should get | |
296 | keyboard input (other sorts of input have the frame encoded in the | |
297 | event). It points to the X focus frame's selected window's | |
298 | frame. It differs from x_focus_frame when we're using a global | |
299 | minibuffer. */ | |
300 | struct frame *x_highlight_frame; | |
b242af88 | 301 | }; |
579dd4be RS |
302 | |
303 | /* This is a chain of structures for all the X displays currently in use. */ | |
304 | extern struct x_display_info *x_display_list; | |
305 | ||
e964ed22 RS |
306 | /* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE), |
307 | one for each element of x_display_list and in the same order. | |
308 | NAME is the name of the frame. | |
309 | FONT-LIST-CACHE records previous values returned by x-list-fonts. */ | |
310 | extern Lisp_Object x_display_name_list; | |
311 | ||
579dd4be RS |
312 | extern struct x_display_info *x_display_info_for_display (); |
313 | extern struct x_display_info *x_display_info_for_name (); | |
314 | ||
315 | extern struct x_display_info *x_term_init (); | |
b242af88 | 316 | \f |
f39d1692 RS |
317 | /* Each X frame object points to its own struct x_output object |
318 | in the output_data.x field. The x_output structure contains | |
3f930d20 JB |
319 | the information that is specific to X windows. */ |
320 | ||
f39d1692 | 321 | struct x_output |
3f930d20 JB |
322 | { |
323 | /* Position of the X window (x and y offsets in root window). */ | |
324 | int left_pos; | |
325 | int top_pos; | |
326 | ||
327 | /* Border width of the X window as known by the X window system. */ | |
328 | int border_width; | |
329 | ||
f3942238 | 330 | /* Size of the X window in pixels. */ |
3f930d20 JB |
331 | int pixel_height, pixel_width; |
332 | ||
ab6c5d93 KH |
333 | /* Height of menu bar widget, in pixels. |
334 | Zero if not using the X toolkit. | |
335 | When using the toolkit, this value is not meaningful | |
336 | if the menubar is turned off. */ | |
337 | int menubar_height; | |
338 | ||
2ba6876c RS |
339 | /* Height of a line, in pixels. */ |
340 | int line_height; | |
341 | ||
f3942238 | 342 | /* The tiled border used when the mouse is out of the frame. */ |
3f930d20 JB |
343 | Pixmap border_tile; |
344 | ||
f3942238 | 345 | /* Here are the Graphics Contexts for the default font. */ |
3f930d20 JB |
346 | GC normal_gc; /* Normal video */ |
347 | GC reverse_gc; /* Reverse video */ | |
348 | GC cursor_gc; /* cursor drawing */ | |
3f930d20 JB |
349 | |
350 | /* Width of the internal border. This is a line of background color | |
f676886a | 351 | just inside the window's border. When the frame is selected, |
3f930d20 JB |
352 | a highlighting is displayed inside the internal border. */ |
353 | int internal_border_width; | |
354 | ||
f676886a JB |
355 | /* The X window used for this frame. |
356 | May be zero while the frame object is being created | |
3f930d20 JB |
357 | and the X window has not yet been created. */ |
358 | Window window_desc; | |
359 | ||
360 | /* The X window used for the bitmap icon; | |
361 | or 0 if we don't have a bitmap icon. */ | |
362 | Window icon_desc; | |
363 | ||
364 | /* The X window that is the parent of this X window. | |
dcc98b56 RS |
365 | Usually this is a window that was made by the window manager, |
366 | but it can be the root window, and it can be explicitly specified | |
367 | (see the explicit_parent field, below). */ | |
3f930d20 JB |
368 | Window parent_desc; |
369 | ||
0be31d57 RS |
370 | #ifdef USE_X_TOOLKIT |
371 | /* The widget of this screen. This is the window of a "shell" widget. */ | |
372 | Widget widget; | |
373 | /* The XmPanedWindows... */ | |
374 | Widget column_widget; | |
375 | /* The widget of the edit portion of this screen; the window in | |
376 | "window_desc" is inside of this. */ | |
377 | Widget edit_widget; | |
378 | ||
379 | Widget menubar_widget; | |
380 | #endif | |
381 | ||
78c3981d RS |
382 | /* If >=0, a bitmap index. The indicated bitmap is used for the |
383 | icon. */ | |
384 | int icon_bitmap; | |
3f930d20 | 385 | |
579dd4be | 386 | XFontStruct *font; |
3f930d20 JB |
387 | |
388 | /* Pixel values used for various purposes. | |
389 | border_pixel may be -1 meaning use a gray tile. */ | |
579dd4be RS |
390 | unsigned long background_pixel; |
391 | unsigned long foreground_pixel; | |
392 | unsigned long cursor_pixel; | |
393 | unsigned long border_pixel; | |
394 | unsigned long mouse_pixel; | |
395 | unsigned long cursor_foreground_pixel; | |
3f930d20 | 396 | |
3f930d20 | 397 | /* Descriptor for the cursor in use for this window. */ |
3f930d20 JB |
398 | Cursor text_cursor; |
399 | Cursor nontext_cursor; | |
400 | Cursor modeline_cursor; | |
6bfbdaeb | 401 | Cursor cross_cursor; |
3f930d20 | 402 | |
f3942238 | 403 | /* Flag to set when the X window needs to be completely repainted. */ |
3f930d20 JB |
404 | int needs_exposure; |
405 | ||
dbc4e1c1 JB |
406 | /* What kind of text cursor is drawn in this window right now? |
407 | (If there is no cursor (phys_cursor_x < 0), then this means nothing.) */ | |
408 | enum text_cursor_kinds current_cursor; | |
409 | ||
410 | /* What kind of text cursor should we draw in the future? | |
411 | This should always be filled_box_cursor or bar_cursor. */ | |
412 | enum text_cursor_kinds desired_cursor; | |
ef15f270 | 413 | |
e36a2711 RS |
414 | /* Width of bar cursor (if we are using that). */ |
415 | int cursor_width; | |
416 | ||
ef15f270 JB |
417 | /* These are the current window manager hints. It seems that |
418 | XSetWMHints, when presented with an unset bit in the `flags' | |
419 | member of the hints structure, does not leave the corresponding | |
420 | attribute unchanged; rather, it resets that attribute to its | |
421 | default value. For example, unless you set the `icon_pixmap' | |
422 | field and the `IconPixmapHint' bit, XSetWMHints will forget what | |
423 | your icon pixmap was. This is rather troublesome, since some of | |
424 | the members (for example, `input' and `icon_pixmap') want to stay | |
425 | the same throughout the execution of Emacs. So, we keep this | |
426 | structure around, just leaving values in it and adding new bits | |
427 | to the mask as we go. */ | |
428 | XWMHints wm_hints; | |
c8e3cbe0 | 429 | |
c8e3cbe0 | 430 | /* The size of the extra width currently allotted for vertical |
a3c87d4e JB |
431 | scroll bars, in pixels. */ |
432 | int vertical_scroll_bar_extra; | |
13bd51a5 | 433 | |
28f72798 JB |
434 | /* Table of parameter faces for this frame. Any X resources (pixel |
435 | values, fonts) referred to here have been allocated explicitly | |
436 | for this face, and should be freed if we change the face. */ | |
437 | struct face **param_faces; | |
438 | int n_param_faces; | |
439 | ||
440 | /* Table of computed faces for this frame. These are the faces | |
441 | whose indexes go into the upper bits of a glyph, computed by | |
442 | combining the parameter faces specified by overlays, text | |
443 | properties, and what have you. The X resources mentioned here | |
444 | are all shared with parameter faces. */ | |
445 | struct face **computed_faces; | |
446 | int n_computed_faces; /* How many are valid */ | |
447 | int size_computed_faces; /* How many are allocated */ | |
379564d6 RS |
448 | |
449 | /* This is the gravity value for the specified window position. */ | |
450 | int win_gravity; | |
f3942238 RS |
451 | |
452 | /* The geometry flags for this window. */ | |
453 | int size_hint_flags; | |
b242af88 RS |
454 | |
455 | /* This is the Emacs structure for the X display this frame is on. */ | |
579dd4be | 456 | struct x_display_info *display_info; |
dcc98b56 | 457 | |
51057b1f RS |
458 | /* This is a button event that wants to activate the menubar. |
459 | We save it here until the command loop gets to think about it. */ | |
460 | XButtonEvent *saved_button_event; | |
461 | ||
462 | /* This is the widget id used for this frame's menubar in lwlib. */ | |
463 | #ifdef USE_X_TOOLKIT | |
464 | int id; | |
465 | #endif | |
466 | ||
dcc98b56 RS |
467 | /* Nonzero means our parent is another application's window |
468 | and was explicitly specified. */ | |
469 | char explicit_parent; | |
cbef58c0 KH |
470 | |
471 | /* Nonzero means tried already to make this frame visible. */ | |
472 | char asked_for_visible; | |
7b8d4a3f RS |
473 | |
474 | #ifdef HAVE_X_I18N | |
f08fe433 RS |
475 | /* Input method. */ |
476 | XIM xim; | |
7b8d4a3f RS |
477 | /* Input context (currently, this means Compose key handler setup). */ |
478 | XIC xic; | |
479 | #endif | |
3f930d20 | 480 | }; |
d2729198 | 481 | |
28f72798 | 482 | /* Get at the computed faces of an X window frame. */ |
f39d1692 RS |
483 | #define FRAME_PARAM_FACES(f) ((f)->output_data.x->param_faces) |
484 | #define FRAME_N_PARAM_FACES(f) ((f)->output_data.x->n_param_faces) | |
28f72798 JB |
485 | #define FRAME_DEFAULT_PARAM_FACE(f) (FRAME_PARAM_FACES (f)[0]) |
486 | #define FRAME_MODE_LINE_PARAM_FACE(f) (FRAME_PARAM_FACES (f)[1]) | |
487 | ||
f39d1692 RS |
488 | #define FRAME_COMPUTED_FACES(f) ((f)->output_data.x->computed_faces) |
489 | #define FRAME_N_COMPUTED_FACES(f) ((f)->output_data.x->n_computed_faces) | |
490 | #define FRAME_SIZE_COMPUTED_FACES(f) ((f)->output_data.x->size_computed_faces) | |
491 | #define FRAME_DEFAULT_FACE(f) ((f)->output_data.x->computed_faces[0]) | |
492 | #define FRAME_MODE_LINE_FACE(f) ((f)->output_data.x->computed_faces[1]) | |
13bd51a5 | 493 | |
d2729198 | 494 | /* Return the window associated with the frame F. */ |
f39d1692 | 495 | #define FRAME_X_WINDOW(f) ((f)->output_data.x->window_desc) |
d2729198 | 496 | |
f39d1692 RS |
497 | #define FRAME_FOREGROUND_PIXEL(f) ((f)->output_data.x->foreground_pixel) |
498 | #define FRAME_BACKGROUND_PIXEL(f) ((f)->output_data.x->background_pixel) | |
499 | #define FRAME_FONT(f) ((f)->output_data.x->font) | |
5c9ee165 GV |
500 | #define FRAME_INTERNAL_BORDER_WIDTH(f) ((f)->output_data.x->internal_border_width) |
501 | #define FRAME_LINE_HEIGHT(f) ((f)->output_data.x->line_height) | |
8e533ff0 | 502 | |
579dd4be | 503 | /* This gives the x_display_info structure for the display F is on. */ |
f39d1692 | 504 | #define FRAME_X_DISPLAY_INFO(f) ((f)->output_data.x->display_info) |
b242af88 RS |
505 | |
506 | /* This is the `Display *' which frame F is on. */ | |
579dd4be RS |
507 | #define FRAME_X_DISPLAY(f) (FRAME_X_DISPLAY_INFO (f)->display) |
508 | ||
509 | /* This is the `Screen *' which frame F is on. */ | |
510 | #define FRAME_X_SCREEN(f) (FRAME_X_DISPLAY_INFO (f)->screen) | |
b242af88 | 511 | |
dbc4e1c1 | 512 | /* These two really ought to be called FRAME_PIXEL_{WIDTH,HEIGHT}. */ |
f39d1692 RS |
513 | #define PIXEL_WIDTH(f) ((f)->output_data.x->pixel_width) |
514 | #define PIXEL_HEIGHT(f) ((f)->output_data.x->pixel_height) | |
dbc4e1c1 | 515 | |
f39d1692 | 516 | #define FRAME_DESIRED_CURSOR(f) ((f)->output_data.x->desired_cursor) |
dbc4e1c1 | 517 | |
f08fe433 | 518 | #define FRAME_XIM(f) ((f)->output_data.x->xim) |
7afa6068 | 519 | #define FRAME_XIC(f) ((f)->output_data.x->xic) |
3f930d20 | 520 | \f |
a3c87d4e | 521 | /* X-specific scroll bar stuff. */ |
c8e3cbe0 | 522 | |
a3c87d4e | 523 | /* We represent scroll bars as lisp vectors. This allows us to place |
4e027793 | 524 | references to them in windows without worrying about whether we'll |
a3c87d4e | 525 | end up with windows referring to dead scroll bars; the garbage |
4e027793 JB |
526 | collector will free it when its time comes. |
527 | ||
a3c87d4e | 528 | We use struct scroll_bar as a template for accessing fields of the |
4e027793 JB |
529 | vector. */ |
530 | ||
a3c87d4e | 531 | struct scroll_bar { |
c8e3cbe0 | 532 | |
4e027793 | 533 | /* These fields are shared by all vectors. */ |
820b2ca2 | 534 | EMACS_INT size_from_Lisp_Vector_struct; |
4e027793 JB |
535 | struct Lisp_Vector *next_from_Lisp_Vector_struct; |
536 | ||
a3c87d4e | 537 | /* The window we're a scroll bar for. */ |
4e027793 | 538 | Lisp_Object window; |
c8e3cbe0 | 539 | |
a3c87d4e | 540 | /* The next and previous in the chain of scroll bars in this frame. */ |
4e027793 | 541 | Lisp_Object next, prev; |
c8e3cbe0 | 542 | |
a3c87d4e | 543 | /* The X window representing this scroll bar. Since this is a full |
4e027793 JB |
544 | 32-bit quantity, we store it split into two 32-bit values. */ |
545 | Lisp_Object x_window_low, x_window_high; | |
c8e3cbe0 | 546 | |
a3c87d4e | 547 | /* The position and size of the scroll bar in pixels, relative to the |
c8e3cbe0 | 548 | frame. */ |
4e027793 | 549 | Lisp_Object top, left, width, height; |
c8e3cbe0 | 550 | |
4e027793 JB |
551 | /* The starting and ending positions of the handle, relative to the |
552 | handle area (i.e. zero is the top position, not | |
a3c87d4e | 553 | SCROLL_BAR_TOP_BORDER). If they're equal, that means the handle |
4e027793 | 554 | hasn't been drawn yet. |
c8e3cbe0 | 555 | |
4e027793 JB |
556 | These are not actually the locations where the beginning and end |
557 | are drawn; in order to keep handles from becoming invisible when | |
558 | editing large files, we establish a minimum height by always | |
a3c87d4e | 559 | drawing handle bottoms VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below |
4e027793 JB |
560 | where they would be normally; the bottom and top are in a |
561 | different co-ordinate system. */ | |
562 | Lisp_Object start, end; | |
c8e3cbe0 | 563 | |
a3c87d4e | 564 | /* If the scroll bar handle is currently being dragged by the user, |
c8e3cbe0 JB |
565 | this is the number of pixels from the top of the handle to the |
566 | place where the user grabbed it. If the handle isn't currently | |
4e027793 JB |
567 | being dragged, this is Qnil. */ |
568 | Lisp_Object dragging; | |
c8e3cbe0 JB |
569 | }; |
570 | ||
a3c87d4e | 571 | /* The number of elements a vector holding a struct scroll_bar needs. */ |
35e5240a KH |
572 | #define SCROLL_BAR_VEC_SIZE \ |
573 | ((sizeof (struct scroll_bar) \ | |
574 | - sizeof (EMACS_INT) - sizeof (struct Lisp_Vector *)) \ | |
4e027793 JB |
575 | / sizeof (Lisp_Object)) |
576 | ||
a3c87d4e | 577 | /* Turning a lisp vector value into a pointer to a struct scroll_bar. */ |
35e5240a | 578 | #define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec)) |
4e027793 JB |
579 | |
580 | ||
581 | /* Building a 32-bit C integer from two 16-bit lisp integers. */ | |
a3c87d4e | 582 | #define SCROLL_BAR_PACK(low, high) (XINT (high) << 16 | XINT (low)) |
4e027793 JB |
583 | |
584 | /* Setting two lisp integers to the low and high words of a 32-bit C int. */ | |
a3c87d4e | 585 | #define SCROLL_BAR_UNPACK(low, high, int32) \ |
df0f379b KH |
586 | (XSETINT ((low), (int32) & 0xffff), \ |
587 | XSETINT ((high), ((int32) >> 16) & 0xffff)) | |
4e027793 JB |
588 | |
589 | ||
a3c87d4e JB |
590 | /* Extract the X window id of the scroll bar from a struct scroll_bar. */ |
591 | #define SCROLL_BAR_X_WINDOW(ptr) \ | |
592 | ((Window) SCROLL_BAR_PACK ((ptr)->x_window_low, (ptr)->x_window_high)) | |
4e027793 | 593 | |
a3c87d4e JB |
594 | /* Store a window id in a struct scroll_bar. */ |
595 | #define SET_SCROLL_BAR_X_WINDOW(ptr, id) \ | |
596 | (SCROLL_BAR_UNPACK ((ptr)->x_window_low, (ptr)->x_window_high, (int) id)) | |
4e027793 JB |
597 | |
598 | ||
a3c87d4e | 599 | /* Return the outside pixel height for a vertical scroll bar HEIGHT |
c8e3cbe0 | 600 | rows high on frame F. */ |
a3c87d4e | 601 | #define VERTICAL_SCROLL_BAR_PIXEL_HEIGHT(f, height) \ |
f39d1692 | 602 | ((height) * (f)->output_data.x->line_height) |
c8e3cbe0 | 603 | |
a3c87d4e | 604 | /* Return the inside width of a vertical scroll bar, given the outside |
4e027793 | 605 | width. */ |
a3c87d4e JB |
606 | #define VERTICAL_SCROLL_BAR_INSIDE_WIDTH(width) \ |
607 | ((width) - VERTICAL_SCROLL_BAR_LEFT_BORDER - VERTICAL_SCROLL_BAR_RIGHT_BORDER) | |
c8e3cbe0 | 608 | |
4e027793 JB |
609 | /* Return the length of the rectangle within which the top of the |
610 | handle must stay. This isn't equivalent to the inside height, | |
a3c87d4e | 611 | because the scroll bar handle has a minimum height. |
4e027793 | 612 | |
a3c87d4e JB |
613 | This is the real range of motion for the scroll bar, so when we're |
614 | scaling buffer positions to scroll bar positions, we use this, not | |
615 | VERTICAL_SCROLL_BAR_INSIDE_HEIGHT. */ | |
616 | #define VERTICAL_SCROLL_BAR_TOP_RANGE(height) \ | |
617 | (VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (height) - VERTICAL_SCROLL_BAR_MIN_HANDLE) | |
4e027793 | 618 | |
a3c87d4e JB |
619 | /* Return the inside height of vertical scroll bar, given the outside |
620 | height. See VERTICAL_SCROLL_BAR_TOP_RANGE too. */ | |
621 | #define VERTICAL_SCROLL_BAR_INSIDE_HEIGHT(height) \ | |
622 | ((height) - VERTICAL_SCROLL_BAR_TOP_BORDER - VERTICAL_SCROLL_BAR_BOTTOM_BORDER) | |
4e027793 JB |
623 | |
624 | ||
a3c87d4e | 625 | /* Border widths for scroll bars. |
4e027793 | 626 | |
a3c87d4e | 627 | Scroll bar windows don't have any X borders; their border width is |
4e027793 JB |
628 | set to zero, and we redraw borders ourselves. This makes the code |
629 | a bit cleaner, since we don't have to convert between outside width | |
630 | (used when relating to the rest of the screen) and inside width | |
a3c87d4e | 631 | (used when sizing and drawing the scroll bar window itself). |
4e027793 | 632 | |
eb8c3be9 | 633 | The handle moves up and down/back and forth in a rectangle inset |
a3c87d4e JB |
634 | from the edges of the scroll bar. These are widths by which we |
635 | inset the handle boundaries from the scroll bar edges. */ | |
636 | #define VERTICAL_SCROLL_BAR_LEFT_BORDER (2) | |
d68eb3a2 | 637 | #define VERTICAL_SCROLL_BAR_RIGHT_BORDER (2) |
a3c87d4e JB |
638 | #define VERTICAL_SCROLL_BAR_TOP_BORDER (2) |
639 | #define VERTICAL_SCROLL_BAR_BOTTOM_BORDER (2) | |
4e027793 | 640 | |
a3c87d4e JB |
641 | /* Minimum lengths for scroll bar handles, in pixels. */ |
642 | #define VERTICAL_SCROLL_BAR_MIN_HANDLE (5) | |
c8e3cbe0 JB |
643 | |
644 | \f | |
645 | /* Manipulating pixel sizes and character sizes. | |
646 | Knowledge of which factors affect the overall size of the window should | |
647 | be hidden in these macros, if that's possible. | |
648 | ||
0cabaf31 | 649 | Return the upper/left pixel position of the character cell on frame F |
4e027793 JB |
650 | at ROW/COL. */ |
651 | #define CHAR_TO_PIXEL_ROW(f, row) \ | |
f39d1692 RS |
652 | ((f)->output_data.x->internal_border_width \ |
653 | + (row) * (f)->output_data.x->line_height) | |
4e027793 | 654 | #define CHAR_TO_PIXEL_COL(f, col) \ |
f39d1692 RS |
655 | ((f)->output_data.x->internal_border_width \ |
656 | + (col) * FONT_WIDTH ((f)->output_data.x->font)) | |
4e027793 JB |
657 | |
658 | /* Return the pixel width/height of frame F if it has | |
659 | WIDTH columns/HEIGHT rows. */ | |
c8e3cbe0 | 660 | #define CHAR_TO_PIXEL_WIDTH(f, width) \ |
4e027793 | 661 | (CHAR_TO_PIXEL_COL (f, width) \ |
f39d1692 RS |
662 | + (f)->output_data.x->vertical_scroll_bar_extra \ |
663 | + (f)->output_data.x->internal_border_width) | |
c8e3cbe0 | 664 | #define CHAR_TO_PIXEL_HEIGHT(f, height) \ |
4e027793 | 665 | (CHAR_TO_PIXEL_ROW (f, height) \ |
f39d1692 | 666 | + (f)->output_data.x->internal_border_width) |
c8e3cbe0 | 667 | |
c8e3cbe0 | 668 | |
4e027793 JB |
669 | /* Return the row/column (zero-based) of the character cell containing |
670 | the pixel on FRAME at ROW/COL. */ | |
cecfe612 | 671 | #define PIXEL_TO_CHAR_ROW(f, row) \ |
f39d1692 RS |
672 | (((row) - (f)->output_data.x->internal_border_width) \ |
673 | / (f)->output_data.x->line_height) | |
cecfe612 | 674 | #define PIXEL_TO_CHAR_COL(f, col) \ |
f39d1692 RS |
675 | (((col) - (f)->output_data.x->internal_border_width) \ |
676 | / FONT_WIDTH ((f)->output_data.x->font)) | |
c8e3cbe0 | 677 | |
4e027793 JB |
678 | /* How many columns/rows of text can we fit in WIDTH/HEIGHT pixels on |
679 | frame F? */ | |
680 | #define PIXEL_TO_CHAR_WIDTH(f, width) \ | |
681 | (PIXEL_TO_CHAR_COL (f, ((width) \ | |
f39d1692 RS |
682 | - (f)->output_data.x->internal_border_width \ |
683 | - (f)->output_data.x->vertical_scroll_bar_extra))) | |
4e027793 JB |
684 | #define PIXEL_TO_CHAR_HEIGHT(f, height) \ |
685 | (PIXEL_TO_CHAR_ROW (f, ((height) \ | |
f39d1692 | 686 | - (f)->output_data.x->internal_border_width))) |
c352056c RS |
687 | \f |
688 | /* If a struct input_event has a kind which is selection_request_event | |
689 | or selection_clear_event, then its contents are really described | |
690 | by this structure. */ | |
691 | ||
692 | /* For an event of kind selection_request_event, | |
d601ce45 RS |
693 | this structure really describes the contents. |
694 | **Don't make this struct longer!** | |
695 | If it overlaps the frame_or_window field of struct input_event, | |
696 | that will cause GC to crash. */ | |
c352056c RS |
697 | struct selection_input_event |
698 | { | |
699 | int kind; | |
700 | Display *display; | |
beaff27b RS |
701 | /* We spell it with an "o" here because X does. */ |
702 | Window requestor; | |
c352056c RS |
703 | Atom selection, target, property; |
704 | Time time; | |
705 | }; | |
706 | ||
707 | #define SELECTION_EVENT_DISPLAY(eventp) \ | |
708 | (((struct selection_input_event *) (eventp))->display) | |
beaff27b RS |
709 | /* We spell it with an "o" here because X does. */ |
710 | #define SELECTION_EVENT_REQUESTOR(eventp) \ | |
711 | (((struct selection_input_event *) (eventp))->requestor) | |
c352056c RS |
712 | #define SELECTION_EVENT_SELECTION(eventp) \ |
713 | (((struct selection_input_event *) (eventp))->selection) | |
714 | #define SELECTION_EVENT_TARGET(eventp) \ | |
715 | (((struct selection_input_event *) (eventp))->target) | |
716 | #define SELECTION_EVENT_PROPERTY(eventp) \ | |
717 | (((struct selection_input_event *) (eventp))->property) | |
718 | #define SELECTION_EVENT_TIME(eventp) \ | |
719 | (((struct selection_input_event *) (eventp))->time) | |
bf489d26 JB |
720 | |
721 | \f | |
722 | /* Interface to the face code functions. */ | |
723 | ||
28f72798 JB |
724 | /* Create the first two computed faces for a frame -- the ones that |
725 | have GC's. */ | |
bf489d26 JB |
726 | extern void init_frame_faces (/* FRAME_PTR */); |
727 | ||
728 | /* Free the resources for the faces associated with a frame. */ | |
729 | extern void free_frame_faces (/* FRAME_PTR */); | |
730 | ||
28f72798 | 731 | /* Given a computed face, find or make an equivalent display face |
bf489d26 JB |
732 | in face_vector, and return a pointer to it. */ |
733 | extern struct face *intern_face (/* FRAME_PTR, struct face * */); | |
734 | ||
735 | /* Given a frame and a face name, return the face's ID number, or | |
736 | zero if it isn't a recognized face name. */ | |
737 | extern int face_name_id_number (/* FRAME_PTR, Lisp_Object */); | |
738 | ||
739 | /* Return non-zero if FONT1 and FONT2 have the same size bounding box. | |
740 | We assume that they're both character-cell fonts. */ | |
741 | extern int same_size_fonts (/* XFontStruct *, XFontStruct * */); | |
742 | ||
743 | /* Recompute the GC's for the default and modeline faces. | |
744 | We call this after changing frame parameters on which those GC's | |
745 | depend. */ | |
746 | extern void recompute_basic_faces (/* FRAME_PTR */); | |
747 | ||
28f72798 JB |
748 | /* Return the face ID associated with a buffer position POS. Store |
749 | into *ENDPTR the next position at which a different face is | |
750 | needed. This does not take account of glyphs that specify their | |
751 | own face codes. F is the frame in use for display, and W is a | |
752 | window displaying the current buffer. | |
bf489d26 JB |
753 | |
754 | REGION_BEG, REGION_END delimit the region, so it can be highlighted. */ | |
755 | extern int compute_char_face (/* FRAME_PTR frame, | |
756 | struct window *w, | |
757 | int pos, | |
758 | int region_beg, int region_end, | |
759 | int *endptr */); | |
760 | /* Return the face ID to use to display a special glyph which selects | |
761 | FACE_CODE as the face ID, assuming that ordinarily the face would | |
762 | be BASIC_FACE. F is the frame. */ | |
763 | extern int compute_glyph_face (/* FRAME_PTR, int */); |