Upgraded to mh-e version 6.1.1.
[bpt/emacs.git] / src / xterm.h
1 /* Definitions and headers for communication with X protocol.
2 Copyright (C) 1989, 1993, 1994, 1998, 1999, 2000, 2001, 2001
3 Free Software Foundation, Inc.
4
5 This file is part of GNU Emacs.
6
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22 #include <X11/Xlib.h>
23 #include <X11/cursorfont.h>
24 #include <X11/Xutil.h>
25 #include <X11/keysym.h>
26 #include <X11/Xatom.h>
27 #include <X11/Xresource.h>
28
29 #ifdef USE_X_TOOLKIT
30 #include <X11/StringDefs.h>
31 #include <X11/IntrinsicP.h> /* CoreP.h needs this */
32 #include <X11/CoreP.h> /* foul, but we need this to use our own
33 window inside a widget instead of one
34 that Xt creates... */
35 #include <X11/StringDefs.h>
36 #endif
37
38 /* The class of this X application. */
39 #define EMACS_CLASS "Emacs"
40 \f
41 /* Bookkeeping to distinguish X versions. */
42
43 /* HAVE_X11R4 is defined if we have the features of X11R4. It should
44 be defined when we're using X11R5, since X11R5 has the features of
45 X11R4. If, in the future, we find we need more of these flags
46 (HAVE_X11R5, for example), code should always be written to test
47 the most recent flag first:
48
49 #ifdef HAVE_X11R5
50 ...
51 #elif HAVE_X11R4
52 ...
53 #elif HAVE_X11
54 ...
55 #endif
56
57 If you ever find yourself writing a "#ifdef HAVE_FOO" clause that
58 looks a lot like another one, consider moving the text into a macro
59 whose definition is configuration-dependent, but whose usage is
60 universal - like the stuff in systime.h.
61
62 It turns out that we can auto-detect whether we're being compiled
63 with X11R3 or X11R4 by looking for the flag macros for R4 structure
64 members that R3 doesn't have. */
65 #ifdef PBaseSize
66 /* AIX 3.1's X is somewhere between X11R3 and X11R4. It has
67 PBaseSize, but not XWithdrawWindow, XSetWMName, XSetWMNormalHints,
68 XSetWMIconName.
69 AIX 3.2 is at least X11R4. */
70 #if (!defined AIX) || (defined AIX3_2)
71 #define HAVE_X11R4
72 #endif
73 #endif
74
75 #ifdef HAVE_X11R5
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
79 #endif
80
81 #ifdef HAVE_X_I18N
82 #include <X11/Xlocale.h>
83 #endif
84 \f
85 #define BLACK_PIX_DEFAULT(f) BlackPixel (FRAME_X_DISPLAY (f), \
86 XScreenNumberOfScreen (FRAME_X_SCREEN (f)))
87 #define WHITE_PIX_DEFAULT(f) WhitePixel (FRAME_X_DISPLAY (f), \
88 XScreenNumberOfScreen (FRAME_X_SCREEN (f)))
89
90 #define FONT_WIDTH(f) ((f)->max_bounds.width)
91 #define FONT_HEIGHT(f) ((f)->ascent + (f)->descent)
92 #define FONT_BASE(f) ((f)->ascent)
93
94 /* The mask of events that text windows always want to receive. This
95 includes mouse movement events, since handling the mouse-font text property
96 means that we must track mouse motion all the time. */
97
98 #define STANDARD_EVENT_SET \
99 (KeyPressMask \
100 | ExposureMask \
101 | ButtonPressMask \
102 | ButtonReleaseMask \
103 | PointerMotionMask \
104 | StructureNotifyMask \
105 | FocusChangeMask \
106 | LeaveWindowMask \
107 | EnterWindowMask \
108 | VisibilityChangeMask)
109
110 /* Structure recording X pixmap and reference count.
111 If REFCOUNT is 0 then this record is free to be reused. */
112
113 struct x_bitmap_record
114 {
115 Pixmap pixmap;
116 char *file;
117 int refcount;
118 /* Record some info about this pixmap. */
119 int height, width, depth;
120 };
121 \f
122 /* For each X display, we have a structure that records
123 information about it. */
124
125 struct x_display_info
126 {
127 /* Chain of all x_display_info structures. */
128 struct x_display_info *next;
129
130 /* Connection number (normally a file descriptor number). */
131 int connection;
132
133 /* This says how to access this display in Xlib. */
134 Display *display;
135
136 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE).
137 The same cons cell also appears in x_display_name_list. */
138 Lisp_Object name_list_element;
139
140 /* Number of frames that are on this display. */
141 int reference_count;
142
143 /* The Screen this connection is connected to. */
144 Screen *screen;
145
146 /* Dots per inch of the screen. */
147 double resx, resy;
148
149 /* The Visual being used for this display. */
150 Visual *visual;
151
152 /* The colormap being used. */
153 Colormap cmap;
154
155 /* Number of panes on this screen. */
156 int n_planes;
157
158 /* Dimensions of this screen. */
159 int height, width;
160
161 /* Mask of things that cause the mouse to be grabbed. */
162 int grabbed;
163
164 /* Emacs bitmap-id of the default icon bitmap for this frame.
165 Or -1 if none has been allocated yet. */
166 int icon_bitmap_id;
167
168 /* The root window of this screen. */
169 Window root_window;
170
171 /* The cursor to use for vertical scroll bars. */
172 Cursor vertical_scroll_bar_cursor;
173
174 /* X Resource data base */
175 XrmDatabase xrdb;
176
177 /* A table of all the fonts we have already loaded. */
178 struct font_info *font_table;
179
180 /* The current capacity of x_font_table. */
181 int font_table_size;
182
183 /* Minimum width over all characters in all fonts in font_table. */
184 int smallest_char_width;
185
186 /* Minimum font height over all fonts in font_table. */
187 int smallest_font_height;
188
189 /* Reusable Graphics Context for drawing a cursor in a non-default face. */
190 GC scratch_cursor_gc;
191
192 /* These variables describe the range of text currently shown in its
193 mouse-face, together with the window they apply to. As long as
194 the mouse stays within this range, we need not redraw anything on
195 its account. Rows and columns are glyph matrix positions in
196 MOUSE_FACE_WINDOW. */
197 int mouse_face_beg_row, mouse_face_beg_col;
198 int mouse_face_beg_x, mouse_face_beg_y;
199 int mouse_face_end_row, mouse_face_end_col;
200 int mouse_face_end_x, mouse_face_end_y;
201 int mouse_face_past_end;
202 Lisp_Object mouse_face_window;
203 int mouse_face_face_id;
204 Lisp_Object mouse_face_overlay;
205
206 /* 1 if a mouse motion event came and we didn't handle it right away because
207 gc was in progress. */
208 int mouse_face_deferred_gc;
209
210 /* FRAME and X, Y position of mouse when last checked for
211 highlighting. X and Y can be negative or out of range for the frame. */
212 struct frame *mouse_face_mouse_frame;
213 int mouse_face_mouse_x, mouse_face_mouse_y;
214
215 /* Nonzero means defer mouse-motion highlighting. */
216 int mouse_face_defer;
217
218 /* Nonzero means that the mouse highlight should not be shown. */
219 int mouse_face_hidden;
220
221 int mouse_face_image_state;
222
223 char *x_id_name;
224
225 /* The number of fonts actually stored in x_font_table.
226 font_table[n] is used and valid iff 0 <= n < n_fonts. 0 <=
227 n_fonts <= font_table_size and font_table[i].name != 0. */
228 int n_fonts;
229
230 /* Pointer to bitmap records. */
231 struct x_bitmap_record *bitmaps;
232
233 /* Allocated size of bitmaps field. */
234 int bitmaps_size;
235
236 /* Last used bitmap index. */
237 int bitmaps_last;
238
239 /* Which modifier keys are on which modifier bits?
240
241 With each keystroke, X returns eight bits indicating which modifier
242 keys were held down when the key was pressed. The interpretation
243 of the top five modifier bits depends on what keys are attached
244 to them. If the Meta_L and Meta_R keysyms are on mod5, then mod5
245 is the meta bit.
246
247 meta_mod_mask is a mask containing the bits used for the meta key.
248 It may have more than one bit set, if more than one modifier bit
249 has meta keys on it. Basically, if EVENT is a KeyPress event,
250 the meta key is pressed if (EVENT.state & meta_mod_mask) != 0.
251
252 shift_lock_mask is LockMask if the XK_Shift_Lock keysym is on the
253 lock modifier bit, or zero otherwise. Non-alphabetic keys should
254 only be affected by the lock modifier bit if XK_Shift_Lock is in
255 use; XK_Caps_Lock should only affect alphabetic keys. With this
256 arrangement, the lock modifier should shift the character if
257 (EVENT.state & shift_lock_mask) != 0. */
258 int meta_mod_mask, shift_lock_mask;
259
260 /* These are like meta_mod_mask, but for different modifiers. */
261 int alt_mod_mask, super_mod_mask, hyper_mod_mask;
262
263 /* Communication with window managers. */
264 Atom Xatom_wm_protocols;
265
266 /* Kinds of protocol things we may receive. */
267 Atom Xatom_wm_take_focus;
268 Atom Xatom_wm_save_yourself;
269 Atom Xatom_wm_delete_window;
270
271 /* Atom for indicating window state to the window manager. */
272 Atom Xatom_wm_change_state;
273
274 /* Other WM communication */
275 Atom Xatom_wm_configure_denied; /* When our config request is denied */
276 Atom Xatom_wm_window_moved; /* When the WM moves us. */
277
278 /* EditRes protocol */
279 Atom Xatom_editres;
280
281 /* More atoms, which are selection types. */
282 Atom Xatom_CLIPBOARD, Xatom_TIMESTAMP, Xatom_TEXT, Xatom_DELETE,
283 Xatom_COMPOUND_TEXT, Xatom_UTF8_STRING,
284 Xatom_MULTIPLE, Xatom_INCR, Xatom_EMACS_TMP, Xatom_TARGETS, Xatom_NULL,
285 Xatom_ATOM_PAIR;
286
287 /* More atoms for font properties. The last three are private
288 properties, see the comments in src/fontset.h. */
289 Atom Xatom_PIXEL_SIZE,
290 Xatom_MULE_BASELINE_OFFSET, Xatom_MULE_RELATIVE_COMPOSE,
291 Xatom_MULE_DEFAULT_ASCENT;
292
293 /* More atoms for Ghostscript support. */
294 Atom Xatom_DONE, Xatom_PAGE;
295
296 /* Atom used in toolkit scroll bar client messages. */
297 Atom Xatom_Scrollbar;
298
299 #ifdef MULTI_KBOARD
300 struct kboard *kboard;
301 #endif
302 int cut_buffers_initialized; /* Whether we're sure they all exist */
303
304 /* The frame (if any) which has the X window that has keyboard focus.
305 Zero if none. This is examined by Ffocus_frame in xfns.c. Note
306 that a mere EnterNotify event can set this; if you need to know the
307 last frame specified in a FocusIn or FocusOut event, use
308 x_focus_event_frame. */
309 struct frame *x_focus_frame;
310
311 /* The last frame mentioned in a FocusIn or FocusOut event. This is
312 separate from x_focus_frame, because whether or not LeaveNotify
313 events cause us to lose focus depends on whether or not we have
314 received a FocusIn event for it. */
315 struct frame *x_focus_event_frame;
316
317 /* The frame which currently has the visual highlight, and should get
318 keyboard input (other sorts of input have the frame encoded in the
319 event). It points to the X focus frame's selected window's
320 frame. It differs from x_focus_frame when we're using a global
321 minibuffer. */
322 struct frame *x_highlight_frame;
323
324 /* The null pixel used for filling a character background with
325 background color of a gc. */
326 Pixmap null_pixel;
327
328 /* The gray pixmap. */
329 Pixmap gray;
330
331 /* Cache of images. */
332 struct image_cache *image_cache;
333
334 #ifdef HAVE_X_I18N
335 /* XIM (X Input method). */
336 XIM xim;
337 XIMStyles *xim_styles;
338 #endif
339
340 /* If non-null, a cache of the colors in the color map. Don't
341 use this directly, call x_color_cells instead. */
342 XColor *color_cells;
343 int ncolor_cells;
344 };
345
346 /* This checks to make sure we have a display. */
347 extern void check_x P_ ((void));
348
349 extern struct frame *x_window_to_frame P_ ((struct x_display_info *, int));
350
351 #ifdef USE_X_TOOLKIT
352 extern struct frame *x_any_window_to_frame P_ ((struct x_display_info *, int));
353 extern struct frame *x_non_menubar_window_to_frame P_ ((struct x_display_info *, int));
354 extern struct frame *x_top_window_to_frame P_ ((struct x_display_info *, int));
355 #endif
356
357 /* This is a chain of structures for all the X displays currently in use. */
358 extern struct x_display_info *x_display_list;
359
360 /* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE),
361 one for each element of x_display_list and in the same order.
362 NAME is the name of the frame.
363 FONT-LIST-CACHE records previous values returned by x-list-fonts. */
364 extern Lisp_Object x_display_name_list;
365
366 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
367 extern Lisp_Object Vx_pixel_size_width_font_regexp;
368
369 /* A flag to control how to display unibyte 8-bit character. */
370 extern int unibyte_display_via_language_environment;
371
372 extern struct x_display_info *x_display_info_for_display P_ ((Display *));
373 extern struct x_display_info *x_display_info_for_name P_ ((Lisp_Object));
374
375 extern struct x_display_info *x_term_init P_ ((Lisp_Object, char *, char *));
376
377 extern Lisp_Object x_list_fonts P_ ((struct frame *, Lisp_Object, int, int));
378 extern void select_visual P_ ((struct x_display_info *));
379 extern struct font_info *x_get_font_info P_ ((struct frame *f, int));
380 extern struct font_info *x_load_font P_ ((struct frame *, char *, int));
381 extern struct font_info *x_query_font P_ ((struct frame *, char *));
382 extern void x_find_ccl_program P_ ((struct font_info *));
383 \f
384 /* Each X frame object points to its own struct x_output object
385 in the output_data.x field. The x_output structure contains
386 the information that is specific to X windows. */
387
388 struct x_output
389 {
390 /* Position of the X window (x and y offsets in root window). */
391 int left_pos;
392 int top_pos;
393
394 /* Border width of the X window as known by the X window system. */
395 int border_width;
396
397 /* Size of the X window in pixels. */
398 int pixel_height, pixel_width;
399
400 /* Height of menu bar widget, in pixels.
401 Zero if not using the X toolkit.
402 When using the toolkit, this value is not meaningful
403 if the menubar is turned off. */
404 int menubar_height;
405
406 /* Height of a line, in pixels. */
407 int line_height;
408
409 /* The tiled border used when the mouse is out of the frame. */
410 Pixmap border_tile;
411
412 /* Here are the Graphics Contexts for the default font. */
413 GC normal_gc; /* Normal video */
414 GC reverse_gc; /* Reverse video */
415 GC cursor_gc; /* cursor drawing */
416
417 /* Width of the internal border. This is a line of background color
418 just inside the window's border. When the frame is selected,
419 a highlighting is displayed inside the internal border. */
420 int internal_border_width;
421
422 /* The X window used for this frame.
423 May be zero while the frame object is being created
424 and the X window has not yet been created. */
425 Window window_desc;
426
427 /* The X window used for the bitmap icon;
428 or 0 if we don't have a bitmap icon. */
429 Window icon_desc;
430
431 /* The X window that is the parent of this X window.
432 Usually this is a window that was made by the window manager,
433 but it can be the root window, and it can be explicitly specified
434 (see the explicit_parent field, below). */
435 Window parent_desc;
436
437 #ifdef USE_X_TOOLKIT
438 /* The widget of this screen. This is the window of a "shell" widget. */
439 Widget widget;
440 /* The XmPanedWindows... */
441 Widget column_widget;
442 /* The widget of the edit portion of this screen; the window in
443 "window_desc" is inside of this. */
444 Widget edit_widget;
445
446 Widget menubar_widget;
447 #endif
448
449 /* If >=0, a bitmap index. The indicated bitmap is used for the
450 icon. */
451 int icon_bitmap;
452
453 /* Default ASCII font of this frame. */
454 XFontStruct *font;
455
456 /* The baseline offset of the default ASCII font. */
457 int baseline_offset;
458
459 /* If a fontset is specified for this frame instead of font, this
460 value contains an ID of the fontset, else -1. */
461 int fontset;
462
463 /* Pixel values used for various purposes.
464 border_pixel may be -1 meaning use a gray tile. */
465 unsigned long background_pixel;
466 unsigned long foreground_pixel;
467 unsigned long cursor_pixel;
468 unsigned long border_pixel;
469 unsigned long mouse_pixel;
470 unsigned long cursor_foreground_pixel;
471
472 /* Foreground color for scroll bars. A value of -1 means use the
473 default (black for non-toolkit scroll bars). */
474 unsigned long scroll_bar_foreground_pixel;
475
476 /* Background color for scroll bars. A value of -1 means use the
477 default (background color of the frame for non-toolkit scroll
478 bars). */
479 unsigned long scroll_bar_background_pixel;
480
481 /* Top and bottom shadow colors for 3d toolkit scrollbars. -1 means
482 let the scroll compute them itself. */
483 unsigned long scroll_bar_top_shadow_pixel;
484 unsigned long scroll_bar_bottom_shadow_pixel;
485
486 /* Descriptor for the cursor in use for this window. */
487 Cursor text_cursor;
488 Cursor nontext_cursor;
489 Cursor modeline_cursor;
490 Cursor cross_cursor;
491 Cursor hourglass_cursor;
492 Cursor horizontal_drag_cursor;
493
494 /* Window whose cursor is hourglass_cursor. This window is temporarily
495 mapped to display an hourglass cursor. */
496 Window hourglass_window;
497
498 /* Non-zero means hourglass cursor is currently displayed. */
499 unsigned hourglass_p : 1;
500
501 /* Flag to set when the X window needs to be completely repainted. */
502 int needs_exposure;
503
504 /* These are the current window manager hints. It seems that
505 XSetWMHints, when presented with an unset bit in the `flags'
506 member of the hints structure, does not leave the corresponding
507 attribute unchanged; rather, it resets that attribute to its
508 default value. For example, unless you set the `icon_pixmap'
509 field and the `IconPixmapHint' bit, XSetWMHints will forget what
510 your icon pixmap was. This is rather troublesome, since some of
511 the members (for example, `input' and `icon_pixmap') want to stay
512 the same throughout the execution of Emacs. So, we keep this
513 structure around, just leaving values in it and adding new bits
514 to the mask as we go. */
515 XWMHints wm_hints;
516
517 /* The size of the extra width currently allotted for vertical
518 scroll bars, in pixels. */
519 int vertical_scroll_bar_extra;
520
521 /* The extra width currently allotted for the areas in which
522 truncation marks, continuation marks, and overlay arrows are
523 displayed. */
524 int left_fringe_width, right_fringe_width;
525 int fringe_cols, fringes_extra;
526
527 /* This is the gravity value for the specified window position. */
528 int win_gravity;
529
530 /* The geometry flags for this window. */
531 int size_hint_flags;
532
533 /* This is the Emacs structure for the X display this frame is on. */
534 struct x_display_info *display_info;
535
536 /* This is a button event that wants to activate the menubar.
537 We save it here until the command loop gets to think about it. */
538 XEvent *saved_menu_event;
539
540 /* This is the widget id used for this frame's menubar in lwlib. */
541 #ifdef USE_X_TOOLKIT
542 int id;
543 #endif
544
545 /* Nonzero means our parent is another application's window
546 and was explicitly specified. */
547 char explicit_parent;
548
549 /* Nonzero means tried already to make this frame visible. */
550 char asked_for_visible;
551
552 /* Nonzero if this frame was ever previously visible. */
553 char has_been_visible;
554
555 #ifdef HAVE_X_I18N
556 /* Input context (currently, this means Compose key handler setup). */
557 XIC xic;
558 XIMStyle xic_style;
559 XFontSet xic_xfs;
560 #endif
561
562 /* Relief GCs, colors etc. */
563 struct relief
564 {
565 GC gc;
566 unsigned long pixel;
567 int allocated_p;
568 }
569 black_relief, white_relief;
570
571 /* The background for which the above relief GCs were set up.
572 They are changed only when a different background is involved. */
573 unsigned long relief_background;
574
575 /* Xt waits for a ConfigureNotify event from the window manager in
576 EmacsFrameSetCharSize when the shell widget is resized. For some
577 window managers like fvwm2 2.2.5 and KDE 2.1 this event doesn't
578 arrive for an unknown reason and Emacs hangs in Xt. If this is
579 zero, tell Xt not to wait. */
580 int wait_for_wm;
581
582 /* See enum below */
583 int want_fullscreen;
584
585 /* This many pixels are the difference between the outer window (i.e. the
586 left of the window manager decoration) and FRAME_X_WINDOW. */
587 int x_pixels_diff;
588
589 /* This many pixels are the difference between the outer window (i.e. the
590 top of the window manager titlebar) and FRAME_X_WINDOW. */
591 int y_pixels_diff;
592
593 /* As x_pixels_diff, but to FRAME_OUTER_WINDOW. For some reason the
594 two might differ by a pixel, depending on WM */
595 int x_pixels_outer_diff;
596
597 /* As y_pixels_diff, but to FRAME_OUTER_WINDOW. In the toolkit version,
598 these may differ because this does not take into account possible
599 menubar. y_pixels_diff is with menubar height included */
600 int y_pixels_outer_diff;
601
602 /* Keep track of focus. May be EXPLICIT if we received a FocusIn for this
603 frame, or IMPLICIT if we received an EnterNotify.
604 FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
605 int focus_state;
606 };
607
608 enum
609 {
610 /* Values used as a bit mask, BOTH == WIDTH | HEIGHT. */
611 FULLSCREEN_NONE = 0,
612 FULLSCREEN_WIDTH = 1,
613 FULLSCREEN_HEIGHT = 2,
614 FULLSCREEN_BOTH = 3,
615 FULLSCREEN_WAIT = 4,
616 FULLSCREEN_MOVE_WAIT = 8,
617 };
618
619 enum
620 {
621 /* Values for focus_state, used as bit mask.
622 EXPLICIT means if we received a FocusIn for the frame and know it has
623 the focus. IMPLICIT means we recevied an EnterNotify and the frame
624 may have the focus if no window manager is running.
625 FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
626 FOCUS_NONE = 0,
627 FOCUS_IMPLICIT = 1,
628 FOCUS_EXPLICIT = 2
629 };
630
631
632 /* Return the X window used for displaying data in frame F. */
633 #define FRAME_X_WINDOW(f) ((f)->output_data.x->window_desc)
634
635 /* Return the outermost X window associated with the frame F. */
636 #ifdef USE_X_TOOLKIT
637 #define FRAME_OUTER_WINDOW(f) ((f)->output_data.x->widget ? \
638 XtWindow ((f)->output_data.x->widget) : \
639 FRAME_X_WINDOW (f))
640 #else
641 #define FRAME_OUTER_WINDOW(f) (FRAME_X_WINDOW (f))
642 #endif
643
644 #define FRAME_FONT(f) ((f)->output_data.x->font)
645 #define FRAME_FONTSET(f) ((f)->output_data.x->fontset)
646 #define FRAME_INTERNAL_BORDER_WIDTH(f) ((f)->output_data.x->internal_border_width)
647 #define FRAME_MENUBAR_HEIGHT(f) ((f)->output_data.x->menubar_height)
648 #define FRAME_LINE_HEIGHT(f) ((f)->output_data.x->line_height)
649
650 /* Width of the default font of frame F. Must be defined by each
651 terminal specific header. */
652 #define FRAME_DEFAULT_FONT_WIDTH(F) FONT_WIDTH (FRAME_FONT (F))
653
654 /* This gives the x_display_info structure for the display F is on. */
655 #define FRAME_X_DISPLAY_INFO(f) ((f)->output_data.x->display_info)
656
657 /* This is the `Display *' which frame F is on. */
658 #define FRAME_X_DISPLAY(f) (FRAME_X_DISPLAY_INFO (f)->display)
659
660 /* This is the `Screen *' which frame F is on. */
661 #define FRAME_X_SCREEN(f) (FRAME_X_DISPLAY_INFO (f)->screen)
662 #define FRAME_X_SCREEN_NUMBER(f) XScreenNumberOfScreen (FRAME_X_SCREEN (f))
663
664 /* This is the Visual which frame F is on. */
665 #define FRAME_X_VISUAL(f) FRAME_X_DISPLAY_INFO (f)->visual
666
667 /* This is the Colormap which frame F uses. */
668 #define FRAME_X_COLORMAP(f) FRAME_X_DISPLAY_INFO (f)->cmap
669
670 /* This is the 'font_info *' which frame F has. */
671 #define FRAME_X_FONT_TABLE(f) (FRAME_X_DISPLAY_INFO (f)->font_table)
672
673 /* These two really ought to be called FRAME_PIXEL_{WIDTH,HEIGHT}. */
674 #define PIXEL_WIDTH(f) ((f)->output_data.x->pixel_width)
675 #define PIXEL_HEIGHT(f) ((f)->output_data.x->pixel_height)
676
677 #define FRAME_XIC(f) ((f)->output_data.x->xic)
678 #define FRAME_X_XIM(f) (FRAME_X_DISPLAY_INFO (f)->xim)
679 #define FRAME_X_XIM_STYLES(f) (FRAME_X_DISPLAY_INFO (f)->xim_styles)
680 #define FRAME_XIC_STYLE(f) ((f)->output_data.x->xic_style)
681 #define FRAME_XIC_FONTSET(f) ((f)->output_data.x->xic_xfs)
682
683 /* Value is the smallest width of any character in any font on frame F. */
684
685 #define FRAME_SMALLEST_CHAR_WIDTH(F) \
686 FRAME_X_DISPLAY_INFO(F)->smallest_char_width
687
688 /* Value is the smallest height of any font on frame F. */
689
690 #define FRAME_SMALLEST_FONT_HEIGHT(F) \
691 FRAME_X_DISPLAY_INFO(F)->smallest_font_height
692
693 /* Return a pointer to the image cache of frame F. */
694
695 #define FRAME_X_IMAGE_CACHE(F) FRAME_X_DISPLAY_INFO ((F))->image_cache
696
697 \f
698 /* Total width of fringes reserved for drawing truncation bitmaps,
699 continuation bitmaps and alike. The width is in canonical char
700 units of the frame. This must currently be the case because window
701 sizes aren't pixel values. If it weren't the case, we wouldn't be
702 able to split windows horizontally nicely. */
703
704 #define FRAME_X_FRINGE_COLS(F) ((F)->output_data.x->fringe_cols)
705
706 /* Total width of fringes in pixels. */
707
708 #define FRAME_X_FRINGE_WIDTH(F) ((F)->output_data.x->fringes_extra)
709
710 /* Pixel-width of the left and right fringe. */
711
712 #define FRAME_X_LEFT_FRINGE_WIDTH(F) ((F)->output_data.x->left_fringe_width)
713 #define FRAME_X_RIGHT_FRINGE_WIDTH(F) ((F)->output_data.x->right_fringe_width)
714
715
716 \f
717 /* X-specific scroll bar stuff. */
718
719 /* We represent scroll bars as lisp vectors. This allows us to place
720 references to them in windows without worrying about whether we'll
721 end up with windows referring to dead scroll bars; the garbage
722 collector will free it when its time comes.
723
724 We use struct scroll_bar as a template for accessing fields of the
725 vector. */
726
727 struct scroll_bar
728 {
729 /* These fields are shared by all vectors. */
730 EMACS_INT size_from_Lisp_Vector_struct;
731 struct Lisp_Vector *next_from_Lisp_Vector_struct;
732
733 /* The window we're a scroll bar for. */
734 Lisp_Object window;
735
736 /* The next and previous in the chain of scroll bars in this frame. */
737 Lisp_Object next, prev;
738
739 /* The X window representing this scroll bar. Since this is a full
740 32-bit quantity, we store it split into two 32-bit values. */
741 Lisp_Object x_window_low, x_window_high;
742
743 /* The position and size of the scroll bar in pixels, relative to the
744 frame. */
745 Lisp_Object top, left, width, height;
746
747 /* The starting and ending positions of the handle, relative to the
748 handle area (i.e. zero is the top position, not
749 SCROLL_BAR_TOP_BORDER). If they're equal, that means the handle
750 hasn't been drawn yet.
751
752 These are not actually the locations where the beginning and end
753 are drawn; in order to keep handles from becoming invisible when
754 editing large files, we establish a minimum height by always
755 drawing handle bottoms VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
756 where they would be normally; the bottom and top are in a
757 different co-ordinate system. */
758 Lisp_Object start, end;
759
760 /* If the scroll bar handle is currently being dragged by the user,
761 this is the number of pixels from the top of the handle to the
762 place where the user grabbed it. If the handle isn't currently
763 being dragged, this is Qnil. */
764 Lisp_Object dragging;
765 };
766
767 /* The number of elements a vector holding a struct scroll_bar needs. */
768 #define SCROLL_BAR_VEC_SIZE \
769 ((sizeof (struct scroll_bar) \
770 - sizeof (EMACS_INT) - sizeof (struct Lisp_Vector *)) \
771 / sizeof (Lisp_Object))
772
773 /* Turning a lisp vector value into a pointer to a struct scroll_bar. */
774 #define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec))
775
776
777 /* Building a 32-bit C integer from two 16-bit lisp integers. */
778 #define SCROLL_BAR_PACK(low, high) (XINT (high) << 16 | XINT (low))
779
780 /* Setting two lisp integers to the low and high words of a 32-bit C int. */
781 #define SCROLL_BAR_UNPACK(low, high, int32) \
782 (XSETINT ((low), (int32) & 0xffff), \
783 XSETINT ((high), ((int32) >> 16) & 0xffff))
784
785
786 /* Extract the X window id of the scroll bar from a struct scroll_bar. */
787 #define SCROLL_BAR_X_WINDOW(ptr) \
788 ((Window) SCROLL_BAR_PACK ((ptr)->x_window_low, (ptr)->x_window_high))
789
790 /* Store a window id in a struct scroll_bar. */
791 #define SET_SCROLL_BAR_X_WINDOW(ptr, id) \
792 (SCROLL_BAR_UNPACK ((ptr)->x_window_low, (ptr)->x_window_high, (int) id))
793
794 /* Extract the X widget of the scroll bar from a struct scroll_bar.
795 XtWindowToWidget should be fast enough since Xt uses a hash table
796 to map windows to widgets. */
797
798 #define SCROLL_BAR_X_WIDGET(dpy, ptr) \
799 XtWindowToWidget (dpy, SCROLL_BAR_X_WINDOW (ptr))
800
801 /* Store a widget id in a struct scroll_bar. */
802
803 #define SET_SCROLL_BAR_X_WIDGET(ptr, w) \
804 do { \
805 Window window = XtWindow (w); \
806 SET_SCROLL_BAR_X_WINDOW (ptr, window); \
807 } while (0)
808
809
810 /* Return the inside width of a vertical scroll bar, given the outside
811 width. */
812 #define VERTICAL_SCROLL_BAR_INSIDE_WIDTH(f, width) \
813 ((width) \
814 - VERTICAL_SCROLL_BAR_LEFT_BORDER \
815 - VERTICAL_SCROLL_BAR_RIGHT_BORDER \
816 - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2)
817
818 /* Return the length of the rectangle within which the top of the
819 handle must stay. This isn't equivalent to the inside height,
820 because the scroll bar handle has a minimum height.
821
822 This is the real range of motion for the scroll bar, so when we're
823 scaling buffer positions to scroll bar positions, we use this, not
824 VERTICAL_SCROLL_BAR_INSIDE_HEIGHT. */
825 #define VERTICAL_SCROLL_BAR_TOP_RANGE(f, height) \
826 (VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, height) - VERTICAL_SCROLL_BAR_MIN_HANDLE)
827
828 /* Return the inside height of vertical scroll bar, given the outside
829 height. See VERTICAL_SCROLL_BAR_TOP_RANGE too. */
830 #define VERTICAL_SCROLL_BAR_INSIDE_HEIGHT(f, height) \
831 ((height) - VERTICAL_SCROLL_BAR_TOP_BORDER - VERTICAL_SCROLL_BAR_BOTTOM_BORDER)
832
833
834 /* Border widths for scroll bars.
835
836 Scroll bar windows don't have any X borders; their border width is
837 set to zero, and we redraw borders ourselves. This makes the code
838 a bit cleaner, since we don't have to convert between outside width
839 (used when relating to the rest of the screen) and inside width
840 (used when sizing and drawing the scroll bar window itself).
841
842 The handle moves up and down/back and forth in a rectangle inset
843 from the edges of the scroll bar. These are widths by which we
844 inset the handle boundaries from the scroll bar edges. */
845 #define VERTICAL_SCROLL_BAR_LEFT_BORDER (2)
846 #define VERTICAL_SCROLL_BAR_RIGHT_BORDER (2)
847 #define VERTICAL_SCROLL_BAR_TOP_BORDER (2)
848 #define VERTICAL_SCROLL_BAR_BOTTOM_BORDER (2)
849
850 /* Minimum lengths for scroll bar handles, in pixels. */
851 #define VERTICAL_SCROLL_BAR_MIN_HANDLE (5)
852
853 /* Trimming off a few pixels from each side prevents
854 text from glomming up against the scroll bar */
855 #define VERTICAL_SCROLL_BAR_WIDTH_TRIM (0)
856
857 \f
858 /* Manipulating pixel sizes and character sizes.
859 Knowledge of which factors affect the overall size of the window should
860 be hidden in these macros, if that's possible.
861
862 Return the upper/left pixel position of the character cell on frame F
863 at ROW/COL. */
864 #define CHAR_TO_PIXEL_ROW(f, row) \
865 ((f)->output_data.x->internal_border_width \
866 + (row) * (f)->output_data.x->line_height)
867 #define CHAR_TO_PIXEL_COL(f, col) \
868 ((f)->output_data.x->internal_border_width \
869 + (col) * FONT_WIDTH ((f)->output_data.x->font))
870
871 /* Return the pixel width/height of frame F if it has
872 WIDTH columns/HEIGHT rows. */
873 #define CHAR_TO_PIXEL_WIDTH(f, width) \
874 (CHAR_TO_PIXEL_COL (f, width) \
875 + (f)->output_data.x->vertical_scroll_bar_extra \
876 + (f)->output_data.x->fringes_extra \
877 + (f)->output_data.x->internal_border_width)
878 #define CHAR_TO_PIXEL_HEIGHT(f, height) \
879 (CHAR_TO_PIXEL_ROW (f, height) \
880 + (f)->output_data.x->internal_border_width)
881
882
883 /* Return the row/column (zero-based) of the character cell containing
884 the pixel on FRAME at ROW/COL. */
885 #define PIXEL_TO_CHAR_ROW(f, row) \
886 (((row) - (f)->output_data.x->internal_border_width) \
887 / (f)->output_data.x->line_height)
888 #define PIXEL_TO_CHAR_COL(f, col) \
889 (((col) - (f)->output_data.x->internal_border_width) \
890 / FONT_WIDTH ((f)->output_data.x->font))
891
892 /* How many columns/rows of text can we fit in WIDTH/HEIGHT pixels on
893 frame F? */
894 #define PIXEL_TO_CHAR_WIDTH(f, width) \
895 (PIXEL_TO_CHAR_COL (f, ((width) \
896 - (f)->output_data.x->internal_border_width \
897 - (f)->output_data.x->fringes_extra \
898 - (f)->output_data.x->vertical_scroll_bar_extra)))
899 #define PIXEL_TO_CHAR_HEIGHT(f, height) \
900 (PIXEL_TO_CHAR_ROW (f, ((height) \
901 - (f)->output_data.x->internal_border_width)))
902
903 \f
904 /* If a struct input_event has a kind which is SELECTION_REQUEST_EVENT
905 or SELECTION_CLEAR_EVENT, then its contents are really described
906 by this structure. */
907
908 /* For an event of kind SELECTION_REQUEST_EVENT,
909 this structure really describes the contents.
910 **Don't make this struct longer!**
911 If it overlaps the frame_or_window field of struct input_event,
912 that will cause GC to crash. */
913 struct selection_input_event
914 {
915 int kind;
916 Display *display;
917 /* We spell it with an "o" here because X does. */
918 Window requestor;
919 Atom selection, target, property;
920 Time time;
921 };
922
923 #define SELECTION_EVENT_DISPLAY(eventp) \
924 (((struct selection_input_event *) (eventp))->display)
925 /* We spell it with an "o" here because X does. */
926 #define SELECTION_EVENT_REQUESTOR(eventp) \
927 (((struct selection_input_event *) (eventp))->requestor)
928 #define SELECTION_EVENT_SELECTION(eventp) \
929 (((struct selection_input_event *) (eventp))->selection)
930 #define SELECTION_EVENT_TARGET(eventp) \
931 (((struct selection_input_event *) (eventp))->target)
932 #define SELECTION_EVENT_PROPERTY(eventp) \
933 (((struct selection_input_event *) (eventp))->property)
934 #define SELECTION_EVENT_TIME(eventp) \
935 (((struct selection_input_event *) (eventp))->time)
936
937 \f
938 struct window;
939 struct glyph_matrix;
940 struct frame;
941 struct input_event;
942 struct face;
943 struct image;
944
945 /* From xselect.c. */
946
947 void x_handle_selection_notify P_ ((XSelectionEvent *));
948 void x_handle_property_notify P_ ((XPropertyEvent *));
949
950 /* From xfns.c. */
951
952 Lisp_Object display_x_get_resource P_ ((struct x_display_info *,
953 Lisp_Object, Lisp_Object,
954 Lisp_Object, Lisp_Object));
955 struct frame *check_x_frame P_ ((Lisp_Object));
956 EXFUN (Fx_display_color_p, 1);
957 EXFUN (Fx_display_grayscale_p, 1);
958 int image_ascent P_ ((struct image *, struct face *));
959 extern void x_free_gcs P_ ((struct frame *));
960
961 /* From xrdb.c. */
962
963 char *x_get_string_resource P_ ((XrmDatabase, char *, char *));
964 char *x_get_customization_string P_ ((XrmDatabase, char *, char *));
965 XrmDatabase x_load_resources P_ ((Display *, char *, char *, char *));
966 int x_get_resource P_ ((XrmDatabase, char *, char *,
967 XrmRepresentation, XrmValue *));
968 void x_delete_display P_ ((struct x_display_info *));
969 void x_make_frame_visible P_ ((struct frame *));
970 void x_iconify_frame P_ ((struct frame *));
971 void x_wm_set_size_hint P_ ((struct frame *, long, int));
972 void x_set_offset P_ ((struct frame *, int, int, int));
973 void x_wm_set_icon_position P_ ((struct frame *, int, int));
974 int x_catch_errors P_ ((Display *));
975 int x_had_errors_p P_ ((Display *));
976 void x_uncatch_errors P_ ((Display *, int));
977 void x_check_errors P_ ((Display *, char *));
978 int x_text_icon P_ ((struct frame *, char *));
979 int x_bitmap_icon P_ ((struct frame *, Lisp_Object));
980 void x_set_window_size P_ ((struct frame *, int, int, int));
981 void x_wm_set_window_state P_ ((struct frame *, int));
982 int x_alloc_nearest_color P_ ((struct frame *, Colormap, XColor *));
983
984 extern void pixel_to_glyph_coords P_ ((struct frame *, int, int,
985 int *, int *, XRectangle *, int));
986
987 /* Defined in xterm.c */
988
989 extern void cancel_mouse_face P_ ((struct frame *));
990 extern void x_scroll_bar_clear P_ ((struct frame *));
991 extern void x_start_queuing_selection_requests P_ ((Display *));
992 extern void x_stop_queuing_selection_requests P_ ((Display *));
993 extern void x_update_cursor P_ ((struct frame *, int));
994 extern int x_text_icon P_ ((struct frame *, char *));
995 extern int x_bitmap_icon P_ ((struct frame *, Lisp_Object));
996 extern int x_catch_errors P_ ((Display *));
997 extern void x_check_errors P_ ((Display *, char *));
998 extern int x_had_errors_p P_ ((Display *));
999 extern void x_uncatch_errors P_ ((Display *, int));
1000 extern Lisp_Object x_new_font P_ ((struct frame *, char *));
1001 extern Lisp_Object x_new_fontset P_ ((struct frame *, char *));
1002 extern void x_compute_fringe_widths P_ ((struct frame *, int));
1003 extern void x_set_offset P_ ((struct frame *, int, int, int));
1004 extern void x_set_window_size P_ ((struct frame *, int, int, int));
1005 extern void x_set_mouse_position P_ ((struct frame *, int, int));
1006 extern void x_set_mouse_pixel_position P_ ((struct frame *, int, int));
1007 extern void x_raise_frame P_ ((struct frame *));
1008 extern void x_lower_frame P_ ((struct frame *));
1009 extern void x_make_frame_visible P_ ((struct frame *));
1010 extern void x_make_frame_invisible P_ ((struct frame *));
1011 extern void x_iconify_frame P_ ((struct frame *));
1012 extern void x_free_frame_resources P_ ((struct frame *));
1013 extern void x_destroy_window P_ ((struct frame *));
1014 extern void x_wm_set_size_hint P_ ((struct frame *, long, int));
1015 extern void x_wm_set_window_state P_ ((struct frame *, int));
1016 extern void x_wm_set_icon_pixmap P_ ((struct frame *, int));
1017 extern void x_wm_set_icon_position P_ ((struct frame *, int, int));
1018 extern void x_delete_display P_ ((struct x_display_info *));
1019 extern void x_initialize P_ ((void));
1020 extern void x_display_cursor P_ ((struct window *, int, int, int, int, int));
1021 extern unsigned long x_copy_color P_ ((struct frame *, unsigned long));
1022 #ifdef USE_X_TOOLKIT
1023 extern XtAppContext Xt_app_con;
1024 #endif
1025 extern void x_query_colors P_ ((struct frame *f, XColor *, int));
1026 extern void x_query_color P_ ((struct frame *f, XColor *));
1027 extern void x_clear_area P_ ((Display *, Window, int, int, int, int, int));
1028
1029 extern void x_fullscreen_adjust P_ ((struct frame *f, int *, int *,
1030 int *, int *));
1031
1032
1033 /* Defined in xselect.c */
1034
1035 extern void x_handle_property_notify P_ ((XPropertyEvent *));
1036 extern void x_handle_selection_notify P_ ((XSelectionEvent *));
1037 extern void x_handle_selection_request P_ ((struct input_event *));
1038 extern void x_handle_selection_clear P_ ((struct input_event *));
1039 extern void x_clear_frame_selections P_ ((struct frame *));
1040
1041 /* Defined in xfns.c */
1042
1043 extern int have_menus_p P_ ((void));
1044 extern int x_bitmap_height P_ ((struct frame *, int));
1045 extern int x_bitmap_width P_ ((struct frame *, int));
1046 extern int x_bitmap_pixmap P_ ((struct frame *, int));
1047 extern void x_reference_bitmap P_ ((struct frame *, int));
1048 extern int x_create_bitmap_from_data P_ ((struct frame *, char *,
1049 unsigned int, unsigned int));
1050 extern int x_create_bitmap_from_file P_ ((struct frame *, Lisp_Object));
1051 extern void x_destroy_bitmap P_ ((struct frame *, int));
1052 extern void x_set_frame_parameters P_ ((struct frame *, Lisp_Object));
1053 extern void x_real_positions P_ ((struct frame *, int *, int *));
1054 extern void x_report_frame_params P_ ((struct frame *, Lisp_Object *));
1055 extern int defined_color P_ ((struct frame *, char *, XColor *, int));
1056 extern void x_set_border_pixel P_ ((struct frame *, int));
1057 extern void x_set_menu_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object));
1058 extern unsigned char * x_encode_text P_ ((Lisp_Object, Lisp_Object, int,
1059 int *, int *));
1060 extern void x_implicitly_set_name P_ ((struct frame *, Lisp_Object, Lisp_Object));
1061 extern void create_frame_xic P_ ((struct frame *));
1062 extern void destroy_frame_xic P_ ((struct frame *));
1063 extern void xic_set_preeditarea P_ ((struct window *, int, int));
1064 extern void xic_set_statusarea P_ ((struct frame *));
1065 extern void xic_set_xfontset P_ ((struct frame *, char *));
1066 extern int x_pixel_width P_ ((struct frame *));
1067 extern int x_pixel_height P_ ((struct frame *));
1068 extern int x_char_width P_ ((struct frame *));
1069 extern int x_char_height P_ ((struct frame *));
1070 extern int x_screen_planes P_ ((struct frame *));
1071 extern void x_sync P_ ((struct frame *));
1072 extern int x_defined_color P_ ((struct frame *, char *, XColor *, int));
1073 #ifdef HAVE_X_I18N
1074 extern void free_frame_xic P_ ((struct frame *));
1075 #endif
1076 extern void x_set_tool_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object));
1077
1078 /* Defined in xfaces.c */
1079
1080 extern int frame_update_line_height P_ ((struct frame *));
1081 extern int compute_glyph_face P_ ((struct frame *, int, int));
1082 extern int compute_glyph_face_1 P_ ((struct frame *, Lisp_Object, int));
1083 extern void x_free_dpy_colors P_ ((Display *, Screen *, Colormap,
1084 unsigned long *, int));
1085
1086 /* Defined in xmenu.c */
1087
1088 extern void x_activate_menubar P_ ((struct frame *));
1089 extern int popup_activated P_ ((void));
1090 extern void initialize_frame_menubar P_ ((struct frame *));
1091
1092 /* Defined in widget.c */
1093
1094 #ifdef USE_X_TOOLKIT
1095 extern void widget_store_internal_border P_ ((Widget));
1096 #endif
1097
1098 /* Defined in xsmfns.c */
1099 #ifdef HAVE_X_SM
1100 extern void x_session_initialize P_ ((void));
1101 extern int x_session_check_input P_ ((struct input_event *bufp,
1102 int *numchars));
1103 extern int x_session_have_connection P_ ((void));
1104 #endif