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