1 /* Definitions and headers for communication with X protocol.
2 Copyright (C) 1989, 1993, 1994 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 #include <X11/cursorfont.h>
23 #include <X11/Xutil.h>
24 #include <X11/keysym.h>
25 #include <X11/Xatom.h>
26 #include <X11/Xresource.h>
32 #include <X11/StringDefs.h>
33 #include <X11/IntrinsicP.h> /* CoreP.h needs this */
34 #include <X11/CoreP.h> /* foul, but we need this to use our own
35 window inside a widget instead of one
37 #include <X11/StringDefs.h>
40 /* The class of this X application. */
41 #define EMACS_CLASS "Emacs"
43 /* Bookkeeping to distinguish X versions. */
45 /* HAVE_X11R4 is defined if we have the features of X11R4. It should
46 be defined when we're using X11R5, since X11R5 has the features of
47 X11R4. If, in the future, we find we need more of these flags
48 (HAVE_X11R5, for example), code should always be written to test
49 the most recent flag first:
59 If you ever find yourself writing a "#ifdef HAVE_FOO" clause that
60 looks a lot like another one, consider moving the text into a macro
61 whose definition is configuration-dependent, but whose usage is
62 universal - like the stuff in systime.h.
64 It turns out that we can auto-detect whether we're being compiled
65 with X11R3 or X11R4 by looking for the flag macros for R4 structure
66 members that R3 doesn't have. */
68 /* AIX 3.1's X is somewhere between X11R3 and X11R4. It has
69 PBaseSize, but not XWithdrawWindow, XSetWMName, XSetWMNormalHints,
71 AIX 3.2 is at least X11R4. */
72 #if (!defined AIX) || (defined AIX3_2)
77 #ifdef XlibSpecificationRelease
78 #if XlibSpecificationRelease >= 5
80 /* In case someone has X11R5 on AIX 3.1,
81 make sure HAVE_X11R4 is defined as well as HAVE_X11R5. */
86 #define BLACK_PIX_DEFAULT(f) BlackPixel (FRAME_X_DISPLAY (f), \
87 XScreenNumberOfScreen (FRAME_X_SCREEN (f)))
88 #define WHITE_PIX_DEFAULT(f) WhitePixel (FRAME_X_DISPLAY (f), \
89 XScreenNumberOfScreen (FRAME_X_SCREEN (f)))
91 #define FONT_WIDTH(f) ((f)->max_bounds.width)
92 #define FONT_HEIGHT(f) ((f)->ascent + (f)->descent)
93 #define FONT_BASE(f) ((f)->ascent)
95 #define CHECK_X_FRAME(f, frame) \
100 CHECK_LIVE_FRAME (frame, 0); \
101 f = XFRAME (frame); \
107 /* The mask of events that text windows always want to receive. This
108 does not include mouse movement events. It is used when the window
109 is created (in x_window) and and in selection processing.
111 We do include ButtonReleases in this set because Emacs isn't always
112 fast enough to catch them when it wants them, and they're rare
113 enough that they don't use much processor time. */
115 #define STANDARD_EVENT_SET \
119 | ButtonReleaseMask \
120 | PointerMotionMask \
121 | PointerMotionHintMask \
122 | StructureNotifyMask \
126 | VisibilityChangeMask)
128 /* This checks to make sure we have a display. */
129 extern void check_x ();
131 extern struct frame
*x_window_to_frame ();
134 extern struct frame
*x_any_window_to_frame ();
135 extern struct frame
*x_top_window_to_frame ();
138 /* The frame (if any) which has the X window that has keyboard focus.
139 Zero if none. This is examined by Ffocus_frame in xfns.c */
141 extern struct frame
*x_focus_frame
;
143 extern Visual
*select_visual ();
145 enum text_cursor_kinds
{
146 filled_box_cursor
, hollow_box_cursor
, bar_cursor
149 /* For each X display, we have a structure that records
150 information about it. */
152 struct x_display_info
154 /* Chain of all x_display structures. */
155 struct x_display_info
*next
;
156 /* Connection number (normally a file descriptor number). */
158 /* This says how to access this display in Xlib. */
160 /* This records previous values returned by x-list-fonts. */
161 Lisp_Object font_list_cache
;
162 /* The name of this display. */
164 /* Number of frames that are on this display. */
166 /* The Screen this connection is connected to. */
168 /* The Visual being used for this display. */
170 /* Number of panes on this screen. */
172 /* Dimensions of this screen. */
174 /* Mask of things that cause the mouse to be grabbed. */
176 /* Emacs bitmap-id of the default icon bitmap for this frame.
177 Or -1 if none has been allocated yet. */
179 /* The root window of this screen. */
182 /* X Resource data base */
185 /* Which modifier keys are on which modifier bits?
187 With each keystroke, X returns eight bits indicating which modifier
188 keys were held down when the key was pressed. The interpretation
189 of the top five modifier bits depends on what keys are attached
190 to them. If the Meta_L and Meta_R keysyms are on mod5, then mod5
193 meta_mod_mask is a mask containing the bits used for the meta key.
194 It may have more than one bit set, if more than one modifier bit
195 has meta keys on it. Basically, if EVENT is a KeyPress event,
196 the meta key is pressed if (EVENT.state & meta_mod_mask) != 0.
198 shift_lock_mask is LockMask if the XK_Shift_Lock keysym is on the
199 lock modifier bit, or zero otherwise. Non-alphabetic keys should
200 only be affected by the lock modifier bit if XK_Shift_Lock is in
201 use; XK_Caps_Lock should only affect alphabetic keys. With this
202 arrangement, the lock modifier should shift the character if
203 (EVENT.state & shift_lock_mask) != 0. */
204 int meta_mod_mask
, shift_lock_mask
;
206 /* These are like meta_mod_mask, but for different modifiers. */
207 int alt_mod_mask
, super_mod_mask
, hyper_mod_mask
;
209 /* Communication with window managers. */
210 Atom Xatom_wm_protocols
;
211 /* Kinds of protocol things we may receive. */
212 Atom Xatom_wm_take_focus
;
213 Atom Xatom_wm_save_yourself
;
214 Atom Xatom_wm_delete_window
;
215 /* Atom for indicating window state to the window manager. */
216 Atom Xatom_wm_change_state
;
217 /* Other WM communication */
218 Atom Xatom_wm_configure_denied
; /* When our config request is denied */
219 Atom Xatom_wm_window_moved
; /* When the WM moves us. */
220 /* EditRes protocol */
223 /* More atoms, which are selection types. */
224 Atom Xatom_CLIPBOARD
, Xatom_TIMESTAMP
, Xatom_TEXT
, Xatom_DELETE
,
225 Xatom_MULTIPLE
, Xatom_INCR
, Xatom_EMACS_TMP
, Xatom_TARGETS
, Xatom_NULL
,
229 /* This is a chain of structures for all the X displays currently in use. */
230 extern struct x_display_info
*x_display_list
;
232 extern struct x_display_info
*x_display_info_for_display ();
233 extern struct x_display_info
*x_display_info_for_name ();
235 extern struct x_display_info
*x_term_init ();
237 /* Each X frame object points to its own struct x_display object
238 in the display.x field. The x_display structure contains all
239 the information that is specific to X windows. */
243 /* Position of the X window (x and y offsets in root window). */
247 /* Border width of the X window as known by the X window system. */
250 /* Size of the X window in pixels. */
251 int pixel_height
, pixel_width
;
253 /* Height of a line, in pixels. */
257 /* The tiled border used when the mouse is out of the frame. */
260 /* Here are the Graphics Contexts for the default font. */
261 GC normal_gc
; /* Normal video */
262 GC reverse_gc
; /* Reverse video */
263 GC cursor_gc
; /* cursor drawing */
264 #endif /* HAVE_X11 */
266 /* Width of the internal border. This is a line of background color
267 just inside the window's border. When the frame is selected,
268 a highlighting is displayed inside the internal border. */
269 int internal_border_width
;
271 /* The X window used for this frame.
272 May be zero while the frame object is being created
273 and the X window has not yet been created. */
276 /* The X window used for the bitmap icon;
277 or 0 if we don't have a bitmap icon. */
280 /* The X window that is the parent of this X window.
281 Usually but not always RootWindow. */
285 /* The widget of this screen. This is the window of a "shell" widget. */
287 /* The XmPanedWindows... */
288 Widget column_widget
;
289 /* The widget of the edit portion of this screen; the window in
290 "window_desc" is inside of this. */
293 Widget menubar_widget
;
296 /* If >=0, a bitmap index. The indicated bitmap is used for the
302 /* Pixel values used for various purposes.
303 border_pixel may be -1 meaning use a gray tile. */
304 unsigned long background_pixel
;
305 unsigned long foreground_pixel
;
306 unsigned long cursor_pixel
;
307 unsigned long border_pixel
;
308 unsigned long mouse_pixel
;
309 unsigned long cursor_foreground_pixel
;
311 /* Descriptor for the cursor in use for this window. */
314 Cursor nontext_cursor
;
315 Cursor modeline_cursor
;
321 /* The name that was associated with the icon, the last time
322 it was refreshed. Usually the same as the name of the
323 buffer in the currently selected window in the frame */
326 /* Flag to set when the X window needs to be completely repainted. */
329 /* What kind of text cursor is drawn in this window right now?
330 (If there is no cursor (phys_cursor_x < 0), then this means nothing.) */
331 enum text_cursor_kinds current_cursor
;
333 /* What kind of text cursor should we draw in the future?
334 This should always be filled_box_cursor or bar_cursor. */
335 enum text_cursor_kinds desired_cursor
;
337 /* These are the current window manager hints. It seems that
338 XSetWMHints, when presented with an unset bit in the `flags'
339 member of the hints structure, does not leave the corresponding
340 attribute unchanged; rather, it resets that attribute to its
341 default value. For example, unless you set the `icon_pixmap'
342 field and the `IconPixmapHint' bit, XSetWMHints will forget what
343 your icon pixmap was. This is rather troublesome, since some of
344 the members (for example, `input' and `icon_pixmap') want to stay
345 the same throughout the execution of Emacs. So, we keep this
346 structure around, just leaving values in it and adding new bits
347 to the mask as we go. */
350 /* The size of the extra width currently allotted for vertical
351 scroll bars, in pixels. */
352 int vertical_scroll_bar_extra
;
354 /* Table of parameter faces for this frame. Any X resources (pixel
355 values, fonts) referred to here have been allocated explicitly
356 for this face, and should be freed if we change the face. */
357 struct face
**param_faces
;
360 /* Table of computed faces for this frame. These are the faces
361 whose indexes go into the upper bits of a glyph, computed by
362 combining the parameter faces specified by overlays, text
363 properties, and what have you. The X resources mentioned here
364 are all shared with parameter faces. */
365 struct face
**computed_faces
;
366 int n_computed_faces
; /* How many are valid */
367 int size_computed_faces
; /* How many are allocated */
369 /* This is the gravity value for the specified window position. */
372 /* The geometry flags for this window. */
375 /* This is the Emacs structure for the X display this frame is on. */
376 struct x_display_info
*display_info
;
379 /* Get at the computed faces of an X window frame. */
380 #define FRAME_PARAM_FACES(f) ((f)->display.x->param_faces)
381 #define FRAME_N_PARAM_FACES(f) ((f)->display.x->n_param_faces)
382 #define FRAME_DEFAULT_PARAM_FACE(f) (FRAME_PARAM_FACES (f)[0])
383 #define FRAME_MODE_LINE_PARAM_FACE(f) (FRAME_PARAM_FACES (f)[1])
385 #define FRAME_COMPUTED_FACES(f) ((f)->display.x->computed_faces)
386 #define FRAME_N_COMPUTED_FACES(f) ((f)->display.x->n_computed_faces)
387 #define FRAME_SIZE_COMPUTED_FACES(f) ((f)->display.x->size_computed_faces)
388 #define FRAME_DEFAULT_FACE(f) ((f)->display.x->computed_faces[0])
389 #define FRAME_MODE_LINE_FACE(f) ((f)->display.x->computed_faces[1])
391 /* Return the window associated with the frame F. */
392 #define FRAME_X_WINDOW(f) ((f)->display.x->window_desc)
394 #define FRAME_FOREGROUND_PIXEL(f) ((f)->display.x->foreground_pixel)
395 #define FRAME_BACKGROUND_PIXEL(f) ((f)->display.x->background_pixel)
396 #define FRAME_FONT(f) ((f)->display.x->font)
398 /* This gives the x_display_info structure for the display F is on. */
399 #define FRAME_X_DISPLAY_INFO(f) ((f)->display.x->display_info)
401 /* This is the `Display *' which frame F is on. */
402 #define FRAME_X_DISPLAY(f) (FRAME_X_DISPLAY_INFO (f)->display)
404 /* This is the `Screen *' which frame F is on. */
405 #define FRAME_X_SCREEN(f) (FRAME_X_DISPLAY_INFO (f)->screen)
407 /* These two really ought to be called FRAME_PIXEL_{WIDTH,HEIGHT}. */
408 #define PIXEL_WIDTH(f) ((f)->display.x->pixel_width)
409 #define PIXEL_HEIGHT(f) ((f)->display.x->pixel_height)
411 #define FRAME_DESIRED_CURSOR(f) ((f)->display.x->desired_cursor)
414 /* X-specific scroll bar stuff. */
416 /* We represent scroll bars as lisp vectors. This allows us to place
417 references to them in windows without worrying about whether we'll
418 end up with windows referring to dead scroll bars; the garbage
419 collector will free it when its time comes.
421 We use struct scroll_bar as a template for accessing fields of the
426 /* These fields are shared by all vectors. */
427 EMACS_INT size_from_Lisp_Vector_struct
;
428 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
430 /* The window we're a scroll bar for. */
433 /* The next and previous in the chain of scroll bars in this frame. */
434 Lisp_Object next
, prev
;
436 /* The X window representing this scroll bar. Since this is a full
437 32-bit quantity, we store it split into two 32-bit values. */
438 Lisp_Object x_window_low
, x_window_high
;
440 /* The position and size of the scroll bar in pixels, relative to the
442 Lisp_Object top
, left
, width
, height
;
444 /* The starting and ending positions of the handle, relative to the
445 handle area (i.e. zero is the top position, not
446 SCROLL_BAR_TOP_BORDER). If they're equal, that means the handle
447 hasn't been drawn yet.
449 These are not actually the locations where the beginning and end
450 are drawn; in order to keep handles from becoming invisible when
451 editing large files, we establish a minimum height by always
452 drawing handle bottoms VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
453 where they would be normally; the bottom and top are in a
454 different co-ordinate system. */
455 Lisp_Object start
, end
;
457 /* If the scroll bar handle is currently being dragged by the user,
458 this is the number of pixels from the top of the handle to the
459 place where the user grabbed it. If the handle isn't currently
460 being dragged, this is Qnil. */
461 Lisp_Object dragging
;
464 /* The number of elements a vector holding a struct scroll_bar needs. */
465 #define SCROLL_BAR_VEC_SIZE \
466 ((sizeof (struct scroll_bar) - sizeof (EMACS_INT) - sizeof (struct Lisp_Vector *)) \
467 / sizeof (Lisp_Object))
469 /* Turning a lisp vector value into a pointer to a struct scroll_bar. */
470 #define XSCROLL_BAR(vec) ((struct scroll_bar *) XPNTR (vec))
473 /* Building a 32-bit C integer from two 16-bit lisp integers. */
474 #define SCROLL_BAR_PACK(low, high) (XINT (high) << 16 | XINT (low))
476 /* Setting two lisp integers to the low and high words of a 32-bit C int. */
477 #define SCROLL_BAR_UNPACK(low, high, int32) \
478 (XSETINT ((low), (int32) & 0xffff), \
479 XSETINT ((high), ((int32) >> 16) & 0xffff))
482 /* Extract the X window id of the scroll bar from a struct scroll_bar. */
483 #define SCROLL_BAR_X_WINDOW(ptr) \
484 ((Window) SCROLL_BAR_PACK ((ptr)->x_window_low, (ptr)->x_window_high))
486 /* Store a window id in a struct scroll_bar. */
487 #define SET_SCROLL_BAR_X_WINDOW(ptr, id) \
488 (SCROLL_BAR_UNPACK ((ptr)->x_window_low, (ptr)->x_window_high, (int) id))
491 /* Return the outside pixel height for a vertical scroll bar HEIGHT
492 rows high on frame F. */
493 #define VERTICAL_SCROLL_BAR_PIXEL_HEIGHT(f, height) \
494 ((height) * (f)->display.x->line_height)
496 /* Return the inside width of a vertical scroll bar, given the outside
498 #define VERTICAL_SCROLL_BAR_INSIDE_WIDTH(width) \
499 ((width) - VERTICAL_SCROLL_BAR_LEFT_BORDER - VERTICAL_SCROLL_BAR_RIGHT_BORDER)
501 /* Return the length of the rectangle within which the top of the
502 handle must stay. This isn't equivalent to the inside height,
503 because the scroll bar handle has a minimum height.
505 This is the real range of motion for the scroll bar, so when we're
506 scaling buffer positions to scroll bar positions, we use this, not
507 VERTICAL_SCROLL_BAR_INSIDE_HEIGHT. */
508 #define VERTICAL_SCROLL_BAR_TOP_RANGE(height) \
509 (VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (height) - VERTICAL_SCROLL_BAR_MIN_HANDLE)
511 /* Return the inside height of vertical scroll bar, given the outside
512 height. See VERTICAL_SCROLL_BAR_TOP_RANGE too. */
513 #define VERTICAL_SCROLL_BAR_INSIDE_HEIGHT(height) \
514 ((height) - VERTICAL_SCROLL_BAR_TOP_BORDER - VERTICAL_SCROLL_BAR_BOTTOM_BORDER)
517 /* Border widths for scroll bars.
519 Scroll bar windows don't have any X borders; their border width is
520 set to zero, and we redraw borders ourselves. This makes the code
521 a bit cleaner, since we don't have to convert between outside width
522 (used when relating to the rest of the screen) and inside width
523 (used when sizing and drawing the scroll bar window itself).
525 The handle moves up and down/back and forth in a rectangle inset
526 from the edges of the scroll bar. These are widths by which we
527 inset the handle boundaries from the scroll bar edges. */
528 #define VERTICAL_SCROLL_BAR_LEFT_BORDER (2)
529 #define VERTICAL_SCROLL_BAR_RIGHT_BORDER (2)
530 #define VERTICAL_SCROLL_BAR_TOP_BORDER (2)
531 #define VERTICAL_SCROLL_BAR_BOTTOM_BORDER (2)
533 /* Minimum lengths for scroll bar handles, in pixels. */
534 #define VERTICAL_SCROLL_BAR_MIN_HANDLE (5)
537 /* Manipulating pixel sizes and character sizes.
538 Knowledge of which factors affect the overall size of the window should
539 be hidden in these macros, if that's possible.
541 Return the upper/left pixel position of the character cell on frame F
543 #define CHAR_TO_PIXEL_ROW(f, row) \
544 ((f)->display.x->internal_border_width \
545 + (row) * (f)->display.x->line_height)
546 #define CHAR_TO_PIXEL_COL(f, col) \
547 ((f)->display.x->internal_border_width \
548 + (col) * FONT_WIDTH ((f)->display.x->font))
550 /* Return the pixel width/height of frame F if it has
551 WIDTH columns/HEIGHT rows. */
552 #define CHAR_TO_PIXEL_WIDTH(f, width) \
553 (CHAR_TO_PIXEL_COL (f, width) \
554 + (f)->display.x->vertical_scroll_bar_extra \
555 + (f)->display.x->internal_border_width)
556 #define CHAR_TO_PIXEL_HEIGHT(f, height) \
557 (CHAR_TO_PIXEL_ROW (f, height) \
558 + (f)->display.x->internal_border_width)
561 /* Return the row/column (zero-based) of the character cell containing
562 the pixel on FRAME at ROW/COL. */
563 #define PIXEL_TO_CHAR_ROW(f, row) \
564 (((row) - (f)->display.x->internal_border_width) \
565 / (f)->display.x->line_height)
566 #define PIXEL_TO_CHAR_COL(f, col) \
567 (((col) - (f)->display.x->internal_border_width) \
568 / FONT_WIDTH ((f)->display.x->font))
570 /* How many columns/rows of text can we fit in WIDTH/HEIGHT pixels on
572 #define PIXEL_TO_CHAR_WIDTH(f, width) \
573 (PIXEL_TO_CHAR_COL (f, ((width) \
574 - (f)->display.x->internal_border_width \
575 - (f)->display.x->vertical_scroll_bar_extra)))
576 #define PIXEL_TO_CHAR_HEIGHT(f, height) \
577 (PIXEL_TO_CHAR_ROW (f, ((height) \
578 - (f)->display.x->internal_border_width)))
580 /* If a struct input_event has a kind which is selection_request_event
581 or selection_clear_event, then its contents are really described
582 by this structure. */
584 /* For an event of kind selection_request_event,
585 this structure really describes the contents. */
586 struct selection_input_event
591 Atom selection
, target
, property
;
595 #define SELECTION_EVENT_DISPLAY(eventp) \
596 (((struct selection_input_event *) (eventp))->display)
597 #define SELECTION_EVENT_REQUESTOR(eventp) \
598 (((struct selection_input_event *) (eventp))->requestor)
599 #define SELECTION_EVENT_SELECTION(eventp) \
600 (((struct selection_input_event *) (eventp))->selection)
601 #define SELECTION_EVENT_TARGET(eventp) \
602 (((struct selection_input_event *) (eventp))->target)
603 #define SELECTION_EVENT_PROPERTY(eventp) \
604 (((struct selection_input_event *) (eventp))->property)
605 #define SELECTION_EVENT_TIME(eventp) \
606 (((struct selection_input_event *) (eventp))->time)
609 /* Interface to the face code functions. */
611 /* Create the first two computed faces for a frame -- the ones that
613 extern void init_frame_faces (/* FRAME_PTR */);
615 /* Free the resources for the faces associated with a frame. */
616 extern void free_frame_faces (/* FRAME_PTR */);
618 /* Given a computed face, find or make an equivalent display face
619 in face_vector, and return a pointer to it. */
620 extern struct face
*intern_face (/* FRAME_PTR, struct face * */);
622 /* Given a frame and a face name, return the face's ID number, or
623 zero if it isn't a recognized face name. */
624 extern int face_name_id_number (/* FRAME_PTR, Lisp_Object */);
626 /* Return non-zero if FONT1 and FONT2 have the same size bounding box.
627 We assume that they're both character-cell fonts. */
628 extern int same_size_fonts (/* XFontStruct *, XFontStruct * */);
630 /* Recompute the GC's for the default and modeline faces.
631 We call this after changing frame parameters on which those GC's
633 extern void recompute_basic_faces (/* FRAME_PTR */);
635 /* Return the face ID associated with a buffer position POS. Store
636 into *ENDPTR the next position at which a different face is
637 needed. This does not take account of glyphs that specify their
638 own face codes. F is the frame in use for display, and W is a
639 window displaying the current buffer.
641 REGION_BEG, REGION_END delimit the region, so it can be highlighted. */
642 extern int compute_char_face (/* FRAME_PTR frame,
645 int region_beg, int region_end,
647 /* Return the face ID to use to display a special glyph which selects
648 FACE_CODE as the face ID, assuming that ordinarily the face would
649 be BASIC_FACE. F is the frame. */
650 extern int compute_glyph_face (/* FRAME_PTR, int */);