* NEWS: Teroffs and detachable tool bar for Gtk+ is gone.
[emacs.git] / src / xterm.h
blob0842195f3308407d380912419f439ac1551526b1
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 /* 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 /* True if _NET_WM_STATE_HIDDEN is set for this frame. */
613 bool_bf net_wm_state_hidden_seen : 1;
615 #ifdef HAVE_X_I18N
616 /* Input context (currently, this means Compose key handler setup). */
617 XIC xic;
618 XIMStyle xic_style;
619 XFontSet xic_xfs;
620 #endif
622 /* Relief GCs, colors etc. */
623 struct relief
625 GC gc;
626 unsigned long pixel;
628 black_relief, white_relief;
630 /* The background for which the above relief GCs were set up.
631 They are changed only when a different background is involved. */
632 unsigned long relief_background;
634 /* As x_pixels_diff, but to FRAME_OUTER_WINDOW. For some reason the
635 two might differ by a pixel, depending on WM */
636 int x_pixels_outer_diff;
638 /* As y_pixels_diff, but to FRAME_OUTER_WINDOW. In the toolkit version,
639 these may differ because this does not take into account possible
640 menubar. y_pixels_diff is with menubar height included */
641 int y_pixels_outer_diff;
643 /* Keep track of focus. May be EXPLICIT if we received a FocusIn for this
644 frame, or IMPLICIT if we received an EnterNotify.
645 FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
646 int focus_state;
648 /* The offset we need to add to compensate for type A WMs. */
649 int move_offset_top;
650 int move_offset_left;
653 /* Extreme 'short' and 'long' values suitable for libX11. */
654 #define X_SHRT_MAX 0x7fff
655 #define X_SHRT_MIN (-1 - X_SHRT_MAX)
656 #define X_LONG_MAX 0x7fffffff
657 #define X_LONG_MIN (-1 - X_LONG_MAX)
658 #define X_ULONG_MAX 0xffffffffUL
660 #define No_Cursor (None)
662 enum
664 /* Values for focus_state, used as bit mask.
665 EXPLICIT means we received a FocusIn for the frame and know it has
666 the focus. IMPLICIT means we received an EnterNotify and the frame
667 may have the focus if no window manager is running.
668 FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
669 FOCUS_NONE = 0,
670 FOCUS_IMPLICIT = 1,
671 FOCUS_EXPLICIT = 2
675 /* Return the X output data for frame F. */
676 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
678 /* Return the X window used for displaying data in frame F. */
679 #define FRAME_X_WINDOW(f) ((f)->output_data.x->window_desc)
681 /* Return the outermost X window associated with the frame F. */
682 #ifdef USE_X_TOOLKIT
683 #define FRAME_OUTER_WINDOW(f) ((f)->output_data.x->widget ? \
684 XtWindow ((f)->output_data.x->widget) : \
685 FRAME_X_WINDOW (f))
686 #else
687 #ifdef USE_GTK
688 /* Functions not present in older Gtk+ */
690 #ifndef HAVE_GTK_WIDGET_GET_WINDOW
691 #define gtk_widget_get_window(w) ((w)->window)
692 #endif
693 #ifndef HAVE_GTK_WIDGET_GET_MAPPED
694 #define gtk_widget_get_mapped(w) (GTK_WIDGET_MAPPED (w))
695 #endif
696 #ifndef HAVE_GTK_ADJUSTMENT_GET_PAGE_SIZE
697 #define gtk_adjustment_get_page_size(w) ((w)->page_size)
698 #define gtk_adjustment_get_upper(w) ((w)->upper)
699 #endif
701 #ifdef HAVE_GTK3
702 #define DEFAULT_GDK_DISPLAY() \
703 gdk_x11_display_get_xdisplay (gdk_display_get_default ())
704 #else
705 #undef GDK_WINDOW_XID
706 #define GDK_WINDOW_XID(w) GDK_WINDOW_XWINDOW (w)
707 #define DEFAULT_GDK_DISPLAY() GDK_DISPLAY ()
708 #define gtk_widget_get_preferred_size(a, ign, b) \
709 gtk_widget_size_request (a, b)
710 #endif
712 #define GTK_WIDGET_TO_X_WIN(w) \
713 ((w) && gtk_widget_get_window (w) \
714 ? GDK_WINDOW_XID (gtk_widget_get_window (w)) : 0)
716 #define FRAME_GTK_OUTER_WIDGET(f) ((f)->output_data.x->widget)
717 #define FRAME_GTK_WIDGET(f) ((f)->output_data.x->edit_widget)
718 #define FRAME_OUTER_WINDOW(f) \
719 (FRAME_GTK_OUTER_WIDGET (f) ? \
720 GTK_WIDGET_TO_X_WIN (FRAME_GTK_OUTER_WIDGET (f)) : \
721 FRAME_X_WINDOW (f))
723 #else /* !USE_GTK */
724 #define FRAME_OUTER_WINDOW(f) (FRAME_X_WINDOW (f))
725 #endif /* !USE_GTK */
726 #endif
728 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
729 #define FRAME_MENUBAR_HEIGHT(f) ((f)->output_data.x->menubar_height)
730 #else
731 #define FRAME_MENUBAR_HEIGHT(f) ((void) f, 0)
732 #endif /* USE_X_TOOLKIT || USE_GTK */
734 #define FRAME_FONT(f) ((f)->output_data.x->font)
735 #define FRAME_FONTSET(f) ((f)->output_data.x->fontset)
736 #define FRAME_TOOLBAR_TOP_HEIGHT(f) ((f)->output_data.x->toolbar_top_height)
737 #define FRAME_TOOLBAR_BOTTOM_HEIGHT(f) \
738 ((f)->output_data.x->toolbar_bottom_height)
739 #define FRAME_TOOLBAR_HEIGHT(f) \
740 (FRAME_TOOLBAR_TOP_HEIGHT (f) + FRAME_TOOLBAR_BOTTOM_HEIGHT (f))
741 #define FRAME_TOOLBAR_LEFT_WIDTH(f) ((f)->output_data.x->toolbar_left_width)
742 #define FRAME_TOOLBAR_RIGHT_WIDTH(f) ((f)->output_data.x->toolbar_right_width)
743 #define FRAME_TOOLBAR_WIDTH(f) \
744 (FRAME_TOOLBAR_LEFT_WIDTH (f) + FRAME_TOOLBAR_RIGHT_WIDTH (f))
745 #define FRAME_BASELINE_OFFSET(f) ((f)->output_data.x->baseline_offset)
747 /* This gives the x_display_info structure for the display F is on. */
748 #define FRAME_DISPLAY_INFO(f) ((f)->output_data.x->display_info)
750 /* This is the `Display *' which frame F is on. */
751 #define FRAME_X_DISPLAY(f) (FRAME_DISPLAY_INFO (f)->display)
753 /* This is the `Screen *' which frame F is on. */
754 #define FRAME_X_SCREEN(f) (FRAME_DISPLAY_INFO (f)->screen)
756 /* This is the screen index number of screen which frame F is on. */
757 #define FRAME_X_SCREEN_NUMBER(f) XScreenNumberOfScreen (FRAME_X_SCREEN (f))
759 /* This is the Visual which frame F is on. */
760 #define FRAME_X_VISUAL(f) FRAME_DISPLAY_INFO (f)->visual
762 /* This is the Colormap which frame F uses. */
763 #define FRAME_X_COLORMAP(f) FRAME_DISPLAY_INFO (f)->cmap
765 /* The difference in pixels between the top left corner of the
766 Emacs window (including possible window manager decorations)
767 and FRAME_X_WINDOW (f). */
768 #define FRAME_OUTER_TO_INNER_DIFF_X(f) \
769 ((f)->output_data.x->x_pixels_outer_diff)
770 #define FRAME_OUTER_TO_INNER_DIFF_Y(f) \
771 ((f)->output_data.x->y_pixels_outer_diff \
772 + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f))
775 #define FRAME_XIC(f) ((f)->output_data.x->xic)
776 #define FRAME_X_XIM(f) (FRAME_DISPLAY_INFO (f)->xim)
777 #define FRAME_X_XIM_STYLES(f) (FRAME_DISPLAY_INFO (f)->xim_styles)
778 #define FRAME_XIC_STYLE(f) ((f)->output_data.x->xic_style)
779 #define FRAME_XIC_FONTSET(f) ((f)->output_data.x->xic_xfs)
781 /* X-specific scroll bar stuff. */
783 /* We represent scroll bars as lisp vectors. This allows us to place
784 references to them in windows without worrying about whether we'll
785 end up with windows referring to dead scroll bars; the garbage
786 collector will free it when its time comes.
788 We use struct scroll_bar as a template for accessing fields of the
789 vector. */
791 struct scroll_bar
793 /* These fields are shared by all vectors. */
794 struct vectorlike_header header;
796 /* The window we're a scroll bar for. */
797 Lisp_Object window;
799 /* The next and previous in the chain of scroll bars in this frame. */
800 Lisp_Object next, prev;
802 /* Fields from `x_window' down will not be traced by the GC. */
804 /* The X window representing this scroll bar. */
805 Window x_window;
807 /* The position and size of the scroll bar in pixels, relative to the
808 frame. */
809 int top, left, width, height;
811 /* The starting and ending positions of the handle, relative to the
812 handle area (i.e. zero is the top position, not
813 SCROLL_BAR_TOP_BORDER). If they're equal, that means the handle
814 hasn't been drawn yet.
816 These are not actually the locations where the beginning and end
817 are drawn; in order to keep handles from becoming invisible when
818 editing large files, we establish a minimum height by always
819 drawing handle bottoms VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
820 where they would be normally; the bottom and top are in a
821 different co-ordinate system. */
822 int start, end;
824 /* If the scroll bar handle is currently being dragged by the user,
825 this is the number of pixels from the top of the handle to the
826 place where the user grabbed it. If the handle isn't currently
827 being dragged, this is -1. */
828 int dragging;
830 #if defined (USE_TOOLKIT_SCROLL_BARS) && defined (USE_LUCID)
831 /* Last scroll bar part seen in xaw_jump_callback and xaw_scroll_callback. */
832 enum scroll_bar_part last_seen_part;
833 #endif
835 #if defined (USE_TOOLKIT_SCROLL_BARS) && !defined (USE_GTK)
836 /* Last value of whole for horizontal scrollbars. */
837 int whole;
838 #endif
840 /* 1 if the scroll bar is horizontal. */
841 bool horizontal;
844 /* Turning a lisp vector value into a pointer to a struct scroll_bar. */
845 #define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec))
847 #ifdef USE_X_TOOLKIT
849 /* Extract the X widget of the scroll bar from a struct scroll_bar.
850 XtWindowToWidget should be fast enough since Xt uses a hash table
851 to map windows to widgets. */
853 #define SCROLL_BAR_X_WIDGET(dpy, ptr) \
854 XtWindowToWidget (dpy, ptr->x_window)
856 /* Store a widget id in a struct scroll_bar. */
858 #define SET_SCROLL_BAR_X_WIDGET(ptr, w) \
859 do { \
860 Window window = XtWindow (w); \
861 ptr->x_window = window; \
862 } while (false)
864 #endif /* USE_X_TOOLKIT */
866 /* Return the inside width of a vertical scroll bar, given the outside
867 width. */
868 #define VERTICAL_SCROLL_BAR_INSIDE_WIDTH(f, width) \
869 ((width) \
870 - VERTICAL_SCROLL_BAR_LEFT_BORDER \
871 - VERTICAL_SCROLL_BAR_RIGHT_BORDER)
873 /* Return the length of the rectangle within which the top of the
874 handle must stay. This isn't equivalent to the inside height,
875 because the scroll bar handle has a minimum height.
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 VERTICAL_SCROLL_BAR_INSIDE_HEIGHT. */
880 #define VERTICAL_SCROLL_BAR_TOP_RANGE(f, height) \
881 (VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, height) - VERTICAL_SCROLL_BAR_MIN_HANDLE)
883 /* Return the inside height of vertical scroll bar, given the outside
884 height. See VERTICAL_SCROLL_BAR_TOP_RANGE too. */
885 #define VERTICAL_SCROLL_BAR_INSIDE_HEIGHT(f, height) \
886 ((height) - VERTICAL_SCROLL_BAR_TOP_BORDER - VERTICAL_SCROLL_BAR_BOTTOM_BORDER)
888 /* Return the inside height of a horizontal scroll bar, given the outside
889 height. */
890 #define HORIZONTAL_SCROLL_BAR_INSIDE_HEIGHT(f, height) \
891 ((height) \
892 - HORIZONTAL_SCROLL_BAR_TOP_BORDER \
893 - HORIZONTAL_SCROLL_BAR_BOTTOM_BORDER)
895 /* Return the length of the rectangle within which the left part of the
896 handle must stay. This isn't equivalent to the inside width, because
897 the scroll bar handle has a minimum width.
899 This is the real range of motion for the scroll bar, so when we're
900 scaling buffer positions to scroll bar positions, we use this, not
901 HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH. */
902 #define HORIZONTAL_SCROLL_BAR_LEFT_RANGE(f, width) \
903 (HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH (f, width) - HORIZONTAL_SCROLL_BAR_MIN_HANDLE)
905 /* Return the inside width of horizontal scroll bar, given the outside
906 width. See HORIZONTAL_SCROLL_BAR_LEFT_RANGE too. */
907 #define HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH(f, width) \
908 ((width) - HORIZONTAL_SCROLL_BAR_LEFT_BORDER - HORIZONTAL_SCROLL_BAR_LEFT_BORDER)
911 /* Border widths for scroll bars.
913 Scroll bar windows don't have any X borders; their border width is
914 set to zero, and we redraw borders ourselves. This makes the code
915 a bit cleaner, since we don't have to convert between outside width
916 (used when relating to the rest of the screen) and inside width
917 (used when sizing and drawing the scroll bar window itself).
919 The handle moves up and down/back and forth in a rectangle inset
920 from the edges of the scroll bar. These are widths by which we
921 inset the handle boundaries from the scroll bar edges. */
922 #define VERTICAL_SCROLL_BAR_LEFT_BORDER (2)
923 #define VERTICAL_SCROLL_BAR_RIGHT_BORDER (2)
924 #define VERTICAL_SCROLL_BAR_TOP_BORDER (2)
925 #define VERTICAL_SCROLL_BAR_BOTTOM_BORDER (2)
927 #define HORIZONTAL_SCROLL_BAR_LEFT_BORDER (2)
928 #define HORIZONTAL_SCROLL_BAR_RIGHT_BORDER (2)
929 #define HORIZONTAL_SCROLL_BAR_TOP_BORDER (2)
930 #define HORIZONTAL_SCROLL_BAR_BOTTOM_BORDER (2)
932 /* Minimum lengths for scroll bar handles, in pixels. */
933 #define VERTICAL_SCROLL_BAR_MIN_HANDLE (5)
934 #define HORIZONTAL_SCROLL_BAR_MIN_HANDLE (5)
936 /* If a struct input_event has a kind which is SELECTION_REQUEST_EVENT
937 or SELECTION_CLEAR_EVENT, then its contents are really described
938 by this structure. */
940 /* For an event of kind SELECTION_REQUEST_EVENT,
941 this structure really describes the contents. */
943 struct selection_input_event
945 int kind;
946 struct x_display_info *dpyinfo;
947 /* We spell it with an "o" here because X does. */
948 Window requestor;
949 Atom selection, target, property;
950 Time time;
953 /* Unlike macros below, this can't be used as an lvalue. */
954 INLINE Display *
955 SELECTION_EVENT_DISPLAY (struct input_event *ev)
957 return ((struct selection_input_event *) ev)->dpyinfo->display;
959 #define SELECTION_EVENT_DPYINFO(eventp) \
960 (((struct selection_input_event *) (eventp))->dpyinfo)
961 /* We spell it with an "o" here because X does. */
962 #define SELECTION_EVENT_REQUESTOR(eventp) \
963 (((struct selection_input_event *) (eventp))->requestor)
964 #define SELECTION_EVENT_SELECTION(eventp) \
965 (((struct selection_input_event *) (eventp))->selection)
966 #define SELECTION_EVENT_TARGET(eventp) \
967 (((struct selection_input_event *) (eventp))->target)
968 #define SELECTION_EVENT_PROPERTY(eventp) \
969 (((struct selection_input_event *) (eventp))->property)
970 #define SELECTION_EVENT_TIME(eventp) \
971 (((struct selection_input_event *) (eventp))->time)
973 /* From xfns.c. */
975 extern void x_free_gcs (struct frame *);
976 extern void x_relative_mouse_position (struct frame *, int *, int *);
978 /* From xrdb.c. */
980 XrmDatabase x_load_resources (Display *, const char *, const char *,
981 const char *);
983 /* Defined in xterm.c */
985 extern int x_text_icon (struct frame *, const char *);
986 extern void x_catch_errors (Display *);
987 extern void x_check_errors (Display *, const char *)
988 ATTRIBUTE_FORMAT_PRINTF (2, 0);
989 extern bool x_had_errors_p (Display *);
990 extern void x_uncatch_errors (void);
991 extern void x_clear_errors (Display *);
992 extern void xembed_request_focus (struct frame *);
993 extern void x_ewmh_activate_frame (struct frame *);
994 extern void x_delete_terminal (struct terminal *terminal);
995 extern unsigned long x_copy_color (struct frame *, unsigned long);
996 #ifdef USE_X_TOOLKIT
997 extern XtAppContext Xt_app_con;
998 extern void x_activate_timeout_atimer (void);
999 #endif
1000 #ifdef USE_LUCID
1001 extern bool x_alloc_lighter_color_for_widget (Widget, Display *, Colormap,
1002 unsigned long *,
1003 double, int);
1004 #endif
1005 extern bool x_alloc_nearest_color (struct frame *, Colormap, XColor *);
1006 extern void x_clear_area (Display *, Window, int, int, int, int);
1007 #if !defined USE_X_TOOLKIT && !defined USE_GTK
1008 extern void x_mouse_leave (struct x_display_info *);
1009 #endif
1011 #if defined USE_X_TOOLKIT || defined USE_MOTIF
1012 extern int x_dispatch_event (XEvent *, Display *);
1013 #endif
1014 extern int x_x_to_emacs_modifiers (struct x_display_info *, int);
1016 INLINE int
1017 x_display_pixel_height (struct x_display_info *dpyinfo)
1019 return HeightOfScreen (dpyinfo->screen);
1022 INLINE int
1023 x_display_pixel_width (struct x_display_info *dpyinfo)
1025 return WidthOfScreen (dpyinfo->screen);
1028 INLINE void
1029 x_display_set_last_user_time (struct x_display_info *dpyinfo, Time t)
1031 #ifdef ENABLE_CHECKING
1032 eassert (t <= X_ULONG_MAX);
1033 #endif
1034 dpyinfo->last_user_time = t;
1037 extern void x_set_sticky (struct frame *, Lisp_Object, Lisp_Object);
1038 extern void x_wait_for_event (struct frame *, int);
1039 extern void x_clear_under_internal_border (struct frame *f);
1041 /* Defined in xselect.c. */
1043 extern void x_handle_property_notify (const XPropertyEvent *);
1044 extern void x_handle_selection_notify (const XSelectionEvent *);
1045 extern void x_handle_selection_event (struct input_event *);
1046 extern void x_clear_frame_selections (struct frame *);
1048 extern void x_send_client_event (Lisp_Object display,
1049 Lisp_Object dest,
1050 Lisp_Object from,
1051 Atom message_type,
1052 Lisp_Object format,
1053 Lisp_Object values);
1055 extern int x_handle_dnd_message (struct frame *,
1056 const XClientMessageEvent *,
1057 struct x_display_info *,
1058 struct input_event *);
1059 extern int x_check_property_data (Lisp_Object);
1060 extern void x_fill_property_data (Display *,
1061 Lisp_Object,
1062 void *,
1063 int);
1064 extern Lisp_Object x_property_data_to_lisp (struct frame *,
1065 const unsigned char *,
1066 Atom,
1067 int,
1068 unsigned long);
1069 extern void x_clipboard_manager_save_frame (Lisp_Object);
1070 extern void x_clipboard_manager_save_all (void);
1072 #ifdef USE_GTK
1073 extern int xg_set_icon (struct frame *, Lisp_Object);
1074 extern int xg_set_icon_from_xpm_data (struct frame *, const char **);
1075 #endif /* USE_GTK */
1077 extern void xic_free_xfontset (struct frame *);
1078 extern void create_frame_xic (struct frame *);
1079 extern void destroy_frame_xic (struct frame *);
1080 extern void xic_set_preeditarea (struct window *, int, int);
1081 extern void xic_set_statusarea (struct frame *);
1082 extern void xic_set_xfontset (struct frame *, const char *);
1083 extern bool x_defined_color (struct frame *, const char *, XColor *, bool);
1084 #ifdef HAVE_X_I18N
1085 extern void free_frame_xic (struct frame *);
1086 # if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
1087 extern char * xic_create_fontsetname (const char *base_fontname, int motif);
1088 # endif
1089 #endif
1091 /* Defined in xfaces.c */
1093 #ifdef USE_X_TOOLKIT
1094 extern void x_free_dpy_colors (Display *, Screen *, Colormap,
1095 unsigned long *, int);
1096 #endif /* USE_X_TOOLKIT */
1098 /* Defined in xmenu.c */
1100 #if defined USE_X_TOOLKIT || defined USE_GTK
1101 extern Lisp_Object xw_popup_dialog (struct frame *, Lisp_Object, Lisp_Object);
1102 #endif
1104 #if defined USE_GTK || defined USE_MOTIF
1105 extern void x_menu_set_in_use (int);
1106 #endif
1107 extern void x_menu_wait_for_event (void *data);
1108 extern void initialize_frame_menubar (struct frame *);
1110 /* Defined in xsmfns.c */
1111 #ifdef HAVE_X_SM
1112 extern void x_session_initialize (struct x_display_info *dpyinfo);
1113 extern int x_session_have_connection (void);
1114 extern void x_session_close (void);
1115 #endif
1117 /* Defined in xterm.c */
1119 extern Lisp_Object Qx_gtk_map_stock;
1121 /* Is the frame embedded into another application? */
1123 #define FRAME_X_EMBEDDED_P(f) (FRAME_X_OUTPUT(f)->explicit_parent != 0)
1125 #define STORE_XCHAR2B(chp, b1, b2) \
1126 ((chp)->byte1 = (b1), (chp)->byte2 = (b2))
1128 #define XCHAR2B_BYTE1(chp) \
1129 ((chp)->byte1)
1131 #define XCHAR2B_BYTE2(chp) \
1132 ((chp)->byte2)
1134 #define STORE_NATIVE_RECT(nr,rx,ry,rwidth,rheight) \
1135 ((nr).x = (rx), \
1136 (nr).y = (ry), \
1137 (nr).width = (rwidth), \
1138 (nr).height = (rheight))
1140 INLINE_HEADER_END
1142 #endif /* XTERM_H */