Auto-commit of loaddefs files.
[emacs/old-mirror.git] / src / xterm.h
blob3e92ebd231793d8861cfc26e334918390376b674
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 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE). */
142 Lisp_Object name_list_element;
144 /* Number of frames that are on this display. */
145 int reference_count;
147 /* The Screen this connection is connected to. */
148 Screen *screen;
150 /* Dots per inch of the screen. */
151 double resx, resy;
153 /* The Visual being used for this display. */
154 Visual *visual;
156 /* The colormap being used. */
157 Colormap cmap;
159 /* Number of planes on this screen. */
160 int n_planes;
162 /* Mask of things that cause the mouse to be grabbed. */
163 int grabbed;
165 /* Emacs bitmap-id of the default icon bitmap for this frame.
166 Or -1 if none has been allocated yet. */
167 ptrdiff_t icon_bitmap_id;
169 /* The root window of this screen. */
170 Window root_window;
172 /* Client leader window. */
173 Window client_leader_window;
175 /* The cursor to use for vertical scroll bars. */
176 Cursor vertical_scroll_bar_cursor;
178 /* The cursor to use for horizontal scroll bars. */
179 Cursor horizontal_scroll_bar_cursor;
181 /* The invisible cursor used for pointer blanking.
182 Unused if this display supports Xfixes extension. */
183 Cursor invisible_cursor;
185 /* Function used to toggle pointer visibility on this display. */
186 void (*toggle_visible_pointer) (struct frame *, bool);
188 #ifdef USE_GTK
189 /* The GDK cursor for scroll bars and popup menus. */
190 GdkCursor *xg_cursor;
191 #endif
193 /* X Resource data base */
194 XrmDatabase xrdb;
196 /* Minimum width over all characters in all fonts in font_table. */
197 int smallest_char_width;
199 /* Minimum font height over all fonts in font_table. */
200 int smallest_font_height;
202 /* Reusable Graphics Context for drawing a cursor in a non-default face. */
203 GC scratch_cursor_gc;
205 /* Information about the range of text currently shown in
206 mouse-face. */
207 Mouse_HLInfo mouse_highlight;
209 /* Logical identifier of this display. */
210 unsigned x_id;
212 /* Default name for all frames on this display. */
213 char *x_id_name;
215 /* The number of fonts opened for this display. */
216 int n_fonts;
218 /* Pointer to bitmap records. */
219 struct x_bitmap_record *bitmaps;
221 /* Allocated size of bitmaps field. */
222 ptrdiff_t bitmaps_size;
224 /* Last used bitmap index. */
225 ptrdiff_t bitmaps_last;
227 /* Which modifier keys are on which modifier bits?
229 With each keystroke, X returns eight bits indicating which modifier
230 keys were held down when the key was pressed. The interpretation
231 of the top five modifier bits depends on what keys are attached
232 to them. If the Meta_L and Meta_R keysyms are on mod5, then mod5
233 is the meta bit.
235 meta_mod_mask is a mask containing the bits used for the meta key.
236 It may have more than one bit set, if more than one modifier bit
237 has meta keys on it. Basically, if EVENT is a KeyPress event,
238 the meta key is pressed if (EVENT.state & meta_mod_mask) != 0.
240 shift_lock_mask is LockMask if the XK_Shift_Lock keysym is on the
241 lock modifier bit, or zero otherwise. Non-alphabetic keys should
242 only be affected by the lock modifier bit if XK_Shift_Lock is in
243 use; XK_Caps_Lock should only affect alphabetic keys. With this
244 arrangement, the lock modifier should shift the character if
245 (EVENT.state & shift_lock_mask) != 0. */
246 int meta_mod_mask, shift_lock_mask;
248 /* These are like meta_mod_mask, but for different modifiers. */
249 int alt_mod_mask, super_mod_mask, hyper_mod_mask;
251 /* Communication with window managers. */
252 Atom Xatom_wm_protocols;
254 /* Kinds of protocol things we may receive. */
255 Atom Xatom_wm_take_focus;
256 Atom Xatom_wm_save_yourself;
257 Atom Xatom_wm_delete_window;
259 /* Atom for indicating window state to the window manager. */
260 Atom Xatom_wm_change_state;
262 /* Other WM communication */
263 Atom Xatom_wm_configure_denied; /* When our config request is denied */
264 Atom Xatom_wm_window_moved; /* When the WM moves us. */
265 Atom Xatom_wm_client_leader; /* Id of client leader window. */
267 /* EditRes protocol */
268 Atom Xatom_editres;
270 /* More atoms, which are selection types. */
271 Atom Xatom_CLIPBOARD, Xatom_TIMESTAMP, Xatom_TEXT, Xatom_DELETE,
272 Xatom_COMPOUND_TEXT, Xatom_UTF8_STRING,
273 Xatom_MULTIPLE, Xatom_INCR, Xatom_EMACS_TMP, Xatom_TARGETS, Xatom_NULL,
274 Xatom_ATOM, Xatom_ATOM_PAIR, Xatom_CLIPBOARD_MANAGER;
276 /* More atoms for font properties. The last three are private
277 properties, see the comments in src/fontset.h. */
278 Atom Xatom_PIXEL_SIZE, Xatom_AVERAGE_WIDTH,
279 Xatom_MULE_BASELINE_OFFSET, Xatom_MULE_RELATIVE_COMPOSE,
280 Xatom_MULE_DEFAULT_ASCENT;
282 /* More atoms for Ghostscript support. */
283 Atom Xatom_DONE, Xatom_PAGE;
285 /* Atoms used in toolkit scroll bar client messages. */
286 Atom Xatom_Scrollbar, Xatom_Horizontal_Scrollbar;
288 /* Atom used in XEmbed client messages. */
289 Atom Xatom_XEMBED, Xatom_XEMBED_INFO;
291 /* The frame (if any) which has the X window that has keyboard focus.
292 Zero if none. This is examined by Ffocus_frame in xfns.c. Note
293 that a mere EnterNotify event can set this; if you need to know the
294 last frame specified in a FocusIn or FocusOut event, use
295 x_focus_event_frame. */
296 struct frame *x_focus_frame;
298 /* The last frame mentioned in a FocusIn or FocusOut event. This is
299 separate from x_focus_frame, because whether or not LeaveNotify
300 events cause us to lose focus depends on whether or not we have
301 received a FocusIn event for it. */
302 struct frame *x_focus_event_frame;
304 /* The frame which currently has the visual highlight, and should get
305 keyboard input (other sorts of input have the frame encoded in the
306 event). It points to the X focus frame's selected window's
307 frame. It differs from x_focus_frame when we're using a global
308 minibuffer. */
309 struct frame *x_highlight_frame;
311 /* The frame waiting to be auto-raised in XTread_socket. */
312 struct frame *x_pending_autoraise_frame;
314 /* The frame where the mouse was last time we reported a ButtonPress event. */
315 struct frame *last_mouse_frame;
317 /* The frame where the mouse was last time we reported a mouse position. */
318 struct frame *last_mouse_glyph_frame;
320 /* The frame where the mouse was last time we reported a mouse motion. */
321 struct frame *last_mouse_motion_frame;
323 /* The scroll bar in which the last X motion event occurred. */
324 struct scroll_bar *last_mouse_scroll_bar;
326 /* Time of last user interaction as returned in X events on this display. */
327 Time last_user_time;
329 /* Position where the mouse was last time we reported a motion.
330 This is a position on last_mouse_motion_frame. */
331 int last_mouse_motion_x;
332 int last_mouse_motion_y;
334 /* Where the mouse was last time we reported a mouse position.
335 This is a rectangle on last_mouse_glyph_frame. */
336 XRectangle last_mouse_glyph;
338 /* Time of last mouse movement on this display. This is a hack because
339 we would really prefer that XTmouse_position would return the time
340 associated with the position it returns, but there doesn't seem to be
341 any way to wrest the time-stamp from the server along with the position
342 query. So, we just keep track of the time of the last movement we
343 received, and return that in hopes that it's somewhat accurate. */
344 Time last_mouse_movement_time;
346 /* The gray pixmap. */
347 Pixmap gray;
349 #ifdef HAVE_X_I18N
350 /* XIM (X Input method). */
351 XIM xim;
352 XIMStyles *xim_styles;
353 struct xim_inst_t *xim_callback_data;
354 #endif
356 /* If non-null, a cache of the colors in the color map. Don't
357 use this directly, call x_color_cells instead. */
358 XColor *color_cells;
359 int ncolor_cells;
361 /* Bits and shifts to use to compose pixel values on TrueColor visuals. */
362 int red_bits, blue_bits, green_bits;
363 int red_offset, blue_offset, green_offset;
365 /* The type of window manager we have. If we move FRAME_OUTER_WINDOW
366 to x/y 0/0, some window managers (type A) puts the window manager
367 decorations outside the screen and FRAME_OUTER_WINDOW exactly at 0/0.
368 Other window managers (type B) puts the window including decorations
369 at 0/0, so FRAME_OUTER_WINDOW is a bit below 0/0.
370 Record the type of WM in use so we can compensate for type A WMs. */
371 enum
373 X_WMTYPE_UNKNOWN,
374 X_WMTYPE_A,
375 X_WMTYPE_B
376 } wm_type;
379 /* Atoms that are drag and drop atoms */
380 Atom *x_dnd_atoms;
381 ptrdiff_t x_dnd_atoms_size;
382 ptrdiff_t x_dnd_atoms_length;
384 /* Extended window manager hints, Atoms supported by the window manager and
385 atoms for setting the window type. */
386 Atom Xatom_net_supported, Xatom_net_supporting_wm_check;
387 Atom *net_supported_atoms;
388 int nr_net_supported_atoms;
389 Window net_supported_window;
390 Atom Xatom_net_window_type, Xatom_net_window_type_tooltip;
391 Atom Xatom_net_active_window;
393 /* Atoms dealing with EWMH (i.e. _NET_...) */
394 Atom Xatom_net_wm_state, Xatom_net_wm_state_fullscreen,
395 Xatom_net_wm_state_maximized_horz, Xatom_net_wm_state_maximized_vert,
396 Xatom_net_wm_state_sticky, Xatom_net_wm_state_hidden,
397 Xatom_net_frame_extents,
398 Xatom_net_current_desktop, Xatom_net_workarea;
400 /* XSettings atoms and windows. */
401 Atom Xatom_xsettings_sel, Xatom_xsettings_prop, Xatom_xsettings_mgr;
402 Window xsettings_window;
404 /* Frame name and icon name */
405 Atom Xatom_net_wm_name, Xatom_net_wm_icon_name;
406 /* Frame opacity */
407 Atom Xatom_net_wm_window_opacity;
409 /* SM */
410 Atom Xatom_SM_CLIENT_ID;
413 #ifdef HAVE_X_I18N
414 /* Whether or not to use XIM if we have it. */
415 extern bool use_xim;
416 #endif
418 /* This is a chain of structures for all the X displays currently in use. */
419 extern struct x_display_info *x_display_list;
421 extern struct x_display_info *x_display_info_for_display (Display *);
422 extern struct frame *x_top_window_to_frame (struct x_display_info *, int);
423 extern struct x_display_info *x_term_init (Lisp_Object, char *, char *);
424 extern bool x_display_ok (const char *);
426 extern void select_visual (struct x_display_info *);
428 /* Each X frame object points to its own struct x_output object
429 in the output_data.x field. The x_output structure contains
430 the information that is specific to X windows. */
432 struct x_output
434 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
435 /* Height of menu bar widget, in pixels. This value
436 is not meaningful if the menubar is turned off. */
437 int menubar_height;
438 #endif
440 /* Height of tool bar widget, in pixels. top_height is used if tool bar
441 at top, bottom_height if tool bar is at the bottom.
442 Zero if not using an external tool bar or if tool bar is vertical. */
443 int toolbar_top_height, toolbar_bottom_height;
445 /* Width of tool bar widget, in pixels. left_width is used if tool bar
446 at left, right_width if tool bar is at the right.
447 Zero if not using an external tool bar or if tool bar is horizontal. */
448 int toolbar_left_width, toolbar_right_width;
450 /* The tiled border used when the mouse is out of the frame. */
451 Pixmap border_tile;
453 /* Here are the Graphics Contexts for the default font. */
454 GC normal_gc; /* Normal video */
455 GC reverse_gc; /* Reverse video */
456 GC cursor_gc; /* cursor drawing */
458 /* The X window used for this frame.
459 May be zero while the frame object is being created
460 and the X window has not yet been created. */
461 Window window_desc;
463 /* The X window used for the bitmap icon;
464 or 0 if we don't have a bitmap icon. */
465 Window icon_desc;
467 /* The X window that is the parent of this X window.
468 Usually this is a window that was made by the window manager,
469 but it can be the root window, and it can be explicitly specified
470 (see the explicit_parent field, below). */
471 Window parent_desc;
473 #ifdef USE_X_TOOLKIT
474 /* The widget of this screen. This is the window of a "shell" widget. */
475 Widget widget;
476 /* The XmPanedWindows... */
477 Widget column_widget;
478 /* The widget of the edit portion of this screen; the window in
479 "window_desc" is inside of this. */
480 Widget edit_widget;
482 Widget menubar_widget;
483 #endif
485 #ifdef USE_GTK
486 /* The widget of this screen. This is the window of a top widget. */
487 GtkWidget *widget;
488 /* The widget of the edit portion of this screen; the window in
489 "window_desc" is inside of this. */
490 GtkWidget *edit_widget;
491 /* The widget used for laying out widgets vertically. */
492 GtkWidget *vbox_widget;
493 /* The widget used for laying out widgets horizontally. */
494 GtkWidget *hbox_widget;
495 /* The menubar in this frame. */
496 GtkWidget *menubar_widget;
497 /* The tool bar in this frame */
498 GtkWidget *toolbar_widget;
499 #ifdef HAVE_GTK_HANDLE_BOX_NEW
500 /* The handle box that makes the tool bar detachable. */
501 GtkWidget *handlebox_widget;
502 #endif
503 /* True if tool bar is packed into the hbox widget (i.e. vertical). */
504 bool_bf toolbar_in_hbox : 1;
505 bool_bf toolbar_is_packed : 1;
507 /* The last size hints set. */
508 GdkGeometry size_hints;
509 long hint_flags;
511 #ifdef USE_GTK_TOOLTIP
512 GtkTooltip *ttip_widget;
513 GtkWidget *ttip_lbl;
514 GtkWindow *ttip_window;
515 #endif /* USE_GTK_TOOLTIP */
517 #endif /* USE_GTK */
519 /* If >=0, a bitmap index. The indicated bitmap is used for the
520 icon. */
521 ptrdiff_t icon_bitmap;
523 /* Default ASCII font of this frame. */
524 struct font *font;
526 /* The baseline offset of the default ASCII font. */
527 int baseline_offset;
529 /* If a fontset is specified for this frame instead of font, this
530 value contains an ID of the fontset, else -1. */
531 int fontset;
533 unsigned long cursor_pixel;
534 unsigned long border_pixel;
535 unsigned long mouse_pixel;
536 unsigned long cursor_foreground_pixel;
538 /* Foreground color for scroll bars. A value of -1 means use the
539 default (black for non-toolkit scroll bars). */
540 unsigned long scroll_bar_foreground_pixel;
542 /* Background color for scroll bars. A value of -1 means use the
543 default (background color of the frame for non-toolkit scroll
544 bars). */
545 unsigned long scroll_bar_background_pixel;
547 #if defined (USE_LUCID) && defined (USE_TOOLKIT_SCROLL_BARS)
548 /* Top and bottom shadow colors for 3D Lucid scrollbars.
549 -1 means let the scroll compute them itself. */
550 unsigned long scroll_bar_top_shadow_pixel;
551 unsigned long scroll_bar_bottom_shadow_pixel;
552 #endif
554 /* Descriptor for the cursor in use for this window. */
555 Cursor text_cursor;
556 Cursor nontext_cursor;
557 Cursor modeline_cursor;
558 Cursor hand_cursor;
559 Cursor hourglass_cursor;
560 Cursor horizontal_drag_cursor;
561 Cursor vertical_drag_cursor;
562 Cursor current_cursor;
564 /* Window whose cursor is hourglass_cursor. This window is temporarily
565 mapped to display an hourglass cursor. */
566 Window hourglass_window;
568 /* These are the current window manager hints. It seems that
569 XSetWMHints, when presented with an unset bit in the `flags'
570 member of the hints structure, does not leave the corresponding
571 attribute unchanged; rather, it resets that attribute to its
572 default value. For example, unless you set the `icon_pixmap'
573 field and the `IconPixmapHint' bit, XSetWMHints will forget what
574 your icon pixmap was. This is rather troublesome, since some of
575 the members (for example, `input' and `icon_pixmap') want to stay
576 the same throughout the execution of Emacs. So, we keep this
577 structure around, just leaving values in it and adding new bits
578 to the mask as we go. */
579 XWMHints wm_hints;
581 /* This is the Emacs structure for the X display this frame is on. */
582 struct x_display_info *display_info;
584 /* This is a button event that wants to activate the menubar.
585 We save it here until the command loop gets to think about it. */
586 XEvent *saved_menu_event;
588 /* This is the widget id used for this frame's menubar in lwlib. */
589 #ifdef USE_X_TOOLKIT
590 int id;
591 #endif
593 /* True means hourglass cursor is currently displayed. */
594 bool_bf hourglass_p : 1;
596 /* True means our parent is another application's window
597 and was explicitly specified. */
598 bool_bf explicit_parent : 1;
600 /* True means tried already to make this frame visible. */
601 bool_bf asked_for_visible : 1;
603 /* True if this frame was ever previously visible. */
604 bool_bf has_been_visible : 1;
606 /* Xt waits for a ConfigureNotify event from the window manager in
607 EmacsFrameSetCharSize when the shell widget is resized. For some
608 window managers like fvwm2 2.2.5 and KDE 2.1 this event doesn't
609 arrive for an unknown reason and Emacs hangs in Xt. If this is
610 false, tell Xt not to wait. */
611 bool_bf wait_for_wm : 1;
613 /* True if _NET_WM_STATE_HIDDEN is set for this frame. */
614 bool_bf net_wm_state_hidden_seen : 1;
616 #ifdef HAVE_X_I18N
617 /* Input context (currently, this means Compose key handler setup). */
618 XIC xic;
619 XIMStyle xic_style;
620 XFontSet xic_xfs;
621 #endif
623 /* Relief GCs, colors etc. */
624 struct relief
626 GC gc;
627 unsigned long pixel;
629 black_relief, white_relief;
631 /* The background for which the above relief GCs were set up.
632 They are changed only when a different background is involved. */
633 unsigned long relief_background;
635 /* As x_pixels_diff, but to FRAME_OUTER_WINDOW. For some reason the
636 two might differ by a pixel, depending on WM */
637 int x_pixels_outer_diff;
639 /* As y_pixels_diff, but to FRAME_OUTER_WINDOW. In the toolkit version,
640 these may differ because this does not take into account possible
641 menubar. y_pixels_diff is with menubar height included */
642 int y_pixels_outer_diff;
644 /* Keep track of focus. May be EXPLICIT if we received a FocusIn for this
645 frame, or IMPLICIT if we received an EnterNotify.
646 FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
647 int focus_state;
649 /* The offset we need to add to compensate for type A WMs. */
650 int move_offset_top;
651 int move_offset_left;
654 #define No_Cursor (None)
656 enum
658 /* Values for focus_state, used as bit mask.
659 EXPLICIT means we received a FocusIn for the frame and know it has
660 the focus. IMPLICIT means we received an EnterNotify and the frame
661 may have the focus if no window manager is running.
662 FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
663 FOCUS_NONE = 0,
664 FOCUS_IMPLICIT = 1,
665 FOCUS_EXPLICIT = 2
669 /* Return the X output data for frame F. */
670 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
672 /* Return the X window used for displaying data in frame F. */
673 #define FRAME_X_WINDOW(f) ((f)->output_data.x->window_desc)
675 /* Return the outermost X window associated with the frame F. */
676 #ifdef USE_X_TOOLKIT
677 #define FRAME_OUTER_WINDOW(f) ((f)->output_data.x->widget ? \
678 XtWindow ((f)->output_data.x->widget) : \
679 FRAME_X_WINDOW (f))
680 #else
681 #ifdef USE_GTK
682 /* Functions not present in older Gtk+ */
684 #ifndef HAVE_GTK_WIDGET_GET_WINDOW
685 #define gtk_widget_get_window(w) ((w)->window)
686 #endif
687 #ifndef HAVE_GTK_WIDGET_GET_MAPPED
688 #define gtk_widget_get_mapped(w) (GTK_WIDGET_MAPPED (w))
689 #endif
690 #ifndef HAVE_GTK_ADJUSTMENT_GET_PAGE_SIZE
691 #define gtk_adjustment_get_page_size(w) ((w)->page_size)
692 #define gtk_adjustment_get_upper(w) ((w)->upper)
693 #endif
695 #ifdef HAVE_GTK3
696 #define DEFAULT_GDK_DISPLAY() \
697 gdk_x11_display_get_xdisplay (gdk_display_get_default ())
698 #else
699 #undef GDK_WINDOW_XID
700 #define GDK_WINDOW_XID(w) GDK_WINDOW_XWINDOW (w)
701 #define DEFAULT_GDK_DISPLAY() GDK_DISPLAY ()
702 #define gtk_widget_get_preferred_size(a, ign, b) \
703 gtk_widget_size_request (a, b)
704 #endif
706 #define GTK_WIDGET_TO_X_WIN(w) \
707 ((w) && gtk_widget_get_window (w) \
708 ? GDK_WINDOW_XID (gtk_widget_get_window (w)) : 0)
710 #define FRAME_GTK_OUTER_WIDGET(f) ((f)->output_data.x->widget)
711 #define FRAME_GTK_WIDGET(f) ((f)->output_data.x->edit_widget)
712 #define FRAME_OUTER_WINDOW(f) \
713 (FRAME_GTK_OUTER_WIDGET (f) ? \
714 GTK_WIDGET_TO_X_WIN (FRAME_GTK_OUTER_WIDGET (f)) : \
715 FRAME_X_WINDOW (f))
717 #else /* !USE_GTK */
718 #define FRAME_OUTER_WINDOW(f) (FRAME_X_WINDOW (f))
719 #endif /* !USE_GTK */
720 #endif
722 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
723 #define FRAME_MENUBAR_HEIGHT(f) ((f)->output_data.x->menubar_height)
724 #else
725 #define FRAME_MENUBAR_HEIGHT(f) ((void) f, 0)
726 #endif /* USE_X_TOOLKIT || USE_GTK */
728 #define FRAME_FONT(f) ((f)->output_data.x->font)
729 #define FRAME_FONTSET(f) ((f)->output_data.x->fontset)
730 #define FRAME_TOOLBAR_TOP_HEIGHT(f) ((f)->output_data.x->toolbar_top_height)
731 #define FRAME_TOOLBAR_BOTTOM_HEIGHT(f) \
732 ((f)->output_data.x->toolbar_bottom_height)
733 #define FRAME_TOOLBAR_HEIGHT(f) \
734 (FRAME_TOOLBAR_TOP_HEIGHT (f) + FRAME_TOOLBAR_BOTTOM_HEIGHT (f))
735 #define FRAME_TOOLBAR_LEFT_WIDTH(f) ((f)->output_data.x->toolbar_left_width)
736 #define FRAME_TOOLBAR_RIGHT_WIDTH(f) ((f)->output_data.x->toolbar_right_width)
737 #define FRAME_TOOLBAR_WIDTH(f) \
738 (FRAME_TOOLBAR_LEFT_WIDTH (f) + FRAME_TOOLBAR_RIGHT_WIDTH (f))
739 #define FRAME_BASELINE_OFFSET(f) ((f)->output_data.x->baseline_offset)
741 /* This gives the x_display_info structure for the display F is on. */
742 #define FRAME_DISPLAY_INFO(f) ((f)->output_data.x->display_info)
744 /* This is the `Display *' which frame F is on. */
745 #define FRAME_X_DISPLAY(f) (FRAME_DISPLAY_INFO (f)->display)
747 /* This is the `Screen *' which frame F is on. */
748 #define FRAME_X_SCREEN(f) (FRAME_DISPLAY_INFO (f)->screen)
750 /* This is the screen index number of screen which frame F is on. */
751 #define FRAME_X_SCREEN_NUMBER(f) XScreenNumberOfScreen (FRAME_X_SCREEN (f))
753 /* This is the Visual which frame F is on. */
754 #define FRAME_X_VISUAL(f) FRAME_DISPLAY_INFO (f)->visual
756 /* This is the Colormap which frame F uses. */
757 #define FRAME_X_COLORMAP(f) FRAME_DISPLAY_INFO (f)->cmap
759 /* The difference in pixels between the top left corner of the
760 Emacs window (including possible window manager decorations)
761 and FRAME_X_WINDOW (f). */
762 #define FRAME_OUTER_TO_INNER_DIFF_X(f) \
763 ((f)->output_data.x->x_pixels_outer_diff)
764 #define FRAME_OUTER_TO_INNER_DIFF_Y(f) \
765 ((f)->output_data.x->y_pixels_outer_diff \
766 + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f))
769 #define FRAME_XIC(f) ((f)->output_data.x->xic)
770 #define FRAME_X_XIM(f) (FRAME_DISPLAY_INFO (f)->xim)
771 #define FRAME_X_XIM_STYLES(f) (FRAME_DISPLAY_INFO (f)->xim_styles)
772 #define FRAME_XIC_STYLE(f) ((f)->output_data.x->xic_style)
773 #define FRAME_XIC_FONTSET(f) ((f)->output_data.x->xic_xfs)
775 /* X-specific scroll bar stuff. */
777 /* We represent scroll bars as lisp vectors. This allows us to place
778 references to them in windows without worrying about whether we'll
779 end up with windows referring to dead scroll bars; the garbage
780 collector will free it when its time comes.
782 We use struct scroll_bar as a template for accessing fields of the
783 vector. */
785 struct scroll_bar
787 /* These fields are shared by all vectors. */
788 struct vectorlike_header header;
790 /* The window we're a scroll bar for. */
791 Lisp_Object window;
793 /* The next and previous in the chain of scroll bars in this frame. */
794 Lisp_Object next, prev;
796 /* Fields from `x_window' down will not be traced by the GC. */
798 /* The X window representing this scroll bar. */
799 Window x_window;
801 /* The position and size of the scroll bar in pixels, relative to the
802 frame. */
803 int top, left, width, height;
805 /* The starting and ending positions of the handle, relative to the
806 handle area (i.e. zero is the top position, not
807 SCROLL_BAR_TOP_BORDER). If they're equal, that means the handle
808 hasn't been drawn yet.
810 These are not actually the locations where the beginning and end
811 are drawn; in order to keep handles from becoming invisible when
812 editing large files, we establish a minimum height by always
813 drawing handle bottoms VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
814 where they would be normally; the bottom and top are in a
815 different co-ordinate system. */
816 int start, end;
818 /* If the scroll bar handle is currently being dragged by the user,
819 this is the number of pixels from the top of the handle to the
820 place where the user grabbed it. If the handle isn't currently
821 being dragged, this is -1. */
822 int dragging;
824 #if defined (USE_TOOLKIT_SCROLL_BARS) && defined (USE_LUCID)
825 /* Last scroll bar part seen in xaw_jump_callback and xaw_scroll_callback. */
826 enum scroll_bar_part last_seen_part;
827 #endif
829 #if defined (USE_TOOLKIT_SCROLL_BARS) && !defined (USE_GTK)
830 /* Last value of whole for horizontal scrollbars. */
831 int whole;
832 #endif
834 /* 1 if the scroll bar is horizontal. */
835 bool horizontal;
838 /* Turning a lisp vector value into a pointer to a struct scroll_bar. */
839 #define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec))
841 #ifdef USE_X_TOOLKIT
843 /* Extract the X widget of the scroll bar from a struct scroll_bar.
844 XtWindowToWidget should be fast enough since Xt uses a hash table
845 to map windows to widgets. */
847 #define SCROLL_BAR_X_WIDGET(dpy, ptr) \
848 XtWindowToWidget (dpy, ptr->x_window)
850 /* Store a widget id in a struct scroll_bar. */
852 #define SET_SCROLL_BAR_X_WIDGET(ptr, w) \
853 do { \
854 Window window = XtWindow (w); \
855 ptr->x_window = window; \
856 } while (false)
858 #endif /* USE_X_TOOLKIT */
860 /* Return the inside width of a vertical scroll bar, given the outside
861 width. */
862 #define VERTICAL_SCROLL_BAR_INSIDE_WIDTH(f, width) \
863 ((width) \
864 - VERTICAL_SCROLL_BAR_LEFT_BORDER \
865 - VERTICAL_SCROLL_BAR_RIGHT_BORDER)
867 /* Return the length of the rectangle within which the top of the
868 handle must stay. This isn't equivalent to the inside height,
869 because the scroll bar handle has a minimum height.
871 This is the real range of motion for the scroll bar, so when we're
872 scaling buffer positions to scroll bar positions, we use this, not
873 VERTICAL_SCROLL_BAR_INSIDE_HEIGHT. */
874 #define VERTICAL_SCROLL_BAR_TOP_RANGE(f, height) \
875 (VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, height) - VERTICAL_SCROLL_BAR_MIN_HANDLE)
877 /* Return the inside height of vertical scroll bar, given the outside
878 height. See VERTICAL_SCROLL_BAR_TOP_RANGE too. */
879 #define VERTICAL_SCROLL_BAR_INSIDE_HEIGHT(f, height) \
880 ((height) - VERTICAL_SCROLL_BAR_TOP_BORDER - VERTICAL_SCROLL_BAR_BOTTOM_BORDER)
882 /* Return the inside height of a horizontal scroll bar, given the outside
883 height. */
884 #define HORIZONTAL_SCROLL_BAR_INSIDE_HEIGHT(f, height) \
885 ((height) \
886 - HORIZONTAL_SCROLL_BAR_TOP_BORDER \
887 - HORIZONTAL_SCROLL_BAR_BOTTOM_BORDER)
889 /* Return the length of the rectangle within which the left part of the
890 handle must stay. This isn't equivalent to the inside width, because
891 the scroll bar handle has a minimum width.
893 This is the real range of motion for the scroll bar, so when we're
894 scaling buffer positions to scroll bar positions, we use this, not
895 HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH. */
896 #define HORIZONTAL_SCROLL_BAR_LEFT_RANGE(f, width) \
897 (HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH (f, width) - HORIZONTAL_SCROLL_BAR_MIN_HANDLE)
899 /* Return the inside width of horizontal scroll bar, given the outside
900 width. See HORIZONTAL_SCROLL_BAR_LEFT_RANGE too. */
901 #define HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH(f, width) \
902 ((width) - HORIZONTAL_SCROLL_BAR_LEFT_BORDER - HORIZONTAL_SCROLL_BAR_LEFT_BORDER)
905 /* Border widths for scroll bars.
907 Scroll bar windows don't have any X borders; their border width is
908 set to zero, and we redraw borders ourselves. This makes the code
909 a bit cleaner, since we don't have to convert between outside width
910 (used when relating to the rest of the screen) and inside width
911 (used when sizing and drawing the scroll bar window itself).
913 The handle moves up and down/back and forth in a rectangle inset
914 from the edges of the scroll bar. These are widths by which we
915 inset the handle boundaries from the scroll bar edges. */
916 #define VERTICAL_SCROLL_BAR_LEFT_BORDER (2)
917 #define VERTICAL_SCROLL_BAR_RIGHT_BORDER (2)
918 #define VERTICAL_SCROLL_BAR_TOP_BORDER (2)
919 #define VERTICAL_SCROLL_BAR_BOTTOM_BORDER (2)
921 #define HORIZONTAL_SCROLL_BAR_LEFT_BORDER (2)
922 #define HORIZONTAL_SCROLL_BAR_RIGHT_BORDER (2)
923 #define HORIZONTAL_SCROLL_BAR_TOP_BORDER (2)
924 #define HORIZONTAL_SCROLL_BAR_BOTTOM_BORDER (2)
926 /* Minimum lengths for scroll bar handles, in pixels. */
927 #define VERTICAL_SCROLL_BAR_MIN_HANDLE (5)
928 #define HORIZONTAL_SCROLL_BAR_MIN_HANDLE (5)
930 /* If a struct input_event has a kind which is SELECTION_REQUEST_EVENT
931 or SELECTION_CLEAR_EVENT, then its contents are really described
932 by this structure. */
934 /* For an event of kind SELECTION_REQUEST_EVENT,
935 this structure really describes the contents. */
937 struct selection_input_event
939 int kind;
940 struct x_display_info *dpyinfo;
941 /* We spell it with an "o" here because X does. */
942 Window requestor;
943 Atom selection, target, property;
944 Time time;
947 /* Unlike macros below, this can't be used as an lvalue. */
948 INLINE Display *
949 SELECTION_EVENT_DISPLAY (struct input_event *ev)
951 return ((struct selection_input_event *) ev)->dpyinfo->display;
953 #define SELECTION_EVENT_DPYINFO(eventp) \
954 (((struct selection_input_event *) (eventp))->dpyinfo)
955 /* We spell it with an "o" here because X does. */
956 #define SELECTION_EVENT_REQUESTOR(eventp) \
957 (((struct selection_input_event *) (eventp))->requestor)
958 #define SELECTION_EVENT_SELECTION(eventp) \
959 (((struct selection_input_event *) (eventp))->selection)
960 #define SELECTION_EVENT_TARGET(eventp) \
961 (((struct selection_input_event *) (eventp))->target)
962 #define SELECTION_EVENT_PROPERTY(eventp) \
963 (((struct selection_input_event *) (eventp))->property)
964 #define SELECTION_EVENT_TIME(eventp) \
965 (((struct selection_input_event *) (eventp))->time)
967 /* From xfns.c. */
969 extern void x_free_gcs (struct frame *);
970 extern void x_relative_mouse_position (struct frame *, int *, int *);
972 /* From xrdb.c. */
974 XrmDatabase x_load_resources (Display *, const char *, const char *,
975 const char *);
977 /* Defined in xterm.c */
979 extern int x_text_icon (struct frame *, const char *);
980 extern void x_catch_errors (Display *);
981 extern void x_check_errors (Display *, const char *)
982 ATTRIBUTE_FORMAT_PRINTF (2, 0);
983 extern bool x_had_errors_p (Display *);
984 extern void x_uncatch_errors (void);
985 extern void x_clear_errors (Display *);
986 extern void xembed_request_focus (struct frame *);
987 extern void x_ewmh_activate_frame (struct frame *);
988 extern void x_delete_terminal (struct terminal *terminal);
989 extern unsigned long x_copy_color (struct frame *, unsigned long);
990 #ifdef USE_X_TOOLKIT
991 extern XtAppContext Xt_app_con;
992 extern void x_activate_timeout_atimer (void);
993 #endif
994 #ifdef USE_LUCID
995 extern bool x_alloc_lighter_color_for_widget (Widget, Display *, Colormap,
996 unsigned long *,
997 double, int);
998 #endif
999 extern bool x_alloc_nearest_color (struct frame *, Colormap, XColor *);
1000 extern void x_clear_area (Display *, Window, int, int, int, int);
1001 #if !defined USE_X_TOOLKIT && !defined USE_GTK
1002 extern void x_mouse_leave (struct x_display_info *);
1003 #endif
1005 #if defined USE_X_TOOLKIT || defined USE_MOTIF
1006 extern int x_dispatch_event (XEvent *, Display *);
1007 #endif
1008 extern int x_x_to_emacs_modifiers (struct x_display_info *, int);
1010 INLINE int
1011 x_display_pixel_height (struct x_display_info *dpyinfo)
1013 return HeightOfScreen (dpyinfo->screen);
1016 INLINE int
1017 x_display_pixel_width (struct x_display_info *dpyinfo)
1019 return WidthOfScreen (dpyinfo->screen);
1022 extern void x_set_sticky (struct frame *, Lisp_Object, Lisp_Object);
1023 extern void x_wait_for_event (struct frame *, int);
1024 extern void x_clear_under_internal_border (struct frame *f);
1026 /* Defined in xselect.c. */
1028 extern void x_handle_property_notify (const XPropertyEvent *);
1029 extern void x_handle_selection_notify (const XSelectionEvent *);
1030 extern void x_handle_selection_event (struct input_event *);
1031 extern void x_clear_frame_selections (struct frame *);
1033 extern void x_send_client_event (Lisp_Object display,
1034 Lisp_Object dest,
1035 Lisp_Object from,
1036 Atom message_type,
1037 Lisp_Object format,
1038 Lisp_Object values);
1040 extern int x_handle_dnd_message (struct frame *,
1041 const XClientMessageEvent *,
1042 struct x_display_info *,
1043 struct input_event *);
1044 extern int x_check_property_data (Lisp_Object);
1045 extern void x_fill_property_data (Display *,
1046 Lisp_Object,
1047 void *,
1048 int);
1049 extern Lisp_Object x_property_data_to_lisp (struct frame *,
1050 const unsigned char *,
1051 Atom,
1052 int,
1053 unsigned long);
1054 extern void x_clipboard_manager_save_frame (Lisp_Object);
1055 extern void x_clipboard_manager_save_all (void);
1057 #ifdef USE_GTK
1058 extern int xg_set_icon (struct frame *, Lisp_Object);
1059 extern int xg_set_icon_from_xpm_data (struct frame *, const char **);
1060 #endif /* USE_GTK */
1062 extern void xic_free_xfontset (struct frame *);
1063 extern void create_frame_xic (struct frame *);
1064 extern void destroy_frame_xic (struct frame *);
1065 extern void xic_set_preeditarea (struct window *, int, int);
1066 extern void xic_set_statusarea (struct frame *);
1067 extern void xic_set_xfontset (struct frame *, const char *);
1068 extern bool x_defined_color (struct frame *, const char *, XColor *, bool);
1069 #ifdef HAVE_X_I18N
1070 extern void free_frame_xic (struct frame *);
1071 # if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
1072 extern char * xic_create_fontsetname (const char *base_fontname, int motif);
1073 # endif
1074 #endif
1076 /* Defined in xfaces.c */
1078 #ifdef USE_X_TOOLKIT
1079 extern void x_free_dpy_colors (Display *, Screen *, Colormap,
1080 unsigned long *, int);
1081 #endif /* USE_X_TOOLKIT */
1083 /* Defined in xmenu.c */
1085 #if defined USE_X_TOOLKIT || defined USE_GTK
1086 extern Lisp_Object xw_popup_dialog (struct frame *, Lisp_Object, Lisp_Object);
1087 #endif
1089 #if defined USE_GTK || defined USE_MOTIF
1090 extern void x_menu_set_in_use (int);
1091 #endif
1092 extern void x_menu_wait_for_event (void *data);
1093 extern void initialize_frame_menubar (struct frame *);
1095 /* Defined in xsmfns.c */
1096 #ifdef HAVE_X_SM
1097 extern void x_session_initialize (struct x_display_info *dpyinfo);
1098 extern int x_session_have_connection (void);
1099 extern void x_session_close (void);
1100 #endif
1102 /* Defined in xterm.c */
1104 extern Lisp_Object Qx_gtk_map_stock;
1106 /* Is the frame embedded into another application? */
1108 #define FRAME_X_EMBEDDED_P(f) (FRAME_X_OUTPUT(f)->explicit_parent != 0)
1110 #define STORE_XCHAR2B(chp, b1, b2) \
1111 ((chp)->byte1 = (b1), (chp)->byte2 = (b2))
1113 #define XCHAR2B_BYTE1(chp) \
1114 ((chp)->byte1)
1116 #define XCHAR2B_BYTE2(chp) \
1117 ((chp)->byte2)
1119 #define STORE_NATIVE_RECT(nr,rx,ry,rwidth,rheight) \
1120 ((nr).x = (rx), \
1121 (nr).y = (ry), \
1122 (nr).width = (rwidth), \
1123 (nr).height = (rheight))
1125 INLINE_HEADER_END
1127 #endif /* XTERM_H */