1 /* Definitions and headers for communication with X protocol.
2 Copyright (C) 1989, 1993-1994, 1998-2016 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 (at
10 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 #ifdef X_TOOLKIT_EDITRES
42 #include <X11/Xmu/Editres.h>
45 typedef Widget xt_or_gtk_widget
;
52 /* Some definitions to reduce conditionals. */
53 typedef GtkWidget
*xt_or_gtk_widget
;
55 #define XSync(d, b) do { gdk_window_process_all_updates (); \
56 XSync (d, b); } while (false)
59 /* True iff GTK's version is at least I.J.K. */
60 #ifndef GTK_CHECK_VERSION
62 # define GTK_CHECK_VERSION(i, j, k) \
64 < GTK_MAJOR_VERSION + ((j) \
65 < GTK_MINOR_VERSION + ((k) \
66 <= GTK_MICRO_VERSION)))
68 # define GTK_CHECK_VERSION(i, j, k) false
72 /* The GtkTooltip API came in 2.12, but gtk-enable-tooltips in 2.14. */
73 #if GTK_CHECK_VERSION (2, 14, 0)
74 #define USE_GTK_TOOLTIP
78 #include <cairo-xlib.h>
79 #ifdef CAIRO_HAS_PDF_SURFACE
80 #include <cairo-pdf.h>
82 #ifdef CAIRO_HAS_PS_SURFACE
85 #ifdef CAIRO_HAS_SVG_SURFACE
86 #include <cairo-svg.h>
91 #include <X11/Xlocale.h>
95 #include <X11/Xlib-xcb.h>
98 #include "dispextern.h"
99 #include "termhooks.h"
103 /* Black and white pixel values for the screen which frame F is on. */
104 #define BLACK_PIX_DEFAULT(f) \
105 BlackPixel (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f))
106 #define WHITE_PIX_DEFAULT(f) \
107 WhitePixel (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f))
109 /* The mask of events that text windows always want to receive. This
110 includes mouse movement events, since handling the mouse-font text property
111 means that we must track mouse motion all the time. */
113 #define STANDARD_EVENT_SET \
117 | ButtonReleaseMask \
118 | PointerMotionMask \
119 | StructureNotifyMask \
123 | VisibilityChangeMask)
125 #ifdef HAVE_X11R6_XIM
126 /* Data structure passed to xim_instantiate_callback. */
129 struct x_display_info
*dpyinfo
;
132 #endif /* HAVE_X11R6_XIM */
134 /* Structure recording X pixmap and reference count.
135 If REFCOUNT is 0 then this record is free to be reused. */
137 struct x_bitmap_record
147 /* Record some info about this pixmap. */
148 int height
, width
, depth
;
154 #define MAX_CLIP_RECTS 2
155 /* Number of clipping rectangles. */
158 /* Clipping rectangles. */
159 XRectangle clip_rects
[MAX_CLIP_RECTS
];
164 struct color_name_cache_entry
166 struct color_name_cache_entry
*next
;
171 Status
x_parse_color (struct frame
*f
, const char *color_name
,
175 /* For each X display, we have a structure that records
176 information about it. */
178 struct x_display_info
180 /* Chain of all x_display_info structures. */
181 struct x_display_info
*next
;
183 /* The generic display parameters corresponding to this X display. */
184 struct terminal
*terminal
;
186 /* This says how to access this display in Xlib. */
189 /* A connection number (file descriptor) for the display. */
192 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE). */
193 Lisp_Object name_list_element
;
195 /* Number of frames that are on this display. */
198 /* The Screen this connection is connected to. */
201 /* Dots per inch of the screen. */
204 /* The Visual being used for this display. */
207 /* The colormap being used. */
210 /* Number of planes on this screen. */
213 /* Mask of things that cause the mouse to be grabbed. */
216 /* Emacs bitmap-id of the default icon bitmap for this frame.
217 Or -1 if none has been allocated yet. */
218 ptrdiff_t icon_bitmap_id
;
220 /* The root window of this screen. */
223 /* Client leader window. */
224 Window client_leader_window
;
226 /* The cursor to use for vertical scroll bars. */
227 Cursor vertical_scroll_bar_cursor
;
229 /* The cursor to use for horizontal scroll bars. */
230 Cursor horizontal_scroll_bar_cursor
;
232 /* The invisible cursor used for pointer blanking.
233 Unused if this display supports Xfixes extension. */
234 Cursor invisible_cursor
;
236 /* Function used to toggle pointer visibility on this display. */
237 void (*toggle_visible_pointer
) (struct frame
*, bool);
240 /* The GDK cursor for scroll bars and popup menus. */
241 GdkCursor
*xg_cursor
;
244 /* X Resource data base */
247 /* Minimum width over all characters in all fonts in font_table. */
248 int smallest_char_width
;
250 /* Minimum font height over all fonts in font_table. */
251 int smallest_font_height
;
253 /* Reusable Graphics Context for drawing a cursor in a non-default face. */
254 GC scratch_cursor_gc
;
256 /* Information about the range of text currently shown in
258 Mouse_HLInfo mouse_highlight
;
260 /* Logical identifier of this display. */
263 /* Default name for all frames on this display. */
266 /* The number of fonts opened for this display. */
269 /* Pointer to bitmap records. */
270 struct x_bitmap_record
*bitmaps
;
272 /* Allocated size of bitmaps field. */
273 ptrdiff_t bitmaps_size
;
275 /* Last used bitmap index. */
276 ptrdiff_t bitmaps_last
;
278 /* Which modifier keys are on which modifier bits?
280 With each keystroke, X returns eight bits indicating which modifier
281 keys were held down when the key was pressed. The interpretation
282 of the top five modifier bits depends on what keys are attached
283 to them. If the Meta_L and Meta_R keysyms are on mod5, then mod5
286 meta_mod_mask is a mask containing the bits used for the meta key.
287 It may have more than one bit set, if more than one modifier bit
288 has meta keys on it. Basically, if EVENT is a KeyPress event,
289 the meta key is pressed if (EVENT.state & meta_mod_mask) != 0.
291 shift_lock_mask is LockMask if the XK_Shift_Lock keysym is on the
292 lock modifier bit, or zero otherwise. Non-alphabetic keys should
293 only be affected by the lock modifier bit if XK_Shift_Lock is in
294 use; XK_Caps_Lock should only affect alphabetic keys. With this
295 arrangement, the lock modifier should shift the character if
296 (EVENT.state & shift_lock_mask) != 0. */
297 int meta_mod_mask
, shift_lock_mask
;
299 /* These are like meta_mod_mask, but for different modifiers. */
300 int alt_mod_mask
, super_mod_mask
, hyper_mod_mask
;
302 /* Communication with window managers. */
303 Atom Xatom_wm_protocols
;
305 /* Kinds of protocol things we may receive. */
306 Atom Xatom_wm_take_focus
;
307 Atom Xatom_wm_save_yourself
;
308 Atom Xatom_wm_delete_window
;
310 /* Atom for indicating window state to the window manager. */
311 Atom Xatom_wm_change_state
;
313 /* Other WM communication */
314 Atom Xatom_wm_configure_denied
; /* When our config request is denied */
315 Atom Xatom_wm_window_moved
; /* When the WM moves us. */
316 Atom Xatom_wm_client_leader
; /* Id of client leader window. */
318 /* EditRes protocol */
321 /* More atoms, which are selection types. */
322 Atom Xatom_CLIPBOARD
, Xatom_TIMESTAMP
, Xatom_TEXT
, Xatom_DELETE
,
323 Xatom_COMPOUND_TEXT
, Xatom_UTF8_STRING
,
324 Xatom_MULTIPLE
, Xatom_INCR
, Xatom_EMACS_TMP
, Xatom_TARGETS
, Xatom_NULL
,
325 Xatom_ATOM
, Xatom_ATOM_PAIR
, Xatom_CLIPBOARD_MANAGER
;
327 /* More atoms for font properties. The last three are private
328 properties, see the comments in src/fontset.h. */
329 Atom Xatom_PIXEL_SIZE
, Xatom_AVERAGE_WIDTH
,
330 Xatom_MULE_BASELINE_OFFSET
, Xatom_MULE_RELATIVE_COMPOSE
,
331 Xatom_MULE_DEFAULT_ASCENT
;
333 /* More atoms for Ghostscript support. */
334 Atom Xatom_DONE
, Xatom_PAGE
;
336 /* Atoms used in toolkit scroll bar client messages. */
337 Atom Xatom_Scrollbar
, Xatom_Horizontal_Scrollbar
;
339 /* Atom used in XEmbed client messages. */
340 Atom Xatom_XEMBED
, Xatom_XEMBED_INFO
;
342 /* The frame (if any) which has the X window that has keyboard focus.
343 Zero if none. This is examined by Ffocus_frame in xfns.c. Note
344 that a mere EnterNotify event can set this; if you need to know the
345 last frame specified in a FocusIn or FocusOut event, use
346 x_focus_event_frame. */
347 struct frame
*x_focus_frame
;
349 /* The last frame mentioned in a FocusIn or FocusOut event. This is
350 separate from x_focus_frame, because whether or not LeaveNotify
351 events cause us to lose focus depends on whether or not we have
352 received a FocusIn event for it. */
353 struct frame
*x_focus_event_frame
;
355 /* The frame which currently has the visual highlight, and should get
356 keyboard input (other sorts of input have the frame encoded in the
357 event). It points to the X focus frame's selected window's
358 frame. It differs from x_focus_frame when we're using a global
360 struct frame
*x_highlight_frame
;
362 /* The frame waiting to be auto-raised in XTread_socket. */
363 struct frame
*x_pending_autoraise_frame
;
365 /* Tooltip frame on this display. */
366 struct frame
*x_tooltip_frame
;
368 /* The frame where the mouse was last time we reported a ButtonPress event. */
369 struct frame
*last_mouse_frame
;
371 /* The frame where the mouse was last time we reported a mouse position. */
372 struct frame
*last_mouse_glyph_frame
;
374 /* The frame where the mouse was last time we reported a mouse motion. */
375 struct frame
*last_mouse_motion_frame
;
377 /* The scroll bar in which the last X motion event occurred. */
378 struct scroll_bar
*last_mouse_scroll_bar
;
380 /* Time of last user interaction as returned in X events on this display. */
383 /* Position where the mouse was last time we reported a motion.
384 This is a position on last_mouse_motion_frame. */
385 int last_mouse_motion_x
;
386 int last_mouse_motion_y
;
388 /* Where the mouse was last time we reported a mouse position.
389 This is a rectangle on last_mouse_glyph_frame. */
390 XRectangle last_mouse_glyph
;
392 /* Time of last mouse movement on this display. This is a hack because
393 we would really prefer that XTmouse_position would return the time
394 associated with the position it returns, but there doesn't seem to be
395 any way to wrest the time-stamp from the server along with the position
396 query. So, we just keep track of the time of the last movement we
397 received, and return that in hopes that it's somewhat accurate. */
398 Time last_mouse_movement_time
;
400 /* The gray pixmap. */
404 /* XIM (X Input method). */
406 XIMStyles
*xim_styles
;
407 struct xim_inst_t
*xim_callback_data
;
410 /* A cache mapping color names to RGB values. */
411 struct color_name_cache_entry
*color_names
;
413 /* If non-null, a cache of the colors in the color map. Don't
414 use this directly, call x_color_cells instead. */
418 /* Bits and shifts to use to compose pixel values on TrueColor visuals. */
419 int red_bits
, blue_bits
, green_bits
;
420 int red_offset
, blue_offset
, green_offset
;
422 /* The type of window manager we have. If we move FRAME_OUTER_WINDOW
423 to x/y 0/0, some window managers (type A) puts the window manager
424 decorations outside the screen and FRAME_OUTER_WINDOW exactly at 0/0.
425 Other window managers (type B) puts the window including decorations
426 at 0/0, so FRAME_OUTER_WINDOW is a bit below 0/0.
427 Record the type of WM in use so we can compensate for type A WMs. */
436 /* Atoms that are drag and drop atoms */
438 ptrdiff_t x_dnd_atoms_size
;
439 ptrdiff_t x_dnd_atoms_length
;
441 /* Extended window manager hints, Atoms supported by the window manager and
442 atoms for setting the window type. */
443 Atom Xatom_net_supported
, Xatom_net_supporting_wm_check
;
444 Atom
*net_supported_atoms
;
445 int nr_net_supported_atoms
;
446 Window net_supported_window
;
447 Atom Xatom_net_window_type
, Xatom_net_window_type_tooltip
;
448 Atom Xatom_net_active_window
;
450 /* Atoms dealing with EWMH (i.e. _NET_...) */
451 Atom Xatom_net_wm_state
, Xatom_net_wm_state_fullscreen
,
452 Xatom_net_wm_state_maximized_horz
, Xatom_net_wm_state_maximized_vert
,
453 Xatom_net_wm_state_sticky
, Xatom_net_wm_state_hidden
,
454 Xatom_net_frame_extents
,
455 Xatom_net_current_desktop
, Xatom_net_workarea
;
457 /* XSettings atoms and windows. */
458 Atom Xatom_xsettings_sel
, Xatom_xsettings_prop
, Xatom_xsettings_mgr
;
459 Window xsettings_window
;
461 /* Frame name and icon name */
462 Atom Xatom_net_wm_name
, Xatom_net_wm_icon_name
;
464 Atom Xatom_net_wm_window_opacity
;
467 Atom Xatom_SM_CLIENT_ID
;
470 int xrandr_major_version
;
471 int xrandr_minor_version
;
475 XExtCodes
*ext_codes
;
479 xcb_connection_t
*xcb_connection
;
484 /* Whether or not to use XIM if we have it. */
488 /* This is a chain of structures for all the X displays currently in use. */
489 extern struct x_display_info
*x_display_list
;
491 extern struct x_display_info
*x_display_info_for_display (Display
*);
492 extern struct frame
*x_top_window_to_frame (struct x_display_info
*, int);
493 extern struct x_display_info
*x_term_init (Lisp_Object
, char *, char *);
494 extern bool x_display_ok (const char *);
496 extern void select_visual (struct x_display_info
*);
498 /* Each X frame object points to its own struct x_output object
499 in the output_data.x field. The x_output structure contains
500 the information that is specific to X windows. */
504 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
505 /* Height of menu bar widget, in pixels. This value
506 is not meaningful if the menubar is turned off. */
510 /* Height of tool bar widget, in pixels. top_height is used if tool bar
511 at top, bottom_height if tool bar is at the bottom.
512 Zero if not using an external tool bar or if tool bar is vertical. */
513 int toolbar_top_height
, toolbar_bottom_height
;
515 /* Width of tool bar widget, in pixels. left_width is used if tool bar
516 at left, right_width if tool bar is at the right.
517 Zero if not using an external tool bar or if tool bar is horizontal. */
518 int toolbar_left_width
, toolbar_right_width
;
520 /* The tiled border used when the mouse is out of the frame. */
523 /* Here are the Graphics Contexts for the default font. */
524 GC normal_gc
; /* Normal video */
525 GC reverse_gc
; /* Reverse video */
526 GC cursor_gc
; /* cursor drawing */
528 /* The X window used for this frame.
529 May be zero while the frame object is being created
530 and the X window has not yet been created. */
533 /* The X window used for the bitmap icon;
534 or 0 if we don't have a bitmap icon. */
537 /* The X window that is the parent of this X window.
538 Usually this is a window that was made by the window manager,
539 but it can be the root window, and it can be explicitly specified
540 (see the explicit_parent field, below). */
544 /* The widget of this screen. This is the window of a "shell" widget. */
546 /* The XmPanedWindows... */
547 Widget column_widget
;
548 /* The widget of the edit portion of this screen; the window in
549 "window_desc" is inside of this. */
552 Widget menubar_widget
;
556 /* The widget of this screen. This is the window of a top widget. */
558 /* The widget of the edit portion of this screen; the window in
559 "window_desc" is inside of this. */
560 GtkWidget
*edit_widget
;
561 /* The widget used for laying out widgets vertically. */
562 GtkWidget
*vbox_widget
;
563 /* The widget used for laying out widgets horizontally. */
564 GtkWidget
*hbox_widget
;
565 /* The menubar in this frame. */
566 GtkWidget
*menubar_widget
;
567 /* The tool bar in this frame */
568 GtkWidget
*toolbar_widget
;
569 /* True if tool bar is packed into the hbox widget (i.e. vertical). */
570 bool_bf toolbar_in_hbox
: 1;
571 bool_bf toolbar_is_packed
: 1;
573 /* The last size hints set. */
574 GdkGeometry size_hints
;
577 #ifdef USE_GTK_TOOLTIP
578 GtkTooltip
*ttip_widget
;
580 GtkWindow
*ttip_window
;
582 #endif /* USE_GTK_TOOLTIP */
586 /* If >=0, a bitmap index. The indicated bitmap is used for the
588 ptrdiff_t icon_bitmap
;
590 /* Default ASCII font of this frame. */
593 /* The baseline offset of the default ASCII font. */
596 /* If a fontset is specified for this frame instead of font, this
597 value contains an ID of the fontset, else -1. */
600 unsigned long cursor_pixel
;
601 unsigned long border_pixel
;
602 unsigned long mouse_pixel
;
603 unsigned long cursor_foreground_pixel
;
605 /* Foreground color for scroll bars. A value of -1 means use the
606 default (black for non-toolkit scroll bars). */
607 unsigned long scroll_bar_foreground_pixel
;
609 /* Background color for scroll bars. A value of -1 means use the
610 default (background color of the frame for non-toolkit scroll
612 unsigned long scroll_bar_background_pixel
;
614 #if defined (USE_LUCID) && defined (USE_TOOLKIT_SCROLL_BARS)
615 /* Top and bottom shadow colors for 3D Lucid scrollbars.
616 -1 means let the scroll compute them itself. */
617 unsigned long scroll_bar_top_shadow_pixel
;
618 unsigned long scroll_bar_bottom_shadow_pixel
;
621 /* Descriptor for the cursor in use for this window. */
623 Cursor nontext_cursor
;
624 Cursor modeline_cursor
;
626 Cursor hourglass_cursor
;
627 Cursor horizontal_drag_cursor
;
628 Cursor vertical_drag_cursor
;
629 Cursor current_cursor
;
631 /* Window whose cursor is hourglass_cursor. This window is temporarily
632 mapped to display an hourglass cursor. */
633 Window hourglass_window
;
635 /* These are the current window manager hints. It seems that
636 XSetWMHints, when presented with an unset bit in the `flags'
637 member of the hints structure, does not leave the corresponding
638 attribute unchanged; rather, it resets that attribute to its
639 default value. For example, unless you set the `icon_pixmap'
640 field and the `IconPixmapHint' bit, XSetWMHints will forget what
641 your icon pixmap was. This is rather troublesome, since some of
642 the members (for example, `input' and `icon_pixmap') want to stay
643 the same throughout the execution of Emacs. So, we keep this
644 structure around, just leaving values in it and adding new bits
645 to the mask as we go. */
648 /* This is the Emacs structure for the X display this frame is on. */
649 struct x_display_info
*display_info
;
651 /* This is a button event that wants to activate the menubar.
652 We save it here until the command loop gets to think about it. */
653 XEvent
*saved_menu_event
;
655 /* This is the widget id used for this frame's menubar in lwlib. */
660 /* True means hourglass cursor is currently displayed. */
661 bool_bf hourglass_p
: 1;
663 /* True means our parent is another application's window
664 and was explicitly specified. */
665 bool_bf explicit_parent
: 1;
667 /* True means tried already to make this frame visible. */
668 bool_bf asked_for_visible
: 1;
670 /* True if this frame was ever previously visible. */
671 bool_bf has_been_visible
: 1;
673 /* Xt waits for a ConfigureNotify event from the window manager in
674 EmacsFrameSetCharSize when the shell widget is resized. For some
675 window managers like fvwm2 2.2.5 and KDE 2.1 this event doesn't
676 arrive for an unknown reason and Emacs hangs in Xt. If this is
677 false, tell Xt not to wait. */
678 bool_bf wait_for_wm
: 1;
681 /* Input context (currently, this means Compose key handler setup). */
687 /* Relief GCs, colors etc. */
693 black_relief
, white_relief
;
695 /* The background for which the above relief GCs were set up.
696 They are changed only when a different background is involved. */
697 unsigned long relief_background
;
699 /* Keep track of focus. May be EXPLICIT if we received a FocusIn for this
700 frame, or IMPLICIT if we received an EnterNotify.
701 FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
704 /* The offset we need to add to compensate for type A WMs. */
706 int move_offset_left
;
708 /* Extreme 'short' and 'long' values suitable for libX11. */
709 #define X_SHRT_MAX 0x7fff
710 #define X_SHRT_MIN (-1 - X_SHRT_MAX)
711 #define X_LONG_MAX 0x7fffffff
712 #define X_LONG_MIN (-1 - X_LONG_MAX)
713 #define X_ULONG_MAX 0xffffffffUL
716 /* Cairo drawing context. */
718 /* Cairo surface for double buffering */
719 cairo_surface_t
*cr_surface
;
723 #define No_Cursor (None)
727 /* Values for focus_state, used as bit mask.
728 EXPLICIT means we received a FocusIn for the frame and know it has
729 the focus. IMPLICIT means we received an EnterNotify and the frame
730 may have the focus if no window manager is running.
731 FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
738 /* Return the X output data for frame F. */
739 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
741 /* Return the X window used for displaying data in frame F. */
742 #define FRAME_X_WINDOW(f) ((f)->output_data.x->window_desc)
744 /* Return the outermost X window associated with the frame F. */
746 #define FRAME_OUTER_WINDOW(f) ((f)->output_data.x->widget ? \
747 XtWindow ((f)->output_data.x->widget) : \
751 /* Functions not present in older Gtk+ */
753 #ifndef HAVE_GTK_WIDGET_GET_WINDOW
754 #define gtk_widget_get_window(w) ((w)->window)
756 #ifndef HAVE_GTK_WIDGET_GET_MAPPED
757 #define gtk_widget_get_mapped(w) (GTK_WIDGET_MAPPED (w))
759 #ifndef HAVE_GTK_ADJUSTMENT_GET_PAGE_SIZE
760 #define gtk_adjustment_get_page_size(w) ((w)->page_size)
761 #define gtk_adjustment_get_upper(w) ((w)->upper)
765 #define DEFAULT_GDK_DISPLAY() \
766 gdk_x11_display_get_xdisplay (gdk_display_get_default ())
768 #undef GDK_WINDOW_XID
769 #define GDK_WINDOW_XID(w) GDK_WINDOW_XWINDOW (w)
770 #define DEFAULT_GDK_DISPLAY() GDK_DISPLAY ()
771 #define gtk_widget_get_preferred_size(a, ign, b) \
772 gtk_widget_size_request (a, b)
775 #define GTK_WIDGET_TO_X_WIN(w) \
776 ((w) && gtk_widget_get_window (w) \
777 ? GDK_WINDOW_XID (gtk_widget_get_window (w)) : 0)
779 #define FRAME_GTK_OUTER_WIDGET(f) ((f)->output_data.x->widget)
780 #define FRAME_GTK_WIDGET(f) ((f)->output_data.x->edit_widget)
781 #define FRAME_OUTER_WINDOW(f) \
782 (FRAME_GTK_OUTER_WIDGET (f) ? \
783 GTK_WIDGET_TO_X_WIN (FRAME_GTK_OUTER_WIDGET (f)) : \
787 #define FRAME_OUTER_WINDOW(f) (FRAME_X_WINDOW (f))
788 #endif /* !USE_GTK */
791 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
792 #define FRAME_MENUBAR_HEIGHT(f) ((f)->output_data.x->menubar_height)
794 #define FRAME_MENUBAR_HEIGHT(f) ((void) f, 0)
795 #endif /* USE_X_TOOLKIT || USE_GTK */
797 #define FRAME_FONT(f) ((f)->output_data.x->font)
798 #define FRAME_FONTSET(f) ((f)->output_data.x->fontset)
799 #define FRAME_TOOLBAR_TOP_HEIGHT(f) ((f)->output_data.x->toolbar_top_height)
800 #define FRAME_TOOLBAR_BOTTOM_HEIGHT(f) \
801 ((f)->output_data.x->toolbar_bottom_height)
802 #define FRAME_TOOLBAR_HEIGHT(f) \
803 (FRAME_TOOLBAR_TOP_HEIGHT (f) + FRAME_TOOLBAR_BOTTOM_HEIGHT (f))
804 #define FRAME_TOOLBAR_LEFT_WIDTH(f) ((f)->output_data.x->toolbar_left_width)
805 #define FRAME_TOOLBAR_RIGHT_WIDTH(f) ((f)->output_data.x->toolbar_right_width)
806 #define FRAME_TOOLBAR_WIDTH(f) \
807 (FRAME_TOOLBAR_LEFT_WIDTH (f) + FRAME_TOOLBAR_RIGHT_WIDTH (f))
808 #define FRAME_BASELINE_OFFSET(f) ((f)->output_data.x->baseline_offset)
810 /* This gives the x_display_info structure for the display F is on. */
811 #define FRAME_DISPLAY_INFO(f) ((f)->output_data.x->display_info)
813 /* This is the `Display *' which frame F is on. */
814 #define FRAME_X_DISPLAY(f) (FRAME_DISPLAY_INFO (f)->display)
816 /* This is the `Screen *' which frame F is on. */
817 #define FRAME_X_SCREEN(f) (FRAME_DISPLAY_INFO (f)->screen)
819 /* This is the screen index number of screen which frame F is on. */
820 #define FRAME_X_SCREEN_NUMBER(f) XScreenNumberOfScreen (FRAME_X_SCREEN (f))
822 /* This is the Visual which frame F is on. */
823 #define FRAME_X_VISUAL(f) FRAME_DISPLAY_INFO (f)->visual
825 /* This is the Colormap which frame F uses. */
826 #define FRAME_X_COLORMAP(f) FRAME_DISPLAY_INFO (f)->cmap
828 #define FRAME_XIC(f) ((f)->output_data.x->xic)
829 #define FRAME_X_XIM(f) (FRAME_DISPLAY_INFO (f)->xim)
830 #define FRAME_X_XIM_STYLES(f) (FRAME_DISPLAY_INFO (f)->xim_styles)
831 #define FRAME_XIC_STYLE(f) ((f)->output_data.x->xic_style)
832 #define FRAME_XIC_FONTSET(f) ((f)->output_data.x->xic_xfs)
834 /* X-specific scroll bar stuff. */
836 /* We represent scroll bars as lisp vectors. This allows us to place
837 references to them in windows without worrying about whether we'll
838 end up with windows referring to dead scroll bars; the garbage
839 collector will free it when its time comes.
841 We use struct scroll_bar as a template for accessing fields of the
846 /* These fields are shared by all vectors. */
847 struct vectorlike_header header
;
849 /* The window we're a scroll bar for. */
852 /* The next and previous in the chain of scroll bars in this frame. */
853 Lisp_Object next
, prev
;
855 /* Fields from `x_window' down will not be traced by the GC. */
857 /* The X window representing this scroll bar. */
860 /* The position and size of the scroll bar in pixels, relative to the
862 int top
, left
, width
, height
;
864 /* The starting and ending positions of the handle, relative to the
865 handle area (i.e. zero is the top position, not
866 SCROLL_BAR_TOP_BORDER). If they're equal, that means the handle
867 hasn't been drawn yet.
869 These are not actually the locations where the beginning and end
870 are drawn; in order to keep handles from becoming invisible when
871 editing large files, we establish a minimum height by always
872 drawing handle bottoms VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
873 where they would be normally; the bottom and top are in a
874 different co-ordinate system. */
877 /* If the scroll bar handle is currently being dragged by the user,
878 this is the number of pixels from the top of the handle to the
879 place where the user grabbed it. If the handle isn't currently
880 being dragged, this is -1. */
883 #if defined (USE_TOOLKIT_SCROLL_BARS) && defined (USE_LUCID)
884 /* Last scroll bar part seen in xaw_jump_callback and xaw_scroll_callback. */
885 enum scroll_bar_part last_seen_part
;
888 #if defined (USE_TOOLKIT_SCROLL_BARS) && !defined (USE_GTK)
889 /* Last value of whole for horizontal scrollbars. */
893 /* True if the scroll bar is horizontal. */
897 /* Turning a lisp vector value into a pointer to a struct scroll_bar. */
898 #define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec))
902 /* Extract the X widget of the scroll bar from a struct scroll_bar.
903 XtWindowToWidget should be fast enough since Xt uses a hash table
904 to map windows to widgets. */
906 #define SCROLL_BAR_X_WIDGET(dpy, ptr) \
907 XtWindowToWidget (dpy, ptr->x_window)
909 /* Store a widget id in a struct scroll_bar. */
911 #define SET_SCROLL_BAR_X_WIDGET(ptr, w) \
913 Window window = XtWindow (w); \
914 ptr->x_window = window; \
917 #endif /* USE_X_TOOLKIT */
919 /* Return the inside width of a vertical scroll bar, given the outside
921 #define VERTICAL_SCROLL_BAR_INSIDE_WIDTH(f, width) \
923 - VERTICAL_SCROLL_BAR_LEFT_BORDER \
924 - VERTICAL_SCROLL_BAR_RIGHT_BORDER)
926 /* Return the length of the rectangle within which the top of the
927 handle must stay. This isn't equivalent to the inside height,
928 because the scroll bar handle has a minimum height.
930 This is the real range of motion for the scroll bar, so when we're
931 scaling buffer positions to scroll bar positions, we use this, not
932 VERTICAL_SCROLL_BAR_INSIDE_HEIGHT. */
933 #define VERTICAL_SCROLL_BAR_TOP_RANGE(f, height) \
934 (VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, height) - VERTICAL_SCROLL_BAR_MIN_HANDLE)
936 /* Return the inside height of vertical scroll bar, given the outside
937 height. See VERTICAL_SCROLL_BAR_TOP_RANGE too. */
938 #define VERTICAL_SCROLL_BAR_INSIDE_HEIGHT(f, height) \
939 ((height) - VERTICAL_SCROLL_BAR_TOP_BORDER - VERTICAL_SCROLL_BAR_BOTTOM_BORDER)
941 /* Return the inside height of a horizontal scroll bar, given the outside
943 #define HORIZONTAL_SCROLL_BAR_INSIDE_HEIGHT(f, height) \
945 - HORIZONTAL_SCROLL_BAR_TOP_BORDER \
946 - HORIZONTAL_SCROLL_BAR_BOTTOM_BORDER)
948 /* Return the length of the rectangle within which the left part of the
949 handle must stay. This isn't equivalent to the inside width, because
950 the scroll bar handle has a minimum width.
952 This is the real range of motion for the scroll bar, so when we're
953 scaling buffer positions to scroll bar positions, we use this, not
954 HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH. */
955 #define HORIZONTAL_SCROLL_BAR_LEFT_RANGE(f, width) \
956 (HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH (f, width) - HORIZONTAL_SCROLL_BAR_MIN_HANDLE)
958 /* Return the inside width of horizontal scroll bar, given the outside
959 width. See HORIZONTAL_SCROLL_BAR_LEFT_RANGE too. */
960 #define HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH(f, width) \
961 ((width) - HORIZONTAL_SCROLL_BAR_LEFT_BORDER - HORIZONTAL_SCROLL_BAR_LEFT_BORDER)
964 /* Border widths for scroll bars.
966 Scroll bar windows don't have any X borders; their border width is
967 set to zero, and we redraw borders ourselves. This makes the code
968 a bit cleaner, since we don't have to convert between outside width
969 (used when relating to the rest of the screen) and inside width
970 (used when sizing and drawing the scroll bar window itself).
972 The handle moves up and down/back and forth in a rectangle inset
973 from the edges of the scroll bar. These are widths by which we
974 inset the handle boundaries from the scroll bar edges. */
975 #define VERTICAL_SCROLL_BAR_LEFT_BORDER (2)
976 #define VERTICAL_SCROLL_BAR_RIGHT_BORDER (2)
977 #define VERTICAL_SCROLL_BAR_TOP_BORDER (2)
978 #define VERTICAL_SCROLL_BAR_BOTTOM_BORDER (2)
980 #define HORIZONTAL_SCROLL_BAR_LEFT_BORDER (2)
981 #define HORIZONTAL_SCROLL_BAR_RIGHT_BORDER (2)
982 #define HORIZONTAL_SCROLL_BAR_TOP_BORDER (2)
983 #define HORIZONTAL_SCROLL_BAR_BOTTOM_BORDER (2)
985 /* Minimum lengths for scroll bar handles, in pixels. */
986 #define VERTICAL_SCROLL_BAR_MIN_HANDLE (5)
987 #define HORIZONTAL_SCROLL_BAR_MIN_HANDLE (5)
989 /* If a struct input_event has a kind which is SELECTION_REQUEST_EVENT
990 or SELECTION_CLEAR_EVENT, then its contents are really described
991 by this structure. */
993 /* For an event of kind SELECTION_REQUEST_EVENT,
994 this structure really describes the contents. */
996 struct selection_input_event
998 ENUM_BF (event_kind
) kind
: EVENT_KIND_WIDTH
;
999 struct x_display_info
*dpyinfo
;
1000 /* We spell it with an "o" here because X does. */
1002 Atom selection
, target
, property
;
1006 /* Unlike macros below, this can't be used as an lvalue. */
1008 SELECTION_EVENT_DISPLAY (struct selection_input_event
*ev
)
1010 return ev
->dpyinfo
->display
;
1012 #define SELECTION_EVENT_DPYINFO(eventp) \
1014 /* We spell it with an "o" here because X does. */
1015 #define SELECTION_EVENT_REQUESTOR(eventp) \
1016 ((eventp)->requestor)
1017 #define SELECTION_EVENT_SELECTION(eventp) \
1018 ((eventp)->selection)
1019 #define SELECTION_EVENT_TARGET(eventp) \
1021 #define SELECTION_EVENT_PROPERTY(eventp) \
1022 ((eventp)->property)
1023 #define SELECTION_EVENT_TIME(eventp) \
1028 extern void x_free_gcs (struct frame
*);
1029 extern void x_relative_mouse_position (struct frame
*, int *, int *);
1030 extern void x_real_pos_and_offsets (struct frame
*f
,
1032 int *right_offset_x
,
1034 int *bottom_offset_y
,
1043 XrmDatabase
x_load_resources (Display
*, const char *, const char *,
1046 /* Defined in xterm.c */
1048 typedef void (*x_special_error_handler
)(Display
*, XErrorEvent
*, char *,
1051 extern bool x_text_icon (struct frame
*, const char *);
1052 extern void x_catch_errors (Display
*);
1053 extern void x_catch_errors_with_handler (Display
*, x_special_error_handler
,
1055 extern void x_check_errors (Display
*, const char *)
1056 ATTRIBUTE_FORMAT_PRINTF (2, 0);
1057 extern bool x_had_errors_p (Display
*);
1058 extern void x_uncatch_errors (void);
1059 extern void x_uncatch_errors_after_check (void);
1060 extern void x_clear_errors (Display
*);
1061 extern void xembed_request_focus (struct frame
*);
1062 extern void x_ewmh_activate_frame (struct frame
*);
1063 extern void x_delete_terminal (struct terminal
*terminal
);
1064 extern unsigned long x_copy_color (struct frame
*, unsigned long);
1065 #ifdef USE_X_TOOLKIT
1066 extern XtAppContext Xt_app_con
;
1067 extern void x_activate_timeout_atimer (void);
1070 extern bool x_alloc_lighter_color_for_widget (Widget
, Display
*, Colormap
,
1074 extern bool x_alloc_nearest_color (struct frame
*, Colormap
, XColor
*);
1075 extern void x_query_color (struct frame
*f
, XColor
*);
1076 extern void x_clear_area (struct frame
*f
, int, int, int, int);
1077 #if !defined USE_X_TOOLKIT && !defined USE_GTK
1078 extern void x_mouse_leave (struct x_display_info
*);
1081 #if defined USE_X_TOOLKIT || defined USE_MOTIF
1082 extern int x_dispatch_event (XEvent
*, Display
*);
1084 extern int x_x_to_emacs_modifiers (struct x_display_info
*, int);
1086 extern cairo_t
*x_begin_cr_clip (struct frame
*, GC
);
1087 extern void x_end_cr_clip (struct frame
*);
1088 extern void x_set_cr_source_with_gc_foreground (struct frame
*, GC
);
1089 extern void x_set_cr_source_with_gc_background (struct frame
*, GC
);
1090 extern void x_cr_draw_frame (cairo_t
*, struct frame
*);
1091 extern Lisp_Object
x_cr_export_frames (Lisp_Object
, cairo_surface_type_t
);
1095 x_display_pixel_height (struct x_display_info
*dpyinfo
)
1097 return HeightOfScreen (dpyinfo
->screen
);
1101 x_display_pixel_width (struct x_display_info
*dpyinfo
)
1103 return WidthOfScreen (dpyinfo
->screen
);
1107 x_display_set_last_user_time (struct x_display_info
*dpyinfo
, Time t
)
1109 #ifdef ENABLE_CHECKING
1110 eassert (t
<= X_ULONG_MAX
);
1112 dpyinfo
->last_user_time
= t
;
1115 INLINE
unsigned long
1116 x_make_truecolor_pixel (struct x_display_info
*dpyinfo
, int r
, int g
, int b
)
1118 unsigned long pr
, pg
, pb
;
1120 /* Scale down RGB values to the visual's bits per RGB, and shift
1121 them to the right position in the pixel color. Note that the
1122 original RGB values are 16-bit values, as usual in X. */
1123 pr
= (r
>> (16 - dpyinfo
->red_bits
)) << dpyinfo
->red_offset
;
1124 pg
= (g
>> (16 - dpyinfo
->green_bits
)) << dpyinfo
->green_offset
;
1125 pb
= (b
>> (16 - dpyinfo
->blue_bits
)) << dpyinfo
->blue_offset
;
1127 /* Assemble the pixel color. */
1128 return pr
| pg
| pb
;
1131 /* If display has an immutable color map, freeing colors is not
1132 necessary and some servers don't allow it, so we won't do it. That
1133 also allows us to make other optimizations relating to server-side
1134 reference counts. */
1136 x_mutable_colormap (Visual
*visual
)
1138 int class = visual
->class;
1139 return (class != StaticColor
&& class != StaticGray
&& class != TrueColor
);
1142 extern void x_set_sticky (struct frame
*, Lisp_Object
, Lisp_Object
);
1143 extern bool x_wm_supports (struct frame
*, Atom
);
1144 extern void x_wait_for_event (struct frame
*, int);
1145 extern void x_clear_under_internal_border (struct frame
*f
);
1147 /* Defined in xselect.c. */
1149 extern void x_handle_property_notify (const XPropertyEvent
*);
1150 extern void x_handle_selection_notify (const XSelectionEvent
*);
1151 extern void x_handle_selection_event (struct selection_input_event
*);
1152 extern void x_clear_frame_selections (struct frame
*);
1154 extern void x_send_client_event (Lisp_Object display
,
1159 Lisp_Object values
);
1161 extern bool x_handle_dnd_message (struct frame
*,
1162 const XClientMessageEvent
*,
1163 struct x_display_info
*,
1164 struct input_event
*);
1165 extern int x_check_property_data (Lisp_Object
);
1166 extern void x_fill_property_data (Display
*,
1170 extern Lisp_Object
x_property_data_to_lisp (struct frame
*,
1171 const unsigned char *,
1175 extern void x_clipboard_manager_save_frame (Lisp_Object
);
1176 extern void x_clipboard_manager_save_all (void);
1179 extern bool xg_set_icon (struct frame
*, Lisp_Object
);
1180 extern bool xg_set_icon_from_xpm_data (struct frame
*, const char **);
1181 #endif /* USE_GTK */
1183 extern void xic_free_xfontset (struct frame
*);
1184 extern void create_frame_xic (struct frame
*);
1185 extern void destroy_frame_xic (struct frame
*);
1186 extern void xic_set_preeditarea (struct window
*, int, int);
1187 extern void xic_set_statusarea (struct frame
*);
1188 extern void xic_set_xfontset (struct frame
*, const char *);
1189 extern bool x_defined_color (struct frame
*, const char *, XColor
*, bool);
1191 extern void free_frame_xic (struct frame
*);
1192 # if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
1193 extern char *xic_create_fontsetname (const char *, bool);
1197 /* Defined in xfaces.c */
1199 #ifdef USE_X_TOOLKIT
1200 extern void x_free_dpy_colors (Display
*, Screen
*, Colormap
,
1201 unsigned long *, int);
1202 #endif /* USE_X_TOOLKIT */
1204 /* Defined in xmenu.c */
1206 #if defined USE_X_TOOLKIT || defined USE_GTK
1207 extern Lisp_Object
xw_popup_dialog (struct frame
*, Lisp_Object
, Lisp_Object
);
1210 #if defined USE_GTK || defined USE_MOTIF
1211 extern void x_menu_set_in_use (bool);
1213 extern void x_menu_wait_for_event (void *data
);
1214 extern void initialize_frame_menubar (struct frame
*);
1216 /* Defined in xsmfns.c */
1218 extern void x_session_initialize (struct x_display_info
*dpyinfo
);
1219 extern bool x_session_have_connection (void);
1220 extern void x_session_close (void);
1224 /* Is the frame embedded into another application? */
1226 #define FRAME_X_EMBEDDED_P(f) (FRAME_X_OUTPUT(f)->explicit_parent != 0)
1228 #define STORE_XCHAR2B(chp, b1, b2) \
1229 ((chp)->byte1 = (b1), (chp)->byte2 = (b2))
1231 #define XCHAR2B_BYTE1(chp) \
1234 #define XCHAR2B_BYTE2(chp) \
1237 #define STORE_NATIVE_RECT(nr,rx,ry,rwidth,rheight) \
1240 (nr).width = (rwidth), \
1241 (nr).height = (rheight))
1245 #endif /* XTERM_H */