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