root/src/xterm.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. SELECTION_EVENT_DISPLAY
  2. x_make_truecolor_pixel
  3. x_mutable_colormap

     1 /* Definitions and headers for communication with X protocol.
     2    Copyright (C) 1989, 1993-1994, 1998-2023 Free Software Foundation,
     3    Inc.
     4 
     5 This file is part of GNU Emacs.
     6 
     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.
    11 
    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.
    16 
    17 You should have received a copy of the GNU General Public License
    18 along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
    19 
    20 #ifndef XTERM_H
    21 #define XTERM_H
    22 
    23 #include <X11/Xlib.h>
    24 
    25 #ifdef HAVE_XFIXES
    26 #include <X11/extensions/Xfixes.h>
    27 
    28 #if defined HAVE_XINPUT2 && XFIXES_MAJOR < 5
    29 /* XI2 headers need PointerBarrier, which is not defined in old
    30    versions of the fixes library.  Define that type here.  */
    31 typedef XID PointerBarrier;
    32 #endif
    33 #if defined HAVE_XCOMPOSITE && XFIXES_MAJOR < 2
    34 /* Recent Composite headers need XserverRegion, which is not defined
    35    in old versions of the fixes library.  Define that type here.  */
    36 typedef XID XserverRegion;
    37 #endif
    38 #endif
    39 
    40 #include <X11/cursorfont.h>
    41 
    42 /* Include Xutil.h after keysym.h to work around a bug that prevents
    43    correct recognition of AltGr key in some X versions.  */
    44 
    45 #include <X11/keysym.h>
    46 #include <X11/Xutil.h>
    47 
    48 #include <X11/Xatom.h>
    49 #include <X11/Xresource.h>
    50 
    51 #ifdef HAVE_XINPUT2
    52 #include <X11/extensions/XInput2.h>
    53 #endif
    54 
    55 #ifdef USE_X_TOOLKIT
    56 #include <X11/StringDefs.h>
    57 #include <X11/IntrinsicP.h>     /* CoreP.h needs this */
    58 #include <X11/CoreP.h>          /* foul, but we need this to use our own
    59                                    window inside a widget instead of one
    60                                    that Xt creates... */
    61 #ifdef X_TOOLKIT_EDITRES
    62 #include <X11/Xmu/Editres.h>
    63 #endif
    64 
    65 typedef Widget xt_or_gtk_widget;
    66 #endif
    67 
    68 #ifdef USE_GTK
    69 #include <gtk/gtk.h>
    70 #include <gdk/gdkx.h>
    71 #endif /* USE_GTK */
    72 
    73 #ifndef USE_GTK
    74 #define GTK_CHECK_VERSION(i, j, k) false
    75 #endif
    76 
    77 #ifdef HAVE_XRENDER
    78 #include <X11/extensions/Xrender.h>
    79 #endif
    80 
    81 #ifdef USE_GTK
    82 /* Some definitions to reduce conditionals.  */
    83 typedef GtkWidget *xt_or_gtk_widget;
    84 #undef XSync
    85 /* gdk_window_process_all_updates is deprecated in GDK 3.22.  */
    86 #if GTK_CHECK_VERSION (3, 22, 0)
    87 #define XSync(d, b) do { XSync ((d), (b)); } while (false)
    88 #else
    89 #define XSync(d, b) do { gdk_window_process_all_updates (); \
    90                          XSync (d, b);  } while (false)
    91 #endif
    92 #endif /* USE_GTK */
    93 
    94 /* Number of "failable requests" to store.  */
    95 #define N_FAILABLE_REQUESTS 128
    96 
    97 #ifdef USE_CAIRO
    98 #include <cairo-xlib.h>
    99 #ifdef CAIRO_HAS_PDF_SURFACE
   100 #include <cairo-pdf.h>
   101 #endif
   102 #ifdef CAIRO_HAS_PS_SURFACE
   103 #include <cairo-ps.h>
   104 #endif
   105 #ifdef CAIRO_HAS_SVG_SURFACE
   106 #include <cairo-svg.h>
   107 #endif
   108 #ifdef USE_CAIRO_XCB
   109 #include <cairo-xcb.h>
   110 #endif
   111 #endif
   112 
   113 #ifdef HAVE_X_I18N
   114 #include <X11/Xlocale.h>
   115 #endif
   116 
   117 #ifdef USE_XCB
   118 #include <X11/Xlib-xcb.h>
   119 #endif
   120 
   121 #ifdef HAVE_XKB
   122 #include <X11/XKBlib.h>
   123 #endif
   124 
   125 #ifdef HAVE_XSYNC
   126 #include <X11/extensions/sync.h>
   127 #endif
   128 
   129 #include "dispextern.h"
   130 #include "termhooks.h"
   131 
   132 INLINE_HEADER_BEGIN
   133 
   134 /* Black and white pixel values for the screen which frame F is on.  */
   135 #define BLACK_PIX_DEFAULT(f)                                    \
   136   BlackPixel (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f))
   137 #define WHITE_PIX_DEFAULT(f)                                    \
   138   WhitePixel (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f))
   139 
   140 /* The mask of events that text windows always want to receive.  This
   141    includes mouse movement events, since handling the mouse-font text property
   142    means that we must track mouse motion all the time.  */
   143 
   144 #define STANDARD_EVENT_SET      \
   145   (KeyPressMask                 \
   146    | ExposureMask               \
   147    | ButtonPressMask            \
   148    | ButtonReleaseMask          \
   149    | PointerMotionMask          \
   150    | StructureNotifyMask        \
   151    | FocusChangeMask            \
   152    | LeaveWindowMask            \
   153    | EnterWindowMask            \
   154    | PropertyChangeMask         \
   155    | VisibilityChangeMask)
   156 
   157 #ifdef HAVE_X11R6_XIM
   158 /* Data structure passed to xim_instantiate_callback.  */
   159 struct xim_inst_t
   160 {
   161   struct x_display_info *dpyinfo;
   162   char *resource_name;
   163 };
   164 #endif /* HAVE_X11R6_XIM */
   165 
   166 #ifdef HAVE_XINPUT2
   167 #if HAVE_XISCROLLCLASSINFO_TYPE && defined XIScrollClass
   168 #define HAVE_XINPUT2_1
   169 #endif
   170 #if HAVE_XITOUCHCLASSINFO_TYPE && defined XITouchClass
   171 #define HAVE_XINPUT2_2
   172 #endif
   173 #if HAVE_XIBARRIERRELEASEPOINTERINFO_DEVICEID && defined XIBarrierPointerReleased
   174 #define HAVE_XINPUT2_3
   175 #endif
   176 #if HAVE_XIGESTURECLASSINFO_TYPE && defined XIGestureClass
   177 #define HAVE_XINPUT2_4
   178 #endif
   179 #endif
   180 
   181 /* Structure recording X pixmap and reference count.
   182    If REFCOUNT is 0 then this record is free to be reused.  */
   183 
   184 struct x_bitmap_record
   185 {
   186 #ifdef USE_CAIRO
   187   cairo_pattern_t *stipple;
   188 #endif
   189   Pixmap pixmap;
   190   bool have_mask;
   191   Pixmap mask;
   192   char *file;
   193   int refcount;
   194   /* Record some info about this pixmap.  */
   195   int height, width, depth;
   196 };
   197 
   198 #if defined USE_CAIRO || defined HAVE_XRENDER
   199 struct x_gc_ext_data
   200 {
   201 #define MAX_CLIP_RECTS 2
   202   /* Number of clipping rectangles.  */
   203   int n_clip_rects;
   204 
   205   /* Clipping rectangles.  */
   206   XRectangle clip_rects[MAX_CLIP_RECTS];
   207 };
   208 #endif
   209 
   210 #ifdef USE_CAIRO
   211 extern cairo_pattern_t *x_bitmap_stipple (struct frame *, Pixmap);
   212 #endif
   213 
   214 
   215 struct color_name_cache_entry
   216 {
   217   struct color_name_cache_entry *next;
   218 
   219   /* The color values of the cached color entry.  */
   220   XColor rgb;
   221 
   222   /* The name of the cached color.  */
   223   char *name;
   224 
   225   /* Whether or not RGB is valid (i.e. the color actually exists).  */
   226   bool_bf valid : 1;
   227 };
   228 
   229 #ifdef HAVE_XINPUT2
   230 
   231 #ifdef HAVE_XINPUT2_1
   232 
   233 struct xi_scroll_valuator_t
   234 {
   235   /* The ID of the valuator.  */
   236   int number;
   237 
   238   /* Whether or not it represents X axis movement.  */
   239   bool_bf horizontal : 1;
   240 
   241   /* Whether or not the value is currently invalid.  */
   242   bool_bf invalid_p : 1;
   243 
   244   /* The current value.  */
   245   double current_value;
   246 
   247   /* Value used to tally up deltas until a threshold is met.  */
   248   double emacs_value;
   249 
   250   /* The scroll increment.  */
   251   double increment;
   252 };
   253 
   254 #endif
   255 
   256 #ifdef HAVE_XINPUT2_2
   257 
   258 /* Enum describing the ownership of a touch point.
   259 
   260    The input extension allows other clients to intercept touch
   261    sequences destined for a client window through passively grabbing
   262    for touch events on a parent window.
   263 
   264    When a passive touch grab for an XI_TouchBegin event activates, one
   265    grabbing client is designated the ``owner'' of the touch sequence
   266    started by the grabbed event.  Touch events are then delivered to
   267    both the grabbing client and other clients that have selected for
   268    touch events on the subwindow.
   269 
   270    The X server will not deliver TouchEnd events to clients other than
   271    the owner until one grabbing client decides to take over processing
   272    the touch event sequence, or no more grabbing clients remain.
   273    Instead, a TouchUpdate event with the TouchPendingEnd flag is sent,
   274    and the TouchEnd event is postponed until the decision is made and
   275    all XI_TouchOwnership events are sent.
   276 
   277    If the owner decides to take over processing the touch sequence, an
   278    XI_TouchEnd event is delivered to all other clients receiving
   279    events for the current touch sequence, who are then expected to
   280    cancel or undo any actions which have taken place in reaction to
   281    events from that sequence.
   282 
   283    If the owner decides to relinquish ownership over the touch
   284    sequence, the X server looks for another grabbing client, and
   285    transfers touch ownership to that client instead.  Nothing changes
   286    from the perspective of clients who have merely selected for events
   287    from the subwindow, while an XI_TouchEnd event is delivered to the
   288    old owner, and an XI_TouchOwnership event is delivered to the new
   289    owner.
   290 
   291    If all grabbing clients reject ownership over the touch sequence,
   292    the X server delivers an XI_TouchOwnership event to the client that
   293    has selected for touch events on the subwindow, the only client
   294    that will receive events for this touch sequence from this time
   295    forward.  */
   296 
   297 enum xi_touch_ownership
   298   {
   299     /* Emacs doesn't own this touch sequence.  */
   300     TOUCH_OWNERSHIP_NONE,
   301 
   302     /* Emacs owns this touch sequence.  */
   303     TOUCH_OWNERSHIP_SELF,
   304   };
   305 
   306 struct xi_touch_point_t
   307 {
   308   /* The touchpoint detail.  */
   309   int number;
   310 
   311   /* Whether or not Emacs has ``exclusive'' access to this touch
   312      point.  */
   313   enum xi_touch_ownership ownership;
   314 
   315   /* The last known rounded X and Y positions of the touchpoint.  */
   316   int x, y;
   317 
   318   /* The frame associated with this touch point.  */
   319   struct frame *frame;
   320 
   321   /* The next touch point in this list.  */
   322   struct xi_touch_point_t *next;
   323 };
   324 
   325 #endif
   326 
   327 struct xi_device_t
   328 {
   329   /* The numerical ID of this device.  */
   330   int device_id;
   331 
   332 #ifdef HAVE_XINPUT2_1
   333   /* The number of scroll valuators in `valuators'.  */
   334   int scroll_valuator_count;
   335 #endif
   336 
   337   /* Whether or not the device is grabbed and its use.  */
   338   int grab, use;
   339 
   340   /* The attached device.  Only valid if USE is some kind of master
   341      device.  */
   342   int attachment;
   343 
   344 #ifdef HAVE_XINPUT2_2
   345   /* Whether or not this device is a direct touch device.  */
   346   bool direct_p;
   347 #endif
   348 
   349 #ifdef HAVE_XINPUT2_1
   350   /* An array of scroll valuators Emacs knows about.  */
   351   struct xi_scroll_valuator_t *valuators;
   352 #endif
   353 
   354 #ifdef HAVE_XINPUT2_2
   355   /* An array of in-progress touchscreen events.  */
   356   struct xi_touch_point_t *touchpoints;
   357 #endif
   358 
   359   /* The name of this device.  */
   360   Lisp_Object name;
   361 
   362   /* The time at which `focus_frame' became the keyboard focus (only
   363      applies to master devices).  */
   364   Time focus_frame_time;
   365 
   366   /* The frame that is currently this device's keyboard focus, or
   367      NULL.  */
   368   struct frame *focus_frame;
   369 
   370   /* The time at which `focus_frame' became the implicit keyboard
   371      focus.  */
   372   Time focus_implicit_time;
   373 
   374   /* The frame that is currently this device's implicit keyboard
   375      focus, or NULL.  */
   376   struct frame *focus_implicit_frame;
   377 
   378   /* The window on which the last motion event happened.  */
   379   Window last_motion_window;
   380 
   381   /* The rounded integer coordinates of the last motion event.  */
   382   int last_motion_x, last_motion_y;
   383 };
   384 #endif
   385 
   386 extern Status x_parse_color (struct frame *, const char *, XColor *);
   387 
   388 struct x_failable_request
   389 {
   390   /* The first request making up this sequence.  */
   391   unsigned long start;
   392 
   393   /* If this is zero, then the request has not yet been made.
   394      Otherwise, this is the request that ends this sequence.  */
   395   unsigned long end;
   396 
   397   /* Any selection event serial associated with this error trap.  */
   398   unsigned int selection_serial;
   399 };
   400 
   401 #ifdef HAVE_XFIXES
   402 
   403 struct x_monitored_selection
   404 {
   405   /* The name of the selection.  */
   406   Atom name;
   407 
   408   /* The current owner of the selection.  */
   409   Window owner;
   410 };
   411 
   412 /* An invalid window.  */
   413 #define X_INVALID_WINDOW 0xffffffff
   414 
   415 #endif
   416 
   417 
   418 /* For each X display, we have a structure that records
   419    information about it.  */
   420 
   421 struct x_display_info
   422 {
   423   /* Chain of all x_display_info structures.  */
   424   struct x_display_info *next;
   425 
   426   /* The generic display parameters corresponding to this X display. */
   427   struct terminal *terminal;
   428 
   429   /* This says how to access this display in Xlib.  */
   430   Display *display;
   431 
   432   /* A connection number (file descriptor) for the display.  */
   433   int connection;
   434 
   435   /* This is a cons cell of the form (NAME . FONT-LIST-CACHE).  */
   436   Lisp_Object name_list_element;
   437 
   438   /* Number of frames that are on this display.  */
   439   int reference_count;
   440 
   441   /* True if this display connection cannot communicate with the
   442      window manager because it is not trusted by the X server.  */
   443   bool untrusted;
   444 
   445   /* The Screen this connection is connected to.  */
   446   Screen *screen;
   447 
   448   /* Dots per inch of the screen.  */
   449   double resx, resy;
   450 
   451   /* The Visual being used for this display.  */
   452   Visual *visual;
   453 
   454   /* The visual information corresponding to VISUAL.  */
   455   XVisualInfo visual_info;
   456 
   457 #ifdef HAVE_XRENDER
   458   /* The picture format for this display.  */
   459   XRenderPictFormat *pict_format;
   460 #endif
   461 
   462   /* The colormap being used.  */
   463   Colormap cmap;
   464 
   465   /* Number of planes on this screen.  */
   466   int n_planes;
   467 
   468   /* Mask of things that cause the mouse to be grabbed.  */
   469   int grabbed;
   470 
   471   /* Emacs bitmap-id of the default icon bitmap for this frame.
   472      Or -1 if none has been allocated yet.  */
   473   ptrdiff_t icon_bitmap_id;
   474 
   475   /* The root window of this screen.  */
   476   Window root_window;
   477 
   478   /* Client leader window.  */
   479   Window client_leader_window;
   480 
   481   /* The cursor to use for vertical scroll bars.  */
   482   Cursor vertical_scroll_bar_cursor;
   483 
   484   /* The cursor to use for horizontal scroll bars.  */
   485   Cursor horizontal_scroll_bar_cursor;
   486 
   487   /* The invisible cursor used for pointer blanking.
   488      Unused if this display supports Xfixes extension.  */
   489   Cursor invisible_cursor;
   490 
   491 #if defined HAVE_XFIXES && XFIXES_VERSION >= 40000
   492   /* Whether or not to use Xfixes for pointer blanking.  */
   493   bool fixes_pointer_blanking;
   494 #endif
   495 
   496 #ifdef USE_GTK
   497   /* The GDK cursor for scroll bars and popup menus.  */
   498   GdkCursor *xg_cursor;
   499 #endif
   500 
   501   /* X Resource data base */
   502   XrmDatabase rdb;
   503 
   504   /* Minimum width over all characters in all fonts in font_table.  */
   505   int smallest_char_width;
   506 
   507   /* Minimum font height over all fonts in font_table.  */
   508   int smallest_font_height;
   509 
   510   /* Reusable Graphics Context for drawing a cursor in a non-default face. */
   511   GC scratch_cursor_gc;
   512 
   513   /* Information about the range of text currently shown in
   514      mouse-face.  */
   515   Mouse_HLInfo mouse_highlight;
   516 
   517   /* Logical identifier of this display.  */
   518   unsigned x_id;
   519 
   520   /* Default name for all frames on this display.  */
   521   char *x_id_name;
   522 
   523   /* The number of fonts opened for this display.  */
   524   int n_fonts;
   525 
   526   /* Pointer to bitmap records.  */
   527   struct x_bitmap_record *bitmaps;
   528 
   529   /* Allocated size of bitmaps field.  */
   530   ptrdiff_t bitmaps_size;
   531 
   532   /* Last used bitmap index.  */
   533   ptrdiff_t bitmaps_last;
   534 
   535   /* Which modifier keys are on which modifier bits?
   536 
   537      With each keystroke, X returns eight bits indicating which modifier
   538      keys were held down when the key was pressed.  The interpretation
   539      of the top five modifier bits depends on what keys are attached
   540      to them.  If the Meta_L and Meta_R keysyms are on mod5, then mod5
   541      is the meta bit.
   542 
   543      meta_mod_mask is a mask containing the bits used for the meta key.
   544      It may have more than one bit set, if more than one modifier bit
   545      has meta keys on it.  Basically, if EVENT is a KeyPress event,
   546      the meta key is pressed if (EVENT.state & meta_mod_mask) != 0.
   547 
   548      shift_lock_mask is LockMask if the XK_Shift_Lock keysym is on the
   549      lock modifier bit, or zero otherwise.  Non-alphabetic keys should
   550      only be affected by the lock modifier bit if XK_Shift_Lock is in
   551      use; XK_Caps_Lock should only affect alphabetic keys.  With this
   552      arrangement, the lock modifier should shift the character if
   553      (EVENT.state & shift_lock_mask) != 0.  */
   554   unsigned int meta_mod_mask, shift_lock_mask;
   555 
   556   /* These are like meta_mod_mask, but for different modifiers.  */
   557   unsigned alt_mod_mask, super_mod_mask, hyper_mod_mask;
   558 
   559   /* Communication with window managers.  */
   560   Atom Xatom_wm_protocols;
   561 
   562   /* Kinds of protocol things we may receive.  */
   563   Atom Xatom_wm_take_focus;
   564   Atom Xatom_wm_save_yourself;
   565   Atom Xatom_wm_delete_window;
   566 
   567   /* Atom for indicating window state to the window manager.  */
   568   Atom Xatom_wm_change_state;
   569   Atom Xatom_wm_state;
   570 
   571   /* Other WM communication */
   572   Atom Xatom_wm_configure_denied; /* When our config request is denied */
   573   Atom Xatom_wm_window_moved;     /* When the WM moves us.  */
   574   Atom Xatom_wm_client_leader;    /* Id of client leader window.  */
   575   Atom Xatom_wm_transient_for;    /* Id of whatever window we are
   576                                      transient for. */
   577 
   578   /* EditRes protocol */
   579   Atom Xatom_editres;
   580 
   581   /* More atoms, which are selection types.  */
   582   Atom Xatom_CLIPBOARD, Xatom_TIMESTAMP, Xatom_TEXT, Xatom_DELETE,
   583     Xatom_COMPOUND_TEXT, Xatom_UTF8_STRING,
   584     Xatom_MULTIPLE, Xatom_INCR, Xatom_EMACS_TMP, Xatom_TARGETS, Xatom_NULL,
   585     Xatom_ATOM, Xatom_ATOM_PAIR, Xatom_CLIPBOARD_MANAGER,
   586     Xatom_EMACS_SERVER_TIME_PROP;
   587 
   588   /* More atoms for font properties.  The last three are private
   589      properties, see the comments in src/fontset.h.  */
   590   Atom Xatom_PIXEL_SIZE, Xatom_AVERAGE_WIDTH,
   591     Xatom_MULE_BASELINE_OFFSET, Xatom_MULE_RELATIVE_COMPOSE,
   592     Xatom_MULE_DEFAULT_ASCENT;
   593 
   594   /* More atoms for Ghostscript support.  */
   595   Atom Xatom_DONE, Xatom_PAGE;
   596 
   597   /* Atoms used in toolkit scroll bar client messages.  */
   598   Atom Xatom_Scrollbar, Xatom_Horizontal_Scrollbar;
   599 
   600   /* Atom used in XEmbed client messages.  */
   601   Atom Xatom_XEMBED, Xatom_XEMBED_INFO;
   602 
   603   /* Atom used to determine whether or not the screen is composited.  */
   604   Atom Xatom_NET_WM_CM_Sn;
   605 
   606   /* Atoms used by the Motif drag and drop protocols.  */
   607   Atom Xatom_MOTIF_WM_HINTS, Xatom_MOTIF_DRAG_WINDOW,
   608     Xatom_MOTIF_DRAG_TARGETS, Xatom_MOTIF_DRAG_AND_DROP_MESSAGE,
   609     Xatom_MOTIF_DRAG_INITIATOR_INFO, Xatom_MOTIF_DRAG_RECEIVER_INFO;
   610 
   611   /* Atoms used by Emacs internally.  */
   612   Atom Xatom_EMACS_DRAG_ATOM;
   613 
   614   /* Special selections used by the Motif drop protocol to indicate
   615      success or failure.  */
   616   Atom Xatom_XmTRANSFER_SUCCESS, Xatom_XmTRANSFER_FAILURE;
   617 
   618   /* Atoms used by both versions of the OffiX DND protocol (the "old
   619      KDE" protocol in x-dnd.el). */
   620   Atom Xatom_DndProtocol, Xatom_DND_PROTOCOL;
   621 
   622   /* Atoms to make x_intern_cached_atom fast.  */
   623   Atom Xatom_text_plain_charset_utf_8, Xatom_LENGTH, Xatom_FILE_NAME,
   624     Xatom_CHARACTER_POSITION, Xatom_LINE_NUMBER, Xatom_COLUMN_NUMBER,
   625     Xatom_OWNER_OS, Xatom_HOST_NAME, Xatom_USER, Xatom_CLASS,
   626     Xatom_NAME, Xatom_SAVE_TARGETS;
   627 
   628   /* The frame (if any) which has the X window that has keyboard focus.
   629      Zero if none.  This is examined by Ffocus_frame in xfns.c.  Note
   630      that a mere EnterNotify event can set this; if you need to know the
   631      last frame specified in a FocusIn or FocusOut event, use
   632      x_focus_event_frame.  */
   633   struct frame *x_focus_frame;
   634 
   635   /* The last frame mentioned in a FocusIn or FocusOut event.  This is
   636      separate from x_focus_frame, because whether or not LeaveNotify
   637      events cause us to lose focus depends on whether or not we have
   638      received a FocusIn event for it.
   639 
   640      This field is not used when the input extension is being
   641      utilized.  */
   642   struct frame *x_focus_event_frame;
   643 
   644   /* The frame which currently has the visual highlight, and should get
   645      keyboard input (other sorts of input have the frame encoded in the
   646      event).  It points to the X focus frame's selected window's
   647      frame.  It differs from x_focus_frame when we're using a global
   648      minibuffer.  */
   649   struct frame *highlight_frame;
   650 
   651   /* The frame waiting to be auto-raised in XTread_socket.  */
   652   struct frame *x_pending_autoraise_frame;
   653 
   654   /* The frame where the mouse was last time we reported a ButtonPress event.  */
   655   struct frame *last_mouse_frame;
   656 
   657   /* The frame where the mouse was last time we reported a mouse position.  */
   658   struct frame *last_mouse_glyph_frame;
   659 
   660   /* The frame where the mouse was last time we reported a mouse motion.  */
   661   struct frame *last_mouse_motion_frame;
   662 
   663   /* The scroll bar in which the last X motion event occurred.  */
   664   struct scroll_bar *last_mouse_scroll_bar;
   665 
   666   /* Time of last user interaction as returned in X events on this
   667      display.  */
   668   Time last_user_time;
   669 
   670   /* Position where the mouse was last time we reported a motion.
   671      This is a position on last_mouse_motion_frame.  It is used in
   672      some situations to report the mouse position as well: see
   673      XTmouse_position.  */
   674   int last_mouse_motion_x;
   675   int last_mouse_motion_y;
   676 
   677   /* Where the mouse was last time we reported a mouse position.
   678      This is a rectangle on last_mouse_glyph_frame.  */
   679   XRectangle last_mouse_glyph;
   680 
   681   /* Time of last mouse movement on this display.  This is a hack because
   682      we would really prefer that XTmouse_position would return the time
   683      associated with the position it returns, but there doesn't seem to be
   684      any way to wrest the time-stamp from the server along with the position
   685      query.  So, we just keep track of the time of the last movement we
   686      received, and return that in hopes that it's somewhat accurate.  */
   687   Time last_mouse_movement_time;
   688 
   689   /* Whether or not the last mouse motion was synthetic.  */
   690   bool last_mouse_movement_time_send_event;
   691 
   692   /* The gray pixmap.  */
   693   Pixmap gray;
   694 
   695 #ifdef HAVE_X_I18N
   696   /* XIM (X Input method).  */
   697   XIM xim;
   698   XIMStyles *xim_styles;
   699   struct xim_inst_t *xim_callback_data;
   700   XIMStyle preferred_xim_style;
   701 
   702   /* The named coding system to use for this input method.  */
   703   Lisp_Object xim_coding;
   704 
   705   /* Whether or not X input methods should be used on this
   706      display.  */
   707   bool use_xim;
   708 #endif /* HAVE_X_I18N */
   709 
   710   /* A cache mapping color names to RGB values.  */
   711   struct color_name_cache_entry **color_names;
   712 
   713   /* The number of buckets for each hash in that hash table.  */
   714   ptrdiff_t *color_names_length;
   715 
   716   /* The size of that hash table.  */
   717   int color_names_size;
   718 
   719   /* If non-null, a cache of the colors in the color map.  Don't
   720      use this directly, call x_color_cells instead.  */
   721   XColor *color_cells;
   722   int ncolor_cells;
   723 
   724   /* Bits and shifts to use to compose pixel values on TrueColor visuals.  */
   725   int red_bits, blue_bits, green_bits, alpha_bits;
   726   int red_offset, blue_offset, green_offset, alpha_offset;
   727   unsigned long alpha_mask;
   728 
   729   /* The type of window manager we have.  If we move FRAME_OUTER_WINDOW
   730      to x/y 0/0, some window managers (type A) puts the window manager
   731      decorations outside the screen and FRAME_OUTER_WINDOW exactly at 0/0.
   732      Other window managers (type B) puts the window including decorations
   733      at 0/0, so FRAME_OUTER_WINDOW is a bit below 0/0.
   734      Record the type of WM in use so we can compensate for type A WMs.  */
   735   enum
   736     {
   737       X_WMTYPE_UNKNOWN,
   738       X_WMTYPE_A,
   739       X_WMTYPE_B
   740     } wm_type;
   741 
   742 
   743   /* Atoms that are drag and drop atoms */
   744   Atom *x_dnd_atoms;
   745   ptrdiff_t x_dnd_atoms_size;
   746   ptrdiff_t x_dnd_atoms_length;
   747 
   748   /* The unique drag and drop atom used on Motif.  None if it was not
   749      already computed.  */
   750   Atom motif_drag_atom;
   751 
   752   /* Its name.  */
   753   char motif_drag_atom_name[sizeof "_EMACS_ATOM_%lu" - 3
   754                             + INT_STRLEN_BOUND (unsigned long)];
   755 
   756   /* When it was owned.  */
   757   Time motif_drag_atom_time;
   758 
   759   /* The frame that currently owns `motif_drag_atom'.  */
   760   struct frame *motif_drag_atom_owner;
   761 
   762   /* The drag window for this display.  */
   763   Window motif_drag_window;
   764 
   765   /* Extended window manager hints, Atoms supported by the window manager and
   766      atoms for setting the window type.  */
   767   Atom Xatom_net_supported, Xatom_net_supporting_wm_check;
   768   Atom *net_supported_atoms;
   769   int nr_net_supported_atoms;
   770   Window net_supported_window;
   771   Atom Xatom_net_window_type, Xatom_net_window_type_tooltip;
   772   Atom Xatom_net_active_window;
   773 
   774   /* Atoms dealing with EWMH (i.e. _NET_...) */
   775   Atom Xatom_net_wm_state, Xatom_net_wm_state_fullscreen,
   776     Xatom_net_wm_state_maximized_horz, Xatom_net_wm_state_maximized_vert,
   777     Xatom_net_wm_state_sticky, Xatom_net_wm_state_above, Xatom_net_wm_state_below,
   778     Xatom_net_wm_state_hidden, Xatom_net_wm_state_skip_taskbar,
   779     Xatom_net_wm_state_shaded, Xatom_net_frame_extents, Xatom_net_current_desktop,
   780     Xatom_net_workarea, Xatom_net_wm_opaque_region, Xatom_net_wm_ping,
   781     Xatom_net_wm_sync_request, Xatom_net_wm_sync_request_counter,
   782     Xatom_net_wm_sync_fences, Xatom_net_wm_frame_drawn, Xatom_net_wm_frame_timings,
   783     Xatom_net_wm_user_time, Xatom_net_wm_user_time_window,
   784     Xatom_net_client_list_stacking, Xatom_net_wm_pid,
   785     Xatom_net_wm_bypass_compositor;
   786 
   787   /* XSettings atoms and windows.  */
   788   Atom Xatom_xsettings_sel, Xatom_xsettings_prop, Xatom_xsettings_mgr;
   789   Window xsettings_window;
   790 
   791   /* Frame name and icon name */
   792   Atom Xatom_net_wm_name, Xatom_net_wm_icon_name;
   793   /* Frame opacity */
   794   Atom Xatom_net_wm_window_opacity;
   795 
   796   /* SM */
   797   Atom Xatom_SM_CLIENT_ID;
   798 
   799   /* DND source.  */
   800   Atom Xatom_XdndAware, Xatom_XdndSelection, Xatom_XdndTypeList,
   801     Xatom_XdndActionCopy, Xatom_XdndActionMove, Xatom_XdndActionLink,
   802     Xatom_XdndActionAsk, Xatom_XdndActionPrivate, Xatom_XdndActionList,
   803     Xatom_XdndActionDescription, Xatom_XdndProxy, Xatom_XdndEnter,
   804     Xatom_XdndPosition, Xatom_XdndStatus, Xatom_XdndLeave, Xatom_XdndDrop,
   805     Xatom_XdndFinished;
   806 
   807   /* XDS source and target.  */
   808   Atom Xatom_XdndDirectSave0, Xatom_XdndActionDirectSave, Xatom_text_plain;
   809 
   810 #ifdef HAVE_XKB
   811   /* Virtual modifiers */
   812   Atom Xatom_Meta, Xatom_Super, Xatom_Hyper, Xatom_ShiftLock, Xatom_Alt;
   813 #endif
   814 
   815   /* Core modifier map when XKB is not present.  */
   816   XModifierKeymap *modmap;
   817 
   818 #ifdef HAVE_XRANDR
   819   bool xrandr_supported_p;
   820   int xrandr_event_base;
   821   int xrandr_error_base;
   822   int xrandr_major_version;
   823   int xrandr_minor_version;
   824 #endif
   825 
   826 #if defined HAVE_XRANDR || defined USE_GTK
   827   /* This is used to determine if the monitor configuration really
   828      changed upon receiving a monitor change event.  */
   829   Lisp_Object last_monitor_attributes_list;
   830 #endif
   831 
   832 #if defined USE_CAIRO || defined HAVE_XRENDER
   833   XExtCodes *ext_codes;
   834 #endif
   835 
   836 #ifdef USE_XCB
   837   xcb_connection_t *xcb_connection;
   838   xcb_visualtype_t *xcb_visual;
   839 #endif
   840 
   841 #ifdef HAVE_XDBE
   842   bool supports_xdbe;
   843 #endif
   844 
   845 #ifdef HAVE_XINPUT2
   846   bool supports_xi2;
   847 
   848   /* The minor version of the input extension.  (Major is always
   849      2.x.) */
   850   int xi2_version;
   851 
   852   /* The generic event opcode of XI2 events.  */
   853   int xi2_opcode;
   854 
   855   /* The number of devices on this display known to Emacs.  */
   856   int num_devices;
   857 
   858   /* Array of all input extension devices on this display known to
   859      Emacs.  */
   860   struct xi_device_t *devices;
   861 
   862   /* Pending keystroke time.  */
   863   Time pending_keystroke_time;
   864 
   865   /* Pending keystroke source.  If a core KeyPress event arrives with
   866      the same timestamp as pending_keystroke_time, it will be treated
   867      as originating from this device.  */
   868   int pending_keystroke_source;
   869 
   870 #if defined USE_GTK && !defined HAVE_GTK3
   871   /* This means the two variables above shouldn't be reset the first
   872      time a KeyPress event arrives, since they were set from a raw key
   873      press event that was sent before the first (real, not sent by an
   874      input method) core key event.  */
   875   bool pending_keystroke_time_special_p;
   876 #endif
   877 
   878   /* The client pointer.  We keep a record client-side to avoid
   879      calling XISetClientPointer all the time.  */
   880   int client_pointer_device;
   881 #endif
   882 
   883 #ifdef HAVE_XKB
   884   bool supports_xkb;
   885   int xkb_event_type;
   886   XkbDescPtr xkb_desc;
   887 #endif
   888 
   889 #ifdef USE_GTK
   890   bool prefer_native_input;
   891 #endif
   892 
   893 #ifdef HAVE_XRENDER
   894   bool xrender_supported_p;
   895   int xrender_major;
   896   int xrender_minor;
   897 #endif
   898 
   899 #ifdef HAVE_XFIXES
   900   bool xfixes_supported_p;
   901   int xfixes_major;
   902   int xfixes_minor;
   903   int xfixes_event_base;
   904 #endif
   905 
   906 #ifdef HAVE_XSYNC
   907   bool xsync_supported_p;
   908   int xsync_major;
   909   int xsync_minor;
   910 #endif
   911 
   912 #ifdef HAVE_XINERAMA
   913   bool xinerama_supported_p;
   914 #endif
   915 
   916 #ifdef HAVE_XCOMPOSITE
   917   bool composite_supported_p;
   918   int composite_major;
   919   int composite_minor;
   920 #endif
   921 
   922 #ifdef HAVE_XSHAPE
   923   bool xshape_supported_p;
   924   int xshape_major;
   925   int xshape_minor;
   926   int xshape_event_base;
   927   int xshape_error_base;
   928 #endif
   929 
   930 #ifdef USE_TOOLKIT_SCROLL_BARS
   931   Lisp_Object *protected_windows;
   932   int n_protected_windows;
   933   int protected_windows_max;
   934 #endif
   935 
   936   /* The current dimensions of the screen.  This is updated when a
   937      ConfigureNotify is received for the root window, and is zero if
   938      that didn't happen.  */
   939   int screen_width;
   940   int screen_height;
   941 
   942   /* The mm width and height of the screen.  Updated on
   943      RRScreenChangeNotify.  */
   944   int screen_mm_width;
   945   int screen_mm_height;
   946 
   947   /* Circular buffer of request serial ranges to ignore inside an
   948      error handler in increasing order.  */
   949   struct x_failable_request failable_requests[N_FAILABLE_REQUESTS];
   950 
   951   /* Pointer to the next request in `failable_requests'.  */
   952   struct x_failable_request *next_failable_request;
   953 
   954 #ifdef HAVE_XFIXES
   955   /* Array of selections being monitored and their owners.  */
   956   struct x_monitored_selection *monitored_selections;
   957 
   958   /* Window used to monitor those selections.  */
   959   Window selection_tracking_window;
   960 
   961   /* The number of those selections.  */
   962   int n_monitored_selections;
   963 #endif
   964 
   965   /* The pending drag-and-drop time for middle-click based
   966      drag-and-drop emulation.  */
   967   Time pending_dnd_time;
   968 
   969 #if defined HAVE_XSYNC && !defined USE_GTK && defined HAVE_CLOCK_GETTIME
   970   /* Whether or not the server time is probably the same as
   971      "clock_gettime (CLOCK_MONOTONIC, ...)".  */
   972   bool server_time_monotonic_p;
   973 
   974   /* The time difference between the X server clock and the monotonic
   975      clock, or 0 if unknown (if the difference is legitimately 0,
   976      server_time_monotonic_p will be true).  */
   977   int_fast64_t server_time_offset;
   978 #endif
   979 
   980   /* Keysym that will cause Emacs to quit if pressed twice within 150
   981      ms.  */
   982   KeySym quit_keysym;
   983 
   984   /* The last time that keysym was pressed.  */
   985   Time quit_keysym_time;
   986 };
   987 
   988 #ifdef HAVE_XINPUT2
   989 /* Defined in xmenu.c. */
   990 extern int popup_activated_flag;
   991 #endif
   992 
   993 /* This is a chain of structures for all the X displays currently in use.  */
   994 extern struct x_display_info *x_display_list;
   995 
   996 extern struct x_display_info *x_display_info_for_display (Display *);
   997 extern struct frame *x_top_window_to_frame (struct x_display_info *, int);
   998 extern struct x_display_info *x_term_init (Lisp_Object, char *, char *);
   999 extern bool x_display_ok (const char *);
  1000 
  1001 extern void select_visual (struct x_display_info *);
  1002 
  1003 extern Window tip_window;
  1004 extern Lisp_Object tip_dx;
  1005 extern Lisp_Object tip_dy;
  1006 extern Lisp_Object tip_frame;
  1007 
  1008 /* Each X frame object points to its own struct x_output object
  1009    in the output_data.x field.  The x_output structure contains
  1010    the information that is specific to X windows.  */
  1011 
  1012 struct x_output
  1013 {
  1014 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
  1015   /* Height of menu bar widget, in pixels.  This value
  1016      is not meaningful if the menubar is turned off.  */
  1017   int menubar_height;
  1018 #endif
  1019 
  1020   /* Height of tool bar widget, in pixels.  top_height is used if tool bar
  1021      at top, bottom_height if tool bar is at the bottom.
  1022      Zero if not using an external tool bar or if tool bar is vertical.  */
  1023   int toolbar_top_height, toolbar_bottom_height;
  1024 
  1025   /* Width of tool bar widget, in pixels.  left_width is used if tool bar
  1026      at left, right_width if tool bar is at the right.
  1027      Zero if not using an external tool bar or if tool bar is horizontal.  */
  1028   int toolbar_left_width, toolbar_right_width;
  1029 
  1030   /* The tiled border used when the mouse is out of the frame.  */
  1031   Pixmap border_tile;
  1032 
  1033   /* Here are the Graphics Contexts for the default font.  */
  1034   GC normal_gc;                         /* Normal video */
  1035   GC reverse_gc;                        /* Reverse video */
  1036   GC cursor_gc;                         /* cursor drawing */
  1037 
  1038   /* The X window used for this frame.
  1039      May be zero while the frame object is being created
  1040      and the X window has not yet been created.  */
  1041   Window window_desc;
  1042 
  1043   /* The drawable to which we're rendering.  In the single-buffered
  1044      base, the window itself.  In the double-buffered case, the
  1045      window's back buffer.  */
  1046   Drawable draw_desc;
  1047 
  1048 #ifdef HAVE_XRENDER
  1049   /* The Xrender picture that corresponds to this drawable.  None
  1050      means no picture format was found, or the Xrender extension is
  1051      not present.  */
  1052   Picture picture;
  1053 #endif
  1054 
  1055   /* The X window used for the bitmap icon;
  1056      or 0 if we don't have a bitmap icon.  */
  1057   Window icon_desc;
  1058 
  1059   /* The X window that is the parent of this X window.
  1060      Usually this is a window that was made by the window manager,
  1061      but it can be the root window, and it can be explicitly specified
  1062      (see the explicit_parent field, below).  */
  1063   Window parent_desc;
  1064 
  1065 #ifdef USE_X_TOOLKIT
  1066   /* The widget of this screen.  This is the window of a "shell" widget.  */
  1067   Widget widget;
  1068   /* The XmPanedWindows...  */
  1069   Widget column_widget;
  1070   /* The widget of the edit portion of this screen; the window in
  1071      "window_desc" is inside of this.  */
  1072   Widget edit_widget;
  1073 
  1074   Widget menubar_widget;
  1075 #endif
  1076 
  1077 #ifndef USE_GTK
  1078   /* A window used to store the user time property.  May be None or
  1079      the frame's outer window.  */
  1080   Window user_time_window;
  1081 #endif
  1082 
  1083 #ifdef USE_GTK
  1084   /* The widget of this screen.  This is the window of a top widget.  */
  1085   GtkWidget *widget;
  1086   /* The widget of the edit portion of this screen; the window in
  1087      "window_desc" is inside of this.  */
  1088   GtkWidget *edit_widget;
  1089   /* The widget used for laying out widgets vertically.  */
  1090   GtkWidget *vbox_widget;
  1091   /* The widget used for laying out widgets horizontally.  */
  1092   GtkWidget *hbox_widget;
  1093   /* The menubar in this frame.  */
  1094   GtkWidget *menubar_widget;
  1095   /* The tool bar in this frame  */
  1096   GtkWidget *toolbar_widget;
  1097   /* True if tool bar is packed into the hbox widget (i.e. vertical).  */
  1098   bool_bf toolbar_in_hbox : 1;
  1099   bool_bf toolbar_is_packed : 1;
  1100 
  1101   /* The last size hints set.  */
  1102   GdkGeometry size_hints;
  1103   long hint_flags;
  1104 
  1105   GtkTooltip *ttip_widget;
  1106   GtkWidget *ttip_lbl;
  1107   GtkWindow *ttip_window;
  1108 
  1109   GtkIMContext *im_context;
  1110 
  1111 #ifdef HAVE_GTK3
  1112   /* The CSS providers used for scroll bar foreground and background
  1113      colors.  */
  1114   GtkCssProvider *scrollbar_foreground_css_provider;
  1115   GtkCssProvider *scrollbar_background_css_provider;
  1116 #endif
  1117 #endif /* USE_GTK */
  1118 
  1119   /* If >=0, a bitmap index.  The indicated bitmap is used for the
  1120      icon. */
  1121   ptrdiff_t icon_bitmap;
  1122 
  1123   /* Default ASCII font of this frame.  */
  1124   struct font *font;
  1125 
  1126   /* The baseline offset of the default ASCII font.  */
  1127   int baseline_offset;
  1128 
  1129   /* If a fontset is specified for this frame instead of font, this
  1130      value contains an ID of the fontset, else -1.  */
  1131   int fontset;
  1132 
  1133   unsigned long cursor_pixel;
  1134   unsigned long border_pixel;
  1135   unsigned long mouse_pixel;
  1136   unsigned long cursor_foreground_pixel;
  1137 
  1138   /* Foreground color for scroll bars.  A value of -1 means use the
  1139      default (black for non-toolkit scroll bars).  */
  1140   unsigned long scroll_bar_foreground_pixel;
  1141 
  1142   /* Background color for scroll bars.  A value of -1 means use the
  1143      default (background color of the frame for non-toolkit scroll
  1144      bars).  */
  1145   unsigned long scroll_bar_background_pixel;
  1146 
  1147 #if defined (USE_LUCID) && defined (USE_TOOLKIT_SCROLL_BARS)
  1148   /* Top and bottom shadow colors for 3D Lucid scrollbars.
  1149      -1 means let the scroll compute them itself.  */
  1150   unsigned long scroll_bar_top_shadow_pixel;
  1151   unsigned long scroll_bar_bottom_shadow_pixel;
  1152 #endif
  1153 
  1154   /* Descriptor for the cursor in use for this window.  */
  1155   Cursor text_cursor;
  1156   Cursor nontext_cursor;
  1157   Cursor modeline_cursor;
  1158   Cursor hand_cursor;
  1159   Cursor hourglass_cursor;
  1160   Cursor horizontal_drag_cursor;
  1161   Cursor vertical_drag_cursor;
  1162   Cursor current_cursor;
  1163   Cursor left_edge_cursor;
  1164   Cursor top_left_corner_cursor;
  1165   Cursor top_edge_cursor;
  1166   Cursor top_right_corner_cursor;
  1167   Cursor right_edge_cursor;
  1168   Cursor bottom_right_corner_cursor;
  1169   Cursor bottom_edge_cursor;
  1170   Cursor bottom_left_corner_cursor;
  1171 
  1172   /* Window whose cursor is hourglass_cursor.  This window is temporarily
  1173      mapped to display an hourglass cursor.  */
  1174   Window hourglass_window;
  1175 
  1176   /* These are the current window manager hints.  It seems that
  1177      XSetWMHints, when presented with an unset bit in the `flags'
  1178      member of the hints structure, does not leave the corresponding
  1179      attribute unchanged; rather, it resets that attribute to its
  1180      default value.  For example, unless you set the `icon_pixmap'
  1181      field and the `IconPixmapHint' bit, XSetWMHints will forget what
  1182      your icon pixmap was.  This is rather troublesome, since some of
  1183      the members (for example, `input' and `icon_pixmap') want to stay
  1184      the same throughout the execution of Emacs.  So, we keep this
  1185      structure around, just leaving values in it and adding new bits
  1186      to the mask as we go.  */
  1187   XWMHints wm_hints;
  1188 
  1189   /* This is the Emacs structure for the X display this frame is on.  */
  1190   struct x_display_info *display_info;
  1191 
  1192   /* This is a button event that wants to activate the menubar.
  1193      We save it here until the command loop gets to think about it.  */
  1194   XEvent *saved_menu_event;
  1195 
  1196   /* This is the widget id used for this frame's menubar in lwlib.  */
  1197 #ifdef USE_X_TOOLKIT
  1198   int id;
  1199 #endif
  1200 
  1201   /* True means hourglass cursor is currently displayed.  */
  1202   bool_bf hourglass_p : 1;
  1203 
  1204   /* True means our parent is another application's window
  1205      and was explicitly specified.  */
  1206   bool_bf explicit_parent : 1;
  1207 
  1208   /* True means tried already to make this frame visible.  */
  1209   bool_bf asked_for_visible : 1;
  1210 
  1211   /* True if this frame was ever previously visible.  */
  1212   bool_bf has_been_visible : 1;
  1213 
  1214   /* Xt waits for a ConfigureNotify event from the window manager in
  1215      EmacsFrameSetCharSize when the shell widget is resized.  For some
  1216      window managers like fvwm2 2.2.5 and KDE 2.1 this event doesn't
  1217      arrive for an unknown reason and Emacs hangs in Xt.  If this is
  1218      false, tell Xt not to wait.  */
  1219   bool_bf wait_for_wm : 1;
  1220 
  1221   /* True if this frame's alpha value is the same for both the active
  1222      and inactive states.  */
  1223   bool_bf alpha_identical_p : 1;
  1224 
  1225 #ifdef HAVE_XDBE
  1226   /* Flag that indicates whether we've modified the back buffer and
  1227      need to publish our modifications to the front buffer at a
  1228      convenient time.  */
  1229   bool_bf need_buffer_flip : 1;
  1230 
  1231   /* Flag that indicates whether or not the frame contents are
  1232      complete and can be safely flushed while handling async
  1233      input.  */
  1234   bool_bf complete : 1;
  1235 #endif
  1236 
  1237 #ifdef HAVE_X_I18N
  1238   /* Input context (currently, this means Compose key handler setup).  */
  1239   XIC xic;
  1240   XIMStyle xic_style;
  1241   XFontSet xic_xfs;
  1242 #endif
  1243 
  1244 #ifdef HAVE_XSYNC
  1245   /* The "basic frame counter" used for resize synchronization.  */
  1246   XSyncCounter basic_frame_counter;
  1247 
  1248   /* The "extended frame counter" used for frame synchronization.  */
  1249   XSyncCounter extended_frame_counter;
  1250 
  1251   /* The pending value of the basic counter.  */
  1252   XSyncValue pending_basic_counter_value;
  1253 
  1254   /* The current value of the extended counter.  */
  1255   XSyncValue current_extended_counter_value;
  1256 
  1257   /* The configure event value of the extended counter.  */
  1258   XSyncValue resize_counter_value;
  1259 
  1260   /* Whether or not basic resize synchronization is in progress.  */
  1261   bool_bf sync_end_pending_p : 1;
  1262 
  1263   /* Whether or not extended resize synchronization is in
  1264      progress.  */
  1265   bool_bf ext_sync_end_pending_p : 1;
  1266 
  1267 #ifdef HAVE_GTK3
  1268   /* Whether or not GDK resize synchronization is in progress.  */
  1269   bool_bf xg_sync_end_pending_p : 1;
  1270 #endif
  1271 
  1272   /* Whether or Emacs is waiting for the compositing manager to draw a
  1273      frame.  */
  1274   bool_bf waiting_for_frame_p : 1;
  1275 
  1276   /* Whether or not Emacs just skipped waiting for a frame due to a
  1277      timeout.  */
  1278   bool_bf draw_just_hung_p : 1;
  1279 
  1280 #if !defined USE_GTK && defined HAVE_CLOCK_GETTIME
  1281   /* Whether or not Emacs should wait for the compositing manager to
  1282      draw frames before starting a new frame.  */
  1283   bool_bf use_vsync_p : 1;
  1284 
  1285   /* The time (in microseconds) it took to draw the last frame.  */
  1286   uint_fast64_t last_frame_time;
  1287 
  1288   /* A temporary time used to calculate that value.  */
  1289   uint_fast64_t temp_frame_time;
  1290 
  1291 #ifdef HAVE_XSYNCTRIGGERFENCE
  1292   /* An array of two sync fences that are triggered in order after a
  1293      frame completes.  Not initialized if the XSync extension is too
  1294      old to support sync fences.  */
  1295   XSyncFence sync_fences[2];
  1296 #endif
  1297 #endif
  1298 #endif
  1299 
  1300   /* Relief GCs, colors etc.  */
  1301   struct relief
  1302   {
  1303     GC gc;
  1304     unsigned long pixel;
  1305   }
  1306   black_relief, white_relief;
  1307 
  1308   /* The background for which the above relief GCs were set up.
  1309      They are changed only when a different background is involved.  */
  1310   unsigned long relief_background;
  1311 
  1312   /* Keep track of focus.  May be EXPLICIT if we received a FocusIn for this
  1313      frame, or IMPLICIT if we received an EnterNotify.
  1314      FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT.
  1315 
  1316      Not used when the input extension is being utilized.  */
  1317   int focus_state;
  1318 
  1319   /* The offset we need to add to compensate for type A WMs.  */
  1320   int move_offset_top;
  1321   int move_offset_left;
  1322 
  1323 /* Extreme 'short' and 'long' values suitable for libX11.  */
  1324 #define X_SHRT_MAX 0x7fff
  1325 #define X_SHRT_MIN (-1 - X_SHRT_MAX)
  1326 #define X_LONG_MAX 0x7fffffff
  1327 #define X_LONG_MIN (-1 - X_LONG_MAX)
  1328 #define X_ULONG_MAX 0xffffffffUL
  1329 
  1330 #ifdef USE_CAIRO
  1331   /* Cairo drawing context.  */
  1332   cairo_t *cr_context;
  1333   /* Width and height reported by the last ConfigureNotify event.
  1334      They are used when creating the cairo surface next time.  */
  1335   int cr_surface_desired_width, cr_surface_desired_height;
  1336 #endif
  1337 
  1338 #ifdef HAVE_X_I18N
  1339   ptrdiff_t preedit_size;
  1340   char *preedit_chars;
  1341   bool preedit_active;
  1342   int preedit_caret;
  1343 #endif
  1344 
  1345 #ifdef HAVE_XINPUT2
  1346   XIEventMask *xi_masks;
  1347   int num_xi_masks;
  1348 #endif
  1349 
  1350   /* Whether or not we are certain we know the offset from the root
  1351      window to this frame.  */
  1352   bool window_offset_certain_p;
  1353 
  1354   /* The offset of the edit window from the root window.  This is
  1355      strictly an optimization to avoid extraneous synchronizing in
  1356      some cases.  */
  1357   int root_x, root_y;
  1358 
  1359   /* The frame visibility state.  This starts out
  1360      VisibilityFullyObscured, but is set to something else in
  1361      handle_one_xevent.  */
  1362   int visibility_state;
  1363 
  1364 #ifdef HAVE_XINPUT2_2
  1365   /* The touch ID of the last touch point to have touched the tool
  1366      bar.  */
  1367   int tool_bar_touch_id;
  1368 
  1369   /* The device that last touched the tool bar.  0 if no device
  1370      touched the tool bar.  */
  1371   int tool_bar_touch_device;
  1372 #endif
  1373 };
  1374 
  1375 enum
  1376 {
  1377   /* Values for focus_state, used as bit mask.
  1378      EXPLICIT means we received a FocusIn for the frame and know it has
  1379      the focus.  IMPLICIT means we received an EnterNotify and the frame
  1380      may have the focus if no window manager is running.
  1381      FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
  1382   FOCUS_NONE     = 0,
  1383   FOCUS_IMPLICIT = 1,
  1384   FOCUS_EXPLICIT = 2
  1385 };
  1386 
  1387 /* Return the X output data for frame F.  */
  1388 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
  1389 #define FRAME_OUTPUT_DATA(f) FRAME_X_OUTPUT (f)
  1390 
  1391 /* Return the X window used for displaying data in frame F.  */
  1392 #define FRAME_X_WINDOW(f) ((f)->output_data.x->window_desc)
  1393 #define FRAME_NATIVE_WINDOW(f) FRAME_X_WINDOW (f)
  1394 
  1395 /* Return the drawable used for rendering to frame F.  */
  1396 #define FRAME_X_RAW_DRAWABLE(f) ((f)->output_data.x->draw_desc)
  1397 
  1398 extern void x_mark_frame_dirty (struct frame *f);
  1399 
  1400 /* Return the drawable used for rendering to frame F and mark the
  1401    frame as needing a buffer flip later.  There's no easy way to run
  1402    code after any drawing command, but we can run code whenever
  1403    someone asks for the handle necessary to draw.  */
  1404 #define FRAME_X_DRAWABLE(f)                             \
  1405   (x_mark_frame_dirty ((f)), FRAME_X_RAW_DRAWABLE ((f)))
  1406 
  1407 #ifdef HAVE_XDBE
  1408 #define FRAME_X_DOUBLE_BUFFERED_P(f)            \
  1409   (FRAME_X_WINDOW (f) != FRAME_X_RAW_DRAWABLE (f))
  1410 
  1411 /* Return the need-buffer-flip flag for frame F.  */
  1412 #define FRAME_X_NEED_BUFFER_FLIP(f) ((f)->output_data.x->need_buffer_flip)
  1413 
  1414 /* Return whether or not the frame F has been completely drawn.  Used
  1415    while handling async input.  */
  1416 #define FRAME_X_COMPLETE_P(f) ((f)->output_data.x->complete)
  1417 #endif
  1418 
  1419 /* Return the outermost X window associated with the frame F.  */
  1420 #ifdef USE_X_TOOLKIT
  1421 #define FRAME_OUTER_WINDOW(f) ((f)->output_data.x->widget ?             \
  1422                                XtWindow ((f)->output_data.x->widget) :  \
  1423                                FRAME_X_WINDOW (f))
  1424 #else
  1425 #ifdef USE_GTK
  1426 
  1427 #ifdef HAVE_GTK3
  1428 #define DEFAULT_GDK_DISPLAY() \
  1429   gdk_x11_display_get_xdisplay (gdk_display_get_default ())
  1430 #else
  1431 #undef GDK_WINDOW_XID
  1432 #define GDK_WINDOW_XID(w) GDK_WINDOW_XWINDOW (w)
  1433 #define DEFAULT_GDK_DISPLAY() GDK_DISPLAY ()
  1434 #define gtk_widget_get_preferred_size(a, ign, b) \
  1435   gtk_widget_size_request (a, b)
  1436 #endif
  1437 
  1438 #define GTK_WIDGET_TO_X_WIN(w) \
  1439   ((w) && gtk_widget_get_window (w) \
  1440    ? GDK_WINDOW_XID (gtk_widget_get_window (w)) : 0)
  1441 
  1442 #define FRAME_GTK_OUTER_WIDGET(f) ((f)->output_data.x->widget)
  1443 #define FRAME_GTK_WIDGET(f) ((f)->output_data.x->edit_widget)
  1444 #define FRAME_OUTER_WINDOW(f)                                   \
  1445        (FRAME_GTK_OUTER_WIDGET (f) ?                            \
  1446         GTK_WIDGET_TO_X_WIN (FRAME_GTK_OUTER_WIDGET (f)) :      \
  1447          FRAME_X_WINDOW (f))
  1448 
  1449 #else /* !USE_GTK */
  1450 #define FRAME_OUTER_WINDOW(f) (FRAME_X_WINDOW (f))
  1451 #endif /* !USE_GTK */
  1452 #endif
  1453 
  1454 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
  1455 #define FRAME_MENUBAR_HEIGHT(f) ((f)->output_data.x->menubar_height)
  1456 #else
  1457 #define FRAME_MENUBAR_HEIGHT(f) ((void) f, 0)
  1458 #endif /* USE_X_TOOLKIT || USE_GTK */
  1459 
  1460 #define FRAME_FONT(f) ((f)->output_data.x->font)
  1461 #define FRAME_FONTSET(f) ((f)->output_data.x->fontset)
  1462 #define FRAME_TOOLBAR_TOP_HEIGHT(f) ((f)->output_data.x->toolbar_top_height)
  1463 #define FRAME_TOOLBAR_BOTTOM_HEIGHT(f) \
  1464   ((f)->output_data.x->toolbar_bottom_height)
  1465 #define FRAME_TOOLBAR_HEIGHT(f) \
  1466   (FRAME_TOOLBAR_TOP_HEIGHT (f) + FRAME_TOOLBAR_BOTTOM_HEIGHT (f))
  1467 #define FRAME_TOOLBAR_LEFT_WIDTH(f) ((f)->output_data.x->toolbar_left_width)
  1468 #define FRAME_TOOLBAR_RIGHT_WIDTH(f) ((f)->output_data.x->toolbar_right_width)
  1469 #define FRAME_TOOLBAR_WIDTH(f) \
  1470   (FRAME_TOOLBAR_LEFT_WIDTH (f) + FRAME_TOOLBAR_RIGHT_WIDTH (f))
  1471 #define FRAME_BASELINE_OFFSET(f) ((f)->output_data.x->baseline_offset)
  1472 
  1473 /* This gives the x_display_info structure for the display F is on.  */
  1474 #define FRAME_DISPLAY_INFO(f) ((f)->output_data.x->display_info)
  1475 
  1476 /* This is the `Display *' which frame F is on.  */
  1477 #define FRAME_X_DISPLAY(f) (FRAME_DISPLAY_INFO (f)->display)
  1478 
  1479 /* This is the `Screen *' which frame F is on.  */
  1480 #define FRAME_X_SCREEN(f) (FRAME_DISPLAY_INFO (f)->screen)
  1481 
  1482 /* This is the screen index number of screen which frame F is on.  */
  1483 #define FRAME_X_SCREEN_NUMBER(f) XScreenNumberOfScreen (FRAME_X_SCREEN (f))
  1484 
  1485 /* This is the Visual which frame F is on.  */
  1486 #define FRAME_X_VISUAL(f) FRAME_DISPLAY_INFO (f)->visual
  1487 
  1488 /* And its corresponding visual info.  */
  1489 #define FRAME_X_VISUAL_INFO(f) (&FRAME_DISPLAY_INFO (f)->visual_info)
  1490 
  1491 /* Whether or not the frame is visible.  Do not test this alone.
  1492    Instead, use FRAME_REDISPLAY_P.  */
  1493 #define FRAME_X_VISIBLE(f) (FRAME_X_OUTPUT (f)->visibility_state        \
  1494                             != VisibilityFullyObscured)
  1495 
  1496 #ifdef HAVE_XRENDER
  1497 #define FRAME_X_PICTURE_FORMAT(f) FRAME_DISPLAY_INFO (f)->pict_format
  1498 #define FRAME_X_PICTURE(f) ((f)->output_data.x->picture)
  1499 #define FRAME_CHECK_XR_VERSION(f, major, minor)                 \
  1500   (FRAME_DISPLAY_INFO (f)->xrender_supported_p                  \
  1501    && ((FRAME_DISPLAY_INFO (f)->xrender_major == (major)        \
  1502         && FRAME_DISPLAY_INFO (f)->xrender_minor >= (minor))    \
  1503        || (FRAME_DISPLAY_INFO (f)->xrender_major > (major))))
  1504 #endif
  1505 
  1506 #ifdef HAVE_XSYNC
  1507 #define FRAME_X_BASIC_COUNTER(f)                \
  1508   FRAME_X_OUTPUT (f)->basic_frame_counter
  1509 #define FRAME_X_EXTENDED_COUNTER(f)             \
  1510   FRAME_X_OUTPUT (f)->extended_frame_counter
  1511 #define FRAME_X_WAITING_FOR_DRAW(f)             \
  1512   FRAME_X_OUTPUT (f)->waiting_for_frame_p
  1513 #define FRAME_X_DRAW_JUST_HUNG(f)               \
  1514   FRAME_X_OUTPUT (f)->draw_just_hung_p
  1515 #define FRAME_X_COUNTER_VALUE(f)                \
  1516   FRAME_X_OUTPUT (f)->current_extended_counter_value
  1517 #endif
  1518 
  1519 /* This is the Colormap which frame F uses.  */
  1520 #define FRAME_X_COLORMAP(f) FRAME_DISPLAY_INFO (f)->cmap
  1521 
  1522 #define FRAME_XIC(f) ((f)->output_data.x->xic)
  1523 #define FRAME_X_XIM(f) (FRAME_DISPLAY_INFO (f)->xim)
  1524 #define FRAME_X_XIM_STYLES(f) (FRAME_DISPLAY_INFO (f)->xim_styles)
  1525 #define FRAME_XIC_STYLE(f) ((f)->output_data.x->xic_style)
  1526 #define FRAME_XIC_FONTSET(f) ((f)->output_data.x->xic_xfs)
  1527 #define FRAME_X_XIM_CODING(f)                           \
  1528   (SYMBOLP (Vx_input_coding_system)                     \
  1529    ? Vx_input_coding_system                             \
  1530    : (!NILP (FRAME_DISPLAY_INFO (f)->xim_coding)        \
  1531       ? FRAME_DISPLAY_INFO(f)->xim_coding               \
  1532       : Vlocale_coding_system))
  1533 
  1534 /* X-specific scroll bar stuff.  */
  1535 
  1536 /* We represent scroll bars as lisp vectors.  This allows us to place
  1537    references to them in windows without worrying about whether we'll
  1538    end up with windows referring to dead scroll bars; the garbage
  1539    collector will free it when its time comes.
  1540 
  1541    We use struct scroll_bar as a template for accessing fields of the
  1542    vector.  */
  1543 
  1544 struct scroll_bar
  1545 {
  1546   /* These fields are shared by all vectors.  */
  1547   union vectorlike_header header;
  1548 
  1549   /* The window we're a scroll bar for.  */
  1550   Lisp_Object window;
  1551 
  1552   /* The next and previous in the chain of scroll bars in this frame.  */
  1553   Lisp_Object next, prev;
  1554 
  1555   /* Fields after 'prev' are not traced by the GC.  */
  1556 
  1557   /* The X window representing this scroll bar.  */
  1558   Window x_window;
  1559 
  1560   /* The position and size of the scroll bar in pixels, relative to the
  1561      frame.  */
  1562   int top, left, width, height;
  1563 
  1564   /* The starting and ending positions of the handle, relative to the
  1565      handle area (i.e. zero is the top position, not
  1566      SCROLL_BAR_TOP_BORDER).  If they're equal, that means the handle
  1567      hasn't been drawn yet.
  1568 
  1569      These are not actually the locations where the beginning and end
  1570      are drawn; in order to keep handles from becoming invisible when
  1571      editing large files, we establish a minimum height by always
  1572      drawing handle bottoms VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
  1573      where they would be normally; the bottom and top are in a
  1574      different coordinate system.  */
  1575   int start, end;
  1576 
  1577   /* If the scroll bar handle is currently being dragged by the user,
  1578      this is the number of pixels from the top of the handle to the
  1579      place where the user grabbed it.  If the handle isn't currently
  1580      being dragged, this is -1.  */
  1581   int dragging;
  1582 
  1583 #if defined (USE_TOOLKIT_SCROLL_BARS) && defined (USE_LUCID)
  1584   /* Last scroll bar part seen in xaw_jump_callback and xaw_scroll_callback.  */
  1585   enum scroll_bar_part last_seen_part;
  1586 #endif
  1587 
  1588 #if defined (USE_TOOLKIT_SCROLL_BARS) && !defined (USE_GTK)
  1589   /* Last value of whole for horizontal scrollbars.  */
  1590   int whole;
  1591 #endif
  1592 
  1593   /* True if the scroll bar is horizontal.  */
  1594   bool horizontal;
  1595 } GCALIGNED_STRUCT;
  1596 
  1597 /* Turning a lisp vector value into a pointer to a struct scroll_bar.  */
  1598 #define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec))
  1599 
  1600 #ifdef USE_X_TOOLKIT
  1601 
  1602 /* Extract the X widget of the scroll bar from a struct scroll_bar.
  1603    XtWindowToWidget should be fast enough since Xt uses a hash table
  1604    to map windows to widgets.  */
  1605 
  1606 #define SCROLL_BAR_X_WIDGET(dpy, ptr) \
  1607   XtWindowToWidget (dpy, ptr->x_window)
  1608 
  1609 /* Store a widget id in a struct scroll_bar.  */
  1610 
  1611 #define SET_SCROLL_BAR_X_WIDGET(ptr, w)         \
  1612   do {                                          \
  1613     Window window = XtWindow (w);               \
  1614     ptr->x_window = window;                     \
  1615   } while (false)
  1616 
  1617 #endif /* USE_X_TOOLKIT */
  1618 
  1619 /* Return the inside width of a vertical scroll bar, given the outside
  1620    width.  */
  1621 #define VERTICAL_SCROLL_BAR_INSIDE_WIDTH(f, width) \
  1622   ((width) \
  1623    - VERTICAL_SCROLL_BAR_LEFT_BORDER \
  1624    - VERTICAL_SCROLL_BAR_RIGHT_BORDER)
  1625 
  1626 /* Return the length of the rectangle within which the top of the
  1627    handle must stay.  This isn't equivalent to the inside height,
  1628    because the scroll bar handle has a minimum height.
  1629 
  1630    This is the real range of motion for the scroll bar, so when we're
  1631    scaling buffer positions to scroll bar positions, we use this, not
  1632    VERTICAL_SCROLL_BAR_INSIDE_HEIGHT.  */
  1633 #define VERTICAL_SCROLL_BAR_TOP_RANGE(f, height) \
  1634   (VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, height) - VERTICAL_SCROLL_BAR_MIN_HANDLE)
  1635 
  1636 /* Return the inside height of vertical scroll bar, given the outside
  1637    height.  See VERTICAL_SCROLL_BAR_TOP_RANGE too.  */
  1638 #define VERTICAL_SCROLL_BAR_INSIDE_HEIGHT(f, height) \
  1639   ((height) - VERTICAL_SCROLL_BAR_TOP_BORDER - VERTICAL_SCROLL_BAR_BOTTOM_BORDER)
  1640 
  1641 /* Return the inside height of a horizontal scroll bar, given the outside
  1642    height.  */
  1643 #define HORIZONTAL_SCROLL_BAR_INSIDE_HEIGHT(f, height)  \
  1644   ((height) \
  1645    - HORIZONTAL_SCROLL_BAR_TOP_BORDER \
  1646    - HORIZONTAL_SCROLL_BAR_BOTTOM_BORDER)
  1647 
  1648 /* Return the length of the rectangle within which the left part of the
  1649    handle must stay.  This isn't equivalent to the inside width, because
  1650    the scroll bar handle has a minimum width.
  1651 
  1652    This is the real range of motion for the scroll bar, so when we're
  1653    scaling buffer positions to scroll bar positions, we use this, not
  1654    HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH.  */
  1655 #define HORIZONTAL_SCROLL_BAR_LEFT_RANGE(f, width) \
  1656   (HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH (f, width) - HORIZONTAL_SCROLL_BAR_MIN_HANDLE)
  1657 
  1658 /* Return the inside width of horizontal scroll bar, given the outside
  1659    width.  See HORIZONTAL_SCROLL_BAR_LEFT_RANGE too.  */
  1660 #define HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH(f, width) \
  1661   ((width) - HORIZONTAL_SCROLL_BAR_LEFT_BORDER - HORIZONTAL_SCROLL_BAR_LEFT_BORDER)
  1662 
  1663 
  1664 /* Border widths for scroll bars.
  1665 
  1666    Scroll bar windows don't have any X borders; their border width is
  1667    set to zero, and we redraw borders ourselves.  This makes the code
  1668    a bit cleaner, since we don't have to convert between outside width
  1669    (used when relating to the rest of the screen) and inside width
  1670    (used when sizing and drawing the scroll bar window itself).
  1671 
  1672    The handle moves up and down/back and forth in a rectangle inset
  1673    from the edges of the scroll bar.  These are widths by which we
  1674    inset the handle boundaries from the scroll bar edges.  */
  1675 #define VERTICAL_SCROLL_BAR_LEFT_BORDER (2)
  1676 #define VERTICAL_SCROLL_BAR_RIGHT_BORDER (2)
  1677 #define VERTICAL_SCROLL_BAR_TOP_BORDER (2)
  1678 #define VERTICAL_SCROLL_BAR_BOTTOM_BORDER (2)
  1679 
  1680 #define HORIZONTAL_SCROLL_BAR_LEFT_BORDER (2)
  1681 #define HORIZONTAL_SCROLL_BAR_RIGHT_BORDER (2)
  1682 #define HORIZONTAL_SCROLL_BAR_TOP_BORDER (2)
  1683 #define HORIZONTAL_SCROLL_BAR_BOTTOM_BORDER (2)
  1684 
  1685 /* Minimum lengths for scroll bar handles, in pixels.  */
  1686 #define VERTICAL_SCROLL_BAR_MIN_HANDLE (5)
  1687 #define HORIZONTAL_SCROLL_BAR_MIN_HANDLE (5)
  1688 
  1689 /* If a struct input_event has a kind which is SELECTION_REQUEST_EVENT
  1690    or SELECTION_CLEAR_EVENT, then its contents are really described
  1691    by this structure.  */
  1692 
  1693 /* For an event of kind SELECTION_REQUEST_EVENT,
  1694    this structure really describes the contents.  */
  1695 
  1696 struct selection_input_event
  1697 {
  1698   ENUM_BF (event_kind) kind : EVENT_KIND_WIDTH;
  1699   struct x_display_info *dpyinfo;
  1700   /* We spell it with an "o" here because X does.  */
  1701   Window requestor;
  1702   Atom selection, target, property;
  1703   Time time;
  1704 };
  1705 
  1706 /* Unlike macros below, this can't be used as an lvalue.  */
  1707 INLINE Display *
  1708 SELECTION_EVENT_DISPLAY (struct selection_input_event *ev)
  1709 {
  1710   return ev->dpyinfo->display;
  1711 }
  1712 #define SELECTION_EVENT_DPYINFO(eventp) \
  1713   ((eventp)->dpyinfo)
  1714 /* We spell it with an "o" here because X does.  */
  1715 #define SELECTION_EVENT_REQUESTOR(eventp)       \
  1716   ((eventp)->requestor)
  1717 #define SELECTION_EVENT_SELECTION(eventp)       \
  1718   ((eventp)->selection)
  1719 #define SELECTION_EVENT_TARGET(eventp)  \
  1720   ((eventp)->target)
  1721 #define SELECTION_EVENT_PROPERTY(eventp)        \
  1722   ((eventp)->property)
  1723 #define SELECTION_EVENT_TIME(eventp)    \
  1724   ((eventp)->time)
  1725 
  1726 /* From xfns.c.  */
  1727 
  1728 extern void x_free_gcs (struct frame *);
  1729 extern void x_relative_mouse_position (struct frame *, int *, int *);
  1730 extern void x_real_pos_and_offsets (struct frame *, int *, int *, int *,
  1731                                     int *, int *, int *, int *, int *,
  1732                                     int *);
  1733 extern void x_default_font_parameter (struct frame *, Lisp_Object);
  1734 
  1735 /* From xrdb.c.  */
  1736 
  1737 extern XrmDatabase x_load_resources (Display *, const char *, const char *,
  1738                                      const char *);
  1739 extern const char *x_get_string_resource (void *, const char *, const char *);
  1740 
  1741 /* Defined in xterm.c */
  1742 
  1743 typedef void (*x_special_error_handler) (Display *, XErrorEvent *, char *,
  1744                                          void *);
  1745 
  1746 extern bool x_text_icon (struct frame *, const char *);
  1747 extern void x_catch_errors (Display *);
  1748 extern void x_catch_errors_with_handler (Display *, x_special_error_handler,
  1749                                          void *);
  1750 extern void x_catch_errors_for_lisp (struct x_display_info *);
  1751 extern void x_uncatch_errors_for_lisp (struct x_display_info *);
  1752 extern void x_check_errors_for_lisp (struct x_display_info *,
  1753                                      const char *)
  1754   ATTRIBUTE_FORMAT_PRINTF (2, 0);
  1755 extern void x_check_errors (Display *, const char *)
  1756   ATTRIBUTE_FORMAT_PRINTF (2, 0);
  1757 extern bool x_had_errors_p (Display *);
  1758 extern void x_unwind_errors_to (int);
  1759 extern void x_uncatch_errors (void);
  1760 extern void x_uncatch_errors_after_check (void);
  1761 extern void x_ignore_errors_for_next_request (struct x_display_info *,
  1762                                               unsigned int);
  1763 extern void x_stop_ignoring_errors (struct x_display_info *);
  1764 extern void x_clear_errors (Display *);
  1765 extern void x_set_window_size (struct frame *, bool, int, int);
  1766 extern void x_set_last_user_time_from_lisp (struct x_display_info *, Time);
  1767 extern void x_make_frame_visible (struct frame *);
  1768 extern void x_make_frame_invisible (struct frame *);
  1769 extern void x_iconify_frame (struct frame *);
  1770 extern void x_free_frame_resources (struct frame *);
  1771 extern void x_wm_set_size_hint (struct frame *, long, bool);
  1772 #if defined HAVE_XSYNCTRIGGERFENCE && !defined USE_GTK \
  1773   && defined HAVE_CLOCK_GETTIME
  1774 extern void x_sync_init_fences (struct frame *);
  1775 #endif
  1776 extern bool x_embed_frame (struct x_display_info *, struct frame *);
  1777 
  1778 extern void x_delete_terminal (struct terminal *);
  1779 extern Cursor x_create_font_cursor (struct x_display_info *, int);
  1780 extern unsigned long x_copy_color (struct frame *, unsigned long);
  1781 #ifdef USE_X_TOOLKIT
  1782 extern XtAppContext Xt_app_con;
  1783 extern void x_activate_timeout_atimer (void);
  1784 #endif
  1785 #ifdef USE_LUCID
  1786 extern bool x_alloc_lighter_color_for_widget (Widget, Display *, Colormap,
  1787                                               unsigned long *,
  1788                                               double, int);
  1789 #endif
  1790 extern bool x_alloc_nearest_color (struct frame *, Colormap, XColor *);
  1791 extern void x_query_colors (struct frame *f, XColor *, int);
  1792 extern void x_clear_area (struct frame *f, int, int, int, int);
  1793 #if (defined USE_LUCID && defined HAVE_XINPUT2) \
  1794   || (!defined USE_X_TOOLKIT && !defined USE_GTK)
  1795 extern void x_mouse_leave (struct x_display_info *);
  1796 #endif
  1797 extern void x_wait_for_cell_change (Lisp_Object, struct timespec);
  1798 
  1799 #ifndef USE_GTK
  1800 extern int x_dispatch_event (XEvent *, Display *);
  1801 #endif
  1802 extern int x_x_to_emacs_modifiers (struct x_display_info *, int);
  1803 extern int x_emacs_to_x_modifiers (struct x_display_info *, intmax_t);
  1804 #ifdef USE_CAIRO
  1805 extern void x_cr_destroy_frame_context (struct frame *);
  1806 extern void x_cr_update_surface_desired_size (struct frame *, int, int);
  1807 extern cairo_t *x_begin_cr_clip (struct frame *, GC);
  1808 extern void x_end_cr_clip (struct frame *);
  1809 extern void x_set_cr_source_with_gc_foreground (struct frame *, GC, bool);
  1810 extern void x_set_cr_source_with_gc_background (struct frame *, GC, bool);
  1811 extern void x_cr_draw_frame (cairo_t *, struct frame *);
  1812 extern Lisp_Object x_cr_export_frames (Lisp_Object, cairo_surface_type_t);
  1813 #endif
  1814 
  1815 #ifdef HAVE_XFIXES
  1816 extern Window x_find_selection_owner (struct x_display_info *, Atom);
  1817 #endif
  1818 
  1819 #ifdef HAVE_XRENDER
  1820 extern void x_xrender_color_from_gc_background (struct frame *, GC,
  1821                                                 XRenderColor *, bool);
  1822 extern void x_xr_ensure_picture (struct frame *);
  1823 extern void x_xr_apply_ext_clip (struct frame *, GC);
  1824 extern void x_xr_reset_ext_clip (struct frame *);
  1825 #endif
  1826 
  1827 extern void x_translate_coordinates (struct frame *, int, int, int *, int *);
  1828 extern void x_translate_coordinates_to_root (struct frame *, int, int,
  1829                                              int *, int *);
  1830 extern Lisp_Object x_handle_translate_coordinates (struct frame *, Lisp_Object,
  1831                                                    int, int);
  1832 
  1833 extern Bool x_query_pointer (Display *, Window, Window *, Window *, int *,
  1834                              int *, int *, int *, unsigned int *);
  1835 extern Atom x_intern_cached_atom (struct x_display_info *, const char *,
  1836                                   bool);
  1837 extern void x_intern_atoms (struct x_display_info *, char **, int, Atom *);
  1838 extern char *x_get_atom_name (struct x_display_info *, Atom, bool *)
  1839   ATTRIBUTE_MALLOC ATTRIBUTE_DEALLOC_FREE;
  1840 
  1841 #ifdef HAVE_GTK3
  1842 extern void x_scroll_bar_configure (GdkEvent *);
  1843 #endif
  1844 
  1845 #define DEFER_SELECTIONS                                                \
  1846   x_defer_selection_requests ();                                        \
  1847   record_unwind_protect_void (x_release_selection_requests_and_flush)
  1848 
  1849 extern void x_defer_selection_requests (void);
  1850 extern void x_release_selection_requests_and_flush (void);
  1851 extern void x_handle_pending_selection_requests (void);
  1852 extern bool x_detect_pending_selection_requests (void);
  1853 extern Lisp_Object x_dnd_begin_drag_and_drop (struct frame *, Time, Atom,
  1854                                               Lisp_Object, Atom *, const char **,
  1855                                               size_t, bool, Atom *, int,
  1856                                               Lisp_Object, bool);
  1857 extern void x_dnd_do_unsupported_drop (struct x_display_info *, Lisp_Object,
  1858                                        Lisp_Object, Lisp_Object, Window, int,
  1859                                        int, Time);
  1860 
  1861 extern int x_display_pixel_height (struct x_display_info *);
  1862 extern int x_display_pixel_width (struct x_display_info *);
  1863 
  1864 INLINE unsigned long
  1865 x_make_truecolor_pixel (struct x_display_info *dpyinfo, int r, int g, int b)
  1866 {
  1867   unsigned long pr, pg, pb, pa = dpyinfo->alpha_mask;
  1868 
  1869   /* Scale down RGB values to the visual's bits per RGB, and shift
  1870      them to the right position in the pixel color.  Note that the
  1871      original RGB values are 16-bit values, as usual in X.  */
  1872   pr = (r >> (16 - dpyinfo->red_bits))   << dpyinfo->red_offset;
  1873   pg = (g >> (16 - dpyinfo->green_bits)) << dpyinfo->green_offset;
  1874   pb = (b >> (16 - dpyinfo->blue_bits))  << dpyinfo->blue_offset;
  1875 
  1876   /* Assemble the pixel color.  */
  1877   return pr | pg | pb | pa;
  1878 }
  1879 
  1880 /* If display has an immutable color map, freeing colors is not
  1881    necessary and some servers don't allow it, so we won't do it.  That
  1882    also allows us to make other optimizations relating to server-side
  1883    reference counts.  */
  1884 INLINE bool
  1885 x_mutable_colormap (XVisualInfo *visual)
  1886 {
  1887   int class = visual->class;
  1888   return (class != StaticColor && class != StaticGray && class != TrueColor);
  1889 }
  1890 
  1891 extern void x_set_sticky (struct frame *, Lisp_Object, Lisp_Object);
  1892 extern void x_set_shaded (struct frame *, Lisp_Object, Lisp_Object);
  1893 extern void x_set_skip_taskbar (struct frame *, Lisp_Object, Lisp_Object);
  1894 extern void x_set_z_group (struct frame *, Lisp_Object, Lisp_Object);
  1895 extern bool x_wm_supports (struct frame *, Atom);
  1896 extern bool x_wm_supports_1 (struct x_display_info *, Atom);
  1897 extern void x_wait_for_event (struct frame *, int);
  1898 extern void x_clear_under_internal_border (struct frame *f);
  1899 
  1900 extern void tear_down_x_back_buffer (struct frame *f);
  1901 extern void initial_set_up_x_back_buffer (struct frame *f);
  1902 
  1903 /* Defined in xfns.c.  */
  1904 extern void x_real_positions (struct frame *, int *, int *);
  1905 extern void x_change_tab_bar_height (struct frame *, int);
  1906 extern void x_change_tool_bar_height (struct frame *, int);
  1907 extern void x_implicitly_set_name (struct frame *, Lisp_Object, Lisp_Object);
  1908 extern void x_set_scroll_bar_default_width (struct frame *);
  1909 extern void x_set_scroll_bar_default_height (struct frame *);
  1910 #ifdef USE_LUCID
  1911 extern void xlw_monitor_dimensions_at_pos (Display *, Screen *, int, int,
  1912                                            int *, int *, int *, int *);
  1913 #endif
  1914 
  1915 /* Defined in xselect.c.  */
  1916 
  1917 extern void x_handle_property_notify (const XPropertyEvent *);
  1918 extern void x_handle_selection_notify (const XSelectionEvent *);
  1919 extern void x_handle_selection_event (struct selection_input_event *);
  1920 extern void x_clear_frame_selections (struct frame *);
  1921 extern void x_remove_selection_transfers (struct x_display_info *);
  1922 extern void x_handle_selection_error (unsigned int, XErrorEvent *);
  1923 
  1924 extern Lisp_Object x_atom_to_symbol (struct x_display_info *, Atom);
  1925 extern Atom symbol_to_x_atom (struct x_display_info *, Lisp_Object);
  1926 
  1927 extern bool x_handle_dnd_message (struct frame *,
  1928                                   const XClientMessageEvent *,
  1929                                   struct x_display_info *,
  1930                                   struct input_event *,
  1931                                   bool, int, int);
  1932 extern int x_check_property_data (Lisp_Object);
  1933 extern void x_fill_property_data (struct x_display_info *, Lisp_Object,
  1934                                   void *, int, int);
  1935 extern Lisp_Object x_property_data_to_lisp (struct frame *,
  1936                                             const unsigned char *,
  1937                                             Atom,
  1938                                             int,
  1939                                             unsigned long);
  1940 extern void x_clipboard_manager_save_frame (Lisp_Object);
  1941 extern void x_clipboard_manager_save_all (void);
  1942 
  1943 extern Lisp_Object x_timestamp_for_selection (struct x_display_info *,
  1944                                               Lisp_Object);
  1945 extern void x_own_selection (Lisp_Object, Lisp_Object, Lisp_Object,
  1946                              Lisp_Object, Time);
  1947 
  1948 extern void mark_xselect (void);
  1949 
  1950 /* Misc definitions.  */
  1951 
  1952 #ifdef USE_GTK
  1953 extern bool xg_set_icon (struct frame *, Lisp_Object);
  1954 extern bool xg_set_icon_from_xpm_data (struct frame *, const char **);
  1955 #endif /* USE_GTK */
  1956 
  1957 extern void xic_free_xfontset (struct frame *);
  1958 extern void create_frame_xic (struct frame *);
  1959 extern void destroy_frame_xic (struct frame *);
  1960 extern void xic_set_preeditarea (struct window *, int, int);
  1961 extern void xic_set_statusarea (struct frame *);
  1962 extern void xic_set_xfontset (struct frame *, const char *);
  1963 extern bool x_defined_color (struct frame *, const char *, Emacs_Color *,
  1964                              bool, bool);
  1965 extern void x_preserve_selections (struct x_display_info *, Lisp_Object,
  1966                                    Lisp_Object);
  1967 extern Lisp_Object x_get_keyboard_modifiers (struct x_display_info *);
  1968 #ifdef HAVE_X_I18N
  1969 extern void free_frame_xic (struct frame *);
  1970 # if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
  1971 extern char *xic_create_fontsetname (const char *, bool);
  1972 # endif
  1973 #endif
  1974 
  1975 /* Defined in xfaces.c */
  1976 
  1977 #ifdef USE_X_TOOLKIT
  1978 extern void x_free_dpy_colors (Display *, Screen *, Colormap,
  1979                                unsigned long *, int);
  1980 #endif /* USE_X_TOOLKIT */
  1981 
  1982 /* Defined in xmenu.c */
  1983 
  1984 #if defined USE_X_TOOLKIT || defined USE_GTK
  1985 extern Lisp_Object xw_popup_dialog (struct frame *, Lisp_Object, Lisp_Object);
  1986 #endif
  1987 
  1988 #if defined USE_GTK || defined USE_MOTIF
  1989 extern void x_menu_set_in_use (bool);
  1990 #endif
  1991 extern void x_menu_wait_for_event (void *data);
  1992 extern void initialize_frame_menubar (struct frame *);
  1993 
  1994 /* Defined in xsmfns.c */
  1995 #ifdef HAVE_X_SM
  1996 extern void x_session_initialize (struct x_display_info *dpyinfo);
  1997 extern bool x_session_have_connection (void);
  1998 extern void x_session_close (void);
  1999 #endif
  2000 
  2001 #ifdef HAVE_X_I18N
  2002 #define STYLE_OFFTHESPOT (XIMPreeditArea | XIMStatusArea)
  2003 #define STYLE_OVERTHESPOT (XIMPreeditPosition | XIMStatusNothing)
  2004 #define STYLE_ROOT (XIMPreeditNothing | XIMStatusNothing)
  2005 #define STYLE_CALLBACK (XIMPreeditCallbacks | XIMStatusNothing)
  2006 #define STYLE_NONE (XIMPreeditNothing | XIMStatusNothing)
  2007 #endif
  2008 
  2009 #ifdef USE_GTK
  2010 extern struct input_event xg_pending_quit_event;
  2011 #endif
  2012 
  2013 extern bool x_dnd_in_progress;
  2014 extern bool x_dnd_waiting_for_finish;
  2015 extern struct frame *x_dnd_frame;
  2016 extern struct frame *x_dnd_finish_frame;
  2017 extern int x_error_message_count;
  2018 
  2019 #ifdef HAVE_XINPUT2
  2020 extern struct xi_device_t *xi_device_from_id (struct x_display_info *, int);
  2021 extern bool xi_frame_selected_for (struct frame *, unsigned long);
  2022 #ifndef USE_GTK
  2023 extern unsigned int xi_convert_event_state (XIDeviceEvent *);
  2024 #endif
  2025 #endif
  2026 
  2027 extern void mark_xterm (void);
  2028 
  2029 /* Is the frame embedded into another application? */
  2030 
  2031 #define FRAME_X_EMBEDDED_P(f) (FRAME_X_OUTPUT (f)->explicit_parent != 0)
  2032 
  2033 #define STORE_NATIVE_RECT(nr,rx,ry,rwidth,rheight)      \
  2034   ((nr).x = (rx),                                       \
  2035    (nr).y = (ry),                                       \
  2036    (nr).width = (rwidth),                               \
  2037    (nr).height = (rheight))
  2038 
  2039 INLINE_HEADER_END
  2040 
  2041 #endif /* XTERM_H */

/* [<][>][^][v][top][bottom][index][help] */