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
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>
91 #include <X11/Xlib-xcb.h>
94 #include "dispextern.h"
95 #include "termhooks.h"
99 /* Black and white pixel values for the screen which frame F is on. */
100 #define BLACK_PIX_DEFAULT(f) \
101 BlackPixel (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f))
102 #define WHITE_PIX_DEFAULT(f) \
103 WhitePixel (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f))
105 /* The mask of events that text windows always want to receive. This
106 includes mouse movement events, since handling the mouse-font text property
107 means that we must track mouse motion all the time. */
109 #define STANDARD_EVENT_SET \
113 | ButtonReleaseMask \
114 | PointerMotionMask \
115 | StructureNotifyMask \
119 | VisibilityChangeMask)
121 #ifdef HAVE_X11R6_XIM
122 /* Data structure passed to xim_instantiate_callback. */
125 struct x_display_info
*dpyinfo
;
128 #endif /* HAVE_X11R6_XIM */
130 /* Structure recording X pixmap and reference count.
131 If REFCOUNT is 0 then this record is free to be reused. */
133 struct x_bitmap_record
143 /* Record some info about this pixmap. */
144 int height
, width
, depth
;
150 #define MAX_CLIP_RECTS 2
151 /* Number of clipping rectangles. */
154 /* Clipping rectangles. */
155 XRectangle clip_rects
[MAX_CLIP_RECTS
];
160 struct color_name_cache_entry
162 struct color_name_cache_entry
*next
;
167 Status
x_parse_color (struct frame
*f
, const char *color_name
,
171 /* For each X display, we have a structure that records
172 information about it. */
174 struct x_display_info
176 /* Chain of all x_display_info structures. */
177 struct x_display_info
*next
;
179 /* The generic display parameters corresponding to this X display. */
180 struct terminal
*terminal
;
182 /* This says how to access this display in Xlib. */
185 /* A connection number (file descriptor) for the display. */
188 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE). */
189 Lisp_Object name_list_element
;
191 /* Number of frames that are on this display. */
194 /* The Screen this connection is connected to. */
197 /* Dots per inch of the screen. */
200 /* The Visual being used for this display. */
203 /* The colormap being used. */
206 /* Number of planes on this screen. */
209 /* Mask of things that cause the mouse to be grabbed. */
212 /* Emacs bitmap-id of the default icon bitmap for this frame.
213 Or -1 if none has been allocated yet. */
214 ptrdiff_t icon_bitmap_id
;
216 /* The root window of this screen. */
219 /* Client leader window. */
220 Window client_leader_window
;
222 /* The cursor to use for vertical scroll bars. */
223 Cursor vertical_scroll_bar_cursor
;
225 /* The cursor to use for horizontal scroll bars. */
226 Cursor horizontal_scroll_bar_cursor
;
228 /* The invisible cursor used for pointer blanking.
229 Unused if this display supports Xfixes extension. */
230 Cursor invisible_cursor
;
232 /* Function used to toggle pointer visibility on this display. */
233 void (*toggle_visible_pointer
) (struct frame
*, bool);
236 /* The GDK cursor for scroll bars and popup menus. */
237 GdkCursor
*xg_cursor
;
240 /* X Resource data base */
243 /* Minimum width over all characters in all fonts in font_table. */
244 int smallest_char_width
;
246 /* Minimum font height over all fonts in font_table. */
247 int smallest_font_height
;
249 /* Reusable Graphics Context for drawing a cursor in a non-default face. */
250 GC scratch_cursor_gc
;
252 /* Information about the range of text currently shown in
254 Mouse_HLInfo mouse_highlight
;
256 /* Logical identifier of this display. */
259 /* Default name for all frames on this display. */
262 /* The number of fonts opened for this display. */
265 /* Pointer to bitmap records. */
266 struct x_bitmap_record
*bitmaps
;
268 /* Allocated size of bitmaps field. */
269 ptrdiff_t bitmaps_size
;
271 /* Last used bitmap index. */
272 ptrdiff_t bitmaps_last
;
274 /* Which modifier keys are on which modifier bits?
276 With each keystroke, X returns eight bits indicating which modifier
277 keys were held down when the key was pressed. The interpretation
278 of the top five modifier bits depends on what keys are attached
279 to them. If the Meta_L and Meta_R keysyms are on mod5, then mod5
282 meta_mod_mask is a mask containing the bits used for the meta key.
283 It may have more than one bit set, if more than one modifier bit
284 has meta keys on it. Basically, if EVENT is a KeyPress event,
285 the meta key is pressed if (EVENT.state & meta_mod_mask) != 0.
287 shift_lock_mask is LockMask if the XK_Shift_Lock keysym is on the
288 lock modifier bit, or zero otherwise. Non-alphabetic keys should
289 only be affected by the lock modifier bit if XK_Shift_Lock is in
290 use; XK_Caps_Lock should only affect alphabetic keys. With this
291 arrangement, the lock modifier should shift the character if
292 (EVENT.state & shift_lock_mask) != 0. */
293 int meta_mod_mask
, shift_lock_mask
;
295 /* These are like meta_mod_mask, but for different modifiers. */
296 int alt_mod_mask
, super_mod_mask
, hyper_mod_mask
;
298 /* Communication with window managers. */
299 Atom Xatom_wm_protocols
;
301 /* Kinds of protocol things we may receive. */
302 Atom Xatom_wm_take_focus
;
303 Atom Xatom_wm_save_yourself
;
304 Atom Xatom_wm_delete_window
;
306 /* Atom for indicating window state to the window manager. */
307 Atom Xatom_wm_change_state
;
309 /* Other WM communication */
310 Atom Xatom_wm_configure_denied
; /* When our config request is denied */
311 Atom Xatom_wm_window_moved
; /* When the WM moves us. */
312 Atom Xatom_wm_client_leader
; /* Id of client leader window. */
314 /* EditRes protocol */
317 /* More atoms, which are selection types. */
318 Atom Xatom_CLIPBOARD
, Xatom_TIMESTAMP
, Xatom_TEXT
, Xatom_DELETE
,
319 Xatom_COMPOUND_TEXT
, Xatom_UTF8_STRING
,
320 Xatom_MULTIPLE
, Xatom_INCR
, Xatom_EMACS_TMP
, Xatom_TARGETS
, Xatom_NULL
,
321 Xatom_ATOM
, Xatom_ATOM_PAIR
, Xatom_CLIPBOARD_MANAGER
;
323 /* More atoms for font properties. The last three are private
324 properties, see the comments in src/fontset.h. */
325 Atom Xatom_PIXEL_SIZE
, Xatom_AVERAGE_WIDTH
,
326 Xatom_MULE_BASELINE_OFFSET
, Xatom_MULE_RELATIVE_COMPOSE
,
327 Xatom_MULE_DEFAULT_ASCENT
;
329 /* More atoms for Ghostscript support. */
330 Atom Xatom_DONE
, Xatom_PAGE
;
332 /* Atoms used in toolkit scroll bar client messages. */
333 Atom Xatom_Scrollbar
, Xatom_Horizontal_Scrollbar
;
335 /* Atom used in XEmbed client messages. */
336 Atom Xatom_XEMBED
, Xatom_XEMBED_INFO
;
338 /* The frame (if any) which has the X window that has keyboard focus.
339 Zero if none. This is examined by Ffocus_frame in xfns.c. Note
340 that a mere EnterNotify event can set this; if you need to know the
341 last frame specified in a FocusIn or FocusOut event, use
342 x_focus_event_frame. */
343 struct frame
*x_focus_frame
;
345 /* The last frame mentioned in a FocusIn or FocusOut event. This is
346 separate from x_focus_frame, because whether or not LeaveNotify
347 events cause us to lose focus depends on whether or not we have
348 received a FocusIn event for it. */
349 struct frame
*x_focus_event_frame
;
351 /* The frame which currently has the visual highlight, and should get
352 keyboard input (other sorts of input have the frame encoded in the
353 event). It points to the X focus frame's selected window's
354 frame. It differs from x_focus_frame when we're using a global
356 struct frame
*x_highlight_frame
;
358 /* The frame waiting to be auto-raised in XTread_socket. */
359 struct frame
*x_pending_autoraise_frame
;
361 /* The frame where the mouse was last time we reported a ButtonPress event. */
362 struct frame
*last_mouse_frame
;
364 /* The frame where the mouse was last time we reported a mouse position. */
365 struct frame
*last_mouse_glyph_frame
;
367 /* The frame where the mouse was last time we reported a mouse motion. */
368 struct frame
*last_mouse_motion_frame
;
370 /* The scroll bar in which the last X motion event occurred. */
371 struct scroll_bar
*last_mouse_scroll_bar
;
373 /* Time of last user interaction as returned in X events on this display. */
376 /* Position where the mouse was last time we reported a motion.
377 This is a position on last_mouse_motion_frame. */
378 int last_mouse_motion_x
;
379 int last_mouse_motion_y
;
381 /* Where the mouse was last time we reported a mouse position.
382 This is a rectangle on last_mouse_glyph_frame. */
383 XRectangle last_mouse_glyph
;
385 /* Time of last mouse movement on this display. This is a hack because
386 we would really prefer that XTmouse_position would return the time
387 associated with the position it returns, but there doesn't seem to be
388 any way to wrest the time-stamp from the server along with the position
389 query. So, we just keep track of the time of the last movement we
390 received, and return that in hopes that it's somewhat accurate. */
391 Time last_mouse_movement_time
;
393 /* The gray pixmap. */
397 /* XIM (X Input method). */
399 XIMStyles
*xim_styles
;
400 struct xim_inst_t
*xim_callback_data
;
403 /* A cache mapping color names to RGB values. */
404 struct color_name_cache_entry
*color_names
;
406 /* If non-null, a cache of the colors in the color map. Don't
407 use this directly, call x_color_cells instead. */
411 /* Bits and shifts to use to compose pixel values on TrueColor visuals. */
412 int red_bits
, blue_bits
, green_bits
;
413 int red_offset
, blue_offset
, green_offset
;
415 /* The type of window manager we have. If we move FRAME_OUTER_WINDOW
416 to x/y 0/0, some window managers (type A) puts the window manager
417 decorations outside the screen and FRAME_OUTER_WINDOW exactly at 0/0.
418 Other window managers (type B) puts the window including decorations
419 at 0/0, so FRAME_OUTER_WINDOW is a bit below 0/0.
420 Record the type of WM in use so we can compensate for type A WMs. */
429 /* Atoms that are drag and drop atoms */
431 ptrdiff_t x_dnd_atoms_size
;
432 ptrdiff_t x_dnd_atoms_length
;
434 /* Extended window manager hints, Atoms supported by the window manager and
435 atoms for setting the window type. */
436 Atom Xatom_net_supported
, Xatom_net_supporting_wm_check
;
437 Atom
*net_supported_atoms
;
438 int nr_net_supported_atoms
;
439 Window net_supported_window
;
440 Atom Xatom_net_window_type
, Xatom_net_window_type_tooltip
;
441 Atom Xatom_net_active_window
;
443 /* Atoms dealing with EWMH (i.e. _NET_...) */
444 Atom Xatom_net_wm_state
, Xatom_net_wm_state_fullscreen
,
445 Xatom_net_wm_state_maximized_horz
, Xatom_net_wm_state_maximized_vert
,
446 Xatom_net_wm_state_sticky
, Xatom_net_wm_state_hidden
,
447 Xatom_net_frame_extents
,
448 Xatom_net_current_desktop
, Xatom_net_workarea
;
450 /* XSettings atoms and windows. */
451 Atom Xatom_xsettings_sel
, Xatom_xsettings_prop
, Xatom_xsettings_mgr
;
452 Window xsettings_window
;
454 /* Frame name and icon name */
455 Atom Xatom_net_wm_name
, Xatom_net_wm_icon_name
;
457 Atom Xatom_net_wm_window_opacity
;
460 Atom Xatom_SM_CLIENT_ID
;
463 XExtCodes
*ext_codes
;
467 xcb_connection_t
*xcb_connection
;
472 /* Whether or not to use XIM if we have it. */
476 /* This is a chain of structures for all the X displays currently in use. */
477 extern struct x_display_info
*x_display_list
;
479 extern struct x_display_info
*x_display_info_for_display (Display
*);
480 extern struct frame
*x_top_window_to_frame (struct x_display_info
*, int);
481 extern struct x_display_info
*x_term_init (Lisp_Object
, char *, char *);
482 extern bool x_display_ok (const char *);
484 extern void select_visual (struct x_display_info
*);
486 /* Each X frame object points to its own struct x_output object
487 in the output_data.x field. The x_output structure contains
488 the information that is specific to X windows. */
492 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
493 /* Height of menu bar widget, in pixels. This value
494 is not meaningful if the menubar is turned off. */
498 /* Height of tool bar widget, in pixels. top_height is used if tool bar
499 at top, bottom_height if tool bar is at the bottom.
500 Zero if not using an external tool bar or if tool bar is vertical. */
501 int toolbar_top_height
, toolbar_bottom_height
;
503 /* Width of tool bar widget, in pixels. left_width is used if tool bar
504 at left, right_width if tool bar is at the right.
505 Zero if not using an external tool bar or if tool bar is horizontal. */
506 int toolbar_left_width
, toolbar_right_width
;
508 /* The tiled border used when the mouse is out of the frame. */
511 /* Here are the Graphics Contexts for the default font. */
512 GC normal_gc
; /* Normal video */
513 GC reverse_gc
; /* Reverse video */
514 GC cursor_gc
; /* cursor drawing */
516 /* The X window used for this frame.
517 May be zero while the frame object is being created
518 and the X window has not yet been created. */
521 /* The X window used for the bitmap icon;
522 or 0 if we don't have a bitmap icon. */
525 /* The X window that is the parent of this X window.
526 Usually this is a window that was made by the window manager,
527 but it can be the root window, and it can be explicitly specified
528 (see the explicit_parent field, below). */
532 /* The widget of this screen. This is the window of a "shell" widget. */
534 /* The XmPanedWindows... */
535 Widget column_widget
;
536 /* The widget of the edit portion of this screen; the window in
537 "window_desc" is inside of this. */
540 Widget menubar_widget
;
544 /* The widget of this screen. This is the window of a top widget. */
546 /* The widget of the edit portion of this screen; the window in
547 "window_desc" is inside of this. */
548 GtkWidget
*edit_widget
;
549 /* The widget used for laying out widgets vertically. */
550 GtkWidget
*vbox_widget
;
551 /* The widget used for laying out widgets horizontally. */
552 GtkWidget
*hbox_widget
;
553 /* The menubar in this frame. */
554 GtkWidget
*menubar_widget
;
555 /* The tool bar in this frame */
556 GtkWidget
*toolbar_widget
;
557 /* True if tool bar is packed into the hbox widget (i.e. vertical). */
558 bool_bf toolbar_in_hbox
: 1;
559 bool_bf toolbar_is_packed
: 1;
561 /* The last size hints set. */
562 GdkGeometry size_hints
;
565 #ifdef USE_GTK_TOOLTIP
566 GtkTooltip
*ttip_widget
;
568 GtkWindow
*ttip_window
;
569 #endif /* USE_GTK_TOOLTIP */
573 /* If >=0, a bitmap index. The indicated bitmap is used for the
575 ptrdiff_t icon_bitmap
;
577 /* Default ASCII font of this frame. */
580 /* The baseline offset of the default ASCII font. */
583 /* If a fontset is specified for this frame instead of font, this
584 value contains an ID of the fontset, else -1. */
587 unsigned long cursor_pixel
;
588 unsigned long border_pixel
;
589 unsigned long mouse_pixel
;
590 unsigned long cursor_foreground_pixel
;
592 /* Foreground color for scroll bars. A value of -1 means use the
593 default (black for non-toolkit scroll bars). */
594 unsigned long scroll_bar_foreground_pixel
;
596 /* Background color for scroll bars. A value of -1 means use the
597 default (background color of the frame for non-toolkit scroll
599 unsigned long scroll_bar_background_pixel
;
601 #if defined (USE_LUCID) && defined (USE_TOOLKIT_SCROLL_BARS)
602 /* Top and bottom shadow colors for 3D Lucid scrollbars.
603 -1 means let the scroll compute them itself. */
604 unsigned long scroll_bar_top_shadow_pixel
;
605 unsigned long scroll_bar_bottom_shadow_pixel
;
608 /* Descriptor for the cursor in use for this window. */
610 Cursor nontext_cursor
;
611 Cursor modeline_cursor
;
613 Cursor hourglass_cursor
;
614 Cursor horizontal_drag_cursor
;
615 Cursor vertical_drag_cursor
;
616 Cursor current_cursor
;
618 /* Window whose cursor is hourglass_cursor. This window is temporarily
619 mapped to display an hourglass cursor. */
620 Window hourglass_window
;
622 /* These are the current window manager hints. It seems that
623 XSetWMHints, when presented with an unset bit in the `flags'
624 member of the hints structure, does not leave the corresponding
625 attribute unchanged; rather, it resets that attribute to its
626 default value. For example, unless you set the `icon_pixmap'
627 field and the `IconPixmapHint' bit, XSetWMHints will forget what
628 your icon pixmap was. This is rather troublesome, since some of
629 the members (for example, `input' and `icon_pixmap') want to stay
630 the same throughout the execution of Emacs. So, we keep this
631 structure around, just leaving values in it and adding new bits
632 to the mask as we go. */
635 /* This is the Emacs structure for the X display this frame is on. */
636 struct x_display_info
*display_info
;
638 /* This is a button event that wants to activate the menubar.
639 We save it here until the command loop gets to think about it. */
640 XEvent
*saved_menu_event
;
642 /* This is the widget id used for this frame's menubar in lwlib. */
647 /* True means hourglass cursor is currently displayed. */
648 bool_bf hourglass_p
: 1;
650 /* True means our parent is another application's window
651 and was explicitly specified. */
652 bool_bf explicit_parent
: 1;
654 /* True means tried already to make this frame visible. */
655 bool_bf asked_for_visible
: 1;
657 /* True if this frame was ever previously visible. */
658 bool_bf has_been_visible
: 1;
660 /* Xt waits for a ConfigureNotify event from the window manager in
661 EmacsFrameSetCharSize when the shell widget is resized. For some
662 window managers like fvwm2 2.2.5 and KDE 2.1 this event doesn't
663 arrive for an unknown reason and Emacs hangs in Xt. If this is
664 false, tell Xt not to wait. */
665 bool_bf wait_for_wm
: 1;
668 /* Input context (currently, this means Compose key handler setup). */
674 /* Relief GCs, colors etc. */
680 black_relief
, white_relief
;
682 /* The background for which the above relief GCs were set up.
683 They are changed only when a different background is involved. */
684 unsigned long relief_background
;
686 /* Keep track of focus. May be EXPLICIT if we received a FocusIn for this
687 frame, or IMPLICIT if we received an EnterNotify.
688 FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
691 /* The offset we need to add to compensate for type A WMs. */
693 int move_offset_left
;
695 /* Extreme 'short' and 'long' values suitable for libX11. */
696 #define X_SHRT_MAX 0x7fff
697 #define X_SHRT_MIN (-1 - X_SHRT_MAX)
698 #define X_LONG_MAX 0x7fffffff
699 #define X_LONG_MIN (-1 - X_LONG_MAX)
700 #define X_ULONG_MAX 0xffffffffUL
703 /* Cairo drawing context. */
705 /* Cairo surface for double buffering */
706 cairo_surface_t
*cr_surface
;
710 #define No_Cursor (None)
714 /* Values for focus_state, used as bit mask.
715 EXPLICIT means we received a FocusIn for the frame and know it has
716 the focus. IMPLICIT means we received an EnterNotify and the frame
717 may have the focus if no window manager is running.
718 FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
725 /* Return the X output data for frame F. */
726 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
728 /* Return the X window used for displaying data in frame F. */
729 #define FRAME_X_WINDOW(f) ((f)->output_data.x->window_desc)
731 /* Return the outermost X window associated with the frame F. */
733 #define FRAME_OUTER_WINDOW(f) ((f)->output_data.x->widget ? \
734 XtWindow ((f)->output_data.x->widget) : \
738 /* Functions not present in older Gtk+ */
740 #ifndef HAVE_GTK_WIDGET_GET_WINDOW
741 #define gtk_widget_get_window(w) ((w)->window)
743 #ifndef HAVE_GTK_WIDGET_GET_MAPPED
744 #define gtk_widget_get_mapped(w) (GTK_WIDGET_MAPPED (w))
746 #ifndef HAVE_GTK_ADJUSTMENT_GET_PAGE_SIZE
747 #define gtk_adjustment_get_page_size(w) ((w)->page_size)
748 #define gtk_adjustment_get_upper(w) ((w)->upper)
752 #define DEFAULT_GDK_DISPLAY() \
753 gdk_x11_display_get_xdisplay (gdk_display_get_default ())
755 #undef GDK_WINDOW_XID
756 #define GDK_WINDOW_XID(w) GDK_WINDOW_XWINDOW (w)
757 #define DEFAULT_GDK_DISPLAY() GDK_DISPLAY ()
758 #define gtk_widget_get_preferred_size(a, ign, b) \
759 gtk_widget_size_request (a, b)
762 #define GTK_WIDGET_TO_X_WIN(w) \
763 ((w) && gtk_widget_get_window (w) \
764 ? GDK_WINDOW_XID (gtk_widget_get_window (w)) : 0)
766 #define FRAME_GTK_OUTER_WIDGET(f) ((f)->output_data.x->widget)
767 #define FRAME_GTK_WIDGET(f) ((f)->output_data.x->edit_widget)
768 #define FRAME_OUTER_WINDOW(f) \
769 (FRAME_GTK_OUTER_WIDGET (f) ? \
770 GTK_WIDGET_TO_X_WIN (FRAME_GTK_OUTER_WIDGET (f)) : \
774 #define FRAME_OUTER_WINDOW(f) (FRAME_X_WINDOW (f))
775 #endif /* !USE_GTK */
778 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
779 #define FRAME_MENUBAR_HEIGHT(f) ((f)->output_data.x->menubar_height)
781 #define FRAME_MENUBAR_HEIGHT(f) ((void) f, 0)
782 #endif /* USE_X_TOOLKIT || USE_GTK */
784 #define FRAME_FONT(f) ((f)->output_data.x->font)
785 #define FRAME_FONTSET(f) ((f)->output_data.x->fontset)
786 #define FRAME_TOOLBAR_TOP_HEIGHT(f) ((f)->output_data.x->toolbar_top_height)
787 #define FRAME_TOOLBAR_BOTTOM_HEIGHT(f) \
788 ((f)->output_data.x->toolbar_bottom_height)
789 #define FRAME_TOOLBAR_HEIGHT(f) \
790 (FRAME_TOOLBAR_TOP_HEIGHT (f) + FRAME_TOOLBAR_BOTTOM_HEIGHT (f))
791 #define FRAME_TOOLBAR_LEFT_WIDTH(f) ((f)->output_data.x->toolbar_left_width)
792 #define FRAME_TOOLBAR_RIGHT_WIDTH(f) ((f)->output_data.x->toolbar_right_width)
793 #define FRAME_TOOLBAR_WIDTH(f) \
794 (FRAME_TOOLBAR_LEFT_WIDTH (f) + FRAME_TOOLBAR_RIGHT_WIDTH (f))
795 #define FRAME_BASELINE_OFFSET(f) ((f)->output_data.x->baseline_offset)
797 /* This gives the x_display_info structure for the display F is on. */
798 #define FRAME_DISPLAY_INFO(f) ((f)->output_data.x->display_info)
800 /* This is the `Display *' which frame F is on. */
801 #define FRAME_X_DISPLAY(f) (FRAME_DISPLAY_INFO (f)->display)
803 /* This is the `Screen *' which frame F is on. */
804 #define FRAME_X_SCREEN(f) (FRAME_DISPLAY_INFO (f)->screen)
806 /* This is the screen index number of screen which frame F is on. */
807 #define FRAME_X_SCREEN_NUMBER(f) XScreenNumberOfScreen (FRAME_X_SCREEN (f))
809 /* This is the Visual which frame F is on. */
810 #define FRAME_X_VISUAL(f) FRAME_DISPLAY_INFO (f)->visual
812 /* This is the Colormap which frame F uses. */
813 #define FRAME_X_COLORMAP(f) FRAME_DISPLAY_INFO (f)->cmap
815 #define FRAME_XIC(f) ((f)->output_data.x->xic)
816 #define FRAME_X_XIM(f) (FRAME_DISPLAY_INFO (f)->xim)
817 #define FRAME_X_XIM_STYLES(f) (FRAME_DISPLAY_INFO (f)->xim_styles)
818 #define FRAME_XIC_STYLE(f) ((f)->output_data.x->xic_style)
819 #define FRAME_XIC_FONTSET(f) ((f)->output_data.x->xic_xfs)
821 /* X-specific scroll bar stuff. */
823 /* We represent scroll bars as lisp vectors. This allows us to place
824 references to them in windows without worrying about whether we'll
825 end up with windows referring to dead scroll bars; the garbage
826 collector will free it when its time comes.
828 We use struct scroll_bar as a template for accessing fields of the
833 /* These fields are shared by all vectors. */
834 struct vectorlike_header header
;
836 /* The window we're a scroll bar for. */
839 /* The next and previous in the chain of scroll bars in this frame. */
840 Lisp_Object next
, prev
;
842 /* Fields from `x_window' down will not be traced by the GC. */
844 /* The X window representing this scroll bar. */
847 /* The position and size of the scroll bar in pixels, relative to the
849 int top
, left
, width
, height
;
851 /* The starting and ending positions of the handle, relative to the
852 handle area (i.e. zero is the top position, not
853 SCROLL_BAR_TOP_BORDER). If they're equal, that means the handle
854 hasn't been drawn yet.
856 These are not actually the locations where the beginning and end
857 are drawn; in order to keep handles from becoming invisible when
858 editing large files, we establish a minimum height by always
859 drawing handle bottoms VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
860 where they would be normally; the bottom and top are in a
861 different co-ordinate system. */
864 /* If the scroll bar handle is currently being dragged by the user,
865 this is the number of pixels from the top of the handle to the
866 place where the user grabbed it. If the handle isn't currently
867 being dragged, this is -1. */
870 #if defined (USE_TOOLKIT_SCROLL_BARS) && defined (USE_LUCID)
871 /* Last scroll bar part seen in xaw_jump_callback and xaw_scroll_callback. */
872 enum scroll_bar_part last_seen_part
;
875 #if defined (USE_TOOLKIT_SCROLL_BARS) && !defined (USE_GTK)
876 /* Last value of whole for horizontal scrollbars. */
880 /* True if the scroll bar is horizontal. */
884 /* Turning a lisp vector value into a pointer to a struct scroll_bar. */
885 #define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec))
889 /* Extract the X widget of the scroll bar from a struct scroll_bar.
890 XtWindowToWidget should be fast enough since Xt uses a hash table
891 to map windows to widgets. */
893 #define SCROLL_BAR_X_WIDGET(dpy, ptr) \
894 XtWindowToWidget (dpy, ptr->x_window)
896 /* Store a widget id in a struct scroll_bar. */
898 #define SET_SCROLL_BAR_X_WIDGET(ptr, w) \
900 Window window = XtWindow (w); \
901 ptr->x_window = window; \
904 #endif /* USE_X_TOOLKIT */
906 /* Return the inside width of a vertical scroll bar, given the outside
908 #define VERTICAL_SCROLL_BAR_INSIDE_WIDTH(f, width) \
910 - VERTICAL_SCROLL_BAR_LEFT_BORDER \
911 - VERTICAL_SCROLL_BAR_RIGHT_BORDER)
913 /* Return the length of the rectangle within which the top of the
914 handle must stay. This isn't equivalent to the inside height,
915 because the scroll bar handle has a minimum height.
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 VERTICAL_SCROLL_BAR_INSIDE_HEIGHT. */
920 #define VERTICAL_SCROLL_BAR_TOP_RANGE(f, height) \
921 (VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, height) - VERTICAL_SCROLL_BAR_MIN_HANDLE)
923 /* Return the inside height of vertical scroll bar, given the outside
924 height. See VERTICAL_SCROLL_BAR_TOP_RANGE too. */
925 #define VERTICAL_SCROLL_BAR_INSIDE_HEIGHT(f, height) \
926 ((height) - VERTICAL_SCROLL_BAR_TOP_BORDER - VERTICAL_SCROLL_BAR_BOTTOM_BORDER)
928 /* Return the inside height of a horizontal scroll bar, given the outside
930 #define HORIZONTAL_SCROLL_BAR_INSIDE_HEIGHT(f, height) \
932 - HORIZONTAL_SCROLL_BAR_TOP_BORDER \
933 - HORIZONTAL_SCROLL_BAR_BOTTOM_BORDER)
935 /* Return the length of the rectangle within which the left part of the
936 handle must stay. This isn't equivalent to the inside width, because
937 the scroll bar handle has a minimum width.
939 This is the real range of motion for the scroll bar, so when we're
940 scaling buffer positions to scroll bar positions, we use this, not
941 HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH. */
942 #define HORIZONTAL_SCROLL_BAR_LEFT_RANGE(f, width) \
943 (HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH (f, width) - HORIZONTAL_SCROLL_BAR_MIN_HANDLE)
945 /* Return the inside width of horizontal scroll bar, given the outside
946 width. See HORIZONTAL_SCROLL_BAR_LEFT_RANGE too. */
947 #define HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH(f, width) \
948 ((width) - HORIZONTAL_SCROLL_BAR_LEFT_BORDER - HORIZONTAL_SCROLL_BAR_LEFT_BORDER)
951 /* Border widths for scroll bars.
953 Scroll bar windows don't have any X borders; their border width is
954 set to zero, and we redraw borders ourselves. This makes the code
955 a bit cleaner, since we don't have to convert between outside width
956 (used when relating to the rest of the screen) and inside width
957 (used when sizing and drawing the scroll bar window itself).
959 The handle moves up and down/back and forth in a rectangle inset
960 from the edges of the scroll bar. These are widths by which we
961 inset the handle boundaries from the scroll bar edges. */
962 #define VERTICAL_SCROLL_BAR_LEFT_BORDER (2)
963 #define VERTICAL_SCROLL_BAR_RIGHT_BORDER (2)
964 #define VERTICAL_SCROLL_BAR_TOP_BORDER (2)
965 #define VERTICAL_SCROLL_BAR_BOTTOM_BORDER (2)
967 #define HORIZONTAL_SCROLL_BAR_LEFT_BORDER (2)
968 #define HORIZONTAL_SCROLL_BAR_RIGHT_BORDER (2)
969 #define HORIZONTAL_SCROLL_BAR_TOP_BORDER (2)
970 #define HORIZONTAL_SCROLL_BAR_BOTTOM_BORDER (2)
972 /* Minimum lengths for scroll bar handles, in pixels. */
973 #define VERTICAL_SCROLL_BAR_MIN_HANDLE (5)
974 #define HORIZONTAL_SCROLL_BAR_MIN_HANDLE (5)
976 /* If a struct input_event has a kind which is SELECTION_REQUEST_EVENT
977 or SELECTION_CLEAR_EVENT, then its contents are really described
978 by this structure. */
980 /* For an event of kind SELECTION_REQUEST_EVENT,
981 this structure really describes the contents. */
983 struct selection_input_event
985 ENUM_BF (event_kind
) kind
: EVENT_KIND_WIDTH
;
986 struct x_display_info
*dpyinfo
;
987 /* We spell it with an "o" here because X does. */
989 Atom selection
, target
, property
;
993 /* Unlike macros below, this can't be used as an lvalue. */
995 SELECTION_EVENT_DISPLAY (struct selection_input_event
*ev
)
997 return ev
->dpyinfo
->display
;
999 #define SELECTION_EVENT_DPYINFO(eventp) \
1001 /* We spell it with an "o" here because X does. */
1002 #define SELECTION_EVENT_REQUESTOR(eventp) \
1003 ((eventp)->requestor)
1004 #define SELECTION_EVENT_SELECTION(eventp) \
1005 ((eventp)->selection)
1006 #define SELECTION_EVENT_TARGET(eventp) \
1008 #define SELECTION_EVENT_PROPERTY(eventp) \
1009 ((eventp)->property)
1010 #define SELECTION_EVENT_TIME(eventp) \
1015 extern void x_free_gcs (struct frame
*);
1016 extern void x_relative_mouse_position (struct frame
*, int *, int *);
1017 extern void x_real_pos_and_offsets (struct frame
*f
,
1019 int *right_offset_x
,
1021 int *bottom_offset_y
,
1030 XrmDatabase
x_load_resources (Display
*, const char *, const char *,
1033 /* Defined in xterm.c */
1035 typedef void (*x_special_error_handler
)(Display
*, XErrorEvent
*, char *,
1038 extern bool x_text_icon (struct frame
*, const char *);
1039 extern void x_catch_errors (Display
*);
1040 extern void x_catch_errors_with_handler (Display
*, x_special_error_handler
,
1042 extern void x_check_errors (Display
*, const char *)
1043 ATTRIBUTE_FORMAT_PRINTF (2, 0);
1044 extern bool x_had_errors_p (Display
*);
1045 extern void x_uncatch_errors (void);
1046 extern void x_uncatch_errors_after_check (void);
1047 extern void x_clear_errors (Display
*);
1048 extern void xembed_request_focus (struct frame
*);
1049 extern void x_ewmh_activate_frame (struct frame
*);
1050 extern void x_delete_terminal (struct terminal
*terminal
);
1051 extern unsigned long x_copy_color (struct frame
*, unsigned long);
1052 #ifdef USE_X_TOOLKIT
1053 extern XtAppContext Xt_app_con
;
1054 extern void x_activate_timeout_atimer (void);
1057 extern bool x_alloc_lighter_color_for_widget (Widget
, Display
*, Colormap
,
1061 extern bool x_alloc_nearest_color (struct frame
*, Colormap
, XColor
*);
1062 extern void x_query_color (struct frame
*f
, XColor
*);
1063 extern void x_clear_area (struct frame
*f
, int, int, int, int);
1064 #if !defined USE_X_TOOLKIT && !defined USE_GTK
1065 extern void x_mouse_leave (struct x_display_info
*);
1068 #if defined USE_X_TOOLKIT || defined USE_MOTIF
1069 extern int x_dispatch_event (XEvent
*, Display
*);
1071 extern int x_x_to_emacs_modifiers (struct x_display_info
*, int);
1073 extern cairo_t
*x_begin_cr_clip (struct frame
*, GC
);
1074 extern void x_end_cr_clip (struct frame
*);
1075 extern void x_set_cr_source_with_gc_foreground (struct frame
*, GC
);
1076 extern void x_set_cr_source_with_gc_background (struct frame
*, GC
);
1077 extern void x_cr_draw_frame (cairo_t
*, struct frame
*);
1078 extern Lisp_Object
x_cr_export_frames (Lisp_Object
, cairo_surface_type_t
);
1082 x_display_pixel_height (struct x_display_info
*dpyinfo
)
1084 return HeightOfScreen (dpyinfo
->screen
);
1088 x_display_pixel_width (struct x_display_info
*dpyinfo
)
1090 return WidthOfScreen (dpyinfo
->screen
);
1094 x_display_set_last_user_time (struct x_display_info
*dpyinfo
, Time t
)
1096 #ifdef ENABLE_CHECKING
1097 eassert (t
<= X_ULONG_MAX
);
1099 dpyinfo
->last_user_time
= t
;
1102 INLINE
unsigned long
1103 x_make_truecolor_pixel (struct x_display_info
*dpyinfo
, int r
, int g
, int b
)
1105 unsigned long pr
, pg
, pb
;
1107 /* Scale down RGB values to the visual's bits per RGB, and shift
1108 them to the right position in the pixel color. Note that the
1109 original RGB values are 16-bit values, as usual in X. */
1110 pr
= (r
>> (16 - dpyinfo
->red_bits
)) << dpyinfo
->red_offset
;
1111 pg
= (g
>> (16 - dpyinfo
->green_bits
)) << dpyinfo
->green_offset
;
1112 pb
= (b
>> (16 - dpyinfo
->blue_bits
)) << dpyinfo
->blue_offset
;
1114 /* Assemble the pixel color. */
1115 return pr
| pg
| pb
;
1118 /* If display has an immutable color map, freeing colors is not
1119 necessary and some servers don't allow it, so we won't do it. That
1120 also allows us to make other optimizations relating to server-side
1121 reference counts. */
1123 x_mutable_colormap (Visual
*visual
)
1125 int class = visual
->class;
1126 return (class != StaticColor
&& class != StaticGray
&& class != TrueColor
);
1129 extern void x_set_sticky (struct frame
*, Lisp_Object
, Lisp_Object
);
1130 extern bool x_wm_supports (struct frame
*, Atom
);
1131 extern void x_wait_for_event (struct frame
*, int);
1132 extern void x_clear_under_internal_border (struct frame
*f
);
1134 /* Defined in xselect.c. */
1136 extern void x_handle_property_notify (const XPropertyEvent
*);
1137 extern void x_handle_selection_notify (const XSelectionEvent
*);
1138 extern void x_handle_selection_event (struct selection_input_event
*);
1139 extern void x_clear_frame_selections (struct frame
*);
1141 extern void x_send_client_event (Lisp_Object display
,
1146 Lisp_Object values
);
1148 extern bool x_handle_dnd_message (struct frame
*,
1149 const XClientMessageEvent
*,
1150 struct x_display_info
*,
1151 struct input_event
*);
1152 extern int x_check_property_data (Lisp_Object
);
1153 extern void x_fill_property_data (Display
*,
1157 extern Lisp_Object
x_property_data_to_lisp (struct frame
*,
1158 const unsigned char *,
1162 extern void x_clipboard_manager_save_frame (Lisp_Object
);
1163 extern void x_clipboard_manager_save_all (void);
1166 extern bool xg_set_icon (struct frame
*, Lisp_Object
);
1167 extern bool xg_set_icon_from_xpm_data (struct frame
*, const char **);
1168 #endif /* USE_GTK */
1170 extern void xic_free_xfontset (struct frame
*);
1171 extern void create_frame_xic (struct frame
*);
1172 extern void destroy_frame_xic (struct frame
*);
1173 extern void xic_set_preeditarea (struct window
*, int, int);
1174 extern void xic_set_statusarea (struct frame
*);
1175 extern void xic_set_xfontset (struct frame
*, const char *);
1176 extern bool x_defined_color (struct frame
*, const char *, XColor
*, bool);
1178 extern void free_frame_xic (struct frame
*);
1179 # if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
1180 extern char *xic_create_fontsetname (const char *, bool);
1184 /* Defined in xfaces.c */
1186 #ifdef USE_X_TOOLKIT
1187 extern void x_free_dpy_colors (Display
*, Screen
*, Colormap
,
1188 unsigned long *, int);
1189 #endif /* USE_X_TOOLKIT */
1191 /* Defined in xmenu.c */
1193 #if defined USE_X_TOOLKIT || defined USE_GTK
1194 extern Lisp_Object
xw_popup_dialog (struct frame
*, Lisp_Object
, Lisp_Object
);
1197 #if defined USE_GTK || defined USE_MOTIF
1198 extern void x_menu_set_in_use (bool);
1200 extern void x_menu_wait_for_event (void *data
);
1201 extern void initialize_frame_menubar (struct frame
*);
1203 /* Defined in xsmfns.c */
1205 extern void x_session_initialize (struct x_display_info
*dpyinfo
);
1206 extern bool x_session_have_connection (void);
1207 extern void x_session_close (void);
1211 /* Is the frame embedded into another application? */
1213 #define FRAME_X_EMBEDDED_P(f) (FRAME_X_OUTPUT(f)->explicit_parent != 0)
1215 #define STORE_XCHAR2B(chp, b1, b2) \
1216 ((chp)->byte1 = (b1), (chp)->byte2 = (b2))
1218 #define XCHAR2B_BYTE1(chp) \
1221 #define XCHAR2B_BYTE2(chp) \
1224 #define STORE_NATIVE_RECT(nr,rx,ry,rwidth,rheight) \
1227 (nr).width = (rwidth), \
1228 (nr).height = (rheight))
1232 #endif /* XTERM_H */