* lisp/progmodes/cc-mode.el (c-after-font-lock-init): Only *move*
[emacs.git] / src / xterm.h
blobd8edbc208f43680a4122ca50b6031c2ae6534d84
1 /* Definitions and headers for communication with X protocol.
2 Copyright (C) 1989, 1993-1994, 1998-2015 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 USE_CAIRO
74 #include <cairo-xlib.h>
75 #ifdef CAIRO_HAS_PDF_SURFACE
76 #include <cairo-pdf.h>
77 #endif
78 #ifdef CAIRO_HAS_PS_SURFACE
79 #include <cairo-ps.h>
80 #endif
81 #ifdef CAIRO_HAS_SVG_SURFACE
82 #include <cairo-svg.h>
83 #endif
84 #endif
86 #ifdef HAVE_X_I18N
87 #include <X11/Xlocale.h>
88 #endif
90 #include "dispextern.h"
91 #include "termhooks.h"
93 INLINE_HEADER_BEGIN
95 /* Black and white pixel values for the screen which frame F is on. */
96 #define BLACK_PIX_DEFAULT(f) \
97 BlackPixel (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f))
98 #define WHITE_PIX_DEFAULT(f) \
99 WhitePixel (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f))
101 /* The mask of events that text windows always want to receive. This
102 includes mouse movement events, since handling the mouse-font text property
103 means that we must track mouse motion all the time. */
105 #define STANDARD_EVENT_SET \
106 (KeyPressMask \
107 | ExposureMask \
108 | ButtonPressMask \
109 | ButtonReleaseMask \
110 | PointerMotionMask \
111 | StructureNotifyMask \
112 | FocusChangeMask \
113 | LeaveWindowMask \
114 | EnterWindowMask \
115 | VisibilityChangeMask)
117 #ifdef HAVE_X11R6_XIM
118 /* Data structure passed to xim_instantiate_callback. */
119 struct xim_inst_t
121 struct x_display_info *dpyinfo;
122 char *resource_name;
124 #endif /* HAVE_X11R6_XIM */
126 /* Structure recording X pixmap and reference count.
127 If REFCOUNT is 0 then this record is free to be reused. */
129 struct x_bitmap_record
131 #ifdef USE_CAIRO
132 void *img;
133 #endif
134 Pixmap pixmap;
135 bool have_mask;
136 Pixmap mask;
137 char *file;
138 int refcount;
139 /* Record some info about this pixmap. */
140 int height, width, depth;
143 #ifdef USE_CAIRO
144 struct x_gc_ext_data
146 #define MAX_CLIP_RECTS 2
147 /* Number of clipping rectangles. */
148 int n_clip_rects;
150 /* Clipping rectangles. */
151 XRectangle clip_rects[MAX_CLIP_RECTS];
153 #endif
156 struct color_name_cache_entry
158 struct color_name_cache_entry *next;
159 XColor rgb;
160 char *name;
163 Status x_parse_color (struct frame *f, const char *color_name,
164 XColor *color);
167 /* For each X display, we have a structure that records
168 information about it. */
170 struct x_display_info
172 /* Chain of all x_display_info structures. */
173 struct x_display_info *next;
175 /* The generic display parameters corresponding to this X display. */
176 struct terminal *terminal;
178 /* This says how to access this display in Xlib. */
179 Display *display;
181 /* A connection number (file descriptor) for the display. */
182 int connection;
184 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE). */
185 Lisp_Object name_list_element;
187 /* Number of frames that are on this display. */
188 int reference_count;
190 /* The Screen this connection is connected to. */
191 Screen *screen;
193 /* Dots per inch of the screen. */
194 double resx, resy;
196 /* The Visual being used for this display. */
197 Visual *visual;
199 /* The colormap being used. */
200 Colormap cmap;
202 /* Number of planes on this screen. */
203 int n_planes;
205 /* Mask of things that cause the mouse to be grabbed. */
206 int grabbed;
208 /* Emacs bitmap-id of the default icon bitmap for this frame.
209 Or -1 if none has been allocated yet. */
210 ptrdiff_t icon_bitmap_id;
212 /* The root window of this screen. */
213 Window root_window;
215 /* Client leader window. */
216 Window client_leader_window;
218 /* The cursor to use for vertical scroll bars. */
219 Cursor vertical_scroll_bar_cursor;
221 /* The cursor to use for horizontal scroll bars. */
222 Cursor horizontal_scroll_bar_cursor;
224 /* The invisible cursor used for pointer blanking.
225 Unused if this display supports Xfixes extension. */
226 Cursor invisible_cursor;
228 /* Function used to toggle pointer visibility on this display. */
229 void (*toggle_visible_pointer) (struct frame *, bool);
231 #ifdef USE_GTK
232 /* The GDK cursor for scroll bars and popup menus. */
233 GdkCursor *xg_cursor;
234 #endif
236 /* X Resource data base */
237 XrmDatabase xrdb;
239 /* Minimum width over all characters in all fonts in font_table. */
240 int smallest_char_width;
242 /* Minimum font height over all fonts in font_table. */
243 int smallest_font_height;
245 /* Reusable Graphics Context for drawing a cursor in a non-default face. */
246 GC scratch_cursor_gc;
248 /* Information about the range of text currently shown in
249 mouse-face. */
250 Mouse_HLInfo mouse_highlight;
252 /* Logical identifier of this display. */
253 unsigned x_id;
255 /* Default name for all frames on this display. */
256 char *x_id_name;
258 /* The number of fonts opened for this display. */
259 int n_fonts;
261 /* Pointer to bitmap records. */
262 struct x_bitmap_record *bitmaps;
264 /* Allocated size of bitmaps field. */
265 ptrdiff_t bitmaps_size;
267 /* Last used bitmap index. */
268 ptrdiff_t bitmaps_last;
270 /* Which modifier keys are on which modifier bits?
272 With each keystroke, X returns eight bits indicating which modifier
273 keys were held down when the key was pressed. The interpretation
274 of the top five modifier bits depends on what keys are attached
275 to them. If the Meta_L and Meta_R keysyms are on mod5, then mod5
276 is the meta bit.
278 meta_mod_mask is a mask containing the bits used for the meta key.
279 It may have more than one bit set, if more than one modifier bit
280 has meta keys on it. Basically, if EVENT is a KeyPress event,
281 the meta key is pressed if (EVENT.state & meta_mod_mask) != 0.
283 shift_lock_mask is LockMask if the XK_Shift_Lock keysym is on the
284 lock modifier bit, or zero otherwise. Non-alphabetic keys should
285 only be affected by the lock modifier bit if XK_Shift_Lock is in
286 use; XK_Caps_Lock should only affect alphabetic keys. With this
287 arrangement, the lock modifier should shift the character if
288 (EVENT.state & shift_lock_mask) != 0. */
289 int meta_mod_mask, shift_lock_mask;
291 /* These are like meta_mod_mask, but for different modifiers. */
292 int alt_mod_mask, super_mod_mask, hyper_mod_mask;
294 /* Communication with window managers. */
295 Atom Xatom_wm_protocols;
297 /* Kinds of protocol things we may receive. */
298 Atom Xatom_wm_take_focus;
299 Atom Xatom_wm_save_yourself;
300 Atom Xatom_wm_delete_window;
302 /* Atom for indicating window state to the window manager. */
303 Atom Xatom_wm_change_state;
305 /* Other WM communication */
306 Atom Xatom_wm_configure_denied; /* When our config request is denied */
307 Atom Xatom_wm_window_moved; /* When the WM moves us. */
308 Atom Xatom_wm_client_leader; /* Id of client leader window. */
310 /* EditRes protocol */
311 Atom Xatom_editres;
313 /* More atoms, which are selection types. */
314 Atom Xatom_CLIPBOARD, Xatom_TIMESTAMP, Xatom_TEXT, Xatom_DELETE,
315 Xatom_COMPOUND_TEXT, Xatom_UTF8_STRING,
316 Xatom_MULTIPLE, Xatom_INCR, Xatom_EMACS_TMP, Xatom_TARGETS, Xatom_NULL,
317 Xatom_ATOM, Xatom_ATOM_PAIR, Xatom_CLIPBOARD_MANAGER;
319 /* More atoms for font properties. The last three are private
320 properties, see the comments in src/fontset.h. */
321 Atom Xatom_PIXEL_SIZE, Xatom_AVERAGE_WIDTH,
322 Xatom_MULE_BASELINE_OFFSET, Xatom_MULE_RELATIVE_COMPOSE,
323 Xatom_MULE_DEFAULT_ASCENT;
325 /* More atoms for Ghostscript support. */
326 Atom Xatom_DONE, Xatom_PAGE;
328 /* Atoms used in toolkit scroll bar client messages. */
329 Atom Xatom_Scrollbar, Xatom_Horizontal_Scrollbar;
331 /* Atom used in XEmbed client messages. */
332 Atom Xatom_XEMBED, Xatom_XEMBED_INFO;
334 /* The frame (if any) which has the X window that has keyboard focus.
335 Zero if none. This is examined by Ffocus_frame in xfns.c. Note
336 that a mere EnterNotify event can set this; if you need to know the
337 last frame specified in a FocusIn or FocusOut event, use
338 x_focus_event_frame. */
339 struct frame *x_focus_frame;
341 /* The last frame mentioned in a FocusIn or FocusOut event. This is
342 separate from x_focus_frame, because whether or not LeaveNotify
343 events cause us to lose focus depends on whether or not we have
344 received a FocusIn event for it. */
345 struct frame *x_focus_event_frame;
347 /* The frame which currently has the visual highlight, and should get
348 keyboard input (other sorts of input have the frame encoded in the
349 event). It points to the X focus frame's selected window's
350 frame. It differs from x_focus_frame when we're using a global
351 minibuffer. */
352 struct frame *x_highlight_frame;
354 /* The frame waiting to be auto-raised in XTread_socket. */
355 struct frame *x_pending_autoraise_frame;
357 /* The frame where the mouse was last time we reported a ButtonPress event. */
358 struct frame *last_mouse_frame;
360 /* The frame where the mouse was last time we reported a mouse position. */
361 struct frame *last_mouse_glyph_frame;
363 /* The frame where the mouse was last time we reported a mouse motion. */
364 struct frame *last_mouse_motion_frame;
366 /* The scroll bar in which the last X motion event occurred. */
367 struct scroll_bar *last_mouse_scroll_bar;
369 /* Time of last user interaction as returned in X events on this display. */
370 Time last_user_time;
372 /* Position where the mouse was last time we reported a motion.
373 This is a position on last_mouse_motion_frame. */
374 int last_mouse_motion_x;
375 int last_mouse_motion_y;
377 /* Where the mouse was last time we reported a mouse position.
378 This is a rectangle on last_mouse_glyph_frame. */
379 XRectangle last_mouse_glyph;
381 /* Time of last mouse movement on this display. This is a hack because
382 we would really prefer that XTmouse_position would return the time
383 associated with the position it returns, but there doesn't seem to be
384 any way to wrest the time-stamp from the server along with the position
385 query. So, we just keep track of the time of the last movement we
386 received, and return that in hopes that it's somewhat accurate. */
387 Time last_mouse_movement_time;
389 /* The gray pixmap. */
390 Pixmap gray;
392 #ifdef HAVE_X_I18N
393 /* XIM (X Input method). */
394 XIM xim;
395 XIMStyles *xim_styles;
396 struct xim_inst_t *xim_callback_data;
397 #endif
399 /* A cache mapping color names to RGB values. */
400 struct color_name_cache_entry *color_names;
402 /* If non-null, a cache of the colors in the color map. Don't
403 use this directly, call x_color_cells instead. */
404 XColor *color_cells;
405 int ncolor_cells;
407 /* Bits and shifts to use to compose pixel values on TrueColor visuals. */
408 int red_bits, blue_bits, green_bits;
409 int red_offset, blue_offset, green_offset;
411 /* The type of window manager we have. If we move FRAME_OUTER_WINDOW
412 to x/y 0/0, some window managers (type A) puts the window manager
413 decorations outside the screen and FRAME_OUTER_WINDOW exactly at 0/0.
414 Other window managers (type B) puts the window including decorations
415 at 0/0, so FRAME_OUTER_WINDOW is a bit below 0/0.
416 Record the type of WM in use so we can compensate for type A WMs. */
417 enum
419 X_WMTYPE_UNKNOWN,
420 X_WMTYPE_A,
421 X_WMTYPE_B
422 } wm_type;
425 /* Atoms that are drag and drop atoms */
426 Atom *x_dnd_atoms;
427 ptrdiff_t x_dnd_atoms_size;
428 ptrdiff_t x_dnd_atoms_length;
430 /* Extended window manager hints, Atoms supported by the window manager and
431 atoms for setting the window type. */
432 Atom Xatom_net_supported, Xatom_net_supporting_wm_check;
433 Atom *net_supported_atoms;
434 int nr_net_supported_atoms;
435 Window net_supported_window;
436 Atom Xatom_net_window_type, Xatom_net_window_type_tooltip;
437 Atom Xatom_net_active_window;
439 /* Atoms dealing with EWMH (i.e. _NET_...) */
440 Atom Xatom_net_wm_state, Xatom_net_wm_state_fullscreen,
441 Xatom_net_wm_state_maximized_horz, Xatom_net_wm_state_maximized_vert,
442 Xatom_net_wm_state_sticky, Xatom_net_wm_state_hidden,
443 Xatom_net_frame_extents,
444 Xatom_net_current_desktop, Xatom_net_workarea;
446 /* XSettings atoms and windows. */
447 Atom Xatom_xsettings_sel, Xatom_xsettings_prop, Xatom_xsettings_mgr;
448 Window xsettings_window;
450 /* Frame name and icon name */
451 Atom Xatom_net_wm_name, Xatom_net_wm_icon_name;
452 /* Frame opacity */
453 Atom Xatom_net_wm_window_opacity;
455 /* SM */
456 Atom Xatom_SM_CLIENT_ID;
458 #ifdef USE_CAIRO
459 XExtCodes *ext_codes;
460 #endif
463 #ifdef HAVE_X_I18N
464 /* Whether or not to use XIM if we have it. */
465 extern bool use_xim;
466 #endif
468 /* This is a chain of structures for all the X displays currently in use. */
469 extern struct x_display_info *x_display_list;
471 extern struct x_display_info *x_display_info_for_display (Display *);
472 extern struct frame *x_top_window_to_frame (struct x_display_info *, int);
473 extern struct x_display_info *x_term_init (Lisp_Object, char *, char *);
474 extern bool x_display_ok (const char *);
476 extern void select_visual (struct x_display_info *);
478 /* Each X frame object points to its own struct x_output object
479 in the output_data.x field. The x_output structure contains
480 the information that is specific to X windows. */
482 struct x_output
484 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
485 /* Height of menu bar widget, in pixels. This value
486 is not meaningful if the menubar is turned off. */
487 int menubar_height;
488 #endif
490 /* Height of tool bar widget, in pixels. top_height is used if tool bar
491 at top, bottom_height if tool bar is at the bottom.
492 Zero if not using an external tool bar or if tool bar is vertical. */
493 int toolbar_top_height, toolbar_bottom_height;
495 /* Width of tool bar widget, in pixels. left_width is used if tool bar
496 at left, right_width if tool bar is at the right.
497 Zero if not using an external tool bar or if tool bar is horizontal. */
498 int toolbar_left_width, toolbar_right_width;
500 /* The tiled border used when the mouse is out of the frame. */
501 Pixmap border_tile;
503 /* Here are the Graphics Contexts for the default font. */
504 GC normal_gc; /* Normal video */
505 GC reverse_gc; /* Reverse video */
506 GC cursor_gc; /* cursor drawing */
508 /* The X window used for this frame.
509 May be zero while the frame object is being created
510 and the X window has not yet been created. */
511 Window window_desc;
513 /* The X window used for the bitmap icon;
514 or 0 if we don't have a bitmap icon. */
515 Window icon_desc;
517 /* The X window that is the parent of this X window.
518 Usually this is a window that was made by the window manager,
519 but it can be the root window, and it can be explicitly specified
520 (see the explicit_parent field, below). */
521 Window parent_desc;
523 #ifdef USE_X_TOOLKIT
524 /* The widget of this screen. This is the window of a "shell" widget. */
525 Widget widget;
526 /* The XmPanedWindows... */
527 Widget column_widget;
528 /* The widget of the edit portion of this screen; the window in
529 "window_desc" is inside of this. */
530 Widget edit_widget;
532 Widget menubar_widget;
533 #endif
535 #ifdef USE_GTK
536 /* The widget of this screen. This is the window of a top widget. */
537 GtkWidget *widget;
538 /* The widget of the edit portion of this screen; the window in
539 "window_desc" is inside of this. */
540 GtkWidget *edit_widget;
541 /* The widget used for laying out widgets vertically. */
542 GtkWidget *vbox_widget;
543 /* The widget used for laying out widgets horizontally. */
544 GtkWidget *hbox_widget;
545 /* The menubar in this frame. */
546 GtkWidget *menubar_widget;
547 /* The tool bar in this frame */
548 GtkWidget *toolbar_widget;
549 /* True if tool bar is packed into the hbox widget (i.e. vertical). */
550 bool_bf toolbar_in_hbox : 1;
551 bool_bf toolbar_is_packed : 1;
553 /* The last size hints set. */
554 GdkGeometry size_hints;
555 long hint_flags;
557 #ifdef USE_GTK_TOOLTIP
558 GtkTooltip *ttip_widget;
559 GtkWidget *ttip_lbl;
560 GtkWindow *ttip_window;
561 #endif /* USE_GTK_TOOLTIP */
563 #endif /* USE_GTK */
565 /* If >=0, a bitmap index. The indicated bitmap is used for the
566 icon. */
567 ptrdiff_t icon_bitmap;
569 /* Default ASCII font of this frame. */
570 struct font *font;
572 /* The baseline offset of the default ASCII font. */
573 int baseline_offset;
575 /* If a fontset is specified for this frame instead of font, this
576 value contains an ID of the fontset, else -1. */
577 int fontset;
579 unsigned long cursor_pixel;
580 unsigned long border_pixel;
581 unsigned long mouse_pixel;
582 unsigned long cursor_foreground_pixel;
584 /* Foreground color for scroll bars. A value of -1 means use the
585 default (black for non-toolkit scroll bars). */
586 unsigned long scroll_bar_foreground_pixel;
588 /* Background color for scroll bars. A value of -1 means use the
589 default (background color of the frame for non-toolkit scroll
590 bars). */
591 unsigned long scroll_bar_background_pixel;
593 #if defined (USE_LUCID) && defined (USE_TOOLKIT_SCROLL_BARS)
594 /* Top and bottom shadow colors for 3D Lucid scrollbars.
595 -1 means let the scroll compute them itself. */
596 unsigned long scroll_bar_top_shadow_pixel;
597 unsigned long scroll_bar_bottom_shadow_pixel;
598 #endif
600 /* Descriptor for the cursor in use for this window. */
601 Cursor text_cursor;
602 Cursor nontext_cursor;
603 Cursor modeline_cursor;
604 Cursor hand_cursor;
605 Cursor hourglass_cursor;
606 Cursor horizontal_drag_cursor;
607 Cursor vertical_drag_cursor;
608 Cursor current_cursor;
610 /* Window whose cursor is hourglass_cursor. This window is temporarily
611 mapped to display an hourglass cursor. */
612 Window hourglass_window;
614 /* These are the current window manager hints. It seems that
615 XSetWMHints, when presented with an unset bit in the `flags'
616 member of the hints structure, does not leave the corresponding
617 attribute unchanged; rather, it resets that attribute to its
618 default value. For example, unless you set the `icon_pixmap'
619 field and the `IconPixmapHint' bit, XSetWMHints will forget what
620 your icon pixmap was. This is rather troublesome, since some of
621 the members (for example, `input' and `icon_pixmap') want to stay
622 the same throughout the execution of Emacs. So, we keep this
623 structure around, just leaving values in it and adding new bits
624 to the mask as we go. */
625 XWMHints wm_hints;
627 /* This is the Emacs structure for the X display this frame is on. */
628 struct x_display_info *display_info;
630 /* This is a button event that wants to activate the menubar.
631 We save it here until the command loop gets to think about it. */
632 XEvent *saved_menu_event;
634 /* This is the widget id used for this frame's menubar in lwlib. */
635 #ifdef USE_X_TOOLKIT
636 int id;
637 #endif
639 /* True means hourglass cursor is currently displayed. */
640 bool_bf hourglass_p : 1;
642 /* True means our parent is another application's window
643 and was explicitly specified. */
644 bool_bf explicit_parent : 1;
646 /* True means tried already to make this frame visible. */
647 bool_bf asked_for_visible : 1;
649 /* True if this frame was ever previously visible. */
650 bool_bf has_been_visible : 1;
652 /* Xt waits for a ConfigureNotify event from the window manager in
653 EmacsFrameSetCharSize when the shell widget is resized. For some
654 window managers like fvwm2 2.2.5 and KDE 2.1 this event doesn't
655 arrive for an unknown reason and Emacs hangs in Xt. If this is
656 false, tell Xt not to wait. */
657 bool_bf wait_for_wm : 1;
659 #ifdef HAVE_X_I18N
660 /* Input context (currently, this means Compose key handler setup). */
661 XIC xic;
662 XIMStyle xic_style;
663 XFontSet xic_xfs;
664 #endif
666 /* Relief GCs, colors etc. */
667 struct relief
669 GC gc;
670 unsigned long pixel;
672 black_relief, white_relief;
674 /* The background for which the above relief GCs were set up.
675 They are changed only when a different background is involved. */
676 unsigned long relief_background;
678 /* Keep track of focus. May be EXPLICIT if we received a FocusIn for this
679 frame, or IMPLICIT if we received an EnterNotify.
680 FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
681 int focus_state;
683 /* The offset we need to add to compensate for type A WMs. */
684 int move_offset_top;
685 int move_offset_left;
687 /* Extreme 'short' and 'long' values suitable for libX11. */
688 #define X_SHRT_MAX 0x7fff
689 #define X_SHRT_MIN (-1 - X_SHRT_MAX)
690 #define X_LONG_MAX 0x7fffffff
691 #define X_LONG_MIN (-1 - X_LONG_MAX)
692 #define X_ULONG_MAX 0xffffffffUL
694 #ifdef USE_CAIRO
695 /* Cairo drawing context. */
696 cairo_t *cr_context;
697 /* Cairo surface for double buffering */
698 cairo_surface_t *cr_surface;
699 #endif
702 #define No_Cursor (None)
704 enum
706 /* Values for focus_state, used as bit mask.
707 EXPLICIT means we received a FocusIn for the frame and know it has
708 the focus. IMPLICIT means we received an EnterNotify and the frame
709 may have the focus if no window manager is running.
710 FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
711 FOCUS_NONE = 0,
712 FOCUS_IMPLICIT = 1,
713 FOCUS_EXPLICIT = 2
717 /* Return the X output data for frame F. */
718 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
720 /* Return the X window used for displaying data in frame F. */
721 #define FRAME_X_WINDOW(f) ((f)->output_data.x->window_desc)
723 /* Return the outermost X window associated with the frame F. */
724 #ifdef USE_X_TOOLKIT
725 #define FRAME_OUTER_WINDOW(f) ((f)->output_data.x->widget ? \
726 XtWindow ((f)->output_data.x->widget) : \
727 FRAME_X_WINDOW (f))
728 #else
729 #ifdef USE_GTK
730 /* Functions not present in older Gtk+ */
732 #ifndef HAVE_GTK_WIDGET_GET_WINDOW
733 #define gtk_widget_get_window(w) ((w)->window)
734 #endif
735 #ifndef HAVE_GTK_WIDGET_GET_MAPPED
736 #define gtk_widget_get_mapped(w) (GTK_WIDGET_MAPPED (w))
737 #endif
738 #ifndef HAVE_GTK_ADJUSTMENT_GET_PAGE_SIZE
739 #define gtk_adjustment_get_page_size(w) ((w)->page_size)
740 #define gtk_adjustment_get_upper(w) ((w)->upper)
741 #endif
743 #ifdef HAVE_GTK3
744 #define DEFAULT_GDK_DISPLAY() \
745 gdk_x11_display_get_xdisplay (gdk_display_get_default ())
746 #else
747 #undef GDK_WINDOW_XID
748 #define GDK_WINDOW_XID(w) GDK_WINDOW_XWINDOW (w)
749 #define DEFAULT_GDK_DISPLAY() GDK_DISPLAY ()
750 #define gtk_widget_get_preferred_size(a, ign, b) \
751 gtk_widget_size_request (a, b)
752 #endif
754 #define GTK_WIDGET_TO_X_WIN(w) \
755 ((w) && gtk_widget_get_window (w) \
756 ? GDK_WINDOW_XID (gtk_widget_get_window (w)) : 0)
758 #define FRAME_GTK_OUTER_WIDGET(f) ((f)->output_data.x->widget)
759 #define FRAME_GTK_WIDGET(f) ((f)->output_data.x->edit_widget)
760 #define FRAME_OUTER_WINDOW(f) \
761 (FRAME_GTK_OUTER_WIDGET (f) ? \
762 GTK_WIDGET_TO_X_WIN (FRAME_GTK_OUTER_WIDGET (f)) : \
763 FRAME_X_WINDOW (f))
765 #else /* !USE_GTK */
766 #define FRAME_OUTER_WINDOW(f) (FRAME_X_WINDOW (f))
767 #endif /* !USE_GTK */
768 #endif
770 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
771 #define FRAME_MENUBAR_HEIGHT(f) ((f)->output_data.x->menubar_height)
772 #else
773 #define FRAME_MENUBAR_HEIGHT(f) ((void) f, 0)
774 #endif /* USE_X_TOOLKIT || USE_GTK */
776 #define FRAME_FONT(f) ((f)->output_data.x->font)
777 #define FRAME_FONTSET(f) ((f)->output_data.x->fontset)
778 #define FRAME_TOOLBAR_TOP_HEIGHT(f) ((f)->output_data.x->toolbar_top_height)
779 #define FRAME_TOOLBAR_BOTTOM_HEIGHT(f) \
780 ((f)->output_data.x->toolbar_bottom_height)
781 #define FRAME_TOOLBAR_HEIGHT(f) \
782 (FRAME_TOOLBAR_TOP_HEIGHT (f) + FRAME_TOOLBAR_BOTTOM_HEIGHT (f))
783 #define FRAME_TOOLBAR_LEFT_WIDTH(f) ((f)->output_data.x->toolbar_left_width)
784 #define FRAME_TOOLBAR_RIGHT_WIDTH(f) ((f)->output_data.x->toolbar_right_width)
785 #define FRAME_TOOLBAR_WIDTH(f) \
786 (FRAME_TOOLBAR_LEFT_WIDTH (f) + FRAME_TOOLBAR_RIGHT_WIDTH (f))
787 #define FRAME_BASELINE_OFFSET(f) ((f)->output_data.x->baseline_offset)
789 /* This gives the x_display_info structure for the display F is on. */
790 #define FRAME_DISPLAY_INFO(f) ((f)->output_data.x->display_info)
792 /* This is the `Display *' which frame F is on. */
793 #define FRAME_X_DISPLAY(f) (FRAME_DISPLAY_INFO (f)->display)
795 /* This is the `Screen *' which frame F is on. */
796 #define FRAME_X_SCREEN(f) (FRAME_DISPLAY_INFO (f)->screen)
798 /* This is the screen index number of screen which frame F is on. */
799 #define FRAME_X_SCREEN_NUMBER(f) XScreenNumberOfScreen (FRAME_X_SCREEN (f))
801 /* This is the Visual which frame F is on. */
802 #define FRAME_X_VISUAL(f) FRAME_DISPLAY_INFO (f)->visual
804 /* This is the Colormap which frame F uses. */
805 #define FRAME_X_COLORMAP(f) FRAME_DISPLAY_INFO (f)->cmap
807 #define FRAME_XIC(f) ((f)->output_data.x->xic)
808 #define FRAME_X_XIM(f) (FRAME_DISPLAY_INFO (f)->xim)
809 #define FRAME_X_XIM_STYLES(f) (FRAME_DISPLAY_INFO (f)->xim_styles)
810 #define FRAME_XIC_STYLE(f) ((f)->output_data.x->xic_style)
811 #define FRAME_XIC_FONTSET(f) ((f)->output_data.x->xic_xfs)
813 /* X-specific scroll bar stuff. */
815 /* We represent scroll bars as lisp vectors. This allows us to place
816 references to them in windows without worrying about whether we'll
817 end up with windows referring to dead scroll bars; the garbage
818 collector will free it when its time comes.
820 We use struct scroll_bar as a template for accessing fields of the
821 vector. */
823 struct scroll_bar
825 /* These fields are shared by all vectors. */
826 struct vectorlike_header header;
828 /* The window we're a scroll bar for. */
829 Lisp_Object window;
831 /* The next and previous in the chain of scroll bars in this frame. */
832 Lisp_Object next, prev;
834 /* Fields from `x_window' down will not be traced by the GC. */
836 /* The X window representing this scroll bar. */
837 Window x_window;
839 /* The position and size of the scroll bar in pixels, relative to the
840 frame. */
841 int top, left, width, height;
843 /* The starting and ending positions of the handle, relative to the
844 handle area (i.e. zero is the top position, not
845 SCROLL_BAR_TOP_BORDER). If they're equal, that means the handle
846 hasn't been drawn yet.
848 These are not actually the locations where the beginning and end
849 are drawn; in order to keep handles from becoming invisible when
850 editing large files, we establish a minimum height by always
851 drawing handle bottoms VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
852 where they would be normally; the bottom and top are in a
853 different co-ordinate system. */
854 int start, end;
856 /* If the scroll bar handle is currently being dragged by the user,
857 this is the number of pixels from the top of the handle to the
858 place where the user grabbed it. If the handle isn't currently
859 being dragged, this is -1. */
860 int dragging;
862 #if defined (USE_TOOLKIT_SCROLL_BARS) && defined (USE_LUCID)
863 /* Last scroll bar part seen in xaw_jump_callback and xaw_scroll_callback. */
864 enum scroll_bar_part last_seen_part;
865 #endif
867 #if defined (USE_TOOLKIT_SCROLL_BARS) && !defined (USE_GTK)
868 /* Last value of whole for horizontal scrollbars. */
869 int whole;
870 #endif
872 /* True if the scroll bar is horizontal. */
873 bool horizontal;
876 /* Turning a lisp vector value into a pointer to a struct scroll_bar. */
877 #define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec))
879 #ifdef USE_X_TOOLKIT
881 /* Extract the X widget of the scroll bar from a struct scroll_bar.
882 XtWindowToWidget should be fast enough since Xt uses a hash table
883 to map windows to widgets. */
885 #define SCROLL_BAR_X_WIDGET(dpy, ptr) \
886 XtWindowToWidget (dpy, ptr->x_window)
888 /* Store a widget id in a struct scroll_bar. */
890 #define SET_SCROLL_BAR_X_WIDGET(ptr, w) \
891 do { \
892 Window window = XtWindow (w); \
893 ptr->x_window = window; \
894 } while (false)
896 #endif /* USE_X_TOOLKIT */
898 /* Return the inside width of a vertical scroll bar, given the outside
899 width. */
900 #define VERTICAL_SCROLL_BAR_INSIDE_WIDTH(f, width) \
901 ((width) \
902 - VERTICAL_SCROLL_BAR_LEFT_BORDER \
903 - VERTICAL_SCROLL_BAR_RIGHT_BORDER)
905 /* Return the length of the rectangle within which the top of the
906 handle must stay. This isn't equivalent to the inside height,
907 because the scroll bar handle has a minimum height.
909 This is the real range of motion for the scroll bar, so when we're
910 scaling buffer positions to scroll bar positions, we use this, not
911 VERTICAL_SCROLL_BAR_INSIDE_HEIGHT. */
912 #define VERTICAL_SCROLL_BAR_TOP_RANGE(f, height) \
913 (VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, height) - VERTICAL_SCROLL_BAR_MIN_HANDLE)
915 /* Return the inside height of vertical scroll bar, given the outside
916 height. See VERTICAL_SCROLL_BAR_TOP_RANGE too. */
917 #define VERTICAL_SCROLL_BAR_INSIDE_HEIGHT(f, height) \
918 ((height) - VERTICAL_SCROLL_BAR_TOP_BORDER - VERTICAL_SCROLL_BAR_BOTTOM_BORDER)
920 /* Return the inside height of a horizontal scroll bar, given the outside
921 height. */
922 #define HORIZONTAL_SCROLL_BAR_INSIDE_HEIGHT(f, height) \
923 ((height) \
924 - HORIZONTAL_SCROLL_BAR_TOP_BORDER \
925 - HORIZONTAL_SCROLL_BAR_BOTTOM_BORDER)
927 /* Return the length of the rectangle within which the left part of the
928 handle must stay. This isn't equivalent to the inside width, because
929 the scroll bar handle has a minimum width.
931 This is the real range of motion for the scroll bar, so when we're
932 scaling buffer positions to scroll bar positions, we use this, not
933 HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH. */
934 #define HORIZONTAL_SCROLL_BAR_LEFT_RANGE(f, width) \
935 (HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH (f, width) - HORIZONTAL_SCROLL_BAR_MIN_HANDLE)
937 /* Return the inside width of horizontal scroll bar, given the outside
938 width. See HORIZONTAL_SCROLL_BAR_LEFT_RANGE too. */
939 #define HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH(f, width) \
940 ((width) - HORIZONTAL_SCROLL_BAR_LEFT_BORDER - HORIZONTAL_SCROLL_BAR_LEFT_BORDER)
943 /* Border widths for scroll bars.
945 Scroll bar windows don't have any X borders; their border width is
946 set to zero, and we redraw borders ourselves. This makes the code
947 a bit cleaner, since we don't have to convert between outside width
948 (used when relating to the rest of the screen) and inside width
949 (used when sizing and drawing the scroll bar window itself).
951 The handle moves up and down/back and forth in a rectangle inset
952 from the edges of the scroll bar. These are widths by which we
953 inset the handle boundaries from the scroll bar edges. */
954 #define VERTICAL_SCROLL_BAR_LEFT_BORDER (2)
955 #define VERTICAL_SCROLL_BAR_RIGHT_BORDER (2)
956 #define VERTICAL_SCROLL_BAR_TOP_BORDER (2)
957 #define VERTICAL_SCROLL_BAR_BOTTOM_BORDER (2)
959 #define HORIZONTAL_SCROLL_BAR_LEFT_BORDER (2)
960 #define HORIZONTAL_SCROLL_BAR_RIGHT_BORDER (2)
961 #define HORIZONTAL_SCROLL_BAR_TOP_BORDER (2)
962 #define HORIZONTAL_SCROLL_BAR_BOTTOM_BORDER (2)
964 /* Minimum lengths for scroll bar handles, in pixels. */
965 #define VERTICAL_SCROLL_BAR_MIN_HANDLE (5)
966 #define HORIZONTAL_SCROLL_BAR_MIN_HANDLE (5)
968 /* If a struct input_event has a kind which is SELECTION_REQUEST_EVENT
969 or SELECTION_CLEAR_EVENT, then its contents are really described
970 by this structure. */
972 /* For an event of kind SELECTION_REQUEST_EVENT,
973 this structure really describes the contents. */
975 struct selection_input_event
977 ENUM_BF (event_kind) kind : EVENT_KIND_WIDTH;
978 struct x_display_info *dpyinfo;
979 /* We spell it with an "o" here because X does. */
980 Window requestor;
981 Atom selection, target, property;
982 Time time;
985 /* Unlike macros below, this can't be used as an lvalue. */
986 INLINE Display *
987 SELECTION_EVENT_DISPLAY (struct selection_input_event *ev)
989 return ev->dpyinfo->display;
991 #define SELECTION_EVENT_DPYINFO(eventp) \
992 ((eventp)->dpyinfo)
993 /* We spell it with an "o" here because X does. */
994 #define SELECTION_EVENT_REQUESTOR(eventp) \
995 ((eventp)->requestor)
996 #define SELECTION_EVENT_SELECTION(eventp) \
997 ((eventp)->selection)
998 #define SELECTION_EVENT_TARGET(eventp) \
999 ((eventp)->target)
1000 #define SELECTION_EVENT_PROPERTY(eventp) \
1001 ((eventp)->property)
1002 #define SELECTION_EVENT_TIME(eventp) \
1003 ((eventp)->time)
1005 /* From xfns.c. */
1007 extern void x_free_gcs (struct frame *);
1008 extern void x_relative_mouse_position (struct frame *, int *, int *);
1009 extern void x_real_pos_and_offsets (struct frame *f,
1010 int *left_offset_x,
1011 int *right_offset_x,
1012 int *top_offset_y,
1013 int *bottom_offset_y,
1014 int *x_pixels_diff,
1015 int *y_pixels_diff,
1016 int *xptr,
1017 int *yptr,
1018 int *outer_border);
1020 /* From xrdb.c. */
1022 XrmDatabase x_load_resources (Display *, const char *, const char *,
1023 const char *);
1025 /* Defined in xterm.c */
1027 extern bool x_text_icon (struct frame *, const char *);
1028 extern void x_catch_errors (Display *);
1029 extern void x_check_errors (Display *, const char *)
1030 ATTRIBUTE_FORMAT_PRINTF (2, 0);
1031 extern bool x_had_errors_p (Display *);
1032 extern void x_uncatch_errors (void);
1033 extern void x_clear_errors (Display *);
1034 extern void xembed_request_focus (struct frame *);
1035 extern void x_ewmh_activate_frame (struct frame *);
1036 extern void x_delete_terminal (struct terminal *terminal);
1037 extern unsigned long x_copy_color (struct frame *, unsigned long);
1038 #ifdef USE_X_TOOLKIT
1039 extern XtAppContext Xt_app_con;
1040 extern void x_activate_timeout_atimer (void);
1041 #endif
1042 #ifdef USE_LUCID
1043 extern bool x_alloc_lighter_color_for_widget (Widget, Display *, Colormap,
1044 unsigned long *,
1045 double, int);
1046 #endif
1047 extern bool x_alloc_nearest_color (struct frame *, Colormap, XColor *);
1048 extern void x_query_color (struct frame *f, XColor *);
1049 extern void x_clear_area (struct frame *f, int, int, int, int);
1050 #if !defined USE_X_TOOLKIT && !defined USE_GTK
1051 extern void x_mouse_leave (struct x_display_info *);
1052 #endif
1054 #if defined USE_X_TOOLKIT || defined USE_MOTIF
1055 extern int x_dispatch_event (XEvent *, Display *);
1056 #endif
1057 extern int x_x_to_emacs_modifiers (struct x_display_info *, int);
1058 #ifdef USE_CAIRO
1059 extern cairo_t *x_begin_cr_clip (struct frame *, GC);
1060 extern void x_end_cr_clip (struct frame *);
1061 extern void x_set_cr_source_with_gc_foreground (struct frame *, GC);
1062 extern void x_set_cr_source_with_gc_background (struct frame *, GC);
1063 extern void x_cr_draw_frame (cairo_t *, struct frame *);
1064 extern Lisp_Object x_cr_export_frames (Lisp_Object, cairo_surface_type_t);
1065 #endif
1067 INLINE int
1068 x_display_pixel_height (struct x_display_info *dpyinfo)
1070 return HeightOfScreen (dpyinfo->screen);
1073 INLINE int
1074 x_display_pixel_width (struct x_display_info *dpyinfo)
1076 return WidthOfScreen (dpyinfo->screen);
1079 INLINE void
1080 x_display_set_last_user_time (struct x_display_info *dpyinfo, Time t)
1082 #ifdef ENABLE_CHECKING
1083 eassert (t <= X_ULONG_MAX);
1084 #endif
1085 dpyinfo->last_user_time = t;
1088 INLINE unsigned long
1089 x_make_truecolor_pixel (struct x_display_info *dpyinfo, int r, int g, int b)
1091 unsigned long pr, pg, pb;
1093 /* Scale down RGB values to the visual's bits per RGB, and shift
1094 them to the right position in the pixel color. Note that the
1095 original RGB values are 16-bit values, as usual in X. */
1096 pr = (r >> (16 - dpyinfo->red_bits)) << dpyinfo->red_offset;
1097 pg = (g >> (16 - dpyinfo->green_bits)) << dpyinfo->green_offset;
1098 pb = (b >> (16 - dpyinfo->blue_bits)) << dpyinfo->blue_offset;
1100 /* Assemble the pixel color. */
1101 return pr | pg | pb;
1104 /* If display has an immutable color map, freeing colors is not
1105 necessary and some servers don't allow it, so we won't do it. That
1106 also allows us to make other optimizations relating to server-side
1107 reference counts. */
1108 INLINE bool
1109 x_mutable_colormap (Visual *visual)
1111 int class = visual->class;
1112 return (class != StaticColor && class != StaticGray && class != TrueColor);
1115 extern void x_set_sticky (struct frame *, Lisp_Object, Lisp_Object);
1116 extern bool x_wm_supports (struct frame *, Atom);
1117 extern void x_wait_for_event (struct frame *, int);
1118 extern void x_clear_under_internal_border (struct frame *f);
1120 /* Defined in xselect.c. */
1122 extern void x_handle_property_notify (const XPropertyEvent *);
1123 extern void x_handle_selection_notify (const XSelectionEvent *);
1124 extern void x_handle_selection_event (struct selection_input_event *);
1125 extern void x_clear_frame_selections (struct frame *);
1127 extern void x_send_client_event (Lisp_Object display,
1128 Lisp_Object dest,
1129 Lisp_Object from,
1130 Atom message_type,
1131 Lisp_Object format,
1132 Lisp_Object values);
1134 extern bool x_handle_dnd_message (struct frame *,
1135 const XClientMessageEvent *,
1136 struct x_display_info *,
1137 struct input_event *);
1138 extern int x_check_property_data (Lisp_Object);
1139 extern void x_fill_property_data (Display *,
1140 Lisp_Object,
1141 void *,
1142 int);
1143 extern Lisp_Object x_property_data_to_lisp (struct frame *,
1144 const unsigned char *,
1145 Atom,
1146 int,
1147 unsigned long);
1148 extern void x_clipboard_manager_save_frame (Lisp_Object);
1149 extern void x_clipboard_manager_save_all (void);
1151 #ifdef USE_GTK
1152 extern bool xg_set_icon (struct frame *, Lisp_Object);
1153 extern bool xg_set_icon_from_xpm_data (struct frame *, const char **);
1154 #endif /* USE_GTK */
1156 extern void xic_free_xfontset (struct frame *);
1157 extern void create_frame_xic (struct frame *);
1158 extern void destroy_frame_xic (struct frame *);
1159 extern void xic_set_preeditarea (struct window *, int, int);
1160 extern void xic_set_statusarea (struct frame *);
1161 extern void xic_set_xfontset (struct frame *, const char *);
1162 extern bool x_defined_color (struct frame *, const char *, XColor *, bool);
1163 #ifdef HAVE_X_I18N
1164 extern void free_frame_xic (struct frame *);
1165 # if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
1166 extern char *xic_create_fontsetname (const char *, bool);
1167 # endif
1168 #endif
1170 /* Defined in xfaces.c */
1172 #ifdef USE_X_TOOLKIT
1173 extern void x_free_dpy_colors (Display *, Screen *, Colormap,
1174 unsigned long *, int);
1175 #endif /* USE_X_TOOLKIT */
1177 /* Defined in xmenu.c */
1179 #if defined USE_X_TOOLKIT || defined USE_GTK
1180 extern Lisp_Object xw_popup_dialog (struct frame *, Lisp_Object, Lisp_Object);
1181 #endif
1183 #if defined USE_GTK || defined USE_MOTIF
1184 extern void x_menu_set_in_use (bool);
1185 #endif
1186 extern void x_menu_wait_for_event (void *data);
1187 extern void initialize_frame_menubar (struct frame *);
1189 /* Defined in xsmfns.c */
1190 #ifdef HAVE_X_SM
1191 extern void x_session_initialize (struct x_display_info *dpyinfo);
1192 extern bool x_session_have_connection (void);
1193 extern void x_session_close (void);
1194 #endif
1197 /* Is the frame embedded into another application? */
1199 #define FRAME_X_EMBEDDED_P(f) (FRAME_X_OUTPUT(f)->explicit_parent != 0)
1201 #define STORE_XCHAR2B(chp, b1, b2) \
1202 ((chp)->byte1 = (b1), (chp)->byte2 = (b2))
1204 #define XCHAR2B_BYTE1(chp) \
1205 ((chp)->byte1)
1207 #define XCHAR2B_BYTE2(chp) \
1208 ((chp)->byte2)
1210 #define STORE_NATIVE_RECT(nr,rx,ry,rwidth,rheight) \
1211 ((nr).x = (rx), \
1212 (nr).y = (ry), \
1213 (nr).width = (rwidth), \
1214 (nr).height = (rheight))
1216 INLINE_HEADER_END
1218 #endif /* XTERM_H */