1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 93, 94, 95, 96, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New display code by Gerd Moellmann <gerd@gnu.org>. */
23 /* Xt features made by Fred Pierresteguy. */
27 /* On 4.3 these lose if they come after xterm.h. */
28 /* Putting these at the beginning seems to be standard for other .c files. */
36 #include "blockinput.h"
38 /* Need syssignal.h for various externs and definitions that may be required
39 by some configurations for calls to signal later in this source file. */
40 #include "syssignal.h"
42 /* This may include sys/types.h, and that somehow loses
43 if this is not done before the other system files. */
45 #include <X11/cursorfont.h>
47 /* Load sys/types.h if not already loaded.
48 In some systems loading it twice is suicidal. */
50 #include <sys/types.h>
54 #include <sys/ioctl.h>
55 #endif /* ! defined (BSD_SYSTEM) */
60 #ifndef INCLUDED_FCNTL
67 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
68 /* #include <sys/param.h> */
74 #include "dispextern.h"
76 #include "termhooks.h"
84 #include "intervals.h"
90 #include <X11/Shell.h>
93 #ifdef HAVE_SYS_TIME_H
101 extern int xlwmenu_window_p (Widget w
, Window window
);
102 extern void xlwmenu_redisplay
P_ ((Widget
));
107 extern void free_frame_menubar
P_ ((struct frame
*));
108 extern struct frame
*x_menubar_window_to_frame
P_ ((struct x_display_info
*,
111 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
113 extern void _XEditResCheckMessages ();
114 #endif /* not NO_EDITRES */
116 /* Include toolkit specific headers for the scroll bar widget. */
118 #ifdef USE_TOOLKIT_SCROLL_BARS
119 #if defined USE_MOTIF
120 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
121 #include <Xm/ScrollBar.h>
122 #else /* !USE_MOTIF i.e. use Xaw */
125 #include <X11/Xaw3d/Simple.h>
126 #include <X11/Xaw3d/Scrollbar.h>
127 #define ARROW_SCROLLBAR
128 #include <X11/Xaw3d/ScrollbarP.h>
129 #else /* !HAVE_XAW3D */
130 #include <X11/Xaw/Simple.h>
131 #include <X11/Xaw/Scrollbar.h>
132 #endif /* !HAVE_XAW3D */
134 #define XtNpickTop "pickTop"
135 #endif /* !XtNpickTop */
136 #endif /* !USE_MOTIF */
137 #endif /* USE_TOOLKIT_SCROLL_BARS */
139 #endif /* USE_X_TOOLKIT */
141 #ifndef USE_X_TOOLKIT
142 #define x_any_window_to_frame x_window_to_frame
143 #define x_top_window_to_frame x_window_to_frame
148 #ifndef XtNinitialState
149 #define XtNinitialState "initialState"
153 #define abs(x) ((x) < 0 ? -(x) : (x))
155 #define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER))
158 /* Fringe bitmaps. */
160 enum fringe_bitmap_type
163 LEFT_TRUNCATION_BITMAP
,
164 RIGHT_TRUNCATION_BITMAP
,
165 OVERLAY_ARROW_BITMAP
,
166 CONTINUED_LINE_BITMAP
,
167 CONTINUATION_LINE_BITMAP
,
171 /* Bitmap drawn to indicate lines not displaying text if
172 `indicate-empty-lines' is non-nil. */
177 static unsigned char zv_bits
[] = {
178 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
179 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
180 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
181 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
182 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
183 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
184 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
185 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00};
187 /* An arrow like this: `<-'. */
190 #define left_height 8
191 static unsigned char left_bits
[] = {
192 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
194 /* Right truncation arrow bitmap `->'. */
196 #define right_width 8
197 #define right_height 8
198 static unsigned char right_bits
[] = {
199 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
201 /* Marker for continued lines. */
203 #define continued_width 8
204 #define continued_height 8
205 static unsigned char continued_bits
[] = {
206 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
208 /* Marker for continuation lines. */
210 #define continuation_width 8
211 #define continuation_height 8
212 static unsigned char continuation_bits
[] = {
213 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
215 /* Overlay arrow bitmap. */
221 static unsigned char ov_bits
[] = {
222 0x30, 0x08, 0x3c, 0x7e, 0x7a, 0x7a, 0x62, 0x3c};
224 /* A triangular arrow. */
227 static unsigned char ov_bits
[] = {
228 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
232 extern Lisp_Object Qhelp_echo
;
235 /* Non-nil means Emacs uses toolkit scroll bars. */
237 Lisp_Object Vx_toolkit_scroll_bars
;
239 /* If a string, XTread_socket generates an event to display that string.
240 (The display is done in read_char.) */
242 static Lisp_Object help_echo
;
243 static Lisp_Object help_echo_window
;
244 static Lisp_Object help_echo_object
;
245 static int help_echo_pos
;
247 /* Temporary variable for XTread_socket. */
249 static Lisp_Object previous_help_echo
;
251 /* Non-zero means that a HELP_EVENT has been generated since Emacs
254 static int any_help_event_p
;
256 /* Non-zero means autoselect window with the mouse cursor. */
258 int autoselect_window_p
;
260 /* Last window where we saw the mouse. Used by autoselect-window. */
261 static Lisp_Object last_window
;
263 /* Non-zero means draw block and hollow cursor as wide as the glyph
264 under it. For example, if a block cursor is over a tab, it will be
265 drawn as wide as that tab on the display. */
267 int x_stretch_cursor_p
;
269 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
271 int x_use_underline_position_properties
;
273 /* This is a chain of structures for all the X displays currently in
276 struct x_display_info
*x_display_list
;
278 /* This is a list of cons cells, each of the form (NAME
279 . FONT-LIST-CACHE), one for each element of x_display_list and in
280 the same order. NAME is the name of the frame. FONT-LIST-CACHE
281 records previous values returned by x-list-fonts. */
283 Lisp_Object x_display_name_list
;
285 /* Frame being updated by update_frame. This is declared in term.c.
286 This is set by update_begin and looked at by all the XT functions.
287 It is zero while not inside an update. In that case, the XT
288 functions assume that `selected_frame' is the frame to apply to. */
290 extern struct frame
*updating_frame
;
292 /* This is a frame waiting to be auto-raised, within XTread_socket. */
294 struct frame
*pending_autoraise_frame
;
297 /* The application context for Xt use. */
298 XtAppContext Xt_app_con
;
299 static String Xt_default_resources
[] = {0};
300 #endif /* USE_X_TOOLKIT */
302 /* Nominal cursor position -- where to draw output.
303 HPOS and VPOS are window relative glyph matrix coordinates.
304 X and Y are window relative pixel coordinates. */
306 struct cursor_pos output_cursor
;
308 /* Non-zero means user is interacting with a toolkit scroll bar. */
310 static int toolkit_scroll_bar_interaction
;
314 Formerly, we used PointerMotionHintMask (in standard_event_mask)
315 so that we would have to call XQueryPointer after each MotionNotify
316 event to ask for another such event. However, this made mouse tracking
317 slow, and there was a bug that made it eventually stop.
319 Simply asking for MotionNotify all the time seems to work better.
321 In order to avoid asking for motion events and then throwing most
322 of them away or busy-polling the server for mouse positions, we ask
323 the server for pointer motion hints. This means that we get only
324 one event per group of mouse movements. "Groups" are delimited by
325 other kinds of events (focus changes and button clicks, for
326 example), or by XQueryPointer calls; when one of these happens, we
327 get another MotionNotify event the next time the mouse moves. This
328 is at least as efficient as getting motion events when mouse
329 tracking is on, and I suspect only negligibly worse when tracking
332 /* Where the mouse was last time we reported a mouse event. */
334 FRAME_PTR last_mouse_frame
;
335 static XRectangle last_mouse_glyph
;
336 static Lisp_Object last_mouse_press_frame
;
338 /* The scroll bar in which the last X motion event occurred.
340 If the last X motion event occurred in a scroll bar, we set this so
341 XTmouse_position can know whether to report a scroll bar motion or
344 If the last X motion event didn't occur in a scroll bar, we set
345 this to Qnil, to tell XTmouse_position to return an ordinary motion
348 static Lisp_Object last_mouse_scroll_bar
;
350 /* This is a hack. We would really prefer that XTmouse_position would
351 return the time associated with the position it returns, but there
352 doesn't seem to be any way to wrest the time-stamp from the server
353 along with the position query. So, we just keep track of the time
354 of the last movement we received, and return that in hopes that
355 it's somewhat accurate. */
357 static Time last_mouse_movement_time
;
359 /* Incremented by XTread_socket whenever it really tries to read
363 static int volatile input_signal_count
;
365 static int input_signal_count
;
368 /* Used locally within XTread_socket. */
370 static int x_noop_count
;
372 /* Initial values of argv and argc. */
374 extern char **initial_argv
;
375 extern int initial_argc
;
377 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
379 /* Tells if a window manager is present or not. */
381 extern Lisp_Object Vx_no_window_manager
;
383 extern Lisp_Object Qface
, Qmouse_face
;
387 /* A mask of extra modifier bits to put into every keyboard char. */
389 extern EMACS_INT extra_keyboard_modifiers
;
391 /* The keysyms to use for the various modifiers. */
393 Lisp_Object Vx_alt_keysym
, Vx_hyper_keysym
, Vx_meta_keysym
, Vx_super_keysym
;
394 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
396 static Lisp_Object Qvendor_specific_keysyms
;
398 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
399 extern Lisp_Object x_icon_type
P_ ((struct frame
*));
402 /* Enumeration for overriding/changing the face to use for drawing
403 glyphs in x_draw_glyphs. */
405 enum draw_glyphs_face
415 static int cursor_in_mouse_face_p
P_ ((struct window
*));
416 static int clear_mouse_face
P_ ((struct x_display_info
*));
417 static int x_alloc_nearest_color_1
P_ ((Display
*, Colormap
, XColor
*));
418 static void x_set_window_size_1
P_ ((struct frame
*, int, int, int));
419 static const XColor
*x_color_cells
P_ ((Display
*, int *));
420 static void x_update_window_end
P_ ((struct window
*, int, int));
421 static void frame_to_window_pixel_xy
P_ ((struct window
*, int *, int *));
422 void x_delete_display
P_ ((struct x_display_info
*));
423 static unsigned int x_x_to_emacs_modifiers
P_ ((struct x_display_info
*,
425 static int fast_find_position
P_ ((struct window
*, int, int *, int *,
426 int *, int *, Lisp_Object
));
427 static int fast_find_string_pos
P_ ((struct window
*, int, Lisp_Object
,
428 int *, int *, int *, int *, int));
429 static void set_output_cursor
P_ ((struct cursor_pos
*));
430 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
431 int *, int *, int *, int));
432 static void note_mode_line_highlight
P_ ((struct window
*, int, int));
433 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
434 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
435 static void x_handle_tool_bar_click
P_ ((struct frame
*, XButtonEvent
*));
436 static void show_mouse_face
P_ ((struct x_display_info
*,
437 enum draw_glyphs_face
));
438 static int x_io_error_quitter
P_ ((Display
*));
439 int x_catch_errors
P_ ((Display
*));
440 void x_uncatch_errors
P_ ((Display
*, int));
441 void x_lower_frame
P_ ((struct frame
*));
442 void x_scroll_bar_clear
P_ ((struct frame
*));
443 int x_had_errors_p
P_ ((Display
*));
444 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
445 void x_raise_frame
P_ ((struct frame
*));
446 void x_set_window_size
P_ ((struct frame
*, int, int, int));
447 void x_wm_set_window_state
P_ ((struct frame
*, int));
448 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
449 void x_initialize
P_ ((void));
450 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
451 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
452 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
454 enum draw_glyphs_face
));
455 static void x_update_end
P_ ((struct frame
*));
456 static void XTframe_up_to_date
P_ ((struct frame
*));
457 static void XTset_terminal_modes
P_ ((void));
458 static void XTreset_terminal_modes
P_ ((void));
459 static void XTcursor_to
P_ ((int, int, int, int));
460 static void x_write_glyphs
P_ ((struct glyph
*, int));
461 static void x_clear_end_of_line
P_ ((int));
462 static void x_clear_frame
P_ ((void));
463 static void x_clear_cursor
P_ ((struct window
*));
464 static void frame_highlight
P_ ((struct frame
*));
465 static void frame_unhighlight
P_ ((struct frame
*));
466 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
467 static void XTframe_rehighlight
P_ ((struct frame
*));
468 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
469 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
470 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int));
471 static int x_intersect_rectangles
P_ ((XRectangle
*, XRectangle
*,
473 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
474 static int expose_window_tree
P_ ((struct window
*, XRectangle
*));
475 static int expose_window
P_ ((struct window
*, XRectangle
*));
476 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
477 XRectangle
*, enum glyph_row_area
));
478 static int expose_line
P_ ((struct window
*, struct glyph_row
*,
480 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
481 static void x_update_window_cursor
P_ ((struct window
*, int));
482 static void x_erase_phys_cursor
P_ ((struct window
*));
483 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
484 static void x_draw_fringe_bitmap
P_ ((struct window
*, struct glyph_row
*,
485 enum fringe_bitmap_type
, int left_p
));
487 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
489 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, XRectangle
*));
490 static void x_draw_row_fringe_bitmaps
P_ ((struct window
*, struct glyph_row
*));
491 static void notice_overwritten_cursor
P_ ((struct window
*, enum glyph_row_area
,
492 int, int, int, int));
493 static void x_flush
P_ ((struct frame
*f
));
494 static void x_update_begin
P_ ((struct frame
*));
495 static void x_update_window_begin
P_ ((struct window
*));
496 static void x_draw_vertical_border
P_ ((struct window
*));
497 static void x_after_update_window_line
P_ ((struct glyph_row
*));
498 static INLINE
void take_vertical_position_into_account
P_ ((struct it
*));
499 static void x_produce_stretch_glyph
P_ ((struct it
*));
500 static struct scroll_bar
*x_window_to_scroll_bar
P_ ((Window
));
501 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
502 enum scroll_bar_part
*,
503 Lisp_Object
*, Lisp_Object
*,
505 static void x_check_fullscreen
P_ ((struct frame
*));
506 static void x_check_fullscreen_move
P_ ((struct frame
*));
508 /* Flush display of frame F, or of all frames if F is null. */
517 Lisp_Object rest
, frame
;
518 FOR_EACH_FRAME (rest
, frame
)
519 x_flush (XFRAME (frame
));
521 else if (FRAME_X_P (f
))
522 XFlush (FRAME_X_DISPLAY (f
));
527 /* Remove calls to XFlush by defining XFlush to an empty replacement.
528 Calls to XFlush should be unnecessary because the X output buffer
529 is flushed automatically as needed by calls to XPending,
530 XNextEvent, or XWindowEvent according to the XFlush man page.
531 XTread_socket calls XPending. Removing XFlush improves
534 #define XFlush(DISPLAY) (void) 0
537 /***********************************************************************
539 ***********************************************************************/
543 /* This is a function useful for recording debugging information about
544 the sequence of occurrences in this file. */
552 struct record event_record
[100];
554 int event_record_index
;
556 record_event (locus
, type
)
560 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
561 event_record_index
= 0;
563 event_record
[event_record_index
].locus
= locus
;
564 event_record
[event_record_index
].type
= type
;
565 event_record_index
++;
572 /* Return the struct x_display_info corresponding to DPY. */
574 struct x_display_info
*
575 x_display_info_for_display (dpy
)
578 struct x_display_info
*dpyinfo
;
580 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
581 if (dpyinfo
->display
== dpy
)
589 /***********************************************************************
590 Starting and ending an update
591 ***********************************************************************/
593 /* Start an update of frame F. This function is installed as a hook
594 for update_begin, i.e. it is called when update_begin is called.
595 This function is called prior to calls to x_update_window_begin for
596 each window being updated. Currently, there is nothing to do here
597 because all interesting stuff is done on a window basis. */
607 /* Start update of window W. Set the global variable updated_window
608 to the window being updated and set output_cursor to the cursor
612 x_update_window_begin (w
)
615 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
616 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
619 set_output_cursor (&w
->cursor
);
623 if (f
== display_info
->mouse_face_mouse_frame
)
625 /* Don't do highlighting for mouse motion during the update. */
626 display_info
->mouse_face_defer
= 1;
628 /* If F needs to be redrawn, simply forget about any prior mouse
630 if (FRAME_GARBAGED_P (f
))
631 display_info
->mouse_face_window
= Qnil
;
633 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
634 their mouse_face_p flag set, which means that they are always
635 unequal to rows in a desired matrix which never have that
636 flag set. So, rows containing mouse-face glyphs are never
637 scrolled, and we don't have to switch the mouse highlight off
638 here to prevent it from being scrolled. */
640 /* Can we tell that this update does not affect the window
641 where the mouse highlight is? If so, no need to turn off.
642 Likewise, don't do anything if the frame is garbaged;
643 in that case, the frame's current matrix that we would use
644 is all wrong, and we will redisplay that line anyway. */
645 if (!NILP (display_info
->mouse_face_window
)
646 && w
== XWINDOW (display_info
->mouse_face_window
))
650 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
651 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
654 if (i
< w
->desired_matrix
->nrows
)
655 clear_mouse_face (display_info
);
664 /* Draw a vertical window border to the right of window W if W doesn't
665 have vertical scroll bars. */
668 x_draw_vertical_border (w
)
671 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
673 /* Redraw borders between horizontally adjacent windows. Don't
674 do it for frames with vertical scroll bars because either the
675 right scroll bar of a window, or the left scroll bar of its
676 neighbor will suffice as a border. */
677 if (!WINDOW_RIGHTMOST_P (w
)
678 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
682 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
683 x1
+= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
686 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
687 f
->output_data
.x
->normal_gc
, x1
, y0
, x1
, y1
);
692 /* End update of window W (which is equal to updated_window).
694 Draw vertical borders between horizontally adjacent windows, and
695 display W's cursor if CURSOR_ON_P is non-zero.
697 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
698 glyphs in mouse-face were overwritten. In that case we have to
699 make sure that the mouse-highlight is properly redrawn.
701 W may be a menu bar pseudo-window in case we don't have X toolkit
702 support. Such windows don't have a cursor, so don't display it
706 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
708 int cursor_on_p
, mouse_face_overwritten_p
;
710 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
712 if (!w
->pseudo_window_p
)
717 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
719 output_cursor
.x
, output_cursor
.y
);
721 x_draw_vertical_border (w
);
725 /* If a row with mouse-face was overwritten, arrange for
726 XTframe_up_to_date to redisplay the mouse highlight. */
727 if (mouse_face_overwritten_p
)
729 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
730 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
731 dpyinfo
->mouse_face_window
= Qnil
;
734 updated_window
= NULL
;
738 /* End update of frame F. This function is installed as a hook in
745 /* Mouse highlight may be displayed again. */
746 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
749 XFlush (FRAME_X_DISPLAY (f
));
754 /* This function is called from various places in xdisp.c whenever a
755 complete update has been performed. The global variable
756 updated_window is not available here. */
759 XTframe_up_to_date (f
)
764 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
766 if (dpyinfo
->mouse_face_deferred_gc
767 || f
== dpyinfo
->mouse_face_mouse_frame
)
770 if (dpyinfo
->mouse_face_mouse_frame
)
771 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
772 dpyinfo
->mouse_face_mouse_x
,
773 dpyinfo
->mouse_face_mouse_y
);
774 dpyinfo
->mouse_face_deferred_gc
= 0;
781 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
782 arrow bitmaps, or clear the fringes if no bitmaps are required
783 before DESIRED_ROW is made current. The window being updated is
784 found in updated_window. This function It is called from
785 update_window_line only if it is known that there are differences
786 between bitmaps to be drawn between current row and DESIRED_ROW. */
789 x_after_update_window_line (desired_row
)
790 struct glyph_row
*desired_row
;
792 struct window
*w
= updated_window
;
798 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
801 x_draw_row_fringe_bitmaps (w
, desired_row
);
805 /* When a window has disappeared, make sure that no rest of
806 full-width rows stays visible in the internal border. Could
807 check here if updated_window is the leftmost/rightmost window,
808 but I guess it's not worth doing since vertically split windows
809 are almost never used, internal border is rarely set, and the
810 overhead is very small. */
811 if (windows_or_buffers_changed
812 && desired_row
->full_width_p
813 && (f
= XFRAME (w
->frame
),
814 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
816 && (height
= desired_row
->visible_height
,
819 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
821 /* Internal border is drawn below the tool bar. */
822 if (WINDOWP (f
->tool_bar_window
)
823 && w
== XWINDOW (f
->tool_bar_window
))
827 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
828 0, y
, width
, height
, False
);
829 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
830 f
->output_data
.x
->pixel_width
- width
,
831 y
, width
, height
, False
);
837 /* Draw the bitmap WHICH in one of the left or right fringes of
838 window W. ROW is the glyph row for which to display the bitmap; it
839 determines the vertical position at which the bitmap has to be
843 x_draw_fringe_bitmap (w
, row
, which
, left_p
)
845 struct glyph_row
*row
;
846 enum fringe_bitmap_type which
;
849 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
850 Display
*display
= FRAME_X_DISPLAY (f
);
851 Window window
= FRAME_X_WINDOW (f
);
856 GC gc
= f
->output_data
.x
->normal_gc
;
858 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
860 /* Must clip because of partially visible lines. */
861 x_clip_to_row (w
, row
, gc
, 1);
863 /* Convert row to frame coordinates. */
864 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
868 case NO_FRINGE_BITMAP
:
873 case LEFT_TRUNCATION_BITMAP
:
879 case OVERLAY_ARROW_BITMAP
:
885 case RIGHT_TRUNCATION_BITMAP
:
891 case CONTINUED_LINE_BITMAP
:
892 wd
= continued_width
;
893 h
= continued_height
;
894 bits
= continued_bits
;
897 case CONTINUATION_LINE_BITMAP
:
898 wd
= continuation_width
;
899 h
= continuation_height
;
900 bits
= continuation_bits
;
905 h
= zv_height
- (y
% zv_period
);
906 bits
= zv_bits
+ (y
% zv_period
);
913 /* Clip bitmap if too high. */
917 /* Set dy to the offset in the row to start drawing the bitmap. */
918 dy
= (row
->height
- h
) / 2;
920 face
= FACE_FROM_ID (f
, FRINGE_FACE_ID
);
921 PREPARE_FACE_FOR_DISPLAY (f
, face
);
923 /* Clear left fringe if no bitmap to draw or if bitmap doesn't fill
928 if (wd
> FRAME_X_LEFT_FRINGE_WIDTH (f
))
929 wd
= FRAME_X_LEFT_FRINGE_WIDTH (f
);
930 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
932 - (FRAME_X_LEFT_FRINGE_WIDTH (f
) - wd
) / 2);
933 if (wd
< FRAME_X_LEFT_FRINGE_WIDTH (f
) || row
->height
> h
)
935 /* If W has a vertical border to its left, don't draw over it. */
936 int border
= ((XFASTINT (w
->left
) > 0
937 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
939 b1
= (window_box_left (w
, -1)
940 - FRAME_X_LEFT_FRINGE_WIDTH (f
)
942 b2
= (FRAME_X_LEFT_FRINGE_WIDTH (f
) - border
);
947 if (wd
> FRAME_X_RIGHT_FRINGE_WIDTH (f
))
948 wd
= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
949 x
= (window_box_right (w
, -1)
950 + (FRAME_X_RIGHT_FRINGE_WIDTH (f
) - wd
) / 2);
951 /* Clear right fringe if no bitmap to draw of if bitmap doesn't fill
953 if (wd
< FRAME_X_RIGHT_FRINGE_WIDTH (f
) || row
->height
> h
)
955 b1
= window_box_right (w
, -1);
956 b2
= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
962 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
964 /* In case the same realized face is used for fringes and
965 for something displayed in the text (e.g. face `region' on
966 mono-displays, the fill style may have been changed to
967 FillSolid in x_draw_glyph_string_background. */
969 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
971 XSetForeground (display
, face
->gc
, face
->background
);
973 XFillRectangle (display
, window
, face
->gc
,
975 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
978 row
->visible_height
);
980 XSetForeground (display
, face
->gc
, face
->foreground
);
983 if (which
!= NO_FRINGE_BITMAP
)
985 /* Draw the bitmap. I believe these small pixmaps can be cached
987 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, wd
, h
,
989 face
->background
, depth
);
990 XCopyArea (display
, pixmap
, window
, gc
, 0, 0, wd
, h
, x
, y
+ dy
);
991 XFreePixmap (display
, pixmap
);
994 XSetClipMask (display
, gc
, None
);
998 /* Draw fringe bitmaps for glyph row ROW on window W. Call this
999 function with input blocked. */
1002 x_draw_row_fringe_bitmaps (w
, row
)
1004 struct glyph_row
*row
;
1006 struct frame
*f
= XFRAME (w
->frame
);
1007 enum fringe_bitmap_type bitmap
;
1009 xassert (interrupt_input_blocked
);
1011 /* If row is completely invisible, because of vscrolling, we
1012 don't have to draw anything. */
1013 if (row
->visible_height
<= 0)
1016 if (FRAME_X_LEFT_FRINGE_WIDTH (f
) != 0)
1018 /* Decide which bitmap to draw in the left fringe. */
1019 if (row
->overlay_arrow_p
)
1020 bitmap
= OVERLAY_ARROW_BITMAP
;
1021 else if (row
->truncated_on_left_p
)
1022 bitmap
= LEFT_TRUNCATION_BITMAP
;
1023 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
1024 bitmap
= CONTINUATION_LINE_BITMAP
;
1025 else if (row
->indicate_empty_line_p
)
1026 bitmap
= ZV_LINE_BITMAP
;
1028 bitmap
= NO_FRINGE_BITMAP
;
1030 x_draw_fringe_bitmap (w
, row
, bitmap
, 1);
1033 if (FRAME_X_RIGHT_FRINGE_WIDTH (f
) != 0)
1035 /* Decide which bitmap to draw in the right fringe. */
1036 if (row
->truncated_on_right_p
)
1037 bitmap
= RIGHT_TRUNCATION_BITMAP
;
1038 else if (row
->continued_p
)
1039 bitmap
= CONTINUED_LINE_BITMAP
;
1040 else if (row
->indicate_empty_line_p
&& FRAME_X_LEFT_FRINGE_WIDTH (f
) == 0)
1041 bitmap
= ZV_LINE_BITMAP
;
1043 bitmap
= NO_FRINGE_BITMAP
;
1045 x_draw_fringe_bitmap (w
, row
, bitmap
, 0);
1051 /* This is called when starting Emacs and when restarting after
1052 suspend. When starting Emacs, no X window is mapped. And nothing
1053 must be done to Emacs's own window if it is suspended (though that
1057 XTset_terminal_modes ()
1061 /* This is called when exiting or suspending Emacs. Exiting will make
1062 the X-windows go away, and suspending requires no action. */
1065 XTreset_terminal_modes ()
1071 /***********************************************************************
1073 ***********************************************************************/
1075 /* Set the global variable output_cursor to CURSOR. All cursor
1076 positions are relative to updated_window. */
1079 set_output_cursor (cursor
)
1080 struct cursor_pos
*cursor
;
1082 output_cursor
.hpos
= cursor
->hpos
;
1083 output_cursor
.vpos
= cursor
->vpos
;
1084 output_cursor
.x
= cursor
->x
;
1085 output_cursor
.y
= cursor
->y
;
1089 /* Set a nominal cursor position.
1091 HPOS and VPOS are column/row positions in a window glyph matrix. X
1092 and Y are window text area relative pixel positions.
1094 If this is done during an update, updated_window will contain the
1095 window that is being updated and the position is the future output
1096 cursor position for that window. If updated_window is null, use
1097 selected_window and display the cursor at the given position. */
1100 XTcursor_to (vpos
, hpos
, y
, x
)
1101 int vpos
, hpos
, y
, x
;
1105 /* If updated_window is not set, work on selected_window. */
1109 w
= XWINDOW (selected_window
);
1111 /* Set the output cursor. */
1112 output_cursor
.hpos
= hpos
;
1113 output_cursor
.vpos
= vpos
;
1114 output_cursor
.x
= x
;
1115 output_cursor
.y
= y
;
1117 /* If not called as part of an update, really display the cursor.
1118 This will also set the cursor position of W. */
1119 if (updated_window
== NULL
)
1122 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
1123 XFlush (FRAME_X_DISPLAY (SELECTED_FRAME ()));
1130 /***********************************************************************
1132 ***********************************************************************/
1134 /* Function prototypes of this page. */
1136 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
1140 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
1141 int, XChar2b
*, int,
1143 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
1144 static void x_encode_char
P_ ((int, XChar2b
*, struct font_info
*));
1145 static void x_append_glyph
P_ ((struct it
*));
1146 static void x_append_composite_glyph
P_ ((struct it
*));
1147 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
1149 static void x_produce_glyphs
P_ ((struct it
*));
1150 static void x_produce_image_glyph
P_ ((struct it
*it
));
1153 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
1154 is not contained in the font. */
1156 static INLINE XCharStruct
*
1157 x_per_char_metric (font
, char2b
)
1161 /* The result metric information. */
1162 XCharStruct
*pcm
= NULL
;
1164 xassert (font
&& char2b
);
1166 if (font
->per_char
!= NULL
)
1168 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
1170 /* min_char_or_byte2 specifies the linear character index
1171 corresponding to the first element of the per_char array,
1172 max_char_or_byte2 is the index of the last character. A
1173 character with non-zero CHAR2B->byte1 is not in the font.
1174 A character with byte2 less than min_char_or_byte2 or
1175 greater max_char_or_byte2 is not in the font. */
1176 if (char2b
->byte1
== 0
1177 && char2b
->byte2
>= font
->min_char_or_byte2
1178 && char2b
->byte2
<= font
->max_char_or_byte2
)
1179 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
1183 /* If either min_byte1 or max_byte1 are nonzero, both
1184 min_char_or_byte2 and max_char_or_byte2 are less than
1185 256, and the 2-byte character index values corresponding
1186 to the per_char array element N (counting from 0) are:
1188 byte1 = N/D + min_byte1
1189 byte2 = N\D + min_char_or_byte2
1193 D = max_char_or_byte2 - min_char_or_byte2 + 1
1194 / = integer division
1195 \ = integer modulus */
1196 if (char2b
->byte1
>= font
->min_byte1
1197 && char2b
->byte1
<= font
->max_byte1
1198 && char2b
->byte2
>= font
->min_char_or_byte2
1199 && char2b
->byte2
<= font
->max_char_or_byte2
)
1201 pcm
= (font
->per_char
1202 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
1203 * (char2b
->byte1
- font
->min_byte1
))
1204 + (char2b
->byte2
- font
->min_char_or_byte2
));
1210 /* If the per_char pointer is null, all glyphs between the first
1211 and last character indexes inclusive have the same
1212 information, as given by both min_bounds and max_bounds. */
1213 if (char2b
->byte2
>= font
->min_char_or_byte2
1214 && char2b
->byte2
<= font
->max_char_or_byte2
)
1215 pcm
= &font
->max_bounds
;
1218 return ((pcm
== NULL
1219 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
1224 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1225 the two-byte form of C. Encoding is returned in *CHAR2B. */
1228 x_encode_char (c
, char2b
, font_info
)
1231 struct font_info
*font_info
;
1233 int charset
= CHAR_CHARSET (c
);
1234 XFontStruct
*font
= font_info
->font
;
1236 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1237 This may be either a program in a special encoder language or a
1239 if (font_info
->font_encoder
)
1241 /* It's a program. */
1242 struct ccl_program
*ccl
= font_info
->font_encoder
;
1244 if (CHARSET_DIMENSION (charset
) == 1)
1246 ccl
->reg
[0] = charset
;
1247 ccl
->reg
[1] = char2b
->byte2
;
1251 ccl
->reg
[0] = charset
;
1252 ccl
->reg
[1] = char2b
->byte1
;
1253 ccl
->reg
[2] = char2b
->byte2
;
1256 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1258 /* We assume that MSBs are appropriately set/reset by CCL
1260 if (font
->max_byte1
== 0) /* 1-byte font */
1261 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
1263 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
1265 else if (font_info
->encoding
[charset
])
1267 /* Fixed encoding scheme. See fontset.h for the meaning of the
1268 encoding numbers. */
1269 int enc
= font_info
->encoding
[charset
];
1271 if ((enc
== 1 || enc
== 2)
1272 && CHARSET_DIMENSION (charset
) == 2)
1273 char2b
->byte1
|= 0x80;
1275 if (enc
== 1 || enc
== 3)
1276 char2b
->byte2
|= 0x80;
1281 /* Get face and two-byte form of character C in face FACE_ID on frame
1282 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1283 means we want to display multibyte text. DISPLAY_P non-zero means
1284 make sure that X resources for the face returned are allocated.
1285 Value is a pointer to a realized face that is ready for display if
1286 DISPLAY_P is non-zero. */
1288 static INLINE
struct face
*
1289 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
1293 int multibyte_p
, display_p
;
1295 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1299 /* Unibyte case. We don't have to encode, but we have to make
1300 sure to use a face suitable for unibyte. */
1303 face_id
= FACE_FOR_CHAR (f
, face
, c
);
1304 face
= FACE_FROM_ID (f
, face_id
);
1306 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1308 /* Case of ASCII in a face known to fit ASCII. */
1314 int c1
, c2
, charset
;
1316 /* Split characters into bytes. If c2 is -1 afterwards, C is
1317 really a one-byte character so that byte1 is zero. */
1318 SPLIT_CHAR (c
, charset
, c1
, c2
);
1320 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1322 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1324 /* Maybe encode the character in *CHAR2B. */
1325 if (face
->font
!= NULL
)
1327 struct font_info
*font_info
1328 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1330 x_encode_char (c
, char2b
, font_info
);
1334 /* Make sure X resources of the face are allocated. */
1337 xassert (face
!= NULL
);
1338 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1345 /* Get face and two-byte form of character glyph GLYPH on frame F.
1346 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
1347 a pointer to a realized face that is ready for display. */
1349 static INLINE
struct face
*
1350 x_get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
1352 struct glyph
*glyph
;
1358 xassert (glyph
->type
== CHAR_GLYPH
);
1359 face
= FACE_FROM_ID (f
, glyph
->face_id
);
1364 if (!glyph
->multibyte_p
)
1366 /* Unibyte case. We don't have to encode, but we have to make
1367 sure to use a face suitable for unibyte. */
1369 char2b
->byte2
= glyph
->u
.ch
;
1371 else if (glyph
->u
.ch
< 128
1372 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
1374 /* Case of ASCII in a face known to fit ASCII. */
1376 char2b
->byte2
= glyph
->u
.ch
;
1380 int c1
, c2
, charset
;
1382 /* Split characters into bytes. If c2 is -1 afterwards, C is
1383 really a one-byte character so that byte1 is zero. */
1384 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
1386 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1388 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1390 /* Maybe encode the character in *CHAR2B. */
1391 if (charset
!= CHARSET_ASCII
)
1393 struct font_info
*font_info
1394 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1397 x_encode_char (glyph
->u
.ch
, char2b
, font_info
);
1400 = ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
1405 /* Make sure X resources of the face are allocated. */
1406 xassert (face
!= NULL
);
1407 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1412 /* Store one glyph for IT->char_to_display in IT->glyph_row.
1413 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1419 struct glyph
*glyph
;
1420 enum glyph_row_area area
= it
->area
;
1422 xassert (it
->glyph_row
);
1423 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
1425 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1426 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1428 glyph
->charpos
= CHARPOS (it
->position
);
1429 glyph
->object
= it
->object
;
1430 glyph
->pixel_width
= it
->pixel_width
;
1431 glyph
->voffset
= it
->voffset
;
1432 glyph
->type
= CHAR_GLYPH
;
1433 glyph
->multibyte_p
= it
->multibyte_p
;
1434 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1435 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1436 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1437 || it
->phys_descent
> it
->descent
);
1438 glyph
->padding_p
= 0;
1439 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
1440 glyph
->face_id
= it
->face_id
;
1441 glyph
->u
.ch
= it
->char_to_display
;
1442 ++it
->glyph_row
->used
[area
];
1446 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
1447 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1450 x_append_composite_glyph (it
)
1453 struct glyph
*glyph
;
1454 enum glyph_row_area area
= it
->area
;
1456 xassert (it
->glyph_row
);
1458 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1459 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1461 glyph
->charpos
= CHARPOS (it
->position
);
1462 glyph
->object
= it
->object
;
1463 glyph
->pixel_width
= it
->pixel_width
;
1464 glyph
->voffset
= it
->voffset
;
1465 glyph
->type
= COMPOSITE_GLYPH
;
1466 glyph
->multibyte_p
= it
->multibyte_p
;
1467 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1468 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1469 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1470 || it
->phys_descent
> it
->descent
);
1471 glyph
->padding_p
= 0;
1472 glyph
->glyph_not_available_p
= 0;
1473 glyph
->face_id
= it
->face_id
;
1474 glyph
->u
.cmp_id
= it
->cmp_id
;
1475 ++it
->glyph_row
->used
[area
];
1480 /* Change IT->ascent and IT->height according to the setting of
1484 take_vertical_position_into_account (it
)
1489 if (it
->voffset
< 0)
1490 /* Increase the ascent so that we can display the text higher
1492 it
->ascent
+= abs (it
->voffset
);
1494 /* Increase the descent so that we can display the text lower
1496 it
->descent
+= it
->voffset
;
1501 /* Produce glyphs/get display metrics for the image IT is loaded with.
1502 See the description of struct display_iterator in dispextern.h for
1503 an overview of struct display_iterator. */
1506 x_produce_image_glyph (it
)
1512 xassert (it
->what
== IT_IMAGE
);
1514 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1515 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
1518 /* Make sure X resources of the face and image are loaded. */
1519 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1520 prepare_image_for_display (it
->f
, img
);
1522 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
1523 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
1524 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
1528 if (face
->box
!= FACE_NO_BOX
)
1530 if (face
->box_line_width
> 0)
1532 it
->ascent
+= face
->box_line_width
;
1533 it
->descent
+= face
->box_line_width
;
1536 if (it
->start_of_box_run_p
)
1537 it
->pixel_width
+= abs (face
->box_line_width
);
1538 if (it
->end_of_box_run_p
)
1539 it
->pixel_width
+= abs (face
->box_line_width
);
1542 take_vertical_position_into_account (it
);
1546 struct glyph
*glyph
;
1547 enum glyph_row_area area
= it
->area
;
1549 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1550 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1552 glyph
->charpos
= CHARPOS (it
->position
);
1553 glyph
->object
= it
->object
;
1554 glyph
->pixel_width
= it
->pixel_width
;
1555 glyph
->voffset
= it
->voffset
;
1556 glyph
->type
= IMAGE_GLYPH
;
1557 glyph
->multibyte_p
= it
->multibyte_p
;
1558 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1559 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1560 glyph
->overlaps_vertically_p
= 0;
1561 glyph
->padding_p
= 0;
1562 glyph
->glyph_not_available_p
= 0;
1563 glyph
->face_id
= it
->face_id
;
1564 glyph
->u
.img_id
= img
->id
;
1565 ++it
->glyph_row
->used
[area
];
1571 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
1572 of the glyph, WIDTH and HEIGHT are the width and height of the
1573 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
1574 ascent of the glyph (0 <= ASCENT <= 1). */
1577 x_append_stretch_glyph (it
, object
, width
, height
, ascent
)
1583 struct glyph
*glyph
;
1584 enum glyph_row_area area
= it
->area
;
1586 xassert (ascent
>= 0 && ascent
<= 1);
1588 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1589 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1591 glyph
->charpos
= CHARPOS (it
->position
);
1592 glyph
->object
= object
;
1593 glyph
->pixel_width
= width
;
1594 glyph
->voffset
= it
->voffset
;
1595 glyph
->type
= STRETCH_GLYPH
;
1596 glyph
->multibyte_p
= it
->multibyte_p
;
1597 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1598 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1599 glyph
->overlaps_vertically_p
= 0;
1600 glyph
->padding_p
= 0;
1601 glyph
->glyph_not_available_p
= 0;
1602 glyph
->face_id
= it
->face_id
;
1603 glyph
->u
.stretch
.ascent
= height
* ascent
;
1604 glyph
->u
.stretch
.height
= height
;
1605 ++it
->glyph_row
->used
[area
];
1610 /* Produce a stretch glyph for iterator IT. IT->object is the value
1611 of the glyph property displayed. The value must be a list
1612 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1615 1. `:width WIDTH' specifies that the space should be WIDTH *
1616 canonical char width wide. WIDTH may be an integer or floating
1619 2. `:relative-width FACTOR' specifies that the width of the stretch
1620 should be computed from the width of the first character having the
1621 `glyph' property, and should be FACTOR times that width.
1623 3. `:align-to HPOS' specifies that the space should be wide enough
1624 to reach HPOS, a value in canonical character units.
1626 Exactly one of the above pairs must be present.
1628 4. `:height HEIGHT' specifies that the height of the stretch produced
1629 should be HEIGHT, measured in canonical character units.
1631 5. `:relative-height FACTOR' specifies that the height of the
1632 stretch should be FACTOR times the height of the characters having
1635 Either none or exactly one of 4 or 5 must be present.
1637 6. `:ascent ASCENT' specifies that ASCENT percent of the height
1638 of the stretch should be used for the ascent of the stretch.
1639 ASCENT must be in the range 0 <= ASCENT <= 100. */
1642 ((INTEGERP (X) || FLOATP (X)) \
1648 x_produce_stretch_glyph (it
)
1651 /* (space :width WIDTH :height HEIGHT. */
1653 extern Lisp_Object Qspace
;
1655 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
1656 extern Lisp_Object QCrelative_width
, QCrelative_height
;
1657 extern Lisp_Object QCalign_to
;
1658 Lisp_Object prop
, plist
;
1659 double width
= 0, height
= 0, ascent
= 0;
1660 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1661 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
1663 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1665 /* List should start with `space'. */
1666 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1667 plist
= XCDR (it
->object
);
1669 /* Compute the width of the stretch. */
1670 if (prop
= Fplist_get (plist
, QCwidth
),
1672 /* Absolute width `:width WIDTH' specified and valid. */
1673 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
1674 else if (prop
= Fplist_get (plist
, QCrelative_width
),
1677 /* Relative width `:relative-width FACTOR' specified and valid.
1678 Compute the width of the characters having the `glyph'
1681 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
1684 if (it
->multibyte_p
)
1686 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
1687 - IT_BYTEPOS (*it
));
1688 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
1691 it2
.c
= *p
, it2
.len
= 1;
1693 it2
.glyph_row
= NULL
;
1694 it2
.what
= IT_CHARACTER
;
1695 x_produce_glyphs (&it2
);
1696 width
= NUMVAL (prop
) * it2
.pixel_width
;
1698 else if (prop
= Fplist_get (plist
, QCalign_to
),
1700 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
1702 /* Nothing specified -> width defaults to canonical char width. */
1703 width
= CANON_X_UNIT (it
->f
);
1705 /* Compute height. */
1706 if (prop
= Fplist_get (plist
, QCheight
),
1708 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
1709 else if (prop
= Fplist_get (plist
, QCrelative_height
),
1711 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
1713 height
= FONT_HEIGHT (font
);
1715 /* Compute percentage of height used for ascent. If
1716 `:ascent ASCENT' is present and valid, use that. Otherwise,
1717 derive the ascent from the font in use. */
1718 if (prop
= Fplist_get (plist
, QCascent
),
1719 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
1720 ascent
= NUMVAL (prop
) / 100.0;
1722 ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1731 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1732 if (!STRINGP (object
))
1733 object
= it
->w
->buffer
;
1734 x_append_stretch_glyph (it
, object
, width
, height
, ascent
);
1737 it
->pixel_width
= width
;
1738 it
->ascent
= it
->phys_ascent
= height
* ascent
;
1739 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
1742 if (face
->box
!= FACE_NO_BOX
)
1744 if (face
->box_line_width
> 0)
1746 it
->ascent
+= face
->box_line_width
;
1747 it
->descent
+= face
->box_line_width
;
1750 if (it
->start_of_box_run_p
)
1751 it
->pixel_width
+= abs (face
->box_line_width
);
1752 if (it
->end_of_box_run_p
)
1753 it
->pixel_width
+= abs (face
->box_line_width
);
1756 take_vertical_position_into_account (it
);
1759 /* Return proper value to be used as baseline offset of font that has
1760 ASCENT and DESCENT to draw characters by the font at the vertical
1761 center of the line of frame F.
1763 Here, out task is to find the value of BOFF in the following figure;
1765 -------------------------+-----------+-
1766 -+-+---------+-+ | |
1768 | | | | F_ASCENT F_HEIGHT
1771 | | |-|-+------+-----------|------- baseline
1773 | |---------|-+-+ | |
1775 -+-+---------+-+ F_DESCENT |
1776 -------------------------+-----------+-
1778 -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
1779 BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
1780 DESCENT = FONT->descent
1781 HEIGHT = FONT_HEIGHT (FONT)
1782 F_DESCENT = (F->output_data.x->font->descent
1783 - F->output_data.x->baseline_offset)
1784 F_HEIGHT = FRAME_LINE_HEIGHT (F)
1787 #define VCENTER_BASELINE_OFFSET(FONT, F) \
1789 + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT)) \
1790 + (FRAME_LINE_HEIGHT ((F)) > FONT_HEIGHT ((FONT)))) / 2 \
1791 - ((F)->output_data.x->font->descent - (F)->output_data.x->baseline_offset))
1793 /* Produce glyphs/get display metrics for the display element IT is
1794 loaded with. See the description of struct display_iterator in
1795 dispextern.h for an overview of struct display_iterator. */
1798 x_produce_glyphs (it
)
1801 it
->glyph_not_available_p
= 0;
1803 if (it
->what
== IT_CHARACTER
)
1807 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1809 int font_not_found_p
;
1810 struct font_info
*font_info
;
1811 int boff
; /* baseline offset */
1812 /* We may change it->multibyte_p upon unibyte<->multibyte
1813 conversion. So, save the current value now and restore it
1816 Note: It seems that we don't have to record multibyte_p in
1817 struct glyph because the character code itself tells if or
1818 not the character is multibyte. Thus, in the future, we must
1819 consider eliminating the field `multibyte_p' in the struct
1821 int saved_multibyte_p
= it
->multibyte_p
;
1823 /* Maybe translate single-byte characters to multibyte, or the
1825 it
->char_to_display
= it
->c
;
1826 if (!ASCII_BYTE_P (it
->c
))
1828 if (unibyte_display_via_language_environment
1829 && SINGLE_BYTE_CHAR_P (it
->c
)
1831 || !NILP (Vnonascii_translation_table
)))
1833 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
1834 it
->multibyte_p
= 1;
1835 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1836 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1838 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
1839 && !it
->multibyte_p
)
1841 it
->multibyte_p
= 1;
1842 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1843 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1847 /* Get font to use. Encode IT->char_to_display. */
1848 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
1849 it
->face_id
, &char2b
,
1850 it
->multibyte_p
, 0);
1853 /* When no suitable font found, use the default font. */
1854 font_not_found_p
= font
== NULL
;
1855 if (font_not_found_p
)
1857 font
= FRAME_FONT (it
->f
);
1858 boff
= it
->f
->output_data
.x
->baseline_offset
;
1863 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
1864 boff
= font_info
->baseline_offset
;
1865 if (font_info
->vertical_centering
)
1866 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
1869 if (it
->char_to_display
>= ' '
1870 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
1872 /* Either unibyte or ASCII. */
1877 pcm
= x_per_char_metric (font
, &char2b
);
1878 it
->ascent
= font
->ascent
+ boff
;
1879 it
->descent
= font
->descent
- boff
;
1883 it
->phys_ascent
= pcm
->ascent
+ boff
;
1884 it
->phys_descent
= pcm
->descent
- boff
;
1885 it
->pixel_width
= pcm
->width
;
1889 it
->glyph_not_available_p
= 1;
1890 it
->phys_ascent
= font
->ascent
+ boff
;
1891 it
->phys_descent
= font
->descent
- boff
;
1892 it
->pixel_width
= FONT_WIDTH (font
);
1895 /* If this is a space inside a region of text with
1896 `space-width' property, change its width. */
1897 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
1899 it
->pixel_width
*= XFLOATINT (it
->space_width
);
1901 /* If face has a box, add the box thickness to the character
1902 height. If character has a box line to the left and/or
1903 right, add the box line width to the character's width. */
1904 if (face
->box
!= FACE_NO_BOX
)
1906 int thick
= face
->box_line_width
;
1910 it
->ascent
+= thick
;
1911 it
->descent
+= thick
;
1916 if (it
->start_of_box_run_p
)
1917 it
->pixel_width
+= thick
;
1918 if (it
->end_of_box_run_p
)
1919 it
->pixel_width
+= thick
;
1922 /* If face has an overline, add the height of the overline
1923 (1 pixel) and a 1 pixel margin to the character height. */
1924 if (face
->overline_p
)
1927 take_vertical_position_into_account (it
);
1929 /* If we have to actually produce glyphs, do it. */
1934 /* Translate a space with a `space-width' property
1935 into a stretch glyph. */
1936 double ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1937 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1938 it
->ascent
+ it
->descent
, ascent
);
1941 x_append_glyph (it
);
1943 /* If characters with lbearing or rbearing are displayed
1944 in this line, record that fact in a flag of the
1945 glyph row. This is used to optimize X output code. */
1946 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
1947 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1950 else if (it
->char_to_display
== '\n')
1952 /* A newline has no width but we need the height of the line. */
1953 it
->pixel_width
= 0;
1955 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1956 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1958 if (face
->box
!= FACE_NO_BOX
1959 && face
->box_line_width
> 0)
1961 it
->ascent
+= face
->box_line_width
;
1962 it
->descent
+= face
->box_line_width
;
1965 else if (it
->char_to_display
== '\t')
1967 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
1968 int x
= it
->current_x
+ it
->continuation_lines_width
;
1969 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
1971 /* If the distance from the current position to the next tab
1972 stop is less than a canonical character width, use the
1973 tab stop after that. */
1974 if (next_tab_x
- x
< CANON_X_UNIT (it
->f
))
1975 next_tab_x
+= tab_width
;
1977 it
->pixel_width
= next_tab_x
- x
;
1979 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1980 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1984 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
1985 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1986 it
->ascent
+ it
->descent
, ascent
);
1991 /* A multi-byte character. Assume that the display width of the
1992 character is the width of the character multiplied by the
1993 width of the font. */
1995 /* If we found a font, this font should give us the right
1996 metrics. If we didn't find a font, use the frame's
1997 default font and calculate the width of the character
1998 from the charset width; this is what old redisplay code
2000 pcm
= x_per_char_metric (font
, &char2b
);
2001 if (font_not_found_p
|| !pcm
)
2003 int charset
= CHAR_CHARSET (it
->char_to_display
);
2005 it
->glyph_not_available_p
= 1;
2006 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
2007 * CHARSET_WIDTH (charset
));
2008 it
->phys_ascent
= font
->ascent
+ boff
;
2009 it
->phys_descent
= font
->descent
- boff
;
2013 it
->pixel_width
= pcm
->width
;
2014 it
->phys_ascent
= pcm
->ascent
+ boff
;
2015 it
->phys_descent
= pcm
->descent
- boff
;
2017 && (pcm
->lbearing
< 0
2018 || pcm
->rbearing
> pcm
->width
))
2019 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
2022 it
->ascent
= font
->ascent
+ boff
;
2023 it
->descent
= font
->descent
- boff
;
2024 if (face
->box
!= FACE_NO_BOX
)
2026 int thick
= face
->box_line_width
;
2030 it
->ascent
+= thick
;
2031 it
->descent
+= thick
;
2036 if (it
->start_of_box_run_p
)
2037 it
->pixel_width
+= thick
;
2038 if (it
->end_of_box_run_p
)
2039 it
->pixel_width
+= thick
;
2042 /* If face has an overline, add the height of the overline
2043 (1 pixel) and a 1 pixel margin to the character height. */
2044 if (face
->overline_p
)
2047 take_vertical_position_into_account (it
);
2050 x_append_glyph (it
);
2052 it
->multibyte_p
= saved_multibyte_p
;
2054 else if (it
->what
== IT_COMPOSITION
)
2056 /* Note: A composition is represented as one glyph in the
2057 glyph matrix. There are no padding glyphs. */
2060 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2062 int font_not_found_p
;
2063 struct font_info
*font_info
;
2064 int boff
; /* baseline offset */
2065 struct composition
*cmp
= composition_table
[it
->cmp_id
];
2067 /* Maybe translate single-byte characters to multibyte. */
2068 it
->char_to_display
= it
->c
;
2069 if (unibyte_display_via_language_environment
2070 && SINGLE_BYTE_CHAR_P (it
->c
)
2073 && !NILP (Vnonascii_translation_table
))))
2075 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2078 /* Get face and font to use. Encode IT->char_to_display. */
2079 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2080 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2081 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2082 it
->face_id
, &char2b
, it
->multibyte_p
, 0);
2085 /* When no suitable font found, use the default font. */
2086 font_not_found_p
= font
== NULL
;
2087 if (font_not_found_p
)
2089 font
= FRAME_FONT (it
->f
);
2090 boff
= it
->f
->output_data
.x
->baseline_offset
;
2095 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2096 boff
= font_info
->baseline_offset
;
2097 if (font_info
->vertical_centering
)
2098 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2101 /* There are no padding glyphs, so there is only one glyph to
2102 produce for the composition. Important is that pixel_width,
2103 ascent and descent are the values of what is drawn by
2104 draw_glyphs (i.e. the values of the overall glyphs composed). */
2107 /* If we have not yet calculated pixel size data of glyphs of
2108 the composition for the current face font, calculate them
2109 now. Theoretically, we have to check all fonts for the
2110 glyphs, but that requires much time and memory space. So,
2111 here we check only the font of the first glyph. This leads
2112 to incorrect display very rarely, and C-l (recenter) can
2113 correct the display anyway. */
2114 if (cmp
->font
!= (void *) font
)
2116 /* Ascent and descent of the font of the first character of
2117 this composition (adjusted by baseline offset). Ascent
2118 and descent of overall glyphs should not be less than
2119 them respectively. */
2120 int font_ascent
= font
->ascent
+ boff
;
2121 int font_descent
= font
->descent
- boff
;
2122 /* Bounding box of the overall glyphs. */
2123 int leftmost
, rightmost
, lowest
, highest
;
2124 int i
, width
, ascent
, descent
;
2126 cmp
->font
= (void *) font
;
2128 /* Initialize the bounding box. */
2130 && (pcm
= x_per_char_metric (font
, &char2b
)))
2133 ascent
= pcm
->ascent
;
2134 descent
= pcm
->descent
;
2138 width
= FONT_WIDTH (font
);
2139 ascent
= font
->ascent
;
2140 descent
= font
->descent
;
2144 lowest
= - descent
+ boff
;
2145 highest
= ascent
+ boff
;
2149 && font_info
->default_ascent
2150 && CHAR_TABLE_P (Vuse_default_ascent
)
2151 && !NILP (Faref (Vuse_default_ascent
,
2152 make_number (it
->char_to_display
))))
2153 highest
= font_info
->default_ascent
+ boff
;
2155 /* Draw the first glyph at the normal position. It may be
2156 shifted to right later if some other glyphs are drawn at
2158 cmp
->offsets
[0] = 0;
2159 cmp
->offsets
[1] = boff
;
2161 /* Set cmp->offsets for the remaining glyphs. */
2162 for (i
= 1; i
< cmp
->glyph_len
; i
++)
2164 int left
, right
, btm
, top
;
2165 int ch
= COMPOSITION_GLYPH (cmp
, i
);
2166 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
2168 face
= FACE_FROM_ID (it
->f
, face_id
);
2169 x_get_char_face_and_encoding (it
->f
, ch
, face
->id
, &char2b
,
2170 it
->multibyte_p
, 0);
2174 font
= FRAME_FONT (it
->f
);
2175 boff
= it
->f
->output_data
.x
->baseline_offset
;
2181 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2182 boff
= font_info
->baseline_offset
;
2183 if (font_info
->vertical_centering
)
2184 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2188 && (pcm
= x_per_char_metric (font
, &char2b
)))
2191 ascent
= pcm
->ascent
;
2192 descent
= pcm
->descent
;
2196 width
= FONT_WIDTH (font
);
2201 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
2203 /* Relative composition with or without
2205 left
= (leftmost
+ rightmost
- width
) / 2;
2206 btm
= - descent
+ boff
;
2207 if (font_info
&& font_info
->relative_compose
2208 && (! CHAR_TABLE_P (Vignore_relative_composition
)
2209 || NILP (Faref (Vignore_relative_composition
,
2210 make_number (ch
)))))
2213 if (- descent
>= font_info
->relative_compose
)
2214 /* One extra pixel between two glyphs. */
2216 else if (ascent
<= 0)
2217 /* One extra pixel between two glyphs. */
2218 btm
= lowest
- 1 - ascent
- descent
;
2223 /* A composition rule is specified by an integer
2224 value that encodes global and new reference
2225 points (GREF and NREF). GREF and NREF are
2226 specified by numbers as below:
2234 ---3---4---5--- baseline
2236 6---7---8 -- descent
2238 int rule
= COMPOSITION_RULE (cmp
, i
);
2239 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
2241 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
2242 grefx
= gref
% 3, nrefx
= nref
% 3;
2243 grefy
= gref
/ 3, nrefy
= nref
/ 3;
2246 + grefx
* (rightmost
- leftmost
) / 2
2247 - nrefx
* width
/ 2);
2248 btm
= ((grefy
== 0 ? highest
2250 : grefy
== 2 ? lowest
2251 : (highest
+ lowest
) / 2)
2252 - (nrefy
== 0 ? ascent
+ descent
2253 : nrefy
== 1 ? descent
- boff
2255 : (ascent
+ descent
) / 2));
2258 cmp
->offsets
[i
* 2] = left
;
2259 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
2261 /* Update the bounding box of the overall glyphs. */
2262 right
= left
+ width
;
2263 top
= btm
+ descent
+ ascent
;
2264 if (left
< leftmost
)
2266 if (right
> rightmost
)
2274 /* If there are glyphs whose x-offsets are negative,
2275 shift all glyphs to the right and make all x-offsets
2279 for (i
= 0; i
< cmp
->glyph_len
; i
++)
2280 cmp
->offsets
[i
* 2] -= leftmost
;
2281 rightmost
-= leftmost
;
2284 cmp
->pixel_width
= rightmost
;
2285 cmp
->ascent
= highest
;
2286 cmp
->descent
= - lowest
;
2287 if (cmp
->ascent
< font_ascent
)
2288 cmp
->ascent
= font_ascent
;
2289 if (cmp
->descent
< font_descent
)
2290 cmp
->descent
= font_descent
;
2293 it
->pixel_width
= cmp
->pixel_width
;
2294 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
2295 it
->descent
= it
->phys_descent
= cmp
->descent
;
2297 if (face
->box
!= FACE_NO_BOX
)
2299 int thick
= face
->box_line_width
;
2303 it
->ascent
+= thick
;
2304 it
->descent
+= thick
;
2309 if (it
->start_of_box_run_p
)
2310 it
->pixel_width
+= thick
;
2311 if (it
->end_of_box_run_p
)
2312 it
->pixel_width
+= thick
;
2315 /* If face has an overline, add the height of the overline
2316 (1 pixel) and a 1 pixel margin to the character height. */
2317 if (face
->overline_p
)
2320 take_vertical_position_into_account (it
);
2323 x_append_composite_glyph (it
);
2325 else if (it
->what
== IT_IMAGE
)
2326 x_produce_image_glyph (it
);
2327 else if (it
->what
== IT_STRETCH
)
2328 x_produce_stretch_glyph (it
);
2330 /* Accumulate dimensions. Note: can't assume that it->descent > 0
2331 because this isn't true for images with `:ascent 100'. */
2332 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
2333 if (it
->area
== TEXT_AREA
)
2334 it
->current_x
+= it
->pixel_width
;
2336 it
->descent
+= it
->extra_line_spacing
;
2338 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
2339 it
->max_descent
= max (it
->max_descent
, it
->descent
);
2340 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
2341 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
2345 /* Estimate the pixel height of the mode or top line on frame F.
2346 FACE_ID specifies what line's height to estimate. */
2349 x_estimate_mode_line_height (f
, face_id
)
2351 enum face_id face_id
;
2353 int height
= FONT_HEIGHT (FRAME_FONT (f
));
2355 /* This function is called so early when Emacs starts that the face
2356 cache and mode line face are not yet initialized. */
2357 if (FRAME_FACE_CACHE (f
))
2359 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2363 height
= FONT_HEIGHT (face
->font
);
2364 if (face
->box_line_width
> 0)
2365 height
+= 2 * face
->box_line_width
;
2373 /***********************************************************************
2375 ***********************************************************************/
2377 /* A sequence of glyphs to be drawn in the same face.
2379 This data structure is not really completely X specific, so it
2380 could possibly, at least partially, be useful for other systems. It
2381 is currently not part of the external redisplay interface because
2382 it's not clear what other systems will need. */
2386 /* X-origin of the string. */
2389 /* Y-origin and y-position of the base line of this string. */
2392 /* The width of the string, not including a face extension. */
2395 /* The width of the string, including a face extension. */
2396 int background_width
;
2398 /* The height of this string. This is the height of the line this
2399 string is drawn in, and can be different from the height of the
2400 font the string is drawn in. */
2403 /* Number of pixels this string overwrites in front of its x-origin.
2404 This number is zero if the string has an lbearing >= 0; it is
2405 -lbearing, if the string has an lbearing < 0. */
2408 /* Number of pixels this string overwrites past its right-most
2409 nominal x-position, i.e. x + width. Zero if the string's
2410 rbearing is <= its nominal width, rbearing - width otherwise. */
2413 /* The frame on which the glyph string is drawn. */
2416 /* The window on which the glyph string is drawn. */
2419 /* X display and window for convenience. */
2423 /* The glyph row for which this string was built. It determines the
2424 y-origin and height of the string. */
2425 struct glyph_row
*row
;
2427 /* The area within row. */
2428 enum glyph_row_area area
;
2430 /* Characters to be drawn, and number of characters. */
2434 /* A face-override for drawing cursors, mouse face and similar. */
2435 enum draw_glyphs_face hl
;
2437 /* Face in which this string is to be drawn. */
2440 /* Font in which this string is to be drawn. */
2443 /* Font info for this string. */
2444 struct font_info
*font_info
;
2446 /* Non-null means this string describes (part of) a composition.
2447 All characters from char2b are drawn composed. */
2448 struct composition
*cmp
;
2450 /* Index of this glyph string's first character in the glyph
2451 definition of CMP. If this is zero, this glyph string describes
2452 the first character of a composition. */
2455 /* 1 means this glyph strings face has to be drawn to the right end
2456 of the window's drawing area. */
2457 unsigned extends_to_end_of_line_p
: 1;
2459 /* 1 means the background of this string has been drawn. */
2460 unsigned background_filled_p
: 1;
2462 /* 1 means glyph string must be drawn with 16-bit functions. */
2463 unsigned two_byte_p
: 1;
2465 /* 1 means that the original font determined for drawing this glyph
2466 string could not be loaded. The member `font' has been set to
2467 the frame's default font in this case. */
2468 unsigned font_not_found_p
: 1;
2470 /* 1 means that the face in which this glyph string is drawn has a
2472 unsigned stippled_p
: 1;
2474 /* 1 means only the foreground of this glyph string must be drawn,
2475 and we should use the physical height of the line this glyph
2476 string appears in as clip rect. */
2477 unsigned for_overlaps_p
: 1;
2479 /* The GC to use for drawing this glyph string. */
2482 /* A pointer to the first glyph in the string. This glyph
2483 corresponds to char2b[0]. Needed to draw rectangles if
2484 font_not_found_p is 1. */
2485 struct glyph
*first_glyph
;
2487 /* Image, if any. */
2490 struct glyph_string
*next
, *prev
;
2497 x_dump_glyph_string (s
)
2498 struct glyph_string
*s
;
2500 fprintf (stderr
, "glyph string\n");
2501 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
2502 s
->x
, s
->y
, s
->width
, s
->height
);
2503 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
2504 fprintf (stderr
, " hl = %d\n", s
->hl
);
2505 fprintf (stderr
, " left overhang = %d, right = %d\n",
2506 s
->left_overhang
, s
->right_overhang
);
2507 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
2508 fprintf (stderr
, " extends to end of line = %d\n",
2509 s
->extends_to_end_of_line_p
);
2510 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
2511 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
2514 #endif /* GLYPH_DEBUG */
2518 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
2519 struct glyph_string
**,
2520 struct glyph_string
*,
2521 struct glyph_string
*));
2522 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
2523 struct glyph_string
**,
2524 struct glyph_string
*,
2525 struct glyph_string
*));
2526 static void x_append_glyph_string
P_ ((struct glyph_string
**,
2527 struct glyph_string
**,
2528 struct glyph_string
*));
2529 static int x_left_overwritten
P_ ((struct glyph_string
*));
2530 static int x_left_overwriting
P_ ((struct glyph_string
*));
2531 static int x_right_overwritten
P_ ((struct glyph_string
*));
2532 static int x_right_overwriting
P_ ((struct glyph_string
*));
2533 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
2535 static void x_init_glyph_string
P_ ((struct glyph_string
*,
2536 XChar2b
*, struct window
*,
2538 enum glyph_row_area
, int,
2539 enum draw_glyphs_face
));
2540 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
2541 enum glyph_row_area
, int, int,
2542 enum draw_glyphs_face
, int));
2543 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2544 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2545 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2547 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2548 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2549 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2550 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2551 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2552 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2553 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2554 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2555 static void x_get_glyph_overhangs
P_ ((struct glyph
*, struct frame
*,
2557 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
2558 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
2559 unsigned long *, double, int));
2560 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2561 double, int, unsigned long));
2562 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2563 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2564 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2565 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2566 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
2567 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
2568 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2570 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2571 int, int, int, int, XRectangle
*));
2572 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2573 int, int, int, XRectangle
*));
2574 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
2575 enum glyph_row_area
));
2576 static int x_fill_stretch_glyph_string
P_ ((struct glyph_string
*,
2578 enum glyph_row_area
, int, int));
2581 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
2585 /* Append the list of glyph strings with head H and tail T to the list
2586 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
2589 x_append_glyph_string_lists (head
, tail
, h
, t
)
2590 struct glyph_string
**head
, **tail
;
2591 struct glyph_string
*h
, *t
;
2605 /* Prepend the list of glyph strings with head H and tail T to the
2606 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
2610 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
2611 struct glyph_string
**head
, **tail
;
2612 struct glyph_string
*h
, *t
;
2626 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
2627 Set *HEAD and *TAIL to the resulting list. */
2630 x_append_glyph_string (head
, tail
, s
)
2631 struct glyph_string
**head
, **tail
;
2632 struct glyph_string
*s
;
2634 s
->next
= s
->prev
= NULL
;
2635 x_append_glyph_string_lists (head
, tail
, s
, s
);
2639 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2644 struct glyph_string
*s
;
2646 if (s
->font
== FRAME_FONT (s
->f
)
2647 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2648 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2650 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
2653 /* Cursor on non-default face: must merge. */
2657 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
2658 xgcv
.foreground
= s
->face
->background
;
2660 /* If the glyph would be invisible, try a different foreground. */
2661 if (xgcv
.foreground
== xgcv
.background
)
2662 xgcv
.foreground
= s
->face
->foreground
;
2663 if (xgcv
.foreground
== xgcv
.background
)
2664 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
2665 if (xgcv
.foreground
== xgcv
.background
)
2666 xgcv
.foreground
= s
->face
->foreground
;
2668 /* Make sure the cursor is distinct from text in this face. */
2669 if (xgcv
.background
== s
->face
->background
2670 && xgcv
.foreground
== s
->face
->foreground
)
2672 xgcv
.background
= s
->face
->foreground
;
2673 xgcv
.foreground
= s
->face
->background
;
2676 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2677 xgcv
.font
= s
->font
->fid
;
2678 xgcv
.graphics_exposures
= False
;
2679 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2681 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2682 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2685 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2686 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2688 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2693 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2696 x_set_mouse_face_gc (s
)
2697 struct glyph_string
*s
;
2702 /* What face has to be used last for the mouse face? */
2703 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2704 face
= FACE_FROM_ID (s
->f
, face_id
);
2706 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
2708 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2709 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2711 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2712 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2713 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2715 /* If font in this face is same as S->font, use it. */
2716 if (s
->font
== s
->face
->font
)
2717 s
->gc
= s
->face
->gc
;
2720 /* Otherwise construct scratch_cursor_gc with values from FACE
2725 xgcv
.background
= s
->face
->background
;
2726 xgcv
.foreground
= s
->face
->foreground
;
2727 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2728 xgcv
.font
= s
->font
->fid
;
2729 xgcv
.graphics_exposures
= False
;
2730 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2732 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2733 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2736 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2737 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2739 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2742 xassert (s
->gc
!= 0);
2746 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2747 Faces to use in the mode line have already been computed when the
2748 matrix was built, so there isn't much to do, here. */
2751 x_set_mode_line_face_gc (s
)
2752 struct glyph_string
*s
;
2754 s
->gc
= s
->face
->gc
;
2758 /* Set S->gc of glyph string S for drawing that glyph string. Set
2759 S->stippled_p to a non-zero value if the face of S has a stipple
2763 x_set_glyph_string_gc (s
)
2764 struct glyph_string
*s
;
2766 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2768 if (s
->hl
== DRAW_NORMAL_TEXT
)
2770 s
->gc
= s
->face
->gc
;
2771 s
->stippled_p
= s
->face
->stipple
!= 0;
2773 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2775 x_set_mode_line_face_gc (s
);
2776 s
->stippled_p
= s
->face
->stipple
!= 0;
2778 else if (s
->hl
== DRAW_CURSOR
)
2780 x_set_cursor_gc (s
);
2783 else if (s
->hl
== DRAW_MOUSE_FACE
)
2785 x_set_mouse_face_gc (s
);
2786 s
->stippled_p
= s
->face
->stipple
!= 0;
2788 else if (s
->hl
== DRAW_IMAGE_RAISED
2789 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2791 s
->gc
= s
->face
->gc
;
2792 s
->stippled_p
= s
->face
->stipple
!= 0;
2796 s
->gc
= s
->face
->gc
;
2797 s
->stippled_p
= s
->face
->stipple
!= 0;
2800 /* GC must have been set. */
2801 xassert (s
->gc
!= 0);
2805 /* Return in *R the clipping rectangle for glyph string S. */
2808 x_get_glyph_string_clip_rect (s
, r
)
2809 struct glyph_string
*s
;
2812 if (s
->row
->full_width_p
)
2814 /* Draw full-width. X coordinates are relative to S->w->left. */
2815 int canon_x
= CANON_X_UNIT (s
->f
);
2817 r
->x
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
2818 r
->width
= XFASTINT (s
->w
->width
) * canon_x
;
2820 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
2822 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
2823 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
2827 r
->x
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
2829 /* Unless displaying a mode or menu bar line, which are always
2830 fully visible, clip to the visible part of the row. */
2831 if (s
->w
->pseudo_window_p
)
2832 r
->height
= s
->row
->visible_height
;
2834 r
->height
= s
->height
;
2838 /* This is a text line that may be partially visible. */
2839 r
->x
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
2840 r
->width
= window_box_width (s
->w
, s
->area
);
2841 r
->height
= s
->row
->visible_height
;
2844 /* If S draws overlapping rows, it's sufficient to use the top and
2845 bottom of the window for clipping because this glyph string
2846 intentionally draws over other lines. */
2847 if (s
->for_overlaps_p
)
2849 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2850 r
->height
= window_text_bottom_y (s
->w
) - r
->y
;
2854 /* Don't use S->y for clipping because it doesn't take partially
2855 visible lines into account. For example, it can be negative for
2856 partially visible lines at the top of a window. */
2857 if (!s
->row
->full_width_p
2858 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2859 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2861 r
->y
= max (0, s
->row
->y
);
2863 /* If drawing a tool-bar window, draw it over the internal border
2864 at the top of the window. */
2865 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
2866 r
->y
-= s
->f
->output_data
.x
->internal_border_width
;
2869 r
->y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->y
);
2873 /* Set clipping for output of glyph string S. S may be part of a mode
2874 line or menu if we don't have X toolkit support. */
2877 x_set_glyph_string_clipping (s
)
2878 struct glyph_string
*s
;
2881 x_get_glyph_string_clip_rect (s
, &r
);
2882 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
2886 /* Compute left and right overhang of glyph string S. If S is a glyph
2887 string for a composition, assume overhangs don't exist. */
2890 x_compute_glyph_string_overhangs (s
)
2891 struct glyph_string
*s
;
2894 && s
->first_glyph
->type
== CHAR_GLYPH
)
2897 int direction
, font_ascent
, font_descent
;
2898 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
2899 &font_ascent
, &font_descent
, &cs
);
2900 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
2901 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
2906 /* Compute overhangs and x-positions for glyph string S and its
2907 predecessors, or successors. X is the starting x-position for S.
2908 BACKWARD_P non-zero means process predecessors. */
2911 x_compute_overhangs_and_x (s
, x
, backward_p
)
2912 struct glyph_string
*s
;
2920 x_compute_glyph_string_overhangs (s
);
2930 x_compute_glyph_string_overhangs (s
);
2939 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
2940 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
2941 assumed to be zero. */
2944 x_get_glyph_overhangs (glyph
, f
, left
, right
)
2945 struct glyph
*glyph
;
2951 if (glyph
->type
== CHAR_GLYPH
)
2955 struct font_info
*font_info
;
2959 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
2961 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
2963 && (pcm
= x_per_char_metric (font
, &char2b
)))
2965 if (pcm
->rbearing
> pcm
->width
)
2966 *right
= pcm
->rbearing
- pcm
->width
;
2967 if (pcm
->lbearing
< 0)
2968 *left
= -pcm
->lbearing
;
2974 /* Return the index of the first glyph preceding glyph string S that
2975 is overwritten by S because of S's left overhang. Value is -1
2976 if no glyphs are overwritten. */
2979 x_left_overwritten (s
)
2980 struct glyph_string
*s
;
2984 if (s
->left_overhang
)
2987 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2988 int first
= s
->first_glyph
- glyphs
;
2990 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
2991 x
-= glyphs
[i
].pixel_width
;
3002 /* Return the index of the first glyph preceding glyph string S that
3003 is overwriting S because of its right overhang. Value is -1 if no
3004 glyph in front of S overwrites S. */
3007 x_left_overwriting (s
)
3008 struct glyph_string
*s
;
3011 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3012 int first
= s
->first_glyph
- glyphs
;
3016 for (i
= first
- 1; i
>= 0; --i
)
3019 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3022 x
-= glyphs
[i
].pixel_width
;
3029 /* Return the index of the last glyph following glyph string S that is
3030 not overwritten by S because of S's right overhang. Value is -1 if
3031 no such glyph is found. */
3034 x_right_overwritten (s
)
3035 struct glyph_string
*s
;
3039 if (s
->right_overhang
)
3042 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3043 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3044 int end
= s
->row
->used
[s
->area
];
3046 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
3047 x
+= glyphs
[i
].pixel_width
;
3056 /* Return the index of the last glyph following glyph string S that
3057 overwrites S because of its left overhang. Value is negative
3058 if no such glyph is found. */
3061 x_right_overwriting (s
)
3062 struct glyph_string
*s
;
3065 int end
= s
->row
->used
[s
->area
];
3066 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3067 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3071 for (i
= first
; i
< end
; ++i
)
3074 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3077 x
+= glyphs
[i
].pixel_width
;
3084 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
3087 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
3088 struct glyph_string
*s
;
3092 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
3093 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3094 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3095 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3099 /* Draw the background of glyph_string S. If S->background_filled_p
3100 is non-zero don't draw it. FORCE_P non-zero means draw the
3101 background even if it wouldn't be drawn normally. This is used
3102 when a string preceding S draws into the background of S, or S
3103 contains the first component of a composition. */
3106 x_draw_glyph_string_background (s
, force_p
)
3107 struct glyph_string
*s
;
3110 /* Nothing to do if background has already been drawn or if it
3111 shouldn't be drawn in the first place. */
3112 if (!s
->background_filled_p
)
3114 int box_line_width
= max (s
->face
->box_line_width
, 0);
3118 /* Fill background with a stipple pattern. */
3119 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3120 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
3121 s
->y
+ box_line_width
,
3122 s
->background_width
,
3123 s
->height
- 2 * box_line_width
);
3124 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3125 s
->background_filled_p
= 1;
3127 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
3128 || s
->font_not_found_p
3129 || s
->extends_to_end_of_line_p
3132 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
3133 s
->background_width
,
3134 s
->height
- 2 * box_line_width
);
3135 s
->background_filled_p
= 1;
3141 /* Draw the foreground of glyph string S. */
3144 x_draw_glyph_string_foreground (s
)
3145 struct glyph_string
*s
;
3149 /* If first glyph of S has a left box line, start drawing the text
3150 of S to the right of that box line. */
3151 if (s
->face
->box
!= FACE_NO_BOX
3152 && s
->first_glyph
->left_box_line_p
)
3153 x
= s
->x
+ abs (s
->face
->box_line_width
);
3157 /* Draw characters of S as rectangles if S's font could not be
3159 if (s
->font_not_found_p
)
3161 for (i
= 0; i
< s
->nchars
; ++i
)
3163 struct glyph
*g
= s
->first_glyph
+ i
;
3164 XDrawRectangle (s
->display
, s
->window
,
3165 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
3167 x
+= g
->pixel_width
;
3172 char *char1b
= (char *) s
->char2b
;
3173 int boff
= s
->font_info
->baseline_offset
;
3175 if (s
->font_info
->vertical_centering
)
3176 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
3178 /* If we can use 8-bit functions, condense S->char2b. */
3180 for (i
= 0; i
< s
->nchars
; ++i
)
3181 char1b
[i
] = s
->char2b
[i
].byte2
;
3183 /* Draw text with XDrawString if background has already been
3184 filled. Otherwise, use XDrawImageString. (Note that
3185 XDrawImageString is usually faster than XDrawString.) Always
3186 use XDrawImageString when drawing the cursor so that there is
3187 no chance that characters under a box cursor are invisible. */
3188 if (s
->for_overlaps_p
3189 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
3191 /* Draw characters with 16-bit or 8-bit functions. */
3193 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
3194 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3196 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
3197 s
->ybase
- boff
, char1b
, s
->nchars
);
3202 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
3203 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3205 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
3206 s
->ybase
- boff
, char1b
, s
->nchars
);
3211 /* Draw the foreground of composite glyph string S. */
3214 x_draw_composite_glyph_string_foreground (s
)
3215 struct glyph_string
*s
;
3219 /* If first glyph of S has a left box line, start drawing the text
3220 of S to the right of that box line. */
3221 if (s
->face
->box
!= FACE_NO_BOX
3222 && s
->first_glyph
->left_box_line_p
)
3223 x
= s
->x
+ abs (s
->face
->box_line_width
);
3227 /* S is a glyph string for a composition. S->gidx is the index of
3228 the first character drawn for glyphs of this composition.
3229 S->gidx == 0 means we are drawing the very first character of
3230 this composition. */
3232 /* Draw a rectangle for the composition if the font for the very
3233 first character of the composition could not be loaded. */
3234 if (s
->font_not_found_p
)
3237 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
3238 s
->width
- 1, s
->height
- 1);
3242 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3243 XDrawString16 (s
->display
, s
->window
, s
->gc
,
3244 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3245 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3251 #ifdef USE_X_TOOLKIT
3253 static struct frame
*x_frame_of_widget
P_ ((Widget
));
3254 static Boolean cvt_string_to_pixel
P_ ((Display
*, XrmValue
*, Cardinal
*,
3255 XrmValue
*, XrmValue
*, XtPointer
*));
3256 static void cvt_pixel_dtor
P_ ((XtAppContext
, XrmValue
*, XtPointer
,
3257 XrmValue
*, Cardinal
*));
3260 /* Return the frame on which widget WIDGET is used.. Abort if frame
3261 cannot be determined. */
3263 static struct frame
*
3264 x_frame_of_widget (widget
)
3267 struct x_display_info
*dpyinfo
;
3271 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
3273 /* Find the top-level shell of the widget. Note that this function
3274 can be called when the widget is not yet realized, so XtWindow
3275 (widget) == 0. That's the reason we can't simply use
3276 x_any_window_to_frame. */
3277 while (!XtIsTopLevelShell (widget
))
3278 widget
= XtParent (widget
);
3280 /* Look for a frame with that top-level widget. Allocate the color
3281 on that frame to get the right gamma correction value. */
3282 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
3283 if (GC_FRAMEP (XCAR (tail
))
3284 && (f
= XFRAME (XCAR (tail
)),
3285 (f
->output_data
.nothing
!= 1
3286 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
3287 && f
->output_data
.x
->widget
== widget
)
3294 /* Allocate the color COLOR->pixel on the screen and display of
3295 widget WIDGET in colormap CMAP. If an exact match cannot be
3296 allocated, try the nearest color available. Value is non-zero
3297 if successful. This is called from lwlib. */
3300 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
3305 struct frame
*f
= x_frame_of_widget (widget
);
3306 return x_alloc_nearest_color (f
, cmap
, color
);
3310 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3311 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3312 If this produces the same color as PIXEL, try a color where all RGB
3313 values have DELTA added. Return the allocated color in *PIXEL.
3314 DISPLAY is the X display, CMAP is the colormap to operate on.
3315 Value is non-zero if successful. */
3318 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
3322 unsigned long *pixel
;
3326 struct frame
*f
= x_frame_of_widget (widget
);
3327 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
3331 /* Structure specifying which arguments should be passed by Xt to
3332 cvt_string_to_pixel. We want the widget's screen and colormap. */
3334 static XtConvertArgRec cvt_string_to_pixel_args
[] =
3336 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
3338 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
3343 /* The address of this variable is returned by
3344 cvt_string_to_pixel. */
3346 static Pixel cvt_string_to_pixel_value
;
3349 /* Convert a color name to a pixel color.
3351 DPY is the display we are working on.
3353 ARGS is an array of *NARGS XrmValue structures holding additional
3354 information about the widget for which the conversion takes place.
3355 The contents of this array are determined by the specification
3356 in cvt_string_to_pixel_args.
3358 FROM is a pointer to an XrmValue which points to the color name to
3359 convert. TO is an XrmValue in which to return the pixel color.
3361 CLOSURE_RET is a pointer to user-data, in which we record if
3362 we allocated the color or not.
3364 Value is True if successful, False otherwise. */
3367 cvt_string_to_pixel (dpy
, args
, nargs
, from
, to
, closure_ret
)
3371 XrmValue
*from
, *to
;
3372 XtPointer
*closure_ret
;
3382 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
3383 "wrongParameters", "cvt_string_to_pixel",
3385 "Screen and colormap args required", NULL
, NULL
);
3389 screen
= *(Screen
**) args
[0].addr
;
3390 cmap
= *(Colormap
*) args
[1].addr
;
3391 color_name
= (String
) from
->addr
;
3393 if (strcmp (color_name
, XtDefaultBackground
) == 0)
3395 *closure_ret
= (XtPointer
) False
;
3396 pixel
= WhitePixelOfScreen (screen
);
3398 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
3400 *closure_ret
= (XtPointer
) False
;
3401 pixel
= BlackPixelOfScreen (screen
);
3403 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
3404 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
3406 pixel
= color
.pixel
;
3407 *closure_ret
= (XtPointer
) True
;
3412 Cardinal nparams
= 1;
3414 params
[0] = color_name
;
3415 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
3416 "badValue", "cvt_string_to_pixel",
3417 "XtToolkitError", "Invalid color `%s'",
3422 if (to
->addr
!= NULL
)
3424 if (to
->size
< sizeof (Pixel
))
3426 to
->size
= sizeof (Pixel
);
3430 *(Pixel
*) to
->addr
= pixel
;
3434 cvt_string_to_pixel_value
= pixel
;
3435 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
3438 to
->size
= sizeof (Pixel
);
3443 /* Free a pixel color which was previously allocated via
3444 cvt_string_to_pixel. This is registered as the destructor
3445 for this type of resource via XtSetTypeConverter.
3447 APP is the application context in which we work.
3449 TO is a pointer to an XrmValue holding the color to free.
3450 CLOSURE is the value we stored in CLOSURE_RET for this color
3451 in cvt_string_to_pixel.
3453 ARGS and NARGS are like for cvt_string_to_pixel. */
3456 cvt_pixel_dtor (app
, to
, closure
, args
, nargs
)
3465 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
3467 "Screen and colormap arguments required",
3470 else if (closure
!= NULL
)
3472 /* We did allocate the pixel, so free it. */
3473 Screen
*screen
= *(Screen
**) args
[0].addr
;
3474 Colormap cmap
= *(Colormap
*) args
[1].addr
;
3475 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
3476 (Pixel
*) to
->addr
, 1);
3481 #endif /* USE_X_TOOLKIT */
3484 /* Value is an array of XColor structures for the contents of the
3485 color map of display DPY. Set *NCELLS to the size of the array.
3486 Note that this probably shouldn't be called for large color maps,
3487 say a 24-bit TrueColor map. */
3489 static const XColor
*
3490 x_color_cells (dpy
, ncells
)
3494 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
3496 if (dpyinfo
->color_cells
== NULL
)
3498 Screen
*screen
= dpyinfo
->screen
;
3501 dpyinfo
->ncolor_cells
3502 = XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
3503 dpyinfo
->color_cells
3504 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
3505 * sizeof *dpyinfo
->color_cells
);
3507 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
3508 dpyinfo
->color_cells
[i
].pixel
= i
;
3510 XQueryColors (dpy
, dpyinfo
->cmap
,
3511 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
3514 *ncells
= dpyinfo
->ncolor_cells
;
3515 return dpyinfo
->color_cells
;
3519 /* On frame F, translate pixel colors to RGB values for the NCOLORS
3520 colors in COLORS. Use cached information, if available. */
3523 x_query_colors (f
, colors
, ncolors
)
3528 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3530 if (dpyinfo
->color_cells
)
3533 for (i
= 0; i
< ncolors
; ++i
)
3535 unsigned long pixel
= colors
[i
].pixel
;
3536 xassert (pixel
< dpyinfo
->ncolor_cells
);
3537 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
3538 colors
[i
] = dpyinfo
->color_cells
[pixel
];
3542 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
3546 /* On frame F, translate pixel color to RGB values for the color in
3547 COLOR. Use cached information, if available. */
3550 x_query_color (f
, color
)
3554 x_query_colors (f
, color
, 1);
3558 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
3559 exact match can't be allocated, try the nearest color available.
3560 Value is non-zero if successful. Set *COLOR to the color
3564 x_alloc_nearest_color_1 (dpy
, cmap
, color
)
3571 rc
= XAllocColor (dpy
, cmap
, color
);
3574 /* If we got to this point, the colormap is full, so we're going
3575 to try to get the next closest color. The algorithm used is
3576 a least-squares matching, which is what X uses for closest
3577 color matching with StaticColor visuals. */
3579 unsigned long nearest_delta
= ~0;
3581 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
3583 for (nearest
= i
= 0; i
< ncells
; ++i
)
3585 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
3586 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
3587 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
3588 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
3590 if (delta
< nearest_delta
)
3593 nearest_delta
= delta
;
3597 color
->red
= cells
[nearest
].red
;
3598 color
->green
= cells
[nearest
].green
;
3599 color
->blue
= cells
[nearest
].blue
;
3600 rc
= XAllocColor (dpy
, cmap
, color
);
3604 /* If allocation succeeded, and the allocated pixel color is not
3605 equal to a cached pixel color recorded earlier, there was a
3606 change in the colormap, so clear the color cache. */
3607 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
3608 XColor
*cached_color
;
3610 if (dpyinfo
->color_cells
3611 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
3612 (cached_color
->red
!= color
->red
3613 || cached_color
->blue
!= color
->blue
3614 || cached_color
->green
!= color
->green
)))
3616 xfree (dpyinfo
->color_cells
);
3617 dpyinfo
->color_cells
= NULL
;
3618 dpyinfo
->ncolor_cells
= 0;
3622 #ifdef DEBUG_X_COLORS
3624 register_color (color
->pixel
);
3625 #endif /* DEBUG_X_COLORS */
3631 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
3632 exact match can't be allocated, try the nearest color available.
3633 Value is non-zero if successful. Set *COLOR to the color
3637 x_alloc_nearest_color (f
, cmap
, color
)
3642 gamma_correct (f
, color
);
3643 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
3647 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
3648 It's necessary to do this instead of just using PIXEL directly to
3649 get color reference counts right. */
3652 x_copy_color (f
, pixel
)
3654 unsigned long pixel
;
3658 color
.pixel
= pixel
;
3660 x_query_color (f
, &color
);
3661 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3663 #ifdef DEBUG_X_COLORS
3664 register_color (pixel
);
3670 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
3671 It's necessary to do this instead of just using PIXEL directly to
3672 get color reference counts right. */
3675 x_copy_dpy_color (dpy
, cmap
, pixel
)
3678 unsigned long pixel
;
3682 color
.pixel
= pixel
;
3684 XQueryColor (dpy
, cmap
, &color
);
3685 XAllocColor (dpy
, cmap
, &color
);
3687 #ifdef DEBUG_X_COLORS
3688 register_color (pixel
);
3694 /* Brightness beyond which a color won't have its highlight brightness
3697 Nominally, highlight colors for `3d' faces are calculated by
3698 brightening an object's color by a constant scale factor, but this
3699 doesn't yield good results for dark colors, so for colors who's
3700 brightness is less than this value (on a scale of 0-65535) have an
3701 use an additional additive factor.
3703 The value here is set so that the default menu-bar/mode-line color
3704 (grey75) will not have its highlights changed at all. */
3705 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
3708 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3709 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3710 If this produces the same color as PIXEL, try a color where all RGB
3711 values have DELTA added. Return the allocated color in *PIXEL.
3712 DISPLAY is the X display, CMAP is the colormap to operate on.
3713 Value is non-zero if successful. */
3716 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
3720 unsigned long *pixel
;
3728 /* Get RGB color values. */
3729 color
.pixel
= *pixel
;
3730 x_query_color (f
, &color
);
3732 /* Change RGB values by specified FACTOR. Avoid overflow! */
3733 xassert (factor
>= 0);
3734 new.red
= min (0xffff, factor
* color
.red
);
3735 new.green
= min (0xffff, factor
* color
.green
);
3736 new.blue
= min (0xffff, factor
* color
.blue
);
3738 /* Calculate brightness of COLOR. */
3739 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
3741 /* We only boost colors that are darker than
3742 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
3743 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
3744 /* Make an additive adjustment to NEW, because it's dark enough so
3745 that scaling by FACTOR alone isn't enough. */
3747 /* How far below the limit this color is (0 - 1, 1 being darker). */
3748 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
3749 /* The additive adjustment. */
3750 int min_delta
= delta
* dimness
* factor
/ 2;
3754 new.red
= max (0, new.red
- min_delta
);
3755 new.green
= max (0, new.green
- min_delta
);
3756 new.blue
= max (0, new.blue
- min_delta
);
3760 new.red
= min (0xffff, min_delta
+ new.red
);
3761 new.green
= min (0xffff, min_delta
+ new.green
);
3762 new.blue
= min (0xffff, min_delta
+ new.blue
);
3766 /* Try to allocate the color. */
3767 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3770 if (new.pixel
== *pixel
)
3772 /* If we end up with the same color as before, try adding
3773 delta to the RGB values. */
3774 x_free_colors (f
, &new.pixel
, 1);
3776 new.red
= min (0xffff, delta
+ color
.red
);
3777 new.green
= min (0xffff, delta
+ color
.green
);
3778 new.blue
= min (0xffff, delta
+ color
.blue
);
3779 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3790 /* Set up the foreground color for drawing relief lines of glyph
3791 string S. RELIEF is a pointer to a struct relief containing the GC
3792 with which lines will be drawn. Use a color that is FACTOR or
3793 DELTA lighter or darker than the relief's background which is found
3794 in S->f->output_data.x->relief_background. If such a color cannot
3795 be allocated, use DEFAULT_PIXEL, instead. */
3798 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3800 struct relief
*relief
;
3803 unsigned long default_pixel
;
3806 struct x_output
*di
= f
->output_data
.x
;
3807 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
3808 unsigned long pixel
;
3809 unsigned long background
= di
->relief_background
;
3810 Colormap cmap
= FRAME_X_COLORMAP (f
);
3811 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3812 Display
*dpy
= FRAME_X_DISPLAY (f
);
3814 xgcv
.graphics_exposures
= False
;
3815 xgcv
.line_width
= 1;
3817 /* Free previously allocated color. The color cell will be reused
3818 when it has been freed as many times as it was allocated, so this
3819 doesn't affect faces using the same colors. */
3821 && relief
->allocated_p
)
3823 x_free_colors (f
, &relief
->pixel
, 1);
3824 relief
->allocated_p
= 0;
3827 /* Allocate new color. */
3828 xgcv
.foreground
= default_pixel
;
3830 if (dpyinfo
->n_planes
!= 1
3831 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
3833 relief
->allocated_p
= 1;
3834 xgcv
.foreground
= relief
->pixel
= pixel
;
3837 if (relief
->gc
== 0)
3839 xgcv
.stipple
= dpyinfo
->gray
;
3841 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
3844 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
3848 /* Set up colors for the relief lines around glyph string S. */
3851 x_setup_relief_colors (s
)
3852 struct glyph_string
*s
;
3854 struct x_output
*di
= s
->f
->output_data
.x
;
3855 unsigned long color
;
3857 if (s
->face
->use_box_color_for_shadows_p
)
3858 color
= s
->face
->box_color
;
3859 else if (s
->first_glyph
->type
== IMAGE_GLYPH
3861 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
3862 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
3867 /* Get the background color of the face. */
3868 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3869 color
= xgcv
.background
;
3872 if (di
->white_relief
.gc
== 0
3873 || color
!= di
->relief_background
)
3875 di
->relief_background
= color
;
3876 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3877 WHITE_PIX_DEFAULT (s
->f
));
3878 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3879 BLACK_PIX_DEFAULT (s
->f
));
3884 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3885 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3886 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3887 relief. LEFT_P non-zero means draw a relief on the left side of
3888 the rectangle. RIGHT_P non-zero means draw a relief on the right
3889 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3893 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3894 raised_p
, left_p
, right_p
, clip_rect
)
3896 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
3897 XRectangle
*clip_rect
;
3899 Display
*dpy
= FRAME_X_DISPLAY (f
);
3900 Window window
= FRAME_X_WINDOW (f
);
3905 gc
= f
->output_data
.x
->white_relief
.gc
;
3907 gc
= f
->output_data
.x
->black_relief
.gc
;
3908 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
3911 for (i
= 0; i
< width
; ++i
)
3912 XDrawLine (dpy
, window
, gc
,
3913 left_x
+ i
* left_p
, top_y
+ i
,
3914 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3918 for (i
= 0; i
< width
; ++i
)
3919 XDrawLine (dpy
, window
, gc
,
3920 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
3922 XSetClipMask (dpy
, gc
, None
);
3924 gc
= f
->output_data
.x
->black_relief
.gc
;
3926 gc
= f
->output_data
.x
->white_relief
.gc
;
3927 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
3930 for (i
= 0; i
< width
; ++i
)
3931 XDrawLine (dpy
, window
, gc
,
3932 left_x
+ i
* left_p
, bottom_y
- i
,
3933 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3937 for (i
= 0; i
< width
; ++i
)
3938 XDrawLine (dpy
, window
, gc
,
3939 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3941 XSetClipMask (dpy
, gc
, None
);
3945 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3946 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3947 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3948 left side of the rectangle. RIGHT_P non-zero means draw a line
3949 on the right side of the rectangle. CLIP_RECT is the clipping
3950 rectangle to use when drawing. */
3953 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3954 left_p
, right_p
, clip_rect
)
3955 struct glyph_string
*s
;
3956 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
;
3957 XRectangle
*clip_rect
;
3961 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3962 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
3963 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
3966 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3967 left_x
, top_y
, right_x
- left_x
+ 1, width
);
3971 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3972 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
3975 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3976 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
3980 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3981 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
3983 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3984 XSetClipMask (s
->display
, s
->gc
, None
);
3988 /* Draw a box around glyph string S. */
3991 x_draw_glyph_string_box (s
)
3992 struct glyph_string
*s
;
3994 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3995 int left_p
, right_p
;
3996 struct glyph
*last_glyph
;
3997 XRectangle clip_rect
;
3999 last_x
= window_box_right (s
->w
, s
->area
);
4000 if (s
->row
->full_width_p
4001 && !s
->w
->pseudo_window_p
)
4003 last_x
+= FRAME_X_RIGHT_FRINGE_WIDTH (s
->f
);
4004 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
4005 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
4008 /* The glyph that may have a right box line. */
4009 last_glyph
= (s
->cmp
|| s
->img
4011 : s
->first_glyph
+ s
->nchars
- 1);
4013 width
= abs (s
->face
->box_line_width
);
4014 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
4016 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
4018 : min (last_x
, s
->x
+ s
->background_width
) - 1);
4020 bottom_y
= top_y
+ s
->height
- 1;
4022 left_p
= (s
->first_glyph
->left_box_line_p
4023 || (s
->hl
== DRAW_MOUSE_FACE
4025 || s
->prev
->hl
!= s
->hl
)));
4026 right_p
= (last_glyph
->right_box_line_p
4027 || (s
->hl
== DRAW_MOUSE_FACE
4029 || s
->next
->hl
!= s
->hl
)));
4031 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4033 if (s
->face
->box
== FACE_SIMPLE_BOX
)
4034 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
4035 left_p
, right_p
, &clip_rect
);
4038 x_setup_relief_colors (s
);
4039 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
4040 width
, raised_p
, left_p
, right_p
, &clip_rect
);
4045 /* Draw foreground of image glyph string S. */
4048 x_draw_image_foreground (s
)
4049 struct glyph_string
*s
;
4052 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
4054 /* If first glyph of S has a left box line, start drawing it to the
4055 right of that line. */
4056 if (s
->face
->box
!= FACE_NO_BOX
4057 && s
->first_glyph
->left_box_line_p
)
4058 x
= s
->x
+ abs (s
->face
->box_line_width
);
4062 /* If there is a margin around the image, adjust x- and y-position
4064 x
+= s
->img
->hmargin
;
4065 y
+= s
->img
->vmargin
;
4071 /* We can't set both a clip mask and use XSetClipRectangles
4072 because the latter also sets a clip mask. We also can't
4073 trust on the shape extension to be available
4074 (XShapeCombineRegion). So, compute the rectangle to draw
4076 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4079 XRectangle clip_rect
, image_rect
, r
;
4081 xgcv
.clip_mask
= s
->img
->mask
;
4082 xgcv
.clip_x_origin
= x
;
4083 xgcv
.clip_y_origin
= y
;
4084 xgcv
.function
= GXcopy
;
4085 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4087 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4090 image_rect
.width
= s
->img
->width
;
4091 image_rect
.height
= s
->img
->height
;
4092 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
4093 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
4094 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
4098 XRectangle clip_rect
, image_rect
, r
;
4100 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4103 image_rect
.width
= s
->img
->width
;
4104 image_rect
.height
= s
->img
->height
;
4105 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
4106 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
4107 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
4109 /* When the image has a mask, we can expect that at
4110 least part of a mouse highlight or a block cursor will
4111 be visible. If the image doesn't have a mask, make
4112 a block cursor visible by drawing a rectangle around
4113 the image. I believe it's looking better if we do
4114 nothing here for mouse-face. */
4115 if (s
->hl
== DRAW_CURSOR
)
4116 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
4117 s
->img
->width
- 1, s
->img
->height
- 1);
4121 /* Draw a rectangle if image could not be loaded. */
4122 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
4123 s
->img
->width
- 1, s
->img
->height
- 1);
4127 /* Draw a relief around the image glyph string S. */
4130 x_draw_image_relief (s
)
4131 struct glyph_string
*s
;
4133 int x0
, y0
, x1
, y1
, thick
, raised_p
;
4136 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
4138 /* If first glyph of S has a left box line, start drawing it to the
4139 right of that line. */
4140 if (s
->face
->box
!= FACE_NO_BOX
4141 && s
->first_glyph
->left_box_line_p
)
4142 x
= s
->x
+ abs (s
->face
->box_line_width
);
4146 /* If there is a margin around the image, adjust x- and y-position
4148 x
+= s
->img
->hmargin
;
4149 y
+= s
->img
->vmargin
;
4151 if (s
->hl
== DRAW_IMAGE_SUNKEN
4152 || s
->hl
== DRAW_IMAGE_RAISED
)
4154 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
4155 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
4159 thick
= abs (s
->img
->relief
);
4160 raised_p
= s
->img
->relief
> 0;
4165 x1
= x
+ s
->img
->width
+ thick
- 1;
4166 y1
= y
+ s
->img
->height
+ thick
- 1;
4168 x_setup_relief_colors (s
);
4169 x_get_glyph_string_clip_rect (s
, &r
);
4170 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
4174 /* Draw the foreground of image glyph string S to PIXMAP. */
4177 x_draw_image_foreground_1 (s
, pixmap
)
4178 struct glyph_string
*s
;
4182 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
4184 /* If first glyph of S has a left box line, start drawing it to the
4185 right of that line. */
4186 if (s
->face
->box
!= FACE_NO_BOX
4187 && s
->first_glyph
->left_box_line_p
)
4188 x
= abs (s
->face
->box_line_width
);
4192 /* If there is a margin around the image, adjust x- and y-position
4194 x
+= s
->img
->hmargin
;
4195 y
+= s
->img
->vmargin
;
4201 /* We can't set both a clip mask and use XSetClipRectangles
4202 because the latter also sets a clip mask. We also can't
4203 trust on the shape extension to be available
4204 (XShapeCombineRegion). So, compute the rectangle to draw
4206 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4210 xgcv
.clip_mask
= s
->img
->mask
;
4211 xgcv
.clip_x_origin
= x
;
4212 xgcv
.clip_y_origin
= y
;
4213 xgcv
.function
= GXcopy
;
4214 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4216 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4217 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4218 XSetClipMask (s
->display
, s
->gc
, None
);
4222 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4223 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4225 /* When the image has a mask, we can expect that at
4226 least part of a mouse highlight or a block cursor will
4227 be visible. If the image doesn't have a mask, make
4228 a block cursor visible by drawing a rectangle around
4229 the image. I believe it's looking better if we do
4230 nothing here for mouse-face. */
4231 if (s
->hl
== DRAW_CURSOR
)
4232 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
4233 s
->img
->width
- 1, s
->img
->height
- 1);
4237 /* Draw a rectangle if image could not be loaded. */
4238 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
4239 s
->img
->width
- 1, s
->img
->height
- 1);
4243 /* Draw part of the background of glyph string S. X, Y, W, and H
4244 give the rectangle to draw. */
4247 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
4248 struct glyph_string
*s
;
4253 /* Fill background with a stipple pattern. */
4254 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4255 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
4256 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4259 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
4263 /* Draw image glyph string S.
4266 s->x +-------------------------
4269 | +-------------------------
4272 | | +-------------------
4278 x_draw_image_glyph_string (s
)
4279 struct glyph_string
*s
;
4282 int box_line_hwidth
= abs (s
->face
->box_line_width
);
4283 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
4285 Pixmap pixmap
= None
;
4287 height
= s
->height
- 2 * box_line_vwidth
;
4289 /* Fill background with face under the image. Do it only if row is
4290 taller than image or if image has a clip mask to reduce
4292 s
->stippled_p
= s
->face
->stipple
!= 0;
4293 if (height
> s
->img
->height
4297 || s
->img
->pixmap
== 0
4298 || s
->width
!= s
->background_width
)
4300 if (box_line_hwidth
&& s
->first_glyph
->left_box_line_p
)
4301 x
= s
->x
+ box_line_hwidth
;
4305 y
= s
->y
+ box_line_vwidth
;
4309 /* Create a pixmap as large as the glyph string. Fill it
4310 with the background color. Copy the image to it, using
4311 its mask. Copy the temporary pixmap to the display. */
4312 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
4313 int depth
= DefaultDepthOfScreen (screen
);
4315 /* Create a pixmap as large as the glyph string. */
4316 pixmap
= XCreatePixmap (s
->display
, s
->window
,
4317 s
->background_width
,
4320 /* Don't clip in the following because we're working on the
4322 XSetClipMask (s
->display
, s
->gc
, None
);
4324 /* Fill the pixmap with the background color/stipple. */
4327 /* Fill background with a stipple pattern. */
4328 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4329 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4330 0, 0, s
->background_width
, s
->height
);
4331 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4336 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
4338 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
4339 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4340 0, 0, s
->background_width
, s
->height
);
4341 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4345 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
4347 s
->background_filled_p
= 1;
4350 /* Draw the foreground. */
4353 x_draw_image_foreground_1 (s
, pixmap
);
4354 x_set_glyph_string_clipping (s
);
4355 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
4356 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
4357 XFreePixmap (s
->display
, pixmap
);
4360 x_draw_image_foreground (s
);
4362 /* If we must draw a relief around the image, do it. */
4364 || s
->hl
== DRAW_IMAGE_RAISED
4365 || s
->hl
== DRAW_IMAGE_SUNKEN
)
4366 x_draw_image_relief (s
);
4370 /* Draw stretch glyph string S. */
4373 x_draw_stretch_glyph_string (s
)
4374 struct glyph_string
*s
;
4376 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4377 s
->stippled_p
= s
->face
->stipple
!= 0;
4379 if (s
->hl
== DRAW_CURSOR
4380 && !x_stretch_cursor_p
)
4382 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
4383 as wide as the stretch glyph. */
4384 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
4387 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
4389 /* Clear rest using the GC of the original non-cursor face. */
4390 if (width
< s
->background_width
)
4392 int x
= s
->x
+ width
, y
= s
->y
;
4393 int w
= s
->background_width
- width
, h
= s
->height
;
4397 if (s
->row
->mouse_face_p
4398 && cursor_in_mouse_face_p (s
->w
))
4400 x_set_mouse_face_gc (s
);
4406 x_get_glyph_string_clip_rect (s
, &r
);
4407 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
4409 if (s
->face
->stipple
)
4411 /* Fill background with a stipple pattern. */
4412 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
4413 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4414 XSetFillStyle (s
->display
, gc
, FillSolid
);
4419 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
4420 XSetForeground (s
->display
, gc
, xgcv
.background
);
4421 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4422 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
4426 else if (!s
->background_filled_p
)
4427 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
4430 s
->background_filled_p
= 1;
4434 /* Draw glyph string S. */
4437 x_draw_glyph_string (s
)
4438 struct glyph_string
*s
;
4440 int relief_drawn_p
= 0;
4442 /* If S draws into the background of its successor, draw the
4443 background of the successor first so that S can draw into it.
4444 This makes S->next use XDrawString instead of XDrawImageString. */
4445 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4447 xassert (s
->next
->img
== NULL
);
4448 x_set_glyph_string_gc (s
->next
);
4449 x_set_glyph_string_clipping (s
->next
);
4450 x_draw_glyph_string_background (s
->next
, 1);
4453 /* Set up S->gc, set clipping and draw S. */
4454 x_set_glyph_string_gc (s
);
4456 /* Draw relief (if any) in advance for char/composition so that the
4457 glyph string can be drawn over it. */
4458 if (!s
->for_overlaps_p
4459 && s
->face
->box
!= FACE_NO_BOX
4460 && (s
->first_glyph
->type
== CHAR_GLYPH
4461 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
4464 x_set_glyph_string_clipping (s
);
4465 x_draw_glyph_string_background (s
, 1);
4466 x_draw_glyph_string_box (s
);
4467 x_set_glyph_string_clipping (s
);
4471 x_set_glyph_string_clipping (s
);
4473 switch (s
->first_glyph
->type
)
4476 x_draw_image_glyph_string (s
);
4480 x_draw_stretch_glyph_string (s
);
4484 if (s
->for_overlaps_p
)
4485 s
->background_filled_p
= 1;
4487 x_draw_glyph_string_background (s
, 0);
4488 x_draw_glyph_string_foreground (s
);
4491 case COMPOSITE_GLYPH
:
4492 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4493 s
->background_filled_p
= 1;
4495 x_draw_glyph_string_background (s
, 1);
4496 x_draw_composite_glyph_string_foreground (s
);
4503 if (!s
->for_overlaps_p
)
4505 /* Draw underline. */
4506 if (s
->face
->underline_p
)
4508 unsigned long tem
, h
;
4511 /* Get the underline thickness. Default is 1 pixel. */
4512 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
4515 /* Get the underline position. This is the recommended
4516 vertical offset in pixels from the baseline to the top of
4517 the underline. This is a signed value according to the
4518 specs, and its default is
4520 ROUND ((maximum descent) / 2), with
4521 ROUND(x) = floor (x + 0.5) */
4523 if (x_use_underline_position_properties
4524 && XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &tem
))
4525 y
= s
->ybase
+ (long) tem
;
4526 else if (s
->face
->font
)
4527 y
= s
->ybase
+ (s
->face
->font
->max_bounds
.descent
+ 1) / 2;
4529 y
= s
->y
+ s
->height
- h
;
4531 if (s
->face
->underline_defaulted_p
)
4532 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4533 s
->x
, y
, s
->width
, h
);
4537 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4538 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
4539 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4540 s
->x
, y
, s
->width
, h
);
4541 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4545 /* Draw overline. */
4546 if (s
->face
->overline_p
)
4548 unsigned long dy
= 0, h
= 1;
4550 if (s
->face
->overline_color_defaulted_p
)
4551 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4556 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4557 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
4558 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4560 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4564 /* Draw strike-through. */
4565 if (s
->face
->strike_through_p
)
4567 unsigned long h
= 1;
4568 unsigned long dy
= (s
->height
- h
) / 2;
4570 if (s
->face
->strike_through_color_defaulted_p
)
4571 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4576 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4577 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
4578 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4580 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4584 /* Draw relief if not yet drawn. */
4585 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
4586 x_draw_glyph_string_box (s
);
4589 /* Reset clipping. */
4590 XSetClipMask (s
->display
, s
->gc
, None
);
4594 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4595 struct face
**, int));
4598 /* Fill glyph string S with composition components specified by S->cmp.
4600 FACES is an array of faces for all components of this composition.
4601 S->gidx is the index of the first component for S.
4602 OVERLAPS_P non-zero means S should draw the foreground only, and
4603 use its physical height for clipping.
4605 Value is the index of a component not in S. */
4608 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4609 struct glyph_string
*s
;
4610 struct face
**faces
;
4617 s
->for_overlaps_p
= overlaps_p
;
4619 s
->face
= faces
[s
->gidx
];
4620 s
->font
= s
->face
->font
;
4621 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4623 /* For all glyphs of this composition, starting at the offset
4624 S->gidx, until we reach the end of the definition or encounter a
4625 glyph that requires the different face, add it to S. */
4627 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4630 /* All glyph strings for the same composition has the same width,
4631 i.e. the width set for the first component of the composition. */
4633 s
->width
= s
->first_glyph
->pixel_width
;
4635 /* If the specified font could not be loaded, use the frame's
4636 default font, but record the fact that we couldn't load it in
4637 the glyph string so that we can draw rectangles for the
4638 characters of the glyph string. */
4639 if (s
->font
== NULL
)
4641 s
->font_not_found_p
= 1;
4642 s
->font
= FRAME_FONT (s
->f
);
4645 /* Adjust base line for subscript/superscript text. */
4646 s
->ybase
+= s
->first_glyph
->voffset
;
4648 xassert (s
->face
&& s
->face
->gc
);
4650 /* This glyph string must always be drawn with 16-bit functions. */
4653 return s
->gidx
+ s
->nchars
;
4657 /* Fill glyph string S from a sequence of character glyphs.
4659 FACE_ID is the face id of the string. START is the index of the
4660 first glyph to consider, END is the index of the last + 1.
4661 OVERLAPS_P non-zero means S should draw the foreground only, and
4662 use its physical height for clipping.
4664 Value is the index of the first glyph not in S. */
4667 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4668 struct glyph_string
*s
;
4670 int start
, end
, overlaps_p
;
4672 struct glyph
*glyph
, *last
;
4674 int glyph_not_available_p
;
4676 xassert (s
->f
== XFRAME (s
->w
->frame
));
4677 xassert (s
->nchars
== 0);
4678 xassert (start
>= 0 && end
> start
);
4680 s
->for_overlaps_p
= overlaps_p
,
4681 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4682 last
= s
->row
->glyphs
[s
->area
] + end
;
4683 voffset
= glyph
->voffset
;
4685 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4688 && glyph
->type
== CHAR_GLYPH
4689 && glyph
->voffset
== voffset
4690 /* Same face id implies same font, nowadays. */
4691 && glyph
->face_id
== face_id
4692 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4696 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4697 s
->char2b
+ s
->nchars
,
4699 s
->two_byte_p
= two_byte_p
;
4701 xassert (s
->nchars
<= end
- start
);
4702 s
->width
+= glyph
->pixel_width
;
4706 s
->font
= s
->face
->font
;
4707 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4709 /* If the specified font could not be loaded, use the frame's font,
4710 but record the fact that we couldn't load it in
4711 S->font_not_found_p so that we can draw rectangles for the
4712 characters of the glyph string. */
4713 if (s
->font
== NULL
|| glyph_not_available_p
)
4715 s
->font_not_found_p
= 1;
4716 s
->font
= FRAME_FONT (s
->f
);
4719 /* Adjust base line for subscript/superscript text. */
4720 s
->ybase
+= voffset
;
4722 xassert (s
->face
&& s
->face
->gc
);
4723 return glyph
- s
->row
->glyphs
[s
->area
];
4727 /* Fill glyph string S from image glyph S->first_glyph. */
4730 x_fill_image_glyph_string (s
)
4731 struct glyph_string
*s
;
4733 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4734 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
4736 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4737 s
->font
= s
->face
->font
;
4738 s
->width
= s
->first_glyph
->pixel_width
;
4740 /* Adjust base line for subscript/superscript text. */
4741 s
->ybase
+= s
->first_glyph
->voffset
;
4745 /* Fill glyph string S from a sequence of stretch glyphs.
4747 ROW is the glyph row in which the glyphs are found, AREA is the
4748 area within the row. START is the index of the first glyph to
4749 consider, END is the index of the last + 1.
4751 Value is the index of the first glyph not in S. */
4754 x_fill_stretch_glyph_string (s
, row
, area
, start
, end
)
4755 struct glyph_string
*s
;
4756 struct glyph_row
*row
;
4757 enum glyph_row_area area
;
4760 struct glyph
*glyph
, *last
;
4761 int voffset
, face_id
;
4763 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4765 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4766 last
= s
->row
->glyphs
[s
->area
] + end
;
4767 face_id
= glyph
->face_id
;
4768 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
4769 s
->font
= s
->face
->font
;
4770 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4771 s
->width
= glyph
->pixel_width
;
4772 voffset
= glyph
->voffset
;
4776 && glyph
->type
== STRETCH_GLYPH
4777 && glyph
->voffset
== voffset
4778 && glyph
->face_id
== face_id
);
4780 s
->width
+= glyph
->pixel_width
;
4782 /* Adjust base line for subscript/superscript text. */
4783 s
->ybase
+= voffset
;
4785 /* The case that face->gc == 0 is handled when drawing the glyph
4786 string by calling PREPARE_FACE_FOR_DISPLAY. */
4788 return glyph
- s
->row
->glyphs
[s
->area
];
4792 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4793 of XChar2b structures for S; it can't be allocated in
4794 x_init_glyph_string because it must be allocated via `alloca'. W
4795 is the window on which S is drawn. ROW and AREA are the glyph row
4796 and area within the row from which S is constructed. START is the
4797 index of the first glyph structure covered by S. HL is a
4798 face-override for drawing S. */
4801 x_init_glyph_string (s
, char2b
, w
, row
, area
, start
, hl
)
4802 struct glyph_string
*s
;
4805 struct glyph_row
*row
;
4806 enum glyph_row_area area
;
4808 enum draw_glyphs_face hl
;
4810 bzero (s
, sizeof *s
);
4812 s
->f
= XFRAME (w
->frame
);
4813 s
->display
= FRAME_X_DISPLAY (s
->f
);
4814 s
->window
= FRAME_X_WINDOW (s
->f
);
4819 s
->first_glyph
= row
->glyphs
[area
] + start
;
4820 s
->height
= row
->height
;
4821 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4823 /* Display the internal border below the tool-bar window. */
4824 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4825 s
->y
-= s
->f
->output_data
.x
->internal_border_width
;
4827 s
->ybase
= s
->y
+ row
->ascent
;
4831 /* Set background width of glyph string S. START is the index of the
4832 first glyph following S. LAST_X is the right-most x-position + 1
4833 in the drawing area. */
4836 x_set_glyph_string_background_width (s
, start
, last_x
)
4837 struct glyph_string
*s
;
4841 /* If the face of this glyph string has to be drawn to the end of
4842 the drawing area, set S->extends_to_end_of_line_p. */
4843 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4845 if (start
== s
->row
->used
[s
->area
]
4846 && s
->area
== TEXT_AREA
4847 && ((s
->hl
== DRAW_NORMAL_TEXT
4848 && (s
->row
->fill_line_p
4849 || s
->face
->background
!= default_face
->background
4850 || s
->face
->stipple
!= default_face
->stipple
4851 || s
->row
->mouse_face_p
))
4852 || s
->hl
== DRAW_MOUSE_FACE
4853 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
4854 && s
->row
->fill_line_p
)))
4855 s
->extends_to_end_of_line_p
= 1;
4857 /* If S extends its face to the end of the line, set its
4858 background_width to the distance to the right edge of the drawing
4860 if (s
->extends_to_end_of_line_p
)
4861 s
->background_width
= last_x
- s
->x
+ 1;
4863 s
->background_width
= s
->width
;
4867 /* Add a glyph string for a stretch glyph to the list of strings
4868 between HEAD and TAIL. START is the index of the stretch glyph in
4869 row area AREA of glyph row ROW. END is the index of the last glyph
4870 in that glyph row area. X is the current output position assigned
4871 to the new glyph string constructed. HL overrides that face of the
4872 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4873 is the right-most x-position of the drawing area. */
4875 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
4876 and below -- keep them on one line. */
4877 #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4880 s = (struct glyph_string *) alloca (sizeof *s); \
4881 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4882 START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \
4883 x_append_glyph_string (&HEAD, &TAIL, s); \
4889 /* Add a glyph string for an image glyph to the list of strings
4890 between HEAD and TAIL. START is the index of the image glyph in
4891 row area AREA of glyph row ROW. END is the index of the last glyph
4892 in that glyph row area. X is the current output position assigned
4893 to the new glyph string constructed. HL overrides that face of the
4894 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4895 is the right-most x-position of the drawing area. */
4897 #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4900 s = (struct glyph_string *) alloca (sizeof *s); \
4901 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4902 x_fill_image_glyph_string (s); \
4903 x_append_glyph_string (&HEAD, &TAIL, s); \
4910 /* Add a glyph string for a sequence of character glyphs to the list
4911 of strings between HEAD and TAIL. START is the index of the first
4912 glyph in row area AREA of glyph row ROW that is part of the new
4913 glyph string. END is the index of the last glyph in that glyph row
4914 area. X is the current output position assigned to the new glyph
4915 string constructed. HL overrides that face of the glyph; e.g. it
4916 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4917 right-most x-position of the drawing area. */
4919 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4925 c = (ROW)->glyphs[AREA][START].u.ch; \
4926 face_id = (ROW)->glyphs[AREA][START].face_id; \
4928 s = (struct glyph_string *) alloca (sizeof *s); \
4929 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
4930 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4931 x_append_glyph_string (&HEAD, &TAIL, s); \
4933 START = x_fill_glyph_string (s, face_id, START, END, \
4939 /* Add a glyph string for a composite sequence to the list of strings
4940 between HEAD and TAIL. START is the index of the first glyph in
4941 row area AREA of glyph row ROW that is part of the new glyph
4942 string. END is the index of the last glyph in that glyph row area.
4943 X is the current output position assigned to the new glyph string
4944 constructed. HL overrides that face of the glyph; e.g. it is
4945 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
4946 x-position of the drawing area. */
4948 #define BUILD_COMPOSITE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4950 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
4951 int face_id = (ROW)->glyphs[AREA][START].face_id; \
4952 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
4953 struct composition *cmp = composition_table[cmp_id]; \
4954 int glyph_len = cmp->glyph_len; \
4956 struct face **faces; \
4957 struct glyph_string *first_s = NULL; \
4960 base_face = base_face->ascii_face; \
4961 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
4962 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
4963 /* At first, fill in `char2b' and `faces'. */ \
4964 for (n = 0; n < glyph_len; n++) \
4966 int c = COMPOSITION_GLYPH (cmp, n); \
4967 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
4968 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
4969 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
4970 this_face_id, char2b + n, 1, 1); \
4973 /* Make glyph_strings for each glyph sequence that is drawable by \
4974 the same face, and append them to HEAD/TAIL. */ \
4975 for (n = 0; n < cmp->glyph_len;) \
4977 s = (struct glyph_string *) alloca (sizeof *s); \
4978 x_init_glyph_string (s, char2b + n, W, ROW, AREA, START, HL); \
4979 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4987 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
4995 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4996 of AREA of glyph row ROW on window W between indices START and END.
4997 HL overrides the face for drawing glyph strings, e.g. it is
4998 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4999 x-positions of the drawing area.
5001 This is an ugly monster macro construct because we must use alloca
5002 to allocate glyph strings (because x_draw_glyphs can be called
5005 #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
5008 HEAD = TAIL = NULL; \
5009 while (START < END) \
5011 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
5012 switch (first_glyph->type) \
5015 BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \
5016 TAIL, HL, X, LAST_X, \
5020 case COMPOSITE_GLYPH: \
5021 BUILD_COMPOSITE_GLYPH_STRING (W, ROW, AREA, START, END, \
5022 HEAD, TAIL, HL, X, LAST_X,\
5026 case STRETCH_GLYPH: \
5027 BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \
5028 HEAD, TAIL, HL, X, LAST_X); \
5032 BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \
5033 TAIL, HL, X, LAST_X); \
5040 x_set_glyph_string_background_width (s, START, LAST_X); \
5047 /* Draw glyphs between START and END in AREA of ROW on window W,
5048 starting at x-position X. X is relative to AREA in W. HL is a
5049 face-override with the following meaning:
5051 DRAW_NORMAL_TEXT draw normally
5052 DRAW_CURSOR draw in cursor face
5053 DRAW_MOUSE_FACE draw in mouse face.
5054 DRAW_INVERSE_VIDEO draw in mode line face
5055 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
5056 DRAW_IMAGE_RAISED draw an image with a raised relief around it
5058 If OVERLAPS_P is non-zero, draw only the foreground of characters
5059 and clip to the physical height of ROW.
5061 Value is the x-position reached, relative to AREA of W. */
5064 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
5067 struct glyph_row
*row
;
5068 enum glyph_row_area area
;
5070 enum draw_glyphs_face hl
;
5073 struct glyph_string
*head
, *tail
;
5074 struct glyph_string
*s
;
5075 int last_x
, area_width
;
5079 /* Let's rather be paranoid than getting a SEGV. */
5080 end
= min (end
, row
->used
[area
]);
5081 start
= max (0, start
);
5082 start
= min (end
, start
);
5084 /* Translate X to frame coordinates. Set last_x to the right
5085 end of the drawing area. */
5086 if (row
->full_width_p
)
5088 /* X is relative to the left edge of W, without scroll bars
5090 struct frame
*f
= XFRAME (w
->frame
);
5091 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
5094 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5095 last_x
= window_left_x
+ area_width
;
5097 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5099 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5100 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
5106 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
5107 last_x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
5111 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
5112 area_width
= window_box_width (w
, area
);
5113 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
5116 /* Build a doubly-linked list of glyph_string structures between
5117 head and tail from what we have to draw. Note that the macro
5118 BUILD_GLYPH_STRINGS will modify its start parameter. That's
5119 the reason we use a separate variable `i'. */
5121 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
5124 x_reached
= tail
->x
+ tail
->background_width
;
5128 /* If there are any glyphs with lbearing < 0 or rbearing > width in
5129 the row, redraw some glyphs in front or following the glyph
5130 strings built above. */
5131 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
5134 struct glyph_string
*h
, *t
;
5136 /* Compute overhangs for all glyph strings. */
5137 for (s
= head
; s
; s
= s
->next
)
5138 x_compute_glyph_string_overhangs (s
);
5140 /* Prepend glyph strings for glyphs in front of the first glyph
5141 string that are overwritten because of the first glyph
5142 string's left overhang. The background of all strings
5143 prepended must be drawn because the first glyph string
5145 i
= x_left_overwritten (head
);
5149 BUILD_GLYPH_STRINGS (w
, row
, area
, j
, start
, h
, t
,
5150 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5153 x_compute_overhangs_and_x (t
, head
->x
, 1);
5154 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5157 /* Prepend glyph strings for glyphs in front of the first glyph
5158 string that overwrite that glyph string because of their
5159 right overhang. For these strings, only the foreground must
5160 be drawn, because it draws over the glyph string at `head'.
5161 The background must not be drawn because this would overwrite
5162 right overhangs of preceding glyphs for which no glyph
5164 i
= x_left_overwriting (head
);
5167 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, start
, h
, t
,
5168 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5170 for (s
= h
; s
; s
= s
->next
)
5171 s
->background_filled_p
= 1;
5172 x_compute_overhangs_and_x (t
, head
->x
, 1);
5173 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5176 /* Append glyphs strings for glyphs following the last glyph
5177 string tail that are overwritten by tail. The background of
5178 these strings has to be drawn because tail's foreground draws
5180 i
= x_right_overwritten (tail
);
5183 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
5184 DRAW_NORMAL_TEXT
, x
, last_x
,
5186 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5187 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5190 /* Append glyph strings for glyphs following the last glyph
5191 string tail that overwrite tail. The foreground of such
5192 glyphs has to be drawn because it writes into the background
5193 of tail. The background must not be drawn because it could
5194 paint over the foreground of following glyphs. */
5195 i
= x_right_overwriting (tail
);
5198 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
5199 DRAW_NORMAL_TEXT
, x
, last_x
,
5201 for (s
= h
; s
; s
= s
->next
)
5202 s
->background_filled_p
= 1;
5203 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5204 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5208 /* Draw all strings. */
5209 for (s
= head
; s
; s
= s
->next
)
5210 x_draw_glyph_string (s
);
5212 if (area
== TEXT_AREA
5213 && !row
->full_width_p
5214 /* When drawing overlapping rows, only the glyph strings'
5215 foreground is drawn, which doesn't erase a cursor
5219 int x0
= head
? head
->x
: x
;
5220 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
5222 x0
= FRAME_TO_WINDOW_PIXEL_X (w
, x0
);
5223 x1
= FRAME_TO_WINDOW_PIXEL_X (w
, x1
);
5225 if (XFASTINT (w
->left_margin_width
) != 0)
5227 int left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
5228 x0
-= left_area_width
;
5229 x1
-= left_area_width
;
5232 notice_overwritten_cursor (w
, area
, x0
, x1
,
5233 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
5236 /* Value is the x-position up to which drawn, relative to AREA of W.
5237 This doesn't include parts drawn because of overhangs. */
5238 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
5239 if (!row
->full_width_p
)
5241 if (area
> LEFT_MARGIN_AREA
&& XFASTINT (w
->left_margin_width
) != 0)
5242 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
5243 if (area
> TEXT_AREA
)
5244 x_reached
-= window_box_width (w
, TEXT_AREA
);
5251 /* Fix the display of area AREA of overlapping row ROW in window W. */
5254 x_fix_overlapping_area (w
, row
, area
)
5256 struct glyph_row
*row
;
5257 enum glyph_row_area area
;
5263 if (area
== LEFT_MARGIN_AREA
)
5265 else if (area
== TEXT_AREA
)
5266 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5268 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5269 + window_box_width (w
, TEXT_AREA
));
5271 for (i
= 0; i
< row
->used
[area
];)
5273 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
5275 int start
= i
, start_x
= x
;
5279 x
+= row
->glyphs
[area
][i
].pixel_width
;
5282 while (i
< row
->used
[area
]
5283 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
5285 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
5286 DRAW_NORMAL_TEXT
, 1);
5290 x
+= row
->glyphs
[area
][i
].pixel_width
;
5299 /* Output LEN glyphs starting at START at the nominal cursor position.
5300 Advance the nominal cursor over the text. The global variable
5301 updated_window contains the window being updated, updated_row is
5302 the glyph row being updated, and updated_area is the area of that
5303 row being updated. */
5306 x_write_glyphs (start
, len
)
5307 struct glyph
*start
;
5312 xassert (updated_window
&& updated_row
);
5317 hpos
= start
- updated_row
->glyphs
[updated_area
];
5318 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
5319 updated_row
, updated_area
,
5321 DRAW_NORMAL_TEXT
, 0);
5325 /* Advance the output cursor. */
5326 output_cursor
.hpos
+= len
;
5327 output_cursor
.x
= x
;
5331 /* Insert LEN glyphs from START at the nominal cursor position. */
5334 x_insert_glyphs (start
, len
)
5335 struct glyph
*start
;
5340 int line_height
, shift_by_width
, shifted_region_width
;
5341 struct glyph_row
*row
;
5342 struct glyph
*glyph
;
5343 int frame_x
, frame_y
, hpos
;
5345 xassert (updated_window
&& updated_row
);
5348 f
= XFRAME (WINDOW_FRAME (w
));
5350 /* Get the height of the line we are in. */
5352 line_height
= row
->height
;
5354 /* Get the width of the glyphs to insert. */
5356 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
5357 shift_by_width
+= glyph
->pixel_width
;
5359 /* Get the width of the region to shift right. */
5360 shifted_region_width
= (window_box_width (w
, updated_area
)
5365 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
5366 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
5367 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5368 f
->output_data
.x
->normal_gc
,
5370 shifted_region_width
, line_height
,
5371 frame_x
+ shift_by_width
, frame_y
);
5373 /* Write the glyphs. */
5374 hpos
= start
- row
->glyphs
[updated_area
];
5375 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
5376 DRAW_NORMAL_TEXT
, 0);
5378 /* Advance the output cursor. */
5379 output_cursor
.hpos
+= len
;
5380 output_cursor
.x
+= shift_by_width
;
5385 /* Delete N glyphs at the nominal cursor position. Not implemented
5396 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
5397 If they are <= 0, this is probably an error. */
5400 x_clear_area (dpy
, window
, x
, y
, width
, height
, exposures
)
5407 xassert (width
> 0 && height
> 0);
5408 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
5412 /* Erase the current text line from the nominal cursor position
5413 (inclusive) to pixel column TO_X (exclusive). The idea is that
5414 everything from TO_X onward is already erased.
5416 TO_X is a pixel position relative to updated_area of
5417 updated_window. TO_X == -1 means clear to the end of this area. */
5420 x_clear_end_of_line (to_x
)
5424 struct window
*w
= updated_window
;
5425 int max_x
, min_y
, max_y
;
5426 int from_x
, from_y
, to_y
;
5428 xassert (updated_window
&& updated_row
);
5429 f
= XFRAME (w
->frame
);
5431 if (updated_row
->full_width_p
)
5433 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5434 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5435 && !w
->pseudo_window_p
)
5436 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5439 max_x
= window_box_width (w
, updated_area
);
5440 max_y
= window_text_bottom_y (w
);
5442 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
5443 of window. For TO_X > 0, truncate to end of drawing area. */
5449 to_x
= min (to_x
, max_x
);
5451 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
5453 /* Notice if the cursor will be cleared by this operation. */
5454 if (!updated_row
->full_width_p
)
5455 notice_overwritten_cursor (w
, updated_area
,
5456 output_cursor
.x
, -1,
5458 MATRIX_ROW_BOTTOM_Y (updated_row
));
5460 from_x
= output_cursor
.x
;
5462 /* Translate to frame coordinates. */
5463 if (updated_row
->full_width_p
)
5465 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
5466 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
5470 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
5471 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
5474 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
5475 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
5476 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
5478 /* Prevent inadvertently clearing to end of the X window. */
5479 if (to_x
> from_x
&& to_y
> from_y
)
5482 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5483 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
5490 /* Clear entire frame. If updating_frame is non-null, clear that
5491 frame. Otherwise clear the selected frame. */
5501 f
= SELECTED_FRAME ();
5503 /* Clearing the frame will erase any cursor, so mark them all as no
5505 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5506 output_cursor
.hpos
= output_cursor
.vpos
= 0;
5507 output_cursor
.x
= -1;
5509 /* We don't set the output cursor here because there will always
5510 follow an explicit cursor_to. */
5512 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5514 /* We have to clear the scroll bars, too. If we have changed
5515 colors or something like that, then they should be notified. */
5516 x_scroll_bar_clear (f
);
5518 XFlush (FRAME_X_DISPLAY (f
));
5524 /* Invert the middle quarter of the frame for .15 sec. */
5526 /* We use the select system call to do the waiting, so we have to make
5527 sure it's available. If it isn't, we just won't do visual bells. */
5529 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5532 /* Subtract the `struct timeval' values X and Y, storing the result in
5533 *RESULT. Return 1 if the difference is negative, otherwise 0. */
5536 timeval_subtract (result
, x
, y
)
5537 struct timeval
*result
, x
, y
;
5539 /* Perform the carry for the later subtraction by updating y. This
5540 is safer because on some systems the tv_sec member is unsigned. */
5541 if (x
.tv_usec
< y
.tv_usec
)
5543 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
5544 y
.tv_usec
-= 1000000 * nsec
;
5548 if (x
.tv_usec
- y
.tv_usec
> 1000000)
5550 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
5551 y
.tv_usec
+= 1000000 * nsec
;
5555 /* Compute the time remaining to wait. tv_usec is certainly
5557 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
5558 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
5560 /* Return indication of whether the result should be considered
5562 return x
.tv_sec
< y
.tv_sec
;
5574 /* Create a GC that will use the GXxor function to flip foreground
5575 pixels into background pixels. */
5579 values
.function
= GXxor
;
5580 values
.foreground
= (f
->output_data
.x
->foreground_pixel
5581 ^ f
->output_data
.x
->background_pixel
);
5583 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5584 GCFunction
| GCForeground
, &values
);
5588 /* Get the height not including a menu bar widget. */
5589 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
5590 /* Height of each line to flash. */
5591 int flash_height
= FRAME_LINE_HEIGHT (f
);
5592 /* These will be the left and right margins of the rectangles. */
5593 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
5594 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
5598 /* Don't flash the area between a scroll bar and the frame
5599 edge it is next to. */
5600 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
5602 case vertical_scroll_bar_left
:
5603 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5606 case vertical_scroll_bar_right
:
5607 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5614 width
= flash_right
- flash_left
;
5616 /* If window is tall, flash top and bottom line. */
5617 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5619 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5621 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5622 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5623 width
, flash_height
);
5624 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5626 (height
- flash_height
5627 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5628 width
, flash_height
);
5631 /* If it is short, flash it all. */
5632 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5633 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5634 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5639 struct timeval wakeup
;
5641 EMACS_GET_TIME (wakeup
);
5643 /* Compute time to wait until, propagating carry from usecs. */
5644 wakeup
.tv_usec
+= 150000;
5645 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
5646 wakeup
.tv_usec
%= 1000000;
5648 /* Keep waiting until past the time wakeup or any input gets
5650 while (! detect_input_pending ())
5652 struct timeval current
;
5653 struct timeval timeout
;
5655 EMACS_GET_TIME (current
);
5657 /* Break if result would be negative. */
5658 if (timeval_subtract (¤t
, wakeup
, current
))
5661 /* How long `select' should wait. */
5663 timeout
.tv_usec
= 10000;
5665 /* Try to wait that long--but we might wake up sooner. */
5666 select (0, NULL
, NULL
, NULL
, &timeout
);
5670 /* If window is tall, flash top and bottom line. */
5671 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5673 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5675 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5676 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5677 width
, flash_height
);
5678 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5680 (height
- flash_height
5681 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5682 width
, flash_height
);
5685 /* If it is short, flash it all. */
5686 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5687 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5688 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5690 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
5698 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
5701 /* Make audible bell. */
5706 struct frame
*f
= SELECTED_FRAME ();
5708 if (FRAME_X_DISPLAY (f
))
5710 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5717 XBell (FRAME_X_DISPLAY (f
), 0);
5718 XFlush (FRAME_X_DISPLAY (f
));
5725 /* Specify how many text lines, from the top of the window,
5726 should be affected by insert-lines and delete-lines operations.
5727 This, and those operations, are used only within an update
5728 that is bounded by calls to x_update_begin and x_update_end. */
5731 XTset_terminal_window (n
)
5734 /* This function intentionally left blank. */
5739 /***********************************************************************
5741 ***********************************************************************/
5743 /* Perform an insert-lines or delete-lines operation, inserting N
5744 lines or deleting -N lines at vertical position VPOS. */
5747 x_ins_del_lines (vpos
, n
)
5754 /* Scroll part of the display as described by RUN. */
5757 x_scroll_run (w
, run
)
5761 struct frame
*f
= XFRAME (w
->frame
);
5762 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5764 /* Get frame-relative bounding box of the text display area of W,
5765 without mode lines. Include in this box the left and right
5767 window_box (w
, -1, &x
, &y
, &width
, &height
);
5768 width
+= FRAME_X_FRINGE_WIDTH (f
);
5769 x
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
5771 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5772 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5773 bottom_y
= y
+ height
;
5777 /* Scrolling up. Make sure we don't copy part of the mode
5778 line at the bottom. */
5779 if (from_y
+ run
->height
> bottom_y
)
5780 height
= bottom_y
- from_y
;
5782 height
= run
->height
;
5786 /* Scolling down. Make sure we don't copy over the mode line.
5788 if (to_y
+ run
->height
> bottom_y
)
5789 height
= bottom_y
- to_y
;
5791 height
= run
->height
;
5796 /* Cursor off. Will be switched on again in x_update_window_end. */
5800 XCopyArea (FRAME_X_DISPLAY (f
),
5801 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5802 f
->output_data
.x
->normal_gc
,
5812 /***********************************************************************
5814 ***********************************************************************/
5816 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5817 corner of the exposed rectangle. W and H are width and height of
5818 the exposed area. All are pixel values. W or H zero means redraw
5819 the entire frame. */
5822 expose_frame (f
, x
, y
, w
, h
)
5827 int mouse_face_overwritten_p
= 0;
5829 TRACE ((stderr
, "expose_frame "));
5831 /* No need to redraw if frame will be redrawn soon. */
5832 if (FRAME_GARBAGED_P (f
))
5834 TRACE ((stderr
, " garbaged\n"));
5838 /* If basic faces haven't been realized yet, there is no point in
5839 trying to redraw anything. This can happen when we get an expose
5840 event while Emacs is starting, e.g. by moving another window. */
5841 if (FRAME_FACE_CACHE (f
) == NULL
5842 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5844 TRACE ((stderr
, " no faces\n"));
5848 if (w
== 0 || h
== 0)
5851 r
.width
= CANON_X_UNIT (f
) * f
->width
;
5852 r
.height
= CANON_Y_UNIT (f
) * f
->height
;
5862 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
5863 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
5865 if (WINDOWP (f
->tool_bar_window
))
5866 mouse_face_overwritten_p
5867 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
5869 #ifndef USE_X_TOOLKIT
5870 if (WINDOWP (f
->menu_bar_window
))
5871 mouse_face_overwritten_p
5872 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
5873 #endif /* not USE_X_TOOLKIT */
5875 /* Some window managers support a focus-follows-mouse style with
5876 delayed raising of frames. Imagine a partially obscured frame,
5877 and moving the mouse into partially obscured mouse-face on that
5878 frame. The visible part of the mouse-face will be highlighted,
5879 then the WM raises the obscured frame. With at least one WM, KDE
5880 2.1, Emacs is not getting any event for the raising of the frame
5881 (even tried with SubstructureRedirectMask), only Expose events.
5882 These expose events will draw text normally, i.e. not
5883 highlighted. Which means we must redo the highlight here.
5884 Subsume it under ``we love X''. --gerd 2001-08-15 */
5885 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
5887 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
5888 if (f
== dpyinfo
->mouse_face_mouse_frame
)
5890 int x
= dpyinfo
->mouse_face_mouse_x
;
5891 int y
= dpyinfo
->mouse_face_mouse_y
;
5892 clear_mouse_face (dpyinfo
);
5893 note_mouse_highlight (f
, x
, y
);
5899 /* Redraw (parts) of all windows in the window tree rooted at W that
5900 intersect R. R contains frame pixel coordinates. Value is
5901 non-zero if the exposure overwrites mouse-face. */
5904 expose_window_tree (w
, r
)
5908 struct frame
*f
= XFRAME (w
->frame
);
5909 int mouse_face_overwritten_p
= 0;
5911 while (w
&& !FRAME_GARBAGED_P (f
))
5913 if (!NILP (w
->hchild
))
5914 mouse_face_overwritten_p
5915 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
5916 else if (!NILP (w
->vchild
))
5917 mouse_face_overwritten_p
5918 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
5920 mouse_face_overwritten_p
|= expose_window (w
, r
);
5922 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
5925 return mouse_face_overwritten_p
;
5929 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5930 which intersects rectangle R. R is in window-relative coordinates. */
5933 expose_area (w
, row
, r
, area
)
5935 struct glyph_row
*row
;
5937 enum glyph_row_area area
;
5939 struct glyph
*first
= row
->glyphs
[area
];
5940 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5942 int first_x
, start_x
, x
;
5944 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5945 /* If row extends face to end of line write the whole line. */
5946 x_draw_glyphs (w
, 0, row
, area
, 0, row
->used
[area
],
5947 DRAW_NORMAL_TEXT
, 0);
5950 /* Set START_X to the window-relative start position for drawing glyphs of
5951 AREA. The first glyph of the text area can be partially visible.
5952 The first glyphs of other areas cannot. */
5953 if (area
== LEFT_MARGIN_AREA
)
5955 else if (area
== TEXT_AREA
)
5956 start_x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5958 start_x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5959 + window_box_width (w
, TEXT_AREA
));
5962 /* Find the first glyph that must be redrawn. */
5964 && x
+ first
->pixel_width
< r
->x
)
5966 x
+= first
->pixel_width
;
5970 /* Find the last one. */
5974 && x
< r
->x
+ r
->width
)
5976 x
+= last
->pixel_width
;
5982 x_draw_glyphs (w
, first_x
- start_x
, row
, area
,
5983 first
- row
->glyphs
[area
],
5984 last
- row
->glyphs
[area
],
5985 DRAW_NORMAL_TEXT
, 0);
5990 /* Redraw the parts of the glyph row ROW on window W intersecting
5991 rectangle R. R is in window-relative coordinates. Value is
5992 non-zero if mouse-face was overwritten. */
5995 expose_line (w
, row
, r
)
5997 struct glyph_row
*row
;
6000 xassert (row
->enabled_p
);
6002 if (row
->mode_line_p
|| w
->pseudo_window_p
)
6003 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
6004 DRAW_NORMAL_TEXT
, 0);
6007 if (row
->used
[LEFT_MARGIN_AREA
])
6008 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
6009 if (row
->used
[TEXT_AREA
])
6010 expose_area (w
, row
, r
, TEXT_AREA
);
6011 if (row
->used
[RIGHT_MARGIN_AREA
])
6012 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
6013 x_draw_row_fringe_bitmaps (w
, row
);
6016 return row
->mouse_face_p
;
6020 /* Return non-zero if W's cursor intersects rectangle R. */
6023 x_phys_cursor_in_rect_p (w
, r
)
6027 XRectangle cr
, result
;
6028 struct glyph
*cursor_glyph
;
6030 cursor_glyph
= get_phys_cursor_glyph (w
);
6033 cr
.x
= w
->phys_cursor
.x
;
6034 cr
.y
= w
->phys_cursor
.y
;
6035 cr
.width
= cursor_glyph
->pixel_width
;
6036 cr
.height
= w
->phys_cursor_height
;
6037 return x_intersect_rectangles (&cr
, r
, &result
);
6044 /* Redraw the part of window W intersection rectangle FR. Pixel
6045 coordinates in FR are frame-relative. Call this function with
6046 input blocked. Value is non-zero if the exposure overwrites
6050 expose_window (w
, fr
)
6054 struct frame
*f
= XFRAME (w
->frame
);
6056 int mouse_face_overwritten_p
= 0;
6058 /* If window is not yet fully initialized, do nothing. This can
6059 happen when toolkit scroll bars are used and a window is split.
6060 Reconfiguring the scroll bar will generate an expose for a newly
6062 if (w
->current_matrix
== NULL
)
6065 /* When we're currently updating the window, display and current
6066 matrix usually don't agree. Arrange for a thorough display
6068 if (w
== updated_window
)
6070 SET_FRAME_GARBAGED (f
);
6074 /* Frame-relative pixel rectangle of W. */
6075 wr
.x
= XFASTINT (w
->left
) * CANON_X_UNIT (f
);
6076 wr
.y
= XFASTINT (w
->top
) * CANON_Y_UNIT (f
);
6077 wr
.width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
6078 wr
.height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
6080 if (x_intersect_rectangles (fr
, &wr
, &r
))
6082 int yb
= window_text_bottom_y (w
);
6083 struct glyph_row
*row
;
6084 int cursor_cleared_p
;
6086 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
6087 r
.x
, r
.y
, r
.width
, r
.height
));
6089 /* Convert to window coordinates. */
6090 r
.x
= FRAME_TO_WINDOW_PIXEL_X (w
, r
.x
);
6091 r
.y
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
.y
);
6093 /* Turn off the cursor. */
6094 if (!w
->pseudo_window_p
6095 && x_phys_cursor_in_rect_p (w
, &r
))
6098 cursor_cleared_p
= 1;
6101 cursor_cleared_p
= 0;
6103 /* Find the first row intersecting the rectangle R. */
6104 for (row
= w
->current_matrix
->rows
;
6109 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
6111 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
6112 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
6113 || (r
.y
>= y0
&& r
.y
< y1
)
6114 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
6116 if (expose_line (w
, row
, &r
))
6117 mouse_face_overwritten_p
= 1;
6124 /* Display the mode line if there is one. */
6125 if (WINDOW_WANTS_MODELINE_P (w
)
6126 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
6128 && row
->y
< r
.y
+ r
.height
)
6130 if (expose_line (w
, row
, &r
))
6131 mouse_face_overwritten_p
= 1;
6134 if (!w
->pseudo_window_p
)
6136 /* Draw border between windows. */
6137 x_draw_vertical_border (w
);
6139 /* Turn the cursor on again. */
6140 if (cursor_cleared_p
)
6141 x_update_window_cursor (w
, 1);
6145 return mouse_face_overwritten_p
;
6149 /* Determine the intersection of two rectangles R1 and R2. Return
6150 the intersection in *RESULT. Value is non-zero if RESULT is not
6154 x_intersect_rectangles (r1
, r2
, result
)
6155 XRectangle
*r1
, *r2
, *result
;
6157 XRectangle
*left
, *right
;
6158 XRectangle
*upper
, *lower
;
6159 int intersection_p
= 0;
6161 /* Rearrange so that R1 is the left-most rectangle. */
6163 left
= r1
, right
= r2
;
6165 left
= r2
, right
= r1
;
6167 /* X0 of the intersection is right.x0, if this is inside R1,
6168 otherwise there is no intersection. */
6169 if (right
->x
<= left
->x
+ left
->width
)
6171 result
->x
= right
->x
;
6173 /* The right end of the intersection is the minimum of the
6174 the right ends of left and right. */
6175 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
6178 /* Same game for Y. */
6180 upper
= r1
, lower
= r2
;
6182 upper
= r2
, lower
= r1
;
6184 /* The upper end of the intersection is lower.y0, if this is inside
6185 of upper. Otherwise, there is no intersection. */
6186 if (lower
->y
<= upper
->y
+ upper
->height
)
6188 result
->y
= lower
->y
;
6190 /* The lower end of the intersection is the minimum of the lower
6191 ends of upper and lower. */
6192 result
->height
= (min (lower
->y
+ lower
->height
,
6193 upper
->y
+ upper
->height
)
6199 return intersection_p
;
6210 /* We used to only do this if Vx_no_window_manager was non-nil, but
6211 the ICCCM (section 4.1.6) says that the window's border pixmap
6212 and border pixel are window attributes which are "private to the
6213 client", so we can always change it to whatever we want. */
6215 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6216 f
->output_data
.x
->border_pixel
);
6218 x_update_cursor (f
, 1);
6222 frame_unhighlight (f
)
6225 /* We used to only do this if Vx_no_window_manager was non-nil, but
6226 the ICCCM (section 4.1.6) says that the window's border pixmap
6227 and border pixel are window attributes which are "private to the
6228 client", so we can always change it to whatever we want. */
6230 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6231 f
->output_data
.x
->border_tile
);
6233 x_update_cursor (f
, 1);
6236 /* The focus has changed. Update the frames as necessary to reflect
6237 the new situation. Note that we can't change the selected frame
6238 here, because the Lisp code we are interrupting might become confused.
6239 Each event gets marked with the frame in which it occurred, so the
6240 Lisp code can tell when the switch took place by examining the events. */
6243 x_new_focus_frame (dpyinfo
, frame
)
6244 struct x_display_info
*dpyinfo
;
6245 struct frame
*frame
;
6247 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
6249 if (frame
!= dpyinfo
->x_focus_frame
)
6251 /* Set this before calling other routines, so that they see
6252 the correct value of x_focus_frame. */
6253 dpyinfo
->x_focus_frame
= frame
;
6255 if (old_focus
&& old_focus
->auto_lower
)
6256 x_lower_frame (old_focus
);
6259 selected_frame
= frame
;
6260 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
6262 Fselect_window (selected_frame
->selected_window
);
6263 choose_minibuf_frame ();
6266 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
6267 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
6269 pending_autoraise_frame
= 0;
6272 x_frame_rehighlight (dpyinfo
);
6275 /* Handle an event saying the mouse has moved out of an Emacs frame. */
6278 x_mouse_leave (dpyinfo
)
6279 struct x_display_info
*dpyinfo
;
6281 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
6284 /* The focus has changed, or we have redirected a frame's focus to
6285 another frame (this happens when a frame uses a surrogate
6286 mini-buffer frame). Shift the highlight as appropriate.
6288 The FRAME argument doesn't necessarily have anything to do with which
6289 frame is being highlighted or un-highlighted; we only use it to find
6290 the appropriate X display info. */
6293 XTframe_rehighlight (frame
)
6294 struct frame
*frame
;
6296 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
6300 x_frame_rehighlight (dpyinfo
)
6301 struct x_display_info
*dpyinfo
;
6303 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
6305 if (dpyinfo
->x_focus_frame
)
6307 dpyinfo
->x_highlight_frame
6308 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
6309 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
6310 : dpyinfo
->x_focus_frame
);
6311 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
6313 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
6314 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
6318 dpyinfo
->x_highlight_frame
= 0;
6320 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
6323 frame_unhighlight (old_highlight
);
6324 if (dpyinfo
->x_highlight_frame
)
6325 frame_highlight (dpyinfo
->x_highlight_frame
);
6331 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
6333 /* Initialize mode_switch_bit and modifier_meaning. */
6335 x_find_modifier_meanings (dpyinfo
)
6336 struct x_display_info
*dpyinfo
;
6338 int min_code
, max_code
;
6341 XModifierKeymap
*mods
;
6343 dpyinfo
->meta_mod_mask
= 0;
6344 dpyinfo
->shift_lock_mask
= 0;
6345 dpyinfo
->alt_mod_mask
= 0;
6346 dpyinfo
->super_mod_mask
= 0;
6347 dpyinfo
->hyper_mod_mask
= 0;
6350 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
6352 min_code
= dpyinfo
->display
->min_keycode
;
6353 max_code
= dpyinfo
->display
->max_keycode
;
6356 syms
= XGetKeyboardMapping (dpyinfo
->display
,
6357 min_code
, max_code
- min_code
+ 1,
6359 mods
= XGetModifierMapping (dpyinfo
->display
);
6361 /* Scan the modifier table to see which modifier bits the Meta and
6362 Alt keysyms are on. */
6364 int row
, col
; /* The row and column in the modifier table. */
6366 for (row
= 3; row
< 8; row
++)
6367 for (col
= 0; col
< mods
->max_keypermod
; col
++)
6370 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
6372 /* Zeroes are used for filler. Skip them. */
6376 /* Are any of this keycode's keysyms a meta key? */
6380 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
6382 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
6388 dpyinfo
->meta_mod_mask
|= (1 << row
);
6393 dpyinfo
->alt_mod_mask
|= (1 << row
);
6398 dpyinfo
->hyper_mod_mask
|= (1 << row
);
6403 dpyinfo
->super_mod_mask
|= (1 << row
);
6407 /* Ignore this if it's not on the lock modifier. */
6408 if ((1 << row
) == LockMask
)
6409 dpyinfo
->shift_lock_mask
= LockMask
;
6417 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
6418 if (! dpyinfo
->meta_mod_mask
)
6420 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
6421 dpyinfo
->alt_mod_mask
= 0;
6424 /* If some keys are both alt and meta,
6425 make them just meta, not alt. */
6426 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
6428 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
6431 XFree ((char *) syms
);
6432 XFreeModifiermap (mods
);
6435 /* Convert between the modifier bits X uses and the modifier bits
6439 x_x_to_emacs_modifiers (dpyinfo
, state
)
6440 struct x_display_info
*dpyinfo
;
6443 EMACS_UINT mod_meta
= meta_modifier
;
6444 EMACS_UINT mod_alt
= alt_modifier
;
6445 EMACS_UINT mod_hyper
= hyper_modifier
;
6446 EMACS_UINT mod_super
= super_modifier
;
6449 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
6450 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
6451 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
6452 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
6453 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
6454 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
6455 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
6456 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
6459 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
6460 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
6461 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
6462 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
6463 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
6464 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
6468 x_emacs_to_x_modifiers (dpyinfo
, state
)
6469 struct x_display_info
*dpyinfo
;
6472 EMACS_UINT mod_meta
= meta_modifier
;
6473 EMACS_UINT mod_alt
= alt_modifier
;
6474 EMACS_UINT mod_hyper
= hyper_modifier
;
6475 EMACS_UINT mod_super
= super_modifier
;
6479 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
6480 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
6481 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
6482 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
6483 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
6484 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
6485 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
6486 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
6489 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
6490 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
6491 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
6492 | ((state
& shift_modifier
) ? ShiftMask
: 0)
6493 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
6494 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
6497 /* Convert a keysym to its name. */
6500 x_get_keysym_name (keysym
)
6506 value
= XKeysymToString (keysym
);
6514 /* Mouse clicks and mouse movement. Rah. */
6516 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
6517 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
6518 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
6519 not force the value into range. */
6522 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
6524 register int pix_x
, pix_y
;
6525 register int *x
, *y
;
6529 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
6530 even for negative values. */
6532 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
6534 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
6536 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
6537 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
6541 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
6542 bounds
->height
= f
->output_data
.x
->line_height
;
6543 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
6544 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
6551 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
6552 pix_x
= FRAME_WINDOW_WIDTH (f
);
6556 else if (pix_y
> f
->height
)
6565 /* Given HPOS/VPOS in the current matrix of W, return corresponding
6566 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
6567 can't tell the positions because W's display is not up to date,
6571 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
6574 int *frame_x
, *frame_y
;
6578 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
6579 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
6581 if (display_completed
)
6583 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6584 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
6585 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
6591 *frame_x
+= glyph
->pixel_width
;
6599 *frame_y
= *frame_x
= 0;
6603 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
6604 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6609 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6611 If the event is a button press, then note that we have grabbed
6615 construct_mouse_click (result
, event
, f
)
6616 struct input_event
*result
;
6617 XButtonEvent
*event
;
6620 /* Make the event type no_event; we'll change that when we decide
6622 result
->kind
= mouse_click
;
6623 result
->code
= event
->button
- Button1
;
6624 result
->timestamp
= event
->time
;
6625 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6627 | (event
->type
== ButtonRelease
6631 XSETINT (result
->x
, event
->x
);
6632 XSETINT (result
->y
, event
->y
);
6633 XSETFRAME (result
->frame_or_window
, f
);
6639 /* Function to report a mouse movement to the mainstream Emacs code.
6640 The input handler calls this.
6642 We have received a mouse movement event, which is given in *event.
6643 If the mouse is over a different glyph than it was last time, tell
6644 the mainstream emacs code by setting mouse_moved. If not, ask for
6645 another motion event, so we can check again the next time it moves. */
6647 static XMotionEvent last_mouse_motion_event
;
6648 static Lisp_Object last_mouse_motion_frame
;
6651 note_mouse_movement (frame
, event
)
6653 XMotionEvent
*event
;
6655 last_mouse_movement_time
= event
->time
;
6656 last_mouse_motion_event
= *event
;
6657 XSETFRAME (last_mouse_motion_frame
, frame
);
6659 if (event
->window
!= FRAME_X_WINDOW (frame
))
6661 frame
->mouse_moved
= 1;
6662 last_mouse_scroll_bar
= Qnil
;
6663 note_mouse_highlight (frame
, -1, -1);
6666 /* Has the mouse moved off the glyph it was on at the last sighting? */
6667 else if (event
->x
< last_mouse_glyph
.x
6668 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
6669 || event
->y
< last_mouse_glyph
.y
6670 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
6672 frame
->mouse_moved
= 1;
6673 last_mouse_scroll_bar
= Qnil
;
6674 note_mouse_highlight (frame
, event
->x
, event
->y
);
6679 /************************************************************************
6681 ************************************************************************/
6683 /* Find the glyph under window-relative coordinates X/Y in window W.
6684 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6685 strings. Return in *HPOS and *VPOS the row and column number of
6686 the glyph found. Return in *AREA the glyph area containing X.
6687 Value is a pointer to the glyph found or null if X/Y is not on
6688 text, or we can't tell because W's current matrix is not up to
6691 static struct glyph
*
6692 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
, buffer_only_p
)
6695 int *hpos
, *vpos
, *area
;
6698 struct glyph
*glyph
, *end
;
6699 struct glyph_row
*row
= NULL
;
6700 int x0
, i
, left_area_width
;
6702 /* Find row containing Y. Give up if some row is not enabled. */
6703 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6705 row
= MATRIX_ROW (w
->current_matrix
, i
);
6706 if (!row
->enabled_p
)
6708 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6715 /* Give up if Y is not in the window. */
6716 if (i
== w
->current_matrix
->nrows
)
6719 /* Get the glyph area containing X. */
6720 if (w
->pseudo_window_p
)
6727 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6728 if (x
< left_area_width
)
6730 *area
= LEFT_MARGIN_AREA
;
6733 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6736 x0
= row
->x
+ left_area_width
;
6740 *area
= RIGHT_MARGIN_AREA
;
6741 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6745 /* Find glyph containing X. */
6746 glyph
= row
->glyphs
[*area
];
6747 end
= glyph
+ row
->used
[*area
];
6750 if (x
< x0
+ glyph
->pixel_width
)
6752 if (w
->pseudo_window_p
)
6754 else if (!buffer_only_p
|| BUFFERP (glyph
->object
))
6758 x0
+= glyph
->pixel_width
;
6765 *hpos
= glyph
- row
->glyphs
[*area
];
6770 /* Convert frame-relative x/y to coordinates relative to window W.
6771 Takes pseudo-windows into account. */
6774 frame_to_window_pixel_xy (w
, x
, y
)
6778 if (w
->pseudo_window_p
)
6780 /* A pseudo-window is always full-width, and starts at the
6781 left edge of the frame, plus a frame border. */
6782 struct frame
*f
= XFRAME (w
->frame
);
6783 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6784 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6788 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6789 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6794 /* Take proper action when mouse has moved to the mode or header line of
6795 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6796 mode line. X is relative to the start of the text display area of
6797 W, so the width of fringes and scroll bars must be subtracted
6798 to get a position relative to the start of the mode line. */
6801 note_mode_line_highlight (w
, x
, mode_line_p
)
6805 struct frame
*f
= XFRAME (w
->frame
);
6806 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6807 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6808 struct glyph_row
*row
;
6811 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
6813 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
6817 struct glyph
*glyph
, *end
;
6818 Lisp_Object help
, map
;
6821 /* Find the glyph under X. */
6822 glyph
= row
->glyphs
[TEXT_AREA
];
6823 end
= glyph
+ row
->used
[TEXT_AREA
];
6824 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6825 + FRAME_X_LEFT_FRINGE_WIDTH (f
));
6828 && x
>= x0
+ glyph
->pixel_width
)
6830 x0
+= glyph
->pixel_width
;
6835 && STRINGP (glyph
->object
)
6836 && XSTRING (glyph
->object
)->intervals
6837 && glyph
->charpos
>= 0
6838 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6840 /* If we're on a string with `help-echo' text property,
6841 arrange for the help to be displayed. This is done by
6842 setting the global variable help_echo to the help string. */
6843 help
= Fget_text_property (make_number (glyph
->charpos
),
6844 Qhelp_echo
, glyph
->object
);
6848 XSETWINDOW (help_echo_window
, w
);
6849 help_echo_object
= glyph
->object
;
6850 help_echo_pos
= glyph
->charpos
;
6853 /* Change the mouse pointer according to what is under X/Y. */
6854 map
= Fget_text_property (make_number (glyph
->charpos
),
6855 Qlocal_map
, glyph
->object
);
6857 cursor
= f
->output_data
.x
->nontext_cursor
;
6860 map
= Fget_text_property (make_number (glyph
->charpos
),
6861 Qkeymap
, glyph
->object
);
6863 cursor
= f
->output_data
.x
->nontext_cursor
;
6868 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6872 /* Take proper action when the mouse has moved to position X, Y on
6873 frame F as regards highlighting characters that have mouse-face
6874 properties. Also de-highlighting chars where the mouse was before.
6875 X and Y can be negative or out of range. */
6878 note_mouse_highlight (f
, x
, y
)
6882 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6886 Cursor cursor
= None
;
6889 /* When a menu is active, don't highlight because this looks odd. */
6890 #ifdef USE_X_TOOLKIT
6891 if (popup_activated ())
6895 if (NILP (Vmouse_highlight
)
6896 || !f
->glyphs_initialized_p
)
6899 dpyinfo
->mouse_face_mouse_x
= x
;
6900 dpyinfo
->mouse_face_mouse_y
= y
;
6901 dpyinfo
->mouse_face_mouse_frame
= f
;
6903 if (dpyinfo
->mouse_face_defer
)
6908 dpyinfo
->mouse_face_deferred_gc
= 1;
6912 /* Which window is that in? */
6913 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6915 /* If we were displaying active text in another window, clear that. */
6916 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6917 clear_mouse_face (dpyinfo
);
6919 /* Not on a window -> return. */
6920 if (!WINDOWP (window
))
6923 /* Convert to window-relative pixel coordinates. */
6924 w
= XWINDOW (window
);
6925 frame_to_window_pixel_xy (w
, &x
, &y
);
6927 /* Handle tool-bar window differently since it doesn't display a
6929 if (EQ (window
, f
->tool_bar_window
))
6931 note_tool_bar_highlight (f
, x
, y
);
6935 /* Mouse is on the mode or header line? */
6936 if (portion
== 1 || portion
== 3)
6938 note_mode_line_highlight (w
, x
, portion
== 1);
6943 cursor
= f
->output_data
.x
->horizontal_drag_cursor
;
6945 cursor
= f
->output_data
.x
->text_cursor
;
6947 /* Are we in a window whose display is up to date?
6948 And verify the buffer's text has not changed. */
6949 b
= XBUFFER (w
->buffer
);
6950 if (/* Within text portion of the window. */
6952 && EQ (w
->window_end_valid
, w
->buffer
)
6953 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
6954 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
6956 int hpos
, vpos
, pos
, i
, area
;
6957 struct glyph
*glyph
;
6959 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
6960 Lisp_Object
*overlay_vec
= NULL
;
6962 struct buffer
*obuf
;
6963 int obegv
, ozv
, same_region
;
6965 /* Find the glyph under X/Y. */
6966 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
, 0);
6968 /* Clear mouse face if X/Y not over text. */
6970 || area
!= TEXT_AREA
6971 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6973 if (clear_mouse_face (dpyinfo
))
6978 pos
= glyph
->charpos
;
6979 object
= glyph
->object
;
6980 if (!STRINGP (object
) && !BUFFERP (object
))
6983 /* If we get an out-of-range value, return now; avoid an error. */
6984 if (BUFFERP (object
) && pos
> BUF_Z (b
))
6987 /* Make the window's buffer temporarily current for
6988 overlays_at and compute_char_face. */
6989 obuf
= current_buffer
;
6996 /* Is this char mouse-active or does it have help-echo? */
6997 position
= make_number (pos
);
6999 if (BUFFERP (object
))
7001 /* Put all the overlays we want in a vector in overlay_vec.
7002 Store the length in len. If there are more than 10, make
7003 enough space for all, and try again. */
7005 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
7006 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
7007 if (noverlays
> len
)
7010 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
7011 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
7014 /* Sort overlays into increasing priority order. */
7015 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
7020 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
7021 && vpos
>= dpyinfo
->mouse_face_beg_row
7022 && vpos
<= dpyinfo
->mouse_face_end_row
7023 && (vpos
> dpyinfo
->mouse_face_beg_row
7024 || hpos
>= dpyinfo
->mouse_face_beg_col
)
7025 && (vpos
< dpyinfo
->mouse_face_end_row
7026 || hpos
< dpyinfo
->mouse_face_end_col
7027 || dpyinfo
->mouse_face_past_end
));
7032 /* Check mouse-face highlighting. */
7034 /* If there exists an overlay with mouse-face overlapping
7035 the one we are currently highlighting, we have to
7036 check if we enter the overlapping overlay, and then
7037 highlight only that. */
7038 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
7039 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
7041 /* Find the highest priority overlay that has a mouse-face
7044 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
7046 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
7047 if (!NILP (mouse_face
))
7048 overlay
= overlay_vec
[i
];
7051 /* If we're actually highlighting the same overlay as
7052 before, there's no need to do that again. */
7054 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
7055 goto check_help_echo
;
7057 dpyinfo
->mouse_face_overlay
= overlay
;
7059 /* Clear the display of the old active region, if any. */
7060 if (clear_mouse_face (dpyinfo
))
7063 /* If no overlay applies, get a text property. */
7065 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
7067 /* Handle the overlay case. */
7068 if (!NILP (overlay
))
7070 /* Find the range of text around this char that
7071 should be active. */
7072 Lisp_Object before
, after
;
7075 before
= Foverlay_start (overlay
);
7076 after
= Foverlay_end (overlay
);
7077 /* Record this as the current active region. */
7078 fast_find_position (w
, XFASTINT (before
),
7079 &dpyinfo
->mouse_face_beg_col
,
7080 &dpyinfo
->mouse_face_beg_row
,
7081 &dpyinfo
->mouse_face_beg_x
,
7082 &dpyinfo
->mouse_face_beg_y
, Qnil
);
7084 dpyinfo
->mouse_face_past_end
7085 = !fast_find_position (w
, XFASTINT (after
),
7086 &dpyinfo
->mouse_face_end_col
,
7087 &dpyinfo
->mouse_face_end_row
,
7088 &dpyinfo
->mouse_face_end_x
,
7089 &dpyinfo
->mouse_face_end_y
, Qnil
);
7090 dpyinfo
->mouse_face_window
= window
;
7091 dpyinfo
->mouse_face_face_id
7092 = face_at_buffer_position (w
, pos
, 0, 0,
7093 &ignore
, pos
+ 1, 1);
7095 /* Display it as active. */
7096 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7099 /* Handle the text property case. */
7100 else if (!NILP (mouse_face
) && BUFFERP (object
))
7102 /* Find the range of text around this char that
7103 should be active. */
7104 Lisp_Object before
, after
, beginning
, end
;
7107 beginning
= Fmarker_position (w
->start
);
7108 end
= make_number (BUF_Z (XBUFFER (object
))
7109 - XFASTINT (w
->window_end_pos
));
7111 = Fprevious_single_property_change (make_number (pos
+ 1),
7115 = Fnext_single_property_change (position
, Qmouse_face
,
7118 /* Record this as the current active region. */
7119 fast_find_position (w
, XFASTINT (before
),
7120 &dpyinfo
->mouse_face_beg_col
,
7121 &dpyinfo
->mouse_face_beg_row
,
7122 &dpyinfo
->mouse_face_beg_x
,
7123 &dpyinfo
->mouse_face_beg_y
, Qnil
);
7124 dpyinfo
->mouse_face_past_end
7125 = !fast_find_position (w
, XFASTINT (after
),
7126 &dpyinfo
->mouse_face_end_col
,
7127 &dpyinfo
->mouse_face_end_row
,
7128 &dpyinfo
->mouse_face_end_x
,
7129 &dpyinfo
->mouse_face_end_y
, Qnil
);
7130 dpyinfo
->mouse_face_window
= window
;
7132 if (BUFFERP (object
))
7133 dpyinfo
->mouse_face_face_id
7134 = face_at_buffer_position (w
, pos
, 0, 0,
7135 &ignore
, pos
+ 1, 1);
7137 /* Display it as active. */
7138 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7141 else if (!NILP (mouse_face
) && STRINGP (object
))
7146 b
= Fprevious_single_property_change (make_number (pos
+ 1),
7149 e
= Fnext_single_property_change (position
, Qmouse_face
,
7152 b
= make_number (0);
7154 e
= make_number (XSTRING (object
)->size
- 1);
7155 fast_find_string_pos (w
, XINT (b
), object
,
7156 &dpyinfo
->mouse_face_beg_col
,
7157 &dpyinfo
->mouse_face_beg_row
,
7158 &dpyinfo
->mouse_face_beg_x
,
7159 &dpyinfo
->mouse_face_beg_y
, 0);
7160 fast_find_string_pos (w
, XINT (e
), object
,
7161 &dpyinfo
->mouse_face_end_col
,
7162 &dpyinfo
->mouse_face_end_row
,
7163 &dpyinfo
->mouse_face_end_x
,
7164 &dpyinfo
->mouse_face_end_y
, 1);
7165 dpyinfo
->mouse_face_past_end
= 0;
7166 dpyinfo
->mouse_face_window
= window
;
7167 dpyinfo
->mouse_face_face_id
7168 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
7170 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7173 else if (STRINGP (object
) && NILP (mouse_face
))
7175 /* A string which doesn't have mouse-face, but
7176 the text ``under'' it might have. */
7177 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
7178 int start
= MATRIX_ROW_START_CHARPOS (r
);
7180 pos
= string_buffer_position (w
, object
, start
);
7182 mouse_face
= get_char_property_and_overlay (make_number (pos
),
7186 if (!NILP (mouse_face
) && !NILP (overlay
))
7188 Lisp_Object before
= Foverlay_start (overlay
);
7189 Lisp_Object after
= Foverlay_end (overlay
);
7192 /* Note that we might not be able to find position
7193 BEFORE in the glyph matrix if the overlay is
7194 entirely covered by a `display' property. In
7195 this case, we overshoot. So let's stop in
7196 the glyph matrix before glyphs for OBJECT. */
7197 fast_find_position (w
, XFASTINT (before
),
7198 &dpyinfo
->mouse_face_beg_col
,
7199 &dpyinfo
->mouse_face_beg_row
,
7200 &dpyinfo
->mouse_face_beg_x
,
7201 &dpyinfo
->mouse_face_beg_y
,
7204 dpyinfo
->mouse_face_past_end
7205 = !fast_find_position (w
, XFASTINT (after
),
7206 &dpyinfo
->mouse_face_end_col
,
7207 &dpyinfo
->mouse_face_end_row
,
7208 &dpyinfo
->mouse_face_end_x
,
7209 &dpyinfo
->mouse_face_end_y
,
7211 dpyinfo
->mouse_face_window
= window
;
7212 dpyinfo
->mouse_face_face_id
7213 = face_at_buffer_position (w
, pos
, 0, 0,
7214 &ignore
, pos
+ 1, 1);
7216 /* Display it as active. */
7217 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7225 /* Look for a `help-echo' property. */
7227 Lisp_Object help
, overlay
;
7229 /* Check overlays first. */
7230 help
= overlay
= Qnil
;
7231 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
7233 overlay
= overlay_vec
[i
];
7234 help
= Foverlay_get (overlay
, Qhelp_echo
);
7240 help_echo_window
= window
;
7241 help_echo_object
= overlay
;
7242 help_echo_pos
= pos
;
7246 Lisp_Object object
= glyph
->object
;
7247 int charpos
= glyph
->charpos
;
7249 /* Try text properties. */
7250 if (STRINGP (object
)
7252 && charpos
< XSTRING (object
)->size
)
7254 help
= Fget_text_property (make_number (charpos
),
7255 Qhelp_echo
, object
);
7258 /* If the string itself doesn't specify a help-echo,
7259 see if the buffer text ``under'' it does. */
7261 = MATRIX_ROW (w
->current_matrix
, vpos
);
7262 int start
= MATRIX_ROW_START_CHARPOS (r
);
7263 int pos
= string_buffer_position (w
, object
, start
);
7266 help
= Fget_char_property (make_number (pos
),
7267 Qhelp_echo
, w
->buffer
);
7276 else if (BUFFERP (object
)
7279 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
7285 help_echo_window
= window
;
7286 help_echo_object
= object
;
7287 help_echo_pos
= charpos
;
7294 current_buffer
= obuf
;
7300 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7304 redo_mouse_highlight ()
7306 if (!NILP (last_mouse_motion_frame
)
7307 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
7308 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
7309 last_mouse_motion_event
.x
,
7310 last_mouse_motion_event
.y
);
7315 /***********************************************************************
7317 ***********************************************************************/
7319 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
7320 struct glyph
**, int *, int *, int *));
7322 /* Tool-bar item index of the item on which a mouse button was pressed
7325 static int last_tool_bar_item
;
7328 /* Get information about the tool-bar item at position X/Y on frame F.
7329 Return in *GLYPH a pointer to the glyph of the tool-bar item in
7330 the current matrix of the tool-bar window of F, or NULL if not
7331 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
7332 item in F->tool_bar_items. Value is
7334 -1 if X/Y is not on a tool-bar item
7335 0 if X/Y is on the same item that was highlighted before.
7339 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
7342 struct glyph
**glyph
;
7343 int *hpos
, *vpos
, *prop_idx
;
7345 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7346 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7349 /* Find the glyph under X/Y. */
7350 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
, 0);
7354 /* Get the start of this tool-bar item's properties in
7355 f->tool_bar_items. */
7356 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
7359 /* Is mouse on the highlighted item? */
7360 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
7361 && *vpos
>= dpyinfo
->mouse_face_beg_row
7362 && *vpos
<= dpyinfo
->mouse_face_end_row
7363 && (*vpos
> dpyinfo
->mouse_face_beg_row
7364 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
7365 && (*vpos
< dpyinfo
->mouse_face_end_row
7366 || *hpos
< dpyinfo
->mouse_face_end_col
7367 || dpyinfo
->mouse_face_past_end
))
7374 /* Handle mouse button event on the tool-bar of frame F, at
7375 frame-relative coordinates X/Y. EVENT_TYPE is either ButtonPress
7379 x_handle_tool_bar_click (f
, button_event
)
7381 XButtonEvent
*button_event
;
7383 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7384 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7385 int hpos
, vpos
, prop_idx
;
7386 struct glyph
*glyph
;
7387 Lisp_Object enabled_p
;
7388 int x
= button_event
->x
;
7389 int y
= button_event
->y
;
7391 /* If not on the highlighted tool-bar item, return. */
7392 frame_to_window_pixel_xy (w
, &x
, &y
);
7393 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
7396 /* If item is disabled, do nothing. */
7397 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7398 if (NILP (enabled_p
))
7401 if (button_event
->type
== ButtonPress
)
7403 /* Show item in pressed state. */
7404 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
7405 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
7406 last_tool_bar_item
= prop_idx
;
7410 Lisp_Object key
, frame
;
7411 struct input_event event
;
7413 /* Show item in released state. */
7414 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
7415 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
7417 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
7419 XSETFRAME (frame
, f
);
7420 event
.kind
= TOOL_BAR_EVENT
;
7421 event
.frame_or_window
= frame
;
7423 kbd_buffer_store_event (&event
);
7425 event
.kind
= TOOL_BAR_EVENT
;
7426 event
.frame_or_window
= frame
;
7428 event
.modifiers
= x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
7429 button_event
->state
);
7430 kbd_buffer_store_event (&event
);
7431 last_tool_bar_item
= -1;
7436 /* Possibly highlight a tool-bar item on frame F when mouse moves to
7437 tool-bar window-relative coordinates X/Y. Called from
7438 note_mouse_highlight. */
7441 note_tool_bar_highlight (f
, x
, y
)
7445 Lisp_Object window
= f
->tool_bar_window
;
7446 struct window
*w
= XWINDOW (window
);
7447 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7449 struct glyph
*glyph
;
7450 struct glyph_row
*row
;
7452 Lisp_Object enabled_p
;
7454 enum draw_glyphs_face draw
;
7455 int mouse_down_p
, rc
;
7457 /* Function note_mouse_highlight is called with negative x(y
7458 values when mouse moves outside of the frame. */
7459 if (x
<= 0 || y
<= 0)
7461 clear_mouse_face (dpyinfo
);
7465 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
7468 /* Not on tool-bar item. */
7469 clear_mouse_face (dpyinfo
);
7475 clear_mouse_face (dpyinfo
);
7477 /* Mouse is down, but on different tool-bar item? */
7478 mouse_down_p
= (dpyinfo
->grabbed
7479 && f
== last_mouse_frame
7480 && FRAME_LIVE_P (f
));
7482 && last_tool_bar_item
!= prop_idx
)
7485 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
7486 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
7488 /* If tool-bar item is not enabled, don't highlight it. */
7489 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7490 if (!NILP (enabled_p
))
7492 /* Compute the x-position of the glyph. In front and past the
7493 image is a space. We include this is the highlighted area. */
7494 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
7495 for (i
= x
= 0; i
< hpos
; ++i
)
7496 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
7498 /* Record this as the current active region. */
7499 dpyinfo
->mouse_face_beg_col
= hpos
;
7500 dpyinfo
->mouse_face_beg_row
= vpos
;
7501 dpyinfo
->mouse_face_beg_x
= x
;
7502 dpyinfo
->mouse_face_beg_y
= row
->y
;
7503 dpyinfo
->mouse_face_past_end
= 0;
7505 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
7506 dpyinfo
->mouse_face_end_row
= vpos
;
7507 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
7508 dpyinfo
->mouse_face_end_y
= row
->y
;
7509 dpyinfo
->mouse_face_window
= window
;
7510 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
7512 /* Display it as active. */
7513 show_mouse_face (dpyinfo
, draw
);
7514 dpyinfo
->mouse_face_image_state
= draw
;
7519 /* Set help_echo to a help string to display for this tool-bar item.
7520 XTread_socket does the rest. */
7521 help_echo_object
= help_echo_window
= Qnil
;
7523 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
7524 if (NILP (help_echo
))
7525 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
7530 /* Find the glyph matrix position of buffer position CHARPOS in window
7531 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
7532 current glyphs must be up to date. If CHARPOS is above window
7533 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
7534 of last line in W. In the row containing CHARPOS, stop before glyphs
7535 having STOP as object. */
7537 #if 0 /* This is a version of fast_find_position that's more correct
7538 in the presence of hscrolling, for example. I didn't install
7539 it right away because the problem fixed is minor, it failed
7540 in 20.x as well, and I think it's too risky to install
7541 so near the release of 21.1. 2001-09-25 gerd. */
7544 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
7547 int *hpos
, *vpos
, *x
, *y
;
7550 struct glyph_row
*row
, *first
;
7551 struct glyph
*glyph
, *end
;
7552 int i
, past_end
= 0;
7554 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7555 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
7558 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
7560 *x
= *y
= *hpos
= *vpos
= 0;
7565 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
7572 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
7574 glyph
= row
->glyphs
[TEXT_AREA
];
7575 end
= glyph
+ row
->used
[TEXT_AREA
];
7577 /* Skip over glyphs not having an object at the start of the row.
7578 These are special glyphs like truncation marks on terminal
7580 if (row
->displays_text_p
)
7582 && INTEGERP (glyph
->object
)
7583 && !EQ (stop
, glyph
->object
)
7584 && glyph
->charpos
< 0)
7586 *x
+= glyph
->pixel_width
;
7591 && !INTEGERP (glyph
->object
)
7592 && !EQ (stop
, glyph
->object
)
7593 && (!BUFFERP (glyph
->object
)
7594 || glyph
->charpos
< charpos
))
7596 *x
+= glyph
->pixel_width
;
7600 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
7607 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
7610 int *hpos
, *vpos
, *x
, *y
;
7615 int maybe_next_line_p
= 0;
7616 int line_start_position
;
7617 int yb
= window_text_bottom_y (w
);
7618 struct glyph_row
*row
, *best_row
;
7619 int row_vpos
, best_row_vpos
;
7622 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7623 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
7627 if (row
->used
[TEXT_AREA
])
7628 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
7630 line_start_position
= 0;
7632 if (line_start_position
> pos
)
7634 /* If the position sought is the end of the buffer,
7635 don't include the blank lines at the bottom of the window. */
7636 else if (line_start_position
== pos
7637 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
7639 maybe_next_line_p
= 1;
7642 else if (line_start_position
> 0)
7645 best_row_vpos
= row_vpos
;
7648 if (row
->y
+ row
->height
>= yb
)
7655 /* Find the right column within BEST_ROW. */
7657 current_x
= best_row
->x
;
7658 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
7660 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
7661 int charpos
= glyph
->charpos
;
7663 if (BUFFERP (glyph
->object
))
7668 *vpos
= best_row_vpos
;
7673 else if (charpos
> pos
)
7676 else if (EQ (glyph
->object
, stop
))
7681 current_x
+= glyph
->pixel_width
;
7684 /* If we're looking for the end of the buffer,
7685 and we didn't find it in the line we scanned,
7686 use the start of the following line. */
7687 if (maybe_next_line_p
)
7692 current_x
= best_row
->x
;
7695 *vpos
= best_row_vpos
;
7696 *hpos
= lastcol
+ 1;
7705 /* Find the position of the glyph for position POS in OBJECT in
7706 window W's current matrix, and return in *X, *Y the pixel
7707 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
7709 RIGHT_P non-zero means return the position of the right edge of the
7710 glyph, RIGHT_P zero means return the left edge position.
7712 If no glyph for POS exists in the matrix, return the position of
7713 the glyph with the next smaller position that is in the matrix, if
7714 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
7715 exists in the matrix, return the position of the glyph with the
7716 next larger position in OBJECT.
7718 Value is non-zero if a glyph was found. */
7721 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
7725 int *hpos
, *vpos
, *x
, *y
;
7728 int yb
= window_text_bottom_y (w
);
7729 struct glyph_row
*r
;
7730 struct glyph
*best_glyph
= NULL
;
7731 struct glyph_row
*best_row
= NULL
;
7734 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7735 r
->enabled_p
&& r
->y
< yb
;
7738 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7739 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
7742 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
7743 if (EQ (g
->object
, object
))
7745 if (g
->charpos
== pos
)
7752 else if (best_glyph
== NULL
7753 || ((abs (g
->charpos
- pos
)
7754 < abs (best_glyph
->charpos
- pos
))
7757 : g
->charpos
> pos
)))
7771 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
7775 *x
+= best_glyph
->pixel_width
;
7780 *vpos
= best_row
- w
->current_matrix
->rows
;
7783 return best_glyph
!= NULL
;
7787 /* Display the active region described by mouse_face_*
7788 in its mouse-face if HL > 0, in its normal face if HL = 0. */
7791 show_mouse_face (dpyinfo
, draw
)
7792 struct x_display_info
*dpyinfo
;
7793 enum draw_glyphs_face draw
;
7795 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
7796 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7798 if (/* If window is in the process of being destroyed, don't bother
7800 w
->current_matrix
!= NULL
7801 /* Don't update mouse highlight if hidden */
7802 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
7803 /* Recognize when we are called to operate on rows that don't exist
7804 anymore. This can happen when a window is split. */
7805 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
7807 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
7808 struct glyph_row
*row
, *first
, *last
;
7810 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
7811 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
7813 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
7815 int start_hpos
, end_hpos
, start_x
;
7817 /* For all but the first row, the highlight starts at column 0. */
7820 start_hpos
= dpyinfo
->mouse_face_beg_col
;
7821 start_x
= dpyinfo
->mouse_face_beg_x
;
7830 end_hpos
= dpyinfo
->mouse_face_end_col
;
7832 end_hpos
= row
->used
[TEXT_AREA
];
7834 if (end_hpos
> start_hpos
)
7836 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
7837 start_hpos
, end_hpos
, draw
, 0);
7840 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
7844 /* When we've written over the cursor, arrange for it to
7845 be displayed again. */
7846 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
7847 x_display_cursor (w
, 1,
7848 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
7849 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
7852 /* Change the mouse cursor. */
7853 if (draw
== DRAW_NORMAL_TEXT
)
7854 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7855 f
->output_data
.x
->text_cursor
);
7856 else if (draw
== DRAW_MOUSE_FACE
)
7857 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7858 f
->output_data
.x
->cross_cursor
);
7860 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7861 f
->output_data
.x
->nontext_cursor
);
7864 /* Clear out the mouse-highlighted active region.
7865 Redraw it un-highlighted first. Value is non-zero if mouse
7866 face was actually drawn unhighlighted. */
7869 clear_mouse_face (dpyinfo
)
7870 struct x_display_info
*dpyinfo
;
7874 if (!NILP (dpyinfo
->mouse_face_window
))
7876 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
7880 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7881 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7882 dpyinfo
->mouse_face_window
= Qnil
;
7883 dpyinfo
->mouse_face_overlay
= Qnil
;
7888 /* Clear any mouse-face on window W. This function is part of the
7889 redisplay interface, and is called from try_window_id and similar
7890 functions to ensure the mouse-highlight is off. */
7893 x_clear_mouse_face (w
)
7896 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
7900 XSETWINDOW (window
, w
);
7901 if (EQ (window
, dpyinfo
->mouse_face_window
))
7902 clear_mouse_face (dpyinfo
);
7907 /* Just discard the mouse face information for frame F, if any.
7908 This is used when the size of F is changed. */
7911 cancel_mouse_face (f
)
7915 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7917 window
= dpyinfo
->mouse_face_window
;
7918 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
7920 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7921 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7922 dpyinfo
->mouse_face_window
= Qnil
;
7927 static int glyph_rect
P_ ((struct frame
*f
, int, int, XRectangle
*));
7930 /* Try to determine frame pixel position and size of the glyph under
7931 frame pixel coordinates X/Y on frame F . Return the position and
7932 size in *RECT. Value is non-zero if we could compute these
7936 glyph_rect (f
, x
, y
, rect
)
7942 int part
, found
= 0;
7944 window
= window_from_coordinates (f
, x
, y
, &part
, 0);
7947 struct window
*w
= XWINDOW (window
);
7948 struct glyph_row
*r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7949 struct glyph_row
*end
= r
+ w
->current_matrix
->nrows
- 1;
7951 frame_to_window_pixel_xy (w
, &x
, &y
);
7953 for (; !found
&& r
< end
&& r
->enabled_p
; ++r
)
7956 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7957 struct glyph
*end
= g
+ r
->used
[TEXT_AREA
];
7960 for (gx
= r
->x
; !found
&& g
< end
; gx
+= g
->pixel_width
, ++g
)
7963 rect
->width
= g
->pixel_width
;
7964 rect
->height
= r
->height
;
7965 rect
->x
= WINDOW_TO_FRAME_PIXEL_X (w
, gx
);
7966 rect
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, r
->y
);
7976 /* Return the current position of the mouse.
7977 *FP should be a frame which indicates which display to ask about.
7979 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
7980 and *PART to the frame, window, and scroll bar part that the mouse
7981 is over. Set *X and *Y to the portion and whole of the mouse's
7982 position on the scroll bar.
7984 If the mouse movement started elsewhere, set *FP to the frame the
7985 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
7988 Set *TIME to the server time-stamp for the time at which the mouse
7989 was at this position.
7991 Don't store anything if we don't have a valid set of values to report.
7993 This clears the mouse_moved flag, so we can wait for the next mouse
7997 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
8000 Lisp_Object
*bar_window
;
8001 enum scroll_bar_part
*part
;
8003 unsigned long *time
;
8009 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
8010 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
8016 Window dummy_window
;
8019 Lisp_Object frame
, tail
;
8021 /* Clear the mouse-moved flag for every frame on this display. */
8022 FOR_EACH_FRAME (tail
, frame
)
8023 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
8024 XFRAME (frame
)->mouse_moved
= 0;
8026 last_mouse_scroll_bar
= Qnil
;
8028 /* Figure out which root window we're on. */
8029 XQueryPointer (FRAME_X_DISPLAY (*fp
),
8030 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
8032 /* The root window which contains the pointer. */
8035 /* Trash which we can't trust if the pointer is on
8036 a different screen. */
8039 /* The position on that root window. */
8042 /* More trash we can't trust. */
8045 /* Modifier keys and pointer buttons, about which
8047 (unsigned int *) &dummy
);
8049 /* Now we have a position on the root; find the innermost window
8050 containing the pointer. */
8054 int parent_x
= 0, parent_y
= 0;
8059 /* XTranslateCoordinates can get errors if the window
8060 structure is changing at the same time this function
8061 is running. So at least we must not crash from them. */
8063 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
8065 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
8066 && FRAME_LIVE_P (last_mouse_frame
))
8068 /* If mouse was grabbed on a frame, give coords for that frame
8069 even if the mouse is now outside it. */
8070 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
8072 /* From-window, to-window. */
8073 root
, FRAME_X_WINDOW (last_mouse_frame
),
8075 /* From-position, to-position. */
8076 root_x
, root_y
, &win_x
, &win_y
,
8080 f1
= last_mouse_frame
;
8086 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
8088 /* From-window, to-window. */
8091 /* From-position, to-position. */
8092 root_x
, root_y
, &win_x
, &win_y
,
8097 if (child
== None
|| child
== win
)
8105 /* Now we know that:
8106 win is the innermost window containing the pointer
8107 (XTC says it has no child containing the pointer),
8108 win_x and win_y are the pointer's position in it
8109 (XTC did this the last time through), and
8110 parent_x and parent_y are the pointer's position in win's parent.
8111 (They are what win_x and win_y were when win was child.
8112 If win is the root window, it has no parent, and
8113 parent_{x,y} are invalid, but that's okay, because we'll
8114 never use them in that case.) */
8116 /* Is win one of our frames? */
8117 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
8119 #ifdef USE_X_TOOLKIT
8120 /* If we end up with the menu bar window, say it's not
8123 && f1
->output_data
.x
->menubar_widget
8124 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
8126 #endif /* USE_X_TOOLKIT */
8129 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
8132 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
8134 /* If not, is it one of our scroll bars? */
8137 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
8141 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8147 if (f1
== 0 && insist
> 0)
8148 f1
= SELECTED_FRAME ();
8152 /* Ok, we found a frame. Store all the values.
8153 last_mouse_glyph is a rectangle used to reduce the
8154 generation of mouse events. To not miss any motion
8155 events, we must divide the frame into rectangles of the
8156 size of the smallest character that could be displayed
8157 on it, i.e. into the same rectangles that matrices on
8158 the frame are divided into. */
8160 int width
, height
, gx
, gy
;
8163 if (glyph_rect (f1
, win_x
, win_y
, &rect
))
8164 last_mouse_glyph
= rect
;
8167 width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
8168 height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
8172 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
8173 round down even for negative values. */
8178 gx
= (gx
+ width
- 1) / width
* width
;
8179 gy
= (gy
+ height
- 1) / height
* height
;
8181 last_mouse_glyph
.width
= width
;
8182 last_mouse_glyph
.height
= height
;
8183 last_mouse_glyph
.x
= gx
;
8184 last_mouse_glyph
.y
= gy
;
8190 XSETINT (*x
, win_x
);
8191 XSETINT (*y
, win_y
);
8192 *time
= last_mouse_movement_time
;
8201 #ifdef USE_X_TOOLKIT
8203 /* Atimer callback function for TIMER. Called every 0.1s to process
8204 Xt timeouts, if needed. We must avoid calling XtAppPending as
8205 much as possible because that function does an implicit XFlush
8206 that slows us down. */
8209 x_process_timeouts (timer
)
8210 struct atimer
*timer
;
8212 if (toolkit_scroll_bar_interaction
|| popup_activated_flag
)
8215 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
8216 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
8221 #endif /* USE_X_TOOLKIT */
8224 /* Scroll bar support. */
8226 /* Given an X window ID, find the struct scroll_bar which manages it.
8227 This can be called in GC, so we have to make sure to strip off mark
8230 static struct scroll_bar
*
8231 x_window_to_scroll_bar (window_id
)
8236 for (tail
= Vframe_list
;
8237 XGCTYPE (tail
) == Lisp_Cons
;
8240 Lisp_Object frame
, bar
, condemned
;
8242 frame
= XCAR (tail
);
8243 /* All elements of Vframe_list should be frames. */
8244 if (! GC_FRAMEP (frame
))
8247 /* Scan this frame's scroll bar list for a scroll bar with the
8249 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
8250 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
8251 /* This trick allows us to search both the ordinary and
8252 condemned scroll bar lists with one loop. */
8253 ! GC_NILP (bar
) || (bar
= condemned
,
8256 bar
= XSCROLL_BAR (bar
)->next
)
8257 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
8258 return XSCROLL_BAR (bar
);
8265 #if defined USE_LUCID
8267 /* Return the Lucid menu bar WINDOW is part of. Return null
8268 if WINDOW is not part of a menu bar. */
8271 x_window_to_menu_bar (window
)
8276 for (tail
= Vframe_list
;
8277 XGCTYPE (tail
) == Lisp_Cons
;
8280 Lisp_Object frame
= XCAR (tail
);
8281 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
8283 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
8290 #endif /* USE_LUCID */
8293 /************************************************************************
8295 ************************************************************************/
8297 #ifdef USE_TOOLKIT_SCROLL_BARS
8299 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
8300 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
8301 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
8302 struct scroll_bar
*));
8303 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
8307 /* Id of action hook installed for scroll bars. */
8309 static XtActionHookId action_hook_id
;
8311 /* Lisp window being scrolled. Set when starting to interact with
8312 a toolkit scroll bar, reset to nil when ending the interaction. */
8314 static Lisp_Object window_being_scrolled
;
8316 /* Last scroll bar part sent in xm_scroll_callback. */
8318 static int last_scroll_bar_part
;
8320 /* Whether this is an Xaw with arrow-scrollbars. This should imply
8321 that movements of 1/20 of the screen size are mapped to up/down. */
8323 static Boolean xaw3d_arrow_scroll
;
8325 /* Whether the drag scrolling maintains the mouse at the top of the
8326 thumb. If not, resizing the thumb needs to be done more carefully
8327 to avoid jerkyness. */
8329 static Boolean xaw3d_pick_top
;
8332 /* Action hook installed via XtAppAddActionHook when toolkit scroll
8333 bars are used.. The hook is responsible for detecting when
8334 the user ends an interaction with the scroll bar, and generates
8335 a `end-scroll' scroll_bar_click' event if so. */
8338 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
8341 XtPointer client_data
;
8345 Cardinal
*num_params
;
8351 scroll_bar_p
= XmIsScrollBar (widget
);
8352 end_action
= "Release";
8353 #else /* !USE_MOTIF i.e. use Xaw */
8354 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
8355 end_action
= "EndScroll";
8356 #endif /* USE_MOTIF */
8359 && strcmp (action_name
, end_action
) == 0
8360 && WINDOWP (window_being_scrolled
))
8364 x_send_scroll_bar_event (window_being_scrolled
,
8365 scroll_bar_end_scroll
, 0, 0);
8366 w
= XWINDOW (window_being_scrolled
);
8367 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
8368 window_being_scrolled
= Qnil
;
8369 last_scroll_bar_part
= -1;
8371 /* Xt timeouts no longer needed. */
8372 toolkit_scroll_bar_interaction
= 0;
8376 /* A vector of windows used for communication between
8377 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
8379 static struct window
**scroll_bar_windows
;
8380 static int scroll_bar_windows_size
;
8383 /* Send a client message with message type Xatom_Scrollbar for a
8384 scroll action to the frame of WINDOW. PART is a value identifying
8385 the part of the scroll bar that was clicked on. PORTION is the
8386 amount to scroll of a whole of WHOLE. */
8389 x_send_scroll_bar_event (window
, part
, portion
, whole
)
8391 int part
, portion
, whole
;
8394 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
8395 struct window
*w
= XWINDOW (window
);
8396 struct frame
*f
= XFRAME (w
->frame
);
8401 /* Construct a ClientMessage event to send to the frame. */
8402 ev
->type
= ClientMessage
;
8403 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
8404 ev
->display
= FRAME_X_DISPLAY (f
);
8405 ev
->window
= FRAME_X_WINDOW (f
);
8408 /* We can only transfer 32 bits in the XClientMessageEvent, which is
8409 not enough to store a pointer or Lisp_Object on a 64 bit system.
8410 So, store the window in scroll_bar_windows and pass the index
8411 into that array in the event. */
8412 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
8413 if (scroll_bar_windows
[i
] == NULL
)
8416 if (i
== scroll_bar_windows_size
)
8418 int new_size
= max (10, 2 * scroll_bar_windows_size
);
8419 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
8420 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
8422 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
8424 bzero (&scroll_bar_windows
[i
], nbytes
- old_nbytes
);
8425 scroll_bar_windows_size
= new_size
;
8428 scroll_bar_windows
[i
] = w
;
8429 ev
->data
.l
[0] = (long) i
;
8430 ev
->data
.l
[1] = (long) part
;
8431 ev
->data
.l
[2] = (long) 0;
8432 ev
->data
.l
[3] = (long) portion
;
8433 ev
->data
.l
[4] = (long) whole
;
8435 /* Make Xt timeouts work while the scroll bar is active. */
8436 toolkit_scroll_bar_interaction
= 1;
8438 /* Setting the event mask to zero means that the message will
8439 be sent to the client that created the window, and if that
8440 window no longer exists, no event will be sent. */
8441 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
8446 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
8450 x_scroll_bar_to_input_event (event
, ievent
)
8452 struct input_event
*ievent
;
8454 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
8459 w
= scroll_bar_windows
[ev
->data
.l
[0]];
8460 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
8462 XSETWINDOW (window
, w
);
8463 f
= XFRAME (w
->frame
);
8465 ievent
->kind
= scroll_bar_click
;
8466 ievent
->frame_or_window
= window
;
8468 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
8469 ievent
->part
= ev
->data
.l
[1];
8470 ievent
->code
= ev
->data
.l
[2];
8471 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
8472 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
8473 ievent
->modifiers
= 0;
8479 /* Minimum and maximum values used for Motif scroll bars. */
8482 #define XM_SB_MAX 10000000
8483 #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN)
8486 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
8487 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
8488 CALL_DATA is a pointer a a XmScrollBarCallbackStruct. */
8491 xm_scroll_callback (widget
, client_data
, call_data
)
8493 XtPointer client_data
, call_data
;
8495 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8496 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
8497 int part
= -1, whole
= 0, portion
= 0;
8501 case XmCR_DECREMENT
:
8502 bar
->dragging
= Qnil
;
8503 part
= scroll_bar_up_arrow
;
8506 case XmCR_INCREMENT
:
8507 bar
->dragging
= Qnil
;
8508 part
= scroll_bar_down_arrow
;
8511 case XmCR_PAGE_DECREMENT
:
8512 bar
->dragging
= Qnil
;
8513 part
= scroll_bar_above_handle
;
8516 case XmCR_PAGE_INCREMENT
:
8517 bar
->dragging
= Qnil
;
8518 part
= scroll_bar_below_handle
;
8522 bar
->dragging
= Qnil
;
8523 part
= scroll_bar_to_top
;
8526 case XmCR_TO_BOTTOM
:
8527 bar
->dragging
= Qnil
;
8528 part
= scroll_bar_to_bottom
;
8534 int dragging_down_p
= (INTEGERP (bar
->dragging
)
8535 && XINT (bar
->dragging
) <= cs
->value
);
8537 /* Get the slider size. */
8539 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
8542 whole
= XM_SB_RANGE
- slider_size
;
8543 portion
= min (cs
->value
- XM_SB_MIN
, whole
);
8544 part
= scroll_bar_handle
;
8545 bar
->dragging
= make_number (cs
->value
);
8549 case XmCR_VALUE_CHANGED
:
8555 window_being_scrolled
= bar
->window
;
8556 last_scroll_bar_part
= part
;
8557 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
8562 #else /* !USE_MOTIF, i.e. Xaw. */
8565 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
8566 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
8567 scroll bar struct. CALL_DATA is a pointer to a float saying where
8571 xaw_jump_callback (widget
, client_data
, call_data
)
8573 XtPointer client_data
, call_data
;
8575 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8576 float top
= *(float *) call_data
;
8578 int whole
, portion
, height
;
8581 /* Get the size of the thumb, a value between 0 and 1. */
8583 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
8587 portion
= shown
< 1 ? top
* whole
: 0;
8589 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
8590 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
8591 the bottom, so we force the scrolling whenever we see that we're
8592 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
8593 we try to ensure that we always stay two pixels away from the
8595 part
= scroll_bar_down_arrow
;
8597 part
= scroll_bar_handle
;
8599 window_being_scrolled
= bar
->window
;
8600 bar
->dragging
= make_number (portion
);
8601 last_scroll_bar_part
= part
;
8602 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
8606 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
8607 i.e. line or page up or down. WIDGET is the Xaw scroll bar
8608 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
8609 the scroll bar. CALL_DATA is an integer specifying the action that
8610 has taken place. It's magnitude is in the range 0..height of the
8611 scroll bar. Negative values mean scroll towards buffer start.
8612 Values < height of scroll bar mean line-wise movement. */
8615 xaw_scroll_callback (widget
, client_data
, call_data
)
8617 XtPointer client_data
, call_data
;
8619 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8620 int position
= (int) call_data
;
8624 /* Get the height of the scroll bar. */
8626 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
8629 if (abs (position
) >= height
)
8630 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
8632 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
8633 it maps line-movement to call_data = max(5, height/20). */
8634 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
8635 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
8637 part
= scroll_bar_move_ratio
;
8639 window_being_scrolled
= bar
->window
;
8640 bar
->dragging
= Qnil
;
8641 last_scroll_bar_part
= part
;
8642 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
8646 #endif /* not USE_MOTIF */
8649 /* Create the widget for scroll bar BAR on frame F. Record the widget
8650 and X window of the scroll bar in BAR. */
8653 x_create_toolkit_scroll_bar (f
, bar
)
8655 struct scroll_bar
*bar
;
8661 char *scroll_bar_name
= "verticalScrollBar";
8662 unsigned long pixel
;
8667 /* Set resources. Create the widget. */
8668 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
8669 XtSetArg (av
[ac
], XmNminimum
, XM_SB_MIN
); ++ac
;
8670 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
8671 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
8672 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
8673 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
8674 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
8676 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
8679 XtSetArg (av
[ac
], XmNforeground
, pixel
);
8683 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8686 XtSetArg (av
[ac
], XmNbackground
, pixel
);
8690 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
8691 scroll_bar_name
, av
, ac
);
8693 /* Add one callback for everything that can happen. */
8694 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
8696 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
8698 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
8700 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
8702 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
8704 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
8706 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
8709 /* Realize the widget. Only after that is the X window created. */
8710 XtRealizeWidget (widget
);
8712 /* Set the cursor to an arrow. I didn't find a resource to do that.
8713 And I'm wondering why it hasn't an arrow cursor by default. */
8714 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
8715 f
->output_data
.x
->nontext_cursor
);
8717 #else /* !USE_MOTIF i.e. use Xaw */
8719 /* Set resources. Create the widget. The background of the
8720 Xaw3d scroll bar widget is a little bit light for my taste.
8721 We don't alter it here to let users change it according
8722 to their taste with `emacs*verticalScrollBar.background: xxx'. */
8723 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
8724 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
8725 /* For smoother scrolling with Xaw3d -sm */
8726 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
8728 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
8731 XtSetArg (av
[ac
], XtNforeground
, pixel
);
8735 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8738 XtSetArg (av
[ac
], XtNbackground
, pixel
);
8742 /* Top/bottom shadow colors. */
8744 /* Allocate them, if necessary. */
8745 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
8747 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8748 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
8749 &pixel
, 1.2, 0x8000))
8751 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
8753 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
8755 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8756 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
8757 &pixel
, 0.6, 0x4000))
8759 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
8762 /* Tell the toolkit about them. */
8763 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
8764 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
8765 /* We tried to allocate a color for the top/bottom shadow, and
8766 failed, so tell Xaw3d to use dithering instead. */
8768 XtSetArg (av
[ac
], XtNbeNiceToColormap
, True
);
8772 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
8773 be more consistent with other emacs 3d colors, and since Xaw3d is
8774 not good at dealing with allocation failure. */
8776 /* This tells Xaw3d to use real colors instead of dithering for
8778 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
8781 /* Specify the colors. */
8782 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
8785 XtSetArg (av
[ac
], "topShadowPixel", pixel
);
8788 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
8791 XtSetArg (av
[ac
], "bottomShadowPixel", pixel
);
8796 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
8797 f
->output_data
.x
->edit_widget
, av
, ac
);
8801 char *val
= initial
;
8802 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
8803 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
8805 { /* ARROW_SCROLL */
8806 xaw3d_arrow_scroll
= True
;
8807 /* Isn't that just a personal preference ? -sm */
8808 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
8812 /* Define callbacks. */
8813 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
8814 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
8817 /* Realize the widget. Only after that is the X window created. */
8818 XtRealizeWidget (widget
);
8820 #endif /* !USE_MOTIF */
8822 /* Install an action hook that let's us detect when the user
8823 finishes interacting with a scroll bar. */
8824 if (action_hook_id
== 0)
8825 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
8827 /* Remember X window and widget in the scroll bar vector. */
8828 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
8829 xwindow
= XtWindow (widget
);
8830 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
8836 /* Set the thumb size and position of scroll bar BAR. We are currently
8837 displaying PORTION out of a whole WHOLE, and our position POSITION. */
8840 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
8841 struct scroll_bar
*bar
;
8842 int portion
, position
, whole
;
8844 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8845 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
8852 /* We use an estimate of 30 chars per line rather than the real
8853 `portion' value. This has the disadvantage that the thumb size
8854 is not very representative, but it makes our life a lot easier.
8855 Otherwise, we have to constantly adjust the thumb size, which
8856 we can't always do quickly enough: while dragging, the size of
8857 the thumb might prevent the user from dragging the thumb all the
8858 way to the end. but Motif and some versions of Xaw3d don't allow
8859 updating the thumb size while dragging. Also, even if we can update
8860 its size, the update will often happen too late.
8861 If you don't believe it, check out revision 1.650 of xterm.c to see
8862 what hoops we were going through and the still poor behavior we got. */
8863 portion
= XFASTINT (XWINDOW (bar
->window
)->height
) * 30;
8864 /* When the thumb is at the bottom, position == whole.
8865 So we need to increase `whole' to make space for the thumb. */
8872 top
= (float) position
/ whole
;
8873 shown
= (float) portion
/ whole
;
8876 if (NILP (bar
->dragging
))
8880 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
8881 is the scroll bar's maximum and MIN is the scroll bar's minimum
8883 size
= shown
* XM_SB_RANGE
;
8884 size
= min (size
, XM_SB_RANGE
);
8885 size
= max (size
, 1);
8887 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
8888 value
= top
* XM_SB_RANGE
;
8889 value
= min (value
, XM_SB_MAX
- size
);
8890 value
= max (value
, XM_SB_MIN
);
8892 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
8894 #else /* !USE_MOTIF i.e. use Xaw */
8900 top
= (float) position
/ whole
;
8901 shown
= (float) portion
/ whole
;
8905 float old_top
, old_shown
;
8907 XtVaGetValues (widget
,
8908 XtNtopOfThumb
, &old_top
,
8909 XtNshown
, &old_shown
,
8913 /* Massage the top+shown values. */
8914 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
8915 top
= max (0, min (1, top
));
8918 /* Keep two pixels available for moving the thumb down. */
8919 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
8921 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
8922 check that your system's configuration file contains a define
8923 for `NARROWPROTO'. See s/freebsd.h for an example. */
8924 if (top
!= old_top
|| shown
!= old_shown
)
8926 if (NILP (bar
->dragging
))
8927 XawScrollbarSetThumb (widget
, top
, shown
);
8931 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
8932 int scroll_mode
= 0;
8934 /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR. */
8935 if (xaw3d_arrow_scroll
)
8937 /* Xaw3d stupidly ignores resize requests while dragging
8938 so we have to make it believe it's not in dragging mode. */
8939 scroll_mode
= sb
->scrollbar
.scroll_mode
;
8940 if (scroll_mode
== 2)
8941 sb
->scrollbar
.scroll_mode
= 0;
8944 /* Try to make the scrolling a tad smoother. */
8945 if (!xaw3d_pick_top
)
8946 shown
= min (shown
, old_shown
);
8948 XawScrollbarSetThumb (widget
, top
, shown
);
8951 if (xaw3d_arrow_scroll
&& scroll_mode
== 2)
8952 sb
->scrollbar
.scroll_mode
= scroll_mode
;
8957 #endif /* !USE_MOTIF */
8962 #endif /* USE_TOOLKIT_SCROLL_BARS */
8966 /************************************************************************
8967 Scroll bars, general
8968 ************************************************************************/
8970 /* Create a scroll bar and return the scroll bar vector for it. W is
8971 the Emacs window on which to create the scroll bar. TOP, LEFT,
8972 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
8975 static struct scroll_bar
*
8976 x_scroll_bar_create (w
, top
, left
, width
, height
)
8978 int top
, left
, width
, height
;
8980 struct frame
*f
= XFRAME (w
->frame
);
8981 struct scroll_bar
*bar
8982 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
8986 #ifdef USE_TOOLKIT_SCROLL_BARS
8987 x_create_toolkit_scroll_bar (f
, bar
);
8988 #else /* not USE_TOOLKIT_SCROLL_BARS */
8990 XSetWindowAttributes a
;
8994 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8995 if (a
.background_pixel
== -1)
8996 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
8998 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
8999 | ButtonMotionMask
| PointerMotionHintMask
9001 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
9003 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
9005 /* Clear the area of W that will serve as a scroll bar. This is
9006 for the case that a window has been split horizontally. In
9007 this case, no clear_frame is generated to reduce flickering. */
9008 if (width
> 0 && height
> 0)
9009 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9011 window_box_height (w
), False
);
9013 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9014 /* Position and size of scroll bar. */
9015 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9017 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
9019 /* Border width, depth, class, and visual. */
9026 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
9028 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9030 XSETWINDOW (bar
->window
, w
);
9031 XSETINT (bar
->top
, top
);
9032 XSETINT (bar
->left
, left
);
9033 XSETINT (bar
->width
, width
);
9034 XSETINT (bar
->height
, height
);
9035 XSETINT (bar
->start
, 0);
9036 XSETINT (bar
->end
, 0);
9037 bar
->dragging
= Qnil
;
9039 /* Add bar to its frame's list of scroll bars. */
9040 bar
->next
= FRAME_SCROLL_BARS (f
);
9042 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
9043 if (!NILP (bar
->next
))
9044 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
9046 /* Map the window/widget. */
9047 #ifdef USE_TOOLKIT_SCROLL_BARS
9049 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
9050 XtConfigureWidget (scroll_bar
,
9051 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9053 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
9054 max (height
, 1), 0);
9055 XtMapWidget (scroll_bar
);
9057 #else /* not USE_TOOLKIT_SCROLL_BARS */
9058 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
9059 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9066 /* Draw BAR's handle in the proper position.
9068 If the handle is already drawn from START to END, don't bother
9069 redrawing it, unless REBUILD is non-zero; in that case, always
9070 redraw it. (REBUILD is handy for drawing the handle after expose
9073 Normally, we want to constrain the start and end of the handle to
9074 fit inside its rectangle, but if the user is dragging the scroll
9075 bar handle, we want to let them drag it down all the way, so that
9076 the bar's top is as far down as it goes; otherwise, there's no way
9077 to move to the very end of the buffer. */
9079 #ifndef USE_TOOLKIT_SCROLL_BARS
9082 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
9083 struct scroll_bar
*bar
;
9087 int dragging
= ! NILP (bar
->dragging
);
9088 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9089 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9090 GC gc
= f
->output_data
.x
->normal_gc
;
9092 /* If the display is already accurate, do nothing. */
9094 && start
== XINT (bar
->start
)
9095 && end
== XINT (bar
->end
))
9101 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
9102 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9103 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9105 /* Make sure the values are reasonable, and try to preserve
9106 the distance between start and end. */
9108 int length
= end
- start
;
9112 else if (start
> top_range
)
9114 end
= start
+ length
;
9118 else if (end
> top_range
&& ! dragging
)
9122 /* Store the adjusted setting in the scroll bar. */
9123 XSETINT (bar
->start
, start
);
9124 XSETINT (bar
->end
, end
);
9126 /* Clip the end position, just for display. */
9127 if (end
> top_range
)
9130 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
9131 below top positions, to make sure the handle is always at least
9132 that many pixels tall. */
9133 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
9135 /* Draw the empty space above the handle. Note that we can't clear
9136 zero-height areas; that means "clear to end of window." */
9138 x_clear_area (FRAME_X_DISPLAY (f
), w
,
9139 /* x, y, width, height, and exposures. */
9140 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
9141 VERTICAL_SCROLL_BAR_TOP_BORDER
,
9142 inside_width
, start
,
9145 /* Change to proper foreground color if one is specified. */
9146 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9147 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
9148 f
->output_data
.x
->scroll_bar_foreground_pixel
);
9150 /* Draw the handle itself. */
9151 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
9152 /* x, y, width, height */
9153 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
9154 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
9155 inside_width
, end
- start
);
9157 /* Restore the foreground color of the GC if we changed it above. */
9158 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9159 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
9160 f
->output_data
.x
->foreground_pixel
);
9162 /* Draw the empty space below the handle. Note that we can't
9163 clear zero-height areas; that means "clear to end of window." */
9164 if (end
< inside_height
)
9165 x_clear_area (FRAME_X_DISPLAY (f
), w
,
9166 /* x, y, width, height, and exposures. */
9167 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
9168 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
9169 inside_width
, inside_height
- end
,
9177 #endif /* !USE_TOOLKIT_SCROLL_BARS */
9179 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
9183 x_scroll_bar_remove (bar
)
9184 struct scroll_bar
*bar
;
9186 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9189 #ifdef USE_TOOLKIT_SCROLL_BARS
9190 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
9192 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
9195 /* Disassociate this scroll bar from its window. */
9196 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
9202 /* Set the handle of the vertical scroll bar for WINDOW to indicate
9203 that we are displaying PORTION characters out of a total of WHOLE
9204 characters, starting at POSITION. If WINDOW has no scroll bar,
9208 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
9210 int portion
, whole
, position
;
9212 struct frame
*f
= XFRAME (w
->frame
);
9213 struct scroll_bar
*bar
;
9214 int top
, height
, left
, sb_left
, width
, sb_width
;
9215 int window_x
, window_y
, window_width
, window_height
;
9217 /* Get window dimensions. */
9218 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
9220 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
9221 height
= window_height
;
9223 /* Compute the left edge of the scroll bar area. */
9224 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
9225 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
9227 left
= XFASTINT (w
->left
);
9228 left
*= CANON_X_UNIT (f
);
9229 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
9231 /* Compute the width of the scroll bar which might be less than
9232 the width of the area reserved for the scroll bar. */
9233 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
9234 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
9238 /* Compute the left edge of the scroll bar. */
9239 #ifdef USE_TOOLKIT_SCROLL_BARS
9240 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
9241 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
9243 sb_left
= left
+ (width
- sb_width
) / 2;
9245 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
9246 sb_left
= left
+ width
- sb_width
;
9251 /* Does the scroll bar exist yet? */
9252 if (NILP (w
->vertical_scroll_bar
))
9254 if (width
> 0 && height
> 0)
9257 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9258 left
, top
, width
, height
, False
);
9262 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
9266 /* It may just need to be moved and resized. */
9267 unsigned int mask
= 0;
9269 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
9273 if (sb_left
!= XINT (bar
->left
))
9275 if (top
!= XINT (bar
->top
))
9277 if (sb_width
!= XINT (bar
->width
))
9279 if (height
!= XINT (bar
->height
))
9282 #ifdef USE_TOOLKIT_SCROLL_BARS
9284 /* Since toolkit scroll bars are smaller than the space reserved
9285 for them on the frame, we have to clear "under" them. */
9286 if (width
> 0 && height
> 0)
9287 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9288 left
, top
, width
, height
, False
);
9290 /* Move/size the scroll bar widget. */
9292 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
9293 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9295 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
9296 max (height
, 1), 0);
9298 #else /* not USE_TOOLKIT_SCROLL_BARS */
9300 /* Clear areas not covered by the scroll bar because of
9301 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
9302 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
9304 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9305 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9307 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9308 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9309 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9313 /* Clear areas not covered by the scroll bar because it's not as
9314 wide as the area reserved for it. This makes sure a
9315 previous mode line display is cleared after C-x 2 C-x 1, for
9318 int area_width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
9319 int rest
= area_width
- sb_width
;
9320 if (rest
> 0 && height
> 0)
9322 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
9323 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9324 left
+ area_width
- rest
, top
,
9325 rest
, height
, False
);
9327 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9328 left
, top
, rest
, height
, False
);
9332 /* Move/size the scroll bar window. */
9337 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
9339 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
9341 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
9345 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9347 /* Remember new settings. */
9348 XSETINT (bar
->left
, sb_left
);
9349 XSETINT (bar
->top
, top
);
9350 XSETINT (bar
->width
, sb_width
);
9351 XSETINT (bar
->height
, height
);
9356 #ifdef USE_TOOLKIT_SCROLL_BARS
9357 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
9358 #else /* not USE_TOOLKIT_SCROLL_BARS */
9359 /* Set the scroll bar's current state, unless we're currently being
9361 if (NILP (bar
->dragging
))
9363 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
9366 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
9369 int start
= ((double) position
* top_range
) / whole
;
9370 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
9371 x_scroll_bar_set_handle (bar
, start
, end
, 0);
9374 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9376 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
9380 /* The following three hooks are used when we're doing a thorough
9381 redisplay of the frame. We don't explicitly know which scroll bars
9382 are going to be deleted, because keeping track of when windows go
9383 away is a real pain - "Can you say set-window-configuration, boys
9384 and girls?" Instead, we just assert at the beginning of redisplay
9385 that *all* scroll bars are to be removed, and then save a scroll bar
9386 from the fiery pit when we actually redisplay its window. */
9388 /* Arrange for all scroll bars on FRAME to be removed at the next call
9389 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
9390 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
9393 XTcondemn_scroll_bars (frame
)
9396 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
9397 while (! NILP (FRAME_SCROLL_BARS (frame
)))
9400 bar
= FRAME_SCROLL_BARS (frame
);
9401 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
9402 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
9403 XSCROLL_BAR (bar
)->prev
= Qnil
;
9404 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
9405 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
9406 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
9411 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
9412 Note that WINDOW isn't necessarily condemned at all. */
9415 XTredeem_scroll_bar (window
)
9416 struct window
*window
;
9418 struct scroll_bar
*bar
;
9421 /* We can't redeem this window's scroll bar if it doesn't have one. */
9422 if (NILP (window
->vertical_scroll_bar
))
9425 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
9427 /* Unlink it from the condemned list. */
9428 f
= XFRAME (WINDOW_FRAME (window
));
9429 if (NILP (bar
->prev
))
9431 /* If the prev pointer is nil, it must be the first in one of
9433 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
9434 /* It's not condemned. Everything's fine. */
9436 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
9437 window
->vertical_scroll_bar
))
9438 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
9440 /* If its prev pointer is nil, it must be at the front of
9441 one or the other! */
9445 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
9447 if (! NILP (bar
->next
))
9448 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
9450 bar
->next
= FRAME_SCROLL_BARS (f
);
9452 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
9453 if (! NILP (bar
->next
))
9454 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
9457 /* Remove all scroll bars on FRAME that haven't been saved since the
9458 last call to `*condemn_scroll_bars_hook'. */
9461 XTjudge_scroll_bars (f
)
9464 Lisp_Object bar
, next
;
9466 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
9468 /* Clear out the condemned list now so we won't try to process any
9469 more events on the hapless scroll bars. */
9470 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
9472 for (; ! NILP (bar
); bar
= next
)
9474 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
9476 x_scroll_bar_remove (b
);
9479 b
->next
= b
->prev
= Qnil
;
9482 /* Now there should be no references to the condemned scroll bars,
9483 and they should get garbage-collected. */
9487 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
9488 is a no-op when using toolkit scroll bars.
9490 This may be called from a signal handler, so we have to ignore GC
9494 x_scroll_bar_expose (bar
, event
)
9495 struct scroll_bar
*bar
;
9498 #ifndef USE_TOOLKIT_SCROLL_BARS
9500 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9501 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9502 GC gc
= f
->output_data
.x
->normal_gc
;
9503 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
9507 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
9509 /* Draw a one-pixel border just inside the edges of the scroll bar. */
9510 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
9512 /* x, y, width, height */
9514 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
9515 XINT (bar
->height
) - 1);
9519 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9522 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
9523 is set to something other than no_event, it is enqueued.
9525 This may be called from a signal handler, so we have to ignore GC
9528 #ifndef USE_TOOLKIT_SCROLL_BARS
9531 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
9532 struct scroll_bar
*bar
;
9534 struct input_event
*emacs_event
;
9536 if (! GC_WINDOWP (bar
->window
))
9539 emacs_event
->kind
= scroll_bar_click
;
9540 emacs_event
->code
= event
->xbutton
.button
- Button1
;
9541 emacs_event
->modifiers
9542 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
9543 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
9544 event
->xbutton
.state
)
9545 | (event
->type
== ButtonRelease
9548 emacs_event
->frame_or_window
= bar
->window
;
9549 emacs_event
->arg
= Qnil
;
9550 emacs_event
->timestamp
= event
->xbutton
.time
;
9553 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9555 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9558 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9559 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
9562 if (y
> top_range
) y
= top_range
;
9564 if (y
< XINT (bar
->start
))
9565 emacs_event
->part
= scroll_bar_above_handle
;
9566 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
9567 emacs_event
->part
= scroll_bar_handle
;
9569 emacs_event
->part
= scroll_bar_below_handle
;
9571 /* Just because the user has clicked on the handle doesn't mean
9572 they want to drag it. Lisp code needs to be able to decide
9573 whether or not we're dragging. */
9575 /* If the user has just clicked on the handle, record where they're
9577 if (event
->type
== ButtonPress
9578 && emacs_event
->part
== scroll_bar_handle
)
9579 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
9582 /* If the user has released the handle, set it to its final position. */
9583 if (event
->type
== ButtonRelease
9584 && ! NILP (bar
->dragging
))
9586 int new_start
= y
- XINT (bar
->dragging
);
9587 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
9589 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
9590 bar
->dragging
= Qnil
;
9593 /* Same deal here as the other #if 0. */
9595 /* Clicks on the handle are always reported as occurring at the top of
9597 if (emacs_event
->part
== scroll_bar_handle
)
9598 emacs_event
->x
= bar
->start
;
9600 XSETINT (emacs_event
->x
, y
);
9602 XSETINT (emacs_event
->x
, y
);
9605 XSETINT (emacs_event
->y
, top_range
);
9609 /* Handle some mouse motion while someone is dragging the scroll bar.
9611 This may be called from a signal handler, so we have to ignore GC
9615 x_scroll_bar_note_movement (bar
, event
)
9616 struct scroll_bar
*bar
;
9619 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
9621 last_mouse_movement_time
= event
->xmotion
.time
;
9624 XSETVECTOR (last_mouse_scroll_bar
, bar
);
9626 /* If we're dragging the bar, display it. */
9627 if (! GC_NILP (bar
->dragging
))
9629 /* Where should the handle be now? */
9630 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
9632 if (new_start
!= XINT (bar
->start
))
9634 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
9636 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
9641 #endif /* !USE_TOOLKIT_SCROLL_BARS */
9643 /* Return information to the user about the current position of the mouse
9644 on the scroll bar. */
9647 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
9649 Lisp_Object
*bar_window
;
9650 enum scroll_bar_part
*part
;
9652 unsigned long *time
;
9654 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
9655 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9656 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9658 Window dummy_window
;
9660 unsigned int dummy_mask
;
9664 /* Get the mouse's position relative to the scroll bar window, and
9666 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
9668 /* Root, child, root x and root y. */
9669 &dummy_window
, &dummy_window
,
9670 &dummy_coord
, &dummy_coord
,
9672 /* Position relative to scroll bar. */
9675 /* Mouse buttons and modifier keys. */
9682 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9685 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9687 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
9689 if (! NILP (bar
->dragging
))
9690 win_y
-= XINT (bar
->dragging
);
9694 if (win_y
> top_range
)
9698 *bar_window
= bar
->window
;
9700 if (! NILP (bar
->dragging
))
9701 *part
= scroll_bar_handle
;
9702 else if (win_y
< XINT (bar
->start
))
9703 *part
= scroll_bar_above_handle
;
9704 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
9705 *part
= scroll_bar_handle
;
9707 *part
= scroll_bar_below_handle
;
9709 XSETINT (*x
, win_y
);
9710 XSETINT (*y
, top_range
);
9713 last_mouse_scroll_bar
= Qnil
;
9716 *time
= last_mouse_movement_time
;
9722 /* The screen has been cleared so we may have changed foreground or
9723 background colors, and the scroll bars may need to be redrawn.
9724 Clear out the scroll bars, and ask for expose events, so we can
9728 x_scroll_bar_clear (f
)
9731 #ifndef USE_TOOLKIT_SCROLL_BARS
9734 /* We can have scroll bars even if this is 0,
9735 if we just turned off scroll bar mode.
9736 But in that case we should not clear them. */
9737 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9738 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
9739 bar
= XSCROLL_BAR (bar
)->next
)
9740 XClearArea (FRAME_X_DISPLAY (f
),
9741 SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
9743 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9746 /* This processes Expose events from the menu-bar specific X event
9747 loop in xmenu.c. This allows to redisplay the frame if necessary
9748 when handling menu-bar or pop-up items. */
9751 process_expose_from_menu (event
)
9755 struct x_display_info
*dpyinfo
;
9756 int frame_exposed_p
= 0;
9760 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
9761 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
9764 if (f
->async_visible
== 0)
9766 f
->async_visible
= 1;
9767 f
->async_iconified
= 0;
9768 f
->output_data
.x
->has_been_visible
= 1;
9769 SET_FRAME_GARBAGED (f
);
9773 expose_frame (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
9774 event
.xexpose
.x
, event
.xexpose
.y
,
9775 event
.xexpose
.width
, event
.xexpose
.height
);
9776 frame_exposed_p
= 1;
9781 struct scroll_bar
*bar
9782 = x_window_to_scroll_bar (event
.xexpose
.window
);
9785 x_scroll_bar_expose (bar
, &event
);
9789 return frame_exposed_p
;
9792 /* Define a queue to save up SelectionRequest events for later handling. */
9794 struct selection_event_queue
9797 struct selection_event_queue
*next
;
9800 static struct selection_event_queue
*queue
;
9802 /* Nonzero means queue up certain events--don't process them yet. */
9804 static int x_queue_selection_requests
;
9806 /* Queue up an X event *EVENT, to be processed later. */
9809 x_queue_event (f
, event
)
9813 struct selection_event_queue
*queue_tmp
9814 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
9816 if (queue_tmp
!= NULL
)
9818 queue_tmp
->event
= *event
;
9819 queue_tmp
->next
= queue
;
9824 /* Take all the queued events and put them back
9825 so that they get processed afresh. */
9828 x_unqueue_events (display
)
9831 while (queue
!= NULL
)
9833 struct selection_event_queue
*queue_tmp
= queue
;
9834 XPutBackEvent (display
, &queue_tmp
->event
);
9835 queue
= queue_tmp
->next
;
9836 xfree ((char *)queue_tmp
);
9840 /* Start queuing SelectionRequest events. */
9843 x_start_queuing_selection_requests (display
)
9846 x_queue_selection_requests
++;
9849 /* Stop queuing SelectionRequest events. */
9852 x_stop_queuing_selection_requests (display
)
9855 x_queue_selection_requests
--;
9856 x_unqueue_events (display
);
9859 /* The main X event-reading loop - XTread_socket. */
9862 /* Time stamp of enter window event. This is only used by XTread_socket,
9863 but we have to put it out here, since static variables within functions
9864 sometimes don't work. */
9866 static Time enter_timestamp
;
9869 /* This holds the state XLookupString needs to implement dead keys
9870 and other tricks known as "compose processing". _X Window System_
9871 says that a portable program can't use this, but Stephen Gildea assures
9872 me that letting the compiler initialize it to zeros will work okay.
9874 This must be defined outside of XTread_socket, for the same reasons
9875 given for enter_timestamp, above. */
9877 static XComposeStatus compose_status
;
9879 /* Record the last 100 characters stored
9880 to help debug the loss-of-chars-during-GC problem. */
9882 static int temp_index
;
9883 static short temp_buffer
[100];
9885 /* Set this to nonzero to fake an "X I/O error"
9886 on a particular display. */
9888 struct x_display_info
*XTread_socket_fake_io_error
;
9890 /* When we find no input here, we occasionally do a no-op command
9891 to verify that the X server is still running and we can still talk with it.
9892 We try all the open displays, one by one.
9893 This variable is used for cycling thru the displays. */
9895 static struct x_display_info
*next_noop_dpyinfo
;
9897 #define SET_SAVED_MENU_EVENT(size) \
9900 if (f->output_data.x->saved_menu_event == 0) \
9901 f->output_data.x->saved_menu_event \
9902 = (XEvent *) xmalloc (sizeof (XEvent)); \
9903 bcopy (&event, f->output_data.x->saved_menu_event, size); \
9904 if (numchars >= 1) \
9906 bufp->kind = menu_bar_activate_event; \
9907 XSETFRAME (bufp->frame_or_window, f); \
9916 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
9917 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
9919 /* Read events coming from the X server.
9920 This routine is called by the SIGIO handler.
9921 We return as soon as there are no more events to be read.
9923 Events representing keys are stored in buffer BUFP,
9924 which can hold up to NUMCHARS characters.
9925 We return the number of characters stored into the buffer,
9926 thus pretending to be `read'.
9928 EXPECTED is nonzero if the caller knows input is available. */
9931 XTread_socket (sd
, bufp
, numchars
, expected
)
9933 /* register */ struct input_event
*bufp
;
9934 /* register */ int numchars
;
9941 int event_found
= 0;
9942 struct x_display_info
*dpyinfo
;
9943 struct coding_system coding
;
9945 if (interrupt_input_blocked
)
9947 interrupt_input_pending
= 1;
9951 interrupt_input_pending
= 0;
9954 /* So people can tell when we have read the available input. */
9955 input_signal_count
++;
9958 abort (); /* Don't think this happens. */
9962 /* The input should be decoded if it is from XIM. Currently the
9963 locale of XIM is the same as that of the system. So, we can use
9964 Vlocale_coding_system which is initialized properly at Emacs
9966 setup_coding_system (Vlocale_coding_system
, &coding
);
9967 coding
.src_multibyte
= 0;
9968 coding
.dst_multibyte
= 1;
9969 /* The input is converted to events, thus we can't handle
9970 composition. Anyway, there's no XIM that gives us composition
9972 coding
.composing
= COMPOSITION_DISABLED
;
9974 /* Find the display we are supposed to read input for.
9975 It's the one communicating on descriptor SD. */
9976 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
9978 #if 0 /* This ought to be unnecessary; let's verify it. */
9980 /* If available, Xlib uses FIOSNBIO to make the socket
9981 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
9982 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
9983 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
9984 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
9985 #endif /* ! defined (FIOSNBIO) */
9988 #if 0 /* This code can't be made to work, with multiple displays,
9989 and appears not to be used on any system any more.
9990 Also keyboard.c doesn't turn O_NDELAY on and off
9991 for X connections. */
9994 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
9996 extern int read_alarm_should_throw
;
9997 read_alarm_should_throw
= 1;
9998 XPeekEvent (dpyinfo
->display
, &event
);
9999 read_alarm_should_throw
= 0;
10001 #endif /* HAVE_SELECT */
10005 /* For debugging, this gives a way to fake an I/O error. */
10006 if (dpyinfo
== XTread_socket_fake_io_error
)
10008 XTread_socket_fake_io_error
= 0;
10009 x_io_error_quitter (dpyinfo
->display
);
10014 count
+= x_session_check_input (bufp
, &numchars
);
10018 while (XPending (dpyinfo
->display
))
10020 XNextEvent (dpyinfo
->display
, &event
);
10024 /* Filter events for the current X input method.
10025 XFilterEvent returns non-zero if the input method has
10026 consumed the event. We pass the frame's X window to
10027 XFilterEvent because that's the one for which the IC
10029 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
10030 event
.xclient
.window
);
10031 if (XFilterEvent (&event
, f1
? FRAME_X_WINDOW (f1
) : None
))
10037 switch (event
.type
)
10039 case ClientMessage
:
10041 if (event
.xclient
.message_type
10042 == dpyinfo
->Xatom_wm_protocols
10043 && event
.xclient
.format
== 32)
10045 if (event
.xclient
.data
.l
[0]
10046 == dpyinfo
->Xatom_wm_take_focus
)
10048 /* Use x_any_window_to_frame because this
10049 could be the shell widget window
10050 if the frame has no title bar. */
10051 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
10053 /* Not quite sure this is needed -pd */
10054 if (f
&& FRAME_XIC (f
))
10055 XSetICFocus (FRAME_XIC (f
));
10057 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
10058 instructs the WM to set the input focus automatically for
10059 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
10060 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
10061 it has set the focus. So, XSetInputFocus below is not
10064 The call to XSetInputFocus below has also caused trouble. In
10065 cases where the XSetInputFocus done by the WM and the one
10066 below are temporally close (on a fast machine), the call
10067 below can generate additional FocusIn events which confuse
10070 /* Since we set WM_TAKE_FOCUS, we must call
10071 XSetInputFocus explicitly. But not if f is null,
10072 since that might be an event for a deleted frame. */
10075 Display
*d
= event
.xclient
.display
;
10076 /* Catch and ignore errors, in case window has been
10077 iconified by a window manager such as GWM. */
10078 int count
= x_catch_errors (d
);
10079 XSetInputFocus (d
, event
.xclient
.window
,
10080 /* The ICCCM says this is
10081 the only valid choice. */
10083 event
.xclient
.data
.l
[1]);
10084 /* This is needed to detect the error
10085 if there is an error. */
10087 x_uncatch_errors (d
, count
);
10089 /* Not certain about handling scroll bars here */
10092 else if (event
.xclient
.data
.l
[0]
10093 == dpyinfo
->Xatom_wm_save_yourself
)
10095 /* Save state modify the WM_COMMAND property to
10096 something which can reinstate us. This notifies
10097 the session manager, who's looking for such a
10098 PropertyNotify. Can restart processing when
10099 a keyboard or mouse event arrives. */
10100 /* If we have a session manager, don't set this.
10101 KDE will then start two Emacsen, one for the
10102 session manager and one for this. */
10105 && ! x_session_have_connection ()
10109 f
= x_top_window_to_frame (dpyinfo
,
10110 event
.xclient
.window
);
10111 /* This is just so we only give real data once
10112 for a single Emacs process. */
10113 if (f
== SELECTED_FRAME ())
10114 XSetCommand (FRAME_X_DISPLAY (f
),
10115 event
.xclient
.window
,
10116 initial_argv
, initial_argc
);
10118 XSetCommand (FRAME_X_DISPLAY (f
),
10119 event
.xclient
.window
,
10123 else if (event
.xclient
.data
.l
[0]
10124 == dpyinfo
->Xatom_wm_delete_window
)
10127 = x_any_window_to_frame (dpyinfo
,
10128 event
.xclient
.window
);
10135 bufp
->kind
= delete_window_event
;
10136 XSETFRAME (bufp
->frame_or_window
, f
);
10145 else if (event
.xclient
.message_type
10146 == dpyinfo
->Xatom_wm_configure_denied
)
10149 else if (event
.xclient
.message_type
10150 == dpyinfo
->Xatom_wm_window_moved
)
10154 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
10156 new_x
= event
.xclient
.data
.s
[0];
10157 new_y
= event
.xclient
.data
.s
[1];
10161 f
->output_data
.x
->left_pos
= new_x
;
10162 f
->output_data
.x
->top_pos
= new_y
;
10165 #ifdef HACK_EDITRES
10166 else if (event
.xclient
.message_type
10167 == dpyinfo
->Xatom_editres
)
10170 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
10171 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
10174 #endif /* HACK_EDITRES */
10175 else if ((event
.xclient
.message_type
10176 == dpyinfo
->Xatom_DONE
)
10177 || (event
.xclient
.message_type
10178 == dpyinfo
->Xatom_PAGE
))
10180 /* Ghostview job completed. Kill it. We could
10181 reply with "Next" if we received "Page", but we
10182 currently never do because we are interested in
10183 images, only, which should have 1 page. */
10184 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
10186 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
10187 x_kill_gs_process (pixmap
, f
);
10188 expose_frame (f
, 0, 0, 0, 0);
10190 #ifdef USE_TOOLKIT_SCROLL_BARS
10191 /* Scroll bar callbacks send a ClientMessage from which
10192 we construct an input_event. */
10193 else if (event
.xclient
.message_type
10194 == dpyinfo
->Xatom_Scrollbar
)
10196 x_scroll_bar_to_input_event (&event
, bufp
);
10197 ++bufp
, ++count
, --numchars
;
10200 #endif /* USE_TOOLKIT_SCROLL_BARS */
10206 case SelectionNotify
:
10207 #ifdef USE_X_TOOLKIT
10208 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
10210 #endif /* not USE_X_TOOLKIT */
10211 x_handle_selection_notify (&event
.xselection
);
10214 case SelectionClear
: /* Someone has grabbed ownership. */
10215 #ifdef USE_X_TOOLKIT
10216 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
10218 #endif /* USE_X_TOOLKIT */
10220 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
10225 bufp
->kind
= selection_clear_event
;
10226 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
10227 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
10228 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
10229 bufp
->frame_or_window
= Qnil
;
10238 case SelectionRequest
: /* Someone wants our selection. */
10239 #ifdef USE_X_TOOLKIT
10240 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
10242 #endif /* USE_X_TOOLKIT */
10243 if (x_queue_selection_requests
)
10244 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
10248 XSelectionRequestEvent
*eventp
10249 = (XSelectionRequestEvent
*) &event
;
10254 bufp
->kind
= selection_request_event
;
10255 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
10256 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
10257 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
10258 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
10259 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
10260 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
10261 bufp
->frame_or_window
= Qnil
;
10270 case PropertyNotify
:
10271 #if 0 /* This is plain wrong. In the case that we are waiting for a
10272 PropertyNotify used as an ACK in incremental selection
10273 transfer, the property will be on the receiver's window. */
10274 #if defined USE_X_TOOLKIT
10275 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
10279 x_handle_property_notify (&event
.xproperty
);
10282 case ReparentNotify
:
10283 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
10287 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
10288 x_real_positions (f
, &x
, &y
);
10289 f
->output_data
.x
->left_pos
= x
;
10290 f
->output_data
.x
->top_pos
= y
;
10295 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
10298 x_check_fullscreen (f
);
10300 if (f
->async_visible
== 0)
10302 f
->async_visible
= 1;
10303 f
->async_iconified
= 0;
10304 f
->output_data
.x
->has_been_visible
= 1;
10305 SET_FRAME_GARBAGED (f
);
10308 expose_frame (x_window_to_frame (dpyinfo
,
10309 event
.xexpose
.window
),
10310 event
.xexpose
.x
, event
.xexpose
.y
,
10311 event
.xexpose
.width
, event
.xexpose
.height
);
10315 #ifndef USE_TOOLKIT_SCROLL_BARS
10316 struct scroll_bar
*bar
;
10318 #if defined USE_LUCID
10319 /* Submenus of the Lucid menu bar aren't widgets
10320 themselves, so there's no way to dispatch events
10321 to them. Recognize this case separately. */
10324 = x_window_to_menu_bar (event
.xexpose
.window
);
10326 xlwmenu_redisplay (widget
);
10328 #endif /* USE_LUCID */
10330 #ifdef USE_TOOLKIT_SCROLL_BARS
10331 /* Dispatch event to the widget. */
10333 #else /* not USE_TOOLKIT_SCROLL_BARS */
10334 bar
= x_window_to_scroll_bar (event
.xexpose
.window
);
10337 x_scroll_bar_expose (bar
, &event
);
10338 #ifdef USE_X_TOOLKIT
10341 #endif /* USE_X_TOOLKIT */
10342 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10346 case GraphicsExpose
: /* This occurs when an XCopyArea's
10347 source area was obscured or not
10349 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
10353 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
10354 event
.xgraphicsexpose
.width
,
10355 event
.xgraphicsexpose
.height
);
10357 #ifdef USE_X_TOOLKIT
10360 #endif /* USE_X_TOOLKIT */
10363 case NoExpose
: /* This occurs when an XCopyArea's
10364 source area was completely
10369 /* Redo the mouse-highlight after the tooltip has gone. */
10370 if (event
.xmap
.window
== tip_window
)
10373 redo_mouse_highlight ();
10376 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
10377 if (f
) /* F may no longer exist if
10378 the frame was deleted. */
10380 /* While a frame is unmapped, display generation is
10381 disabled; you don't want to spend time updating a
10382 display that won't ever be seen. */
10383 f
->async_visible
= 0;
10384 /* We can't distinguish, from the event, whether the window
10385 has become iconified or invisible. So assume, if it
10386 was previously visible, than now it is iconified.
10387 But x_make_frame_invisible clears both
10388 the visible flag and the iconified flag;
10389 and that way, we know the window is not iconified now. */
10390 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
10392 f
->async_iconified
= 1;
10394 bufp
->kind
= iconify_event
;
10395 XSETFRAME (bufp
->frame_or_window
, f
);
10405 if (event
.xmap
.window
== tip_window
)
10406 /* The tooltip has been drawn already. Avoid
10407 the SET_FRAME_GARBAGED below. */
10410 /* We use x_top_window_to_frame because map events can
10411 come for sub-windows and they don't mean that the
10412 frame is visible. */
10413 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
10416 f
->async_visible
= 1;
10417 f
->async_iconified
= 0;
10418 f
->output_data
.x
->has_been_visible
= 1;
10420 /* wait_reading_process_input will notice this and update
10421 the frame's display structures. */
10422 SET_FRAME_GARBAGED (f
);
10426 bufp
->kind
= deiconify_event
;
10427 XSETFRAME (bufp
->frame_or_window
, f
);
10433 else if (! NILP (Vframe_list
)
10434 && ! NILP (XCDR (Vframe_list
)))
10435 /* Force a redisplay sooner or later
10436 to update the frame titles
10437 in case this is the second frame. */
10438 record_asynch_buffer_change ();
10443 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
10445 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
))
10447 dpyinfo
->mouse_face_hidden
= 1;
10448 clear_mouse_face (dpyinfo
);
10451 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
10454 /* Scroll bars consume key events, but we want
10455 the keys to go to the scroll bar's frame. */
10456 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
10457 event
.xkey
.window
);
10458 if (widget
&& XmIsScrollBar (widget
))
10460 widget
= XtParent (widget
);
10461 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
10464 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
10468 KeySym keysym
, orig_keysym
;
10469 /* al%imercury@uunet.uu.net says that making this 81
10470 instead of 80 fixed a bug whereby meta chars made
10473 It seems that some version of XmbLookupString has
10474 a bug of not returning XBufferOverflow in
10475 status_return even if the input is too long to
10476 fit in 81 bytes. So, we must prepare sufficient
10477 bytes for copy_buffer. 513 bytes (256 chars for
10478 two-byte character set) seems to be a fairly good
10479 approximation. -- 2000.8.10 handa@etl.go.jp */
10480 unsigned char copy_buffer
[513];
10481 unsigned char *copy_bufptr
= copy_buffer
;
10482 int copy_bufsiz
= sizeof (copy_buffer
);
10486 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
10487 extra_keyboard_modifiers
);
10488 modifiers
= event
.xkey
.state
;
10490 /* This will have to go some day... */
10492 /* make_lispy_event turns chars into control chars.
10493 Don't do it here because XLookupString is too eager. */
10494 event
.xkey
.state
&= ~ControlMask
;
10495 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
10496 | dpyinfo
->super_mod_mask
10497 | dpyinfo
->hyper_mod_mask
10498 | dpyinfo
->alt_mod_mask
);
10500 /* In case Meta is ComposeCharacter,
10501 clear its status. According to Markus Ehrnsperger
10502 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
10503 this enables ComposeCharacter to work whether or
10504 not it is combined with Meta. */
10505 if (modifiers
& dpyinfo
->meta_mod_mask
)
10506 bzero (&compose_status
, sizeof (compose_status
));
10511 Status status_return
;
10513 nbytes
= XmbLookupString (FRAME_XIC (f
),
10514 &event
.xkey
, copy_bufptr
,
10515 copy_bufsiz
, &keysym
,
10517 if (status_return
== XBufferOverflow
)
10519 copy_bufsiz
= nbytes
+ 1;
10520 copy_bufptr
= (char *) alloca (copy_bufsiz
);
10521 nbytes
= XmbLookupString (FRAME_XIC (f
),
10522 &event
.xkey
, copy_bufptr
,
10523 copy_bufsiz
, &keysym
,
10527 if (status_return
== XLookupNone
)
10529 else if (status_return
== XLookupChars
)
10534 else if (status_return
!= XLookupKeySym
10535 && status_return
!= XLookupBoth
)
10539 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
10540 copy_bufsiz
, &keysym
,
10543 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
10544 copy_bufsiz
, &keysym
,
10548 orig_keysym
= keysym
;
10552 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
10553 || keysym
== XK_Delete
10554 #ifdef XK_ISO_Left_Tab
10555 || (keysym
>= XK_ISO_Left_Tab
&& keysym
<= XK_ISO_Enter
)
10557 || (keysym
>= XK_Kanji
&& keysym
<= XK_Eisu_toggle
)
10558 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
10559 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
10561 /* This recognizes the "extended function keys".
10562 It seems there's no cleaner way.
10563 Test IsModifierKey to avoid handling mode_switch
10565 || ((unsigned) (keysym
) >= XK_Select
10566 && (unsigned)(keysym
) < XK_KP_Space
)
10568 #ifdef XK_dead_circumflex
10569 || orig_keysym
== XK_dead_circumflex
10571 #ifdef XK_dead_grave
10572 || orig_keysym
== XK_dead_grave
10574 #ifdef XK_dead_tilde
10575 || orig_keysym
== XK_dead_tilde
10577 #ifdef XK_dead_diaeresis
10578 || orig_keysym
== XK_dead_diaeresis
10580 #ifdef XK_dead_macron
10581 || orig_keysym
== XK_dead_macron
10583 #ifdef XK_dead_degree
10584 || orig_keysym
== XK_dead_degree
10586 #ifdef XK_dead_acute
10587 || orig_keysym
== XK_dead_acute
10589 #ifdef XK_dead_cedilla
10590 || orig_keysym
== XK_dead_cedilla
10592 #ifdef XK_dead_breve
10593 || orig_keysym
== XK_dead_breve
10595 #ifdef XK_dead_ogonek
10596 || orig_keysym
== XK_dead_ogonek
10598 #ifdef XK_dead_caron
10599 || orig_keysym
== XK_dead_caron
10601 #ifdef XK_dead_doubleacute
10602 || orig_keysym
== XK_dead_doubleacute
10604 #ifdef XK_dead_abovedot
10605 || orig_keysym
== XK_dead_abovedot
10607 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
10608 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
10609 /* Any "vendor-specific" key is ok. */
10610 || (orig_keysym
& (1 << 28))
10611 || (keysym
!= NoSymbol
&& nbytes
== 0))
10612 && ! (IsModifierKey (orig_keysym
)
10614 #ifdef XK_Mode_switch
10615 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
10618 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
10620 #endif /* not HAVE_X11R5 */
10621 /* The symbols from XK_ISO_Lock to
10622 XK_ISO_Last_Group_Lock doesn't have real
10623 modifiers but should be treated similarly
10624 to Mode_switch by Emacs. */
10625 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
10626 || ((unsigned)(orig_keysym
) >= XK_ISO_Lock
10627 && (unsigned)(orig_keysym
) <= XK_ISO_Last_Group_Lock
)
10631 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
10633 temp_buffer
[temp_index
++] = keysym
;
10634 bufp
->kind
= non_ascii_keystroke
;
10635 bufp
->code
= keysym
;
10636 XSETFRAME (bufp
->frame_or_window
, f
);
10639 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10641 bufp
->timestamp
= event
.xkey
.time
;
10646 else if (numchars
> nbytes
)
10652 for (i
= 0; i
< nbytes
; i
++)
10654 if (temp_index
== (sizeof temp_buffer
10657 temp_buffer
[temp_index
++] = copy_bufptr
[i
];
10660 if (/* If the event is not from XIM, */
10661 event
.xkey
.keycode
!= 0
10662 /* or the current locale doesn't request
10663 decoding of the intup data, ... */
10664 || coding
.type
== coding_type_raw_text
10665 || coding
.type
== coding_type_no_conversion
)
10667 /* ... we can use the input data as is. */
10672 /* We have to decode the input data. */
10676 require
= decoding_buffer_size (&coding
, nbytes
);
10677 p
= (unsigned char *) alloca (require
);
10678 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
10679 decode_coding (&coding
, copy_bufptr
, p
,
10681 nbytes
= coding
.produced
;
10682 nchars
= coding
.produced_char
;
10686 /* Convert the input data to a sequence of
10687 character events. */
10688 for (i
= 0; i
< nbytes
; i
+= len
)
10690 if (nchars
== nbytes
)
10691 c
= copy_bufptr
[i
], len
= 1;
10693 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
10696 bufp
->kind
= (SINGLE_BYTE_CHAR_P (c
)
10698 : multibyte_char_keystroke
);
10700 XSETFRAME (bufp
->frame_or_window
, f
);
10703 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10705 bufp
->timestamp
= event
.xkey
.time
;
10710 numchars
-= nchars
;
10712 if (keysym
== NoSymbol
)
10722 /* Don't dispatch this event since XtDispatchEvent calls
10723 XFilterEvent, and two calls in a row may freeze the
10732 /* Don't dispatch this event since XtDispatchEvent calls
10733 XFilterEvent, and two calls in a row may freeze the
10740 /* Here's a possible interpretation of the whole
10741 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If
10742 you get a FocusIn event, you have to get a FocusOut
10743 event before you relinquish the focus. If you
10744 haven't received a FocusIn event, then a mere
10745 LeaveNotify is enough to free you. */
10749 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10752 if (event
.xcrossing
.focus
)
10754 /* Avoid nasty pop/raise loops. */
10755 if (f
&& (!(f
->auto_raise
)
10756 || !(f
->auto_lower
)
10757 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
10759 x_new_focus_frame (dpyinfo
, f
);
10760 enter_timestamp
= event
.xcrossing
.time
;
10763 else if (f
== dpyinfo
->x_focus_frame
)
10764 x_new_focus_frame (dpyinfo
, 0);
10767 /* EnterNotify counts as mouse movement,
10768 so update things that depend on mouse position. */
10769 if (f
&& !f
->output_data
.x
->hourglass_p
)
10770 note_mouse_movement (f
, &event
.xmotion
);
10775 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
10776 if (event
.xfocus
.detail
!= NotifyPointer
)
10777 dpyinfo
->x_focus_event_frame
= f
;
10780 x_new_focus_frame (dpyinfo
, f
);
10782 /* Don't stop displaying the initial startup message
10783 for a switch-frame event we don't need. */
10784 if (GC_NILP (Vterminal_frame
)
10785 && GC_CONSP (Vframe_list
)
10786 && !GC_NILP (XCDR (Vframe_list
)))
10788 bufp
->kind
= FOCUS_IN_EVENT
;
10789 XSETFRAME (bufp
->frame_or_window
, f
);
10791 ++bufp
, ++count
, --numchars
;
10796 if (f
&& FRAME_XIC (f
))
10797 XSetICFocus (FRAME_XIC (f
));
10803 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10806 if (f
== dpyinfo
->mouse_face_mouse_frame
)
10808 /* If we move outside the frame, then we're
10809 certainly no longer on any text in the frame. */
10810 clear_mouse_face (dpyinfo
);
10811 dpyinfo
->mouse_face_mouse_frame
= 0;
10814 /* Generate a nil HELP_EVENT to cancel a help-echo.
10815 Do it only if there's something to cancel.
10816 Otherwise, the startup message is cleared when
10817 the mouse leaves the frame. */
10818 if (any_help_event_p
)
10823 XSETFRAME (frame
, f
);
10825 n
= gen_help_event (bufp
, numchars
,
10826 Qnil
, frame
, Qnil
, Qnil
, 0);
10827 bufp
+= n
, count
+= n
, numchars
-= n
;
10831 if (event
.xcrossing
.focus
)
10832 x_mouse_leave (dpyinfo
);
10835 if (f
== dpyinfo
->x_focus_event_frame
)
10836 dpyinfo
->x_focus_event_frame
= 0;
10837 if (f
== dpyinfo
->x_focus_frame
)
10838 x_new_focus_frame (dpyinfo
, 0);
10845 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
10846 if (event
.xfocus
.detail
!= NotifyPointer
10847 && f
== dpyinfo
->x_focus_event_frame
)
10848 dpyinfo
->x_focus_event_frame
= 0;
10849 if (f
&& f
== dpyinfo
->x_focus_frame
)
10850 x_new_focus_frame (dpyinfo
, 0);
10853 if (f
&& FRAME_XIC (f
))
10854 XUnsetICFocus (FRAME_XIC (f
));
10861 previous_help_echo
= help_echo
;
10862 help_echo
= help_echo_object
= help_echo_window
= Qnil
;
10863 help_echo_pos
= -1;
10865 if (dpyinfo
->grabbed
&& last_mouse_frame
10866 && FRAME_LIVE_P (last_mouse_frame
))
10867 f
= last_mouse_frame
;
10869 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
10871 if (dpyinfo
->mouse_face_hidden
)
10873 dpyinfo
->mouse_face_hidden
= 0;
10874 clear_mouse_face (dpyinfo
);
10880 /* Generate SELECT_WINDOW_EVENTs when needed. */
10881 if (autoselect_window_p
)
10883 Lisp_Object window
;
10886 window
= window_from_coordinates (f
,
10887 XINT (event
.xmotion
.x
), XINT (event
.xmotion
.y
),
10890 /* Window will be selected only when it is not selected now and
10891 last mouse movement event was not in it. Minibuffer window
10892 will be selected iff it is active. */
10893 if (!EQ (window
, last_window
)
10894 && !EQ (window
, selected_window
)
10897 bufp
->kind
= SELECT_WINDOW_EVENT
;
10898 bufp
->frame_or_window
= window
;
10900 ++bufp
, ++count
, --numchars
;
10903 last_window
=window
;
10905 note_mouse_movement (f
, &event
.xmotion
);
10909 #ifndef USE_TOOLKIT_SCROLL_BARS
10910 struct scroll_bar
*bar
10911 = x_window_to_scroll_bar (event
.xmotion
.window
);
10914 x_scroll_bar_note_movement (bar
, &event
);
10915 #endif /* USE_TOOLKIT_SCROLL_BARS */
10917 /* If we move outside the frame, then we're
10918 certainly no longer on any text in the frame. */
10919 clear_mouse_face (dpyinfo
);
10922 /* If the contents of the global variable help_echo
10923 has changed, generate a HELP_EVENT. */
10924 if (!NILP (help_echo
)
10925 || !NILP (previous_help_echo
))
10931 XSETFRAME (frame
, f
);
10935 any_help_event_p
= 1;
10936 n
= gen_help_event (bufp
, numchars
, help_echo
, frame
,
10937 help_echo_window
, help_echo_object
,
10939 bufp
+= n
, count
+= n
, numchars
-= n
;
10945 case ConfigureNotify
:
10946 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
10949 #ifndef USE_X_TOOLKIT
10950 /* If there is a pending resize for fullscreen, don't
10951 do this one, the right one will come later.
10952 The toolkit version doesn't seem to need this, but we
10953 need to reset it below. */
10955 ((f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WAIT
)
10956 && FRAME_NEW_WIDTH (f
) != 0);
10957 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
10958 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
10962 /* In the toolkit version, change_frame_size
10963 is called by the code that handles resizing
10964 of the EmacsFrame widget. */
10966 /* Even if the number of character rows and columns has
10967 not changed, the font size may have changed, so we need
10968 to check the pixel dimensions as well. */
10969 if (columns
!= f
->width
10970 || rows
!= f
->height
10971 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
10972 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
10974 change_frame_size (f
, rows
, columns
, 0, 1, 0);
10975 SET_FRAME_GARBAGED (f
);
10976 cancel_mouse_face (f
);
10980 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
10981 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
10983 /* What we have now is the position of Emacs's own window.
10984 Convert that to the position of the window manager window. */
10985 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
10986 &f
->output_data
.x
->top_pos
);
10988 x_check_fullscreen_move(f
);
10989 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WAIT
)
10990 f
->output_data
.x
->want_fullscreen
&=
10991 ~(FULLSCREEN_WAIT
|FULLSCREEN_BOTH
);
10993 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
10994 xic_set_statusarea (f
);
10997 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
10999 /* Since the WM decorations come below top_pos now,
11000 we must put them below top_pos in the future. */
11001 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
11002 x_wm_set_size_hint (f
, (long) 0, 0);
11005 /* Some window managers pass (0,0) as the location of
11006 the window, and the Motif event handler stores it
11007 in the emacs widget, which messes up Motif menus. */
11008 if (event
.xconfigure
.x
== 0 && event
.xconfigure
.y
== 0)
11010 event
.xconfigure
.x
= f
->output_data
.x
->widget
->core
.x
;
11011 event
.xconfigure
.y
= f
->output_data
.x
->widget
->core
.y
;
11013 #endif /* USE_MOTIF */
11018 case ButtonRelease
:
11020 /* If we decide we want to generate an event to be seen
11021 by the rest of Emacs, we put it here. */
11022 struct input_event emacs_event
;
11023 int tool_bar_p
= 0;
11025 emacs_event
.kind
= no_event
;
11026 bzero (&compose_status
, sizeof (compose_status
));
11028 if (dpyinfo
->grabbed
11029 && last_mouse_frame
11030 && FRAME_LIVE_P (last_mouse_frame
))
11031 f
= last_mouse_frame
;
11033 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
11037 /* Is this in the tool-bar? */
11038 if (WINDOWP (f
->tool_bar_window
)
11039 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
11041 Lisp_Object window
;
11044 x
= event
.xbutton
.x
;
11045 y
= event
.xbutton
.y
;
11048 window
= window_from_coordinates (f
, x
, y
, &p
, 1);
11049 if (EQ (window
, f
->tool_bar_window
))
11051 x_handle_tool_bar_click (f
, &event
.xbutton
);
11057 if (!dpyinfo
->x_focus_frame
11058 || f
== dpyinfo
->x_focus_frame
)
11059 construct_mouse_click (&emacs_event
, &event
, f
);
11063 #ifndef USE_TOOLKIT_SCROLL_BARS
11064 struct scroll_bar
*bar
11065 = x_window_to_scroll_bar (event
.xbutton
.window
);
11068 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
11069 #endif /* not USE_TOOLKIT_SCROLL_BARS */
11072 if (event
.type
== ButtonPress
)
11074 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
11075 last_mouse_frame
= f
;
11076 /* Ignore any mouse motion that happened
11077 before this event; any subsequent mouse-movement
11078 Emacs events should reflect only motion after
11079 the ButtonPress. */
11081 f
->mouse_moved
= 0;
11084 last_tool_bar_item
= -1;
11088 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
11091 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
11093 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
11099 #ifdef USE_X_TOOLKIT
11100 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
11101 /* For a down-event in the menu bar,
11102 don't pass it to Xt right now.
11103 Instead, save it away
11104 and we will pass it to Xt from kbd_buffer_get_event.
11105 That way, we can run some Lisp code first. */
11106 if (f
&& event
.type
== ButtonPress
11107 /* Verify the event is really within the menu bar
11108 and not just sent to it due to grabbing. */
11109 && event
.xbutton
.x
>= 0
11110 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
11111 && event
.xbutton
.y
>= 0
11112 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
11113 && event
.xbutton
.same_screen
)
11115 SET_SAVED_BUTTON_EVENT
;
11116 XSETFRAME (last_mouse_press_frame
, f
);
11118 else if (event
.type
== ButtonPress
)
11120 last_mouse_press_frame
= Qnil
;
11124 #ifdef USE_MOTIF /* This should do not harm for Lucid,
11125 but I am trying to be cautious. */
11126 else if (event
.type
== ButtonRelease
)
11128 if (!NILP (last_mouse_press_frame
))
11130 f
= XFRAME (last_mouse_press_frame
);
11131 if (f
->output_data
.x
)
11132 SET_SAVED_BUTTON_EVENT
;
11137 #endif /* USE_MOTIF */
11140 #endif /* USE_X_TOOLKIT */
11144 case CirculateNotify
:
11147 case CirculateRequest
:
11150 case VisibilityNotify
:
11153 case MappingNotify
:
11154 /* Someone has changed the keyboard mapping - update the
11156 switch (event
.xmapping
.request
)
11158 case MappingModifier
:
11159 x_find_modifier_meanings (dpyinfo
);
11160 /* This is meant to fall through. */
11161 case MappingKeyboard
:
11162 XRefreshKeyboardMapping (&event
.xmapping
);
11168 #ifdef USE_X_TOOLKIT
11170 XtDispatchEvent (&event
);
11172 #endif /* USE_X_TOOLKIT */
11180 /* On some systems, an X bug causes Emacs to get no more events
11181 when the window is destroyed. Detect that. (1994.) */
11184 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
11185 One XNOOP in 100 loops will make Emacs terminate.
11186 B. Bretthauer, 1994 */
11188 if (x_noop_count
>= 100)
11192 if (next_noop_dpyinfo
== 0)
11193 next_noop_dpyinfo
= x_display_list
;
11195 XNoOp (next_noop_dpyinfo
->display
);
11197 /* Each time we get here, cycle through the displays now open. */
11198 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
11202 /* If the focus was just given to an auto-raising frame,
11204 /* ??? This ought to be able to handle more than one such frame. */
11205 if (pending_autoraise_frame
)
11207 x_raise_frame (pending_autoraise_frame
);
11208 pending_autoraise_frame
= 0;
11219 /***********************************************************************
11221 ***********************************************************************/
11223 /* Notice when the text cursor of window W has been completely
11224 overwritten by a drawing operation that outputs glyphs in AREA
11225 starting at X0 and ending at X1 in the line starting at Y0 and
11226 ending at Y1. X coordinates are area-relative. X1 < 0 means all
11227 the rest of the line after X0 has been written. Y coordinates
11228 are window-relative. */
11231 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
11233 enum glyph_row_area area
;
11234 int x0
, y0
, x1
, y1
;
11236 if (area
== TEXT_AREA
11237 && w
->phys_cursor_on_p
11238 && y0
<= w
->phys_cursor
.y
11239 && y1
>= w
->phys_cursor
.y
+ w
->phys_cursor_height
11240 && x0
<= w
->phys_cursor
.x
11241 && (x1
< 0 || x1
> w
->phys_cursor
.x
))
11242 w
->phys_cursor_on_p
= 0;
11246 /* Set clipping for output in glyph row ROW. W is the window in which
11247 we operate. GC is the graphics context to set clipping in.
11248 WHOLE_LINE_P non-zero means include the areas used for truncation
11249 mark display and alike in the clipping rectangle.
11251 ROW may be a text row or, e.g., a mode line. Text rows must be
11252 clipped to the interior of the window dedicated to text display,
11253 mode lines must be clipped to the whole window. */
11256 x_clip_to_row (w
, row
, gc
, whole_line_p
)
11258 struct glyph_row
*row
;
11262 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11263 XRectangle clip_rect
;
11264 int window_x
, window_y
, window_width
, window_height
;
11266 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
11268 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
11269 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
11270 clip_rect
.y
= max (clip_rect
.y
, window_y
);
11271 clip_rect
.width
= window_width
;
11272 clip_rect
.height
= row
->visible_height
;
11274 /* If clipping to the whole line, including trunc marks, extend
11275 the rectangle to the left and increase its width. */
11278 clip_rect
.x
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
11279 clip_rect
.width
+= FRAME_X_FRINGE_WIDTH (f
);
11282 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
11286 /* Draw a hollow box cursor on window W in glyph row ROW. */
11289 x_draw_hollow_cursor (w
, row
)
11291 struct glyph_row
*row
;
11293 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11294 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11295 Display
*dpy
= FRAME_X_DISPLAY (f
);
11298 struct glyph
*cursor_glyph
;
11301 /* Compute frame-relative coordinates from window-relative
11303 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
11304 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
11305 + row
->ascent
- w
->phys_cursor_ascent
);
11306 h
= row
->height
- 1;
11308 /* Get the glyph the cursor is on. If we can't tell because
11309 the current matrix is invalid or such, give up. */
11310 cursor_glyph
= get_phys_cursor_glyph (w
);
11311 if (cursor_glyph
== NULL
)
11314 /* Compute the width of the rectangle to draw. If on a stretch
11315 glyph, and `x-stretch-block-cursor' is nil, don't draw a
11316 rectangle as wide as the glyph, but use a canonical character
11318 wd
= cursor_glyph
->pixel_width
- 1;
11319 if (cursor_glyph
->type
== STRETCH_GLYPH
11320 && !x_stretch_cursor_p
)
11321 wd
= min (CANON_X_UNIT (f
), wd
);
11323 /* The foreground of cursor_gc is typically the same as the normal
11324 background color, which can cause the cursor box to be invisible. */
11325 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
11326 if (dpyinfo
->scratch_cursor_gc
)
11327 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
11329 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
11330 GCForeground
, &xgcv
);
11331 gc
= dpyinfo
->scratch_cursor_gc
;
11333 /* Set clipping, draw the rectangle, and reset clipping again. */
11334 x_clip_to_row (w
, row
, gc
, 0);
11335 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
11336 XSetClipMask (dpy
, gc
, None
);
11340 /* Draw a bar cursor on window W in glyph row ROW.
11342 Implementation note: One would like to draw a bar cursor with an
11343 angle equal to the one given by the font property XA_ITALIC_ANGLE.
11344 Unfortunately, I didn't find a font yet that has this property set.
11348 x_draw_bar_cursor (w
, row
, width
)
11350 struct glyph_row
*row
;
11353 struct frame
*f
= XFRAME (w
->frame
);
11354 struct glyph
*cursor_glyph
;
11356 /* If cursor is out of bounds, don't draw garbage. This can happen
11357 in mini-buffer windows when switching between echo area glyphs
11358 and mini-buffer. */
11359 cursor_glyph
= get_phys_cursor_glyph (w
);
11360 if (cursor_glyph
== NULL
)
11363 /* If on an image, draw like a normal cursor. That's usually better
11364 visible than drawing a bar, esp. if the image is large so that
11365 the bar might not be in the window. */
11366 if (cursor_glyph
->type
== IMAGE_GLYPH
)
11368 struct glyph_row
*row
;
11369 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
11370 x_draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
11374 Display
*dpy
= FRAME_X_DISPLAY (f
);
11375 Window window
= FRAME_X_WINDOW (f
);
11376 GC gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
11377 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
11378 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
11381 /* If the glyph's background equals the color we normally draw
11382 the bar cursor in, the bar cursor in its normal color is
11383 invisible. Use the glyph's foreground color instead in this
11384 case, on the assumption that the glyph's colors are chosen so
11385 that the glyph is legible. */
11386 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
11387 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
11389 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
11390 xgcv
.graphics_exposures
= 0;
11393 XChangeGC (dpy
, gc
, mask
, &xgcv
);
11396 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
11397 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
11401 width
= f
->output_data
.x
->cursor_width
;
11402 width
= min (cursor_glyph
->pixel_width
, width
);
11404 x_clip_to_row (w
, row
, gc
, 0);
11405 XFillRectangle (dpy
, window
, gc
,
11406 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
11407 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
11408 width
, row
->height
);
11409 XSetClipMask (dpy
, gc
, None
);
11414 /* Clear the cursor of window W to background color, and mark the
11415 cursor as not shown. This is used when the text where the cursor
11416 is is about to be rewritten. */
11422 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
11423 x_update_window_cursor (w
, 0);
11427 /* Draw the cursor glyph of window W in glyph row ROW. See the
11428 comment of x_draw_glyphs for the meaning of HL. */
11431 x_draw_phys_cursor_glyph (w
, row
, hl
)
11433 struct glyph_row
*row
;
11434 enum draw_glyphs_face hl
;
11436 /* If cursor hpos is out of bounds, don't draw garbage. This can
11437 happen in mini-buffer windows when switching between echo area
11438 glyphs and mini-buffer. */
11439 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
11441 int on_p
= w
->phys_cursor_on_p
;
11443 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
11444 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
11446 w
->phys_cursor_on_p
= on_p
;
11448 /* When we erase the cursor, and ROW is overlapped by other
11449 rows, make sure that these overlapping parts of other rows
11451 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
11453 if (row
> w
->current_matrix
->rows
11454 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
11455 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
11457 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
11458 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
11459 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
11465 /* Erase the image of a cursor of window W from the screen. */
11468 x_erase_phys_cursor (w
)
11471 struct frame
*f
= XFRAME (w
->frame
);
11472 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11473 int hpos
= w
->phys_cursor
.hpos
;
11474 int vpos
= w
->phys_cursor
.vpos
;
11475 int mouse_face_here_p
= 0;
11476 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
11477 struct glyph_row
*cursor_row
;
11478 struct glyph
*cursor_glyph
;
11479 enum draw_glyphs_face hl
;
11481 /* No cursor displayed or row invalidated => nothing to do on the
11483 if (w
->phys_cursor_type
== NO_CURSOR
)
11484 goto mark_cursor_off
;
11486 /* VPOS >= active_glyphs->nrows means that window has been resized.
11487 Don't bother to erase the cursor. */
11488 if (vpos
>= active_glyphs
->nrows
)
11489 goto mark_cursor_off
;
11491 /* If row containing cursor is marked invalid, there is nothing we
11493 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
11494 if (!cursor_row
->enabled_p
)
11495 goto mark_cursor_off
;
11497 /* If row is completely invisible, don't attempt to delete a cursor which
11498 isn't there. This can happen if cursor is at top of a window, and
11499 we switch to a buffer with a header line in that window. */
11500 if (cursor_row
->visible_height
<= 0)
11501 goto mark_cursor_off
;
11503 /* This can happen when the new row is shorter than the old one.
11504 In this case, either x_draw_glyphs or clear_end_of_line
11505 should have cleared the cursor. Note that we wouldn't be
11506 able to erase the cursor in this case because we don't have a
11507 cursor glyph at hand. */
11508 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
11509 goto mark_cursor_off
;
11511 /* If the cursor is in the mouse face area, redisplay that when
11512 we clear the cursor. */
11513 if (! NILP (dpyinfo
->mouse_face_window
)
11514 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
11515 && (vpos
> dpyinfo
->mouse_face_beg_row
11516 || (vpos
== dpyinfo
->mouse_face_beg_row
11517 && hpos
>= dpyinfo
->mouse_face_beg_col
))
11518 && (vpos
< dpyinfo
->mouse_face_end_row
11519 || (vpos
== dpyinfo
->mouse_face_end_row
11520 && hpos
< dpyinfo
->mouse_face_end_col
))
11521 /* Don't redraw the cursor's spot in mouse face if it is at the
11522 end of a line (on a newline). The cursor appears there, but
11523 mouse highlighting does not. */
11524 && cursor_row
->used
[TEXT_AREA
] > hpos
)
11525 mouse_face_here_p
= 1;
11527 /* Maybe clear the display under the cursor. */
11528 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
11531 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11533 cursor_glyph
= get_phys_cursor_glyph (w
);
11534 if (cursor_glyph
== NULL
)
11535 goto mark_cursor_off
;
11537 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
11539 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11541 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
11543 cursor_glyph
->pixel_width
,
11544 cursor_row
->visible_height
,
11548 /* Erase the cursor by redrawing the character underneath it. */
11549 if (mouse_face_here_p
)
11550 hl
= DRAW_MOUSE_FACE
;
11552 hl
= DRAW_NORMAL_TEXT
;
11553 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
11556 w
->phys_cursor_on_p
= 0;
11557 w
->phys_cursor_type
= NO_CURSOR
;
11561 /* Non-zero if physical cursor of window W is within mouse face. */
11564 cursor_in_mouse_face_p (w
)
11567 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
11568 int in_mouse_face
= 0;
11570 if (WINDOWP (dpyinfo
->mouse_face_window
)
11571 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
11573 int hpos
= w
->phys_cursor
.hpos
;
11574 int vpos
= w
->phys_cursor
.vpos
;
11576 if (vpos
>= dpyinfo
->mouse_face_beg_row
11577 && vpos
<= dpyinfo
->mouse_face_end_row
11578 && (vpos
> dpyinfo
->mouse_face_beg_row
11579 || hpos
>= dpyinfo
->mouse_face_beg_col
)
11580 && (vpos
< dpyinfo
->mouse_face_end_row
11581 || hpos
< dpyinfo
->mouse_face_end_col
11582 || dpyinfo
->mouse_face_past_end
))
11586 return in_mouse_face
;
11590 /* Display or clear cursor of window W. If ON is zero, clear the
11591 cursor. If it is non-zero, display the cursor. If ON is nonzero,
11592 where to put the cursor is specified by HPOS, VPOS, X and Y. */
11595 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
11597 int on
, hpos
, vpos
, x
, y
;
11599 struct frame
*f
= XFRAME (w
->frame
);
11600 int new_cursor_type
;
11601 int new_cursor_width
;
11602 struct glyph_matrix
*current_glyphs
;
11603 struct glyph_row
*glyph_row
;
11604 struct glyph
*glyph
;
11605 int cursor_non_selected
;
11607 /* This is pointless on invisible frames, and dangerous on garbaged
11608 windows and frames; in the latter case, the frame or window may
11609 be in the midst of changing its size, and x and y may be off the
11611 if (! FRAME_VISIBLE_P (f
)
11612 || FRAME_GARBAGED_P (f
)
11613 || vpos
>= w
->current_matrix
->nrows
11614 || hpos
>= w
->current_matrix
->matrix_w
)
11617 /* If cursor is off and we want it off, return quickly. */
11618 if (!on
&& !w
->phys_cursor_on_p
)
11621 current_glyphs
= w
->current_matrix
;
11622 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
11623 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
11625 /* If cursor row is not enabled, we don't really know where to
11626 display the cursor. */
11627 if (!glyph_row
->enabled_p
)
11629 w
->phys_cursor_on_p
= 0;
11633 xassert (interrupt_input_blocked
);
11635 /* Set new_cursor_type to the cursor we want to be displayed. In a
11636 mini-buffer window, we want the cursor only to appear if we are
11637 reading input from this window. For the selected window, we want
11638 the cursor type given by the frame parameter. If explicitly
11639 marked off, draw no cursor. In all other cases, we want a hollow
11641 cursor_non_selected
11642 = !NILP (Fbuffer_local_value (Qcursor_in_non_selected_windows
,
11644 new_cursor_width
= -1;
11645 if (cursor_in_echo_area
11646 && FRAME_HAS_MINIBUF_P (f
)
11647 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
11649 if (w
== XWINDOW (echo_area_window
))
11650 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
11651 else if (cursor_non_selected
)
11652 new_cursor_type
= HOLLOW_BOX_CURSOR
;
11654 new_cursor_type
= NO_CURSOR
;
11658 if (f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
11659 || w
!= XWINDOW (f
->selected_window
))
11661 if ((MINI_WINDOW_P (w
) && minibuf_level
== 0)
11662 || !cursor_non_selected
11663 || NILP (XBUFFER (w
->buffer
)->cursor_type
))
11664 new_cursor_type
= NO_CURSOR
;
11666 new_cursor_type
= HOLLOW_BOX_CURSOR
;
11670 struct buffer
*b
= XBUFFER (w
->buffer
);
11672 if (EQ (b
->cursor_type
, Qt
))
11673 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
11675 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
11676 &new_cursor_width
);
11677 if (w
->cursor_off_p
)
11679 if (new_cursor_type
== FILLED_BOX_CURSOR
)
11680 new_cursor_type
= HOLLOW_BOX_CURSOR
;
11681 else if (new_cursor_type
== BAR_CURSOR
&& new_cursor_width
> 1)
11682 new_cursor_width
= 1;
11684 new_cursor_type
= NO_CURSOR
;
11689 /* If cursor is currently being shown and we don't want it to be or
11690 it is in the wrong place, or the cursor type is not what we want,
11692 if (w
->phys_cursor_on_p
11694 || w
->phys_cursor
.x
!= x
11695 || w
->phys_cursor
.y
!= y
11696 || new_cursor_type
!= w
->phys_cursor_type
11697 || (new_cursor_type
== BAR_CURSOR
11698 && new_cursor_width
!= w
->phys_cursor_width
)))
11699 x_erase_phys_cursor (w
);
11701 /* If the cursor is now invisible and we want it to be visible,
11703 if (on
&& !w
->phys_cursor_on_p
)
11705 w
->phys_cursor_ascent
= glyph_row
->ascent
;
11706 w
->phys_cursor_height
= glyph_row
->height
;
11708 /* Set phys_cursor_.* before x_draw_.* is called because some
11709 of them may need the information. */
11710 w
->phys_cursor
.x
= x
;
11711 w
->phys_cursor
.y
= glyph_row
->y
;
11712 w
->phys_cursor
.hpos
= hpos
;
11713 w
->phys_cursor
.vpos
= vpos
;
11714 w
->phys_cursor_type
= new_cursor_type
;
11715 w
->phys_cursor_width
= new_cursor_width
;
11716 w
->phys_cursor_on_p
= 1;
11718 switch (new_cursor_type
)
11720 case HOLLOW_BOX_CURSOR
:
11721 x_draw_hollow_cursor (w
, glyph_row
);
11724 case FILLED_BOX_CURSOR
:
11725 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
11729 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
);
11740 if (w
== XWINDOW (f
->selected_window
))
11741 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
11742 xic_set_preeditarea (w
, x
, y
);
11747 if (updating_frame
!= f
)
11748 XFlush (FRAME_X_DISPLAY (f
));
11753 /* Display the cursor on window W, or clear it. X and Y are window
11754 relative pixel coordinates. HPOS and VPOS are glyph matrix
11755 positions. If W is not the selected window, display a hollow
11756 cursor. ON non-zero means display the cursor at X, Y which
11757 correspond to HPOS, VPOS, otherwise it is cleared. */
11760 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
11762 int on
, hpos
, vpos
, x
, y
;
11765 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
11770 /* Display the cursor on window W, or clear it, according to ON_P.
11771 Don't change the cursor's position. */
11774 x_update_cursor (f
, on_p
)
11777 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
11781 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
11782 in the window tree rooted at W. */
11785 x_update_cursor_in_window_tree (w
, on_p
)
11791 if (!NILP (w
->hchild
))
11792 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
11793 else if (!NILP (w
->vchild
))
11794 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
11796 x_update_window_cursor (w
, on_p
);
11798 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
11803 /* Switch the display of W's cursor on or off, according to the value
11807 x_update_window_cursor (w
, on
)
11811 /* Don't update cursor in windows whose frame is in the process
11812 of being deleted. */
11813 if (w
->current_matrix
)
11816 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
11817 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
11827 /* Make the x-window of frame F use the gnu icon bitmap. */
11830 x_bitmap_icon (f
, file
)
11836 if (FRAME_X_WINDOW (f
) == 0)
11839 /* Free up our existing icon bitmap if any. */
11840 if (f
->output_data
.x
->icon_bitmap
> 0)
11841 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
11842 f
->output_data
.x
->icon_bitmap
= 0;
11844 if (STRINGP (file
))
11845 bitmap_id
= x_create_bitmap_from_file (f
, file
);
11848 /* Create the GNU bitmap if necessary. */
11849 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
11850 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
11851 = x_create_bitmap_from_data (f
, gnu_bits
,
11852 gnu_width
, gnu_height
);
11854 /* The first time we create the GNU bitmap,
11855 this increments the ref-count one extra time.
11856 As a result, the GNU bitmap is never freed.
11857 That way, we don't have to worry about allocating it again. */
11858 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
11860 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
11863 x_wm_set_icon_pixmap (f
, bitmap_id
);
11864 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
11870 /* Make the x-window of frame F use a rectangle with text.
11871 Use ICON_NAME as the text. */
11874 x_text_icon (f
, icon_name
)
11878 if (FRAME_X_WINDOW (f
) == 0)
11883 XTextProperty text
;
11884 text
.value
= (unsigned char *) icon_name
;
11885 text
.encoding
= XA_STRING
;
11887 text
.nitems
= strlen (icon_name
);
11888 #ifdef USE_X_TOOLKIT
11889 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
11891 #else /* not USE_X_TOOLKIT */
11892 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
11893 #endif /* not USE_X_TOOLKIT */
11895 #else /* not HAVE_X11R4 */
11896 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
11897 #endif /* not HAVE_X11R4 */
11899 if (f
->output_data
.x
->icon_bitmap
> 0)
11900 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
11901 f
->output_data
.x
->icon_bitmap
= 0;
11902 x_wm_set_icon_pixmap (f
, 0);
11907 #define X_ERROR_MESSAGE_SIZE 200
11909 /* If non-nil, this should be a string.
11910 It means catch X errors and store the error message in this string. */
11912 static Lisp_Object x_error_message_string
;
11914 /* An X error handler which stores the error message in
11915 x_error_message_string. This is called from x_error_handler if
11916 x_catch_errors is in effect. */
11919 x_error_catcher (display
, error
)
11921 XErrorEvent
*error
;
11923 XGetErrorText (display
, error
->error_code
,
11924 XSTRING (x_error_message_string
)->data
,
11925 X_ERROR_MESSAGE_SIZE
);
11928 /* Begin trapping X errors for display DPY. Actually we trap X errors
11929 for all displays, but DPY should be the display you are actually
11932 After calling this function, X protocol errors no longer cause
11933 Emacs to exit; instead, they are recorded in the string
11934 stored in x_error_message_string.
11936 Calling x_check_errors signals an Emacs error if an X error has
11937 occurred since the last call to x_catch_errors or x_check_errors.
11939 Calling x_uncatch_errors resumes the normal error handling. */
11941 void x_check_errors ();
11942 static Lisp_Object
x_catch_errors_unwind ();
11945 x_catch_errors (dpy
)
11948 int count
= specpdl_ptr
- specpdl
;
11950 /* Make sure any errors from previous requests have been dealt with. */
11951 XSync (dpy
, False
);
11953 record_unwind_protect (x_catch_errors_unwind
, x_error_message_string
);
11955 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
11956 XSTRING (x_error_message_string
)->data
[0] = 0;
11961 /* Unbind the binding that we made to check for X errors. */
11964 x_catch_errors_unwind (old_val
)
11965 Lisp_Object old_val
;
11967 x_error_message_string
= old_val
;
11971 /* If any X protocol errors have arrived since the last call to
11972 x_catch_errors or x_check_errors, signal an Emacs error using
11973 sprintf (a buffer, FORMAT, the x error message text) as the text. */
11976 x_check_errors (dpy
, format
)
11980 /* Make sure to catch any errors incurred so far. */
11981 XSync (dpy
, False
);
11983 if (XSTRING (x_error_message_string
)->data
[0])
11984 error (format
, XSTRING (x_error_message_string
)->data
);
11987 /* Nonzero if we had any X protocol errors
11988 since we did x_catch_errors on DPY. */
11991 x_had_errors_p (dpy
)
11994 /* Make sure to catch any errors incurred so far. */
11995 XSync (dpy
, False
);
11997 return XSTRING (x_error_message_string
)->data
[0] != 0;
12000 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
12003 x_clear_errors (dpy
)
12006 XSTRING (x_error_message_string
)->data
[0] = 0;
12009 /* Stop catching X protocol errors and let them make Emacs die.
12010 DPY should be the display that was passed to x_catch_errors.
12011 COUNT should be the value that was returned by
12012 the corresponding call to x_catch_errors. */
12015 x_uncatch_errors (dpy
, count
)
12019 unbind_to (count
, Qnil
);
12023 static unsigned int x_wire_count
;
12026 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
12031 /* Handle SIGPIPE, which can happen when the connection to a server
12032 simply goes away. SIGPIPE is handled by x_connection_signal.
12033 Don't need to do anything, because the write which caused the
12034 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
12035 which will do the appropriate cleanup for us. */
12038 x_connection_signal (signalnum
) /* If we don't have an argument, */
12039 int signalnum
; /* some compilers complain in signal calls. */
12042 /* USG systems forget handlers when they are used;
12043 must reestablish each time */
12044 signal (signalnum
, x_connection_signal
);
12049 /************************************************************************
12051 ************************************************************************/
12053 /* Error message passed to x_connection_closed. */
12055 static char *error_msg
;
12057 /* Function installed as fatal_error_signal_hook in
12058 x_connection_closed. Print the X error message, and exit normally,
12059 instead of dumping core when XtCloseDisplay fails. */
12062 x_fatal_error_signal ()
12064 fprintf (stderr
, "%s\n", error_msg
);
12068 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
12069 the text of an error message that lead to the connection loss. */
12072 x_connection_closed (dpy
, error_message
)
12074 char *error_message
;
12076 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
12077 Lisp_Object frame
, tail
;
12080 error_msg
= (char *) alloca (strlen (error_message
) + 1);
12081 strcpy (error_msg
, error_message
);
12082 handling_signal
= 0;
12084 /* Prevent being called recursively because of an error condition
12085 below. Otherwise, we might end up with printing ``can't find per
12086 display information'' in the recursive call instead of printing
12087 the original message here. */
12088 count
= x_catch_errors (dpy
);
12090 /* We have to close the display to inform Xt that it doesn't
12091 exist anymore. If we don't, Xt will continue to wait for
12092 events from the display. As a consequence, a sequence of
12094 M-x make-frame-on-display RET :1 RET
12095 ...kill the new frame, so that we get an IO error...
12096 M-x make-frame-on-display RET :1 RET
12098 will indefinitely wait in Xt for events for display `:1', opened
12099 in the first class to make-frame-on-display.
12101 Closing the display is reported to lead to a bus error on
12102 OpenWindows in certain situations. I suspect that is a bug
12103 in OpenWindows. I don't know how to cicumvent it here. */
12105 #ifdef USE_X_TOOLKIT
12106 /* If DPYINFO is null, this means we didn't open the display
12107 in the first place, so don't try to close it. */
12110 extern void (*fatal_error_signal_hook
) P_ ((void));
12111 fatal_error_signal_hook
= x_fatal_error_signal
;
12112 XtCloseDisplay (dpy
);
12113 fatal_error_signal_hook
= NULL
;
12117 /* Indicate that this display is dead. */
12119 dpyinfo
->display
= 0;
12121 /* First delete frames whose mini-buffers are on frames
12122 that are on the dead display. */
12123 FOR_EACH_FRAME (tail
, frame
)
12125 Lisp_Object minibuf_frame
;
12127 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
12128 if (FRAME_X_P (XFRAME (frame
))
12129 && FRAME_X_P (XFRAME (minibuf_frame
))
12130 && ! EQ (frame
, minibuf_frame
)
12131 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
12132 Fdelete_frame (frame
, Qt
);
12135 /* Now delete all remaining frames on the dead display.
12136 We are now sure none of these is used as the mini-buffer
12137 for another frame that we need to delete. */
12138 FOR_EACH_FRAME (tail
, frame
)
12139 if (FRAME_X_P (XFRAME (frame
))
12140 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
12142 /* Set this to t so that Fdelete_frame won't get confused
12143 trying to find a replacement. */
12144 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
12145 Fdelete_frame (frame
, Qt
);
12149 x_delete_display (dpyinfo
);
12151 x_uncatch_errors (dpy
, count
);
12153 if (x_display_list
== 0)
12155 fprintf (stderr
, "%s\n", error_msg
);
12156 shut_down_emacs (0, 0, Qnil
);
12160 /* Ordinary stack unwind doesn't deal with these. */
12162 sigunblock (sigmask (SIGIO
));
12164 sigunblock (sigmask (SIGALRM
));
12165 TOTALLY_UNBLOCK_INPUT
;
12167 clear_waiting_for_input ();
12168 error ("%s", error_msg
);
12172 /* This is the usual handler for X protocol errors.
12173 It kills all frames on the display that we got the error for.
12174 If that was the only one, it prints an error message and kills Emacs. */
12177 x_error_quitter (display
, error
)
12179 XErrorEvent
*error
;
12181 char buf
[256], buf1
[356];
12183 /* Note that there is no real way portable across R3/R4 to get the
12184 original error handler. */
12186 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
12187 sprintf (buf1
, "X protocol error: %s on protocol request %d",
12188 buf
, error
->request_code
);
12189 x_connection_closed (display
, buf1
);
12193 /* This is the first-level handler for X protocol errors.
12194 It calls x_error_quitter or x_error_catcher. */
12197 x_error_handler (display
, error
)
12199 XErrorEvent
*error
;
12201 if (! NILP (x_error_message_string
))
12202 x_error_catcher (display
, error
);
12204 x_error_quitter (display
, error
);
12208 /* This is the handler for X IO errors, always.
12209 It kills all frames on the display that we lost touch with.
12210 If that was the only one, it prints an error message and kills Emacs. */
12213 x_io_error_quitter (display
)
12218 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
12219 x_connection_closed (display
, buf
);
12223 /* Changing the font of the frame. */
12225 /* Give frame F the font named FONTNAME as its default font, and
12226 return the full name of that font. FONTNAME may be a wildcard
12227 pattern; in that case, we choose some font that fits the pattern.
12228 The return value shows which font we chose. */
12231 x_new_font (f
, fontname
)
12233 register char *fontname
;
12235 struct font_info
*fontp
12236 = FS_LOAD_FONT (f
, 0, fontname
, -1);
12241 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
12242 f
->output_data
.x
->baseline_offset
= fontp
->baseline_offset
;
12243 f
->output_data
.x
->fontset
= -1;
12245 x_compute_fringe_widths (f
, 1);
12247 /* Compute the scroll bar width in character columns. */
12248 if (f
->scroll_bar_pixel_width
> 0)
12250 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
12251 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
12255 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
12256 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
12259 /* Now make the frame display the given font. */
12260 if (FRAME_X_WINDOW (f
) != 0)
12262 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
12263 f
->output_data
.x
->font
->fid
);
12264 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
12265 f
->output_data
.x
->font
->fid
);
12266 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
12267 f
->output_data
.x
->font
->fid
);
12269 frame_update_line_height (f
);
12271 /* Don't change the size of a tip frame; there's no point in
12272 doing it because it's done in Fx_show_tip, and it leads to
12273 problems because the tip frame has no widget. */
12274 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
12275 x_set_window_size (f
, 0, f
->width
, f
->height
);
12278 /* If we are setting a new frame's font for the first time,
12279 there are no faces yet, so this font's height is the line height. */
12280 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
12282 return build_string (fontp
->full_name
);
12285 /* Give frame F the fontset named FONTSETNAME as its default font, and
12286 return the full name of that fontset. FONTSETNAME may be a wildcard
12287 pattern; in that case, we choose some fontset that fits the pattern.
12288 The return value shows which fontset we chose. */
12291 x_new_fontset (f
, fontsetname
)
12295 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
12296 Lisp_Object result
;
12301 if (f
->output_data
.x
->fontset
== fontset
)
12302 /* This fontset is already set in frame F. There's nothing more
12304 return fontset_name (fontset
);
12306 result
= x_new_font (f
, (XSTRING (fontset_ascii (fontset
))->data
));
12308 if (!STRINGP (result
))
12309 /* Can't load ASCII font. */
12312 /* Since x_new_font doesn't update any fontset information, do it now. */
12313 f
->output_data
.x
->fontset
= fontset
;
12317 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
12318 xic_set_xfontset (f
, XSTRING (fontset_ascii (fontset
))->data
);
12321 return build_string (fontsetname
);
12324 /* Compute actual fringe widths */
12327 x_compute_fringe_widths (f
, redraw
)
12331 int o_left
= f
->output_data
.x
->left_fringe_width
;
12332 int o_right
= f
->output_data
.x
->right_fringe_width
;
12333 int o_cols
= f
->output_data
.x
->fringe_cols
;
12335 Lisp_Object left_fringe
= Fassq (Qleft_fringe
, f
->param_alist
);
12336 Lisp_Object right_fringe
= Fassq (Qright_fringe
, f
->param_alist
);
12337 int left_fringe_width
, right_fringe_width
;
12339 if (!NILP (left_fringe
))
12340 left_fringe
= Fcdr (left_fringe
);
12341 if (!NILP (right_fringe
))
12342 right_fringe
= Fcdr (right_fringe
);
12344 left_fringe_width
= ((NILP (left_fringe
) || !INTEGERP (left_fringe
)) ? 8 :
12345 XINT (left_fringe
));
12346 right_fringe_width
= ((NILP (right_fringe
) || !INTEGERP (right_fringe
)) ? 8 :
12347 XINT (right_fringe
));
12349 if (left_fringe_width
|| right_fringe_width
)
12351 int left_wid
= left_fringe_width
>= 0 ? left_fringe_width
: -left_fringe_width
;
12352 int right_wid
= right_fringe_width
>= 0 ? right_fringe_width
: -right_fringe_width
;
12353 int conf_wid
= left_wid
+ right_wid
;
12354 int font_wid
= FONT_WIDTH (f
->output_data
.x
->font
);
12355 int cols
= (left_wid
+ right_wid
+ font_wid
-1) / font_wid
;
12356 int real_wid
= cols
* font_wid
;
12357 if (left_wid
&& right_wid
)
12359 if (left_fringe_width
< 0)
12361 /* Left fringe width is fixed, adjust right fringe if necessary */
12362 f
->output_data
.x
->left_fringe_width
= left_wid
;
12363 f
->output_data
.x
->right_fringe_width
= real_wid
- left_wid
;
12365 else if (right_fringe_width
< 0)
12367 /* Right fringe width is fixed, adjust left fringe if necessary */
12368 f
->output_data
.x
->left_fringe_width
= real_wid
- right_wid
;
12369 f
->output_data
.x
->right_fringe_width
= right_wid
;
12373 /* Adjust both fringes with an equal amount.
12374 Note that we are doing integer arithmetic here, so don't
12375 lose a pixel if the total width is an odd number. */
12376 int fill
= real_wid
- conf_wid
;
12377 f
->output_data
.x
->left_fringe_width
= left_wid
+ fill
/2;
12378 f
->output_data
.x
->right_fringe_width
= right_wid
+ fill
- fill
/2;
12381 else if (left_fringe_width
)
12383 f
->output_data
.x
->left_fringe_width
= real_wid
;
12384 f
->output_data
.x
->right_fringe_width
= 0;
12388 f
->output_data
.x
->left_fringe_width
= 0;
12389 f
->output_data
.x
->right_fringe_width
= real_wid
;
12391 f
->output_data
.x
->fringe_cols
= cols
;
12392 f
->output_data
.x
->fringes_extra
= real_wid
;
12396 f
->output_data
.x
->left_fringe_width
= 0;
12397 f
->output_data
.x
->right_fringe_width
= 0;
12398 f
->output_data
.x
->fringe_cols
= 0;
12399 f
->output_data
.x
->fringes_extra
= 0;
12402 if (redraw
&& FRAME_VISIBLE_P (f
))
12403 if (o_left
!= f
->output_data
.x
->left_fringe_width
||
12404 o_right
!= f
->output_data
.x
->right_fringe_width
||
12405 o_cols
!= f
->output_data
.x
->fringe_cols
)
12409 /***********************************************************************
12411 ***********************************************************************/
12417 /* XIM destroy callback function, which is called whenever the
12418 connection to input method XIM dies. CLIENT_DATA contains a
12419 pointer to the x_display_info structure corresponding to XIM. */
12422 xim_destroy_callback (xim
, client_data
, call_data
)
12424 XPointer client_data
;
12425 XPointer call_data
;
12427 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
12428 Lisp_Object frame
, tail
;
12432 /* No need to call XDestroyIC.. */
12433 FOR_EACH_FRAME (tail
, frame
)
12435 struct frame
*f
= XFRAME (frame
);
12436 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
12438 FRAME_XIC (f
) = NULL
;
12439 if (FRAME_XIC_FONTSET (f
))
12441 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
12442 FRAME_XIC_FONTSET (f
) = NULL
;
12447 /* No need to call XCloseIM. */
12448 dpyinfo
->xim
= NULL
;
12449 XFree (dpyinfo
->xim_styles
);
12453 #endif /* HAVE_X11R6 */
12455 /* Open the connection to the XIM server on display DPYINFO.
12456 RESOURCE_NAME is the resource name Emacs uses. */
12459 xim_open_dpy (dpyinfo
, resource_name
)
12460 struct x_display_info
*dpyinfo
;
12461 char *resource_name
;
12466 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
, EMACS_CLASS
);
12467 dpyinfo
->xim
= xim
;
12472 XIMCallback destroy
;
12475 /* Get supported styles and XIM values. */
12476 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
12479 destroy
.callback
= xim_destroy_callback
;
12480 destroy
.client_data
= (XPointer
)dpyinfo
;
12481 /* This isn't prototyped in OSF 5.0. */
12482 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
12486 #else /* not USE_XIM */
12487 dpyinfo
->xim
= NULL
;
12488 #endif /* not USE_XIM */
12492 #ifdef HAVE_X11R6_XIM
12496 struct x_display_info
*dpyinfo
;
12497 char *resource_name
;
12500 /* XIM instantiate callback function, which is called whenever an XIM
12501 server is available. DISPLAY is teh display of the XIM.
12502 CLIENT_DATA contains a pointer to an xim_inst_t structure created
12503 when the callback was registered. */
12506 xim_instantiate_callback (display
, client_data
, call_data
)
12508 XPointer client_data
;
12509 XPointer call_data
;
12511 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
12512 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
12514 /* We don't support multiple XIM connections. */
12518 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
12520 /* Create XIC for the existing frames on the same display, as long
12521 as they have no XIC. */
12522 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
12524 Lisp_Object tail
, frame
;
12527 FOR_EACH_FRAME (tail
, frame
)
12529 struct frame
*f
= XFRAME (frame
);
12531 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
12532 if (FRAME_XIC (f
) == NULL
)
12534 create_frame_xic (f
);
12535 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
12536 xic_set_statusarea (f
);
12537 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
12539 struct window
*w
= XWINDOW (f
->selected_window
);
12540 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
12549 #endif /* HAVE_X11R6_XIM */
12552 /* Open a connection to the XIM server on display DPYINFO.
12553 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
12554 connection only at the first time. On X11R6, open the connection
12555 in the XIM instantiate callback function. */
12558 xim_initialize (dpyinfo
, resource_name
)
12559 struct x_display_info
*dpyinfo
;
12560 char *resource_name
;
12563 #ifdef HAVE_X11R6_XIM
12564 struct xim_inst_t
*xim_inst
;
12567 dpyinfo
->xim
= NULL
;
12568 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
12569 xim_inst
->dpyinfo
= dpyinfo
;
12570 len
= strlen (resource_name
);
12571 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
12572 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
12573 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
12574 resource_name
, EMACS_CLASS
,
12575 xim_instantiate_callback
,
12576 /* Fixme: This is XPointer in
12577 XFree86 but (XPointer *) on
12578 Tru64, at least. */
12579 (XPointer
) xim_inst
);
12580 #else /* not HAVE_X11R6_XIM */
12581 dpyinfo
->xim
= NULL
;
12582 xim_open_dpy (dpyinfo
, resource_name
);
12583 #endif /* not HAVE_X11R6_XIM */
12585 #else /* not USE_XIM */
12586 dpyinfo
->xim
= NULL
;
12587 #endif /* not USE_XIM */
12591 /* Close the connection to the XIM server on display DPYINFO. */
12594 xim_close_dpy (dpyinfo
)
12595 struct x_display_info
*dpyinfo
;
12598 #ifdef HAVE_X11R6_XIM
12599 if (dpyinfo
->display
)
12600 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
12602 xim_instantiate_callback
, NULL
);
12603 #endif /* not HAVE_X11R6_XIM */
12604 if (dpyinfo
->display
)
12605 XCloseIM (dpyinfo
->xim
);
12606 dpyinfo
->xim
= NULL
;
12607 XFree (dpyinfo
->xim_styles
);
12608 #endif /* USE_XIM */
12611 #endif /* not HAVE_X11R6_XIM */
12615 /* Calculate the absolute position in frame F
12616 from its current recorded position values and gravity. */
12619 x_calc_absolute_position (f
)
12623 int win_x
= 0, win_y
= 0;
12624 int flags
= f
->output_data
.x
->size_hint_flags
;
12627 /* We have nothing to do if the current position
12628 is already for the top-left corner. */
12629 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
12632 #ifdef USE_X_TOOLKIT
12633 this_window
= XtWindow (f
->output_data
.x
->widget
);
12635 this_window
= FRAME_X_WINDOW (f
);
12638 /* Find the position of the outside upper-left corner of
12639 the inner window, with respect to the outer window.
12640 But do this only if we will need the results. */
12641 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
12646 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
12649 x_clear_errors (FRAME_X_DISPLAY (f
));
12650 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
12652 /* From-window, to-window. */
12654 f
->output_data
.x
->parent_desc
,
12656 /* From-position, to-position. */
12657 0, 0, &win_x
, &win_y
,
12659 /* Child of win. */
12661 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
12663 Window newroot
, newparent
= 0xdeadbeef;
12664 Window
*newchildren
;
12665 unsigned int nchildren
;
12667 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
12668 &newparent
, &newchildren
, &nchildren
))
12671 XFree ((char *) newchildren
);
12673 f
->output_data
.x
->parent_desc
= newparent
;
12679 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
12683 /* Treat negative positions as relative to the leftmost bottommost
12684 position that fits on the screen. */
12685 if (flags
& XNegative
)
12686 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
12687 - 2 * f
->output_data
.x
->border_width
- win_x
12689 + f
->output_data
.x
->left_pos
);
12692 int height
= PIXEL_HEIGHT (f
);
12694 #if defined USE_X_TOOLKIT && defined USE_MOTIF
12695 /* Something is fishy here. When using Motif, starting Emacs with
12696 `-g -0-0', the frame appears too low by a few pixels.
12698 This seems to be so because initially, while Emacs is starting,
12699 the column widget's height and the frame's pixel height are
12700 different. The column widget's height is the right one. In
12701 later invocations, when Emacs is up, the frame's pixel height
12704 It's not obvious where the initial small difference comes from.
12705 2000-12-01, gerd. */
12707 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
12710 if (flags
& YNegative
)
12711 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
12712 - 2 * f
->output_data
.x
->border_width
12715 + f
->output_data
.x
->top_pos
);
12718 /* The left_pos and top_pos
12719 are now relative to the top and left screen edges,
12720 so the flags should correspond. */
12721 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
12724 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
12725 to really change the position, and 0 when calling from
12726 x_make_frame_visible (in that case, XOFF and YOFF are the current
12727 position values). It is -1 when calling from x_set_frame_parameters,
12728 which means, do adjust for borders but don't change the gravity. */
12731 x_set_offset (f
, xoff
, yoff
, change_gravity
)
12733 register int xoff
, yoff
;
12734 int change_gravity
;
12736 int modified_top
, modified_left
;
12738 if (change_gravity
> 0)
12740 f
->output_data
.x
->top_pos
= yoff
;
12741 f
->output_data
.x
->left_pos
= xoff
;
12742 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
12744 f
->output_data
.x
->size_hint_flags
|= XNegative
;
12746 f
->output_data
.x
->size_hint_flags
|= YNegative
;
12747 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
12749 x_calc_absolute_position (f
);
12752 x_wm_set_size_hint (f
, (long) 0, 0);
12754 modified_left
= f
->output_data
.x
->left_pos
;
12755 modified_top
= f
->output_data
.x
->top_pos
;
12756 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
12757 this seems to be unnecessary and incorrect. rms, 4/17/97. */
12758 /* It is a mystery why we need to add the border_width here
12759 when the frame is already visible, but experiment says we do. */
12760 if (change_gravity
!= 0)
12762 modified_left
+= f
->output_data
.x
->border_width
;
12763 modified_top
+= f
->output_data
.x
->border_width
;
12767 #ifdef USE_X_TOOLKIT
12768 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
12769 modified_left
, modified_top
);
12770 #else /* not USE_X_TOOLKIT */
12771 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12772 modified_left
, modified_top
);
12773 #endif /* not USE_X_TOOLKIT */
12777 /* Check if we need to resize the frame due to a fullscreen request.
12778 If so needed, resize the frame. */
12780 x_check_fullscreen (f
)
12783 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_BOTH
)
12785 int width
, height
, ign
;
12787 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
12788 &f
->output_data
.x
->top_pos
);
12790 x_fullscreen_adjust (f
, &width
, &height
, &ign
, &ign
);
12792 /* We do not need to move the window, it shall be taken care of
12793 when setting WM manager hints.
12794 If the frame is visible already, the position is checked by
12795 x_check_fullscreen_move. */
12796 if (f
->width
!= width
|| f
->height
!= height
)
12798 change_frame_size (f
, height
, width
, 0, 1, 0);
12799 SET_FRAME_GARBAGED (f
);
12800 cancel_mouse_face (f
);
12802 /* Wait for the change of frame size to occur */
12803 f
->output_data
.x
->want_fullscreen
|= FULLSCREEN_WAIT
;
12809 /* If frame parameters are set after the frame is mapped, we need to move
12810 the window. This is done in xfns.c.
12811 Some window managers moves the window to the right position, some
12812 moves the outer window manager window to the specified position.
12813 Here we check that we are in the right spot. If not, make a second
12814 move, assuming we are dealing with the second kind of window manager. */
12816 x_check_fullscreen_move (f
)
12819 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_MOVE_WAIT
)
12821 int expect_top
= f
->output_data
.x
->top_pos
;
12822 int expect_left
= f
->output_data
.x
->left_pos
;
12824 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_HEIGHT
)
12826 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WIDTH
)
12829 if (expect_top
!= f
->output_data
.x
->top_pos
12830 || expect_left
!= f
->output_data
.x
->left_pos
)
12831 x_set_offset (f
, expect_left
, expect_top
, 1);
12833 /* Just do this once */
12834 f
->output_data
.x
->want_fullscreen
&= ~FULLSCREEN_MOVE_WAIT
;
12839 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
12840 wanted positions of the WM window (not emacs window).
12841 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
12842 window (FRAME_X_WINDOW).
12845 x_fullscreen_adjust (f
, width
, height
, top_pos
, left_pos
)
12852 int newwidth
= f
->width
, newheight
= f
->height
;
12854 *top_pos
= f
->output_data
.x
->top_pos
;
12855 *left_pos
= f
->output_data
.x
->left_pos
;
12857 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_HEIGHT
)
12861 ph
= FRAME_X_DISPLAY_INFO (f
)->height
;
12862 newheight
= PIXEL_TO_CHAR_HEIGHT (f
, ph
);
12863 ph
= CHAR_TO_PIXEL_HEIGHT (f
, newheight
)
12864 - f
->output_data
.x
->y_pixels_diff
;
12865 newheight
= PIXEL_TO_CHAR_HEIGHT (f
, ph
);
12869 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WIDTH
)
12873 pw
= FRAME_X_DISPLAY_INFO (f
)->width
;
12874 newwidth
= PIXEL_TO_CHAR_WIDTH (f
, pw
);
12875 pw
= CHAR_TO_PIXEL_WIDTH (f
, newwidth
)
12876 - f
->output_data
.x
->x_pixels_diff
;
12877 newwidth
= PIXEL_TO_CHAR_WIDTH (f
, pw
);
12882 *height
= newheight
;
12886 /* Change the size of frame F's X window to COLS/ROWS in the case F
12887 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
12888 top-left-corner window gravity for this size change and subsequent
12889 size changes. Otherwise we leave the window gravity unchanged. */
12892 x_set_window_size_1 (f
, change_gravity
, cols
, rows
)
12894 int change_gravity
;
12897 int pixelwidth
, pixelheight
;
12899 check_frame_size (f
, &rows
, &cols
);
12900 f
->output_data
.x
->vertical_scroll_bar_extra
12901 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
12903 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
12904 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
12905 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
12907 x_compute_fringe_widths (f
, 0);
12909 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
12910 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
12912 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
12913 x_wm_set_size_hint (f
, (long) 0, 0);
12915 XSync (FRAME_X_DISPLAY (f
), False
);
12916 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12917 pixelwidth
, pixelheight
);
12919 /* Now, strictly speaking, we can't be sure that this is accurate,
12920 but the window manager will get around to dealing with the size
12921 change request eventually, and we'll hear how it went when the
12922 ConfigureNotify event gets here.
12924 We could just not bother storing any of this information here,
12925 and let the ConfigureNotify event set everything up, but that
12926 might be kind of confusing to the Lisp code, since size changes
12927 wouldn't be reported in the frame parameters until some random
12928 point in the future when the ConfigureNotify event arrives.
12930 We pass 1 for DELAY since we can't run Lisp code inside of
12932 change_frame_size (f
, rows
, cols
, 0, 1, 0);
12933 PIXEL_WIDTH (f
) = pixelwidth
;
12934 PIXEL_HEIGHT (f
) = pixelheight
;
12936 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
12937 receive in the ConfigureNotify event; if we get what we asked
12938 for, then the event won't cause the screen to become garbaged, so
12939 we have to make sure to do it here. */
12940 SET_FRAME_GARBAGED (f
);
12942 XFlush (FRAME_X_DISPLAY (f
));
12946 /* Call this to change the size of frame F's x-window.
12947 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
12948 for this size change and subsequent size changes.
12949 Otherwise we leave the window gravity unchanged. */
12952 x_set_window_size (f
, change_gravity
, cols
, rows
)
12954 int change_gravity
;
12959 #ifdef USE_X_TOOLKIT
12961 if (f
->output_data
.x
->widget
!= NULL
)
12963 /* The x and y position of the widget is clobbered by the
12964 call to XtSetValues within EmacsFrameSetCharSize.
12965 This is a real kludge, but I don't understand Xt so I can't
12966 figure out a correct fix. Can anyone else tell me? -- rms. */
12967 int xpos
= f
->output_data
.x
->widget
->core
.x
;
12968 int ypos
= f
->output_data
.x
->widget
->core
.y
;
12969 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
12970 f
->output_data
.x
->widget
->core
.x
= xpos
;
12971 f
->output_data
.x
->widget
->core
.y
= ypos
;
12974 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
12976 #else /* not USE_X_TOOLKIT */
12978 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
12980 #endif /* not USE_X_TOOLKIT */
12982 /* If cursor was outside the new size, mark it as off. */
12983 mark_window_cursors_off (XWINDOW (f
->root_window
));
12985 /* Clear out any recollection of where the mouse highlighting was,
12986 since it might be in a place that's outside the new frame size.
12987 Actually checking whether it is outside is a pain in the neck,
12988 so don't try--just let the highlighting be done afresh with new size. */
12989 cancel_mouse_face (f
);
12994 /* Mouse warping. */
12997 x_set_mouse_position (f
, x
, y
)
13003 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
13004 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
13006 if (pix_x
< 0) pix_x
= 0;
13007 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
13009 if (pix_y
< 0) pix_y
= 0;
13010 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
13014 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
13015 0, 0, 0, 0, pix_x
, pix_y
);
13019 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
13022 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
13028 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
13029 0, 0, 0, 0, pix_x
, pix_y
);
13033 /* focus shifting, raising and lowering. */
13036 x_focus_on_frame (f
)
13039 #if 0 /* This proves to be unpleasant. */
13043 /* I don't think that the ICCCM allows programs to do things like this
13044 without the interaction of the window manager. Whatever you end up
13045 doing with this code, do it to x_unfocus_frame too. */
13046 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
13047 RevertToPointerRoot
, CurrentTime
);
13052 x_unfocus_frame (f
)
13056 /* Look at the remarks in x_focus_on_frame. */
13057 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
13058 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
13059 RevertToPointerRoot
, CurrentTime
);
13063 /* Raise frame F. */
13069 if (f
->async_visible
)
13072 #ifdef USE_X_TOOLKIT
13073 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
13074 #else /* not USE_X_TOOLKIT */
13075 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13076 #endif /* not USE_X_TOOLKIT */
13077 XFlush (FRAME_X_DISPLAY (f
));
13082 /* Lower frame F. */
13088 if (f
->async_visible
)
13091 #ifdef USE_X_TOOLKIT
13092 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
13093 #else /* not USE_X_TOOLKIT */
13094 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13095 #endif /* not USE_X_TOOLKIT */
13096 XFlush (FRAME_X_DISPLAY (f
));
13102 XTframe_raise_lower (f
, raise_flag
)
13112 /* Change of visibility. */
13114 /* This tries to wait until the frame is really visible.
13115 However, if the window manager asks the user where to position
13116 the frame, this will return before the user finishes doing that.
13117 The frame will not actually be visible at that time,
13118 but it will become visible later when the window manager
13119 finishes with it. */
13122 x_make_frame_visible (f
)
13126 int original_top
, original_left
;
13127 int retry_count
= 2;
13133 type
= x_icon_type (f
);
13135 x_bitmap_icon (f
, type
);
13137 if (! FRAME_VISIBLE_P (f
))
13139 /* We test FRAME_GARBAGED_P here to make sure we don't
13140 call x_set_offset a second time
13141 if we get to x_make_frame_visible a second time
13142 before the window gets really visible. */
13143 if (! FRAME_ICONIFIED_P (f
)
13144 && ! f
->output_data
.x
->asked_for_visible
)
13145 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
13147 f
->output_data
.x
->asked_for_visible
= 1;
13149 if (! EQ (Vx_no_window_manager
, Qt
))
13150 x_wm_set_window_state (f
, NormalState
);
13151 #ifdef USE_X_TOOLKIT
13152 /* This was XtPopup, but that did nothing for an iconified frame. */
13153 XtMapWidget (f
->output_data
.x
->widget
);
13154 #else /* not USE_X_TOOLKIT */
13155 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13156 #endif /* not USE_X_TOOLKIT */
13157 #if 0 /* This seems to bring back scroll bars in the wrong places
13158 if the window configuration has changed. They seem
13159 to come back ok without this. */
13160 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
13161 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13165 XFlush (FRAME_X_DISPLAY (f
));
13167 /* Synchronize to ensure Emacs knows the frame is visible
13168 before we do anything else. We do this loop with input not blocked
13169 so that incoming events are handled. */
13173 /* This must be before UNBLOCK_INPUT
13174 since events that arrive in response to the actions above
13175 will set it when they are handled. */
13176 int previously_visible
= f
->output_data
.x
->has_been_visible
;
13178 original_left
= f
->output_data
.x
->left_pos
;
13179 original_top
= f
->output_data
.x
->top_pos
;
13181 /* This must come after we set COUNT. */
13184 /* We unblock here so that arriving X events are processed. */
13186 /* Now move the window back to where it was "supposed to be".
13187 But don't do it if the gravity is negative.
13188 When the gravity is negative, this uses a position
13189 that is 3 pixels too low. Perhaps that's really the border width.
13191 Don't do this if the window has never been visible before,
13192 because the window manager may choose the position
13193 and we don't want to override it. */
13195 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
13196 && f
->output_data
.x
->win_gravity
== NorthWestGravity
13197 && previously_visible
)
13201 unsigned int width
, height
, border
, depth
;
13205 /* On some window managers (such as FVWM) moving an existing
13206 window, even to the same place, causes the window manager
13207 to introduce an offset. This can cause the window to move
13208 to an unexpected location. Check the geometry (a little
13209 slow here) and then verify that the window is in the right
13210 place. If the window is not in the right place, move it
13211 there, and take the potential window manager hit. */
13212 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
13213 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
13215 if (original_left
!= x
|| original_top
!= y
)
13216 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
13217 original_left
, original_top
);
13222 XSETFRAME (frame
, f
);
13224 /* Wait until the frame is visible. Process X events until a
13225 MapNotify event has been seen, or until we think we won't get a
13226 MapNotify at all.. */
13227 for (count
= input_signal_count
+ 10;
13228 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
13230 /* Force processing of queued events. */
13233 /* Machines that do polling rather than SIGIO have been
13234 observed to go into a busy-wait here. So we'll fake an
13235 alarm signal to let the handler know that there's something
13236 to be read. We used to raise a real alarm, but it seems
13237 that the handler isn't always enabled here. This is
13239 if (input_polling_used ())
13241 /* It could be confusing if a real alarm arrives while
13242 processing the fake one. Turn it off and let the
13243 handler reset it. */
13244 extern void poll_for_input_1
P_ ((void));
13245 int old_poll_suppress_count
= poll_suppress_count
;
13246 poll_suppress_count
= 1;
13247 poll_for_input_1 ();
13248 poll_suppress_count
= old_poll_suppress_count
;
13251 /* See if a MapNotify event has been processed. */
13252 FRAME_SAMPLE_VISIBILITY (f
);
13257 (let ((f (selected-frame)))
13261 the frame is not raised with various window managers on
13262 FreeBSD, Linux and Solaris. It turns out that, for some
13263 unknown reason, the call to XtMapWidget is completely ignored.
13264 Mapping the widget a second time works. */
13266 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
13271 /* Change from mapped state to withdrawn state. */
13273 /* Make the frame visible (mapped and not iconified). */
13276 x_make_frame_invisible (f
)
13281 #ifdef USE_X_TOOLKIT
13282 /* Use the frame's outermost window, not the one we normally draw on. */
13283 window
= XtWindow (f
->output_data
.x
->widget
);
13284 #else /* not USE_X_TOOLKIT */
13285 window
= FRAME_X_WINDOW (f
);
13286 #endif /* not USE_X_TOOLKIT */
13288 /* Don't keep the highlight on an invisible frame. */
13289 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
13290 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
13292 #if 0/* This might add unreliability; I don't trust it -- rms. */
13293 if (! f
->async_visible
&& ! f
->async_iconified
)
13299 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
13300 that the current position of the window is user-specified, rather than
13301 program-specified, so that when the window is mapped again, it will be
13302 placed at the same location, without forcing the user to position it
13303 by hand again (they have already done that once for this window.) */
13304 x_wm_set_size_hint (f
, (long) 0, 1);
13308 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
13309 DefaultScreen (FRAME_X_DISPLAY (f
))))
13311 UNBLOCK_INPUT_RESIGNAL
;
13312 error ("Can't notify window manager of window withdrawal");
13314 #else /* ! defined (HAVE_X11R4) */
13316 /* Tell the window manager what we're going to do. */
13317 if (! EQ (Vx_no_window_manager
, Qt
))
13321 unmap
.xunmap
.type
= UnmapNotify
;
13322 unmap
.xunmap
.window
= window
;
13323 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
13324 unmap
.xunmap
.from_configure
= False
;
13325 if (! XSendEvent (FRAME_X_DISPLAY (f
),
13326 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
13328 SubstructureRedirectMaskSubstructureNotifyMask
,
13331 UNBLOCK_INPUT_RESIGNAL
;
13332 error ("Can't notify window manager of withdrawal");
13336 /* Unmap the window ourselves. Cheeky! */
13337 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
13338 #endif /* ! defined (HAVE_X11R4) */
13340 /* We can't distinguish this from iconification
13341 just by the event that we get from the server.
13342 So we can't win using the usual strategy of letting
13343 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
13344 and synchronize with the server to make sure we agree. */
13346 FRAME_ICONIFIED_P (f
) = 0;
13347 f
->async_visible
= 0;
13348 f
->async_iconified
= 0;
13355 /* Change window state from mapped to iconified. */
13358 x_iconify_frame (f
)
13364 /* Don't keep the highlight on an invisible frame. */
13365 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
13366 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
13368 if (f
->async_iconified
)
13373 FRAME_SAMPLE_VISIBILITY (f
);
13375 type
= x_icon_type (f
);
13377 x_bitmap_icon (f
, type
);
13379 #ifdef USE_X_TOOLKIT
13381 if (! FRAME_VISIBLE_P (f
))
13383 if (! EQ (Vx_no_window_manager
, Qt
))
13384 x_wm_set_window_state (f
, IconicState
);
13385 /* This was XtPopup, but that did nothing for an iconified frame. */
13386 XtMapWidget (f
->output_data
.x
->widget
);
13387 /* The server won't give us any event to indicate
13388 that an invisible frame was changed to an icon,
13389 so we have to record it here. */
13392 f
->async_iconified
= 1;
13393 f
->async_visible
= 0;
13398 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
13399 XtWindow (f
->output_data
.x
->widget
),
13400 DefaultScreen (FRAME_X_DISPLAY (f
)));
13404 error ("Can't notify window manager of iconification");
13406 f
->async_iconified
= 1;
13407 f
->async_visible
= 0;
13411 XFlush (FRAME_X_DISPLAY (f
));
13413 #else /* not USE_X_TOOLKIT */
13415 /* Make sure the X server knows where the window should be positioned,
13416 in case the user deiconifies with the window manager. */
13417 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
13418 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
13420 /* Since we don't know which revision of X we're running, we'll use both
13421 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
13423 /* X11R4: send a ClientMessage to the window manager using the
13424 WM_CHANGE_STATE type. */
13428 message
.xclient
.window
= FRAME_X_WINDOW (f
);
13429 message
.xclient
.type
= ClientMessage
;
13430 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
13431 message
.xclient
.format
= 32;
13432 message
.xclient
.data
.l
[0] = IconicState
;
13434 if (! XSendEvent (FRAME_X_DISPLAY (f
),
13435 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
13437 SubstructureRedirectMask
| SubstructureNotifyMask
,
13440 UNBLOCK_INPUT_RESIGNAL
;
13441 error ("Can't notify window manager of iconification");
13445 /* X11R3: set the initial_state field of the window manager hints to
13447 x_wm_set_window_state (f
, IconicState
);
13449 if (!FRAME_VISIBLE_P (f
))
13451 /* If the frame was withdrawn, before, we must map it. */
13452 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13455 f
->async_iconified
= 1;
13456 f
->async_visible
= 0;
13458 XFlush (FRAME_X_DISPLAY (f
));
13460 #endif /* not USE_X_TOOLKIT */
13464 /* Free X resources of frame F. */
13467 x_free_frame_resources (f
)
13470 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13472 struct scroll_bar
*b
;
13476 /* If a display connection is dead, don't try sending more
13477 commands to the X server. */
13478 if (dpyinfo
->display
)
13480 if (f
->output_data
.x
->icon_desc
)
13481 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
13483 #ifdef USE_X_TOOLKIT
13484 /* Explicitly destroy the scroll bars of the frame. Without
13485 this, we get "BadDrawable" errors from the toolkit later on,
13486 presumably from expose events generated for the disappearing
13487 toolkit scroll bars. */
13488 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
13490 b
= XSCROLL_BAR (bar
);
13491 x_scroll_bar_remove (b
);
13497 free_frame_xic (f
);
13500 #ifdef USE_X_TOOLKIT
13501 if (f
->output_data
.x
->widget
)
13503 XtDestroyWidget (f
->output_data
.x
->widget
);
13504 f
->output_data
.x
->widget
= NULL
;
13506 /* Tooltips don't have widgets, only a simple X window, even if
13507 we are using a toolkit. */
13508 else if (FRAME_X_WINDOW (f
))
13509 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13511 free_frame_menubar (f
);
13512 #else /* !USE_X_TOOLKIT */
13513 if (FRAME_X_WINDOW (f
))
13514 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13515 #endif /* !USE_X_TOOLKIT */
13517 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
13518 unload_color (f
, f
->output_data
.x
->background_pixel
);
13519 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
13520 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
13521 unload_color (f
, f
->output_data
.x
->border_pixel
);
13522 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
13524 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
13525 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
13526 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
13527 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
13528 #ifdef USE_TOOLKIT_SCROLL_BARS
13529 /* Scrollbar shadow colors. */
13530 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
13531 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
13532 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
13533 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
13534 #endif /* USE_TOOLKIT_SCROLL_BARS */
13535 if (f
->output_data
.x
->white_relief
.allocated_p
)
13536 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
13537 if (f
->output_data
.x
->black_relief
.allocated_p
)
13538 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
13540 if (FRAME_FACE_CACHE (f
))
13541 free_frame_faces (f
);
13544 XFlush (FRAME_X_DISPLAY (f
));
13547 if (f
->output_data
.x
->saved_menu_event
)
13548 xfree (f
->output_data
.x
->saved_menu_event
);
13550 xfree (f
->output_data
.x
);
13551 f
->output_data
.x
= NULL
;
13553 if (f
== dpyinfo
->x_focus_frame
)
13554 dpyinfo
->x_focus_frame
= 0;
13555 if (f
== dpyinfo
->x_focus_event_frame
)
13556 dpyinfo
->x_focus_event_frame
= 0;
13557 if (f
== dpyinfo
->x_highlight_frame
)
13558 dpyinfo
->x_highlight_frame
= 0;
13560 if (f
== dpyinfo
->mouse_face_mouse_frame
)
13562 dpyinfo
->mouse_face_beg_row
13563 = dpyinfo
->mouse_face_beg_col
= -1;
13564 dpyinfo
->mouse_face_end_row
13565 = dpyinfo
->mouse_face_end_col
= -1;
13566 dpyinfo
->mouse_face_window
= Qnil
;
13567 dpyinfo
->mouse_face_deferred_gc
= 0;
13568 dpyinfo
->mouse_face_mouse_frame
= 0;
13575 /* Destroy the X window of frame F. */
13578 x_destroy_window (f
)
13581 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13583 /* If a display connection is dead, don't try sending more
13584 commands to the X server. */
13585 if (dpyinfo
->display
!= 0)
13586 x_free_frame_resources (f
);
13588 dpyinfo
->reference_count
--;
13592 /* Setting window manager hints. */
13594 /* Set the normal size hints for the window manager, for frame F.
13595 FLAGS is the flags word to use--or 0 meaning preserve the flags
13596 that the window now has.
13597 If USER_POSITION is nonzero, we set the USPosition
13598 flag (this is useful when FLAGS is 0). */
13601 x_wm_set_size_hint (f
, flags
, user_position
)
13606 XSizeHints size_hints
;
13608 #ifdef USE_X_TOOLKIT
13611 Dimension widget_width
, widget_height
;
13612 Window window
= XtWindow (f
->output_data
.x
->widget
);
13613 #else /* not USE_X_TOOLKIT */
13614 Window window
= FRAME_X_WINDOW (f
);
13615 #endif /* not USE_X_TOOLKIT */
13617 /* Setting PMaxSize caused various problems. */
13618 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
13620 size_hints
.x
= f
->output_data
.x
->left_pos
;
13621 size_hints
.y
= f
->output_data
.x
->top_pos
;
13623 #ifdef USE_X_TOOLKIT
13624 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
13625 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
13626 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
13627 size_hints
.height
= widget_height
;
13628 size_hints
.width
= widget_width
;
13629 #else /* not USE_X_TOOLKIT */
13630 size_hints
.height
= PIXEL_HEIGHT (f
);
13631 size_hints
.width
= PIXEL_WIDTH (f
);
13632 #endif /* not USE_X_TOOLKIT */
13634 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
13635 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
13636 size_hints
.max_width
13637 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
13638 size_hints
.max_height
13639 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
13641 /* Calculate the base and minimum sizes.
13643 (When we use the X toolkit, we don't do it here.
13644 Instead we copy the values that the widgets are using, below.) */
13645 #ifndef USE_X_TOOLKIT
13647 int base_width
, base_height
;
13648 int min_rows
= 0, min_cols
= 0;
13650 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
13651 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
13653 check_frame_size (f
, &min_rows
, &min_cols
);
13655 /* The window manager uses the base width hints to calculate the
13656 current number of rows and columns in the frame while
13657 resizing; min_width and min_height aren't useful for this
13658 purpose, since they might not give the dimensions for a
13659 zero-row, zero-column frame.
13661 We use the base_width and base_height members if we have
13662 them; otherwise, we set the min_width and min_height members
13663 to the size for a zero x zero frame. */
13666 size_hints
.flags
|= PBaseSize
;
13667 size_hints
.base_width
= base_width
;
13668 size_hints
.base_height
= base_height
;
13669 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
13670 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
13672 size_hints
.min_width
= base_width
;
13673 size_hints
.min_height
= base_height
;
13677 /* If we don't need the old flags, we don't need the old hint at all. */
13680 size_hints
.flags
|= flags
;
13683 #endif /* not USE_X_TOOLKIT */
13686 XSizeHints hints
; /* Sometimes I hate X Windows... */
13687 long supplied_return
;
13691 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
13694 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
13697 #ifdef USE_X_TOOLKIT
13698 size_hints
.base_height
= hints
.base_height
;
13699 size_hints
.base_width
= hints
.base_width
;
13700 size_hints
.min_height
= hints
.min_height
;
13701 size_hints
.min_width
= hints
.min_width
;
13705 size_hints
.flags
|= flags
;
13710 if (hints
.flags
& PSize
)
13711 size_hints
.flags
|= PSize
;
13712 if (hints
.flags
& PPosition
)
13713 size_hints
.flags
|= PPosition
;
13714 if (hints
.flags
& USPosition
)
13715 size_hints
.flags
|= USPosition
;
13716 if (hints
.flags
& USSize
)
13717 size_hints
.flags
|= USSize
;
13721 #ifndef USE_X_TOOLKIT
13726 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
13727 size_hints
.flags
|= PWinGravity
;
13731 size_hints
.flags
&= ~ PPosition
;
13732 size_hints
.flags
|= USPosition
;
13734 #endif /* PWinGravity */
13737 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
13739 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
13743 /* Used for IconicState or NormalState */
13746 x_wm_set_window_state (f
, state
)
13750 #ifdef USE_X_TOOLKIT
13753 XtSetArg (al
[0], XtNinitialState
, state
);
13754 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
13755 #else /* not USE_X_TOOLKIT */
13756 Window window
= FRAME_X_WINDOW (f
);
13758 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
13759 f
->output_data
.x
->wm_hints
.initial_state
= state
;
13761 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
13762 #endif /* not USE_X_TOOLKIT */
13766 x_wm_set_icon_pixmap (f
, pixmap_id
)
13770 Pixmap icon_pixmap
;
13772 #ifndef USE_X_TOOLKIT
13773 Window window
= FRAME_X_WINDOW (f
);
13778 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
13779 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
13783 /* It seems there is no way to turn off use of an icon pixmap.
13784 The following line does it, only if no icon has yet been created,
13785 for some window managers. But with mwm it crashes.
13786 Some people say it should clear the IconPixmapHint bit in this case,
13787 but that doesn't work, and the X consortium said it isn't the
13788 right thing at all. Since there is no way to win,
13789 best to explicitly give up. */
13791 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
13797 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
13801 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
13802 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
13805 #else /* not USE_X_TOOLKIT */
13807 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
13808 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
13810 #endif /* not USE_X_TOOLKIT */
13814 x_wm_set_icon_position (f
, icon_x
, icon_y
)
13816 int icon_x
, icon_y
;
13818 #ifdef USE_X_TOOLKIT
13819 Window window
= XtWindow (f
->output_data
.x
->widget
);
13821 Window window
= FRAME_X_WINDOW (f
);
13824 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
13825 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
13826 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
13828 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
13832 /***********************************************************************
13834 ***********************************************************************/
13836 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
13839 x_get_font_info (f
, font_idx
)
13843 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
13847 /* Return a list of names of available fonts matching PATTERN on frame F.
13849 If SIZE is > 0, it is the size (maximum bounds width) of fonts
13852 SIZE < 0 means include scalable fonts.
13854 Frame F null means we have not yet created any frame on X, and
13855 consult the first display in x_display_list. MAXNAMES sets a limit
13856 on how many fonts to match. */
13859 x_list_fonts (f
, pattern
, size
, maxnames
)
13861 Lisp_Object pattern
;
13865 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
13866 Lisp_Object tem
, second_best
;
13867 struct x_display_info
*dpyinfo
13868 = f
? FRAME_X_DISPLAY_INFO (f
) : x_display_list
;
13869 Display
*dpy
= dpyinfo
->display
;
13870 int try_XLoadQueryFont
= 0;
13872 int allow_scalable_fonts_p
= 0;
13876 allow_scalable_fonts_p
= 1;
13880 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
13881 if (NILP (patterns
))
13882 patterns
= Fcons (pattern
, Qnil
);
13884 if (maxnames
== 1 && !size
)
13885 /* We can return any single font matching PATTERN. */
13886 try_XLoadQueryFont
= 1;
13888 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
13891 char **names
= NULL
;
13893 pattern
= XCAR (patterns
);
13894 /* See if we cached the result for this particular query.
13895 The cache is an alist of the form:
13896 ((((PATTERN . MAXNAMES) . SCALABLE) (FONTNAME . WIDTH) ...) ...) */
13897 tem
= XCDR (dpyinfo
->name_list_element
);
13898 key
= Fcons (Fcons (pattern
, make_number (maxnames
)),
13899 allow_scalable_fonts_p
? Qt
: Qnil
);
13900 list
= Fassoc (key
, tem
);
13903 list
= Fcdr_safe (list
);
13904 /* We have a cashed list. Don't have to get the list again. */
13908 /* At first, put PATTERN in the cache. */
13911 count
= x_catch_errors (dpy
);
13913 if (try_XLoadQueryFont
)
13916 unsigned long value
;
13918 font
= XLoadQueryFont (dpy
, XSTRING (pattern
)->data
);
13919 if (x_had_errors_p (dpy
))
13921 /* This error is perhaps due to insufficient memory on X
13922 server. Let's just ignore it. */
13924 x_clear_errors (dpy
);
13928 && XGetFontProperty (font
, XA_FONT
, &value
))
13930 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
13931 int len
= strlen (name
);
13934 /* If DXPC (a Differential X Protocol Compressor)
13935 Ver.3.7 is running, XGetAtomName will return null
13936 string. We must avoid such a name. */
13938 try_XLoadQueryFont
= 0;
13942 names
= (char **) alloca (sizeof (char *));
13943 /* Some systems only allow alloca assigned to a
13945 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
13946 bcopy (name
, names
[0], len
+ 1);
13951 try_XLoadQueryFont
= 0;
13954 XFreeFont (dpy
, font
);
13957 if (!try_XLoadQueryFont
)
13959 /* We try at least 10 fonts because XListFonts will return
13960 auto-scaled fonts at the head. */
13961 names
= XListFonts (dpy
, XSTRING (pattern
)->data
, max (maxnames
, 10),
13963 if (x_had_errors_p (dpy
))
13965 /* This error is perhaps due to insufficient memory on X
13966 server. Let's just ignore it. */
13968 x_clear_errors (dpy
);
13972 x_uncatch_errors (dpy
, count
);
13979 /* Make a list of all the fonts we got back.
13980 Store that in the font cache for the display. */
13981 for (i
= 0; i
< num_fonts
; i
++)
13984 char *p
= names
[i
];
13985 int average_width
= -1, dashes
= 0;
13987 /* Count the number of dashes in NAMES[I]. If there are
13988 14 dashes, and the field value following 12th dash
13989 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
13990 is usually too ugly to be used for editing. Let's
13996 if (dashes
== 7) /* PIXEL_SIZE field */
13998 else if (dashes
== 12) /* AVERAGE_WIDTH field */
13999 average_width
= atoi (p
);
14002 if (allow_scalable_fonts_p
14003 || dashes
< 14 || average_width
!= 0)
14005 tem
= build_string (names
[i
]);
14006 if (NILP (Fassoc (tem
, list
)))
14008 if (STRINGP (Vx_pixel_size_width_font_regexp
)
14009 && ((fast_c_string_match_ignore_case
14010 (Vx_pixel_size_width_font_regexp
, names
[i
]))
14012 /* We can set the value of PIXEL_SIZE to the
14013 width of this font. */
14014 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
14016 /* For the moment, width is not known. */
14017 list
= Fcons (Fcons (tem
, Qnil
), list
);
14022 if (!try_XLoadQueryFont
)
14025 XFreeFontNames (names
);
14030 /* Now store the result in the cache. */
14031 XSETCDR (dpyinfo
->name_list_element
,
14032 Fcons (Fcons (key
, list
), XCDR (dpyinfo
->name_list_element
)));
14035 if (NILP (list
)) continue; /* Try the remaining alternatives. */
14037 newlist
= second_best
= Qnil
;
14038 /* Make a list of the fonts that have the right width. */
14039 for (; CONSP (list
); list
= XCDR (list
))
14045 if (!CONSP (tem
) || NILP (XCAR (tem
)))
14049 newlist
= Fcons (XCAR (tem
), newlist
);
14053 if (!INTEGERP (XCDR (tem
)))
14055 /* Since we have not yet known the size of this font, we
14056 must try slow function call XLoadQueryFont. */
14057 XFontStruct
*thisinfo
;
14060 count
= x_catch_errors (dpy
);
14061 thisinfo
= XLoadQueryFont (dpy
,
14062 XSTRING (XCAR (tem
))->data
);
14063 if (x_had_errors_p (dpy
))
14065 /* This error is perhaps due to insufficient memory on X
14066 server. Let's just ignore it. */
14068 x_clear_errors (dpy
);
14070 x_uncatch_errors (dpy
, count
);
14076 (thisinfo
->min_bounds
.width
== 0
14078 : make_number (thisinfo
->max_bounds
.width
)));
14080 XFreeFont (dpy
, thisinfo
);
14084 /* For unknown reason, the previous call of XListFont had
14085 returned a font which can't be opened. Record the size
14086 as 0 not to try to open it again. */
14087 XSETCDR (tem
, make_number (0));
14090 found_size
= XINT (XCDR (tem
));
14091 if (found_size
== size
)
14092 newlist
= Fcons (XCAR (tem
), newlist
);
14093 else if (found_size
> 0)
14095 if (NILP (second_best
))
14097 else if (found_size
< size
)
14099 if (XINT (XCDR (second_best
)) > size
14100 || XINT (XCDR (second_best
)) < found_size
)
14105 if (XINT (XCDR (second_best
)) > size
14106 && XINT (XCDR (second_best
)) > found_size
)
14111 if (!NILP (newlist
))
14113 else if (!NILP (second_best
))
14115 newlist
= Fcons (XCAR (second_best
), Qnil
);
14126 /* Check that FONT is valid on frame F. It is if it can be found in F's
14130 x_check_font (f
, font
)
14135 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14137 xassert (font
!= NULL
);
14139 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
14140 if (dpyinfo
->font_table
[i
].name
14141 && font
== dpyinfo
->font_table
[i
].font
)
14144 xassert (i
< dpyinfo
->n_fonts
);
14147 #endif /* GLYPH_DEBUG != 0 */
14149 /* Set *W to the minimum width, *H to the minimum font height of FONT.
14150 Note: There are (broken) X fonts out there with invalid XFontStruct
14151 min_bounds contents. For example, handa@etl.go.jp reports that
14152 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
14153 have font->min_bounds.width == 0. */
14156 x_font_min_bounds (font
, w
, h
)
14160 *h
= FONT_HEIGHT (font
);
14161 *w
= font
->min_bounds
.width
;
14163 /* Try to handle the case where FONT->min_bounds has invalid
14164 contents. Since the only font known to have invalid min_bounds
14165 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
14167 *w
= font
->max_bounds
.width
;
14171 /* Compute the smallest character width and smallest font height over
14172 all fonts available on frame F. Set the members smallest_char_width
14173 and smallest_font_height in F's x_display_info structure to
14174 the values computed. Value is non-zero if smallest_font_height or
14175 smallest_char_width become smaller than they were before. */
14178 x_compute_min_glyph_bounds (f
)
14182 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14184 int old_width
= dpyinfo
->smallest_char_width
;
14185 int old_height
= dpyinfo
->smallest_font_height
;
14187 dpyinfo
->smallest_font_height
= 100000;
14188 dpyinfo
->smallest_char_width
= 100000;
14190 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
14191 if (dpyinfo
->font_table
[i
].name
)
14193 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
14196 font
= (XFontStruct
*) fontp
->font
;
14197 xassert (font
!= (XFontStruct
*) ~0);
14198 x_font_min_bounds (font
, &w
, &h
);
14200 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
14201 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
14204 xassert (dpyinfo
->smallest_char_width
> 0
14205 && dpyinfo
->smallest_font_height
> 0);
14207 return (dpyinfo
->n_fonts
== 1
14208 || dpyinfo
->smallest_char_width
< old_width
14209 || dpyinfo
->smallest_font_height
< old_height
);
14213 /* Load font named FONTNAME of the size SIZE for frame F, and return a
14214 pointer to the structure font_info while allocating it dynamically.
14215 If SIZE is 0, load any size of font.
14216 If loading is failed, return NULL. */
14219 x_load_font (f
, fontname
, size
)
14221 register char *fontname
;
14224 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14225 Lisp_Object font_names
;
14228 /* Get a list of all the fonts that match this name. Once we
14229 have a list of matching fonts, we compare them against the fonts
14230 we already have by comparing names. */
14231 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
14233 if (!NILP (font_names
))
14238 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
14239 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
14240 if (dpyinfo
->font_table
[i
].name
14241 && (!strcmp (dpyinfo
->font_table
[i
].name
,
14242 XSTRING (XCAR (tail
))->data
)
14243 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
14244 XSTRING (XCAR (tail
))->data
)))
14245 return (dpyinfo
->font_table
+ i
);
14248 /* Load the font and add it to the table. */
14252 struct font_info
*fontp
;
14253 unsigned long value
;
14256 /* If we have found fonts by x_list_font, load one of them. If
14257 not, we still try to load a font by the name given as FONTNAME
14258 because XListFonts (called in x_list_font) of some X server has
14259 a bug of not finding a font even if the font surely exists and
14260 is loadable by XLoadQueryFont. */
14261 if (size
> 0 && !NILP (font_names
))
14262 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
14265 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
14266 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
14267 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
14269 /* This error is perhaps due to insufficient memory on X
14270 server. Let's just ignore it. */
14272 x_clear_errors (FRAME_X_DISPLAY (f
));
14274 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
14279 /* Find a free slot in the font table. */
14280 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
14281 if (dpyinfo
->font_table
[i
].name
== NULL
)
14284 /* If no free slot found, maybe enlarge the font table. */
14285 if (i
== dpyinfo
->n_fonts
14286 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
14289 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
14290 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
14291 dpyinfo
->font_table
14292 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
14295 fontp
= dpyinfo
->font_table
+ i
;
14296 if (i
== dpyinfo
->n_fonts
)
14297 ++dpyinfo
->n_fonts
;
14299 /* Now fill in the slots of *FONTP. */
14301 fontp
->font
= font
;
14302 fontp
->font_idx
= i
;
14303 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
14304 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
14306 /* Try to get the full name of FONT. Put it in FULL_NAME. */
14308 if (XGetFontProperty (font
, XA_FONT
, &value
))
14310 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
14314 /* Count the number of dashes in the "full name".
14315 If it is too few, this isn't really the font's full name,
14317 In X11R4, the fonts did not come with their canonical names
14328 full_name
= (char *) xmalloc (p
- name
+ 1);
14329 bcopy (name
, full_name
, p
- name
+ 1);
14335 if (full_name
!= 0)
14336 fontp
->full_name
= full_name
;
14338 fontp
->full_name
= fontp
->name
;
14340 fontp
->size
= font
->max_bounds
.width
;
14341 fontp
->height
= FONT_HEIGHT (font
);
14343 if (NILP (font_names
))
14345 /* We come here because of a bug of XListFonts mentioned at
14346 the head of this block. Let's store this information in
14347 the cache for x_list_fonts. */
14348 Lisp_Object lispy_name
= build_string (fontname
);
14349 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
14350 Lisp_Object key
= Fcons (Fcons (lispy_name
, make_number (256)),
14353 XSETCDR (dpyinfo
->name_list_element
,
14355 Fcons (Fcons (lispy_full_name
,
14356 make_number (fontp
->size
)),
14358 XCDR (dpyinfo
->name_list_element
)));
14361 key
= Fcons (Fcons (lispy_full_name
, make_number (256)),
14363 XSETCDR (dpyinfo
->name_list_element
,
14365 Fcons (Fcons (lispy_full_name
,
14366 make_number (fontp
->size
)),
14368 XCDR (dpyinfo
->name_list_element
)));
14372 /* The slot `encoding' specifies how to map a character
14373 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
14374 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
14375 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
14376 2:0xA020..0xFF7F). For the moment, we don't know which charset
14377 uses this font. So, we set information in fontp->encoding[1]
14378 which is never used by any charset. If mapping can't be
14379 decided, set FONT_ENCODING_NOT_DECIDED. */
14381 = (font
->max_byte1
== 0
14383 ? (font
->min_char_or_byte2
< 0x80
14384 ? (font
->max_char_or_byte2
< 0x80
14385 ? 0 /* 0x20..0x7F */
14386 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
14387 : 1) /* 0xA0..0xFF */
14389 : (font
->min_byte1
< 0x80
14390 ? (font
->max_byte1
< 0x80
14391 ? (font
->min_char_or_byte2
< 0x80
14392 ? (font
->max_char_or_byte2
< 0x80
14393 ? 0 /* 0x2020..0x7F7F */
14394 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
14395 : 3) /* 0x20A0..0x7FFF */
14396 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
14397 : (font
->min_char_or_byte2
< 0x80
14398 ? (font
->max_char_or_byte2
< 0x80
14399 ? 2 /* 0xA020..0xFF7F */
14400 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
14401 : 1))); /* 0xA0A0..0xFFFF */
14403 fontp
->baseline_offset
14404 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
14405 ? (long) value
: 0);
14406 fontp
->relative_compose
14407 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
14408 ? (long) value
: 0);
14409 fontp
->default_ascent
14410 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
14411 ? (long) value
: 0);
14413 /* Set global flag fonts_changed_p to non-zero if the font loaded
14414 has a character with a smaller width than any other character
14415 before, or if the font loaded has a smaller height than any
14416 other font loaded before. If this happens, it will make a
14417 glyph matrix reallocation necessary. */
14418 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
14425 /* Return a pointer to struct font_info of a font named FONTNAME for
14426 frame F. If no such font is loaded, return NULL. */
14429 x_query_font (f
, fontname
)
14431 register char *fontname
;
14433 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14436 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
14437 if (dpyinfo
->font_table
[i
].name
14438 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
14439 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
14440 return (dpyinfo
->font_table
+ i
);
14445 /* Find a CCL program for a font specified by FONTP, and set the member
14446 `encoder' of the structure. */
14449 x_find_ccl_program (fontp
)
14450 struct font_info
*fontp
;
14452 Lisp_Object list
, elt
;
14455 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
14459 && STRINGP (XCAR (elt
))
14460 && ((fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
14462 || (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->full_name
)
14469 struct ccl_program
*ccl
14470 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
14472 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
14475 fontp
->font_encoder
= ccl
;
14481 /***********************************************************************
14483 ***********************************************************************/
14485 #ifdef USE_X_TOOLKIT
14486 static XrmOptionDescRec emacs_options
[] = {
14487 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
14488 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
14490 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
14491 XrmoptionSepArg
, NULL
},
14492 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
14494 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
14495 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
14496 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
14497 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
14498 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
14499 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
14500 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
14502 #endif /* USE_X_TOOLKIT */
14504 static int x_initialized
;
14506 #ifdef MULTI_KBOARD
14507 /* Test whether two display-name strings agree up to the dot that separates
14508 the screen number from the server number. */
14510 same_x_server (name1
, name2
)
14511 char *name1
, *name2
;
14513 int seen_colon
= 0;
14514 unsigned char *system_name
= XSTRING (Vsystem_name
)->data
;
14515 int system_name_length
= strlen (system_name
);
14516 int length_until_period
= 0;
14518 while (system_name
[length_until_period
] != 0
14519 && system_name
[length_until_period
] != '.')
14520 length_until_period
++;
14522 /* Treat `unix' like an empty host name. */
14523 if (! strncmp (name1
, "unix:", 5))
14525 if (! strncmp (name2
, "unix:", 5))
14527 /* Treat this host's name like an empty host name. */
14528 if (! strncmp (name1
, system_name
, system_name_length
)
14529 && name1
[system_name_length
] == ':')
14530 name1
+= system_name_length
;
14531 if (! strncmp (name2
, system_name
, system_name_length
)
14532 && name2
[system_name_length
] == ':')
14533 name2
+= system_name_length
;
14534 /* Treat this host's domainless name like an empty host name. */
14535 if (! strncmp (name1
, system_name
, length_until_period
)
14536 && name1
[length_until_period
] == ':')
14537 name1
+= length_until_period
;
14538 if (! strncmp (name2
, system_name
, length_until_period
)
14539 && name2
[length_until_period
] == ':')
14540 name2
+= length_until_period
;
14542 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
14546 if (seen_colon
&& *name1
== '.')
14550 && (*name1
== '.' || *name1
== '\0')
14551 && (*name2
== '.' || *name2
== '\0'));
14555 struct x_display_info
*
14556 x_term_init (display_name
, xrm_option
, resource_name
)
14557 Lisp_Object display_name
;
14559 char *resource_name
;
14563 struct x_display_info
*dpyinfo
;
14568 if (!x_initialized
)
14574 #ifdef USE_X_TOOLKIT
14575 /* weiner@footloose.sps.mot.com reports that this causes
14577 X protocol error: BadAtom (invalid Atom parameter)
14578 on protocol request 18skiloaf.
14579 So let's not use it until R6. */
14580 #ifdef HAVE_X11XTR6
14581 XtSetLanguageProc (NULL
, NULL
, NULL
);
14592 argv
[argc
++] = "-xrm";
14593 argv
[argc
++] = xrm_option
;
14595 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
14596 resource_name
, EMACS_CLASS
,
14597 emacs_options
, XtNumber (emacs_options
),
14600 #ifdef HAVE_X11XTR6
14601 /* I think this is to compensate for XtSetLanguageProc. */
14606 #else /* not USE_X_TOOLKIT */
14608 XSetLocaleModifiers ("");
14610 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
14611 #endif /* not USE_X_TOOLKIT */
14613 /* Detect failure. */
14620 /* We have definitely succeeded. Record the new connection. */
14622 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
14623 bzero (dpyinfo
, sizeof *dpyinfo
);
14625 #ifdef MULTI_KBOARD
14627 struct x_display_info
*share
;
14630 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
14631 share
= share
->next
, tail
= XCDR (tail
))
14632 if (same_x_server (XSTRING (XCAR (XCAR (tail
)))->data
,
14633 XSTRING (display_name
)->data
))
14636 dpyinfo
->kboard
= share
->kboard
;
14639 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
14640 init_kboard (dpyinfo
->kboard
);
14641 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
14643 char *vendor
= ServerVendor (dpy
);
14645 dpyinfo
->kboard
->Vsystem_key_alist
14646 = call1 (Qvendor_specific_keysyms
,
14647 build_string (vendor
? vendor
: ""));
14651 dpyinfo
->kboard
->next_kboard
= all_kboards
;
14652 all_kboards
= dpyinfo
->kboard
;
14653 /* Don't let the initial kboard remain current longer than necessary.
14654 That would cause problems if a file loaded on startup tries to
14655 prompt in the mini-buffer. */
14656 if (current_kboard
== initial_kboard
)
14657 current_kboard
= dpyinfo
->kboard
;
14659 dpyinfo
->kboard
->reference_count
++;
14663 /* Put this display on the chain. */
14664 dpyinfo
->next
= x_display_list
;
14665 x_display_list
= dpyinfo
;
14667 /* Put it on x_display_name_list as well, to keep them parallel. */
14668 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
14669 x_display_name_list
);
14670 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
14672 dpyinfo
->display
= dpy
;
14675 XSetAfterFunction (x_current_display
, x_trace_wire
);
14679 = (char *) xmalloc (STRING_BYTES (XSTRING (Vinvocation_name
))
14680 + STRING_BYTES (XSTRING (Vsystem_name
))
14682 sprintf (dpyinfo
->x_id_name
, "%s@%s",
14683 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
14685 /* Figure out which modifier bits mean what. */
14686 x_find_modifier_meanings (dpyinfo
);
14688 /* Get the scroll bar cursor. */
14689 dpyinfo
->vertical_scroll_bar_cursor
14690 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
14692 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
14693 resource_name
, EMACS_CLASS
);
14694 #ifdef HAVE_XRMSETDATABASE
14695 XrmSetDatabase (dpyinfo
->display
, xrdb
);
14697 dpyinfo
->display
->db
= xrdb
;
14699 /* Put the rdb where we can find it in a way that works on
14701 dpyinfo
->xrdb
= xrdb
;
14703 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
14704 DefaultScreen (dpyinfo
->display
));
14705 select_visual (dpyinfo
);
14706 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
14707 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
14708 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
14709 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
14710 dpyinfo
->grabbed
= 0;
14711 dpyinfo
->reference_count
= 0;
14712 dpyinfo
->icon_bitmap_id
= -1;
14713 dpyinfo
->font_table
= NULL
;
14714 dpyinfo
->n_fonts
= 0;
14715 dpyinfo
->font_table_size
= 0;
14716 dpyinfo
->bitmaps
= 0;
14717 dpyinfo
->bitmaps_size
= 0;
14718 dpyinfo
->bitmaps_last
= 0;
14719 dpyinfo
->scratch_cursor_gc
= 0;
14720 dpyinfo
->mouse_face_mouse_frame
= 0;
14721 dpyinfo
->mouse_face_deferred_gc
= 0;
14722 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
14723 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
14724 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
14725 dpyinfo
->mouse_face_window
= Qnil
;
14726 dpyinfo
->mouse_face_overlay
= Qnil
;
14727 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
14728 dpyinfo
->mouse_face_defer
= 0;
14729 dpyinfo
->mouse_face_hidden
= 0;
14730 dpyinfo
->x_focus_frame
= 0;
14731 dpyinfo
->x_focus_event_frame
= 0;
14732 dpyinfo
->x_highlight_frame
= 0;
14733 dpyinfo
->image_cache
= make_image_cache ();
14735 /* See if a private colormap is requested. */
14736 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
14738 if (dpyinfo
->visual
->class == PseudoColor
)
14741 value
= display_x_get_resource (dpyinfo
,
14742 build_string ("privateColormap"),
14743 build_string ("PrivateColormap"),
14745 if (STRINGP (value
)
14746 && (!strcmp (XSTRING (value
)->data
, "true")
14747 || !strcmp (XSTRING (value
)->data
, "on")))
14748 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
14752 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
14753 dpyinfo
->visual
, AllocNone
);
14756 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
14757 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
14758 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
14759 dpyinfo
->resy
= pixels
* 25.4 / mm
;
14760 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
14761 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
14762 dpyinfo
->resx
= pixels
* 25.4 / mm
;
14765 dpyinfo
->Xatom_wm_protocols
14766 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
14767 dpyinfo
->Xatom_wm_take_focus
14768 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
14769 dpyinfo
->Xatom_wm_save_yourself
14770 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
14771 dpyinfo
->Xatom_wm_delete_window
14772 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
14773 dpyinfo
->Xatom_wm_change_state
14774 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
14775 dpyinfo
->Xatom_wm_configure_denied
14776 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
14777 dpyinfo
->Xatom_wm_window_moved
14778 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
14779 dpyinfo
->Xatom_editres
14780 = XInternAtom (dpyinfo
->display
, "Editres", False
);
14781 dpyinfo
->Xatom_CLIPBOARD
14782 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
14783 dpyinfo
->Xatom_TIMESTAMP
14784 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
14785 dpyinfo
->Xatom_TEXT
14786 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
14787 dpyinfo
->Xatom_COMPOUND_TEXT
14788 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
14789 dpyinfo
->Xatom_DELETE
14790 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
14791 dpyinfo
->Xatom_MULTIPLE
14792 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
14793 dpyinfo
->Xatom_INCR
14794 = XInternAtom (dpyinfo
->display
, "INCR", False
);
14795 dpyinfo
->Xatom_EMACS_TMP
14796 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
14797 dpyinfo
->Xatom_TARGETS
14798 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
14799 dpyinfo
->Xatom_NULL
14800 = XInternAtom (dpyinfo
->display
, "NULL", False
);
14801 dpyinfo
->Xatom_ATOM_PAIR
14802 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
14803 /* For properties of font. */
14804 dpyinfo
->Xatom_PIXEL_SIZE
14805 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
14806 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
14807 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
14808 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
14809 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
14810 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
14811 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
14813 /* Ghostscript support. */
14814 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
14815 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
14817 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
14820 dpyinfo
->cut_buffers_initialized
= 0;
14822 connection
= ConnectionNumber (dpyinfo
->display
);
14823 dpyinfo
->connection
= connection
;
14828 null_bits
[0] = 0x00;
14830 dpyinfo
->null_pixel
14831 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
14832 null_bits
, 1, 1, (long) 0, (long) 0,
14837 extern int gray_bitmap_width
, gray_bitmap_height
;
14838 extern char *gray_bitmap_bits
;
14840 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
14842 gray_bitmap_width
, gray_bitmap_height
,
14843 (unsigned long) 1, (unsigned long) 0, 1);
14847 xim_initialize (dpyinfo
, resource_name
);
14850 #ifdef subprocesses
14851 /* This is only needed for distinguishing keyboard and process input. */
14852 if (connection
!= 0)
14853 add_keyboard_wait_descriptor (connection
);
14856 #ifndef F_SETOWN_BUG
14858 #ifdef F_SETOWN_SOCK_NEG
14859 /* stdin is a socket here */
14860 fcntl (connection
, F_SETOWN
, -getpid ());
14861 #else /* ! defined (F_SETOWN_SOCK_NEG) */
14862 fcntl (connection
, F_SETOWN
, getpid ());
14863 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
14864 #endif /* ! defined (F_SETOWN) */
14865 #endif /* F_SETOWN_BUG */
14868 if (interrupt_input
)
14869 init_sigio (connection
);
14870 #endif /* ! defined (SIGIO) */
14873 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
14874 /* Make sure that we have a valid font for dialog boxes
14875 so that Xt does not crash. */
14877 Display
*dpy
= dpyinfo
->display
;
14878 XrmValue d
, fr
, to
;
14882 d
.addr
= (XPointer
)&dpy
;
14883 d
.size
= sizeof (Display
*);
14884 fr
.addr
= XtDefaultFont
;
14885 fr
.size
= sizeof (XtDefaultFont
);
14886 to
.size
= sizeof (Font
*);
14887 to
.addr
= (XPointer
)&font
;
14888 count
= x_catch_errors (dpy
);
14889 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
14891 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
14892 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
14893 x_uncatch_errors (dpy
, count
);
14898 /* See if we should run in synchronous mode. This is useful
14899 for debugging X code. */
14902 value
= display_x_get_resource (dpyinfo
,
14903 build_string ("synchronous"),
14904 build_string ("Synchronous"),
14906 if (STRINGP (value
)
14907 && (!strcmp (XSTRING (value
)->data
, "true")
14908 || !strcmp (XSTRING (value
)->data
, "on")))
14909 XSynchronize (dpyinfo
->display
, True
);
14917 /* Get rid of display DPYINFO, assuming all frames are already gone,
14918 and without sending any more commands to the X server. */
14921 x_delete_display (dpyinfo
)
14922 struct x_display_info
*dpyinfo
;
14924 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
14926 /* Discard this display from x_display_name_list and x_display_list.
14927 We can't use Fdelq because that can quit. */
14928 if (! NILP (x_display_name_list
)
14929 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
14930 x_display_name_list
= XCDR (x_display_name_list
);
14935 tail
= x_display_name_list
;
14936 while (CONSP (tail
) && CONSP (XCDR (tail
)))
14938 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
14940 XSETCDR (tail
, XCDR (XCDR (tail
)));
14943 tail
= XCDR (tail
);
14947 if (next_noop_dpyinfo
== dpyinfo
)
14948 next_noop_dpyinfo
= dpyinfo
->next
;
14950 if (x_display_list
== dpyinfo
)
14951 x_display_list
= dpyinfo
->next
;
14954 struct x_display_info
*tail
;
14956 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
14957 if (tail
->next
== dpyinfo
)
14958 tail
->next
= tail
->next
->next
;
14961 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
14962 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
14963 XrmDestroyDatabase (dpyinfo
->xrdb
);
14966 #ifdef MULTI_KBOARD
14967 if (--dpyinfo
->kboard
->reference_count
== 0)
14968 delete_kboard (dpyinfo
->kboard
);
14972 xim_close_dpy (dpyinfo
);
14975 xfree (dpyinfo
->font_table
);
14976 xfree (dpyinfo
->x_id_name
);
14977 xfree (dpyinfo
->color_cells
);
14982 /* Set up use of X before we make the first connection. */
14984 static struct redisplay_interface x_redisplay_interface
=
14989 x_clear_end_of_line
,
14991 x_after_update_window_line
,
14992 x_update_window_begin
,
14993 x_update_window_end
,
14996 x_clear_mouse_face
,
14997 x_get_glyph_overhangs
,
14998 x_fix_overlapping_area
15004 rif
= &x_redisplay_interface
;
15006 clear_frame_hook
= x_clear_frame
;
15007 ins_del_lines_hook
= x_ins_del_lines
;
15008 delete_glyphs_hook
= x_delete_glyphs
;
15009 ring_bell_hook
= XTring_bell
;
15010 reset_terminal_modes_hook
= XTreset_terminal_modes
;
15011 set_terminal_modes_hook
= XTset_terminal_modes
;
15012 update_begin_hook
= x_update_begin
;
15013 update_end_hook
= x_update_end
;
15014 set_terminal_window_hook
= XTset_terminal_window
;
15015 read_socket_hook
= XTread_socket
;
15016 frame_up_to_date_hook
= XTframe_up_to_date
;
15017 mouse_position_hook
= XTmouse_position
;
15018 frame_rehighlight_hook
= XTframe_rehighlight
;
15019 frame_raise_lower_hook
= XTframe_raise_lower
;
15020 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
15021 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
15022 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
15023 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
15024 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
15026 scroll_region_ok
= 1; /* we'll scroll partial frames */
15027 char_ins_del_ok
= 1;
15028 line_ins_del_ok
= 1; /* we'll just blt 'em */
15029 fast_clear_end_of_line
= 1; /* X does this well */
15030 memory_below_frame
= 0; /* we don't remember what scrolls
15035 last_tool_bar_item
= -1;
15036 any_help_event_p
= 0;
15038 /* Try to use interrupt input; if we can't, then start polling. */
15039 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
15041 #ifdef USE_X_TOOLKIT
15042 XtToolkitInitialize ();
15044 Xt_app_con
= XtCreateApplicationContext ();
15046 /* Register a converter from strings to pixels, which uses
15047 Emacs' color allocation infrastructure. */
15048 XtAppSetTypeConverter (Xt_app_con
,
15049 XtRString
, XtRPixel
, cvt_string_to_pixel
,
15050 cvt_string_to_pixel_args
,
15051 XtNumber (cvt_string_to_pixel_args
),
15052 XtCacheByDisplay
, cvt_pixel_dtor
);
15054 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
15056 /* Install an asynchronous timer that processes Xt timeout events
15057 every 0.1s. This is necessary because some widget sets use
15058 timeouts internally, for example the LessTif menu bar, or the
15059 Xaw3d scroll bar. When Xt timouts aren't processed, these
15060 widgets don't behave normally. */
15062 EMACS_TIME interval
;
15063 EMACS_SET_SECS_USECS (interval
, 0, 100000);
15064 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
15068 #ifdef USE_TOOLKIT_SCROLL_BARS
15069 xaw3d_arrow_scroll
= False
;
15070 xaw3d_pick_top
= True
;
15073 /* Note that there is no real way portable across R3/R4 to get the
15074 original error handler. */
15075 XSetErrorHandler (x_error_handler
);
15076 XSetIOErrorHandler (x_io_error_quitter
);
15078 /* Disable Window Change signals; they are handled by X events. */
15080 signal (SIGWINCH
, SIG_DFL
);
15081 #endif /* ! defined (SIGWINCH) */
15083 signal (SIGPIPE
, x_connection_signal
);
15086 x_session_initialize ();
15094 staticpro (&x_error_message_string
);
15095 x_error_message_string
= Qnil
;
15097 staticpro (&x_display_name_list
);
15098 x_display_name_list
= Qnil
;
15100 staticpro (&last_mouse_scroll_bar
);
15101 last_mouse_scroll_bar
= Qnil
;
15103 staticpro (&Qvendor_specific_keysyms
);
15104 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
15106 staticpro (&last_mouse_press_frame
);
15107 last_mouse_press_frame
= Qnil
;
15110 staticpro (&help_echo
);
15111 help_echo_object
= Qnil
;
15112 staticpro (&help_echo_object
);
15113 help_echo_window
= Qnil
;
15114 staticpro (&help_echo_window
);
15115 previous_help_echo
= Qnil
;
15116 staticpro (&previous_help_echo
);
15117 help_echo_pos
= -1;
15119 DEFVAR_BOOL ("autoselect-window", &autoselect_window_p
,
15120 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
15121 autoselect_window_p
= 0;
15123 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
15124 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
15125 For example, if a block cursor is over a tab, it will be drawn as
15126 wide as that tab on the display. */);
15127 x_stretch_cursor_p
= 0;
15129 DEFVAR_BOOL ("x-use-underline-position-properties",
15130 &x_use_underline_position_properties
,
15131 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
15132 nil means ignore them. If you encounter fonts with bogus
15133 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
15134 to 4.1, set this to nil. */);
15135 x_use_underline_position_properties
= 1;
15137 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
15138 doc
: /* What X toolkit scroll bars Emacs uses.
15139 A value of nil means Emacs doesn't use X toolkit scroll bars.
15140 Otherwise, value is a symbol describing the X toolkit. */);
15141 #ifdef USE_TOOLKIT_SCROLL_BARS
15143 Vx_toolkit_scroll_bars
= intern ("motif");
15144 #elif defined HAVE_XAW3D
15145 Vx_toolkit_scroll_bars
= intern ("xaw3d");
15147 Vx_toolkit_scroll_bars
= intern ("xaw");
15150 Vx_toolkit_scroll_bars
= Qnil
;
15153 staticpro (&last_mouse_motion_frame
);
15154 last_mouse_motion_frame
= Qnil
;
15156 Qmodifier_value
= intern ("modifier-value");
15157 Qalt
= intern ("alt");
15158 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
15159 Qhyper
= intern ("hyper");
15160 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
15161 Qmeta
= intern ("meta");
15162 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
15163 Qsuper
= intern ("super");
15164 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
15166 DEFVAR_LISP ("x-alt-keysym", &Vx_alt_keysym
,
15167 doc
: /* Which keys Emacs uses for the alt modifier.
15168 This should be one of the symbols `alt', `hyper', `meta', `super'.
15169 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
15170 is nil, which is the same as `alt'. */);
15171 Vx_alt_keysym
= Qnil
;
15173 DEFVAR_LISP ("x-hyper-keysym", &Vx_hyper_keysym
,
15174 doc
: /* Which keys Emacs uses for the hyper modifier.
15175 This should be one of the symbols `alt', `hyper', `meta', `super'.
15176 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
15177 default is nil, which is the same as `hyper'. */);
15178 Vx_hyper_keysym
= Qnil
;
15180 DEFVAR_LISP ("x-meta-keysym", &Vx_meta_keysym
,
15181 doc
: /* Which keys Emacs uses for the meta modifier.
15182 This should be one of the symbols `alt', `hyper', `meta', `super'.
15183 For example, `meta' means use the Meta_L and Meta_R keysyms. The
15184 default is nil, which is the same as `meta'. */);
15185 Vx_meta_keysym
= Qnil
;
15187 DEFVAR_LISP ("x-super-keysym", &Vx_super_keysym
,
15188 doc
: /* Which keys Emacs uses for the super modifier.
15189 This should be one of the symbols `alt', `hyper', `meta', `super'.
15190 For example, `super' means use the Super_L and Super_R keysyms. The
15191 default is nil, which is the same as `super'. */);
15192 Vx_super_keysym
= Qnil
;
15196 #endif /* HAVE_X_WINDOWS */