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