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