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