* configure.ac: Move the OSX 10.6 test.
[emacs.git] / src / xterm.h
blobed611f1d19fa16bc31ef46f173b02afd55e37cc9
1 /* Definitions and headers for communication with X protocol.
2 Copyright (C) 1989, 1993-1994, 1998-2014 Free Software Foundation,
3 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 3 of the License, or
10 (at your option) 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. If not, see <http://www.gnu.org/licenses/>. */
20 #ifndef XTERM_H
21 #define XTERM_H
23 #include <X11/Xlib.h>
24 #include <X11/cursorfont.h>
26 /* Include Xutil.h after keysym.h to work around a bug that prevents
27 correct recognition of AltGr key in some X versions. */
29 #include <X11/keysym.h>
30 #include <X11/Xutil.h>
32 #include <X11/Xatom.h>
33 #include <X11/Xresource.h>
35 #ifdef USE_X_TOOLKIT
36 #include <X11/StringDefs.h>
37 #include <X11/IntrinsicP.h> /* CoreP.h needs this */
38 #include <X11/CoreP.h> /* foul, but we need this to use our own
39 window inside a widget instead of one
40 that Xt creates... */
41 typedef Widget xt_or_gtk_widget;
42 #endif
44 #ifdef USE_GTK
45 #include <gtk/gtk.h>
46 #include <gdk/gdkx.h>
48 /* Some definitions to reduce conditionals. */
49 typedef GtkWidget *xt_or_gtk_widget;
50 #undef XSync
51 #define XSync(d, b) do { gdk_window_process_all_updates (); \
52 XSync (d, b); } while (false)
53 #endif /* USE_GTK */
55 /* True iff GTK's version is at least I.J.K. */
56 #ifndef GTK_CHECK_VERSION
57 # ifdef USE_GTK
58 # define GTK_CHECK_VERSION(i, j, k) \
59 ((i) \
60 < GTK_MAJOR_VERSION + ((j) \
61 < GTK_MINOR_VERSION + ((k) \
62 <= GTK_MICRO_VERSION)))
63 # else
64 # define GTK_CHECK_VERSION(i, j, k) false
65 # endif
66 #endif
68 /* The GtkTooltip API came in 2.12, but gtk-enable-tooltips in 2.14. */
69 #if GTK_CHECK_VERSION (2, 14, 0)
70 #define USE_GTK_TOOLTIP
71 #endif
73 #ifdef HAVE_X_I18N
74 #include <X11/Xlocale.h>
75 #endif
77 #include "dispextern.h"
78 #include "termhooks.h"
80 INLINE_HEADER_BEGIN
82 /* Black and white pixel values for the screen which frame F is on. */
83 #define BLACK_PIX_DEFAULT(f) \
84 BlackPixel (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f))
85 #define WHITE_PIX_DEFAULT(f) \
86 WhitePixel (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f))
88 /* The mask of events that text windows always want to receive. This
89 includes mouse movement events, since handling the mouse-font text property
90 means that we must track mouse motion all the time. */
92 #define STANDARD_EVENT_SET \
93 (KeyPressMask \
94 | ExposureMask \
95 | ButtonPressMask \
96 | ButtonReleaseMask \
97 | PointerMotionMask \
98 | StructureNotifyMask \
99 | FocusChangeMask \
100 | LeaveWindowMask \
101 | EnterWindowMask \
102 | VisibilityChangeMask)
104 #ifdef HAVE_X11R6_XIM
105 /* Data structure passed to xim_instantiate_callback. */
106 struct xim_inst_t
108 struct x_display_info *dpyinfo;
109 char *resource_name;
111 #endif /* HAVE_X11R6_XIM */
113 /* Structure recording X pixmap and reference count.
114 If REFCOUNT is 0 then this record is free to be reused. */
116 struct x_bitmap_record
118 Pixmap pixmap;
119 bool have_mask;
120 Pixmap mask;
121 char *file;
122 int refcount;
123 /* Record some info about this pixmap. */
124 int height, width, depth;
127 /* For each X display, we have a structure that records
128 information about it. */
130 struct x_display_info
132 /* Chain of all x_display_info structures. */
133 struct x_display_info *next;
135 /* The generic display parameters corresponding to this X display. */
136 struct terminal *terminal;
138 /* This says how to access this display in Xlib. */
139 Display *display;
141 /* A connection number (file descriptor) for the display. */
142 int connection;
144 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE). */
145 Lisp_Object name_list_element;
147 /* Number of frames that are on this display. */
148 int reference_count;
150 /* The Screen this connection is connected to. */
151 Screen *screen;
153 /* Dots per inch of the screen. */
154 double resx, resy;
156 /* The Visual being used for this display. */
157 Visual *visual;
159 /* The colormap being used. */
160 Colormap cmap;
162 /* Number of planes on this screen. */
163 int n_planes;
165 /* Mask of things that cause the mouse to be grabbed. */
166 int grabbed;
168 /* Emacs bitmap-id of the default icon bitmap for this frame.
169 Or -1 if none has been allocated yet. */
170 ptrdiff_t icon_bitmap_id;
172 /* The root window of this screen. */
173 Window root_window;
175 /* Client leader window. */
176 Window client_leader_window;
178 /* The cursor to use for vertical scroll bars. */
179 Cursor vertical_scroll_bar_cursor;
181 /* The cursor to use for horizontal scroll bars. */
182 Cursor horizontal_scroll_bar_cursor;
184 /* The invisible cursor used for pointer blanking.
185 Unused if this display supports Xfixes extension. */
186 Cursor invisible_cursor;
188 /* Function used to toggle pointer visibility on this display. */
189 void (*toggle_visible_pointer) (struct frame *, bool);
191 #ifdef USE_GTK
192 /* The GDK cursor for scroll bars and popup menus. */
193 GdkCursor *xg_cursor;
194 #endif
196 /* X Resource data base */
197 XrmDatabase xrdb;
199 /* Minimum width over all characters in all fonts in font_table. */
200 int smallest_char_width;
202 /* Minimum font height over all fonts in font_table. */
203 int smallest_font_height;
205 /* Reusable Graphics Context for drawing a cursor in a non-default face. */
206 GC scratch_cursor_gc;
208 /* Information about the range of text currently shown in
209 mouse-face. */
210 Mouse_HLInfo mouse_highlight;
212 /* Logical identifier of this display. */
213 unsigned x_id;
215 /* Default name for all frames on this display. */
216 char *x_id_name;
218 /* The number of fonts opened for this display. */
219 int n_fonts;
221 /* Pointer to bitmap records. */
222 struct x_bitmap_record *bitmaps;
224 /* Allocated size of bitmaps field. */
225 ptrdiff_t bitmaps_size;
227 /* Last used bitmap index. */
228 ptrdiff_t bitmaps_last;
230 /* Which modifier keys are on which modifier bits?
232 With each keystroke, X returns eight bits indicating which modifier
233 keys were held down when the key was pressed. The interpretation
234 of the top five modifier bits depends on what keys are attached
235 to them. If the Meta_L and Meta_R keysyms are on mod5, then mod5
236 is the meta bit.
238 meta_mod_mask is a mask containing the bits used for the meta key.
239 It may have more than one bit set, if more than one modifier bit
240 has meta keys on it. Basically, if EVENT is a KeyPress event,
241 the meta key is pressed if (EVENT.state & meta_mod_mask) != 0.
243 shift_lock_mask is LockMask if the XK_Shift_Lock keysym is on the
244 lock modifier bit, or zero otherwise. Non-alphabetic keys should
245 only be affected by the lock modifier bit if XK_Shift_Lock is in
246 use; XK_Caps_Lock should only affect alphabetic keys. With this
247 arrangement, the lock modifier should shift the character if
248 (EVENT.state & shift_lock_mask) != 0. */
249 int meta_mod_mask, shift_lock_mask;
251 /* These are like meta_mod_mask, but for different modifiers. */
252 int alt_mod_mask, super_mod_mask, hyper_mod_mask;
254 /* Communication with window managers. */
255 Atom Xatom_wm_protocols;
257 /* Kinds of protocol things we may receive. */
258 Atom Xatom_wm_take_focus;
259 Atom Xatom_wm_save_yourself;
260 Atom Xatom_wm_delete_window;
262 /* Atom for indicating window state to the window manager. */
263 Atom Xatom_wm_change_state;
265 /* Other WM communication */
266 Atom Xatom_wm_configure_denied; /* When our config request is denied */
267 Atom Xatom_wm_window_moved; /* When the WM moves us. */
268 Atom Xatom_wm_client_leader; /* Id of client leader window. */
270 /* EditRes protocol */
271 Atom Xatom_editres;
273 /* More atoms, which are selection types. */
274 Atom Xatom_CLIPBOARD, Xatom_TIMESTAMP, Xatom_TEXT, Xatom_DELETE,
275 Xatom_COMPOUND_TEXT, Xatom_UTF8_STRING,
276 Xatom_MULTIPLE, Xatom_INCR, Xatom_EMACS_TMP, Xatom_TARGETS, Xatom_NULL,
277 Xatom_ATOM, Xatom_ATOM_PAIR, Xatom_CLIPBOARD_MANAGER;
279 /* More atoms for font properties. The last three are private
280 properties, see the comments in src/fontset.h. */
281 Atom Xatom_PIXEL_SIZE, Xatom_AVERAGE_WIDTH,
282 Xatom_MULE_BASELINE_OFFSET, Xatom_MULE_RELATIVE_COMPOSE,
283 Xatom_MULE_DEFAULT_ASCENT;
285 /* More atoms for Ghostscript support. */
286 Atom Xatom_DONE, Xatom_PAGE;
288 /* Atoms used in toolkit scroll bar client messages. */
289 Atom Xatom_Scrollbar, Xatom_Horizontal_Scrollbar;
291 /* Atom used in XEmbed client messages. */
292 Atom Xatom_XEMBED, Xatom_XEMBED_INFO;
294 /* The frame (if any) which has the X window that has keyboard focus.
295 Zero if none. This is examined by Ffocus_frame in xfns.c. Note
296 that a mere EnterNotify event can set this; if you need to know the
297 last frame specified in a FocusIn or FocusOut event, use
298 x_focus_event_frame. */
299 struct frame *x_focus_frame;
301 /* The last frame mentioned in a FocusIn or FocusOut event. This is
302 separate from x_focus_frame, because whether or not LeaveNotify
303 events cause us to lose focus depends on whether or not we have
304 received a FocusIn event for it. */
305 struct frame *x_focus_event_frame;
307 /* The frame which currently has the visual highlight, and should get
308 keyboard input (other sorts of input have the frame encoded in the
309 event). It points to the X focus frame's selected window's
310 frame. It differs from x_focus_frame when we're using a global
311 minibuffer. */
312 struct frame *x_highlight_frame;
314 /* The frame waiting to be auto-raised in XTread_socket. */
315 struct frame *x_pending_autoraise_frame;
317 /* The frame where the mouse was last time we reported a ButtonPress event. */
318 struct frame *last_mouse_frame;
320 /* The frame where the mouse was last time we reported a mouse position. */
321 struct frame *last_mouse_glyph_frame;
323 /* The frame where the mouse was last time we reported a mouse motion. */
324 struct frame *last_mouse_motion_frame;
326 /* The scroll bar in which the last X motion event occurred. */
327 struct scroll_bar *last_mouse_scroll_bar;
329 /* Time of last user interaction as returned in X events on this display. */
330 Time last_user_time;
332 /* Position where the mouse was last time we reported a motion.
333 This is a position on last_mouse_motion_frame. */
334 int last_mouse_motion_x;
335 int last_mouse_motion_y;
337 /* Where the mouse was last time we reported a mouse position.
338 This is a rectangle on last_mouse_glyph_frame. */
339 XRectangle last_mouse_glyph;
341 /* Time of last mouse movement on this display. This is a hack because
342 we would really prefer that XTmouse_position would return the time
343 associated with the position it returns, but there doesn't seem to be
344 any way to wrest the time-stamp from the server along with the position
345 query. So, we just keep track of the time of the last movement we
346 received, and return that in hopes that it's somewhat accurate. */
347 Time last_mouse_movement_time;
349 /* The gray pixmap. */
350 Pixmap gray;
352 #ifdef HAVE_X_I18N
353 /* XIM (X Input method). */
354 XIM xim;
355 XIMStyles *xim_styles;
356 struct xim_inst_t *xim_callback_data;
357 #endif
359 /* If non-null, a cache of the colors in the color map. Don't
360 use this directly, call x_color_cells instead. */
361 XColor *color_cells;
362 int ncolor_cells;
364 /* Bits and shifts to use to compose pixel values on TrueColor visuals. */
365 int red_bits, blue_bits, green_bits;
366 int red_offset, blue_offset, green_offset;
368 /* The type of window manager we have. If we move FRAME_OUTER_WINDOW
369 to x/y 0/0, some window managers (type A) puts the window manager
370 decorations outside the screen and FRAME_OUTER_WINDOW exactly at 0/0.
371 Other window managers (type B) puts the window including decorations
372 at 0/0, so FRAME_OUTER_WINDOW is a bit below 0/0.
373 Record the type of WM in use so we can compensate for type A WMs. */
374 enum
376 X_WMTYPE_UNKNOWN,
377 X_WMTYPE_A,
378 X_WMTYPE_B
379 } wm_type;
382 /* Atoms that are drag and drop atoms */
383 Atom *x_dnd_atoms;
384 ptrdiff_t x_dnd_atoms_size;
385 ptrdiff_t x_dnd_atoms_length;
387 /* Extended window manager hints, Atoms supported by the window manager and
388 atoms for setting the window type. */
389 Atom Xatom_net_supported, Xatom_net_supporting_wm_check;
390 Atom *net_supported_atoms;
391 int nr_net_supported_atoms;
392 Window net_supported_window;
393 Atom Xatom_net_window_type, Xatom_net_window_type_tooltip;
394 Atom Xatom_net_active_window;
396 /* Atoms dealing with EWMH (i.e. _NET_...) */
397 Atom Xatom_net_wm_state, Xatom_net_wm_state_fullscreen,
398 Xatom_net_wm_state_maximized_horz, Xatom_net_wm_state_maximized_vert,
399 Xatom_net_wm_state_sticky, Xatom_net_wm_state_hidden,
400 Xatom_net_frame_extents,
401 Xatom_net_current_desktop, Xatom_net_workarea;
403 /* XSettings atoms and windows. */
404 Atom Xatom_xsettings_sel, Xatom_xsettings_prop, Xatom_xsettings_mgr;
405 Window xsettings_window;
407 /* Frame name and icon name */
408 Atom Xatom_net_wm_name, Xatom_net_wm_icon_name;
409 /* Frame opacity */
410 Atom Xatom_net_wm_window_opacity;
412 /* SM */
413 Atom Xatom_SM_CLIENT_ID;
416 #ifdef HAVE_X_I18N
417 /* Whether or not to use XIM if we have it. */
418 extern bool use_xim;
419 #endif
421 /* This is a chain of structures for all the X displays currently in use. */
422 extern struct x_display_info *x_display_list;
424 extern struct x_display_info *x_display_info_for_display (Display *);
425 extern struct frame *x_top_window_to_frame (struct x_display_info *, int);
426 extern struct x_display_info *x_term_init (Lisp_Object, char *, char *);
427 extern bool x_display_ok (const char *);
429 extern void select_visual (struct x_display_info *);
431 /* Each X frame object points to its own struct x_output object
432 in the output_data.x field. The x_output structure contains
433 the information that is specific to X windows. */
435 struct x_output
437 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
438 /* Height of menu bar widget, in pixels. This value
439 is not meaningful if the menubar is turned off. */
440 int menubar_height;
441 #endif
443 /* Height of tool bar widget, in pixels. top_height is used if tool bar
444 at top, bottom_height if tool bar is at the bottom.
445 Zero if not using an external tool bar or if tool bar is vertical. */
446 int toolbar_top_height, toolbar_bottom_height;
448 /* Width of tool bar widget, in pixels. left_width is used if tool bar
449 at left, right_width if tool bar is at the right.
450 Zero if not using an external tool bar or if tool bar is horizontal. */
451 int toolbar_left_width, toolbar_right_width;
453 /* The tiled border used when the mouse is out of the frame. */
454 Pixmap border_tile;
456 /* Here are the Graphics Contexts for the default font. */
457 GC normal_gc; /* Normal video */
458 GC reverse_gc; /* Reverse video */
459 GC cursor_gc; /* cursor drawing */
461 /* The X window used for this frame.
462 May be zero while the frame object is being created
463 and the X window has not yet been created. */
464 Window window_desc;
466 /* The X window used for the bitmap icon;
467 or 0 if we don't have a bitmap icon. */
468 Window icon_desc;
470 /* The X window that is the parent of this X window.
471 Usually this is a window that was made by the window manager,
472 but it can be the root window, and it can be explicitly specified
473 (see the explicit_parent field, below). */
474 Window parent_desc;
476 #ifdef USE_X_TOOLKIT
477 /* The widget of this screen. This is the window of a "shell" widget. */
478 Widget widget;
479 /* The XmPanedWindows... */
480 Widget column_widget;
481 /* The widget of the edit portion of this screen; the window in
482 "window_desc" is inside of this. */
483 Widget edit_widget;
485 Widget menubar_widget;
486 #endif
488 #ifdef USE_GTK
489 /* The widget of this screen. This is the window of a top widget. */
490 GtkWidget *widget;
491 /* The widget of the edit portion of this screen; the window in
492 "window_desc" is inside of this. */
493 GtkWidget *edit_widget;
494 /* The widget used for laying out widgets vertically. */
495 GtkWidget *vbox_widget;
496 /* The widget used for laying out widgets horizontally. */
497 GtkWidget *hbox_widget;
498 /* The menubar in this frame. */
499 GtkWidget *menubar_widget;
500 /* The tool bar in this frame */
501 GtkWidget *toolbar_widget;
502 #ifdef HAVE_GTK_HANDLE_BOX_NEW
503 /* The handle box that makes the tool bar detachable. */
504 GtkWidget *handlebox_widget;
505 #endif
506 /* True if tool bar is packed into the hbox widget (i.e. vertical). */
507 bool_bf toolbar_in_hbox : 1;
508 bool_bf toolbar_is_packed : 1;
510 /* The last size hints set. */
511 GdkGeometry size_hints;
512 long hint_flags;
514 #ifdef USE_GTK_TOOLTIP
515 GtkTooltip *ttip_widget;
516 GtkWidget *ttip_lbl;
517 GtkWindow *ttip_window;
518 #endif /* USE_GTK_TOOLTIP */
520 #endif /* USE_GTK */
522 /* If >=0, a bitmap index. The indicated bitmap is used for the
523 icon. */
524 ptrdiff_t icon_bitmap;
526 /* Default ASCII font of this frame. */
527 struct font *font;
529 /* The baseline offset of the default ASCII font. */
530 int baseline_offset;
532 /* If a fontset is specified for this frame instead of font, this
533 value contains an ID of the fontset, else -1. */
534 int fontset;
536 unsigned long cursor_pixel;
537 unsigned long border_pixel;
538 unsigned long mouse_pixel;
539 unsigned long cursor_foreground_pixel;
541 /* Foreground color for scroll bars. A value of -1 means use the
542 default (black for non-toolkit scroll bars). */
543 unsigned long scroll_bar_foreground_pixel;
545 /* Background color for scroll bars. A value of -1 means use the
546 default (background color of the frame for non-toolkit scroll
547 bars). */
548 unsigned long scroll_bar_background_pixel;
550 #if defined (USE_LUCID) && defined (USE_TOOLKIT_SCROLL_BARS)
551 /* Top and bottom shadow colors for 3D Lucid scrollbars.
552 -1 means let the scroll compute them itself. */
553 unsigned long scroll_bar_top_shadow_pixel;
554 unsigned long scroll_bar_bottom_shadow_pixel;
555 #endif
557 /* Descriptor for the cursor in use for this window. */
558 Cursor text_cursor;
559 Cursor nontext_cursor;
560 Cursor modeline_cursor;
561 Cursor hand_cursor;
562 Cursor hourglass_cursor;
563 Cursor horizontal_drag_cursor;
564 Cursor vertical_drag_cursor;
565 Cursor current_cursor;
567 /* Window whose cursor is hourglass_cursor. This window is temporarily
568 mapped to display an hourglass cursor. */
569 Window hourglass_window;
571 /* These are the current window manager hints. It seems that
572 XSetWMHints, when presented with an unset bit in the `flags'
573 member of the hints structure, does not leave the corresponding
574 attribute unchanged; rather, it resets that attribute to its
575 default value. For example, unless you set the `icon_pixmap'
576 field and the `IconPixmapHint' bit, XSetWMHints will forget what
577 your icon pixmap was. This is rather troublesome, since some of
578 the members (for example, `input' and `icon_pixmap') want to stay
579 the same throughout the execution of Emacs. So, we keep this
580 structure around, just leaving values in it and adding new bits
581 to the mask as we go. */
582 XWMHints wm_hints;
584 /* This is the Emacs structure for the X display this frame is on. */
585 struct x_display_info *display_info;
587 /* This is a button event that wants to activate the menubar.
588 We save it here until the command loop gets to think about it. */
589 XEvent *saved_menu_event;
591 /* This is the widget id used for this frame's menubar in lwlib. */
592 #ifdef USE_X_TOOLKIT
593 int id;
594 #endif
596 /* True means hourglass cursor is currently displayed. */
597 bool_bf hourglass_p : 1;
599 /* True means our parent is another application's window
600 and was explicitly specified. */
601 bool_bf explicit_parent : 1;
603 /* True means tried already to make this frame visible. */
604 bool_bf asked_for_visible : 1;
606 /* True if this frame was ever previously visible. */
607 bool_bf has_been_visible : 1;
609 /* Xt waits for a ConfigureNotify event from the window manager in
610 EmacsFrameSetCharSize when the shell widget is resized. For some
611 window managers like fvwm2 2.2.5 and KDE 2.1 this event doesn't
612 arrive for an unknown reason and Emacs hangs in Xt. If this is
613 false, tell Xt not to wait. */
614 bool_bf wait_for_wm : 1;
616 /* True if _NET_WM_STATE_HIDDEN is set for this frame. */
617 bool_bf net_wm_state_hidden_seen : 1;
619 #ifdef HAVE_X_I18N
620 /* Input context (currently, this means Compose key handler setup). */
621 XIC xic;
622 XIMStyle xic_style;
623 XFontSet xic_xfs;
624 #endif
626 /* Relief GCs, colors etc. */
627 struct relief
629 GC gc;
630 unsigned long pixel;
632 black_relief, white_relief;
634 /* The background for which the above relief GCs were set up.
635 They are changed only when a different background is involved. */
636 unsigned long relief_background;
638 /* As x_pixels_diff, but to FRAME_OUTER_WINDOW. For some reason the
639 two might differ by a pixel, depending on WM */
640 int x_pixels_outer_diff;
642 /* As y_pixels_diff, but to FRAME_OUTER_WINDOW. In the toolkit version,
643 these may differ because this does not take into account possible
644 menubar. y_pixels_diff is with menubar height included */
645 int y_pixels_outer_diff;
647 /* Keep track of focus. May be EXPLICIT if we received a FocusIn for this
648 frame, or IMPLICIT if we received an EnterNotify.
649 FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
650 int focus_state;
652 /* The offset we need to add to compensate for type A WMs. */
653 int move_offset_top;
654 int move_offset_left;
657 /* Extreme 'short' and 'long' values suitable for libX11. */
658 #define X_SHRT_MAX 0x7fff
659 #define X_SHRT_MIN (-1 - X_SHRT_MAX)
660 #define X_LONG_MAX 0x7fffffff
661 #define X_LONG_MIN (-1 - X_LONG_MAX)
662 #define X_ULONG_MAX 0xffffffffUL
664 #define No_Cursor (None)
666 enum
668 /* Values for focus_state, used as bit mask.
669 EXPLICIT means we received a FocusIn for the frame and know it has
670 the focus. IMPLICIT means we received an EnterNotify and the frame
671 may have the focus if no window manager is running.
672 FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
673 FOCUS_NONE = 0,
674 FOCUS_IMPLICIT = 1,
675 FOCUS_EXPLICIT = 2
679 /* Return the X output data for frame F. */
680 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
682 /* Return the X window used for displaying data in frame F. */
683 #define FRAME_X_WINDOW(f) ((f)->output_data.x->window_desc)
685 /* Return the outermost X window associated with the frame F. */
686 #ifdef USE_X_TOOLKIT
687 #define FRAME_OUTER_WINDOW(f) ((f)->output_data.x->widget ? \
688 XtWindow ((f)->output_data.x->widget) : \
689 FRAME_X_WINDOW (f))
690 #else
691 #ifdef USE_GTK
692 /* Functions not present in older Gtk+ */
694 #ifndef HAVE_GTK_WIDGET_GET_WINDOW
695 #define gtk_widget_get_window(w) ((w)->window)
696 #endif
697 #ifndef HAVE_GTK_WIDGET_GET_MAPPED
698 #define gtk_widget_get_mapped(w) (GTK_WIDGET_MAPPED (w))
699 #endif
700 #ifndef HAVE_GTK_ADJUSTMENT_GET_PAGE_SIZE
701 #define gtk_adjustment_get_page_size(w) ((w)->page_size)
702 #define gtk_adjustment_get_upper(w) ((w)->upper)
703 #endif
705 #ifdef HAVE_GTK3
706 #define DEFAULT_GDK_DISPLAY() \
707 gdk_x11_display_get_xdisplay (gdk_display_get_default ())
708 #else
709 #undef GDK_WINDOW_XID
710 #define GDK_WINDOW_XID(w) GDK_WINDOW_XWINDOW (w)
711 #define DEFAULT_GDK_DISPLAY() GDK_DISPLAY ()
712 #define gtk_widget_get_preferred_size(a, ign, b) \
713 gtk_widget_size_request (a, b)
714 #endif
716 #define GTK_WIDGET_TO_X_WIN(w) \
717 ((w) && gtk_widget_get_window (w) \
718 ? GDK_WINDOW_XID (gtk_widget_get_window (w)) : 0)
720 #define FRAME_GTK_OUTER_WIDGET(f) ((f)->output_data.x->widget)
721 #define FRAME_GTK_WIDGET(f) ((f)->output_data.x->edit_widget)
722 #define FRAME_OUTER_WINDOW(f) \
723 (FRAME_GTK_OUTER_WIDGET (f) ? \
724 GTK_WIDGET_TO_X_WIN (FRAME_GTK_OUTER_WIDGET (f)) : \
725 FRAME_X_WINDOW (f))
727 #else /* !USE_GTK */
728 #define FRAME_OUTER_WINDOW(f) (FRAME_X_WINDOW (f))
729 #endif /* !USE_GTK */
730 #endif
732 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
733 #define FRAME_MENUBAR_HEIGHT(f) ((f)->output_data.x->menubar_height)
734 #else
735 #define FRAME_MENUBAR_HEIGHT(f) ((void) f, 0)
736 #endif /* USE_X_TOOLKIT || USE_GTK */
738 #define FRAME_FONT(f) ((f)->output_data.x->font)
739 #define FRAME_FONTSET(f) ((f)->output_data.x->fontset)
740 #define FRAME_TOOLBAR_TOP_HEIGHT(f) ((f)->output_data.x->toolbar_top_height)
741 #define FRAME_TOOLBAR_BOTTOM_HEIGHT(f) \
742 ((f)->output_data.x->toolbar_bottom_height)
743 #define FRAME_TOOLBAR_HEIGHT(f) \
744 (FRAME_TOOLBAR_TOP_HEIGHT (f) + FRAME_TOOLBAR_BOTTOM_HEIGHT (f))
745 #define FRAME_TOOLBAR_LEFT_WIDTH(f) ((f)->output_data.x->toolbar_left_width)
746 #define FRAME_TOOLBAR_RIGHT_WIDTH(f) ((f)->output_data.x->toolbar_right_width)
747 #define FRAME_TOOLBAR_WIDTH(f) \
748 (FRAME_TOOLBAR_LEFT_WIDTH (f) + FRAME_TOOLBAR_RIGHT_WIDTH (f))
749 #define FRAME_BASELINE_OFFSET(f) ((f)->output_data.x->baseline_offset)
751 /* This gives the x_display_info structure for the display F is on. */
752 #define FRAME_DISPLAY_INFO(f) ((f)->output_data.x->display_info)
754 /* This is the `Display *' which frame F is on. */
755 #define FRAME_X_DISPLAY(f) (FRAME_DISPLAY_INFO (f)->display)
757 /* This is the `Screen *' which frame F is on. */
758 #define FRAME_X_SCREEN(f) (FRAME_DISPLAY_INFO (f)->screen)
760 /* This is the screen index number of screen which frame F is on. */
761 #define FRAME_X_SCREEN_NUMBER(f) XScreenNumberOfScreen (FRAME_X_SCREEN (f))
763 /* This is the Visual which frame F is on. */
764 #define FRAME_X_VISUAL(f) FRAME_DISPLAY_INFO (f)->visual
766 /* This is the Colormap which frame F uses. */
767 #define FRAME_X_COLORMAP(f) FRAME_DISPLAY_INFO (f)->cmap
769 /* The difference in pixels between the top left corner of the
770 Emacs window (including possible window manager decorations)
771 and FRAME_X_WINDOW (f). */
772 #define FRAME_OUTER_TO_INNER_DIFF_X(f) \
773 ((f)->output_data.x->x_pixels_outer_diff)
774 #define FRAME_OUTER_TO_INNER_DIFF_Y(f) \
775 ((f)->output_data.x->y_pixels_outer_diff \
776 + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f))
779 #define FRAME_XIC(f) ((f)->output_data.x->xic)
780 #define FRAME_X_XIM(f) (FRAME_DISPLAY_INFO (f)->xim)
781 #define FRAME_X_XIM_STYLES(f) (FRAME_DISPLAY_INFO (f)->xim_styles)
782 #define FRAME_XIC_STYLE(f) ((f)->output_data.x->xic_style)
783 #define FRAME_XIC_FONTSET(f) ((f)->output_data.x->xic_xfs)
785 /* X-specific scroll bar stuff. */
787 /* We represent scroll bars as lisp vectors. This allows us to place
788 references to them in windows without worrying about whether we'll
789 end up with windows referring to dead scroll bars; the garbage
790 collector will free it when its time comes.
792 We use struct scroll_bar as a template for accessing fields of the
793 vector. */
795 struct scroll_bar
797 /* These fields are shared by all vectors. */
798 struct vectorlike_header header;
800 /* The window we're a scroll bar for. */
801 Lisp_Object window;
803 /* The next and previous in the chain of scroll bars in this frame. */
804 Lisp_Object next, prev;
806 /* Fields from `x_window' down will not be traced by the GC. */
808 /* The X window representing this scroll bar. */
809 Window x_window;
811 /* The position and size of the scroll bar in pixels, relative to the
812 frame. */
813 int top, left, width, height;
815 /* The starting and ending positions of the handle, relative to the
816 handle area (i.e. zero is the top position, not
817 SCROLL_BAR_TOP_BORDER). If they're equal, that means the handle
818 hasn't been drawn yet.
820 These are not actually the locations where the beginning and end
821 are drawn; in order to keep handles from becoming invisible when
822 editing large files, we establish a minimum height by always
823 drawing handle bottoms VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
824 where they would be normally; the bottom and top are in a
825 different co-ordinate system. */
826 int start, end;
828 /* If the scroll bar handle is currently being dragged by the user,
829 this is the number of pixels from the top of the handle to the
830 place where the user grabbed it. If the handle isn't currently
831 being dragged, this is -1. */
832 int dragging;
834 #if defined (USE_TOOLKIT_SCROLL_BARS) && defined (USE_LUCID)
835 /* Last scroll bar part seen in xaw_jump_callback and xaw_scroll_callback. */
836 enum scroll_bar_part last_seen_part;
837 #endif
839 #if defined (USE_TOOLKIT_SCROLL_BARS) && !defined (USE_GTK)
840 /* Last value of whole for horizontal scrollbars. */
841 int whole;
842 #endif
844 /* 1 if the scroll bar is horizontal. */
845 bool horizontal;
848 /* Turning a lisp vector value into a pointer to a struct scroll_bar. */
849 #define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec))
851 #ifdef USE_X_TOOLKIT
853 /* Extract the X widget of the scroll bar from a struct scroll_bar.
854 XtWindowToWidget should be fast enough since Xt uses a hash table
855 to map windows to widgets. */
857 #define SCROLL_BAR_X_WIDGET(dpy, ptr) \
858 XtWindowToWidget (dpy, ptr->x_window)
860 /* Store a widget id in a struct scroll_bar. */
862 #define SET_SCROLL_BAR_X_WIDGET(ptr, w) \
863 do { \
864 Window window = XtWindow (w); \
865 ptr->x_window = window; \
866 } while (false)
868 #endif /* USE_X_TOOLKIT */
870 /* Return the inside width of a vertical scroll bar, given the outside
871 width. */
872 #define VERTICAL_SCROLL_BAR_INSIDE_WIDTH(f, width) \
873 ((width) \
874 - VERTICAL_SCROLL_BAR_LEFT_BORDER \
875 - VERTICAL_SCROLL_BAR_RIGHT_BORDER)
877 /* Return the length of the rectangle within which the top of the
878 handle must stay. This isn't equivalent to the inside height,
879 because the scroll bar handle has a minimum height.
881 This is the real range of motion for the scroll bar, so when we're
882 scaling buffer positions to scroll bar positions, we use this, not
883 VERTICAL_SCROLL_BAR_INSIDE_HEIGHT. */
884 #define VERTICAL_SCROLL_BAR_TOP_RANGE(f, height) \
885 (VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, height) - VERTICAL_SCROLL_BAR_MIN_HANDLE)
887 /* Return the inside height of vertical scroll bar, given the outside
888 height. See VERTICAL_SCROLL_BAR_TOP_RANGE too. */
889 #define VERTICAL_SCROLL_BAR_INSIDE_HEIGHT(f, height) \
890 ((height) - VERTICAL_SCROLL_BAR_TOP_BORDER - VERTICAL_SCROLL_BAR_BOTTOM_BORDER)
892 /* Return the inside height of a horizontal scroll bar, given the outside
893 height. */
894 #define HORIZONTAL_SCROLL_BAR_INSIDE_HEIGHT(f, height) \
895 ((height) \
896 - HORIZONTAL_SCROLL_BAR_TOP_BORDER \
897 - HORIZONTAL_SCROLL_BAR_BOTTOM_BORDER)
899 /* Return the length of the rectangle within which the left part of the
900 handle must stay. This isn't equivalent to the inside width, because
901 the scroll bar handle has a minimum width.
903 This is the real range of motion for the scroll bar, so when we're
904 scaling buffer positions to scroll bar positions, we use this, not
905 HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH. */
906 #define HORIZONTAL_SCROLL_BAR_LEFT_RANGE(f, width) \
907 (HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH (f, width) - HORIZONTAL_SCROLL_BAR_MIN_HANDLE)
909 /* Return the inside width of horizontal scroll bar, given the outside
910 width. See HORIZONTAL_SCROLL_BAR_LEFT_RANGE too. */
911 #define HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH(f, width) \
912 ((width) - HORIZONTAL_SCROLL_BAR_LEFT_BORDER - HORIZONTAL_SCROLL_BAR_LEFT_BORDER)
915 /* Border widths for scroll bars.
917 Scroll bar windows don't have any X borders; their border width is
918 set to zero, and we redraw borders ourselves. This makes the code
919 a bit cleaner, since we don't have to convert between outside width
920 (used when relating to the rest of the screen) and inside width
921 (used when sizing and drawing the scroll bar window itself).
923 The handle moves up and down/back and forth in a rectangle inset
924 from the edges of the scroll bar. These are widths by which we
925 inset the handle boundaries from the scroll bar edges. */
926 #define VERTICAL_SCROLL_BAR_LEFT_BORDER (2)
927 #define VERTICAL_SCROLL_BAR_RIGHT_BORDER (2)
928 #define VERTICAL_SCROLL_BAR_TOP_BORDER (2)
929 #define VERTICAL_SCROLL_BAR_BOTTOM_BORDER (2)
931 #define HORIZONTAL_SCROLL_BAR_LEFT_BORDER (2)
932 #define HORIZONTAL_SCROLL_BAR_RIGHT_BORDER (2)
933 #define HORIZONTAL_SCROLL_BAR_TOP_BORDER (2)
934 #define HORIZONTAL_SCROLL_BAR_BOTTOM_BORDER (2)
936 /* Minimum lengths for scroll bar handles, in pixels. */
937 #define VERTICAL_SCROLL_BAR_MIN_HANDLE (5)
938 #define HORIZONTAL_SCROLL_BAR_MIN_HANDLE (5)
940 /* If a struct input_event has a kind which is SELECTION_REQUEST_EVENT
941 or SELECTION_CLEAR_EVENT, then its contents are really described
942 by this structure. */
944 /* For an event of kind SELECTION_REQUEST_EVENT,
945 this structure really describes the contents. */
947 struct selection_input_event
949 int kind;
950 struct x_display_info *dpyinfo;
951 /* We spell it with an "o" here because X does. */
952 Window requestor;
953 Atom selection, target, property;
954 Time time;
957 /* Unlike macros below, this can't be used as an lvalue. */
958 INLINE Display *
959 SELECTION_EVENT_DISPLAY (struct input_event *ev)
961 return ((struct selection_input_event *) ev)->dpyinfo->display;
963 #define SELECTION_EVENT_DPYINFO(eventp) \
964 (((struct selection_input_event *) (eventp))->dpyinfo)
965 /* We spell it with an "o" here because X does. */
966 #define SELECTION_EVENT_REQUESTOR(eventp) \
967 (((struct selection_input_event *) (eventp))->requestor)
968 #define SELECTION_EVENT_SELECTION(eventp) \
969 (((struct selection_input_event *) (eventp))->selection)
970 #define SELECTION_EVENT_TARGET(eventp) \
971 (((struct selection_input_event *) (eventp))->target)
972 #define SELECTION_EVENT_PROPERTY(eventp) \
973 (((struct selection_input_event *) (eventp))->property)
974 #define SELECTION_EVENT_TIME(eventp) \
975 (((struct selection_input_event *) (eventp))->time)
977 /* From xfns.c. */
979 extern void x_free_gcs (struct frame *);
980 extern void x_relative_mouse_position (struct frame *, int *, int *);
982 /* From xrdb.c. */
984 XrmDatabase x_load_resources (Display *, const char *, const char *,
985 const char *);
987 /* Defined in xterm.c */
989 extern int x_text_icon (struct frame *, const char *);
990 extern void x_catch_errors (Display *);
991 extern void x_check_errors (Display *, const char *)
992 ATTRIBUTE_FORMAT_PRINTF (2, 0);
993 extern bool x_had_errors_p (Display *);
994 extern void x_uncatch_errors (void);
995 extern void x_clear_errors (Display *);
996 extern void xembed_request_focus (struct frame *);
997 extern void x_ewmh_activate_frame (struct frame *);
998 extern void x_delete_terminal (struct terminal *terminal);
999 extern unsigned long x_copy_color (struct frame *, unsigned long);
1000 #ifdef USE_X_TOOLKIT
1001 extern XtAppContext Xt_app_con;
1002 extern void x_activate_timeout_atimer (void);
1003 #endif
1004 #ifdef USE_LUCID
1005 extern bool x_alloc_lighter_color_for_widget (Widget, Display *, Colormap,
1006 unsigned long *,
1007 double, int);
1008 #endif
1009 extern bool x_alloc_nearest_color (struct frame *, Colormap, XColor *);
1010 extern void x_clear_area (Display *, Window, int, int, int, int);
1011 #if !defined USE_X_TOOLKIT && !defined USE_GTK
1012 extern void x_mouse_leave (struct x_display_info *);
1013 #endif
1015 #if defined USE_X_TOOLKIT || defined USE_MOTIF
1016 extern int x_dispatch_event (XEvent *, Display *);
1017 #endif
1018 extern int x_x_to_emacs_modifiers (struct x_display_info *, int);
1020 INLINE int
1021 x_display_pixel_height (struct x_display_info *dpyinfo)
1023 return HeightOfScreen (dpyinfo->screen);
1026 INLINE int
1027 x_display_pixel_width (struct x_display_info *dpyinfo)
1029 return WidthOfScreen (dpyinfo->screen);
1032 INLINE void
1033 x_display_set_last_user_time (struct x_display_info *dpyinfo, Time t)
1035 #ifdef ENABLE_CHECKING
1036 eassert (t <= X_ULONG_MAX);
1037 #endif
1038 dpyinfo->last_user_time = t;
1041 extern void x_set_sticky (struct frame *, Lisp_Object, Lisp_Object);
1042 extern void x_wait_for_event (struct frame *, int);
1043 extern void x_clear_under_internal_border (struct frame *f);
1045 /* Defined in xselect.c. */
1047 extern void x_handle_property_notify (const XPropertyEvent *);
1048 extern void x_handle_selection_notify (const XSelectionEvent *);
1049 extern void x_handle_selection_event (struct input_event *);
1050 extern void x_clear_frame_selections (struct frame *);
1052 extern void x_send_client_event (Lisp_Object display,
1053 Lisp_Object dest,
1054 Lisp_Object from,
1055 Atom message_type,
1056 Lisp_Object format,
1057 Lisp_Object values);
1059 extern int x_handle_dnd_message (struct frame *,
1060 const XClientMessageEvent *,
1061 struct x_display_info *,
1062 struct input_event *);
1063 extern int x_check_property_data (Lisp_Object);
1064 extern void x_fill_property_data (Display *,
1065 Lisp_Object,
1066 void *,
1067 int);
1068 extern Lisp_Object x_property_data_to_lisp (struct frame *,
1069 const unsigned char *,
1070 Atom,
1071 int,
1072 unsigned long);
1073 extern void x_clipboard_manager_save_frame (Lisp_Object);
1074 extern void x_clipboard_manager_save_all (void);
1076 #ifdef USE_GTK
1077 extern int xg_set_icon (struct frame *, Lisp_Object);
1078 extern int xg_set_icon_from_xpm_data (struct frame *, const char **);
1079 #endif /* USE_GTK */
1081 extern void xic_free_xfontset (struct frame *);
1082 extern void create_frame_xic (struct frame *);
1083 extern void destroy_frame_xic (struct frame *);
1084 extern void xic_set_preeditarea (struct window *, int, int);
1085 extern void xic_set_statusarea (struct frame *);
1086 extern void xic_set_xfontset (struct frame *, const char *);
1087 extern bool x_defined_color (struct frame *, const char *, XColor *, bool);
1088 #ifdef HAVE_X_I18N
1089 extern void free_frame_xic (struct frame *);
1090 # if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
1091 extern char * xic_create_fontsetname (const char *base_fontname, int motif);
1092 # endif
1093 #endif
1095 /* Defined in xfaces.c */
1097 #ifdef USE_X_TOOLKIT
1098 extern void x_free_dpy_colors (Display *, Screen *, Colormap,
1099 unsigned long *, int);
1100 #endif /* USE_X_TOOLKIT */
1102 /* Defined in xmenu.c */
1104 #if defined USE_X_TOOLKIT || defined USE_GTK
1105 extern Lisp_Object xw_popup_dialog (struct frame *, Lisp_Object, Lisp_Object);
1106 #endif
1108 #if defined USE_GTK || defined USE_MOTIF
1109 extern void x_menu_set_in_use (int);
1110 #endif
1111 extern void x_menu_wait_for_event (void *data);
1112 extern void initialize_frame_menubar (struct frame *);
1114 /* Defined in xsmfns.c */
1115 #ifdef HAVE_X_SM
1116 extern void x_session_initialize (struct x_display_info *dpyinfo);
1117 extern int x_session_have_connection (void);
1118 extern void x_session_close (void);
1119 #endif
1121 /* Defined in xterm.c */
1123 extern Lisp_Object Qx_gtk_map_stock;
1125 /* Is the frame embedded into another application? */
1127 #define FRAME_X_EMBEDDED_P(f) (FRAME_X_OUTPUT(f)->explicit_parent != 0)
1129 #define STORE_XCHAR2B(chp, b1, b2) \
1130 ((chp)->byte1 = (b1), (chp)->byte2 = (b2))
1132 #define XCHAR2B_BYTE1(chp) \
1133 ((chp)->byte1)
1135 #define XCHAR2B_BYTE2(chp) \
1136 ((chp)->byte2)
1138 #define STORE_NATIVE_RECT(nr,rx,ry,rwidth,rheight) \
1139 ((nr).x = (rx), \
1140 (nr).y = (ry), \
1141 (nr).width = (rwidth), \
1142 (nr).height = (rheight))
1144 INLINE_HEADER_END
1146 #endif /* XTERM_H */