1 /* Definitions and headers for communication with X protocol.
2 Copyright (C) 1989, 1993-1994, 1998-2015 Free Software Foundation,
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/>. */
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>
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
41 typedef Widget xt_or_gtk_widget
;
48 /* Some definitions to reduce conditionals. */
49 typedef GtkWidget
*xt_or_gtk_widget
;
51 #define XSync(d, b) do { gdk_window_process_all_updates (); \
52 XSync (d, b); } while (false)
55 /* True iff GTK's version is at least I.J.K. */
56 #ifndef GTK_CHECK_VERSION
58 # define GTK_CHECK_VERSION(i, j, k) \
60 < GTK_MAJOR_VERSION + ((j) \
61 < GTK_MINOR_VERSION + ((k) \
62 <= GTK_MICRO_VERSION)))
64 # define GTK_CHECK_VERSION(i, j, k) false
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
74 #include <cairo-xlib.h>
75 #ifdef CAIRO_HAS_PDF_SURFACE
76 #include <cairo-pdf.h>
78 #ifdef CAIRO_HAS_PS_SURFACE
81 #ifdef CAIRO_HAS_SVG_SURFACE
82 #include <cairo-svg.h>
87 #include <X11/Xlocale.h>
90 #include "dispextern.h"
91 #include "termhooks.h"
95 /* Black and white pixel values for the screen which frame F is on. */
96 #define BLACK_PIX_DEFAULT(f) \
97 BlackPixel (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f))
98 #define WHITE_PIX_DEFAULT(f) \
99 WhitePixel (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f))
101 /* The mask of events that text windows always want to receive. This
102 includes mouse movement events, since handling the mouse-font text property
103 means that we must track mouse motion all the time. */
105 #define STANDARD_EVENT_SET \
109 | ButtonReleaseMask \
110 | PointerMotionMask \
111 | StructureNotifyMask \
115 | VisibilityChangeMask)
117 #ifdef HAVE_X11R6_XIM
118 /* Data structure passed to xim_instantiate_callback. */
121 struct x_display_info
*dpyinfo
;
124 #endif /* HAVE_X11R6_XIM */
126 /* Structure recording X pixmap and reference count.
127 If REFCOUNT is 0 then this record is free to be reused. */
129 struct x_bitmap_record
139 /* Record some info about this pixmap. */
140 int height
, width
, depth
;
146 #define MAX_CLIP_RECTS 2
147 /* Number of clipping rectangles. */
150 /* Clipping rectangles. */
151 XRectangle clip_rects
[MAX_CLIP_RECTS
];
156 /* For each X display, we have a structure that records
157 information about it. */
159 struct x_display_info
161 /* Chain of all x_display_info structures. */
162 struct x_display_info
*next
;
164 /* The generic display parameters corresponding to this X display. */
165 struct terminal
*terminal
;
167 /* This says how to access this display in Xlib. */
170 /* A connection number (file descriptor) for the display. */
173 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE). */
174 Lisp_Object name_list_element
;
176 /* Number of frames that are on this display. */
179 /* The Screen this connection is connected to. */
182 /* Dots per inch of the screen. */
185 /* The Visual being used for this display. */
188 /* The colormap being used. */
191 /* Number of planes on this screen. */
194 /* Mask of things that cause the mouse to be grabbed. */
197 /* Emacs bitmap-id of the default icon bitmap for this frame.
198 Or -1 if none has been allocated yet. */
199 ptrdiff_t icon_bitmap_id
;
201 /* The root window of this screen. */
204 /* Client leader window. */
205 Window client_leader_window
;
207 /* The cursor to use for vertical scroll bars. */
208 Cursor vertical_scroll_bar_cursor
;
210 /* The cursor to use for horizontal scroll bars. */
211 Cursor horizontal_scroll_bar_cursor
;
213 /* The invisible cursor used for pointer blanking.
214 Unused if this display supports Xfixes extension. */
215 Cursor invisible_cursor
;
217 /* Function used to toggle pointer visibility on this display. */
218 void (*toggle_visible_pointer
) (struct frame
*, bool);
221 /* The GDK cursor for scroll bars and popup menus. */
222 GdkCursor
*xg_cursor
;
225 /* X Resource data base */
228 /* Minimum width over all characters in all fonts in font_table. */
229 int smallest_char_width
;
231 /* Minimum font height over all fonts in font_table. */
232 int smallest_font_height
;
234 /* Reusable Graphics Context for drawing a cursor in a non-default face. */
235 GC scratch_cursor_gc
;
237 /* Information about the range of text currently shown in
239 Mouse_HLInfo mouse_highlight
;
241 /* Logical identifier of this display. */
244 /* Default name for all frames on this display. */
247 /* The number of fonts opened for this display. */
250 /* Pointer to bitmap records. */
251 struct x_bitmap_record
*bitmaps
;
253 /* Allocated size of bitmaps field. */
254 ptrdiff_t bitmaps_size
;
256 /* Last used bitmap index. */
257 ptrdiff_t bitmaps_last
;
259 /* Which modifier keys are on which modifier bits?
261 With each keystroke, X returns eight bits indicating which modifier
262 keys were held down when the key was pressed. The interpretation
263 of the top five modifier bits depends on what keys are attached
264 to them. If the Meta_L and Meta_R keysyms are on mod5, then mod5
267 meta_mod_mask is a mask containing the bits used for the meta key.
268 It may have more than one bit set, if more than one modifier bit
269 has meta keys on it. Basically, if EVENT is a KeyPress event,
270 the meta key is pressed if (EVENT.state & meta_mod_mask) != 0.
272 shift_lock_mask is LockMask if the XK_Shift_Lock keysym is on the
273 lock modifier bit, or zero otherwise. Non-alphabetic keys should
274 only be affected by the lock modifier bit if XK_Shift_Lock is in
275 use; XK_Caps_Lock should only affect alphabetic keys. With this
276 arrangement, the lock modifier should shift the character if
277 (EVENT.state & shift_lock_mask) != 0. */
278 int meta_mod_mask
, shift_lock_mask
;
280 /* These are like meta_mod_mask, but for different modifiers. */
281 int alt_mod_mask
, super_mod_mask
, hyper_mod_mask
;
283 /* Communication with window managers. */
284 Atom Xatom_wm_protocols
;
286 /* Kinds of protocol things we may receive. */
287 Atom Xatom_wm_take_focus
;
288 Atom Xatom_wm_save_yourself
;
289 Atom Xatom_wm_delete_window
;
291 /* Atom for indicating window state to the window manager. */
292 Atom Xatom_wm_change_state
;
294 /* Other WM communication */
295 Atom Xatom_wm_configure_denied
; /* When our config request is denied */
296 Atom Xatom_wm_window_moved
; /* When the WM moves us. */
297 Atom Xatom_wm_client_leader
; /* Id of client leader window. */
299 /* EditRes protocol */
302 /* More atoms, which are selection types. */
303 Atom Xatom_CLIPBOARD
, Xatom_TIMESTAMP
, Xatom_TEXT
, Xatom_DELETE
,
304 Xatom_COMPOUND_TEXT
, Xatom_UTF8_STRING
,
305 Xatom_MULTIPLE
, Xatom_INCR
, Xatom_EMACS_TMP
, Xatom_TARGETS
, Xatom_NULL
,
306 Xatom_ATOM
, Xatom_ATOM_PAIR
, Xatom_CLIPBOARD_MANAGER
;
308 /* More atoms for font properties. The last three are private
309 properties, see the comments in src/fontset.h. */
310 Atom Xatom_PIXEL_SIZE
, Xatom_AVERAGE_WIDTH
,
311 Xatom_MULE_BASELINE_OFFSET
, Xatom_MULE_RELATIVE_COMPOSE
,
312 Xatom_MULE_DEFAULT_ASCENT
;
314 /* More atoms for Ghostscript support. */
315 Atom Xatom_DONE
, Xatom_PAGE
;
317 /* Atoms used in toolkit scroll bar client messages. */
318 Atom Xatom_Scrollbar
, Xatom_Horizontal_Scrollbar
;
320 /* Atom used in XEmbed client messages. */
321 Atom Xatom_XEMBED
, Xatom_XEMBED_INFO
;
323 /* The frame (if any) which has the X window that has keyboard focus.
324 Zero if none. This is examined by Ffocus_frame in xfns.c. Note
325 that a mere EnterNotify event can set this; if you need to know the
326 last frame specified in a FocusIn or FocusOut event, use
327 x_focus_event_frame. */
328 struct frame
*x_focus_frame
;
330 /* The last frame mentioned in a FocusIn or FocusOut event. This is
331 separate from x_focus_frame, because whether or not LeaveNotify
332 events cause us to lose focus depends on whether or not we have
333 received a FocusIn event for it. */
334 struct frame
*x_focus_event_frame
;
336 /* The frame which currently has the visual highlight, and should get
337 keyboard input (other sorts of input have the frame encoded in the
338 event). It points to the X focus frame's selected window's
339 frame. It differs from x_focus_frame when we're using a global
341 struct frame
*x_highlight_frame
;
343 /* The frame waiting to be auto-raised in XTread_socket. */
344 struct frame
*x_pending_autoraise_frame
;
346 /* The frame where the mouse was last time we reported a ButtonPress event. */
347 struct frame
*last_mouse_frame
;
349 /* The frame where the mouse was last time we reported a mouse position. */
350 struct frame
*last_mouse_glyph_frame
;
352 /* The frame where the mouse was last time we reported a mouse motion. */
353 struct frame
*last_mouse_motion_frame
;
355 /* The scroll bar in which the last X motion event occurred. */
356 struct scroll_bar
*last_mouse_scroll_bar
;
358 /* Time of last user interaction as returned in X events on this display. */
361 /* Position where the mouse was last time we reported a motion.
362 This is a position on last_mouse_motion_frame. */
363 int last_mouse_motion_x
;
364 int last_mouse_motion_y
;
366 /* Where the mouse was last time we reported a mouse position.
367 This is a rectangle on last_mouse_glyph_frame. */
368 XRectangle last_mouse_glyph
;
370 /* Time of last mouse movement on this display. This is a hack because
371 we would really prefer that XTmouse_position would return the time
372 associated with the position it returns, but there doesn't seem to be
373 any way to wrest the time-stamp from the server along with the position
374 query. So, we just keep track of the time of the last movement we
375 received, and return that in hopes that it's somewhat accurate. */
376 Time last_mouse_movement_time
;
378 /* The gray pixmap. */
382 /* XIM (X Input method). */
384 XIMStyles
*xim_styles
;
385 struct xim_inst_t
*xim_callback_data
;
388 /* If non-null, a cache of the colors in the color map. Don't
389 use this directly, call x_color_cells instead. */
393 /* Bits and shifts to use to compose pixel values on TrueColor visuals. */
394 int red_bits
, blue_bits
, green_bits
;
395 int red_offset
, blue_offset
, green_offset
;
397 /* The type of window manager we have. If we move FRAME_OUTER_WINDOW
398 to x/y 0/0, some window managers (type A) puts the window manager
399 decorations outside the screen and FRAME_OUTER_WINDOW exactly at 0/0.
400 Other window managers (type B) puts the window including decorations
401 at 0/0, so FRAME_OUTER_WINDOW is a bit below 0/0.
402 Record the type of WM in use so we can compensate for type A WMs. */
411 /* Atoms that are drag and drop atoms */
413 ptrdiff_t x_dnd_atoms_size
;
414 ptrdiff_t x_dnd_atoms_length
;
416 /* Extended window manager hints, Atoms supported by the window manager and
417 atoms for setting the window type. */
418 Atom Xatom_net_supported
, Xatom_net_supporting_wm_check
;
419 Atom
*net_supported_atoms
;
420 int nr_net_supported_atoms
;
421 Window net_supported_window
;
422 Atom Xatom_net_window_type
, Xatom_net_window_type_tooltip
;
423 Atom Xatom_net_active_window
;
425 /* Atoms dealing with EWMH (i.e. _NET_...) */
426 Atom Xatom_net_wm_state
, Xatom_net_wm_state_fullscreen
,
427 Xatom_net_wm_state_maximized_horz
, Xatom_net_wm_state_maximized_vert
,
428 Xatom_net_wm_state_sticky
, Xatom_net_wm_state_hidden
,
429 Xatom_net_frame_extents
,
430 Xatom_net_current_desktop
, Xatom_net_workarea
;
432 /* XSettings atoms and windows. */
433 Atom Xatom_xsettings_sel
, Xatom_xsettings_prop
, Xatom_xsettings_mgr
;
434 Window xsettings_window
;
436 /* Frame name and icon name */
437 Atom Xatom_net_wm_name
, Xatom_net_wm_icon_name
;
439 Atom Xatom_net_wm_window_opacity
;
442 Atom Xatom_SM_CLIENT_ID
;
445 XExtCodes
*ext_codes
;
450 /* Whether or not to use XIM if we have it. */
454 /* This is a chain of structures for all the X displays currently in use. */
455 extern struct x_display_info
*x_display_list
;
457 extern struct x_display_info
*x_display_info_for_display (Display
*);
458 extern struct frame
*x_top_window_to_frame (struct x_display_info
*, int);
459 extern struct x_display_info
*x_term_init (Lisp_Object
, char *, char *);
460 extern bool x_display_ok (const char *);
462 extern void select_visual (struct x_display_info
*);
464 /* Each X frame object points to its own struct x_output object
465 in the output_data.x field. The x_output structure contains
466 the information that is specific to X windows. */
470 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
471 /* Height of menu bar widget, in pixels. This value
472 is not meaningful if the menubar is turned off. */
476 /* Height of tool bar widget, in pixels. top_height is used if tool bar
477 at top, bottom_height if tool bar is at the bottom.
478 Zero if not using an external tool bar or if tool bar is vertical. */
479 int toolbar_top_height
, toolbar_bottom_height
;
481 /* Width of tool bar widget, in pixels. left_width is used if tool bar
482 at left, right_width if tool bar is at the right.
483 Zero if not using an external tool bar or if tool bar is horizontal. */
484 int toolbar_left_width
, toolbar_right_width
;
486 /* The tiled border used when the mouse is out of the frame. */
489 /* Here are the Graphics Contexts for the default font. */
490 GC normal_gc
; /* Normal video */
491 GC reverse_gc
; /* Reverse video */
492 GC cursor_gc
; /* cursor drawing */
494 /* The X window used for this frame.
495 May be zero while the frame object is being created
496 and the X window has not yet been created. */
499 /* The X window used for the bitmap icon;
500 or 0 if we don't have a bitmap icon. */
503 /* The X window that is the parent of this X window.
504 Usually this is a window that was made by the window manager,
505 but it can be the root window, and it can be explicitly specified
506 (see the explicit_parent field, below). */
510 /* The widget of this screen. This is the window of a "shell" widget. */
512 /* The XmPanedWindows... */
513 Widget column_widget
;
514 /* The widget of the edit portion of this screen; the window in
515 "window_desc" is inside of this. */
518 Widget menubar_widget
;
522 /* The widget of this screen. This is the window of a top widget. */
524 /* The widget of the edit portion of this screen; the window in
525 "window_desc" is inside of this. */
526 GtkWidget
*edit_widget
;
527 /* The widget used for laying out widgets vertically. */
528 GtkWidget
*vbox_widget
;
529 /* The widget used for laying out widgets horizontally. */
530 GtkWidget
*hbox_widget
;
531 /* The menubar in this frame. */
532 GtkWidget
*menubar_widget
;
533 /* The tool bar in this frame */
534 GtkWidget
*toolbar_widget
;
535 /* True if tool bar is packed into the hbox widget (i.e. vertical). */
536 bool_bf toolbar_in_hbox
: 1;
537 bool_bf toolbar_is_packed
: 1;
539 /* The last size hints set. */
540 GdkGeometry size_hints
;
543 #ifdef USE_GTK_TOOLTIP
544 GtkTooltip
*ttip_widget
;
546 GtkWindow
*ttip_window
;
547 #endif /* USE_GTK_TOOLTIP */
551 /* If >=0, a bitmap index. The indicated bitmap is used for the
553 ptrdiff_t icon_bitmap
;
555 /* Default ASCII font of this frame. */
558 /* The baseline offset of the default ASCII font. */
561 /* If a fontset is specified for this frame instead of font, this
562 value contains an ID of the fontset, else -1. */
565 unsigned long cursor_pixel
;
566 unsigned long border_pixel
;
567 unsigned long mouse_pixel
;
568 unsigned long cursor_foreground_pixel
;
570 /* Foreground color for scroll bars. A value of -1 means use the
571 default (black for non-toolkit scroll bars). */
572 unsigned long scroll_bar_foreground_pixel
;
574 /* Background color for scroll bars. A value of -1 means use the
575 default (background color of the frame for non-toolkit scroll
577 unsigned long scroll_bar_background_pixel
;
579 #if defined (USE_LUCID) && defined (USE_TOOLKIT_SCROLL_BARS)
580 /* Top and bottom shadow colors for 3D Lucid scrollbars.
581 -1 means let the scroll compute them itself. */
582 unsigned long scroll_bar_top_shadow_pixel
;
583 unsigned long scroll_bar_bottom_shadow_pixel
;
586 /* Descriptor for the cursor in use for this window. */
588 Cursor nontext_cursor
;
589 Cursor modeline_cursor
;
591 Cursor hourglass_cursor
;
592 Cursor horizontal_drag_cursor
;
593 Cursor vertical_drag_cursor
;
594 Cursor current_cursor
;
596 /* Window whose cursor is hourglass_cursor. This window is temporarily
597 mapped to display an hourglass cursor. */
598 Window hourglass_window
;
600 /* These are the current window manager hints. It seems that
601 XSetWMHints, when presented with an unset bit in the `flags'
602 member of the hints structure, does not leave the corresponding
603 attribute unchanged; rather, it resets that attribute to its
604 default value. For example, unless you set the `icon_pixmap'
605 field and the `IconPixmapHint' bit, XSetWMHints will forget what
606 your icon pixmap was. This is rather troublesome, since some of
607 the members (for example, `input' and `icon_pixmap') want to stay
608 the same throughout the execution of Emacs. So, we keep this
609 structure around, just leaving values in it and adding new bits
610 to the mask as we go. */
613 /* This is the Emacs structure for the X display this frame is on. */
614 struct x_display_info
*display_info
;
616 /* This is a button event that wants to activate the menubar.
617 We save it here until the command loop gets to think about it. */
618 XEvent
*saved_menu_event
;
620 /* This is the widget id used for this frame's menubar in lwlib. */
625 /* True means hourglass cursor is currently displayed. */
626 bool_bf hourglass_p
: 1;
628 /* True means our parent is another application's window
629 and was explicitly specified. */
630 bool_bf explicit_parent
: 1;
632 /* True means tried already to make this frame visible. */
633 bool_bf asked_for_visible
: 1;
635 /* True if this frame was ever previously visible. */
636 bool_bf has_been_visible
: 1;
638 /* Xt waits for a ConfigureNotify event from the window manager in
639 EmacsFrameSetCharSize when the shell widget is resized. For some
640 window managers like fvwm2 2.2.5 and KDE 2.1 this event doesn't
641 arrive for an unknown reason and Emacs hangs in Xt. If this is
642 false, tell Xt not to wait. */
643 bool_bf wait_for_wm
: 1;
646 /* Input context (currently, this means Compose key handler setup). */
652 /* Relief GCs, colors etc. */
658 black_relief
, white_relief
;
660 /* The background for which the above relief GCs were set up.
661 They are changed only when a different background is involved. */
662 unsigned long relief_background
;
664 /* Keep track of focus. May be EXPLICIT if we received a FocusIn for this
665 frame, or IMPLICIT if we received an EnterNotify.
666 FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
669 /* The offset we need to add to compensate for type A WMs. */
671 int move_offset_left
;
673 /* Extreme 'short' and 'long' values suitable for libX11. */
674 #define X_SHRT_MAX 0x7fff
675 #define X_SHRT_MIN (-1 - X_SHRT_MAX)
676 #define X_LONG_MAX 0x7fffffff
677 #define X_LONG_MIN (-1 - X_LONG_MAX)
678 #define X_ULONG_MAX 0xffffffffUL
681 /* Cairo drawing context. */
683 /* Cairo surface for double buffering */
684 cairo_surface_t
*cr_surface
;
688 #define No_Cursor (None)
692 /* Values for focus_state, used as bit mask.
693 EXPLICIT means we received a FocusIn for the frame and know it has
694 the focus. IMPLICIT means we received an EnterNotify and the frame
695 may have the focus if no window manager is running.
696 FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
703 /* Return the X output data for frame F. */
704 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
706 /* Return the X window used for displaying data in frame F. */
707 #define FRAME_X_WINDOW(f) ((f)->output_data.x->window_desc)
709 /* Return the outermost X window associated with the frame F. */
711 #define FRAME_OUTER_WINDOW(f) ((f)->output_data.x->widget ? \
712 XtWindow ((f)->output_data.x->widget) : \
716 /* Functions not present in older Gtk+ */
718 #ifndef HAVE_GTK_WIDGET_GET_WINDOW
719 #define gtk_widget_get_window(w) ((w)->window)
721 #ifndef HAVE_GTK_WIDGET_GET_MAPPED
722 #define gtk_widget_get_mapped(w) (GTK_WIDGET_MAPPED (w))
724 #ifndef HAVE_GTK_ADJUSTMENT_GET_PAGE_SIZE
725 #define gtk_adjustment_get_page_size(w) ((w)->page_size)
726 #define gtk_adjustment_get_upper(w) ((w)->upper)
730 #define DEFAULT_GDK_DISPLAY() \
731 gdk_x11_display_get_xdisplay (gdk_display_get_default ())
733 #undef GDK_WINDOW_XID
734 #define GDK_WINDOW_XID(w) GDK_WINDOW_XWINDOW (w)
735 #define DEFAULT_GDK_DISPLAY() GDK_DISPLAY ()
736 #define gtk_widget_get_preferred_size(a, ign, b) \
737 gtk_widget_size_request (a, b)
740 #define GTK_WIDGET_TO_X_WIN(w) \
741 ((w) && gtk_widget_get_window (w) \
742 ? GDK_WINDOW_XID (gtk_widget_get_window (w)) : 0)
744 #define FRAME_GTK_OUTER_WIDGET(f) ((f)->output_data.x->widget)
745 #define FRAME_GTK_WIDGET(f) ((f)->output_data.x->edit_widget)
746 #define FRAME_OUTER_WINDOW(f) \
747 (FRAME_GTK_OUTER_WIDGET (f) ? \
748 GTK_WIDGET_TO_X_WIN (FRAME_GTK_OUTER_WIDGET (f)) : \
752 #define FRAME_OUTER_WINDOW(f) (FRAME_X_WINDOW (f))
753 #endif /* !USE_GTK */
756 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
757 #define FRAME_MENUBAR_HEIGHT(f) ((f)->output_data.x->menubar_height)
759 #define FRAME_MENUBAR_HEIGHT(f) ((void) f, 0)
760 #endif /* USE_X_TOOLKIT || USE_GTK */
762 #define FRAME_FONT(f) ((f)->output_data.x->font)
763 #define FRAME_FONTSET(f) ((f)->output_data.x->fontset)
764 #define FRAME_TOOLBAR_TOP_HEIGHT(f) ((f)->output_data.x->toolbar_top_height)
765 #define FRAME_TOOLBAR_BOTTOM_HEIGHT(f) \
766 ((f)->output_data.x->toolbar_bottom_height)
767 #define FRAME_TOOLBAR_HEIGHT(f) \
768 (FRAME_TOOLBAR_TOP_HEIGHT (f) + FRAME_TOOLBAR_BOTTOM_HEIGHT (f))
769 #define FRAME_TOOLBAR_LEFT_WIDTH(f) ((f)->output_data.x->toolbar_left_width)
770 #define FRAME_TOOLBAR_RIGHT_WIDTH(f) ((f)->output_data.x->toolbar_right_width)
771 #define FRAME_TOOLBAR_WIDTH(f) \
772 (FRAME_TOOLBAR_LEFT_WIDTH (f) + FRAME_TOOLBAR_RIGHT_WIDTH (f))
773 #define FRAME_BASELINE_OFFSET(f) ((f)->output_data.x->baseline_offset)
775 /* This gives the x_display_info structure for the display F is on. */
776 #define FRAME_DISPLAY_INFO(f) ((f)->output_data.x->display_info)
778 /* This is the `Display *' which frame F is on. */
779 #define FRAME_X_DISPLAY(f) (FRAME_DISPLAY_INFO (f)->display)
781 /* This is the `Screen *' which frame F is on. */
782 #define FRAME_X_SCREEN(f) (FRAME_DISPLAY_INFO (f)->screen)
784 /* This is the screen index number of screen which frame F is on. */
785 #define FRAME_X_SCREEN_NUMBER(f) XScreenNumberOfScreen (FRAME_X_SCREEN (f))
787 /* This is the Visual which frame F is on. */
788 #define FRAME_X_VISUAL(f) FRAME_DISPLAY_INFO (f)->visual
790 /* This is the Colormap which frame F uses. */
791 #define FRAME_X_COLORMAP(f) FRAME_DISPLAY_INFO (f)->cmap
793 #define FRAME_XIC(f) ((f)->output_data.x->xic)
794 #define FRAME_X_XIM(f) (FRAME_DISPLAY_INFO (f)->xim)
795 #define FRAME_X_XIM_STYLES(f) (FRAME_DISPLAY_INFO (f)->xim_styles)
796 #define FRAME_XIC_STYLE(f) ((f)->output_data.x->xic_style)
797 #define FRAME_XIC_FONTSET(f) ((f)->output_data.x->xic_xfs)
799 /* X-specific scroll bar stuff. */
801 /* We represent scroll bars as lisp vectors. This allows us to place
802 references to them in windows without worrying about whether we'll
803 end up with windows referring to dead scroll bars; the garbage
804 collector will free it when its time comes.
806 We use struct scroll_bar as a template for accessing fields of the
811 /* These fields are shared by all vectors. */
812 struct vectorlike_header header
;
814 /* The window we're a scroll bar for. */
817 /* The next and previous in the chain of scroll bars in this frame. */
818 Lisp_Object next
, prev
;
820 /* Fields from `x_window' down will not be traced by the GC. */
822 /* The X window representing this scroll bar. */
825 /* The position and size of the scroll bar in pixels, relative to the
827 int top
, left
, width
, height
;
829 /* The starting and ending positions of the handle, relative to the
830 handle area (i.e. zero is the top position, not
831 SCROLL_BAR_TOP_BORDER). If they're equal, that means the handle
832 hasn't been drawn yet.
834 These are not actually the locations where the beginning and end
835 are drawn; in order to keep handles from becoming invisible when
836 editing large files, we establish a minimum height by always
837 drawing handle bottoms VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
838 where they would be normally; the bottom and top are in a
839 different co-ordinate system. */
842 /* If the scroll bar handle is currently being dragged by the user,
843 this is the number of pixels from the top of the handle to the
844 place where the user grabbed it. If the handle isn't currently
845 being dragged, this is -1. */
848 #if defined (USE_TOOLKIT_SCROLL_BARS) && defined (USE_LUCID)
849 /* Last scroll bar part seen in xaw_jump_callback and xaw_scroll_callback. */
850 enum scroll_bar_part last_seen_part
;
853 #if defined (USE_TOOLKIT_SCROLL_BARS) && !defined (USE_GTK)
854 /* Last value of whole for horizontal scrollbars. */
858 /* True if the scroll bar is horizontal. */
862 /* Turning a lisp vector value into a pointer to a struct scroll_bar. */
863 #define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec))
867 /* Extract the X widget of the scroll bar from a struct scroll_bar.
868 XtWindowToWidget should be fast enough since Xt uses a hash table
869 to map windows to widgets. */
871 #define SCROLL_BAR_X_WIDGET(dpy, ptr) \
872 XtWindowToWidget (dpy, ptr->x_window)
874 /* Store a widget id in a struct scroll_bar. */
876 #define SET_SCROLL_BAR_X_WIDGET(ptr, w) \
878 Window window = XtWindow (w); \
879 ptr->x_window = window; \
882 #endif /* USE_X_TOOLKIT */
884 /* Return the inside width of a vertical scroll bar, given the outside
886 #define VERTICAL_SCROLL_BAR_INSIDE_WIDTH(f, width) \
888 - VERTICAL_SCROLL_BAR_LEFT_BORDER \
889 - VERTICAL_SCROLL_BAR_RIGHT_BORDER)
891 /* Return the length of the rectangle within which the top of the
892 handle must stay. This isn't equivalent to the inside height,
893 because the scroll bar handle has a minimum height.
895 This is the real range of motion for the scroll bar, so when we're
896 scaling buffer positions to scroll bar positions, we use this, not
897 VERTICAL_SCROLL_BAR_INSIDE_HEIGHT. */
898 #define VERTICAL_SCROLL_BAR_TOP_RANGE(f, height) \
899 (VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, height) - VERTICAL_SCROLL_BAR_MIN_HANDLE)
901 /* Return the inside height of vertical scroll bar, given the outside
902 height. See VERTICAL_SCROLL_BAR_TOP_RANGE too. */
903 #define VERTICAL_SCROLL_BAR_INSIDE_HEIGHT(f, height) \
904 ((height) - VERTICAL_SCROLL_BAR_TOP_BORDER - VERTICAL_SCROLL_BAR_BOTTOM_BORDER)
906 /* Return the inside height of a horizontal scroll bar, given the outside
908 #define HORIZONTAL_SCROLL_BAR_INSIDE_HEIGHT(f, height) \
910 - HORIZONTAL_SCROLL_BAR_TOP_BORDER \
911 - HORIZONTAL_SCROLL_BAR_BOTTOM_BORDER)
913 /* Return the length of the rectangle within which the left part of the
914 handle must stay. This isn't equivalent to the inside width, because
915 the scroll bar handle has a minimum width.
917 This is the real range of motion for the scroll bar, so when we're
918 scaling buffer positions to scroll bar positions, we use this, not
919 HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH. */
920 #define HORIZONTAL_SCROLL_BAR_LEFT_RANGE(f, width) \
921 (HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH (f, width) - HORIZONTAL_SCROLL_BAR_MIN_HANDLE)
923 /* Return the inside width of horizontal scroll bar, given the outside
924 width. See HORIZONTAL_SCROLL_BAR_LEFT_RANGE too. */
925 #define HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH(f, width) \
926 ((width) - HORIZONTAL_SCROLL_BAR_LEFT_BORDER - HORIZONTAL_SCROLL_BAR_LEFT_BORDER)
929 /* Border widths for scroll bars.
931 Scroll bar windows don't have any X borders; their border width is
932 set to zero, and we redraw borders ourselves. This makes the code
933 a bit cleaner, since we don't have to convert between outside width
934 (used when relating to the rest of the screen) and inside width
935 (used when sizing and drawing the scroll bar window itself).
937 The handle moves up and down/back and forth in a rectangle inset
938 from the edges of the scroll bar. These are widths by which we
939 inset the handle boundaries from the scroll bar edges. */
940 #define VERTICAL_SCROLL_BAR_LEFT_BORDER (2)
941 #define VERTICAL_SCROLL_BAR_RIGHT_BORDER (2)
942 #define VERTICAL_SCROLL_BAR_TOP_BORDER (2)
943 #define VERTICAL_SCROLL_BAR_BOTTOM_BORDER (2)
945 #define HORIZONTAL_SCROLL_BAR_LEFT_BORDER (2)
946 #define HORIZONTAL_SCROLL_BAR_RIGHT_BORDER (2)
947 #define HORIZONTAL_SCROLL_BAR_TOP_BORDER (2)
948 #define HORIZONTAL_SCROLL_BAR_BOTTOM_BORDER (2)
950 /* Minimum lengths for scroll bar handles, in pixels. */
951 #define VERTICAL_SCROLL_BAR_MIN_HANDLE (5)
952 #define HORIZONTAL_SCROLL_BAR_MIN_HANDLE (5)
954 /* If a struct input_event has a kind which is SELECTION_REQUEST_EVENT
955 or SELECTION_CLEAR_EVENT, then its contents are really described
956 by this structure. */
958 /* For an event of kind SELECTION_REQUEST_EVENT,
959 this structure really describes the contents. */
961 struct selection_input_event
963 ENUM_BF (event_kind
) kind
: EVENT_KIND_WIDTH
;
964 struct x_display_info
*dpyinfo
;
965 /* We spell it with an "o" here because X does. */
967 Atom selection
, target
, property
;
971 /* Unlike macros below, this can't be used as an lvalue. */
973 SELECTION_EVENT_DISPLAY (struct selection_input_event
*ev
)
975 return ev
->dpyinfo
->display
;
977 #define SELECTION_EVENT_DPYINFO(eventp) \
979 /* We spell it with an "o" here because X does. */
980 #define SELECTION_EVENT_REQUESTOR(eventp) \
981 ((eventp)->requestor)
982 #define SELECTION_EVENT_SELECTION(eventp) \
983 ((eventp)->selection)
984 #define SELECTION_EVENT_TARGET(eventp) \
986 #define SELECTION_EVENT_PROPERTY(eventp) \
988 #define SELECTION_EVENT_TIME(eventp) \
993 extern void x_free_gcs (struct frame
*);
994 extern void x_relative_mouse_position (struct frame
*, int *, int *);
995 extern void x_real_pos_and_offsets (struct frame
*f
,
999 int *bottom_offset_y
,
1008 XrmDatabase
x_load_resources (Display
*, const char *, const char *,
1011 /* Defined in xterm.c */
1013 extern bool x_text_icon (struct frame
*, const char *);
1014 extern void x_catch_errors (Display
*);
1015 extern void x_check_errors (Display
*, const char *)
1016 ATTRIBUTE_FORMAT_PRINTF (2, 0);
1017 extern bool x_had_errors_p (Display
*);
1018 extern void x_uncatch_errors (void);
1019 extern void x_clear_errors (Display
*);
1020 extern void xembed_request_focus (struct frame
*);
1021 extern void x_ewmh_activate_frame (struct frame
*);
1022 extern void x_delete_terminal (struct terminal
*terminal
);
1023 extern unsigned long x_copy_color (struct frame
*, unsigned long);
1024 #ifdef USE_X_TOOLKIT
1025 extern XtAppContext Xt_app_con
;
1026 extern void x_activate_timeout_atimer (void);
1029 extern bool x_alloc_lighter_color_for_widget (Widget
, Display
*, Colormap
,
1033 extern bool x_alloc_nearest_color (struct frame
*, Colormap
, XColor
*);
1034 extern void x_query_color (struct frame
*f
, XColor
*);
1035 extern void x_clear_area (struct frame
*f
, int, int, int, int);
1036 #if !defined USE_X_TOOLKIT && !defined USE_GTK
1037 extern void x_mouse_leave (struct x_display_info
*);
1040 #if defined USE_X_TOOLKIT || defined USE_MOTIF
1041 extern int x_dispatch_event (XEvent
*, Display
*);
1043 extern int x_x_to_emacs_modifiers (struct x_display_info
*, int);
1045 extern cairo_t
*x_begin_cr_clip (struct frame
*, GC
);
1046 extern void x_end_cr_clip (struct frame
*);
1047 extern void x_set_cr_source_with_gc_foreground (struct frame
*, GC
);
1048 extern void x_set_cr_source_with_gc_background (struct frame
*, GC
);
1049 extern void x_cr_draw_frame (cairo_t
*, struct frame
*);
1050 extern Lisp_Object
x_cr_export_frames (Lisp_Object
, cairo_surface_type_t
);
1054 x_display_pixel_height (struct x_display_info
*dpyinfo
)
1056 return HeightOfScreen (dpyinfo
->screen
);
1060 x_display_pixel_width (struct x_display_info
*dpyinfo
)
1062 return WidthOfScreen (dpyinfo
->screen
);
1066 x_display_set_last_user_time (struct x_display_info
*dpyinfo
, Time t
)
1068 #ifdef ENABLE_CHECKING
1069 eassert (t
<= X_ULONG_MAX
);
1071 dpyinfo
->last_user_time
= t
;
1074 extern void x_set_sticky (struct frame
*, Lisp_Object
, Lisp_Object
);
1075 extern void x_wait_for_event (struct frame
*, int);
1076 extern void x_clear_under_internal_border (struct frame
*f
);
1078 /* Defined in xselect.c. */
1080 extern void x_handle_property_notify (const XPropertyEvent
*);
1081 extern void x_handle_selection_notify (const XSelectionEvent
*);
1082 extern void x_handle_selection_event (struct selection_input_event
*);
1083 extern void x_clear_frame_selections (struct frame
*);
1085 extern void x_send_client_event (Lisp_Object display
,
1090 Lisp_Object values
);
1092 extern bool x_handle_dnd_message (struct frame
*,
1093 const XClientMessageEvent
*,
1094 struct x_display_info
*,
1095 struct input_event
*);
1096 extern int x_check_property_data (Lisp_Object
);
1097 extern void x_fill_property_data (Display
*,
1101 extern Lisp_Object
x_property_data_to_lisp (struct frame
*,
1102 const unsigned char *,
1106 extern void x_clipboard_manager_save_frame (Lisp_Object
);
1107 extern void x_clipboard_manager_save_all (void);
1110 extern bool xg_set_icon (struct frame
*, Lisp_Object
);
1111 extern bool xg_set_icon_from_xpm_data (struct frame
*, const char **);
1112 #endif /* USE_GTK */
1114 extern void xic_free_xfontset (struct frame
*);
1115 extern void create_frame_xic (struct frame
*);
1116 extern void destroy_frame_xic (struct frame
*);
1117 extern void xic_set_preeditarea (struct window
*, int, int);
1118 extern void xic_set_statusarea (struct frame
*);
1119 extern void xic_set_xfontset (struct frame
*, const char *);
1120 extern bool x_defined_color (struct frame
*, const char *, XColor
*, bool);
1122 extern void free_frame_xic (struct frame
*);
1123 # if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
1124 extern char *xic_create_fontsetname (const char *, bool);
1128 /* Defined in xfaces.c */
1130 #ifdef USE_X_TOOLKIT
1131 extern void x_free_dpy_colors (Display
*, Screen
*, Colormap
,
1132 unsigned long *, int);
1133 #endif /* USE_X_TOOLKIT */
1135 /* Defined in xmenu.c */
1137 #if defined USE_X_TOOLKIT || defined USE_GTK
1138 extern Lisp_Object
xw_popup_dialog (struct frame
*, Lisp_Object
, Lisp_Object
);
1141 #if defined USE_GTK || defined USE_MOTIF
1142 extern void x_menu_set_in_use (bool);
1144 extern void x_menu_wait_for_event (void *data
);
1145 extern void initialize_frame_menubar (struct frame
*);
1147 /* Defined in xsmfns.c */
1149 extern void x_session_initialize (struct x_display_info
*dpyinfo
);
1150 extern bool x_session_have_connection (void);
1151 extern void x_session_close (void);
1155 /* Is the frame embedded into another application? */
1157 #define FRAME_X_EMBEDDED_P(f) (FRAME_X_OUTPUT(f)->explicit_parent != 0)
1159 #define STORE_XCHAR2B(chp, b1, b2) \
1160 ((chp)->byte1 = (b1), (chp)->byte2 = (b2))
1162 #define XCHAR2B_BYTE1(chp) \
1165 #define XCHAR2B_BYTE2(chp) \
1168 #define STORE_NATIVE_RECT(nr,rx,ry,rwidth,rheight) \
1171 (nr).width = (rwidth), \
1172 (nr).height = (rheight))
1176 #endif /* XTERM_H */