* etc/NEWS: Document package-hiding functionality
[emacs.git] / src / xterm.h
blob0366261b2f4d1da6bc647f6141fe5b09d7128973
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 /* Keep track of focus. May be EXPLICIT if we received a FocusIn for this
632 frame, or IMPLICIT if we received an EnterNotify.
633 FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
634 int focus_state;
636 /* The offset we need to add to compensate for type A WMs. */
637 int move_offset_top;
638 int move_offset_left;
641 /* Extreme 'short' and 'long' values suitable for libX11. */
642 #define X_SHRT_MAX 0x7fff
643 #define X_SHRT_MIN (-1 - X_SHRT_MAX)
644 #define X_LONG_MAX 0x7fffffff
645 #define X_LONG_MIN (-1 - X_LONG_MAX)
646 #define X_ULONG_MAX 0xffffffffUL
648 #define No_Cursor (None)
650 enum
652 /* Values for focus_state, used as bit mask.
653 EXPLICIT means we received a FocusIn for the frame and know it has
654 the focus. IMPLICIT means we received an EnterNotify and the frame
655 may have the focus if no window manager is running.
656 FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
657 FOCUS_NONE = 0,
658 FOCUS_IMPLICIT = 1,
659 FOCUS_EXPLICIT = 2
663 /* Return the X output data for frame F. */
664 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
666 /* Return the X window used for displaying data in frame F. */
667 #define FRAME_X_WINDOW(f) ((f)->output_data.x->window_desc)
669 /* Return the outermost X window associated with the frame F. */
670 #ifdef USE_X_TOOLKIT
671 #define FRAME_OUTER_WINDOW(f) ((f)->output_data.x->widget ? \
672 XtWindow ((f)->output_data.x->widget) : \
673 FRAME_X_WINDOW (f))
674 #else
675 #ifdef USE_GTK
676 /* Functions not present in older Gtk+ */
678 #ifndef HAVE_GTK_WIDGET_GET_WINDOW
679 #define gtk_widget_get_window(w) ((w)->window)
680 #endif
681 #ifndef HAVE_GTK_WIDGET_GET_MAPPED
682 #define gtk_widget_get_mapped(w) (GTK_WIDGET_MAPPED (w))
683 #endif
684 #ifndef HAVE_GTK_ADJUSTMENT_GET_PAGE_SIZE
685 #define gtk_adjustment_get_page_size(w) ((w)->page_size)
686 #define gtk_adjustment_get_upper(w) ((w)->upper)
687 #endif
689 #ifdef HAVE_GTK3
690 #define DEFAULT_GDK_DISPLAY() \
691 gdk_x11_display_get_xdisplay (gdk_display_get_default ())
692 #else
693 #undef GDK_WINDOW_XID
694 #define GDK_WINDOW_XID(w) GDK_WINDOW_XWINDOW (w)
695 #define DEFAULT_GDK_DISPLAY() GDK_DISPLAY ()
696 #define gtk_widget_get_preferred_size(a, ign, b) \
697 gtk_widget_size_request (a, b)
698 #endif
700 #define GTK_WIDGET_TO_X_WIN(w) \
701 ((w) && gtk_widget_get_window (w) \
702 ? GDK_WINDOW_XID (gtk_widget_get_window (w)) : 0)
704 #define FRAME_GTK_OUTER_WIDGET(f) ((f)->output_data.x->widget)
705 #define FRAME_GTK_WIDGET(f) ((f)->output_data.x->edit_widget)
706 #define FRAME_OUTER_WINDOW(f) \
707 (FRAME_GTK_OUTER_WIDGET (f) ? \
708 GTK_WIDGET_TO_X_WIN (FRAME_GTK_OUTER_WIDGET (f)) : \
709 FRAME_X_WINDOW (f))
711 #else /* !USE_GTK */
712 #define FRAME_OUTER_WINDOW(f) (FRAME_X_WINDOW (f))
713 #endif /* !USE_GTK */
714 #endif
716 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
717 #define FRAME_MENUBAR_HEIGHT(f) ((f)->output_data.x->menubar_height)
718 #else
719 #define FRAME_MENUBAR_HEIGHT(f) ((void) f, 0)
720 #endif /* USE_X_TOOLKIT || USE_GTK */
722 #define FRAME_FONT(f) ((f)->output_data.x->font)
723 #define FRAME_FONTSET(f) ((f)->output_data.x->fontset)
724 #define FRAME_TOOLBAR_TOP_HEIGHT(f) ((f)->output_data.x->toolbar_top_height)
725 #define FRAME_TOOLBAR_BOTTOM_HEIGHT(f) \
726 ((f)->output_data.x->toolbar_bottom_height)
727 #define FRAME_TOOLBAR_HEIGHT(f) \
728 (FRAME_TOOLBAR_TOP_HEIGHT (f) + FRAME_TOOLBAR_BOTTOM_HEIGHT (f))
729 #define FRAME_TOOLBAR_LEFT_WIDTH(f) ((f)->output_data.x->toolbar_left_width)
730 #define FRAME_TOOLBAR_RIGHT_WIDTH(f) ((f)->output_data.x->toolbar_right_width)
731 #define FRAME_TOOLBAR_WIDTH(f) \
732 (FRAME_TOOLBAR_LEFT_WIDTH (f) + FRAME_TOOLBAR_RIGHT_WIDTH (f))
733 #define FRAME_BASELINE_OFFSET(f) ((f)->output_data.x->baseline_offset)
735 /* This gives the x_display_info structure for the display F is on. */
736 #define FRAME_DISPLAY_INFO(f) ((f)->output_data.x->display_info)
738 /* This is the `Display *' which frame F is on. */
739 #define FRAME_X_DISPLAY(f) (FRAME_DISPLAY_INFO (f)->display)
741 /* This is the `Screen *' which frame F is on. */
742 #define FRAME_X_SCREEN(f) (FRAME_DISPLAY_INFO (f)->screen)
744 /* This is the screen index number of screen which frame F is on. */
745 #define FRAME_X_SCREEN_NUMBER(f) XScreenNumberOfScreen (FRAME_X_SCREEN (f))
747 /* This is the Visual which frame F is on. */
748 #define FRAME_X_VISUAL(f) FRAME_DISPLAY_INFO (f)->visual
750 /* This is the Colormap which frame F uses. */
751 #define FRAME_X_COLORMAP(f) FRAME_DISPLAY_INFO (f)->cmap
753 #define FRAME_XIC(f) ((f)->output_data.x->xic)
754 #define FRAME_X_XIM(f) (FRAME_DISPLAY_INFO (f)->xim)
755 #define FRAME_X_XIM_STYLES(f) (FRAME_DISPLAY_INFO (f)->xim_styles)
756 #define FRAME_XIC_STYLE(f) ((f)->output_data.x->xic_style)
757 #define FRAME_XIC_FONTSET(f) ((f)->output_data.x->xic_xfs)
759 /* X-specific scroll bar stuff. */
761 /* We represent scroll bars as lisp vectors. This allows us to place
762 references to them in windows without worrying about whether we'll
763 end up with windows referring to dead scroll bars; the garbage
764 collector will free it when its time comes.
766 We use struct scroll_bar as a template for accessing fields of the
767 vector. */
769 struct scroll_bar
771 /* These fields are shared by all vectors. */
772 struct vectorlike_header header;
774 /* The window we're a scroll bar for. */
775 Lisp_Object window;
777 /* The next and previous in the chain of scroll bars in this frame. */
778 Lisp_Object next, prev;
780 /* Fields from `x_window' down will not be traced by the GC. */
782 /* The X window representing this scroll bar. */
783 Window x_window;
785 /* The position and size of the scroll bar in pixels, relative to the
786 frame. */
787 int top, left, width, height;
789 /* The starting and ending positions of the handle, relative to the
790 handle area (i.e. zero is the top position, not
791 SCROLL_BAR_TOP_BORDER). If they're equal, that means the handle
792 hasn't been drawn yet.
794 These are not actually the locations where the beginning and end
795 are drawn; in order to keep handles from becoming invisible when
796 editing large files, we establish a minimum height by always
797 drawing handle bottoms VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
798 where they would be normally; the bottom and top are in a
799 different co-ordinate system. */
800 int start, end;
802 /* If the scroll bar handle is currently being dragged by the user,
803 this is the number of pixels from the top of the handle to the
804 place where the user grabbed it. If the handle isn't currently
805 being dragged, this is -1. */
806 int dragging;
808 #if defined (USE_TOOLKIT_SCROLL_BARS) && defined (USE_LUCID)
809 /* Last scroll bar part seen in xaw_jump_callback and xaw_scroll_callback. */
810 enum scroll_bar_part last_seen_part;
811 #endif
813 #if defined (USE_TOOLKIT_SCROLL_BARS) && !defined (USE_GTK)
814 /* Last value of whole for horizontal scrollbars. */
815 int whole;
816 #endif
818 /* True if the scroll bar is horizontal. */
819 bool horizontal;
822 /* Turning a lisp vector value into a pointer to a struct scroll_bar. */
823 #define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec))
825 #ifdef USE_X_TOOLKIT
827 /* Extract the X widget of the scroll bar from a struct scroll_bar.
828 XtWindowToWidget should be fast enough since Xt uses a hash table
829 to map windows to widgets. */
831 #define SCROLL_BAR_X_WIDGET(dpy, ptr) \
832 XtWindowToWidget (dpy, ptr->x_window)
834 /* Store a widget id in a struct scroll_bar. */
836 #define SET_SCROLL_BAR_X_WIDGET(ptr, w) \
837 do { \
838 Window window = XtWindow (w); \
839 ptr->x_window = window; \
840 } while (false)
842 #endif /* USE_X_TOOLKIT */
844 /* Return the inside width of a vertical scroll bar, given the outside
845 width. */
846 #define VERTICAL_SCROLL_BAR_INSIDE_WIDTH(f, width) \
847 ((width) \
848 - VERTICAL_SCROLL_BAR_LEFT_BORDER \
849 - VERTICAL_SCROLL_BAR_RIGHT_BORDER)
851 /* Return the length of the rectangle within which the top of the
852 handle must stay. This isn't equivalent to the inside height,
853 because the scroll bar handle has a minimum height.
855 This is the real range of motion for the scroll bar, so when we're
856 scaling buffer positions to scroll bar positions, we use this, not
857 VERTICAL_SCROLL_BAR_INSIDE_HEIGHT. */
858 #define VERTICAL_SCROLL_BAR_TOP_RANGE(f, height) \
859 (VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, height) - VERTICAL_SCROLL_BAR_MIN_HANDLE)
861 /* Return the inside height of vertical scroll bar, given the outside
862 height. See VERTICAL_SCROLL_BAR_TOP_RANGE too. */
863 #define VERTICAL_SCROLL_BAR_INSIDE_HEIGHT(f, height) \
864 ((height) - VERTICAL_SCROLL_BAR_TOP_BORDER - VERTICAL_SCROLL_BAR_BOTTOM_BORDER)
866 /* Return the inside height of a horizontal scroll bar, given the outside
867 height. */
868 #define HORIZONTAL_SCROLL_BAR_INSIDE_HEIGHT(f, height) \
869 ((height) \
870 - HORIZONTAL_SCROLL_BAR_TOP_BORDER \
871 - HORIZONTAL_SCROLL_BAR_BOTTOM_BORDER)
873 /* Return the length of the rectangle within which the left part of the
874 handle must stay. This isn't equivalent to the inside width, because
875 the scroll bar handle has a minimum width.
877 This is the real range of motion for the scroll bar, so when we're
878 scaling buffer positions to scroll bar positions, we use this, not
879 HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH. */
880 #define HORIZONTAL_SCROLL_BAR_LEFT_RANGE(f, width) \
881 (HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH (f, width) - HORIZONTAL_SCROLL_BAR_MIN_HANDLE)
883 /* Return the inside width of horizontal scroll bar, given the outside
884 width. See HORIZONTAL_SCROLL_BAR_LEFT_RANGE too. */
885 #define HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH(f, width) \
886 ((width) - HORIZONTAL_SCROLL_BAR_LEFT_BORDER - HORIZONTAL_SCROLL_BAR_LEFT_BORDER)
889 /* Border widths for scroll bars.
891 Scroll bar windows don't have any X borders; their border width is
892 set to zero, and we redraw borders ourselves. This makes the code
893 a bit cleaner, since we don't have to convert between outside width
894 (used when relating to the rest of the screen) and inside width
895 (used when sizing and drawing the scroll bar window itself).
897 The handle moves up and down/back and forth in a rectangle inset
898 from the edges of the scroll bar. These are widths by which we
899 inset the handle boundaries from the scroll bar edges. */
900 #define VERTICAL_SCROLL_BAR_LEFT_BORDER (2)
901 #define VERTICAL_SCROLL_BAR_RIGHT_BORDER (2)
902 #define VERTICAL_SCROLL_BAR_TOP_BORDER (2)
903 #define VERTICAL_SCROLL_BAR_BOTTOM_BORDER (2)
905 #define HORIZONTAL_SCROLL_BAR_LEFT_BORDER (2)
906 #define HORIZONTAL_SCROLL_BAR_RIGHT_BORDER (2)
907 #define HORIZONTAL_SCROLL_BAR_TOP_BORDER (2)
908 #define HORIZONTAL_SCROLL_BAR_BOTTOM_BORDER (2)
910 /* Minimum lengths for scroll bar handles, in pixels. */
911 #define VERTICAL_SCROLL_BAR_MIN_HANDLE (5)
912 #define HORIZONTAL_SCROLL_BAR_MIN_HANDLE (5)
914 /* If a struct input_event has a kind which is SELECTION_REQUEST_EVENT
915 or SELECTION_CLEAR_EVENT, then its contents are really described
916 by this structure. */
918 /* For an event of kind SELECTION_REQUEST_EVENT,
919 this structure really describes the contents. */
921 struct selection_input_event
923 int kind;
924 struct x_display_info *dpyinfo;
925 /* We spell it with an "o" here because X does. */
926 Window requestor;
927 Atom selection, target, property;
928 Time time;
931 /* Unlike macros below, this can't be used as an lvalue. */
932 INLINE Display *
933 SELECTION_EVENT_DISPLAY (struct input_event *ev)
935 return ((struct selection_input_event *) ev)->dpyinfo->display;
937 #define SELECTION_EVENT_DPYINFO(eventp) \
938 (((struct selection_input_event *) (eventp))->dpyinfo)
939 /* We spell it with an "o" here because X does. */
940 #define SELECTION_EVENT_REQUESTOR(eventp) \
941 (((struct selection_input_event *) (eventp))->requestor)
942 #define SELECTION_EVENT_SELECTION(eventp) \
943 (((struct selection_input_event *) (eventp))->selection)
944 #define SELECTION_EVENT_TARGET(eventp) \
945 (((struct selection_input_event *) (eventp))->target)
946 #define SELECTION_EVENT_PROPERTY(eventp) \
947 (((struct selection_input_event *) (eventp))->property)
948 #define SELECTION_EVENT_TIME(eventp) \
949 (((struct selection_input_event *) (eventp))->time)
951 /* From xfns.c. */
953 extern void x_free_gcs (struct frame *);
954 extern void x_relative_mouse_position (struct frame *, int *, int *);
955 extern void x_real_pos_and_offsets (struct frame *f,
956 int *left_offset_x,
957 int *right_offset_x,
958 int *top_offset_y,
959 int *bottom_offset_y,
960 int *x_pixels_diff,
961 int *y_pixels_diff,
962 int *xptr,
963 int *yptr,
964 int *outer_border);
966 /* From xrdb.c. */
968 XrmDatabase x_load_resources (Display *, const char *, const char *,
969 const char *);
971 /* Defined in xterm.c */
973 extern bool x_text_icon (struct frame *, const char *);
974 extern void x_catch_errors (Display *);
975 extern void x_check_errors (Display *, const char *)
976 ATTRIBUTE_FORMAT_PRINTF (2, 0);
977 extern bool x_had_errors_p (Display *);
978 extern void x_uncatch_errors (void);
979 extern void x_clear_errors (Display *);
980 extern void xembed_request_focus (struct frame *);
981 extern void x_ewmh_activate_frame (struct frame *);
982 extern void x_delete_terminal (struct terminal *terminal);
983 extern unsigned long x_copy_color (struct frame *, unsigned long);
984 #ifdef USE_X_TOOLKIT
985 extern XtAppContext Xt_app_con;
986 extern void x_activate_timeout_atimer (void);
987 #endif
988 #ifdef USE_LUCID
989 extern bool x_alloc_lighter_color_for_widget (Widget, Display *, Colormap,
990 unsigned long *,
991 double, int);
992 #endif
993 extern bool x_alloc_nearest_color (struct frame *, Colormap, XColor *);
994 extern void x_clear_area (Display *, Window, int, int, int, int);
995 #if !defined USE_X_TOOLKIT && !defined USE_GTK
996 extern void x_mouse_leave (struct x_display_info *);
997 #endif
999 #if defined USE_X_TOOLKIT || defined USE_MOTIF
1000 extern int x_dispatch_event (XEvent *, Display *);
1001 #endif
1002 extern int x_x_to_emacs_modifiers (struct x_display_info *, int);
1004 INLINE int
1005 x_display_pixel_height (struct x_display_info *dpyinfo)
1007 return HeightOfScreen (dpyinfo->screen);
1010 INLINE int
1011 x_display_pixel_width (struct x_display_info *dpyinfo)
1013 return WidthOfScreen (dpyinfo->screen);
1016 INLINE void
1017 x_display_set_last_user_time (struct x_display_info *dpyinfo, Time t)
1019 #ifdef ENABLE_CHECKING
1020 eassert (t <= X_ULONG_MAX);
1021 #endif
1022 dpyinfo->last_user_time = t;
1025 extern void x_set_sticky (struct frame *, Lisp_Object, Lisp_Object);
1026 extern void x_wait_for_event (struct frame *, int);
1027 extern void x_clear_under_internal_border (struct frame *f);
1029 /* Defined in xselect.c. */
1031 extern void x_handle_property_notify (const XPropertyEvent *);
1032 extern void x_handle_selection_notify (const XSelectionEvent *);
1033 extern void x_handle_selection_event (struct input_event *);
1034 extern void x_clear_frame_selections (struct frame *);
1036 extern void x_send_client_event (Lisp_Object display,
1037 Lisp_Object dest,
1038 Lisp_Object from,
1039 Atom message_type,
1040 Lisp_Object format,
1041 Lisp_Object values);
1043 extern bool x_handle_dnd_message (struct frame *,
1044 const XClientMessageEvent *,
1045 struct x_display_info *,
1046 struct input_event *);
1047 extern int x_check_property_data (Lisp_Object);
1048 extern void x_fill_property_data (Display *,
1049 Lisp_Object,
1050 void *,
1051 int);
1052 extern Lisp_Object x_property_data_to_lisp (struct frame *,
1053 const unsigned char *,
1054 Atom,
1055 int,
1056 unsigned long);
1057 extern void x_clipboard_manager_save_frame (Lisp_Object);
1058 extern void x_clipboard_manager_save_all (void);
1060 #ifdef USE_GTK
1061 extern bool xg_set_icon (struct frame *, Lisp_Object);
1062 extern bool xg_set_icon_from_xpm_data (struct frame *, const char **);
1063 #endif /* USE_GTK */
1065 extern void xic_free_xfontset (struct frame *);
1066 extern void create_frame_xic (struct frame *);
1067 extern void destroy_frame_xic (struct frame *);
1068 extern void xic_set_preeditarea (struct window *, int, int);
1069 extern void xic_set_statusarea (struct frame *);
1070 extern void xic_set_xfontset (struct frame *, const char *);
1071 extern bool x_defined_color (struct frame *, const char *, XColor *, bool);
1072 #ifdef HAVE_X_I18N
1073 extern void free_frame_xic (struct frame *);
1074 # if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
1075 extern char *xic_create_fontsetname (const char *, bool);
1076 # endif
1077 #endif
1079 /* Defined in xfaces.c */
1081 #ifdef USE_X_TOOLKIT
1082 extern void x_free_dpy_colors (Display *, Screen *, Colormap,
1083 unsigned long *, int);
1084 #endif /* USE_X_TOOLKIT */
1086 /* Defined in xmenu.c */
1088 #if defined USE_X_TOOLKIT || defined USE_GTK
1089 extern Lisp_Object xw_popup_dialog (struct frame *, Lisp_Object, Lisp_Object);
1090 #endif
1092 #if defined USE_GTK || defined USE_MOTIF
1093 extern void x_menu_set_in_use (bool);
1094 #endif
1095 extern void x_menu_wait_for_event (void *data);
1096 extern void initialize_frame_menubar (struct frame *);
1098 /* Defined in xsmfns.c */
1099 #ifdef HAVE_X_SM
1100 extern void x_session_initialize (struct x_display_info *dpyinfo);
1101 extern bool x_session_have_connection (void);
1102 extern void x_session_close (void);
1103 #endif
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 */