1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 93, 94, 95, 96, 1997, 1998, 1999, 2000, 2001
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 draw block and hollow cursor as wide as the glyph
257 under it. For example, if a block cursor is over a tab, it will be
258 drawn as wide as that tab on the display. */
260 int x_stretch_cursor_p
;
262 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
264 int x_use_underline_position_properties
;
266 /* This is a chain of structures for all the X displays currently in
269 struct x_display_info
*x_display_list
;
271 /* This is a list of cons cells, each of the form (NAME
272 . FONT-LIST-CACHE), one for each element of x_display_list and in
273 the same order. NAME is the name of the frame. FONT-LIST-CACHE
274 records previous values returned by x-list-fonts. */
276 Lisp_Object x_display_name_list
;
278 /* Frame being updated by update_frame. This is declared in term.c.
279 This is set by update_begin and looked at by all the XT functions.
280 It is zero while not inside an update. In that case, the XT
281 functions assume that `selected_frame' is the frame to apply to. */
283 extern struct frame
*updating_frame
;
285 /* This is a frame waiting to be auto-raised, within XTread_socket. */
287 struct frame
*pending_autoraise_frame
;
290 /* The application context for Xt use. */
291 XtAppContext Xt_app_con
;
292 static String Xt_default_resources
[] = {0};
293 #endif /* USE_X_TOOLKIT */
295 /* Nominal cursor position -- where to draw output.
296 HPOS and VPOS are window relative glyph matrix coordinates.
297 X and Y are window relative pixel coordinates. */
299 struct cursor_pos output_cursor
;
301 /* Non-zero means user is interacting with a toolkit scroll bar. */
303 static int toolkit_scroll_bar_interaction
;
307 Formerly, we used PointerMotionHintMask (in standard_event_mask)
308 so that we would have to call XQueryPointer after each MotionNotify
309 event to ask for another such event. However, this made mouse tracking
310 slow, and there was a bug that made it eventually stop.
312 Simply asking for MotionNotify all the time seems to work better.
314 In order to avoid asking for motion events and then throwing most
315 of them away or busy-polling the server for mouse positions, we ask
316 the server for pointer motion hints. This means that we get only
317 one event per group of mouse movements. "Groups" are delimited by
318 other kinds of events (focus changes and button clicks, for
319 example), or by XQueryPointer calls; when one of these happens, we
320 get another MotionNotify event the next time the mouse moves. This
321 is at least as efficient as getting motion events when mouse
322 tracking is on, and I suspect only negligibly worse when tracking
325 /* Where the mouse was last time we reported a mouse event. */
327 FRAME_PTR last_mouse_frame
;
328 static XRectangle last_mouse_glyph
;
329 static Lisp_Object last_mouse_press_frame
;
331 /* The scroll bar in which the last X motion event occurred.
333 If the last X motion event occurred in a scroll bar, we set this so
334 XTmouse_position can know whether to report a scroll bar motion or
337 If the last X motion event didn't occur in a scroll bar, we set
338 this to Qnil, to tell XTmouse_position to return an ordinary motion
341 static Lisp_Object last_mouse_scroll_bar
;
343 /* This is a hack. We would really prefer that XTmouse_position would
344 return the time associated with the position it returns, but there
345 doesn't seem to be any way to wrest the time-stamp from the server
346 along with the position query. So, we just keep track of the time
347 of the last movement we received, and return that in hopes that
348 it's somewhat accurate. */
350 static Time last_mouse_movement_time
;
352 /* Incremented by XTread_socket whenever it really tries to read
356 static int volatile input_signal_count
;
358 static int input_signal_count
;
361 /* Used locally within XTread_socket. */
363 static int x_noop_count
;
365 /* Initial values of argv and argc. */
367 extern char **initial_argv
;
368 extern int initial_argc
;
370 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
372 /* Tells if a window manager is present or not. */
374 extern Lisp_Object Vx_no_window_manager
;
376 extern Lisp_Object Qface
, Qmouse_face
;
380 /* A mask of extra modifier bits to put into every keyboard char. */
382 extern int extra_keyboard_modifiers
;
384 static Lisp_Object Qvendor_specific_keysyms
;
386 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
387 extern Lisp_Object x_icon_type
P_ ((struct frame
*));
390 /* Enumeration for overriding/changing the face to use for drawing
391 glyphs in x_draw_glyphs. */
393 enum draw_glyphs_face
403 static int cursor_in_mouse_face_p
P_ ((struct window
*));
404 static int clear_mouse_face
P_ ((struct x_display_info
*));
405 static int x_alloc_nearest_color_1
P_ ((Display
*, Colormap
, XColor
*));
406 static void x_set_window_size_1
P_ ((struct frame
*, int, int, int));
407 static const XColor
*x_color_cells
P_ ((Display
*, int *));
408 static void x_update_window_end
P_ ((struct window
*, int, int));
409 static void frame_to_window_pixel_xy
P_ ((struct window
*, int *, int *));
410 void x_delete_display
P_ ((struct x_display_info
*));
411 static unsigned int x_x_to_emacs_modifiers
P_ ((struct x_display_info
*,
413 static int fast_find_position
P_ ((struct window
*, int, int *, int *,
414 int *, int *, Lisp_Object
));
415 static int fast_find_string_pos
P_ ((struct window
*, int, Lisp_Object
,
416 int *, int *, int *, int *, int));
417 static void set_output_cursor
P_ ((struct cursor_pos
*));
418 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
419 int *, int *, int *, int));
420 static void note_mode_line_highlight
P_ ((struct window
*, int, int));
421 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
422 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
423 static void x_handle_tool_bar_click
P_ ((struct frame
*, XButtonEvent
*));
424 static void show_mouse_face
P_ ((struct x_display_info
*,
425 enum draw_glyphs_face
));
426 static int x_io_error_quitter
P_ ((Display
*));
427 int x_catch_errors
P_ ((Display
*));
428 void x_uncatch_errors
P_ ((Display
*, int));
429 void x_lower_frame
P_ ((struct frame
*));
430 void x_scroll_bar_clear
P_ ((struct frame
*));
431 int x_had_errors_p
P_ ((Display
*));
432 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
433 void x_raise_frame
P_ ((struct frame
*));
434 void x_set_window_size
P_ ((struct frame
*, int, int, int));
435 void x_wm_set_window_state
P_ ((struct frame
*, int));
436 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
437 void x_initialize
P_ ((void));
438 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
439 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
440 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
442 enum draw_glyphs_face
));
443 static void x_update_end
P_ ((struct frame
*));
444 static void XTframe_up_to_date
P_ ((struct frame
*));
445 static void XTset_terminal_modes
P_ ((void));
446 static void XTreset_terminal_modes
P_ ((void));
447 static void XTcursor_to
P_ ((int, int, int, int));
448 static void x_write_glyphs
P_ ((struct glyph
*, int));
449 static void x_clear_end_of_line
P_ ((int));
450 static void x_clear_frame
P_ ((void));
451 static void x_clear_cursor
P_ ((struct window
*));
452 static void frame_highlight
P_ ((struct frame
*));
453 static void frame_unhighlight
P_ ((struct frame
*));
454 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
455 static void XTframe_rehighlight
P_ ((struct frame
*));
456 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
457 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
458 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int));
459 static int x_intersect_rectangles
P_ ((XRectangle
*, XRectangle
*,
461 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
462 static int expose_window_tree
P_ ((struct window
*, XRectangle
*));
463 static int expose_window
P_ ((struct window
*, XRectangle
*));
464 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
465 XRectangle
*, enum glyph_row_area
));
466 static int expose_line
P_ ((struct window
*, struct glyph_row
*,
468 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
469 static void x_update_window_cursor
P_ ((struct window
*, int));
470 static void x_erase_phys_cursor
P_ ((struct window
*));
471 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
472 static void x_draw_fringe_bitmap
P_ ((struct window
*, struct glyph_row
*,
473 enum fringe_bitmap_type
, int left_p
));
475 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
477 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, XRectangle
*));
478 static void x_draw_row_fringe_bitmaps
P_ ((struct window
*, struct glyph_row
*));
479 static void notice_overwritten_cursor
P_ ((struct window
*, enum glyph_row_area
,
480 int, int, int, int));
481 static void x_flush
P_ ((struct frame
*f
));
482 static void x_update_begin
P_ ((struct frame
*));
483 static void x_update_window_begin
P_ ((struct window
*));
484 static void x_draw_vertical_border
P_ ((struct window
*));
485 static void x_after_update_window_line
P_ ((struct glyph_row
*));
486 static INLINE
void take_vertical_position_into_account
P_ ((struct it
*));
487 static void x_produce_stretch_glyph
P_ ((struct it
*));
488 static struct scroll_bar
*x_window_to_scroll_bar
P_ ((Window
));
489 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
490 enum scroll_bar_part
*,
491 Lisp_Object
*, Lisp_Object
*,
493 static void x_check_fullscreen
P_ ((struct frame
*));
494 static void x_check_fullscreen_move
P_ ((struct frame
*));
496 /* Flush display of frame F, or of all frames if F is null. */
505 Lisp_Object rest
, frame
;
506 FOR_EACH_FRAME (rest
, frame
)
507 x_flush (XFRAME (frame
));
509 else if (FRAME_X_P (f
))
510 XFlush (FRAME_X_DISPLAY (f
));
515 /* Remove calls to XFlush by defining XFlush to an empty replacement.
516 Calls to XFlush should be unnecessary because the X output buffer
517 is flushed automatically as needed by calls to XPending,
518 XNextEvent, or XWindowEvent according to the XFlush man page.
519 XTread_socket calls XPending. Removing XFlush improves
522 #define XFlush(DISPLAY) (void) 0
525 /***********************************************************************
527 ***********************************************************************/
531 /* This is a function useful for recording debugging information about
532 the sequence of occurrences in this file. */
540 struct record event_record
[100];
542 int event_record_index
;
544 record_event (locus
, type
)
548 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
549 event_record_index
= 0;
551 event_record
[event_record_index
].locus
= locus
;
552 event_record
[event_record_index
].type
= type
;
553 event_record_index
++;
560 /* Return the struct x_display_info corresponding to DPY. */
562 struct x_display_info
*
563 x_display_info_for_display (dpy
)
566 struct x_display_info
*dpyinfo
;
568 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
569 if (dpyinfo
->display
== dpy
)
577 /***********************************************************************
578 Starting and ending an update
579 ***********************************************************************/
581 /* Start an update of frame F. This function is installed as a hook
582 for update_begin, i.e. it is called when update_begin is called.
583 This function is called prior to calls to x_update_window_begin for
584 each window being updated. Currently, there is nothing to do here
585 because all interesting stuff is done on a window basis. */
595 /* Start update of window W. Set the global variable updated_window
596 to the window being updated and set output_cursor to the cursor
600 x_update_window_begin (w
)
603 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
604 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
607 set_output_cursor (&w
->cursor
);
611 if (f
== display_info
->mouse_face_mouse_frame
)
613 /* Don't do highlighting for mouse motion during the update. */
614 display_info
->mouse_face_defer
= 1;
616 /* If F needs to be redrawn, simply forget about any prior mouse
618 if (FRAME_GARBAGED_P (f
))
619 display_info
->mouse_face_window
= Qnil
;
621 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
622 their mouse_face_p flag set, which means that they are always
623 unequal to rows in a desired matrix which never have that
624 flag set. So, rows containing mouse-face glyphs are never
625 scrolled, and we don't have to switch the mouse highlight off
626 here to prevent it from being scrolled. */
628 /* Can we tell that this update does not affect the window
629 where the mouse highlight is? If so, no need to turn off.
630 Likewise, don't do anything if the frame is garbaged;
631 in that case, the frame's current matrix that we would use
632 is all wrong, and we will redisplay that line anyway. */
633 if (!NILP (display_info
->mouse_face_window
)
634 && w
== XWINDOW (display_info
->mouse_face_window
))
638 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
639 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
642 if (i
< w
->desired_matrix
->nrows
)
643 clear_mouse_face (display_info
);
652 /* Draw a vertical window border to the right of window W if W doesn't
653 have vertical scroll bars. */
656 x_draw_vertical_border (w
)
659 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
661 /* Redraw borders between horizontally adjacent windows. Don't
662 do it for frames with vertical scroll bars because either the
663 right scroll bar of a window, or the left scroll bar of its
664 neighbor will suffice as a border. */
665 if (!WINDOW_RIGHTMOST_P (w
)
666 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
670 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
671 x1
+= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
674 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
675 f
->output_data
.x
->normal_gc
, x1
, y0
, x1
, y1
);
680 /* End update of window W (which is equal to updated_window).
682 Draw vertical borders between horizontally adjacent windows, and
683 display W's cursor if CURSOR_ON_P is non-zero.
685 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
686 glyphs in mouse-face were overwritten. In that case we have to
687 make sure that the mouse-highlight is properly redrawn.
689 W may be a menu bar pseudo-window in case we don't have X toolkit
690 support. Such windows don't have a cursor, so don't display it
694 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
696 int cursor_on_p
, mouse_face_overwritten_p
;
698 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
700 if (!w
->pseudo_window_p
)
705 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
707 output_cursor
.x
, output_cursor
.y
);
709 x_draw_vertical_border (w
);
713 /* If a row with mouse-face was overwritten, arrange for
714 XTframe_up_to_date to redisplay the mouse highlight. */
715 if (mouse_face_overwritten_p
)
717 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
718 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
719 dpyinfo
->mouse_face_window
= Qnil
;
722 updated_window
= NULL
;
726 /* End update of frame F. This function is installed as a hook in
733 /* Mouse highlight may be displayed again. */
734 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
737 XFlush (FRAME_X_DISPLAY (f
));
742 /* This function is called from various places in xdisp.c whenever a
743 complete update has been performed. The global variable
744 updated_window is not available here. */
747 XTframe_up_to_date (f
)
752 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
754 if (dpyinfo
->mouse_face_deferred_gc
755 || f
== dpyinfo
->mouse_face_mouse_frame
)
758 if (dpyinfo
->mouse_face_mouse_frame
)
759 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
760 dpyinfo
->mouse_face_mouse_x
,
761 dpyinfo
->mouse_face_mouse_y
);
762 dpyinfo
->mouse_face_deferred_gc
= 0;
769 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
770 arrow bitmaps, or clear the fringes if no bitmaps are required
771 before DESIRED_ROW is made current. The window being updated is
772 found in updated_window. This function It is called from
773 update_window_line only if it is known that there are differences
774 between bitmaps to be drawn between current row and DESIRED_ROW. */
777 x_after_update_window_line (desired_row
)
778 struct glyph_row
*desired_row
;
780 struct window
*w
= updated_window
;
786 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
789 x_draw_row_fringe_bitmaps (w
, desired_row
);
793 /* When a window has disappeared, make sure that no rest of
794 full-width rows stays visible in the internal border. Could
795 check here if updated_window is the leftmost/rightmost window,
796 but I guess it's not worth doing since vertically split windows
797 are almost never used, internal border is rarely set, and the
798 overhead is very small. */
799 if (windows_or_buffers_changed
800 && desired_row
->full_width_p
801 && (f
= XFRAME (w
->frame
),
802 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
804 && (height
= desired_row
->visible_height
,
807 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
809 /* Internal border is drawn below the tool bar. */
810 if (WINDOWP (f
->tool_bar_window
)
811 && w
== XWINDOW (f
->tool_bar_window
))
815 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
816 0, y
, width
, height
, False
);
817 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
818 f
->output_data
.x
->pixel_width
- width
,
819 y
, width
, height
, False
);
825 /* Draw the bitmap WHICH in one of the left or right fringes of
826 window W. ROW is the glyph row for which to display the bitmap; it
827 determines the vertical position at which the bitmap has to be
831 x_draw_fringe_bitmap (w
, row
, which
, left_p
)
833 struct glyph_row
*row
;
834 enum fringe_bitmap_type which
;
837 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
838 Display
*display
= FRAME_X_DISPLAY (f
);
839 Window window
= FRAME_X_WINDOW (f
);
844 GC gc
= f
->output_data
.x
->normal_gc
;
846 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
848 /* Must clip because of partially visible lines. */
849 x_clip_to_row (w
, row
, gc
, 1);
851 /* Convert row to frame coordinates. */
852 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
856 case NO_FRINGE_BITMAP
:
861 case LEFT_TRUNCATION_BITMAP
:
867 case OVERLAY_ARROW_BITMAP
:
873 case RIGHT_TRUNCATION_BITMAP
:
879 case CONTINUED_LINE_BITMAP
:
880 wd
= continued_width
;
881 h
= continued_height
;
882 bits
= continued_bits
;
885 case CONTINUATION_LINE_BITMAP
:
886 wd
= continuation_width
;
887 h
= continuation_height
;
888 bits
= continuation_bits
;
893 h
= zv_height
- (y
% zv_period
);
894 bits
= zv_bits
+ (y
% zv_period
);
901 /* Clip bitmap if too high. */
905 /* Set dy to the offset in the row to start drawing the bitmap. */
906 dy
= (row
->height
- h
) / 2;
908 face
= FACE_FROM_ID (f
, FRINGE_FACE_ID
);
909 PREPARE_FACE_FOR_DISPLAY (f
, face
);
911 /* Clear left fringe if no bitmap to draw or if bitmap doesn't fill
916 if (wd
> FRAME_X_LEFT_FRINGE_WIDTH (f
))
917 wd
= FRAME_X_LEFT_FRINGE_WIDTH (f
);
918 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
920 - (FRAME_X_LEFT_FRINGE_WIDTH (f
) - wd
) / 2);
921 if (wd
< FRAME_X_LEFT_FRINGE_WIDTH (f
) || row
->height
> h
)
923 /* If W has a vertical border to its left, don't draw over it. */
924 int border
= ((XFASTINT (w
->left
) > 0
925 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
927 b1
= (window_box_left (w
, -1)
928 - FRAME_X_LEFT_FRINGE_WIDTH (f
)
930 b2
= (FRAME_X_LEFT_FRINGE_WIDTH (f
) - border
);
935 if (wd
> FRAME_X_RIGHT_FRINGE_WIDTH (f
))
936 wd
= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
937 x
= (window_box_right (w
, -1)
938 + (FRAME_X_RIGHT_FRINGE_WIDTH (f
) - wd
) / 2);
939 /* Clear right fringe if no bitmap to draw of if bitmap doesn't fill
941 if (wd
< FRAME_X_RIGHT_FRINGE_WIDTH (f
) || row
->height
> h
)
943 b1
= window_box_right (w
, -1);
944 b2
= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
950 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
952 /* In case the same realized face is used for fringes and
953 for something displayed in the text (e.g. face `region' on
954 mono-displays, the fill style may have been changed to
955 FillSolid in x_draw_glyph_string_background. */
957 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
959 XSetForeground (display
, face
->gc
, face
->background
);
961 XFillRectangle (display
, window
, face
->gc
,
963 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
966 row
->visible_height
);
968 XSetForeground (display
, face
->gc
, face
->foreground
);
971 if (which
!= NO_FRINGE_BITMAP
)
973 /* Draw the bitmap. I believe these small pixmaps can be cached
975 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, wd
, h
,
977 face
->background
, depth
);
978 XCopyArea (display
, pixmap
, window
, gc
, 0, 0, wd
, h
, x
, y
+ dy
);
979 XFreePixmap (display
, pixmap
);
982 XSetClipMask (display
, gc
, None
);
986 /* Draw fringe bitmaps for glyph row ROW on window W. Call this
987 function with input blocked. */
990 x_draw_row_fringe_bitmaps (w
, row
)
992 struct glyph_row
*row
;
994 struct frame
*f
= XFRAME (w
->frame
);
995 enum fringe_bitmap_type bitmap
;
997 xassert (interrupt_input_blocked
);
999 /* If row is completely invisible, because of vscrolling, we
1000 don't have to draw anything. */
1001 if (row
->visible_height
<= 0)
1004 if (FRAME_X_LEFT_FRINGE_WIDTH (f
) != 0)
1006 /* Decide which bitmap to draw in the left fringe. */
1007 if (row
->overlay_arrow_p
)
1008 bitmap
= OVERLAY_ARROW_BITMAP
;
1009 else if (row
->truncated_on_left_p
)
1010 bitmap
= LEFT_TRUNCATION_BITMAP
;
1011 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
1012 bitmap
= CONTINUATION_LINE_BITMAP
;
1013 else if (row
->indicate_empty_line_p
)
1014 bitmap
= ZV_LINE_BITMAP
;
1016 bitmap
= NO_FRINGE_BITMAP
;
1018 x_draw_fringe_bitmap (w
, row
, bitmap
, 1);
1021 if (FRAME_X_RIGHT_FRINGE_WIDTH (f
) != 0)
1023 /* Decide which bitmap to draw in the right fringe. */
1024 if (row
->truncated_on_right_p
)
1025 bitmap
= RIGHT_TRUNCATION_BITMAP
;
1026 else if (row
->continued_p
)
1027 bitmap
= CONTINUED_LINE_BITMAP
;
1028 else if (row
->indicate_empty_line_p
&& FRAME_X_LEFT_FRINGE_WIDTH (f
) == 0)
1029 bitmap
= ZV_LINE_BITMAP
;
1031 bitmap
= NO_FRINGE_BITMAP
;
1033 x_draw_fringe_bitmap (w
, row
, bitmap
, 0);
1039 /* This is called when starting Emacs and when restarting after
1040 suspend. When starting Emacs, no X window is mapped. And nothing
1041 must be done to Emacs's own window if it is suspended (though that
1045 XTset_terminal_modes ()
1049 /* This is called when exiting or suspending Emacs. Exiting will make
1050 the X-windows go away, and suspending requires no action. */
1053 XTreset_terminal_modes ()
1059 /***********************************************************************
1061 ***********************************************************************/
1063 /* Set the global variable output_cursor to CURSOR. All cursor
1064 positions are relative to updated_window. */
1067 set_output_cursor (cursor
)
1068 struct cursor_pos
*cursor
;
1070 output_cursor
.hpos
= cursor
->hpos
;
1071 output_cursor
.vpos
= cursor
->vpos
;
1072 output_cursor
.x
= cursor
->x
;
1073 output_cursor
.y
= cursor
->y
;
1077 /* Set a nominal cursor position.
1079 HPOS and VPOS are column/row positions in a window glyph matrix. X
1080 and Y are window text area relative pixel positions.
1082 If this is done during an update, updated_window will contain the
1083 window that is being updated and the position is the future output
1084 cursor position for that window. If updated_window is null, use
1085 selected_window and display the cursor at the given position. */
1088 XTcursor_to (vpos
, hpos
, y
, x
)
1089 int vpos
, hpos
, y
, x
;
1093 /* If updated_window is not set, work on selected_window. */
1097 w
= XWINDOW (selected_window
);
1099 /* Set the output cursor. */
1100 output_cursor
.hpos
= hpos
;
1101 output_cursor
.vpos
= vpos
;
1102 output_cursor
.x
= x
;
1103 output_cursor
.y
= y
;
1105 /* If not called as part of an update, really display the cursor.
1106 This will also set the cursor position of W. */
1107 if (updated_window
== NULL
)
1110 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
1111 XFlush (FRAME_X_DISPLAY (SELECTED_FRAME ()));
1118 /***********************************************************************
1120 ***********************************************************************/
1122 /* Function prototypes of this page. */
1124 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
1128 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
1129 int, XChar2b
*, int));
1130 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
1131 static void x_encode_char
P_ ((int, XChar2b
*, struct font_info
*));
1132 static void x_append_glyph
P_ ((struct it
*));
1133 static void x_append_composite_glyph
P_ ((struct it
*));
1134 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
1136 static void x_produce_glyphs
P_ ((struct it
*));
1137 static void x_produce_image_glyph
P_ ((struct it
*it
));
1140 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
1141 is not contained in the font. */
1143 static INLINE XCharStruct
*
1144 x_per_char_metric (font
, char2b
)
1148 /* The result metric information. */
1149 XCharStruct
*pcm
= NULL
;
1151 xassert (font
&& char2b
);
1153 if (font
->per_char
!= NULL
)
1155 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
1157 /* min_char_or_byte2 specifies the linear character index
1158 corresponding to the first element of the per_char array,
1159 max_char_or_byte2 is the index of the last character. A
1160 character with non-zero CHAR2B->byte1 is not in the font.
1161 A character with byte2 less than min_char_or_byte2 or
1162 greater max_char_or_byte2 is not in the font. */
1163 if (char2b
->byte1
== 0
1164 && char2b
->byte2
>= font
->min_char_or_byte2
1165 && char2b
->byte2
<= font
->max_char_or_byte2
)
1166 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
1170 /* If either min_byte1 or max_byte1 are nonzero, both
1171 min_char_or_byte2 and max_char_or_byte2 are less than
1172 256, and the 2-byte character index values corresponding
1173 to the per_char array element N (counting from 0) are:
1175 byte1 = N/D + min_byte1
1176 byte2 = N\D + min_char_or_byte2
1180 D = max_char_or_byte2 - min_char_or_byte2 + 1
1181 / = integer division
1182 \ = integer modulus */
1183 if (char2b
->byte1
>= font
->min_byte1
1184 && char2b
->byte1
<= font
->max_byte1
1185 && char2b
->byte2
>= font
->min_char_or_byte2
1186 && char2b
->byte2
<= font
->max_char_or_byte2
)
1188 pcm
= (font
->per_char
1189 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
1190 * (char2b
->byte1
- font
->min_byte1
))
1191 + (char2b
->byte2
- font
->min_char_or_byte2
));
1197 /* If the per_char pointer is null, all glyphs between the first
1198 and last character indexes inclusive have the same
1199 information, as given by both min_bounds and max_bounds. */
1200 if (char2b
->byte2
>= font
->min_char_or_byte2
1201 && char2b
->byte2
<= font
->max_char_or_byte2
)
1202 pcm
= &font
->max_bounds
;
1205 return ((pcm
== NULL
1206 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
1211 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1212 the two-byte form of C. Encoding is returned in *CHAR2B. */
1215 x_encode_char (c
, char2b
, font_info
)
1218 struct font_info
*font_info
;
1220 int charset
= CHAR_CHARSET (c
);
1221 XFontStruct
*font
= font_info
->font
;
1223 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1224 This may be either a program in a special encoder language or a
1226 if (font_info
->font_encoder
)
1228 /* It's a program. */
1229 struct ccl_program
*ccl
= font_info
->font_encoder
;
1231 if (CHARSET_DIMENSION (charset
) == 1)
1233 ccl
->reg
[0] = charset
;
1234 ccl
->reg
[1] = char2b
->byte2
;
1238 ccl
->reg
[0] = charset
;
1239 ccl
->reg
[1] = char2b
->byte1
;
1240 ccl
->reg
[2] = char2b
->byte2
;
1243 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1245 /* We assume that MSBs are appropriately set/reset by CCL
1247 if (font
->max_byte1
== 0) /* 1-byte font */
1248 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
1250 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
1252 else if (font_info
->encoding
[charset
])
1254 /* Fixed encoding scheme. See fontset.h for the meaning of the
1255 encoding numbers. */
1256 int enc
= font_info
->encoding
[charset
];
1258 if ((enc
== 1 || enc
== 2)
1259 && CHARSET_DIMENSION (charset
) == 2)
1260 char2b
->byte1
|= 0x80;
1262 if (enc
== 1 || enc
== 3)
1263 char2b
->byte2
|= 0x80;
1268 /* Get face and two-byte form of character C in face FACE_ID on frame
1269 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1270 means we want to display multibyte text. Value is a pointer to a
1271 realized face that is ready for display. */
1273 static INLINE
struct face
*
1274 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
)
1280 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1284 /* Unibyte case. We don't have to encode, but we have to make
1285 sure to use a face suitable for unibyte. */
1288 face_id
= FACE_FOR_CHAR (f
, face
, c
);
1289 face
= FACE_FROM_ID (f
, face_id
);
1291 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1293 /* Case of ASCII in a face known to fit ASCII. */
1299 int c1
, c2
, charset
;
1301 /* Split characters into bytes. If c2 is -1 afterwards, C is
1302 really a one-byte character so that byte1 is zero. */
1303 SPLIT_CHAR (c
, charset
, c1
, c2
);
1305 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1307 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1309 /* Maybe encode the character in *CHAR2B. */
1310 if (face
->font
!= NULL
)
1312 struct font_info
*font_info
1313 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1315 x_encode_char (c
, char2b
, font_info
);
1319 /* Make sure X resources of the face are allocated. */
1320 xassert (face
!= NULL
);
1321 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1327 /* Get face and two-byte form of character glyph GLYPH on frame F.
1328 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
1329 a pointer to a realized face that is ready for display. */
1331 static INLINE
struct face
*
1332 x_get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
1334 struct glyph
*glyph
;
1340 xassert (glyph
->type
== CHAR_GLYPH
);
1341 face
= FACE_FROM_ID (f
, glyph
->face_id
);
1346 if (!glyph
->multibyte_p
)
1348 /* Unibyte case. We don't have to encode, but we have to make
1349 sure to use a face suitable for unibyte. */
1351 char2b
->byte2
= glyph
->u
.ch
;
1353 else if (glyph
->u
.ch
< 128
1354 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
1356 /* Case of ASCII in a face known to fit ASCII. */
1358 char2b
->byte2
= glyph
->u
.ch
;
1362 int c1
, c2
, charset
;
1364 /* Split characters into bytes. If c2 is -1 afterwards, C is
1365 really a one-byte character so that byte1 is zero. */
1366 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
1368 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1370 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1372 /* Maybe encode the character in *CHAR2B. */
1373 if (charset
!= CHARSET_ASCII
)
1375 struct font_info
*font_info
1376 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1379 x_encode_char (glyph
->u
.ch
, char2b
, font_info
);
1382 = ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
1387 /* Make sure X resources of the face are allocated. */
1388 xassert (face
!= NULL
);
1389 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1394 /* Store one glyph for IT->char_to_display in IT->glyph_row.
1395 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1401 struct glyph
*glyph
;
1402 enum glyph_row_area area
= it
->area
;
1404 xassert (it
->glyph_row
);
1405 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
1407 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1408 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1410 glyph
->charpos
= CHARPOS (it
->position
);
1411 glyph
->object
= it
->object
;
1412 glyph
->pixel_width
= it
->pixel_width
;
1413 glyph
->voffset
= it
->voffset
;
1414 glyph
->type
= CHAR_GLYPH
;
1415 glyph
->multibyte_p
= it
->multibyte_p
;
1416 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1417 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1418 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1419 || it
->phys_descent
> it
->descent
);
1420 glyph
->padding_p
= 0;
1421 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
1422 glyph
->face_id
= it
->face_id
;
1423 glyph
->u
.ch
= it
->char_to_display
;
1424 ++it
->glyph_row
->used
[area
];
1428 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
1429 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1432 x_append_composite_glyph (it
)
1435 struct glyph
*glyph
;
1436 enum glyph_row_area area
= it
->area
;
1438 xassert (it
->glyph_row
);
1440 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1441 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1443 glyph
->charpos
= CHARPOS (it
->position
);
1444 glyph
->object
= it
->object
;
1445 glyph
->pixel_width
= it
->pixel_width
;
1446 glyph
->voffset
= it
->voffset
;
1447 glyph
->type
= COMPOSITE_GLYPH
;
1448 glyph
->multibyte_p
= it
->multibyte_p
;
1449 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1450 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1451 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1452 || it
->phys_descent
> it
->descent
);
1453 glyph
->padding_p
= 0;
1454 glyph
->glyph_not_available_p
= 0;
1455 glyph
->face_id
= it
->face_id
;
1456 glyph
->u
.cmp_id
= it
->cmp_id
;
1457 ++it
->glyph_row
->used
[area
];
1462 /* Change IT->ascent and IT->height according to the setting of
1466 take_vertical_position_into_account (it
)
1471 if (it
->voffset
< 0)
1472 /* Increase the ascent so that we can display the text higher
1474 it
->ascent
+= abs (it
->voffset
);
1476 /* Increase the descent so that we can display the text lower
1478 it
->descent
+= it
->voffset
;
1483 /* Produce glyphs/get display metrics for the image IT is loaded with.
1484 See the description of struct display_iterator in dispextern.h for
1485 an overview of struct display_iterator. */
1488 x_produce_image_glyph (it
)
1494 xassert (it
->what
== IT_IMAGE
);
1496 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1497 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
1500 /* Make sure X resources of the face and image are loaded. */
1501 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1502 prepare_image_for_display (it
->f
, img
);
1504 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
1505 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
1506 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
1510 if (face
->box
!= FACE_NO_BOX
)
1512 if (face
->box_line_width
> 0)
1514 it
->ascent
+= face
->box_line_width
;
1515 it
->descent
+= face
->box_line_width
;
1518 if (it
->start_of_box_run_p
)
1519 it
->pixel_width
+= abs (face
->box_line_width
);
1520 if (it
->end_of_box_run_p
)
1521 it
->pixel_width
+= abs (face
->box_line_width
);
1524 take_vertical_position_into_account (it
);
1528 struct glyph
*glyph
;
1529 enum glyph_row_area area
= it
->area
;
1531 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1532 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1534 glyph
->charpos
= CHARPOS (it
->position
);
1535 glyph
->object
= it
->object
;
1536 glyph
->pixel_width
= it
->pixel_width
;
1537 glyph
->voffset
= it
->voffset
;
1538 glyph
->type
= IMAGE_GLYPH
;
1539 glyph
->multibyte_p
= it
->multibyte_p
;
1540 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1541 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1542 glyph
->overlaps_vertically_p
= 0;
1543 glyph
->padding_p
= 0;
1544 glyph
->glyph_not_available_p
= 0;
1545 glyph
->face_id
= it
->face_id
;
1546 glyph
->u
.img_id
= img
->id
;
1547 ++it
->glyph_row
->used
[area
];
1553 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
1554 of the glyph, WIDTH and HEIGHT are the width and height of the
1555 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
1556 ascent of the glyph (0 <= ASCENT <= 1). */
1559 x_append_stretch_glyph (it
, object
, width
, height
, ascent
)
1565 struct glyph
*glyph
;
1566 enum glyph_row_area area
= it
->area
;
1568 xassert (ascent
>= 0 && ascent
<= 1);
1570 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1571 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1573 glyph
->charpos
= CHARPOS (it
->position
);
1574 glyph
->object
= object
;
1575 glyph
->pixel_width
= width
;
1576 glyph
->voffset
= it
->voffset
;
1577 glyph
->type
= STRETCH_GLYPH
;
1578 glyph
->multibyte_p
= it
->multibyte_p
;
1579 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1580 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1581 glyph
->overlaps_vertically_p
= 0;
1582 glyph
->padding_p
= 0;
1583 glyph
->glyph_not_available_p
= 0;
1584 glyph
->face_id
= it
->face_id
;
1585 glyph
->u
.stretch
.ascent
= height
* ascent
;
1586 glyph
->u
.stretch
.height
= height
;
1587 ++it
->glyph_row
->used
[area
];
1592 /* Produce a stretch glyph for iterator IT. IT->object is the value
1593 of the glyph property displayed. The value must be a list
1594 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1597 1. `:width WIDTH' specifies that the space should be WIDTH *
1598 canonical char width wide. WIDTH may be an integer or floating
1601 2. `:relative-width FACTOR' specifies that the width of the stretch
1602 should be computed from the width of the first character having the
1603 `glyph' property, and should be FACTOR times that width.
1605 3. `:align-to HPOS' specifies that the space should be wide enough
1606 to reach HPOS, a value in canonical character units.
1608 Exactly one of the above pairs must be present.
1610 4. `:height HEIGHT' specifies that the height of the stretch produced
1611 should be HEIGHT, measured in canonical character units.
1613 5. `:relative-height FACTOR' specifies that the height of the
1614 stretch should be FACTOR times the height of the characters having
1617 Either none or exactly one of 4 or 5 must be present.
1619 6. `:ascent ASCENT' specifies that ASCENT percent of the height
1620 of the stretch should be used for the ascent of the stretch.
1621 ASCENT must be in the range 0 <= ASCENT <= 100. */
1624 ((INTEGERP (X) || FLOATP (X)) \
1630 x_produce_stretch_glyph (it
)
1633 /* (space :width WIDTH :height HEIGHT. */
1635 extern Lisp_Object Qspace
;
1637 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
1638 extern Lisp_Object QCrelative_width
, QCrelative_height
;
1639 extern Lisp_Object QCalign_to
;
1640 Lisp_Object prop
, plist
;
1641 double width
= 0, height
= 0, ascent
= 0;
1642 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1643 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
1645 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1647 /* List should start with `space'. */
1648 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1649 plist
= XCDR (it
->object
);
1651 /* Compute the width of the stretch. */
1652 if (prop
= Fplist_get (plist
, QCwidth
),
1654 /* Absolute width `:width WIDTH' specified and valid. */
1655 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
1656 else if (prop
= Fplist_get (plist
, QCrelative_width
),
1659 /* Relative width `:relative-width FACTOR' specified and valid.
1660 Compute the width of the characters having the `glyph'
1663 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
1666 if (it
->multibyte_p
)
1668 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
1669 - IT_BYTEPOS (*it
));
1670 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
1673 it2
.c
= *p
, it2
.len
= 1;
1675 it2
.glyph_row
= NULL
;
1676 it2
.what
= IT_CHARACTER
;
1677 x_produce_glyphs (&it2
);
1678 width
= NUMVAL (prop
) * it2
.pixel_width
;
1680 else if (prop
= Fplist_get (plist
, QCalign_to
),
1682 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
1684 /* Nothing specified -> width defaults to canonical char width. */
1685 width
= CANON_X_UNIT (it
->f
);
1687 /* Compute height. */
1688 if (prop
= Fplist_get (plist
, QCheight
),
1690 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
1691 else if (prop
= Fplist_get (plist
, QCrelative_height
),
1693 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
1695 height
= FONT_HEIGHT (font
);
1697 /* Compute percentage of height used for ascent. If
1698 `:ascent ASCENT' is present and valid, use that. Otherwise,
1699 derive the ascent from the font in use. */
1700 if (prop
= Fplist_get (plist
, QCascent
),
1701 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
1702 ascent
= NUMVAL (prop
) / 100.0;
1704 ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1713 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1714 if (!STRINGP (object
))
1715 object
= it
->w
->buffer
;
1716 x_append_stretch_glyph (it
, object
, width
, height
, ascent
);
1719 it
->pixel_width
= width
;
1720 it
->ascent
= it
->phys_ascent
= height
* ascent
;
1721 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
1724 if (face
->box
!= FACE_NO_BOX
)
1726 if (face
->box_line_width
> 0)
1728 it
->ascent
+= face
->box_line_width
;
1729 it
->descent
+= face
->box_line_width
;
1732 if (it
->start_of_box_run_p
)
1733 it
->pixel_width
+= abs (face
->box_line_width
);
1734 if (it
->end_of_box_run_p
)
1735 it
->pixel_width
+= abs (face
->box_line_width
);
1738 take_vertical_position_into_account (it
);
1741 /* Return proper value to be used as baseline offset of font that has
1742 ASCENT and DESCENT to draw characters by the font at the vertical
1743 center of the line of frame F.
1745 Here, out task is to find the value of BOFF in the following figure;
1747 -------------------------+-----------+-
1748 -+-+---------+-+ | |
1750 | | | | F_ASCENT F_HEIGHT
1753 | | |-|-+------+-----------|------- baseline
1755 | |---------|-+-+ | |
1757 -+-+---------+-+ F_DESCENT |
1758 -------------------------+-----------+-
1760 -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
1761 BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
1762 DESCENT = FONT->descent
1763 HEIGHT = FONT_HEIGHT (FONT)
1764 F_DESCENT = (F->output_data.x->font->descent
1765 - F->output_data.x->baseline_offset)
1766 F_HEIGHT = FRAME_LINE_HEIGHT (F)
1769 #define VCENTER_BASELINE_OFFSET(FONT, F) \
1771 + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT)) \
1772 + (FRAME_LINE_HEIGHT ((F)) > FONT_HEIGHT ((FONT)))) / 2 \
1773 - ((F)->output_data.x->font->descent - (F)->output_data.x->baseline_offset))
1775 /* Produce glyphs/get display metrics for the display element IT is
1776 loaded with. See the description of struct display_iterator in
1777 dispextern.h for an overview of struct display_iterator. */
1780 x_produce_glyphs (it
)
1783 it
->glyph_not_available_p
= 0;
1785 if (it
->what
== IT_CHARACTER
)
1789 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1791 int font_not_found_p
;
1792 struct font_info
*font_info
;
1793 int boff
; /* baseline offset */
1794 /* We may change it->multibyte_p upon unibyte<->multibyte
1795 conversion. So, save the current value now and restore it
1798 Note: It seems that we don't have to record multibyte_p in
1799 struct glyph because the character code itself tells if or
1800 not the character is multibyte. Thus, in the future, we must
1801 consider eliminating the field `multibyte_p' in the struct
1803 int saved_multibyte_p
= it
->multibyte_p
;
1805 /* Maybe translate single-byte characters to multibyte, or the
1807 it
->char_to_display
= it
->c
;
1808 if (!ASCII_BYTE_P (it
->c
))
1810 if (unibyte_display_via_language_environment
1811 && SINGLE_BYTE_CHAR_P (it
->c
)
1813 || !NILP (Vnonascii_translation_table
)))
1815 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
1816 it
->multibyte_p
= 1;
1817 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1818 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1820 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
1821 && !it
->multibyte_p
)
1823 it
->multibyte_p
= 1;
1824 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1825 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1829 /* Get font to use. Encode IT->char_to_display. */
1830 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
1831 it
->face_id
, &char2b
,
1835 /* When no suitable font found, use the default font. */
1836 font_not_found_p
= font
== NULL
;
1837 if (font_not_found_p
)
1839 font
= FRAME_FONT (it
->f
);
1840 boff
= it
->f
->output_data
.x
->baseline_offset
;
1845 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
1846 boff
= font_info
->baseline_offset
;
1847 if (font_info
->vertical_centering
)
1848 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
1851 if (it
->char_to_display
>= ' '
1852 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
1854 /* Either unibyte or ASCII. */
1859 pcm
= x_per_char_metric (font
, &char2b
);
1860 it
->ascent
= font
->ascent
+ boff
;
1861 it
->descent
= font
->descent
- boff
;
1865 it
->phys_ascent
= pcm
->ascent
+ boff
;
1866 it
->phys_descent
= pcm
->descent
- boff
;
1867 it
->pixel_width
= pcm
->width
;
1871 it
->glyph_not_available_p
= 1;
1872 it
->phys_ascent
= font
->ascent
+ boff
;
1873 it
->phys_descent
= font
->descent
- boff
;
1874 it
->pixel_width
= FONT_WIDTH (font
);
1877 /* If this is a space inside a region of text with
1878 `space-width' property, change its width. */
1879 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
1881 it
->pixel_width
*= XFLOATINT (it
->space_width
);
1883 /* If face has a box, add the box thickness to the character
1884 height. If character has a box line to the left and/or
1885 right, add the box line width to the character's width. */
1886 if (face
->box
!= FACE_NO_BOX
)
1888 int thick
= face
->box_line_width
;
1892 it
->ascent
+= thick
;
1893 it
->descent
+= thick
;
1898 if (it
->start_of_box_run_p
)
1899 it
->pixel_width
+= thick
;
1900 if (it
->end_of_box_run_p
)
1901 it
->pixel_width
+= thick
;
1904 /* If face has an overline, add the height of the overline
1905 (1 pixel) and a 1 pixel margin to the character height. */
1906 if (face
->overline_p
)
1909 take_vertical_position_into_account (it
);
1911 /* If we have to actually produce glyphs, do it. */
1916 /* Translate a space with a `space-width' property
1917 into a stretch glyph. */
1918 double ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1919 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1920 it
->ascent
+ it
->descent
, ascent
);
1923 x_append_glyph (it
);
1925 /* If characters with lbearing or rbearing are displayed
1926 in this line, record that fact in a flag of the
1927 glyph row. This is used to optimize X output code. */
1928 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
1929 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1932 else if (it
->char_to_display
== '\n')
1934 /* A newline has no width but we need the height of the line. */
1935 it
->pixel_width
= 0;
1937 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1938 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1940 if (face
->box
!= FACE_NO_BOX
1941 && face
->box_line_width
> 0)
1943 it
->ascent
+= face
->box_line_width
;
1944 it
->descent
+= face
->box_line_width
;
1947 else if (it
->char_to_display
== '\t')
1949 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
1950 int x
= it
->current_x
+ it
->continuation_lines_width
;
1951 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
1953 /* If the distance from the current position to the next tab
1954 stop is less than a canonical character width, use the
1955 tab stop after that. */
1956 if (next_tab_x
- x
< CANON_X_UNIT (it
->f
))
1957 next_tab_x
+= tab_width
;
1959 it
->pixel_width
= next_tab_x
- x
;
1961 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1962 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1966 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
1967 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1968 it
->ascent
+ it
->descent
, ascent
);
1973 /* A multi-byte character. Assume that the display width of the
1974 character is the width of the character multiplied by the
1975 width of the font. */
1977 /* If we found a font, this font should give us the right
1978 metrics. If we didn't find a font, use the frame's
1979 default font and calculate the width of the character
1980 from the charset width; this is what old redisplay code
1982 pcm
= x_per_char_metric (font
, &char2b
);
1983 if (font_not_found_p
|| !pcm
)
1985 int charset
= CHAR_CHARSET (it
->char_to_display
);
1987 it
->glyph_not_available_p
= 1;
1988 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
1989 * CHARSET_WIDTH (charset
));
1990 it
->phys_ascent
= font
->ascent
+ boff
;
1991 it
->phys_descent
= font
->descent
- boff
;
1995 it
->pixel_width
= pcm
->width
;
1996 it
->phys_ascent
= pcm
->ascent
+ boff
;
1997 it
->phys_descent
= pcm
->descent
- boff
;
1999 && (pcm
->lbearing
< 0
2000 || pcm
->rbearing
> pcm
->width
))
2001 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
2004 it
->ascent
= font
->ascent
+ boff
;
2005 it
->descent
= font
->descent
- boff
;
2006 if (face
->box
!= FACE_NO_BOX
)
2008 int thick
= face
->box_line_width
;
2012 it
->ascent
+= thick
;
2013 it
->descent
+= thick
;
2018 if (it
->start_of_box_run_p
)
2019 it
->pixel_width
+= thick
;
2020 if (it
->end_of_box_run_p
)
2021 it
->pixel_width
+= thick
;
2024 /* If face has an overline, add the height of the overline
2025 (1 pixel) and a 1 pixel margin to the character height. */
2026 if (face
->overline_p
)
2029 take_vertical_position_into_account (it
);
2032 x_append_glyph (it
);
2034 it
->multibyte_p
= saved_multibyte_p
;
2036 else if (it
->what
== IT_COMPOSITION
)
2038 /* Note: A composition is represented as one glyph in the
2039 glyph matrix. There are no padding glyphs. */
2042 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2044 int font_not_found_p
;
2045 struct font_info
*font_info
;
2046 int boff
; /* baseline offset */
2047 struct composition
*cmp
= composition_table
[it
->cmp_id
];
2049 /* Maybe translate single-byte characters to multibyte. */
2050 it
->char_to_display
= it
->c
;
2051 if (unibyte_display_via_language_environment
2052 && SINGLE_BYTE_CHAR_P (it
->c
)
2055 && !NILP (Vnonascii_translation_table
))))
2057 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2060 /* Get face and font to use. Encode IT->char_to_display. */
2061 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2062 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2063 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2064 it
->face_id
, &char2b
, it
->multibyte_p
);
2067 /* When no suitable font found, use the default font. */
2068 font_not_found_p
= font
== NULL
;
2069 if (font_not_found_p
)
2071 font
= FRAME_FONT (it
->f
);
2072 boff
= it
->f
->output_data
.x
->baseline_offset
;
2077 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2078 boff
= font_info
->baseline_offset
;
2079 if (font_info
->vertical_centering
)
2080 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2083 /* There are no padding glyphs, so there is only one glyph to
2084 produce for the composition. Important is that pixel_width,
2085 ascent and descent are the values of what is drawn by
2086 draw_glyphs (i.e. the values of the overall glyphs composed). */
2089 /* If we have not yet calculated pixel size data of glyphs of
2090 the composition for the current face font, calculate them
2091 now. Theoretically, we have to check all fonts for the
2092 glyphs, but that requires much time and memory space. So,
2093 here we check only the font of the first glyph. This leads
2094 to incorrect display very rarely, and C-l (recenter) can
2095 correct the display anyway. */
2096 if (cmp
->font
!= (void *) font
)
2098 /* Ascent and descent of the font of the first character of
2099 this composition (adjusted by baseline offset). Ascent
2100 and descent of overall glyphs should not be less than
2101 them respectively. */
2102 int font_ascent
= font
->ascent
+ boff
;
2103 int font_descent
= font
->descent
- boff
;
2104 /* Bounding box of the overall glyphs. */
2105 int leftmost
, rightmost
, lowest
, highest
;
2106 int i
, width
, ascent
, descent
;
2108 cmp
->font
= (void *) font
;
2110 /* Initialize the bounding box. */
2112 && (pcm
= x_per_char_metric (font
, &char2b
)))
2115 ascent
= pcm
->ascent
;
2116 descent
= pcm
->descent
;
2120 width
= FONT_WIDTH (font
);
2121 ascent
= font
->ascent
;
2122 descent
= font
->descent
;
2126 lowest
= - descent
+ boff
;
2127 highest
= ascent
+ boff
;
2131 && font_info
->default_ascent
2132 && CHAR_TABLE_P (Vuse_default_ascent
)
2133 && !NILP (Faref (Vuse_default_ascent
,
2134 make_number (it
->char_to_display
))))
2135 highest
= font_info
->default_ascent
+ boff
;
2137 /* Draw the first glyph at the normal position. It may be
2138 shifted to right later if some other glyphs are drawn at
2140 cmp
->offsets
[0] = 0;
2141 cmp
->offsets
[1] = boff
;
2143 /* Set cmp->offsets for the remaining glyphs. */
2144 for (i
= 1; i
< cmp
->glyph_len
; i
++)
2146 int left
, right
, btm
, top
;
2147 int ch
= COMPOSITION_GLYPH (cmp
, i
);
2148 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
2150 face
= FACE_FROM_ID (it
->f
, face_id
);
2151 x_get_char_face_and_encoding (it
->f
, ch
, face
->id
, &char2b
,
2156 font
= FRAME_FONT (it
->f
);
2157 boff
= it
->f
->output_data
.x
->baseline_offset
;
2163 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2164 boff
= font_info
->baseline_offset
;
2165 if (font_info
->vertical_centering
)
2166 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2170 && (pcm
= x_per_char_metric (font
, &char2b
)))
2173 ascent
= pcm
->ascent
;
2174 descent
= pcm
->descent
;
2178 width
= FONT_WIDTH (font
);
2183 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
2185 /* Relative composition with or without
2187 left
= (leftmost
+ rightmost
- width
) / 2;
2188 btm
= - descent
+ boff
;
2189 if (font_info
&& font_info
->relative_compose
2190 && (! CHAR_TABLE_P (Vignore_relative_composition
)
2191 || NILP (Faref (Vignore_relative_composition
,
2192 make_number (ch
)))))
2195 if (- descent
>= font_info
->relative_compose
)
2196 /* One extra pixel between two glyphs. */
2198 else if (ascent
<= 0)
2199 /* One extra pixel between two glyphs. */
2200 btm
= lowest
- 1 - ascent
- descent
;
2205 /* A composition rule is specified by an integer
2206 value that encodes global and new reference
2207 points (GREF and NREF). GREF and NREF are
2208 specified by numbers as below:
2216 ---3---4---5--- baseline
2218 6---7---8 -- descent
2220 int rule
= COMPOSITION_RULE (cmp
, i
);
2221 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
2223 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
2224 grefx
= gref
% 3, nrefx
= nref
% 3;
2225 grefy
= gref
/ 3, nrefy
= nref
/ 3;
2228 + grefx
* (rightmost
- leftmost
) / 2
2229 - nrefx
* width
/ 2);
2230 btm
= ((grefy
== 0 ? highest
2232 : grefy
== 2 ? lowest
2233 : (highest
+ lowest
) / 2)
2234 - (nrefy
== 0 ? ascent
+ descent
2235 : nrefy
== 1 ? descent
- boff
2237 : (ascent
+ descent
) / 2));
2240 cmp
->offsets
[i
* 2] = left
;
2241 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
2243 /* Update the bounding box of the overall glyphs. */
2244 right
= left
+ width
;
2245 top
= btm
+ descent
+ ascent
;
2246 if (left
< leftmost
)
2248 if (right
> rightmost
)
2256 /* If there are glyphs whose x-offsets are negative,
2257 shift all glyphs to the right and make all x-offsets
2261 for (i
= 0; i
< cmp
->glyph_len
; i
++)
2262 cmp
->offsets
[i
* 2] -= leftmost
;
2263 rightmost
-= leftmost
;
2266 cmp
->pixel_width
= rightmost
;
2267 cmp
->ascent
= highest
;
2268 cmp
->descent
= - lowest
;
2269 if (cmp
->ascent
< font_ascent
)
2270 cmp
->ascent
= font_ascent
;
2271 if (cmp
->descent
< font_descent
)
2272 cmp
->descent
= font_descent
;
2275 it
->pixel_width
= cmp
->pixel_width
;
2276 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
2277 it
->descent
= it
->phys_descent
= cmp
->descent
;
2279 if (face
->box
!= FACE_NO_BOX
)
2281 int thick
= face
->box_line_width
;
2285 it
->ascent
+= thick
;
2286 it
->descent
+= thick
;
2291 if (it
->start_of_box_run_p
)
2292 it
->pixel_width
+= thick
;
2293 if (it
->end_of_box_run_p
)
2294 it
->pixel_width
+= thick
;
2297 /* If face has an overline, add the height of the overline
2298 (1 pixel) and a 1 pixel margin to the character height. */
2299 if (face
->overline_p
)
2302 take_vertical_position_into_account (it
);
2305 x_append_composite_glyph (it
);
2307 else if (it
->what
== IT_IMAGE
)
2308 x_produce_image_glyph (it
);
2309 else if (it
->what
== IT_STRETCH
)
2310 x_produce_stretch_glyph (it
);
2312 /* Accumulate dimensions. Note: can't assume that it->descent > 0
2313 because this isn't true for images with `:ascent 100'. */
2314 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
2315 if (it
->area
== TEXT_AREA
)
2316 it
->current_x
+= it
->pixel_width
;
2318 it
->descent
+= it
->extra_line_spacing
;
2320 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
2321 it
->max_descent
= max (it
->max_descent
, it
->descent
);
2322 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
2323 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
2327 /* Estimate the pixel height of the mode or top line on frame F.
2328 FACE_ID specifies what line's height to estimate. */
2331 x_estimate_mode_line_height (f
, face_id
)
2333 enum face_id face_id
;
2335 int height
= FONT_HEIGHT (FRAME_FONT (f
));
2337 /* This function is called so early when Emacs starts that the face
2338 cache and mode line face are not yet initialized. */
2339 if (FRAME_FACE_CACHE (f
))
2341 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2345 height
= FONT_HEIGHT (face
->font
);
2346 if (face
->box_line_width
> 0)
2347 height
+= 2 * face
->box_line_width
;
2355 /***********************************************************************
2357 ***********************************************************************/
2359 /* A sequence of glyphs to be drawn in the same face.
2361 This data structure is not really completely X specific, so it
2362 could possibly, at least partially, be useful for other systems. It
2363 is currently not part of the external redisplay interface because
2364 it's not clear what other systems will need. */
2368 /* X-origin of the string. */
2371 /* Y-origin and y-position of the base line of this string. */
2374 /* The width of the string, not including a face extension. */
2377 /* The width of the string, including a face extension. */
2378 int background_width
;
2380 /* The height of this string. This is the height of the line this
2381 string is drawn in, and can be different from the height of the
2382 font the string is drawn in. */
2385 /* Number of pixels this string overwrites in front of its x-origin.
2386 This number is zero if the string has an lbearing >= 0; it is
2387 -lbearing, if the string has an lbearing < 0. */
2390 /* Number of pixels this string overwrites past its right-most
2391 nominal x-position, i.e. x + width. Zero if the string's
2392 rbearing is <= its nominal width, rbearing - width otherwise. */
2395 /* The frame on which the glyph string is drawn. */
2398 /* The window on which the glyph string is drawn. */
2401 /* X display and window for convenience. */
2405 /* The glyph row for which this string was built. It determines the
2406 y-origin and height of the string. */
2407 struct glyph_row
*row
;
2409 /* The area within row. */
2410 enum glyph_row_area area
;
2412 /* Characters to be drawn, and number of characters. */
2416 /* A face-override for drawing cursors, mouse face and similar. */
2417 enum draw_glyphs_face hl
;
2419 /* Face in which this string is to be drawn. */
2422 /* Font in which this string is to be drawn. */
2425 /* Font info for this string. */
2426 struct font_info
*font_info
;
2428 /* Non-null means this string describes (part of) a composition.
2429 All characters from char2b are drawn composed. */
2430 struct composition
*cmp
;
2432 /* Index of this glyph string's first character in the glyph
2433 definition of CMP. If this is zero, this glyph string describes
2434 the first character of a composition. */
2437 /* 1 means this glyph strings face has to be drawn to the right end
2438 of the window's drawing area. */
2439 unsigned extends_to_end_of_line_p
: 1;
2441 /* 1 means the background of this string has been drawn. */
2442 unsigned background_filled_p
: 1;
2444 /* 1 means glyph string must be drawn with 16-bit functions. */
2445 unsigned two_byte_p
: 1;
2447 /* 1 means that the original font determined for drawing this glyph
2448 string could not be loaded. The member `font' has been set to
2449 the frame's default font in this case. */
2450 unsigned font_not_found_p
: 1;
2452 /* 1 means that the face in which this glyph string is drawn has a
2454 unsigned stippled_p
: 1;
2456 /* 1 means only the foreground of this glyph string must be drawn,
2457 and we should use the physical height of the line this glyph
2458 string appears in as clip rect. */
2459 unsigned for_overlaps_p
: 1;
2461 /* The GC to use for drawing this glyph string. */
2464 /* A pointer to the first glyph in the string. This glyph
2465 corresponds to char2b[0]. Needed to draw rectangles if
2466 font_not_found_p is 1. */
2467 struct glyph
*first_glyph
;
2469 /* Image, if any. */
2472 struct glyph_string
*next
, *prev
;
2479 x_dump_glyph_string (s
)
2480 struct glyph_string
*s
;
2482 fprintf (stderr
, "glyph string\n");
2483 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
2484 s
->x
, s
->y
, s
->width
, s
->height
);
2485 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
2486 fprintf (stderr
, " hl = %d\n", s
->hl
);
2487 fprintf (stderr
, " left overhang = %d, right = %d\n",
2488 s
->left_overhang
, s
->right_overhang
);
2489 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
2490 fprintf (stderr
, " extends to end of line = %d\n",
2491 s
->extends_to_end_of_line_p
);
2492 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
2493 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
2496 #endif /* GLYPH_DEBUG */
2500 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
2501 struct glyph_string
**,
2502 struct glyph_string
*,
2503 struct glyph_string
*));
2504 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
2505 struct glyph_string
**,
2506 struct glyph_string
*,
2507 struct glyph_string
*));
2508 static void x_append_glyph_string
P_ ((struct glyph_string
**,
2509 struct glyph_string
**,
2510 struct glyph_string
*));
2511 static int x_left_overwritten
P_ ((struct glyph_string
*));
2512 static int x_left_overwriting
P_ ((struct glyph_string
*));
2513 static int x_right_overwritten
P_ ((struct glyph_string
*));
2514 static int x_right_overwriting
P_ ((struct glyph_string
*));
2515 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
2517 static void x_init_glyph_string
P_ ((struct glyph_string
*,
2518 XChar2b
*, struct window
*,
2520 enum glyph_row_area
, int,
2521 enum draw_glyphs_face
));
2522 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
2523 enum glyph_row_area
, int, int,
2524 enum draw_glyphs_face
, int));
2525 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2526 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2527 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2529 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2530 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2531 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2532 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2533 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2534 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2535 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2536 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2537 static void x_get_glyph_overhangs
P_ ((struct glyph
*, struct frame
*,
2539 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
2540 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
2541 unsigned long *, double, int));
2542 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2543 double, int, unsigned long));
2544 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2545 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2546 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2547 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2548 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
2549 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
2550 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2552 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2553 int, int, int, int, XRectangle
*));
2554 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2555 int, int, int, XRectangle
*));
2556 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
2557 enum glyph_row_area
));
2558 static int x_fill_stretch_glyph_string
P_ ((struct glyph_string
*,
2560 enum glyph_row_area
, int, int));
2563 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
2567 /* Append the list of glyph strings with head H and tail T to the list
2568 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
2571 x_append_glyph_string_lists (head
, tail
, h
, t
)
2572 struct glyph_string
**head
, **tail
;
2573 struct glyph_string
*h
, *t
;
2587 /* Prepend the list of glyph strings with head H and tail T to the
2588 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
2592 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
2593 struct glyph_string
**head
, **tail
;
2594 struct glyph_string
*h
, *t
;
2608 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
2609 Set *HEAD and *TAIL to the resulting list. */
2612 x_append_glyph_string (head
, tail
, s
)
2613 struct glyph_string
**head
, **tail
;
2614 struct glyph_string
*s
;
2616 s
->next
= s
->prev
= NULL
;
2617 x_append_glyph_string_lists (head
, tail
, s
, s
);
2621 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2626 struct glyph_string
*s
;
2628 if (s
->font
== FRAME_FONT (s
->f
)
2629 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2630 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2632 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
2635 /* Cursor on non-default face: must merge. */
2639 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
2640 xgcv
.foreground
= s
->face
->background
;
2642 /* If the glyph would be invisible, try a different foreground. */
2643 if (xgcv
.foreground
== xgcv
.background
)
2644 xgcv
.foreground
= s
->face
->foreground
;
2645 if (xgcv
.foreground
== xgcv
.background
)
2646 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
2647 if (xgcv
.foreground
== xgcv
.background
)
2648 xgcv
.foreground
= s
->face
->foreground
;
2650 /* Make sure the cursor is distinct from text in this face. */
2651 if (xgcv
.background
== s
->face
->background
2652 && xgcv
.foreground
== s
->face
->foreground
)
2654 xgcv
.background
= s
->face
->foreground
;
2655 xgcv
.foreground
= s
->face
->background
;
2658 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2659 xgcv
.font
= s
->font
->fid
;
2660 xgcv
.graphics_exposures
= False
;
2661 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2663 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2664 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2667 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2668 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2670 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2675 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2678 x_set_mouse_face_gc (s
)
2679 struct glyph_string
*s
;
2684 /* What face has to be used last for the mouse face? */
2685 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2686 face
= FACE_FROM_ID (s
->f
, face_id
);
2688 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
2690 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2691 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2693 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2694 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2695 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2697 /* If font in this face is same as S->font, use it. */
2698 if (s
->font
== s
->face
->font
)
2699 s
->gc
= s
->face
->gc
;
2702 /* Otherwise construct scratch_cursor_gc with values from FACE
2707 xgcv
.background
= s
->face
->background
;
2708 xgcv
.foreground
= s
->face
->foreground
;
2709 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2710 xgcv
.font
= s
->font
->fid
;
2711 xgcv
.graphics_exposures
= False
;
2712 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2714 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2715 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2718 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2719 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2721 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2724 xassert (s
->gc
!= 0);
2728 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2729 Faces to use in the mode line have already been computed when the
2730 matrix was built, so there isn't much to do, here. */
2733 x_set_mode_line_face_gc (s
)
2734 struct glyph_string
*s
;
2736 s
->gc
= s
->face
->gc
;
2740 /* Set S->gc of glyph string S for drawing that glyph string. Set
2741 S->stippled_p to a non-zero value if the face of S has a stipple
2745 x_set_glyph_string_gc (s
)
2746 struct glyph_string
*s
;
2748 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2750 if (s
->hl
== DRAW_NORMAL_TEXT
)
2752 s
->gc
= s
->face
->gc
;
2753 s
->stippled_p
= s
->face
->stipple
!= 0;
2755 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2757 x_set_mode_line_face_gc (s
);
2758 s
->stippled_p
= s
->face
->stipple
!= 0;
2760 else if (s
->hl
== DRAW_CURSOR
)
2762 x_set_cursor_gc (s
);
2765 else if (s
->hl
== DRAW_MOUSE_FACE
)
2767 x_set_mouse_face_gc (s
);
2768 s
->stippled_p
= s
->face
->stipple
!= 0;
2770 else if (s
->hl
== DRAW_IMAGE_RAISED
2771 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2773 s
->gc
= s
->face
->gc
;
2774 s
->stippled_p
= s
->face
->stipple
!= 0;
2778 s
->gc
= s
->face
->gc
;
2779 s
->stippled_p
= s
->face
->stipple
!= 0;
2782 /* GC must have been set. */
2783 xassert (s
->gc
!= 0);
2787 /* Return in *R the clipping rectangle for glyph string S. */
2790 x_get_glyph_string_clip_rect (s
, r
)
2791 struct glyph_string
*s
;
2794 if (s
->row
->full_width_p
)
2796 /* Draw full-width. X coordinates are relative to S->w->left. */
2797 int canon_x
= CANON_X_UNIT (s
->f
);
2799 r
->x
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
2800 r
->width
= XFASTINT (s
->w
->width
) * canon_x
;
2802 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
2804 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
2805 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
2809 r
->x
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
2811 /* Unless displaying a mode or menu bar line, which are always
2812 fully visible, clip to the visible part of the row. */
2813 if (s
->w
->pseudo_window_p
)
2814 r
->height
= s
->row
->visible_height
;
2816 r
->height
= s
->height
;
2820 /* This is a text line that may be partially visible. */
2821 r
->x
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
2822 r
->width
= window_box_width (s
->w
, s
->area
);
2823 r
->height
= s
->row
->visible_height
;
2826 /* If S draws overlapping rows, it's sufficient to use the top and
2827 bottom of the window for clipping because this glyph string
2828 intentionally draws over other lines. */
2829 if (s
->for_overlaps_p
)
2831 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2832 r
->height
= window_text_bottom_y (s
->w
) - r
->y
;
2836 /* Don't use S->y for clipping because it doesn't take partially
2837 visible lines into account. For example, it can be negative for
2838 partially visible lines at the top of a window. */
2839 if (!s
->row
->full_width_p
2840 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2841 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2843 r
->y
= max (0, s
->row
->y
);
2845 /* If drawing a tool-bar window, draw it over the internal border
2846 at the top of the window. */
2847 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
2848 r
->y
-= s
->f
->output_data
.x
->internal_border_width
;
2851 r
->y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->y
);
2855 /* Set clipping for output of glyph string S. S may be part of a mode
2856 line or menu if we don't have X toolkit support. */
2859 x_set_glyph_string_clipping (s
)
2860 struct glyph_string
*s
;
2863 x_get_glyph_string_clip_rect (s
, &r
);
2864 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
2868 /* Compute left and right overhang of glyph string S. If S is a glyph
2869 string for a composition, assume overhangs don't exist. */
2872 x_compute_glyph_string_overhangs (s
)
2873 struct glyph_string
*s
;
2876 && s
->first_glyph
->type
== CHAR_GLYPH
)
2879 int direction
, font_ascent
, font_descent
;
2880 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
2881 &font_ascent
, &font_descent
, &cs
);
2882 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
2883 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
2888 /* Compute overhangs and x-positions for glyph string S and its
2889 predecessors, or successors. X is the starting x-position for S.
2890 BACKWARD_P non-zero means process predecessors. */
2893 x_compute_overhangs_and_x (s
, x
, backward_p
)
2894 struct glyph_string
*s
;
2902 x_compute_glyph_string_overhangs (s
);
2912 x_compute_glyph_string_overhangs (s
);
2921 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
2922 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
2923 assumed to be zero. */
2926 x_get_glyph_overhangs (glyph
, f
, left
, right
)
2927 struct glyph
*glyph
;
2933 if (glyph
->type
== CHAR_GLYPH
)
2937 struct font_info
*font_info
;
2941 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
2943 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
2945 && (pcm
= x_per_char_metric (font
, &char2b
)))
2947 if (pcm
->rbearing
> pcm
->width
)
2948 *right
= pcm
->rbearing
- pcm
->width
;
2949 if (pcm
->lbearing
< 0)
2950 *left
= -pcm
->lbearing
;
2956 /* Return the index of the first glyph preceding glyph string S that
2957 is overwritten by S because of S's left overhang. Value is -1
2958 if no glyphs are overwritten. */
2961 x_left_overwritten (s
)
2962 struct glyph_string
*s
;
2966 if (s
->left_overhang
)
2969 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2970 int first
= s
->first_glyph
- glyphs
;
2972 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
2973 x
-= glyphs
[i
].pixel_width
;
2984 /* Return the index of the first glyph preceding glyph string S that
2985 is overwriting S because of its right overhang. Value is -1 if no
2986 glyph in front of S overwrites S. */
2989 x_left_overwriting (s
)
2990 struct glyph_string
*s
;
2993 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2994 int first
= s
->first_glyph
- glyphs
;
2998 for (i
= first
- 1; i
>= 0; --i
)
3001 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3004 x
-= glyphs
[i
].pixel_width
;
3011 /* Return the index of the last glyph following glyph string S that is
3012 not overwritten by S because of S's right overhang. Value is -1 if
3013 no such glyph is found. */
3016 x_right_overwritten (s
)
3017 struct glyph_string
*s
;
3021 if (s
->right_overhang
)
3024 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3025 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3026 int end
= s
->row
->used
[s
->area
];
3028 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
3029 x
+= glyphs
[i
].pixel_width
;
3038 /* Return the index of the last glyph following glyph string S that
3039 overwrites S because of its left overhang. Value is negative
3040 if no such glyph is found. */
3043 x_right_overwriting (s
)
3044 struct glyph_string
*s
;
3047 int end
= s
->row
->used
[s
->area
];
3048 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3049 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3053 for (i
= first
; i
< end
; ++i
)
3056 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3059 x
+= glyphs
[i
].pixel_width
;
3066 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
3069 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
3070 struct glyph_string
*s
;
3074 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
3075 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3076 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3077 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3081 /* Draw the background of glyph_string S. If S->background_filled_p
3082 is non-zero don't draw it. FORCE_P non-zero means draw the
3083 background even if it wouldn't be drawn normally. This is used
3084 when a string preceding S draws into the background of S, or S
3085 contains the first component of a composition. */
3088 x_draw_glyph_string_background (s
, force_p
)
3089 struct glyph_string
*s
;
3092 /* Nothing to do if background has already been drawn or if it
3093 shouldn't be drawn in the first place. */
3094 if (!s
->background_filled_p
)
3096 int box_line_width
= max (s
->face
->box_line_width
, 0);
3100 /* Fill background with a stipple pattern. */
3101 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3102 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
3103 s
->y
+ box_line_width
,
3104 s
->background_width
,
3105 s
->height
- 2 * box_line_width
);
3106 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3107 s
->background_filled_p
= 1;
3109 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
3110 || s
->font_not_found_p
3111 || s
->extends_to_end_of_line_p
3114 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
3115 s
->background_width
,
3116 s
->height
- 2 * box_line_width
);
3117 s
->background_filled_p
= 1;
3123 /* Draw the foreground of glyph string S. */
3126 x_draw_glyph_string_foreground (s
)
3127 struct glyph_string
*s
;
3131 /* If first glyph of S has a left box line, start drawing the text
3132 of S to the right of that box line. */
3133 if (s
->face
->box
!= FACE_NO_BOX
3134 && s
->first_glyph
->left_box_line_p
)
3135 x
= s
->x
+ abs (s
->face
->box_line_width
);
3139 /* Draw characters of S as rectangles if S's font could not be
3141 if (s
->font_not_found_p
)
3143 for (i
= 0; i
< s
->nchars
; ++i
)
3145 struct glyph
*g
= s
->first_glyph
+ i
;
3146 XDrawRectangle (s
->display
, s
->window
,
3147 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
3149 x
+= g
->pixel_width
;
3154 char *char1b
= (char *) s
->char2b
;
3155 int boff
= s
->font_info
->baseline_offset
;
3157 if (s
->font_info
->vertical_centering
)
3158 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
3160 /* If we can use 8-bit functions, condense S->char2b. */
3162 for (i
= 0; i
< s
->nchars
; ++i
)
3163 char1b
[i
] = s
->char2b
[i
].byte2
;
3165 /* Draw text with XDrawString if background has already been
3166 filled. Otherwise, use XDrawImageString. (Note that
3167 XDrawImageString is usually faster than XDrawString.) Always
3168 use XDrawImageString when drawing the cursor so that there is
3169 no chance that characters under a box cursor are invisible. */
3170 if (s
->for_overlaps_p
3171 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
3173 /* Draw characters with 16-bit or 8-bit functions. */
3175 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
3176 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3178 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
3179 s
->ybase
- boff
, char1b
, s
->nchars
);
3184 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
3185 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3187 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
3188 s
->ybase
- boff
, char1b
, s
->nchars
);
3193 /* Draw the foreground of composite glyph string S. */
3196 x_draw_composite_glyph_string_foreground (s
)
3197 struct glyph_string
*s
;
3201 /* If first glyph of S has a left box line, start drawing the text
3202 of S to the right of that box line. */
3203 if (s
->face
->box
!= FACE_NO_BOX
3204 && s
->first_glyph
->left_box_line_p
)
3205 x
= s
->x
+ abs (s
->face
->box_line_width
);
3209 /* S is a glyph string for a composition. S->gidx is the index of
3210 the first character drawn for glyphs of this composition.
3211 S->gidx == 0 means we are drawing the very first character of
3212 this composition. */
3214 /* Draw a rectangle for the composition if the font for the very
3215 first character of the composition could not be loaded. */
3216 if (s
->font_not_found_p
)
3219 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
3220 s
->width
- 1, s
->height
- 1);
3224 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3225 XDrawString16 (s
->display
, s
->window
, s
->gc
,
3226 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3227 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3233 #ifdef USE_X_TOOLKIT
3235 static struct frame
*x_frame_of_widget
P_ ((Widget
));
3236 static Boolean cvt_string_to_pixel
P_ ((Display
*, XrmValue
*, Cardinal
*,
3237 XrmValue
*, XrmValue
*, XtPointer
*));
3238 static void cvt_pixel_dtor
P_ ((XtAppContext
, XrmValue
*, XtPointer
,
3239 XrmValue
*, Cardinal
*));
3242 /* Return the frame on which widget WIDGET is used.. Abort if frame
3243 cannot be determined. */
3245 static struct frame
*
3246 x_frame_of_widget (widget
)
3249 struct x_display_info
*dpyinfo
;
3253 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
3255 /* Find the top-level shell of the widget. Note that this function
3256 can be called when the widget is not yet realized, so XtWindow
3257 (widget) == 0. That's the reason we can't simply use
3258 x_any_window_to_frame. */
3259 while (!XtIsTopLevelShell (widget
))
3260 widget
= XtParent (widget
);
3262 /* Look for a frame with that top-level widget. Allocate the color
3263 on that frame to get the right gamma correction value. */
3264 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
3265 if (GC_FRAMEP (XCAR (tail
))
3266 && (f
= XFRAME (XCAR (tail
)),
3267 (f
->output_data
.nothing
!= 1
3268 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
3269 && f
->output_data
.x
->widget
== widget
)
3276 /* Allocate the color COLOR->pixel on the screen and display of
3277 widget WIDGET in colormap CMAP. If an exact match cannot be
3278 allocated, try the nearest color available. Value is non-zero
3279 if successful. This is called from lwlib. */
3282 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
3287 struct frame
*f
= x_frame_of_widget (widget
);
3288 return x_alloc_nearest_color (f
, cmap
, color
);
3292 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3293 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3294 If this produces the same color as PIXEL, try a color where all RGB
3295 values have DELTA added. Return the allocated color in *PIXEL.
3296 DISPLAY is the X display, CMAP is the colormap to operate on.
3297 Value is non-zero if successful. */
3300 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
3304 unsigned long *pixel
;
3308 struct frame
*f
= x_frame_of_widget (widget
);
3309 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
3313 /* Structure specifying which arguments should be passed by Xt to
3314 cvt_string_to_pixel. We want the widget's screen and colormap. */
3316 static XtConvertArgRec cvt_string_to_pixel_args
[] =
3318 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
3320 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
3325 /* The address of this variable is returned by
3326 cvt_string_to_pixel. */
3328 static Pixel cvt_string_to_pixel_value
;
3331 /* Convert a color name to a pixel color.
3333 DPY is the display we are working on.
3335 ARGS is an array of *NARGS XrmValue structures holding additional
3336 information about the widget for which the conversion takes place.
3337 The contents of this array are determined by the specification
3338 in cvt_string_to_pixel_args.
3340 FROM is a pointer to an XrmValue which points to the color name to
3341 convert. TO is an XrmValue in which to return the pixel color.
3343 CLOSURE_RET is a pointer to user-data, in which we record if
3344 we allocated the color or not.
3346 Value is True if successful, False otherwise. */
3349 cvt_string_to_pixel (dpy
, args
, nargs
, from
, to
, closure_ret
)
3353 XrmValue
*from
, *to
;
3354 XtPointer
*closure_ret
;
3364 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
3365 "wrongParameters", "cvt_string_to_pixel",
3367 "Screen and colormap args required", NULL
, NULL
);
3371 screen
= *(Screen
**) args
[0].addr
;
3372 cmap
= *(Colormap
*) args
[1].addr
;
3373 color_name
= (String
) from
->addr
;
3375 if (strcmp (color_name
, XtDefaultBackground
) == 0)
3377 *closure_ret
= (XtPointer
) False
;
3378 pixel
= WhitePixelOfScreen (screen
);
3380 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
3382 *closure_ret
= (XtPointer
) False
;
3383 pixel
= BlackPixelOfScreen (screen
);
3385 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
3386 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
3388 pixel
= color
.pixel
;
3389 *closure_ret
= (XtPointer
) True
;
3394 Cardinal nparams
= 1;
3396 params
[0] = color_name
;
3397 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
3398 "badValue", "cvt_string_to_pixel",
3399 "XtToolkitError", "Invalid color `%s'",
3404 if (to
->addr
!= NULL
)
3406 if (to
->size
< sizeof (Pixel
))
3408 to
->size
= sizeof (Pixel
);
3412 *(Pixel
*) to
->addr
= pixel
;
3416 cvt_string_to_pixel_value
= pixel
;
3417 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
3420 to
->size
= sizeof (Pixel
);
3425 /* Free a pixel color which was previously allocated via
3426 cvt_string_to_pixel. This is registered as the destructor
3427 for this type of resource via XtSetTypeConverter.
3429 APP is the application context in which we work.
3431 TO is a pointer to an XrmValue holding the color to free.
3432 CLOSURE is the value we stored in CLOSURE_RET for this color
3433 in cvt_string_to_pixel.
3435 ARGS and NARGS are like for cvt_string_to_pixel. */
3438 cvt_pixel_dtor (app
, to
, closure
, args
, nargs
)
3447 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
3449 "Screen and colormap arguments required",
3452 else if (closure
!= NULL
)
3454 /* We did allocate the pixel, so free it. */
3455 Screen
*screen
= *(Screen
**) args
[0].addr
;
3456 Colormap cmap
= *(Colormap
*) args
[1].addr
;
3457 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
3458 (Pixel
*) to
->addr
, 1);
3463 #endif /* USE_X_TOOLKIT */
3466 /* Value is an array of XColor structures for the contents of the
3467 color map of display DPY. Set *NCELLS to the size of the array.
3468 Note that this probably shouldn't be called for large color maps,
3469 say a 24-bit TrueColor map. */
3471 static const XColor
*
3472 x_color_cells (dpy
, ncells
)
3476 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
3478 if (dpyinfo
->color_cells
== NULL
)
3480 Screen
*screen
= dpyinfo
->screen
;
3483 dpyinfo
->ncolor_cells
3484 = XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
3485 dpyinfo
->color_cells
3486 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
3487 * sizeof *dpyinfo
->color_cells
);
3489 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
3490 dpyinfo
->color_cells
[i
].pixel
= i
;
3492 XQueryColors (dpy
, dpyinfo
->cmap
,
3493 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
3496 *ncells
= dpyinfo
->ncolor_cells
;
3497 return dpyinfo
->color_cells
;
3501 /* On frame F, translate pixel colors to RGB values for the NCOLORS
3502 colors in COLORS. Use cached information, if available. */
3505 x_query_colors (f
, colors
, ncolors
)
3510 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3512 if (dpyinfo
->color_cells
)
3515 for (i
= 0; i
< ncolors
; ++i
)
3517 unsigned long pixel
= colors
[i
].pixel
;
3518 xassert (pixel
< dpyinfo
->ncolor_cells
);
3519 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
3520 colors
[i
] = dpyinfo
->color_cells
[pixel
];
3524 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
3528 /* On frame F, translate pixel color to RGB values for the color in
3529 COLOR. Use cached information, if available. */
3532 x_query_color (f
, color
)
3536 x_query_colors (f
, color
, 1);
3540 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
3541 exact match can't be allocated, try the nearest color available.
3542 Value is non-zero if successful. Set *COLOR to the color
3546 x_alloc_nearest_color_1 (dpy
, cmap
, color
)
3553 rc
= XAllocColor (dpy
, cmap
, color
);
3556 /* If we got to this point, the colormap is full, so we're going
3557 to try to get the next closest color. The algorithm used is
3558 a least-squares matching, which is what X uses for closest
3559 color matching with StaticColor visuals. */
3561 unsigned long nearest_delta
= ~0;
3563 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
3565 for (nearest
= i
= 0; i
< ncells
; ++i
)
3567 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
3568 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
3569 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
3570 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
3572 if (delta
< nearest_delta
)
3575 nearest_delta
= delta
;
3579 color
->red
= cells
[nearest
].red
;
3580 color
->green
= cells
[nearest
].green
;
3581 color
->blue
= cells
[nearest
].blue
;
3582 rc
= XAllocColor (dpy
, cmap
, color
);
3586 /* If allocation succeeded, and the allocated pixel color is not
3587 equal to a cached pixel color recorded earlier, there was a
3588 change in the colormap, so clear the color cache. */
3589 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
3590 XColor
*cached_color
;
3592 if (dpyinfo
->color_cells
3593 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
3594 (cached_color
->red
!= color
->red
3595 || cached_color
->blue
!= color
->blue
3596 || cached_color
->green
!= color
->green
)))
3598 xfree (dpyinfo
->color_cells
);
3599 dpyinfo
->color_cells
= NULL
;
3600 dpyinfo
->ncolor_cells
= 0;
3604 #ifdef DEBUG_X_COLORS
3606 register_color (color
->pixel
);
3607 #endif /* DEBUG_X_COLORS */
3613 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
3614 exact match can't be allocated, try the nearest color available.
3615 Value is non-zero if successful. Set *COLOR to the color
3619 x_alloc_nearest_color (f
, cmap
, color
)
3624 gamma_correct (f
, color
);
3625 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
3629 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
3630 It's necessary to do this instead of just using PIXEL directly to
3631 get color reference counts right. */
3634 x_copy_color (f
, pixel
)
3636 unsigned long pixel
;
3640 color
.pixel
= pixel
;
3642 x_query_color (f
, &color
);
3643 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3645 #ifdef DEBUG_X_COLORS
3646 register_color (pixel
);
3652 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
3653 It's necessary to do this instead of just using PIXEL directly to
3654 get color reference counts right. */
3657 x_copy_dpy_color (dpy
, cmap
, pixel
)
3660 unsigned long pixel
;
3664 color
.pixel
= pixel
;
3666 XQueryColor (dpy
, cmap
, &color
);
3667 XAllocColor (dpy
, cmap
, &color
);
3669 #ifdef DEBUG_X_COLORS
3670 register_color (pixel
);
3676 /* Brightness beyond which a color won't have its highlight brightness
3679 Nominally, highlight colors for `3d' faces are calculated by
3680 brightening an object's color by a constant scale factor, but this
3681 doesn't yield good results for dark colors, so for colors who's
3682 brightness is less than this value (on a scale of 0-65535) have an
3683 use an additional additive factor.
3685 The value here is set so that the default menu-bar/mode-line color
3686 (grey75) will not have its highlights changed at all. */
3687 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
3690 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3691 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3692 If this produces the same color as PIXEL, try a color where all RGB
3693 values have DELTA added. Return the allocated color in *PIXEL.
3694 DISPLAY is the X display, CMAP is the colormap to operate on.
3695 Value is non-zero if successful. */
3698 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
3702 unsigned long *pixel
;
3710 /* Get RGB color values. */
3711 color
.pixel
= *pixel
;
3712 x_query_color (f
, &color
);
3714 /* Change RGB values by specified FACTOR. Avoid overflow! */
3715 xassert (factor
>= 0);
3716 new.red
= min (0xffff, factor
* color
.red
);
3717 new.green
= min (0xffff, factor
* color
.green
);
3718 new.blue
= min (0xffff, factor
* color
.blue
);
3720 /* Calculate brightness of COLOR. */
3721 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
3723 /* We only boost colors that are darker than
3724 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
3725 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
3726 /* Make an additive adjustment to NEW, because it's dark enough so
3727 that scaling by FACTOR alone isn't enough. */
3729 /* How far below the limit this color is (0 - 1, 1 being darker). */
3730 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
3731 /* The additive adjustment. */
3732 int min_delta
= delta
* dimness
* factor
/ 2;
3736 new.red
= max (0, new.red
- min_delta
);
3737 new.green
= max (0, new.green
- min_delta
);
3738 new.blue
= max (0, new.blue
- min_delta
);
3742 new.red
= min (0xffff, min_delta
+ new.red
);
3743 new.green
= min (0xffff, min_delta
+ new.green
);
3744 new.blue
= min (0xffff, min_delta
+ new.blue
);
3748 /* Try to allocate the color. */
3749 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3752 if (new.pixel
== *pixel
)
3754 /* If we end up with the same color as before, try adding
3755 delta to the RGB values. */
3756 x_free_colors (f
, &new.pixel
, 1);
3758 new.red
= min (0xffff, delta
+ color
.red
);
3759 new.green
= min (0xffff, delta
+ color
.green
);
3760 new.blue
= min (0xffff, delta
+ color
.blue
);
3761 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3772 /* Set up the foreground color for drawing relief lines of glyph
3773 string S. RELIEF is a pointer to a struct relief containing the GC
3774 with which lines will be drawn. Use a color that is FACTOR or
3775 DELTA lighter or darker than the relief's background which is found
3776 in S->f->output_data.x->relief_background. If such a color cannot
3777 be allocated, use DEFAULT_PIXEL, instead. */
3780 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3782 struct relief
*relief
;
3785 unsigned long default_pixel
;
3788 struct x_output
*di
= f
->output_data
.x
;
3789 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
3790 unsigned long pixel
;
3791 unsigned long background
= di
->relief_background
;
3792 Colormap cmap
= FRAME_X_COLORMAP (f
);
3793 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3794 Display
*dpy
= FRAME_X_DISPLAY (f
);
3796 xgcv
.graphics_exposures
= False
;
3797 xgcv
.line_width
= 1;
3799 /* Free previously allocated color. The color cell will be reused
3800 when it has been freed as many times as it was allocated, so this
3801 doesn't affect faces using the same colors. */
3803 && relief
->allocated_p
)
3805 x_free_colors (f
, &relief
->pixel
, 1);
3806 relief
->allocated_p
= 0;
3809 /* Allocate new color. */
3810 xgcv
.foreground
= default_pixel
;
3812 if (dpyinfo
->n_planes
!= 1
3813 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
3815 relief
->allocated_p
= 1;
3816 xgcv
.foreground
= relief
->pixel
= pixel
;
3819 if (relief
->gc
== 0)
3821 xgcv
.stipple
= dpyinfo
->gray
;
3823 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
3826 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
3830 /* Set up colors for the relief lines around glyph string S. */
3833 x_setup_relief_colors (s
)
3834 struct glyph_string
*s
;
3836 struct x_output
*di
= s
->f
->output_data
.x
;
3837 unsigned long color
;
3839 if (s
->face
->use_box_color_for_shadows_p
)
3840 color
= s
->face
->box_color
;
3841 else if (s
->first_glyph
->type
== IMAGE_GLYPH
3843 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
3844 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
3849 /* Get the background color of the face. */
3850 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3851 color
= xgcv
.background
;
3854 if (di
->white_relief
.gc
== 0
3855 || color
!= di
->relief_background
)
3857 di
->relief_background
= color
;
3858 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3859 WHITE_PIX_DEFAULT (s
->f
));
3860 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3861 BLACK_PIX_DEFAULT (s
->f
));
3866 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3867 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3868 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3869 relief. LEFT_P non-zero means draw a relief on the left side of
3870 the rectangle. RIGHT_P non-zero means draw a relief on the right
3871 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3875 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3876 raised_p
, left_p
, right_p
, clip_rect
)
3878 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
3879 XRectangle
*clip_rect
;
3881 Display
*dpy
= FRAME_X_DISPLAY (f
);
3882 Window window
= FRAME_X_WINDOW (f
);
3887 gc
= f
->output_data
.x
->white_relief
.gc
;
3889 gc
= f
->output_data
.x
->black_relief
.gc
;
3890 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
3893 for (i
= 0; i
< width
; ++i
)
3894 XDrawLine (dpy
, window
, gc
,
3895 left_x
+ i
* left_p
, top_y
+ i
,
3896 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3900 for (i
= 0; i
< width
; ++i
)
3901 XDrawLine (dpy
, window
, gc
,
3902 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
3904 XSetClipMask (dpy
, gc
, None
);
3906 gc
= f
->output_data
.x
->black_relief
.gc
;
3908 gc
= f
->output_data
.x
->white_relief
.gc
;
3909 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
3912 for (i
= 0; i
< width
; ++i
)
3913 XDrawLine (dpy
, window
, gc
,
3914 left_x
+ i
* left_p
, bottom_y
- i
,
3915 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3919 for (i
= 0; i
< width
; ++i
)
3920 XDrawLine (dpy
, window
, gc
,
3921 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3923 XSetClipMask (dpy
, gc
, None
);
3927 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3928 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3929 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3930 left side of the rectangle. RIGHT_P non-zero means draw a line
3931 on the right side of the rectangle. CLIP_RECT is the clipping
3932 rectangle to use when drawing. */
3935 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3936 left_p
, right_p
, clip_rect
)
3937 struct glyph_string
*s
;
3938 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
;
3939 XRectangle
*clip_rect
;
3943 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3944 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
3945 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
3948 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3949 left_x
, top_y
, right_x
- left_x
+ 1, width
);
3953 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3954 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
3957 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3958 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
3962 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3963 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
3965 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3966 XSetClipMask (s
->display
, s
->gc
, None
);
3970 /* Draw a box around glyph string S. */
3973 x_draw_glyph_string_box (s
)
3974 struct glyph_string
*s
;
3976 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3977 int left_p
, right_p
;
3978 struct glyph
*last_glyph
;
3979 XRectangle clip_rect
;
3981 last_x
= window_box_right (s
->w
, s
->area
);
3982 if (s
->row
->full_width_p
3983 && !s
->w
->pseudo_window_p
)
3985 last_x
+= FRAME_X_RIGHT_FRINGE_WIDTH (s
->f
);
3986 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
3987 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
3990 /* The glyph that may have a right box line. */
3991 last_glyph
= (s
->cmp
|| s
->img
3993 : s
->first_glyph
+ s
->nchars
- 1);
3995 width
= abs (s
->face
->box_line_width
);
3996 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
3998 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
4000 : min (last_x
, s
->x
+ s
->background_width
) - 1);
4002 bottom_y
= top_y
+ s
->height
- 1;
4004 left_p
= (s
->first_glyph
->left_box_line_p
4005 || (s
->hl
== DRAW_MOUSE_FACE
4007 || s
->prev
->hl
!= s
->hl
)));
4008 right_p
= (last_glyph
->right_box_line_p
4009 || (s
->hl
== DRAW_MOUSE_FACE
4011 || s
->next
->hl
!= s
->hl
)));
4013 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4015 if (s
->face
->box
== FACE_SIMPLE_BOX
)
4016 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
4017 left_p
, right_p
, &clip_rect
);
4020 x_setup_relief_colors (s
);
4021 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
4022 width
, raised_p
, left_p
, right_p
, &clip_rect
);
4027 /* Draw foreground of image glyph string S. */
4030 x_draw_image_foreground (s
)
4031 struct glyph_string
*s
;
4034 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
4036 /* If first glyph of S has a left box line, start drawing it to the
4037 right of that line. */
4038 if (s
->face
->box
!= FACE_NO_BOX
4039 && s
->first_glyph
->left_box_line_p
)
4040 x
= s
->x
+ abs (s
->face
->box_line_width
);
4044 /* If there is a margin around the image, adjust x- and y-position
4046 x
+= s
->img
->hmargin
;
4047 y
+= s
->img
->vmargin
;
4053 /* We can't set both a clip mask and use XSetClipRectangles
4054 because the latter also sets a clip mask. We also can't
4055 trust on the shape extension to be available
4056 (XShapeCombineRegion). So, compute the rectangle to draw
4058 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4061 XRectangle clip_rect
, image_rect
, r
;
4063 xgcv
.clip_mask
= s
->img
->mask
;
4064 xgcv
.clip_x_origin
= x
;
4065 xgcv
.clip_y_origin
= y
;
4066 xgcv
.function
= GXcopy
;
4067 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4069 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4072 image_rect
.width
= s
->img
->width
;
4073 image_rect
.height
= s
->img
->height
;
4074 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
4075 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
4076 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
4080 XRectangle clip_rect
, image_rect
, r
;
4082 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4085 image_rect
.width
= s
->img
->width
;
4086 image_rect
.height
= s
->img
->height
;
4087 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
4088 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
4089 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
4091 /* When the image has a mask, we can expect that at
4092 least part of a mouse highlight or a block cursor will
4093 be visible. If the image doesn't have a mask, make
4094 a block cursor visible by drawing a rectangle around
4095 the image. I believe it's looking better if we do
4096 nothing here for mouse-face. */
4097 if (s
->hl
== DRAW_CURSOR
)
4098 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
4099 s
->img
->width
- 1, s
->img
->height
- 1);
4103 /* Draw a rectangle if image could not be loaded. */
4104 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
4105 s
->img
->width
- 1, s
->img
->height
- 1);
4109 /* Draw a relief around the image glyph string S. */
4112 x_draw_image_relief (s
)
4113 struct glyph_string
*s
;
4115 int x0
, y0
, x1
, y1
, thick
, raised_p
;
4118 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
4120 /* If first glyph of S has a left box line, start drawing it to the
4121 right of that line. */
4122 if (s
->face
->box
!= FACE_NO_BOX
4123 && s
->first_glyph
->left_box_line_p
)
4124 x
= s
->x
+ abs (s
->face
->box_line_width
);
4128 /* If there is a margin around the image, adjust x- and y-position
4130 x
+= s
->img
->hmargin
;
4131 y
+= s
->img
->vmargin
;
4133 if (s
->hl
== DRAW_IMAGE_SUNKEN
4134 || s
->hl
== DRAW_IMAGE_RAISED
)
4136 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
4137 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
4141 thick
= abs (s
->img
->relief
);
4142 raised_p
= s
->img
->relief
> 0;
4147 x1
= x
+ s
->img
->width
+ thick
- 1;
4148 y1
= y
+ s
->img
->height
+ thick
- 1;
4150 x_setup_relief_colors (s
);
4151 x_get_glyph_string_clip_rect (s
, &r
);
4152 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
4156 /* Draw the foreground of image glyph string S to PIXMAP. */
4159 x_draw_image_foreground_1 (s
, pixmap
)
4160 struct glyph_string
*s
;
4164 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
4166 /* If first glyph of S has a left box line, start drawing it to the
4167 right of that line. */
4168 if (s
->face
->box
!= FACE_NO_BOX
4169 && s
->first_glyph
->left_box_line_p
)
4170 x
= abs (s
->face
->box_line_width
);
4174 /* If there is a margin around the image, adjust x- and y-position
4176 x
+= s
->img
->hmargin
;
4177 y
+= s
->img
->vmargin
;
4183 /* We can't set both a clip mask and use XSetClipRectangles
4184 because the latter also sets a clip mask. We also can't
4185 trust on the shape extension to be available
4186 (XShapeCombineRegion). So, compute the rectangle to draw
4188 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4192 xgcv
.clip_mask
= s
->img
->mask
;
4193 xgcv
.clip_x_origin
= x
;
4194 xgcv
.clip_y_origin
= y
;
4195 xgcv
.function
= GXcopy
;
4196 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4198 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4199 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4200 XSetClipMask (s
->display
, s
->gc
, None
);
4204 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4205 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4207 /* When the image has a mask, we can expect that at
4208 least part of a mouse highlight or a block cursor will
4209 be visible. If the image doesn't have a mask, make
4210 a block cursor visible by drawing a rectangle around
4211 the image. I believe it's looking better if we do
4212 nothing here for mouse-face. */
4213 if (s
->hl
== DRAW_CURSOR
)
4214 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
4215 s
->img
->width
- 1, s
->img
->height
- 1);
4219 /* Draw a rectangle if image could not be loaded. */
4220 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
4221 s
->img
->width
- 1, s
->img
->height
- 1);
4225 /* Draw part of the background of glyph string S. X, Y, W, and H
4226 give the rectangle to draw. */
4229 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
4230 struct glyph_string
*s
;
4235 /* Fill background with a stipple pattern. */
4236 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4237 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
4238 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4241 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
4245 /* Draw image glyph string S.
4248 s->x +-------------------------
4251 | +-------------------------
4254 | | +-------------------
4260 x_draw_image_glyph_string (s
)
4261 struct glyph_string
*s
;
4264 int box_line_hwidth
= abs (s
->face
->box_line_width
);
4265 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
4267 Pixmap pixmap
= None
;
4269 height
= s
->height
- 2 * box_line_vwidth
;
4271 /* Fill background with face under the image. Do it only if row is
4272 taller than image or if image has a clip mask to reduce
4274 s
->stippled_p
= s
->face
->stipple
!= 0;
4275 if (height
> s
->img
->height
4279 || s
->img
->pixmap
== 0
4280 || s
->width
!= s
->background_width
)
4282 if (box_line_hwidth
&& s
->first_glyph
->left_box_line_p
)
4283 x
= s
->x
+ box_line_hwidth
;
4287 y
= s
->y
+ box_line_vwidth
;
4291 /* Create a pixmap as large as the glyph string. Fill it
4292 with the background color. Copy the image to it, using
4293 its mask. Copy the temporary pixmap to the display. */
4294 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
4295 int depth
= DefaultDepthOfScreen (screen
);
4297 /* Create a pixmap as large as the glyph string. */
4298 pixmap
= XCreatePixmap (s
->display
, s
->window
,
4299 s
->background_width
,
4302 /* Don't clip in the following because we're working on the
4304 XSetClipMask (s
->display
, s
->gc
, None
);
4306 /* Fill the pixmap with the background color/stipple. */
4309 /* Fill background with a stipple pattern. */
4310 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4311 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4312 0, 0, s
->background_width
, s
->height
);
4313 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4318 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
4320 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
4321 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4322 0, 0, s
->background_width
, s
->height
);
4323 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4327 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
4329 s
->background_filled_p
= 1;
4332 /* Draw the foreground. */
4335 x_draw_image_foreground_1 (s
, pixmap
);
4336 x_set_glyph_string_clipping (s
);
4337 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
4338 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
4339 XFreePixmap (s
->display
, pixmap
);
4342 x_draw_image_foreground (s
);
4344 /* If we must draw a relief around the image, do it. */
4346 || s
->hl
== DRAW_IMAGE_RAISED
4347 || s
->hl
== DRAW_IMAGE_SUNKEN
)
4348 x_draw_image_relief (s
);
4352 /* Draw stretch glyph string S. */
4355 x_draw_stretch_glyph_string (s
)
4356 struct glyph_string
*s
;
4358 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4359 s
->stippled_p
= s
->face
->stipple
!= 0;
4361 if (s
->hl
== DRAW_CURSOR
4362 && !x_stretch_cursor_p
)
4364 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
4365 as wide as the stretch glyph. */
4366 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
4369 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
4371 /* Clear rest using the GC of the original non-cursor face. */
4372 if (width
< s
->background_width
)
4374 int x
= s
->x
+ width
, y
= s
->y
;
4375 int w
= s
->background_width
- width
, h
= s
->height
;
4379 if (s
->row
->mouse_face_p
4380 && cursor_in_mouse_face_p (s
->w
))
4382 x_set_mouse_face_gc (s
);
4388 x_get_glyph_string_clip_rect (s
, &r
);
4389 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
4391 if (s
->face
->stipple
)
4393 /* Fill background with a stipple pattern. */
4394 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
4395 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4396 XSetFillStyle (s
->display
, gc
, FillSolid
);
4401 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
4402 XSetForeground (s
->display
, gc
, xgcv
.background
);
4403 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4404 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
4408 else if (!s
->background_filled_p
)
4409 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
4412 s
->background_filled_p
= 1;
4416 /* Draw glyph string S. */
4419 x_draw_glyph_string (s
)
4420 struct glyph_string
*s
;
4422 int relief_drawn_p
= 0;
4424 /* If S draws into the background of its successor, draw the
4425 background of the successor first so that S can draw into it.
4426 This makes S->next use XDrawString instead of XDrawImageString. */
4427 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4429 xassert (s
->next
->img
== NULL
);
4430 x_set_glyph_string_gc (s
->next
);
4431 x_set_glyph_string_clipping (s
->next
);
4432 x_draw_glyph_string_background (s
->next
, 1);
4435 /* Set up S->gc, set clipping and draw S. */
4436 x_set_glyph_string_gc (s
);
4438 /* Draw relief (if any) in advance for char/composition so that the
4439 glyph string can be drawn over it. */
4440 if (!s
->for_overlaps_p
4441 && s
->face
->box
!= FACE_NO_BOX
4442 && (s
->first_glyph
->type
== CHAR_GLYPH
4443 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
4446 x_set_glyph_string_clipping (s
);
4447 x_draw_glyph_string_background (s
, 1);
4448 x_draw_glyph_string_box (s
);
4449 x_set_glyph_string_clipping (s
);
4453 x_set_glyph_string_clipping (s
);
4455 switch (s
->first_glyph
->type
)
4458 x_draw_image_glyph_string (s
);
4462 x_draw_stretch_glyph_string (s
);
4466 if (s
->for_overlaps_p
)
4467 s
->background_filled_p
= 1;
4469 x_draw_glyph_string_background (s
, 0);
4470 x_draw_glyph_string_foreground (s
);
4473 case COMPOSITE_GLYPH
:
4474 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4475 s
->background_filled_p
= 1;
4477 x_draw_glyph_string_background (s
, 1);
4478 x_draw_composite_glyph_string_foreground (s
);
4485 if (!s
->for_overlaps_p
)
4487 /* Draw underline. */
4488 if (s
->face
->underline_p
)
4490 unsigned long tem
, h
;
4493 /* Get the underline thickness. Default is 1 pixel. */
4494 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
4497 /* Get the underline position. This is the recommended
4498 vertical offset in pixels from the baseline to the top of
4499 the underline. This is a signed value according to the
4500 specs, and its default is
4502 ROUND ((maximum descent) / 2), with
4503 ROUND(x) = floor (x + 0.5) */
4505 if (x_use_underline_position_properties
4506 && XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &tem
))
4507 y
= s
->ybase
+ (long) tem
;
4508 else if (s
->face
->font
)
4509 y
= s
->ybase
+ (s
->face
->font
->max_bounds
.descent
+ 1) / 2;
4511 y
= s
->y
+ s
->height
- h
;
4513 if (s
->face
->underline_defaulted_p
)
4514 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4515 s
->x
, y
, s
->width
, h
);
4519 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4520 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
4521 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4522 s
->x
, y
, s
->width
, h
);
4523 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4527 /* Draw overline. */
4528 if (s
->face
->overline_p
)
4530 unsigned long dy
= 0, h
= 1;
4532 if (s
->face
->overline_color_defaulted_p
)
4533 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4538 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4539 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
4540 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4542 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4546 /* Draw strike-through. */
4547 if (s
->face
->strike_through_p
)
4549 unsigned long h
= 1;
4550 unsigned long dy
= (s
->height
- h
) / 2;
4552 if (s
->face
->strike_through_color_defaulted_p
)
4553 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4558 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4559 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
4560 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4562 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4566 /* Draw relief if not yet drawn. */
4567 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
4568 x_draw_glyph_string_box (s
);
4571 /* Reset clipping. */
4572 XSetClipMask (s
->display
, s
->gc
, None
);
4576 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4577 struct face
**, int));
4580 /* Fill glyph string S with composition components specified by S->cmp.
4582 FACES is an array of faces for all components of this composition.
4583 S->gidx is the index of the first component for S.
4584 OVERLAPS_P non-zero means S should draw the foreground only, and
4585 use its physical height for clipping.
4587 Value is the index of a component not in S. */
4590 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4591 struct glyph_string
*s
;
4592 struct face
**faces
;
4599 s
->for_overlaps_p
= overlaps_p
;
4601 s
->face
= faces
[s
->gidx
];
4602 s
->font
= s
->face
->font
;
4603 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4605 /* For all glyphs of this composition, starting at the offset
4606 S->gidx, until we reach the end of the definition or encounter a
4607 glyph that requires the different face, add it to S. */
4609 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4612 /* All glyph strings for the same composition has the same width,
4613 i.e. the width set for the first component of the composition. */
4615 s
->width
= s
->first_glyph
->pixel_width
;
4617 /* If the specified font could not be loaded, use the frame's
4618 default font, but record the fact that we couldn't load it in
4619 the glyph string so that we can draw rectangles for the
4620 characters of the glyph string. */
4621 if (s
->font
== NULL
)
4623 s
->font_not_found_p
= 1;
4624 s
->font
= FRAME_FONT (s
->f
);
4627 /* Adjust base line for subscript/superscript text. */
4628 s
->ybase
+= s
->first_glyph
->voffset
;
4630 xassert (s
->face
&& s
->face
->gc
);
4632 /* This glyph string must always be drawn with 16-bit functions. */
4635 return s
->gidx
+ s
->nchars
;
4639 /* Fill glyph string S from a sequence of character glyphs.
4641 FACE_ID is the face id of the string. START is the index of the
4642 first glyph to consider, END is the index of the last + 1.
4643 OVERLAPS_P non-zero means S should draw the foreground only, and
4644 use its physical height for clipping.
4646 Value is the index of the first glyph not in S. */
4649 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4650 struct glyph_string
*s
;
4652 int start
, end
, overlaps_p
;
4654 struct glyph
*glyph
, *last
;
4656 int glyph_not_available_p
;
4658 xassert (s
->f
== XFRAME (s
->w
->frame
));
4659 xassert (s
->nchars
== 0);
4660 xassert (start
>= 0 && end
> start
);
4662 s
->for_overlaps_p
= overlaps_p
,
4663 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4664 last
= s
->row
->glyphs
[s
->area
] + end
;
4665 voffset
= glyph
->voffset
;
4667 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4670 && glyph
->type
== CHAR_GLYPH
4671 && glyph
->voffset
== voffset
4672 /* Same face id implies same font, nowadays. */
4673 && glyph
->face_id
== face_id
4674 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4678 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4679 s
->char2b
+ s
->nchars
,
4681 s
->two_byte_p
= two_byte_p
;
4683 xassert (s
->nchars
<= end
- start
);
4684 s
->width
+= glyph
->pixel_width
;
4688 s
->font
= s
->face
->font
;
4689 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4691 /* If the specified font could not be loaded, use the frame's font,
4692 but record the fact that we couldn't load it in
4693 S->font_not_found_p so that we can draw rectangles for the
4694 characters of the glyph string. */
4695 if (s
->font
== NULL
|| glyph_not_available_p
)
4697 s
->font_not_found_p
= 1;
4698 s
->font
= FRAME_FONT (s
->f
);
4701 /* Adjust base line for subscript/superscript text. */
4702 s
->ybase
+= voffset
;
4704 xassert (s
->face
&& s
->face
->gc
);
4705 return glyph
- s
->row
->glyphs
[s
->area
];
4709 /* Fill glyph string S from image glyph S->first_glyph. */
4712 x_fill_image_glyph_string (s
)
4713 struct glyph_string
*s
;
4715 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4716 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
4718 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4719 s
->font
= s
->face
->font
;
4720 s
->width
= s
->first_glyph
->pixel_width
;
4722 /* Adjust base line for subscript/superscript text. */
4723 s
->ybase
+= s
->first_glyph
->voffset
;
4727 /* Fill glyph string S from a sequence of stretch glyphs.
4729 ROW is the glyph row in which the glyphs are found, AREA is the
4730 area within the row. START is the index of the first glyph to
4731 consider, END is the index of the last + 1.
4733 Value is the index of the first glyph not in S. */
4736 x_fill_stretch_glyph_string (s
, row
, area
, start
, end
)
4737 struct glyph_string
*s
;
4738 struct glyph_row
*row
;
4739 enum glyph_row_area area
;
4742 struct glyph
*glyph
, *last
;
4743 int voffset
, face_id
;
4745 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4747 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4748 last
= s
->row
->glyphs
[s
->area
] + end
;
4749 face_id
= glyph
->face_id
;
4750 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
4751 s
->font
= s
->face
->font
;
4752 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4753 s
->width
= glyph
->pixel_width
;
4754 voffset
= glyph
->voffset
;
4758 && glyph
->type
== STRETCH_GLYPH
4759 && glyph
->voffset
== voffset
4760 && glyph
->face_id
== face_id
);
4762 s
->width
+= glyph
->pixel_width
;
4764 /* Adjust base line for subscript/superscript text. */
4765 s
->ybase
+= voffset
;
4767 /* The case that face->gc == 0 is handled when drawing the glyph
4768 string by calling PREPARE_FACE_FOR_DISPLAY. */
4770 return glyph
- s
->row
->glyphs
[s
->area
];
4774 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4775 of XChar2b structures for S; it can't be allocated in
4776 x_init_glyph_string because it must be allocated via `alloca'. W
4777 is the window on which S is drawn. ROW and AREA are the glyph row
4778 and area within the row from which S is constructed. START is the
4779 index of the first glyph structure covered by S. HL is a
4780 face-override for drawing S. */
4783 x_init_glyph_string (s
, char2b
, w
, row
, area
, start
, hl
)
4784 struct glyph_string
*s
;
4787 struct glyph_row
*row
;
4788 enum glyph_row_area area
;
4790 enum draw_glyphs_face hl
;
4792 bzero (s
, sizeof *s
);
4794 s
->f
= XFRAME (w
->frame
);
4795 s
->display
= FRAME_X_DISPLAY (s
->f
);
4796 s
->window
= FRAME_X_WINDOW (s
->f
);
4801 s
->first_glyph
= row
->glyphs
[area
] + start
;
4802 s
->height
= row
->height
;
4803 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4805 /* Display the internal border below the tool-bar window. */
4806 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4807 s
->y
-= s
->f
->output_data
.x
->internal_border_width
;
4809 s
->ybase
= s
->y
+ row
->ascent
;
4813 /* Set background width of glyph string S. START is the index of the
4814 first glyph following S. LAST_X is the right-most x-position + 1
4815 in the drawing area. */
4818 x_set_glyph_string_background_width (s
, start
, last_x
)
4819 struct glyph_string
*s
;
4823 /* If the face of this glyph string has to be drawn to the end of
4824 the drawing area, set S->extends_to_end_of_line_p. */
4825 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4827 if (start
== s
->row
->used
[s
->area
]
4828 && s
->area
== TEXT_AREA
4829 && ((s
->hl
== DRAW_NORMAL_TEXT
4830 && (s
->row
->fill_line_p
4831 || s
->face
->background
!= default_face
->background
4832 || s
->face
->stipple
!= default_face
->stipple
4833 || s
->row
->mouse_face_p
))
4834 || s
->hl
== DRAW_MOUSE_FACE
4835 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
4836 && s
->row
->fill_line_p
)))
4837 s
->extends_to_end_of_line_p
= 1;
4839 /* If S extends its face to the end of the line, set its
4840 background_width to the distance to the right edge of the drawing
4842 if (s
->extends_to_end_of_line_p
)
4843 s
->background_width
= last_x
- s
->x
+ 1;
4845 s
->background_width
= s
->width
;
4849 /* Add a glyph string for a stretch glyph to the list of strings
4850 between HEAD and TAIL. START is the index of the stretch glyph in
4851 row area AREA of glyph row ROW. END is the index of the last glyph
4852 in that glyph row area. X is the current output position assigned
4853 to the new glyph string constructed. HL overrides that face of the
4854 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4855 is the right-most x-position of the drawing area. */
4857 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
4858 and below -- keep them on one line. */
4859 #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4862 s = (struct glyph_string *) alloca (sizeof *s); \
4863 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4864 START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \
4865 x_append_glyph_string (&HEAD, &TAIL, s); \
4871 /* Add a glyph string for an image glyph to the list of strings
4872 between HEAD and TAIL. START is the index of the image glyph in
4873 row area AREA of glyph row ROW. END is the index of the last glyph
4874 in that glyph row area. X is the current output position assigned
4875 to the new glyph string constructed. HL overrides that face of the
4876 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4877 is the right-most x-position of the drawing area. */
4879 #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4882 s = (struct glyph_string *) alloca (sizeof *s); \
4883 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4884 x_fill_image_glyph_string (s); \
4885 x_append_glyph_string (&HEAD, &TAIL, s); \
4892 /* Add a glyph string for a sequence of character glyphs to the list
4893 of strings between HEAD and TAIL. START is the index of the first
4894 glyph in row area AREA of glyph row ROW that is part of the new
4895 glyph string. END is the index of the last glyph in that glyph row
4896 area. X is the current output position assigned to the new glyph
4897 string constructed. HL overrides that face of the glyph; e.g. it
4898 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4899 right-most x-position of the drawing area. */
4901 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4907 c = (ROW)->glyphs[AREA][START].u.ch; \
4908 face_id = (ROW)->glyphs[AREA][START].face_id; \
4910 s = (struct glyph_string *) alloca (sizeof *s); \
4911 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
4912 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4913 x_append_glyph_string (&HEAD, &TAIL, s); \
4915 START = x_fill_glyph_string (s, face_id, START, END, \
4921 /* Add a glyph string for a composite sequence to the list of strings
4922 between HEAD and TAIL. START is the index of the first glyph in
4923 row area AREA of glyph row ROW that is part of the new glyph
4924 string. END is the index of the last glyph in that glyph row area.
4925 X is the current output position assigned to the new glyph string
4926 constructed. HL overrides that face of the glyph; e.g. it is
4927 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
4928 x-position of the drawing area. */
4930 #define BUILD_COMPOSITE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4932 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
4933 int face_id = (ROW)->glyphs[AREA][START].face_id; \
4934 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
4935 struct composition *cmp = composition_table[cmp_id]; \
4936 int glyph_len = cmp->glyph_len; \
4938 struct face **faces; \
4939 struct glyph_string *first_s = NULL; \
4942 base_face = base_face->ascii_face; \
4943 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
4944 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
4945 /* At first, fill in `char2b' and `faces'. */ \
4946 for (n = 0; n < glyph_len; n++) \
4948 int c = COMPOSITION_GLYPH (cmp, n); \
4949 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
4950 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
4951 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
4952 this_face_id, char2b + n, 1); \
4955 /* Make glyph_strings for each glyph sequence that is drawable by \
4956 the same face, and append them to HEAD/TAIL. */ \
4957 for (n = 0; n < cmp->glyph_len;) \
4959 s = (struct glyph_string *) alloca (sizeof *s); \
4960 x_init_glyph_string (s, char2b + n, W, ROW, AREA, START, HL); \
4961 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4969 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
4977 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4978 of AREA of glyph row ROW on window W between indices START and END.
4979 HL overrides the face for drawing glyph strings, e.g. it is
4980 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4981 x-positions of the drawing area.
4983 This is an ugly monster macro construct because we must use alloca
4984 to allocate glyph strings (because x_draw_glyphs can be called
4987 #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4990 HEAD = TAIL = NULL; \
4991 while (START < END) \
4993 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
4994 switch (first_glyph->type) \
4997 BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \
4998 TAIL, HL, X, LAST_X, \
5002 case COMPOSITE_GLYPH: \
5003 BUILD_COMPOSITE_GLYPH_STRING (W, ROW, AREA, START, END, \
5004 HEAD, TAIL, HL, X, LAST_X,\
5008 case STRETCH_GLYPH: \
5009 BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \
5010 HEAD, TAIL, HL, X, LAST_X); \
5014 BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \
5015 TAIL, HL, X, LAST_X); \
5022 x_set_glyph_string_background_width (s, START, LAST_X); \
5029 /* Draw glyphs between START and END in AREA of ROW on window W,
5030 starting at x-position X. X is relative to AREA in W. HL is a
5031 face-override with the following meaning:
5033 DRAW_NORMAL_TEXT draw normally
5034 DRAW_CURSOR draw in cursor face
5035 DRAW_MOUSE_FACE draw in mouse face.
5036 DRAW_INVERSE_VIDEO draw in mode line face
5037 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
5038 DRAW_IMAGE_RAISED draw an image with a raised relief around it
5040 If OVERLAPS_P is non-zero, draw only the foreground of characters
5041 and clip to the physical height of ROW.
5043 Value is the x-position reached, relative to AREA of W. */
5046 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
5049 struct glyph_row
*row
;
5050 enum glyph_row_area area
;
5052 enum draw_glyphs_face hl
;
5055 struct glyph_string
*head
, *tail
;
5056 struct glyph_string
*s
;
5057 int last_x
, area_width
;
5061 /* Let's rather be paranoid than getting a SEGV. */
5062 end
= min (end
, row
->used
[area
]);
5063 start
= max (0, start
);
5064 start
= min (end
, start
);
5066 /* Translate X to frame coordinates. Set last_x to the right
5067 end of the drawing area. */
5068 if (row
->full_width_p
)
5070 /* X is relative to the left edge of W, without scroll bars
5072 struct frame
*f
= XFRAME (w
->frame
);
5073 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
5076 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5077 last_x
= window_left_x
+ area_width
;
5079 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5081 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5082 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
5088 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
5089 last_x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
5093 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
5094 area_width
= window_box_width (w
, area
);
5095 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
5098 /* Build a doubly-linked list of glyph_string structures between
5099 head and tail from what we have to draw. Note that the macro
5100 BUILD_GLYPH_STRINGS will modify its start parameter. That's
5101 the reason we use a separate variable `i'. */
5103 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
5106 x_reached
= tail
->x
+ tail
->background_width
;
5110 /* If there are any glyphs with lbearing < 0 or rbearing > width in
5111 the row, redraw some glyphs in front or following the glyph
5112 strings built above. */
5113 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
5116 struct glyph_string
*h
, *t
;
5118 /* Compute overhangs for all glyph strings. */
5119 for (s
= head
; s
; s
= s
->next
)
5120 x_compute_glyph_string_overhangs (s
);
5122 /* Prepend glyph strings for glyphs in front of the first glyph
5123 string that are overwritten because of the first glyph
5124 string's left overhang. The background of all strings
5125 prepended must be drawn because the first glyph string
5127 i
= x_left_overwritten (head
);
5131 BUILD_GLYPH_STRINGS (w
, row
, area
, j
, start
, h
, t
,
5132 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5135 x_compute_overhangs_and_x (t
, head
->x
, 1);
5136 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5139 /* Prepend glyph strings for glyphs in front of the first glyph
5140 string that overwrite that glyph string because of their
5141 right overhang. For these strings, only the foreground must
5142 be drawn, because it draws over the glyph string at `head'.
5143 The background must not be drawn because this would overwrite
5144 right overhangs of preceding glyphs for which no glyph
5146 i
= x_left_overwriting (head
);
5149 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, start
, h
, t
,
5150 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5152 for (s
= h
; s
; s
= s
->next
)
5153 s
->background_filled_p
= 1;
5154 x_compute_overhangs_and_x (t
, head
->x
, 1);
5155 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5158 /* Append glyphs strings for glyphs following the last glyph
5159 string tail that are overwritten by tail. The background of
5160 these strings has to be drawn because tail's foreground draws
5162 i
= x_right_overwritten (tail
);
5165 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
5166 DRAW_NORMAL_TEXT
, x
, last_x
,
5168 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5169 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5172 /* Append glyph strings for glyphs following the last glyph
5173 string tail that overwrite tail. The foreground of such
5174 glyphs has to be drawn because it writes into the background
5175 of tail. The background must not be drawn because it could
5176 paint over the foreground of following glyphs. */
5177 i
= x_right_overwriting (tail
);
5180 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
5181 DRAW_NORMAL_TEXT
, x
, last_x
,
5183 for (s
= h
; s
; s
= s
->next
)
5184 s
->background_filled_p
= 1;
5185 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5186 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5190 /* Draw all strings. */
5191 for (s
= head
; s
; s
= s
->next
)
5192 x_draw_glyph_string (s
);
5194 if (area
== TEXT_AREA
5195 && !row
->full_width_p
5196 /* When drawing overlapping rows, only the glyph strings'
5197 foreground is drawn, which doesn't erase a cursor
5201 int x0
= head
? head
->x
: x
;
5202 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
5204 x0
= FRAME_TO_WINDOW_PIXEL_X (w
, x0
);
5205 x1
= FRAME_TO_WINDOW_PIXEL_X (w
, x1
);
5207 if (XFASTINT (w
->left_margin_width
) != 0)
5209 int left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
5210 x0
-= left_area_width
;
5211 x1
-= left_area_width
;
5214 notice_overwritten_cursor (w
, area
, x0
, x1
,
5215 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
5218 /* Value is the x-position up to which drawn, relative to AREA of W.
5219 This doesn't include parts drawn because of overhangs. */
5220 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
5221 if (!row
->full_width_p
)
5223 if (area
> LEFT_MARGIN_AREA
&& XFASTINT (w
->left_margin_width
) != 0)
5224 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
5225 if (area
> TEXT_AREA
)
5226 x_reached
-= window_box_width (w
, TEXT_AREA
);
5233 /* Fix the display of area AREA of overlapping row ROW in window W. */
5236 x_fix_overlapping_area (w
, row
, area
)
5238 struct glyph_row
*row
;
5239 enum glyph_row_area area
;
5245 if (area
== LEFT_MARGIN_AREA
)
5247 else if (area
== TEXT_AREA
)
5248 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5250 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5251 + window_box_width (w
, TEXT_AREA
));
5253 for (i
= 0; i
< row
->used
[area
];)
5255 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
5257 int start
= i
, start_x
= x
;
5261 x
+= row
->glyphs
[area
][i
].pixel_width
;
5264 while (i
< row
->used
[area
]
5265 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
5267 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
5268 DRAW_NORMAL_TEXT
, 1);
5272 x
+= row
->glyphs
[area
][i
].pixel_width
;
5281 /* Output LEN glyphs starting at START at the nominal cursor position.
5282 Advance the nominal cursor over the text. The global variable
5283 updated_window contains the window being updated, updated_row is
5284 the glyph row being updated, and updated_area is the area of that
5285 row being updated. */
5288 x_write_glyphs (start
, len
)
5289 struct glyph
*start
;
5294 xassert (updated_window
&& updated_row
);
5299 hpos
= start
- updated_row
->glyphs
[updated_area
];
5300 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
5301 updated_row
, updated_area
,
5303 DRAW_NORMAL_TEXT
, 0);
5307 /* Advance the output cursor. */
5308 output_cursor
.hpos
+= len
;
5309 output_cursor
.x
= x
;
5313 /* Insert LEN glyphs from START at the nominal cursor position. */
5316 x_insert_glyphs (start
, len
)
5317 struct glyph
*start
;
5322 int line_height
, shift_by_width
, shifted_region_width
;
5323 struct glyph_row
*row
;
5324 struct glyph
*glyph
;
5325 int frame_x
, frame_y
, hpos
;
5327 xassert (updated_window
&& updated_row
);
5330 f
= XFRAME (WINDOW_FRAME (w
));
5332 /* Get the height of the line we are in. */
5334 line_height
= row
->height
;
5336 /* Get the width of the glyphs to insert. */
5338 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
5339 shift_by_width
+= glyph
->pixel_width
;
5341 /* Get the width of the region to shift right. */
5342 shifted_region_width
= (window_box_width (w
, updated_area
)
5347 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
5348 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
5349 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5350 f
->output_data
.x
->normal_gc
,
5352 shifted_region_width
, line_height
,
5353 frame_x
+ shift_by_width
, frame_y
);
5355 /* Write the glyphs. */
5356 hpos
= start
- row
->glyphs
[updated_area
];
5357 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
5358 DRAW_NORMAL_TEXT
, 0);
5360 /* Advance the output cursor. */
5361 output_cursor
.hpos
+= len
;
5362 output_cursor
.x
+= shift_by_width
;
5367 /* Delete N glyphs at the nominal cursor position. Not implemented
5378 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
5379 If they are <= 0, this is probably an error. */
5382 x_clear_area (dpy
, window
, x
, y
, width
, height
, exposures
)
5389 xassert (width
> 0 && height
> 0);
5390 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
5394 /* Erase the current text line from the nominal cursor position
5395 (inclusive) to pixel column TO_X (exclusive). The idea is that
5396 everything from TO_X onward is already erased.
5398 TO_X is a pixel position relative to updated_area of
5399 updated_window. TO_X == -1 means clear to the end of this area. */
5402 x_clear_end_of_line (to_x
)
5406 struct window
*w
= updated_window
;
5407 int max_x
, min_y
, max_y
;
5408 int from_x
, from_y
, to_y
;
5410 xassert (updated_window
&& updated_row
);
5411 f
= XFRAME (w
->frame
);
5413 if (updated_row
->full_width_p
)
5415 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5416 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5417 && !w
->pseudo_window_p
)
5418 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5421 max_x
= window_box_width (w
, updated_area
);
5422 max_y
= window_text_bottom_y (w
);
5424 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
5425 of window. For TO_X > 0, truncate to end of drawing area. */
5431 to_x
= min (to_x
, max_x
);
5433 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
5435 /* Notice if the cursor will be cleared by this operation. */
5436 if (!updated_row
->full_width_p
)
5437 notice_overwritten_cursor (w
, updated_area
,
5438 output_cursor
.x
, -1,
5440 MATRIX_ROW_BOTTOM_Y (updated_row
));
5442 from_x
= output_cursor
.x
;
5444 /* Translate to frame coordinates. */
5445 if (updated_row
->full_width_p
)
5447 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
5448 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
5452 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
5453 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
5456 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
5457 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
5458 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
5460 /* Prevent inadvertently clearing to end of the X window. */
5461 if (to_x
> from_x
&& to_y
> from_y
)
5464 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5465 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
5472 /* Clear entire frame. If updating_frame is non-null, clear that
5473 frame. Otherwise clear the selected frame. */
5483 f
= SELECTED_FRAME ();
5485 /* Clearing the frame will erase any cursor, so mark them all as no
5487 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5488 output_cursor
.hpos
= output_cursor
.vpos
= 0;
5489 output_cursor
.x
= -1;
5491 /* We don't set the output cursor here because there will always
5492 follow an explicit cursor_to. */
5494 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5496 /* We have to clear the scroll bars, too. If we have changed
5497 colors or something like that, then they should be notified. */
5498 x_scroll_bar_clear (f
);
5500 XFlush (FRAME_X_DISPLAY (f
));
5506 /* Invert the middle quarter of the frame for .15 sec. */
5508 /* We use the select system call to do the waiting, so we have to make
5509 sure it's available. If it isn't, we just won't do visual bells. */
5511 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5514 /* Subtract the `struct timeval' values X and Y, storing the result in
5515 *RESULT. Return 1 if the difference is negative, otherwise 0. */
5518 timeval_subtract (result
, x
, y
)
5519 struct timeval
*result
, x
, y
;
5521 /* Perform the carry for the later subtraction by updating y. This
5522 is safer because on some systems the tv_sec member is unsigned. */
5523 if (x
.tv_usec
< y
.tv_usec
)
5525 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
5526 y
.tv_usec
-= 1000000 * nsec
;
5530 if (x
.tv_usec
- y
.tv_usec
> 1000000)
5532 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
5533 y
.tv_usec
+= 1000000 * nsec
;
5537 /* Compute the time remaining to wait. tv_usec is certainly
5539 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
5540 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
5542 /* Return indication of whether the result should be considered
5544 return x
.tv_sec
< y
.tv_sec
;
5556 /* Create a GC that will use the GXxor function to flip foreground
5557 pixels into background pixels. */
5561 values
.function
= GXxor
;
5562 values
.foreground
= (f
->output_data
.x
->foreground_pixel
5563 ^ f
->output_data
.x
->background_pixel
);
5565 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5566 GCFunction
| GCForeground
, &values
);
5570 /* Get the height not including a menu bar widget. */
5571 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
5572 /* Height of each line to flash. */
5573 int flash_height
= FRAME_LINE_HEIGHT (f
);
5574 /* These will be the left and right margins of the rectangles. */
5575 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
5576 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
5580 /* Don't flash the area between a scroll bar and the frame
5581 edge it is next to. */
5582 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
5584 case vertical_scroll_bar_left
:
5585 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5588 case vertical_scroll_bar_right
:
5589 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5596 width
= flash_right
- flash_left
;
5598 /* If window is tall, flash top and bottom line. */
5599 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5601 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5603 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5604 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5605 width
, flash_height
);
5606 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5608 (height
- flash_height
5609 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5610 width
, flash_height
);
5613 /* If it is short, flash it all. */
5614 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5615 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5616 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5621 struct timeval wakeup
;
5623 EMACS_GET_TIME (wakeup
);
5625 /* Compute time to wait until, propagating carry from usecs. */
5626 wakeup
.tv_usec
+= 150000;
5627 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
5628 wakeup
.tv_usec
%= 1000000;
5630 /* Keep waiting until past the time wakeup or any input gets
5632 while (! detect_input_pending ())
5634 struct timeval current
;
5635 struct timeval timeout
;
5637 EMACS_GET_TIME (current
);
5639 /* Break if result would be negative. */
5640 if (timeval_subtract (¤t
, wakeup
, current
))
5643 /* How long `select' should wait. */
5645 timeout
.tv_usec
= 10000;
5647 /* Try to wait that long--but we might wake up sooner. */
5648 select (0, NULL
, NULL
, NULL
, &timeout
);
5652 /* If window is tall, flash top and bottom line. */
5653 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5655 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5657 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5658 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5659 width
, flash_height
);
5660 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5662 (height
- flash_height
5663 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5664 width
, flash_height
);
5667 /* If it is short, flash it all. */
5668 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5669 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5670 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5672 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
5680 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
5683 /* Make audible bell. */
5688 struct frame
*f
= SELECTED_FRAME ();
5690 if (FRAME_X_DISPLAY (f
))
5692 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5699 XBell (FRAME_X_DISPLAY (f
), 0);
5700 XFlush (FRAME_X_DISPLAY (f
));
5707 /* Specify how many text lines, from the top of the window,
5708 should be affected by insert-lines and delete-lines operations.
5709 This, and those operations, are used only within an update
5710 that is bounded by calls to x_update_begin and x_update_end. */
5713 XTset_terminal_window (n
)
5716 /* This function intentionally left blank. */
5721 /***********************************************************************
5723 ***********************************************************************/
5725 /* Perform an insert-lines or delete-lines operation, inserting N
5726 lines or deleting -N lines at vertical position VPOS. */
5729 x_ins_del_lines (vpos
, n
)
5736 /* Scroll part of the display as described by RUN. */
5739 x_scroll_run (w
, run
)
5743 struct frame
*f
= XFRAME (w
->frame
);
5744 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5746 /* Get frame-relative bounding box of the text display area of W,
5747 without mode lines. Include in this box the left and right
5749 window_box (w
, -1, &x
, &y
, &width
, &height
);
5750 width
+= FRAME_X_FRINGE_WIDTH (f
);
5751 x
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
5753 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5754 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5755 bottom_y
= y
+ height
;
5759 /* Scrolling up. Make sure we don't copy part of the mode
5760 line at the bottom. */
5761 if (from_y
+ run
->height
> bottom_y
)
5762 height
= bottom_y
- from_y
;
5764 height
= run
->height
;
5768 /* Scolling down. Make sure we don't copy over the mode line.
5770 if (to_y
+ run
->height
> bottom_y
)
5771 height
= bottom_y
- to_y
;
5773 height
= run
->height
;
5778 /* Cursor off. Will be switched on again in x_update_window_end. */
5782 XCopyArea (FRAME_X_DISPLAY (f
),
5783 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5784 f
->output_data
.x
->normal_gc
,
5794 /***********************************************************************
5796 ***********************************************************************/
5798 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5799 corner of the exposed rectangle. W and H are width and height of
5800 the exposed area. All are pixel values. W or H zero means redraw
5801 the entire frame. */
5804 expose_frame (f
, x
, y
, w
, h
)
5809 int mouse_face_overwritten_p
= 0;
5811 TRACE ((stderr
, "expose_frame "));
5813 /* No need to redraw if frame will be redrawn soon. */
5814 if (FRAME_GARBAGED_P (f
))
5816 TRACE ((stderr
, " garbaged\n"));
5820 /* If basic faces haven't been realized yet, there is no point in
5821 trying to redraw anything. This can happen when we get an expose
5822 event while Emacs is starting, e.g. by moving another window. */
5823 if (FRAME_FACE_CACHE (f
) == NULL
5824 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5826 TRACE ((stderr
, " no faces\n"));
5830 if (w
== 0 || h
== 0)
5833 r
.width
= CANON_X_UNIT (f
) * f
->width
;
5834 r
.height
= CANON_Y_UNIT (f
) * f
->height
;
5844 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
5845 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
5847 if (WINDOWP (f
->tool_bar_window
))
5848 mouse_face_overwritten_p
5849 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
5851 #ifndef USE_X_TOOLKIT
5852 if (WINDOWP (f
->menu_bar_window
))
5853 mouse_face_overwritten_p
5854 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
5855 #endif /* not USE_X_TOOLKIT */
5857 /* Some window managers support a focus-follows-mouse style with
5858 delayed raising of frames. Imagine a partially obscured frame,
5859 and moving the mouse into partially obscured mouse-face on that
5860 frame. The visible part of the mouse-face will be highlighted,
5861 then the WM raises the obscured frame. With at least one WM, KDE
5862 2.1, Emacs is not getting any event for the raising of the frame
5863 (even tried with SubstructureRedirectMask), only Expose events.
5864 These expose events will draw text normally, i.e. not
5865 highlighted. Which means we must redo the highlight here.
5866 Subsume it under ``we love X''. --gerd 2001-08-15 */
5867 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
5869 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
5870 if (f
== dpyinfo
->mouse_face_mouse_frame
)
5872 int x
= dpyinfo
->mouse_face_mouse_x
;
5873 int y
= dpyinfo
->mouse_face_mouse_y
;
5874 clear_mouse_face (dpyinfo
);
5875 note_mouse_highlight (f
, x
, y
);
5881 /* Redraw (parts) of all windows in the window tree rooted at W that
5882 intersect R. R contains frame pixel coordinates. Value is
5883 non-zero if the exposure overwrites mouse-face. */
5886 expose_window_tree (w
, r
)
5890 struct frame
*f
= XFRAME (w
->frame
);
5891 int mouse_face_overwritten_p
= 0;
5893 while (w
&& !FRAME_GARBAGED_P (f
))
5895 if (!NILP (w
->hchild
))
5896 mouse_face_overwritten_p
5897 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
5898 else if (!NILP (w
->vchild
))
5899 mouse_face_overwritten_p
5900 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
5902 mouse_face_overwritten_p
|= expose_window (w
, r
);
5904 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
5907 return mouse_face_overwritten_p
;
5911 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5912 which intersects rectangle R. R is in window-relative coordinates. */
5915 expose_area (w
, row
, r
, area
)
5917 struct glyph_row
*row
;
5919 enum glyph_row_area area
;
5921 struct glyph
*first
= row
->glyphs
[area
];
5922 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5924 int first_x
, start_x
, x
;
5926 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5927 /* If row extends face to end of line write the whole line. */
5928 x_draw_glyphs (w
, 0, row
, area
, 0, row
->used
[area
],
5929 DRAW_NORMAL_TEXT
, 0);
5932 /* Set START_X to the window-relative start position for drawing glyphs of
5933 AREA. The first glyph of the text area can be partially visible.
5934 The first glyphs of other areas cannot. */
5935 if (area
== LEFT_MARGIN_AREA
)
5937 else if (area
== TEXT_AREA
)
5938 start_x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5940 start_x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5941 + window_box_width (w
, TEXT_AREA
));
5944 /* Find the first glyph that must be redrawn. */
5946 && x
+ first
->pixel_width
< r
->x
)
5948 x
+= first
->pixel_width
;
5952 /* Find the last one. */
5956 && x
< r
->x
+ r
->width
)
5958 x
+= last
->pixel_width
;
5964 x_draw_glyphs (w
, first_x
- start_x
, row
, area
,
5965 first
- row
->glyphs
[area
],
5966 last
- row
->glyphs
[area
],
5967 DRAW_NORMAL_TEXT
, 0);
5972 /* Redraw the parts of the glyph row ROW on window W intersecting
5973 rectangle R. R is in window-relative coordinates. Value is
5974 non-zero if mouse-face was overwritten. */
5977 expose_line (w
, row
, r
)
5979 struct glyph_row
*row
;
5982 xassert (row
->enabled_p
);
5984 if (row
->mode_line_p
|| w
->pseudo_window_p
)
5985 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
5986 DRAW_NORMAL_TEXT
, 0);
5989 if (row
->used
[LEFT_MARGIN_AREA
])
5990 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
5991 if (row
->used
[TEXT_AREA
])
5992 expose_area (w
, row
, r
, TEXT_AREA
);
5993 if (row
->used
[RIGHT_MARGIN_AREA
])
5994 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
5995 x_draw_row_fringe_bitmaps (w
, row
);
5998 return row
->mouse_face_p
;
6002 /* Return non-zero if W's cursor intersects rectangle R. */
6005 x_phys_cursor_in_rect_p (w
, r
)
6009 XRectangle cr
, result
;
6010 struct glyph
*cursor_glyph
;
6012 cursor_glyph
= get_phys_cursor_glyph (w
);
6015 cr
.x
= w
->phys_cursor
.x
;
6016 cr
.y
= w
->phys_cursor
.y
;
6017 cr
.width
= cursor_glyph
->pixel_width
;
6018 cr
.height
= w
->phys_cursor_height
;
6019 return x_intersect_rectangles (&cr
, r
, &result
);
6026 /* Redraw the part of window W intersection rectangle FR. Pixel
6027 coordinates in FR are frame-relative. Call this function with
6028 input blocked. Value is non-zero if the exposure overwrites
6032 expose_window (w
, fr
)
6036 struct frame
*f
= XFRAME (w
->frame
);
6038 int mouse_face_overwritten_p
= 0;
6040 /* If window is not yet fully initialized, do nothing. This can
6041 happen when toolkit scroll bars are used and a window is split.
6042 Reconfiguring the scroll bar will generate an expose for a newly
6044 if (w
->current_matrix
== NULL
)
6047 /* When we're currently updating the window, display and current
6048 matrix usually don't agree. Arrange for a thorough display
6050 if (w
== updated_window
)
6052 SET_FRAME_GARBAGED (f
);
6056 /* Frame-relative pixel rectangle of W. */
6057 wr
.x
= XFASTINT (w
->left
) * CANON_X_UNIT (f
);
6058 wr
.y
= XFASTINT (w
->top
) * CANON_Y_UNIT (f
);
6059 wr
.width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
6060 wr
.height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
6062 if (x_intersect_rectangles (fr
, &wr
, &r
))
6064 int yb
= window_text_bottom_y (w
);
6065 struct glyph_row
*row
;
6066 int cursor_cleared_p
;
6068 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
6069 r
.x
, r
.y
, r
.width
, r
.height
));
6071 /* Convert to window coordinates. */
6072 r
.x
= FRAME_TO_WINDOW_PIXEL_X (w
, r
.x
);
6073 r
.y
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
.y
);
6075 /* Turn off the cursor. */
6076 if (!w
->pseudo_window_p
6077 && x_phys_cursor_in_rect_p (w
, &r
))
6080 cursor_cleared_p
= 1;
6083 cursor_cleared_p
= 0;
6085 /* Find the first row intersecting the rectangle R. */
6086 for (row
= w
->current_matrix
->rows
;
6091 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
6093 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
6094 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
6095 || (r
.y
>= y0
&& r
.y
< y1
)
6096 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
6098 if (expose_line (w
, row
, &r
))
6099 mouse_face_overwritten_p
= 1;
6106 /* Display the mode line if there is one. */
6107 if (WINDOW_WANTS_MODELINE_P (w
)
6108 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
6110 && row
->y
< r
.y
+ r
.height
)
6112 if (expose_line (w
, row
, &r
))
6113 mouse_face_overwritten_p
= 1;
6116 if (!w
->pseudo_window_p
)
6118 /* Draw border between windows. */
6119 x_draw_vertical_border (w
);
6121 /* Turn the cursor on again. */
6122 if (cursor_cleared_p
)
6123 x_update_window_cursor (w
, 1);
6127 return mouse_face_overwritten_p
;
6131 /* Determine the intersection of two rectangles R1 and R2. Return
6132 the intersection in *RESULT. Value is non-zero if RESULT is not
6136 x_intersect_rectangles (r1
, r2
, result
)
6137 XRectangle
*r1
, *r2
, *result
;
6139 XRectangle
*left
, *right
;
6140 XRectangle
*upper
, *lower
;
6141 int intersection_p
= 0;
6143 /* Rearrange so that R1 is the left-most rectangle. */
6145 left
= r1
, right
= r2
;
6147 left
= r2
, right
= r1
;
6149 /* X0 of the intersection is right.x0, if this is inside R1,
6150 otherwise there is no intersection. */
6151 if (right
->x
<= left
->x
+ left
->width
)
6153 result
->x
= right
->x
;
6155 /* The right end of the intersection is the minimum of the
6156 the right ends of left and right. */
6157 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
6160 /* Same game for Y. */
6162 upper
= r1
, lower
= r2
;
6164 upper
= r2
, lower
= r1
;
6166 /* The upper end of the intersection is lower.y0, if this is inside
6167 of upper. Otherwise, there is no intersection. */
6168 if (lower
->y
<= upper
->y
+ upper
->height
)
6170 result
->y
= lower
->y
;
6172 /* The lower end of the intersection is the minimum of the lower
6173 ends of upper and lower. */
6174 result
->height
= (min (lower
->y
+ lower
->height
,
6175 upper
->y
+ upper
->height
)
6181 return intersection_p
;
6192 /* We used to only do this if Vx_no_window_manager was non-nil, but
6193 the ICCCM (section 4.1.6) says that the window's border pixmap
6194 and border pixel are window attributes which are "private to the
6195 client", so we can always change it to whatever we want. */
6197 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6198 f
->output_data
.x
->border_pixel
);
6200 x_update_cursor (f
, 1);
6204 frame_unhighlight (f
)
6207 /* We used to only do this if Vx_no_window_manager was non-nil, but
6208 the ICCCM (section 4.1.6) says that the window's border pixmap
6209 and border pixel are window attributes which are "private to the
6210 client", so we can always change it to whatever we want. */
6212 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6213 f
->output_data
.x
->border_tile
);
6215 x_update_cursor (f
, 1);
6218 /* The focus has changed. Update the frames as necessary to reflect
6219 the new situation. Note that we can't change the selected frame
6220 here, because the Lisp code we are interrupting might become confused.
6221 Each event gets marked with the frame in which it occurred, so the
6222 Lisp code can tell when the switch took place by examining the events. */
6225 x_new_focus_frame (dpyinfo
, frame
)
6226 struct x_display_info
*dpyinfo
;
6227 struct frame
*frame
;
6229 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
6231 if (frame
!= dpyinfo
->x_focus_frame
)
6233 /* Set this before calling other routines, so that they see
6234 the correct value of x_focus_frame. */
6235 dpyinfo
->x_focus_frame
= frame
;
6237 if (old_focus
&& old_focus
->auto_lower
)
6238 x_lower_frame (old_focus
);
6241 selected_frame
= frame
;
6242 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
6244 Fselect_window (selected_frame
->selected_window
);
6245 choose_minibuf_frame ();
6248 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
6249 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
6251 pending_autoraise_frame
= 0;
6254 x_frame_rehighlight (dpyinfo
);
6257 /* Handle an event saying the mouse has moved out of an Emacs frame. */
6260 x_mouse_leave (dpyinfo
)
6261 struct x_display_info
*dpyinfo
;
6263 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
6266 /* The focus has changed, or we have redirected a frame's focus to
6267 another frame (this happens when a frame uses a surrogate
6268 mini-buffer frame). Shift the highlight as appropriate.
6270 The FRAME argument doesn't necessarily have anything to do with which
6271 frame is being highlighted or un-highlighted; we only use it to find
6272 the appropriate X display info. */
6275 XTframe_rehighlight (frame
)
6276 struct frame
*frame
;
6278 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
6282 x_frame_rehighlight (dpyinfo
)
6283 struct x_display_info
*dpyinfo
;
6285 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
6287 if (dpyinfo
->x_focus_frame
)
6289 dpyinfo
->x_highlight_frame
6290 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
6291 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
6292 : dpyinfo
->x_focus_frame
);
6293 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
6295 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
6296 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
6300 dpyinfo
->x_highlight_frame
= 0;
6302 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
6305 frame_unhighlight (old_highlight
);
6306 if (dpyinfo
->x_highlight_frame
)
6307 frame_highlight (dpyinfo
->x_highlight_frame
);
6313 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
6315 /* Initialize mode_switch_bit and modifier_meaning. */
6317 x_find_modifier_meanings (dpyinfo
)
6318 struct x_display_info
*dpyinfo
;
6320 int min_code
, max_code
;
6323 XModifierKeymap
*mods
;
6325 dpyinfo
->meta_mod_mask
= 0;
6326 dpyinfo
->shift_lock_mask
= 0;
6327 dpyinfo
->alt_mod_mask
= 0;
6328 dpyinfo
->super_mod_mask
= 0;
6329 dpyinfo
->hyper_mod_mask
= 0;
6332 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
6334 min_code
= dpyinfo
->display
->min_keycode
;
6335 max_code
= dpyinfo
->display
->max_keycode
;
6338 syms
= XGetKeyboardMapping (dpyinfo
->display
,
6339 min_code
, max_code
- min_code
+ 1,
6341 mods
= XGetModifierMapping (dpyinfo
->display
);
6343 /* Scan the modifier table to see which modifier bits the Meta and
6344 Alt keysyms are on. */
6346 int row
, col
; /* The row and column in the modifier table. */
6348 for (row
= 3; row
< 8; row
++)
6349 for (col
= 0; col
< mods
->max_keypermod
; col
++)
6352 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
6354 /* Zeroes are used for filler. Skip them. */
6358 /* Are any of this keycode's keysyms a meta key? */
6362 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
6364 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
6370 dpyinfo
->meta_mod_mask
|= (1 << row
);
6375 dpyinfo
->alt_mod_mask
|= (1 << row
);
6380 dpyinfo
->hyper_mod_mask
|= (1 << row
);
6385 dpyinfo
->super_mod_mask
|= (1 << row
);
6389 /* Ignore this if it's not on the lock modifier. */
6390 if ((1 << row
) == LockMask
)
6391 dpyinfo
->shift_lock_mask
= LockMask
;
6399 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
6400 if (! dpyinfo
->meta_mod_mask
)
6402 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
6403 dpyinfo
->alt_mod_mask
= 0;
6406 /* If some keys are both alt and meta,
6407 make them just meta, not alt. */
6408 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
6410 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
6413 XFree ((char *) syms
);
6414 XFreeModifiermap (mods
);
6417 /* Convert between the modifier bits X uses and the modifier bits
6421 x_x_to_emacs_modifiers (dpyinfo
, state
)
6422 struct x_display_info
*dpyinfo
;
6425 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
6426 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
6427 | ((state
& dpyinfo
->meta_mod_mask
) ? meta_modifier
: 0)
6428 | ((state
& dpyinfo
->alt_mod_mask
) ? alt_modifier
: 0)
6429 | ((state
& dpyinfo
->super_mod_mask
) ? super_modifier
: 0)
6430 | ((state
& dpyinfo
->hyper_mod_mask
) ? hyper_modifier
: 0));
6434 x_emacs_to_x_modifiers (dpyinfo
, state
)
6435 struct x_display_info
*dpyinfo
;
6438 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
6439 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
6440 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
6441 | ((state
& shift_modifier
) ? ShiftMask
: 0)
6442 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
6443 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
6446 /* Convert a keysym to its name. */
6449 x_get_keysym_name (keysym
)
6455 value
= XKeysymToString (keysym
);
6463 /* Mouse clicks and mouse movement. Rah. */
6465 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
6466 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
6467 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
6468 not force the value into range. */
6471 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
6473 register int pix_x
, pix_y
;
6474 register int *x
, *y
;
6478 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
6479 even for negative values. */
6481 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
6483 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
6485 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
6486 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
6490 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
6491 bounds
->height
= f
->output_data
.x
->line_height
;
6492 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
6493 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
6500 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
6501 pix_x
= FRAME_WINDOW_WIDTH (f
);
6505 else if (pix_y
> f
->height
)
6514 /* Given HPOS/VPOS in the current matrix of W, return corresponding
6515 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
6516 can't tell the positions because W's display is not up to date,
6520 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
6523 int *frame_x
, *frame_y
;
6527 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
6528 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
6530 if (display_completed
)
6532 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6533 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
6534 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
6540 *frame_x
+= glyph
->pixel_width
;
6548 *frame_y
= *frame_x
= 0;
6552 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
6553 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6558 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6560 If the event is a button press, then note that we have grabbed
6564 construct_mouse_click (result
, event
, f
)
6565 struct input_event
*result
;
6566 XButtonEvent
*event
;
6569 /* Make the event type no_event; we'll change that when we decide
6571 result
->kind
= mouse_click
;
6572 result
->code
= event
->button
- Button1
;
6573 result
->timestamp
= event
->time
;
6574 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6576 | (event
->type
== ButtonRelease
6580 XSETINT (result
->x
, event
->x
);
6581 XSETINT (result
->y
, event
->y
);
6582 XSETFRAME (result
->frame_or_window
, f
);
6588 /* Function to report a mouse movement to the mainstream Emacs code.
6589 The input handler calls this.
6591 We have received a mouse movement event, which is given in *event.
6592 If the mouse is over a different glyph than it was last time, tell
6593 the mainstream emacs code by setting mouse_moved. If not, ask for
6594 another motion event, so we can check again the next time it moves. */
6596 static XMotionEvent last_mouse_motion_event
;
6597 static Lisp_Object last_mouse_motion_frame
;
6600 note_mouse_movement (frame
, event
)
6602 XMotionEvent
*event
;
6604 last_mouse_movement_time
= event
->time
;
6605 last_mouse_motion_event
= *event
;
6606 XSETFRAME (last_mouse_motion_frame
, frame
);
6608 if (event
->window
!= FRAME_X_WINDOW (frame
))
6610 frame
->mouse_moved
= 1;
6611 last_mouse_scroll_bar
= Qnil
;
6612 note_mouse_highlight (frame
, -1, -1);
6615 /* Has the mouse moved off the glyph it was on at the last sighting? */
6616 else if (event
->x
< last_mouse_glyph
.x
6617 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
6618 || event
->y
< last_mouse_glyph
.y
6619 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
6621 frame
->mouse_moved
= 1;
6622 last_mouse_scroll_bar
= Qnil
;
6623 note_mouse_highlight (frame
, event
->x
, event
->y
);
6627 /* This is used for debugging, to turn off note_mouse_highlight. */
6629 int disable_mouse_highlight
;
6633 /************************************************************************
6635 ************************************************************************/
6637 /* Find the glyph under window-relative coordinates X/Y in window W.
6638 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6639 strings. Return in *HPOS and *VPOS the row and column number of
6640 the glyph found. Return in *AREA the glyph area containing X.
6641 Value is a pointer to the glyph found or null if X/Y is not on
6642 text, or we can't tell because W's current matrix is not up to
6645 static struct glyph
*
6646 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
, buffer_only_p
)
6649 int *hpos
, *vpos
, *area
;
6652 struct glyph
*glyph
, *end
;
6653 struct glyph_row
*row
= NULL
;
6654 int x0
, i
, left_area_width
;
6656 /* Find row containing Y. Give up if some row is not enabled. */
6657 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6659 row
= MATRIX_ROW (w
->current_matrix
, i
);
6660 if (!row
->enabled_p
)
6662 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6669 /* Give up if Y is not in the window. */
6670 if (i
== w
->current_matrix
->nrows
)
6673 /* Get the glyph area containing X. */
6674 if (w
->pseudo_window_p
)
6681 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6682 if (x
< left_area_width
)
6684 *area
= LEFT_MARGIN_AREA
;
6687 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6690 x0
= row
->x
+ left_area_width
;
6694 *area
= RIGHT_MARGIN_AREA
;
6695 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6699 /* Find glyph containing X. */
6700 glyph
= row
->glyphs
[*area
];
6701 end
= glyph
+ row
->used
[*area
];
6704 if (x
< x0
+ glyph
->pixel_width
)
6706 if (w
->pseudo_window_p
)
6708 else if (!buffer_only_p
|| BUFFERP (glyph
->object
))
6712 x0
+= glyph
->pixel_width
;
6719 *hpos
= glyph
- row
->glyphs
[*area
];
6724 /* Convert frame-relative x/y to coordinates relative to window W.
6725 Takes pseudo-windows into account. */
6728 frame_to_window_pixel_xy (w
, x
, y
)
6732 if (w
->pseudo_window_p
)
6734 /* A pseudo-window is always full-width, and starts at the
6735 left edge of the frame, plus a frame border. */
6736 struct frame
*f
= XFRAME (w
->frame
);
6737 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6738 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6742 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6743 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6748 /* Take proper action when mouse has moved to the mode or header line of
6749 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6750 mode line. X is relative to the start of the text display area of
6751 W, so the width of fringes and scroll bars must be subtracted
6752 to get a position relative to the start of the mode line. */
6755 note_mode_line_highlight (w
, x
, mode_line_p
)
6759 struct frame
*f
= XFRAME (w
->frame
);
6760 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6761 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6762 struct glyph_row
*row
;
6765 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
6767 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
6771 struct glyph
*glyph
, *end
;
6772 Lisp_Object help
, map
;
6775 /* Find the glyph under X. */
6776 glyph
= row
->glyphs
[TEXT_AREA
];
6777 end
= glyph
+ row
->used
[TEXT_AREA
];
6778 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6779 + FRAME_X_LEFT_FRINGE_WIDTH (f
));
6782 && x
>= x0
+ glyph
->pixel_width
)
6784 x0
+= glyph
->pixel_width
;
6789 && STRINGP (glyph
->object
)
6790 && XSTRING (glyph
->object
)->intervals
6791 && glyph
->charpos
>= 0
6792 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6794 /* If we're on a string with `help-echo' text property,
6795 arrange for the help to be displayed. This is done by
6796 setting the global variable help_echo to the help string. */
6797 help
= Fget_text_property (make_number (glyph
->charpos
),
6798 Qhelp_echo
, glyph
->object
);
6802 XSETWINDOW (help_echo_window
, w
);
6803 help_echo_object
= glyph
->object
;
6804 help_echo_pos
= glyph
->charpos
;
6807 /* Change the mouse pointer according to what is under X/Y. */
6808 map
= Fget_text_property (make_number (glyph
->charpos
),
6809 Qlocal_map
, glyph
->object
);
6811 cursor
= f
->output_data
.x
->nontext_cursor
;
6814 map
= Fget_text_property (make_number (glyph
->charpos
),
6815 Qkeymap
, glyph
->object
);
6817 cursor
= f
->output_data
.x
->nontext_cursor
;
6822 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6826 /* Take proper action when the mouse has moved to position X, Y on
6827 frame F as regards highlighting characters that have mouse-face
6828 properties. Also de-highlighting chars where the mouse was before.
6829 X and Y can be negative or out of range. */
6832 note_mouse_highlight (f
, x
, y
)
6836 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6840 Cursor cursor
= None
;
6843 /* When a menu is active, don't highlight because this looks odd. */
6844 #ifdef USE_X_TOOLKIT
6845 if (popup_activated ())
6849 if (disable_mouse_highlight
6850 || !f
->glyphs_initialized_p
)
6853 dpyinfo
->mouse_face_mouse_x
= x
;
6854 dpyinfo
->mouse_face_mouse_y
= y
;
6855 dpyinfo
->mouse_face_mouse_frame
= f
;
6857 if (dpyinfo
->mouse_face_defer
)
6862 dpyinfo
->mouse_face_deferred_gc
= 1;
6866 /* Which window is that in? */
6867 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6869 /* If we were displaying active text in another window, clear that. */
6870 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6871 clear_mouse_face (dpyinfo
);
6873 /* Not on a window -> return. */
6874 if (!WINDOWP (window
))
6877 /* Convert to window-relative pixel coordinates. */
6878 w
= XWINDOW (window
);
6879 frame_to_window_pixel_xy (w
, &x
, &y
);
6881 /* Handle tool-bar window differently since it doesn't display a
6883 if (EQ (window
, f
->tool_bar_window
))
6885 note_tool_bar_highlight (f
, x
, y
);
6889 /* Mouse is on the mode or header line? */
6890 if (portion
== 1 || portion
== 3)
6892 note_mode_line_highlight (w
, x
, portion
== 1);
6897 cursor
= f
->output_data
.x
->horizontal_drag_cursor
;
6899 cursor
= f
->output_data
.x
->text_cursor
;
6901 /* Are we in a window whose display is up to date?
6902 And verify the buffer's text has not changed. */
6903 b
= XBUFFER (w
->buffer
);
6904 if (/* Within text portion of the window. */
6906 && EQ (w
->window_end_valid
, w
->buffer
)
6907 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
6908 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
6910 int hpos
, vpos
, pos
, i
, area
;
6911 struct glyph
*glyph
;
6913 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
6914 Lisp_Object
*overlay_vec
= NULL
;
6916 struct buffer
*obuf
;
6917 int obegv
, ozv
, same_region
;
6919 /* Find the glyph under X/Y. */
6920 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
, 0);
6922 /* Clear mouse face if X/Y not over text. */
6924 || area
!= TEXT_AREA
6925 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6927 if (clear_mouse_face (dpyinfo
))
6932 pos
= glyph
->charpos
;
6933 object
= glyph
->object
;
6934 if (!STRINGP (object
) && !BUFFERP (object
))
6937 /* If we get an out-of-range value, return now; avoid an error. */
6938 if (BUFFERP (object
) && pos
> BUF_Z (b
))
6941 /* Make the window's buffer temporarily current for
6942 overlays_at and compute_char_face. */
6943 obuf
= current_buffer
;
6950 /* Is this char mouse-active or does it have help-echo? */
6951 position
= make_number (pos
);
6953 if (BUFFERP (object
))
6955 /* Put all the overlays we want in a vector in overlay_vec.
6956 Store the length in len. If there are more than 10, make
6957 enough space for all, and try again. */
6959 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6960 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
6961 if (noverlays
> len
)
6964 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6965 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
6968 /* Sort overlays into increasing priority order. */
6969 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6974 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
6975 && vpos
>= dpyinfo
->mouse_face_beg_row
6976 && vpos
<= dpyinfo
->mouse_face_end_row
6977 && (vpos
> dpyinfo
->mouse_face_beg_row
6978 || hpos
>= dpyinfo
->mouse_face_beg_col
)
6979 && (vpos
< dpyinfo
->mouse_face_end_row
6980 || hpos
< dpyinfo
->mouse_face_end_col
6981 || dpyinfo
->mouse_face_past_end
));
6986 /* Check mouse-face highlighting. */
6988 /* If there exists an overlay with mouse-face overlapping
6989 the one we are currently highlighting, we have to
6990 check if we enter the overlapping overlay, and then
6991 highlight only that. */
6992 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
6993 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
6995 /* Find the highest priority overlay that has a mouse-face
6998 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
7000 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
7001 if (!NILP (mouse_face
))
7002 overlay
= overlay_vec
[i
];
7005 /* If we're actually highlighting the same overlay as
7006 before, there's no need to do that again. */
7008 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
7009 goto check_help_echo
;
7011 dpyinfo
->mouse_face_overlay
= overlay
;
7013 /* Clear the display of the old active region, if any. */
7014 if (clear_mouse_face (dpyinfo
))
7017 /* If no overlay applies, get a text property. */
7019 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
7021 /* Handle the overlay case. */
7022 if (!NILP (overlay
))
7024 /* Find the range of text around this char that
7025 should be active. */
7026 Lisp_Object before
, after
;
7029 before
= Foverlay_start (overlay
);
7030 after
= Foverlay_end (overlay
);
7031 /* Record this as the current active region. */
7032 fast_find_position (w
, XFASTINT (before
),
7033 &dpyinfo
->mouse_face_beg_col
,
7034 &dpyinfo
->mouse_face_beg_row
,
7035 &dpyinfo
->mouse_face_beg_x
,
7036 &dpyinfo
->mouse_face_beg_y
, Qnil
);
7038 dpyinfo
->mouse_face_past_end
7039 = !fast_find_position (w
, XFASTINT (after
),
7040 &dpyinfo
->mouse_face_end_col
,
7041 &dpyinfo
->mouse_face_end_row
,
7042 &dpyinfo
->mouse_face_end_x
,
7043 &dpyinfo
->mouse_face_end_y
, Qnil
);
7044 dpyinfo
->mouse_face_window
= window
;
7045 dpyinfo
->mouse_face_face_id
7046 = face_at_buffer_position (w
, pos
, 0, 0,
7047 &ignore
, pos
+ 1, 1);
7049 /* Display it as active. */
7050 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7053 /* Handle the text property case. */
7054 else if (!NILP (mouse_face
) && BUFFERP (object
))
7056 /* Find the range of text around this char that
7057 should be active. */
7058 Lisp_Object before
, after
, beginning
, end
;
7061 beginning
= Fmarker_position (w
->start
);
7062 end
= make_number (BUF_Z (XBUFFER (object
))
7063 - XFASTINT (w
->window_end_pos
));
7065 = Fprevious_single_property_change (make_number (pos
+ 1),
7069 = Fnext_single_property_change (position
, Qmouse_face
,
7072 /* Record this as the current active region. */
7073 fast_find_position (w
, XFASTINT (before
),
7074 &dpyinfo
->mouse_face_beg_col
,
7075 &dpyinfo
->mouse_face_beg_row
,
7076 &dpyinfo
->mouse_face_beg_x
,
7077 &dpyinfo
->mouse_face_beg_y
, Qnil
);
7078 dpyinfo
->mouse_face_past_end
7079 = !fast_find_position (w
, XFASTINT (after
),
7080 &dpyinfo
->mouse_face_end_col
,
7081 &dpyinfo
->mouse_face_end_row
,
7082 &dpyinfo
->mouse_face_end_x
,
7083 &dpyinfo
->mouse_face_end_y
, Qnil
);
7084 dpyinfo
->mouse_face_window
= window
;
7086 if (BUFFERP (object
))
7087 dpyinfo
->mouse_face_face_id
7088 = face_at_buffer_position (w
, pos
, 0, 0,
7089 &ignore
, pos
+ 1, 1);
7091 /* Display it as active. */
7092 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7095 else if (!NILP (mouse_face
) && STRINGP (object
))
7100 b
= Fprevious_single_property_change (make_number (pos
+ 1),
7103 e
= Fnext_single_property_change (position
, Qmouse_face
,
7106 b
= make_number (0);
7108 e
= make_number (XSTRING (object
)->size
- 1);
7109 fast_find_string_pos (w
, XINT (b
), object
,
7110 &dpyinfo
->mouse_face_beg_col
,
7111 &dpyinfo
->mouse_face_beg_row
,
7112 &dpyinfo
->mouse_face_beg_x
,
7113 &dpyinfo
->mouse_face_beg_y
, 0);
7114 fast_find_string_pos (w
, XINT (e
), object
,
7115 &dpyinfo
->mouse_face_end_col
,
7116 &dpyinfo
->mouse_face_end_row
,
7117 &dpyinfo
->mouse_face_end_x
,
7118 &dpyinfo
->mouse_face_end_y
, 1);
7119 dpyinfo
->mouse_face_past_end
= 0;
7120 dpyinfo
->mouse_face_window
= window
;
7121 dpyinfo
->mouse_face_face_id
7122 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
7124 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7127 else if (STRINGP (object
) && NILP (mouse_face
))
7129 /* A string which doesn't have mouse-face, but
7130 the text ``under'' it might have. */
7131 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
7132 int start
= MATRIX_ROW_START_CHARPOS (r
);
7134 pos
= string_buffer_position (w
, object
, start
);
7136 mouse_face
= get_char_property_and_overlay (make_number (pos
),
7140 if (!NILP (mouse_face
) && !NILP (overlay
))
7142 Lisp_Object before
= Foverlay_start (overlay
);
7143 Lisp_Object after
= Foverlay_end (overlay
);
7146 /* Note that we might not be able to find position
7147 BEFORE in the glyph matrix if the overlay is
7148 entirely covered by a `display' property. In
7149 this case, we overshoot. So let's stop in
7150 the glyph matrix before glyphs for OBJECT. */
7151 fast_find_position (w
, XFASTINT (before
),
7152 &dpyinfo
->mouse_face_beg_col
,
7153 &dpyinfo
->mouse_face_beg_row
,
7154 &dpyinfo
->mouse_face_beg_x
,
7155 &dpyinfo
->mouse_face_beg_y
,
7158 dpyinfo
->mouse_face_past_end
7159 = !fast_find_position (w
, XFASTINT (after
),
7160 &dpyinfo
->mouse_face_end_col
,
7161 &dpyinfo
->mouse_face_end_row
,
7162 &dpyinfo
->mouse_face_end_x
,
7163 &dpyinfo
->mouse_face_end_y
,
7165 dpyinfo
->mouse_face_window
= window
;
7166 dpyinfo
->mouse_face_face_id
7167 = face_at_buffer_position (w
, pos
, 0, 0,
7168 &ignore
, pos
+ 1, 1);
7170 /* Display it as active. */
7171 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7179 /* Look for a `help-echo' property. */
7181 Lisp_Object help
, overlay
;
7183 /* Check overlays first. */
7184 help
= overlay
= Qnil
;
7185 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
7187 overlay
= overlay_vec
[i
];
7188 help
= Foverlay_get (overlay
, Qhelp_echo
);
7194 help_echo_window
= window
;
7195 help_echo_object
= overlay
;
7196 help_echo_pos
= pos
;
7200 Lisp_Object object
= glyph
->object
;
7201 int charpos
= glyph
->charpos
;
7203 /* Try text properties. */
7204 if (STRINGP (object
)
7206 && charpos
< XSTRING (object
)->size
)
7208 help
= Fget_text_property (make_number (charpos
),
7209 Qhelp_echo
, object
);
7212 /* If the string itself doesn't specify a help-echo,
7213 see if the buffer text ``under'' it does. */
7215 = MATRIX_ROW (w
->current_matrix
, vpos
);
7216 int start
= MATRIX_ROW_START_CHARPOS (r
);
7217 int pos
= string_buffer_position (w
, object
, start
);
7220 help
= Fget_char_property (make_number (pos
),
7221 Qhelp_echo
, w
->buffer
);
7230 else if (BUFFERP (object
)
7233 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
7239 help_echo_window
= window
;
7240 help_echo_object
= object
;
7241 help_echo_pos
= charpos
;
7248 current_buffer
= obuf
;
7254 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7258 redo_mouse_highlight ()
7260 if (!NILP (last_mouse_motion_frame
)
7261 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
7262 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
7263 last_mouse_motion_event
.x
,
7264 last_mouse_motion_event
.y
);
7269 /***********************************************************************
7271 ***********************************************************************/
7273 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
7274 struct glyph
**, int *, int *, int *));
7276 /* Tool-bar item index of the item on which a mouse button was pressed
7279 static int last_tool_bar_item
;
7282 /* Get information about the tool-bar item at position X/Y on frame F.
7283 Return in *GLYPH a pointer to the glyph of the tool-bar item in
7284 the current matrix of the tool-bar window of F, or NULL if not
7285 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
7286 item in F->tool_bar_items. Value is
7288 -1 if X/Y is not on a tool-bar item
7289 0 if X/Y is on the same item that was highlighted before.
7293 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
7296 struct glyph
**glyph
;
7297 int *hpos
, *vpos
, *prop_idx
;
7299 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7300 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7303 /* Find the glyph under X/Y. */
7304 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
, 0);
7308 /* Get the start of this tool-bar item's properties in
7309 f->tool_bar_items. */
7310 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
7313 /* Is mouse on the highlighted item? */
7314 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
7315 && *vpos
>= dpyinfo
->mouse_face_beg_row
7316 && *vpos
<= dpyinfo
->mouse_face_end_row
7317 && (*vpos
> dpyinfo
->mouse_face_beg_row
7318 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
7319 && (*vpos
< dpyinfo
->mouse_face_end_row
7320 || *hpos
< dpyinfo
->mouse_face_end_col
7321 || dpyinfo
->mouse_face_past_end
))
7328 /* Handle mouse button event on the tool-bar of frame F, at
7329 frame-relative coordinates X/Y. EVENT_TYPE is either ButtonPress
7333 x_handle_tool_bar_click (f
, button_event
)
7335 XButtonEvent
*button_event
;
7337 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7338 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7339 int hpos
, vpos
, prop_idx
;
7340 struct glyph
*glyph
;
7341 Lisp_Object enabled_p
;
7342 int x
= button_event
->x
;
7343 int y
= button_event
->y
;
7345 /* If not on the highlighted tool-bar item, return. */
7346 frame_to_window_pixel_xy (w
, &x
, &y
);
7347 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
7350 /* If item is disabled, do nothing. */
7351 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7352 if (NILP (enabled_p
))
7355 if (button_event
->type
== ButtonPress
)
7357 /* Show item in pressed state. */
7358 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
7359 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
7360 last_tool_bar_item
= prop_idx
;
7364 Lisp_Object key
, frame
;
7365 struct input_event event
;
7367 /* Show item in released state. */
7368 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
7369 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
7371 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
7373 XSETFRAME (frame
, f
);
7374 event
.kind
= TOOL_BAR_EVENT
;
7375 event
.frame_or_window
= frame
;
7377 kbd_buffer_store_event (&event
);
7379 event
.kind
= TOOL_BAR_EVENT
;
7380 event
.frame_or_window
= frame
;
7382 event
.modifiers
= x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
7383 button_event
->state
);
7384 kbd_buffer_store_event (&event
);
7385 last_tool_bar_item
= -1;
7390 /* Possibly highlight a tool-bar item on frame F when mouse moves to
7391 tool-bar window-relative coordinates X/Y. Called from
7392 note_mouse_highlight. */
7395 note_tool_bar_highlight (f
, x
, y
)
7399 Lisp_Object window
= f
->tool_bar_window
;
7400 struct window
*w
= XWINDOW (window
);
7401 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7403 struct glyph
*glyph
;
7404 struct glyph_row
*row
;
7406 Lisp_Object enabled_p
;
7408 enum draw_glyphs_face draw
;
7409 int mouse_down_p
, rc
;
7411 /* Function note_mouse_highlight is called with negative x(y
7412 values when mouse moves outside of the frame. */
7413 if (x
<= 0 || y
<= 0)
7415 clear_mouse_face (dpyinfo
);
7419 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
7422 /* Not on tool-bar item. */
7423 clear_mouse_face (dpyinfo
);
7429 clear_mouse_face (dpyinfo
);
7431 /* Mouse is down, but on different tool-bar item? */
7432 mouse_down_p
= (dpyinfo
->grabbed
7433 && f
== last_mouse_frame
7434 && FRAME_LIVE_P (f
));
7436 && last_tool_bar_item
!= prop_idx
)
7439 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
7440 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
7442 /* If tool-bar item is not enabled, don't highlight it. */
7443 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7444 if (!NILP (enabled_p
))
7446 /* Compute the x-position of the glyph. In front and past the
7447 image is a space. We include this is the highlighted area. */
7448 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
7449 for (i
= x
= 0; i
< hpos
; ++i
)
7450 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
7452 /* Record this as the current active region. */
7453 dpyinfo
->mouse_face_beg_col
= hpos
;
7454 dpyinfo
->mouse_face_beg_row
= vpos
;
7455 dpyinfo
->mouse_face_beg_x
= x
;
7456 dpyinfo
->mouse_face_beg_y
= row
->y
;
7457 dpyinfo
->mouse_face_past_end
= 0;
7459 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
7460 dpyinfo
->mouse_face_end_row
= vpos
;
7461 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
7462 dpyinfo
->mouse_face_end_y
= row
->y
;
7463 dpyinfo
->mouse_face_window
= window
;
7464 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
7466 /* Display it as active. */
7467 show_mouse_face (dpyinfo
, draw
);
7468 dpyinfo
->mouse_face_image_state
= draw
;
7473 /* Set help_echo to a help string to display for this tool-bar item.
7474 XTread_socket does the rest. */
7475 help_echo_object
= help_echo_window
= Qnil
;
7477 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
7478 if (NILP (help_echo
))
7479 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
7484 /* Find the glyph matrix position of buffer position CHARPOS in window
7485 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
7486 current glyphs must be up to date. If CHARPOS is above window
7487 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
7488 of last line in W. In the row containing CHARPOS, stop before glyphs
7489 having STOP as object. */
7491 #if 0 /* This is a version of fast_find_position that's more correct
7492 in the presence of hscrolling, for example. I didn't install
7493 it right away because the problem fixed is minor, it failed
7494 in 20.x as well, and I think it's too risky to install
7495 so near the release of 21.1. 2001-09-25 gerd. */
7498 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
7501 int *hpos
, *vpos
, *x
, *y
;
7504 struct glyph_row
*row
, *first
;
7505 struct glyph
*glyph
, *end
;
7506 int i
, past_end
= 0;
7508 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7509 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
7512 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
7514 *x
= *y
= *hpos
= *vpos
= 0;
7519 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
7526 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
7528 glyph
= row
->glyphs
[TEXT_AREA
];
7529 end
= glyph
+ row
->used
[TEXT_AREA
];
7531 /* Skip over glyphs not having an object at the start of the row.
7532 These are special glyphs like truncation marks on terminal
7534 if (row
->displays_text_p
)
7536 && INTEGERP (glyph
->object
)
7537 && !EQ (stop
, glyph
->object
)
7538 && glyph
->charpos
< 0)
7540 *x
+= glyph
->pixel_width
;
7545 && !INTEGERP (glyph
->object
)
7546 && !EQ (stop
, glyph
->object
)
7547 && (!BUFFERP (glyph
->object
)
7548 || glyph
->charpos
< charpos
))
7550 *x
+= glyph
->pixel_width
;
7554 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
7561 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
7564 int *hpos
, *vpos
, *x
, *y
;
7569 int maybe_next_line_p
= 0;
7570 int line_start_position
;
7571 int yb
= window_text_bottom_y (w
);
7572 struct glyph_row
*row
, *best_row
;
7573 int row_vpos
, best_row_vpos
;
7576 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7577 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
7581 if (row
->used
[TEXT_AREA
])
7582 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
7584 line_start_position
= 0;
7586 if (line_start_position
> pos
)
7588 /* If the position sought is the end of the buffer,
7589 don't include the blank lines at the bottom of the window. */
7590 else if (line_start_position
== pos
7591 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
7593 maybe_next_line_p
= 1;
7596 else if (line_start_position
> 0)
7599 best_row_vpos
= row_vpos
;
7602 if (row
->y
+ row
->height
>= yb
)
7609 /* Find the right column within BEST_ROW. */
7611 current_x
= best_row
->x
;
7612 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
7614 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
7615 int charpos
= glyph
->charpos
;
7617 if (BUFFERP (glyph
->object
))
7622 *vpos
= best_row_vpos
;
7627 else if (charpos
> pos
)
7630 else if (EQ (glyph
->object
, stop
))
7635 current_x
+= glyph
->pixel_width
;
7638 /* If we're looking for the end of the buffer,
7639 and we didn't find it in the line we scanned,
7640 use the start of the following line. */
7641 if (maybe_next_line_p
)
7646 current_x
= best_row
->x
;
7649 *vpos
= best_row_vpos
;
7650 *hpos
= lastcol
+ 1;
7659 /* Find the position of the glyph for position POS in OBJECT in
7660 window W's current matrix, and return in *X, *Y the pixel
7661 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
7663 RIGHT_P non-zero means return the position of the right edge of the
7664 glyph, RIGHT_P zero means return the left edge position.
7666 If no glyph for POS exists in the matrix, return the position of
7667 the glyph with the next smaller position that is in the matrix, if
7668 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
7669 exists in the matrix, return the position of the glyph with the
7670 next larger position in OBJECT.
7672 Value is non-zero if a glyph was found. */
7675 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
7679 int *hpos
, *vpos
, *x
, *y
;
7682 int yb
= window_text_bottom_y (w
);
7683 struct glyph_row
*r
;
7684 struct glyph
*best_glyph
= NULL
;
7685 struct glyph_row
*best_row
= NULL
;
7688 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7689 r
->enabled_p
&& r
->y
< yb
;
7692 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7693 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
7696 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
7697 if (EQ (g
->object
, object
))
7699 if (g
->charpos
== pos
)
7706 else if (best_glyph
== NULL
7707 || ((abs (g
->charpos
- pos
)
7708 < abs (best_glyph
->charpos
- pos
))
7711 : g
->charpos
> pos
)))
7725 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
7729 *x
+= best_glyph
->pixel_width
;
7734 *vpos
= best_row
- w
->current_matrix
->rows
;
7737 return best_glyph
!= NULL
;
7741 /* Display the active region described by mouse_face_*
7742 in its mouse-face if HL > 0, in its normal face if HL = 0. */
7745 show_mouse_face (dpyinfo
, draw
)
7746 struct x_display_info
*dpyinfo
;
7747 enum draw_glyphs_face draw
;
7749 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
7750 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7752 if (/* If window is in the process of being destroyed, don't bother
7754 w
->current_matrix
!= NULL
7755 /* Recognize when we are called to operate on rows that don't exist
7756 anymore. This can happen when a window is split. */
7757 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
7759 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
7760 struct glyph_row
*row
, *first
, *last
;
7762 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
7763 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
7765 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
7767 int start_hpos
, end_hpos
, start_x
;
7769 /* For all but the first row, the highlight starts at column 0. */
7772 start_hpos
= dpyinfo
->mouse_face_beg_col
;
7773 start_x
= dpyinfo
->mouse_face_beg_x
;
7782 end_hpos
= dpyinfo
->mouse_face_end_col
;
7784 end_hpos
= row
->used
[TEXT_AREA
];
7786 if (end_hpos
> start_hpos
)
7788 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
7789 start_hpos
, end_hpos
, draw
, 0);
7792 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
7796 /* When we've written over the cursor, arrange for it to
7797 be displayed again. */
7798 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
7799 x_display_cursor (w
, 1,
7800 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
7801 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
7804 /* Change the mouse cursor. */
7805 if (draw
== DRAW_NORMAL_TEXT
)
7806 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7807 f
->output_data
.x
->text_cursor
);
7808 else if (draw
== DRAW_MOUSE_FACE
)
7809 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7810 f
->output_data
.x
->cross_cursor
);
7812 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7813 f
->output_data
.x
->nontext_cursor
);
7816 /* Clear out the mouse-highlighted active region.
7817 Redraw it un-highlighted first. Value is non-zero if mouse
7818 face was actually drawn unhighlighted. */
7821 clear_mouse_face (dpyinfo
)
7822 struct x_display_info
*dpyinfo
;
7826 if (!NILP (dpyinfo
->mouse_face_window
))
7828 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
7832 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7833 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7834 dpyinfo
->mouse_face_window
= Qnil
;
7835 dpyinfo
->mouse_face_overlay
= Qnil
;
7840 /* Clear any mouse-face on window W. This function is part of the
7841 redisplay interface, and is called from try_window_id and similar
7842 functions to ensure the mouse-highlight is off. */
7845 x_clear_mouse_face (w
)
7848 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
7852 XSETWINDOW (window
, w
);
7853 if (EQ (window
, dpyinfo
->mouse_face_window
))
7854 clear_mouse_face (dpyinfo
);
7859 /* Just discard the mouse face information for frame F, if any.
7860 This is used when the size of F is changed. */
7863 cancel_mouse_face (f
)
7867 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7869 window
= dpyinfo
->mouse_face_window
;
7870 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
7872 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7873 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7874 dpyinfo
->mouse_face_window
= Qnil
;
7879 static int glyph_rect
P_ ((struct frame
*f
, int, int, XRectangle
*));
7882 /* Try to determine frame pixel position and size of the glyph under
7883 frame pixel coordinates X/Y on frame F . Return the position and
7884 size in *RECT. Value is non-zero if we could compute these
7888 glyph_rect (f
, x
, y
, rect
)
7894 int part
, found
= 0;
7896 window
= window_from_coordinates (f
, x
, y
, &part
, 0);
7899 struct window
*w
= XWINDOW (window
);
7900 struct glyph_row
*r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7901 struct glyph_row
*end
= r
+ w
->current_matrix
->nrows
- 1;
7903 frame_to_window_pixel_xy (w
, &x
, &y
);
7905 for (; !found
&& r
< end
&& r
->enabled_p
; ++r
)
7908 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7909 struct glyph
*end
= g
+ r
->used
[TEXT_AREA
];
7912 for (gx
= r
->x
; !found
&& g
< end
; gx
+= g
->pixel_width
, ++g
)
7915 rect
->width
= g
->pixel_width
;
7916 rect
->height
= r
->height
;
7917 rect
->x
= WINDOW_TO_FRAME_PIXEL_X (w
, gx
);
7918 rect
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, r
->y
);
7928 /* Return the current position of the mouse.
7929 *FP should be a frame which indicates which display to ask about.
7931 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
7932 and *PART to the frame, window, and scroll bar part that the mouse
7933 is over. Set *X and *Y to the portion and whole of the mouse's
7934 position on the scroll bar.
7936 If the mouse movement started elsewhere, set *FP to the frame the
7937 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
7940 Set *TIME to the server time-stamp for the time at which the mouse
7941 was at this position.
7943 Don't store anything if we don't have a valid set of values to report.
7945 This clears the mouse_moved flag, so we can wait for the next mouse
7949 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
7952 Lisp_Object
*bar_window
;
7953 enum scroll_bar_part
*part
;
7955 unsigned long *time
;
7961 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
7962 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
7968 Window dummy_window
;
7971 Lisp_Object frame
, tail
;
7973 /* Clear the mouse-moved flag for every frame on this display. */
7974 FOR_EACH_FRAME (tail
, frame
)
7975 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
7976 XFRAME (frame
)->mouse_moved
= 0;
7978 last_mouse_scroll_bar
= Qnil
;
7980 /* Figure out which root window we're on. */
7981 XQueryPointer (FRAME_X_DISPLAY (*fp
),
7982 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
7984 /* The root window which contains the pointer. */
7987 /* Trash which we can't trust if the pointer is on
7988 a different screen. */
7991 /* The position on that root window. */
7994 /* More trash we can't trust. */
7997 /* Modifier keys and pointer buttons, about which
7999 (unsigned int *) &dummy
);
8001 /* Now we have a position on the root; find the innermost window
8002 containing the pointer. */
8006 int parent_x
= 0, parent_y
= 0;
8011 /* XTranslateCoordinates can get errors if the window
8012 structure is changing at the same time this function
8013 is running. So at least we must not crash from them. */
8015 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
8017 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
8018 && FRAME_LIVE_P (last_mouse_frame
))
8020 /* If mouse was grabbed on a frame, give coords for that frame
8021 even if the mouse is now outside it. */
8022 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
8024 /* From-window, to-window. */
8025 root
, FRAME_X_WINDOW (last_mouse_frame
),
8027 /* From-position, to-position. */
8028 root_x
, root_y
, &win_x
, &win_y
,
8032 f1
= last_mouse_frame
;
8038 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
8040 /* From-window, to-window. */
8043 /* From-position, to-position. */
8044 root_x
, root_y
, &win_x
, &win_y
,
8049 if (child
== None
|| child
== win
)
8057 /* Now we know that:
8058 win is the innermost window containing the pointer
8059 (XTC says it has no child containing the pointer),
8060 win_x and win_y are the pointer's position in it
8061 (XTC did this the last time through), and
8062 parent_x and parent_y are the pointer's position in win's parent.
8063 (They are what win_x and win_y were when win was child.
8064 If win is the root window, it has no parent, and
8065 parent_{x,y} are invalid, but that's okay, because we'll
8066 never use them in that case.) */
8068 /* Is win one of our frames? */
8069 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
8071 #ifdef USE_X_TOOLKIT
8072 /* If we end up with the menu bar window, say it's not
8075 && f1
->output_data
.x
->menubar_widget
8076 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
8078 #endif /* USE_X_TOOLKIT */
8081 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
8084 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
8086 /* If not, is it one of our scroll bars? */
8089 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
8093 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8099 if (f1
== 0 && insist
> 0)
8100 f1
= SELECTED_FRAME ();
8104 /* Ok, we found a frame. Store all the values.
8105 last_mouse_glyph is a rectangle used to reduce the
8106 generation of mouse events. To not miss any motion
8107 events, we must divide the frame into rectangles of the
8108 size of the smallest character that could be displayed
8109 on it, i.e. into the same rectangles that matrices on
8110 the frame are divided into. */
8112 int width
, height
, gx
, gy
;
8115 if (glyph_rect (f1
, win_x
, win_y
, &rect
))
8116 last_mouse_glyph
= rect
;
8119 width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
8120 height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
8124 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
8125 round down even for negative values. */
8130 gx
= (gx
+ width
- 1) / width
* width
;
8131 gy
= (gy
+ height
- 1) / height
* height
;
8133 last_mouse_glyph
.width
= width
;
8134 last_mouse_glyph
.height
= height
;
8135 last_mouse_glyph
.x
= gx
;
8136 last_mouse_glyph
.y
= gy
;
8142 XSETINT (*x
, win_x
);
8143 XSETINT (*y
, win_y
);
8144 *time
= last_mouse_movement_time
;
8153 #ifdef USE_X_TOOLKIT
8155 /* Atimer callback function for TIMER. Called every 0.1s to process
8156 Xt timeouts, if needed. We must avoid calling XtAppPending as
8157 much as possible because that function does an implicit XFlush
8158 that slows us down. */
8161 x_process_timeouts (timer
)
8162 struct atimer
*timer
;
8164 if (toolkit_scroll_bar_interaction
|| popup_activated_flag
)
8167 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
8168 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
8173 #endif /* USE_X_TOOLKIT */
8176 /* Scroll bar support. */
8178 /* Given an X window ID, find the struct scroll_bar which manages it.
8179 This can be called in GC, so we have to make sure to strip off mark
8182 static struct scroll_bar
*
8183 x_window_to_scroll_bar (window_id
)
8188 for (tail
= Vframe_list
;
8189 XGCTYPE (tail
) == Lisp_Cons
;
8192 Lisp_Object frame
, bar
, condemned
;
8194 frame
= XCAR (tail
);
8195 /* All elements of Vframe_list should be frames. */
8196 if (! GC_FRAMEP (frame
))
8199 /* Scan this frame's scroll bar list for a scroll bar with the
8201 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
8202 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
8203 /* This trick allows us to search both the ordinary and
8204 condemned scroll bar lists with one loop. */
8205 ! GC_NILP (bar
) || (bar
= condemned
,
8208 bar
= XSCROLL_BAR (bar
)->next
)
8209 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
8210 return XSCROLL_BAR (bar
);
8217 #if defined USE_LUCID
8219 /* Return the Lucid menu bar WINDOW is part of. Return null
8220 if WINDOW is not part of a menu bar. */
8223 x_window_to_menu_bar (window
)
8228 for (tail
= Vframe_list
;
8229 XGCTYPE (tail
) == Lisp_Cons
;
8232 Lisp_Object frame
= XCAR (tail
);
8233 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
8235 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
8242 #endif /* USE_LUCID */
8245 /************************************************************************
8247 ************************************************************************/
8249 #ifdef USE_TOOLKIT_SCROLL_BARS
8251 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
8252 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
8253 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
8254 struct scroll_bar
*));
8255 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
8259 /* Id of action hook installed for scroll bars. */
8261 static XtActionHookId action_hook_id
;
8263 /* Lisp window being scrolled. Set when starting to interact with
8264 a toolkit scroll bar, reset to nil when ending the interaction. */
8266 static Lisp_Object window_being_scrolled
;
8268 /* Last scroll bar part sent in xm_scroll_callback. */
8270 static int last_scroll_bar_part
;
8272 /* Whether this is an Xaw with arrow-scrollbars. This should imply
8273 that movements of 1/20 of the screen size are mapped to up/down. */
8275 static Boolean xaw3d_arrow_scroll
;
8277 /* Whether the drag scrolling maintains the mouse at the top of the
8278 thumb. If not, resizing the thumb needs to be done more carefully
8279 to avoid jerkyness. */
8281 static Boolean xaw3d_pick_top
;
8284 /* Action hook installed via XtAppAddActionHook when toolkit scroll
8285 bars are used.. The hook is responsible for detecting when
8286 the user ends an interaction with the scroll bar, and generates
8287 a `end-scroll' scroll_bar_click' event if so. */
8290 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
8293 XtPointer client_data
;
8297 Cardinal
*num_params
;
8303 scroll_bar_p
= XmIsScrollBar (widget
);
8304 end_action
= "Release";
8305 #else /* !USE_MOTIF i.e. use Xaw */
8306 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
8307 end_action
= "EndScroll";
8308 #endif /* USE_MOTIF */
8311 && strcmp (action_name
, end_action
) == 0
8312 && WINDOWP (window_being_scrolled
))
8316 x_send_scroll_bar_event (window_being_scrolled
,
8317 scroll_bar_end_scroll
, 0, 0);
8318 w
= XWINDOW (window_being_scrolled
);
8319 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
8320 window_being_scrolled
= Qnil
;
8321 last_scroll_bar_part
= -1;
8323 /* Xt timeouts no longer needed. */
8324 toolkit_scroll_bar_interaction
= 0;
8328 /* A vector of windows used for communication between
8329 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
8331 static struct window
**scroll_bar_windows
;
8332 static int scroll_bar_windows_size
;
8335 /* Send a client message with message type Xatom_Scrollbar for a
8336 scroll action to the frame of WINDOW. PART is a value identifying
8337 the part of the scroll bar that was clicked on. PORTION is the
8338 amount to scroll of a whole of WHOLE. */
8341 x_send_scroll_bar_event (window
, part
, portion
, whole
)
8343 int part
, portion
, whole
;
8346 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
8347 struct window
*w
= XWINDOW (window
);
8348 struct frame
*f
= XFRAME (w
->frame
);
8353 /* Construct a ClientMessage event to send to the frame. */
8354 ev
->type
= ClientMessage
;
8355 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
8356 ev
->display
= FRAME_X_DISPLAY (f
);
8357 ev
->window
= FRAME_X_WINDOW (f
);
8360 /* We can only transfer 32 bits in the XClientMessageEvent, which is
8361 not enough to store a pointer or Lisp_Object on a 64 bit system.
8362 So, store the window in scroll_bar_windows and pass the index
8363 into that array in the event. */
8364 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
8365 if (scroll_bar_windows
[i
] == NULL
)
8368 if (i
== scroll_bar_windows_size
)
8370 int new_size
= max (10, 2 * scroll_bar_windows_size
);
8371 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
8372 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
8374 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
8376 bzero (&scroll_bar_windows
[i
], nbytes
- old_nbytes
);
8377 scroll_bar_windows_size
= new_size
;
8380 scroll_bar_windows
[i
] = w
;
8381 ev
->data
.l
[0] = (long) i
;
8382 ev
->data
.l
[1] = (long) part
;
8383 ev
->data
.l
[2] = (long) 0;
8384 ev
->data
.l
[3] = (long) portion
;
8385 ev
->data
.l
[4] = (long) whole
;
8387 /* Make Xt timeouts work while the scroll bar is active. */
8388 toolkit_scroll_bar_interaction
= 1;
8390 /* Setting the event mask to zero means that the message will
8391 be sent to the client that created the window, and if that
8392 window no longer exists, no event will be sent. */
8393 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
8398 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
8402 x_scroll_bar_to_input_event (event
, ievent
)
8404 struct input_event
*ievent
;
8406 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
8411 w
= scroll_bar_windows
[ev
->data
.l
[0]];
8412 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
8414 XSETWINDOW (window
, w
);
8415 f
= XFRAME (w
->frame
);
8417 ievent
->kind
= scroll_bar_click
;
8418 ievent
->frame_or_window
= window
;
8420 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
8421 ievent
->part
= ev
->data
.l
[1];
8422 ievent
->code
= ev
->data
.l
[2];
8423 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
8424 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
8425 ievent
->modifiers
= 0;
8431 /* Minimum and maximum values used for Motif scroll bars. */
8434 #define XM_SB_MAX 10000000
8435 #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN)
8438 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
8439 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
8440 CALL_DATA is a pointer a a XmScrollBarCallbackStruct. */
8443 xm_scroll_callback (widget
, client_data
, call_data
)
8445 XtPointer client_data
, call_data
;
8447 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8448 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
8449 int part
= -1, whole
= 0, portion
= 0;
8453 case XmCR_DECREMENT
:
8454 bar
->dragging
= Qnil
;
8455 part
= scroll_bar_up_arrow
;
8458 case XmCR_INCREMENT
:
8459 bar
->dragging
= Qnil
;
8460 part
= scroll_bar_down_arrow
;
8463 case XmCR_PAGE_DECREMENT
:
8464 bar
->dragging
= Qnil
;
8465 part
= scroll_bar_above_handle
;
8468 case XmCR_PAGE_INCREMENT
:
8469 bar
->dragging
= Qnil
;
8470 part
= scroll_bar_below_handle
;
8474 bar
->dragging
= Qnil
;
8475 part
= scroll_bar_to_top
;
8478 case XmCR_TO_BOTTOM
:
8479 bar
->dragging
= Qnil
;
8480 part
= scroll_bar_to_bottom
;
8486 int dragging_down_p
= (INTEGERP (bar
->dragging
)
8487 && XINT (bar
->dragging
) <= cs
->value
);
8489 /* Get the slider size. */
8491 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
8494 /* At the max position of the scroll bar, do a line-wise
8495 movement. Without doing anything, we would be called with
8496 the same cs->value again and again. If we want to make
8497 sure that we can reach the end of the buffer, we have to do
8500 Implementation note: setting bar->dragging always to
8501 cs->value gives a smoother movement at the max position.
8502 Setting it to nil when doing line-wise movement gives
8503 a better slider behavior. */
8505 if (cs
->value
+ slider_size
== XM_SB_MAX
8507 && last_scroll_bar_part
== scroll_bar_down_arrow
))
8509 part
= scroll_bar_down_arrow
;
8510 bar
->dragging
= Qnil
;
8514 whole
= XM_SB_RANGE
;
8515 portion
= min (cs
->value
- XM_SB_MIN
, XM_SB_MAX
- slider_size
);
8516 part
= scroll_bar_handle
;
8517 bar
->dragging
= make_number (cs
->value
);
8522 case XmCR_VALUE_CHANGED
:
8528 window_being_scrolled
= bar
->window
;
8529 last_scroll_bar_part
= part
;
8530 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
8535 #else /* !USE_MOTIF, i.e. Xaw. */
8538 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
8539 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
8540 scroll bar struct. CALL_DATA is a pointer to a float saying where
8544 xaw_jump_callback (widget
, client_data
, call_data
)
8546 XtPointer client_data
, call_data
;
8548 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8549 float top
= *(float *) call_data
;
8551 int whole
, portion
, height
;
8554 /* Get the size of the thumb, a value between 0 and 1. */
8556 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
8560 portion
= shown
< 1 ? top
* whole
: 0;
8562 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
8563 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
8564 the bottom, so we force the scrolling whenever we see that we're
8565 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
8566 we try to ensure that we always stay two pixels away from the
8568 part
= scroll_bar_down_arrow
;
8570 part
= scroll_bar_handle
;
8572 window_being_scrolled
= bar
->window
;
8573 bar
->dragging
= make_number (portion
);
8574 last_scroll_bar_part
= part
;
8575 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
8579 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
8580 i.e. line or page up or down. WIDGET is the Xaw scroll bar
8581 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
8582 the scroll bar. CALL_DATA is an integer specifying the action that
8583 has taken place. It's magnitude is in the range 0..height of the
8584 scroll bar. Negative values mean scroll towards buffer start.
8585 Values < height of scroll bar mean line-wise movement. */
8588 xaw_scroll_callback (widget
, client_data
, call_data
)
8590 XtPointer client_data
, call_data
;
8592 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8593 int position
= (int) call_data
;
8597 /* Get the height of the scroll bar. */
8599 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
8602 if (abs (position
) >= height
)
8603 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
8605 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
8606 it maps line-movement to call_data = max(5, height/20). */
8607 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
8608 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
8610 part
= scroll_bar_move_ratio
;
8612 window_being_scrolled
= bar
->window
;
8613 bar
->dragging
= Qnil
;
8614 last_scroll_bar_part
= part
;
8615 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
8619 #endif /* not USE_MOTIF */
8622 /* Create the widget for scroll bar BAR on frame F. Record the widget
8623 and X window of the scroll bar in BAR. */
8626 x_create_toolkit_scroll_bar (f
, bar
)
8628 struct scroll_bar
*bar
;
8634 char *scroll_bar_name
= "verticalScrollBar";
8635 unsigned long pixel
;
8640 /* Set resources. Create the widget. */
8641 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
8642 XtSetArg (av
[ac
], XmNminimum
, XM_SB_MIN
); ++ac
;
8643 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
8644 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
8645 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
8646 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
8647 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
8649 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
8652 XtSetArg (av
[ac
], XmNforeground
, pixel
);
8656 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8659 XtSetArg (av
[ac
], XmNbackground
, pixel
);
8663 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
8664 scroll_bar_name
, av
, ac
);
8666 /* Add one callback for everything that can happen. */
8667 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
8669 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
8671 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
8673 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
8675 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
8677 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
8679 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
8682 /* Realize the widget. Only after that is the X window created. */
8683 XtRealizeWidget (widget
);
8685 /* Set the cursor to an arrow. I didn't find a resource to do that.
8686 And I'm wondering why it hasn't an arrow cursor by default. */
8687 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
8688 f
->output_data
.x
->nontext_cursor
);
8690 #else /* !USE_MOTIF i.e. use Xaw */
8692 /* Set resources. Create the widget. The background of the
8693 Xaw3d scroll bar widget is a little bit light for my taste.
8694 We don't alter it here to let users change it according
8695 to their taste with `emacs*verticalScrollBar.background: xxx'. */
8696 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
8697 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
8698 /* For smoother scrolling with Xaw3d -sm */
8699 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
8701 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
8704 XtSetArg (av
[ac
], XtNforeground
, pixel
);
8708 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8711 XtSetArg (av
[ac
], XtNbackground
, pixel
);
8715 /* Top/bottom shadow colors. */
8717 /* Allocate them, if necessary. */
8718 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
8720 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8721 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
8722 &pixel
, 1.2, 0x8000))
8724 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
8726 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
8728 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8729 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
8730 &pixel
, 0.6, 0x4000))
8732 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
8735 /* Tell the toolkit about them. */
8736 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
8737 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
8738 /* We tried to allocate a color for the top/bottom shadow, and
8739 failed, so tell Xaw3d to use dithering instead. */
8741 XtSetArg (av
[ac
], XtNbeNiceToColormap
, True
);
8745 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
8746 be more consistent with other emacs 3d colors, and since Xaw3d is
8747 not good at dealing with allocation failure. */
8749 /* This tells Xaw3d to use real colors instead of dithering for
8751 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
8754 /* Specify the colors. */
8755 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
8758 XtSetArg (av
[ac
], "topShadowPixel", pixel
);
8761 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
8764 XtSetArg (av
[ac
], "bottomShadowPixel", pixel
);
8769 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
8770 f
->output_data
.x
->edit_widget
, av
, ac
);
8774 char *val
= initial
;
8775 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
8776 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
8778 { /* ARROW_SCROLL */
8779 xaw3d_arrow_scroll
= True
;
8780 /* Isn't that just a personal preference ? -sm */
8781 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
8785 /* Define callbacks. */
8786 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
8787 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
8790 /* Realize the widget. Only after that is the X window created. */
8791 XtRealizeWidget (widget
);
8793 #endif /* !USE_MOTIF */
8795 /* Install an action hook that let's us detect when the user
8796 finishes interacting with a scroll bar. */
8797 if (action_hook_id
== 0)
8798 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
8800 /* Remember X window and widget in the scroll bar vector. */
8801 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
8802 xwindow
= XtWindow (widget
);
8803 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
8809 /* Set the thumb size and position of scroll bar BAR. We are currently
8810 displaying PORTION out of a whole WHOLE, and our position POSITION. */
8813 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
8814 struct scroll_bar
*bar
;
8815 int portion
, position
, whole
;
8817 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8818 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
8825 top
= (float) position
/ whole
;
8826 shown
= (float) portion
/ whole
;
8835 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
8836 is the scroll bar's maximum and MIN is the scroll bar's minimum
8838 size
= shown
* XM_SB_RANGE
;
8839 size
= min (size
, XM_SB_RANGE
);
8840 size
= max (size
, 1);
8842 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
8843 value
= top
* XM_SB_RANGE
;
8844 value
= min (value
, XM_SB_MAX
- size
);
8845 value
= max (value
, XM_SB_MIN
);
8847 if (NILP (bar
->dragging
))
8848 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
8849 else if (last_scroll_bar_part
== scroll_bar_down_arrow
)
8850 /* This has the negative side effect that the slider value is
8851 not what it would be if we scrolled here using line-wise or
8852 page-wise movement. */
8853 XmScrollBarSetValues (widget
, value
, XM_SB_RANGE
- value
, 0, 0, False
);
8856 /* If currently dragging, only update the slider size.
8857 This reduces flicker effects. */
8858 int old_value
, old_size
, increment
, page_increment
;
8860 XmScrollBarGetValues (widget
, &old_value
, &old_size
,
8861 &increment
, &page_increment
);
8862 XmScrollBarSetValues (widget
, old_value
,
8863 min (size
, XM_SB_RANGE
- old_value
),
8867 #else /* !USE_MOTIF i.e. use Xaw */
8869 float old_top
, old_shown
;
8871 XtVaGetValues (widget
,
8872 XtNtopOfThumb
, &old_top
,
8873 XtNshown
, &old_shown
,
8877 /* Massage the top+shown values. */
8878 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
8879 top
= max (0, min (1, top
));
8882 /* Keep two pixels available for moving the thumb down. */
8883 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
8885 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
8886 check that your system's configuration file contains a define
8887 for `NARROWPROTO'. See s/freebsd.h for an example. */
8888 if (top
!= old_top
|| shown
!= old_shown
)
8890 if (NILP (bar
->dragging
))
8891 XawScrollbarSetThumb (widget
, top
, shown
);
8895 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
8896 int scroll_mode
= 0;
8898 /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR. */
8899 if (xaw3d_arrow_scroll
)
8901 /* Xaw3d stupidly ignores resize requests while dragging
8902 so we have to make it believe it's not in dragging mode. */
8903 scroll_mode
= sb
->scrollbar
.scroll_mode
;
8904 if (scroll_mode
== 2)
8905 sb
->scrollbar
.scroll_mode
= 0;
8908 /* Try to make the scrolling a tad smoother. */
8909 if (!xaw3d_pick_top
)
8910 shown
= min (shown
, old_shown
);
8912 XawScrollbarSetThumb (widget
, top
, shown
);
8915 if (xaw3d_arrow_scroll
&& scroll_mode
== 2)
8916 sb
->scrollbar
.scroll_mode
= scroll_mode
;
8921 #endif /* !USE_MOTIF */
8926 #endif /* USE_TOOLKIT_SCROLL_BARS */
8930 /************************************************************************
8931 Scroll bars, general
8932 ************************************************************************/
8934 /* Create a scroll bar and return the scroll bar vector for it. W is
8935 the Emacs window on which to create the scroll bar. TOP, LEFT,
8936 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
8939 static struct scroll_bar
*
8940 x_scroll_bar_create (w
, top
, left
, width
, height
)
8942 int top
, left
, width
, height
;
8944 struct frame
*f
= XFRAME (w
->frame
);
8945 struct scroll_bar
*bar
8946 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
8950 #ifdef USE_TOOLKIT_SCROLL_BARS
8951 x_create_toolkit_scroll_bar (f
, bar
);
8952 #else /* not USE_TOOLKIT_SCROLL_BARS */
8954 XSetWindowAttributes a
;
8958 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8959 if (a
.background_pixel
== -1)
8960 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
8962 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
8963 | ButtonMotionMask
| PointerMotionHintMask
8965 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
8967 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
8969 /* Clear the area of W that will serve as a scroll bar. This is
8970 for the case that a window has been split horizontally. In
8971 this case, no clear_frame is generated to reduce flickering. */
8972 if (width
> 0 && height
> 0)
8973 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8975 window_box_height (w
), False
);
8977 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8978 /* Position and size of scroll bar. */
8979 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8981 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8983 /* Border width, depth, class, and visual. */
8990 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
8992 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8994 XSETWINDOW (bar
->window
, w
);
8995 XSETINT (bar
->top
, top
);
8996 XSETINT (bar
->left
, left
);
8997 XSETINT (bar
->width
, width
);
8998 XSETINT (bar
->height
, height
);
8999 XSETINT (bar
->start
, 0);
9000 XSETINT (bar
->end
, 0);
9001 bar
->dragging
= Qnil
;
9003 /* Add bar to its frame's list of scroll bars. */
9004 bar
->next
= FRAME_SCROLL_BARS (f
);
9006 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
9007 if (!NILP (bar
->next
))
9008 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
9010 /* Map the window/widget. */
9011 #ifdef USE_TOOLKIT_SCROLL_BARS
9013 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
9014 XtConfigureWidget (scroll_bar
,
9015 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9017 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
9018 max (height
, 1), 0);
9019 XtMapWidget (scroll_bar
);
9021 #else /* not USE_TOOLKIT_SCROLL_BARS */
9022 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
9023 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9030 /* Draw BAR's handle in the proper position.
9032 If the handle is already drawn from START to END, don't bother
9033 redrawing it, unless REBUILD is non-zero; in that case, always
9034 redraw it. (REBUILD is handy for drawing the handle after expose
9037 Normally, we want to constrain the start and end of the handle to
9038 fit inside its rectangle, but if the user is dragging the scroll
9039 bar handle, we want to let them drag it down all the way, so that
9040 the bar's top is as far down as it goes; otherwise, there's no way
9041 to move to the very end of the buffer. */
9043 #ifndef USE_TOOLKIT_SCROLL_BARS
9046 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
9047 struct scroll_bar
*bar
;
9051 int dragging
= ! NILP (bar
->dragging
);
9052 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9053 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9054 GC gc
= f
->output_data
.x
->normal_gc
;
9056 /* If the display is already accurate, do nothing. */
9058 && start
== XINT (bar
->start
)
9059 && end
== XINT (bar
->end
))
9065 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
9066 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9067 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9069 /* Make sure the values are reasonable, and try to preserve
9070 the distance between start and end. */
9072 int length
= end
- start
;
9076 else if (start
> top_range
)
9078 end
= start
+ length
;
9082 else if (end
> top_range
&& ! dragging
)
9086 /* Store the adjusted setting in the scroll bar. */
9087 XSETINT (bar
->start
, start
);
9088 XSETINT (bar
->end
, end
);
9090 /* Clip the end position, just for display. */
9091 if (end
> top_range
)
9094 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
9095 below top positions, to make sure the handle is always at least
9096 that many pixels tall. */
9097 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
9099 /* Draw the empty space above the handle. Note that we can't clear
9100 zero-height areas; that means "clear to end of window." */
9102 x_clear_area (FRAME_X_DISPLAY (f
), w
,
9103 /* x, y, width, height, and exposures. */
9104 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
9105 VERTICAL_SCROLL_BAR_TOP_BORDER
,
9106 inside_width
, start
,
9109 /* Change to proper foreground color if one is specified. */
9110 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9111 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
9112 f
->output_data
.x
->scroll_bar_foreground_pixel
);
9114 /* Draw the handle itself. */
9115 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
9116 /* x, y, width, height */
9117 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
9118 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
9119 inside_width
, end
- start
);
9121 /* Restore the foreground color of the GC if we changed it above. */
9122 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9123 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
9124 f
->output_data
.x
->foreground_pixel
);
9126 /* Draw the empty space below the handle. Note that we can't
9127 clear zero-height areas; that means "clear to end of window." */
9128 if (end
< inside_height
)
9129 x_clear_area (FRAME_X_DISPLAY (f
), w
,
9130 /* x, y, width, height, and exposures. */
9131 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
9132 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
9133 inside_width
, inside_height
- end
,
9141 #endif /* !USE_TOOLKIT_SCROLL_BARS */
9143 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
9147 x_scroll_bar_remove (bar
)
9148 struct scroll_bar
*bar
;
9150 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9153 #ifdef USE_TOOLKIT_SCROLL_BARS
9154 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
9156 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
9159 /* Disassociate this scroll bar from its window. */
9160 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
9166 /* Set the handle of the vertical scroll bar for WINDOW to indicate
9167 that we are displaying PORTION characters out of a total of WHOLE
9168 characters, starting at POSITION. If WINDOW has no scroll bar,
9172 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
9174 int portion
, whole
, position
;
9176 struct frame
*f
= XFRAME (w
->frame
);
9177 struct scroll_bar
*bar
;
9178 int top
, height
, left
, sb_left
, width
, sb_width
;
9179 int window_x
, window_y
, window_width
, window_height
;
9181 /* Get window dimensions. */
9182 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
9184 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
9185 height
= window_height
;
9187 /* Compute the left edge of the scroll bar area. */
9188 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
9189 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
9191 left
= XFASTINT (w
->left
);
9192 left
*= CANON_X_UNIT (f
);
9193 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
9195 /* Compute the width of the scroll bar which might be less than
9196 the width of the area reserved for the scroll bar. */
9197 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
9198 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
9202 /* Compute the left edge of the scroll bar. */
9203 #ifdef USE_TOOLKIT_SCROLL_BARS
9204 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
9205 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
9207 sb_left
= left
+ (width
- sb_width
) / 2;
9209 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
9210 sb_left
= left
+ width
- sb_width
;
9215 /* Does the scroll bar exist yet? */
9216 if (NILP (w
->vertical_scroll_bar
))
9218 if (width
> 0 && height
> 0)
9221 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9222 left
, top
, width
, height
, False
);
9226 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
9230 /* It may just need to be moved and resized. */
9231 unsigned int mask
= 0;
9233 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
9237 if (sb_left
!= XINT (bar
->left
))
9239 if (top
!= XINT (bar
->top
))
9241 if (sb_width
!= XINT (bar
->width
))
9243 if (height
!= XINT (bar
->height
))
9246 #ifdef USE_TOOLKIT_SCROLL_BARS
9248 /* Since toolkit scroll bars are smaller than the space reserved
9249 for them on the frame, we have to clear "under" them. */
9250 if (width
> 0 && height
> 0)
9251 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9252 left
, top
, width
, height
, False
);
9254 /* Move/size the scroll bar widget. */
9256 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
9257 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9259 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
9260 max (height
, 1), 0);
9262 #else /* not USE_TOOLKIT_SCROLL_BARS */
9264 /* Clear areas not covered by the scroll bar because of
9265 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
9266 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
9268 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9269 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9271 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9272 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9273 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9277 /* Clear areas not covered by the scroll bar because it's not as
9278 wide as the area reserved for it . This makes sure a
9279 previous mode line display is cleared after C-x 2 C-x 1, for
9282 int area_width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
9283 int rest
= area_width
- sb_width
;
9284 if (rest
> 0 && height
> 0)
9286 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
9287 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9288 left
+ area_width
- rest
, top
,
9289 rest
, height
, False
);
9291 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9292 left
, top
, rest
, height
, False
);
9296 /* Move/size the scroll bar window. */
9301 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
9303 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
9305 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
9309 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9311 /* Remember new settings. */
9312 XSETINT (bar
->left
, sb_left
);
9313 XSETINT (bar
->top
, top
);
9314 XSETINT (bar
->width
, sb_width
);
9315 XSETINT (bar
->height
, height
);
9320 #ifdef USE_TOOLKIT_SCROLL_BARS
9321 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
9322 #else /* not USE_TOOLKIT_SCROLL_BARS */
9323 /* Set the scroll bar's current state, unless we're currently being
9325 if (NILP (bar
->dragging
))
9327 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
9330 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
9333 int start
= ((double) position
* top_range
) / whole
;
9334 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
9335 x_scroll_bar_set_handle (bar
, start
, end
, 0);
9338 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9340 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
9344 /* The following three hooks are used when we're doing a thorough
9345 redisplay of the frame. We don't explicitly know which scroll bars
9346 are going to be deleted, because keeping track of when windows go
9347 away is a real pain - "Can you say set-window-configuration, boys
9348 and girls?" Instead, we just assert at the beginning of redisplay
9349 that *all* scroll bars are to be removed, and then save a scroll bar
9350 from the fiery pit when we actually redisplay its window. */
9352 /* Arrange for all scroll bars on FRAME to be removed at the next call
9353 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
9354 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
9357 XTcondemn_scroll_bars (frame
)
9360 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
9361 while (! NILP (FRAME_SCROLL_BARS (frame
)))
9364 bar
= FRAME_SCROLL_BARS (frame
);
9365 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
9366 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
9367 XSCROLL_BAR (bar
)->prev
= Qnil
;
9368 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
9369 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
9370 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
9375 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
9376 Note that WINDOW isn't necessarily condemned at all. */
9379 XTredeem_scroll_bar (window
)
9380 struct window
*window
;
9382 struct scroll_bar
*bar
;
9385 /* We can't redeem this window's scroll bar if it doesn't have one. */
9386 if (NILP (window
->vertical_scroll_bar
))
9389 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
9391 /* Unlink it from the condemned list. */
9392 f
= XFRAME (WINDOW_FRAME (window
));
9393 if (NILP (bar
->prev
))
9395 /* If the prev pointer is nil, it must be the first in one of
9397 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
9398 /* It's not condemned. Everything's fine. */
9400 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
9401 window
->vertical_scroll_bar
))
9402 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
9404 /* If its prev pointer is nil, it must be at the front of
9405 one or the other! */
9409 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
9411 if (! NILP (bar
->next
))
9412 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
9414 bar
->next
= FRAME_SCROLL_BARS (f
);
9416 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
9417 if (! NILP (bar
->next
))
9418 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
9421 /* Remove all scroll bars on FRAME that haven't been saved since the
9422 last call to `*condemn_scroll_bars_hook'. */
9425 XTjudge_scroll_bars (f
)
9428 Lisp_Object bar
, next
;
9430 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
9432 /* Clear out the condemned list now so we won't try to process any
9433 more events on the hapless scroll bars. */
9434 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
9436 for (; ! NILP (bar
); bar
= next
)
9438 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
9440 x_scroll_bar_remove (b
);
9443 b
->next
= b
->prev
= Qnil
;
9446 /* Now there should be no references to the condemned scroll bars,
9447 and they should get garbage-collected. */
9451 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
9452 is a no-op when using toolkit scroll bars.
9454 This may be called from a signal handler, so we have to ignore GC
9458 x_scroll_bar_expose (bar
, event
)
9459 struct scroll_bar
*bar
;
9462 #ifndef USE_TOOLKIT_SCROLL_BARS
9464 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9465 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9466 GC gc
= f
->output_data
.x
->normal_gc
;
9467 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
9471 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
9473 /* Draw a one-pixel border just inside the edges of the scroll bar. */
9474 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
9476 /* x, y, width, height */
9478 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
9479 XINT (bar
->height
) - 1);
9483 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9486 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
9487 is set to something other than no_event, it is enqueued.
9489 This may be called from a signal handler, so we have to ignore GC
9492 #ifndef USE_TOOLKIT_SCROLL_BARS
9495 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
9496 struct scroll_bar
*bar
;
9498 struct input_event
*emacs_event
;
9500 if (! GC_WINDOWP (bar
->window
))
9503 emacs_event
->kind
= scroll_bar_click
;
9504 emacs_event
->code
= event
->xbutton
.button
- Button1
;
9505 emacs_event
->modifiers
9506 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
9507 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
9508 event
->xbutton
.state
)
9509 | (event
->type
== ButtonRelease
9512 emacs_event
->frame_or_window
= bar
->window
;
9513 emacs_event
->arg
= Qnil
;
9514 emacs_event
->timestamp
= event
->xbutton
.time
;
9517 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9519 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9522 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9523 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
9526 if (y
> top_range
) y
= top_range
;
9528 if (y
< XINT (bar
->start
))
9529 emacs_event
->part
= scroll_bar_above_handle
;
9530 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
9531 emacs_event
->part
= scroll_bar_handle
;
9533 emacs_event
->part
= scroll_bar_below_handle
;
9535 /* Just because the user has clicked on the handle doesn't mean
9536 they want to drag it. Lisp code needs to be able to decide
9537 whether or not we're dragging. */
9539 /* If the user has just clicked on the handle, record where they're
9541 if (event
->type
== ButtonPress
9542 && emacs_event
->part
== scroll_bar_handle
)
9543 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
9546 /* If the user has released the handle, set it to its final position. */
9547 if (event
->type
== ButtonRelease
9548 && ! NILP (bar
->dragging
))
9550 int new_start
= y
- XINT (bar
->dragging
);
9551 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
9553 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
9554 bar
->dragging
= Qnil
;
9557 /* Same deal here as the other #if 0. */
9559 /* Clicks on the handle are always reported as occurring at the top of
9561 if (emacs_event
->part
== scroll_bar_handle
)
9562 emacs_event
->x
= bar
->start
;
9564 XSETINT (emacs_event
->x
, y
);
9566 XSETINT (emacs_event
->x
, y
);
9569 XSETINT (emacs_event
->y
, top_range
);
9573 /* Handle some mouse motion while someone is dragging the scroll bar.
9575 This may be called from a signal handler, so we have to ignore GC
9579 x_scroll_bar_note_movement (bar
, event
)
9580 struct scroll_bar
*bar
;
9583 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
9585 last_mouse_movement_time
= event
->xmotion
.time
;
9588 XSETVECTOR (last_mouse_scroll_bar
, bar
);
9590 /* If we're dragging the bar, display it. */
9591 if (! GC_NILP (bar
->dragging
))
9593 /* Where should the handle be now? */
9594 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
9596 if (new_start
!= XINT (bar
->start
))
9598 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
9600 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
9605 #endif /* !USE_TOOLKIT_SCROLL_BARS */
9607 /* Return information to the user about the current position of the mouse
9608 on the scroll bar. */
9611 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
9613 Lisp_Object
*bar_window
;
9614 enum scroll_bar_part
*part
;
9616 unsigned long *time
;
9618 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
9619 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9620 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9622 Window dummy_window
;
9624 unsigned int dummy_mask
;
9628 /* Get the mouse's position relative to the scroll bar window, and
9630 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
9632 /* Root, child, root x and root y. */
9633 &dummy_window
, &dummy_window
,
9634 &dummy_coord
, &dummy_coord
,
9636 /* Position relative to scroll bar. */
9639 /* Mouse buttons and modifier keys. */
9646 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9649 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9651 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
9653 if (! NILP (bar
->dragging
))
9654 win_y
-= XINT (bar
->dragging
);
9658 if (win_y
> top_range
)
9662 *bar_window
= bar
->window
;
9664 if (! NILP (bar
->dragging
))
9665 *part
= scroll_bar_handle
;
9666 else if (win_y
< XINT (bar
->start
))
9667 *part
= scroll_bar_above_handle
;
9668 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
9669 *part
= scroll_bar_handle
;
9671 *part
= scroll_bar_below_handle
;
9673 XSETINT (*x
, win_y
);
9674 XSETINT (*y
, top_range
);
9677 last_mouse_scroll_bar
= Qnil
;
9680 *time
= last_mouse_movement_time
;
9686 /* The screen has been cleared so we may have changed foreground or
9687 background colors, and the scroll bars may need to be redrawn.
9688 Clear out the scroll bars, and ask for expose events, so we can
9692 x_scroll_bar_clear (f
)
9695 #ifndef USE_TOOLKIT_SCROLL_BARS
9698 /* We can have scroll bars even if this is 0,
9699 if we just turned off scroll bar mode.
9700 But in that case we should not clear them. */
9701 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9702 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
9703 bar
= XSCROLL_BAR (bar
)->next
)
9704 XClearArea (FRAME_X_DISPLAY (f
),
9705 SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
9707 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9710 /* This processes Expose events from the menu-bar specific X event
9711 loop in xmenu.c. This allows to redisplay the frame if necessary
9712 when handling menu-bar or pop-up items. */
9715 process_expose_from_menu (event
)
9719 struct x_display_info
*dpyinfo
;
9720 int frame_exposed_p
= 0;
9724 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
9725 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
9728 if (f
->async_visible
== 0)
9730 f
->async_visible
= 1;
9731 f
->async_iconified
= 0;
9732 f
->output_data
.x
->has_been_visible
= 1;
9733 SET_FRAME_GARBAGED (f
);
9737 expose_frame (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
9738 event
.xexpose
.x
, event
.xexpose
.y
,
9739 event
.xexpose
.width
, event
.xexpose
.height
);
9740 frame_exposed_p
= 1;
9745 struct scroll_bar
*bar
9746 = x_window_to_scroll_bar (event
.xexpose
.window
);
9749 x_scroll_bar_expose (bar
, &event
);
9753 return frame_exposed_p
;
9756 /* Define a queue to save up SelectionRequest events for later handling. */
9758 struct selection_event_queue
9761 struct selection_event_queue
*next
;
9764 static struct selection_event_queue
*queue
;
9766 /* Nonzero means queue up certain events--don't process them yet. */
9768 static int x_queue_selection_requests
;
9770 /* Queue up an X event *EVENT, to be processed later. */
9773 x_queue_event (f
, event
)
9777 struct selection_event_queue
*queue_tmp
9778 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
9780 if (queue_tmp
!= NULL
)
9782 queue_tmp
->event
= *event
;
9783 queue_tmp
->next
= queue
;
9788 /* Take all the queued events and put them back
9789 so that they get processed afresh. */
9792 x_unqueue_events (display
)
9795 while (queue
!= NULL
)
9797 struct selection_event_queue
*queue_tmp
= queue
;
9798 XPutBackEvent (display
, &queue_tmp
->event
);
9799 queue
= queue_tmp
->next
;
9800 xfree ((char *)queue_tmp
);
9804 /* Start queuing SelectionRequest events. */
9807 x_start_queuing_selection_requests (display
)
9810 x_queue_selection_requests
++;
9813 /* Stop queuing SelectionRequest events. */
9816 x_stop_queuing_selection_requests (display
)
9819 x_queue_selection_requests
--;
9820 x_unqueue_events (display
);
9823 /* The main X event-reading loop - XTread_socket. */
9825 /* Time stamp of enter window event. This is only used by XTread_socket,
9826 but we have to put it out here, since static variables within functions
9827 sometimes don't work. */
9829 static Time enter_timestamp
;
9831 /* This holds the state XLookupString needs to implement dead keys
9832 and other tricks known as "compose processing". _X Window System_
9833 says that a portable program can't use this, but Stephen Gildea assures
9834 me that letting the compiler initialize it to zeros will work okay.
9836 This must be defined outside of XTread_socket, for the same reasons
9837 given for enter_timestamp, above. */
9839 static XComposeStatus compose_status
;
9841 /* Record the last 100 characters stored
9842 to help debug the loss-of-chars-during-GC problem. */
9844 static int temp_index
;
9845 static short temp_buffer
[100];
9847 /* Set this to nonzero to fake an "X I/O error"
9848 on a particular display. */
9850 struct x_display_info
*XTread_socket_fake_io_error
;
9852 /* When we find no input here, we occasionally do a no-op command
9853 to verify that the X server is still running and we can still talk with it.
9854 We try all the open displays, one by one.
9855 This variable is used for cycling thru the displays. */
9857 static struct x_display_info
*next_noop_dpyinfo
;
9859 #define SET_SAVED_MENU_EVENT(size) \
9862 if (f->output_data.x->saved_menu_event == 0) \
9863 f->output_data.x->saved_menu_event \
9864 = (XEvent *) xmalloc (sizeof (XEvent)); \
9865 bcopy (&event, f->output_data.x->saved_menu_event, size); \
9866 if (numchars >= 1) \
9868 bufp->kind = menu_bar_activate_event; \
9869 XSETFRAME (bufp->frame_or_window, f); \
9878 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
9879 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
9881 /* Read events coming from the X server.
9882 This routine is called by the SIGIO handler.
9883 We return as soon as there are no more events to be read.
9885 Events representing keys are stored in buffer BUFP,
9886 which can hold up to NUMCHARS characters.
9887 We return the number of characters stored into the buffer,
9888 thus pretending to be `read'.
9890 EXPECTED is nonzero if the caller knows input is available. */
9893 XTread_socket (sd
, bufp
, numchars
, expected
)
9895 /* register */ struct input_event
*bufp
;
9896 /* register */ int numchars
;
9903 int event_found
= 0;
9904 struct x_display_info
*dpyinfo
;
9905 struct coding_system coding
;
9907 if (interrupt_input_blocked
)
9909 interrupt_input_pending
= 1;
9913 interrupt_input_pending
= 0;
9916 /* So people can tell when we have read the available input. */
9917 input_signal_count
++;
9920 abort (); /* Don't think this happens. */
9924 /* The input should be decoded if it is from XIM. Currently the
9925 locale of XIM is the same as that of the system. So, we can use
9926 Vlocale_coding_system which is initialized properly at Emacs
9928 setup_coding_system (Vlocale_coding_system
, &coding
);
9929 coding
.src_multibyte
= 0;
9930 coding
.dst_multibyte
= 1;
9931 /* The input is converted to events, thus we can't handle
9932 composition. Anyway, there's no XIM that gives us composition
9934 coding
.composing
= COMPOSITION_DISABLED
;
9936 /* Find the display we are supposed to read input for.
9937 It's the one communicating on descriptor SD. */
9938 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
9940 #if 0 /* This ought to be unnecessary; let's verify it. */
9942 /* If available, Xlib uses FIOSNBIO to make the socket
9943 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
9944 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
9945 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
9946 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
9947 #endif /* ! defined (FIOSNBIO) */
9950 #if 0 /* This code can't be made to work, with multiple displays,
9951 and appears not to be used on any system any more.
9952 Also keyboard.c doesn't turn O_NDELAY on and off
9953 for X connections. */
9956 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
9958 extern int read_alarm_should_throw
;
9959 read_alarm_should_throw
= 1;
9960 XPeekEvent (dpyinfo
->display
, &event
);
9961 read_alarm_should_throw
= 0;
9963 #endif /* HAVE_SELECT */
9967 /* For debugging, this gives a way to fake an I/O error. */
9968 if (dpyinfo
== XTread_socket_fake_io_error
)
9970 XTread_socket_fake_io_error
= 0;
9971 x_io_error_quitter (dpyinfo
->display
);
9974 while (XPending (dpyinfo
->display
))
9976 XNextEvent (dpyinfo
->display
, &event
);
9980 /* Filter events for the current X input method.
9981 XFilterEvent returns non-zero if the input method has
9982 consumed the event. We pass the frame's X window to
9983 XFilterEvent because that's the one for which the IC
9985 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
9986 event
.xclient
.window
);
9987 if (XFilterEvent (&event
, f1
? FRAME_X_WINDOW (f1
) : None
))
9997 if (event
.xclient
.message_type
9998 == dpyinfo
->Xatom_wm_protocols
9999 && event
.xclient
.format
== 32)
10001 if (event
.xclient
.data
.l
[0]
10002 == dpyinfo
->Xatom_wm_take_focus
)
10004 /* Use x_any_window_to_frame because this
10005 could be the shell widget window
10006 if the frame has no title bar. */
10007 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
10009 /* Not quite sure this is needed -pd */
10010 if (f
&& FRAME_XIC (f
))
10011 XSetICFocus (FRAME_XIC (f
));
10013 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
10014 instructs the WM to set the input focus automatically for
10015 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
10016 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
10017 it has set the focus. So, XSetInputFocus below is not
10020 The call to XSetInputFocus below has also caused trouble. In
10021 cases where the XSetInputFocus done by the WM and the one
10022 below are temporally close (on a fast machine), the call
10023 below can generate additional FocusIn events which confuse
10026 /* Since we set WM_TAKE_FOCUS, we must call
10027 XSetInputFocus explicitly. But not if f is null,
10028 since that might be an event for a deleted frame. */
10031 Display
*d
= event
.xclient
.display
;
10032 /* Catch and ignore errors, in case window has been
10033 iconified by a window manager such as GWM. */
10034 int count
= x_catch_errors (d
);
10035 XSetInputFocus (d
, event
.xclient
.window
,
10036 /* The ICCCM says this is
10037 the only valid choice. */
10039 event
.xclient
.data
.l
[1]);
10040 /* This is needed to detect the error
10041 if there is an error. */
10043 x_uncatch_errors (d
, count
);
10045 /* Not certain about handling scroll bars here */
10048 else if (event
.xclient
.data
.l
[0]
10049 == dpyinfo
->Xatom_wm_save_yourself
)
10051 /* Save state modify the WM_COMMAND property to
10052 something which can reinstate us. This notifies
10053 the session manager, who's looking for such a
10054 PropertyNotify. Can restart processing when
10055 a keyboard or mouse event arrives. */
10058 f
= x_top_window_to_frame (dpyinfo
,
10059 event
.xclient
.window
);
10061 /* This is just so we only give real data once
10062 for a single Emacs process. */
10063 if (f
== SELECTED_FRAME ())
10064 XSetCommand (FRAME_X_DISPLAY (f
),
10065 event
.xclient
.window
,
10066 initial_argv
, initial_argc
);
10068 XSetCommand (FRAME_X_DISPLAY (f
),
10069 event
.xclient
.window
,
10073 else if (event
.xclient
.data
.l
[0]
10074 == dpyinfo
->Xatom_wm_delete_window
)
10077 = x_any_window_to_frame (dpyinfo
,
10078 event
.xclient
.window
);
10085 bufp
->kind
= delete_window_event
;
10086 XSETFRAME (bufp
->frame_or_window
, f
);
10095 else if (event
.xclient
.message_type
10096 == dpyinfo
->Xatom_wm_configure_denied
)
10099 else if (event
.xclient
.message_type
10100 == dpyinfo
->Xatom_wm_window_moved
)
10104 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
10106 new_x
= event
.xclient
.data
.s
[0];
10107 new_y
= event
.xclient
.data
.s
[1];
10111 f
->output_data
.x
->left_pos
= new_x
;
10112 f
->output_data
.x
->top_pos
= new_y
;
10115 #ifdef HACK_EDITRES
10116 else if (event
.xclient
.message_type
10117 == dpyinfo
->Xatom_editres
)
10120 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
10121 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
10124 #endif /* HACK_EDITRES */
10125 else if ((event
.xclient
.message_type
10126 == dpyinfo
->Xatom_DONE
)
10127 || (event
.xclient
.message_type
10128 == dpyinfo
->Xatom_PAGE
))
10130 /* Ghostview job completed. Kill it. We could
10131 reply with "Next" if we received "Page", but we
10132 currently never do because we are interested in
10133 images, only, which should have 1 page. */
10134 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
10136 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
10137 x_kill_gs_process (pixmap
, f
);
10138 expose_frame (f
, 0, 0, 0, 0);
10140 #ifdef USE_TOOLKIT_SCROLL_BARS
10141 /* Scroll bar callbacks send a ClientMessage from which
10142 we construct an input_event. */
10143 else if (event
.xclient
.message_type
10144 == dpyinfo
->Xatom_Scrollbar
)
10146 x_scroll_bar_to_input_event (&event
, bufp
);
10147 ++bufp
, ++count
, --numchars
;
10150 #endif /* USE_TOOLKIT_SCROLL_BARS */
10156 case SelectionNotify
:
10157 #ifdef USE_X_TOOLKIT
10158 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
10160 #endif /* not USE_X_TOOLKIT */
10161 x_handle_selection_notify (&event
.xselection
);
10164 case SelectionClear
: /* Someone has grabbed ownership. */
10165 #ifdef USE_X_TOOLKIT
10166 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
10168 #endif /* USE_X_TOOLKIT */
10170 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
10175 bufp
->kind
= selection_clear_event
;
10176 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
10177 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
10178 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
10179 bufp
->frame_or_window
= Qnil
;
10188 case SelectionRequest
: /* Someone wants our selection. */
10189 #ifdef USE_X_TOOLKIT
10190 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
10192 #endif /* USE_X_TOOLKIT */
10193 if (x_queue_selection_requests
)
10194 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
10198 XSelectionRequestEvent
*eventp
10199 = (XSelectionRequestEvent
*) &event
;
10204 bufp
->kind
= selection_request_event
;
10205 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
10206 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
10207 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
10208 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
10209 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
10210 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
10211 bufp
->frame_or_window
= Qnil
;
10220 case PropertyNotify
:
10221 #if 0 /* This is plain wrong. In the case that we are waiting for a
10222 PropertyNotify used as an ACK in incremental selection
10223 transfer, the property will be on the receiver's window. */
10224 #if defined USE_X_TOOLKIT
10225 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
10229 x_handle_property_notify (&event
.xproperty
);
10232 case ReparentNotify
:
10233 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
10237 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
10238 x_real_positions (f
, &x
, &y
);
10239 f
->output_data
.x
->left_pos
= x
;
10240 f
->output_data
.x
->top_pos
= y
;
10245 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
10248 x_check_fullscreen (f
);
10250 if (f
->async_visible
== 0)
10252 f
->async_visible
= 1;
10253 f
->async_iconified
= 0;
10254 f
->output_data
.x
->has_been_visible
= 1;
10255 SET_FRAME_GARBAGED (f
);
10258 expose_frame (x_window_to_frame (dpyinfo
,
10259 event
.xexpose
.window
),
10260 event
.xexpose
.x
, event
.xexpose
.y
,
10261 event
.xexpose
.width
, event
.xexpose
.height
);
10265 #ifndef USE_TOOLKIT_SCROLL_BARS
10266 struct scroll_bar
*bar
;
10268 #if defined USE_LUCID
10269 /* Submenus of the Lucid menu bar aren't widgets
10270 themselves, so there's no way to dispatch events
10271 to them. Recognize this case separately. */
10274 = x_window_to_menu_bar (event
.xexpose
.window
);
10276 xlwmenu_redisplay (widget
);
10278 #endif /* USE_LUCID */
10280 #ifdef USE_TOOLKIT_SCROLL_BARS
10281 /* Dispatch event to the widget. */
10283 #else /* not USE_TOOLKIT_SCROLL_BARS */
10284 bar
= x_window_to_scroll_bar (event
.xexpose
.window
);
10287 x_scroll_bar_expose (bar
, &event
);
10288 #ifdef USE_X_TOOLKIT
10291 #endif /* USE_X_TOOLKIT */
10292 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10296 case GraphicsExpose
: /* This occurs when an XCopyArea's
10297 source area was obscured or not
10299 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
10303 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
10304 event
.xgraphicsexpose
.width
,
10305 event
.xgraphicsexpose
.height
);
10307 #ifdef USE_X_TOOLKIT
10310 #endif /* USE_X_TOOLKIT */
10313 case NoExpose
: /* This occurs when an XCopyArea's
10314 source area was completely
10319 /* Redo the mouse-highlight after the tooltip has gone. */
10320 if (event
.xmap
.window
== tip_window
)
10323 redo_mouse_highlight ();
10326 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
10327 if (f
) /* F may no longer exist if
10328 the frame was deleted. */
10330 /* While a frame is unmapped, display generation is
10331 disabled; you don't want to spend time updating a
10332 display that won't ever be seen. */
10333 f
->async_visible
= 0;
10334 /* We can't distinguish, from the event, whether the window
10335 has become iconified or invisible. So assume, if it
10336 was previously visible, than now it is iconified.
10337 But x_make_frame_invisible clears both
10338 the visible flag and the iconified flag;
10339 and that way, we know the window is not iconified now. */
10340 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
10342 f
->async_iconified
= 1;
10344 bufp
->kind
= iconify_event
;
10345 XSETFRAME (bufp
->frame_or_window
, f
);
10355 if (event
.xmap
.window
== tip_window
)
10356 /* The tooltip has been drawn already. Avoid
10357 the SET_FRAME_GARBAGED below. */
10360 /* We use x_top_window_to_frame because map events can
10361 come for sub-windows and they don't mean that the
10362 frame is visible. */
10363 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
10366 f
->async_visible
= 1;
10367 f
->async_iconified
= 0;
10368 f
->output_data
.x
->has_been_visible
= 1;
10370 /* wait_reading_process_input will notice this and update
10371 the frame's display structures. */
10372 SET_FRAME_GARBAGED (f
);
10376 bufp
->kind
= deiconify_event
;
10377 XSETFRAME (bufp
->frame_or_window
, f
);
10383 else if (! NILP (Vframe_list
)
10384 && ! NILP (XCDR (Vframe_list
)))
10385 /* Force a redisplay sooner or later
10386 to update the frame titles
10387 in case this is the second frame. */
10388 record_asynch_buffer_change ();
10393 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
10395 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
10398 /* Scroll bars consume key events, but we want
10399 the keys to go to the scroll bar's frame. */
10400 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
10401 event
.xkey
.window
);
10402 if (widget
&& XmIsScrollBar (widget
))
10404 widget
= XtParent (widget
);
10405 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
10408 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
10412 KeySym keysym
, orig_keysym
;
10413 /* al%imercury@uunet.uu.net says that making this 81
10414 instead of 80 fixed a bug whereby meta chars made
10417 It seems that some version of XmbLookupString has
10418 a bug of not returning XBufferOverflow in
10419 status_return even if the input is too long to
10420 fit in 81 bytes. So, we must prepare sufficient
10421 bytes for copy_buffer. 513 bytes (256 chars for
10422 two-byte character set) seems to be a fairly good
10423 approximation. -- 2000.8.10 handa@etl.go.jp */
10424 unsigned char copy_buffer
[513];
10425 unsigned char *copy_bufptr
= copy_buffer
;
10426 int copy_bufsiz
= sizeof (copy_buffer
);
10430 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
10431 extra_keyboard_modifiers
);
10432 modifiers
= event
.xkey
.state
;
10434 /* This will have to go some day... */
10436 /* make_lispy_event turns chars into control chars.
10437 Don't do it here because XLookupString is too eager. */
10438 event
.xkey
.state
&= ~ControlMask
;
10439 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
10440 | dpyinfo
->super_mod_mask
10441 | dpyinfo
->hyper_mod_mask
10442 | dpyinfo
->alt_mod_mask
);
10444 /* In case Meta is ComposeCharacter,
10445 clear its status. According to Markus Ehrnsperger
10446 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
10447 this enables ComposeCharacter to work whether or
10448 not it is combined with Meta. */
10449 if (modifiers
& dpyinfo
->meta_mod_mask
)
10450 bzero (&compose_status
, sizeof (compose_status
));
10455 Status status_return
;
10457 nbytes
= XmbLookupString (FRAME_XIC (f
),
10458 &event
.xkey
, copy_bufptr
,
10459 copy_bufsiz
, &keysym
,
10461 if (status_return
== XBufferOverflow
)
10463 copy_bufsiz
= nbytes
+ 1;
10464 copy_bufptr
= (char *) alloca (copy_bufsiz
);
10465 nbytes
= XmbLookupString (FRAME_XIC (f
),
10466 &event
.xkey
, copy_bufptr
,
10467 copy_bufsiz
, &keysym
,
10471 if (status_return
== XLookupNone
)
10473 else if (status_return
== XLookupChars
)
10478 else if (status_return
!= XLookupKeySym
10479 && status_return
!= XLookupBoth
)
10483 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
10484 copy_bufsiz
, &keysym
,
10487 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
10488 copy_bufsiz
, &keysym
,
10492 orig_keysym
= keysym
;
10496 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
10497 || keysym
== XK_Delete
10498 #ifdef XK_ISO_Left_Tab
10499 || (keysym
>= XK_ISO_Left_Tab
&& keysym
<= XK_ISO_Enter
)
10501 || (keysym
>= XK_Kanji
&& keysym
<= XK_Eisu_toggle
)
10502 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
10503 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
10505 /* This recognizes the "extended function keys".
10506 It seems there's no cleaner way.
10507 Test IsModifierKey to avoid handling mode_switch
10509 || ((unsigned) (keysym
) >= XK_Select
10510 && (unsigned)(keysym
) < XK_KP_Space
)
10512 #ifdef XK_dead_circumflex
10513 || orig_keysym
== XK_dead_circumflex
10515 #ifdef XK_dead_grave
10516 || orig_keysym
== XK_dead_grave
10518 #ifdef XK_dead_tilde
10519 || orig_keysym
== XK_dead_tilde
10521 #ifdef XK_dead_diaeresis
10522 || orig_keysym
== XK_dead_diaeresis
10524 #ifdef XK_dead_macron
10525 || orig_keysym
== XK_dead_macron
10527 #ifdef XK_dead_degree
10528 || orig_keysym
== XK_dead_degree
10530 #ifdef XK_dead_acute
10531 || orig_keysym
== XK_dead_acute
10533 #ifdef XK_dead_cedilla
10534 || orig_keysym
== XK_dead_cedilla
10536 #ifdef XK_dead_breve
10537 || orig_keysym
== XK_dead_breve
10539 #ifdef XK_dead_ogonek
10540 || orig_keysym
== XK_dead_ogonek
10542 #ifdef XK_dead_caron
10543 || orig_keysym
== XK_dead_caron
10545 #ifdef XK_dead_doubleacute
10546 || orig_keysym
== XK_dead_doubleacute
10548 #ifdef XK_dead_abovedot
10549 || orig_keysym
== XK_dead_abovedot
10551 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
10552 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
10553 /* Any "vendor-specific" key is ok. */
10554 || (orig_keysym
& (1 << 28))
10555 || (keysym
!= NoSymbol
&& nbytes
== 0))
10556 && ! (IsModifierKey (orig_keysym
)
10558 #ifdef XK_Mode_switch
10559 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
10562 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
10564 #endif /* not HAVE_X11R5 */
10567 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
10569 temp_buffer
[temp_index
++] = keysym
;
10570 bufp
->kind
= non_ascii_keystroke
;
10571 bufp
->code
= keysym
;
10572 XSETFRAME (bufp
->frame_or_window
, f
);
10575 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10577 bufp
->timestamp
= event
.xkey
.time
;
10582 else if (numchars
> nbytes
)
10588 for (i
= 0; i
< nbytes
; i
++)
10590 if (temp_index
== (sizeof temp_buffer
10593 temp_buffer
[temp_index
++] = copy_bufptr
[i
];
10596 if (/* If the event is not from XIM, */
10597 event
.xkey
.keycode
!= 0
10598 /* or the current locale doesn't request
10599 decoding of the intup data, ... */
10600 || coding
.type
== coding_type_raw_text
10601 || coding
.type
== coding_type_no_conversion
)
10603 /* ... we can use the input data as is. */
10608 /* We have to decode the input data. */
10612 require
= decoding_buffer_size (&coding
, nbytes
);
10613 p
= (unsigned char *) alloca (require
);
10614 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
10615 decode_coding (&coding
, copy_bufptr
, p
,
10617 nbytes
= coding
.produced
;
10618 nchars
= coding
.produced_char
;
10622 /* Convert the input data to a sequence of
10623 character events. */
10624 for (i
= 0; i
< nbytes
; i
+= len
)
10626 if (nchars
== nbytes
)
10627 c
= copy_bufptr
[i
], len
= 1;
10629 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
10632 bufp
->kind
= (SINGLE_BYTE_CHAR_P (c
)
10634 : multibyte_char_keystroke
);
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 numchars
-= nchars
;
10648 if (keysym
== NoSymbol
)
10658 /* Don't dispatch this event since XtDispatchEvent calls
10659 XFilterEvent, and two calls in a row may freeze the
10668 /* Don't dispatch this event since XtDispatchEvent calls
10669 XFilterEvent, and two calls in a row may freeze the
10676 /* Here's a possible interpretation of the whole
10677 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If
10678 you get a FocusIn event, you have to get a FocusOut
10679 event before you relinquish the focus. If you
10680 haven't received a FocusIn event, then a mere
10681 LeaveNotify is enough to free you. */
10685 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10688 if (event
.xcrossing
.focus
)
10690 /* Avoid nasty pop/raise loops. */
10691 if (f
&& (!(f
->auto_raise
)
10692 || !(f
->auto_lower
)
10693 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
10695 x_new_focus_frame (dpyinfo
, f
);
10696 enter_timestamp
= event
.xcrossing
.time
;
10699 else if (f
== dpyinfo
->x_focus_frame
)
10700 x_new_focus_frame (dpyinfo
, 0);
10703 /* EnterNotify counts as mouse movement,
10704 so update things that depend on mouse position. */
10705 if (f
&& !f
->output_data
.x
->hourglass_p
)
10706 note_mouse_movement (f
, &event
.xmotion
);
10711 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
10712 if (event
.xfocus
.detail
!= NotifyPointer
)
10713 dpyinfo
->x_focus_event_frame
= f
;
10716 x_new_focus_frame (dpyinfo
, f
);
10718 /* Don't stop displaying the initial startup message
10719 for a switch-frame event we don't need. */
10720 if (GC_NILP (Vterminal_frame
)
10721 && GC_CONSP (Vframe_list
)
10722 && !GC_NILP (XCDR (Vframe_list
)))
10724 bufp
->kind
= FOCUS_IN_EVENT
;
10725 XSETFRAME (bufp
->frame_or_window
, f
);
10727 ++bufp
, ++count
, --numchars
;
10732 if (f
&& FRAME_XIC (f
))
10733 XSetICFocus (FRAME_XIC (f
));
10739 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10742 if (f
== dpyinfo
->mouse_face_mouse_frame
)
10744 /* If we move outside the frame, then we're
10745 certainly no longer on any text in the frame. */
10746 clear_mouse_face (dpyinfo
);
10747 dpyinfo
->mouse_face_mouse_frame
= 0;
10750 /* Generate a nil HELP_EVENT to cancel a help-echo.
10751 Do it only if there's something to cancel.
10752 Otherwise, the startup message is cleared when
10753 the mouse leaves the frame. */
10754 if (any_help_event_p
)
10759 XSETFRAME (frame
, f
);
10761 n
= gen_help_event (bufp
, numchars
,
10762 Qnil
, frame
, Qnil
, Qnil
, 0);
10763 bufp
+= n
, count
+= n
, numchars
-= n
;
10767 if (event
.xcrossing
.focus
)
10768 x_mouse_leave (dpyinfo
);
10771 if (f
== dpyinfo
->x_focus_event_frame
)
10772 dpyinfo
->x_focus_event_frame
= 0;
10773 if (f
== dpyinfo
->x_focus_frame
)
10774 x_new_focus_frame (dpyinfo
, 0);
10781 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
10782 if (event
.xfocus
.detail
!= NotifyPointer
10783 && f
== dpyinfo
->x_focus_event_frame
)
10784 dpyinfo
->x_focus_event_frame
= 0;
10785 if (f
&& f
== dpyinfo
->x_focus_frame
)
10786 x_new_focus_frame (dpyinfo
, 0);
10789 if (f
&& FRAME_XIC (f
))
10790 XUnsetICFocus (FRAME_XIC (f
));
10797 previous_help_echo
= help_echo
;
10798 help_echo
= help_echo_object
= help_echo_window
= Qnil
;
10799 help_echo_pos
= -1;
10801 if (dpyinfo
->grabbed
&& last_mouse_frame
10802 && FRAME_LIVE_P (last_mouse_frame
))
10803 f
= last_mouse_frame
;
10805 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
10808 note_mouse_movement (f
, &event
.xmotion
);
10811 #ifndef USE_TOOLKIT_SCROLL_BARS
10812 struct scroll_bar
*bar
10813 = x_window_to_scroll_bar (event
.xmotion
.window
);
10816 x_scroll_bar_note_movement (bar
, &event
);
10817 #endif /* USE_TOOLKIT_SCROLL_BARS */
10819 /* If we move outside the frame, then we're
10820 certainly no longer on any text in the frame. */
10821 clear_mouse_face (dpyinfo
);
10824 /* If the contents of the global variable help_echo
10825 has changed, generate a HELP_EVENT. */
10826 if (!NILP (help_echo
)
10827 || !NILP (previous_help_echo
))
10833 XSETFRAME (frame
, f
);
10837 any_help_event_p
= 1;
10838 n
= gen_help_event (bufp
, numchars
, help_echo
, frame
,
10839 help_echo_window
, help_echo_object
,
10841 bufp
+= n
, count
+= n
, numchars
-= n
;
10847 case ConfigureNotify
:
10848 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
10851 #ifndef USE_X_TOOLKIT
10852 /* If there is a pending resize for fullscreen, don't
10853 do this one, the right one will come later.
10854 The toolkit version doesn't seem to need this, but we
10855 need to reset it below. */
10857 ((f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WAIT
)
10858 && FRAME_NEW_WIDTH (f
) != 0);
10859 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
10860 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
10864 /* In the toolkit version, change_frame_size
10865 is called by the code that handles resizing
10866 of the EmacsFrame widget. */
10868 /* Even if the number of character rows and columns has
10869 not changed, the font size may have changed, so we need
10870 to check the pixel dimensions as well. */
10871 if (columns
!= f
->width
10872 || rows
!= f
->height
10873 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
10874 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
10876 change_frame_size (f
, rows
, columns
, 0, 1, 0);
10877 SET_FRAME_GARBAGED (f
);
10878 cancel_mouse_face (f
);
10882 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
10883 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
10885 /* What we have now is the position of Emacs's own window.
10886 Convert that to the position of the window manager window. */
10887 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
10888 &f
->output_data
.x
->top_pos
);
10890 x_check_fullscreen_move(f
);
10891 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WAIT
)
10892 f
->output_data
.x
->want_fullscreen
&=
10893 ~(FULLSCREEN_WAIT
|FULLSCREEN_BOTH
);
10895 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
10896 xic_set_statusarea (f
);
10899 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
10901 /* Since the WM decorations come below top_pos now,
10902 we must put them below top_pos in the future. */
10903 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
10904 x_wm_set_size_hint (f
, (long) 0, 0);
10907 /* Some window managers pass (0,0) as the location of
10908 the window, and the Motif event handler stores it
10909 in the emacs widget, which messes up Motif menus. */
10910 if (event
.xconfigure
.x
== 0 && event
.xconfigure
.y
== 0)
10912 event
.xconfigure
.x
= f
->output_data
.x
->widget
->core
.x
;
10913 event
.xconfigure
.y
= f
->output_data
.x
->widget
->core
.y
;
10915 #endif /* USE_MOTIF */
10920 case ButtonRelease
:
10922 /* If we decide we want to generate an event to be seen
10923 by the rest of Emacs, we put it here. */
10924 struct input_event emacs_event
;
10925 int tool_bar_p
= 0;
10927 emacs_event
.kind
= no_event
;
10928 bzero (&compose_status
, sizeof (compose_status
));
10930 if (dpyinfo
->grabbed
10931 && last_mouse_frame
10932 && FRAME_LIVE_P (last_mouse_frame
))
10933 f
= last_mouse_frame
;
10935 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
10939 /* Is this in the tool-bar? */
10940 if (WINDOWP (f
->tool_bar_window
)
10941 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
10943 Lisp_Object window
;
10946 x
= event
.xbutton
.x
;
10947 y
= event
.xbutton
.y
;
10950 window
= window_from_coordinates (f
, x
, y
, &p
, 1);
10951 if (EQ (window
, f
->tool_bar_window
))
10953 x_handle_tool_bar_click (f
, &event
.xbutton
);
10959 if (!dpyinfo
->x_focus_frame
10960 || f
== dpyinfo
->x_focus_frame
)
10961 construct_mouse_click (&emacs_event
, &event
, f
);
10965 #ifndef USE_TOOLKIT_SCROLL_BARS
10966 struct scroll_bar
*bar
10967 = x_window_to_scroll_bar (event
.xbutton
.window
);
10970 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
10971 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10974 if (event
.type
== ButtonPress
)
10976 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
10977 last_mouse_frame
= f
;
10978 /* Ignore any mouse motion that happened
10979 before this event; any subsequent mouse-movement
10980 Emacs events should reflect only motion after
10981 the ButtonPress. */
10983 f
->mouse_moved
= 0;
10986 last_tool_bar_item
= -1;
10990 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
10993 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
10995 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
11001 #ifdef USE_X_TOOLKIT
11002 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
11003 /* For a down-event in the menu bar,
11004 don't pass it to Xt right now.
11005 Instead, save it away
11006 and we will pass it to Xt from kbd_buffer_get_event.
11007 That way, we can run some Lisp code first. */
11008 if (f
&& event
.type
== ButtonPress
11009 /* Verify the event is really within the menu bar
11010 and not just sent to it due to grabbing. */
11011 && event
.xbutton
.x
>= 0
11012 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
11013 && event
.xbutton
.y
>= 0
11014 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
11015 && event
.xbutton
.same_screen
)
11017 SET_SAVED_BUTTON_EVENT
;
11018 XSETFRAME (last_mouse_press_frame
, f
);
11020 else if (event
.type
== ButtonPress
)
11022 last_mouse_press_frame
= Qnil
;
11026 #ifdef USE_MOTIF /* This should do not harm for Lucid,
11027 but I am trying to be cautious. */
11028 else if (event
.type
== ButtonRelease
)
11030 if (!NILP (last_mouse_press_frame
))
11032 f
= XFRAME (last_mouse_press_frame
);
11033 if (f
->output_data
.x
)
11034 SET_SAVED_BUTTON_EVENT
;
11039 #endif /* USE_MOTIF */
11042 #endif /* USE_X_TOOLKIT */
11046 case CirculateNotify
:
11049 case CirculateRequest
:
11052 case VisibilityNotify
:
11055 case MappingNotify
:
11056 /* Someone has changed the keyboard mapping - update the
11058 switch (event
.xmapping
.request
)
11060 case MappingModifier
:
11061 x_find_modifier_meanings (dpyinfo
);
11062 /* This is meant to fall through. */
11063 case MappingKeyboard
:
11064 XRefreshKeyboardMapping (&event
.xmapping
);
11070 #ifdef USE_X_TOOLKIT
11072 XtDispatchEvent (&event
);
11074 #endif /* USE_X_TOOLKIT */
11082 /* On some systems, an X bug causes Emacs to get no more events
11083 when the window is destroyed. Detect that. (1994.) */
11086 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
11087 One XNOOP in 100 loops will make Emacs terminate.
11088 B. Bretthauer, 1994 */
11090 if (x_noop_count
>= 100)
11094 if (next_noop_dpyinfo
== 0)
11095 next_noop_dpyinfo
= x_display_list
;
11097 XNoOp (next_noop_dpyinfo
->display
);
11099 /* Each time we get here, cycle through the displays now open. */
11100 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
11104 /* If the focus was just given to an auto-raising frame,
11106 /* ??? This ought to be able to handle more than one such frame. */
11107 if (pending_autoraise_frame
)
11109 x_raise_frame (pending_autoraise_frame
);
11110 pending_autoraise_frame
= 0;
11121 /***********************************************************************
11123 ***********************************************************************/
11125 /* Notice when the text cursor of window W has been completely
11126 overwritten by a drawing operation that outputs glyphs in AREA
11127 starting at X0 and ending at X1 in the line starting at Y0 and
11128 ending at Y1. X coordinates are area-relative. X1 < 0 means all
11129 the rest of the line after X0 has been written. Y coordinates
11130 are window-relative. */
11133 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
11135 enum glyph_row_area area
;
11136 int x0
, y0
, x1
, y1
;
11138 if (area
== TEXT_AREA
11139 && w
->phys_cursor_on_p
11140 && y0
<= w
->phys_cursor
.y
11141 && y1
>= w
->phys_cursor
.y
+ w
->phys_cursor_height
11142 && x0
<= w
->phys_cursor
.x
11143 && (x1
< 0 || x1
> w
->phys_cursor
.x
))
11144 w
->phys_cursor_on_p
= 0;
11148 /* Set clipping for output in glyph row ROW. W is the window in which
11149 we operate. GC is the graphics context to set clipping in.
11150 WHOLE_LINE_P non-zero means include the areas used for truncation
11151 mark display and alike in the clipping rectangle.
11153 ROW may be a text row or, e.g., a mode line. Text rows must be
11154 clipped to the interior of the window dedicated to text display,
11155 mode lines must be clipped to the whole window. */
11158 x_clip_to_row (w
, row
, gc
, whole_line_p
)
11160 struct glyph_row
*row
;
11164 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11165 XRectangle clip_rect
;
11166 int window_x
, window_y
, window_width
, window_height
;
11168 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
11170 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
11171 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
11172 clip_rect
.y
= max (clip_rect
.y
, window_y
);
11173 clip_rect
.width
= window_width
;
11174 clip_rect
.height
= row
->visible_height
;
11176 /* If clipping to the whole line, including trunc marks, extend
11177 the rectangle to the left and increase its width. */
11180 clip_rect
.x
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
11181 clip_rect
.width
+= FRAME_X_FRINGE_WIDTH (f
);
11184 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
11188 /* Draw a hollow box cursor on window W in glyph row ROW. */
11191 x_draw_hollow_cursor (w
, row
)
11193 struct glyph_row
*row
;
11195 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11196 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11197 Display
*dpy
= FRAME_X_DISPLAY (f
);
11200 struct glyph
*cursor_glyph
;
11203 /* Compute frame-relative coordinates from window-relative
11205 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
11206 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
11207 + row
->ascent
- w
->phys_cursor_ascent
);
11208 h
= row
->height
- 1;
11210 /* Get the glyph the cursor is on. If we can't tell because
11211 the current matrix is invalid or such, give up. */
11212 cursor_glyph
= get_phys_cursor_glyph (w
);
11213 if (cursor_glyph
== NULL
)
11216 /* Compute the width of the rectangle to draw. If on a stretch
11217 glyph, and `x-stretch-block-cursor' is nil, don't draw a
11218 rectangle as wide as the glyph, but use a canonical character
11220 wd
= cursor_glyph
->pixel_width
- 1;
11221 if (cursor_glyph
->type
== STRETCH_GLYPH
11222 && !x_stretch_cursor_p
)
11223 wd
= min (CANON_X_UNIT (f
), wd
);
11225 /* The foreground of cursor_gc is typically the same as the normal
11226 background color, which can cause the cursor box to be invisible. */
11227 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
11228 if (dpyinfo
->scratch_cursor_gc
)
11229 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
11231 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
11232 GCForeground
, &xgcv
);
11233 gc
= dpyinfo
->scratch_cursor_gc
;
11235 /* Set clipping, draw the rectangle, and reset clipping again. */
11236 x_clip_to_row (w
, row
, gc
, 0);
11237 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
11238 XSetClipMask (dpy
, gc
, None
);
11242 /* Draw a bar cursor on window W in glyph row ROW.
11244 Implementation note: One would like to draw a bar cursor with an
11245 angle equal to the one given by the font property XA_ITALIC_ANGLE.
11246 Unfortunately, I didn't find a font yet that has this property set.
11250 x_draw_bar_cursor (w
, row
, width
)
11252 struct glyph_row
*row
;
11255 struct frame
*f
= XFRAME (w
->frame
);
11256 struct glyph
*cursor_glyph
;
11258 /* If cursor is out of bounds, don't draw garbage. This can happen
11259 in mini-buffer windows when switching between echo area glyphs
11260 and mini-buffer. */
11261 cursor_glyph
= get_phys_cursor_glyph (w
);
11262 if (cursor_glyph
== NULL
)
11265 /* If on an image, draw like a normal cursor. That's usually better
11266 visible than drawing a bar, esp. if the image is large so that
11267 the bar might not be in the window. */
11268 if (cursor_glyph
->type
== IMAGE_GLYPH
)
11270 struct glyph_row
*row
;
11271 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
11272 x_draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
11276 Display
*dpy
= FRAME_X_DISPLAY (f
);
11277 Window window
= FRAME_X_WINDOW (f
);
11278 GC gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
11279 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
11280 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
11283 /* If the glyph's background equals the color we normally draw
11284 the bar cursor in, the bar cursor in its normal color is
11285 invisible. Use the glyph's foreground color instead in this
11286 case, on the assumption that the glyph's colors are chosen so
11287 that the glyph is legible. */
11288 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
11289 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
11291 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
11292 xgcv
.graphics_exposures
= 0;
11295 XChangeGC (dpy
, gc
, mask
, &xgcv
);
11298 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
11299 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
11303 width
= f
->output_data
.x
->cursor_width
;
11304 width
= min (cursor_glyph
->pixel_width
, width
);
11306 x_clip_to_row (w
, row
, gc
, 0);
11307 XFillRectangle (dpy
, window
, gc
,
11308 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
11309 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
11310 width
, row
->height
);
11311 XSetClipMask (dpy
, gc
, None
);
11316 /* Clear the cursor of window W to background color, and mark the
11317 cursor as not shown. This is used when the text where the cursor
11318 is is about to be rewritten. */
11324 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
11325 x_update_window_cursor (w
, 0);
11329 /* Draw the cursor glyph of window W in glyph row ROW. See the
11330 comment of x_draw_glyphs for the meaning of HL. */
11333 x_draw_phys_cursor_glyph (w
, row
, hl
)
11335 struct glyph_row
*row
;
11336 enum draw_glyphs_face hl
;
11338 /* If cursor hpos is out of bounds, don't draw garbage. This can
11339 happen in mini-buffer windows when switching between echo area
11340 glyphs and mini-buffer. */
11341 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
11343 int on_p
= w
->phys_cursor_on_p
;
11345 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
11346 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
11348 w
->phys_cursor_on_p
= on_p
;
11350 /* When we erase the cursor, and ROW is overlapped by other
11351 rows, make sure that these overlapping parts of other rows
11353 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
11355 if (row
> w
->current_matrix
->rows
11356 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
11357 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
11359 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
11360 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
11361 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
11367 /* Erase the image of a cursor of window W from the screen. */
11370 x_erase_phys_cursor (w
)
11373 struct frame
*f
= XFRAME (w
->frame
);
11374 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11375 int hpos
= w
->phys_cursor
.hpos
;
11376 int vpos
= w
->phys_cursor
.vpos
;
11377 int mouse_face_here_p
= 0;
11378 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
11379 struct glyph_row
*cursor_row
;
11380 struct glyph
*cursor_glyph
;
11381 enum draw_glyphs_face hl
;
11383 /* No cursor displayed or row invalidated => nothing to do on the
11385 if (w
->phys_cursor_type
== NO_CURSOR
)
11386 goto mark_cursor_off
;
11388 /* VPOS >= active_glyphs->nrows means that window has been resized.
11389 Don't bother to erase the cursor. */
11390 if (vpos
>= active_glyphs
->nrows
)
11391 goto mark_cursor_off
;
11393 /* If row containing cursor is marked invalid, there is nothing we
11395 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
11396 if (!cursor_row
->enabled_p
)
11397 goto mark_cursor_off
;
11399 /* If row is completely invisible, don't attempt to delete a cursor which
11400 isn't there. This can happen if cursor is at top of a window, and
11401 we switch to a buffer with a header line in that window. */
11402 if (cursor_row
->visible_height
<= 0)
11403 goto mark_cursor_off
;
11405 /* This can happen when the new row is shorter than the old one.
11406 In this case, either x_draw_glyphs or clear_end_of_line
11407 should have cleared the cursor. Note that we wouldn't be
11408 able to erase the cursor in this case because we don't have a
11409 cursor glyph at hand. */
11410 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
11411 goto mark_cursor_off
;
11413 /* If the cursor is in the mouse face area, redisplay that when
11414 we clear the cursor. */
11415 if (! NILP (dpyinfo
->mouse_face_window
)
11416 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
11417 && (vpos
> dpyinfo
->mouse_face_beg_row
11418 || (vpos
== dpyinfo
->mouse_face_beg_row
11419 && hpos
>= dpyinfo
->mouse_face_beg_col
))
11420 && (vpos
< dpyinfo
->mouse_face_end_row
11421 || (vpos
== dpyinfo
->mouse_face_end_row
11422 && hpos
< dpyinfo
->mouse_face_end_col
))
11423 /* Don't redraw the cursor's spot in mouse face if it is at the
11424 end of a line (on a newline). The cursor appears there, but
11425 mouse highlighting does not. */
11426 && cursor_row
->used
[TEXT_AREA
] > hpos
)
11427 mouse_face_here_p
= 1;
11429 /* Maybe clear the display under the cursor. */
11430 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
11433 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11435 cursor_glyph
= get_phys_cursor_glyph (w
);
11436 if (cursor_glyph
== NULL
)
11437 goto mark_cursor_off
;
11439 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
11441 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11443 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
11445 cursor_glyph
->pixel_width
,
11446 cursor_row
->visible_height
,
11450 /* Erase the cursor by redrawing the character underneath it. */
11451 if (mouse_face_here_p
)
11452 hl
= DRAW_MOUSE_FACE
;
11454 hl
= DRAW_NORMAL_TEXT
;
11455 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
11458 w
->phys_cursor_on_p
= 0;
11459 w
->phys_cursor_type
= NO_CURSOR
;
11463 /* Non-zero if physical cursor of window W is within mouse face. */
11466 cursor_in_mouse_face_p (w
)
11469 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
11470 int in_mouse_face
= 0;
11472 if (WINDOWP (dpyinfo
->mouse_face_window
)
11473 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
11475 int hpos
= w
->phys_cursor
.hpos
;
11476 int vpos
= w
->phys_cursor
.vpos
;
11478 if (vpos
>= dpyinfo
->mouse_face_beg_row
11479 && vpos
<= dpyinfo
->mouse_face_end_row
11480 && (vpos
> dpyinfo
->mouse_face_beg_row
11481 || hpos
>= dpyinfo
->mouse_face_beg_col
)
11482 && (vpos
< dpyinfo
->mouse_face_end_row
11483 || hpos
< dpyinfo
->mouse_face_end_col
11484 || dpyinfo
->mouse_face_past_end
))
11488 return in_mouse_face
;
11492 /* Display or clear cursor of window W. If ON is zero, clear the
11493 cursor. If it is non-zero, display the cursor. If ON is nonzero,
11494 where to put the cursor is specified by HPOS, VPOS, X and Y. */
11497 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
11499 int on
, hpos
, vpos
, x
, y
;
11501 struct frame
*f
= XFRAME (w
->frame
);
11502 int new_cursor_type
;
11503 int new_cursor_width
;
11504 struct glyph_matrix
*current_glyphs
;
11505 struct glyph_row
*glyph_row
;
11506 struct glyph
*glyph
;
11507 int cursor_non_selected
;
11509 /* This is pointless on invisible frames, and dangerous on garbaged
11510 windows and frames; in the latter case, the frame or window may
11511 be in the midst of changing its size, and x and y may be off the
11513 if (! FRAME_VISIBLE_P (f
)
11514 || FRAME_GARBAGED_P (f
)
11515 || vpos
>= w
->current_matrix
->nrows
11516 || hpos
>= w
->current_matrix
->matrix_w
)
11519 /* If cursor is off and we want it off, return quickly. */
11520 if (!on
&& !w
->phys_cursor_on_p
)
11523 current_glyphs
= w
->current_matrix
;
11524 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
11525 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
11527 /* If cursor row is not enabled, we don't really know where to
11528 display the cursor. */
11529 if (!glyph_row
->enabled_p
)
11531 w
->phys_cursor_on_p
= 0;
11535 xassert (interrupt_input_blocked
);
11537 /* Set new_cursor_type to the cursor we want to be displayed. In a
11538 mini-buffer window, we want the cursor only to appear if we are
11539 reading input from this window. For the selected window, we want
11540 the cursor type given by the frame parameter. If explicitly
11541 marked off, draw no cursor. In all other cases, we want a hollow
11543 cursor_non_selected
11544 = !NILP (Fbuffer_local_value (Qcursor_in_non_selected_windows
,
11546 new_cursor_width
= -1;
11547 if (cursor_in_echo_area
11548 && FRAME_HAS_MINIBUF_P (f
)
11549 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
11551 if (w
== XWINDOW (echo_area_window
))
11552 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
11553 else if (cursor_non_selected
)
11554 new_cursor_type
= HOLLOW_BOX_CURSOR
;
11556 new_cursor_type
= NO_CURSOR
;
11560 if (f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
11561 || w
!= XWINDOW (f
->selected_window
))
11563 if ((MINI_WINDOW_P (w
) && minibuf_level
== 0)
11564 || !cursor_non_selected
11565 || NILP (XBUFFER (w
->buffer
)->cursor_type
))
11566 new_cursor_type
= NO_CURSOR
;
11568 new_cursor_type
= HOLLOW_BOX_CURSOR
;
11570 else if (w
->cursor_off_p
)
11571 new_cursor_type
= NO_CURSOR
;
11574 struct buffer
*b
= XBUFFER (w
->buffer
);
11576 if (EQ (b
->cursor_type
, Qt
))
11577 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
11579 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
11580 &new_cursor_width
);
11584 /* If cursor is currently being shown and we don't want it to be or
11585 it is in the wrong place, or the cursor type is not what we want,
11587 if (w
->phys_cursor_on_p
11589 || w
->phys_cursor
.x
!= x
11590 || w
->phys_cursor
.y
!= y
11591 || new_cursor_type
!= w
->phys_cursor_type
))
11592 x_erase_phys_cursor (w
);
11594 /* If the cursor is now invisible and we want it to be visible,
11596 if (on
&& !w
->phys_cursor_on_p
)
11598 w
->phys_cursor_ascent
= glyph_row
->ascent
;
11599 w
->phys_cursor_height
= glyph_row
->height
;
11601 /* Set phys_cursor_.* before x_draw_.* is called because some
11602 of them may need the information. */
11603 w
->phys_cursor
.x
= x
;
11604 w
->phys_cursor
.y
= glyph_row
->y
;
11605 w
->phys_cursor
.hpos
= hpos
;
11606 w
->phys_cursor
.vpos
= vpos
;
11607 w
->phys_cursor_type
= new_cursor_type
;
11608 w
->phys_cursor_on_p
= 1;
11610 switch (new_cursor_type
)
11612 case HOLLOW_BOX_CURSOR
:
11613 x_draw_hollow_cursor (w
, glyph_row
);
11616 case FILLED_BOX_CURSOR
:
11617 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
11621 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
);
11632 if (w
== XWINDOW (f
->selected_window
))
11633 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
11634 xic_set_preeditarea (w
, x
, y
);
11639 if (updating_frame
!= f
)
11640 XFlush (FRAME_X_DISPLAY (f
));
11645 /* Display the cursor on window W, or clear it. X and Y are window
11646 relative pixel coordinates. HPOS and VPOS are glyph matrix
11647 positions. If W is not the selected window, display a hollow
11648 cursor. ON non-zero means display the cursor at X, Y which
11649 correspond to HPOS, VPOS, otherwise it is cleared. */
11652 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
11654 int on
, hpos
, vpos
, x
, y
;
11657 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
11662 /* Display the cursor on window W, or clear it, according to ON_P.
11663 Don't change the cursor's position. */
11666 x_update_cursor (f
, on_p
)
11669 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
11673 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
11674 in the window tree rooted at W. */
11677 x_update_cursor_in_window_tree (w
, on_p
)
11683 if (!NILP (w
->hchild
))
11684 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
11685 else if (!NILP (w
->vchild
))
11686 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
11688 x_update_window_cursor (w
, on_p
);
11690 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
11695 /* Switch the display of W's cursor on or off, according to the value
11699 x_update_window_cursor (w
, on
)
11703 /* Don't update cursor in windows whose frame is in the process
11704 of being deleted. */
11705 if (w
->current_matrix
)
11708 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
11709 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
11719 /* Make the x-window of frame F use the gnu icon bitmap. */
11722 x_bitmap_icon (f
, file
)
11728 if (FRAME_X_WINDOW (f
) == 0)
11731 /* Free up our existing icon bitmap if any. */
11732 if (f
->output_data
.x
->icon_bitmap
> 0)
11733 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
11734 f
->output_data
.x
->icon_bitmap
= 0;
11736 if (STRINGP (file
))
11737 bitmap_id
= x_create_bitmap_from_file (f
, file
);
11740 /* Create the GNU bitmap if necessary. */
11741 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
11742 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
11743 = x_create_bitmap_from_data (f
, gnu_bits
,
11744 gnu_width
, gnu_height
);
11746 /* The first time we create the GNU bitmap,
11747 this increments the ref-count one extra time.
11748 As a result, the GNU bitmap is never freed.
11749 That way, we don't have to worry about allocating it again. */
11750 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
11752 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
11755 x_wm_set_icon_pixmap (f
, bitmap_id
);
11756 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
11762 /* Make the x-window of frame F use a rectangle with text.
11763 Use ICON_NAME as the text. */
11766 x_text_icon (f
, icon_name
)
11770 if (FRAME_X_WINDOW (f
) == 0)
11775 XTextProperty text
;
11776 text
.value
= (unsigned char *) icon_name
;
11777 text
.encoding
= XA_STRING
;
11779 text
.nitems
= strlen (icon_name
);
11780 #ifdef USE_X_TOOLKIT
11781 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
11783 #else /* not USE_X_TOOLKIT */
11784 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
11785 #endif /* not USE_X_TOOLKIT */
11787 #else /* not HAVE_X11R4 */
11788 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
11789 #endif /* not HAVE_X11R4 */
11791 if (f
->output_data
.x
->icon_bitmap
> 0)
11792 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
11793 f
->output_data
.x
->icon_bitmap
= 0;
11794 x_wm_set_icon_pixmap (f
, 0);
11799 #define X_ERROR_MESSAGE_SIZE 200
11801 /* If non-nil, this should be a string.
11802 It means catch X errors and store the error message in this string. */
11804 static Lisp_Object x_error_message_string
;
11806 /* An X error handler which stores the error message in
11807 x_error_message_string. This is called from x_error_handler if
11808 x_catch_errors is in effect. */
11811 x_error_catcher (display
, error
)
11813 XErrorEvent
*error
;
11815 XGetErrorText (display
, error
->error_code
,
11816 XSTRING (x_error_message_string
)->data
,
11817 X_ERROR_MESSAGE_SIZE
);
11820 /* Begin trapping X errors for display DPY. Actually we trap X errors
11821 for all displays, but DPY should be the display you are actually
11824 After calling this function, X protocol errors no longer cause
11825 Emacs to exit; instead, they are recorded in the string
11826 stored in x_error_message_string.
11828 Calling x_check_errors signals an Emacs error if an X error has
11829 occurred since the last call to x_catch_errors or x_check_errors.
11831 Calling x_uncatch_errors resumes the normal error handling. */
11833 void x_check_errors ();
11834 static Lisp_Object
x_catch_errors_unwind ();
11837 x_catch_errors (dpy
)
11840 int count
= specpdl_ptr
- specpdl
;
11842 /* Make sure any errors from previous requests have been dealt with. */
11843 XSync (dpy
, False
);
11845 record_unwind_protect (x_catch_errors_unwind
, x_error_message_string
);
11847 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
11848 XSTRING (x_error_message_string
)->data
[0] = 0;
11853 /* Unbind the binding that we made to check for X errors. */
11856 x_catch_errors_unwind (old_val
)
11857 Lisp_Object old_val
;
11859 x_error_message_string
= old_val
;
11863 /* If any X protocol errors have arrived since the last call to
11864 x_catch_errors or x_check_errors, signal an Emacs error using
11865 sprintf (a buffer, FORMAT, the x error message text) as the text. */
11868 x_check_errors (dpy
, format
)
11872 /* Make sure to catch any errors incurred so far. */
11873 XSync (dpy
, False
);
11875 if (XSTRING (x_error_message_string
)->data
[0])
11876 error (format
, XSTRING (x_error_message_string
)->data
);
11879 /* Nonzero if we had any X protocol errors
11880 since we did x_catch_errors on DPY. */
11883 x_had_errors_p (dpy
)
11886 /* Make sure to catch any errors incurred so far. */
11887 XSync (dpy
, False
);
11889 return XSTRING (x_error_message_string
)->data
[0] != 0;
11892 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
11895 x_clear_errors (dpy
)
11898 XSTRING (x_error_message_string
)->data
[0] = 0;
11901 /* Stop catching X protocol errors and let them make Emacs die.
11902 DPY should be the display that was passed to x_catch_errors.
11903 COUNT should be the value that was returned by
11904 the corresponding call to x_catch_errors. */
11907 x_uncatch_errors (dpy
, count
)
11911 unbind_to (count
, Qnil
);
11915 static unsigned int x_wire_count
;
11918 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
11923 /* Handle SIGPIPE, which can happen when the connection to a server
11924 simply goes away. SIGPIPE is handled by x_connection_signal.
11925 Don't need to do anything, because the write which caused the
11926 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
11927 which will do the appropriate cleanup for us. */
11930 x_connection_signal (signalnum
) /* If we don't have an argument, */
11931 int signalnum
; /* some compilers complain in signal calls. */
11934 /* USG systems forget handlers when they are used;
11935 must reestablish each time */
11936 signal (signalnum
, x_connection_signal
);
11941 /************************************************************************
11943 ************************************************************************/
11945 /* Error message passed to x_connection_closed. */
11947 static char *error_msg
;
11949 /* Function installed as fatal_error_signal_hook in
11950 x_connection_closed. Print the X error message, and exit normally,
11951 instead of dumping core when XtCloseDisplay fails. */
11954 x_fatal_error_signal ()
11956 fprintf (stderr
, "%s\n", error_msg
);
11960 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
11961 the text of an error message that lead to the connection loss. */
11964 x_connection_closed (dpy
, error_message
)
11966 char *error_message
;
11968 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
11969 Lisp_Object frame
, tail
;
11972 error_msg
= (char *) alloca (strlen (error_message
) + 1);
11973 strcpy (error_msg
, error_message
);
11974 handling_signal
= 0;
11976 /* Prevent being called recursively because of an error condition
11977 below. Otherwise, we might end up with printing ``can't find per
11978 display information'' in the recursive call instead of printing
11979 the original message here. */
11980 count
= x_catch_errors (dpy
);
11982 /* We have to close the display to inform Xt that it doesn't
11983 exist anymore. If we don't, Xt will continue to wait for
11984 events from the display. As a consequence, a sequence of
11986 M-x make-frame-on-display RET :1 RET
11987 ...kill the new frame, so that we get an IO error...
11988 M-x make-frame-on-display RET :1 RET
11990 will indefinitely wait in Xt for events for display `:1', opened
11991 in the first class to make-frame-on-display.
11993 Closing the display is reported to lead to a bus error on
11994 OpenWindows in certain situations. I suspect that is a bug
11995 in OpenWindows. I don't know how to cicumvent it here. */
11997 #ifdef USE_X_TOOLKIT
11998 /* If DPYINFO is null, this means we didn't open the display
11999 in the first place, so don't try to close it. */
12002 extern void (*fatal_error_signal_hook
) P_ ((void));
12003 fatal_error_signal_hook
= x_fatal_error_signal
;
12004 XtCloseDisplay (dpy
);
12005 fatal_error_signal_hook
= NULL
;
12009 /* Indicate that this display is dead. */
12011 dpyinfo
->display
= 0;
12013 /* First delete frames whose mini-buffers are on frames
12014 that are on the dead display. */
12015 FOR_EACH_FRAME (tail
, frame
)
12017 Lisp_Object minibuf_frame
;
12019 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
12020 if (FRAME_X_P (XFRAME (frame
))
12021 && FRAME_X_P (XFRAME (minibuf_frame
))
12022 && ! EQ (frame
, minibuf_frame
)
12023 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
12024 Fdelete_frame (frame
, Qt
);
12027 /* Now delete all remaining frames on the dead display.
12028 We are now sure none of these is used as the mini-buffer
12029 for another frame that we need to delete. */
12030 FOR_EACH_FRAME (tail
, frame
)
12031 if (FRAME_X_P (XFRAME (frame
))
12032 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
12034 /* Set this to t so that Fdelete_frame won't get confused
12035 trying to find a replacement. */
12036 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
12037 Fdelete_frame (frame
, Qt
);
12041 x_delete_display (dpyinfo
);
12043 x_uncatch_errors (dpy
, count
);
12045 if (x_display_list
== 0)
12047 fprintf (stderr
, "%s\n", error_msg
);
12048 shut_down_emacs (0, 0, Qnil
);
12052 /* Ordinary stack unwind doesn't deal with these. */
12054 sigunblock (sigmask (SIGIO
));
12056 sigunblock (sigmask (SIGALRM
));
12057 TOTALLY_UNBLOCK_INPUT
;
12059 clear_waiting_for_input ();
12060 error ("%s", error_msg
);
12064 /* This is the usual handler for X protocol errors.
12065 It kills all frames on the display that we got the error for.
12066 If that was the only one, it prints an error message and kills Emacs. */
12069 x_error_quitter (display
, error
)
12071 XErrorEvent
*error
;
12073 char buf
[256], buf1
[356];
12075 /* Note that there is no real way portable across R3/R4 to get the
12076 original error handler. */
12078 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
12079 sprintf (buf1
, "X protocol error: %s on protocol request %d",
12080 buf
, error
->request_code
);
12081 x_connection_closed (display
, buf1
);
12085 /* This is the first-level handler for X protocol errors.
12086 It calls x_error_quitter or x_error_catcher. */
12089 x_error_handler (display
, error
)
12091 XErrorEvent
*error
;
12093 if (! NILP (x_error_message_string
))
12094 x_error_catcher (display
, error
);
12096 x_error_quitter (display
, error
);
12100 /* This is the handler for X IO errors, always.
12101 It kills all frames on the display that we lost touch with.
12102 If that was the only one, it prints an error message and kills Emacs. */
12105 x_io_error_quitter (display
)
12110 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
12111 x_connection_closed (display
, buf
);
12115 /* Changing the font of the frame. */
12117 /* Give frame F the font named FONTNAME as its default font, and
12118 return the full name of that font. FONTNAME may be a wildcard
12119 pattern; in that case, we choose some font that fits the pattern.
12120 The return value shows which font we chose. */
12123 x_new_font (f
, fontname
)
12125 register char *fontname
;
12127 struct font_info
*fontp
12128 = FS_LOAD_FONT (f
, 0, fontname
, -1);
12133 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
12134 f
->output_data
.x
->baseline_offset
= fontp
->baseline_offset
;
12135 f
->output_data
.x
->fontset
= -1;
12137 x_compute_fringe_widths (f
, 1);
12139 /* Compute the scroll bar width in character columns. */
12140 if (f
->scroll_bar_pixel_width
> 0)
12142 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
12143 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
12147 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
12148 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
12151 /* Now make the frame display the given font. */
12152 if (FRAME_X_WINDOW (f
) != 0)
12154 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
12155 f
->output_data
.x
->font
->fid
);
12156 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
12157 f
->output_data
.x
->font
->fid
);
12158 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
12159 f
->output_data
.x
->font
->fid
);
12161 frame_update_line_height (f
);
12163 /* Don't change the size of a tip frame; there's no point in
12164 doing it because it's done in Fx_show_tip, and it leads to
12165 problems because the tip frame has no widget. */
12166 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
12167 x_set_window_size (f
, 0, f
->width
, f
->height
);
12170 /* If we are setting a new frame's font for the first time,
12171 there are no faces yet, so this font's height is the line height. */
12172 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
12174 return build_string (fontp
->full_name
);
12177 /* Give frame F the fontset named FONTSETNAME as its default font, and
12178 return the full name of that fontset. FONTSETNAME may be a wildcard
12179 pattern; in that case, we choose some fontset that fits the pattern.
12180 The return value shows which fontset we chose. */
12183 x_new_fontset (f
, fontsetname
)
12187 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
12188 Lisp_Object result
;
12193 if (f
->output_data
.x
->fontset
== fontset
)
12194 /* This fontset is already set in frame F. There's nothing more
12196 return fontset_name (fontset
);
12198 result
= x_new_font (f
, (XSTRING (fontset_ascii (fontset
))->data
));
12200 if (!STRINGP (result
))
12201 /* Can't load ASCII font. */
12204 /* Since x_new_font doesn't update any fontset information, do it now. */
12205 f
->output_data
.x
->fontset
= fontset
;
12209 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
12210 xic_set_xfontset (f
, XSTRING (fontset_ascii (fontset
))->data
);
12213 return build_string (fontsetname
);
12216 /* Compute actual fringe widths */
12219 x_compute_fringe_widths (f
, redraw
)
12223 int o_left
= f
->output_data
.x
->left_fringe_width
;
12224 int o_right
= f
->output_data
.x
->right_fringe_width
;
12225 int o_cols
= f
->output_data
.x
->fringe_cols
;
12227 Lisp_Object left_fringe
= Fassq (Qleft_fringe
, f
->param_alist
);
12228 Lisp_Object right_fringe
= Fassq (Qright_fringe
, f
->param_alist
);
12229 int left_fringe_width
, right_fringe_width
;
12231 if (!NILP (left_fringe
))
12232 left_fringe
= Fcdr (left_fringe
);
12233 if (!NILP (right_fringe
))
12234 right_fringe
= Fcdr (right_fringe
);
12236 left_fringe_width
= ((NILP (left_fringe
) || !INTEGERP (left_fringe
)) ? 8 :
12237 XINT (left_fringe
));
12238 right_fringe_width
= ((NILP (right_fringe
) || !INTEGERP (right_fringe
)) ? 8 :
12239 XINT (right_fringe
));
12241 if (left_fringe_width
|| right_fringe_width
)
12243 int left_wid
= left_fringe_width
>= 0 ? left_fringe_width
: -left_fringe_width
;
12244 int right_wid
= right_fringe_width
>= 0 ? right_fringe_width
: -right_fringe_width
;
12245 int conf_wid
= left_wid
+ right_wid
;
12246 int font_wid
= FONT_WIDTH (f
->output_data
.x
->font
);
12247 int cols
= (left_wid
+ right_wid
+ font_wid
-1) / font_wid
;
12248 int real_wid
= cols
* font_wid
;
12249 if (left_wid
&& right_wid
)
12251 if (left_fringe_width
< 0)
12253 /* Left fringe width is fixed, adjust right fringe if necessary */
12254 f
->output_data
.x
->left_fringe_width
= left_wid
;
12255 f
->output_data
.x
->right_fringe_width
= real_wid
- left_wid
;
12257 else if (right_fringe_width
< 0)
12259 /* Right fringe width is fixed, adjust left fringe if necessary */
12260 f
->output_data
.x
->left_fringe_width
= real_wid
- right_wid
;
12261 f
->output_data
.x
->right_fringe_width
= right_wid
;
12265 /* Adjust both fringes with an equal amount.
12266 Note that we are doing integer arithmetic here, so don't
12267 lose a pixel if the total width is an odd number. */
12268 int fill
= real_wid
- conf_wid
;
12269 f
->output_data
.x
->left_fringe_width
= left_wid
+ fill
/2;
12270 f
->output_data
.x
->right_fringe_width
= right_wid
+ fill
- fill
/2;
12273 else if (left_fringe_width
)
12275 f
->output_data
.x
->left_fringe_width
= real_wid
;
12276 f
->output_data
.x
->right_fringe_width
= 0;
12280 f
->output_data
.x
->left_fringe_width
= 0;
12281 f
->output_data
.x
->right_fringe_width
= real_wid
;
12283 f
->output_data
.x
->fringe_cols
= cols
;
12284 f
->output_data
.x
->fringes_extra
= real_wid
;
12288 f
->output_data
.x
->left_fringe_width
= 0;
12289 f
->output_data
.x
->right_fringe_width
= 0;
12290 f
->output_data
.x
->fringe_cols
= 0;
12291 f
->output_data
.x
->fringes_extra
= 0;
12294 if (redraw
&& FRAME_VISIBLE_P (f
))
12295 if (o_left
!= f
->output_data
.x
->left_fringe_width
||
12296 o_right
!= f
->output_data
.x
->right_fringe_width
||
12297 o_cols
!= f
->output_data
.x
->fringe_cols
)
12301 /***********************************************************************
12303 ***********************************************************************/
12309 /* XIM destroy callback function, which is called whenever the
12310 connection to input method XIM dies. CLIENT_DATA contains a
12311 pointer to the x_display_info structure corresponding to XIM. */
12314 xim_destroy_callback (xim
, client_data
, call_data
)
12316 XPointer client_data
;
12317 XPointer call_data
;
12319 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
12320 Lisp_Object frame
, tail
;
12324 /* No need to call XDestroyIC.. */
12325 FOR_EACH_FRAME (tail
, frame
)
12327 struct frame
*f
= XFRAME (frame
);
12328 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
12330 FRAME_XIC (f
) = NULL
;
12331 if (FRAME_XIC_FONTSET (f
))
12333 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
12334 FRAME_XIC_FONTSET (f
) = NULL
;
12339 /* No need to call XCloseIM. */
12340 dpyinfo
->xim
= NULL
;
12341 XFree (dpyinfo
->xim_styles
);
12345 #endif /* HAVE_X11R6 */
12347 /* Open the connection to the XIM server on display DPYINFO.
12348 RESOURCE_NAME is the resource name Emacs uses. */
12351 xim_open_dpy (dpyinfo
, resource_name
)
12352 struct x_display_info
*dpyinfo
;
12353 char *resource_name
;
12358 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
, EMACS_CLASS
);
12359 dpyinfo
->xim
= xim
;
12364 XIMCallback destroy
;
12367 /* Get supported styles and XIM values. */
12368 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
12371 destroy
.callback
= xim_destroy_callback
;
12372 destroy
.client_data
= (XPointer
)dpyinfo
;
12373 /* This isn't prototyped in OSF 5.0. */
12374 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
12378 #else /* not USE_XIM */
12379 dpyinfo
->xim
= NULL
;
12380 #endif /* not USE_XIM */
12384 #ifdef HAVE_X11R6_XIM
12388 struct x_display_info
*dpyinfo
;
12389 char *resource_name
;
12392 /* XIM instantiate callback function, which is called whenever an XIM
12393 server is available. DISPLAY is teh display of the XIM.
12394 CLIENT_DATA contains a pointer to an xim_inst_t structure created
12395 when the callback was registered. */
12398 xim_instantiate_callback (display
, client_data
, call_data
)
12400 XPointer client_data
;
12401 XPointer call_data
;
12403 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
12404 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
12406 /* We don't support multiple XIM connections. */
12410 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
12412 /* Create XIC for the existing frames on the same display, as long
12413 as they have no XIC. */
12414 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
12416 Lisp_Object tail
, frame
;
12419 FOR_EACH_FRAME (tail
, frame
)
12421 struct frame
*f
= XFRAME (frame
);
12423 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
12424 if (FRAME_XIC (f
) == NULL
)
12426 create_frame_xic (f
);
12427 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
12428 xic_set_statusarea (f
);
12429 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
12431 struct window
*w
= XWINDOW (f
->selected_window
);
12432 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
12441 #endif /* HAVE_X11R6_XIM */
12444 /* Open a connection to the XIM server on display DPYINFO.
12445 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
12446 connection only at the first time. On X11R6, open the connection
12447 in the XIM instantiate callback function. */
12450 xim_initialize (dpyinfo
, resource_name
)
12451 struct x_display_info
*dpyinfo
;
12452 char *resource_name
;
12455 #ifdef HAVE_X11R6_XIM
12456 struct xim_inst_t
*xim_inst
;
12459 dpyinfo
->xim
= NULL
;
12460 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
12461 xim_inst
->dpyinfo
= dpyinfo
;
12462 len
= strlen (resource_name
);
12463 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
12464 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
12465 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
12466 resource_name
, EMACS_CLASS
,
12467 xim_instantiate_callback
,
12468 /* Fixme: This is XPointer in
12469 XFree86 but (XPointer *) on
12470 Tru64, at least. */
12471 (XPointer
) xim_inst
);
12472 #else /* not HAVE_X11R6_XIM */
12473 dpyinfo
->xim
= NULL
;
12474 xim_open_dpy (dpyinfo
, resource_name
);
12475 #endif /* not HAVE_X11R6_XIM */
12477 #else /* not USE_XIM */
12478 dpyinfo
->xim
= NULL
;
12479 #endif /* not USE_XIM */
12483 /* Close the connection to the XIM server on display DPYINFO. */
12486 xim_close_dpy (dpyinfo
)
12487 struct x_display_info
*dpyinfo
;
12490 #ifdef HAVE_X11R6_XIM
12491 if (dpyinfo
->display
)
12492 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
12494 xim_instantiate_callback
, NULL
);
12495 #endif /* not HAVE_X11R6_XIM */
12496 if (dpyinfo
->display
)
12497 XCloseIM (dpyinfo
->xim
);
12498 dpyinfo
->xim
= NULL
;
12499 XFree (dpyinfo
->xim_styles
);
12500 #endif /* USE_XIM */
12503 #endif /* not HAVE_X11R6_XIM */
12507 /* Calculate the absolute position in frame F
12508 from its current recorded position values and gravity. */
12511 x_calc_absolute_position (f
)
12515 int win_x
= 0, win_y
= 0;
12516 int flags
= f
->output_data
.x
->size_hint_flags
;
12519 /* We have nothing to do if the current position
12520 is already for the top-left corner. */
12521 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
12524 #ifdef USE_X_TOOLKIT
12525 this_window
= XtWindow (f
->output_data
.x
->widget
);
12527 this_window
= FRAME_X_WINDOW (f
);
12530 /* Find the position of the outside upper-left corner of
12531 the inner window, with respect to the outer window.
12532 But do this only if we will need the results. */
12533 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
12538 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
12541 x_clear_errors (FRAME_X_DISPLAY (f
));
12542 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
12544 /* From-window, to-window. */
12546 f
->output_data
.x
->parent_desc
,
12548 /* From-position, to-position. */
12549 0, 0, &win_x
, &win_y
,
12551 /* Child of win. */
12553 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
12555 Window newroot
, newparent
= 0xdeadbeef;
12556 Window
*newchildren
;
12557 unsigned int nchildren
;
12559 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
12560 &newparent
, &newchildren
, &nchildren
))
12563 XFree ((char *) newchildren
);
12565 f
->output_data
.x
->parent_desc
= newparent
;
12571 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
12575 /* Treat negative positions as relative to the leftmost bottommost
12576 position that fits on the screen. */
12577 if (flags
& XNegative
)
12578 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
12579 - 2 * f
->output_data
.x
->border_width
- win_x
12581 + f
->output_data
.x
->left_pos
);
12584 int height
= PIXEL_HEIGHT (f
);
12586 #if defined USE_X_TOOLKIT && defined USE_MOTIF
12587 /* Something is fishy here. When using Motif, starting Emacs with
12588 `-g -0-0', the frame appears too low by a few pixels.
12590 This seems to be so because initially, while Emacs is starting,
12591 the column widget's height and the frame's pixel height are
12592 different. The column widget's height is the right one. In
12593 later invocations, when Emacs is up, the frame's pixel height
12596 It's not obvious where the initial small difference comes from.
12597 2000-12-01, gerd. */
12599 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
12602 if (flags
& YNegative
)
12603 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
12604 - 2 * f
->output_data
.x
->border_width
12607 + f
->output_data
.x
->top_pos
);
12610 /* The left_pos and top_pos
12611 are now relative to the top and left screen edges,
12612 so the flags should correspond. */
12613 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
12616 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
12617 to really change the position, and 0 when calling from
12618 x_make_frame_visible (in that case, XOFF and YOFF are the current
12619 position values). It is -1 when calling from x_set_frame_parameters,
12620 which means, do adjust for borders but don't change the gravity. */
12623 x_set_offset (f
, xoff
, yoff
, change_gravity
)
12625 register int xoff
, yoff
;
12626 int change_gravity
;
12628 int modified_top
, modified_left
;
12630 if (change_gravity
> 0)
12632 f
->output_data
.x
->top_pos
= yoff
;
12633 f
->output_data
.x
->left_pos
= xoff
;
12634 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
12636 f
->output_data
.x
->size_hint_flags
|= XNegative
;
12638 f
->output_data
.x
->size_hint_flags
|= YNegative
;
12639 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
12641 x_calc_absolute_position (f
);
12644 x_wm_set_size_hint (f
, (long) 0, 0);
12646 modified_left
= f
->output_data
.x
->left_pos
;
12647 modified_top
= f
->output_data
.x
->top_pos
;
12648 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
12649 this seems to be unnecessary and incorrect. rms, 4/17/97. */
12650 /* It is a mystery why we need to add the border_width here
12651 when the frame is already visible, but experiment says we do. */
12652 if (change_gravity
!= 0)
12654 modified_left
+= f
->output_data
.x
->border_width
;
12655 modified_top
+= f
->output_data
.x
->border_width
;
12659 #ifdef USE_X_TOOLKIT
12660 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
12661 modified_left
, modified_top
);
12662 #else /* not USE_X_TOOLKIT */
12663 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12664 modified_left
, modified_top
);
12665 #endif /* not USE_X_TOOLKIT */
12669 /* Check if we need to resize the frame due to a fullscreen request.
12670 If so needed, resize the frame. */
12672 x_check_fullscreen (f
)
12675 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_BOTH
)
12677 int width
, height
, ign
;
12679 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
12680 &f
->output_data
.x
->top_pos
);
12682 x_fullscreen_adjust (f
, &width
, &height
, &ign
, &ign
);
12684 /* We do not need to move the window, it shall be taken care of
12685 when setting WM manager hints.
12686 If the frame is visible already, the position is checked by
12687 x_check_fullscreen_move. */
12688 if (f
->width
!= width
|| f
->height
!= height
)
12690 change_frame_size (f
, height
, width
, 0, 1, 0);
12691 SET_FRAME_GARBAGED (f
);
12692 cancel_mouse_face (f
);
12694 /* Wait for the change of frame size to occur */
12695 f
->output_data
.x
->want_fullscreen
|= FULLSCREEN_WAIT
;
12701 /* If frame parameters are set after the frame is mapped, we need to move
12702 the window. This is done in xfns.c.
12703 Some window managers moves the window to the right position, some
12704 moves the outer window manager window to the specified position.
12705 Here we check that we are in the right spot. If not, make a second
12706 move, assuming we are dealing with the second kind of window manager. */
12708 x_check_fullscreen_move (f
)
12711 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_MOVE_WAIT
)
12713 int expect_top
= f
->output_data
.x
->top_pos
;
12714 int expect_left
= f
->output_data
.x
->left_pos
;
12716 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_HEIGHT
)
12718 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WIDTH
)
12721 if (expect_top
!= f
->output_data
.x
->top_pos
12722 || expect_left
!= f
->output_data
.x
->left_pos
)
12723 x_set_offset (f
, expect_left
, expect_top
, 1);
12725 /* Just do this once */
12726 f
->output_data
.x
->want_fullscreen
&= ~FULLSCREEN_MOVE_WAIT
;
12731 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
12732 wanted positions of the WM window (not emacs window).
12733 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
12734 window (FRAME_X_WINDOW).
12737 x_fullscreen_adjust (f
, width
, height
, top_pos
, left_pos
)
12744 int newwidth
= f
->width
, newheight
= f
->height
;
12746 *top_pos
= f
->output_data
.x
->top_pos
;
12747 *left_pos
= f
->output_data
.x
->left_pos
;
12749 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_HEIGHT
)
12753 ph
= FRAME_X_DISPLAY_INFO (f
)->height
;
12754 newheight
= PIXEL_TO_CHAR_HEIGHT (f
, ph
);
12755 ph
= CHAR_TO_PIXEL_HEIGHT (f
, newheight
)
12756 - f
->output_data
.x
->y_pixels_diff
;
12757 newheight
= PIXEL_TO_CHAR_HEIGHT (f
, ph
);
12761 if (f
->output_data
.x
->want_fullscreen
& FULLSCREEN_WIDTH
)
12765 pw
= FRAME_X_DISPLAY_INFO (f
)->width
;
12766 newwidth
= PIXEL_TO_CHAR_WIDTH (f
, pw
);
12767 pw
= CHAR_TO_PIXEL_WIDTH (f
, newwidth
)
12768 - f
->output_data
.x
->x_pixels_diff
;
12769 newwidth
= PIXEL_TO_CHAR_WIDTH (f
, pw
);
12774 *height
= newheight
;
12778 /* Change the size of frame F's X window to COLS/ROWS in the case F
12779 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
12780 top-left-corner window gravity for this size change and subsequent
12781 size changes. Otherwise we leave the window gravity unchanged. */
12784 x_set_window_size_1 (f
, change_gravity
, cols
, rows
)
12786 int change_gravity
;
12789 int pixelwidth
, pixelheight
;
12791 check_frame_size (f
, &rows
, &cols
);
12792 f
->output_data
.x
->vertical_scroll_bar_extra
12793 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
12795 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
12796 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
12797 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
12799 x_compute_fringe_widths (f
, 0);
12801 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
12802 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
12804 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
12805 x_wm_set_size_hint (f
, (long) 0, 0);
12807 XSync (FRAME_X_DISPLAY (f
), False
);
12808 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12809 pixelwidth
, pixelheight
);
12811 /* Now, strictly speaking, we can't be sure that this is accurate,
12812 but the window manager will get around to dealing with the size
12813 change request eventually, and we'll hear how it went when the
12814 ConfigureNotify event gets here.
12816 We could just not bother storing any of this information here,
12817 and let the ConfigureNotify event set everything up, but that
12818 might be kind of confusing to the Lisp code, since size changes
12819 wouldn't be reported in the frame parameters until some random
12820 point in the future when the ConfigureNotify event arrives.
12822 We pass 1 for DELAY since we can't run Lisp code inside of
12824 change_frame_size (f
, rows
, cols
, 0, 1, 0);
12825 PIXEL_WIDTH (f
) = pixelwidth
;
12826 PIXEL_HEIGHT (f
) = pixelheight
;
12828 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
12829 receive in the ConfigureNotify event; if we get what we asked
12830 for, then the event won't cause the screen to become garbaged, so
12831 we have to make sure to do it here. */
12832 SET_FRAME_GARBAGED (f
);
12834 XFlush (FRAME_X_DISPLAY (f
));
12838 /* Call this to change the size of frame F's x-window.
12839 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
12840 for this size change and subsequent size changes.
12841 Otherwise we leave the window gravity unchanged. */
12844 x_set_window_size (f
, change_gravity
, cols
, rows
)
12846 int change_gravity
;
12851 #ifdef USE_X_TOOLKIT
12853 if (f
->output_data
.x
->widget
!= NULL
)
12855 /* The x and y position of the widget is clobbered by the
12856 call to XtSetValues within EmacsFrameSetCharSize.
12857 This is a real kludge, but I don't understand Xt so I can't
12858 figure out a correct fix. Can anyone else tell me? -- rms. */
12859 int xpos
= f
->output_data
.x
->widget
->core
.x
;
12860 int ypos
= f
->output_data
.x
->widget
->core
.y
;
12861 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
12862 f
->output_data
.x
->widget
->core
.x
= xpos
;
12863 f
->output_data
.x
->widget
->core
.y
= ypos
;
12866 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
12868 #else /* not USE_X_TOOLKIT */
12870 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
12872 #endif /* not USE_X_TOOLKIT */
12874 /* If cursor was outside the new size, mark it as off. */
12875 mark_window_cursors_off (XWINDOW (f
->root_window
));
12877 /* Clear out any recollection of where the mouse highlighting was,
12878 since it might be in a place that's outside the new frame size.
12879 Actually checking whether it is outside is a pain in the neck,
12880 so don't try--just let the highlighting be done afresh with new size. */
12881 cancel_mouse_face (f
);
12886 /* Mouse warping. */
12889 x_set_mouse_position (f
, x
, y
)
12895 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
12896 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
12898 if (pix_x
< 0) pix_x
= 0;
12899 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
12901 if (pix_y
< 0) pix_y
= 0;
12902 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
12906 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
12907 0, 0, 0, 0, pix_x
, pix_y
);
12911 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
12914 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
12920 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
12921 0, 0, 0, 0, pix_x
, pix_y
);
12925 /* focus shifting, raising and lowering. */
12928 x_focus_on_frame (f
)
12931 #if 0 /* This proves to be unpleasant. */
12935 /* I don't think that the ICCCM allows programs to do things like this
12936 without the interaction of the window manager. Whatever you end up
12937 doing with this code, do it to x_unfocus_frame too. */
12938 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12939 RevertToPointerRoot
, CurrentTime
);
12944 x_unfocus_frame (f
)
12948 /* Look at the remarks in x_focus_on_frame. */
12949 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
12950 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
12951 RevertToPointerRoot
, CurrentTime
);
12955 /* Raise frame F. */
12961 if (f
->async_visible
)
12964 #ifdef USE_X_TOOLKIT
12965 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
12966 #else /* not USE_X_TOOLKIT */
12967 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12968 #endif /* not USE_X_TOOLKIT */
12969 XFlush (FRAME_X_DISPLAY (f
));
12974 /* Lower frame F. */
12980 if (f
->async_visible
)
12983 #ifdef USE_X_TOOLKIT
12984 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
12985 #else /* not USE_X_TOOLKIT */
12986 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12987 #endif /* not USE_X_TOOLKIT */
12988 XFlush (FRAME_X_DISPLAY (f
));
12994 XTframe_raise_lower (f
, raise_flag
)
13004 /* Change of visibility. */
13006 /* This tries to wait until the frame is really visible.
13007 However, if the window manager asks the user where to position
13008 the frame, this will return before the user finishes doing that.
13009 The frame will not actually be visible at that time,
13010 but it will become visible later when the window manager
13011 finishes with it. */
13014 x_make_frame_visible (f
)
13018 int original_top
, original_left
;
13019 int retry_count
= 2;
13025 type
= x_icon_type (f
);
13027 x_bitmap_icon (f
, type
);
13029 if (! FRAME_VISIBLE_P (f
))
13031 /* We test FRAME_GARBAGED_P here to make sure we don't
13032 call x_set_offset a second time
13033 if we get to x_make_frame_visible a second time
13034 before the window gets really visible. */
13035 if (! FRAME_ICONIFIED_P (f
)
13036 && ! f
->output_data
.x
->asked_for_visible
)
13037 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
13039 f
->output_data
.x
->asked_for_visible
= 1;
13041 if (! EQ (Vx_no_window_manager
, Qt
))
13042 x_wm_set_window_state (f
, NormalState
);
13043 #ifdef USE_X_TOOLKIT
13044 /* This was XtPopup, but that did nothing for an iconified frame. */
13045 XtMapWidget (f
->output_data
.x
->widget
);
13046 #else /* not USE_X_TOOLKIT */
13047 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13048 #endif /* not USE_X_TOOLKIT */
13049 #if 0 /* This seems to bring back scroll bars in the wrong places
13050 if the window configuration has changed. They seem
13051 to come back ok without this. */
13052 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
13053 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13057 XFlush (FRAME_X_DISPLAY (f
));
13059 /* Synchronize to ensure Emacs knows the frame is visible
13060 before we do anything else. We do this loop with input not blocked
13061 so that incoming events are handled. */
13065 /* This must be before UNBLOCK_INPUT
13066 since events that arrive in response to the actions above
13067 will set it when they are handled. */
13068 int previously_visible
= f
->output_data
.x
->has_been_visible
;
13070 original_left
= f
->output_data
.x
->left_pos
;
13071 original_top
= f
->output_data
.x
->top_pos
;
13073 /* This must come after we set COUNT. */
13076 /* We unblock here so that arriving X events are processed. */
13078 /* Now move the window back to where it was "supposed to be".
13079 But don't do it if the gravity is negative.
13080 When the gravity is negative, this uses a position
13081 that is 3 pixels too low. Perhaps that's really the border width.
13083 Don't do this if the window has never been visible before,
13084 because the window manager may choose the position
13085 and we don't want to override it. */
13087 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
13088 && f
->output_data
.x
->win_gravity
== NorthWestGravity
13089 && previously_visible
)
13093 unsigned int width
, height
, border
, depth
;
13097 /* On some window managers (such as FVWM) moving an existing
13098 window, even to the same place, causes the window manager
13099 to introduce an offset. This can cause the window to move
13100 to an unexpected location. Check the geometry (a little
13101 slow here) and then verify that the window is in the right
13102 place. If the window is not in the right place, move it
13103 there, and take the potential window manager hit. */
13104 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
13105 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
13107 if (original_left
!= x
|| original_top
!= y
)
13108 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
13109 original_left
, original_top
);
13114 XSETFRAME (frame
, f
);
13116 /* Wait until the frame is visible. Process X events until a
13117 MapNotify event has been seen, or until we think we won't get a
13118 MapNotify at all.. */
13119 for (count
= input_signal_count
+ 10;
13120 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
13122 /* Force processing of queued events. */
13125 /* Machines that do polling rather than SIGIO have been
13126 observed to go into a busy-wait here. So we'll fake an
13127 alarm signal to let the handler know that there's something
13128 to be read. We used to raise a real alarm, but it seems
13129 that the handler isn't always enabled here. This is
13131 if (input_polling_used ())
13133 /* It could be confusing if a real alarm arrives while
13134 processing the fake one. Turn it off and let the
13135 handler reset it. */
13136 extern void poll_for_input_1
P_ ((void));
13137 int old_poll_suppress_count
= poll_suppress_count
;
13138 poll_suppress_count
= 1;
13139 poll_for_input_1 ();
13140 poll_suppress_count
= old_poll_suppress_count
;
13143 /* See if a MapNotify event has been processed. */
13144 FRAME_SAMPLE_VISIBILITY (f
);
13149 (let ((f (selected-frame)))
13153 the frame is not raised with various window managers on
13154 FreeBSD, Linux and Solaris. It turns out that, for some
13155 unknown reason, the call to XtMapWidget is completely ignored.
13156 Mapping the widget a second time works. */
13158 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
13163 /* Change from mapped state to withdrawn state. */
13165 /* Make the frame visible (mapped and not iconified). */
13168 x_make_frame_invisible (f
)
13173 #ifdef USE_X_TOOLKIT
13174 /* Use the frame's outermost window, not the one we normally draw on. */
13175 window
= XtWindow (f
->output_data
.x
->widget
);
13176 #else /* not USE_X_TOOLKIT */
13177 window
= FRAME_X_WINDOW (f
);
13178 #endif /* not USE_X_TOOLKIT */
13180 /* Don't keep the highlight on an invisible frame. */
13181 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
13182 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
13184 #if 0/* This might add unreliability; I don't trust it -- rms. */
13185 if (! f
->async_visible
&& ! f
->async_iconified
)
13191 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
13192 that the current position of the window is user-specified, rather than
13193 program-specified, so that when the window is mapped again, it will be
13194 placed at the same location, without forcing the user to position it
13195 by hand again (they have already done that once for this window.) */
13196 x_wm_set_size_hint (f
, (long) 0, 1);
13200 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
13201 DefaultScreen (FRAME_X_DISPLAY (f
))))
13203 UNBLOCK_INPUT_RESIGNAL
;
13204 error ("Can't notify window manager of window withdrawal");
13206 #else /* ! defined (HAVE_X11R4) */
13208 /* Tell the window manager what we're going to do. */
13209 if (! EQ (Vx_no_window_manager
, Qt
))
13213 unmap
.xunmap
.type
= UnmapNotify
;
13214 unmap
.xunmap
.window
= window
;
13215 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
13216 unmap
.xunmap
.from_configure
= False
;
13217 if (! XSendEvent (FRAME_X_DISPLAY (f
),
13218 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
13220 SubstructureRedirectMaskSubstructureNotifyMask
,
13223 UNBLOCK_INPUT_RESIGNAL
;
13224 error ("Can't notify window manager of withdrawal");
13228 /* Unmap the window ourselves. Cheeky! */
13229 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
13230 #endif /* ! defined (HAVE_X11R4) */
13232 /* We can't distinguish this from iconification
13233 just by the event that we get from the server.
13234 So we can't win using the usual strategy of letting
13235 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
13236 and synchronize with the server to make sure we agree. */
13238 FRAME_ICONIFIED_P (f
) = 0;
13239 f
->async_visible
= 0;
13240 f
->async_iconified
= 0;
13247 /* Change window state from mapped to iconified. */
13250 x_iconify_frame (f
)
13256 /* Don't keep the highlight on an invisible frame. */
13257 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
13258 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
13260 if (f
->async_iconified
)
13265 FRAME_SAMPLE_VISIBILITY (f
);
13267 type
= x_icon_type (f
);
13269 x_bitmap_icon (f
, type
);
13271 #ifdef USE_X_TOOLKIT
13273 if (! FRAME_VISIBLE_P (f
))
13275 if (! EQ (Vx_no_window_manager
, Qt
))
13276 x_wm_set_window_state (f
, IconicState
);
13277 /* This was XtPopup, but that did nothing for an iconified frame. */
13278 XtMapWidget (f
->output_data
.x
->widget
);
13279 /* The server won't give us any event to indicate
13280 that an invisible frame was changed to an icon,
13281 so we have to record it here. */
13284 f
->async_iconified
= 1;
13285 f
->async_visible
= 0;
13290 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
13291 XtWindow (f
->output_data
.x
->widget
),
13292 DefaultScreen (FRAME_X_DISPLAY (f
)));
13296 error ("Can't notify window manager of iconification");
13298 f
->async_iconified
= 1;
13299 f
->async_visible
= 0;
13303 XFlush (FRAME_X_DISPLAY (f
));
13305 #else /* not USE_X_TOOLKIT */
13307 /* Make sure the X server knows where the window should be positioned,
13308 in case the user deiconifies with the window manager. */
13309 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
13310 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
13312 /* Since we don't know which revision of X we're running, we'll use both
13313 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
13315 /* X11R4: send a ClientMessage to the window manager using the
13316 WM_CHANGE_STATE type. */
13320 message
.xclient
.window
= FRAME_X_WINDOW (f
);
13321 message
.xclient
.type
= ClientMessage
;
13322 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
13323 message
.xclient
.format
= 32;
13324 message
.xclient
.data
.l
[0] = IconicState
;
13326 if (! XSendEvent (FRAME_X_DISPLAY (f
),
13327 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
13329 SubstructureRedirectMask
| SubstructureNotifyMask
,
13332 UNBLOCK_INPUT_RESIGNAL
;
13333 error ("Can't notify window manager of iconification");
13337 /* X11R3: set the initial_state field of the window manager hints to
13339 x_wm_set_window_state (f
, IconicState
);
13341 if (!FRAME_VISIBLE_P (f
))
13343 /* If the frame was withdrawn, before, we must map it. */
13344 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13347 f
->async_iconified
= 1;
13348 f
->async_visible
= 0;
13350 XFlush (FRAME_X_DISPLAY (f
));
13352 #endif /* not USE_X_TOOLKIT */
13356 /* Free X resources of frame F. */
13359 x_free_frame_resources (f
)
13362 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13364 struct scroll_bar
*b
;
13368 /* If a display connection is dead, don't try sending more
13369 commands to the X server. */
13370 if (dpyinfo
->display
)
13372 if (f
->output_data
.x
->icon_desc
)
13373 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
13375 #ifdef USE_X_TOOLKIT
13376 /* Explicitly destroy the scroll bars of the frame. Without
13377 this, we get "BadDrawable" errors from the toolkit later on,
13378 presumably from expose events generated for the disappearing
13379 toolkit scroll bars. */
13380 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
13382 b
= XSCROLL_BAR (bar
);
13383 x_scroll_bar_remove (b
);
13389 free_frame_xic (f
);
13392 #ifdef USE_X_TOOLKIT
13393 if (f
->output_data
.x
->widget
)
13395 XtDestroyWidget (f
->output_data
.x
->widget
);
13396 f
->output_data
.x
->widget
= NULL
;
13398 /* Tooltips don't have widgets, only a simple X window, even if
13399 we are using a toolkit. */
13400 else if (FRAME_X_WINDOW (f
))
13401 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13403 free_frame_menubar (f
);
13404 #else /* !USE_X_TOOLKIT */
13405 if (FRAME_X_WINDOW (f
))
13406 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13407 #endif /* !USE_X_TOOLKIT */
13409 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
13410 unload_color (f
, f
->output_data
.x
->background_pixel
);
13411 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
13412 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
13413 unload_color (f
, f
->output_data
.x
->border_pixel
);
13414 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
13416 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
13417 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
13418 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
13419 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
13420 #ifdef USE_TOOLKIT_SCROLL_BARS
13421 /* Scrollbar shadow colors. */
13422 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
13423 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
13424 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
13425 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
13426 #endif /* USE_TOOLKIT_SCROLL_BARS */
13427 if (f
->output_data
.x
->white_relief
.allocated_p
)
13428 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
13429 if (f
->output_data
.x
->black_relief
.allocated_p
)
13430 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
13432 if (FRAME_FACE_CACHE (f
))
13433 free_frame_faces (f
);
13436 XFlush (FRAME_X_DISPLAY (f
));
13439 if (f
->output_data
.x
->saved_menu_event
)
13440 xfree (f
->output_data
.x
->saved_menu_event
);
13442 xfree (f
->output_data
.x
);
13443 f
->output_data
.x
= NULL
;
13445 if (f
== dpyinfo
->x_focus_frame
)
13446 dpyinfo
->x_focus_frame
= 0;
13447 if (f
== dpyinfo
->x_focus_event_frame
)
13448 dpyinfo
->x_focus_event_frame
= 0;
13449 if (f
== dpyinfo
->x_highlight_frame
)
13450 dpyinfo
->x_highlight_frame
= 0;
13452 if (f
== dpyinfo
->mouse_face_mouse_frame
)
13454 dpyinfo
->mouse_face_beg_row
13455 = dpyinfo
->mouse_face_beg_col
= -1;
13456 dpyinfo
->mouse_face_end_row
13457 = dpyinfo
->mouse_face_end_col
= -1;
13458 dpyinfo
->mouse_face_window
= Qnil
;
13459 dpyinfo
->mouse_face_deferred_gc
= 0;
13460 dpyinfo
->mouse_face_mouse_frame
= 0;
13467 /* Destroy the X window of frame F. */
13470 x_destroy_window (f
)
13473 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13475 /* If a display connection is dead, don't try sending more
13476 commands to the X server. */
13477 if (dpyinfo
->display
!= 0)
13478 x_free_frame_resources (f
);
13480 dpyinfo
->reference_count
--;
13484 /* Setting window manager hints. */
13486 /* Set the normal size hints for the window manager, for frame F.
13487 FLAGS is the flags word to use--or 0 meaning preserve the flags
13488 that the window now has.
13489 If USER_POSITION is nonzero, we set the USPosition
13490 flag (this is useful when FLAGS is 0). */
13493 x_wm_set_size_hint (f
, flags
, user_position
)
13498 XSizeHints size_hints
;
13500 #ifdef USE_X_TOOLKIT
13503 Dimension widget_width
, widget_height
;
13504 Window window
= XtWindow (f
->output_data
.x
->widget
);
13505 #else /* not USE_X_TOOLKIT */
13506 Window window
= FRAME_X_WINDOW (f
);
13507 #endif /* not USE_X_TOOLKIT */
13509 /* Setting PMaxSize caused various problems. */
13510 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
13512 size_hints
.x
= f
->output_data
.x
->left_pos
;
13513 size_hints
.y
= f
->output_data
.x
->top_pos
;
13515 #ifdef USE_X_TOOLKIT
13516 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
13517 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
13518 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
13519 size_hints
.height
= widget_height
;
13520 size_hints
.width
= widget_width
;
13521 #else /* not USE_X_TOOLKIT */
13522 size_hints
.height
= PIXEL_HEIGHT (f
);
13523 size_hints
.width
= PIXEL_WIDTH (f
);
13524 #endif /* not USE_X_TOOLKIT */
13526 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
13527 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
13528 size_hints
.max_width
13529 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
13530 size_hints
.max_height
13531 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
13533 /* Calculate the base and minimum sizes.
13535 (When we use the X toolkit, we don't do it here.
13536 Instead we copy the values that the widgets are using, below.) */
13537 #ifndef USE_X_TOOLKIT
13539 int base_width
, base_height
;
13540 int min_rows
= 0, min_cols
= 0;
13542 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
13543 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
13545 check_frame_size (f
, &min_rows
, &min_cols
);
13547 /* The window manager uses the base width hints to calculate the
13548 current number of rows and columns in the frame while
13549 resizing; min_width and min_height aren't useful for this
13550 purpose, since they might not give the dimensions for a
13551 zero-row, zero-column frame.
13553 We use the base_width and base_height members if we have
13554 them; otherwise, we set the min_width and min_height members
13555 to the size for a zero x zero frame. */
13558 size_hints
.flags
|= PBaseSize
;
13559 size_hints
.base_width
= base_width
;
13560 size_hints
.base_height
= base_height
;
13561 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
13562 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
13564 size_hints
.min_width
= base_width
;
13565 size_hints
.min_height
= base_height
;
13569 /* If we don't need the old flags, we don't need the old hint at all. */
13572 size_hints
.flags
|= flags
;
13575 #endif /* not USE_X_TOOLKIT */
13578 XSizeHints hints
; /* Sometimes I hate X Windows... */
13579 long supplied_return
;
13583 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
13586 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
13589 #ifdef USE_X_TOOLKIT
13590 size_hints
.base_height
= hints
.base_height
;
13591 size_hints
.base_width
= hints
.base_width
;
13592 size_hints
.min_height
= hints
.min_height
;
13593 size_hints
.min_width
= hints
.min_width
;
13597 size_hints
.flags
|= flags
;
13602 if (hints
.flags
& PSize
)
13603 size_hints
.flags
|= PSize
;
13604 if (hints
.flags
& PPosition
)
13605 size_hints
.flags
|= PPosition
;
13606 if (hints
.flags
& USPosition
)
13607 size_hints
.flags
|= USPosition
;
13608 if (hints
.flags
& USSize
)
13609 size_hints
.flags
|= USSize
;
13613 #ifndef USE_X_TOOLKIT
13618 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
13619 size_hints
.flags
|= PWinGravity
;
13623 size_hints
.flags
&= ~ PPosition
;
13624 size_hints
.flags
|= USPosition
;
13626 #endif /* PWinGravity */
13629 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
13631 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
13635 /* Used for IconicState or NormalState */
13638 x_wm_set_window_state (f
, state
)
13642 #ifdef USE_X_TOOLKIT
13645 XtSetArg (al
[0], XtNinitialState
, state
);
13646 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
13647 #else /* not USE_X_TOOLKIT */
13648 Window window
= FRAME_X_WINDOW (f
);
13650 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
13651 f
->output_data
.x
->wm_hints
.initial_state
= state
;
13653 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
13654 #endif /* not USE_X_TOOLKIT */
13658 x_wm_set_icon_pixmap (f
, pixmap_id
)
13662 Pixmap icon_pixmap
;
13664 #ifndef USE_X_TOOLKIT
13665 Window window
= FRAME_X_WINDOW (f
);
13670 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
13671 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
13675 /* It seems there is no way to turn off use of an icon pixmap.
13676 The following line does it, only if no icon has yet been created,
13677 for some window managers. But with mwm it crashes.
13678 Some people say it should clear the IconPixmapHint bit in this case,
13679 but that doesn't work, and the X consortium said it isn't the
13680 right thing at all. Since there is no way to win,
13681 best to explicitly give up. */
13683 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
13689 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
13693 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
13694 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
13697 #else /* not USE_X_TOOLKIT */
13699 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
13700 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
13702 #endif /* not USE_X_TOOLKIT */
13706 x_wm_set_icon_position (f
, icon_x
, icon_y
)
13708 int icon_x
, icon_y
;
13710 #ifdef USE_X_TOOLKIT
13711 Window window
= XtWindow (f
->output_data
.x
->widget
);
13713 Window window
= FRAME_X_WINDOW (f
);
13716 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
13717 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
13718 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
13720 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
13724 /***********************************************************************
13726 ***********************************************************************/
13728 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
13731 x_get_font_info (f
, font_idx
)
13735 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
13739 /* Return a list of names of available fonts matching PATTERN on frame F.
13741 If SIZE is > 0, it is the size (maximum bounds width) of fonts
13744 SIZE < 0 means include scalable fonts.
13746 Frame F null means we have not yet created any frame on X, and
13747 consult the first display in x_display_list. MAXNAMES sets a limit
13748 on how many fonts to match. */
13751 x_list_fonts (f
, pattern
, size
, maxnames
)
13753 Lisp_Object pattern
;
13757 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
13758 Lisp_Object tem
, second_best
;
13759 struct x_display_info
*dpyinfo
13760 = f
? FRAME_X_DISPLAY_INFO (f
) : x_display_list
;
13761 Display
*dpy
= dpyinfo
->display
;
13762 int try_XLoadQueryFont
= 0;
13764 int allow_scalable_fonts_p
= 0;
13768 allow_scalable_fonts_p
= 1;
13772 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
13773 if (NILP (patterns
))
13774 patterns
= Fcons (pattern
, Qnil
);
13776 if (maxnames
== 1 && !size
)
13777 /* We can return any single font matching PATTERN. */
13778 try_XLoadQueryFont
= 1;
13780 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
13783 char **names
= NULL
;
13785 pattern
= XCAR (patterns
);
13786 /* See if we cached the result for this particular query.
13787 The cache is an alist of the form:
13788 ((((PATTERN . MAXNAMES) . SCALABLE) (FONTNAME . WIDTH) ...) ...) */
13789 tem
= XCDR (dpyinfo
->name_list_element
);
13790 key
= Fcons (Fcons (pattern
, make_number (maxnames
)),
13791 allow_scalable_fonts_p
? Qt
: Qnil
);
13792 list
= Fassoc (key
, tem
);
13795 list
= Fcdr_safe (list
);
13796 /* We have a cashed list. Don't have to get the list again. */
13800 /* At first, put PATTERN in the cache. */
13803 count
= x_catch_errors (dpy
);
13805 if (try_XLoadQueryFont
)
13808 unsigned long value
;
13810 font
= XLoadQueryFont (dpy
, XSTRING (pattern
)->data
);
13811 if (x_had_errors_p (dpy
))
13813 /* This error is perhaps due to insufficient memory on X
13814 server. Let's just ignore it. */
13816 x_clear_errors (dpy
);
13820 && XGetFontProperty (font
, XA_FONT
, &value
))
13822 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
13823 int len
= strlen (name
);
13826 /* If DXPC (a Differential X Protocol Compressor)
13827 Ver.3.7 is running, XGetAtomName will return null
13828 string. We must avoid such a name. */
13830 try_XLoadQueryFont
= 0;
13834 names
= (char **) alloca (sizeof (char *));
13835 /* Some systems only allow alloca assigned to a
13837 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
13838 bcopy (name
, names
[0], len
+ 1);
13843 try_XLoadQueryFont
= 0;
13846 XFreeFont (dpy
, font
);
13849 if (!try_XLoadQueryFont
)
13851 /* We try at least 10 fonts because XListFonts will return
13852 auto-scaled fonts at the head. */
13853 names
= XListFonts (dpy
, XSTRING (pattern
)->data
, max (maxnames
, 10),
13855 if (x_had_errors_p (dpy
))
13857 /* This error is perhaps due to insufficient memory on X
13858 server. Let's just ignore it. */
13860 x_clear_errors (dpy
);
13864 x_uncatch_errors (dpy
, count
);
13871 /* Make a list of all the fonts we got back.
13872 Store that in the font cache for the display. */
13873 for (i
= 0; i
< num_fonts
; i
++)
13876 char *p
= names
[i
];
13877 int average_width
= -1, dashes
= 0;
13879 /* Count the number of dashes in NAMES[I]. If there are
13880 14 dashes, and the field value following 12th dash
13881 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
13882 is usually too ugly to be used for editing. Let's
13888 if (dashes
== 7) /* PIXEL_SIZE field */
13890 else if (dashes
== 12) /* AVERAGE_WIDTH field */
13891 average_width
= atoi (p
);
13894 if (allow_scalable_fonts_p
13895 || dashes
< 14 || average_width
!= 0)
13897 tem
= build_string (names
[i
]);
13898 if (NILP (Fassoc (tem
, list
)))
13900 if (STRINGP (Vx_pixel_size_width_font_regexp
)
13901 && ((fast_c_string_match_ignore_case
13902 (Vx_pixel_size_width_font_regexp
, names
[i
]))
13904 /* We can set the value of PIXEL_SIZE to the
13905 width of this font. */
13906 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
13908 /* For the moment, width is not known. */
13909 list
= Fcons (Fcons (tem
, Qnil
), list
);
13914 if (!try_XLoadQueryFont
)
13917 XFreeFontNames (names
);
13922 /* Now store the result in the cache. */
13923 XSETCDR (dpyinfo
->name_list_element
,
13924 Fcons (Fcons (key
, list
), XCDR (dpyinfo
->name_list_element
)));
13927 if (NILP (list
)) continue; /* Try the remaining alternatives. */
13929 newlist
= second_best
= Qnil
;
13930 /* Make a list of the fonts that have the right width. */
13931 for (; CONSP (list
); list
= XCDR (list
))
13937 if (!CONSP (tem
) || NILP (XCAR (tem
)))
13941 newlist
= Fcons (XCAR (tem
), newlist
);
13945 if (!INTEGERP (XCDR (tem
)))
13947 /* Since we have not yet known the size of this font, we
13948 must try slow function call XLoadQueryFont. */
13949 XFontStruct
*thisinfo
;
13952 count
= x_catch_errors (dpy
);
13953 thisinfo
= XLoadQueryFont (dpy
,
13954 XSTRING (XCAR (tem
))->data
);
13955 if (x_had_errors_p (dpy
))
13957 /* This error is perhaps due to insufficient memory on X
13958 server. Let's just ignore it. */
13960 x_clear_errors (dpy
);
13962 x_uncatch_errors (dpy
, count
);
13968 (thisinfo
->min_bounds
.width
== 0
13970 : make_number (thisinfo
->max_bounds
.width
)));
13972 XFreeFont (dpy
, thisinfo
);
13976 /* For unknown reason, the previous call of XListFont had
13977 returned a font which can't be opened. Record the size
13978 as 0 not to try to open it again. */
13979 XSETCDR (tem
, make_number (0));
13982 found_size
= XINT (XCDR (tem
));
13983 if (found_size
== size
)
13984 newlist
= Fcons (XCAR (tem
), newlist
);
13985 else if (found_size
> 0)
13987 if (NILP (second_best
))
13989 else if (found_size
< size
)
13991 if (XINT (XCDR (second_best
)) > size
13992 || XINT (XCDR (second_best
)) < found_size
)
13997 if (XINT (XCDR (second_best
)) > size
13998 && XINT (XCDR (second_best
)) > found_size
)
14003 if (!NILP (newlist
))
14005 else if (!NILP (second_best
))
14007 newlist
= Fcons (XCAR (second_best
), Qnil
);
14018 /* Check that FONT is valid on frame F. It is if it can be found in F's
14022 x_check_font (f
, font
)
14027 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14029 xassert (font
!= NULL
);
14031 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
14032 if (dpyinfo
->font_table
[i
].name
14033 && font
== dpyinfo
->font_table
[i
].font
)
14036 xassert (i
< dpyinfo
->n_fonts
);
14039 #endif /* GLYPH_DEBUG != 0 */
14041 /* Set *W to the minimum width, *H to the minimum font height of FONT.
14042 Note: There are (broken) X fonts out there with invalid XFontStruct
14043 min_bounds contents. For example, handa@etl.go.jp reports that
14044 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
14045 have font->min_bounds.width == 0. */
14048 x_font_min_bounds (font
, w
, h
)
14052 *h
= FONT_HEIGHT (font
);
14053 *w
= font
->min_bounds
.width
;
14055 /* Try to handle the case where FONT->min_bounds has invalid
14056 contents. Since the only font known to have invalid min_bounds
14057 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
14059 *w
= font
->max_bounds
.width
;
14063 /* Compute the smallest character width and smallest font height over
14064 all fonts available on frame F. Set the members smallest_char_width
14065 and smallest_font_height in F's x_display_info structure to
14066 the values computed. Value is non-zero if smallest_font_height or
14067 smallest_char_width become smaller than they were before. */
14070 x_compute_min_glyph_bounds (f
)
14074 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14076 int old_width
= dpyinfo
->smallest_char_width
;
14077 int old_height
= dpyinfo
->smallest_font_height
;
14079 dpyinfo
->smallest_font_height
= 100000;
14080 dpyinfo
->smallest_char_width
= 100000;
14082 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
14083 if (dpyinfo
->font_table
[i
].name
)
14085 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
14088 font
= (XFontStruct
*) fontp
->font
;
14089 xassert (font
!= (XFontStruct
*) ~0);
14090 x_font_min_bounds (font
, &w
, &h
);
14092 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
14093 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
14096 xassert (dpyinfo
->smallest_char_width
> 0
14097 && dpyinfo
->smallest_font_height
> 0);
14099 return (dpyinfo
->n_fonts
== 1
14100 || dpyinfo
->smallest_char_width
< old_width
14101 || dpyinfo
->smallest_font_height
< old_height
);
14105 /* Load font named FONTNAME of the size SIZE for frame F, and return a
14106 pointer to the structure font_info while allocating it dynamically.
14107 If SIZE is 0, load any size of font.
14108 If loading is failed, return NULL. */
14111 x_load_font (f
, fontname
, size
)
14113 register char *fontname
;
14116 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14117 Lisp_Object font_names
;
14120 /* Get a list of all the fonts that match this name. Once we
14121 have a list of matching fonts, we compare them against the fonts
14122 we already have by comparing names. */
14123 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
14125 if (!NILP (font_names
))
14130 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
14131 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
14132 if (dpyinfo
->font_table
[i
].name
14133 && (!strcmp (dpyinfo
->font_table
[i
].name
,
14134 XSTRING (XCAR (tail
))->data
)
14135 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
14136 XSTRING (XCAR (tail
))->data
)))
14137 return (dpyinfo
->font_table
+ i
);
14140 /* Load the font and add it to the table. */
14144 struct font_info
*fontp
;
14145 unsigned long value
;
14148 /* If we have found fonts by x_list_font, load one of them. If
14149 not, we still try to load a font by the name given as FONTNAME
14150 because XListFonts (called in x_list_font) of some X server has
14151 a bug of not finding a font even if the font surely exists and
14152 is loadable by XLoadQueryFont. */
14153 if (size
> 0 && !NILP (font_names
))
14154 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
14157 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
14158 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
14159 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
14161 /* This error is perhaps due to insufficient memory on X
14162 server. Let's just ignore it. */
14164 x_clear_errors (FRAME_X_DISPLAY (f
));
14166 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
14171 /* Find a free slot in the font table. */
14172 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
14173 if (dpyinfo
->font_table
[i
].name
== NULL
)
14176 /* If no free slot found, maybe enlarge the font table. */
14177 if (i
== dpyinfo
->n_fonts
14178 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
14181 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
14182 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
14183 dpyinfo
->font_table
14184 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
14187 fontp
= dpyinfo
->font_table
+ i
;
14188 if (i
== dpyinfo
->n_fonts
)
14189 ++dpyinfo
->n_fonts
;
14191 /* Now fill in the slots of *FONTP. */
14193 fontp
->font
= font
;
14194 fontp
->font_idx
= i
;
14195 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
14196 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
14198 /* Try to get the full name of FONT. Put it in FULL_NAME. */
14200 if (XGetFontProperty (font
, XA_FONT
, &value
))
14202 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
14206 /* Count the number of dashes in the "full name".
14207 If it is too few, this isn't really the font's full name,
14209 In X11R4, the fonts did not come with their canonical names
14220 full_name
= (char *) xmalloc (p
- name
+ 1);
14221 bcopy (name
, full_name
, p
- name
+ 1);
14227 if (full_name
!= 0)
14228 fontp
->full_name
= full_name
;
14230 fontp
->full_name
= fontp
->name
;
14232 fontp
->size
= font
->max_bounds
.width
;
14233 fontp
->height
= FONT_HEIGHT (font
);
14235 if (NILP (font_names
))
14237 /* We come here because of a bug of XListFonts mentioned at
14238 the head of this block. Let's store this information in
14239 the cache for x_list_fonts. */
14240 Lisp_Object lispy_name
= build_string (fontname
);
14241 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
14242 Lisp_Object key
= Fcons (Fcons (lispy_name
, make_number (256)),
14245 XSETCDR (dpyinfo
->name_list_element
,
14247 Fcons (Fcons (lispy_full_name
,
14248 make_number (fontp
->size
)),
14250 XCDR (dpyinfo
->name_list_element
)));
14253 key
= Fcons (Fcons (lispy_full_name
, make_number (256)),
14255 XSETCDR (dpyinfo
->name_list_element
,
14257 Fcons (Fcons (lispy_full_name
,
14258 make_number (fontp
->size
)),
14260 XCDR (dpyinfo
->name_list_element
)));
14264 /* The slot `encoding' specifies how to map a character
14265 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
14266 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
14267 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
14268 2:0xA020..0xFF7F). For the moment, we don't know which charset
14269 uses this font. So, we set information in fontp->encoding[1]
14270 which is never used by any charset. If mapping can't be
14271 decided, set FONT_ENCODING_NOT_DECIDED. */
14273 = (font
->max_byte1
== 0
14275 ? (font
->min_char_or_byte2
< 0x80
14276 ? (font
->max_char_or_byte2
< 0x80
14277 ? 0 /* 0x20..0x7F */
14278 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
14279 : 1) /* 0xA0..0xFF */
14281 : (font
->min_byte1
< 0x80
14282 ? (font
->max_byte1
< 0x80
14283 ? (font
->min_char_or_byte2
< 0x80
14284 ? (font
->max_char_or_byte2
< 0x80
14285 ? 0 /* 0x2020..0x7F7F */
14286 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
14287 : 3) /* 0x20A0..0x7FFF */
14288 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
14289 : (font
->min_char_or_byte2
< 0x80
14290 ? (font
->max_char_or_byte2
< 0x80
14291 ? 2 /* 0xA020..0xFF7F */
14292 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
14293 : 1))); /* 0xA0A0..0xFFFF */
14295 fontp
->baseline_offset
14296 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
14297 ? (long) value
: 0);
14298 fontp
->relative_compose
14299 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
14300 ? (long) value
: 0);
14301 fontp
->default_ascent
14302 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
14303 ? (long) value
: 0);
14305 /* Set global flag fonts_changed_p to non-zero if the font loaded
14306 has a character with a smaller width than any other character
14307 before, or if the font loaded has a smaller height than any
14308 other font loaded before. If this happens, it will make a
14309 glyph matrix reallocation necessary. */
14310 fonts_changed_p
|= x_compute_min_glyph_bounds (f
);
14317 /* Return a pointer to struct font_info of a font named FONTNAME for
14318 frame F. If no such font is loaded, return NULL. */
14321 x_query_font (f
, fontname
)
14323 register char *fontname
;
14325 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14328 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
14329 if (dpyinfo
->font_table
[i
].name
14330 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
14331 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
14332 return (dpyinfo
->font_table
+ i
);
14337 /* Find a CCL program for a font specified by FONTP, and set the member
14338 `encoder' of the structure. */
14341 x_find_ccl_program (fontp
)
14342 struct font_info
*fontp
;
14344 Lisp_Object list
, elt
;
14347 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
14351 && STRINGP (XCAR (elt
))
14352 && ((fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
14354 || (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->full_name
)
14361 struct ccl_program
*ccl
14362 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
14364 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
14367 fontp
->font_encoder
= ccl
;
14373 /***********************************************************************
14375 ***********************************************************************/
14377 #ifdef USE_X_TOOLKIT
14378 static XrmOptionDescRec emacs_options
[] = {
14379 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
14380 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
14382 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
14383 XrmoptionSepArg
, NULL
},
14384 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
14386 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
14387 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
14388 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
14389 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
14390 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
14391 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
14392 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
14394 #endif /* USE_X_TOOLKIT */
14396 static int x_initialized
;
14398 #ifdef MULTI_KBOARD
14399 /* Test whether two display-name strings agree up to the dot that separates
14400 the screen number from the server number. */
14402 same_x_server (name1
, name2
)
14403 char *name1
, *name2
;
14405 int seen_colon
= 0;
14406 unsigned char *system_name
= XSTRING (Vsystem_name
)->data
;
14407 int system_name_length
= strlen (system_name
);
14408 int length_until_period
= 0;
14410 while (system_name
[length_until_period
] != 0
14411 && system_name
[length_until_period
] != '.')
14412 length_until_period
++;
14414 /* Treat `unix' like an empty host name. */
14415 if (! strncmp (name1
, "unix:", 5))
14417 if (! strncmp (name2
, "unix:", 5))
14419 /* Treat this host's name like an empty host name. */
14420 if (! strncmp (name1
, system_name
, system_name_length
)
14421 && name1
[system_name_length
] == ':')
14422 name1
+= system_name_length
;
14423 if (! strncmp (name2
, system_name
, system_name_length
)
14424 && name2
[system_name_length
] == ':')
14425 name2
+= system_name_length
;
14426 /* Treat this host's domainless name like an empty host name. */
14427 if (! strncmp (name1
, system_name
, length_until_period
)
14428 && name1
[length_until_period
] == ':')
14429 name1
+= length_until_period
;
14430 if (! strncmp (name2
, system_name
, length_until_period
)
14431 && name2
[length_until_period
] == ':')
14432 name2
+= length_until_period
;
14434 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
14438 if (seen_colon
&& *name1
== '.')
14442 && (*name1
== '.' || *name1
== '\0')
14443 && (*name2
== '.' || *name2
== '\0'));
14447 struct x_display_info
*
14448 x_term_init (display_name
, xrm_option
, resource_name
)
14449 Lisp_Object display_name
;
14451 char *resource_name
;
14455 struct x_display_info
*dpyinfo
;
14460 if (!x_initialized
)
14466 #ifdef USE_X_TOOLKIT
14467 /* weiner@footloose.sps.mot.com reports that this causes
14469 X protocol error: BadAtom (invalid Atom parameter)
14470 on protocol request 18skiloaf.
14471 So let's not use it until R6. */
14472 #ifdef HAVE_X11XTR6
14473 XtSetLanguageProc (NULL
, NULL
, NULL
);
14484 argv
[argc
++] = "-xrm";
14485 argv
[argc
++] = xrm_option
;
14487 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
14488 resource_name
, EMACS_CLASS
,
14489 emacs_options
, XtNumber (emacs_options
),
14492 #ifdef HAVE_X11XTR6
14493 /* I think this is to compensate for XtSetLanguageProc. */
14498 #else /* not USE_X_TOOLKIT */
14500 XSetLocaleModifiers ("");
14502 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
14503 #endif /* not USE_X_TOOLKIT */
14505 /* Detect failure. */
14512 /* We have definitely succeeded. Record the new connection. */
14514 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
14515 bzero (dpyinfo
, sizeof *dpyinfo
);
14517 #ifdef MULTI_KBOARD
14519 struct x_display_info
*share
;
14522 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
14523 share
= share
->next
, tail
= XCDR (tail
))
14524 if (same_x_server (XSTRING (XCAR (XCAR (tail
)))->data
,
14525 XSTRING (display_name
)->data
))
14528 dpyinfo
->kboard
= share
->kboard
;
14531 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
14532 init_kboard (dpyinfo
->kboard
);
14533 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
14535 char *vendor
= ServerVendor (dpy
);
14537 dpyinfo
->kboard
->Vsystem_key_alist
14538 = call1 (Qvendor_specific_keysyms
,
14539 build_string (vendor
? vendor
: ""));
14543 dpyinfo
->kboard
->next_kboard
= all_kboards
;
14544 all_kboards
= dpyinfo
->kboard
;
14545 /* Don't let the initial kboard remain current longer than necessary.
14546 That would cause problems if a file loaded on startup tries to
14547 prompt in the mini-buffer. */
14548 if (current_kboard
== initial_kboard
)
14549 current_kboard
= dpyinfo
->kboard
;
14551 dpyinfo
->kboard
->reference_count
++;
14555 /* Put this display on the chain. */
14556 dpyinfo
->next
= x_display_list
;
14557 x_display_list
= dpyinfo
;
14559 /* Put it on x_display_name_list as well, to keep them parallel. */
14560 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
14561 x_display_name_list
);
14562 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
14564 dpyinfo
->display
= dpy
;
14567 XSetAfterFunction (x_current_display
, x_trace_wire
);
14571 = (char *) xmalloc (STRING_BYTES (XSTRING (Vinvocation_name
))
14572 + STRING_BYTES (XSTRING (Vsystem_name
))
14574 sprintf (dpyinfo
->x_id_name
, "%s@%s",
14575 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
14577 /* Figure out which modifier bits mean what. */
14578 x_find_modifier_meanings (dpyinfo
);
14580 /* Get the scroll bar cursor. */
14581 dpyinfo
->vertical_scroll_bar_cursor
14582 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
14584 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
14585 resource_name
, EMACS_CLASS
);
14586 #ifdef HAVE_XRMSETDATABASE
14587 XrmSetDatabase (dpyinfo
->display
, xrdb
);
14589 dpyinfo
->display
->db
= xrdb
;
14591 /* Put the rdb where we can find it in a way that works on
14593 dpyinfo
->xrdb
= xrdb
;
14595 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
14596 DefaultScreen (dpyinfo
->display
));
14597 select_visual (dpyinfo
);
14598 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
14599 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
14600 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
14601 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
14602 dpyinfo
->grabbed
= 0;
14603 dpyinfo
->reference_count
= 0;
14604 dpyinfo
->icon_bitmap_id
= -1;
14605 dpyinfo
->font_table
= NULL
;
14606 dpyinfo
->n_fonts
= 0;
14607 dpyinfo
->font_table_size
= 0;
14608 dpyinfo
->bitmaps
= 0;
14609 dpyinfo
->bitmaps_size
= 0;
14610 dpyinfo
->bitmaps_last
= 0;
14611 dpyinfo
->scratch_cursor_gc
= 0;
14612 dpyinfo
->mouse_face_mouse_frame
= 0;
14613 dpyinfo
->mouse_face_deferred_gc
= 0;
14614 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
14615 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
14616 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
14617 dpyinfo
->mouse_face_window
= Qnil
;
14618 dpyinfo
->mouse_face_overlay
= Qnil
;
14619 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
14620 dpyinfo
->mouse_face_defer
= 0;
14621 dpyinfo
->x_focus_frame
= 0;
14622 dpyinfo
->x_focus_event_frame
= 0;
14623 dpyinfo
->x_highlight_frame
= 0;
14624 dpyinfo
->image_cache
= make_image_cache ();
14626 /* See if a private colormap is requested. */
14627 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
14629 if (dpyinfo
->visual
->class == PseudoColor
)
14632 value
= display_x_get_resource (dpyinfo
,
14633 build_string ("privateColormap"),
14634 build_string ("PrivateColormap"),
14636 if (STRINGP (value
)
14637 && (!strcmp (XSTRING (value
)->data
, "true")
14638 || !strcmp (XSTRING (value
)->data
, "on")))
14639 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
14643 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
14644 dpyinfo
->visual
, AllocNone
);
14647 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
14648 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
14649 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
14650 dpyinfo
->resy
= pixels
* 25.4 / mm
;
14651 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
14652 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
14653 dpyinfo
->resx
= pixels
* 25.4 / mm
;
14656 dpyinfo
->Xatom_wm_protocols
14657 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
14658 dpyinfo
->Xatom_wm_take_focus
14659 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
14660 dpyinfo
->Xatom_wm_save_yourself
14661 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
14662 dpyinfo
->Xatom_wm_delete_window
14663 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
14664 dpyinfo
->Xatom_wm_change_state
14665 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
14666 dpyinfo
->Xatom_wm_configure_denied
14667 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
14668 dpyinfo
->Xatom_wm_window_moved
14669 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
14670 dpyinfo
->Xatom_editres
14671 = XInternAtom (dpyinfo
->display
, "Editres", False
);
14672 dpyinfo
->Xatom_CLIPBOARD
14673 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
14674 dpyinfo
->Xatom_TIMESTAMP
14675 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
14676 dpyinfo
->Xatom_TEXT
14677 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
14678 dpyinfo
->Xatom_COMPOUND_TEXT
14679 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
14680 dpyinfo
->Xatom_DELETE
14681 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
14682 dpyinfo
->Xatom_MULTIPLE
14683 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
14684 dpyinfo
->Xatom_INCR
14685 = XInternAtom (dpyinfo
->display
, "INCR", False
);
14686 dpyinfo
->Xatom_EMACS_TMP
14687 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
14688 dpyinfo
->Xatom_TARGETS
14689 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
14690 dpyinfo
->Xatom_NULL
14691 = XInternAtom (dpyinfo
->display
, "NULL", False
);
14692 dpyinfo
->Xatom_ATOM_PAIR
14693 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
14694 /* For properties of font. */
14695 dpyinfo
->Xatom_PIXEL_SIZE
14696 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
14697 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
14698 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
14699 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
14700 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
14701 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
14702 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
14704 /* Ghostscript support. */
14705 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
14706 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
14708 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
14711 dpyinfo
->cut_buffers_initialized
= 0;
14713 connection
= ConnectionNumber (dpyinfo
->display
);
14714 dpyinfo
->connection
= connection
;
14719 null_bits
[0] = 0x00;
14721 dpyinfo
->null_pixel
14722 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
14723 null_bits
, 1, 1, (long) 0, (long) 0,
14728 extern int gray_bitmap_width
, gray_bitmap_height
;
14729 extern char *gray_bitmap_bits
;
14731 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
14733 gray_bitmap_width
, gray_bitmap_height
,
14734 (unsigned long) 1, (unsigned long) 0, 1);
14738 xim_initialize (dpyinfo
, resource_name
);
14741 #ifdef subprocesses
14742 /* This is only needed for distinguishing keyboard and process input. */
14743 if (connection
!= 0)
14744 add_keyboard_wait_descriptor (connection
);
14747 #ifndef F_SETOWN_BUG
14749 #ifdef F_SETOWN_SOCK_NEG
14750 /* stdin is a socket here */
14751 fcntl (connection
, F_SETOWN
, -getpid ());
14752 #else /* ! defined (F_SETOWN_SOCK_NEG) */
14753 fcntl (connection
, F_SETOWN
, getpid ());
14754 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
14755 #endif /* ! defined (F_SETOWN) */
14756 #endif /* F_SETOWN_BUG */
14759 if (interrupt_input
)
14760 init_sigio (connection
);
14761 #endif /* ! defined (SIGIO) */
14764 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
14765 /* Make sure that we have a valid font for dialog boxes
14766 so that Xt does not crash. */
14768 Display
*dpy
= dpyinfo
->display
;
14769 XrmValue d
, fr
, to
;
14773 d
.addr
= (XPointer
)&dpy
;
14774 d
.size
= sizeof (Display
*);
14775 fr
.addr
= XtDefaultFont
;
14776 fr
.size
= sizeof (XtDefaultFont
);
14777 to
.size
= sizeof (Font
*);
14778 to
.addr
= (XPointer
)&font
;
14779 count
= x_catch_errors (dpy
);
14780 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
14782 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
14783 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
14784 x_uncatch_errors (dpy
, count
);
14789 /* See if we should run in synchronous mode. This is useful
14790 for debugging X code. */
14793 value
= display_x_get_resource (dpyinfo
,
14794 build_string ("synchronous"),
14795 build_string ("Synchronous"),
14797 if (STRINGP (value
)
14798 && (!strcmp (XSTRING (value
)->data
, "true")
14799 || !strcmp (XSTRING (value
)->data
, "on")))
14800 XSynchronize (dpyinfo
->display
, True
);
14808 /* Get rid of display DPYINFO, assuming all frames are already gone,
14809 and without sending any more commands to the X server. */
14812 x_delete_display (dpyinfo
)
14813 struct x_display_info
*dpyinfo
;
14815 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
14817 /* Discard this display from x_display_name_list and x_display_list.
14818 We can't use Fdelq because that can quit. */
14819 if (! NILP (x_display_name_list
)
14820 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
14821 x_display_name_list
= XCDR (x_display_name_list
);
14826 tail
= x_display_name_list
;
14827 while (CONSP (tail
) && CONSP (XCDR (tail
)))
14829 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
14831 XSETCDR (tail
, XCDR (XCDR (tail
)));
14834 tail
= XCDR (tail
);
14838 if (next_noop_dpyinfo
== dpyinfo
)
14839 next_noop_dpyinfo
= dpyinfo
->next
;
14841 if (x_display_list
== dpyinfo
)
14842 x_display_list
= dpyinfo
->next
;
14845 struct x_display_info
*tail
;
14847 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
14848 if (tail
->next
== dpyinfo
)
14849 tail
->next
= tail
->next
->next
;
14852 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
14853 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
14854 XrmDestroyDatabase (dpyinfo
->xrdb
);
14857 #ifdef MULTI_KBOARD
14858 if (--dpyinfo
->kboard
->reference_count
== 0)
14859 delete_kboard (dpyinfo
->kboard
);
14863 xim_close_dpy (dpyinfo
);
14866 xfree (dpyinfo
->font_table
);
14867 xfree (dpyinfo
->x_id_name
);
14868 xfree (dpyinfo
->color_cells
);
14873 /* Set up use of X before we make the first connection. */
14875 static struct redisplay_interface x_redisplay_interface
=
14880 x_clear_end_of_line
,
14882 x_after_update_window_line
,
14883 x_update_window_begin
,
14884 x_update_window_end
,
14887 x_clear_mouse_face
,
14888 x_get_glyph_overhangs
,
14889 x_fix_overlapping_area
14895 rif
= &x_redisplay_interface
;
14897 clear_frame_hook
= x_clear_frame
;
14898 ins_del_lines_hook
= x_ins_del_lines
;
14899 delete_glyphs_hook
= x_delete_glyphs
;
14900 ring_bell_hook
= XTring_bell
;
14901 reset_terminal_modes_hook
= XTreset_terminal_modes
;
14902 set_terminal_modes_hook
= XTset_terminal_modes
;
14903 update_begin_hook
= x_update_begin
;
14904 update_end_hook
= x_update_end
;
14905 set_terminal_window_hook
= XTset_terminal_window
;
14906 read_socket_hook
= XTread_socket
;
14907 frame_up_to_date_hook
= XTframe_up_to_date
;
14908 mouse_position_hook
= XTmouse_position
;
14909 frame_rehighlight_hook
= XTframe_rehighlight
;
14910 frame_raise_lower_hook
= XTframe_raise_lower
;
14911 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
14912 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
14913 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
14914 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
14915 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
14917 scroll_region_ok
= 1; /* we'll scroll partial frames */
14918 char_ins_del_ok
= 1;
14919 line_ins_del_ok
= 1; /* we'll just blt 'em */
14920 fast_clear_end_of_line
= 1; /* X does this well */
14921 memory_below_frame
= 0; /* we don't remember what scrolls
14926 last_tool_bar_item
= -1;
14927 any_help_event_p
= 0;
14929 /* Try to use interrupt input; if we can't, then start polling. */
14930 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
14932 #ifdef USE_X_TOOLKIT
14933 XtToolkitInitialize ();
14935 Xt_app_con
= XtCreateApplicationContext ();
14937 /* Register a converter from strings to pixels, which uses
14938 Emacs' color allocation infrastructure. */
14939 XtAppSetTypeConverter (Xt_app_con
,
14940 XtRString
, XtRPixel
, cvt_string_to_pixel
,
14941 cvt_string_to_pixel_args
,
14942 XtNumber (cvt_string_to_pixel_args
),
14943 XtCacheByDisplay
, cvt_pixel_dtor
);
14945 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
14947 /* Install an asynchronous timer that processes Xt timeout events
14948 every 0.1s. This is necessary because some widget sets use
14949 timeouts internally, for example the LessTif menu bar, or the
14950 Xaw3d scroll bar. When Xt timouts aren't processed, these
14951 widgets don't behave normally. */
14953 EMACS_TIME interval
;
14954 EMACS_SET_SECS_USECS (interval
, 0, 100000);
14955 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
14959 #ifdef USE_TOOLKIT_SCROLL_BARS
14960 xaw3d_arrow_scroll
= False
;
14961 xaw3d_pick_top
= True
;
14964 /* Note that there is no real way portable across R3/R4 to get the
14965 original error handler. */
14966 XSetErrorHandler (x_error_handler
);
14967 XSetIOErrorHandler (x_io_error_quitter
);
14969 /* Disable Window Change signals; they are handled by X events. */
14971 signal (SIGWINCH
, SIG_DFL
);
14972 #endif /* ! defined (SIGWINCH) */
14974 signal (SIGPIPE
, x_connection_signal
);
14981 staticpro (&x_error_message_string
);
14982 x_error_message_string
= Qnil
;
14984 staticpro (&x_display_name_list
);
14985 x_display_name_list
= Qnil
;
14987 staticpro (&last_mouse_scroll_bar
);
14988 last_mouse_scroll_bar
= Qnil
;
14990 staticpro (&Qvendor_specific_keysyms
);
14991 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
14993 staticpro (&last_mouse_press_frame
);
14994 last_mouse_press_frame
= Qnil
;
14997 staticpro (&help_echo
);
14998 help_echo_object
= Qnil
;
14999 staticpro (&help_echo_object
);
15000 help_echo_window
= Qnil
;
15001 staticpro (&help_echo_window
);
15002 previous_help_echo
= Qnil
;
15003 staticpro (&previous_help_echo
);
15004 help_echo_pos
= -1;
15006 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
15007 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
15008 For example, if a block cursor is over a tab, it will be drawn as
15009 wide as that tab on the display. */);
15010 x_stretch_cursor_p
= 0;
15012 DEFVAR_BOOL ("x-use-underline-position-properties",
15013 &x_use_underline_position_properties
,
15014 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
15015 nil means ignore them. If you encounter fonts with bogus
15016 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
15017 to 4.1, set this to nil. */);
15018 x_use_underline_position_properties
= 1;
15020 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
15021 doc
: /* What X toolkit scroll bars Emacs uses.
15022 A value of nil means Emacs doesn't use X toolkit scroll bars.
15023 Otherwise, value is a symbol describing the X toolkit. */);
15024 #ifdef USE_TOOLKIT_SCROLL_BARS
15026 Vx_toolkit_scroll_bars
= intern ("motif");
15027 #elif defined HAVE_XAW3D
15028 Vx_toolkit_scroll_bars
= intern ("xaw3d");
15030 Vx_toolkit_scroll_bars
= intern ("xaw");
15033 Vx_toolkit_scroll_bars
= Qnil
;
15036 staticpro (&last_mouse_motion_frame
);
15037 last_mouse_motion_frame
= Qnil
;
15040 #endif /* HAVE_X_WINDOWS */