Unify FRAME_window_system_DISPLAY_INFO macros between all ports.
[bpt/emacs.git] / src / xterm.h
1 /* Definitions and headers for communication with X protocol.
2 Copyright (C) 1989, 1993-1994, 1998-2013 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
10 (at 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 <http://www.gnu.org/licenses/>. */
19
20 #ifndef XTERM_H
21 #define XTERM_H
22
23 #include <X11/Xlib.h>
24 #include <X11/cursorfont.h>
25
26 /* Include Xutil.h after keysym.h to work around a bug that prevents
27 correct recognition of AltGr key in some X versions. */
28
29 #include <X11/keysym.h>
30 #include <X11/Xutil.h>
31
32 #include <X11/Xatom.h>
33 #include <X11/Xresource.h>
34
35 #ifdef USE_X_TOOLKIT
36 #include <X11/StringDefs.h>
37 #include <X11/IntrinsicP.h> /* CoreP.h needs this */
38 #include <X11/CoreP.h> /* foul, but we need this to use our own
39 window inside a widget instead of one
40 that Xt creates... */
41 typedef Widget xt_or_gtk_widget;
42 #endif
43
44 #ifdef USE_GTK
45 #include <gtk/gtk.h>
46 #include <gdk/gdkx.h>
47
48 /* Some definitions to reduce conditionals. */
49 typedef GtkWidget *xt_or_gtk_widget;
50 #define XtParent(x) (gtk_widget_get_parent (x))
51 #undef XSync
52 #define XSync(d, b) do { gdk_window_process_all_updates (); \
53 XSync (d, b); } while (0)
54 #endif /* USE_GTK */
55
56 /* True iff GTK's version is at least I.J.K. */
57 #ifndef GTK_CHECK_VERSION
58 # ifdef USE_GTK
59 # define GTK_CHECK_VERSION(i, j, k) \
60 ((i) \
61 < GTK_MAJOR_VERSION + ((j) \
62 < GTK_MINOR_VERSION + ((k) \
63 <= GTK_MICRO_VERSION)))
64 # else
65 # define GTK_CHECK_VERSION(i, j, k) 0
66 # endif
67 #endif
68
69 /* The GtkTooltip API came in 2.12, but gtk-enable-tooltips in 2.14. */
70 #if GTK_CHECK_VERSION (2, 14, 0)
71 #define USE_GTK_TOOLTIP
72 #endif
73
74 #ifdef HAVE_X_I18N
75 #include <X11/Xlocale.h>
76 #endif
77
78 #include "dispextern.h"
79 #include "termhooks.h"
80
81 #define BLACK_PIX_DEFAULT(f) BlackPixel (FRAME_X_DISPLAY (f), \
82 XScreenNumberOfScreen (FRAME_X_SCREEN (f)))
83 #define WHITE_PIX_DEFAULT(f) WhitePixel (FRAME_X_DISPLAY (f), \
84 XScreenNumberOfScreen (FRAME_X_SCREEN (f)))
85
86 #define FONT_WIDTH(f) ((f)->max_width)
87 #define FONT_HEIGHT(f) ((f)->ascent + (f)->descent)
88 #define FONT_BASE(f) ((f)->ascent)
89 #define FONT_DESCENT(f) ((f)->descent)
90
91 /* The mask of events that text windows always want to receive. This
92 includes mouse movement events, since handling the mouse-font text property
93 means that we must track mouse motion all the time. */
94
95 #define STANDARD_EVENT_SET \
96 (KeyPressMask \
97 | ExposureMask \
98 | ButtonPressMask \
99 | ButtonReleaseMask \
100 | PointerMotionMask \
101 | StructureNotifyMask \
102 | FocusChangeMask \
103 | LeaveWindowMask \
104 | EnterWindowMask \
105 | VisibilityChangeMask)
106
107 #ifdef HAVE_X11R6_XIM
108 /* Data structure passed to xim_instantiate_callback. */
109 struct xim_inst_t
110 {
111 struct x_display_info *dpyinfo;
112 char *resource_name;
113 };
114 #endif /* HAVE_X11R6_XIM */
115
116 /* Structure recording X pixmap and reference count.
117 If REFCOUNT is 0 then this record is free to be reused. */
118
119 struct x_bitmap_record
120 {
121 Pixmap pixmap;
122 int have_mask;
123 Pixmap mask;
124 char *file;
125 int refcount;
126 /* Record some info about this pixmap. */
127 int height, width, depth;
128 };
129 \f
130 /* For each X display, we have a structure that records
131 information about it. */
132
133 struct x_display_info
134 {
135 /* Chain of all x_display_info structures. */
136 struct x_display_info *next;
137
138 /* The generic display parameters corresponding to this X display. */
139 struct terminal *terminal;
140
141 /* This says how to access this display in Xlib. */
142 Display *display;
143
144 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE).
145 The same cons cell also appears in x_display_name_list. */
146 Lisp_Object name_list_element;
147
148 /* Number of frames that are on this display. */
149 int reference_count;
150
151 /* The Screen this connection is connected to. */
152 Screen *screen;
153
154 /* Dots per inch of the screen. */
155 double resx, resy;
156
157 /* The Visual being used for this display. */
158 Visual *visual;
159
160 /* The colormap being used. */
161 Colormap cmap;
162
163 /* Number of planes on this screen. */
164 int n_planes;
165
166 /* Mask of things that cause the mouse to be grabbed. */
167 int grabbed;
168
169 /* Emacs bitmap-id of the default icon bitmap for this frame.
170 Or -1 if none has been allocated yet. */
171 ptrdiff_t icon_bitmap_id;
172
173 /* The root window of this screen. */
174 Window root_window;
175
176 /* Client leader window. */
177 Window client_leader_window;
178
179 /* The cursor to use for vertical scroll bars. */
180 Cursor vertical_scroll_bar_cursor;
181
182 /* The invisible cursor used for pointer blanking. */
183 Cursor invisible_cursor;
184
185 #ifdef USE_GTK
186 /* The GDK cursor for scroll bars and popup menus. */
187 GdkCursor *xg_cursor;
188 #endif
189
190 /* X Resource data base */
191 XrmDatabase xrdb;
192
193 /* Minimum width over all characters in all fonts in font_table. */
194 int smallest_char_width;
195
196 /* Minimum font height over all fonts in font_table. */
197 int smallest_font_height;
198
199 /* Reusable Graphics Context for drawing a cursor in a non-default face. */
200 GC scratch_cursor_gc;
201
202 /* Information about the range of text currently shown in
203 mouse-face. */
204 Mouse_HLInfo mouse_highlight;
205
206 char *x_id_name;
207
208 /* The number of fonts opened for this display. */
209 int n_fonts;
210
211 /* Pointer to bitmap records. */
212 struct x_bitmap_record *bitmaps;
213
214 /* Allocated size of bitmaps field. */
215 ptrdiff_t bitmaps_size;
216
217 /* Last used bitmap index. */
218 ptrdiff_t bitmaps_last;
219
220 /* Which modifier keys are on which modifier bits?
221
222 With each keystroke, X returns eight bits indicating which modifier
223 keys were held down when the key was pressed. The interpretation
224 of the top five modifier bits depends on what keys are attached
225 to them. If the Meta_L and Meta_R keysyms are on mod5, then mod5
226 is the meta bit.
227
228 meta_mod_mask is a mask containing the bits used for the meta key.
229 It may have more than one bit set, if more than one modifier bit
230 has meta keys on it. Basically, if EVENT is a KeyPress event,
231 the meta key is pressed if (EVENT.state & meta_mod_mask) != 0.
232
233 shift_lock_mask is LockMask if the XK_Shift_Lock keysym is on the
234 lock modifier bit, or zero otherwise. Non-alphabetic keys should
235 only be affected by the lock modifier bit if XK_Shift_Lock is in
236 use; XK_Caps_Lock should only affect alphabetic keys. With this
237 arrangement, the lock modifier should shift the character if
238 (EVENT.state & shift_lock_mask) != 0. */
239 int meta_mod_mask, shift_lock_mask;
240
241 /* These are like meta_mod_mask, but for different modifiers. */
242 int alt_mod_mask, super_mod_mask, hyper_mod_mask;
243
244 /* Communication with window managers. */
245 Atom Xatom_wm_protocols;
246
247 /* Kinds of protocol things we may receive. */
248 Atom Xatom_wm_take_focus;
249 Atom Xatom_wm_save_yourself;
250 Atom Xatom_wm_delete_window;
251
252 /* Atom for indicating window state to the window manager. */
253 Atom Xatom_wm_change_state;
254
255 /* Other WM communication */
256 Atom Xatom_wm_configure_denied; /* When our config request is denied */
257 Atom Xatom_wm_window_moved; /* When the WM moves us. */
258 Atom Xatom_wm_client_leader; /* Id of client leader window. */
259
260 /* EditRes protocol */
261 Atom Xatom_editres;
262
263 /* More atoms, which are selection types. */
264 Atom Xatom_CLIPBOARD, Xatom_TIMESTAMP, Xatom_TEXT, Xatom_DELETE,
265 Xatom_COMPOUND_TEXT, Xatom_UTF8_STRING,
266 Xatom_MULTIPLE, Xatom_INCR, Xatom_EMACS_TMP, Xatom_TARGETS, Xatom_NULL,
267 Xatom_ATOM, Xatom_ATOM_PAIR, Xatom_CLIPBOARD_MANAGER;
268
269 /* More atoms for font properties. The last three are private
270 properties, see the comments in src/fontset.h. */
271 Atom Xatom_PIXEL_SIZE, Xatom_AVERAGE_WIDTH,
272 Xatom_MULE_BASELINE_OFFSET, Xatom_MULE_RELATIVE_COMPOSE,
273 Xatom_MULE_DEFAULT_ASCENT;
274
275 /* More atoms for Ghostscript support. */
276 Atom Xatom_DONE, Xatom_PAGE;
277
278 /* Atom used in toolkit scroll bar client messages. */
279 Atom Xatom_Scrollbar;
280
281 /* Atom used in XEmbed client messages. */
282 Atom Xatom_XEMBED, Xatom_XEMBED_INFO;
283
284 /* The frame (if any) which has the X window that has keyboard focus.
285 Zero if none. This is examined by Ffocus_frame in xfns.c. Note
286 that a mere EnterNotify event can set this; if you need to know the
287 last frame specified in a FocusIn or FocusOut event, use
288 x_focus_event_frame. */
289 struct frame *x_focus_frame;
290
291 /* The last frame mentioned in a FocusIn or FocusOut event. This is
292 separate from x_focus_frame, because whether or not LeaveNotify
293 events cause us to lose focus depends on whether or not we have
294 received a FocusIn event for it. */
295 struct frame *x_focus_event_frame;
296
297 /* The frame which currently has the visual highlight, and should get
298 keyboard input (other sorts of input have the frame encoded in the
299 event). It points to the X focus frame's selected window's
300 frame. It differs from x_focus_frame when we're using a global
301 minibuffer. */
302 struct frame *x_highlight_frame;
303
304 /* Time of last user interaction as returned in X events on this display. */
305 Time last_user_time;
306
307 /* The gray pixmap. */
308 Pixmap gray;
309
310 #ifdef HAVE_X_I18N
311 /* XIM (X Input method). */
312 XIM xim;
313 XIMStyles *xim_styles;
314 struct xim_inst_t *xim_callback_data;
315 #endif
316
317 /* If non-null, a cache of the colors in the color map. Don't
318 use this directly, call x_color_cells instead. */
319 XColor *color_cells;
320 int ncolor_cells;
321
322 /* Bits and shifts to use to compose pixel values on TrueColor visuals. */
323 int red_bits, blue_bits, green_bits;
324 int red_offset, blue_offset, green_offset;
325
326 /* The type of window manager we have. If we move FRAME_OUTER_WINDOW
327 to x/y 0/0, some window managers (type A) puts the window manager
328 decorations outside the screen and FRAME_OUTER_WINDOW exactly at 0/0.
329 Other window managers (type B) puts the window including decorations
330 at 0/0, so FRAME_OUTER_WINDOW is a bit below 0/0.
331 Record the type of WM in use so we can compensate for type A WMs. */
332 enum
333 {
334 X_WMTYPE_UNKNOWN,
335 X_WMTYPE_A,
336 X_WMTYPE_B
337 } wm_type;
338
339
340 /* Atoms that are drag and drop atoms */
341 Atom *x_dnd_atoms;
342 ptrdiff_t x_dnd_atoms_size;
343 ptrdiff_t x_dnd_atoms_length;
344
345 /* Extended window manager hints, Atoms supported by the window manager and
346 atoms for setting the window type. */
347 Atom Xatom_net_supported, Xatom_net_supporting_wm_check;
348 Atom *net_supported_atoms;
349 int nr_net_supported_atoms;
350 Window net_supported_window;
351 Atom Xatom_net_window_type, Xatom_net_window_type_tooltip;
352 Atom Xatom_net_active_window;
353
354 /* Atoms dealing with EWMH (i.e. _NET_...) */
355 Atom Xatom_net_wm_state, Xatom_net_wm_state_fullscreen,
356 Xatom_net_wm_state_maximized_horz, Xatom_net_wm_state_maximized_vert,
357 Xatom_net_wm_state_sticky, Xatom_net_wm_state_hidden,
358 Xatom_net_frame_extents,
359 Xatom_net_current_desktop, Xatom_net_workarea;
360
361 /* XSettings atoms and windows. */
362 Atom Xatom_xsettings_sel, Xatom_xsettings_prop, Xatom_xsettings_mgr;
363 Window xsettings_window;
364
365 /* Frame name and icon name */
366 Atom Xatom_net_wm_name, Xatom_net_wm_icon_name;
367 /* Frame opacity */
368 Atom Xatom_net_wm_window_opacity;
369
370 /* SM */
371 Atom Xatom_SM_CLIENT_ID;
372 };
373
374 #ifdef HAVE_X_I18N
375 /* Whether or not to use XIM if we have it. */
376 extern int use_xim;
377 #endif
378
379 /* This is a chain of structures for all the X displays currently in use. */
380 extern struct x_display_info *x_display_list;
381
382 /* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE),
383 one for each element of x_display_list and in the same order.
384 NAME is the name of the frame.
385 FONT-LIST-CACHE records previous values returned by x-list-fonts. */
386 extern Lisp_Object x_display_name_list;
387
388 extern struct x_display_info *x_display_info_for_display (Display *);
389 extern struct frame *x_top_window_to_frame (struct x_display_info *, int);
390 extern struct x_display_info *x_term_init (Lisp_Object, char *, char *);
391 extern bool x_display_ok (const char *);
392
393 extern void select_visual (struct x_display_info *);
394
395 /* Each X frame object points to its own struct x_output object
396 in the output_data.x field. The x_output structure contains
397 the information that is specific to X windows. */
398
399 struct x_output
400 {
401 /* Height of menu bar widget, in pixels.
402 Zero if not using the X toolkit.
403 When using the toolkit, this value is not meaningful
404 if the menubar is turned off. */
405 int menubar_height;
406
407 /* Height of tool bar widget, in pixels. top_height is used if tool bar
408 at top, bottom_height if tool bar is at the bottom.
409 Zero if not using an external tool bar or if tool bar is vertical. */
410 int toolbar_top_height, toolbar_bottom_height;
411
412 /* Width of tool bar widget, in pixels. left_width is used if tool bar
413 at left, right_width if tool bar is at the right.
414 Zero if not using an external tool bar or if tool bar is horizontal. */
415 int toolbar_left_width, toolbar_right_width;
416
417 /* The tiled border used when the mouse is out of the frame. */
418 Pixmap border_tile;
419
420 /* Here are the Graphics Contexts for the default font. */
421 GC normal_gc; /* Normal video */
422 GC reverse_gc; /* Reverse video */
423 GC cursor_gc; /* cursor drawing */
424
425 /* The X window used for this frame.
426 May be zero while the frame object is being created
427 and the X window has not yet been created. */
428 Window window_desc;
429
430 /* The X window used for the bitmap icon;
431 or 0 if we don't have a bitmap icon. */
432 Window icon_desc;
433
434 /* The X window that is the parent of this X window.
435 Usually this is a window that was made by the window manager,
436 but it can be the root window, and it can be explicitly specified
437 (see the explicit_parent field, below). */
438 Window parent_desc;
439
440 #ifdef USE_X_TOOLKIT
441 /* The widget of this screen. This is the window of a "shell" widget. */
442 Widget widget;
443 /* The XmPanedWindows... */
444 Widget column_widget;
445 /* The widget of the edit portion of this screen; the window in
446 "window_desc" is inside of this. */
447 Widget edit_widget;
448
449 Widget menubar_widget;
450 #endif
451
452 #ifdef USE_GTK
453 /* The widget of this screen. This is the window of a top widget. */
454 GtkWidget *widget;
455 /* The widget of the edit portion of this screen; the window in
456 "window_desc" is inside of this. */
457 GtkWidget *edit_widget;
458 /* The widget used for laying out widgets vertically. */
459 GtkWidget *vbox_widget;
460 /* The widget used for laying out widgets horizontally. */
461 GtkWidget *hbox_widget;
462 /* The menubar in this frame. */
463 GtkWidget *menubar_widget;
464 /* The tool bar in this frame */
465 GtkWidget *toolbar_widget;
466 #ifdef HAVE_GTK_HANDLE_BOX_NEW
467 /* The handle box that makes the tool bar detachable. */
468 GtkWidget *handlebox_widget;
469 #endif
470 /* Non-zero if tool bar is packed into the hbox widget (i.e. vertical). */
471 bool toolbar_in_hbox;
472 bool toolbar_is_packed;
473
474 /* The last size hints set. */
475 GdkGeometry size_hints;
476 long hint_flags;
477
478 #ifdef USE_GTK_TOOLTIP
479 GtkTooltip *ttip_widget;
480 GtkWidget *ttip_lbl;
481 GtkWindow *ttip_window;
482 #endif /* USE_GTK_TOOLTIP */
483
484 #endif /* USE_GTK */
485
486 /* If >=0, a bitmap index. The indicated bitmap is used for the
487 icon. */
488 ptrdiff_t icon_bitmap;
489
490 /* Default ASCII font of this frame. */
491 struct font *font;
492
493 /* The baseline offset of the default ASCII font. */
494 int baseline_offset;
495
496 /* If a fontset is specified for this frame instead of font, this
497 value contains an ID of the fontset, else -1. */
498 int fontset;
499
500 unsigned long cursor_pixel;
501 unsigned long border_pixel;
502 unsigned long mouse_pixel;
503 unsigned long cursor_foreground_pixel;
504
505 /* Foreground color for scroll bars. A value of -1 means use the
506 default (black for non-toolkit scroll bars). */
507 unsigned long scroll_bar_foreground_pixel;
508
509 /* Background color for scroll bars. A value of -1 means use the
510 default (background color of the frame for non-toolkit scroll
511 bars). */
512 unsigned long scroll_bar_background_pixel;
513
514 /* Top and bottom shadow colors for 3d toolkit scrollbars. -1 means
515 let the scroll compute them itself. */
516 unsigned long scroll_bar_top_shadow_pixel;
517 unsigned long scroll_bar_bottom_shadow_pixel;
518
519 /* Descriptor for the cursor in use for this window. */
520 Cursor text_cursor;
521 Cursor nontext_cursor;
522 Cursor modeline_cursor;
523 Cursor hand_cursor;
524 Cursor hourglass_cursor;
525 Cursor horizontal_drag_cursor;
526 Cursor current_cursor;
527
528 /* Window whose cursor is hourglass_cursor. This window is temporarily
529 mapped to display an hourglass cursor. */
530 Window hourglass_window;
531
532 /* Non-zero means hourglass cursor is currently displayed. */
533 unsigned hourglass_p : 1;
534
535 /* These are the current window manager hints. It seems that
536 XSetWMHints, when presented with an unset bit in the `flags'
537 member of the hints structure, does not leave the corresponding
538 attribute unchanged; rather, it resets that attribute to its
539 default value. For example, unless you set the `icon_pixmap'
540 field and the `IconPixmapHint' bit, XSetWMHints will forget what
541 your icon pixmap was. This is rather troublesome, since some of
542 the members (for example, `input' and `icon_pixmap') want to stay
543 the same throughout the execution of Emacs. So, we keep this
544 structure around, just leaving values in it and adding new bits
545 to the mask as we go. */
546 XWMHints wm_hints;
547
548 /* This is the Emacs structure for the X display this frame is on. */
549 struct x_display_info *display_info;
550
551 /* This is a button event that wants to activate the menubar.
552 We save it here until the command loop gets to think about it. */
553 XEvent *saved_menu_event;
554
555 /* This is the widget id used for this frame's menubar in lwlib. */
556 #ifdef USE_X_TOOLKIT
557 int id;
558 #endif
559
560 /* Nonzero means our parent is another application's window
561 and was explicitly specified. */
562 unsigned explicit_parent : 1;
563
564 /* Nonzero means tried already to make this frame visible. */
565 unsigned asked_for_visible : 1;
566
567 /* Nonzero if this frame was ever previously visible. */
568 unsigned has_been_visible : 1;
569
570 #ifdef HAVE_X_I18N
571 /* Input context (currently, this means Compose key handler setup). */
572 XIC xic;
573 XIMStyle xic_style;
574 XFontSet xic_xfs;
575 #endif
576
577 /* Relief GCs, colors etc. */
578 struct relief
579 {
580 GC gc;
581 unsigned long pixel;
582 int allocated_p;
583 }
584 black_relief, white_relief;
585
586 /* The background for which the above relief GCs were set up.
587 They are changed only when a different background is involved. */
588 unsigned long relief_background;
589
590 /* Xt waits for a ConfigureNotify event from the window manager in
591 EmacsFrameSetCharSize when the shell widget is resized. For some
592 window managers like fvwm2 2.2.5 and KDE 2.1 this event doesn't
593 arrive for an unknown reason and Emacs hangs in Xt. If this is
594 zero, tell Xt not to wait. */
595 int wait_for_wm;
596
597 /* As x_pixels_diff, but to FRAME_OUTER_WINDOW. For some reason the
598 two might differ by a pixel, depending on WM */
599 int x_pixels_outer_diff;
600
601 /* As y_pixels_diff, but to FRAME_OUTER_WINDOW. In the toolkit version,
602 these may differ because this does not take into account possible
603 menubar. y_pixels_diff is with menubar height included */
604 int y_pixels_outer_diff;
605
606 /* Keep track of focus. May be EXPLICIT if we received a FocusIn for this
607 frame, or IMPLICIT if we received an EnterNotify.
608 FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
609 int focus_state;
610
611 /* The offset we need to add to compensate for type A WMs. */
612 int move_offset_top;
613 int move_offset_left;
614
615 /* Non-zero if _NET_WM_STATE_HIDDEN is set for this frame. */
616 unsigned net_wm_state_hidden_seen : 1;
617 };
618
619 #define No_Cursor (None)
620
621 enum
622 {
623 /* Values for focus_state, used as bit mask.
624 EXPLICIT means we received a FocusIn for the frame and know it has
625 the focus. IMPLICIT means we received an EnterNotify and the frame
626 may have the focus if no window manager is running.
627 FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
628 FOCUS_NONE = 0,
629 FOCUS_IMPLICIT = 1,
630 FOCUS_EXPLICIT = 2
631 };
632
633
634 /* Return the X output data for frame F. */
635 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
636
637 /* Return the X window used for displaying data in frame F. */
638 #define FRAME_X_WINDOW(f) ((f)->output_data.x->window_desc)
639
640 /* Return the outermost X window associated with the frame F. */
641 #ifdef USE_X_TOOLKIT
642 #define FRAME_OUTER_WINDOW(f) ((f)->output_data.x->widget ? \
643 XtWindow ((f)->output_data.x->widget) : \
644 FRAME_X_WINDOW (f))
645 #else
646 #ifdef USE_GTK
647 /* Functions not present in older Gtk+ */
648
649 #ifndef HAVE_GTK_WIDGET_GET_WINDOW
650 #define gtk_widget_get_window(w) ((w)->window)
651 #endif
652 #ifndef HAVE_GTK_WIDGET_GET_MAPPED
653 #define gtk_widget_get_mapped(w) (GTK_WIDGET_MAPPED (w))
654 #endif
655 #ifndef HAVE_GTK_ADJUSTMENT_GET_PAGE_SIZE
656 #define gtk_adjustment_get_page_size(w) ((w)->page_size)
657 #define gtk_adjustment_get_upper(w) ((w)->upper)
658 #endif
659
660 #ifdef HAVE_GTK3
661 #define DEFAULT_GDK_DISPLAY() \
662 gdk_x11_display_get_xdisplay (gdk_display_get_default ())
663 #else
664 #undef GDK_WINDOW_XID
665 #define GDK_WINDOW_XID(w) GDK_WINDOW_XWINDOW (w)
666 #define DEFAULT_GDK_DISPLAY() GDK_DISPLAY ()
667 #define gtk_widget_get_preferred_size(a, ign, b) \
668 gtk_widget_size_request (a, b)
669 #endif
670
671 #define GTK_WIDGET_TO_X_WIN(w) \
672 ((w) && gtk_widget_get_window (w) \
673 ? GDK_WINDOW_XID (gtk_widget_get_window (w)) : 0)
674
675 #define FRAME_GTK_OUTER_WIDGET(f) ((f)->output_data.x->widget)
676 #define FRAME_GTK_WIDGET(f) ((f)->output_data.x->edit_widget)
677 #define FRAME_OUTER_WINDOW(f) \
678 (FRAME_GTK_OUTER_WIDGET (f) ? \
679 GTK_WIDGET_TO_X_WIN (FRAME_GTK_OUTER_WIDGET (f)) : \
680 FRAME_X_WINDOW (f))
681
682 #else /* !USE_GTK */
683 #define FRAME_OUTER_WINDOW(f) (FRAME_X_WINDOW (f))
684 #endif /* !USE_GTK */
685 #endif
686
687
688 #define FRAME_FONT(f) ((f)->output_data.x->font)
689 #define FRAME_FONTSET(f) ((f)->output_data.x->fontset)
690 #define FRAME_MENUBAR_HEIGHT(f) ((f)->output_data.x->menubar_height)
691 #define FRAME_TOOLBAR_TOP_HEIGHT(f) ((f)->output_data.x->toolbar_top_height)
692 #define FRAME_TOOLBAR_BOTTOM_HEIGHT(f) \
693 ((f)->output_data.x->toolbar_bottom_height)
694 #define FRAME_TOOLBAR_HEIGHT(f) \
695 (FRAME_TOOLBAR_TOP_HEIGHT (f) + FRAME_TOOLBAR_BOTTOM_HEIGHT (f))
696 #define FRAME_TOOLBAR_LEFT_WIDTH(f) ((f)->output_data.x->toolbar_left_width)
697 #define FRAME_TOOLBAR_RIGHT_WIDTH(f) ((f)->output_data.x->toolbar_right_width)
698 #define FRAME_TOOLBAR_WIDTH(f) \
699 (FRAME_TOOLBAR_LEFT_WIDTH (f) + FRAME_TOOLBAR_RIGHT_WIDTH (f))
700 #define FRAME_BASELINE_OFFSET(f) ((f)->output_data.x->baseline_offset)
701
702 /* This gives the x_display_info structure for the display F is on. */
703 #define FRAME_DISPLAY_INFO(f) ((f)->output_data.x->display_info)
704
705 /* This is the `Display *' which frame F is on. */
706 #define FRAME_X_DISPLAY(f) (FRAME_DISPLAY_INFO (f)->display)
707
708 /* This is the `Screen *' which frame F is on. */
709 #define FRAME_X_SCREEN(f) (FRAME_DISPLAY_INFO (f)->screen)
710 #define FRAME_X_SCREEN_NUMBER(f) XScreenNumberOfScreen (FRAME_X_SCREEN (f))
711
712 /* This is the Visual which frame F is on. */
713 #define FRAME_X_VISUAL(f) FRAME_DISPLAY_INFO (f)->visual
714
715 /* This is the Colormap which frame F uses. */
716 #define FRAME_X_COLORMAP(f) FRAME_DISPLAY_INFO (f)->cmap
717
718 /* The difference in pixels between the top left corner of the
719 Emacs window (including possible window manager decorations)
720 and FRAME_X_WINDOW (f). */
721 #define FRAME_OUTER_TO_INNER_DIFF_X(f) \
722 ((f)->output_data.x->x_pixels_outer_diff)
723 #define FRAME_OUTER_TO_INNER_DIFF_Y(f) \
724 ((f)->output_data.x->y_pixels_outer_diff \
725 + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f))
726
727
728 #define FRAME_XIC(f) ((f)->output_data.x->xic)
729 #define FRAME_X_XIM(f) (FRAME_DISPLAY_INFO (f)->xim)
730 #define FRAME_X_XIM_STYLES(f) (FRAME_DISPLAY_INFO (f)->xim_styles)
731 #define FRAME_XIC_STYLE(f) ((f)->output_data.x->xic_style)
732 #define FRAME_XIC_FONTSET(f) ((f)->output_data.x->xic_xfs)
733
734 /* Value is the smallest width of any character in any font on frame F. */
735
736 #define FRAME_SMALLEST_CHAR_WIDTH(F) \
737 FRAME_DISPLAY_INFO(F)->smallest_char_width
738
739 /* Value is the smallest height of any font on frame F. */
740
741 #define FRAME_SMALLEST_FONT_HEIGHT(F) \
742 FRAME_DISPLAY_INFO(F)->smallest_font_height
743 \f
744 /* X-specific scroll bar stuff. */
745
746 /* We represent scroll bars as lisp vectors. This allows us to place
747 references to them in windows without worrying about whether we'll
748 end up with windows referring to dead scroll bars; the garbage
749 collector will free it when its time comes.
750
751 We use struct scroll_bar as a template for accessing fields of the
752 vector. */
753
754 struct scroll_bar
755 {
756 /* These fields are shared by all vectors. */
757 struct vectorlike_header header;
758
759 /* The window we're a scroll bar for. */
760 Lisp_Object window;
761
762 /* The next and previous in the chain of scroll bars in this frame. */
763 Lisp_Object next, prev;
764
765 /* Fields from `x_window' down will not be traced by the GC. */
766
767 /* The X window representing this scroll bar. */
768 Window x_window;
769
770 /* The position and size of the scroll bar in pixels, relative to the
771 frame. */
772 int top, left, width, height;
773
774 /* The starting and ending positions of the handle, relative to the
775 handle area (i.e. zero is the top position, not
776 SCROLL_BAR_TOP_BORDER). If they're equal, that means the handle
777 hasn't been drawn yet.
778
779 These are not actually the locations where the beginning and end
780 are drawn; in order to keep handles from becoming invisible when
781 editing large files, we establish a minimum height by always
782 drawing handle bottoms VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
783 where they would be normally; the bottom and top are in a
784 different co-ordinate system. */
785 int start, end;
786
787 /* If the scroll bar handle is currently being dragged by the user,
788 this is the number of pixels from the top of the handle to the
789 place where the user grabbed it. If the handle isn't currently
790 being dragged, this is -1. */
791 int dragging;
792
793 #if defined (USE_TOOLKIT_SCROLL_BARS) && defined (USE_LUCID)
794 /* Last scroll bar part seen in xaw_jump_callback and xaw_scroll_callback. */
795 enum scroll_bar_part last_seen_part;
796 #endif
797
798 /* 1 if the background of the fringe that is adjacent to a scroll
799 bar is extended to the gap between the fringe and the bar. */
800 unsigned fringe_extended_p : 1;
801 };
802
803 /* Turning a lisp vector value into a pointer to a struct scroll_bar. */
804 #define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec))
805
806
807 /* Extract the X widget of the scroll bar from a struct scroll_bar.
808 XtWindowToWidget should be fast enough since Xt uses a hash table
809 to map windows to widgets. */
810
811 #define SCROLL_BAR_X_WIDGET(dpy, ptr) \
812 XtWindowToWidget (dpy, ptr->x_window)
813
814 /* Store a widget id in a struct scroll_bar. */
815
816 #define SET_SCROLL_BAR_X_WIDGET(ptr, w) \
817 do { \
818 Window window = XtWindow (w); \
819 ptr->x_window = window; \
820 } while (0)
821
822
823 /* Return the inside width of a vertical scroll bar, given the outside
824 width. */
825 #define VERTICAL_SCROLL_BAR_INSIDE_WIDTH(f, width) \
826 ((width) \
827 - VERTICAL_SCROLL_BAR_LEFT_BORDER \
828 - VERTICAL_SCROLL_BAR_RIGHT_BORDER \
829 - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2)
830
831 /* Return the length of the rectangle within which the top of the
832 handle must stay. This isn't equivalent to the inside height,
833 because the scroll bar handle has a minimum height.
834
835 This is the real range of motion for the scroll bar, so when we're
836 scaling buffer positions to scroll bar positions, we use this, not
837 VERTICAL_SCROLL_BAR_INSIDE_HEIGHT. */
838 #define VERTICAL_SCROLL_BAR_TOP_RANGE(f, height) \
839 (VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, height) - VERTICAL_SCROLL_BAR_MIN_HANDLE)
840
841 /* Return the inside height of vertical scroll bar, given the outside
842 height. See VERTICAL_SCROLL_BAR_TOP_RANGE too. */
843 #define VERTICAL_SCROLL_BAR_INSIDE_HEIGHT(f, height) \
844 ((height) - VERTICAL_SCROLL_BAR_TOP_BORDER - VERTICAL_SCROLL_BAR_BOTTOM_BORDER)
845
846
847 /* Border widths for scroll bars.
848
849 Scroll bar windows don't have any X borders; their border width is
850 set to zero, and we redraw borders ourselves. This makes the code
851 a bit cleaner, since we don't have to convert between outside width
852 (used when relating to the rest of the screen) and inside width
853 (used when sizing and drawing the scroll bar window itself).
854
855 The handle moves up and down/back and forth in a rectangle inset
856 from the edges of the scroll bar. These are widths by which we
857 inset the handle boundaries from the scroll bar edges. */
858 #define VERTICAL_SCROLL_BAR_LEFT_BORDER (2)
859 #define VERTICAL_SCROLL_BAR_RIGHT_BORDER (2)
860 #define VERTICAL_SCROLL_BAR_TOP_BORDER (2)
861 #define VERTICAL_SCROLL_BAR_BOTTOM_BORDER (2)
862
863 /* Minimum lengths for scroll bar handles, in pixels. */
864 #define VERTICAL_SCROLL_BAR_MIN_HANDLE (5)
865
866 /* Trimming off a few pixels from each side prevents
867 text from glomming up against the scroll bar */
868 #define VERTICAL_SCROLL_BAR_WIDTH_TRIM (0)
869
870 \f
871 /* If a struct input_event has a kind which is SELECTION_REQUEST_EVENT
872 or SELECTION_CLEAR_EVENT, then its contents are really described
873 by this structure. */
874
875 /* For an event of kind SELECTION_REQUEST_EVENT,
876 this structure really describes the contents. */
877
878 struct selection_input_event
879 {
880 int kind;
881 Display *display;
882 /* We spell it with an "o" here because X does. */
883 Window requestor;
884 Atom selection, target, property;
885 Time time;
886 };
887
888 #define SELECTION_EVENT_DISPLAY(eventp) \
889 (((struct selection_input_event *) (eventp))->display)
890 /* We spell it with an "o" here because X does. */
891 #define SELECTION_EVENT_REQUESTOR(eventp) \
892 (((struct selection_input_event *) (eventp))->requestor)
893 #define SELECTION_EVENT_SELECTION(eventp) \
894 (((struct selection_input_event *) (eventp))->selection)
895 #define SELECTION_EVENT_TARGET(eventp) \
896 (((struct selection_input_event *) (eventp))->target)
897 #define SELECTION_EVENT_PROPERTY(eventp) \
898 (((struct selection_input_event *) (eventp))->property)
899 #define SELECTION_EVENT_TIME(eventp) \
900 (((struct selection_input_event *) (eventp))->time)
901
902 /* From xselect.c. */
903
904 void x_handle_selection_notify (XSelectionEvent *);
905 void x_handle_property_notify (XPropertyEvent *);
906
907 /* From xfns.c. */
908
909 extern void x_free_gcs (struct frame *);
910
911 /* From xrdb.c. */
912
913 XrmDatabase x_load_resources (Display *, const char *, const char *,
914 const char *);
915
916 /* Defined in xterm.c */
917
918 extern int x_text_icon (struct frame *, const char *);
919 extern void x_catch_errors (Display *);
920 extern void x_check_errors (Display *, const char *)
921 ATTRIBUTE_FORMAT_PRINTF (2, 0);
922 extern bool x_had_errors_p (Display *);
923 extern void x_uncatch_errors (void);
924 extern void x_clear_errors (Display *);
925 extern void x_set_window_size (struct frame *, int, int, int);
926 extern void x_set_mouse_position (struct frame *, int, int);
927 extern void x_set_mouse_pixel_position (struct frame *, int, int);
928 extern void xembed_request_focus (struct frame *);
929 extern void x_ewmh_activate_frame (struct frame *);
930 extern void x_delete_terminal (struct terminal *terminal);
931 extern unsigned long x_copy_color (struct frame *, unsigned long);
932 #ifdef USE_X_TOOLKIT
933 extern XtAppContext Xt_app_con;
934 extern void x_activate_timeout_atimer (void);
935 #endif
936 #ifdef USE_LUCID
937 extern bool x_alloc_lighter_color_for_widget (Widget, Display *, Colormap,
938 unsigned long *,
939 double, int);
940 #endif
941 extern bool x_alloc_nearest_color (struct frame *, Colormap, XColor *);
942 extern void x_query_color (struct frame *f, XColor *);
943 extern void x_clear_area (Display *, Window, int, int, int, int);
944 #if defined HAVE_MENUS && !defined USE_X_TOOLKIT && !defined USE_GTK
945 extern void x_mouse_leave (struct x_display_info *);
946 #endif
947
948 #ifdef USE_X_TOOLKIT
949 extern int x_dispatch_event (XEvent *, Display *);
950 #endif
951 extern int x_x_to_emacs_modifiers (struct x_display_info *, int);
952 extern int x_display_pixel_height (struct x_display_info *);
953 extern int x_display_pixel_width (struct x_display_info *);
954
955 extern void x_set_sticky (struct frame *, Lisp_Object, Lisp_Object);
956 extern void x_wait_for_event (struct frame *, int);
957
958 /* Defined in xselect.c */
959
960 extern void x_handle_property_notify (XPropertyEvent *);
961 extern void x_handle_selection_notify (XSelectionEvent *);
962 extern void x_handle_selection_event (struct input_event *);
963 extern void x_clear_frame_selections (struct frame *);
964
965 extern void x_send_client_event (Lisp_Object display,
966 Lisp_Object dest,
967 Lisp_Object from,
968 Atom message_type,
969 Lisp_Object format,
970 Lisp_Object values);
971
972 extern int x_handle_dnd_message (struct frame *,
973 XClientMessageEvent *,
974 struct x_display_info *,
975 struct input_event *bufp);
976 extern int x_check_property_data (Lisp_Object);
977 extern void x_fill_property_data (Display *,
978 Lisp_Object,
979 void *,
980 int);
981 extern Lisp_Object x_property_data_to_lisp (struct frame *,
982 const unsigned char *,
983 Atom,
984 int,
985 unsigned long);
986 extern void x_clipboard_manager_save_frame (Lisp_Object);
987 extern void x_clipboard_manager_save_all (void);
988
989 /* Defined in xfns.c */
990
991 extern struct x_display_info * check_x_display_info (Lisp_Object);
992 extern Lisp_Object x_get_focus_frame (struct frame *);
993
994 #ifdef USE_GTK
995 extern int xg_set_icon (struct frame *, Lisp_Object);
996 extern int xg_set_icon_from_xpm_data (struct frame *, const char**);
997 #endif /* USE_GTK */
998
999 extern void x_implicitly_set_name (struct frame *, Lisp_Object, Lisp_Object);
1000 extern void xic_free_xfontset (struct frame *);
1001 extern void create_frame_xic (struct frame *);
1002 extern void destroy_frame_xic (struct frame *);
1003 extern void xic_set_preeditarea (struct window *, int, int);
1004 extern void xic_set_statusarea (struct frame *);
1005 extern void xic_set_xfontset (struct frame *, const char *);
1006 extern bool x_defined_color (struct frame *, const char *, XColor *, bool);
1007 #ifdef HAVE_X_I18N
1008 extern void free_frame_xic (struct frame *);
1009 # if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
1010 extern char * xic_create_fontsetname (const char *base_fontname, int motif);
1011 # endif
1012 #endif
1013
1014 /* Defined in xfaces.c */
1015
1016 #ifdef USE_X_TOOLKIT
1017 extern void x_free_dpy_colors (Display *, Screen *, Colormap,
1018 unsigned long *, int);
1019 #endif /* USE_X_TOOLKIT */
1020
1021 /* Defined in xmenu.c */
1022
1023 #if defined USE_GTK || defined USE_MOTIF
1024 extern void x_menu_set_in_use (int);
1025 #endif
1026 #ifdef USE_MOTIF
1027 extern void x_menu_wait_for_event (void *data);
1028 #endif
1029 extern int popup_activated (void);
1030 extern void initialize_frame_menubar (struct frame *);
1031
1032 /* Defined in widget.c */
1033
1034 #ifdef USE_X_TOOLKIT
1035 extern void widget_store_internal_border (Widget);
1036 #endif
1037
1038 /* Defined in xsmfns.c */
1039 #ifdef HAVE_X_SM
1040 extern void x_session_initialize (struct x_display_info *dpyinfo);
1041 extern int x_session_have_connection (void);
1042 extern void x_session_close (void);
1043 #endif
1044
1045 /* Defined in xterm.c */
1046
1047 extern Lisp_Object Qx_gtk_map_stock;
1048
1049 /* Is the frame embedded into another application? */
1050
1051 #define FRAME_X_EMBEDDED_P(f) (FRAME_X_OUTPUT(f)->explicit_parent != 0)
1052
1053 #define STORE_XCHAR2B(chp, b1, b2) \
1054 ((chp)->byte1 = (b1), (chp)->byte2 = (b2))
1055
1056 #define XCHAR2B_BYTE1(chp) \
1057 ((chp)->byte1)
1058
1059 #define XCHAR2B_BYTE2(chp) \
1060 ((chp)->byte2)
1061
1062 #define STORE_NATIVE_RECT(nr,rx,ry,rwidth,rheight) \
1063 ((nr).x = (rx), \
1064 (nr).y = (ry), \
1065 (nr).width = (rwidth), \
1066 (nr).height = (rheight))
1067
1068 #endif /* XTERM_H */