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