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. */
176 static unsigned char zv_bits
[] = {
177 0x00, 0x00, 0x1e, 0x1e, 0x1e, 0x1e, 0x00, 0x00};
179 /* An arrow like this: `<-'. */
182 #define left_height 8
183 static unsigned char left_bits
[] = {
184 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
186 /* Right truncation arrow bitmap `->'. */
188 #define right_width 8
189 #define right_height 8
190 static unsigned char right_bits
[] = {
191 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
193 /* Marker for continued lines. */
195 #define continued_width 8
196 #define continued_height 8
197 static unsigned char continued_bits
[] = {
198 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
200 /* Marker for continuation lines. */
202 #define continuation_width 8
203 #define continuation_height 8
204 static unsigned char continuation_bits
[] = {
205 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
207 /* Overlay arrow bitmap. */
213 static unsigned char ov_bits
[] = {
214 0x30, 0x08, 0x3c, 0x7e, 0x7a, 0x7a, 0x62, 0x3c};
216 /* A triangular arrow. */
219 static unsigned char ov_bits
[] = {
220 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
224 extern Lisp_Object Qhelp_echo
;
227 /* Non-nil means Emacs uses toolkit scroll bars. */
229 Lisp_Object Vx_toolkit_scroll_bars
;
231 /* If a string, XTread_socket generates an event to display that string.
232 (The display is done in read_char.) */
234 static Lisp_Object help_echo
;
235 static Lisp_Object help_echo_window
;
236 static Lisp_Object help_echo_object
;
237 static int help_echo_pos
;
239 /* Temporary variable for XTread_socket. */
241 static Lisp_Object previous_help_echo
;
243 /* Non-zero means that a HELP_EVENT has been generated since Emacs
246 static int any_help_event_p
;
248 /* Non-zero means draw block and hollow cursor as wide as the glyph
249 under it. For example, if a block cursor is over a tab, it will be
250 drawn as wide as that tab on the display. */
252 int x_stretch_cursor_p
;
254 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
256 int x_use_underline_position_properties
;
258 /* This is a chain of structures for all the X displays currently in
261 struct x_display_info
*x_display_list
;
263 /* This is a list of cons cells, each of the form (NAME
264 . FONT-LIST-CACHE), one for each element of x_display_list and in
265 the same order. NAME is the name of the frame. FONT-LIST-CACHE
266 records previous values returned by x-list-fonts. */
268 Lisp_Object x_display_name_list
;
270 /* Frame being updated by update_frame. This is declared in term.c.
271 This is set by update_begin and looked at by all the XT functions.
272 It is zero while not inside an update. In that case, the XT
273 functions assume that `selected_frame' is the frame to apply to. */
275 extern struct frame
*updating_frame
;
277 /* This is a frame waiting to be auto-raised, within XTread_socket. */
279 struct frame
*pending_autoraise_frame
;
282 /* The application context for Xt use. */
283 XtAppContext Xt_app_con
;
284 static String Xt_default_resources
[] = {0};
285 #endif /* USE_X_TOOLKIT */
287 /* Nominal cursor position -- where to draw output.
288 HPOS and VPOS are window relative glyph matrix coordinates.
289 X and Y are window relative pixel coordinates. */
291 struct cursor_pos output_cursor
;
293 /* Non-zero means user is interacting with a toolkit scroll bar. */
295 static int toolkit_scroll_bar_interaction
;
299 Formerly, we used PointerMotionHintMask (in standard_event_mask)
300 so that we would have to call XQueryPointer after each MotionNotify
301 event to ask for another such event. However, this made mouse tracking
302 slow, and there was a bug that made it eventually stop.
304 Simply asking for MotionNotify all the time seems to work better.
306 In order to avoid asking for motion events and then throwing most
307 of them away or busy-polling the server for mouse positions, we ask
308 the server for pointer motion hints. This means that we get only
309 one event per group of mouse movements. "Groups" are delimited by
310 other kinds of events (focus changes and button clicks, for
311 example), or by XQueryPointer calls; when one of these happens, we
312 get another MotionNotify event the next time the mouse moves. This
313 is at least as efficient as getting motion events when mouse
314 tracking is on, and I suspect only negligibly worse when tracking
317 /* Where the mouse was last time we reported a mouse event. */
319 FRAME_PTR last_mouse_frame
;
320 static XRectangle last_mouse_glyph
;
321 static Lisp_Object last_mouse_press_frame
;
323 /* The scroll bar in which the last X motion event occurred.
325 If the last X motion event occurred in a scroll bar, we set this so
326 XTmouse_position can know whether to report a scroll bar motion or
329 If the last X motion event didn't occur in a scroll bar, we set
330 this to Qnil, to tell XTmouse_position to return an ordinary motion
333 static Lisp_Object last_mouse_scroll_bar
;
335 /* This is a hack. We would really prefer that XTmouse_position would
336 return the time associated with the position it returns, but there
337 doesn't seem to be any way to wrest the time-stamp from the server
338 along with the position query. So, we just keep track of the time
339 of the last movement we received, and return that in hopes that
340 it's somewhat accurate. */
342 static Time last_mouse_movement_time
;
344 /* Incremented by XTread_socket whenever it really tries to read
348 static int volatile input_signal_count
;
350 static int input_signal_count
;
353 /* Used locally within XTread_socket. */
355 static int x_noop_count
;
357 /* Initial values of argv and argc. */
359 extern char **initial_argv
;
360 extern int initial_argc
;
362 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
364 /* Tells if a window manager is present or not. */
366 extern Lisp_Object Vx_no_window_manager
;
368 extern Lisp_Object Qface
, Qmouse_face
;
372 /* A mask of extra modifier bits to put into every keyboard char. */
374 extern int extra_keyboard_modifiers
;
376 static Lisp_Object Qvendor_specific_keysyms
;
378 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
379 extern Lisp_Object x_icon_type
P_ ((struct frame
*));
382 /* Enumeration for overriding/changing the face to use for drawing
383 glyphs in x_draw_glyphs. */
385 enum draw_glyphs_face
395 static int cursor_in_mouse_face_p
P_ ((struct window
*));
396 static int clear_mouse_face
P_ ((struct x_display_info
*));
397 static int x_alloc_nearest_color_1
P_ ((Display
*, Colormap
, XColor
*));
398 static void x_set_window_size_1
P_ ((struct frame
*, int, int, int));
399 static const XColor
*x_color_cells
P_ ((Display
*, int *));
400 static void x_update_window_end
P_ ((struct window
*, int, int));
401 static void frame_to_window_pixel_xy
P_ ((struct window
*, int *, int *));
402 void x_delete_display
P_ ((struct x_display_info
*));
403 static unsigned int x_x_to_emacs_modifiers
P_ ((struct x_display_info
*,
405 static int fast_find_position
P_ ((struct window
*, int, int *, int *,
406 int *, int *, Lisp_Object
));
407 static int fast_find_string_pos
P_ ((struct window
*, int, Lisp_Object
,
408 int *, int *, int *, int *, int));
409 static void set_output_cursor
P_ ((struct cursor_pos
*));
410 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
411 int *, int *, int *, int));
412 static void note_mode_line_highlight
P_ ((struct window
*, int, int));
413 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
414 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
415 static void x_handle_tool_bar_click
P_ ((struct frame
*, XButtonEvent
*));
416 static void show_mouse_face
P_ ((struct x_display_info
*,
417 enum draw_glyphs_face
));
418 static int x_io_error_quitter
P_ ((Display
*));
419 int x_catch_errors
P_ ((Display
*));
420 void x_uncatch_errors
P_ ((Display
*, int));
421 void x_lower_frame
P_ ((struct frame
*));
422 void x_scroll_bar_clear
P_ ((struct frame
*));
423 int x_had_errors_p
P_ ((Display
*));
424 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
425 void x_raise_frame
P_ ((struct frame
*));
426 void x_set_window_size
P_ ((struct frame
*, int, int, int));
427 void x_wm_set_window_state
P_ ((struct frame
*, int));
428 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
429 void x_initialize
P_ ((void));
430 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
431 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
432 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
434 enum draw_glyphs_face
));
435 static void x_update_end
P_ ((struct frame
*));
436 static void XTframe_up_to_date
P_ ((struct frame
*));
437 static void XTset_terminal_modes
P_ ((void));
438 static void XTreset_terminal_modes
P_ ((void));
439 static void XTcursor_to
P_ ((int, int, int, int));
440 static void x_write_glyphs
P_ ((struct glyph
*, int));
441 static void x_clear_end_of_line
P_ ((int));
442 static void x_clear_frame
P_ ((void));
443 static void x_clear_cursor
P_ ((struct window
*));
444 static void frame_highlight
P_ ((struct frame
*));
445 static void frame_unhighlight
P_ ((struct frame
*));
446 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
447 static void XTframe_rehighlight
P_ ((struct frame
*));
448 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
449 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
450 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int));
451 static int x_intersect_rectangles
P_ ((XRectangle
*, XRectangle
*,
453 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
454 static int expose_window_tree
P_ ((struct window
*, XRectangle
*));
455 static int expose_window
P_ ((struct window
*, XRectangle
*));
456 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
457 XRectangle
*, enum glyph_row_area
));
458 static int expose_line
P_ ((struct window
*, struct glyph_row
*,
460 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
461 static void x_update_window_cursor
P_ ((struct window
*, int));
462 static void x_erase_phys_cursor
P_ ((struct window
*));
463 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
464 static void x_draw_fringe_bitmap
P_ ((struct window
*, struct glyph_row
*,
465 enum fringe_bitmap_type
));
467 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
469 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, XRectangle
*));
470 static void x_draw_row_fringe_bitmaps
P_ ((struct window
*, struct glyph_row
*));
471 static void notice_overwritten_cursor
P_ ((struct window
*, int, int));
472 static void x_flush
P_ ((struct frame
*f
));
473 static void x_update_begin
P_ ((struct frame
*));
474 static void x_update_window_begin
P_ ((struct window
*));
475 static void x_draw_vertical_border
P_ ((struct window
*));
476 static void x_after_update_window_line
P_ ((struct glyph_row
*));
477 static INLINE
void take_vertical_position_into_account
P_ ((struct it
*));
478 static void x_produce_stretch_glyph
P_ ((struct it
*));
479 static struct scroll_bar
*x_window_to_scroll_bar
P_ ((Window
));
480 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
481 enum scroll_bar_part
*,
482 Lisp_Object
*, Lisp_Object
*,
485 /* Flush display of frame F, or of all frames if F is null. */
494 Lisp_Object rest
, frame
;
495 FOR_EACH_FRAME (rest
, frame
)
496 x_flush (XFRAME (frame
));
498 else if (FRAME_X_P (f
))
499 XFlush (FRAME_X_DISPLAY (f
));
504 /* Remove calls to XFlush by defining XFlush to an empty replacement.
505 Calls to XFlush should be unnecessary because the X output buffer
506 is flushed automatically as needed by calls to XPending,
507 XNextEvent, or XWindowEvent according to the XFlush man page.
508 XTread_socket calls XPending. Removing XFlush improves
511 #define XFlush(DISPLAY) (void) 0
514 /***********************************************************************
516 ***********************************************************************/
520 /* This is a function useful for recording debugging information about
521 the sequence of occurrences in this file. */
529 struct record event_record
[100];
531 int event_record_index
;
533 record_event (locus
, type
)
537 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
538 event_record_index
= 0;
540 event_record
[event_record_index
].locus
= locus
;
541 event_record
[event_record_index
].type
= type
;
542 event_record_index
++;
549 /* Return the struct x_display_info corresponding to DPY. */
551 struct x_display_info
*
552 x_display_info_for_display (dpy
)
555 struct x_display_info
*dpyinfo
;
557 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
558 if (dpyinfo
->display
== dpy
)
566 /***********************************************************************
567 Starting and ending an update
568 ***********************************************************************/
570 /* Start an update of frame F. This function is installed as a hook
571 for update_begin, i.e. it is called when update_begin is called.
572 This function is called prior to calls to x_update_window_begin for
573 each window being updated. Currently, there is nothing to do here
574 because all interesting stuff is done on a window basis. */
584 /* Start update of window W. Set the global variable updated_window
585 to the window being updated and set output_cursor to the cursor
589 x_update_window_begin (w
)
592 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
593 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
596 set_output_cursor (&w
->cursor
);
600 if (f
== display_info
->mouse_face_mouse_frame
)
602 /* Don't do highlighting for mouse motion during the update. */
603 display_info
->mouse_face_defer
= 1;
605 /* If F needs to be redrawn, simply forget about any prior mouse
607 if (FRAME_GARBAGED_P (f
))
608 display_info
->mouse_face_window
= Qnil
;
610 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
611 their mouse_face_p flag set, which means that they are always
612 unequal to rows in a desired matrix which never have that
613 flag set. So, rows containing mouse-face glyphs are never
614 scrolled, and we don't have to switch the mouse highlight off
615 here to prevent it from being scrolled. */
617 /* Can we tell that this update does not affect the window
618 where the mouse highlight is? If so, no need to turn off.
619 Likewise, don't do anything if the frame is garbaged;
620 in that case, the frame's current matrix that we would use
621 is all wrong, and we will redisplay that line anyway. */
622 if (!NILP (display_info
->mouse_face_window
)
623 && w
== XWINDOW (display_info
->mouse_face_window
))
627 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
628 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
631 if (i
< w
->desired_matrix
->nrows
)
632 clear_mouse_face (display_info
);
641 /* Draw a vertical window border to the right of window W if W doesn't
642 have vertical scroll bars. */
645 x_draw_vertical_border (w
)
648 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
650 /* Redraw borders between horizontally adjacent windows. Don't
651 do it for frames with vertical scroll bars because either the
652 right scroll bar of a window, or the left scroll bar of its
653 neighbor will suffice as a border. */
654 if (!WINDOW_RIGHTMOST_P (w
)
655 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
659 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
660 x1
+= FRAME_X_RIGHT_FRINGE_WIDTH (f
);
663 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
664 f
->output_data
.x
->normal_gc
, x1
, y0
, x1
, y1
);
669 /* End update of window W (which is equal to updated_window).
671 Draw vertical borders between horizontally adjacent windows, and
672 display W's cursor if CURSOR_ON_P is non-zero.
674 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
675 glyphs in mouse-face were overwritten. In that case we have to
676 make sure that the mouse-highlight is properly redrawn.
678 W may be a menu bar pseudo-window in case we don't have X toolkit
679 support. Such windows don't have a cursor, so don't display it
683 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
685 int cursor_on_p
, mouse_face_overwritten_p
;
687 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
689 if (!w
->pseudo_window_p
)
694 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
696 output_cursor
.x
, output_cursor
.y
);
698 x_draw_vertical_border (w
);
702 /* If a row with mouse-face was overwritten, arrange for
703 XTframe_up_to_date to redisplay the mouse highlight. */
704 if (mouse_face_overwritten_p
)
706 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
707 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
708 dpyinfo
->mouse_face_window
= Qnil
;
711 updated_window
= NULL
;
715 /* End update of frame F. This function is installed as a hook in
722 /* Mouse highlight may be displayed again. */
723 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
726 XFlush (FRAME_X_DISPLAY (f
));
731 /* This function is called from various places in xdisp.c whenever a
732 complete update has been performed. The global variable
733 updated_window is not available here. */
736 XTframe_up_to_date (f
)
741 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
743 if (dpyinfo
->mouse_face_deferred_gc
744 || f
== dpyinfo
->mouse_face_mouse_frame
)
747 if (dpyinfo
->mouse_face_mouse_frame
)
748 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
749 dpyinfo
->mouse_face_mouse_x
,
750 dpyinfo
->mouse_face_mouse_y
);
751 dpyinfo
->mouse_face_deferred_gc
= 0;
758 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
759 arrow bitmaps, or clear the fringes if no bitmaps are required
760 before DESIRED_ROW is made current. The window being updated is
761 found in updated_window. This function It is called from
762 update_window_line only if it is known that there are differences
763 between bitmaps to be drawn between current row and DESIRED_ROW. */
766 x_after_update_window_line (desired_row
)
767 struct glyph_row
*desired_row
;
769 struct window
*w
= updated_window
;
775 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
778 x_draw_row_fringe_bitmaps (w
, desired_row
);
782 /* When a window has disappeared, make sure that no rest of
783 full-width rows stays visible in the internal border. Could
784 check here if updated_window is the leftmost/rightmost window,
785 but I guess it's not worth doing since vertically split windows
786 are almost never used, internal border is rarely set, and the
787 overhead is very small. */
788 if (windows_or_buffers_changed
789 && desired_row
->full_width_p
790 && (f
= XFRAME (w
->frame
),
791 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
793 && (height
= desired_row
->visible_height
,
796 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
798 /* Internal border is drawn below the tool bar. */
799 if (WINDOWP (f
->tool_bar_window
)
800 && w
== XWINDOW (f
->tool_bar_window
))
804 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
805 0, y
, width
, height
, False
);
806 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
807 f
->output_data
.x
->pixel_width
- width
,
808 y
, width
, height
, False
);
814 /* Draw the bitmap WHICH in one of the left or right fringes of
815 window W. ROW is the glyph row for which to display the bitmap; it
816 determines the vertical position at which the bitmap has to be
820 x_draw_fringe_bitmap (w
, row
, which
)
822 struct glyph_row
*row
;
823 enum fringe_bitmap_type which
;
825 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
826 Display
*display
= FRAME_X_DISPLAY (f
);
827 Window window
= FRAME_X_WINDOW (f
);
831 GC gc
= f
->output_data
.x
->normal_gc
;
833 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
835 /* Must clip because of partially visible lines. */
836 x_clip_to_row (w
, row
, gc
, 1);
840 case LEFT_TRUNCATION_BITMAP
:
844 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
846 - (FRAME_X_LEFT_FRINGE_WIDTH (f
) - wd
) / 2);
849 case OVERLAY_ARROW_BITMAP
:
853 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
855 - (FRAME_X_LEFT_FRINGE_WIDTH (f
) - wd
) / 2);
858 case RIGHT_TRUNCATION_BITMAP
:
862 x
= window_box_right (w
, -1);
863 x
+= (FRAME_X_RIGHT_FRINGE_WIDTH (f
) - wd
) / 2;
866 case CONTINUED_LINE_BITMAP
:
869 bits
= continued_bits
;
870 x
= window_box_right (w
, -1);
871 x
+= (FRAME_X_RIGHT_FRINGE_WIDTH (f
) - wd
) / 2;
874 case CONTINUATION_LINE_BITMAP
:
875 wd
= continuation_width
;
876 h
= continuation_height
;
877 bits
= continuation_bits
;
878 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
880 - (FRAME_X_LEFT_FRINGE_WIDTH (f
) - wd
) / 2);
887 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
889 - (FRAME_X_LEFT_FRINGE_WIDTH (f
) - wd
) / 2);
896 /* Convert to frame coordinates. Set dy to the offset in the row to
897 start drawing the bitmap. */
898 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
899 dy
= (row
->height
- h
) / 2;
901 /* Draw the bitmap. I believe these small pixmaps can be cached
903 face
= FACE_FROM_ID (f
, FRINGE_FACE_ID
);
904 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, wd
, h
,
906 face
->background
, depth
);
907 XCopyArea (display
, pixmap
, window
, gc
, 0, 0, wd
, h
, x
, y
+ dy
);
908 XFreePixmap (display
, pixmap
);
909 XSetClipMask (display
, gc
, None
);
913 /* Draw fringe bitmaps for glyph row ROW on window W. Call this
914 function with input blocked. */
917 x_draw_row_fringe_bitmaps (w
, row
)
919 struct glyph_row
*row
;
921 struct frame
*f
= XFRAME (w
->frame
);
922 enum fringe_bitmap_type bitmap
;
924 int header_line_height
= -1;
926 xassert (interrupt_input_blocked
);
928 /* If row is completely invisible, because of vscrolling, we
929 don't have to draw anything. */
930 if (row
->visible_height
<= 0)
933 face
= FACE_FROM_ID (f
, FRINGE_FACE_ID
);
934 PREPARE_FACE_FOR_DISPLAY (f
, face
);
936 /* Decide which bitmap to draw in the left fringe. */
937 if (row
->overlay_arrow_p
)
938 bitmap
= OVERLAY_ARROW_BITMAP
;
939 else if (row
->truncated_on_left_p
)
940 bitmap
= LEFT_TRUNCATION_BITMAP
;
941 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
942 bitmap
= CONTINUATION_LINE_BITMAP
;
943 else if (row
->indicate_empty_line_p
)
944 bitmap
= ZV_LINE_BITMAP
;
946 bitmap
= NO_FRINGE_BITMAP
;
948 /* Clear left fringe if no bitmap to draw or if bitmap doesn't fill
950 if (bitmap
== NO_FRINGE_BITMAP
951 || FRAME_FRINGE_BITMAP_WIDTH (f
) < FRAME_X_LEFT_FRINGE_WIDTH (f
)
952 || row
->height
> FRAME_FRINGE_BITMAP_HEIGHT (f
))
954 /* If W has a vertical border to its left, don't draw over it. */
955 int border
= ((XFASTINT (w
->left
) > 0
956 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
958 int left
= window_box_left (w
, -1);
960 if (header_line_height
< 0)
961 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
963 /* In case the same realized face is used for fringes and
964 for something displayed in the text (e.g. face `region' on
965 mono-displays, the fill style may have been changed to
966 FillSolid in x_draw_glyph_string_background. */
968 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
970 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
972 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
975 - FRAME_X_LEFT_FRINGE_WIDTH (f
)
977 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
979 FRAME_X_LEFT_FRINGE_WIDTH (f
) - border
,
980 row
->visible_height
);
982 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
985 /* Draw the left bitmap. */
986 if (bitmap
!= NO_FRINGE_BITMAP
)
987 x_draw_fringe_bitmap (w
, row
, bitmap
);
989 /* Decide which bitmap to draw in the right fringe. */
990 if (row
->truncated_on_right_p
)
991 bitmap
= RIGHT_TRUNCATION_BITMAP
;
992 else if (row
->continued_p
)
993 bitmap
= CONTINUED_LINE_BITMAP
;
995 bitmap
= NO_FRINGE_BITMAP
;
997 /* Clear right fringe if no bitmap to draw of if bitmap doesn't fill
999 if (bitmap
== NO_FRINGE_BITMAP
1000 || FRAME_FRINGE_BITMAP_WIDTH (f
) < FRAME_X_RIGHT_FRINGE_WIDTH (f
)
1001 || row
->height
> FRAME_FRINGE_BITMAP_HEIGHT (f
))
1003 int right
= window_box_right (w
, -1);
1005 if (header_line_height
< 0)
1006 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
1008 /* In case the same realized face is used for fringes and
1009 for something displayed in the text (e.g. face `region' on
1010 mono-displays, the fill style may have been changed to
1011 FillSolid in x_draw_glyph_string_background. */
1013 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
1015 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
1016 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1019 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
1021 FRAME_X_RIGHT_FRINGE_WIDTH (f
),
1022 row
->visible_height
);
1024 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
1027 /* Draw the right bitmap. */
1028 if (bitmap
!= NO_FRINGE_BITMAP
)
1029 x_draw_fringe_bitmap (w
, row
, bitmap
);
1034 /* This is called when starting Emacs and when restarting after
1035 suspend. When starting Emacs, no X window is mapped. And nothing
1036 must be done to Emacs's own window if it is suspended (though that
1040 XTset_terminal_modes ()
1044 /* This is called when exiting or suspending Emacs. Exiting will make
1045 the X-windows go away, and suspending requires no action. */
1048 XTreset_terminal_modes ()
1054 /***********************************************************************
1056 ***********************************************************************/
1058 /* Set the global variable output_cursor to CURSOR. All cursor
1059 positions are relative to updated_window. */
1062 set_output_cursor (cursor
)
1063 struct cursor_pos
*cursor
;
1065 output_cursor
.hpos
= cursor
->hpos
;
1066 output_cursor
.vpos
= cursor
->vpos
;
1067 output_cursor
.x
= cursor
->x
;
1068 output_cursor
.y
= cursor
->y
;
1072 /* Set a nominal cursor position.
1074 HPOS and VPOS are column/row positions in a window glyph matrix. X
1075 and Y are window text area relative pixel positions.
1077 If this is done during an update, updated_window will contain the
1078 window that is being updated and the position is the future output
1079 cursor position for that window. If updated_window is null, use
1080 selected_window and display the cursor at the given position. */
1083 XTcursor_to (vpos
, hpos
, y
, x
)
1084 int vpos
, hpos
, y
, x
;
1088 /* If updated_window is not set, work on selected_window. */
1092 w
= XWINDOW (selected_window
);
1094 /* Set the output cursor. */
1095 output_cursor
.hpos
= hpos
;
1096 output_cursor
.vpos
= vpos
;
1097 output_cursor
.x
= x
;
1098 output_cursor
.y
= y
;
1100 /* If not called as part of an update, really display the cursor.
1101 This will also set the cursor position of W. */
1102 if (updated_window
== NULL
)
1105 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
1106 XFlush (FRAME_X_DISPLAY (SELECTED_FRAME ()));
1113 /***********************************************************************
1115 ***********************************************************************/
1117 /* Function prototypes of this page. */
1119 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
1123 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
1124 int, XChar2b
*, int));
1125 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
1126 static void x_encode_char
P_ ((int, XChar2b
*, struct font_info
*));
1127 static void x_append_glyph
P_ ((struct it
*));
1128 static void x_append_composite_glyph
P_ ((struct it
*));
1129 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
1131 static void x_produce_glyphs
P_ ((struct it
*));
1132 static void x_produce_image_glyph
P_ ((struct it
*it
));
1135 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
1136 is not contained in the font. */
1138 static INLINE XCharStruct
*
1139 x_per_char_metric (font
, char2b
)
1143 /* The result metric information. */
1144 XCharStruct
*pcm
= NULL
;
1146 xassert (font
&& char2b
);
1148 if (font
->per_char
!= NULL
)
1150 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
1152 /* min_char_or_byte2 specifies the linear character index
1153 corresponding to the first element of the per_char array,
1154 max_char_or_byte2 is the index of the last character. A
1155 character with non-zero CHAR2B->byte1 is not in the font.
1156 A character with byte2 less than min_char_or_byte2 or
1157 greater max_char_or_byte2 is not in the font. */
1158 if (char2b
->byte1
== 0
1159 && char2b
->byte2
>= font
->min_char_or_byte2
1160 && char2b
->byte2
<= font
->max_char_or_byte2
)
1161 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
1165 /* If either min_byte1 or max_byte1 are nonzero, both
1166 min_char_or_byte2 and max_char_or_byte2 are less than
1167 256, and the 2-byte character index values corresponding
1168 to the per_char array element N (counting from 0) are:
1170 byte1 = N/D + min_byte1
1171 byte2 = N\D + min_char_or_byte2
1175 D = max_char_or_byte2 - min_char_or_byte2 + 1
1176 / = integer division
1177 \ = integer modulus */
1178 if (char2b
->byte1
>= font
->min_byte1
1179 && char2b
->byte1
<= font
->max_byte1
1180 && char2b
->byte2
>= font
->min_char_or_byte2
1181 && char2b
->byte2
<= font
->max_char_or_byte2
)
1183 pcm
= (font
->per_char
1184 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
1185 * (char2b
->byte1
- font
->min_byte1
))
1186 + (char2b
->byte2
- font
->min_char_or_byte2
));
1192 /* If the per_char pointer is null, all glyphs between the first
1193 and last character indexes inclusive have the same
1194 information, as given by both min_bounds and max_bounds. */
1195 if (char2b
->byte2
>= font
->min_char_or_byte2
1196 && char2b
->byte2
<= font
->max_char_or_byte2
)
1197 pcm
= &font
->max_bounds
;
1200 return ((pcm
== NULL
1201 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
1206 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1207 the two-byte form of C. Encoding is returned in *CHAR2B. */
1210 x_encode_char (c
, char2b
, font_info
)
1213 struct font_info
*font_info
;
1215 int charset
= CHAR_CHARSET (c
);
1216 XFontStruct
*font
= font_info
->font
;
1218 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1219 This may be either a program in a special encoder language or a
1221 if (font_info
->font_encoder
)
1223 /* It's a program. */
1224 struct ccl_program
*ccl
= font_info
->font_encoder
;
1226 if (CHARSET_DIMENSION (charset
) == 1)
1228 ccl
->reg
[0] = charset
;
1229 ccl
->reg
[1] = char2b
->byte2
;
1233 ccl
->reg
[0] = charset
;
1234 ccl
->reg
[1] = char2b
->byte1
;
1235 ccl
->reg
[2] = char2b
->byte2
;
1238 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1240 /* We assume that MSBs are appropriately set/reset by CCL
1242 if (font
->max_byte1
== 0) /* 1-byte font */
1243 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
1245 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
1247 else if (font_info
->encoding
[charset
])
1249 /* Fixed encoding scheme. See fontset.h for the meaning of the
1250 encoding numbers. */
1251 int enc
= font_info
->encoding
[charset
];
1253 if ((enc
== 1 || enc
== 2)
1254 && CHARSET_DIMENSION (charset
) == 2)
1255 char2b
->byte1
|= 0x80;
1257 if (enc
== 1 || enc
== 3)
1258 char2b
->byte2
|= 0x80;
1263 /* Get face and two-byte form of character C in face FACE_ID on frame
1264 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1265 means we want to display multibyte text. Value is a pointer to a
1266 realized face that is ready for display. */
1268 static INLINE
struct face
*
1269 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
)
1275 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1279 /* Unibyte case. We don't have to encode, but we have to make
1280 sure to use a face suitable for unibyte. */
1283 face_id
= FACE_FOR_CHAR (f
, face
, c
);
1284 face
= FACE_FROM_ID (f
, face_id
);
1286 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1288 /* Case of ASCII in a face known to fit ASCII. */
1294 int c1
, c2
, charset
;
1296 /* Split characters into bytes. If c2 is -1 afterwards, C is
1297 really a one-byte character so that byte1 is zero. */
1298 SPLIT_CHAR (c
, charset
, c1
, c2
);
1300 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1302 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1304 /* Maybe encode the character in *CHAR2B. */
1305 if (face
->font
!= NULL
)
1307 struct font_info
*font_info
1308 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1310 x_encode_char (c
, char2b
, font_info
);
1314 /* Make sure X resources of the face are allocated. */
1315 xassert (face
!= NULL
);
1316 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1322 /* Get face and two-byte form of character glyph GLYPH on frame F.
1323 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
1324 a pointer to a realized face that is ready for display. */
1326 static INLINE
struct face
*
1327 x_get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
1329 struct glyph
*glyph
;
1335 xassert (glyph
->type
== CHAR_GLYPH
);
1336 face
= FACE_FROM_ID (f
, glyph
->face_id
);
1341 if (!glyph
->multibyte_p
)
1343 /* Unibyte case. We don't have to encode, but we have to make
1344 sure to use a face suitable for unibyte. */
1346 char2b
->byte2
= glyph
->u
.ch
;
1348 else if (glyph
->u
.ch
< 128
1349 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
1351 /* Case of ASCII in a face known to fit ASCII. */
1353 char2b
->byte2
= glyph
->u
.ch
;
1357 int c1
, c2
, charset
;
1359 /* Split characters into bytes. If c2 is -1 afterwards, C is
1360 really a one-byte character so that byte1 is zero. */
1361 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
1363 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1365 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1367 /* Maybe encode the character in *CHAR2B. */
1368 if (charset
!= CHARSET_ASCII
)
1370 struct font_info
*font_info
1371 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1374 x_encode_char (glyph
->u
.ch
, char2b
, font_info
);
1377 = ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
1382 /* Make sure X resources of the face are allocated. */
1383 xassert (face
!= NULL
);
1384 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1389 /* Store one glyph for IT->char_to_display in IT->glyph_row.
1390 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1396 struct glyph
*glyph
;
1397 enum glyph_row_area area
= it
->area
;
1399 xassert (it
->glyph_row
);
1400 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
1402 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1403 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1405 glyph
->charpos
= CHARPOS (it
->position
);
1406 glyph
->object
= it
->object
;
1407 glyph
->pixel_width
= it
->pixel_width
;
1408 glyph
->voffset
= it
->voffset
;
1409 glyph
->type
= CHAR_GLYPH
;
1410 glyph
->multibyte_p
= it
->multibyte_p
;
1411 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1412 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1413 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1414 || it
->phys_descent
> it
->descent
);
1415 glyph
->padding_p
= 0;
1416 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
1417 glyph
->face_id
= it
->face_id
;
1418 glyph
->u
.ch
= it
->char_to_display
;
1419 ++it
->glyph_row
->used
[area
];
1423 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
1424 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1427 x_append_composite_glyph (it
)
1430 struct glyph
*glyph
;
1431 enum glyph_row_area area
= it
->area
;
1433 xassert (it
->glyph_row
);
1435 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1436 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1438 glyph
->charpos
= CHARPOS (it
->position
);
1439 glyph
->object
= it
->object
;
1440 glyph
->pixel_width
= it
->pixel_width
;
1441 glyph
->voffset
= it
->voffset
;
1442 glyph
->type
= COMPOSITE_GLYPH
;
1443 glyph
->multibyte_p
= it
->multibyte_p
;
1444 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1445 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1446 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1447 || it
->phys_descent
> it
->descent
);
1448 glyph
->padding_p
= 0;
1449 glyph
->glyph_not_available_p
= 0;
1450 glyph
->face_id
= it
->face_id
;
1451 glyph
->u
.cmp_id
= it
->cmp_id
;
1452 ++it
->glyph_row
->used
[area
];
1457 /* Change IT->ascent and IT->height according to the setting of
1461 take_vertical_position_into_account (it
)
1466 if (it
->voffset
< 0)
1467 /* Increase the ascent so that we can display the text higher
1469 it
->ascent
+= abs (it
->voffset
);
1471 /* Increase the descent so that we can display the text lower
1473 it
->descent
+= it
->voffset
;
1478 /* Produce glyphs/get display metrics for the image IT is loaded with.
1479 See the description of struct display_iterator in dispextern.h for
1480 an overview of struct display_iterator. */
1483 x_produce_image_glyph (it
)
1489 xassert (it
->what
== IT_IMAGE
);
1491 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1492 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
1495 /* Make sure X resources of the face and image are loaded. */
1496 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1497 prepare_image_for_display (it
->f
, img
);
1499 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
1500 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
1501 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
1505 if (face
->box
!= FACE_NO_BOX
)
1507 if (face
->box_line_width
> 0)
1509 it
->ascent
+= face
->box_line_width
;
1510 it
->descent
+= face
->box_line_width
;
1513 if (it
->start_of_box_run_p
)
1514 it
->pixel_width
+= abs (face
->box_line_width
);
1515 if (it
->end_of_box_run_p
)
1516 it
->pixel_width
+= abs (face
->box_line_width
);
1519 take_vertical_position_into_account (it
);
1523 struct glyph
*glyph
;
1524 enum glyph_row_area area
= it
->area
;
1526 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1527 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1529 glyph
->charpos
= CHARPOS (it
->position
);
1530 glyph
->object
= it
->object
;
1531 glyph
->pixel_width
= it
->pixel_width
;
1532 glyph
->voffset
= it
->voffset
;
1533 glyph
->type
= IMAGE_GLYPH
;
1534 glyph
->multibyte_p
= it
->multibyte_p
;
1535 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1536 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1537 glyph
->overlaps_vertically_p
= 0;
1538 glyph
->padding_p
= 0;
1539 glyph
->glyph_not_available_p
= 0;
1540 glyph
->face_id
= it
->face_id
;
1541 glyph
->u
.img_id
= img
->id
;
1542 ++it
->glyph_row
->used
[area
];
1548 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
1549 of the glyph, WIDTH and HEIGHT are the width and height of the
1550 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
1551 ascent of the glyph (0 <= ASCENT <= 1). */
1554 x_append_stretch_glyph (it
, object
, width
, height
, ascent
)
1560 struct glyph
*glyph
;
1561 enum glyph_row_area area
= it
->area
;
1563 xassert (ascent
>= 0 && ascent
<= 1);
1565 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1566 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1568 glyph
->charpos
= CHARPOS (it
->position
);
1569 glyph
->object
= object
;
1570 glyph
->pixel_width
= width
;
1571 glyph
->voffset
= it
->voffset
;
1572 glyph
->type
= STRETCH_GLYPH
;
1573 glyph
->multibyte_p
= it
->multibyte_p
;
1574 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1575 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1576 glyph
->overlaps_vertically_p
= 0;
1577 glyph
->padding_p
= 0;
1578 glyph
->glyph_not_available_p
= 0;
1579 glyph
->face_id
= it
->face_id
;
1580 glyph
->u
.stretch
.ascent
= height
* ascent
;
1581 glyph
->u
.stretch
.height
= height
;
1582 ++it
->glyph_row
->used
[area
];
1587 /* Produce a stretch glyph for iterator IT. IT->object is the value
1588 of the glyph property displayed. The value must be a list
1589 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1592 1. `:width WIDTH' specifies that the space should be WIDTH *
1593 canonical char width wide. WIDTH may be an integer or floating
1596 2. `:relative-width FACTOR' specifies that the width of the stretch
1597 should be computed from the width of the first character having the
1598 `glyph' property, and should be FACTOR times that width.
1600 3. `:align-to HPOS' specifies that the space should be wide enough
1601 to reach HPOS, a value in canonical character units.
1603 Exactly one of the above pairs must be present.
1605 4. `:height HEIGHT' specifies that the height of the stretch produced
1606 should be HEIGHT, measured in canonical character units.
1608 5. `:relative-height FACTOR' specifies that the height of the the
1609 stretch should be FACTOR times the height of the characters having
1612 Either none or exactly one of 4 or 5 must be present.
1614 6. `:ascent ASCENT' specifies that ASCENT percent of the height
1615 of the stretch should be used for the ascent of the stretch.
1616 ASCENT must be in the range 0 <= ASCENT <= 100. */
1619 ((INTEGERP (X) || FLOATP (X)) \
1625 x_produce_stretch_glyph (it
)
1628 /* (space :width WIDTH :height HEIGHT. */
1630 extern Lisp_Object Qspace
;
1632 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
1633 extern Lisp_Object QCrelative_width
, QCrelative_height
;
1634 extern Lisp_Object QCalign_to
;
1635 Lisp_Object prop
, plist
;
1636 double width
= 0, height
= 0, ascent
= 0;
1637 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1638 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
1640 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1642 /* List should start with `space'. */
1643 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1644 plist
= XCDR (it
->object
);
1646 /* Compute the width of the stretch. */
1647 if (prop
= Fplist_get (plist
, QCwidth
),
1649 /* Absolute width `:width WIDTH' specified and valid. */
1650 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
1651 else if (prop
= Fplist_get (plist
, QCrelative_width
),
1654 /* Relative width `:relative-width FACTOR' specified and valid.
1655 Compute the width of the characters having the `glyph'
1658 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
1661 if (it
->multibyte_p
)
1663 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
1664 - IT_BYTEPOS (*it
));
1665 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
1668 it2
.c
= *p
, it2
.len
= 1;
1670 it2
.glyph_row
= NULL
;
1671 it2
.what
= IT_CHARACTER
;
1672 x_produce_glyphs (&it2
);
1673 width
= NUMVAL (prop
) * it2
.pixel_width
;
1675 else if (prop
= Fplist_get (plist
, QCalign_to
),
1677 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
1679 /* Nothing specified -> width defaults to canonical char width. */
1680 width
= CANON_X_UNIT (it
->f
);
1682 /* Compute height. */
1683 if (prop
= Fplist_get (plist
, QCheight
),
1685 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
1686 else if (prop
= Fplist_get (plist
, QCrelative_height
),
1688 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
1690 height
= FONT_HEIGHT (font
);
1692 /* Compute percentage of height used for ascent. If
1693 `:ascent ASCENT' is present and valid, use that. Otherwise,
1694 derive the ascent from the font in use. */
1695 if (prop
= Fplist_get (plist
, QCascent
),
1696 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
1697 ascent
= NUMVAL (prop
) / 100.0;
1699 ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1708 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1709 if (!STRINGP (object
))
1710 object
= it
->w
->buffer
;
1711 x_append_stretch_glyph (it
, object
, width
, height
, ascent
);
1714 it
->pixel_width
= width
;
1715 it
->ascent
= it
->phys_ascent
= height
* ascent
;
1716 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
1719 if (face
->box
!= FACE_NO_BOX
)
1721 if (face
->box_line_width
> 0)
1723 it
->ascent
+= face
->box_line_width
;
1724 it
->descent
+= face
->box_line_width
;
1727 if (it
->start_of_box_run_p
)
1728 it
->pixel_width
+= abs (face
->box_line_width
);
1729 if (it
->end_of_box_run_p
)
1730 it
->pixel_width
+= abs (face
->box_line_width
);
1733 take_vertical_position_into_account (it
);
1736 /* Return proper value to be used as baseline offset of font that has
1737 ASCENT and DESCENT to draw characters by the font at the vertical
1738 center of the line of frame F.
1740 Here, out task is to find the value of BOFF in the following figure;
1742 -------------------------+-----------+-
1743 -+-+---------+-+ | |
1745 | | | | F_ASCENT F_HEIGHT
1748 | | |-|-+------+-----------|------- baseline
1750 | |---------|-+-+ | |
1752 -+-+---------+-+ F_DESCENT |
1753 -------------------------+-----------+-
1755 -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
1756 BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
1757 DESCENT = FONT->descent
1758 HEIGHT = FONT_HEIGHT (FONT)
1759 F_DESCENT = (F->output_data.x->font->descent
1760 - F->output_data.x->baseline_offset)
1761 F_HEIGHT = FRAME_LINE_HEIGHT (F)
1764 #define VCENTER_BASELINE_OFFSET(FONT, F) \
1766 + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT)) \
1767 + (FRAME_LINE_HEIGHT ((F)) > FONT_HEIGHT ((FONT)))) / 2 \
1768 - ((F)->output_data.x->font->descent - (F)->output_data.x->baseline_offset))
1770 /* Produce glyphs/get display metrics for the display element IT is
1771 loaded with. See the description of struct display_iterator in
1772 dispextern.h for an overview of struct display_iterator. */
1775 x_produce_glyphs (it
)
1778 it
->glyph_not_available_p
= 0;
1780 if (it
->what
== IT_CHARACTER
)
1784 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1786 int font_not_found_p
;
1787 struct font_info
*font_info
;
1788 int boff
; /* baseline offset */
1789 /* We may change it->multibyte_p upon unibyte<->multibyte
1790 conversion. So, save the current value now and restore it
1793 Note: It seems that we don't have to record multibyte_p in
1794 struct glyph because the character code itself tells if or
1795 not the character is multibyte. Thus, in the future, we must
1796 consider eliminating the field `multibyte_p' in the struct
1798 int saved_multibyte_p
= it
->multibyte_p
;
1800 /* Maybe translate single-byte characters to multibyte, or the
1802 it
->char_to_display
= it
->c
;
1803 if (!ASCII_BYTE_P (it
->c
))
1805 if (unibyte_display_via_language_environment
1806 && SINGLE_BYTE_CHAR_P (it
->c
)
1808 || !NILP (Vnonascii_translation_table
)))
1810 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
1811 it
->multibyte_p
= 1;
1812 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1813 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1815 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
1816 && !it
->multibyte_p
)
1818 it
->multibyte_p
= 1;
1819 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1820 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1824 /* Get font to use. Encode IT->char_to_display. */
1825 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
1826 it
->face_id
, &char2b
,
1830 /* When no suitable font found, use the default font. */
1831 font_not_found_p
= font
== NULL
;
1832 if (font_not_found_p
)
1834 font
= FRAME_FONT (it
->f
);
1835 boff
= it
->f
->output_data
.x
->baseline_offset
;
1840 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
1841 boff
= font_info
->baseline_offset
;
1842 if (font_info
->vertical_centering
)
1843 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
1846 if (it
->char_to_display
>= ' '
1847 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
1849 /* Either unibyte or ASCII. */
1854 pcm
= x_per_char_metric (font
, &char2b
);
1855 it
->ascent
= font
->ascent
+ boff
;
1856 it
->descent
= font
->descent
- boff
;
1860 it
->phys_ascent
= pcm
->ascent
+ boff
;
1861 it
->phys_descent
= pcm
->descent
- boff
;
1862 it
->pixel_width
= pcm
->width
;
1866 it
->glyph_not_available_p
= 1;
1867 it
->phys_ascent
= font
->ascent
+ boff
;
1868 it
->phys_descent
= font
->descent
- boff
;
1869 it
->pixel_width
= FONT_WIDTH (font
);
1872 /* If this is a space inside a region of text with
1873 `space-width' property, change its width. */
1874 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
1876 it
->pixel_width
*= XFLOATINT (it
->space_width
);
1878 /* If face has a box, add the box thickness to the character
1879 height. If character has a box line to the left and/or
1880 right, add the box line width to the character's width. */
1881 if (face
->box
!= FACE_NO_BOX
)
1883 int thick
= face
->box_line_width
;
1887 it
->ascent
+= thick
;
1888 it
->descent
+= thick
;
1893 if (it
->start_of_box_run_p
)
1894 it
->pixel_width
+= thick
;
1895 if (it
->end_of_box_run_p
)
1896 it
->pixel_width
+= thick
;
1899 /* If face has an overline, add the height of the overline
1900 (1 pixel) and a 1 pixel margin to the character height. */
1901 if (face
->overline_p
)
1904 take_vertical_position_into_account (it
);
1906 /* If we have to actually produce glyphs, do it. */
1911 /* Translate a space with a `space-width' property
1912 into a stretch glyph. */
1913 double ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1914 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1915 it
->ascent
+ it
->descent
, ascent
);
1918 x_append_glyph (it
);
1920 /* If characters with lbearing or rbearing are displayed
1921 in this line, record that fact in a flag of the
1922 glyph row. This is used to optimize X output code. */
1923 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
1924 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1927 else if (it
->char_to_display
== '\n')
1929 /* A newline has no width but we need the height of the line. */
1930 it
->pixel_width
= 0;
1932 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1933 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1935 if (face
->box
!= FACE_NO_BOX
1936 && face
->box_line_width
> 0)
1938 it
->ascent
+= face
->box_line_width
;
1939 it
->descent
+= face
->box_line_width
;
1942 else if (it
->char_to_display
== '\t')
1944 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
1945 int x
= it
->current_x
+ it
->continuation_lines_width
;
1946 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
1948 /* If the distance from the current position to the next tab
1949 stop is less than a canonical character width, use the
1950 tab stop after that. */
1951 if (next_tab_x
- x
< CANON_X_UNIT (it
->f
))
1952 next_tab_x
+= tab_width
;
1954 it
->pixel_width
= next_tab_x
- x
;
1956 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1957 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1961 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
1962 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1963 it
->ascent
+ it
->descent
, ascent
);
1968 /* A multi-byte character. Assume that the display width of the
1969 character is the width of the character multiplied by the
1970 width of the font. */
1972 /* If we found a font, this font should give us the right
1973 metrics. If we didn't find a font, use the frame's
1974 default font and calculate the width of the character
1975 from the charset width; this is what old redisplay code
1977 pcm
= x_per_char_metric (font
, &char2b
);
1978 if (font_not_found_p
|| !pcm
)
1980 int charset
= CHAR_CHARSET (it
->char_to_display
);
1982 it
->glyph_not_available_p
= 1;
1983 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
1984 * CHARSET_WIDTH (charset
));
1985 it
->phys_ascent
= font
->ascent
+ boff
;
1986 it
->phys_descent
= font
->descent
- boff
;
1990 it
->pixel_width
= pcm
->width
;
1991 it
->phys_ascent
= pcm
->ascent
+ boff
;
1992 it
->phys_descent
= pcm
->descent
- boff
;
1994 && (pcm
->lbearing
< 0
1995 || pcm
->rbearing
> pcm
->width
))
1996 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1999 it
->ascent
= font
->ascent
+ boff
;
2000 it
->descent
= font
->descent
- boff
;
2001 if (face
->box
!= FACE_NO_BOX
)
2003 int thick
= face
->box_line_width
;
2007 it
->ascent
+= thick
;
2008 it
->descent
+= thick
;
2013 if (it
->start_of_box_run_p
)
2014 it
->pixel_width
+= thick
;
2015 if (it
->end_of_box_run_p
)
2016 it
->pixel_width
+= thick
;
2019 /* If face has an overline, add the height of the overline
2020 (1 pixel) and a 1 pixel margin to the character height. */
2021 if (face
->overline_p
)
2024 take_vertical_position_into_account (it
);
2027 x_append_glyph (it
);
2029 it
->multibyte_p
= saved_multibyte_p
;
2031 else if (it
->what
== IT_COMPOSITION
)
2033 /* Note: A composition is represented as one glyph in the
2034 glyph matrix. There are no padding glyphs. */
2037 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2039 int font_not_found_p
;
2040 struct font_info
*font_info
;
2041 int boff
; /* baseline offset */
2042 struct composition
*cmp
= composition_table
[it
->cmp_id
];
2044 /* Maybe translate single-byte characters to multibyte. */
2045 it
->char_to_display
= it
->c
;
2046 if (unibyte_display_via_language_environment
2047 && SINGLE_BYTE_CHAR_P (it
->c
)
2050 && !NILP (Vnonascii_translation_table
))))
2052 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2055 /* Get face and font to use. Encode IT->char_to_display. */
2056 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2057 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2058 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2059 it
->face_id
, &char2b
, it
->multibyte_p
);
2062 /* When no suitable font found, use the default font. */
2063 font_not_found_p
= font
== NULL
;
2064 if (font_not_found_p
)
2066 font
= FRAME_FONT (it
->f
);
2067 boff
= it
->f
->output_data
.x
->baseline_offset
;
2072 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2073 boff
= font_info
->baseline_offset
;
2074 if (font_info
->vertical_centering
)
2075 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2078 /* There are no padding glyphs, so there is only one glyph to
2079 produce for the composition. Important is that pixel_width,
2080 ascent and descent are the values of what is drawn by
2081 draw_glyphs (i.e. the values of the overall glyphs composed). */
2084 /* If we have not yet calculated pixel size data of glyphs of
2085 the composition for the current face font, calculate them
2086 now. Theoretically, we have to check all fonts for the
2087 glyphs, but that requires much time and memory space. So,
2088 here we check only the font of the first glyph. This leads
2089 to incorrect display very rarely, and C-l (recenter) can
2090 correct the display anyway. */
2091 if (cmp
->font
!= (void *) font
)
2093 /* Ascent and descent of the font of the first character of
2094 this composition (adjusted by baseline offset). Ascent
2095 and descent of overall glyphs should not be less than
2096 them respectively. */
2097 int font_ascent
= font
->ascent
+ boff
;
2098 int font_descent
= font
->descent
- boff
;
2099 /* Bounding box of the overall glyphs. */
2100 int leftmost
, rightmost
, lowest
, highest
;
2101 int i
, width
, ascent
, descent
;
2103 cmp
->font
= (void *) font
;
2105 /* Initialize the bounding box. */
2107 && (pcm
= x_per_char_metric (font
, &char2b
)))
2110 ascent
= pcm
->ascent
;
2111 descent
= pcm
->descent
;
2115 width
= FONT_WIDTH (font
);
2116 ascent
= font
->ascent
;
2117 descent
= font
->descent
;
2121 lowest
= - descent
+ boff
;
2122 highest
= ascent
+ boff
;
2126 && font_info
->default_ascent
2127 && CHAR_TABLE_P (Vuse_default_ascent
)
2128 && !NILP (Faref (Vuse_default_ascent
,
2129 make_number (it
->char_to_display
))))
2130 highest
= font_info
->default_ascent
+ boff
;
2132 /* Draw the first glyph at the normal position. It may be
2133 shifted to right later if some other glyphs are drawn at
2135 cmp
->offsets
[0] = 0;
2136 cmp
->offsets
[1] = boff
;
2138 /* Set cmp->offsets for the remaining glyphs. */
2139 for (i
= 1; i
< cmp
->glyph_len
; i
++)
2141 int left
, right
, btm
, top
;
2142 int ch
= COMPOSITION_GLYPH (cmp
, i
);
2143 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
2145 face
= FACE_FROM_ID (it
->f
, face_id
);
2146 x_get_char_face_and_encoding (it
->f
, ch
, face
->id
, &char2b
,
2151 font
= FRAME_FONT (it
->f
);
2152 boff
= it
->f
->output_data
.x
->baseline_offset
;
2158 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2159 boff
= font_info
->baseline_offset
;
2160 if (font_info
->vertical_centering
)
2161 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2165 && (pcm
= x_per_char_metric (font
, &char2b
)))
2168 ascent
= pcm
->ascent
;
2169 descent
= pcm
->descent
;
2173 width
= FONT_WIDTH (font
);
2178 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
2180 /* Relative composition with or without
2182 left
= (leftmost
+ rightmost
- width
) / 2;
2183 btm
= - descent
+ boff
;
2184 if (font_info
&& font_info
->relative_compose
2185 && (! CHAR_TABLE_P (Vignore_relative_composition
)
2186 || NILP (Faref (Vignore_relative_composition
,
2187 make_number (ch
)))))
2190 if (- descent
>= font_info
->relative_compose
)
2191 /* One extra pixel between two glyphs. */
2193 else if (ascent
<= 0)
2194 /* One extra pixel between two glyphs. */
2195 btm
= lowest
- 1 - ascent
- descent
;
2200 /* A composition rule is specified by an integer
2201 value that encodes global and new reference
2202 points (GREF and NREF). GREF and NREF are
2203 specified by numbers as below:
2211 ---3---4---5--- baseline
2213 6---7---8 -- descent
2215 int rule
= COMPOSITION_RULE (cmp
, i
);
2216 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
2218 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
2219 grefx
= gref
% 3, nrefx
= nref
% 3;
2220 grefy
= gref
/ 3, nrefy
= nref
/ 3;
2223 + grefx
* (rightmost
- leftmost
) / 2
2224 - nrefx
* width
/ 2);
2225 btm
= ((grefy
== 0 ? highest
2227 : grefy
== 2 ? lowest
2228 : (highest
+ lowest
) / 2)
2229 - (nrefy
== 0 ? ascent
+ descent
2230 : nrefy
== 1 ? descent
- boff
2232 : (ascent
+ descent
) / 2));
2235 cmp
->offsets
[i
* 2] = left
;
2236 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
2238 /* Update the bounding box of the overall glyphs. */
2239 right
= left
+ width
;
2240 top
= btm
+ descent
+ ascent
;
2241 if (left
< leftmost
)
2243 if (right
> rightmost
)
2251 /* If there are glyphs whose x-offsets are negative,
2252 shift all glyphs to the right and make all x-offsets
2256 for (i
= 0; i
< cmp
->glyph_len
; i
++)
2257 cmp
->offsets
[i
* 2] -= leftmost
;
2258 rightmost
-= leftmost
;
2261 cmp
->pixel_width
= rightmost
;
2262 cmp
->ascent
= highest
;
2263 cmp
->descent
= - lowest
;
2264 if (cmp
->ascent
< font_ascent
)
2265 cmp
->ascent
= font_ascent
;
2266 if (cmp
->descent
< font_descent
)
2267 cmp
->descent
= font_descent
;
2270 it
->pixel_width
= cmp
->pixel_width
;
2271 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
2272 it
->descent
= it
->phys_descent
= cmp
->descent
;
2274 if (face
->box
!= FACE_NO_BOX
)
2276 int thick
= face
->box_line_width
;
2280 it
->ascent
+= thick
;
2281 it
->descent
+= thick
;
2286 if (it
->start_of_box_run_p
)
2287 it
->pixel_width
+= thick
;
2288 if (it
->end_of_box_run_p
)
2289 it
->pixel_width
+= thick
;
2292 /* If face has an overline, add the height of the overline
2293 (1 pixel) and a 1 pixel margin to the character height. */
2294 if (face
->overline_p
)
2297 take_vertical_position_into_account (it
);
2300 x_append_composite_glyph (it
);
2302 else if (it
->what
== IT_IMAGE
)
2303 x_produce_image_glyph (it
);
2304 else if (it
->what
== IT_STRETCH
)
2305 x_produce_stretch_glyph (it
);
2307 /* Accumulate dimensions. Note: can't assume that it->descent > 0
2308 because this isn't true for images with `:ascent 100'. */
2309 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
2310 if (it
->area
== TEXT_AREA
)
2311 it
->current_x
+= it
->pixel_width
;
2313 it
->descent
+= it
->extra_line_spacing
;
2315 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
2316 it
->max_descent
= max (it
->max_descent
, it
->descent
);
2317 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
2318 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
2322 /* Estimate the pixel height of the mode or top line on frame F.
2323 FACE_ID specifies what line's height to estimate. */
2326 x_estimate_mode_line_height (f
, face_id
)
2328 enum face_id face_id
;
2330 int height
= FONT_HEIGHT (FRAME_FONT (f
));
2332 /* This function is called so early when Emacs starts that the face
2333 cache and mode line face are not yet initialized. */
2334 if (FRAME_FACE_CACHE (f
))
2336 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2340 height
= FONT_HEIGHT (face
->font
);
2341 if (face
->box_line_width
> 0)
2342 height
+= 2 * face
->box_line_width
;
2350 /***********************************************************************
2352 ***********************************************************************/
2354 /* A sequence of glyphs to be drawn in the same face.
2356 This data structure is not really completely X specific, so it
2357 could possibly, at least partially, be useful for other systems. It
2358 is currently not part of the external redisplay interface because
2359 it's not clear what other systems will need. */
2363 /* X-origin of the string. */
2366 /* Y-origin and y-position of the base line of this string. */
2369 /* The width of the string, not including a face extension. */
2372 /* The width of the string, including a face extension. */
2373 int background_width
;
2375 /* The height of this string. This is the height of the line this
2376 string is drawn in, and can be different from the height of the
2377 font the string is drawn in. */
2380 /* Number of pixels this string overwrites in front of its x-origin.
2381 This number is zero if the string has an lbearing >= 0; it is
2382 -lbearing, if the string has an lbearing < 0. */
2385 /* Number of pixels this string overwrites past its right-most
2386 nominal x-position, i.e. x + width. Zero if the string's
2387 rbearing is <= its nominal width, rbearing - width otherwise. */
2390 /* The frame on which the glyph string is drawn. */
2393 /* The window on which the glyph string is drawn. */
2396 /* X display and window for convenience. */
2400 /* The glyph row for which this string was built. It determines the
2401 y-origin and height of the string. */
2402 struct glyph_row
*row
;
2404 /* The area within row. */
2405 enum glyph_row_area area
;
2407 /* Characters to be drawn, and number of characters. */
2411 /* A face-override for drawing cursors, mouse face and similar. */
2412 enum draw_glyphs_face hl
;
2414 /* Face in which this string is to be drawn. */
2417 /* Font in which this string is to be drawn. */
2420 /* Font info for this string. */
2421 struct font_info
*font_info
;
2423 /* Non-null means this string describes (part of) a composition.
2424 All characters from char2b are drawn composed. */
2425 struct composition
*cmp
;
2427 /* Index of this glyph string's first character in the glyph
2428 definition of CMP. If this is zero, this glyph string describes
2429 the first character of a composition. */
2432 /* 1 means this glyph strings face has to be drawn to the right end
2433 of the window's drawing area. */
2434 unsigned extends_to_end_of_line_p
: 1;
2436 /* 1 means the background of this string has been drawn. */
2437 unsigned background_filled_p
: 1;
2439 /* 1 means glyph string must be drawn with 16-bit functions. */
2440 unsigned two_byte_p
: 1;
2442 /* 1 means that the original font determined for drawing this glyph
2443 string could not be loaded. The member `font' has been set to
2444 the frame's default font in this case. */
2445 unsigned font_not_found_p
: 1;
2447 /* 1 means that the face in which this glyph string is drawn has a
2449 unsigned stippled_p
: 1;
2451 /* 1 means only the foreground of this glyph string must be drawn,
2452 and we should use the physical height of the line this glyph
2453 string appears in as clip rect. */
2454 unsigned for_overlaps_p
: 1;
2456 /* The GC to use for drawing this glyph string. */
2459 /* A pointer to the first glyph in the string. This glyph
2460 corresponds to char2b[0]. Needed to draw rectangles if
2461 font_not_found_p is 1. */
2462 struct glyph
*first_glyph
;
2464 /* Image, if any. */
2467 struct glyph_string
*next
, *prev
;
2474 x_dump_glyph_string (s
)
2475 struct glyph_string
*s
;
2477 fprintf (stderr
, "glyph string\n");
2478 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
2479 s
->x
, s
->y
, s
->width
, s
->height
);
2480 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
2481 fprintf (stderr
, " hl = %d\n", s
->hl
);
2482 fprintf (stderr
, " left overhang = %d, right = %d\n",
2483 s
->left_overhang
, s
->right_overhang
);
2484 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
2485 fprintf (stderr
, " extends to end of line = %d\n",
2486 s
->extends_to_end_of_line_p
);
2487 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
2488 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
2491 #endif /* GLYPH_DEBUG */
2495 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
2496 struct glyph_string
**,
2497 struct glyph_string
*,
2498 struct glyph_string
*));
2499 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
2500 struct glyph_string
**,
2501 struct glyph_string
*,
2502 struct glyph_string
*));
2503 static void x_append_glyph_string
P_ ((struct glyph_string
**,
2504 struct glyph_string
**,
2505 struct glyph_string
*));
2506 static int x_left_overwritten
P_ ((struct glyph_string
*));
2507 static int x_left_overwriting
P_ ((struct glyph_string
*));
2508 static int x_right_overwritten
P_ ((struct glyph_string
*));
2509 static int x_right_overwriting
P_ ((struct glyph_string
*));
2510 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
2512 static void x_init_glyph_string
P_ ((struct glyph_string
*,
2513 XChar2b
*, struct window
*,
2515 enum glyph_row_area
, int,
2516 enum draw_glyphs_face
));
2517 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
2518 enum glyph_row_area
, int, int,
2519 enum draw_glyphs_face
, int));
2520 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2521 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2522 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2524 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2525 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2526 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2527 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2528 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2529 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2530 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2531 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2532 static void x_get_glyph_overhangs
P_ ((struct glyph
*, struct frame
*,
2534 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
2535 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
2536 unsigned long *, double, int));
2537 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2538 double, int, unsigned long));
2539 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2540 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2541 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2542 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2543 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
2544 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
2545 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2547 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2548 int, int, int, int, XRectangle
*));
2549 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2550 int, int, int, XRectangle
*));
2551 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
2552 enum glyph_row_area
));
2553 static int x_fill_stretch_glyph_string
P_ ((struct glyph_string
*,
2555 enum glyph_row_area
, int, int));
2558 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
2562 /* Append the list of glyph strings with head H and tail T to the list
2563 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
2566 x_append_glyph_string_lists (head
, tail
, h
, t
)
2567 struct glyph_string
**head
, **tail
;
2568 struct glyph_string
*h
, *t
;
2582 /* Prepend the list of glyph strings with head H and tail T to the
2583 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
2587 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
2588 struct glyph_string
**head
, **tail
;
2589 struct glyph_string
*h
, *t
;
2603 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
2604 Set *HEAD and *TAIL to the resulting list. */
2607 x_append_glyph_string (head
, tail
, s
)
2608 struct glyph_string
**head
, **tail
;
2609 struct glyph_string
*s
;
2611 s
->next
= s
->prev
= NULL
;
2612 x_append_glyph_string_lists (head
, tail
, s
, s
);
2616 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2621 struct glyph_string
*s
;
2623 if (s
->font
== FRAME_FONT (s
->f
)
2624 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2625 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2627 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
2630 /* Cursor on non-default face: must merge. */
2634 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
2635 xgcv
.foreground
= s
->face
->background
;
2637 /* If the glyph would be invisible, try a different foreground. */
2638 if (xgcv
.foreground
== xgcv
.background
)
2639 xgcv
.foreground
= s
->face
->foreground
;
2640 if (xgcv
.foreground
== xgcv
.background
)
2641 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
2642 if (xgcv
.foreground
== xgcv
.background
)
2643 xgcv
.foreground
= s
->face
->foreground
;
2645 /* Make sure the cursor is distinct from text in this face. */
2646 if (xgcv
.background
== s
->face
->background
2647 && xgcv
.foreground
== s
->face
->foreground
)
2649 xgcv
.background
= s
->face
->foreground
;
2650 xgcv
.foreground
= s
->face
->background
;
2653 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2654 xgcv
.font
= s
->font
->fid
;
2655 xgcv
.graphics_exposures
= False
;
2656 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2658 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2659 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2662 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2663 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2665 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2670 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2673 x_set_mouse_face_gc (s
)
2674 struct glyph_string
*s
;
2679 /* What face has to be used last for the mouse face? */
2680 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2681 face
= FACE_FROM_ID (s
->f
, face_id
);
2683 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
2685 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2686 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2688 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2689 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2690 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2692 /* If font in this face is same as S->font, use it. */
2693 if (s
->font
== s
->face
->font
)
2694 s
->gc
= s
->face
->gc
;
2697 /* Otherwise construct scratch_cursor_gc with values from FACE
2702 xgcv
.background
= s
->face
->background
;
2703 xgcv
.foreground
= s
->face
->foreground
;
2704 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2705 xgcv
.font
= s
->font
->fid
;
2706 xgcv
.graphics_exposures
= False
;
2707 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2709 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2710 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2713 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2714 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2716 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2719 xassert (s
->gc
!= 0);
2723 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2724 Faces to use in the mode line have already been computed when the
2725 matrix was built, so there isn't much to do, here. */
2728 x_set_mode_line_face_gc (s
)
2729 struct glyph_string
*s
;
2731 s
->gc
= s
->face
->gc
;
2735 /* Set S->gc of glyph string S for drawing that glyph string. Set
2736 S->stippled_p to a non-zero value if the face of S has a stipple
2740 x_set_glyph_string_gc (s
)
2741 struct glyph_string
*s
;
2743 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2745 if (s
->hl
== DRAW_NORMAL_TEXT
)
2747 s
->gc
= s
->face
->gc
;
2748 s
->stippled_p
= s
->face
->stipple
!= 0;
2750 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2752 x_set_mode_line_face_gc (s
);
2753 s
->stippled_p
= s
->face
->stipple
!= 0;
2755 else if (s
->hl
== DRAW_CURSOR
)
2757 x_set_cursor_gc (s
);
2760 else if (s
->hl
== DRAW_MOUSE_FACE
)
2762 x_set_mouse_face_gc (s
);
2763 s
->stippled_p
= s
->face
->stipple
!= 0;
2765 else if (s
->hl
== DRAW_IMAGE_RAISED
2766 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2768 s
->gc
= s
->face
->gc
;
2769 s
->stippled_p
= s
->face
->stipple
!= 0;
2773 s
->gc
= s
->face
->gc
;
2774 s
->stippled_p
= s
->face
->stipple
!= 0;
2777 /* GC must have been set. */
2778 xassert (s
->gc
!= 0);
2782 /* Return in *R the clipping rectangle for glyph string S. */
2785 x_get_glyph_string_clip_rect (s
, r
)
2786 struct glyph_string
*s
;
2789 if (s
->row
->full_width_p
)
2791 /* Draw full-width. X coordinates are relative to S->w->left. */
2792 int canon_x
= CANON_X_UNIT (s
->f
);
2794 r
->x
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
2795 r
->width
= XFASTINT (s
->w
->width
) * canon_x
;
2797 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
2799 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
2800 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
2804 r
->x
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
2806 /* Unless displaying a mode or menu bar line, which are always
2807 fully visible, clip to the visible part of the row. */
2808 if (s
->w
->pseudo_window_p
)
2809 r
->height
= s
->row
->visible_height
;
2811 r
->height
= s
->height
;
2815 /* This is a text line that may be partially visible. */
2816 r
->x
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
2817 r
->width
= window_box_width (s
->w
, s
->area
);
2818 r
->height
= s
->row
->visible_height
;
2821 /* If S draws overlapping rows, it's sufficient to use the top and
2822 bottom of the window for clipping because this glyph string
2823 intentionally draws over other lines. */
2824 if (s
->for_overlaps_p
)
2826 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2827 r
->height
= window_text_bottom_y (s
->w
) - r
->y
;
2831 /* Don't use S->y for clipping because it doesn't take partially
2832 visible lines into account. For example, it can be negative for
2833 partially visible lines at the top of a window. */
2834 if (!s
->row
->full_width_p
2835 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2836 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2838 r
->y
= max (0, s
->row
->y
);
2840 /* If drawing a tool-bar window, draw it over the internal border
2841 at the top of the window. */
2842 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
2843 r
->y
-= s
->f
->output_data
.x
->internal_border_width
;
2846 r
->y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->y
);
2850 /* Set clipping for output of glyph string S. S may be part of a mode
2851 line or menu if we don't have X toolkit support. */
2854 x_set_glyph_string_clipping (s
)
2855 struct glyph_string
*s
;
2858 x_get_glyph_string_clip_rect (s
, &r
);
2859 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
2863 /* Compute left and right overhang of glyph string S. If S is a glyph
2864 string for a composition, assume overhangs don't exist. */
2867 x_compute_glyph_string_overhangs (s
)
2868 struct glyph_string
*s
;
2871 && s
->first_glyph
->type
== CHAR_GLYPH
)
2874 int direction
, font_ascent
, font_descent
;
2875 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
2876 &font_ascent
, &font_descent
, &cs
);
2877 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
2878 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
2883 /* Compute overhangs and x-positions for glyph string S and its
2884 predecessors, or successors. X is the starting x-position for S.
2885 BACKWARD_P non-zero means process predecessors. */
2888 x_compute_overhangs_and_x (s
, x
, backward_p
)
2889 struct glyph_string
*s
;
2897 x_compute_glyph_string_overhangs (s
);
2907 x_compute_glyph_string_overhangs (s
);
2916 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
2917 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
2918 assumed to be zero. */
2921 x_get_glyph_overhangs (glyph
, f
, left
, right
)
2922 struct glyph
*glyph
;
2928 if (glyph
->type
== CHAR_GLYPH
)
2932 struct font_info
*font_info
;
2936 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
2938 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
2940 && (pcm
= x_per_char_metric (font
, &char2b
)))
2942 if (pcm
->rbearing
> pcm
->width
)
2943 *right
= pcm
->rbearing
- pcm
->width
;
2944 if (pcm
->lbearing
< 0)
2945 *left
= -pcm
->lbearing
;
2951 /* Return the index of the first glyph preceding glyph string S that
2952 is overwritten by S because of S's left overhang. Value is -1
2953 if no glyphs are overwritten. */
2956 x_left_overwritten (s
)
2957 struct glyph_string
*s
;
2961 if (s
->left_overhang
)
2964 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2965 int first
= s
->first_glyph
- glyphs
;
2967 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
2968 x
-= glyphs
[i
].pixel_width
;
2979 /* Return the index of the first glyph preceding glyph string S that
2980 is overwriting S because of its right overhang. Value is -1 if no
2981 glyph in front of S overwrites S. */
2984 x_left_overwriting (s
)
2985 struct glyph_string
*s
;
2988 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2989 int first
= s
->first_glyph
- glyphs
;
2993 for (i
= first
- 1; i
>= 0; --i
)
2996 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
2999 x
-= glyphs
[i
].pixel_width
;
3006 /* Return the index of the last glyph following glyph string S that is
3007 not overwritten by S because of S's right overhang. Value is -1 if
3008 no such glyph is found. */
3011 x_right_overwritten (s
)
3012 struct glyph_string
*s
;
3016 if (s
->right_overhang
)
3019 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3020 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3021 int end
= s
->row
->used
[s
->area
];
3023 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
3024 x
+= glyphs
[i
].pixel_width
;
3033 /* Return the index of the last glyph following glyph string S that
3034 overwrites S because of its left overhang. Value is negative
3035 if no such glyph is found. */
3038 x_right_overwriting (s
)
3039 struct glyph_string
*s
;
3042 int end
= s
->row
->used
[s
->area
];
3043 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3044 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3048 for (i
= first
; i
< end
; ++i
)
3051 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3054 x
+= glyphs
[i
].pixel_width
;
3061 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
3064 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
3065 struct glyph_string
*s
;
3069 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
3070 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3071 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3072 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3076 /* Draw the background of glyph_string S. If S->background_filled_p
3077 is non-zero don't draw it. FORCE_P non-zero means draw the
3078 background even if it wouldn't be drawn normally. This is used
3079 when a string preceding S draws into the background of S, or S
3080 contains the first component of a composition. */
3083 x_draw_glyph_string_background (s
, force_p
)
3084 struct glyph_string
*s
;
3087 /* Nothing to do if background has already been drawn or if it
3088 shouldn't be drawn in the first place. */
3089 if (!s
->background_filled_p
)
3091 int box_line_width
= max (s
->face
->box_line_width
, 0);
3095 /* Fill background with a stipple pattern. */
3096 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3097 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
3098 s
->y
+ box_line_width
,
3099 s
->background_width
,
3100 s
->height
- 2 * box_line_width
);
3101 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3102 s
->background_filled_p
= 1;
3104 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
3105 || s
->font_not_found_p
3106 || s
->extends_to_end_of_line_p
3109 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
3110 s
->background_width
,
3111 s
->height
- 2 * box_line_width
);
3112 s
->background_filled_p
= 1;
3118 /* Draw the foreground of glyph string S. */
3121 x_draw_glyph_string_foreground (s
)
3122 struct glyph_string
*s
;
3126 /* If first glyph of S has a left box line, start drawing the text
3127 of S to the right of that box line. */
3128 if (s
->face
->box
!= FACE_NO_BOX
3129 && s
->first_glyph
->left_box_line_p
)
3130 x
= s
->x
+ abs (s
->face
->box_line_width
);
3134 /* Draw characters of S as rectangles if S's font could not be
3136 if (s
->font_not_found_p
)
3138 for (i
= 0; i
< s
->nchars
; ++i
)
3140 struct glyph
*g
= s
->first_glyph
+ i
;
3141 XDrawRectangle (s
->display
, s
->window
,
3142 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
3144 x
+= g
->pixel_width
;
3149 char *char1b
= (char *) s
->char2b
;
3150 int boff
= s
->font_info
->baseline_offset
;
3152 if (s
->font_info
->vertical_centering
)
3153 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
3155 /* If we can use 8-bit functions, condense S->char2b. */
3157 for (i
= 0; i
< s
->nchars
; ++i
)
3158 char1b
[i
] = s
->char2b
[i
].byte2
;
3160 /* Draw text with XDrawString if background has already been
3161 filled. Otherwise, use XDrawImageString. (Note that
3162 XDrawImageString is usually faster than XDrawString.) Always
3163 use XDrawImageString when drawing the cursor so that there is
3164 no chance that characters under a box cursor are invisible. */
3165 if (s
->for_overlaps_p
3166 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
3168 /* Draw characters with 16-bit or 8-bit functions. */
3170 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
3171 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3173 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
3174 s
->ybase
- boff
, char1b
, s
->nchars
);
3179 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
3180 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3182 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
3183 s
->ybase
- boff
, char1b
, s
->nchars
);
3188 /* Draw the foreground of composite glyph string S. */
3191 x_draw_composite_glyph_string_foreground (s
)
3192 struct glyph_string
*s
;
3196 /* If first glyph of S has a left box line, start drawing the text
3197 of S to the right of that box line. */
3198 if (s
->face
->box
!= FACE_NO_BOX
3199 && s
->first_glyph
->left_box_line_p
)
3200 x
= s
->x
+ abs (s
->face
->box_line_width
);
3204 /* S is a glyph string for a composition. S->gidx is the index of
3205 the first character drawn for glyphs of this composition.
3206 S->gidx == 0 means we are drawing the very first character of
3207 this composition. */
3209 /* Draw a rectangle for the composition if the font for the very
3210 first character of the composition could not be loaded. */
3211 if (s
->font_not_found_p
)
3214 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
3215 s
->width
- 1, s
->height
- 1);
3219 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3220 XDrawString16 (s
->display
, s
->window
, s
->gc
,
3221 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3222 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3228 #ifdef USE_X_TOOLKIT
3230 static struct frame
*x_frame_of_widget
P_ ((Widget
));
3231 static Boolean cvt_string_to_pixel
P_ ((Display
*, XrmValue
*, Cardinal
*,
3232 XrmValue
*, XrmValue
*, XtPointer
*));
3233 static void cvt_pixel_dtor
P_ ((XtAppContext
, XrmValue
*, XtPointer
,
3234 XrmValue
*, Cardinal
*));
3237 /* Return the frame on which widget WIDGET is used.. Abort if frame
3238 cannot be determined. */
3240 static struct frame
*
3241 x_frame_of_widget (widget
)
3244 struct x_display_info
*dpyinfo
;
3248 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
3250 /* Find the top-level shell of the widget. Note that this function
3251 can be called when the widget is not yet realized, so XtWindow
3252 (widget) == 0. That's the reason we can't simply use
3253 x_any_window_to_frame. */
3254 while (!XtIsTopLevelShell (widget
))
3255 widget
= XtParent (widget
);
3257 /* Look for a frame with that top-level widget. Allocate the color
3258 on that frame to get the right gamma correction value. */
3259 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
3260 if (GC_FRAMEP (XCAR (tail
))
3261 && (f
= XFRAME (XCAR (tail
)),
3262 (f
->output_data
.nothing
!= 1
3263 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
3264 && f
->output_data
.x
->widget
== widget
)
3271 /* Allocate the color COLOR->pixel on the screen and display of
3272 widget WIDGET in colormap CMAP. If an exact match cannot be
3273 allocated, try the nearest color available. Value is non-zero
3274 if successful. This is called from lwlib. */
3277 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
3282 struct frame
*f
= x_frame_of_widget (widget
);
3283 return x_alloc_nearest_color (f
, cmap
, color
);
3287 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3288 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3289 If this produces the same color as PIXEL, try a color where all RGB
3290 values have DELTA added. Return the allocated color in *PIXEL.
3291 DISPLAY is the X display, CMAP is the colormap to operate on.
3292 Value is non-zero if successful. */
3295 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
3299 unsigned long *pixel
;
3303 struct frame
*f
= x_frame_of_widget (widget
);
3304 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
3308 /* Structure specifying which arguments should be passed by Xt to
3309 cvt_string_to_pixel. We want the widget's screen and colormap. */
3311 static XtConvertArgRec cvt_string_to_pixel_args
[] =
3313 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
3315 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
3320 /* The address of this variable is returned by
3321 cvt_string_to_pixel. */
3323 static Pixel cvt_string_to_pixel_value
;
3326 /* Convert a color name to a pixel color.
3328 DPY is the display we are working on.
3330 ARGS is an array of *NARGS XrmValue structures holding additional
3331 information about the widget for which the conversion takes place.
3332 The contents of this array are determined by the specification
3333 in cvt_string_to_pixel_args.
3335 FROM is a pointer to an XrmValue which points to the color name to
3336 convert. TO is an XrmValue in which to return the pixel color.
3338 CLOSURE_RET is a pointer to user-data, in which we record if
3339 we allocated the color or not.
3341 Value is True if successful, False otherwise. */
3344 cvt_string_to_pixel (dpy
, args
, nargs
, from
, to
, closure_ret
)
3348 XrmValue
*from
, *to
;
3349 XtPointer
*closure_ret
;
3359 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
3360 "wrongParameters", "cvt_string_to_pixel",
3362 "Screen and colormap args required", NULL
, NULL
);
3366 screen
= *(Screen
**) args
[0].addr
;
3367 cmap
= *(Colormap
*) args
[1].addr
;
3368 color_name
= (String
) from
->addr
;
3370 if (strcmp (color_name
, XtDefaultBackground
) == 0)
3372 *closure_ret
= (XtPointer
) False
;
3373 pixel
= WhitePixelOfScreen (screen
);
3375 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
3377 *closure_ret
= (XtPointer
) False
;
3378 pixel
= BlackPixelOfScreen (screen
);
3380 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
3381 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
3383 pixel
= color
.pixel
;
3384 *closure_ret
= (XtPointer
) True
;
3389 Cardinal nparams
= 1;
3391 params
[0] = color_name
;
3392 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
3393 "badValue", "cvt_string_to_pixel",
3394 "XtToolkitError", "Invalid color `%s'",
3399 if (to
->addr
!= NULL
)
3401 if (to
->size
< sizeof (Pixel
))
3403 to
->size
= sizeof (Pixel
);
3407 *(Pixel
*) to
->addr
= pixel
;
3411 cvt_string_to_pixel_value
= pixel
;
3412 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
3415 to
->size
= sizeof (Pixel
);
3420 /* Free a pixel color which was previously allocated via
3421 cvt_string_to_pixel. This is registered as the destructor
3422 for this type of resource via XtSetTypeConverter.
3424 APP is the application context in which we work.
3426 TO is a pointer to an XrmValue holding the color to free.
3427 CLOSURE is the value we stored in CLOSURE_RET for this color
3428 in cvt_string_to_pixel.
3430 ARGS and NARGS are like for cvt_string_to_pixel. */
3433 cvt_pixel_dtor (app
, to
, closure
, args
, nargs
)
3442 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
3444 "Screen and colormap arguments required",
3447 else if (closure
!= NULL
)
3449 /* We did allocate the pixel, so free it. */
3450 Screen
*screen
= *(Screen
**) args
[0].addr
;
3451 Colormap cmap
= *(Colormap
*) args
[1].addr
;
3452 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
3453 (Pixel
*) to
->addr
, 1);
3458 #endif /* USE_X_TOOLKIT */
3461 /* Value is an array of XColor structures for the contents of the
3462 color map of display DPY. Set *NCELLS to the size of the array.
3463 Note that this probably shouldn't be called for large color maps,
3464 say a 24-bit TrueColor map. */
3466 static const XColor
*
3467 x_color_cells (dpy
, ncells
)
3471 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
3473 if (dpyinfo
->color_cells
== NULL
)
3475 Screen
*screen
= dpyinfo
->screen
;
3478 dpyinfo
->ncolor_cells
3479 = XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
3480 dpyinfo
->color_cells
3481 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
3482 * sizeof *dpyinfo
->color_cells
);
3484 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
3485 dpyinfo
->color_cells
[i
].pixel
= i
;
3487 XQueryColors (dpy
, dpyinfo
->cmap
,
3488 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
3491 *ncells
= dpyinfo
->ncolor_cells
;
3492 return dpyinfo
->color_cells
;
3496 /* On frame F, translate pixel colors to RGB values for the NCOLORS
3497 colors in COLORS. Use cached information, if available. */
3500 x_query_colors (f
, colors
, ncolors
)
3505 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3507 if (dpyinfo
->color_cells
)
3510 for (i
= 0; i
< ncolors
; ++i
)
3512 unsigned long pixel
= colors
[i
].pixel
;
3513 xassert (pixel
< dpyinfo
->ncolor_cells
);
3514 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
3515 colors
[i
] = dpyinfo
->color_cells
[pixel
];
3519 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
3523 /* On frame F, translate pixel color to RGB values for the color in
3524 COLOR. Use cached information, if available. */
3527 x_query_color (f
, color
)
3531 x_query_colors (f
, color
, 1);
3535 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
3536 exact match can't be allocated, try the nearest color available.
3537 Value is non-zero if successful. Set *COLOR to the color
3541 x_alloc_nearest_color_1 (dpy
, cmap
, color
)
3548 rc
= XAllocColor (dpy
, cmap
, color
);
3551 /* If we got to this point, the colormap is full, so we're going
3552 to try to get the next closest color. The algorithm used is
3553 a least-squares matching, which is what X uses for closest
3554 color matching with StaticColor visuals. */
3556 unsigned long nearest_delta
= ~0;
3558 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
3560 for (nearest
= i
= 0; i
< ncells
; ++i
)
3562 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
3563 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
3564 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
3565 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
3567 if (delta
< nearest_delta
)
3570 nearest_delta
= delta
;
3574 color
->red
= cells
[nearest
].red
;
3575 color
->green
= cells
[nearest
].green
;
3576 color
->blue
= cells
[nearest
].blue
;
3577 rc
= XAllocColor (dpy
, cmap
, color
);
3581 /* If allocation succeeded, and the allocated pixel color is not
3582 equal to a cached pixel color recorded earlier, there was a
3583 change in the colormap, so clear the color cache. */
3584 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
3585 XColor
*cached_color
;
3587 if (dpyinfo
->color_cells
3588 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
3589 (cached_color
->red
!= color
->red
3590 || cached_color
->blue
!= color
->blue
3591 || cached_color
->green
!= color
->green
)))
3593 xfree (dpyinfo
->color_cells
);
3594 dpyinfo
->color_cells
= NULL
;
3595 dpyinfo
->ncolor_cells
= 0;
3599 #ifdef DEBUG_X_COLORS
3601 register_color (color
->pixel
);
3602 #endif /* DEBUG_X_COLORS */
3608 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
3609 exact match can't be allocated, try the nearest color available.
3610 Value is non-zero if successful. Set *COLOR to the color
3614 x_alloc_nearest_color (f
, cmap
, color
)
3619 gamma_correct (f
, color
);
3620 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
3624 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
3625 It's necessary to do this instead of just using PIXEL directly to
3626 get color reference counts right. */
3629 x_copy_color (f
, pixel
)
3631 unsigned long pixel
;
3635 color
.pixel
= pixel
;
3637 x_query_color (f
, &color
);
3638 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3640 #ifdef DEBUG_X_COLORS
3641 register_color (pixel
);
3647 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
3648 It's necessary to do this instead of just using PIXEL directly to
3649 get color reference counts right. */
3652 x_copy_dpy_color (dpy
, cmap
, pixel
)
3655 unsigned long pixel
;
3659 color
.pixel
= pixel
;
3661 XQueryColor (dpy
, cmap
, &color
);
3662 XAllocColor (dpy
, cmap
, &color
);
3664 #ifdef DEBUG_X_COLORS
3665 register_color (pixel
);
3671 /* Brightness beyond which a color won't have its highlight brightness
3674 Nominally, highlight colors for `3d' faces are calculated by
3675 brightening an object's color by a constant scale factor, but this
3676 doesn't yield good results for dark colors, so for colors who's
3677 brightness is less than this value (on a scale of 0-65535) have an
3678 use an additional additive factor.
3680 The value here is set so that the default menu-bar/mode-line color
3681 (grey75) will not have its highlights changed at all. */
3682 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
3685 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3686 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3687 If this produces the same color as PIXEL, try a color where all RGB
3688 values have DELTA added. Return the allocated color in *PIXEL.
3689 DISPLAY is the X display, CMAP is the colormap to operate on.
3690 Value is non-zero if successful. */
3693 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
3697 unsigned long *pixel
;
3705 /* Get RGB color values. */
3706 color
.pixel
= *pixel
;
3707 x_query_color (f
, &color
);
3709 /* Change RGB values by specified FACTOR. Avoid overflow! */
3710 xassert (factor
>= 0);
3711 new.red
= min (0xffff, factor
* color
.red
);
3712 new.green
= min (0xffff, factor
* color
.green
);
3713 new.blue
= min (0xffff, factor
* color
.blue
);
3715 /* Calculate brightness of COLOR. */
3716 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
3718 /* We only boost colors that are darker than
3719 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
3720 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
3721 /* Make an additive adjustment to NEW, because it's dark enough so
3722 that scaling by FACTOR alone isn't enough. */
3724 /* How far below the limit this color is (0 - 1, 1 being darker). */
3725 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
3726 /* The additive adjustment. */
3727 int min_delta
= delta
* dimness
* factor
/ 2;
3731 new.red
= max (0, new.red
- min_delta
);
3732 new.green
= max (0, new.green
- min_delta
);
3733 new.blue
= max (0, new.blue
- min_delta
);
3737 new.red
= min (0xffff, min_delta
+ new.red
);
3738 new.green
= min (0xffff, min_delta
+ new.green
);
3739 new.blue
= min (0xffff, min_delta
+ new.blue
);
3743 /* Try to allocate the color. */
3744 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3747 if (new.pixel
== *pixel
)
3749 /* If we end up with the same color as before, try adding
3750 delta to the RGB values. */
3751 x_free_colors (f
, &new.pixel
, 1);
3753 new.red
= min (0xffff, delta
+ color
.red
);
3754 new.green
= min (0xffff, delta
+ color
.green
);
3755 new.blue
= min (0xffff, delta
+ color
.blue
);
3756 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3767 /* Set up the foreground color for drawing relief lines of glyph
3768 string S. RELIEF is a pointer to a struct relief containing the GC
3769 with which lines will be drawn. Use a color that is FACTOR or
3770 DELTA lighter or darker than the relief's background which is found
3771 in S->f->output_data.x->relief_background. If such a color cannot
3772 be allocated, use DEFAULT_PIXEL, instead. */
3775 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3777 struct relief
*relief
;
3780 unsigned long default_pixel
;
3783 struct x_output
*di
= f
->output_data
.x
;
3784 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
3785 unsigned long pixel
;
3786 unsigned long background
= di
->relief_background
;
3787 Colormap cmap
= FRAME_X_COLORMAP (f
);
3788 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3789 Display
*dpy
= FRAME_X_DISPLAY (f
);
3791 xgcv
.graphics_exposures
= False
;
3792 xgcv
.line_width
= 1;
3794 /* Free previously allocated color. The color cell will be reused
3795 when it has been freed as many times as it was allocated, so this
3796 doesn't affect faces using the same colors. */
3798 && relief
->allocated_p
)
3800 x_free_colors (f
, &relief
->pixel
, 1);
3801 relief
->allocated_p
= 0;
3804 /* Allocate new color. */
3805 xgcv
.foreground
= default_pixel
;
3807 if (dpyinfo
->n_planes
!= 1
3808 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
3810 relief
->allocated_p
= 1;
3811 xgcv
.foreground
= relief
->pixel
= pixel
;
3814 if (relief
->gc
== 0)
3816 xgcv
.stipple
= dpyinfo
->gray
;
3818 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
3821 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
3825 /* Set up colors for the relief lines around glyph string S. */
3828 x_setup_relief_colors (s
)
3829 struct glyph_string
*s
;
3831 struct x_output
*di
= s
->f
->output_data
.x
;
3832 unsigned long color
;
3834 if (s
->face
->use_box_color_for_shadows_p
)
3835 color
= s
->face
->box_color
;
3836 else if (s
->first_glyph
->type
== IMAGE_GLYPH
3837 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
3838 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
3843 /* Get the background color of the face. */
3844 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3845 color
= xgcv
.background
;
3848 if (di
->white_relief
.gc
== 0
3849 || color
!= di
->relief_background
)
3851 di
->relief_background
= color
;
3852 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3853 WHITE_PIX_DEFAULT (s
->f
));
3854 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3855 BLACK_PIX_DEFAULT (s
->f
));
3860 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3861 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3862 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3863 relief. LEFT_P non-zero means draw a relief on the left side of
3864 the rectangle. RIGHT_P non-zero means draw a relief on the right
3865 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3869 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3870 raised_p
, left_p
, right_p
, clip_rect
)
3872 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
3873 XRectangle
*clip_rect
;
3875 Display
*dpy
= FRAME_X_DISPLAY (f
);
3876 Window window
= FRAME_X_WINDOW (f
);
3881 gc
= f
->output_data
.x
->white_relief
.gc
;
3883 gc
= f
->output_data
.x
->black_relief
.gc
;
3884 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
3887 for (i
= 0; i
< width
; ++i
)
3888 XDrawLine (dpy
, window
, gc
,
3889 left_x
+ i
* left_p
, top_y
+ i
,
3890 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3894 for (i
= 0; i
< width
; ++i
)
3895 XDrawLine (dpy
, window
, gc
,
3896 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
3898 XSetClipMask (dpy
, gc
, None
);
3900 gc
= f
->output_data
.x
->black_relief
.gc
;
3902 gc
= f
->output_data
.x
->white_relief
.gc
;
3903 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
3906 for (i
= 0; i
< width
; ++i
)
3907 XDrawLine (dpy
, window
, gc
,
3908 left_x
+ i
* left_p
, bottom_y
- i
,
3909 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3913 for (i
= 0; i
< width
; ++i
)
3914 XDrawLine (dpy
, window
, gc
,
3915 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3917 XSetClipMask (dpy
, gc
, None
);
3921 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3922 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3923 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3924 left side of the rectangle. RIGHT_P non-zero means draw a line
3925 on the right side of the rectangle. CLIP_RECT is the clipping
3926 rectangle to use when drawing. */
3929 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3930 left_p
, right_p
, clip_rect
)
3931 struct glyph_string
*s
;
3932 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
;
3933 XRectangle
*clip_rect
;
3937 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3938 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
3939 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
3942 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3943 left_x
, top_y
, right_x
- left_x
+ 1, width
);
3947 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3948 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
3951 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3952 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
3956 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3957 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
3959 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3960 XSetClipMask (s
->display
, s
->gc
, None
);
3964 /* Draw a box around glyph string S. */
3967 x_draw_glyph_string_box (s
)
3968 struct glyph_string
*s
;
3970 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3971 int left_p
, right_p
;
3972 struct glyph
*last_glyph
;
3973 XRectangle clip_rect
;
3975 last_x
= window_box_right (s
->w
, s
->area
);
3976 if (s
->row
->full_width_p
3977 && !s
->w
->pseudo_window_p
)
3979 last_x
+= FRAME_X_RIGHT_FRINGE_WIDTH (s
->f
);
3980 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
3981 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
3984 /* The glyph that may have a right box line. */
3985 last_glyph
= (s
->cmp
|| s
->img
3987 : s
->first_glyph
+ s
->nchars
- 1);
3989 width
= abs (s
->face
->box_line_width
);
3990 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
3992 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
3994 : min (last_x
, s
->x
+ s
->background_width
) - 1);
3996 bottom_y
= top_y
+ s
->height
- 1;
3998 left_p
= (s
->first_glyph
->left_box_line_p
3999 || (s
->hl
== DRAW_MOUSE_FACE
4001 || s
->prev
->hl
!= s
->hl
)));
4002 right_p
= (last_glyph
->right_box_line_p
4003 || (s
->hl
== DRAW_MOUSE_FACE
4005 || s
->next
->hl
!= s
->hl
)));
4007 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4009 if (s
->face
->box
== FACE_SIMPLE_BOX
)
4010 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
4011 left_p
, right_p
, &clip_rect
);
4014 x_setup_relief_colors (s
);
4015 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
4016 width
, raised_p
, left_p
, right_p
, &clip_rect
);
4021 /* Draw foreground of image glyph string S. */
4024 x_draw_image_foreground (s
)
4025 struct glyph_string
*s
;
4028 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
4030 /* If first glyph of S has a left box line, start drawing it to the
4031 right of that line. */
4032 if (s
->face
->box
!= FACE_NO_BOX
4033 && s
->first_glyph
->left_box_line_p
)
4034 x
= s
->x
+ abs (s
->face
->box_line_width
);
4038 /* If there is a margin around the image, adjust x- and y-position
4040 x
+= s
->img
->hmargin
;
4041 y
+= s
->img
->vmargin
;
4047 /* We can't set both a clip mask and use XSetClipRectangles
4048 because the latter also sets a clip mask. We also can't
4049 trust on the shape extension to be available
4050 (XShapeCombineRegion). So, compute the rectangle to draw
4052 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4055 XRectangle clip_rect
, image_rect
, r
;
4057 xgcv
.clip_mask
= s
->img
->mask
;
4058 xgcv
.clip_x_origin
= x
;
4059 xgcv
.clip_y_origin
= y
;
4060 xgcv
.function
= GXcopy
;
4061 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4063 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4066 image_rect
.width
= s
->img
->width
;
4067 image_rect
.height
= s
->img
->height
;
4068 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
4069 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
4070 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
4074 XRectangle clip_rect
, image_rect
, r
;
4076 x_get_glyph_string_clip_rect (s
, &clip_rect
);
4079 image_rect
.width
= s
->img
->width
;
4080 image_rect
.height
= s
->img
->height
;
4081 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
4082 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
4083 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
4085 /* When the image has a mask, we can expect that at
4086 least part of a mouse highlight or a block cursor will
4087 be visible. If the image doesn't have a mask, make
4088 a block cursor visible by drawing a rectangle around
4089 the image. I believe it's looking better if we do
4090 nothing here for mouse-face. */
4091 if (s
->hl
== DRAW_CURSOR
)
4092 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
4093 s
->img
->width
- 1, s
->img
->height
- 1);
4097 /* Draw a rectangle if image could not be loaded. */
4098 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
4099 s
->img
->width
- 1, s
->img
->height
- 1);
4103 /* Draw a relief around the image glyph string S. */
4106 x_draw_image_relief (s
)
4107 struct glyph_string
*s
;
4109 int x0
, y0
, x1
, y1
, thick
, raised_p
;
4112 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
4114 /* If first glyph of S has a left box line, start drawing it to the
4115 right of that line. */
4116 if (s
->face
->box
!= FACE_NO_BOX
4117 && s
->first_glyph
->left_box_line_p
)
4118 x
= s
->x
+ abs (s
->face
->box_line_width
);
4122 /* If there is a margin around the image, adjust x- and y-position
4124 x
+= s
->img
->hmargin
;
4125 y
+= s
->img
->vmargin
;
4127 if (s
->hl
== DRAW_IMAGE_SUNKEN
4128 || s
->hl
== DRAW_IMAGE_RAISED
)
4130 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: 3;
4131 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
4135 thick
= abs (s
->img
->relief
);
4136 raised_p
= s
->img
->relief
> 0;
4141 x1
= x
+ s
->img
->width
+ thick
- 1;
4142 y1
= y
+ s
->img
->height
+ thick
- 1;
4144 x_setup_relief_colors (s
);
4145 x_get_glyph_string_clip_rect (s
, &r
);
4146 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
4150 /* Draw the foreground of image glyph string S to PIXMAP. */
4153 x_draw_image_foreground_1 (s
, pixmap
)
4154 struct glyph_string
*s
;
4158 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
4160 /* If first glyph of S has a left box line, start drawing it to the
4161 right of that line. */
4162 if (s
->face
->box
!= FACE_NO_BOX
4163 && s
->first_glyph
->left_box_line_p
)
4164 x
= abs (s
->face
->box_line_width
);
4168 /* If there is a margin around the image, adjust x- and y-position
4170 x
+= s
->img
->hmargin
;
4171 y
+= s
->img
->vmargin
;
4177 /* We can't set both a clip mask and use XSetClipRectangles
4178 because the latter also sets a clip mask. We also can't
4179 trust on the shape extension to be available
4180 (XShapeCombineRegion). So, compute the rectangle to draw
4182 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4186 xgcv
.clip_mask
= s
->img
->mask
;
4187 xgcv
.clip_x_origin
= x
;
4188 xgcv
.clip_y_origin
= y
;
4189 xgcv
.function
= GXcopy
;
4190 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4192 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4193 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4194 XSetClipMask (s
->display
, s
->gc
, None
);
4198 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4199 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4201 /* When the image has a mask, we can expect that at
4202 least part of a mouse highlight or a block cursor will
4203 be visible. If the image doesn't have a mask, make
4204 a block cursor visible by drawing a rectangle around
4205 the image. I believe it's looking better if we do
4206 nothing here for mouse-face. */
4207 if (s
->hl
== DRAW_CURSOR
)
4208 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
4209 s
->img
->width
- 1, s
->img
->height
- 1);
4213 /* Draw a rectangle if image could not be loaded. */
4214 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
4215 s
->img
->width
- 1, s
->img
->height
- 1);
4219 /* Draw part of the background of glyph string S. X, Y, W, and H
4220 give the rectangle to draw. */
4223 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
4224 struct glyph_string
*s
;
4229 /* Fill background with a stipple pattern. */
4230 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4231 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
4232 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4235 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
4239 /* Draw image glyph string S.
4242 s->x +-------------------------
4245 | +-------------------------
4248 | | +-------------------
4254 x_draw_image_glyph_string (s
)
4255 struct glyph_string
*s
;
4258 int box_line_hwidth
= abs (s
->face
->box_line_width
);
4259 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
4261 Pixmap pixmap
= None
;
4263 height
= s
->height
- 2 * box_line_vwidth
;
4265 /* Fill background with face under the image. Do it only if row is
4266 taller than image or if image has a clip mask to reduce
4268 s
->stippled_p
= s
->face
->stipple
!= 0;
4269 if (height
> s
->img
->height
4273 || s
->img
->pixmap
== 0
4274 || s
->width
!= s
->background_width
)
4276 if (box_line_hwidth
&& s
->first_glyph
->left_box_line_p
)
4277 x
= s
->x
+ box_line_hwidth
;
4281 y
= s
->y
+ box_line_vwidth
;
4285 /* Create a pixmap as large as the glyph string. Fill it
4286 with the background color. Copy the image to it, using
4287 its mask. Copy the temporary pixmap to the display. */
4288 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
4289 int depth
= DefaultDepthOfScreen (screen
);
4291 /* Create a pixmap as large as the glyph string. */
4292 pixmap
= XCreatePixmap (s
->display
, s
->window
,
4293 s
->background_width
,
4296 /* Don't clip in the following because we're working on the
4298 XSetClipMask (s
->display
, s
->gc
, None
);
4300 /* Fill the pixmap with the background color/stipple. */
4303 /* Fill background with a stipple pattern. */
4304 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4305 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4306 0, 0, s
->background_width
, s
->height
);
4307 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4312 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
4314 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
4315 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4316 0, 0, s
->background_width
, s
->height
);
4317 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4321 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
4323 s
->background_filled_p
= 1;
4326 /* Draw the foreground. */
4329 x_draw_image_foreground_1 (s
, pixmap
);
4330 x_set_glyph_string_clipping (s
);
4331 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
4332 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
4333 XFreePixmap (s
->display
, pixmap
);
4336 x_draw_image_foreground (s
);
4338 /* If we must draw a relief around the image, do it. */
4340 || s
->hl
== DRAW_IMAGE_RAISED
4341 || s
->hl
== DRAW_IMAGE_SUNKEN
)
4342 x_draw_image_relief (s
);
4346 /* Draw stretch glyph string S. */
4349 x_draw_stretch_glyph_string (s
)
4350 struct glyph_string
*s
;
4352 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4353 s
->stippled_p
= s
->face
->stipple
!= 0;
4355 if (s
->hl
== DRAW_CURSOR
4356 && !x_stretch_cursor_p
)
4358 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
4359 as wide as the stretch glyph. */
4360 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
4363 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
4365 /* Clear rest using the GC of the original non-cursor face. */
4366 if (width
< s
->background_width
)
4368 int x
= s
->x
+ width
, y
= s
->y
;
4369 int w
= s
->background_width
- width
, h
= s
->height
;
4373 if (s
->row
->mouse_face_p
4374 && cursor_in_mouse_face_p (s
->w
))
4376 x_set_mouse_face_gc (s
);
4382 x_get_glyph_string_clip_rect (s
, &r
);
4383 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
4385 if (s
->face
->stipple
)
4387 /* Fill background with a stipple pattern. */
4388 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
4389 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4390 XSetFillStyle (s
->display
, gc
, FillSolid
);
4395 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
4396 XSetForeground (s
->display
, gc
, xgcv
.background
);
4397 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4398 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
4402 else if (!s
->background_filled_p
)
4403 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
4406 s
->background_filled_p
= 1;
4410 /* Draw glyph string S. */
4413 x_draw_glyph_string (s
)
4414 struct glyph_string
*s
;
4416 int relief_drawn_p
= 0;
4418 /* If S draws into the background of its successor, draw the
4419 background of the successor first so that S can draw into it.
4420 This makes S->next use XDrawString instead of XDrawImageString. */
4421 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4423 xassert (s
->next
->img
== NULL
);
4424 x_set_glyph_string_gc (s
->next
);
4425 x_set_glyph_string_clipping (s
->next
);
4426 x_draw_glyph_string_background (s
->next
, 1);
4429 /* Set up S->gc, set clipping and draw S. */
4430 x_set_glyph_string_gc (s
);
4432 /* Draw relief (if any) in advance for char/composition so that the
4433 glyph string can be drawn over it. */
4434 if (!s
->for_overlaps_p
4435 && s
->face
->box
!= FACE_NO_BOX
4436 && (s
->first_glyph
->type
== CHAR_GLYPH
4437 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
4440 x_set_glyph_string_clipping (s
);
4441 x_draw_glyph_string_background (s
, 1);
4442 x_draw_glyph_string_box (s
);
4443 x_set_glyph_string_clipping (s
);
4447 x_set_glyph_string_clipping (s
);
4449 switch (s
->first_glyph
->type
)
4452 x_draw_image_glyph_string (s
);
4456 x_draw_stretch_glyph_string (s
);
4460 if (s
->for_overlaps_p
)
4461 s
->background_filled_p
= 1;
4463 x_draw_glyph_string_background (s
, 0);
4464 x_draw_glyph_string_foreground (s
);
4467 case COMPOSITE_GLYPH
:
4468 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4469 s
->background_filled_p
= 1;
4471 x_draw_glyph_string_background (s
, 1);
4472 x_draw_composite_glyph_string_foreground (s
);
4479 if (!s
->for_overlaps_p
)
4481 /* Draw underline. */
4482 if (s
->face
->underline_p
)
4484 unsigned long tem
, h
;
4487 /* Get the underline thickness. Default is 1 pixel. */
4488 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
4491 /* Get the underline position. This is the recommended
4492 vertical offset in pixels from the baseline to the top of
4493 the underline. This is a signed value according to the
4494 specs, and its default is
4496 ROUND ((maximum descent) / 2), with
4497 ROUND(x) = floor (x + 0.5) */
4499 if (x_use_underline_position_properties
4500 && XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &tem
))
4501 y
= s
->ybase
+ (long) tem
;
4502 else if (s
->face
->font
)
4503 y
= s
->ybase
+ (s
->face
->font
->max_bounds
.descent
+ 1) / 2;
4505 y
= s
->y
+ s
->height
- h
;
4507 if (s
->face
->underline_defaulted_p
)
4508 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4509 s
->x
, y
, s
->width
, h
);
4513 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4514 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
4515 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4516 s
->x
, y
, s
->width
, h
);
4517 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4521 /* Draw overline. */
4522 if (s
->face
->overline_p
)
4524 unsigned long dy
= 0, h
= 1;
4526 if (s
->face
->overline_color_defaulted_p
)
4527 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4532 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4533 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
4534 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4536 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4540 /* Draw strike-through. */
4541 if (s
->face
->strike_through_p
)
4543 unsigned long h
= 1;
4544 unsigned long dy
= (s
->height
- h
) / 2;
4546 if (s
->face
->strike_through_color_defaulted_p
)
4547 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4552 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4553 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
4554 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4556 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4560 /* Draw relief if not yet drawn. */
4561 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
4562 x_draw_glyph_string_box (s
);
4565 /* Reset clipping. */
4566 XSetClipMask (s
->display
, s
->gc
, None
);
4570 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4571 struct face
**, int));
4574 /* Fill glyph string S with composition components specified by S->cmp.
4576 FACES is an array of faces for all components of this composition.
4577 S->gidx is the index of the first component for S.
4578 OVERLAPS_P non-zero means S should draw the foreground only, and
4579 use its physical height for clipping.
4581 Value is the index of a component not in S. */
4584 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4585 struct glyph_string
*s
;
4586 struct face
**faces
;
4593 s
->for_overlaps_p
= overlaps_p
;
4595 s
->face
= faces
[s
->gidx
];
4596 s
->font
= s
->face
->font
;
4597 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4599 /* For all glyphs of this composition, starting at the offset
4600 S->gidx, until we reach the end of the definition or encounter a
4601 glyph that requires the different face, add it to S. */
4603 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4606 /* All glyph strings for the same composition has the same width,
4607 i.e. the width set for the first component of the composition. */
4609 s
->width
= s
->first_glyph
->pixel_width
;
4611 /* If the specified font could not be loaded, use the frame's
4612 default font, but record the fact that we couldn't load it in
4613 the glyph string so that we can draw rectangles for the
4614 characters of the glyph string. */
4615 if (s
->font
== NULL
)
4617 s
->font_not_found_p
= 1;
4618 s
->font
= FRAME_FONT (s
->f
);
4621 /* Adjust base line for subscript/superscript text. */
4622 s
->ybase
+= s
->first_glyph
->voffset
;
4624 xassert (s
->face
&& s
->face
->gc
);
4626 /* This glyph string must always be drawn with 16-bit functions. */
4629 return s
->gidx
+ s
->nchars
;
4633 /* Fill glyph string S from a sequence of character glyphs.
4635 FACE_ID is the face id of the string. START is the index of the
4636 first glyph to consider, END is the index of the last + 1.
4637 OVERLAPS_P non-zero means S should draw the foreground only, and
4638 use its physical height for clipping.
4640 Value is the index of the first glyph not in S. */
4643 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4644 struct glyph_string
*s
;
4646 int start
, end
, overlaps_p
;
4648 struct glyph
*glyph
, *last
;
4650 int glyph_not_available_p
;
4652 xassert (s
->f
== XFRAME (s
->w
->frame
));
4653 xassert (s
->nchars
== 0);
4654 xassert (start
>= 0 && end
> start
);
4656 s
->for_overlaps_p
= overlaps_p
,
4657 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4658 last
= s
->row
->glyphs
[s
->area
] + end
;
4659 voffset
= glyph
->voffset
;
4661 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4664 && glyph
->type
== CHAR_GLYPH
4665 && glyph
->voffset
== voffset
4666 /* Same face id implies same font, nowadays. */
4667 && glyph
->face_id
== face_id
4668 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4672 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4673 s
->char2b
+ s
->nchars
,
4675 s
->two_byte_p
= two_byte_p
;
4677 xassert (s
->nchars
<= end
- start
);
4678 s
->width
+= glyph
->pixel_width
;
4682 s
->font
= s
->face
->font
;
4683 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4685 /* If the specified font could not be loaded, use the frame's font,
4686 but record the fact that we couldn't load it in
4687 S->font_not_found_p so that we can draw rectangles for the
4688 characters of the glyph string. */
4689 if (s
->font
== NULL
|| glyph_not_available_p
)
4691 s
->font_not_found_p
= 1;
4692 s
->font
= FRAME_FONT (s
->f
);
4695 /* Adjust base line for subscript/superscript text. */
4696 s
->ybase
+= voffset
;
4698 xassert (s
->face
&& s
->face
->gc
);
4699 return glyph
- s
->row
->glyphs
[s
->area
];
4703 /* Fill glyph string S from image glyph S->first_glyph. */
4706 x_fill_image_glyph_string (s
)
4707 struct glyph_string
*s
;
4709 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4710 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
4712 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4713 s
->font
= s
->face
->font
;
4714 s
->width
= s
->first_glyph
->pixel_width
;
4716 /* Adjust base line for subscript/superscript text. */
4717 s
->ybase
+= s
->first_glyph
->voffset
;
4721 /* Fill glyph string S from a sequence of stretch glyphs.
4723 ROW is the glyph row in which the glyphs are found, AREA is the
4724 area within the row. START is the index of the first glyph to
4725 consider, END is the index of the last + 1.
4727 Value is the index of the first glyph not in S. */
4730 x_fill_stretch_glyph_string (s
, row
, area
, start
, end
)
4731 struct glyph_string
*s
;
4732 struct glyph_row
*row
;
4733 enum glyph_row_area area
;
4736 struct glyph
*glyph
, *last
;
4737 int voffset
, face_id
;
4739 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4741 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4742 last
= s
->row
->glyphs
[s
->area
] + end
;
4743 face_id
= glyph
->face_id
;
4744 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
4745 s
->font
= s
->face
->font
;
4746 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4747 s
->width
= glyph
->pixel_width
;
4748 voffset
= glyph
->voffset
;
4752 && glyph
->type
== STRETCH_GLYPH
4753 && glyph
->voffset
== voffset
4754 && glyph
->face_id
== face_id
);
4756 s
->width
+= glyph
->pixel_width
;
4758 /* Adjust base line for subscript/superscript text. */
4759 s
->ybase
+= voffset
;
4761 /* The case that face->gc == 0 is handled when drawing the glyph
4762 string by calling PREPARE_FACE_FOR_DISPLAY. */
4764 return glyph
- s
->row
->glyphs
[s
->area
];
4768 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4769 of XChar2b structures for S; it can't be allocated in
4770 x_init_glyph_string because it must be allocated via `alloca'. W
4771 is the window on which S is drawn. ROW and AREA are the glyph row
4772 and area within the row from which S is constructed. START is the
4773 index of the first glyph structure covered by S. HL is a
4774 face-override for drawing S. */
4777 x_init_glyph_string (s
, char2b
, w
, row
, area
, start
, hl
)
4778 struct glyph_string
*s
;
4781 struct glyph_row
*row
;
4782 enum glyph_row_area area
;
4784 enum draw_glyphs_face hl
;
4786 bzero (s
, sizeof *s
);
4788 s
->f
= XFRAME (w
->frame
);
4789 s
->display
= FRAME_X_DISPLAY (s
->f
);
4790 s
->window
= FRAME_X_WINDOW (s
->f
);
4795 s
->first_glyph
= row
->glyphs
[area
] + start
;
4796 s
->height
= row
->height
;
4797 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4799 /* Display the internal border below the tool-bar window. */
4800 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4801 s
->y
-= s
->f
->output_data
.x
->internal_border_width
;
4803 s
->ybase
= s
->y
+ row
->ascent
;
4807 /* Set background width of glyph string S. START is the index of the
4808 first glyph following S. LAST_X is the right-most x-position + 1
4809 in the drawing area. */
4812 x_set_glyph_string_background_width (s
, start
, last_x
)
4813 struct glyph_string
*s
;
4817 /* If the face of this glyph string has to be drawn to the end of
4818 the drawing area, set S->extends_to_end_of_line_p. */
4819 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4821 if (start
== s
->row
->used
[s
->area
]
4822 && s
->area
== TEXT_AREA
4823 && ((s
->hl
== DRAW_NORMAL_TEXT
4824 && (s
->row
->fill_line_p
4825 || s
->face
->background
!= default_face
->background
4826 || s
->face
->stipple
!= default_face
->stipple
4827 || s
->row
->mouse_face_p
))
4828 || s
->hl
== DRAW_MOUSE_FACE
4829 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
4830 && s
->row
->fill_line_p
)))
4831 s
->extends_to_end_of_line_p
= 1;
4833 /* If S extends its face to the end of the line, set its
4834 background_width to the distance to the right edge of the drawing
4836 if (s
->extends_to_end_of_line_p
)
4837 s
->background_width
= last_x
- s
->x
+ 1;
4839 s
->background_width
= s
->width
;
4843 /* Add a glyph string for a stretch glyph to the list of strings
4844 between HEAD and TAIL. START is the index of the stretch glyph in
4845 row area AREA of glyph row ROW. END is the index of the last glyph
4846 in that glyph row area. X is the current output position assigned
4847 to the new glyph string constructed. HL overrides that face of the
4848 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4849 is the right-most x-position of the drawing area. */
4851 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
4852 and below -- keep them on one line. */
4853 #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4856 s = (struct glyph_string *) alloca (sizeof *s); \
4857 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4858 START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \
4859 x_append_glyph_string (&HEAD, &TAIL, s); \
4865 /* Add a glyph string for an image glyph to the list of strings
4866 between HEAD and TAIL. START is the index of the image glyph in
4867 row area AREA of glyph row ROW. END is the index of the last glyph
4868 in that glyph row area. X is the current output position assigned
4869 to the new glyph string constructed. HL overrides that face of the
4870 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4871 is the right-most x-position of the drawing area. */
4873 #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4876 s = (struct glyph_string *) alloca (sizeof *s); \
4877 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4878 x_fill_image_glyph_string (s); \
4879 x_append_glyph_string (&HEAD, &TAIL, s); \
4886 /* Add a glyph string for a sequence of character glyphs to the list
4887 of strings between HEAD and TAIL. START is the index of the first
4888 glyph in row area AREA of glyph row ROW that is part of the new
4889 glyph string. END is the index of the last glyph in that glyph row
4890 area. X is the current output position assigned to the new glyph
4891 string constructed. HL overrides that face of the glyph; e.g. it
4892 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4893 right-most x-position of the drawing area. */
4895 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4901 c = (ROW)->glyphs[AREA][START].u.ch; \
4902 face_id = (ROW)->glyphs[AREA][START].face_id; \
4904 s = (struct glyph_string *) alloca (sizeof *s); \
4905 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
4906 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4907 x_append_glyph_string (&HEAD, &TAIL, s); \
4909 START = x_fill_glyph_string (s, face_id, START, END, \
4915 /* Add a glyph string for a composite sequence to the list of strings
4916 between HEAD and TAIL. START is the index of the first glyph in
4917 row area AREA of glyph row ROW that is part of the new glyph
4918 string. END is the index of the last glyph in that glyph row area.
4919 X is the current output position assigned to the new glyph string
4920 constructed. HL overrides that face of the glyph; e.g. it is
4921 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
4922 x-position of the drawing area. */
4924 #define BUILD_COMPOSITE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4926 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
4927 int face_id = (ROW)->glyphs[AREA][START].face_id; \
4928 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
4929 struct composition *cmp = composition_table[cmp_id]; \
4930 int glyph_len = cmp->glyph_len; \
4932 struct face **faces; \
4933 struct glyph_string *first_s = NULL; \
4936 base_face = base_face->ascii_face; \
4937 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
4938 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
4939 /* At first, fill in `char2b' and `faces'. */ \
4940 for (n = 0; n < glyph_len; n++) \
4942 int c = COMPOSITION_GLYPH (cmp, n); \
4943 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
4944 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
4945 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
4946 this_face_id, char2b + n, 1); \
4949 /* Make glyph_strings for each glyph sequence that is drawable by \
4950 the same face, and append them to HEAD/TAIL. */ \
4951 for (n = 0; n < cmp->glyph_len;) \
4953 s = (struct glyph_string *) alloca (sizeof *s); \
4954 x_init_glyph_string (s, char2b + n, W, ROW, AREA, START, HL); \
4955 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4963 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
4971 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4972 of AREA of glyph row ROW on window W between indices START and END.
4973 HL overrides the face for drawing glyph strings, e.g. it is
4974 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4975 x-positions of the drawing area.
4977 This is an ugly monster macro construct because we must use alloca
4978 to allocate glyph strings (because x_draw_glyphs can be called
4981 #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4984 HEAD = TAIL = NULL; \
4985 while (START < END) \
4987 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
4988 switch (first_glyph->type) \
4991 BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \
4992 TAIL, HL, X, LAST_X, \
4996 case COMPOSITE_GLYPH: \
4997 BUILD_COMPOSITE_GLYPH_STRING (W, ROW, AREA, START, END, \
4998 HEAD, TAIL, HL, X, LAST_X,\
5002 case STRETCH_GLYPH: \
5003 BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \
5004 HEAD, TAIL, HL, X, LAST_X); \
5008 BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \
5009 TAIL, HL, X, LAST_X); \
5016 x_set_glyph_string_background_width (s, START, LAST_X); \
5023 /* Draw glyphs between START and END in AREA of ROW on window W,
5024 starting at x-position X. X is relative to AREA in W. HL is a
5025 face-override with the following meaning:
5027 DRAW_NORMAL_TEXT draw normally
5028 DRAW_CURSOR draw in cursor face
5029 DRAW_MOUSE_FACE draw in mouse face.
5030 DRAW_INVERSE_VIDEO draw in mode line face
5031 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
5032 DRAW_IMAGE_RAISED draw an image with a raised relief around it
5034 If OVERLAPS_P is non-zero, draw only the foreground of characters
5035 and clip to the physical height of ROW.
5037 Value is the x-position reached, relative to AREA of W. */
5040 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
5043 struct glyph_row
*row
;
5044 enum glyph_row_area area
;
5046 enum draw_glyphs_face hl
;
5049 struct glyph_string
*head
, *tail
;
5050 struct glyph_string
*s
;
5051 int last_x
, area_width
;
5055 /* Let's rather be paranoid than getting a SEGV. */
5056 end
= min (end
, row
->used
[area
]);
5057 start
= max (0, start
);
5058 start
= min (end
, start
);
5060 /* Translate X to frame coordinates. Set last_x to the right
5061 end of the drawing area. */
5062 if (row
->full_width_p
)
5064 /* X is relative to the left edge of W, without scroll bars
5066 struct frame
*f
= XFRAME (w
->frame
);
5067 /* int width = FRAME_FRINGE_WIDTH (f); */
5068 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
5071 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5072 last_x
= window_left_x
+ area_width
;
5074 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5076 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5077 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
5083 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
5084 last_x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
5088 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
5089 area_width
= window_box_width (w
, area
);
5090 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
5093 /* Build a doubly-linked list of glyph_string structures between
5094 head and tail from what we have to draw. Note that the macro
5095 BUILD_GLYPH_STRINGS will modify its start parameter. That's
5096 the reason we use a separate variable `i'. */
5098 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
5101 x_reached
= tail
->x
+ tail
->background_width
;
5105 /* If there are any glyphs with lbearing < 0 or rbearing > width in
5106 the row, redraw some glyphs in front or following the glyph
5107 strings built above. */
5108 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
5111 struct glyph_string
*h
, *t
;
5113 /* Compute overhangs for all glyph strings. */
5114 for (s
= head
; s
; s
= s
->next
)
5115 x_compute_glyph_string_overhangs (s
);
5117 /* Prepend glyph strings for glyphs in front of the first glyph
5118 string that are overwritten because of the first glyph
5119 string's left overhang. The background of all strings
5120 prepended must be drawn because the first glyph string
5122 i
= x_left_overwritten (head
);
5126 BUILD_GLYPH_STRINGS (w
, row
, area
, j
, start
, h
, t
,
5127 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5130 x_compute_overhangs_and_x (t
, head
->x
, 1);
5131 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5134 /* Prepend glyph strings for glyphs in front of the first glyph
5135 string that overwrite that glyph string because of their
5136 right overhang. For these strings, only the foreground must
5137 be drawn, because it draws over the glyph string at `head'.
5138 The background must not be drawn because this would overwrite
5139 right overhangs of preceding glyphs for which no glyph
5141 i
= x_left_overwriting (head
);
5144 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, start
, h
, t
,
5145 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
5147 for (s
= h
; s
; s
= s
->next
)
5148 s
->background_filled_p
= 1;
5149 x_compute_overhangs_and_x (t
, head
->x
, 1);
5150 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
5153 /* Append glyphs strings for glyphs following the last glyph
5154 string tail that are overwritten by tail. The background of
5155 these strings has to be drawn because tail's foreground draws
5157 i
= x_right_overwritten (tail
);
5160 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
5161 DRAW_NORMAL_TEXT
, x
, last_x
,
5163 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5164 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5167 /* Append glyph strings for glyphs following the last glyph
5168 string tail that overwrite tail. The foreground of such
5169 glyphs has to be drawn because it writes into the background
5170 of tail. The background must not be drawn because it could
5171 paint over the foreground of following glyphs. */
5172 i
= x_right_overwriting (tail
);
5175 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
5176 DRAW_NORMAL_TEXT
, x
, last_x
,
5178 for (s
= h
; s
; s
= s
->next
)
5179 s
->background_filled_p
= 1;
5180 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5181 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5185 /* Draw all strings. */
5186 for (s
= head
; s
; s
= s
->next
)
5187 x_draw_glyph_string (s
);
5189 if (area
== TEXT_AREA
&& !row
->full_width_p
)
5191 int x0
= head
? head
->x
: x
;
5192 int x1
= tail
? tail
->x
+ tail
->background_width
: x
;
5194 x0
= FRAME_TO_WINDOW_PIXEL_X (w
, x0
);
5195 x1
= FRAME_TO_WINDOW_PIXEL_X (w
, x1
);
5197 if (!row
->full_width_p
&& XFASTINT (w
->left_margin_width
) != 0)
5199 int left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
5200 x0
-= left_area_width
;
5201 x1
-= left_area_width
;
5204 notice_overwritten_cursor (w
, x0
, x1
);
5207 /* Value is the x-position up to which drawn, relative to AREA of W.
5208 This doesn't include parts drawn because of overhangs. */
5209 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
5210 if (!row
->full_width_p
)
5212 if (area
> LEFT_MARGIN_AREA
&& XFASTINT (w
->left_margin_width
) != 0)
5213 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
5214 if (area
> TEXT_AREA
)
5215 x_reached
-= window_box_width (w
, TEXT_AREA
);
5222 /* Fix the display of area AREA of overlapping row ROW in window W. */
5225 x_fix_overlapping_area (w
, row
, area
)
5227 struct glyph_row
*row
;
5228 enum glyph_row_area area
;
5234 if (area
== LEFT_MARGIN_AREA
)
5236 else if (area
== TEXT_AREA
)
5237 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5239 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5240 + window_box_width (w
, TEXT_AREA
));
5242 for (i
= 0; i
< row
->used
[area
];)
5244 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
5246 int start
= i
, start_x
= x
;
5250 x
+= row
->glyphs
[area
][i
].pixel_width
;
5253 while (i
< row
->used
[area
]
5254 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
5256 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
5257 DRAW_NORMAL_TEXT
, 1);
5261 x
+= row
->glyphs
[area
][i
].pixel_width
;
5270 /* Output LEN glyphs starting at START at the nominal cursor position.
5271 Advance the nominal cursor over the text. The global variable
5272 updated_window contains the window being updated, updated_row is
5273 the glyph row being updated, and updated_area is the area of that
5274 row being updated. */
5277 x_write_glyphs (start
, len
)
5278 struct glyph
*start
;
5283 xassert (updated_window
&& updated_row
);
5288 hpos
= start
- updated_row
->glyphs
[updated_area
];
5289 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
5290 updated_row
, updated_area
,
5292 DRAW_NORMAL_TEXT
, 0);
5296 /* Advance the output cursor. */
5297 output_cursor
.hpos
+= len
;
5298 output_cursor
.x
= x
;
5302 /* Insert LEN glyphs from START at the nominal cursor position. */
5305 x_insert_glyphs (start
, len
)
5306 struct glyph
*start
;
5311 int line_height
, shift_by_width
, shifted_region_width
;
5312 struct glyph_row
*row
;
5313 struct glyph
*glyph
;
5314 int frame_x
, frame_y
, hpos
;
5316 xassert (updated_window
&& updated_row
);
5319 f
= XFRAME (WINDOW_FRAME (w
));
5321 /* Get the height of the line we are in. */
5323 line_height
= row
->height
;
5325 /* Get the width of the glyphs to insert. */
5327 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
5328 shift_by_width
+= glyph
->pixel_width
;
5330 /* Get the width of the region to shift right. */
5331 shifted_region_width
= (window_box_width (w
, updated_area
)
5336 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
5337 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
5338 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5339 f
->output_data
.x
->normal_gc
,
5341 shifted_region_width
, line_height
,
5342 frame_x
+ shift_by_width
, frame_y
);
5344 /* Write the glyphs. */
5345 hpos
= start
- row
->glyphs
[updated_area
];
5346 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
5347 DRAW_NORMAL_TEXT
, 0);
5349 /* Advance the output cursor. */
5350 output_cursor
.hpos
+= len
;
5351 output_cursor
.x
+= shift_by_width
;
5356 /* Delete N glyphs at the nominal cursor position. Not implemented
5367 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
5368 If they are <= 0, this is probably an error. */
5371 x_clear_area (dpy
, window
, x
, y
, width
, height
, exposures
)
5378 xassert (width
> 0 && height
> 0);
5379 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
5383 /* Erase the current text line from the nominal cursor position
5384 (inclusive) to pixel column TO_X (exclusive). The idea is that
5385 everything from TO_X onward is already erased.
5387 TO_X is a pixel position relative to updated_area of
5388 updated_window. TO_X == -1 means clear to the end of this area. */
5391 x_clear_end_of_line (to_x
)
5395 struct window
*w
= updated_window
;
5396 int max_x
, min_y
, max_y
;
5397 int from_x
, from_y
, to_y
;
5399 xassert (updated_window
&& updated_row
);
5400 f
= XFRAME (w
->frame
);
5402 if (updated_row
->full_width_p
)
5404 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5405 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5406 && !w
->pseudo_window_p
)
5407 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5410 max_x
= window_box_width (w
, updated_area
);
5411 max_y
= window_text_bottom_y (w
);
5413 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
5414 of window. For TO_X > 0, truncate to end of drawing area. */
5420 to_x
= min (to_x
, max_x
);
5422 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
5424 /* Notice if the cursor will be cleared by this operation. */
5425 if (!updated_row
->full_width_p
)
5426 notice_overwritten_cursor (w
, output_cursor
.x
, -1);
5428 from_x
= output_cursor
.x
;
5430 /* Translate to frame coordinates. */
5431 if (updated_row
->full_width_p
)
5433 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
5434 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
5438 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
5439 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
5442 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
5443 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
5444 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
5446 /* Prevent inadvertently clearing to end of the X window. */
5447 if (to_x
> from_x
&& to_y
> from_y
)
5450 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5451 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
5458 /* Clear entire frame. If updating_frame is non-null, clear that
5459 frame. Otherwise clear the selected frame. */
5469 f
= SELECTED_FRAME ();
5471 /* Clearing the frame will erase any cursor, so mark them all as no
5473 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5474 output_cursor
.hpos
= output_cursor
.vpos
= 0;
5475 output_cursor
.x
= -1;
5477 /* We don't set the output cursor here because there will always
5478 follow an explicit cursor_to. */
5480 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5482 /* We have to clear the scroll bars, too. If we have changed
5483 colors or something like that, then they should be notified. */
5484 x_scroll_bar_clear (f
);
5486 XFlush (FRAME_X_DISPLAY (f
));
5492 /* Invert the middle quarter of the frame for .15 sec. */
5494 /* We use the select system call to do the waiting, so we have to make
5495 sure it's available. If it isn't, we just won't do visual bells. */
5497 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5500 /* Subtract the `struct timeval' values X and Y, storing the result in
5501 *RESULT. Return 1 if the difference is negative, otherwise 0. */
5504 timeval_subtract (result
, x
, y
)
5505 struct timeval
*result
, x
, y
;
5507 /* Perform the carry for the later subtraction by updating y. This
5508 is safer because on some systems the tv_sec member is unsigned. */
5509 if (x
.tv_usec
< y
.tv_usec
)
5511 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
5512 y
.tv_usec
-= 1000000 * nsec
;
5516 if (x
.tv_usec
- y
.tv_usec
> 1000000)
5518 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
5519 y
.tv_usec
+= 1000000 * nsec
;
5523 /* Compute the time remaining to wait. tv_usec is certainly
5525 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
5526 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
5528 /* Return indication of whether the result should be considered
5530 return x
.tv_sec
< y
.tv_sec
;
5542 /* Create a GC that will use the GXxor function to flip foreground
5543 pixels into background pixels. */
5547 values
.function
= GXxor
;
5548 values
.foreground
= (f
->output_data
.x
->foreground_pixel
5549 ^ f
->output_data
.x
->background_pixel
);
5551 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5552 GCFunction
| GCForeground
, &values
);
5556 /* Get the height not including a menu bar widget. */
5557 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
5558 /* Height of each line to flash. */
5559 int flash_height
= FRAME_LINE_HEIGHT (f
);
5560 /* These will be the left and right margins of the rectangles. */
5561 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
5562 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
5566 /* Don't flash the area between a scroll bar and the frame
5567 edge it is next to. */
5568 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
5570 case vertical_scroll_bar_left
:
5571 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5574 case vertical_scroll_bar_right
:
5575 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5582 width
= flash_right
- flash_left
;
5584 /* If window is tall, flash top and bottom line. */
5585 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5587 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5589 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5590 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5591 width
, flash_height
);
5592 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5594 (height
- flash_height
5595 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5596 width
, flash_height
);
5599 /* If it is short, flash it all. */
5600 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5601 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5602 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5607 struct timeval wakeup
;
5609 EMACS_GET_TIME (wakeup
);
5611 /* Compute time to wait until, propagating carry from usecs. */
5612 wakeup
.tv_usec
+= 150000;
5613 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
5614 wakeup
.tv_usec
%= 1000000;
5616 /* Keep waiting until past the time wakeup or any input gets
5618 while (! detect_input_pending ())
5620 struct timeval current
;
5621 struct timeval timeout
;
5623 EMACS_GET_TIME (current
);
5625 /* Break if result would be negative. */
5626 if (timeval_subtract (¤t
, wakeup
, current
))
5629 /* How long `select' should wait. */
5631 timeout
.tv_usec
= 10000;
5633 /* Try to wait that long--but we might wake up sooner. */
5634 select (0, NULL
, NULL
, NULL
, &timeout
);
5638 /* If window is tall, flash top and bottom line. */
5639 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5641 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5643 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5644 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5645 width
, flash_height
);
5646 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5648 (height
- flash_height
5649 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5650 width
, flash_height
);
5653 /* If it is short, flash it all. */
5654 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5655 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5656 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5658 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
5666 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
5669 /* Make audible bell. */
5674 struct frame
*f
= SELECTED_FRAME ();
5676 if (FRAME_X_DISPLAY (f
))
5678 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5685 XBell (FRAME_X_DISPLAY (f
), 0);
5686 XFlush (FRAME_X_DISPLAY (f
));
5693 /* Specify how many text lines, from the top of the window,
5694 should be affected by insert-lines and delete-lines operations.
5695 This, and those operations, are used only within an update
5696 that is bounded by calls to x_update_begin and x_update_end. */
5699 XTset_terminal_window (n
)
5702 /* This function intentionally left blank. */
5707 /***********************************************************************
5709 ***********************************************************************/
5711 /* Perform an insert-lines or delete-lines operation, inserting N
5712 lines or deleting -N lines at vertical position VPOS. */
5715 x_ins_del_lines (vpos
, n
)
5722 /* Scroll part of the display as described by RUN. */
5725 x_scroll_run (w
, run
)
5729 struct frame
*f
= XFRAME (w
->frame
);
5730 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5732 /* Get frame-relative bounding box of the text display area of W,
5733 without mode lines. Include in this box the left and right
5735 window_box (w
, -1, &x
, &y
, &width
, &height
);
5736 width
+= FRAME_X_FRINGE_WIDTH (f
);
5737 x
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
5739 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5740 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5741 bottom_y
= y
+ height
;
5745 /* Scrolling up. Make sure we don't copy part of the mode
5746 line at the bottom. */
5747 if (from_y
+ run
->height
> bottom_y
)
5748 height
= bottom_y
- from_y
;
5750 height
= run
->height
;
5754 /* Scolling down. Make sure we don't copy over the mode line.
5756 if (to_y
+ run
->height
> bottom_y
)
5757 height
= bottom_y
- to_y
;
5759 height
= run
->height
;
5764 /* Cursor off. Will be switched on again in x_update_window_end. */
5768 XCopyArea (FRAME_X_DISPLAY (f
),
5769 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5770 f
->output_data
.x
->normal_gc
,
5780 /***********************************************************************
5782 ***********************************************************************/
5784 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5785 corner of the exposed rectangle. W and H are width and height of
5786 the exposed area. All are pixel values. W or H zero means redraw
5787 the entire frame. */
5790 expose_frame (f
, x
, y
, w
, h
)
5795 int mouse_face_overwritten_p
= 0;
5797 TRACE ((stderr
, "expose_frame "));
5799 /* No need to redraw if frame will be redrawn soon. */
5800 if (FRAME_GARBAGED_P (f
))
5802 TRACE ((stderr
, " garbaged\n"));
5806 /* If basic faces haven't been realized yet, there is no point in
5807 trying to redraw anything. This can happen when we get an expose
5808 event while Emacs is starting, e.g. by moving another window. */
5809 if (FRAME_FACE_CACHE (f
) == NULL
5810 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5812 TRACE ((stderr
, " no faces\n"));
5816 if (w
== 0 || h
== 0)
5819 r
.width
= CANON_X_UNIT (f
) * f
->width
;
5820 r
.height
= CANON_Y_UNIT (f
) * f
->height
;
5830 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
5831 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
5833 if (WINDOWP (f
->tool_bar_window
))
5834 mouse_face_overwritten_p
5835 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
5837 #ifndef USE_X_TOOLKIT
5838 if (WINDOWP (f
->menu_bar_window
))
5839 mouse_face_overwritten_p
5840 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
5841 #endif /* not USE_X_TOOLKIT */
5843 /* Some window managers support a focus-follows-mouse style with
5844 delayed raising of frames. Imagine a partially obscured frame,
5845 and moving the mouse into partially obscured mouse-face on that
5846 frame. The visible part of the mouse-face will be highlighted,
5847 then the WM raises the obscured frame. With at least one WM, KDE
5848 2.1, Emacs is not getting any event for the raising of the frame
5849 (even tried with SubstructureRedirectMask), only Expose events.
5850 These expose events will draw text normally, i.e. not
5851 highlighted. Which means we must redo the highlight here.
5852 Subsume it under ``we love X''. --gerd 2001-08-15 */
5853 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
5855 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
5856 if (f
== dpyinfo
->mouse_face_mouse_frame
)
5858 int x
= dpyinfo
->mouse_face_mouse_x
;
5859 int y
= dpyinfo
->mouse_face_mouse_y
;
5860 clear_mouse_face (dpyinfo
);
5861 note_mouse_highlight (f
, x
, y
);
5867 /* Redraw (parts) of all windows in the window tree rooted at W that
5868 intersect R. R contains frame pixel coordinates. Value is
5869 non-zero if the exposure overwrites mouse-face. */
5872 expose_window_tree (w
, r
)
5876 struct frame
*f
= XFRAME (w
->frame
);
5877 int mouse_face_overwritten_p
= 0;
5879 while (w
&& !FRAME_GARBAGED_P (f
))
5881 if (!NILP (w
->hchild
))
5882 mouse_face_overwritten_p
5883 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
5884 else if (!NILP (w
->vchild
))
5885 mouse_face_overwritten_p
5886 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
5888 mouse_face_overwritten_p
|= expose_window (w
, r
);
5890 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
5893 return mouse_face_overwritten_p
;
5897 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5898 which intersects rectangle R. R is in window-relative coordinates. */
5901 expose_area (w
, row
, r
, area
)
5903 struct glyph_row
*row
;
5905 enum glyph_row_area area
;
5907 struct glyph
*first
= row
->glyphs
[area
];
5908 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5910 int first_x
, start_x
, x
;
5912 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5913 /* If row extends face to end of line write the whole line. */
5914 x_draw_glyphs (w
, 0, row
, area
, 0, row
->used
[area
],
5915 DRAW_NORMAL_TEXT
, 0);
5918 /* Set START_X to the window-relative start position for drawing glyphs of
5919 AREA. The first glyph of the text area can be partially visible.
5920 The first glyphs of other areas cannot. */
5921 if (area
== LEFT_MARGIN_AREA
)
5923 else if (area
== TEXT_AREA
)
5924 start_x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5926 start_x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5927 + window_box_width (w
, TEXT_AREA
));
5930 /* Find the first glyph that must be redrawn. */
5932 && x
+ first
->pixel_width
< r
->x
)
5934 x
+= first
->pixel_width
;
5938 /* Find the last one. */
5942 && x
< r
->x
+ r
->width
)
5944 x
+= last
->pixel_width
;
5950 x_draw_glyphs (w
, first_x
- start_x
, row
, area
,
5951 first
- row
->glyphs
[area
],
5952 last
- row
->glyphs
[area
],
5953 DRAW_NORMAL_TEXT
, 0);
5958 /* Redraw the parts of the glyph row ROW on window W intersecting
5959 rectangle R. R is in window-relative coordinates. Value is
5960 non-zero if mouse-face was overwritten. */
5963 expose_line (w
, row
, r
)
5965 struct glyph_row
*row
;
5968 xassert (row
->enabled_p
);
5970 if (row
->mode_line_p
|| w
->pseudo_window_p
)
5971 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
5972 DRAW_NORMAL_TEXT
, 0);
5975 if (row
->used
[LEFT_MARGIN_AREA
])
5976 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
5977 if (row
->used
[TEXT_AREA
])
5978 expose_area (w
, row
, r
, TEXT_AREA
);
5979 if (row
->used
[RIGHT_MARGIN_AREA
])
5980 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
5981 x_draw_row_fringe_bitmaps (w
, row
);
5984 return row
->mouse_face_p
;
5988 /* Return non-zero if W's cursor intersects rectangle R. */
5991 x_phys_cursor_in_rect_p (w
, r
)
5995 XRectangle cr
, result
;
5996 struct glyph
*cursor_glyph
;
5998 cursor_glyph
= get_phys_cursor_glyph (w
);
6001 cr
.x
= w
->phys_cursor
.x
;
6002 cr
.y
= w
->phys_cursor
.y
;
6003 cr
.width
= cursor_glyph
->pixel_width
;
6004 cr
.height
= w
->phys_cursor_height
;
6005 return x_intersect_rectangles (&cr
, r
, &result
);
6012 /* Redraw the part of window W intersection rectangle FR. Pixel
6013 coordinates in FR are frame-relative. Call this function with
6014 input blocked. Value is non-zero if the exposure overwrites
6018 expose_window (w
, fr
)
6022 struct frame
*f
= XFRAME (w
->frame
);
6024 int mouse_face_overwritten_p
= 0;
6026 /* If window is not yet fully initialized, do nothing. This can
6027 happen when toolkit scroll bars are used and a window is split.
6028 Reconfiguring the scroll bar will generate an expose for a newly
6030 if (w
->current_matrix
== NULL
)
6033 /* When we're currently updating the window, display and current
6034 matrix usually don't agree. Arrange for a thorough display
6036 if (w
== updated_window
)
6038 SET_FRAME_GARBAGED (f
);
6042 /* Frame-relative pixel rectangle of W. */
6043 wr
.x
= XFASTINT (w
->left
) * CANON_X_UNIT (f
);
6044 wr
.y
= XFASTINT (w
->top
) * CANON_Y_UNIT (f
);
6045 wr
.width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
6046 wr
.height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
6048 if (x_intersect_rectangles (fr
, &wr
, &r
))
6050 int yb
= window_text_bottom_y (w
);
6051 struct glyph_row
*row
;
6052 int cursor_cleared_p
;
6054 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
6055 r
.x
, r
.y
, r
.width
, r
.height
));
6057 /* Convert to window coordinates. */
6058 r
.x
= FRAME_TO_WINDOW_PIXEL_X (w
, r
.x
);
6059 r
.y
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
.y
);
6061 /* Turn off the cursor. */
6062 if (!w
->pseudo_window_p
6063 && x_phys_cursor_in_rect_p (w
, &r
))
6066 cursor_cleared_p
= 1;
6069 cursor_cleared_p
= 0;
6071 /* Find the first row intersecting the rectangle R. */
6072 for (row
= w
->current_matrix
->rows
;
6077 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
6079 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
6080 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
6081 || (r
.y
>= y0
&& r
.y
< y1
)
6082 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
6084 if (expose_line (w
, row
, &r
))
6085 mouse_face_overwritten_p
= 1;
6092 /* Display the mode line if there is one. */
6093 if (WINDOW_WANTS_MODELINE_P (w
)
6094 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
6096 && row
->y
< r
.y
+ r
.height
)
6098 if (expose_line (w
, row
, &r
))
6099 mouse_face_overwritten_p
= 1;
6102 if (!w
->pseudo_window_p
)
6104 /* Draw border between windows. */
6105 x_draw_vertical_border (w
);
6107 /* Turn the cursor on again. */
6108 if (cursor_cleared_p
)
6109 x_update_window_cursor (w
, 1);
6113 return mouse_face_overwritten_p
;
6117 /* Determine the intersection of two rectangles R1 and R2. Return
6118 the intersection in *RESULT. Value is non-zero if RESULT is not
6122 x_intersect_rectangles (r1
, r2
, result
)
6123 XRectangle
*r1
, *r2
, *result
;
6125 XRectangle
*left
, *right
;
6126 XRectangle
*upper
, *lower
;
6127 int intersection_p
= 0;
6129 /* Rearrange so that R1 is the left-most rectangle. */
6131 left
= r1
, right
= r2
;
6133 left
= r2
, right
= r1
;
6135 /* X0 of the intersection is right.x0, if this is inside R1,
6136 otherwise there is no intersection. */
6137 if (right
->x
<= left
->x
+ left
->width
)
6139 result
->x
= right
->x
;
6141 /* The right end of the intersection is the minimum of the
6142 the right ends of left and right. */
6143 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
6146 /* Same game for Y. */
6148 upper
= r1
, lower
= r2
;
6150 upper
= r2
, lower
= r1
;
6152 /* The upper end of the intersection is lower.y0, if this is inside
6153 of upper. Otherwise, there is no intersection. */
6154 if (lower
->y
<= upper
->y
+ upper
->height
)
6156 result
->y
= lower
->y
;
6158 /* The lower end of the intersection is the minimum of the lower
6159 ends of upper and lower. */
6160 result
->height
= (min (lower
->y
+ lower
->height
,
6161 upper
->y
+ upper
->height
)
6167 return intersection_p
;
6178 /* We used to only do this if Vx_no_window_manager was non-nil, but
6179 the ICCCM (section 4.1.6) says that the window's border pixmap
6180 and border pixel are window attributes which are "private to the
6181 client", so we can always change it to whatever we want. */
6183 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6184 f
->output_data
.x
->border_pixel
);
6186 x_update_cursor (f
, 1);
6190 frame_unhighlight (f
)
6193 /* We used to only do this if Vx_no_window_manager was non-nil, but
6194 the ICCCM (section 4.1.6) says that the window's border pixmap
6195 and border pixel are window attributes which are "private to the
6196 client", so we can always change it to whatever we want. */
6198 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6199 f
->output_data
.x
->border_tile
);
6201 x_update_cursor (f
, 1);
6204 /* The focus has changed. Update the frames as necessary to reflect
6205 the new situation. Note that we can't change the selected frame
6206 here, because the Lisp code we are interrupting might become confused.
6207 Each event gets marked with the frame in which it occurred, so the
6208 Lisp code can tell when the switch took place by examining the events. */
6211 x_new_focus_frame (dpyinfo
, frame
)
6212 struct x_display_info
*dpyinfo
;
6213 struct frame
*frame
;
6215 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
6217 if (frame
!= dpyinfo
->x_focus_frame
)
6219 /* Set this before calling other routines, so that they see
6220 the correct value of x_focus_frame. */
6221 dpyinfo
->x_focus_frame
= frame
;
6223 if (old_focus
&& old_focus
->auto_lower
)
6224 x_lower_frame (old_focus
);
6227 selected_frame
= frame
;
6228 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
6230 Fselect_window (selected_frame
->selected_window
);
6231 choose_minibuf_frame ();
6234 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
6235 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
6237 pending_autoraise_frame
= 0;
6240 x_frame_rehighlight (dpyinfo
);
6243 /* Handle an event saying the mouse has moved out of an Emacs frame. */
6246 x_mouse_leave (dpyinfo
)
6247 struct x_display_info
*dpyinfo
;
6249 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
6252 /* The focus has changed, or we have redirected a frame's focus to
6253 another frame (this happens when a frame uses a surrogate
6254 mini-buffer frame). Shift the highlight as appropriate.
6256 The FRAME argument doesn't necessarily have anything to do with which
6257 frame is being highlighted or un-highlighted; we only use it to find
6258 the appropriate X display info. */
6261 XTframe_rehighlight (frame
)
6262 struct frame
*frame
;
6264 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
6268 x_frame_rehighlight (dpyinfo
)
6269 struct x_display_info
*dpyinfo
;
6271 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
6273 if (dpyinfo
->x_focus_frame
)
6275 dpyinfo
->x_highlight_frame
6276 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
6277 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
6278 : dpyinfo
->x_focus_frame
);
6279 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
6281 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
6282 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
6286 dpyinfo
->x_highlight_frame
= 0;
6288 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
6291 frame_unhighlight (old_highlight
);
6292 if (dpyinfo
->x_highlight_frame
)
6293 frame_highlight (dpyinfo
->x_highlight_frame
);
6299 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
6301 /* Initialize mode_switch_bit and modifier_meaning. */
6303 x_find_modifier_meanings (dpyinfo
)
6304 struct x_display_info
*dpyinfo
;
6306 int min_code
, max_code
;
6309 XModifierKeymap
*mods
;
6311 dpyinfo
->meta_mod_mask
= 0;
6312 dpyinfo
->shift_lock_mask
= 0;
6313 dpyinfo
->alt_mod_mask
= 0;
6314 dpyinfo
->super_mod_mask
= 0;
6315 dpyinfo
->hyper_mod_mask
= 0;
6318 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
6320 min_code
= dpyinfo
->display
->min_keycode
;
6321 max_code
= dpyinfo
->display
->max_keycode
;
6324 syms
= XGetKeyboardMapping (dpyinfo
->display
,
6325 min_code
, max_code
- min_code
+ 1,
6327 mods
= XGetModifierMapping (dpyinfo
->display
);
6329 /* Scan the modifier table to see which modifier bits the Meta and
6330 Alt keysyms are on. */
6332 int row
, col
; /* The row and column in the modifier table. */
6334 for (row
= 3; row
< 8; row
++)
6335 for (col
= 0; col
< mods
->max_keypermod
; col
++)
6338 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
6340 /* Zeroes are used for filler. Skip them. */
6344 /* Are any of this keycode's keysyms a meta key? */
6348 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
6350 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
6356 dpyinfo
->meta_mod_mask
|= (1 << row
);
6361 dpyinfo
->alt_mod_mask
|= (1 << row
);
6366 dpyinfo
->hyper_mod_mask
|= (1 << row
);
6371 dpyinfo
->super_mod_mask
|= (1 << row
);
6375 /* Ignore this if it's not on the lock modifier. */
6376 if ((1 << row
) == LockMask
)
6377 dpyinfo
->shift_lock_mask
= LockMask
;
6385 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
6386 if (! dpyinfo
->meta_mod_mask
)
6388 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
6389 dpyinfo
->alt_mod_mask
= 0;
6392 /* If some keys are both alt and meta,
6393 make them just meta, not alt. */
6394 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
6396 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
6399 XFree ((char *) syms
);
6400 XFreeModifiermap (mods
);
6403 /* Convert between the modifier bits X uses and the modifier bits
6407 x_x_to_emacs_modifiers (dpyinfo
, state
)
6408 struct x_display_info
*dpyinfo
;
6411 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
6412 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
6413 | ((state
& dpyinfo
->meta_mod_mask
) ? meta_modifier
: 0)
6414 | ((state
& dpyinfo
->alt_mod_mask
) ? alt_modifier
: 0)
6415 | ((state
& dpyinfo
->super_mod_mask
) ? super_modifier
: 0)
6416 | ((state
& dpyinfo
->hyper_mod_mask
) ? hyper_modifier
: 0));
6420 x_emacs_to_x_modifiers (dpyinfo
, state
)
6421 struct x_display_info
*dpyinfo
;
6424 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
6425 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
6426 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
6427 | ((state
& shift_modifier
) ? ShiftMask
: 0)
6428 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
6429 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
6432 /* Convert a keysym to its name. */
6435 x_get_keysym_name (keysym
)
6441 value
= XKeysymToString (keysym
);
6449 /* Mouse clicks and mouse movement. Rah. */
6451 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
6452 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
6453 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
6454 not force the value into range. */
6457 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
6459 register int pix_x
, pix_y
;
6460 register int *x
, *y
;
6464 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
6465 even for negative values. */
6467 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
6469 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
6471 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
6472 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
6476 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
6477 bounds
->height
= f
->output_data
.x
->line_height
;
6478 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
6479 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
6486 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
6487 pix_x
= FRAME_WINDOW_WIDTH (f
);
6491 else if (pix_y
> f
->height
)
6500 /* Given HPOS/VPOS in the current matrix of W, return corresponding
6501 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
6502 can't tell the positions because W's display is not up to date,
6506 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
6509 int *frame_x
, *frame_y
;
6513 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
6514 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
6516 if (display_completed
)
6518 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6519 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
6520 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
6526 *frame_x
+= glyph
->pixel_width
;
6534 *frame_y
= *frame_x
= 0;
6538 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
6539 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6544 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6546 If the event is a button press, then note that we have grabbed
6550 construct_mouse_click (result
, event
, f
)
6551 struct input_event
*result
;
6552 XButtonEvent
*event
;
6555 /* Make the event type no_event; we'll change that when we decide
6557 result
->kind
= mouse_click
;
6558 result
->code
= event
->button
- Button1
;
6559 result
->timestamp
= event
->time
;
6560 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6562 | (event
->type
== ButtonRelease
6566 XSETINT (result
->x
, event
->x
);
6567 XSETINT (result
->y
, event
->y
);
6568 XSETFRAME (result
->frame_or_window
, f
);
6574 /* Function to report a mouse movement to the mainstream Emacs code.
6575 The input handler calls this.
6577 We have received a mouse movement event, which is given in *event.
6578 If the mouse is over a different glyph than it was last time, tell
6579 the mainstream emacs code by setting mouse_moved. If not, ask for
6580 another motion event, so we can check again the next time it moves. */
6582 static XMotionEvent last_mouse_motion_event
;
6583 static Lisp_Object last_mouse_motion_frame
;
6586 note_mouse_movement (frame
, event
)
6588 XMotionEvent
*event
;
6590 last_mouse_movement_time
= event
->time
;
6591 last_mouse_motion_event
= *event
;
6592 XSETFRAME (last_mouse_motion_frame
, frame
);
6594 if (event
->window
!= FRAME_X_WINDOW (frame
))
6596 frame
->mouse_moved
= 1;
6597 last_mouse_scroll_bar
= Qnil
;
6598 note_mouse_highlight (frame
, -1, -1);
6601 /* Has the mouse moved off the glyph it was on at the last sighting? */
6602 else if (event
->x
< last_mouse_glyph
.x
6603 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
6604 || event
->y
< last_mouse_glyph
.y
6605 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
6607 frame
->mouse_moved
= 1;
6608 last_mouse_scroll_bar
= Qnil
;
6609 note_mouse_highlight (frame
, event
->x
, event
->y
);
6613 /* This is used for debugging, to turn off note_mouse_highlight. */
6615 int disable_mouse_highlight
;
6619 /************************************************************************
6621 ************************************************************************/
6623 /* Find the glyph under window-relative coordinates X/Y in window W.
6624 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6625 strings. Return in *HPOS and *VPOS the row and column number of
6626 the glyph found. Return in *AREA the glyph area containing X.
6627 Value is a pointer to the glyph found or null if X/Y is not on
6628 text, or we can't tell because W's current matrix is not up to
6631 static struct glyph
*
6632 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
, buffer_only_p
)
6635 int *hpos
, *vpos
, *area
;
6638 struct glyph
*glyph
, *end
;
6639 struct glyph_row
*row
= NULL
;
6640 int x0
, i
, left_area_width
;
6642 /* Find row containing Y. Give up if some row is not enabled. */
6643 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6645 row
= MATRIX_ROW (w
->current_matrix
, i
);
6646 if (!row
->enabled_p
)
6648 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6655 /* Give up if Y is not in the window. */
6656 if (i
== w
->current_matrix
->nrows
)
6659 /* Get the glyph area containing X. */
6660 if (w
->pseudo_window_p
)
6667 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6668 if (x
< left_area_width
)
6670 *area
= LEFT_MARGIN_AREA
;
6673 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6676 x0
= row
->x
+ left_area_width
;
6680 *area
= RIGHT_MARGIN_AREA
;
6681 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6685 /* Find glyph containing X. */
6686 glyph
= row
->glyphs
[*area
];
6687 end
= glyph
+ row
->used
[*area
];
6690 if (x
< x0
+ glyph
->pixel_width
)
6692 if (w
->pseudo_window_p
)
6694 else if (!buffer_only_p
|| BUFFERP (glyph
->object
))
6698 x0
+= glyph
->pixel_width
;
6705 *hpos
= glyph
- row
->glyphs
[*area
];
6710 /* Convert frame-relative x/y to coordinates relative to window W.
6711 Takes pseudo-windows into account. */
6714 frame_to_window_pixel_xy (w
, x
, y
)
6718 if (w
->pseudo_window_p
)
6720 /* A pseudo-window is always full-width, and starts at the
6721 left edge of the frame, plus a frame border. */
6722 struct frame
*f
= XFRAME (w
->frame
);
6723 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6724 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6728 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6729 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6734 /* Take proper action when mouse has moved to the mode or header line of
6735 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6736 mode line. X is relative to the start of the text display area of
6737 W, so the width of fringes and scroll bars must be subtracted
6738 to get a position relative to the start of the mode line. */
6741 note_mode_line_highlight (w
, x
, mode_line_p
)
6745 struct frame
*f
= XFRAME (w
->frame
);
6746 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6747 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6748 struct glyph_row
*row
;
6751 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
6753 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
6757 struct glyph
*glyph
, *end
;
6758 Lisp_Object help
, map
;
6761 /* Find the glyph under X. */
6762 glyph
= row
->glyphs
[TEXT_AREA
];
6763 end
= glyph
+ row
->used
[TEXT_AREA
];
6764 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6765 + FRAME_X_LEFT_FRINGE_WIDTH (f
));
6768 && x
>= x0
+ glyph
->pixel_width
)
6770 x0
+= glyph
->pixel_width
;
6775 && STRINGP (glyph
->object
)
6776 && XSTRING (glyph
->object
)->intervals
6777 && glyph
->charpos
>= 0
6778 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6780 /* If we're on a string with `help-echo' text property,
6781 arrange for the help to be displayed. This is done by
6782 setting the global variable help_echo to the help string. */
6783 help
= Fget_text_property (make_number (glyph
->charpos
),
6784 Qhelp_echo
, glyph
->object
);
6788 XSETWINDOW (help_echo_window
, w
);
6789 help_echo_object
= glyph
->object
;
6790 help_echo_pos
= glyph
->charpos
;
6793 /* Change the mouse pointer according to what is under X/Y. */
6794 map
= Fget_text_property (make_number (glyph
->charpos
),
6795 Qlocal_map
, glyph
->object
);
6797 cursor
= f
->output_data
.x
->nontext_cursor
;
6800 map
= Fget_text_property (make_number (glyph
->charpos
),
6801 Qkeymap
, glyph
->object
);
6803 cursor
= f
->output_data
.x
->nontext_cursor
;
6808 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6812 /* Take proper action when the mouse has moved to position X, Y on
6813 frame F as regards highlighting characters that have mouse-face
6814 properties. Also de-highlighting chars where the mouse was before.
6815 X and Y can be negative or out of range. */
6818 note_mouse_highlight (f
, x
, y
)
6822 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6826 Cursor cursor
= None
;
6829 /* When a menu is active, don't highlight because this looks odd. */
6830 #ifdef USE_X_TOOLKIT
6831 if (popup_activated ())
6835 if (disable_mouse_highlight
6836 || !f
->glyphs_initialized_p
)
6839 dpyinfo
->mouse_face_mouse_x
= x
;
6840 dpyinfo
->mouse_face_mouse_y
= y
;
6841 dpyinfo
->mouse_face_mouse_frame
= f
;
6843 if (dpyinfo
->mouse_face_defer
)
6848 dpyinfo
->mouse_face_deferred_gc
= 1;
6852 /* Which window is that in? */
6853 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6855 /* If we were displaying active text in another window, clear that. */
6856 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6857 clear_mouse_face (dpyinfo
);
6859 /* Not on a window -> return. */
6860 if (!WINDOWP (window
))
6863 /* Convert to window-relative pixel coordinates. */
6864 w
= XWINDOW (window
);
6865 frame_to_window_pixel_xy (w
, &x
, &y
);
6867 /* Handle tool-bar window differently since it doesn't display a
6869 if (EQ (window
, f
->tool_bar_window
))
6871 note_tool_bar_highlight (f
, x
, y
);
6875 /* Mouse is on the mode or header line? */
6876 if (portion
== 1 || portion
== 3)
6878 note_mode_line_highlight (w
, x
, portion
== 1);
6883 cursor
= f
->output_data
.x
->horizontal_drag_cursor
;
6885 cursor
= f
->output_data
.x
->text_cursor
;
6887 /* Are we in a window whose display is up to date?
6888 And verify the buffer's text has not changed. */
6889 b
= XBUFFER (w
->buffer
);
6890 if (/* Within text portion of the window. */
6892 && EQ (w
->window_end_valid
, w
->buffer
)
6893 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
6894 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
6896 int hpos
, vpos
, pos
, i
, area
;
6897 struct glyph
*glyph
;
6899 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
6900 Lisp_Object
*overlay_vec
= NULL
;
6902 struct buffer
*obuf
;
6903 int obegv
, ozv
, same_region
;
6905 /* Find the glyph under X/Y. */
6906 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
, 0);
6908 /* Clear mouse face if X/Y not over text. */
6910 || area
!= TEXT_AREA
6911 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6913 if (clear_mouse_face (dpyinfo
))
6918 pos
= glyph
->charpos
;
6919 object
= glyph
->object
;
6920 if (!STRINGP (object
) && !BUFFERP (object
))
6923 /* If we get an out-of-range value, return now; avoid an error. */
6924 if (BUFFERP (object
) && pos
> BUF_Z (b
))
6927 /* Make the window's buffer temporarily current for
6928 overlays_at and compute_char_face. */
6929 obuf
= current_buffer
;
6936 /* Is this char mouse-active or does it have help-echo? */
6937 position
= make_number (pos
);
6939 if (BUFFERP (object
))
6941 /* Put all the overlays we want in a vector in overlay_vec.
6942 Store the length in len. If there are more than 10, make
6943 enough space for all, and try again. */
6945 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6946 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
6947 if (noverlays
> len
)
6950 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6951 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
6954 /* Sort overlays into increasing priority order. */
6955 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6960 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
6961 && vpos
>= dpyinfo
->mouse_face_beg_row
6962 && vpos
<= dpyinfo
->mouse_face_end_row
6963 && (vpos
> dpyinfo
->mouse_face_beg_row
6964 || hpos
>= dpyinfo
->mouse_face_beg_col
)
6965 && (vpos
< dpyinfo
->mouse_face_end_row
6966 || hpos
< dpyinfo
->mouse_face_end_col
6967 || dpyinfo
->mouse_face_past_end
));
6972 /* Check mouse-face highlighting. */
6974 /* If there exists an overlay with mouse-face overlapping
6975 the one we are currently highlighting, we have to
6976 check if we enter the overlapping overlay, and then
6977 highlight only that. */
6978 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
6979 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
6981 /* Find the highest priority overlay that has a mouse-face
6984 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
6986 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
6987 if (!NILP (mouse_face
))
6988 overlay
= overlay_vec
[i
];
6991 /* If we're actually highlighting the same overlay as
6992 before, there's no need to do that again. */
6994 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
6995 goto check_help_echo
;
6997 dpyinfo
->mouse_face_overlay
= overlay
;
6999 /* Clear the display of the old active region, if any. */
7000 if (clear_mouse_face (dpyinfo
))
7003 /* If no overlay applies, get a text property. */
7005 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
7007 /* Handle the overlay case. */
7008 if (!NILP (overlay
))
7010 /* Find the range of text around this char that
7011 should be active. */
7012 Lisp_Object before
, after
;
7015 before
= Foverlay_start (overlay
);
7016 after
= Foverlay_end (overlay
);
7017 /* Record this as the current active region. */
7018 fast_find_position (w
, XFASTINT (before
),
7019 &dpyinfo
->mouse_face_beg_col
,
7020 &dpyinfo
->mouse_face_beg_row
,
7021 &dpyinfo
->mouse_face_beg_x
,
7022 &dpyinfo
->mouse_face_beg_y
, Qnil
);
7024 dpyinfo
->mouse_face_past_end
7025 = !fast_find_position (w
, XFASTINT (after
),
7026 &dpyinfo
->mouse_face_end_col
,
7027 &dpyinfo
->mouse_face_end_row
,
7028 &dpyinfo
->mouse_face_end_x
,
7029 &dpyinfo
->mouse_face_end_y
, Qnil
);
7030 dpyinfo
->mouse_face_window
= window
;
7031 dpyinfo
->mouse_face_face_id
7032 = face_at_buffer_position (w
, pos
, 0, 0,
7033 &ignore
, pos
+ 1, 1);
7035 /* Display it as active. */
7036 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7039 /* Handle the text property case. */
7040 else if (!NILP (mouse_face
) && BUFFERP (object
))
7042 /* Find the range of text around this char that
7043 should be active. */
7044 Lisp_Object before
, after
, beginning
, end
;
7047 beginning
= Fmarker_position (w
->start
);
7048 end
= make_number (BUF_Z (XBUFFER (object
))
7049 - XFASTINT (w
->window_end_pos
));
7051 = Fprevious_single_property_change (make_number (pos
+ 1),
7055 = Fnext_single_property_change (position
, Qmouse_face
,
7058 /* Record this as the current active region. */
7059 fast_find_position (w
, XFASTINT (before
),
7060 &dpyinfo
->mouse_face_beg_col
,
7061 &dpyinfo
->mouse_face_beg_row
,
7062 &dpyinfo
->mouse_face_beg_x
,
7063 &dpyinfo
->mouse_face_beg_y
, Qnil
);
7064 dpyinfo
->mouse_face_past_end
7065 = !fast_find_position (w
, XFASTINT (after
),
7066 &dpyinfo
->mouse_face_end_col
,
7067 &dpyinfo
->mouse_face_end_row
,
7068 &dpyinfo
->mouse_face_end_x
,
7069 &dpyinfo
->mouse_face_end_y
, Qnil
);
7070 dpyinfo
->mouse_face_window
= window
;
7072 if (BUFFERP (object
))
7073 dpyinfo
->mouse_face_face_id
7074 = face_at_buffer_position (w
, pos
, 0, 0,
7075 &ignore
, pos
+ 1, 1);
7077 /* Display it as active. */
7078 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7081 else if (!NILP (mouse_face
) && STRINGP (object
))
7086 b
= Fprevious_single_property_change (make_number (pos
+ 1),
7089 e
= Fnext_single_property_change (position
, Qmouse_face
,
7092 b
= make_number (0);
7094 e
= make_number (XSTRING (object
)->size
- 1);
7095 fast_find_string_pos (w
, XINT (b
), object
,
7096 &dpyinfo
->mouse_face_beg_col
,
7097 &dpyinfo
->mouse_face_beg_row
,
7098 &dpyinfo
->mouse_face_beg_x
,
7099 &dpyinfo
->mouse_face_beg_y
, 0);
7100 fast_find_string_pos (w
, XINT (e
), object
,
7101 &dpyinfo
->mouse_face_end_col
,
7102 &dpyinfo
->mouse_face_end_row
,
7103 &dpyinfo
->mouse_face_end_x
,
7104 &dpyinfo
->mouse_face_end_y
, 1);
7105 dpyinfo
->mouse_face_past_end
= 0;
7106 dpyinfo
->mouse_face_window
= window
;
7107 dpyinfo
->mouse_face_face_id
7108 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
7110 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7113 else if (STRINGP (object
) && NILP (mouse_face
))
7115 /* A string which doesn't have mouse-face, but
7116 the text ``under'' it might have. */
7117 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
7118 int start
= MATRIX_ROW_START_CHARPOS (r
);
7120 pos
= string_buffer_position (w
, object
, start
);
7122 mouse_face
= get_char_property_and_overlay (make_number (pos
),
7126 if (!NILP (mouse_face
) && !NILP (overlay
))
7128 Lisp_Object before
= Foverlay_start (overlay
);
7129 Lisp_Object after
= Foverlay_end (overlay
);
7132 /* Note that we might not be able to find position
7133 BEFORE in the glyph matrix if the overlay is
7134 entirely covered by a `display' property. In
7135 this case, we overshoot. So let's stop in
7136 the glyph matrix before glyphs for OBJECT. */
7137 fast_find_position (w
, XFASTINT (before
),
7138 &dpyinfo
->mouse_face_beg_col
,
7139 &dpyinfo
->mouse_face_beg_row
,
7140 &dpyinfo
->mouse_face_beg_x
,
7141 &dpyinfo
->mouse_face_beg_y
,
7144 dpyinfo
->mouse_face_past_end
7145 = !fast_find_position (w
, XFASTINT (after
),
7146 &dpyinfo
->mouse_face_end_col
,
7147 &dpyinfo
->mouse_face_end_row
,
7148 &dpyinfo
->mouse_face_end_x
,
7149 &dpyinfo
->mouse_face_end_y
,
7151 dpyinfo
->mouse_face_window
= window
;
7152 dpyinfo
->mouse_face_face_id
7153 = face_at_buffer_position (w
, pos
, 0, 0,
7154 &ignore
, pos
+ 1, 1);
7156 /* Display it as active. */
7157 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
7165 /* Look for a `help-echo' property. */
7167 Lisp_Object help
, overlay
;
7169 /* Check overlays first. */
7170 help
= overlay
= Qnil
;
7171 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
7173 overlay
= overlay_vec
[i
];
7174 help
= Foverlay_get (overlay
, Qhelp_echo
);
7180 help_echo_window
= window
;
7181 help_echo_object
= overlay
;
7182 help_echo_pos
= pos
;
7186 Lisp_Object object
= glyph
->object
;
7187 int charpos
= glyph
->charpos
;
7189 /* Try text properties. */
7190 if (STRINGP (object
)
7192 && charpos
< XSTRING (object
)->size
)
7194 help
= Fget_text_property (make_number (charpos
),
7195 Qhelp_echo
, object
);
7198 /* If the string itself doesn't specify a help-echo,
7199 see if the buffer text ``under'' it does. */
7201 = MATRIX_ROW (w
->current_matrix
, vpos
);
7202 int start
= MATRIX_ROW_START_CHARPOS (r
);
7203 int pos
= string_buffer_position (w
, object
, start
);
7206 help
= Fget_char_property (make_number (pos
),
7207 Qhelp_echo
, w
->buffer
);
7216 else if (BUFFERP (object
)
7219 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
7225 help_echo_window
= window
;
7226 help_echo_object
= object
;
7227 help_echo_pos
= charpos
;
7234 current_buffer
= obuf
;
7240 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7244 redo_mouse_highlight ()
7246 if (!NILP (last_mouse_motion_frame
)
7247 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
7248 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
7249 last_mouse_motion_event
.x
,
7250 last_mouse_motion_event
.y
);
7255 /***********************************************************************
7257 ***********************************************************************/
7259 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
7260 struct glyph
**, int *, int *, int *));
7262 /* Tool-bar item index of the item on which a mouse button was pressed
7265 static int last_tool_bar_item
;
7268 /* Get information about the tool-bar item at position X/Y on frame F.
7269 Return in *GLYPH a pointer to the glyph of the tool-bar item in
7270 the current matrix of the tool-bar window of F, or NULL if not
7271 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
7272 item in F->tool_bar_items. Value is
7274 -1 if X/Y is not on a tool-bar item
7275 0 if X/Y is on the same item that was highlighted before.
7279 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
7282 struct glyph
**glyph
;
7283 int *hpos
, *vpos
, *prop_idx
;
7285 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7286 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7289 /* Find the glyph under X/Y. */
7290 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
, 0);
7294 /* Get the start of this tool-bar item's properties in
7295 f->tool_bar_items. */
7296 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
7299 /* Is mouse on the highlighted item? */
7300 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
7301 && *vpos
>= dpyinfo
->mouse_face_beg_row
7302 && *vpos
<= dpyinfo
->mouse_face_end_row
7303 && (*vpos
> dpyinfo
->mouse_face_beg_row
7304 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
7305 && (*vpos
< dpyinfo
->mouse_face_end_row
7306 || *hpos
< dpyinfo
->mouse_face_end_col
7307 || dpyinfo
->mouse_face_past_end
))
7314 /* Handle mouse button event on the tool-bar of frame F, at
7315 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
7319 x_handle_tool_bar_click (f
, button_event
)
7321 XButtonEvent
*button_event
;
7323 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7324 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7325 int hpos
, vpos
, prop_idx
;
7326 struct glyph
*glyph
;
7327 Lisp_Object enabled_p
;
7328 int x
= button_event
->x
;
7329 int y
= button_event
->y
;
7331 /* If not on the highlighted tool-bar item, return. */
7332 frame_to_window_pixel_xy (w
, &x
, &y
);
7333 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
7336 /* If item is disabled, do nothing. */
7337 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7338 if (NILP (enabled_p
))
7341 if (button_event
->type
== ButtonPress
)
7343 /* Show item in pressed state. */
7344 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
7345 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
7346 last_tool_bar_item
= prop_idx
;
7350 Lisp_Object key
, frame
;
7351 struct input_event event
;
7353 /* Show item in released state. */
7354 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
7355 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
7357 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
7359 XSETFRAME (frame
, f
);
7360 event
.kind
= TOOL_BAR_EVENT
;
7361 event
.frame_or_window
= frame
;
7363 kbd_buffer_store_event (&event
);
7365 event
.kind
= TOOL_BAR_EVENT
;
7366 event
.frame_or_window
= frame
;
7368 event
.modifiers
= x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
7369 button_event
->state
);
7370 kbd_buffer_store_event (&event
);
7371 last_tool_bar_item
= -1;
7376 /* Possibly highlight a tool-bar item on frame F when mouse moves to
7377 tool-bar window-relative coordinates X/Y. Called from
7378 note_mouse_highlight. */
7381 note_tool_bar_highlight (f
, x
, y
)
7385 Lisp_Object window
= f
->tool_bar_window
;
7386 struct window
*w
= XWINDOW (window
);
7387 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7389 struct glyph
*glyph
;
7390 struct glyph_row
*row
;
7392 Lisp_Object enabled_p
;
7394 enum draw_glyphs_face draw
;
7395 int mouse_down_p
, rc
;
7397 /* Function note_mouse_highlight is called with negative x(y
7398 values when mouse moves outside of the frame. */
7399 if (x
<= 0 || y
<= 0)
7401 clear_mouse_face (dpyinfo
);
7405 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
7408 /* Not on tool-bar item. */
7409 clear_mouse_face (dpyinfo
);
7415 clear_mouse_face (dpyinfo
);
7417 /* Mouse is down, but on different tool-bar item? */
7418 mouse_down_p
= (dpyinfo
->grabbed
7419 && f
== last_mouse_frame
7420 && FRAME_LIVE_P (f
));
7422 && last_tool_bar_item
!= prop_idx
)
7425 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
7426 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
7428 /* If tool-bar item is not enabled, don't highlight it. */
7429 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7430 if (!NILP (enabled_p
))
7432 /* Compute the x-position of the glyph. In front and past the
7433 image is a space. We include this is the highlighted area. */
7434 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
7435 for (i
= x
= 0; i
< hpos
; ++i
)
7436 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
7438 /* Record this as the current active region. */
7439 dpyinfo
->mouse_face_beg_col
= hpos
;
7440 dpyinfo
->mouse_face_beg_row
= vpos
;
7441 dpyinfo
->mouse_face_beg_x
= x
;
7442 dpyinfo
->mouse_face_beg_y
= row
->y
;
7443 dpyinfo
->mouse_face_past_end
= 0;
7445 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
7446 dpyinfo
->mouse_face_end_row
= vpos
;
7447 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
7448 dpyinfo
->mouse_face_end_y
= row
->y
;
7449 dpyinfo
->mouse_face_window
= window
;
7450 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
7452 /* Display it as active. */
7453 show_mouse_face (dpyinfo
, draw
);
7454 dpyinfo
->mouse_face_image_state
= draw
;
7459 /* Set help_echo to a help string.to display for this tool-bar item.
7460 XTread_socket does the rest. */
7461 help_echo_object
= help_echo_window
= Qnil
;
7463 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
7464 if (NILP (help_echo
))
7465 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
7470 /* Find the glyph matrix position of buffer position CHARPOS in window
7471 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
7472 current glyphs must be up to date. If CHARPOS is above window
7473 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
7474 of last line in W. In the row containing CHARPOS, stop before glyphs
7475 having STOP as object. */
7477 #if 0 /* This is a version of fast_find_position that's more correct
7478 in the presence of hscrolling, for example. I didn't install
7479 it right away because the problem fixed is minor, it failed
7480 in 20.x as well, and I think it's too risky to install
7481 so near the release of 21.1. 2001-09-25 gerd. */
7484 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
7487 int *hpos
, *vpos
, *x
, *y
;
7490 struct glyph_row
*row
, *first
;
7491 struct glyph
*glyph
, *end
;
7492 int i
, past_end
= 0;
7494 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7495 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
7498 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
7500 *x
= *y
= *hpos
= *vpos
= 0;
7505 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
7512 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
7514 glyph
= row
->glyphs
[TEXT_AREA
];
7515 end
= glyph
+ row
->used
[TEXT_AREA
];
7517 /* Skip over glyphs not having an object at the start of the row.
7518 These are special glyphs like truncation marks on terminal
7520 if (row
->displays_text_p
)
7522 && INTEGERP (glyph
->object
)
7523 && !EQ (stop
, glyph
->object
)
7524 && glyph
->charpos
< 0)
7526 *x
+= glyph
->pixel_width
;
7531 && !INTEGERP (glyph
->object
)
7532 && !EQ (stop
, glyph
->object
)
7533 && (!BUFFERP (glyph
->object
)
7534 || glyph
->charpos
< charpos
))
7536 *x
+= glyph
->pixel_width
;
7540 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
7547 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
7550 int *hpos
, *vpos
, *x
, *y
;
7555 int maybe_next_line_p
= 0;
7556 int line_start_position
;
7557 int yb
= window_text_bottom_y (w
);
7558 struct glyph_row
*row
, *best_row
;
7559 int row_vpos
, best_row_vpos
;
7562 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7563 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
7567 if (row
->used
[TEXT_AREA
])
7568 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
7570 line_start_position
= 0;
7572 if (line_start_position
> pos
)
7574 /* If the position sought is the end of the buffer,
7575 don't include the blank lines at the bottom of the window. */
7576 else if (line_start_position
== pos
7577 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
7579 maybe_next_line_p
= 1;
7582 else if (line_start_position
> 0)
7585 best_row_vpos
= row_vpos
;
7588 if (row
->y
+ row
->height
>= yb
)
7595 /* Find the right column within BEST_ROW. */
7597 current_x
= best_row
->x
;
7598 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
7600 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
7601 int charpos
= glyph
->charpos
;
7603 if (BUFFERP (glyph
->object
))
7608 *vpos
= best_row_vpos
;
7613 else if (charpos
> pos
)
7616 else if (EQ (glyph
->object
, stop
))
7621 current_x
+= glyph
->pixel_width
;
7624 /* If we're looking for the end of the buffer,
7625 and we didn't find it in the line we scanned,
7626 use the start of the following line. */
7627 if (maybe_next_line_p
)
7632 current_x
= best_row
->x
;
7635 *vpos
= best_row_vpos
;
7636 *hpos
= lastcol
+ 1;
7645 /* Find the position of the the glyph for position POS in OBJECT in
7646 window W's current matrix, and return in *X/*Y the pixel
7647 coordinates, and return in *HPOS/*VPOS the column/row of the glyph.
7649 RIGHT_P non-zero means return the position of the right edge of the
7650 glyph, RIGHT_P zero means return the left edge position.
7652 If no glyph for POS exists in the matrix, return the position of
7653 the glyph with the next smaller position that is in the matrix, if
7654 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
7655 exists in the matrix, return the position of the glyph with the
7656 next larger position in OBJECT.
7658 Value is non-zero if a glyph was found. */
7661 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
7665 int *hpos
, *vpos
, *x
, *y
;
7668 int yb
= window_text_bottom_y (w
);
7669 struct glyph_row
*r
;
7670 struct glyph
*best_glyph
= NULL
;
7671 struct glyph_row
*best_row
= NULL
;
7674 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7675 r
->enabled_p
&& r
->y
< yb
;
7678 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7679 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
7682 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
7683 if (EQ (g
->object
, object
))
7685 if (g
->charpos
== pos
)
7692 else if (best_glyph
== NULL
7693 || ((abs (g
->charpos
- pos
)
7694 < abs (best_glyph
->charpos
- pos
))
7697 : g
->charpos
> pos
)))
7711 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
7715 *x
+= best_glyph
->pixel_width
;
7720 *vpos
= best_row
- w
->current_matrix
->rows
;
7723 return best_glyph
!= NULL
;
7727 /* Display the active region described by mouse_face_*
7728 in its mouse-face if HL > 0, in its normal face if HL = 0. */
7731 show_mouse_face (dpyinfo
, draw
)
7732 struct x_display_info
*dpyinfo
;
7733 enum draw_glyphs_face draw
;
7735 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
7736 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7738 if (/* If window is in the process of being destroyed, don't bother
7740 w
->current_matrix
!= NULL
7741 /* Recognize when we are called to operate on rows that don't exist
7742 anymore. This can happen when a window is split. */
7743 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
7745 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
7746 struct glyph_row
*row
, *first
, *last
;
7748 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
7749 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
7751 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
7753 int start_hpos
, end_hpos
, start_x
;
7755 /* For all but the first row, the highlight starts at column 0. */
7758 start_hpos
= dpyinfo
->mouse_face_beg_col
;
7759 start_x
= dpyinfo
->mouse_face_beg_x
;
7768 end_hpos
= dpyinfo
->mouse_face_end_col
;
7770 end_hpos
= row
->used
[TEXT_AREA
];
7772 if (end_hpos
> start_hpos
)
7774 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
7775 start_hpos
, end_hpos
, draw
, 0);
7777 row
->mouse_face_p
= draw
== DRAW_MOUSE_FACE
|| DRAW_IMAGE_RAISED
;
7781 /* When we've written over the cursor, arrange for it to
7782 be displayed again. */
7783 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
7784 x_display_cursor (w
, 1,
7785 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
7786 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
7789 /* Change the mouse cursor. */
7790 if (draw
== DRAW_NORMAL_TEXT
)
7791 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7792 f
->output_data
.x
->text_cursor
);
7793 else if (draw
== DRAW_MOUSE_FACE
)
7794 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7795 f
->output_data
.x
->cross_cursor
);
7797 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7798 f
->output_data
.x
->nontext_cursor
);
7801 /* Clear out the mouse-highlighted active region.
7802 Redraw it un-highlighted first. Value is non-zero if mouse
7803 face was actually drawn unhighlighted. */
7806 clear_mouse_face (dpyinfo
)
7807 struct x_display_info
*dpyinfo
;
7811 if (!NILP (dpyinfo
->mouse_face_window
))
7813 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
7817 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7818 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7819 dpyinfo
->mouse_face_window
= Qnil
;
7820 dpyinfo
->mouse_face_overlay
= Qnil
;
7825 /* Clear any mouse-face on window W. This function is part of the
7826 redisplay interface, and is called from try_window_id and similar
7827 functions to ensure the mouse-highlight is off. */
7830 x_clear_mouse_face (w
)
7833 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
7837 XSETWINDOW (window
, w
);
7838 if (EQ (window
, dpyinfo
->mouse_face_window
))
7839 clear_mouse_face (dpyinfo
);
7844 /* Just discard the mouse face information for frame F, if any.
7845 This is used when the size of F is changed. */
7848 cancel_mouse_face (f
)
7852 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7854 window
= dpyinfo
->mouse_face_window
;
7855 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
7857 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7858 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7859 dpyinfo
->mouse_face_window
= Qnil
;
7864 static int glyph_rect
P_ ((struct frame
*f
, int, int, XRectangle
*));
7867 /* Try to determine frame pixel position and size of the glyph under
7868 frame pixel coordinates X/Y on frame F . Return the position and
7869 size in *RECT. Value is non-zero if we could compute these
7873 glyph_rect (f
, x
, y
, rect
)
7879 int part
, found
= 0;
7881 window
= window_from_coordinates (f
, x
, y
, &part
, 0);
7884 struct window
*w
= XWINDOW (window
);
7885 struct glyph_row
*r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7886 struct glyph_row
*end
= r
+ w
->current_matrix
->nrows
- 1;
7888 frame_to_window_pixel_xy (w
, &x
, &y
);
7890 for (; !found
&& r
< end
&& r
->enabled_p
; ++r
)
7893 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7894 struct glyph
*end
= g
+ r
->used
[TEXT_AREA
];
7897 for (gx
= r
->x
; !found
&& g
< end
; gx
+= g
->pixel_width
, ++g
)
7900 rect
->width
= g
->pixel_width
;
7901 rect
->height
= r
->height
;
7902 rect
->x
= WINDOW_TO_FRAME_PIXEL_X (w
, gx
);
7903 rect
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, r
->y
);
7913 /* Return the current position of the mouse.
7914 *FP should be a frame which indicates which display to ask about.
7916 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
7917 and *PART to the frame, window, and scroll bar part that the mouse
7918 is over. Set *X and *Y to the portion and whole of the mouse's
7919 position on the scroll bar.
7921 If the mouse movement started elsewhere, set *FP to the frame the
7922 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
7925 Set *TIME to the server time-stamp for the time at which the mouse
7926 was at this position.
7928 Don't store anything if we don't have a valid set of values to report.
7930 This clears the mouse_moved flag, so we can wait for the next mouse
7934 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
7937 Lisp_Object
*bar_window
;
7938 enum scroll_bar_part
*part
;
7940 unsigned long *time
;
7946 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
7947 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
7953 Window dummy_window
;
7956 Lisp_Object frame
, tail
;
7958 /* Clear the mouse-moved flag for every frame on this display. */
7959 FOR_EACH_FRAME (tail
, frame
)
7960 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
7961 XFRAME (frame
)->mouse_moved
= 0;
7963 last_mouse_scroll_bar
= Qnil
;
7965 /* Figure out which root window we're on. */
7966 XQueryPointer (FRAME_X_DISPLAY (*fp
),
7967 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
7969 /* The root window which contains the pointer. */
7972 /* Trash which we can't trust if the pointer is on
7973 a different screen. */
7976 /* The position on that root window. */
7979 /* More trash we can't trust. */
7982 /* Modifier keys and pointer buttons, about which
7984 (unsigned int *) &dummy
);
7986 /* Now we have a position on the root; find the innermost window
7987 containing the pointer. */
7991 int parent_x
= 0, parent_y
= 0;
7996 /* XTranslateCoordinates can get errors if the window
7997 structure is changing at the same time this function
7998 is running. So at least we must not crash from them. */
8000 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
8002 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
8003 && FRAME_LIVE_P (last_mouse_frame
))
8005 /* If mouse was grabbed on a frame, give coords for that frame
8006 even if the mouse is now outside it. */
8007 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
8009 /* From-window, to-window. */
8010 root
, FRAME_X_WINDOW (last_mouse_frame
),
8012 /* From-position, to-position. */
8013 root_x
, root_y
, &win_x
, &win_y
,
8017 f1
= last_mouse_frame
;
8023 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
8025 /* From-window, to-window. */
8028 /* From-position, to-position. */
8029 root_x
, root_y
, &win_x
, &win_y
,
8034 if (child
== None
|| child
== win
)
8042 /* Now we know that:
8043 win is the innermost window containing the pointer
8044 (XTC says it has no child containing the pointer),
8045 win_x and win_y are the pointer's position in it
8046 (XTC did this the last time through), and
8047 parent_x and parent_y are the pointer's position in win's parent.
8048 (They are what win_x and win_y were when win was child.
8049 If win is the root window, it has no parent, and
8050 parent_{x,y} are invalid, but that's okay, because we'll
8051 never use them in that case.) */
8053 /* Is win one of our frames? */
8054 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
8056 #ifdef USE_X_TOOLKIT
8057 /* If we end up with the menu bar window, say it's not
8060 && f1
->output_data
.x
->menubar_widget
8061 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
8063 #endif /* USE_X_TOOLKIT */
8066 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
8069 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
8071 /* If not, is it one of our scroll bars? */
8074 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
8078 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8084 if (f1
== 0 && insist
> 0)
8085 f1
= SELECTED_FRAME ();
8089 /* Ok, we found a frame. Store all the values.
8090 last_mouse_glyph is a rectangle used to reduce the
8091 generation of mouse events. To not miss any motion
8092 events, we must divide the frame into rectangles of the
8093 size of the smallest character that could be displayed
8094 on it, i.e. into the same rectangles that matrices on
8095 the frame are divided into. */
8097 int width
, height
, gx
, gy
;
8100 if (glyph_rect (f1
, win_x
, win_y
, &rect
))
8101 last_mouse_glyph
= rect
;
8104 width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
8105 height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
8109 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
8110 round down even for negative values. */
8115 gx
= (gx
+ width
- 1) / width
* width
;
8116 gy
= (gy
+ height
- 1) / height
* height
;
8118 last_mouse_glyph
.width
= width
;
8119 last_mouse_glyph
.height
= height
;
8120 last_mouse_glyph
.x
= gx
;
8121 last_mouse_glyph
.y
= gy
;
8127 XSETINT (*x
, win_x
);
8128 XSETINT (*y
, win_y
);
8129 *time
= last_mouse_movement_time
;
8138 #ifdef USE_X_TOOLKIT
8140 /* Atimer callback function for TIMER. Called every 0.1s to process
8141 Xt timeouts, if needed. We must avoid calling XtAppPending as
8142 much as possible because that function does an implicit XFlush
8143 that slows us down. */
8146 x_process_timeouts (timer
)
8147 struct atimer
*timer
;
8149 if (toolkit_scroll_bar_interaction
|| popup_activated_flag
)
8152 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
8153 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
8158 #endif /* USE_X_TOOLKIT */
8161 /* Scroll bar support. */
8163 /* Given an X window ID, find the struct scroll_bar which manages it.
8164 This can be called in GC, so we have to make sure to strip off mark
8167 static struct scroll_bar
*
8168 x_window_to_scroll_bar (window_id
)
8173 for (tail
= Vframe_list
;
8174 XGCTYPE (tail
) == Lisp_Cons
;
8177 Lisp_Object frame
, bar
, condemned
;
8179 frame
= XCAR (tail
);
8180 /* All elements of Vframe_list should be frames. */
8181 if (! GC_FRAMEP (frame
))
8184 /* Scan this frame's scroll bar list for a scroll bar with the
8186 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
8187 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
8188 /* This trick allows us to search both the ordinary and
8189 condemned scroll bar lists with one loop. */
8190 ! GC_NILP (bar
) || (bar
= condemned
,
8193 bar
= XSCROLL_BAR (bar
)->next
)
8194 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
8195 return XSCROLL_BAR (bar
);
8202 #if defined USE_LUCID
8204 /* Return the Lucid menu bar WINDOW is part of. Return null
8205 if WINDOW is not part of a menu bar. */
8208 x_window_to_menu_bar (window
)
8213 for (tail
= Vframe_list
;
8214 XGCTYPE (tail
) == Lisp_Cons
;
8217 Lisp_Object frame
= XCAR (tail
);
8218 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
8220 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
8227 #endif /* USE_LUCID */
8230 /************************************************************************
8232 ************************************************************************/
8234 #ifdef USE_TOOLKIT_SCROLL_BARS
8236 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
8237 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
8238 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
8239 struct scroll_bar
*));
8240 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
8244 /* Id of action hook installed for scroll bars. */
8246 static XtActionHookId action_hook_id
;
8248 /* Lisp window being scrolled. Set when starting to interact with
8249 a toolkit scroll bar, reset to nil when ending the interaction. */
8251 static Lisp_Object window_being_scrolled
;
8253 /* Last scroll bar part sent in xm_scroll_callback. */
8255 static int last_scroll_bar_part
;
8257 /* Whether this is an Xaw with arrow-scrollbars. This should imply
8258 that movements of 1/20 of the screen size are mapped to up/down. */
8260 static Boolean xaw3d_arrow_scroll
;
8262 /* Whether the drag scrolling maintains the mouse at the top of the
8263 thumb. If not, resizing the thumb needs to be done more carefully
8264 to avoid jerkyness. */
8266 static Boolean xaw3d_pick_top
;
8269 /* Action hook installed via XtAppAddActionHook when toolkit scroll
8270 bars are used.. The hook is responsible for detecting when
8271 the user ends an interaction with the scroll bar, and generates
8272 a `end-scroll' scroll_bar_click' event if so. */
8275 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
8278 XtPointer client_data
;
8282 Cardinal
*num_params
;
8288 scroll_bar_p
= XmIsScrollBar (widget
);
8289 end_action
= "Release";
8290 #else /* !USE_MOTIF i.e. use Xaw */
8291 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
8292 end_action
= "EndScroll";
8293 #endif /* USE_MOTIF */
8296 && strcmp (action_name
, end_action
) == 0
8297 && WINDOWP (window_being_scrolled
))
8301 x_send_scroll_bar_event (window_being_scrolled
,
8302 scroll_bar_end_scroll
, 0, 0);
8303 w
= XWINDOW (window_being_scrolled
);
8304 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
8305 window_being_scrolled
= Qnil
;
8306 last_scroll_bar_part
= -1;
8308 /* Xt timeouts no longer needed. */
8309 toolkit_scroll_bar_interaction
= 0;
8313 /* A vector of windows used for communication between
8314 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
8316 static struct window
**scroll_bar_windows
;
8317 static int scroll_bar_windows_size
;
8320 /* Send a client message with message type Xatom_Scrollbar for a
8321 scroll action to the frame of WINDOW. PART is a value identifying
8322 the part of the scroll bar that was clicked on. PORTION is the
8323 amount to scroll of a whole of WHOLE. */
8326 x_send_scroll_bar_event (window
, part
, portion
, whole
)
8328 int part
, portion
, whole
;
8331 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
8332 struct window
*w
= XWINDOW (window
);
8333 struct frame
*f
= XFRAME (w
->frame
);
8338 /* Construct a ClientMessage event to send to the frame. */
8339 ev
->type
= ClientMessage
;
8340 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
8341 ev
->display
= FRAME_X_DISPLAY (f
);
8342 ev
->window
= FRAME_X_WINDOW (f
);
8345 /* We can only transfer 32 bits in the XClientMessageEvent, which is
8346 not enough to store a pointer or Lisp_Object on a 64 bit system.
8347 So, store the window in scroll_bar_windows and pass the index
8348 into that array in the event. */
8349 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
8350 if (scroll_bar_windows
[i
] == NULL
)
8353 if (i
== scroll_bar_windows_size
)
8355 int new_size
= max (10, 2 * scroll_bar_windows_size
);
8356 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
8357 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
8359 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
8361 bzero (&scroll_bar_windows
[i
], nbytes
- old_nbytes
);
8362 scroll_bar_windows_size
= new_size
;
8365 scroll_bar_windows
[i
] = w
;
8366 ev
->data
.l
[0] = (long) i
;
8367 ev
->data
.l
[1] = (long) part
;
8368 ev
->data
.l
[2] = (long) 0;
8369 ev
->data
.l
[3] = (long) portion
;
8370 ev
->data
.l
[4] = (long) whole
;
8372 /* Make Xt timeouts work while the scroll bar is active. */
8373 toolkit_scroll_bar_interaction
= 1;
8375 /* Setting the event mask to zero means that the message will
8376 be sent to the client that created the window, and if that
8377 window no longer exists, no event will be sent. */
8378 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
8383 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
8387 x_scroll_bar_to_input_event (event
, ievent
)
8389 struct input_event
*ievent
;
8391 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
8396 w
= scroll_bar_windows
[ev
->data
.l
[0]];
8397 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
8399 XSETWINDOW (window
, w
);
8400 f
= XFRAME (w
->frame
);
8402 ievent
->kind
= scroll_bar_click
;
8403 ievent
->frame_or_window
= window
;
8405 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
8406 ievent
->part
= ev
->data
.l
[1];
8407 ievent
->code
= ev
->data
.l
[2];
8408 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
8409 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
8410 ievent
->modifiers
= 0;
8416 /* Minimum and maximum values used for Motif scroll bars. */
8419 #define XM_SB_MAX 10000000
8420 #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN)
8423 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
8424 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
8425 CALL_DATA is a pointer a a XmScrollBarCallbackStruct. */
8428 xm_scroll_callback (widget
, client_data
, call_data
)
8430 XtPointer client_data
, call_data
;
8432 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8433 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
8434 int part
= -1, whole
= 0, portion
= 0;
8438 case XmCR_DECREMENT
:
8439 bar
->dragging
= Qnil
;
8440 part
= scroll_bar_up_arrow
;
8443 case XmCR_INCREMENT
:
8444 bar
->dragging
= Qnil
;
8445 part
= scroll_bar_down_arrow
;
8448 case XmCR_PAGE_DECREMENT
:
8449 bar
->dragging
= Qnil
;
8450 part
= scroll_bar_above_handle
;
8453 case XmCR_PAGE_INCREMENT
:
8454 bar
->dragging
= Qnil
;
8455 part
= scroll_bar_below_handle
;
8459 bar
->dragging
= Qnil
;
8460 part
= scroll_bar_to_top
;
8463 case XmCR_TO_BOTTOM
:
8464 bar
->dragging
= Qnil
;
8465 part
= scroll_bar_to_bottom
;
8471 int dragging_down_p
= (INTEGERP (bar
->dragging
)
8472 && XINT (bar
->dragging
) <= cs
->value
);
8474 /* Get the slider size. */
8476 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
8479 /* At the max position of the scroll bar, do a line-wise
8480 movement. Without doing anything, we would be called with
8481 the same cs->value again and again. If we want to make
8482 sure that we can reach the end of the buffer, we have to do
8485 Implementation note: setting bar->dragging always to
8486 cs->value gives a smoother movement at the max position.
8487 Setting it to nil when doing line-wise movement gives
8488 a better slider behavior. */
8490 if (cs
->value
+ slider_size
== XM_SB_MAX
8492 && last_scroll_bar_part
== scroll_bar_down_arrow
))
8494 part
= scroll_bar_down_arrow
;
8495 bar
->dragging
= Qnil
;
8499 whole
= XM_SB_RANGE
;
8500 portion
= min (cs
->value
- XM_SB_MIN
, XM_SB_MAX
- slider_size
);
8501 part
= scroll_bar_handle
;
8502 bar
->dragging
= make_number (cs
->value
);
8507 case XmCR_VALUE_CHANGED
:
8513 window_being_scrolled
= bar
->window
;
8514 last_scroll_bar_part
= part
;
8515 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
8520 #else /* !USE_MOTIF, i.e. Xaw. */
8523 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
8524 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
8525 scroll bar struct. CALL_DATA is a pointer to a float saying where
8529 xaw_jump_callback (widget
, client_data
, call_data
)
8531 XtPointer client_data
, call_data
;
8533 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8534 float top
= *(float *) call_data
;
8536 int whole
, portion
, height
;
8539 /* Get the size of the thumb, a value between 0 and 1. */
8541 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
8545 portion
= shown
< 1 ? top
* whole
: 0;
8547 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
8548 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
8549 the bottom, so we force the scrolling whenever we see that we're
8550 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
8551 we try to ensure that we always stay two pixels away from the
8553 part
= scroll_bar_down_arrow
;
8555 part
= scroll_bar_handle
;
8557 window_being_scrolled
= bar
->window
;
8558 bar
->dragging
= make_number (portion
);
8559 last_scroll_bar_part
= part
;
8560 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
8564 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
8565 i.e. line or page up or down. WIDGET is the Xaw scroll bar
8566 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
8567 the scroll bar. CALL_DATA is an integer specifying the action that
8568 has taken place. It's magnitude is in the range 0..height of the
8569 scroll bar. Negative values mean scroll towards buffer start.
8570 Values < height of scroll bar mean line-wise movement. */
8573 xaw_scroll_callback (widget
, client_data
, call_data
)
8575 XtPointer client_data
, call_data
;
8577 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8578 int position
= (int) call_data
;
8582 /* Get the height of the scroll bar. */
8584 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
8587 if (abs (position
) >= height
)
8588 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
8590 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
8591 it maps line-movement to call_data = max(5, height/20). */
8592 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
8593 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
8595 part
= scroll_bar_move_ratio
;
8597 window_being_scrolled
= bar
->window
;
8598 bar
->dragging
= Qnil
;
8599 last_scroll_bar_part
= part
;
8600 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
8604 #endif /* not USE_MOTIF */
8607 /* Create the widget for scroll bar BAR on frame F. Record the widget
8608 and X window of the scroll bar in BAR. */
8611 x_create_toolkit_scroll_bar (f
, bar
)
8613 struct scroll_bar
*bar
;
8619 char *scroll_bar_name
= "verticalScrollBar";
8620 unsigned long pixel
;
8625 /* Set resources. Create the widget. */
8626 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
8627 XtSetArg (av
[ac
], XmNminimum
, XM_SB_MIN
); ++ac
;
8628 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
8629 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
8630 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
8631 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
8632 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
8634 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
8637 XtSetArg (av
[ac
], XmNforeground
, pixel
);
8641 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8644 XtSetArg (av
[ac
], XmNbackground
, pixel
);
8648 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
8649 scroll_bar_name
, av
, ac
);
8651 /* Add one callback for everything that can happen. */
8652 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
8654 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
8656 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
8658 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
8660 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
8662 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
8664 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
8667 /* Realize the widget. Only after that is the X window created. */
8668 XtRealizeWidget (widget
);
8670 /* Set the cursor to an arrow. I didn't find a resource to do that.
8671 And I'm wondering why it hasn't an arrow cursor by default. */
8672 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
8673 f
->output_data
.x
->nontext_cursor
);
8675 #else /* !USE_MOTIF i.e. use Xaw */
8677 /* Set resources. Create the widget. The background of the
8678 Xaw3d scroll bar widget is a little bit light for my taste.
8679 We don't alter it here to let users change it according
8680 to their taste with `emacs*verticalScrollBar.background: xxx'. */
8681 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
8682 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
8683 /* For smoother scrolling with Xaw3d -sm */
8684 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
8686 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
8689 XtSetArg (av
[ac
], XtNforeground
, pixel
);
8693 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8696 XtSetArg (av
[ac
], XtNbackground
, pixel
);
8700 /* Top/bottom shadow colors. */
8702 /* Allocate them, if necessary. */
8703 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
8705 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8706 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
8707 &pixel
, 1.2, 0x8000))
8709 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
8711 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
8713 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8714 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
8715 &pixel
, 0.6, 0x4000))
8717 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
8720 /* Tell the toolkit about them. */
8721 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
8722 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
8723 /* We tried to allocate a color for the top/bottom shadow, and
8724 failed, so tell Xaw3d to use dithering instead. */
8726 XtSetArg (av
[ac
], XtNbeNiceToColormap
, True
);
8730 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
8731 be more consistent with other emacs 3d colors, and since Xaw3d is
8732 not good at dealing with allocation failure. */
8734 /* This tells Xaw3d to use real colors instead of dithering for
8736 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
8739 /* Specify the colors. */
8740 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
8743 XtSetArg (av
[ac
], "topShadowPixel", pixel
);
8746 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
8749 XtSetArg (av
[ac
], "bottomShadowPixel", pixel
);
8754 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
8755 f
->output_data
.x
->edit_widget
, av
, ac
);
8759 char *val
= initial
;
8760 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
8761 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
8763 { /* ARROW_SCROLL */
8764 xaw3d_arrow_scroll
= True
;
8765 /* Isn't that just a personal preference ? -sm */
8766 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
8770 /* Define callbacks. */
8771 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
8772 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
8775 /* Realize the widget. Only after that is the X window created. */
8776 XtRealizeWidget (widget
);
8778 #endif /* !USE_MOTIF */
8780 /* Install an action hook that let's us detect when the user
8781 finishes interacting with a scroll bar. */
8782 if (action_hook_id
== 0)
8783 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
8785 /* Remember X window and widget in the scroll bar vector. */
8786 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
8787 xwindow
= XtWindow (widget
);
8788 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
8794 /* Set the thumb size and position of scroll bar BAR. We are currently
8795 displaying PORTION out of a whole WHOLE, and our position POSITION. */
8798 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
8799 struct scroll_bar
*bar
;
8800 int portion
, position
, whole
;
8802 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8803 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
8810 top
= (float) position
/ whole
;
8811 shown
= (float) portion
/ whole
;
8820 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
8821 is the scroll bar's maximum and MIN is the scroll bar's minimum
8823 size
= shown
* XM_SB_RANGE
;
8824 size
= min (size
, XM_SB_RANGE
);
8825 size
= max (size
, 1);
8827 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
8828 value
= top
* XM_SB_RANGE
;
8829 value
= min (value
, XM_SB_MAX
- size
);
8830 value
= max (value
, XM_SB_MIN
);
8832 if (NILP (bar
->dragging
))
8833 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
8834 else if (last_scroll_bar_part
== scroll_bar_down_arrow
)
8835 /* This has the negative side effect that the slider value is
8836 not what it would be if we scrolled here using line-wise or
8837 page-wise movement. */
8838 XmScrollBarSetValues (widget
, value
, XM_SB_RANGE
- value
, 0, 0, False
);
8841 /* If currently dragging, only update the slider size.
8842 This reduces flicker effects. */
8843 int old_value
, old_size
, increment
, page_increment
;
8845 XmScrollBarGetValues (widget
, &old_value
, &old_size
,
8846 &increment
, &page_increment
);
8847 XmScrollBarSetValues (widget
, old_value
,
8848 min (size
, XM_SB_RANGE
- old_value
),
8852 #else /* !USE_MOTIF i.e. use Xaw */
8854 float old_top
, old_shown
;
8856 XtVaGetValues (widget
,
8857 XtNtopOfThumb
, &old_top
,
8858 XtNshown
, &old_shown
,
8862 /* Massage the top+shown values. */
8863 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
8864 top
= max (0, min (1, top
));
8867 /* Keep two pixels available for moving the thumb down. */
8868 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
8870 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
8871 check that your system's configuration file contains a define
8872 for `NARROWPROTO'. See s/freebsd.h for an example. */
8873 if (top
!= old_top
|| shown
!= old_shown
)
8875 if (NILP (bar
->dragging
))
8876 XawScrollbarSetThumb (widget
, top
, shown
);
8880 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
8881 int scroll_mode
= 0;
8883 /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR. */
8884 if (xaw3d_arrow_scroll
)
8886 /* Xaw3d stupidly ignores resize requests while dragging
8887 so we have to make it believe it's not in dragging mode. */
8888 scroll_mode
= sb
->scrollbar
.scroll_mode
;
8889 if (scroll_mode
== 2)
8890 sb
->scrollbar
.scroll_mode
= 0;
8893 /* Try to make the scrolling a tad smoother. */
8894 if (!xaw3d_pick_top
)
8895 shown
= min (shown
, old_shown
);
8897 XawScrollbarSetThumb (widget
, top
, shown
);
8900 if (xaw3d_arrow_scroll
&& scroll_mode
== 2)
8901 sb
->scrollbar
.scroll_mode
= scroll_mode
;
8906 #endif /* !USE_MOTIF */
8911 #endif /* USE_TOOLKIT_SCROLL_BARS */
8915 /************************************************************************
8916 Scroll bars, general
8917 ************************************************************************/
8919 /* Create a scroll bar and return the scroll bar vector for it. W is
8920 the Emacs window on which to create the scroll bar. TOP, LEFT,
8921 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
8924 static struct scroll_bar
*
8925 x_scroll_bar_create (w
, top
, left
, width
, height
)
8927 int top
, left
, width
, height
;
8929 struct frame
*f
= XFRAME (w
->frame
);
8930 struct scroll_bar
*bar
8931 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
8935 #ifdef USE_TOOLKIT_SCROLL_BARS
8936 x_create_toolkit_scroll_bar (f
, bar
);
8937 #else /* not USE_TOOLKIT_SCROLL_BARS */
8939 XSetWindowAttributes a
;
8943 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8944 if (a
.background_pixel
== -1)
8945 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
8947 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
8948 | ButtonMotionMask
| PointerMotionHintMask
8950 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
8952 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
8954 /* Clear the area of W that will serve as a scroll bar. This is
8955 for the case that a window has been split horizontally. In
8956 this case, no clear_frame is generated to reduce flickering. */
8957 if (width
> 0 && height
> 0)
8958 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8960 window_box_height (w
), False
);
8962 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8963 /* Position and size of scroll bar. */
8964 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8966 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8968 /* Border width, depth, class, and visual. */
8975 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
8977 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8979 XSETWINDOW (bar
->window
, w
);
8980 XSETINT (bar
->top
, top
);
8981 XSETINT (bar
->left
, left
);
8982 XSETINT (bar
->width
, width
);
8983 XSETINT (bar
->height
, height
);
8984 XSETINT (bar
->start
, 0);
8985 XSETINT (bar
->end
, 0);
8986 bar
->dragging
= Qnil
;
8988 /* Add bar to its frame's list of scroll bars. */
8989 bar
->next
= FRAME_SCROLL_BARS (f
);
8991 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8992 if (!NILP (bar
->next
))
8993 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8995 /* Map the window/widget. */
8996 #ifdef USE_TOOLKIT_SCROLL_BARS
8998 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
8999 XtConfigureWidget (scroll_bar
,
9000 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9002 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
9003 max (height
, 1), 0);
9004 XtMapWidget (scroll_bar
);
9006 #else /* not USE_TOOLKIT_SCROLL_BARS */
9007 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
9008 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9015 /* Draw BAR's handle in the proper position.
9017 If the handle is already drawn from START to END, don't bother
9018 redrawing it, unless REBUILD is non-zero; in that case, always
9019 redraw it. (REBUILD is handy for drawing the handle after expose
9022 Normally, we want to constrain the start and end of the handle to
9023 fit inside its rectangle, but if the user is dragging the scroll
9024 bar handle, we want to let them drag it down all the way, so that
9025 the bar's top is as far down as it goes; otherwise, there's no way
9026 to move to the very end of the buffer. */
9028 #ifndef USE_TOOLKIT_SCROLL_BARS
9031 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
9032 struct scroll_bar
*bar
;
9036 int dragging
= ! NILP (bar
->dragging
);
9037 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9038 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9039 GC gc
= f
->output_data
.x
->normal_gc
;
9041 /* If the display is already accurate, do nothing. */
9043 && start
== XINT (bar
->start
)
9044 && end
== XINT (bar
->end
))
9050 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
9051 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9052 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9054 /* Make sure the values are reasonable, and try to preserve
9055 the distance between start and end. */
9057 int length
= end
- start
;
9061 else if (start
> top_range
)
9063 end
= start
+ length
;
9067 else if (end
> top_range
&& ! dragging
)
9071 /* Store the adjusted setting in the scroll bar. */
9072 XSETINT (bar
->start
, start
);
9073 XSETINT (bar
->end
, end
);
9075 /* Clip the end position, just for display. */
9076 if (end
> top_range
)
9079 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
9080 below top positions, to make sure the handle is always at least
9081 that many pixels tall. */
9082 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
9084 /* Draw the empty space above the handle. Note that we can't clear
9085 zero-height areas; that means "clear to end of window." */
9087 x_clear_area (FRAME_X_DISPLAY (f
), w
,
9088 /* x, y, width, height, and exposures. */
9089 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
9090 VERTICAL_SCROLL_BAR_TOP_BORDER
,
9091 inside_width
, start
,
9094 /* Change to proper foreground color if one is specified. */
9095 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9096 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
9097 f
->output_data
.x
->scroll_bar_foreground_pixel
);
9099 /* Draw the handle itself. */
9100 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
9101 /* x, y, width, height */
9102 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
9103 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
9104 inside_width
, end
- start
);
9106 /* Restore the foreground color of the GC if we changed it above. */
9107 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9108 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
9109 f
->output_data
.x
->foreground_pixel
);
9111 /* Draw the empty space below the handle. Note that we can't
9112 clear zero-height areas; that means "clear to end of window." */
9113 if (end
< inside_height
)
9114 x_clear_area (FRAME_X_DISPLAY (f
), w
,
9115 /* x, y, width, height, and exposures. */
9116 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
9117 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
9118 inside_width
, inside_height
- end
,
9126 #endif /* !USE_TOOLKIT_SCROLL_BARS */
9128 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
9132 x_scroll_bar_remove (bar
)
9133 struct scroll_bar
*bar
;
9135 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9138 #ifdef USE_TOOLKIT_SCROLL_BARS
9139 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
9141 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
9144 /* Disassociate this scroll bar from its window. */
9145 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
9151 /* Set the handle of the vertical scroll bar for WINDOW to indicate
9152 that we are displaying PORTION characters out of a total of WHOLE
9153 characters, starting at POSITION. If WINDOW has no scroll bar,
9157 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
9159 int portion
, whole
, position
;
9161 struct frame
*f
= XFRAME (w
->frame
);
9162 struct scroll_bar
*bar
;
9163 int top
, height
, left
, sb_left
, width
, sb_width
;
9164 int window_x
, window_y
, window_width
, window_height
;
9166 /* Get window dimensions. */
9167 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
9169 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
9170 height
= window_height
;
9172 /* Compute the left edge of the scroll bar area. */
9173 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
9174 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
9176 left
= XFASTINT (w
->left
);
9177 left
*= CANON_X_UNIT (f
);
9178 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
9180 /* Compute the width of the scroll bar which might be less than
9181 the width of the area reserved for the scroll bar. */
9182 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
9183 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
9187 /* Compute the left edge of the scroll bar. */
9188 #ifdef USE_TOOLKIT_SCROLL_BARS
9189 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
9190 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
9192 sb_left
= left
+ (width
- sb_width
) / 2;
9194 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
9195 sb_left
= left
+ width
- sb_width
;
9200 /* Does the scroll bar exist yet? */
9201 if (NILP (w
->vertical_scroll_bar
))
9203 if (width
> 0 && height
> 0)
9206 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9207 left
, top
, width
, height
, False
);
9211 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
9215 /* It may just need to be moved and resized. */
9216 unsigned int mask
= 0;
9218 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
9222 if (sb_left
!= XINT (bar
->left
))
9224 if (top
!= XINT (bar
->top
))
9226 if (sb_width
!= XINT (bar
->width
))
9228 if (height
!= XINT (bar
->height
))
9231 #ifdef USE_TOOLKIT_SCROLL_BARS
9233 /* Since toolkit scroll bars are smaller than the space reserved
9234 for them on the frame, we have to clear "under" them. */
9235 if (width
> 0 && height
> 0)
9236 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9237 left
, top
, width
, height
, False
);
9239 /* Move/size the scroll bar widget. */
9241 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
9242 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9244 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
9245 max (height
, 1), 0);
9247 #else /* not USE_TOOLKIT_SCROLL_BARS */
9249 /* Clear areas not covered by the scroll bar because of
9250 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
9251 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
9253 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9254 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9256 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9257 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9258 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
9262 /* Clear areas not covered by the scroll bar because it's not as
9263 wide as the area reserved for it . This makes sure a
9264 previous mode line display is cleared after C-x 2 C-x 1, for
9267 int area_width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
9268 int rest
= area_width
- sb_width
;
9269 if (rest
> 0 && height
> 0)
9271 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f
))
9272 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9273 left
+ area_width
- rest
, top
,
9274 rest
, height
, False
);
9276 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9277 left
, top
, rest
, height
, False
);
9281 /* Move/size the scroll bar window. */
9286 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
9288 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
9290 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
9294 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9296 /* Remember new settings. */
9297 XSETINT (bar
->left
, sb_left
);
9298 XSETINT (bar
->top
, top
);
9299 XSETINT (bar
->width
, sb_width
);
9300 XSETINT (bar
->height
, height
);
9305 #ifdef USE_TOOLKIT_SCROLL_BARS
9306 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
9307 #else /* not USE_TOOLKIT_SCROLL_BARS */
9308 /* Set the scroll bar's current state, unless we're currently being
9310 if (NILP (bar
->dragging
))
9312 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
9315 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
9318 int start
= ((double) position
* top_range
) / whole
;
9319 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
9320 x_scroll_bar_set_handle (bar
, start
, end
, 0);
9323 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9325 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
9329 /* The following three hooks are used when we're doing a thorough
9330 redisplay of the frame. We don't explicitly know which scroll bars
9331 are going to be deleted, because keeping track of when windows go
9332 away is a real pain - "Can you say set-window-configuration, boys
9333 and girls?" Instead, we just assert at the beginning of redisplay
9334 that *all* scroll bars are to be removed, and then save a scroll bar
9335 from the fiery pit when we actually redisplay its window. */
9337 /* Arrange for all scroll bars on FRAME to be removed at the next call
9338 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
9339 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
9342 XTcondemn_scroll_bars (frame
)
9345 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
9346 while (! NILP (FRAME_SCROLL_BARS (frame
)))
9349 bar
= FRAME_SCROLL_BARS (frame
);
9350 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
9351 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
9352 XSCROLL_BAR (bar
)->prev
= Qnil
;
9353 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
9354 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
9355 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
9360 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
9361 Note that WINDOW isn't necessarily condemned at all. */
9364 XTredeem_scroll_bar (window
)
9365 struct window
*window
;
9367 struct scroll_bar
*bar
;
9370 /* We can't redeem this window's scroll bar if it doesn't have one. */
9371 if (NILP (window
->vertical_scroll_bar
))
9374 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
9376 /* Unlink it from the condemned list. */
9377 f
= XFRAME (WINDOW_FRAME (window
));
9378 if (NILP (bar
->prev
))
9380 /* If the prev pointer is nil, it must be the first in one of
9382 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
9383 /* It's not condemned. Everything's fine. */
9385 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
9386 window
->vertical_scroll_bar
))
9387 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
9389 /* If its prev pointer is nil, it must be at the front of
9390 one or the other! */
9394 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
9396 if (! NILP (bar
->next
))
9397 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
9399 bar
->next
= FRAME_SCROLL_BARS (f
);
9401 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
9402 if (! NILP (bar
->next
))
9403 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
9406 /* Remove all scroll bars on FRAME that haven't been saved since the
9407 last call to `*condemn_scroll_bars_hook'. */
9410 XTjudge_scroll_bars (f
)
9413 Lisp_Object bar
, next
;
9415 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
9417 /* Clear out the condemned list now so we won't try to process any
9418 more events on the hapless scroll bars. */
9419 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
9421 for (; ! NILP (bar
); bar
= next
)
9423 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
9425 x_scroll_bar_remove (b
);
9428 b
->next
= b
->prev
= Qnil
;
9431 /* Now there should be no references to the condemned scroll bars,
9432 and they should get garbage-collected. */
9436 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
9437 is a no-op when using toolkit scroll bars.
9439 This may be called from a signal handler, so we have to ignore GC
9443 x_scroll_bar_expose (bar
, event
)
9444 struct scroll_bar
*bar
;
9447 #ifndef USE_TOOLKIT_SCROLL_BARS
9449 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9450 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9451 GC gc
= f
->output_data
.x
->normal_gc
;
9452 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
9456 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
9458 /* Draw a one-pixel border just inside the edges of the scroll bar. */
9459 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
9461 /* x, y, width, height */
9463 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
9464 XINT (bar
->height
) - 1);
9468 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9471 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
9472 is set to something other than no_event, it is enqueued.
9474 This may be called from a signal handler, so we have to ignore GC
9477 #ifndef USE_TOOLKIT_SCROLL_BARS
9480 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
9481 struct scroll_bar
*bar
;
9483 struct input_event
*emacs_event
;
9485 if (! GC_WINDOWP (bar
->window
))
9488 emacs_event
->kind
= scroll_bar_click
;
9489 emacs_event
->code
= event
->xbutton
.button
- Button1
;
9490 emacs_event
->modifiers
9491 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
9492 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
9493 event
->xbutton
.state
)
9494 | (event
->type
== ButtonRelease
9497 emacs_event
->frame_or_window
= bar
->window
;
9498 emacs_event
->arg
= Qnil
;
9499 emacs_event
->timestamp
= event
->xbutton
.time
;
9502 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9504 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9507 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9508 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
9511 if (y
> top_range
) y
= top_range
;
9513 if (y
< XINT (bar
->start
))
9514 emacs_event
->part
= scroll_bar_above_handle
;
9515 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
9516 emacs_event
->part
= scroll_bar_handle
;
9518 emacs_event
->part
= scroll_bar_below_handle
;
9520 /* Just because the user has clicked on the handle doesn't mean
9521 they want to drag it. Lisp code needs to be able to decide
9522 whether or not we're dragging. */
9524 /* If the user has just clicked on the handle, record where they're
9526 if (event
->type
== ButtonPress
9527 && emacs_event
->part
== scroll_bar_handle
)
9528 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
9531 /* If the user has released the handle, set it to its final position. */
9532 if (event
->type
== ButtonRelease
9533 && ! NILP (bar
->dragging
))
9535 int new_start
= y
- XINT (bar
->dragging
);
9536 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
9538 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
9539 bar
->dragging
= Qnil
;
9542 /* Same deal here as the other #if 0. */
9544 /* Clicks on the handle are always reported as occurring at the top of
9546 if (emacs_event
->part
== scroll_bar_handle
)
9547 emacs_event
->x
= bar
->start
;
9549 XSETINT (emacs_event
->x
, y
);
9551 XSETINT (emacs_event
->x
, y
);
9554 XSETINT (emacs_event
->y
, top_range
);
9558 /* Handle some mouse motion while someone is dragging the scroll bar.
9560 This may be called from a signal handler, so we have to ignore GC
9564 x_scroll_bar_note_movement (bar
, event
)
9565 struct scroll_bar
*bar
;
9568 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
9570 last_mouse_movement_time
= event
->xmotion
.time
;
9573 XSETVECTOR (last_mouse_scroll_bar
, bar
);
9575 /* If we're dragging the bar, display it. */
9576 if (! GC_NILP (bar
->dragging
))
9578 /* Where should the handle be now? */
9579 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
9581 if (new_start
!= XINT (bar
->start
))
9583 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
9585 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
9590 #endif /* !USE_TOOLKIT_SCROLL_BARS */
9592 /* Return information to the user about the current position of the mouse
9593 on the scroll bar. */
9596 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
9598 Lisp_Object
*bar_window
;
9599 enum scroll_bar_part
*part
;
9601 unsigned long *time
;
9603 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
9604 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9605 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9607 Window dummy_window
;
9609 unsigned int dummy_mask
;
9613 /* Get the mouse's position relative to the scroll bar window, and
9615 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
9617 /* Root, child, root x and root y. */
9618 &dummy_window
, &dummy_window
,
9619 &dummy_coord
, &dummy_coord
,
9621 /* Position relative to scroll bar. */
9624 /* Mouse buttons and modifier keys. */
9631 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9634 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9636 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
9638 if (! NILP (bar
->dragging
))
9639 win_y
-= XINT (bar
->dragging
);
9643 if (win_y
> top_range
)
9647 *bar_window
= bar
->window
;
9649 if (! NILP (bar
->dragging
))
9650 *part
= scroll_bar_handle
;
9651 else if (win_y
< XINT (bar
->start
))
9652 *part
= scroll_bar_above_handle
;
9653 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
9654 *part
= scroll_bar_handle
;
9656 *part
= scroll_bar_below_handle
;
9658 XSETINT (*x
, win_y
);
9659 XSETINT (*y
, top_range
);
9662 last_mouse_scroll_bar
= Qnil
;
9665 *time
= last_mouse_movement_time
;
9671 /* The screen has been cleared so we may have changed foreground or
9672 background colors, and the scroll bars may need to be redrawn.
9673 Clear out the scroll bars, and ask for expose events, so we can
9677 x_scroll_bar_clear (f
)
9680 #ifndef USE_TOOLKIT_SCROLL_BARS
9683 /* We can have scroll bars even if this is 0,
9684 if we just turned off scroll bar mode.
9685 But in that case we should not clear them. */
9686 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9687 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
9688 bar
= XSCROLL_BAR (bar
)->next
)
9689 XClearArea (FRAME_X_DISPLAY (f
),
9690 SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
9692 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9695 /* This processes Expose events from the menu-bar specific X event
9696 loop in xmenu.c. This allows to redisplay the frame if necessary
9697 when handling menu-bar or pop-up items. */
9700 process_expose_from_menu (event
)
9704 struct x_display_info
*dpyinfo
;
9705 int frame_exposed_p
= 0;
9709 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
9710 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
9713 if (f
->async_visible
== 0)
9715 f
->async_visible
= 1;
9716 f
->async_iconified
= 0;
9717 f
->output_data
.x
->has_been_visible
= 1;
9718 SET_FRAME_GARBAGED (f
);
9722 expose_frame (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
9723 event
.xexpose
.x
, event
.xexpose
.y
,
9724 event
.xexpose
.width
, event
.xexpose
.height
);
9725 frame_exposed_p
= 1;
9730 struct scroll_bar
*bar
9731 = x_window_to_scroll_bar (event
.xexpose
.window
);
9734 x_scroll_bar_expose (bar
, &event
);
9738 return frame_exposed_p
;
9741 /* Define a queue to save up SelectionRequest events for later handling. */
9743 struct selection_event_queue
9746 struct selection_event_queue
*next
;
9749 static struct selection_event_queue
*queue
;
9751 /* Nonzero means queue up certain events--don't process them yet. */
9753 static int x_queue_selection_requests
;
9755 /* Queue up an X event *EVENT, to be processed later. */
9758 x_queue_event (f
, event
)
9762 struct selection_event_queue
*queue_tmp
9763 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
9765 if (queue_tmp
!= NULL
)
9767 queue_tmp
->event
= *event
;
9768 queue_tmp
->next
= queue
;
9773 /* Take all the queued events and put them back
9774 so that they get processed afresh. */
9777 x_unqueue_events (display
)
9780 while (queue
!= NULL
)
9782 struct selection_event_queue
*queue_tmp
= queue
;
9783 XPutBackEvent (display
, &queue_tmp
->event
);
9784 queue
= queue_tmp
->next
;
9785 xfree ((char *)queue_tmp
);
9789 /* Start queuing SelectionRequest events. */
9792 x_start_queuing_selection_requests (display
)
9795 x_queue_selection_requests
++;
9798 /* Stop queuing SelectionRequest events. */
9801 x_stop_queuing_selection_requests (display
)
9804 x_queue_selection_requests
--;
9805 x_unqueue_events (display
);
9808 /* The main X event-reading loop - XTread_socket. */
9810 /* Time stamp of enter window event. This is only used by XTread_socket,
9811 but we have to put it out here, since static variables within functions
9812 sometimes don't work. */
9814 static Time enter_timestamp
;
9816 /* This holds the state XLookupString needs to implement dead keys
9817 and other tricks known as "compose processing". _X Window System_
9818 says that a portable program can't use this, but Stephen Gildea assures
9819 me that letting the compiler initialize it to zeros will work okay.
9821 This must be defined outside of XTread_socket, for the same reasons
9822 given for enter_time stamp, above. */
9824 static XComposeStatus compose_status
;
9826 /* Record the last 100 characters stored
9827 to help debug the loss-of-chars-during-GC problem. */
9829 static int temp_index
;
9830 static short temp_buffer
[100];
9832 /* Set this to nonzero to fake an "X I/O error"
9833 on a particular display. */
9835 struct x_display_info
*XTread_socket_fake_io_error
;
9837 /* When we find no input here, we occasionally do a no-op command
9838 to verify that the X server is still running and we can still talk with it.
9839 We try all the open displays, one by one.
9840 This variable is used for cycling thru the displays. */
9842 static struct x_display_info
*next_noop_dpyinfo
;
9844 #define SET_SAVED_MENU_EVENT(size) \
9847 if (f->output_data.x->saved_menu_event == 0) \
9848 f->output_data.x->saved_menu_event \
9849 = (XEvent *) xmalloc (sizeof (XEvent)); \
9850 bcopy (&event, f->output_data.x->saved_menu_event, size); \
9851 if (numchars >= 1) \
9853 bufp->kind = menu_bar_activate_event; \
9854 XSETFRAME (bufp->frame_or_window, f); \
9863 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
9864 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
9866 /* Read events coming from the X server.
9867 This routine is called by the SIGIO handler.
9868 We return as soon as there are no more events to be read.
9870 Events representing keys are stored in buffer BUFP,
9871 which can hold up to NUMCHARS characters.
9872 We return the number of characters stored into the buffer,
9873 thus pretending to be `read'.
9875 EXPECTED is nonzero if the caller knows input is available. */
9878 XTread_socket (sd
, bufp
, numchars
, expected
)
9880 /* register */ struct input_event
*bufp
;
9881 /* register */ int numchars
;
9888 int event_found
= 0;
9889 struct x_display_info
*dpyinfo
;
9890 struct coding_system coding
;
9892 if (interrupt_input_blocked
)
9894 interrupt_input_pending
= 1;
9898 interrupt_input_pending
= 0;
9901 /* So people can tell when we have read the available input. */
9902 input_signal_count
++;
9905 abort (); /* Don't think this happens. */
9909 /* The input should be decoded if it is from XIM. Currently the
9910 locale of XIM is the same as that of the system. So, we can use
9911 Vlocale_coding_system which is initialized properly at Emacs
9913 setup_coding_system (Vlocale_coding_system
, &coding
);
9914 coding
.src_multibyte
= 0;
9915 coding
.dst_multibyte
= 1;
9916 /* The input is converted to events, thus we can't handle
9917 composition. Anyway, there's no XIM that gives us composition
9919 coding
.composing
= COMPOSITION_DISABLED
;
9921 /* Find the display we are supposed to read input for.
9922 It's the one communicating on descriptor SD. */
9923 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
9925 #if 0 /* This ought to be unnecessary; let's verify it. */
9927 /* If available, Xlib uses FIOSNBIO to make the socket
9928 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
9929 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
9930 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
9931 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
9932 #endif /* ! defined (FIOSNBIO) */
9935 #if 0 /* This code can't be made to work, with multiple displays,
9936 and appears not to be used on any system any more.
9937 Also keyboard.c doesn't turn O_NDELAY on and off
9938 for X connections. */
9941 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
9943 extern int read_alarm_should_throw
;
9944 read_alarm_should_throw
= 1;
9945 XPeekEvent (dpyinfo
->display
, &event
);
9946 read_alarm_should_throw
= 0;
9948 #endif /* HAVE_SELECT */
9952 /* For debugging, this gives a way to fake an I/O error. */
9953 if (dpyinfo
== XTread_socket_fake_io_error
)
9955 XTread_socket_fake_io_error
= 0;
9956 x_io_error_quitter (dpyinfo
->display
);
9959 while (XPending (dpyinfo
->display
))
9961 XNextEvent (dpyinfo
->display
, &event
);
9965 /* Filter events for the current X input method.
9966 XFilterEvent returns non-zero if the input method has
9967 consumed the event. We pass the frame's X window to
9968 XFilterEvent because that's the one for which the IC
9970 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
9971 event
.xclient
.window
);
9972 if (XFilterEvent (&event
, f1
? FRAME_X_WINDOW (f1
) : None
))
9982 if (event
.xclient
.message_type
9983 == dpyinfo
->Xatom_wm_protocols
9984 && event
.xclient
.format
== 32)
9986 if (event
.xclient
.data
.l
[0]
9987 == dpyinfo
->Xatom_wm_take_focus
)
9989 /* Use x_any_window_to_frame because this
9990 could be the shell widget window
9991 if the frame has no title bar. */
9992 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9994 /* Not quite sure this is needed -pd */
9995 if (f
&& FRAME_XIC (f
))
9996 XSetICFocus (FRAME_XIC (f
));
9998 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
9999 instructs the WM to set the input focus automatically for
10000 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
10001 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
10002 it has set the focus. So, XSetInputFocus below is not
10005 The call to XSetInputFocus below has also caused trouble. In
10006 cases where the XSetInputFocus done by the WM and the one
10007 below are temporally close (on a fast machine), the call
10008 below can generate additional FocusIn events which confuse
10011 /* Since we set WM_TAKE_FOCUS, we must call
10012 XSetInputFocus explicitly. But not if f is null,
10013 since that might be an event for a deleted frame. */
10016 Display
*d
= event
.xclient
.display
;
10017 /* Catch and ignore errors, in case window has been
10018 iconified by a window manager such as GWM. */
10019 int count
= x_catch_errors (d
);
10020 XSetInputFocus (d
, event
.xclient
.window
,
10021 /* The ICCCM says this is
10022 the only valid choice. */
10024 event
.xclient
.data
.l
[1]);
10025 /* This is needed to detect the error
10026 if there is an error. */
10028 x_uncatch_errors (d
, count
);
10030 /* Not certain about handling scroll bars here */
10033 else if (event
.xclient
.data
.l
[0]
10034 == dpyinfo
->Xatom_wm_save_yourself
)
10036 /* Save state modify the WM_COMMAND property to
10037 something which can reinstate us. This notifies
10038 the session manager, who's looking for such a
10039 PropertyNotify. Can restart processing when
10040 a keyboard or mouse event arrives. */
10043 f
= x_top_window_to_frame (dpyinfo
,
10044 event
.xclient
.window
);
10046 /* This is just so we only give real data once
10047 for a single Emacs process. */
10048 if (f
== SELECTED_FRAME ())
10049 XSetCommand (FRAME_X_DISPLAY (f
),
10050 event
.xclient
.window
,
10051 initial_argv
, initial_argc
);
10053 XSetCommand (FRAME_X_DISPLAY (f
),
10054 event
.xclient
.window
,
10058 else if (event
.xclient
.data
.l
[0]
10059 == dpyinfo
->Xatom_wm_delete_window
)
10062 = x_any_window_to_frame (dpyinfo
,
10063 event
.xclient
.window
);
10070 bufp
->kind
= delete_window_event
;
10071 XSETFRAME (bufp
->frame_or_window
, f
);
10080 else if (event
.xclient
.message_type
10081 == dpyinfo
->Xatom_wm_configure_denied
)
10084 else if (event
.xclient
.message_type
10085 == dpyinfo
->Xatom_wm_window_moved
)
10089 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
10091 new_x
= event
.xclient
.data
.s
[0];
10092 new_y
= event
.xclient
.data
.s
[1];
10096 f
->output_data
.x
->left_pos
= new_x
;
10097 f
->output_data
.x
->top_pos
= new_y
;
10100 #ifdef HACK_EDITRES
10101 else if (event
.xclient
.message_type
10102 == dpyinfo
->Xatom_editres
)
10105 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
10106 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
10109 #endif /* HACK_EDITRES */
10110 else if ((event
.xclient
.message_type
10111 == dpyinfo
->Xatom_DONE
)
10112 || (event
.xclient
.message_type
10113 == dpyinfo
->Xatom_PAGE
))
10115 /* Ghostview job completed. Kill it. We could
10116 reply with "Next" if we received "Page", but we
10117 currently never do because we are interested in
10118 images, only, which should have 1 page. */
10119 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
10121 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
10122 x_kill_gs_process (pixmap
, f
);
10123 expose_frame (f
, 0, 0, 0, 0);
10125 #ifdef USE_TOOLKIT_SCROLL_BARS
10126 /* Scroll bar callbacks send a ClientMessage from which
10127 we construct an input_event. */
10128 else if (event
.xclient
.message_type
10129 == dpyinfo
->Xatom_Scrollbar
)
10131 x_scroll_bar_to_input_event (&event
, bufp
);
10132 ++bufp
, ++count
, --numchars
;
10135 #endif /* USE_TOOLKIT_SCROLL_BARS */
10141 case SelectionNotify
:
10142 #ifdef USE_X_TOOLKIT
10143 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
10145 #endif /* not USE_X_TOOLKIT */
10146 x_handle_selection_notify (&event
.xselection
);
10149 case SelectionClear
: /* Someone has grabbed ownership. */
10150 #ifdef USE_X_TOOLKIT
10151 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
10153 #endif /* USE_X_TOOLKIT */
10155 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
10160 bufp
->kind
= selection_clear_event
;
10161 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
10162 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
10163 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
10164 bufp
->frame_or_window
= Qnil
;
10173 case SelectionRequest
: /* Someone wants our selection. */
10174 #ifdef USE_X_TOOLKIT
10175 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
10177 #endif /* USE_X_TOOLKIT */
10178 if (x_queue_selection_requests
)
10179 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
10183 XSelectionRequestEvent
*eventp
10184 = (XSelectionRequestEvent
*) &event
;
10189 bufp
->kind
= selection_request_event
;
10190 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
10191 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
10192 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
10193 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
10194 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
10195 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
10196 bufp
->frame_or_window
= Qnil
;
10205 case PropertyNotify
:
10206 #if 0 /* This is plain wrong. In the case that we are waiting for a
10207 PropertyNotify used as an ACK in incremental selection
10208 transfer, the property will be on the receiver's window. */
10209 #if defined USE_X_TOOLKIT
10210 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
10214 x_handle_property_notify (&event
.xproperty
);
10217 case ReparentNotify
:
10218 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
10222 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
10223 x_real_positions (f
, &x
, &y
);
10224 f
->output_data
.x
->left_pos
= x
;
10225 f
->output_data
.x
->top_pos
= y
;
10230 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
10233 if (f
->async_visible
== 0)
10235 f
->async_visible
= 1;
10236 f
->async_iconified
= 0;
10237 f
->output_data
.x
->has_been_visible
= 1;
10238 SET_FRAME_GARBAGED (f
);
10241 expose_frame (x_window_to_frame (dpyinfo
,
10242 event
.xexpose
.window
),
10243 event
.xexpose
.x
, event
.xexpose
.y
,
10244 event
.xexpose
.width
, event
.xexpose
.height
);
10248 #ifndef USE_TOOLKIT_SCROLL_BARS
10249 struct scroll_bar
*bar
;
10251 #if defined USE_LUCID
10252 /* Submenus of the Lucid menu bar aren't widgets
10253 themselves, so there's no way to dispatch events
10254 to them. Recognize this case separately. */
10257 = x_window_to_menu_bar (event
.xexpose
.window
);
10259 xlwmenu_redisplay (widget
);
10261 #endif /* USE_LUCID */
10263 #ifdef USE_TOOLKIT_SCROLL_BARS
10264 /* Dispatch event to the widget. */
10266 #else /* not USE_TOOLKIT_SCROLL_BARS */
10267 bar
= x_window_to_scroll_bar (event
.xexpose
.window
);
10270 x_scroll_bar_expose (bar
, &event
);
10271 #ifdef USE_X_TOOLKIT
10274 #endif /* USE_X_TOOLKIT */
10275 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10279 case GraphicsExpose
: /* This occurs when an XCopyArea's
10280 source area was obscured or not
10282 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
10286 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
10287 event
.xgraphicsexpose
.width
,
10288 event
.xgraphicsexpose
.height
);
10290 #ifdef USE_X_TOOLKIT
10293 #endif /* USE_X_TOOLKIT */
10296 case NoExpose
: /* This occurs when an XCopyArea's
10297 source area was completely
10302 /* Redo the mouse-highlight after the tooltip has gone. */
10303 if (event
.xmap
.window
== tip_window
)
10306 redo_mouse_highlight ();
10309 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
10310 if (f
) /* F may no longer exist if
10311 the frame was deleted. */
10313 /* While a frame is unmapped, display generation is
10314 disabled; you don't want to spend time updating a
10315 display that won't ever be seen. */
10316 f
->async_visible
= 0;
10317 /* We can't distinguish, from the event, whether the window
10318 has become iconified or invisible. So assume, if it
10319 was previously visible, than now it is iconified.
10320 But x_make_frame_invisible clears both
10321 the visible flag and the iconified flag;
10322 and that way, we know the window is not iconified now. */
10323 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
10325 f
->async_iconified
= 1;
10327 bufp
->kind
= iconify_event
;
10328 XSETFRAME (bufp
->frame_or_window
, f
);
10338 if (event
.xmap
.window
== tip_window
)
10339 /* The tooltip has been drawn already. Avoid
10340 the SET_FRAME_GARBAGED below. */
10343 /* We use x_top_window_to_frame because map events can
10344 come for sub-windows and they don't mean that the
10345 frame is visible. */
10346 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
10349 f
->async_visible
= 1;
10350 f
->async_iconified
= 0;
10351 f
->output_data
.x
->has_been_visible
= 1;
10353 /* wait_reading_process_input will notice this and update
10354 the frame's display structures. */
10355 SET_FRAME_GARBAGED (f
);
10359 bufp
->kind
= deiconify_event
;
10360 XSETFRAME (bufp
->frame_or_window
, f
);
10366 else if (! NILP (Vframe_list
)
10367 && ! NILP (XCDR (Vframe_list
)))
10368 /* Force a redisplay sooner or later
10369 to update the frame titles
10370 in case this is the second frame. */
10371 record_asynch_buffer_change ();
10376 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
10378 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
10381 /* Scroll bars consume key events, but we want
10382 the keys to go to the scroll bar's frame. */
10383 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
10384 event
.xkey
.window
);
10385 if (widget
&& XmIsScrollBar (widget
))
10387 widget
= XtParent (widget
);
10388 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
10391 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
10395 KeySym keysym
, orig_keysym
;
10396 /* al%imercury@uunet.uu.net says that making this 81
10397 instead of 80 fixed a bug whereby meta chars made
10400 It seems that some version of XmbLookupString has
10401 a bug of not returning XBufferOverflow in
10402 status_return even if the input is too long to
10403 fit in 81 bytes. So, we must prepare sufficient
10404 bytes for copy_buffer. 513 bytes (256 chars for
10405 two-byte character set) seems to be a faily good
10406 approximation. -- 2000.8.10 handa@etl.go.jp */
10407 unsigned char copy_buffer
[513];
10408 unsigned char *copy_bufptr
= copy_buffer
;
10409 int copy_bufsiz
= sizeof (copy_buffer
);
10413 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
10414 extra_keyboard_modifiers
);
10415 modifiers
= event
.xkey
.state
;
10417 /* This will have to go some day... */
10419 /* make_lispy_event turns chars into control chars.
10420 Don't do it here because XLookupString is too eager. */
10421 event
.xkey
.state
&= ~ControlMask
;
10422 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
10423 | dpyinfo
->super_mod_mask
10424 | dpyinfo
->hyper_mod_mask
10425 | dpyinfo
->alt_mod_mask
);
10427 /* In case Meta is ComposeCharacter,
10428 clear its status. According to Markus Ehrnsperger
10429 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
10430 this enables ComposeCharacter to work whether or
10431 not it is combined with Meta. */
10432 if (modifiers
& dpyinfo
->meta_mod_mask
)
10433 bzero (&compose_status
, sizeof (compose_status
));
10438 Status status_return
;
10440 nbytes
= XmbLookupString (FRAME_XIC (f
),
10441 &event
.xkey
, copy_bufptr
,
10442 copy_bufsiz
, &keysym
,
10444 if (status_return
== XBufferOverflow
)
10446 copy_bufsiz
= nbytes
+ 1;
10447 copy_bufptr
= (char *) alloca (copy_bufsiz
);
10448 nbytes
= XmbLookupString (FRAME_XIC (f
),
10449 &event
.xkey
, copy_bufptr
,
10450 copy_bufsiz
, &keysym
,
10454 if (status_return
== XLookupNone
)
10456 else if (status_return
== XLookupChars
)
10461 else if (status_return
!= XLookupKeySym
10462 && status_return
!= XLookupBoth
)
10466 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
10467 copy_bufsiz
, &keysym
,
10470 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
10471 copy_bufsiz
, &keysym
,
10475 orig_keysym
= keysym
;
10479 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
10480 || keysym
== XK_Delete
10481 #ifdef XK_ISO_Left_Tab
10482 || (keysym
>= XK_ISO_Left_Tab
&& keysym
<= XK_ISO_Enter
)
10484 || (keysym
>= XK_Kanji
&& keysym
<= XK_Eisu_toggle
)
10485 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
10486 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
10488 /* This recognizes the "extended function keys".
10489 It seems there's no cleaner way.
10490 Test IsModifierKey to avoid handling mode_switch
10492 || ((unsigned) (keysym
) >= XK_Select
10493 && (unsigned)(keysym
) < XK_KP_Space
)
10495 #ifdef XK_dead_circumflex
10496 || orig_keysym
== XK_dead_circumflex
10498 #ifdef XK_dead_grave
10499 || orig_keysym
== XK_dead_grave
10501 #ifdef XK_dead_tilde
10502 || orig_keysym
== XK_dead_tilde
10504 #ifdef XK_dead_diaeresis
10505 || orig_keysym
== XK_dead_diaeresis
10507 #ifdef XK_dead_macron
10508 || orig_keysym
== XK_dead_macron
10510 #ifdef XK_dead_degree
10511 || orig_keysym
== XK_dead_degree
10513 #ifdef XK_dead_acute
10514 || orig_keysym
== XK_dead_acute
10516 #ifdef XK_dead_cedilla
10517 || orig_keysym
== XK_dead_cedilla
10519 #ifdef XK_dead_breve
10520 || orig_keysym
== XK_dead_breve
10522 #ifdef XK_dead_ogonek
10523 || orig_keysym
== XK_dead_ogonek
10525 #ifdef XK_dead_caron
10526 || orig_keysym
== XK_dead_caron
10528 #ifdef XK_dead_doubleacute
10529 || orig_keysym
== XK_dead_doubleacute
10531 #ifdef XK_dead_abovedot
10532 || orig_keysym
== XK_dead_abovedot
10534 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
10535 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
10536 /* Any "vendor-specific" key is ok. */
10537 || (orig_keysym
& (1 << 28))
10538 || (keysym
!= NoSymbol
&& nbytes
== 0))
10539 && ! (IsModifierKey (orig_keysym
)
10541 #ifdef XK_Mode_switch
10542 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
10545 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
10547 #endif /* not HAVE_X11R5 */
10550 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
10552 temp_buffer
[temp_index
++] = keysym
;
10553 bufp
->kind
= non_ascii_keystroke
;
10554 bufp
->code
= keysym
;
10555 XSETFRAME (bufp
->frame_or_window
, f
);
10558 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10560 bufp
->timestamp
= event
.xkey
.time
;
10565 else if (numchars
> nbytes
)
10571 for (i
= 0; i
< nbytes
; i
++)
10573 if (temp_index
== (sizeof temp_buffer
10576 temp_buffer
[temp_index
++] = copy_bufptr
[i
];
10579 if (/* If the event is not from XIM, */
10580 event
.xkey
.keycode
!= 0
10581 /* or the current locale doesn't request
10582 decoding of the intup data, ... */
10583 || coding
.type
== coding_type_raw_text
10584 || coding
.type
== coding_type_no_conversion
)
10586 /* ... we can use the input data as is. */
10591 /* We have to decode the input data. */
10595 require
= decoding_buffer_size (&coding
, nbytes
);
10596 p
= (unsigned char *) alloca (require
);
10597 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
10598 decode_coding (&coding
, copy_bufptr
, p
,
10600 nbytes
= coding
.produced
;
10601 nchars
= coding
.produced_char
;
10605 /* Convert the input data to a sequence of
10606 character events. */
10607 for (i
= 0; i
< nbytes
; i
+= len
)
10609 if (nchars
== nbytes
)
10610 c
= copy_bufptr
[i
], len
= 1;
10612 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
10615 bufp
->kind
= (SINGLE_BYTE_CHAR_P (c
)
10617 : multibyte_char_keystroke
);
10619 XSETFRAME (bufp
->frame_or_window
, f
);
10622 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10624 bufp
->timestamp
= event
.xkey
.time
;
10629 numchars
-= nchars
;
10631 if (keysym
== NoSymbol
)
10641 /* Don't dispatch this event since XtDispatchEvent calls
10642 XFilterEvent, and two calls in a row may freeze the
10651 /* Don't dispatch this event since XtDispatchEvent calls
10652 XFilterEvent, and two calls in a row may freeze the
10659 /* Here's a possible interpretation of the whole
10660 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If
10661 you get a FocusIn event, you have to get a FocusOut
10662 event before you relinquish the focus. If you
10663 haven't received a FocusIn event, then a mere
10664 LeaveNotify is enough to free you. */
10668 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10671 if (event
.xcrossing
.focus
)
10673 /* Avoid nasty pop/raise loops. */
10674 if (f
&& (!(f
->auto_raise
)
10675 || !(f
->auto_lower
)
10676 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
10678 x_new_focus_frame (dpyinfo
, f
);
10679 enter_timestamp
= event
.xcrossing
.time
;
10682 else if (f
== dpyinfo
->x_focus_frame
)
10683 x_new_focus_frame (dpyinfo
, 0);
10686 /* EnterNotify counts as mouse movement,
10687 so update things that depend on mouse position. */
10688 if (f
&& !f
->output_data
.x
->hourglass_p
)
10689 note_mouse_movement (f
, &event
.xmotion
);
10694 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
10695 if (event
.xfocus
.detail
!= NotifyPointer
)
10696 dpyinfo
->x_focus_event_frame
= f
;
10699 x_new_focus_frame (dpyinfo
, f
);
10701 /* Don't stop displaying the initial startup message
10702 for a switch-frame event we don't need. */
10703 if (GC_NILP (Vterminal_frame
)
10704 && GC_CONSP (Vframe_list
)
10705 && !GC_NILP (XCDR (Vframe_list
)))
10707 bufp
->kind
= FOCUS_IN_EVENT
;
10708 XSETFRAME (bufp
->frame_or_window
, f
);
10710 ++bufp
, ++count
, --numchars
;
10715 if (f
&& FRAME_XIC (f
))
10716 XSetICFocus (FRAME_XIC (f
));
10722 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10725 if (f
== dpyinfo
->mouse_face_mouse_frame
)
10727 /* If we move outside the frame, then we're
10728 certainly no longer on any text in the frame. */
10729 clear_mouse_face (dpyinfo
);
10730 dpyinfo
->mouse_face_mouse_frame
= 0;
10733 /* Generate a nil HELP_EVENT to cancel a help-echo.
10734 Do it only if there's something to cancel.
10735 Otherwise, the startup message is cleared when
10736 the mouse leaves the frame. */
10737 if (any_help_event_p
)
10742 XSETFRAME (frame
, f
);
10744 n
= gen_help_event (bufp
, numchars
,
10745 Qnil
, frame
, Qnil
, Qnil
, 0);
10746 bufp
+= n
, count
+= n
, numchars
-= n
;
10750 if (event
.xcrossing
.focus
)
10751 x_mouse_leave (dpyinfo
);
10754 if (f
== dpyinfo
->x_focus_event_frame
)
10755 dpyinfo
->x_focus_event_frame
= 0;
10756 if (f
== dpyinfo
->x_focus_frame
)
10757 x_new_focus_frame (dpyinfo
, 0);
10764 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
10765 if (event
.xfocus
.detail
!= NotifyPointer
10766 && f
== dpyinfo
->x_focus_event_frame
)
10767 dpyinfo
->x_focus_event_frame
= 0;
10768 if (f
&& f
== dpyinfo
->x_focus_frame
)
10769 x_new_focus_frame (dpyinfo
, 0);
10772 if (f
&& FRAME_XIC (f
))
10773 XUnsetICFocus (FRAME_XIC (f
));
10780 previous_help_echo
= help_echo
;
10781 help_echo
= help_echo_object
= help_echo_window
= Qnil
;
10782 help_echo_pos
= -1;
10784 if (dpyinfo
->grabbed
&& last_mouse_frame
10785 && FRAME_LIVE_P (last_mouse_frame
))
10786 f
= last_mouse_frame
;
10788 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
10791 note_mouse_movement (f
, &event
.xmotion
);
10794 #ifndef USE_TOOLKIT_SCROLL_BARS
10795 struct scroll_bar
*bar
10796 = x_window_to_scroll_bar (event
.xmotion
.window
);
10799 x_scroll_bar_note_movement (bar
, &event
);
10800 #endif /* USE_TOOLKIT_SCROLL_BARS */
10802 /* If we move outside the frame, then we're
10803 certainly no longer on any text in the frame. */
10804 clear_mouse_face (dpyinfo
);
10807 /* If the contents of the global variable help_echo
10808 has changed, generate a HELP_EVENT. */
10809 if (!NILP (help_echo
)
10810 || !NILP (previous_help_echo
))
10816 XSETFRAME (frame
, f
);
10820 any_help_event_p
= 1;
10821 n
= gen_help_event (bufp
, numchars
, help_echo
, frame
,
10822 help_echo_window
, help_echo_object
,
10824 bufp
+= n
, count
+= n
, numchars
-= n
;
10830 case ConfigureNotify
:
10831 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
10834 #ifndef USE_X_TOOLKIT
10835 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
10836 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
10838 /* In the toolkit version, change_frame_size
10839 is called by the code that handles resizing
10840 of the EmacsFrame widget. */
10842 /* Even if the number of character rows and columns has
10843 not changed, the font size may have changed, so we need
10844 to check the pixel dimensions as well. */
10845 if (columns
!= f
->width
10846 || rows
!= f
->height
10847 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
10848 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
10850 change_frame_size (f
, rows
, columns
, 0, 1, 0);
10851 SET_FRAME_GARBAGED (f
);
10852 cancel_mouse_face (f
);
10856 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
10857 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
10859 /* What we have now is the position of Emacs's own window.
10860 Convert that to the position of the window manager window. */
10861 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
10862 &f
->output_data
.x
->top_pos
);
10865 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
10866 xic_set_statusarea (f
);
10869 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
10871 /* Since the WM decorations come below top_pos now,
10872 we must put them below top_pos in the future. */
10873 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
10874 x_wm_set_size_hint (f
, (long) 0, 0);
10877 /* Some window managers pass (0,0) as the location of
10878 the window, and the Motif event handler stores it
10879 in the emacs widget, which messes up Motif menus. */
10880 if (event
.xconfigure
.x
== 0 && event
.xconfigure
.y
== 0)
10882 event
.xconfigure
.x
= f
->output_data
.x
->widget
->core
.x
;
10883 event
.xconfigure
.y
= f
->output_data
.x
->widget
->core
.y
;
10885 #endif /* USE_MOTIF */
10890 case ButtonRelease
:
10892 /* If we decide we want to generate an event to be seen
10893 by the rest of Emacs, we put it here. */
10894 struct input_event emacs_event
;
10895 int tool_bar_p
= 0;
10897 emacs_event
.kind
= no_event
;
10898 bzero (&compose_status
, sizeof (compose_status
));
10900 if (dpyinfo
->grabbed
10901 && last_mouse_frame
10902 && FRAME_LIVE_P (last_mouse_frame
))
10903 f
= last_mouse_frame
;
10905 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
10909 /* Is this in the tool-bar? */
10910 if (WINDOWP (f
->tool_bar_window
)
10911 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
10913 Lisp_Object window
;
10916 x
= event
.xbutton
.x
;
10917 y
= event
.xbutton
.y
;
10920 window
= window_from_coordinates (f
, x
, y
, &p
, 1);
10921 if (EQ (window
, f
->tool_bar_window
))
10923 x_handle_tool_bar_click (f
, &event
.xbutton
);
10929 if (!dpyinfo
->x_focus_frame
10930 || f
== dpyinfo
->x_focus_frame
)
10931 construct_mouse_click (&emacs_event
, &event
, f
);
10935 #ifndef USE_TOOLKIT_SCROLL_BARS
10936 struct scroll_bar
*bar
10937 = x_window_to_scroll_bar (event
.xbutton
.window
);
10940 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
10941 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10944 if (event
.type
== ButtonPress
)
10946 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
10947 last_mouse_frame
= f
;
10948 /* Ignore any mouse motion that happened
10949 before this event; any subsequent mouse-movement
10950 Emacs events should reflect only motion after
10951 the ButtonPress. */
10953 f
->mouse_moved
= 0;
10956 last_tool_bar_item
= -1;
10960 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
10963 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
10965 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
10971 #ifdef USE_X_TOOLKIT
10972 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
10973 /* For a down-event in the menu bar,
10974 don't pass it to Xt right now.
10975 Instead, save it away
10976 and we will pass it to Xt from kbd_buffer_get_event.
10977 That way, we can run some Lisp code first. */
10978 if (f
&& event
.type
== ButtonPress
10979 /* Verify the event is really within the menu bar
10980 and not just sent to it due to grabbing. */
10981 && event
.xbutton
.x
>= 0
10982 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
10983 && event
.xbutton
.y
>= 0
10984 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
10985 && event
.xbutton
.same_screen
)
10987 SET_SAVED_BUTTON_EVENT
;
10988 XSETFRAME (last_mouse_press_frame
, f
);
10990 else if (event
.type
== ButtonPress
)
10992 last_mouse_press_frame
= Qnil
;
10996 #ifdef USE_MOTIF /* This should do not harm for Lucid,
10997 but I am trying to be cautious. */
10998 else if (event
.type
== ButtonRelease
)
11000 if (!NILP (last_mouse_press_frame
))
11002 f
= XFRAME (last_mouse_press_frame
);
11003 if (f
->output_data
.x
)
11004 SET_SAVED_BUTTON_EVENT
;
11009 #endif /* USE_MOTIF */
11012 #endif /* USE_X_TOOLKIT */
11016 case CirculateNotify
:
11019 case CirculateRequest
:
11022 case VisibilityNotify
:
11025 case MappingNotify
:
11026 /* Someone has changed the keyboard mapping - update the
11028 switch (event
.xmapping
.request
)
11030 case MappingModifier
:
11031 x_find_modifier_meanings (dpyinfo
);
11032 /* This is meant to fall through. */
11033 case MappingKeyboard
:
11034 XRefreshKeyboardMapping (&event
.xmapping
);
11040 #ifdef USE_X_TOOLKIT
11042 XtDispatchEvent (&event
);
11044 #endif /* USE_X_TOOLKIT */
11052 /* On some systems, an X bug causes Emacs to get no more events
11053 when the window is destroyed. Detect that. (1994.) */
11056 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
11057 One XNOOP in 100 loops will make Emacs terminate.
11058 B. Bretthauer, 1994 */
11060 if (x_noop_count
>= 100)
11064 if (next_noop_dpyinfo
== 0)
11065 next_noop_dpyinfo
= x_display_list
;
11067 XNoOp (next_noop_dpyinfo
->display
);
11069 /* Each time we get here, cycle through the displays now open. */
11070 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
11074 /* If the focus was just given to an auto-raising frame,
11076 /* ??? This ought to be able to handle more than one such frame. */
11077 if (pending_autoraise_frame
)
11079 x_raise_frame (pending_autoraise_frame
);
11080 pending_autoraise_frame
= 0;
11091 /***********************************************************************
11093 ***********************************************************************/
11095 /* Notice if the text cursor of window W has been overwritten by a
11096 drawing operation that outputs N glyphs starting at START_X and
11097 ending at END_X in the line given by output_cursor.vpos.
11098 Coordinates are area-relative. END_X < 0 means all the rest
11099 of the line after START_X has been written. */
11102 notice_overwritten_cursor (w
, start_x
, end_x
)
11104 int start_x
, end_x
;
11106 if (updated_area
== TEXT_AREA
11107 && w
->phys_cursor_on_p
11108 && output_cursor
.vpos
== w
->phys_cursor
.vpos
11109 && start_x
<= w
->phys_cursor
.x
11110 && (end_x
< 0 || end_x
> w
->phys_cursor
.x
))
11111 w
->phys_cursor_on_p
= 0;
11115 /* Set clipping for output in glyph row ROW. W is the window in which
11116 we operate. GC is the graphics context to set clipping in.
11117 WHOLE_LINE_P non-zero means include the areas used for truncation
11118 mark display and alike in the clipping rectangle.
11120 ROW may be a text row or, e.g., a mode line. Text rows must be
11121 clipped to the interior of the window dedicated to text display,
11122 mode lines must be clipped to the whole window. */
11125 x_clip_to_row (w
, row
, gc
, whole_line_p
)
11127 struct glyph_row
*row
;
11131 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11132 XRectangle clip_rect
;
11133 int window_x
, window_y
, window_width
, window_height
;
11135 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
11137 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
11138 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
11139 clip_rect
.y
= max (clip_rect
.y
, window_y
);
11140 clip_rect
.width
= window_width
;
11141 clip_rect
.height
= row
->visible_height
;
11143 /* If clipping to the whole line, including trunc marks, extend
11144 the rectangle to the left and increase its width. */
11147 clip_rect
.x
-= FRAME_X_LEFT_FRINGE_WIDTH (f
);
11148 clip_rect
.width
+= FRAME_X_FRINGE_WIDTH (f
);
11151 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
11155 /* Draw a hollow box cursor on window W in glyph row ROW. */
11158 x_draw_hollow_cursor (w
, row
)
11160 struct glyph_row
*row
;
11162 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11163 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11164 Display
*dpy
= FRAME_X_DISPLAY (f
);
11167 struct glyph
*cursor_glyph
;
11170 /* Compute frame-relative coordinates from window-relative
11172 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
11173 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
11174 + row
->ascent
- w
->phys_cursor_ascent
);
11175 h
= row
->height
- 1;
11177 /* Get the glyph the cursor is on. If we can't tell because
11178 the current matrix is invalid or such, give up. */
11179 cursor_glyph
= get_phys_cursor_glyph (w
);
11180 if (cursor_glyph
== NULL
)
11183 /* Compute the width of the rectangle to draw. If on a stretch
11184 glyph, and `x-stretch-block-cursor' is nil, don't draw a
11185 rectangle as wide as the glyph, but use a canonical character
11187 wd
= cursor_glyph
->pixel_width
- 1;
11188 if (cursor_glyph
->type
== STRETCH_GLYPH
11189 && !x_stretch_cursor_p
)
11190 wd
= min (CANON_X_UNIT (f
), wd
);
11192 /* The foreground of cursor_gc is typically the same as the normal
11193 background color, which can cause the cursor box to be invisible. */
11194 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
11195 if (dpyinfo
->scratch_cursor_gc
)
11196 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
11198 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
11199 GCForeground
, &xgcv
);
11200 gc
= dpyinfo
->scratch_cursor_gc
;
11202 /* Set clipping, draw the rectangle, and reset clipping again. */
11203 x_clip_to_row (w
, row
, gc
, 0);
11204 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
11205 XSetClipMask (dpy
, gc
, None
);
11209 /* Draw a bar cursor on window W in glyph row ROW.
11211 Implementation note: One would like to draw a bar cursor with an
11212 angle equal to the one given by the font property XA_ITALIC_ANGLE.
11213 Unfortunately, I didn't find a font yet that has this property set.
11217 x_draw_bar_cursor (w
, row
, width
)
11219 struct glyph_row
*row
;
11222 struct frame
*f
= XFRAME (w
->frame
);
11223 struct glyph
*cursor_glyph
;
11225 /* If cursor is out of bounds, don't draw garbage. This can happen
11226 in mini-buffer windows when switching between echo area glyphs
11227 and mini-buffer. */
11228 cursor_glyph
= get_phys_cursor_glyph (w
);
11229 if (cursor_glyph
== NULL
)
11232 /* If on an image, draw like a normal cursor. That's usually better
11233 visible than drawing a bar, esp. if the image is large so that
11234 the bar might not be in the window. */
11235 if (cursor_glyph
->type
== IMAGE_GLYPH
)
11237 struct glyph_row
*row
;
11238 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
11239 x_draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
11243 Display
*dpy
= FRAME_X_DISPLAY (f
);
11244 Window window
= FRAME_X_WINDOW (f
);
11245 GC gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
11246 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
11247 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
11250 /* If the glyph's background equals the color we normally draw
11251 the bar cursor in, the bar cursor in its normal color is
11252 invisible. Use the glyph's foreground color instead in this
11253 case, on the assumption that the glyph's colors are chosen so
11254 that the glyph is legible. */
11255 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
11256 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
11258 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
11259 xgcv
.graphics_exposures
= 0;
11262 XChangeGC (dpy
, gc
, mask
, &xgcv
);
11265 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
11266 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
11270 width
= f
->output_data
.x
->cursor_width
;
11271 width
= min (cursor_glyph
->pixel_width
, width
);
11273 x_clip_to_row (w
, row
, gc
, 0);
11274 XFillRectangle (dpy
, window
, gc
,
11275 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
11276 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
11277 width
, row
->height
);
11278 XSetClipMask (dpy
, gc
, None
);
11283 /* Clear the cursor of window W to background color, and mark the
11284 cursor as not shown. This is used when the text where the cursor
11285 is is about to be rewritten. */
11291 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
11292 x_update_window_cursor (w
, 0);
11296 /* Draw the cursor glyph of window W in glyph row ROW. See the
11297 comment of x_draw_glyphs for the meaning of HL. */
11300 x_draw_phys_cursor_glyph (w
, row
, hl
)
11302 struct glyph_row
*row
;
11303 enum draw_glyphs_face hl
;
11305 /* If cursor hpos is out of bounds, don't draw garbage. This can
11306 happen in mini-buffer windows when switching between echo area
11307 glyphs and mini-buffer. */
11308 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
11310 int on_p
= w
->phys_cursor_on_p
;
11312 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
11313 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
11315 w
->phys_cursor_on_p
= on_p
;
11317 /* When we erase the cursor, and ROW is overlapped by other
11318 rows, make sure that these overlapping parts of other rows
11320 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
11322 if (row
> w
->current_matrix
->rows
11323 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
11324 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
11326 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
11327 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
11328 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
11334 /* Erase the image of a cursor of window W from the screen. */
11337 x_erase_phys_cursor (w
)
11340 struct frame
*f
= XFRAME (w
->frame
);
11341 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
11342 int hpos
= w
->phys_cursor
.hpos
;
11343 int vpos
= w
->phys_cursor
.vpos
;
11344 int mouse_face_here_p
= 0;
11345 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
11346 struct glyph_row
*cursor_row
;
11347 struct glyph
*cursor_glyph
;
11348 enum draw_glyphs_face hl
;
11350 /* No cursor displayed or row invalidated => nothing to do on the
11352 if (w
->phys_cursor_type
== NO_CURSOR
)
11353 goto mark_cursor_off
;
11355 /* VPOS >= active_glyphs->nrows means that window has been resized.
11356 Don't bother to erase the cursor. */
11357 if (vpos
>= active_glyphs
->nrows
)
11358 goto mark_cursor_off
;
11360 /* If row containing cursor is marked invalid, there is nothing we
11362 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
11363 if (!cursor_row
->enabled_p
)
11364 goto mark_cursor_off
;
11366 /* This can happen when the new row is shorter than the old one.
11367 In this case, either x_draw_glyphs or clear_end_of_line
11368 should have cleared the cursor. Note that we wouldn't be
11369 able to erase the cursor in this case because we don't have a
11370 cursor glyph at hand. */
11371 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
11372 goto mark_cursor_off
;
11374 /* If the cursor is in the mouse face area, redisplay that when
11375 we clear the cursor. */
11376 if (! NILP (dpyinfo
->mouse_face_window
)
11377 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
11378 && (vpos
> dpyinfo
->mouse_face_beg_row
11379 || (vpos
== dpyinfo
->mouse_face_beg_row
11380 && hpos
>= dpyinfo
->mouse_face_beg_col
))
11381 && (vpos
< dpyinfo
->mouse_face_end_row
11382 || (vpos
== dpyinfo
->mouse_face_end_row
11383 && hpos
< dpyinfo
->mouse_face_end_col
))
11384 /* Don't redraw the cursor's spot in mouse face if it is at the
11385 end of a line (on a newline). The cursor appears there, but
11386 mouse highlighting does not. */
11387 && cursor_row
->used
[TEXT_AREA
] > hpos
)
11388 mouse_face_here_p
= 1;
11390 /* Maybe clear the display under the cursor. */
11391 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
11394 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
11396 cursor_glyph
= get_phys_cursor_glyph (w
);
11397 if (cursor_glyph
== NULL
)
11398 goto mark_cursor_off
;
11400 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
11402 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11404 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
11406 cursor_glyph
->pixel_width
,
11407 cursor_row
->visible_height
,
11411 /* Erase the cursor by redrawing the character underneath it. */
11412 if (mouse_face_here_p
)
11413 hl
= DRAW_MOUSE_FACE
;
11415 hl
= DRAW_NORMAL_TEXT
;
11416 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
11419 w
->phys_cursor_on_p
= 0;
11420 w
->phys_cursor_type
= NO_CURSOR
;
11424 /* Non-zero if physical cursor of window W is within mouse face. */
11427 cursor_in_mouse_face_p (w
)
11430 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
11431 int in_mouse_face
= 0;
11433 if (WINDOWP (dpyinfo
->mouse_face_window
)
11434 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
11436 int hpos
= w
->phys_cursor
.hpos
;
11437 int vpos
= w
->phys_cursor
.vpos
;
11439 if (vpos
>= dpyinfo
->mouse_face_beg_row
11440 && vpos
<= dpyinfo
->mouse_face_end_row
11441 && (vpos
> dpyinfo
->mouse_face_beg_row
11442 || hpos
>= dpyinfo
->mouse_face_beg_col
)
11443 && (vpos
< dpyinfo
->mouse_face_end_row
11444 || hpos
< dpyinfo
->mouse_face_end_col
11445 || dpyinfo
->mouse_face_past_end
))
11449 return in_mouse_face
;
11453 /* Display or clear cursor of window W. If ON is zero, clear the
11454 cursor. If it is non-zero, display the cursor. If ON is nonzero,
11455 where to put the cursor is specified by HPOS, VPOS, X and Y. */
11458 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
11460 int on
, hpos
, vpos
, x
, y
;
11462 struct frame
*f
= XFRAME (w
->frame
);
11463 int new_cursor_type
;
11464 int new_cursor_width
;
11465 struct glyph_matrix
*current_glyphs
;
11466 struct glyph_row
*glyph_row
;
11467 struct glyph
*glyph
;
11468 int cursor_non_selected
;
11470 /* This is pointless on invisible frames, and dangerous on garbaged
11471 windows and frames; in the latter case, the frame or window may
11472 be in the midst of changing its size, and x and y may be off the
11474 if (! FRAME_VISIBLE_P (f
)
11475 || FRAME_GARBAGED_P (f
)
11476 || vpos
>= w
->current_matrix
->nrows
11477 || hpos
>= w
->current_matrix
->matrix_w
)
11480 /* If cursor is off and we want it off, return quickly. */
11481 if (!on
&& !w
->phys_cursor_on_p
)
11484 current_glyphs
= w
->current_matrix
;
11485 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
11486 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
11488 /* If cursor row is not enabled, we don't really know where to
11489 display the cursor. */
11490 if (!glyph_row
->enabled_p
)
11492 w
->phys_cursor_on_p
= 0;
11496 xassert (interrupt_input_blocked
);
11498 /* Set new_cursor_type to the cursor we want to be displayed. In a
11499 mini-buffer window, we want the cursor only to appear if we are
11500 reading input from this window. For the selected window, we want
11501 the cursor type given by the frame parameter. If explicitly
11502 marked off, draw no cursor. In all other cases, we want a hollow
11504 cursor_non_selected
11505 = !NILP (Fbuffer_local_value (Qcursor_in_non_selected_windows
,
11507 new_cursor_width
= -1;
11508 if (cursor_in_echo_area
11509 && FRAME_HAS_MINIBUF_P (f
)
11510 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
11512 if (w
== XWINDOW (echo_area_window
))
11513 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
11514 else if (cursor_non_selected
)
11515 new_cursor_type
= HOLLOW_BOX_CURSOR
;
11517 new_cursor_type
= NO_CURSOR
;
11521 if (f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
11522 || w
!= XWINDOW (f
->selected_window
))
11524 if ((MINI_WINDOW_P (w
) && minibuf_level
== 0)
11525 || !cursor_non_selected
11526 || NILP (XBUFFER (w
->buffer
)->cursor_type
))
11527 new_cursor_type
= NO_CURSOR
;
11529 new_cursor_type
= HOLLOW_BOX_CURSOR
;
11531 else if (w
->cursor_off_p
)
11532 new_cursor_type
= NO_CURSOR
;
11535 struct buffer
*b
= XBUFFER (w
->buffer
);
11537 if (EQ (b
->cursor_type
, Qt
))
11538 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
11540 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
11541 &new_cursor_width
);
11545 /* If cursor is currently being shown and we don't want it to be or
11546 it is in the wrong place, or the cursor type is not what we want,
11548 if (w
->phys_cursor_on_p
11550 || w
->phys_cursor
.x
!= x
11551 || w
->phys_cursor
.y
!= y
11552 || new_cursor_type
!= w
->phys_cursor_type
))
11553 x_erase_phys_cursor (w
);
11555 /* If the cursor is now invisible and we want it to be visible,
11557 if (on
&& !w
->phys_cursor_on_p
)
11559 w
->phys_cursor_ascent
= glyph_row
->ascent
;
11560 w
->phys_cursor_height
= glyph_row
->height
;
11562 /* Set phys_cursor_.* before x_draw_.* is called because some
11563 of them may need the information. */
11564 w
->phys_cursor
.x
= x
;
11565 w
->phys_cursor
.y
= glyph_row
->y
;
11566 w
->phys_cursor
.hpos
= hpos
;
11567 w
->phys_cursor
.vpos
= vpos
;
11568 w
->phys_cursor_type
= new_cursor_type
;
11569 w
->phys_cursor_on_p
= 1;
11571 switch (new_cursor_type
)
11573 case HOLLOW_BOX_CURSOR
:
11574 x_draw_hollow_cursor (w
, glyph_row
);
11577 case FILLED_BOX_CURSOR
:
11578 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
11582 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
);
11593 if (w
== XWINDOW (f
->selected_window
))
11594 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
11595 xic_set_preeditarea (w
, x
, y
);
11600 if (updating_frame
!= f
)
11601 XFlush (FRAME_X_DISPLAY (f
));
11606 /* Display the cursor on window W, or clear it. X and Y are window
11607 relative pixel coordinates. HPOS and VPOS are glyph matrix
11608 positions. If W is not the selected window, display a hollow
11609 cursor. ON non-zero means display the cursor at X, Y which
11610 correspond to HPOS, VPOS, otherwise it is cleared. */
11613 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
11615 int on
, hpos
, vpos
, x
, y
;
11618 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
11623 /* Display the cursor on window W, or clear it, according to ON_P.
11624 Don't change the cursor's position. */
11627 x_update_cursor (f
, on_p
)
11630 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
11634 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
11635 in the window tree rooted at W. */
11638 x_update_cursor_in_window_tree (w
, on_p
)
11644 if (!NILP (w
->hchild
))
11645 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
11646 else if (!NILP (w
->vchild
))
11647 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
11649 x_update_window_cursor (w
, on_p
);
11651 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
11656 /* Switch the display of W's cursor on or off, according to the value
11660 x_update_window_cursor (w
, on
)
11664 /* Don't update cursor in windows whose frame is in the process
11665 of being deleted. */
11666 if (w
->current_matrix
)
11669 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
11670 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
11680 /* Make the x-window of frame F use the gnu icon bitmap. */
11683 x_bitmap_icon (f
, file
)
11689 if (FRAME_X_WINDOW (f
) == 0)
11692 /* Free up our existing icon bitmap if any. */
11693 if (f
->output_data
.x
->icon_bitmap
> 0)
11694 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
11695 f
->output_data
.x
->icon_bitmap
= 0;
11697 if (STRINGP (file
))
11698 bitmap_id
= x_create_bitmap_from_file (f
, file
);
11701 /* Create the GNU bitmap if necessary. */
11702 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
11703 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
11704 = x_create_bitmap_from_data (f
, gnu_bits
,
11705 gnu_width
, gnu_height
);
11707 /* The first time we create the GNU bitmap,
11708 this increments the ref-count one extra time.
11709 As a result, the GNU bitmap is never freed.
11710 That way, we don't have to worry about allocating it again. */
11711 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
11713 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
11716 x_wm_set_icon_pixmap (f
, bitmap_id
);
11717 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
11723 /* Make the x-window of frame F use a rectangle with text.
11724 Use ICON_NAME as the text. */
11727 x_text_icon (f
, icon_name
)
11731 if (FRAME_X_WINDOW (f
) == 0)
11736 XTextProperty text
;
11737 text
.value
= (unsigned char *) icon_name
;
11738 text
.encoding
= XA_STRING
;
11740 text
.nitems
= strlen (icon_name
);
11741 #ifdef USE_X_TOOLKIT
11742 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
11744 #else /* not USE_X_TOOLKIT */
11745 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
11746 #endif /* not USE_X_TOOLKIT */
11748 #else /* not HAVE_X11R4 */
11749 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
11750 #endif /* not HAVE_X11R4 */
11752 if (f
->output_data
.x
->icon_bitmap
> 0)
11753 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
11754 f
->output_data
.x
->icon_bitmap
= 0;
11755 x_wm_set_icon_pixmap (f
, 0);
11760 #define X_ERROR_MESSAGE_SIZE 200
11762 /* If non-nil, this should be a string.
11763 It means catch X errors and store the error message in this string. */
11765 static Lisp_Object x_error_message_string
;
11767 /* An X error handler which stores the error message in
11768 x_error_message_string. This is called from x_error_handler if
11769 x_catch_errors is in effect. */
11772 x_error_catcher (display
, error
)
11774 XErrorEvent
*error
;
11776 XGetErrorText (display
, error
->error_code
,
11777 XSTRING (x_error_message_string
)->data
,
11778 X_ERROR_MESSAGE_SIZE
);
11781 /* Begin trapping X errors for display DPY. Actually we trap X errors
11782 for all displays, but DPY should be the display you are actually
11785 After calling this function, X protocol errors no longer cause
11786 Emacs to exit; instead, they are recorded in the string
11787 stored in x_error_message_string.
11789 Calling x_check_errors signals an Emacs error if an X error has
11790 occurred since the last call to x_catch_errors or x_check_errors.
11792 Calling x_uncatch_errors resumes the normal error handling. */
11794 void x_check_errors ();
11795 static Lisp_Object
x_catch_errors_unwind ();
11798 x_catch_errors (dpy
)
11801 int count
= specpdl_ptr
- specpdl
;
11803 /* Make sure any errors from previous requests have been dealt with. */
11804 XSync (dpy
, False
);
11806 record_unwind_protect (x_catch_errors_unwind
, x_error_message_string
);
11808 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
11809 XSTRING (x_error_message_string
)->data
[0] = 0;
11814 /* Unbind the binding that we made to check for X errors. */
11817 x_catch_errors_unwind (old_val
)
11818 Lisp_Object old_val
;
11820 x_error_message_string
= old_val
;
11824 /* If any X protocol errors have arrived since the last call to
11825 x_catch_errors or x_check_errors, signal an Emacs error using
11826 sprintf (a buffer, FORMAT, the x error message text) as the text. */
11829 x_check_errors (dpy
, format
)
11833 /* Make sure to catch any errors incurred so far. */
11834 XSync (dpy
, False
);
11836 if (XSTRING (x_error_message_string
)->data
[0])
11837 error (format
, XSTRING (x_error_message_string
)->data
);
11840 /* Nonzero if we had any X protocol errors
11841 since we did x_catch_errors on DPY. */
11844 x_had_errors_p (dpy
)
11847 /* Make sure to catch any errors incurred so far. */
11848 XSync (dpy
, False
);
11850 return XSTRING (x_error_message_string
)->data
[0] != 0;
11853 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
11856 x_clear_errors (dpy
)
11859 XSTRING (x_error_message_string
)->data
[0] = 0;
11862 /* Stop catching X protocol errors and let them make Emacs die.
11863 DPY should be the display that was passed to x_catch_errors.
11864 COUNT should be the value that was returned by
11865 the corresponding call to x_catch_errors. */
11868 x_uncatch_errors (dpy
, count
)
11872 unbind_to (count
, Qnil
);
11876 static unsigned int x_wire_count
;
11879 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
11884 /* Handle SIGPIPE, which can happen when the connection to a server
11885 simply goes away. SIGPIPE is handled by x_connection_signal.
11886 Don't need to do anything, because the write which caused the
11887 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
11888 which will do the appropriate cleanup for us. */
11891 x_connection_signal (signalnum
) /* If we don't have an argument, */
11892 int signalnum
; /* some compilers complain in signal calls. */
11895 /* USG systems forget handlers when they are used;
11896 must reestablish each time */
11897 signal (signalnum
, x_connection_signal
);
11902 /************************************************************************
11904 ************************************************************************/
11906 /* Error message passed to x_connection_closed. */
11908 static char *error_msg
;
11910 /* Function installed as fatal_error_signal_hook in
11911 x_connection_closed. Print the X error message, and exit normally,
11912 instead of dumping core when XtCloseDisplay fails. */
11915 x_fatal_error_signal ()
11917 fprintf (stderr
, "%s\n", error_msg
);
11921 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
11922 the text of an error message that lead to the connection loss. */
11925 x_connection_closed (dpy
, error_message
)
11927 char *error_message
;
11929 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
11930 Lisp_Object frame
, tail
;
11933 error_msg
= (char *) alloca (strlen (error_message
) + 1);
11934 strcpy (error_msg
, error_message
);
11935 handling_signal
= 0;
11937 /* Prevent being called recursively because of an error condition
11938 below. Otherwise, we might end up with printing ``can't find per
11939 display information'' in the recursive call instead of printing
11940 the original message here. */
11941 count
= x_catch_errors (dpy
);
11943 /* We have to close the display to inform Xt that it doesn't
11944 exist anymore. If we don't, Xt will continue to wait for
11945 events from the display. As a consequence, a sequence of
11947 M-x make-frame-on-display RET :1 RET
11948 ...kill the new frame, so that we get an IO error...
11949 M-x make-frame-on-display RET :1 RET
11951 will indefinitely wait in Xt for events for display `:1', opened
11952 in the first class to make-frame-on-display.
11954 Closing the display is reported to lead to a bus error on
11955 OpenWindows in certain situations. I suspect that is a bug
11956 in OpenWindows. I don't know how to cicumvent it here. */
11958 #ifdef USE_X_TOOLKIT
11959 /* If DPYINFO is null, this means we didn't open the display
11960 in the first place, so don't try to close it. */
11963 extern void (*fatal_error_signal_hook
) P_ ((void));
11964 fatal_error_signal_hook
= x_fatal_error_signal
;
11965 XtCloseDisplay (dpy
);
11966 fatal_error_signal_hook
= NULL
;
11970 /* Indicate that this display is dead. */
11972 dpyinfo
->display
= 0;
11974 /* First delete frames whose mini-buffers are on frames
11975 that are on the dead display. */
11976 FOR_EACH_FRAME (tail
, frame
)
11978 Lisp_Object minibuf_frame
;
11980 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
11981 if (FRAME_X_P (XFRAME (frame
))
11982 && FRAME_X_P (XFRAME (minibuf_frame
))
11983 && ! EQ (frame
, minibuf_frame
)
11984 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
11985 Fdelete_frame (frame
, Qt
);
11988 /* Now delete all remaining frames on the dead display.
11989 We are now sure none of these is used as the mini-buffer
11990 for another frame that we need to delete. */
11991 FOR_EACH_FRAME (tail
, frame
)
11992 if (FRAME_X_P (XFRAME (frame
))
11993 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
11995 /* Set this to t so that Fdelete_frame won't get confused
11996 trying to find a replacement. */
11997 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
11998 Fdelete_frame (frame
, Qt
);
12002 x_delete_display (dpyinfo
);
12004 x_uncatch_errors (dpy
, count
);
12006 if (x_display_list
== 0)
12008 fprintf (stderr
, "%s\n", error_msg
);
12009 shut_down_emacs (0, 0, Qnil
);
12013 /* Ordinary stack unwind doesn't deal with these. */
12015 sigunblock (sigmask (SIGIO
));
12017 sigunblock (sigmask (SIGALRM
));
12018 TOTALLY_UNBLOCK_INPUT
;
12020 clear_waiting_for_input ();
12021 error ("%s", error_msg
);
12025 /* This is the usual handler for X protocol errors.
12026 It kills all frames on the display that we got the error for.
12027 If that was the only one, it prints an error message and kills Emacs. */
12030 x_error_quitter (display
, error
)
12032 XErrorEvent
*error
;
12034 char buf
[256], buf1
[356];
12036 /* Note that there is no real way portable across R3/R4 to get the
12037 original error handler. */
12039 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
12040 sprintf (buf1
, "X protocol error: %s on protocol request %d",
12041 buf
, error
->request_code
);
12042 x_connection_closed (display
, buf1
);
12046 /* This is the first-level handler for X protocol errors.
12047 It calls x_error_quitter or x_error_catcher. */
12050 x_error_handler (display
, error
)
12052 XErrorEvent
*error
;
12054 if (! NILP (x_error_message_string
))
12055 x_error_catcher (display
, error
);
12057 x_error_quitter (display
, error
);
12061 /* This is the handler for X IO errors, always.
12062 It kills all frames on the display that we lost touch with.
12063 If that was the only one, it prints an error message and kills Emacs. */
12066 x_io_error_quitter (display
)
12071 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
12072 x_connection_closed (display
, buf
);
12076 /* Changing the font of the frame. */
12078 /* Give frame F the font named FONTNAME as its default font, and
12079 return the full name of that font. FONTNAME may be a wildcard
12080 pattern; in that case, we choose some font that fits the pattern.
12081 The return value shows which font we chose. */
12084 x_new_font (f
, fontname
)
12086 register char *fontname
;
12088 struct font_info
*fontp
12089 = FS_LOAD_FONT (f
, 0, fontname
, -1);
12094 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
12095 f
->output_data
.x
->baseline_offset
= fontp
->baseline_offset
;
12096 f
->output_data
.x
->fontset
= -1;
12098 /* Compute the scroll bar width in character columns. */
12099 if (f
->scroll_bar_pixel_width
> 0)
12101 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
12102 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
12106 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
12107 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
12110 /* Now make the frame display the given font. */
12111 if (FRAME_X_WINDOW (f
) != 0)
12113 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
12114 f
->output_data
.x
->font
->fid
);
12115 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
12116 f
->output_data
.x
->font
->fid
);
12117 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
12118 f
->output_data
.x
->font
->fid
);
12120 frame_update_line_height (f
);
12122 /* Don't change the size of a tip frame; there's no point in
12123 doing it because it's done in Fx_show_tip, and it leads to
12124 problems because the tip frame has no widget. */
12125 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
12126 x_set_window_size (f
, 0, f
->width
, f
->height
);
12129 /* If we are setting a new frame's font for the first time,
12130 there are no faces yet, so this font's height is the line height. */
12131 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
12133 return build_string (fontp
->full_name
);
12136 /* Give frame F the fontset named FONTSETNAME as its default font, and
12137 return the full name of that fontset. FONTSETNAME may be a wildcard
12138 pattern; in that case, we choose some fontset that fits the pattern.
12139 The return value shows which fontset we chose. */
12142 x_new_fontset (f
, fontsetname
)
12146 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
12147 Lisp_Object result
;
12152 if (f
->output_data
.x
->fontset
== fontset
)
12153 /* This fontset is already set in frame F. There's nothing more
12155 return fontset_name (fontset
);
12157 result
= x_new_font (f
, (XSTRING (fontset_ascii (fontset
))->data
));
12159 if (!STRINGP (result
))
12160 /* Can't load ASCII font. */
12163 /* Since x_new_font doesn't update any fontset information, do it now. */
12164 f
->output_data
.x
->fontset
= fontset
;
12168 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
12169 xic_set_xfontset (f
, XSTRING (fontset_ascii (fontset
))->data
);
12172 return build_string (fontsetname
);
12176 /***********************************************************************
12178 ***********************************************************************/
12184 /* XIM destroy callback function, which is called whenever the
12185 connection to input method XIM dies. CLIENT_DATA contains a
12186 pointer to the x_display_info structure corresponding to XIM. */
12189 xim_destroy_callback (xim
, client_data
, call_data
)
12191 XPointer client_data
;
12192 XPointer call_data
;
12194 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
12195 Lisp_Object frame
, tail
;
12199 /* No need to call XDestroyIC.. */
12200 FOR_EACH_FRAME (tail
, frame
)
12202 struct frame
*f
= XFRAME (frame
);
12203 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
12205 FRAME_XIC (f
) = NULL
;
12206 if (FRAME_XIC_FONTSET (f
))
12208 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
12209 FRAME_XIC_FONTSET (f
) = NULL
;
12214 /* No need to call XCloseIM. */
12215 dpyinfo
->xim
= NULL
;
12216 XFree (dpyinfo
->xim_styles
);
12220 #endif /* HAVE_X11R6 */
12222 /* Open the connection to the XIM server on display DPYINFO.
12223 RESOURCE_NAME is the resource name Emacs uses. */
12226 xim_open_dpy (dpyinfo
, resource_name
)
12227 struct x_display_info
*dpyinfo
;
12228 char *resource_name
;
12233 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
, EMACS_CLASS
);
12234 dpyinfo
->xim
= xim
;
12239 XIMCallback destroy
;
12242 /* Get supported styles and XIM values. */
12243 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
12246 destroy
.callback
= xim_destroy_callback
;
12247 destroy
.client_data
= (XPointer
)dpyinfo
;
12248 /* This isn't prototyped in OSF 5.0. */
12249 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
12253 #else /* not USE_XIM */
12254 dpyinfo
->xim
= NULL
;
12255 #endif /* not USE_XIM */
12259 #ifdef HAVE_X11R6_XIM
12263 struct x_display_info
*dpyinfo
;
12264 char *resource_name
;
12267 /* XIM instantiate callback function, which is called whenever an XIM
12268 server is available. DISPLAY is teh display of the XIM.
12269 CLIENT_DATA contains a pointer to an xim_inst_t structure created
12270 when the callback was registered. */
12273 xim_instantiate_callback (display
, client_data
, call_data
)
12275 XPointer client_data
;
12276 XPointer call_data
;
12278 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
12279 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
12281 /* We don't support multiple XIM connections. */
12285 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
12287 /* Create XIC for the existing frames on the same display, as long
12288 as they have no XIC. */
12289 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
12291 Lisp_Object tail
, frame
;
12294 FOR_EACH_FRAME (tail
, frame
)
12296 struct frame
*f
= XFRAME (frame
);
12298 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
12299 if (FRAME_XIC (f
) == NULL
)
12301 create_frame_xic (f
);
12302 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
12303 xic_set_statusarea (f
);
12304 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
12306 struct window
*w
= XWINDOW (f
->selected_window
);
12307 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
12316 #endif /* HAVE_X11R6_XIM */
12319 /* Open a connection to the XIM server on display DPYINFO.
12320 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
12321 connection only at the first time. On X11R6, open the connection
12322 in the XIM instantiate callback function. */
12325 xim_initialize (dpyinfo
, resource_name
)
12326 struct x_display_info
*dpyinfo
;
12327 char *resource_name
;
12330 #ifdef HAVE_X11R6_XIM
12331 struct xim_inst_t
*xim_inst
;
12334 dpyinfo
->xim
= NULL
;
12335 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
12336 xim_inst
->dpyinfo
= dpyinfo
;
12337 len
= strlen (resource_name
);
12338 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
12339 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
12340 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
12341 resource_name
, EMACS_CLASS
,
12342 xim_instantiate_callback
,
12343 /* Fixme: This is XPointer in
12344 XFree86 but (XPointer *) on
12345 Tru64, at least. */
12346 (XPointer
) xim_inst
);
12347 #else /* not HAVE_X11R6_XIM */
12348 dpyinfo
->xim
= NULL
;
12349 xim_open_dpy (dpyinfo
, resource_name
);
12350 #endif /* not HAVE_X11R6_XIM */
12352 #else /* not USE_XIM */
12353 dpyinfo
->xim
= NULL
;
12354 #endif /* not USE_XIM */
12358 /* Close the connection to the XIM server on display DPYINFO. */
12361 xim_close_dpy (dpyinfo
)
12362 struct x_display_info
*dpyinfo
;
12365 #ifdef HAVE_X11R6_XIM
12366 if (dpyinfo
->display
)
12367 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
12369 xim_instantiate_callback
, NULL
);
12370 #endif /* not HAVE_X11R6_XIM */
12371 if (dpyinfo
->display
)
12372 XCloseIM (dpyinfo
->xim
);
12373 dpyinfo
->xim
= NULL
;
12374 XFree (dpyinfo
->xim_styles
);
12375 #endif /* USE_XIM */
12378 #endif /* not HAVE_X11R6_XIM */
12382 /* Calculate the absolute position in frame F
12383 from its current recorded position values and gravity. */
12386 x_calc_absolute_position (f
)
12390 int win_x
= 0, win_y
= 0;
12391 int flags
= f
->output_data
.x
->size_hint_flags
;
12394 /* We have nothing to do if the current position
12395 is already for the top-left corner. */
12396 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
12399 #ifdef USE_X_TOOLKIT
12400 this_window
= XtWindow (f
->output_data
.x
->widget
);
12402 this_window
= FRAME_X_WINDOW (f
);
12405 /* Find the position of the outside upper-left corner of
12406 the inner window, with respect to the outer window.
12407 But do this only if we will need the results. */
12408 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
12413 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
12416 x_clear_errors (FRAME_X_DISPLAY (f
));
12417 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
12419 /* From-window, to-window. */
12421 f
->output_data
.x
->parent_desc
,
12423 /* From-position, to-position. */
12424 0, 0, &win_x
, &win_y
,
12426 /* Child of win. */
12428 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
12430 Window newroot
, newparent
= 0xdeadbeef;
12431 Window
*newchildren
;
12432 unsigned int nchildren
;
12434 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
12435 &newparent
, &newchildren
, &nchildren
))
12438 XFree ((char *) newchildren
);
12440 f
->output_data
.x
->parent_desc
= newparent
;
12446 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
12450 /* Treat negative positions as relative to the leftmost bottommost
12451 position that fits on the screen. */
12452 if (flags
& XNegative
)
12453 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
12454 - 2 * f
->output_data
.x
->border_width
- win_x
12456 + f
->output_data
.x
->left_pos
);
12459 int height
= PIXEL_HEIGHT (f
);
12461 #if defined USE_X_TOOLKIT && defined USE_MOTIF
12462 /* Something is fishy here. When using Motif, starting Emacs with
12463 `-g -0-0', the frame appears too low by a few pixels.
12465 This seems to be so because initially, while Emacs is starting,
12466 the column widget's height and the frame's pixel height are
12467 different. The column widget's height is the right one. In
12468 later invocations, when Emacs is up, the frame's pixel height
12471 It's not obvious where the initial small difference comes from.
12472 2000-12-01, gerd. */
12474 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
12477 if (flags
& YNegative
)
12478 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
12479 - 2 * f
->output_data
.x
->border_width
12482 + f
->output_data
.x
->top_pos
);
12485 /* The left_pos and top_pos
12486 are now relative to the top and left screen edges,
12487 so the flags should correspond. */
12488 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
12491 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
12492 to really change the position, and 0 when calling from
12493 x_make_frame_visible (in that case, XOFF and YOFF are the current
12494 position values). It is -1 when calling from x_set_frame_parameters,
12495 which means, do adjust for borders but don't change the gravity. */
12498 x_set_offset (f
, xoff
, yoff
, change_gravity
)
12500 register int xoff
, yoff
;
12501 int change_gravity
;
12503 int modified_top
, modified_left
;
12505 if (change_gravity
> 0)
12507 f
->output_data
.x
->top_pos
= yoff
;
12508 f
->output_data
.x
->left_pos
= xoff
;
12509 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
12511 f
->output_data
.x
->size_hint_flags
|= XNegative
;
12513 f
->output_data
.x
->size_hint_flags
|= YNegative
;
12514 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
12516 x_calc_absolute_position (f
);
12519 x_wm_set_size_hint (f
, (long) 0, 0);
12521 modified_left
= f
->output_data
.x
->left_pos
;
12522 modified_top
= f
->output_data
.x
->top_pos
;
12523 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
12524 this seems to be unnecessary and incorrect. rms, 4/17/97. */
12525 /* It is a mystery why we need to add the border_width here
12526 when the frame is already visible, but experiment says we do. */
12527 if (change_gravity
!= 0)
12529 modified_left
+= f
->output_data
.x
->border_width
;
12530 modified_top
+= f
->output_data
.x
->border_width
;
12534 #ifdef USE_X_TOOLKIT
12535 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
12536 modified_left
, modified_top
);
12537 #else /* not USE_X_TOOLKIT */
12538 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12539 modified_left
, modified_top
);
12540 #endif /* not USE_X_TOOLKIT */
12545 /* Change the size of frame F's X window to COLS/ROWS in the case F
12546 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
12547 top-left-corner window gravity for this size change and subsequent
12548 size changes. Otherwise we leave the window gravity unchanged. */
12551 x_set_window_size_1 (f
, change_gravity
, cols
, rows
)
12553 int change_gravity
;
12556 int pixelwidth
, pixelheight
;
12558 check_frame_size (f
, &rows
, &cols
);
12559 f
->output_data
.x
->vertical_scroll_bar_extra
12560 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
12562 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
12563 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
12564 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
12565 f
->output_data
.x
->fringes_extra
12566 = FRAME_FRINGE_WIDTH (f
);
12567 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
12568 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
12570 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
12571 x_wm_set_size_hint (f
, (long) 0, 0);
12573 XSync (FRAME_X_DISPLAY (f
), False
);
12574 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12575 pixelwidth
, pixelheight
);
12577 /* Now, strictly speaking, we can't be sure that this is accurate,
12578 but the window manager will get around to dealing with the size
12579 change request eventually, and we'll hear how it went when the
12580 ConfigureNotify event gets here.
12582 We could just not bother storing any of this information here,
12583 and let the ConfigureNotify event set everything up, but that
12584 might be kind of confusing to the Lisp code, since size changes
12585 wouldn't be reported in the frame parameters until some random
12586 point in the future when the ConfigureNotify event arrives.
12588 We pass 1 for DELAY since we can't run Lisp code inside of
12590 change_frame_size (f
, rows
, cols
, 0, 1, 0);
12591 PIXEL_WIDTH (f
) = pixelwidth
;
12592 PIXEL_HEIGHT (f
) = pixelheight
;
12594 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
12595 receive in the ConfigureNotify event; if we get what we asked
12596 for, then the event won't cause the screen to become garbaged, so
12597 we have to make sure to do it here. */
12598 SET_FRAME_GARBAGED (f
);
12600 XFlush (FRAME_X_DISPLAY (f
));
12604 /* Call this to change the size of frame F's x-window.
12605 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
12606 for this size change and subsequent size changes.
12607 Otherwise we leave the window gravity unchanged. */
12610 x_set_window_size (f
, change_gravity
, cols
, rows
)
12612 int change_gravity
;
12617 #ifdef USE_X_TOOLKIT
12619 if (f
->output_data
.x
->widget
!= NULL
)
12621 /* The x and y position of the widget is clobbered by the
12622 call to XtSetValues within EmacsFrameSetCharSize.
12623 This is a real kludge, but I don't understand Xt so I can't
12624 figure out a correct fix. Can anyone else tell me? -- rms. */
12625 int xpos
= f
->output_data
.x
->widget
->core
.x
;
12626 int ypos
= f
->output_data
.x
->widget
->core
.y
;
12627 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
12628 f
->output_data
.x
->widget
->core
.x
= xpos
;
12629 f
->output_data
.x
->widget
->core
.y
= ypos
;
12632 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
12634 #else /* not USE_X_TOOLKIT */
12636 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
12638 #endif /* not USE_X_TOOLKIT */
12640 /* If cursor was outside the new size, mark it as off. */
12641 mark_window_cursors_off (XWINDOW (f
->root_window
));
12643 /* Clear out any recollection of where the mouse highlighting was,
12644 since it might be in a place that's outside the new frame size.
12645 Actually checking whether it is outside is a pain in the neck,
12646 so don't try--just let the highlighting be done afresh with new size. */
12647 cancel_mouse_face (f
);
12652 /* Mouse warping. */
12655 x_set_mouse_position (f
, x
, y
)
12661 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
12662 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
12664 if (pix_x
< 0) pix_x
= 0;
12665 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
12667 if (pix_y
< 0) pix_y
= 0;
12668 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
12672 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
12673 0, 0, 0, 0, pix_x
, pix_y
);
12677 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
12680 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
12686 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
12687 0, 0, 0, 0, pix_x
, pix_y
);
12691 /* focus shifting, raising and lowering. */
12694 x_focus_on_frame (f
)
12697 #if 0 /* This proves to be unpleasant. */
12701 /* I don't think that the ICCCM allows programs to do things like this
12702 without the interaction of the window manager. Whatever you end up
12703 doing with this code, do it to x_unfocus_frame too. */
12704 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12705 RevertToPointerRoot
, CurrentTime
);
12710 x_unfocus_frame (f
)
12714 /* Look at the remarks in x_focus_on_frame. */
12715 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
12716 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
12717 RevertToPointerRoot
, CurrentTime
);
12721 /* Raise frame F. */
12727 if (f
->async_visible
)
12730 #ifdef USE_X_TOOLKIT
12731 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
12732 #else /* not USE_X_TOOLKIT */
12733 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12734 #endif /* not USE_X_TOOLKIT */
12735 XFlush (FRAME_X_DISPLAY (f
));
12740 /* Lower frame F. */
12746 if (f
->async_visible
)
12749 #ifdef USE_X_TOOLKIT
12750 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
12751 #else /* not USE_X_TOOLKIT */
12752 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12753 #endif /* not USE_X_TOOLKIT */
12754 XFlush (FRAME_X_DISPLAY (f
));
12760 XTframe_raise_lower (f
, raise_flag
)
12770 /* Change of visibility. */
12772 /* This tries to wait until the frame is really visible.
12773 However, if the window manager asks the user where to position
12774 the frame, this will return before the user finishes doing that.
12775 The frame will not actually be visible at that time,
12776 but it will become visible later when the window manager
12777 finishes with it. */
12780 x_make_frame_visible (f
)
12784 int original_top
, original_left
;
12785 int retry_count
= 2;
12791 type
= x_icon_type (f
);
12793 x_bitmap_icon (f
, type
);
12795 if (! FRAME_VISIBLE_P (f
))
12797 /* We test FRAME_GARBAGED_P here to make sure we don't
12798 call x_set_offset a second time
12799 if we get to x_make_frame_visible a second time
12800 before the window gets really visible. */
12801 if (! FRAME_ICONIFIED_P (f
)
12802 && ! f
->output_data
.x
->asked_for_visible
)
12803 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
12805 f
->output_data
.x
->asked_for_visible
= 1;
12807 if (! EQ (Vx_no_window_manager
, Qt
))
12808 x_wm_set_window_state (f
, NormalState
);
12809 #ifdef USE_X_TOOLKIT
12810 /* This was XtPopup, but that did nothing for an iconified frame. */
12811 XtMapWidget (f
->output_data
.x
->widget
);
12812 #else /* not USE_X_TOOLKIT */
12813 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12814 #endif /* not USE_X_TOOLKIT */
12815 #if 0 /* This seems to bring back scroll bars in the wrong places
12816 if the window configuration has changed. They seem
12817 to come back ok without this. */
12818 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
12819 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12823 XFlush (FRAME_X_DISPLAY (f
));
12825 /* Synchronize to ensure Emacs knows the frame is visible
12826 before we do anything else. We do this loop with input not blocked
12827 so that incoming events are handled. */
12831 /* This must be before UNBLOCK_INPUT
12832 since events that arrive in response to the actions above
12833 will set it when they are handled. */
12834 int previously_visible
= f
->output_data
.x
->has_been_visible
;
12836 original_left
= f
->output_data
.x
->left_pos
;
12837 original_top
= f
->output_data
.x
->top_pos
;
12839 /* This must come after we set COUNT. */
12842 /* We unblock here so that arriving X events are processed. */
12844 /* Now move the window back to where it was "supposed to be".
12845 But don't do it if the gravity is negative.
12846 When the gravity is negative, this uses a position
12847 that is 3 pixels too low. Perhaps that's really the border width.
12849 Don't do this if the window has never been visible before,
12850 because the window manager may choose the position
12851 and we don't want to override it. */
12853 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
12854 && f
->output_data
.x
->win_gravity
== NorthWestGravity
12855 && previously_visible
)
12859 unsigned int width
, height
, border
, depth
;
12863 /* On some window managers (such as FVWM) moving an existing
12864 window, even to the same place, causes the window manager
12865 to introduce an offset. This can cause the window to move
12866 to an unexpected location. Check the geometry (a little
12867 slow here) and then verify that the window is in the right
12868 place. If the window is not in the right place, move it
12869 there, and take the potential window manager hit. */
12870 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
12871 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
12873 if (original_left
!= x
|| original_top
!= y
)
12874 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
12875 original_left
, original_top
);
12880 XSETFRAME (frame
, f
);
12882 /* Wait until the frame is visible. Process X events until a
12883 MapNotify event has been seen, or until we think we won't get a
12884 MapNotify at all.. */
12885 for (count
= input_signal_count
+ 10;
12886 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
12888 /* Force processing of queued events. */
12891 /* Machines that do polling rather than SIGIO have been
12892 observed to go into a busy-wait here. So we'll fake an
12893 alarm signal to let the handler know that there's something
12894 to be read. We used to raise a real alarm, but it seems
12895 that the handler isn't always enabled here. This is
12897 if (input_polling_used ())
12899 /* It could be confusing if a real alarm arrives while
12900 processing the fake one. Turn it off and let the
12901 handler reset it. */
12902 extern void poll_for_input_1
P_ ((void));
12903 int old_poll_suppress_count
= poll_suppress_count
;
12904 poll_suppress_count
= 1;
12905 poll_for_input_1 ();
12906 poll_suppress_count
= old_poll_suppress_count
;
12909 /* See if a MapNotify event has been processed. */
12910 FRAME_SAMPLE_VISIBILITY (f
);
12915 (let ((f (selected-frame)))
12919 the frame is not raised with various window managers on
12920 FreeBSD, Linux and Solaris. It turns out that, for some
12921 unknown reason, the call to XtMapWidget is completely ignored.
12922 Mapping the widget a second time works. */
12924 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
12929 /* Change from mapped state to withdrawn state. */
12931 /* Make the frame visible (mapped and not iconified). */
12934 x_make_frame_invisible (f
)
12939 #ifdef USE_X_TOOLKIT
12940 /* Use the frame's outermost window, not the one we normally draw on. */
12941 window
= XtWindow (f
->output_data
.x
->widget
);
12942 #else /* not USE_X_TOOLKIT */
12943 window
= FRAME_X_WINDOW (f
);
12944 #endif /* not USE_X_TOOLKIT */
12946 /* Don't keep the highlight on an invisible frame. */
12947 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
12948 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
12950 #if 0/* This might add unreliability; I don't trust it -- rms. */
12951 if (! f
->async_visible
&& ! f
->async_iconified
)
12957 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
12958 that the current position of the window is user-specified, rather than
12959 program-specified, so that when the window is mapped again, it will be
12960 placed at the same location, without forcing the user to position it
12961 by hand again (they have already done that once for this window.) */
12962 x_wm_set_size_hint (f
, (long) 0, 1);
12966 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
12967 DefaultScreen (FRAME_X_DISPLAY (f
))))
12969 UNBLOCK_INPUT_RESIGNAL
;
12970 error ("Can't notify window manager of window withdrawal");
12972 #else /* ! defined (HAVE_X11R4) */
12974 /* Tell the window manager what we're going to do. */
12975 if (! EQ (Vx_no_window_manager
, Qt
))
12979 unmap
.xunmap
.type
= UnmapNotify
;
12980 unmap
.xunmap
.window
= window
;
12981 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
12982 unmap
.xunmap
.from_configure
= False
;
12983 if (! XSendEvent (FRAME_X_DISPLAY (f
),
12984 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
12986 SubstructureRedirectMaskSubstructureNotifyMask
,
12989 UNBLOCK_INPUT_RESIGNAL
;
12990 error ("Can't notify window manager of withdrawal");
12994 /* Unmap the window ourselves. Cheeky! */
12995 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
12996 #endif /* ! defined (HAVE_X11R4) */
12998 /* We can't distinguish this from iconification
12999 just by the event that we get from the server.
13000 So we can't win using the usual strategy of letting
13001 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
13002 and synchronize with the server to make sure we agree. */
13004 FRAME_ICONIFIED_P (f
) = 0;
13005 f
->async_visible
= 0;
13006 f
->async_iconified
= 0;
13013 /* Change window state from mapped to iconified. */
13016 x_iconify_frame (f
)
13022 /* Don't keep the highlight on an invisible frame. */
13023 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
13024 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
13026 if (f
->async_iconified
)
13031 FRAME_SAMPLE_VISIBILITY (f
);
13033 type
= x_icon_type (f
);
13035 x_bitmap_icon (f
, type
);
13037 #ifdef USE_X_TOOLKIT
13039 if (! FRAME_VISIBLE_P (f
))
13041 if (! EQ (Vx_no_window_manager
, Qt
))
13042 x_wm_set_window_state (f
, IconicState
);
13043 /* This was XtPopup, but that did nothing for an iconified frame. */
13044 XtMapWidget (f
->output_data
.x
->widget
);
13045 /* The server won't give us any event to indicate
13046 that an invisible frame was changed to an icon,
13047 so we have to record it here. */
13050 f
->async_iconified
= 1;
13051 f
->async_visible
= 0;
13056 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
13057 XtWindow (f
->output_data
.x
->widget
),
13058 DefaultScreen (FRAME_X_DISPLAY (f
)));
13062 error ("Can't notify window manager of iconification");
13064 f
->async_iconified
= 1;
13065 f
->async_visible
= 0;
13069 XFlush (FRAME_X_DISPLAY (f
));
13071 #else /* not USE_X_TOOLKIT */
13073 /* Make sure the X server knows where the window should be positioned,
13074 in case the user deiconifies with the window manager. */
13075 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
13076 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
13078 /* Since we don't know which revision of X we're running, we'll use both
13079 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
13081 /* X11R4: send a ClientMessage to the window manager using the
13082 WM_CHANGE_STATE type. */
13086 message
.xclient
.window
= FRAME_X_WINDOW (f
);
13087 message
.xclient
.type
= ClientMessage
;
13088 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
13089 message
.xclient
.format
= 32;
13090 message
.xclient
.data
.l
[0] = IconicState
;
13092 if (! XSendEvent (FRAME_X_DISPLAY (f
),
13093 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
13095 SubstructureRedirectMask
| SubstructureNotifyMask
,
13098 UNBLOCK_INPUT_RESIGNAL
;
13099 error ("Can't notify window manager of iconification");
13103 /* X11R3: set the initial_state field of the window manager hints to
13105 x_wm_set_window_state (f
, IconicState
);
13107 if (!FRAME_VISIBLE_P (f
))
13109 /* If the frame was withdrawn, before, we must map it. */
13110 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13113 f
->async_iconified
= 1;
13114 f
->async_visible
= 0;
13116 XFlush (FRAME_X_DISPLAY (f
));
13118 #endif /* not USE_X_TOOLKIT */
13122 /* Free X resources of frame F. */
13125 x_free_frame_resources (f
)
13128 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13132 /* If a display connection is dead, don't try sending more
13133 commands to the X server. */
13134 if (dpyinfo
->display
)
13136 if (f
->output_data
.x
->icon_desc
)
13137 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
13141 free_frame_xic (f
);
13144 if (FRAME_X_WINDOW (f
))
13145 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
13147 #ifdef USE_X_TOOLKIT
13148 if (f
->output_data
.x
->widget
)
13150 XtDestroyWidget (f
->output_data
.x
->widget
);
13151 f
->output_data
.x
->widget
= NULL
;
13153 free_frame_menubar (f
);
13154 #endif /* USE_X_TOOLKIT */
13156 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
13157 unload_color (f
, f
->output_data
.x
->background_pixel
);
13158 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
13159 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
13160 unload_color (f
, f
->output_data
.x
->border_pixel
);
13161 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
13163 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
13164 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
13165 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
13166 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
13167 #ifdef USE_TOOLKIT_SCROLL_BARS
13168 /* Scrollbar shadow colors. */
13169 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
13170 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
13171 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
13172 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
13173 #endif /* USE_TOOLKIT_SCROLL_BARS */
13174 if (f
->output_data
.x
->white_relief
.allocated_p
)
13175 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
13176 if (f
->output_data
.x
->black_relief
.allocated_p
)
13177 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
13179 if (FRAME_FACE_CACHE (f
))
13180 free_frame_faces (f
);
13183 XFlush (FRAME_X_DISPLAY (f
));
13186 if (f
->output_data
.x
->saved_menu_event
)
13187 xfree (f
->output_data
.x
->saved_menu_event
);
13189 xfree (f
->output_data
.x
);
13190 f
->output_data
.x
= NULL
;
13192 if (f
== dpyinfo
->x_focus_frame
)
13193 dpyinfo
->x_focus_frame
= 0;
13194 if (f
== dpyinfo
->x_focus_event_frame
)
13195 dpyinfo
->x_focus_event_frame
= 0;
13196 if (f
== dpyinfo
->x_highlight_frame
)
13197 dpyinfo
->x_highlight_frame
= 0;
13199 if (f
== dpyinfo
->mouse_face_mouse_frame
)
13201 dpyinfo
->mouse_face_beg_row
13202 = dpyinfo
->mouse_face_beg_col
= -1;
13203 dpyinfo
->mouse_face_end_row
13204 = dpyinfo
->mouse_face_end_col
= -1;
13205 dpyinfo
->mouse_face_window
= Qnil
;
13206 dpyinfo
->mouse_face_deferred_gc
= 0;
13207 dpyinfo
->mouse_face_mouse_frame
= 0;
13214 /* Destroy the X window of frame F. */
13217 x_destroy_window (f
)
13220 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13222 /* If a display connection is dead, don't try sending more
13223 commands to the X server. */
13224 if (dpyinfo
->display
!= 0)
13225 x_free_frame_resources (f
);
13227 dpyinfo
->reference_count
--;
13231 /* Setting window manager hints. */
13233 /* Set the normal size hints for the window manager, for frame F.
13234 FLAGS is the flags word to use--or 0 meaning preserve the flags
13235 that the window now has.
13236 If USER_POSITION is nonzero, we set the USPosition
13237 flag (this is useful when FLAGS is 0). */
13240 x_wm_set_size_hint (f
, flags
, user_position
)
13245 XSizeHints size_hints
;
13247 #ifdef USE_X_TOOLKIT
13250 Dimension widget_width
, widget_height
;
13251 Window window
= XtWindow (f
->output_data
.x
->widget
);
13252 #else /* not USE_X_TOOLKIT */
13253 Window window
= FRAME_X_WINDOW (f
);
13254 #endif /* not USE_X_TOOLKIT */
13256 /* Setting PMaxSize caused various problems. */
13257 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
13259 size_hints
.x
= f
->output_data
.x
->left_pos
;
13260 size_hints
.y
= f
->output_data
.x
->top_pos
;
13262 #ifdef USE_X_TOOLKIT
13263 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
13264 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
13265 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
13266 size_hints
.height
= widget_height
;
13267 size_hints
.width
= widget_width
;
13268 #else /* not USE_X_TOOLKIT */
13269 size_hints
.height
= PIXEL_HEIGHT (f
);
13270 size_hints
.width
= PIXEL_WIDTH (f
);
13271 #endif /* not USE_X_TOOLKIT */
13273 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
13274 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
13275 size_hints
.max_width
13276 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
13277 size_hints
.max_height
13278 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
13280 /* Calculate the base and minimum sizes.
13282 (When we use the X toolkit, we don't do it here.
13283 Instead we copy the values that the widgets are using, below.) */
13284 #ifndef USE_X_TOOLKIT
13286 int base_width
, base_height
;
13287 int min_rows
= 0, min_cols
= 0;
13289 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
13290 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
13292 check_frame_size (f
, &min_rows
, &min_cols
);
13294 /* The window manager uses the base width hints to calculate the
13295 current number of rows and columns in the frame while
13296 resizing; min_width and min_height aren't useful for this
13297 purpose, since they might not give the dimensions for a
13298 zero-row, zero-column frame.
13300 We use the base_width and base_height members if we have
13301 them; otherwise, we set the min_width and min_height members
13302 to the size for a zero x zero frame. */
13305 size_hints
.flags
|= PBaseSize
;
13306 size_hints
.base_width
= base_width
;
13307 size_hints
.base_height
= base_height
;
13308 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
13309 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
13311 size_hints
.min_width
= base_width
;
13312 size_hints
.min_height
= base_height
;
13316 /* If we don't need the old flags, we don't need the old hint at all. */
13319 size_hints
.flags
|= flags
;
13322 #endif /* not USE_X_TOOLKIT */
13325 XSizeHints hints
; /* Sometimes I hate X Windows... */
13326 long supplied_return
;
13330 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
13333 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
13336 #ifdef USE_X_TOOLKIT
13337 size_hints
.base_height
= hints
.base_height
;
13338 size_hints
.base_width
= hints
.base_width
;
13339 size_hints
.min_height
= hints
.min_height
;
13340 size_hints
.min_width
= hints
.min_width
;
13344 size_hints
.flags
|= flags
;
13349 if (hints
.flags
& PSize
)
13350 size_hints
.flags
|= PSize
;
13351 if (hints
.flags
& PPosition
)
13352 size_hints
.flags
|= PPosition
;
13353 if (hints
.flags
& USPosition
)
13354 size_hints
.flags
|= USPosition
;
13355 if (hints
.flags
& USSize
)
13356 size_hints
.flags
|= USSize
;
13360 #ifndef USE_X_TOOLKIT
13365 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
13366 size_hints
.flags
|= PWinGravity
;
13370 size_hints
.flags
&= ~ PPosition
;
13371 size_hints
.flags
|= USPosition
;
13373 #endif /* PWinGravity */
13376 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
13378 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
13382 /* Used for IconicState or NormalState */
13385 x_wm_set_window_state (f
, state
)
13389 #ifdef USE_X_TOOLKIT
13392 XtSetArg (al
[0], XtNinitialState
, state
);
13393 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
13394 #else /* not USE_X_TOOLKIT */
13395 Window window
= FRAME_X_WINDOW (f
);
13397 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
13398 f
->output_data
.x
->wm_hints
.initial_state
= state
;
13400 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
13401 #endif /* not USE_X_TOOLKIT */
13405 x_wm_set_icon_pixmap (f
, pixmap_id
)
13409 Pixmap icon_pixmap
;
13411 #ifndef USE_X_TOOLKIT
13412 Window window
= FRAME_X_WINDOW (f
);
13417 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
13418 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
13422 /* It seems there is no way to turn off use of an icon pixmap.
13423 The following line does it, only if no icon has yet been created,
13424 for some window managers. But with mwm it crashes.
13425 Some people say it should clear the IconPixmapHint bit in this case,
13426 but that doesn't work, and the X consortium said it isn't the
13427 right thing at all. Since there is no way to win,
13428 best to explicitly give up. */
13430 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
13436 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
13440 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
13441 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
13444 #else /* not USE_X_TOOLKIT */
13446 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
13447 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
13449 #endif /* not USE_X_TOOLKIT */
13453 x_wm_set_icon_position (f
, icon_x
, icon_y
)
13455 int icon_x
, icon_y
;
13457 #ifdef USE_X_TOOLKIT
13458 Window window
= XtWindow (f
->output_data
.x
->widget
);
13460 Window window
= FRAME_X_WINDOW (f
);
13463 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
13464 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
13465 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
13467 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
13471 /***********************************************************************
13473 ***********************************************************************/
13475 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
13478 x_get_font_info (f
, font_idx
)
13482 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
13486 /* Return a list of names of available fonts matching PATTERN on frame F.
13488 If SIZE is > 0, it is the size (maximum bounds width) of fonts
13491 SIZE < 0 means include scalable fonts.
13493 Frame F null means we have not yet created any frame on X, and
13494 consult the first display in x_display_list. MAXNAMES sets a limit
13495 on how many fonts to match. */
13498 x_list_fonts (f
, pattern
, size
, maxnames
)
13500 Lisp_Object pattern
;
13504 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
13505 Lisp_Object tem
, second_best
;
13506 struct x_display_info
*dpyinfo
13507 = f
? FRAME_X_DISPLAY_INFO (f
) : x_display_list
;
13508 Display
*dpy
= dpyinfo
->display
;
13509 int try_XLoadQueryFont
= 0;
13511 int allow_scalable_fonts_p
= 0;
13515 allow_scalable_fonts_p
= 1;
13519 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
13520 if (NILP (patterns
))
13521 patterns
= Fcons (pattern
, Qnil
);
13523 if (maxnames
== 1 && !size
)
13524 /* We can return any single font matching PATTERN. */
13525 try_XLoadQueryFont
= 1;
13527 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
13530 char **names
= NULL
;
13532 pattern
= XCAR (patterns
);
13533 /* See if we cached the result for this particular query.
13534 The cache is an alist of the form:
13535 ((((PATTERN . MAXNAMES) . SCALABLE) (FONTNAME . WIDTH) ...) ...) */
13536 tem
= XCDR (dpyinfo
->name_list_element
);
13537 key
= Fcons (Fcons (pattern
, make_number (maxnames
)),
13538 allow_scalable_fonts_p
? Qt
: Qnil
);
13539 list
= Fassoc (key
, tem
);
13542 list
= Fcdr_safe (list
);
13543 /* We have a cashed list. Don't have to get the list again. */
13547 /* At first, put PATTERN in the cache. */
13550 count
= x_catch_errors (dpy
);
13552 if (try_XLoadQueryFont
)
13555 unsigned long value
;
13557 font
= XLoadQueryFont (dpy
, XSTRING (pattern
)->data
);
13558 if (x_had_errors_p (dpy
))
13560 /* This error is perhaps due to insufficient memory on X
13561 server. Let's just ignore it. */
13563 x_clear_errors (dpy
);
13567 && XGetFontProperty (font
, XA_FONT
, &value
))
13569 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
13570 int len
= strlen (name
);
13573 /* If DXPC (a Differential X Protocol Compressor)
13574 Ver.3.7 is running, XGetAtomName will return null
13575 string. We must avoid such a name. */
13577 try_XLoadQueryFont
= 0;
13581 names
= (char **) alloca (sizeof (char *));
13582 /* Some systems only allow alloca assigned to a
13584 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
13585 bcopy (name
, names
[0], len
+ 1);
13590 try_XLoadQueryFont
= 0;
13593 XFreeFont (dpy
, font
);
13596 if (!try_XLoadQueryFont
)
13598 /* We try at least 10 fonts because XListFonts will return
13599 auto-scaled fonts at the head. */
13600 names
= XListFonts (dpy
, XSTRING (pattern
)->data
, max (maxnames
, 10),
13602 if (x_had_errors_p (dpy
))
13604 /* This error is perhaps due to insufficient memory on X
13605 server. Let's just ignore it. */
13607 x_clear_errors (dpy
);
13611 x_uncatch_errors (dpy
, count
);
13618 /* Make a list of all the fonts we got back.
13619 Store that in the font cache for the display. */
13620 for (i
= 0; i
< num_fonts
; i
++)
13623 char *p
= names
[i
];
13624 int average_width
= -1, dashes
= 0;
13626 /* Count the number of dashes in NAMES[I]. If there are
13627 14 dashes, and the field value following 12th dash
13628 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
13629 is usually too ugly to be used for editing. Let's
13635 if (dashes
== 7) /* PIXEL_SIZE field */
13637 else if (dashes
== 12) /* AVERAGE_WIDTH field */
13638 average_width
= atoi (p
);
13641 if (allow_scalable_fonts_p
13642 || dashes
< 14 || average_width
!= 0)
13644 tem
= build_string (names
[i
]);
13645 if (NILP (Fassoc (tem
, list
)))
13647 if (STRINGP (Vx_pixel_size_width_font_regexp
)
13648 && ((fast_c_string_match_ignore_case
13649 (Vx_pixel_size_width_font_regexp
, names
[i
]))
13651 /* We can set the value of PIXEL_SIZE to the
13652 width of this font. */
13653 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
13655 /* For the moment, width is not known. */
13656 list
= Fcons (Fcons (tem
, Qnil
), list
);
13661 if (!try_XLoadQueryFont
)
13664 XFreeFontNames (names
);
13669 /* Now store the result in the cache. */
13670 XSETCDR (dpyinfo
->name_list_element
,
13671 Fcons (Fcons (key
, list
), XCDR (dpyinfo
->name_list_element
)));
13674 if (NILP (list
)) continue; /* Try the remaining alternatives. */
13676 newlist
= second_best
= Qnil
;
13677 /* Make a list of the fonts that have the right width. */
13678 for (; CONSP (list
); list
= XCDR (list
))
13684 if (!CONSP (tem
) || NILP (XCAR (tem
)))
13688 newlist
= Fcons (XCAR (tem
), newlist
);
13692 if (!INTEGERP (XCDR (tem
)))
13694 /* Since we have not yet known the size of this font, we
13695 must try slow function call XLoadQueryFont. */
13696 XFontStruct
*thisinfo
;
13699 count
= x_catch_errors (dpy
);
13700 thisinfo
= XLoadQueryFont (dpy
,
13701 XSTRING (XCAR (tem
))->data
);
13702 if (x_had_errors_p (dpy
))
13704 /* This error is perhaps due to insufficient memory on X
13705 server. Let's just ignore it. */
13707 x_clear_errors (dpy
);
13709 x_uncatch_errors (dpy
, count
);
13715 (thisinfo
->min_bounds
.width
== 0
13717 : make_number (thisinfo
->max_bounds
.width
)));
13719 XFreeFont (dpy
, thisinfo
);
13723 /* For unknown reason, the previous call of XListFont had
13724 returned a font which can't be opened. Record the size
13725 as 0 not to try to open it again. */
13726 XSETCDR (tem
, make_number (0));
13729 found_size
= XINT (XCDR (tem
));
13730 if (found_size
== size
)
13731 newlist
= Fcons (XCAR (tem
), newlist
);
13732 else if (found_size
> 0)
13734 if (NILP (second_best
))
13736 else if (found_size
< size
)
13738 if (XINT (XCDR (second_best
)) > size
13739 || XINT (XCDR (second_best
)) < found_size
)
13744 if (XINT (XCDR (second_best
)) > size
13745 && XINT (XCDR (second_best
)) > found_size
)
13750 if (!NILP (newlist
))
13752 else if (!NILP (second_best
))
13754 newlist
= Fcons (XCAR (second_best
), Qnil
);
13765 /* Check that FONT is valid on frame F. It is if it can be found in F's
13769 x_check_font (f
, font
)
13774 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13776 xassert (font
!= NULL
);
13778 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
13779 if (dpyinfo
->font_table
[i
].name
13780 && font
== dpyinfo
->font_table
[i
].font
)
13783 xassert (i
< dpyinfo
->n_fonts
);
13786 #endif /* GLYPH_DEBUG != 0 */
13788 /* Set *W to the minimum width, *H to the minimum font height of FONT.
13789 Note: There are (broken) X fonts out there with invalid XFontStruct
13790 min_bounds contents. For example, handa@etl.go.jp reports that
13791 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
13792 have font->min_bounds.width == 0. */
13795 x_font_min_bounds (font
, w
, h
)
13799 *h
= FONT_HEIGHT (font
);
13800 *w
= font
->min_bounds
.width
;
13802 /* Try to handle the case where FONT->min_bounds has invalid
13803 contents. Since the only font known to have invalid min_bounds
13804 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
13806 *w
= font
->max_bounds
.width
;
13810 /* Compute the smallest character width and smallest font height over
13811 all fonts available on frame F. Set the members smallest_char_width
13812 and smallest_font_height in F's x_display_info structure to
13813 the values computed. Value is non-zero if smallest_font_height or
13814 smallest_char_width become smaller than they were before. */
13817 x_compute_min_glyph_bounds (f
)
13821 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13823 int old_width
= dpyinfo
->smallest_char_width
;
13824 int old_height
= dpyinfo
->smallest_font_height
;
13826 dpyinfo
->smallest_font_height
= 100000;
13827 dpyinfo
->smallest_char_width
= 100000;
13829 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
13830 if (dpyinfo
->font_table
[i
].name
)
13832 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
13835 font
= (XFontStruct
*) fontp
->font
;
13836 xassert (font
!= (XFontStruct
*) ~0);
13837 x_font_min_bounds (font
, &w
, &h
);
13839 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
13840 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
13843 xassert (dpyinfo
->smallest_char_width
> 0
13844 && dpyinfo
->smallest_font_height
> 0);
13846 return (dpyinfo
->n_fonts
== 1
13847 || dpyinfo
->smallest_char_width
< old_width
13848 || dpyinfo
->smallest_font_height
< old_height
);
13852 /* Load font named FONTNAME of the size SIZE for frame F, and return a
13853 pointer to the structure font_info while allocating it dynamically.
13854 If SIZE is 0, load any size of font.
13855 If loading is failed, return NULL. */
13858 x_load_font (f
, fontname
, size
)
13860 register char *fontname
;
13863 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13864 Lisp_Object font_names
;
13867 /* Get a list of all the fonts that match this name. Once we
13868 have a list of matching fonts, we compare them against the fonts
13869 we already have by comparing names. */
13870 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
13872 if (!NILP (font_names
))
13877 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
13878 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
13879 if (dpyinfo
->font_table
[i
].name
13880 && (!strcmp (dpyinfo
->font_table
[i
].name
,
13881 XSTRING (XCAR (tail
))->data
)
13882 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
13883 XSTRING (XCAR (tail
))->data
)))
13884 return (dpyinfo
->font_table
+ i
);
13887 /* Load the font and add it to the table. */
13891 struct font_info
*fontp
;
13892 unsigned long value
;
13895 /* If we have found fonts by x_list_font, load one of them. If
13896 not, we still try to load a font by the name given as FONTNAME
13897 because XListFonts (called in x_list_font) of some X server has
13898 a bug of not finding a font even if the font surely exists and
13899 is loadable by XLoadQueryFont. */
13900 if (size
> 0 && !NILP (font_names
))
13901 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
13904 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
13905 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
13906 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
13908 /* This error is perhaps due to insufficient memory on X
13909 server. Let's just ignore it. */
13911 x_clear_errors (FRAME_X_DISPLAY (f
));
13913 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
13918 /* Find a free slot in the font table. */
13919 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
13920 if (dpyinfo
->font_table
[i
].name
== NULL
)
13923 /* If no free slot found, maybe enlarge the font table. */
13924 if (i
== dpyinfo
->n_fonts
13925 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
13928 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
13929 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
13930 dpyinfo
->font_table
13931 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
13934 fontp
= dpyinfo
->font_table
+ i
;
13935 if (i
== dpyinfo
->n_fonts
)
13936 ++dpyinfo
->n_fonts
;
13938 /* Now fill in the slots of *FONTP. */
13940 fontp
->font
= font
;
13941 fontp
->font_idx
= i
;
13942 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
13943 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
13945 /* Try to get the full name of FONT. Put it in FULL_NAME. */
13947 if (XGetFontProperty (font
, XA_FONT
, &value
))
13949 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
13953 /* Count the number of dashes in the "full name".
13954 If it is too few, this isn't really the font's full name,
13956 In X11R4, the fonts did not come with their canonical names
13967 full_name
= (char *) xmalloc (p
- name
+ 1);
13968 bcopy (name
, full_name
, p
- name
+ 1);
13974 if (full_name
!= 0)
13975 fontp
->full_name
= full_name
;
13977 fontp
->full_name
= fontp
->name
;
13979 fontp
->size
= font
->max_bounds
.width
;
13980 fontp
->height
= FONT_HEIGHT (font
);
13982 if (NILP (font_names
))
13984 /* We come here because of a bug of XListFonts mentioned at
13985 the head of this block. Let's store this information in
13986 the cache for x_list_fonts. */
13987 Lisp_Object lispy_name
= build_string (fontname
);
13988 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
13989 Lisp_Object key
= Fcons (Fcons (lispy_name
, make_number (256)),
13992 XSETCDR (dpyinfo
->name_list_element
,
13994 Fcons (Fcons (lispy_full_name
,
13995 make_number (fontp
->size
)),
13997 XCDR (dpyinfo
->name_list_element
)));
14000 key
= Fcons (Fcons (lispy_full_name
, make_number (256)),
14002 XSETCDR (dpyinfo
->name_list_element
,
14004 Fcons (Fcons (lispy_full_name
,
14005 make_number (fontp
->size
)),
14007 XCDR (dpyinfo
->name_list_element
)));
14011 /* The slot `encoding' specifies how to map a character
14012 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
14013 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
14014 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
14015 2:0xA020..0xFF7F). For the moment, we don't know which charset
14016 uses this font. So, we set information in fontp->encoding[1]
14017 which is never used by any charset. If mapping can't be
14018 decided, set FONT_ENCODING_NOT_DECIDED. */
14020 = (font
->max_byte1
== 0
14022 ? (font
->min_char_or_byte2
< 0x80
14023 ? (font
->max_char_or_byte2
< 0x80
14024 ? 0 /* 0x20..0x7F */
14025 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
14026 : 1) /* 0xA0..0xFF */
14028 : (font
->min_byte1
< 0x80
14029 ? (font
->max_byte1
< 0x80
14030 ? (font
->min_char_or_byte2
< 0x80
14031 ? (font
->max_char_or_byte2
< 0x80
14032 ? 0 /* 0x2020..0x7F7F */
14033 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
14034 : 3) /* 0x20A0..0x7FFF */
14035 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
14036 : (font
->min_char_or_byte2
< 0x80
14037 ? (font
->max_char_or_byte2
< 0x80
14038 ? 2 /* 0xA020..0xFF7F */
14039 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
14040 : 1))); /* 0xA0A0..0xFFFF */
14042 fontp
->baseline_offset
14043 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
14044 ? (long) value
: 0);
14045 fontp
->relative_compose
14046 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
14047 ? (long) value
: 0);
14048 fontp
->default_ascent
14049 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
14050 ? (long) value
: 0);
14052 /* Set global flag fonts_changed_p to non-zero if the font loaded
14053 has a character with a smaller width than any other character
14054 before, or if the font loaded has a smalle>r height than any
14055 other font loaded before. If this happens, it will make a
14056 glyph matrix reallocation necessary. */
14057 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
14064 /* Return a pointer to struct font_info of a font named FONTNAME for
14065 frame F. If no such font is loaded, return NULL. */
14068 x_query_font (f
, fontname
)
14070 register char *fontname
;
14072 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
14075 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
14076 if (dpyinfo
->font_table
[i
].name
14077 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
14078 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
14079 return (dpyinfo
->font_table
+ i
);
14084 /* Find a CCL program for a font specified by FONTP, and set the member
14085 `encoder' of the structure. */
14088 x_find_ccl_program (fontp
)
14089 struct font_info
*fontp
;
14091 Lisp_Object list
, elt
;
14094 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
14098 && STRINGP (XCAR (elt
))
14099 && ((fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
14101 || (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->full_name
)
14108 struct ccl_program
*ccl
14109 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
14111 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
14114 fontp
->font_encoder
= ccl
;
14120 /***********************************************************************
14122 ***********************************************************************/
14124 #ifdef USE_X_TOOLKIT
14125 static XrmOptionDescRec emacs_options
[] = {
14126 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
14127 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
14129 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
14130 XrmoptionSepArg
, NULL
},
14131 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
14133 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
14134 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
14135 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
14136 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
14137 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
14138 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
14139 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
14141 #endif /* USE_X_TOOLKIT */
14143 static int x_initialized
;
14145 #ifdef MULTI_KBOARD
14146 /* Test whether two display-name strings agree up to the dot that separates
14147 the screen number from the server number. */
14149 same_x_server (name1
, name2
)
14150 char *name1
, *name2
;
14152 int seen_colon
= 0;
14153 unsigned char *system_name
= XSTRING (Vsystem_name
)->data
;
14154 int system_name_length
= strlen (system_name
);
14155 int length_until_period
= 0;
14157 while (system_name
[length_until_period
] != 0
14158 && system_name
[length_until_period
] != '.')
14159 length_until_period
++;
14161 /* Treat `unix' like an empty host name. */
14162 if (! strncmp (name1
, "unix:", 5))
14164 if (! strncmp (name2
, "unix:", 5))
14166 /* Treat this host's name like an empty host name. */
14167 if (! strncmp (name1
, system_name
, system_name_length
)
14168 && name1
[system_name_length
] == ':')
14169 name1
+= system_name_length
;
14170 if (! strncmp (name2
, system_name
, system_name_length
)
14171 && name2
[system_name_length
] == ':')
14172 name2
+= system_name_length
;
14173 /* Treat this host's domainless name like an empty host name. */
14174 if (! strncmp (name1
, system_name
, length_until_period
)
14175 && name1
[length_until_period
] == ':')
14176 name1
+= length_until_period
;
14177 if (! strncmp (name2
, system_name
, length_until_period
)
14178 && name2
[length_until_period
] == ':')
14179 name2
+= length_until_period
;
14181 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
14185 if (seen_colon
&& *name1
== '.')
14189 && (*name1
== '.' || *name1
== '\0')
14190 && (*name2
== '.' || *name2
== '\0'));
14194 struct x_display_info
*
14195 x_term_init (display_name
, xrm_option
, resource_name
)
14196 Lisp_Object display_name
;
14198 char *resource_name
;
14202 struct x_display_info
*dpyinfo
;
14207 if (!x_initialized
)
14213 #ifdef USE_X_TOOLKIT
14214 /* weiner@footloose.sps.mot.com reports that this causes
14216 X protocol error: BadAtom (invalid Atom parameter)
14217 on protocol request 18skiloaf.
14218 So let's not use it until R6. */
14219 #ifdef HAVE_X11XTR6
14220 XtSetLanguageProc (NULL
, NULL
, NULL
);
14231 argv
[argc
++] = "-xrm";
14232 argv
[argc
++] = xrm_option
;
14234 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
14235 resource_name
, EMACS_CLASS
,
14236 emacs_options
, XtNumber (emacs_options
),
14239 #ifdef HAVE_X11XTR6
14240 /* I think this is to compensate for XtSetLanguageProc. */
14245 #else /* not USE_X_TOOLKIT */
14247 XSetLocaleModifiers ("");
14249 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
14250 #endif /* not USE_X_TOOLKIT */
14252 /* Detect failure. */
14259 /* We have definitely succeeded. Record the new connection. */
14261 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
14262 bzero (dpyinfo
, sizeof *dpyinfo
);
14264 #ifdef MULTI_KBOARD
14266 struct x_display_info
*share
;
14269 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
14270 share
= share
->next
, tail
= XCDR (tail
))
14271 if (same_x_server (XSTRING (XCAR (XCAR (tail
)))->data
,
14272 XSTRING (display_name
)->data
))
14275 dpyinfo
->kboard
= share
->kboard
;
14278 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
14279 init_kboard (dpyinfo
->kboard
);
14280 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
14282 char *vendor
= ServerVendor (dpy
);
14284 dpyinfo
->kboard
->Vsystem_key_alist
14285 = call1 (Qvendor_specific_keysyms
,
14286 build_string (vendor
? vendor
: ""));
14290 dpyinfo
->kboard
->next_kboard
= all_kboards
;
14291 all_kboards
= dpyinfo
->kboard
;
14292 /* Don't let the initial kboard remain current longer than necessary.
14293 That would cause problems if a file loaded on startup tries to
14294 prompt in the mini-buffer. */
14295 if (current_kboard
== initial_kboard
)
14296 current_kboard
= dpyinfo
->kboard
;
14298 dpyinfo
->kboard
->reference_count
++;
14302 /* Put this display on the chain. */
14303 dpyinfo
->next
= x_display_list
;
14304 x_display_list
= dpyinfo
;
14306 /* Put it on x_display_name_list as well, to keep them parallel. */
14307 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
14308 x_display_name_list
);
14309 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
14311 dpyinfo
->display
= dpy
;
14314 XSetAfterFunction (x_current_display
, x_trace_wire
);
14318 = (char *) xmalloc (STRING_BYTES (XSTRING (Vinvocation_name
))
14319 + STRING_BYTES (XSTRING (Vsystem_name
))
14321 sprintf (dpyinfo
->x_id_name
, "%s@%s",
14322 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
14324 /* Figure out which modifier bits mean what. */
14325 x_find_modifier_meanings (dpyinfo
);
14327 /* Get the scroll bar cursor. */
14328 dpyinfo
->vertical_scroll_bar_cursor
14329 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
14331 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
14332 resource_name
, EMACS_CLASS
);
14333 #ifdef HAVE_XRMSETDATABASE
14334 XrmSetDatabase (dpyinfo
->display
, xrdb
);
14336 dpyinfo
->display
->db
= xrdb
;
14338 /* Put the rdb where we can find it in a way that works on
14340 dpyinfo
->xrdb
= xrdb
;
14342 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
14343 DefaultScreen (dpyinfo
->display
));
14344 select_visual (dpyinfo
);
14345 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
14346 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
14347 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
14348 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
14349 dpyinfo
->grabbed
= 0;
14350 dpyinfo
->reference_count
= 0;
14351 dpyinfo
->icon_bitmap_id
= -1;
14352 dpyinfo
->font_table
= NULL
;
14353 dpyinfo
->n_fonts
= 0;
14354 dpyinfo
->font_table_size
= 0;
14355 dpyinfo
->bitmaps
= 0;
14356 dpyinfo
->bitmaps_size
= 0;
14357 dpyinfo
->bitmaps_last
= 0;
14358 dpyinfo
->scratch_cursor_gc
= 0;
14359 dpyinfo
->mouse_face_mouse_frame
= 0;
14360 dpyinfo
->mouse_face_deferred_gc
= 0;
14361 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
14362 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
14363 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
14364 dpyinfo
->mouse_face_window
= Qnil
;
14365 dpyinfo
->mouse_face_overlay
= Qnil
;
14366 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
14367 dpyinfo
->mouse_face_defer
= 0;
14368 dpyinfo
->x_focus_frame
= 0;
14369 dpyinfo
->x_focus_event_frame
= 0;
14370 dpyinfo
->x_highlight_frame
= 0;
14371 dpyinfo
->image_cache
= make_image_cache ();
14373 /* See if a private colormap is requested. */
14374 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
14376 if (dpyinfo
->visual
->class == PseudoColor
)
14379 value
= display_x_get_resource (dpyinfo
,
14380 build_string ("privateColormap"),
14381 build_string ("PrivateColormap"),
14383 if (STRINGP (value
)
14384 && (!strcmp (XSTRING (value
)->data
, "true")
14385 || !strcmp (XSTRING (value
)->data
, "on")))
14386 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
14390 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
14391 dpyinfo
->visual
, AllocNone
);
14394 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
14395 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
14396 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
14397 dpyinfo
->resy
= pixels
* 25.4 / mm
;
14398 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
14399 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
14400 dpyinfo
->resx
= pixels
* 25.4 / mm
;
14403 dpyinfo
->Xatom_wm_protocols
14404 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
14405 dpyinfo
->Xatom_wm_take_focus
14406 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
14407 dpyinfo
->Xatom_wm_save_yourself
14408 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
14409 dpyinfo
->Xatom_wm_delete_window
14410 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
14411 dpyinfo
->Xatom_wm_change_state
14412 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
14413 dpyinfo
->Xatom_wm_configure_denied
14414 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
14415 dpyinfo
->Xatom_wm_window_moved
14416 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
14417 dpyinfo
->Xatom_editres
14418 = XInternAtom (dpyinfo
->display
, "Editres", False
);
14419 dpyinfo
->Xatom_CLIPBOARD
14420 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
14421 dpyinfo
->Xatom_TIMESTAMP
14422 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
14423 dpyinfo
->Xatom_TEXT
14424 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
14425 dpyinfo
->Xatom_COMPOUND_TEXT
14426 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
14427 dpyinfo
->Xatom_DELETE
14428 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
14429 dpyinfo
->Xatom_MULTIPLE
14430 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
14431 dpyinfo
->Xatom_INCR
14432 = XInternAtom (dpyinfo
->display
, "INCR", False
);
14433 dpyinfo
->Xatom_EMACS_TMP
14434 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
14435 dpyinfo
->Xatom_TARGETS
14436 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
14437 dpyinfo
->Xatom_NULL
14438 = XInternAtom (dpyinfo
->display
, "NULL", False
);
14439 dpyinfo
->Xatom_ATOM_PAIR
14440 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
14441 /* For properties of font. */
14442 dpyinfo
->Xatom_PIXEL_SIZE
14443 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
14444 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
14445 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
14446 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
14447 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
14448 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
14449 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
14451 /* Ghostscript support. */
14452 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
14453 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
14455 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
14458 dpyinfo
->cut_buffers_initialized
= 0;
14460 connection
= ConnectionNumber (dpyinfo
->display
);
14461 dpyinfo
->connection
= connection
;
14466 null_bits
[0] = 0x00;
14468 dpyinfo
->null_pixel
14469 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
14470 null_bits
, 1, 1, (long) 0, (long) 0,
14475 extern int gray_bitmap_width
, gray_bitmap_height
;
14476 extern char *gray_bitmap_bits
;
14478 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
14480 gray_bitmap_width
, gray_bitmap_height
,
14481 (unsigned long) 1, (unsigned long) 0, 1);
14485 xim_initialize (dpyinfo
, resource_name
);
14488 #ifdef subprocesses
14489 /* This is only needed for distinguishing keyboard and process input. */
14490 if (connection
!= 0)
14491 add_keyboard_wait_descriptor (connection
);
14494 #ifndef F_SETOWN_BUG
14496 #ifdef F_SETOWN_SOCK_NEG
14497 /* stdin is a socket here */
14498 fcntl (connection
, F_SETOWN
, -getpid ());
14499 #else /* ! defined (F_SETOWN_SOCK_NEG) */
14500 fcntl (connection
, F_SETOWN
, getpid ());
14501 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
14502 #endif /* ! defined (F_SETOWN) */
14503 #endif /* F_SETOWN_BUG */
14506 if (interrupt_input
)
14507 init_sigio (connection
);
14508 #endif /* ! defined (SIGIO) */
14511 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
14512 /* Make sure that we have a valid font for dialog boxes
14513 so that Xt does not crash. */
14515 Display
*dpy
= dpyinfo
->display
;
14516 XrmValue d
, fr
, to
;
14520 d
.addr
= (XPointer
)&dpy
;
14521 d
.size
= sizeof (Display
*);
14522 fr
.addr
= XtDefaultFont
;
14523 fr
.size
= sizeof (XtDefaultFont
);
14524 to
.size
= sizeof (Font
*);
14525 to
.addr
= (XPointer
)&font
;
14526 count
= x_catch_errors (dpy
);
14527 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
14529 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
14530 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
14531 x_uncatch_errors (dpy
, count
);
14536 /* See if we should run in synchronous mode. This is useful
14537 for debugging X code. */
14540 value
= display_x_get_resource (dpyinfo
,
14541 build_string ("synchronous"),
14542 build_string ("Synchronous"),
14544 if (STRINGP (value
)
14545 && (!strcmp (XSTRING (value
)->data
, "true")
14546 || !strcmp (XSTRING (value
)->data
, "on")))
14547 XSynchronize (dpyinfo
->display
, True
);
14555 /* Get rid of display DPYINFO, assuming all frames are already gone,
14556 and without sending any more commands to the X server. */
14559 x_delete_display (dpyinfo
)
14560 struct x_display_info
*dpyinfo
;
14562 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
14564 /* Discard this display from x_display_name_list and x_display_list.
14565 We can't use Fdelq because that can quit. */
14566 if (! NILP (x_display_name_list
)
14567 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
14568 x_display_name_list
= XCDR (x_display_name_list
);
14573 tail
= x_display_name_list
;
14574 while (CONSP (tail
) && CONSP (XCDR (tail
)))
14576 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
14578 XSETCDR (tail
, XCDR (XCDR (tail
)));
14581 tail
= XCDR (tail
);
14585 if (next_noop_dpyinfo
== dpyinfo
)
14586 next_noop_dpyinfo
= dpyinfo
->next
;
14588 if (x_display_list
== dpyinfo
)
14589 x_display_list
= dpyinfo
->next
;
14592 struct x_display_info
*tail
;
14594 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
14595 if (tail
->next
== dpyinfo
)
14596 tail
->next
= tail
->next
->next
;
14599 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
14600 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
14601 XrmDestroyDatabase (dpyinfo
->xrdb
);
14604 #ifdef MULTI_KBOARD
14605 if (--dpyinfo
->kboard
->reference_count
== 0)
14606 delete_kboard (dpyinfo
->kboard
);
14610 xim_close_dpy (dpyinfo
);
14613 xfree (dpyinfo
->font_table
);
14614 xfree (dpyinfo
->x_id_name
);
14615 xfree (dpyinfo
->color_cells
);
14620 /* Set up use of X before we make the first connection. */
14622 static struct redisplay_interface x_redisplay_interface
=
14627 x_clear_end_of_line
,
14629 x_after_update_window_line
,
14630 x_update_window_begin
,
14631 x_update_window_end
,
14634 x_clear_mouse_face
,
14635 x_get_glyph_overhangs
,
14636 x_fix_overlapping_area
14642 rif
= &x_redisplay_interface
;
14644 clear_frame_hook
= x_clear_frame
;
14645 ins_del_lines_hook
= x_ins_del_lines
;
14646 delete_glyphs_hook
= x_delete_glyphs
;
14647 ring_bell_hook
= XTring_bell
;
14648 reset_terminal_modes_hook
= XTreset_terminal_modes
;
14649 set_terminal_modes_hook
= XTset_terminal_modes
;
14650 update_begin_hook
= x_update_begin
;
14651 update_end_hook
= x_update_end
;
14652 set_terminal_window_hook
= XTset_terminal_window
;
14653 read_socket_hook
= XTread_socket
;
14654 frame_up_to_date_hook
= XTframe_up_to_date
;
14655 mouse_position_hook
= XTmouse_position
;
14656 frame_rehighlight_hook
= XTframe_rehighlight
;
14657 frame_raise_lower_hook
= XTframe_raise_lower
;
14658 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
14659 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
14660 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
14661 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
14662 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
14664 scroll_region_ok
= 1; /* we'll scroll partial frames */
14665 char_ins_del_ok
= 1;
14666 line_ins_del_ok
= 1; /* we'll just blt 'em */
14667 fast_clear_end_of_line
= 1; /* X does this well */
14668 memory_below_frame
= 0; /* we don't remember what scrolls
14673 last_tool_bar_item
= -1;
14674 any_help_event_p
= 0;
14676 /* Try to use interrupt input; if we can't, then start polling. */
14677 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
14679 #ifdef USE_X_TOOLKIT
14680 XtToolkitInitialize ();
14682 Xt_app_con
= XtCreateApplicationContext ();
14684 /* Register a converter from strings to pixels, which uses
14685 Emacs' color allocation infrastructure. */
14686 XtAppSetTypeConverter (Xt_app_con
,
14687 XtRString
, XtRPixel
, cvt_string_to_pixel
,
14688 cvt_string_to_pixel_args
,
14689 XtNumber (cvt_string_to_pixel_args
),
14690 XtCacheByDisplay
, cvt_pixel_dtor
);
14692 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
14694 /* Install an asynchronous timer that processes Xt timeout events
14695 every 0.1s. This is necessary because some widget sets use
14696 timeouts internally, for example the LessTif menu bar, or the
14697 Xaw3d scroll bar. When Xt timouts aren't processed, these
14698 widgets don't behave normally. */
14700 EMACS_TIME interval
;
14701 EMACS_SET_SECS_USECS (interval
, 0, 100000);
14702 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
14706 #ifdef USE_TOOLKIT_SCROLL_BARS
14707 xaw3d_arrow_scroll
= False
;
14708 xaw3d_pick_top
= True
;
14711 /* Note that there is no real way portable across R3/R4 to get the
14712 original error handler. */
14713 XSetErrorHandler (x_error_handler
);
14714 XSetIOErrorHandler (x_io_error_quitter
);
14716 /* Disable Window Change signals; they are handled by X events. */
14718 signal (SIGWINCH
, SIG_DFL
);
14719 #endif /* ! defined (SIGWINCH) */
14721 signal (SIGPIPE
, x_connection_signal
);
14728 staticpro (&x_error_message_string
);
14729 x_error_message_string
= Qnil
;
14731 staticpro (&x_display_name_list
);
14732 x_display_name_list
= Qnil
;
14734 staticpro (&last_mouse_scroll_bar
);
14735 last_mouse_scroll_bar
= Qnil
;
14737 staticpro (&Qvendor_specific_keysyms
);
14738 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
14740 staticpro (&last_mouse_press_frame
);
14741 last_mouse_press_frame
= Qnil
;
14744 staticpro (&help_echo
);
14745 help_echo_object
= Qnil
;
14746 staticpro (&help_echo_object
);
14747 help_echo_window
= Qnil
;
14748 staticpro (&help_echo_window
);
14749 previous_help_echo
= Qnil
;
14750 staticpro (&previous_help_echo
);
14751 help_echo_pos
= -1;
14753 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
14754 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
14755 For example, if a block cursor is over a tab, it will be drawn as
14756 wide as that tab on the display. */);
14757 x_stretch_cursor_p
= 0;
14759 DEFVAR_BOOL ("x-use-underline-position-properties",
14760 &x_use_underline_position_properties
,
14761 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
14762 Nil means ignore them. If you encounter fonts with bogus
14763 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
14764 to 4.1, set this to nil. */);
14765 x_use_underline_position_properties
= 1;
14767 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
14768 doc
: /* What X toolkit scroll bars Emacs uses.
14769 A value of nil means Emacs doesn't use X toolkit scroll bars.
14770 Otherwise, value is a symbol describing the X toolkit. */);
14771 #ifdef USE_TOOLKIT_SCROLL_BARS
14773 Vx_toolkit_scroll_bars
= intern ("motif");
14774 #elif defined HAVE_XAW3D
14775 Vx_toolkit_scroll_bars
= intern ("xaw3d");
14777 Vx_toolkit_scroll_bars
= intern ("xaw");
14780 Vx_toolkit_scroll_bars
= Qnil
;
14783 staticpro (&last_mouse_motion_frame
);
14784 last_mouse_motion_frame
= Qnil
;
14787 #endif /* HAVE_X_WINDOWS */