1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 93, 94, 95, 96, 1997, 1998, 1999, 2000
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"
88 #include "intervals.h"
93 #include <X11/Shell.h>
96 #ifdef HAVE_SYS_TIME_H
105 extern void free_frame_menubar
P_ ((struct frame
*));
106 extern struct frame
*x_menubar_window_to_frame
P_ ((struct x_display_info
*,
109 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
111 extern void _XEditResCheckMessages ();
112 #endif /* not NO_EDITRES */
114 /* Include toolkit specific headers for the scroll bar widget. */
116 #ifdef USE_TOOLKIT_SCROLL_BARS
117 #if defined USE_MOTIF
118 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
119 #include <Xm/ScrollBar.h>
120 #include <Xm/ScrollBarP.h>
121 #else /* !USE_MOTIF i.e. use Xaw */
124 #include <X11/Xaw3d/Simple.h>
125 #include <X11/Xaw3d/Scrollbar.h>
126 #define ARROW_SCROLLBAR
127 #include <X11/Xaw3d/ScrollbarP.h>
128 #else /* !HAVE_XAW3D */
129 #include <X11/Xaw/Simple.h>
130 #include <X11/Xaw/Scrollbar.h>
131 #endif /* !HAVE_XAW3D */
133 #define XtNpickTop "pickTop"
134 #endif /* !XtNpickTop */
135 #endif /* !USE_MOTIF */
136 #endif /* USE_TOOLKIT_SCROLL_BARS */
138 #endif /* USE_X_TOOLKIT */
140 #ifndef USE_X_TOOLKIT
141 #define x_any_window_to_frame x_window_to_frame
142 #define x_top_window_to_frame x_window_to_frame
147 #ifndef XtNinitialState
148 #define XtNinitialState "initialState"
153 #define min(a,b) ((a) < (b) ? (a) : (b))
156 #define max(a,b) ((a) > (b) ? (a) : (b))
159 #define abs(x) ((x) < 0 ? -(x) : (x))
161 #define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER))
164 /* Bitmaps for truncated lines. */
169 LEFT_TRUNCATION_BITMAP
,
170 RIGHT_TRUNCATION_BITMAP
,
171 OVERLAY_ARROW_BITMAP
,
172 CONTINUED_LINE_BITMAP
,
173 CONTINUATION_LINE_BITMAP
,
177 /* Bitmap drawn to indicate lines not displaying text if
178 `indicate-empty-lines' is non-nil. */
182 static unsigned char zv_bits
[] = {
183 0x00, 0x00, 0x1e, 0x1e, 0x1e, 0x1e, 0x00, 0x00};
185 /* An arrow like this: `<-'. */
188 #define left_height 8
189 static unsigned char left_bits
[] = {
190 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
192 /* Right truncation arrow bitmap `->'. */
194 #define right_width 8
195 #define right_height 8
196 static unsigned char right_bits
[] = {
197 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
199 /* Marker for continued lines. */
201 #define continued_width 8
202 #define continued_height 8
203 static unsigned char continued_bits
[] = {
204 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
206 /* Marker for continuation lines. */
208 #define continuation_width 8
209 #define continuation_height 8
210 static unsigned char continuation_bits
[] = {
211 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
213 /* Overlay arrow bitmap. */
219 static unsigned char ov_bits
[] = {
220 0x30, 0x08, 0x3c, 0x7e, 0x7a, 0x7a, 0x62, 0x3c};
222 /* A triangular arrow. */
225 static unsigned char ov_bits
[] = {
226 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
230 extern Lisp_Object Qhelp_echo
;
233 /* Non-zero means Emacs uses toolkit scroll bars. */
235 int x_toolkit_scroll_bars_p
;
237 /* If a string, XTread_socket generates an event to display that string.
238 (The display is done in read_char.) */
240 static Lisp_Object help_echo
;
241 static Lisp_Object help_echo_window
;
242 static Lisp_Object help_echo_object
;
243 static int help_echo_pos
;
245 /* Temporary variable for XTread_socket. */
247 static Lisp_Object previous_help_echo
;
249 /* Non-zero means that a HELP_EVENT has been generated since Emacs
252 static int any_help_event_p
;
254 /* Non-zero means draw block and hollow cursor as wide as the glyph
255 under it. For example, if a block cursor is over a tab, it will be
256 drawn as wide as that tab on the display. */
258 int x_stretch_cursor_p
;
260 /* This is a chain of structures for all the X displays currently in
263 struct x_display_info
*x_display_list
;
265 /* This is a list of cons cells, each of the form (NAME
266 . FONT-LIST-CACHE), one for each element of x_display_list and in
267 the same order. NAME is the name of the frame. FONT-LIST-CACHE
268 records previous values returned by x-list-fonts. */
270 Lisp_Object x_display_name_list
;
272 /* Frame being updated by update_frame. This is declared in term.c.
273 This is set by update_begin and looked at by all the XT functions.
274 It is zero while not inside an update. In that case, the XT
275 functions assume that `selected_frame' is the frame to apply to. */
277 extern struct frame
*updating_frame
;
279 extern int waiting_for_input
;
281 /* This is a frame waiting to be auto-raised, within XTread_socket. */
283 struct frame
*pending_autoraise_frame
;
286 /* The application context for Xt use. */
287 XtAppContext Xt_app_con
;
288 static String Xt_default_resources
[] = {0};
289 #endif /* USE_X_TOOLKIT */
291 /* Nominal cursor position -- where to draw output.
292 HPOS and VPOS are window relative glyph matrix coordinates.
293 X and Y are window relative pixel coordinates. */
295 struct cursor_pos output_cursor
;
297 /* Non-zero means user is interacting with a toolkit scroll bar. */
299 static int toolkit_scroll_bar_interaction
;
303 Formerly, we used PointerMotionHintMask (in standard_event_mask)
304 so that we would have to call XQueryPointer after each MotionNotify
305 event to ask for another such event. However, this made mouse tracking
306 slow, and there was a bug that made it eventually stop.
308 Simply asking for MotionNotify all the time seems to work better.
310 In order to avoid asking for motion events and then throwing most
311 of them away or busy-polling the server for mouse positions, we ask
312 the server for pointer motion hints. This means that we get only
313 one event per group of mouse movements. "Groups" are delimited by
314 other kinds of events (focus changes and button clicks, for
315 example), or by XQueryPointer calls; when one of these happens, we
316 get another MotionNotify event the next time the mouse moves. This
317 is at least as efficient as getting motion events when mouse
318 tracking is on, and I suspect only negligibly worse when tracking
321 /* Where the mouse was last time we reported a mouse event. */
323 FRAME_PTR last_mouse_frame
;
324 static XRectangle last_mouse_glyph
;
325 static Lisp_Object last_mouse_press_frame
;
327 /* The scroll bar in which the last X motion event occurred.
329 If the last X motion event occurred in a scroll bar, we set this so
330 XTmouse_position can know whether to report a scroll bar motion or
333 If the last X motion event didn't occur in a scroll bar, we set
334 this to Qnil, to tell XTmouse_position to return an ordinary motion
337 static Lisp_Object last_mouse_scroll_bar
;
339 /* This is a hack. We would really prefer that XTmouse_position would
340 return the time associated with the position it returns, but there
341 doesn't seem to be any way to wrest the time-stamp from the server
342 along with the position query. So, we just keep track of the time
343 of the last movement we received, and return that in hopes that
344 it's somewhat accurate. */
346 static Time last_mouse_movement_time
;
348 /* Incremented by XTread_socket whenever it really tries to read
352 static int volatile input_signal_count
;
354 static int input_signal_count
;
357 /* Used locally within XTread_socket. */
359 static int x_noop_count
;
361 /* Initial values of argv and argc. */
363 extern char **initial_argv
;
364 extern int initial_argc
;
366 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
368 /* Tells if a window manager is present or not. */
370 extern Lisp_Object Vx_no_window_manager
;
372 extern Lisp_Object Qface
, Qmouse_face
;
376 /* A mask of extra modifier bits to put into every keyboard char. */
378 extern int extra_keyboard_modifiers
;
380 static Lisp_Object Qvendor_specific_keysyms
;
382 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
383 extern Lisp_Object x_icon_type
P_ ((struct frame
*));
386 /* Enumeration for overriding/changing the face to use for drawing
387 glyphs in x_draw_glyphs. */
389 enum draw_glyphs_face
399 static const XColor
*x_color_cells
P_ ((struct frame
*, 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 *,
407 static void set_output_cursor
P_ ((struct cursor_pos
*));
408 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
409 int *, int *, int *));
410 static void note_mode_line_highlight
P_ ((struct window
*, int, int));
411 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
412 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
413 static void x_handle_tool_bar_click
P_ ((struct frame
*, XButtonEvent
*));
414 static void show_mouse_face
P_ ((struct x_display_info
*,
415 enum draw_glyphs_face
));
416 static int x_io_error_quitter
P_ ((Display
*));
417 int x_catch_errors
P_ ((Display
*));
418 void x_uncatch_errors
P_ ((Display
*, int));
419 void x_lower_frame
P_ ((struct frame
*));
420 void x_scroll_bar_clear
P_ ((struct frame
*));
421 int x_had_errors_p
P_ ((Display
*));
422 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
423 void x_raise_frame
P_ ((struct frame
*));
424 void x_set_window_size
P_ ((struct frame
*, int, int, int));
425 void x_wm_set_window_state
P_ ((struct frame
*, int));
426 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
427 void x_initialize
P_ ((void));
428 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
429 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
430 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
432 enum draw_glyphs_face
));
433 static void x_update_end
P_ ((struct frame
*));
434 static void XTframe_up_to_date
P_ ((struct frame
*));
435 static void XTreassert_line_highlight
P_ ((int, int));
436 static void x_change_line_highlight
P_ ((int, int, int, int));
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 void expose_window_tree
P_ ((struct window
*, XRectangle
*));
455 static void 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 void 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_bitmap
P_ ((struct window
*, struct glyph_row
*,
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_bitmaps
P_ ((struct window
*, struct glyph_row
*));
471 static void note_overwritten_text_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
*));
481 /* Flush display of frame F, or of all frames if F is null. */
490 Lisp_Object rest
, frame
;
491 FOR_EACH_FRAME (rest
, frame
)
492 x_flush (XFRAME (frame
));
494 else if (FRAME_X_P (f
))
495 XFlush (FRAME_X_DISPLAY (f
));
500 /* Remove calls to XFlush by defining XFlush to an empty replacement.
501 Calls to XFlush should be unnecessary because the X output buffer
502 is flushed automatically as needed by calls to XPending,
503 XNextEvent, or XWindowEvent according to the XFlush man page.
504 XTread_socket calls XPending. Removing XFlush improves
507 #define XFlush(DISPLAY) (void) 0
510 /***********************************************************************
512 ***********************************************************************/
516 /* This is a function useful for recording debugging information about
517 the sequence of occurrences in this file. */
525 struct record event_record
[100];
527 int event_record_index
;
529 record_event (locus
, type
)
533 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
534 event_record_index
= 0;
536 event_record
[event_record_index
].locus
= locus
;
537 event_record
[event_record_index
].type
= type
;
538 event_record_index
++;
545 /* Return the struct x_display_info corresponding to DPY. */
547 struct x_display_info
*
548 x_display_info_for_display (dpy
)
551 struct x_display_info
*dpyinfo
;
553 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
554 if (dpyinfo
->display
== dpy
)
562 /***********************************************************************
563 Starting and ending an update
564 ***********************************************************************/
566 /* Start an update of frame F. This function is installed as a hook
567 for update_begin, i.e. it is called when update_begin is called.
568 This function is called prior to calls to x_update_window_begin for
569 each window being updated. Currently, there is nothing to do here
570 because all interesting stuff is done on a window basis. */
580 /* Start update of window W. Set the global variable updated_window
581 to the window being updated and set output_cursor to the cursor
585 x_update_window_begin (w
)
588 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
589 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
592 set_output_cursor (&w
->cursor
);
596 if (f
== display_info
->mouse_face_mouse_frame
)
598 /* Don't do highlighting for mouse motion during the update. */
599 display_info
->mouse_face_defer
= 1;
601 /* If F needs to be redrawn, simply forget about any prior mouse
603 if (FRAME_GARBAGED_P (f
))
604 display_info
->mouse_face_window
= Qnil
;
606 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
607 their mouse_face_p flag set, which means that they are always
608 unequal to rows in a desired matrix which never have that
609 flag set. So, rows containing mouse-face glyphs are never
610 scrolled, and we don't have to switch the mouse highlight off
611 here to prevent it from being scrolled. */
613 /* Can we tell that this update does not affect the window
614 where the mouse highlight is? If so, no need to turn off.
615 Likewise, don't do anything if the frame is garbaged;
616 in that case, the frame's current matrix that we would use
617 is all wrong, and we will redisplay that line anyway. */
618 if (!NILP (display_info
->mouse_face_window
)
619 && w
== XWINDOW (display_info
->mouse_face_window
))
623 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
624 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
627 if (i
< w
->desired_matrix
->nrows
)
628 clear_mouse_face (display_info
);
637 /* Draw a vertical window border to the right of window W if W doesn't
638 have vertical scroll bars. */
641 x_draw_vertical_border (w
)
644 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
646 /* Redraw borders between horizontally adjacent windows. Don't
647 do it for frames with vertical scroll bars because either the
648 right scroll bar of a window, or the left scroll bar of its
649 neighbor will suffice as a border. */
650 if (!WINDOW_RIGHTMOST_P (w
)
651 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
655 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
656 x1
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
);
659 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
660 f
->output_data
.x
->normal_gc
, x1
, y0
, x1
, y1
);
665 /* End update of window W (which is equal to updated_window).
667 Draw vertical borders between horizontally adjacent windows, and
668 display W's cursor if CURSOR_ON_P is non-zero.
670 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
671 glyphs in mouse-face were overwritten. In that case we have to
672 make sure that the mouse-highlight is properly redrawn.
674 W may be a menu bar pseudo-window in case we don't have X toolkit
675 support. Such windows don't have a cursor, so don't display it
679 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
681 int cursor_on_p
, mouse_face_overwritten_p
;
683 if (!w
->pseudo_window_p
)
685 struct x_display_info
*dpyinfo
686 = FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
690 /* If a row with mouse-face was overwritten, arrange for
691 XTframe_up_to_date to redisplay the mouse highlight. */
692 if (mouse_face_overwritten_p
)
694 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
695 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
696 dpyinfo
->mouse_face_window
= Qnil
;
700 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
702 output_cursor
.x
, output_cursor
.y
);
704 x_draw_vertical_border (w
);
708 updated_window
= NULL
;
712 /* End update of frame F. This function is installed as a hook in
719 /* Mouse highlight may be displayed again. */
720 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
723 XFlush (FRAME_X_DISPLAY (f
));
728 /* This function is called from various places in xdisp.c whenever a
729 complete update has been performed. The global variable
730 updated_window is not available here. */
733 XTframe_up_to_date (f
)
738 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
740 if (dpyinfo
->mouse_face_deferred_gc
741 || f
== dpyinfo
->mouse_face_mouse_frame
)
744 if (dpyinfo
->mouse_face_mouse_frame
)
745 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
746 dpyinfo
->mouse_face_mouse_x
,
747 dpyinfo
->mouse_face_mouse_y
);
748 dpyinfo
->mouse_face_deferred_gc
= 0;
755 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
756 arrow bitmaps, or clear the areas where they would be displayed
757 before DESIRED_ROW is made current. The window being updated is
758 found in updated_window. This function It is called from
759 update_window_line only if it is known that there are differences
760 between bitmaps to be drawn between current row and DESIRED_ROW. */
763 x_after_update_window_line (desired_row
)
764 struct glyph_row
*desired_row
;
766 struct window
*w
= updated_window
;
770 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
773 x_draw_row_bitmaps (w
, desired_row
);
775 /* When a window has disappeared, make sure that no rest of
776 full-width rows stays visible in the internal border. */
777 if (windows_or_buffers_changed
)
779 struct frame
*f
= XFRAME (w
->frame
);
780 int width
= FRAME_INTERNAL_BORDER_WIDTH (f
);
781 int height
= desired_row
->visible_height
;
782 int x
= (window_box_right (w
, -1)
783 + FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
));
784 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
786 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
787 x
, y
, width
, height
, False
);
795 /* Draw the bitmap WHICH in one of the areas to the left or right of
796 window W. ROW is the glyph row for which to display the bitmap; it
797 determines the vertical position at which the bitmap has to be
801 x_draw_bitmap (w
, row
, which
)
803 struct glyph_row
*row
;
804 enum bitmap_type which
;
806 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
807 Display
*display
= FRAME_X_DISPLAY (f
);
808 Window window
= FRAME_X_WINDOW (f
);
812 GC gc
= f
->output_data
.x
->normal_gc
;
814 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
816 /* Must clip because of partially visible lines. */
817 x_clip_to_row (w
, row
, gc
, 1);
821 case LEFT_TRUNCATION_BITMAP
:
825 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
827 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
830 case OVERLAY_ARROW_BITMAP
:
834 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
836 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
839 case RIGHT_TRUNCATION_BITMAP
:
843 x
= window_box_right (w
, -1);
844 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
847 case CONTINUED_LINE_BITMAP
:
850 bits
= continued_bits
;
851 x
= window_box_right (w
, -1);
852 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
855 case CONTINUATION_LINE_BITMAP
:
856 wd
= continuation_width
;
857 h
= continuation_height
;
858 bits
= continuation_bits
;
859 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
861 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
868 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
870 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
877 /* Convert to frame coordinates. Set dy to the offset in the row to
878 start drawing the bitmap. */
879 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
880 dy
= (row
->height
- h
) / 2;
882 /* Draw the bitmap. I believe these small pixmaps can be cached
884 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
885 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, wd
, h
,
887 face
->background
, depth
);
888 XCopyArea (display
, pixmap
, window
, gc
, 0, 0, wd
, h
, x
, y
+ dy
);
889 XFreePixmap (display
, pixmap
);
890 XSetClipMask (display
, gc
, None
);
894 /* Draw flags bitmaps for glyph row ROW on window W. Call this
895 function with input blocked. */
898 x_draw_row_bitmaps (w
, row
)
900 struct glyph_row
*row
;
902 struct frame
*f
= XFRAME (w
->frame
);
903 enum bitmap_type bitmap
;
905 int header_line_height
= -1;
907 xassert (interrupt_input_blocked
);
909 /* If row is completely invisible, because of vscrolling, we
910 don't have to draw anything. */
911 if (row
->visible_height
<= 0)
914 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
915 PREPARE_FACE_FOR_DISPLAY (f
, face
);
917 /* Decide which bitmap to draw at the left side. */
918 if (row
->overlay_arrow_p
)
919 bitmap
= OVERLAY_ARROW_BITMAP
;
920 else if (row
->truncated_on_left_p
)
921 bitmap
= LEFT_TRUNCATION_BITMAP
;
922 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
923 bitmap
= CONTINUATION_LINE_BITMAP
;
924 else if (row
->indicate_empty_line_p
)
925 bitmap
= ZV_LINE_BITMAP
;
929 /* Clear flags area if no bitmap to draw or if bitmap doesn't fill
931 if (bitmap
== NO_BITMAP
932 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
933 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
935 /* If W has a vertical border to its left, don't draw over it. */
936 int border
= ((XFASTINT (w
->left
) > 0
937 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
939 int left
= window_box_left (w
, -1);
941 if (header_line_height
< 0)
942 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
944 /* In case the same realized face is used for bitmap areas and
945 for something displayed in the text (e.g. face `region' on
946 mono-displays, the fill style may have been changed to
947 FillSolid in x_draw_glyph_string_background. */
949 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
951 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
953 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
956 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
958 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
960 FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - border
,
961 row
->visible_height
);
963 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
966 /* Draw the left bitmap. */
967 if (bitmap
!= NO_BITMAP
)
968 x_draw_bitmap (w
, row
, bitmap
);
970 /* Decide which bitmap to draw at the right side. */
971 if (row
->truncated_on_right_p
)
972 bitmap
= RIGHT_TRUNCATION_BITMAP
;
973 else if (row
->continued_p
)
974 bitmap
= CONTINUED_LINE_BITMAP
;
978 /* Clear flags area if no bitmap to draw of if bitmap doesn't fill
980 if (bitmap
== NO_BITMAP
981 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
)
982 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
984 int right
= window_box_right (w
, -1);
986 if (header_line_height
< 0)
987 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
989 /* In case the same realized face is used for bitmap areas and
990 for something displayed in the text (e.g. face `region' on
991 mono-displays, the fill style may have been changed to
992 FillSolid in x_draw_glyph_string_background. */
994 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
996 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
997 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1000 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
1002 FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
),
1003 row
->visible_height
);
1005 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
1008 /* Draw the right bitmap. */
1009 if (bitmap
!= NO_BITMAP
)
1010 x_draw_bitmap (w
, row
, bitmap
);
1014 /***********************************************************************
1016 ***********************************************************************/
1018 /* External interface to control of standout mode. Not used for X
1019 frames. Aborts when called. */
1022 XTreassert_line_highlight (new, vpos
)
1029 /* Call this when about to modify line at position VPOS and change
1030 whether it is highlighted. Not used for X frames. Aborts when
1034 x_change_line_highlight (new_highlight
, vpos
, y
, first_unused_hpos
)
1035 int new_highlight
, vpos
, y
, first_unused_hpos
;
1041 /* This is called when starting Emacs and when restarting after
1042 suspend. When starting Emacs, no X window is mapped. And nothing
1043 must be done to Emacs's own window if it is suspended (though that
1047 XTset_terminal_modes ()
1051 /* This is called when exiting or suspending Emacs. Exiting will make
1052 the X-windows go away, and suspending requires no action. */
1055 XTreset_terminal_modes ()
1061 /***********************************************************************
1063 ***********************************************************************/
1065 /* Set the global variable output_cursor to CURSOR. All cursor
1066 positions are relative to updated_window. */
1069 set_output_cursor (cursor
)
1070 struct cursor_pos
*cursor
;
1072 output_cursor
.hpos
= cursor
->hpos
;
1073 output_cursor
.vpos
= cursor
->vpos
;
1074 output_cursor
.x
= cursor
->x
;
1075 output_cursor
.y
= cursor
->y
;
1079 /* Set a nominal cursor position.
1081 HPOS and VPOS are column/row positions in a window glyph matrix. X
1082 and Y are window text area relative pixel positions.
1084 If this is done during an update, updated_window will contain the
1085 window that is being updated and the position is the future output
1086 cursor position for that window. If updated_window is null, use
1087 selected_window and display the cursor at the given position. */
1090 XTcursor_to (vpos
, hpos
, y
, x
)
1091 int vpos
, hpos
, y
, x
;
1095 /* If updated_window is not set, work on selected_window. */
1099 w
= XWINDOW (selected_window
);
1101 /* Set the output cursor. */
1102 output_cursor
.hpos
= hpos
;
1103 output_cursor
.vpos
= vpos
;
1104 output_cursor
.x
= x
;
1105 output_cursor
.y
= y
;
1107 /* If not called as part of an update, really display the cursor.
1108 This will also set the cursor position of W. */
1109 if (updated_window
== NULL
)
1112 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
1113 XFlush (FRAME_X_DISPLAY (SELECTED_FRAME ()));
1120 /***********************************************************************
1122 ***********************************************************************/
1124 /* Function prototypes of this page. */
1126 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
1130 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
1131 int, XChar2b
*, int));
1132 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
1133 static void x_encode_char
P_ ((int, XChar2b
*, struct font_info
*));
1134 static void x_append_glyph
P_ ((struct it
*));
1135 static void x_append_composite_glyph
P_ ((struct it
*));
1136 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
1138 static void x_produce_glyphs
P_ ((struct it
*));
1139 static void x_produce_image_glyph
P_ ((struct it
*it
));
1142 /* Return a pointer to per-char metric information in FONT of a
1143 character pointed by B which is a pointer to an XChar2b. */
1145 #define PER_CHAR_METRIC(font, b) \
1147 ? ((font)->per_char + (b)->byte2 - (font)->min_char_or_byte2 \
1148 + (((font)->min_byte1 || (font)->max_byte1) \
1149 ? (((b)->byte1 - (font)->min_byte1) \
1150 * ((font)->max_char_or_byte2 - (font)->min_char_or_byte2 + 1)) \
1152 : &((font)->max_bounds))
1155 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
1156 is not contained in the font. */
1158 static INLINE XCharStruct
*
1159 x_per_char_metric (font
, char2b
)
1163 /* The result metric information. */
1164 XCharStruct
*pcm
= NULL
;
1166 xassert (font
&& char2b
);
1168 if (font
->per_char
!= NULL
)
1170 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
1172 /* min_char_or_byte2 specifies the linear character index
1173 corresponding to the first element of the per_char array,
1174 max_char_or_byte2 is the index of the last character. A
1175 character with non-zero CHAR2B->byte1 is not in the font.
1176 A character with byte2 less than min_char_or_byte2 or
1177 greater max_char_or_byte2 is not in the font. */
1178 if (char2b
->byte1
== 0
1179 && char2b
->byte2
>= font
->min_char_or_byte2
1180 && char2b
->byte2
<= font
->max_char_or_byte2
)
1181 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
1185 /* If either min_byte1 or max_byte1 are nonzero, both
1186 min_char_or_byte2 and max_char_or_byte2 are less than
1187 256, and the 2-byte character index values corresponding
1188 to the per_char array element N (counting from 0) are:
1190 byte1 = N/D + min_byte1
1191 byte2 = N\D + min_char_or_byte2
1195 D = max_char_or_byte2 - min_char_or_byte2 + 1
1196 / = integer division
1197 \ = integer modulus */
1198 if (char2b
->byte1
>= font
->min_byte1
1199 && char2b
->byte1
<= font
->max_byte1
1200 && char2b
->byte2
>= font
->min_char_or_byte2
1201 && char2b
->byte2
<= font
->max_char_or_byte2
)
1203 pcm
= (font
->per_char
1204 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
1205 * (char2b
->byte1
- font
->min_byte1
))
1206 + (char2b
->byte2
- font
->min_char_or_byte2
));
1212 /* If the per_char pointer is null, all glyphs between the first
1213 and last character indexes inclusive have the same
1214 information, as given by both min_bounds and max_bounds. */
1215 if (char2b
->byte2
>= font
->min_char_or_byte2
1216 && char2b
->byte2
<= font
->max_char_or_byte2
)
1217 pcm
= &font
->max_bounds
;
1220 return ((pcm
== NULL
1221 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
1226 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1227 the two-byte form of C. Encoding is returned in *CHAR2B. */
1230 x_encode_char (c
, char2b
, font_info
)
1233 struct font_info
*font_info
;
1235 int charset
= CHAR_CHARSET (c
);
1236 XFontStruct
*font
= font_info
->font
;
1238 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1239 This may be either a program in a special encoder language or a
1241 if (font_info
->font_encoder
)
1243 /* It's a program. */
1244 struct ccl_program
*ccl
= font_info
->font_encoder
;
1246 if (CHARSET_DIMENSION (charset
) == 1)
1248 ccl
->reg
[0] = charset
;
1249 ccl
->reg
[1] = char2b
->byte2
;
1253 ccl
->reg
[0] = charset
;
1254 ccl
->reg
[1] = char2b
->byte1
;
1255 ccl
->reg
[2] = char2b
->byte2
;
1258 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1260 /* We assume that MSBs are appropriately set/reset by CCL
1262 if (font
->max_byte1
== 0) /* 1-byte font */
1263 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
1265 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
1267 else if (font_info
->encoding
[charset
])
1269 /* Fixed encoding scheme. See fontset.h for the meaning of the
1270 encoding numbers. */
1271 int enc
= font_info
->encoding
[charset
];
1273 if ((enc
== 1 || enc
== 2)
1274 && CHARSET_DIMENSION (charset
) == 2)
1275 char2b
->byte1
|= 0x80;
1277 if (enc
== 1 || enc
== 3)
1278 char2b
->byte2
|= 0x80;
1283 /* Get face and two-byte form of character C in face FACE_ID on frame
1284 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1285 means we want to display multibyte text. Value is a pointer to a
1286 realized face that is ready for display. */
1288 static INLINE
struct face
*
1289 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
)
1295 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1299 /* Unibyte case. We don't have to encode, but we have to make
1300 sure to use a face suitable for unibyte. */
1303 face_id
= FACE_FOR_CHAR (f
, face
, c
);
1304 face
= FACE_FROM_ID (f
, face_id
);
1306 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1308 /* Case of ASCII in a face known to fit ASCII. */
1314 int c1
, c2
, charset
;
1316 /* Split characters into bytes. If c2 is -1 afterwards, C is
1317 really a one-byte character so that byte1 is zero. */
1318 SPLIT_CHAR (c
, charset
, c1
, c2
);
1320 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1322 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1324 /* Maybe encode the character in *CHAR2B. */
1325 if (face
->font
!= NULL
)
1327 struct font_info
*font_info
1328 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1330 x_encode_char (c
, char2b
, font_info
);
1334 /* Make sure X resources of the face are allocated. */
1335 xassert (face
!= NULL
);
1336 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1342 /* Get face and two-byte form of character glyph GLYPH on frame F.
1343 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
1344 a pointer to a realized face that is ready for display. */
1346 static INLINE
struct face
*
1347 x_get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
1349 struct glyph
*glyph
;
1355 xassert (glyph
->type
== CHAR_GLYPH
);
1356 face
= FACE_FROM_ID (f
, glyph
->face_id
);
1361 if (!glyph
->multibyte_p
)
1363 /* Unibyte case. We don't have to encode, but we have to make
1364 sure to use a face suitable for unibyte. */
1366 char2b
->byte2
= glyph
->u
.ch
;
1368 else if (glyph
->u
.ch
< 128
1369 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
1371 /* Case of ASCII in a face known to fit ASCII. */
1373 char2b
->byte2
= glyph
->u
.ch
;
1377 int c1
, c2
, charset
;
1379 /* Split characters into bytes. If c2 is -1 afterwards, C is
1380 really a one-byte character so that byte1 is zero. */
1381 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
1383 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1385 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1387 /* Maybe encode the character in *CHAR2B. */
1388 if (charset
!= CHARSET_ASCII
)
1390 struct font_info
*font_info
1391 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1394 x_encode_char (glyph
->u
.ch
, char2b
, font_info
);
1397 = ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
1402 /* Make sure X resources of the face are allocated. */
1403 xassert (face
!= NULL
);
1404 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1409 /* Store one glyph for IT->char_to_display in IT->glyph_row.
1410 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1416 struct glyph
*glyph
;
1417 enum glyph_row_area area
= it
->area
;
1419 xassert (it
->glyph_row
);
1420 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
1422 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1423 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1425 glyph
->charpos
= CHARPOS (it
->position
);
1426 glyph
->object
= it
->object
;
1427 glyph
->pixel_width
= it
->pixel_width
;
1428 glyph
->voffset
= it
->voffset
;
1429 glyph
->type
= CHAR_GLYPH
;
1430 glyph
->multibyte_p
= it
->multibyte_p
;
1431 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1432 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1433 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1434 || it
->phys_descent
> it
->descent
);
1435 glyph
->padding_p
= 0;
1436 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
1437 glyph
->face_id
= it
->face_id
;
1438 glyph
->u
.ch
= it
->char_to_display
;
1439 ++it
->glyph_row
->used
[area
];
1443 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
1444 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1447 x_append_composite_glyph (it
)
1450 struct glyph
*glyph
;
1451 enum glyph_row_area area
= it
->area
;
1453 xassert (it
->glyph_row
);
1455 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1456 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1458 glyph
->charpos
= CHARPOS (it
->position
);
1459 glyph
->object
= it
->object
;
1460 glyph
->pixel_width
= it
->pixel_width
;
1461 glyph
->voffset
= it
->voffset
;
1462 glyph
->type
= COMPOSITE_GLYPH
;
1463 glyph
->multibyte_p
= it
->multibyte_p
;
1464 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1465 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1466 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1467 || it
->phys_descent
> it
->descent
);
1468 glyph
->padding_p
= 0;
1469 glyph
->glyph_not_available_p
= 0;
1470 glyph
->face_id
= it
->face_id
;
1471 glyph
->u
.cmp_id
= it
->cmp_id
;
1472 ++it
->glyph_row
->used
[area
];
1477 /* Change IT->ascent and IT->height according to the setting of
1481 take_vertical_position_into_account (it
)
1486 if (it
->voffset
< 0)
1487 /* Increase the ascent so that we can display the text higher
1489 it
->ascent
+= abs (it
->voffset
);
1491 /* Increase the descent so that we can display the text lower
1493 it
->descent
+= it
->voffset
;
1498 /* Produce glyphs/get display metrics for the image IT is loaded with.
1499 See the description of struct display_iterator in dispextern.h for
1500 an overview of struct display_iterator. */
1503 x_produce_image_glyph (it
)
1509 xassert (it
->what
== IT_IMAGE
);
1511 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1512 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
1515 /* Make sure X resources of the face and image are loaded. */
1516 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1517 prepare_image_for_display (it
->f
, img
);
1519 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
1520 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->margin
- it
->ascent
;
1521 it
->pixel_width
= img
->width
+ 2 * img
->margin
;
1525 if (face
->box
!= FACE_NO_BOX
)
1527 it
->ascent
+= face
->box_line_width
;
1528 it
->descent
+= face
->box_line_width
;
1530 if (it
->start_of_box_run_p
)
1531 it
->pixel_width
+= face
->box_line_width
;
1532 if (it
->end_of_box_run_p
)
1533 it
->pixel_width
+= face
->box_line_width
;
1536 take_vertical_position_into_account (it
);
1540 struct glyph
*glyph
;
1541 enum glyph_row_area area
= it
->area
;
1543 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1544 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1546 glyph
->charpos
= CHARPOS (it
->position
);
1547 glyph
->object
= it
->object
;
1548 glyph
->pixel_width
= it
->pixel_width
;
1549 glyph
->voffset
= it
->voffset
;
1550 glyph
->type
= IMAGE_GLYPH
;
1551 glyph
->multibyte_p
= it
->multibyte_p
;
1552 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1553 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1554 glyph
->overlaps_vertically_p
= 0;
1555 glyph
->padding_p
= 0;
1556 glyph
->glyph_not_available_p
= 0;
1557 glyph
->face_id
= it
->face_id
;
1558 glyph
->u
.img_id
= img
->id
;
1559 ++it
->glyph_row
->used
[area
];
1565 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
1566 of the glyph, WIDTH and HEIGHT are the width and height of the
1567 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
1568 ascent of the glyph (0 <= ASCENT <= 1). */
1571 x_append_stretch_glyph (it
, object
, width
, height
, ascent
)
1577 struct glyph
*glyph
;
1578 enum glyph_row_area area
= it
->area
;
1580 xassert (ascent
>= 0 && ascent
<= 1);
1582 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1583 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1585 glyph
->charpos
= CHARPOS (it
->position
);
1586 glyph
->object
= object
;
1587 glyph
->pixel_width
= width
;
1588 glyph
->voffset
= it
->voffset
;
1589 glyph
->type
= STRETCH_GLYPH
;
1590 glyph
->multibyte_p
= it
->multibyte_p
;
1591 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1592 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1593 glyph
->overlaps_vertically_p
= 0;
1594 glyph
->padding_p
= 0;
1595 glyph
->glyph_not_available_p
= 0;
1596 glyph
->face_id
= it
->face_id
;
1597 glyph
->u
.stretch
.ascent
= height
* ascent
;
1598 glyph
->u
.stretch
.height
= height
;
1599 ++it
->glyph_row
->used
[area
];
1604 /* Produce a stretch glyph for iterator IT. IT->object is the value
1605 of the glyph property displayed. The value must be a list
1606 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1609 1. `:width WIDTH' specifies that the space should be WIDTH *
1610 canonical char width wide. WIDTH may be an integer or floating
1613 2. `:relative-width FACTOR' specifies that the width of the stretch
1614 should be computed from the width of the first character having the
1615 `glyph' property, and should be FACTOR times that width.
1617 3. `:align-to HPOS' specifies that the space should be wide enough
1618 to reach HPOS, a value in canonical character units.
1620 Exactly one of the above pairs must be present.
1622 4. `:height HEIGHT' specifies that the height of the stretch produced
1623 should be HEIGHT, measured in canonical character units.
1625 5. `:relative-height FACTOR' specifies that the height of the the
1626 stretch should be FACTOR times the height of the characters having
1629 Either none or exactly one of 4 or 5 must be present.
1631 6. `:ascent ASCENT' specifies that ASCENT percent of the height
1632 of the stretch should be used for the ascent of the stretch.
1633 ASCENT must be in the range 0 <= ASCENT <= 100. */
1636 ((INTEGERP (X) || FLOATP (X)) \
1642 x_produce_stretch_glyph (it
)
1645 /* (space :width WIDTH :height HEIGHT. */
1647 extern Lisp_Object Qspace
;
1649 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
1650 extern Lisp_Object QCrelative_width
, QCrelative_height
;
1651 extern Lisp_Object QCalign_to
;
1652 Lisp_Object prop
, plist
;
1653 double width
= 0, height
= 0, ascent
= 0;
1654 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1655 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
1657 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1659 /* List should start with `space'. */
1660 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1661 plist
= XCDR (it
->object
);
1663 /* Compute the width of the stretch. */
1664 if (prop
= Fplist_get (plist
, QCwidth
),
1666 /* Absolute width `:width WIDTH' specified and valid. */
1667 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
1668 else if (prop
= Fplist_get (plist
, QCrelative_width
),
1671 /* Relative width `:relative-width FACTOR' specified and valid.
1672 Compute the width of the characters having the `glyph'
1675 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
1678 if (it
->multibyte_p
)
1680 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
1681 - IT_BYTEPOS (*it
));
1682 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
1685 it2
.c
= *p
, it2
.len
= 1;
1687 it2
.glyph_row
= NULL
;
1688 it2
.what
= IT_CHARACTER
;
1689 x_produce_glyphs (&it2
);
1690 width
= NUMVAL (prop
) * it2
.pixel_width
;
1692 else if (prop
= Fplist_get (plist
, QCalign_to
),
1694 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
1696 /* Nothing specified -> width defaults to canonical char width. */
1697 width
= CANON_X_UNIT (it
->f
);
1699 /* Compute height. */
1700 if (prop
= Fplist_get (plist
, QCheight
),
1702 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
1703 else if (prop
= Fplist_get (plist
, QCrelative_height
),
1705 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
1707 height
= FONT_HEIGHT (font
);
1709 /* Compute percentage of height used for ascent. If
1710 `:ascent ASCENT' is present and valid, use that. Otherwise,
1711 derive the ascent from the font in use. */
1712 if (prop
= Fplist_get (plist
, QCascent
),
1713 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
1714 ascent
= NUMVAL (prop
) / 100.0;
1716 ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1725 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1726 if (!STRINGP (object
))
1727 object
= it
->w
->buffer
;
1728 x_append_stretch_glyph (it
, object
, width
, height
, ascent
);
1731 it
->pixel_width
= width
;
1732 it
->ascent
= it
->phys_ascent
= height
* ascent
;
1733 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
1736 if (face
->box
!= FACE_NO_BOX
)
1738 it
->ascent
+= face
->box_line_width
;
1739 it
->descent
+= face
->box_line_width
;
1741 if (it
->start_of_box_run_p
)
1742 it
->pixel_width
+= face
->box_line_width
;
1743 if (it
->end_of_box_run_p
)
1744 it
->pixel_width
+= face
->box_line_width
;
1747 take_vertical_position_into_account (it
);
1750 /* Return proper value to be used as baseline offset of font that has
1751 ASCENT and DESCENT to draw characters by the font at the vertical
1752 center of the line of frame F.
1754 Here, out task is to find the value of BOFF in the following figure;
1756 -------------------------+-----------+-
1757 -+-+---------+-+ | |
1759 | | | | F_ASCENT F_HEIGHT
1762 | | |-|-+------+-----------|------- baseline
1764 | |---------|-+-+ | |
1766 -+-+---------+-+ F_DESCENT |
1767 -------------------------+-----------+-
1769 -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
1770 BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
1771 DESCENT = FONT->descent
1772 HEIGHT = FONT_HEIGHT (FONT)
1773 F_DESCENT = (F->output_data.x->font->descent
1774 - F->output_data.x->baseline_offset)
1775 F_HEIGHT = FRAME_LINE_HEIGHT (F)
1778 #define VCENTER_BASELINE_OFFSET(FONT, F) \
1780 + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT)) \
1781 + (FRAME_LINE_HEIGHT ((F)) > FONT_HEIGHT ((FONT)))) / 2 \
1782 - ((F)->output_data.x->font->descent - (F)->output_data.x->baseline_offset))
1784 /* Produce glyphs/get display metrics for the display element IT is
1785 loaded with. See the description of struct display_iterator in
1786 dispextern.h for an overview of struct display_iterator. */
1789 x_produce_glyphs (it
)
1792 it
->glyph_not_available_p
= 0;
1794 if (it
->what
== IT_CHARACTER
)
1798 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1800 int font_not_found_p
;
1801 struct font_info
*font_info
;
1802 int boff
; /* baseline offset */
1803 /* We may change it->multibyte_p upon unibyte<->multibyte
1804 conversion. So, save the current value now and restore it
1807 Note: It seems that we don't have to record multibyte_p in
1808 struct glyph because the character code itself tells if or
1809 not the character is multibyte. Thus, in the future, we must
1810 consider eliminating the field `multibyte_p' in the struct
1813 int saved_multibyte_p
= it
->multibyte_p
;
1815 /* Maybe translate single-byte characters to multibyte, or the
1817 it
->char_to_display
= it
->c
;
1818 if (!ASCII_BYTE_P (it
->c
))
1820 if (unibyte_display_via_language_environment
1821 && SINGLE_BYTE_CHAR_P (it
->c
)
1823 || !NILP (Vnonascii_translation_table
)))
1825 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
1826 it
->multibyte_p
= 1;
1827 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1828 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1830 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
1831 && !it
->multibyte_p
)
1833 it
->char_to_display
= multibyte_char_to_unibyte (it
->c
, Qnil
);
1834 it
->multibyte_p
= 0;
1835 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1836 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1840 /* Get font to use. Encode IT->char_to_display. */
1841 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
1842 it
->face_id
, &char2b
,
1846 /* When no suitable font found, use the default font. */
1847 font_not_found_p
= font
== NULL
;
1848 if (font_not_found_p
)
1850 font
= FRAME_FONT (it
->f
);
1851 boff
= it
->f
->output_data
.x
->baseline_offset
;
1856 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
1857 boff
= font_info
->baseline_offset
;
1858 if (font_info
->vertical_centering
)
1859 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
1862 if (it
->char_to_display
>= ' '
1863 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
1865 /* Either unibyte or ASCII. */
1870 pcm
= x_per_char_metric (font
, &char2b
);
1871 it
->ascent
= font
->ascent
+ boff
;
1872 it
->descent
= font
->descent
- boff
;
1876 it
->phys_ascent
= pcm
->ascent
+ boff
;
1877 it
->phys_descent
= pcm
->descent
- boff
;
1878 it
->pixel_width
= pcm
->width
;
1882 it
->glyph_not_available_p
= 1;
1883 it
->phys_ascent
= font
->ascent
+ boff
;
1884 it
->phys_descent
= font
->descent
- boff
;
1885 it
->pixel_width
= FONT_WIDTH (font
);
1888 /* If this is a space inside a region of text with
1889 `space-width' property, change its width. */
1890 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
1892 it
->pixel_width
*= XFLOATINT (it
->space_width
);
1894 /* If face has a box, add the box thickness to the character
1895 height. If character has a box line to the left and/or
1896 right, add the box line width to the character's width. */
1897 if (face
->box
!= FACE_NO_BOX
)
1899 int thick
= face
->box_line_width
;
1901 it
->ascent
+= thick
;
1902 it
->descent
+= thick
;
1904 if (it
->start_of_box_run_p
)
1905 it
->pixel_width
+= thick
;
1906 if (it
->end_of_box_run_p
)
1907 it
->pixel_width
+= thick
;
1910 /* If face has an overline, add the height of the overline
1911 (1 pixel) and a 1 pixel margin to the character height. */
1912 if (face
->overline_p
)
1915 take_vertical_position_into_account (it
);
1917 /* If we have to actually produce glyphs, do it. */
1922 /* Translate a space with a `space-width' property
1923 into a stretch glyph. */
1924 double ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1925 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1926 it
->ascent
+ it
->descent
, ascent
);
1929 x_append_glyph (it
);
1931 /* If characters with lbearing or rbearing are displayed
1932 in this line, record that fact in a flag of the
1933 glyph row. This is used to optimize X output code. */
1934 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
1935 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1938 else if (it
->char_to_display
== '\n')
1940 /* A newline has no width but we need the height of the line. */
1941 it
->pixel_width
= 0;
1943 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1944 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1946 if (face
->box
!= FACE_NO_BOX
)
1948 int thick
= face
->box_line_width
;
1949 it
->ascent
+= thick
;
1950 it
->descent
+= thick
;
1953 else if (it
->char_to_display
== '\t')
1955 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
1956 int x
= it
->current_x
+ it
->continuation_lines_width
;
1957 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
1959 /* If the distance from the current position to the next tab
1960 stop is less than a canonical character width, use the
1961 tab stop after that. */
1962 if (next_tab_x
- x
< CANON_X_UNIT (it
->f
))
1963 next_tab_x
+= tab_width
;
1965 it
->pixel_width
= next_tab_x
- x
;
1967 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1968 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1972 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
1973 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1974 it
->ascent
+ it
->descent
, ascent
);
1979 /* A multi-byte character. Assume that the display width of the
1980 character is the width of the character multiplied by the
1981 width of the font. */
1983 /* If we found a font, this font should give us the right
1984 metrics. If we didn't find a font, use the frame's
1985 default font and calculate the width of the character
1986 from the charset width; this is what old redisplay code
1988 pcm
= x_per_char_metric (font
, &char2b
);
1989 if (font_not_found_p
|| !pcm
)
1991 int charset
= CHAR_CHARSET (it
->char_to_display
);
1993 it
->glyph_not_available_p
= 1;
1994 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
1995 * CHARSET_WIDTH (charset
));
1996 it
->phys_ascent
= font
->ascent
+ boff
;
1997 it
->phys_descent
= font
->descent
- boff
;
2001 it
->pixel_width
= pcm
->width
;
2002 it
->phys_ascent
= pcm
->ascent
+ boff
;
2003 it
->phys_descent
= pcm
->descent
- boff
;
2005 && (pcm
->lbearing
< 0
2006 || pcm
->rbearing
> pcm
->width
))
2007 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
2010 it
->ascent
= font
->ascent
+ boff
;
2011 it
->descent
= font
->descent
- boff
;
2012 if (face
->box
!= FACE_NO_BOX
)
2014 int thick
= face
->box_line_width
;
2015 it
->ascent
+= thick
;
2016 it
->descent
+= thick
;
2018 if (it
->start_of_box_run_p
)
2019 it
->pixel_width
+= thick
;
2020 if (it
->end_of_box_run_p
)
2021 it
->pixel_width
+= thick
;
2024 /* If face has an overline, add the height of the overline
2025 (1 pixel) and a 1 pixel margin to the character height. */
2026 if (face
->overline_p
)
2029 take_vertical_position_into_account (it
);
2032 x_append_glyph (it
);
2034 it
->multibyte_p
= saved_multibyte_p
;
2036 else if (it
->what
== IT_COMPOSITION
)
2038 /* Note: A composition is represented as one glyph in the
2039 glyph matrix. There are no padding glyphs. */
2042 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2044 int font_not_found_p
;
2045 struct font_info
*font_info
;
2046 int boff
; /* baseline offset */
2047 struct composition
*cmp
= composition_table
[it
->cmp_id
];
2049 /* Maybe translate single-byte characters to multibyte. */
2050 it
->char_to_display
= it
->c
;
2051 if (unibyte_display_via_language_environment
2052 && SINGLE_BYTE_CHAR_P (it
->c
)
2055 && !NILP (Vnonascii_translation_table
))))
2057 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2060 /* Get face and font to use. Encode IT->char_to_display. */
2061 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2062 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2063 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2064 it
->face_id
, &char2b
, it
->multibyte_p
);
2067 /* When no suitable font found, use the default font. */
2068 font_not_found_p
= font
== NULL
;
2069 if (font_not_found_p
)
2071 font
= FRAME_FONT (it
->f
);
2072 boff
= it
->f
->output_data
.x
->baseline_offset
;
2077 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2078 boff
= font_info
->baseline_offset
;
2079 if (font_info
->vertical_centering
)
2080 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2083 /* There are no padding glyphs, so there is only one glyph to
2084 produce for the composition. Important is that pixel_width,
2085 ascent and descent are the values of what is drawn by
2086 draw_glyphs (i.e. the values of the overall glyphs composed). */
2089 /* If we have not yet calculated pixel size data of glyphs of
2090 the composition for the current face font, calculate them
2091 now. Theoretically, we have to check all fonts for the
2092 glyphs, but that requires much time and memory space. So,
2093 here we check only the font of the first glyph. This leads
2094 to incorrect display very rarely, and C-l (recenter) can
2095 correct the display anyway. */
2096 if (cmp
->font
!= (void *) font
)
2098 /* Ascent and descent of the font of the first character of
2099 this composition (adjusted by baseline offset). Ascent
2100 and descent of overall glyphs should not be less than
2101 them respectively. */
2102 int font_ascent
= font
->ascent
+ boff
;
2103 int font_descent
= font
->descent
- boff
;
2104 /* Bounding box of the overall glyphs. */
2105 int leftmost
, rightmost
, lowest
, highest
;
2106 int i
, width
, ascent
, descent
;
2108 cmp
->font
= (void *) font
;
2110 /* Initialize the bounding box. */
2111 pcm
= x_per_char_metric (font
, &char2b
);
2115 ascent
= pcm
->ascent
;
2116 descent
= pcm
->descent
;
2120 width
= FONT_WIDTH (font
);
2121 ascent
= font
->ascent
;
2122 descent
= font
->descent
;
2126 lowest
= - descent
+ boff
;
2127 highest
= ascent
+ boff
;
2131 && font_info
->default_ascent
2132 && CHAR_TABLE_P (Vuse_default_ascent
)
2133 && !NILP (Faref (Vuse_default_ascent
,
2134 make_number (it
->char_to_display
))))
2135 highest
= font_info
->default_ascent
+ boff
;
2137 /* Draw the first glyph at the normal position. It may be
2138 shifted to right later if some other glyphs are drawn at
2140 cmp
->offsets
[0] = 0;
2141 cmp
->offsets
[1] = boff
;
2143 /* Set cmp->offsets for the remaining glyphs. */
2144 for (i
= 1; i
< cmp
->glyph_len
; i
++)
2146 int left
, right
, btm
, top
;
2147 int ch
= COMPOSITION_GLYPH (cmp
, i
);
2148 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
2150 face
= FACE_FROM_ID (it
->f
, face_id
);
2151 x_get_char_face_and_encoding (it
->f
, ch
, face
->id
, &char2b
,
2156 font
= FRAME_FONT (it
->f
);
2157 boff
= it
->f
->output_data
.x
->baseline_offset
;
2163 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2164 boff
= font_info
->baseline_offset
;
2165 if (font_info
->vertical_centering
)
2166 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2169 pcm
= x_per_char_metric (font
, &char2b
);
2173 ascent
= pcm
->ascent
;
2174 descent
= pcm
->descent
;
2178 width
= FONT_WIDTH (font
);
2179 ascent
= font
->ascent
;
2180 descent
= font
->descent
;
2183 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
2185 /* Relative composition with or without
2187 left
= (leftmost
+ rightmost
- width
) / 2;
2188 btm
= - descent
+ boff
;
2189 if (font_info
&& font_info
->relative_compose
2190 && (! CHAR_TABLE_P (Vignore_relative_composition
)
2191 || NILP (Faref (Vignore_relative_composition
,
2192 make_number (ch
)))))
2195 if (- descent
>= font_info
->relative_compose
)
2196 /* One extra pixel between two glyphs. */
2198 else if (ascent
<= 0)
2199 /* One extra pixel between two glyphs. */
2200 btm
= lowest
- 1 - ascent
- descent
;
2205 /* A composition rule is specified by an integer
2206 value that encodes global and new reference
2207 points (GREF and NREF). GREF and NREF are
2208 specified by numbers as below:
2216 ---3---4---5--- baseline
2218 6---7---8 -- descent
2220 int rule
= COMPOSITION_RULE (cmp
, i
);
2221 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
2223 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
2224 grefx
= gref
% 3, nrefx
= nref
% 3;
2225 grefy
= gref
/ 3, nrefy
= nref
/ 3;
2228 + grefx
* (rightmost
- leftmost
) / 2
2229 - nrefx
* width
/ 2);
2230 btm
= ((grefy
== 0 ? highest
2232 : grefy
== 2 ? lowest
2233 : (highest
+ lowest
) / 2)
2234 - (nrefy
== 0 ? ascent
+ descent
2235 : nrefy
== 1 ? descent
- boff
2237 : (ascent
+ descent
) / 2));
2240 cmp
->offsets
[i
* 2] = left
;
2241 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
2243 /* Update the bounding box of the overall glyphs. */
2244 right
= left
+ width
;
2245 top
= btm
+ descent
+ ascent
;
2246 if (left
< leftmost
)
2248 if (right
> rightmost
)
2256 /* If there are glyphs whose x-offsets are negative,
2257 shift all glyphs to the right and make all x-offsets
2261 for (i
= 0; i
< cmp
->glyph_len
; i
++)
2262 cmp
->offsets
[i
* 2] -= leftmost
;
2263 rightmost
-= leftmost
;
2266 cmp
->pixel_width
= rightmost
;
2267 cmp
->ascent
= highest
;
2268 cmp
->descent
= - lowest
;
2269 if (cmp
->ascent
< font_ascent
)
2270 cmp
->ascent
= font_ascent
;
2271 if (cmp
->descent
< font_descent
)
2272 cmp
->descent
= font_descent
;
2275 it
->pixel_width
= cmp
->pixel_width
;
2276 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
2277 it
->descent
= it
->phys_descent
= cmp
->descent
;
2279 if (face
->box
!= FACE_NO_BOX
)
2281 int thick
= face
->box_line_width
;
2282 it
->ascent
+= thick
;
2283 it
->descent
+= thick
;
2285 if (it
->start_of_box_run_p
)
2286 it
->pixel_width
+= thick
;
2287 if (it
->end_of_box_run_p
)
2288 it
->pixel_width
+= thick
;
2291 /* If face has an overline, add the height of the overline
2292 (1 pixel) and a 1 pixel margin to the character height. */
2293 if (face
->overline_p
)
2296 take_vertical_position_into_account (it
);
2299 x_append_composite_glyph (it
);
2301 else if (it
->what
== IT_IMAGE
)
2302 x_produce_image_glyph (it
);
2303 else if (it
->what
== IT_STRETCH
)
2304 x_produce_stretch_glyph (it
);
2306 /* Accumulate dimensions. Note: can't assume that it->descent > 0
2307 because this isn't true for images with `:ascent 100'. */
2308 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
2309 if (it
->area
== TEXT_AREA
)
2310 it
->current_x
+= it
->pixel_width
;
2312 it
->descent
+= it
->extra_line_spacing
;
2314 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
2315 it
->max_descent
= max (it
->max_descent
, it
->descent
);
2316 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
2317 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
2321 /* Estimate the pixel height of the mode or top line on frame F.
2322 FACE_ID specifies what line's height to estimate. */
2325 x_estimate_mode_line_height (f
, face_id
)
2327 enum face_id face_id
;
2331 /* This function is called so early when Emacs starts that the face
2332 cache and mode line face are not yet initialized. */
2333 if (FRAME_FACE_CACHE (f
))
2335 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2337 height
= FONT_HEIGHT (face
->font
) + 2 * face
->box_line_width
;
2344 /***********************************************************************
2346 ***********************************************************************/
2348 /* A sequence of glyphs to be drawn in the same face.
2350 This data structure is not really completely X specific, so it
2351 could possibly, at least partially, be useful for other systems. It
2352 is currently not part of the external redisplay interface because
2353 it's not clear what other systems will need. */
2357 /* X-origin of the string. */
2360 /* Y-origin and y-position of the base line of this string. */
2363 /* The width of the string, not including a face extension. */
2366 /* The width of the string, including a face extension. */
2367 int background_width
;
2369 /* The height of this string. This is the height of the line this
2370 string is drawn in, and can be different from the height of the
2371 font the string is drawn in. */
2374 /* Number of pixels this string overwrites in front of its x-origin.
2375 This number is zero if the string has an lbearing >= 0; it is
2376 -lbearing, if the string has an lbearing < 0. */
2379 /* Number of pixels this string overwrites past its right-most
2380 nominal x-position, i.e. x + width. Zero if the string's
2381 rbearing is <= its nominal width, rbearing - width otherwise. */
2384 /* The frame on which the glyph string is drawn. */
2387 /* The window on which the glyph string is drawn. */
2390 /* X display and window for convenience. */
2394 /* The glyph row for which this string was built. It determines the
2395 y-origin and height of the string. */
2396 struct glyph_row
*row
;
2398 /* The area within row. */
2399 enum glyph_row_area area
;
2401 /* Characters to be drawn, and number of characters. */
2405 /* A face-override for drawing cursors, mouse face and similar. */
2406 enum draw_glyphs_face hl
;
2408 /* Face in which this string is to be drawn. */
2411 /* Font in which this string is to be drawn. */
2414 /* Font info for this string. */
2415 struct font_info
*font_info
;
2417 /* Non-null means this string describes (part of) a composition.
2418 All characters from char2b are drawn composed. */
2419 struct composition
*cmp
;
2421 /* Index of this glyph string's first character in the glyph
2422 definition of CMP. If this is zero, this glyph string describes
2423 the first character of a composition. */
2426 /* 1 means this glyph strings face has to be drawn to the right end
2427 of the window's drawing area. */
2428 unsigned extends_to_end_of_line_p
: 1;
2430 /* 1 means the background of this string has been drawn. */
2431 unsigned background_filled_p
: 1;
2433 /* 1 means glyph string must be drawn with 16-bit functions. */
2434 unsigned two_byte_p
: 1;
2436 /* 1 means that the original font determined for drawing this glyph
2437 string could not be loaded. The member `font' has been set to
2438 the frame's default font in this case. */
2439 unsigned font_not_found_p
: 1;
2441 /* 1 means that the face in which this glyph string is drawn has a
2443 unsigned stippled_p
: 1;
2445 /* 1 means only the foreground of this glyph string must be drawn,
2446 and we should use the physical height of the line this glyph
2447 string appears in as clip rect. */
2448 unsigned for_overlaps_p
: 1;
2450 /* The GC to use for drawing this glyph string. */
2453 /* A pointer to the first glyph in the string. This glyph
2454 corresponds to char2b[0]. Needed to draw rectangles if
2455 font_not_found_p is 1. */
2456 struct glyph
*first_glyph
;
2458 /* Image, if any. */
2461 struct glyph_string
*next
, *prev
;
2468 x_dump_glyph_string (s
)
2469 struct glyph_string
*s
;
2471 fprintf (stderr
, "glyph string\n");
2472 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
2473 s
->x
, s
->y
, s
->width
, s
->height
);
2474 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
2475 fprintf (stderr
, " hl = %d\n", s
->hl
);
2476 fprintf (stderr
, " left overhang = %d, right = %d\n",
2477 s
->left_overhang
, s
->right_overhang
);
2478 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
2479 fprintf (stderr
, " extends to end of line = %d\n",
2480 s
->extends_to_end_of_line_p
);
2481 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
2482 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
2485 #endif /* GLYPH_DEBUG */
2489 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
2490 struct glyph_string
**,
2491 struct glyph_string
*,
2492 struct glyph_string
*));
2493 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
2494 struct glyph_string
**,
2495 struct glyph_string
*,
2496 struct glyph_string
*));
2497 static void x_append_glyph_string
P_ ((struct glyph_string
**,
2498 struct glyph_string
**,
2499 struct glyph_string
*));
2500 static int x_left_overwritten
P_ ((struct glyph_string
*));
2501 static int x_left_overwriting
P_ ((struct glyph_string
*));
2502 static int x_right_overwritten
P_ ((struct glyph_string
*));
2503 static int x_right_overwriting
P_ ((struct glyph_string
*));
2504 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
2506 static void x_init_glyph_string
P_ ((struct glyph_string
*,
2507 XChar2b
*, struct window
*,
2509 enum glyph_row_area
, int,
2510 enum draw_glyphs_face
));
2511 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
2512 enum glyph_row_area
, int, int,
2513 enum draw_glyphs_face
, int *, int *, int));
2514 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2515 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2516 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2518 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2519 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2520 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2521 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2522 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2523 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2524 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2525 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2526 static void x_get_glyph_overhangs
P_ ((struct glyph
*, struct frame
*,
2528 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
2529 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
2530 unsigned long *, double, int));
2531 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2532 double, int, unsigned long));
2533 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2534 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2535 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2536 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2537 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
2538 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
2539 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2541 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2542 int, int, int, int, XRectangle
*));
2543 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2544 int, int, int, XRectangle
*));
2545 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
2546 enum glyph_row_area
));
2547 static int x_fill_stretch_glyph_string
P_ ((struct glyph_string
*,
2549 enum glyph_row_area
, int, int));
2552 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
2556 /* Append the list of glyph strings with head H and tail T to the list
2557 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
2560 x_append_glyph_string_lists (head
, tail
, h
, t
)
2561 struct glyph_string
**head
, **tail
;
2562 struct glyph_string
*h
, *t
;
2576 /* Prepend the list of glyph strings with head H and tail T to the
2577 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
2581 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
2582 struct glyph_string
**head
, **tail
;
2583 struct glyph_string
*h
, *t
;
2597 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
2598 Set *HEAD and *TAIL to the resulting list. */
2601 x_append_glyph_string (head
, tail
, s
)
2602 struct glyph_string
**head
, **tail
;
2603 struct glyph_string
*s
;
2605 s
->next
= s
->prev
= NULL
;
2606 x_append_glyph_string_lists (head
, tail
, s
, s
);
2610 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2615 struct glyph_string
*s
;
2617 if (s
->font
== FRAME_FONT (s
->f
)
2618 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2619 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2621 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
2624 /* Cursor on non-default face: must merge. */
2628 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
2629 xgcv
.foreground
= s
->face
->background
;
2631 /* If the glyph would be invisible, try a different foreground. */
2632 if (xgcv
.foreground
== xgcv
.background
)
2633 xgcv
.foreground
= s
->face
->foreground
;
2634 if (xgcv
.foreground
== xgcv
.background
)
2635 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
2636 if (xgcv
.foreground
== xgcv
.background
)
2637 xgcv
.foreground
= s
->face
->foreground
;
2639 /* Make sure the cursor is distinct from text in this face. */
2640 if (xgcv
.background
== s
->face
->background
2641 && xgcv
.foreground
== s
->face
->foreground
)
2643 xgcv
.background
= s
->face
->foreground
;
2644 xgcv
.foreground
= s
->face
->background
;
2647 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2648 xgcv
.font
= s
->font
->fid
;
2649 xgcv
.graphics_exposures
= False
;
2650 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2652 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2653 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2656 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2657 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2659 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2664 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2667 x_set_mouse_face_gc (s
)
2668 struct glyph_string
*s
;
2673 /* What face has to be used for the mouse face? */
2674 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2675 face
= FACE_FROM_ID (s
->f
, face_id
);
2676 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2677 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2679 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2680 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2681 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2683 /* If font in this face is same as S->font, use it. */
2684 if (s
->font
== s
->face
->font
)
2685 s
->gc
= s
->face
->gc
;
2688 /* Otherwise construct scratch_cursor_gc with values from FACE
2693 xgcv
.background
= s
->face
->background
;
2694 xgcv
.foreground
= s
->face
->foreground
;
2695 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2696 xgcv
.font
= s
->font
->fid
;
2697 xgcv
.graphics_exposures
= False
;
2698 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2700 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2701 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2704 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2705 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2707 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2710 xassert (s
->gc
!= 0);
2714 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2715 Faces to use in the mode line have already been computed when the
2716 matrix was built, so there isn't much to do, here. */
2719 x_set_mode_line_face_gc (s
)
2720 struct glyph_string
*s
;
2722 s
->gc
= s
->face
->gc
;
2726 /* Set S->gc of glyph string S for drawing that glyph string. Set
2727 S->stippled_p to a non-zero value if the face of S has a stipple
2731 x_set_glyph_string_gc (s
)
2732 struct glyph_string
*s
;
2734 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2736 if (s
->hl
== DRAW_NORMAL_TEXT
)
2738 s
->gc
= s
->face
->gc
;
2739 s
->stippled_p
= s
->face
->stipple
!= 0;
2741 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2743 x_set_mode_line_face_gc (s
);
2744 s
->stippled_p
= s
->face
->stipple
!= 0;
2746 else if (s
->hl
== DRAW_CURSOR
)
2748 x_set_cursor_gc (s
);
2751 else if (s
->hl
== DRAW_MOUSE_FACE
)
2753 x_set_mouse_face_gc (s
);
2754 s
->stippled_p
= s
->face
->stipple
!= 0;
2756 else if (s
->hl
== DRAW_IMAGE_RAISED
2757 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2759 s
->gc
= s
->face
->gc
;
2760 s
->stippled_p
= s
->face
->stipple
!= 0;
2764 s
->gc
= s
->face
->gc
;
2765 s
->stippled_p
= s
->face
->stipple
!= 0;
2768 /* GC must have been set. */
2769 xassert (s
->gc
!= 0);
2773 /* Return in *R the clipping rectangle for glyph string S. */
2776 x_get_glyph_string_clip_rect (s
, r
)
2777 struct glyph_string
*s
;
2780 if (s
->row
->full_width_p
)
2782 /* Draw full-width. X coordinates are relative to S->w->left. */
2783 int canon_x
= CANON_X_UNIT (s
->f
);
2785 r
->x
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
2786 r
->width
= XFASTINT (s
->w
->width
) * canon_x
;
2788 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
2790 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
2791 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
2795 r
->x
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
2797 /* Unless displaying a mode or menu bar line, which are always
2798 fully visible, clip to the visible part of the row. */
2799 if (s
->w
->pseudo_window_p
)
2800 r
->height
= s
->row
->visible_height
;
2802 r
->height
= s
->height
;
2806 /* This is a text line that may be partially visible. */
2807 r
->x
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
2808 r
->width
= window_box_width (s
->w
, s
->area
);
2809 r
->height
= s
->row
->visible_height
;
2812 /* Don't use S->y for clipping because it doesn't take partially
2813 visible lines into account. For example, it can be negative for
2814 partially visible lines at the top of a window. */
2815 if (!s
->row
->full_width_p
2816 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2817 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2819 r
->y
= max (0, s
->row
->y
);
2821 /* If drawing a tool-bar window, draw it over the internal border
2822 at the top of the window. */
2823 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
2824 r
->y
-= s
->f
->output_data
.x
->internal_border_width
;
2826 /* If S draws overlapping rows, it's sufficient to use the top and
2827 bottom of the window for clipping because this glyph string
2828 intentionally draws over other lines. */
2829 if (s
->for_overlaps_p
)
2831 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2832 r
->height
= window_text_bottom_y (s
->w
) - r
->y
;
2835 r
->y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->y
);
2839 /* Set clipping for output of glyph string S. S may be part of a mode
2840 line or menu if we don't have X toolkit support. */
2843 x_set_glyph_string_clipping (s
)
2844 struct glyph_string
*s
;
2847 x_get_glyph_string_clip_rect (s
, &r
);
2848 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
2852 /* Compute left and right overhang of glyph string S. If S is a glyph
2853 string for a composition, assume overhangs don't exist. */
2856 x_compute_glyph_string_overhangs (s
)
2857 struct glyph_string
*s
;
2860 && s
->first_glyph
->type
== CHAR_GLYPH
)
2863 int direction
, font_ascent
, font_descent
;
2864 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
2865 &font_ascent
, &font_descent
, &cs
);
2866 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
2867 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
2872 /* Compute overhangs and x-positions for glyph string S and its
2873 predecessors, or successors. X is the starting x-position for S.
2874 BACKWARD_P non-zero means process predecessors. */
2877 x_compute_overhangs_and_x (s
, x
, backward_p
)
2878 struct glyph_string
*s
;
2886 x_compute_glyph_string_overhangs (s
);
2896 x_compute_glyph_string_overhangs (s
);
2905 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
2906 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
2907 assumed to be zero. */
2910 x_get_glyph_overhangs (glyph
, f
, left
, right
)
2911 struct glyph
*glyph
;
2917 if (glyph
->type
== CHAR_GLYPH
)
2921 struct font_info
*font_info
;
2925 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
2927 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
2929 && (pcm
= x_per_char_metric (font
, &char2b
)))
2931 if (pcm
->rbearing
> pcm
->width
)
2932 *right
= pcm
->rbearing
- pcm
->width
;
2933 if (pcm
->lbearing
< 0)
2934 *left
= -pcm
->lbearing
;
2940 /* Return the index of the first glyph preceding glyph string S that
2941 is overwritten by S because of S's left overhang. Value is -1
2942 if no glyphs are overwritten. */
2945 x_left_overwritten (s
)
2946 struct glyph_string
*s
;
2950 if (s
->left_overhang
)
2953 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2954 int first
= s
->first_glyph
- glyphs
;
2956 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
2957 x
-= glyphs
[i
].pixel_width
;
2968 /* Return the index of the first glyph preceding glyph string S that
2969 is overwriting S because of its right overhang. Value is -1 if no
2970 glyph in front of S overwrites S. */
2973 x_left_overwriting (s
)
2974 struct glyph_string
*s
;
2977 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2978 int first
= s
->first_glyph
- glyphs
;
2982 for (i
= first
- 1; i
>= 0; --i
)
2985 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
2988 x
-= glyphs
[i
].pixel_width
;
2995 /* Return the index of the last glyph following glyph string S that is
2996 not overwritten by S because of S's right overhang. Value is -1 if
2997 no such glyph is found. */
3000 x_right_overwritten (s
)
3001 struct glyph_string
*s
;
3005 if (s
->right_overhang
)
3008 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3009 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3010 int end
= s
->row
->used
[s
->area
];
3012 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
3013 x
+= glyphs
[i
].pixel_width
;
3022 /* Return the index of the last glyph following glyph string S that
3023 overwrites S because of its left overhang. Value is negative
3024 if no such glyph is found. */
3027 x_right_overwriting (s
)
3028 struct glyph_string
*s
;
3031 int end
= s
->row
->used
[s
->area
];
3032 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3033 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3037 for (i
= first
; i
< end
; ++i
)
3040 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3043 x
+= glyphs
[i
].pixel_width
;
3050 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
3053 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
3054 struct glyph_string
*s
;
3058 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
3059 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3060 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3061 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3065 /* Draw the background of glyph_string S. If S->background_filled_p
3066 is non-zero don't draw it. FORCE_P non-zero means draw the
3067 background even if it wouldn't be drawn normally. This is used
3068 when a string preceding S draws into the background of S, or S
3069 contains the first component of a composition. */
3072 x_draw_glyph_string_background (s
, force_p
)
3073 struct glyph_string
*s
;
3076 /* Nothing to do if background has already been drawn or if it
3077 shouldn't be drawn in the first place. */
3078 if (!s
->background_filled_p
)
3082 /* Fill background with a stipple pattern. */
3083 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3084 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
3085 s
->y
+ s
->face
->box_line_width
,
3086 s
->background_width
,
3087 s
->height
- 2 * s
->face
->box_line_width
);
3088 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3089 s
->background_filled_p
= 1;
3091 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * s
->face
->box_line_width
3092 || s
->font_not_found_p
3093 || s
->extends_to_end_of_line_p
3096 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ s
->face
->box_line_width
,
3097 s
->background_width
,
3098 s
->height
- 2 * s
->face
->box_line_width
);
3099 s
->background_filled_p
= 1;
3105 /* Draw the foreground of glyph string S. */
3108 x_draw_glyph_string_foreground (s
)
3109 struct glyph_string
*s
;
3113 /* If first glyph of S has a left box line, start drawing the text
3114 of S to the right of that box line. */
3115 if (s
->face
->box
!= FACE_NO_BOX
3116 && s
->first_glyph
->left_box_line_p
)
3117 x
= s
->x
+ s
->face
->box_line_width
;
3121 /* Draw characters of S as rectangles if S's font could not be
3123 if (s
->font_not_found_p
)
3125 for (i
= 0; i
< s
->nchars
; ++i
)
3127 struct glyph
*g
= s
->first_glyph
+ i
;
3128 XDrawRectangle (s
->display
, s
->window
,
3129 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
3131 x
+= g
->pixel_width
;
3136 char *char1b
= (char *) s
->char2b
;
3137 int boff
= s
->font_info
->baseline_offset
;
3139 if (s
->font_info
->vertical_centering
)
3140 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
3142 /* If we can use 8-bit functions, condense S->char2b. */
3144 for (i
= 0; i
< s
->nchars
; ++i
)
3145 char1b
[i
] = s
->char2b
[i
].byte2
;
3147 /* Draw text with XDrawString if background has already been
3148 filled. Otherwise, use XDrawImageString. (Note that
3149 XDrawImageString is usually faster than XDrawString.) Always
3150 use XDrawImageString when drawing the cursor so that there is
3151 no chance that characters under a box cursor are invisible. */
3152 if (s
->for_overlaps_p
3153 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
3155 /* Draw characters with 16-bit or 8-bit functions. */
3157 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
3158 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3160 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
3161 s
->ybase
- boff
, char1b
, s
->nchars
);
3166 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
3167 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3169 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
3170 s
->ybase
- boff
, char1b
, s
->nchars
);
3175 /* Draw the foreground of composite glyph string S. */
3178 x_draw_composite_glyph_string_foreground (s
)
3179 struct glyph_string
*s
;
3183 /* If first glyph of S has a left box line, start drawing the text
3184 of S to the right of that box line. */
3185 if (s
->face
->box
!= FACE_NO_BOX
3186 && s
->first_glyph
->left_box_line_p
)
3187 x
= s
->x
+ s
->face
->box_line_width
;
3191 /* S is a glyph string for a composition. S->gidx is the index of
3192 the first character drawn for glyphs of this composition.
3193 S->gidx == 0 means we are drawing the very first character of
3194 this composition. */
3196 /* Draw a rectangle for the composition if the font for the very
3197 first character of the composition could not be loaded. */
3198 if (s
->font_not_found_p
)
3201 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
3202 s
->width
- 1, s
->height
- 1);
3206 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3207 XDrawString16 (s
->display
, s
->window
, s
->gc
,
3208 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3209 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3215 #ifdef USE_X_TOOLKIT
3217 static struct frame
*x_frame_of_widget
P_ ((Widget
));
3220 /* Return the frame on which widget WIDGET is used.. Abort if frame
3221 cannot be determined. */
3223 static struct frame
*
3224 x_frame_of_widget (widget
)
3227 struct x_display_info
*dpyinfo
;
3231 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
3233 /* Find the top-level shell of the widget. Note that this function
3234 can be called when the widget is not yet realized, so XtWindow
3235 (widget) == 0. That's the reason we can't simply use
3236 x_any_window_to_frame. */
3237 while (!XtIsTopLevelShell (widget
))
3238 widget
= XtParent (widget
);
3240 /* Look for a frame with that top-level widget. Allocate the color
3241 on that frame to get the right gamma correction value. */
3242 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
3243 if (GC_FRAMEP (XCAR (tail
))
3244 && (f
= XFRAME (XCAR (tail
)),
3245 (f
->output_data
.nothing
!= 1
3246 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
3247 && f
->output_data
.x
->widget
== widget
)
3254 /* Allocate the color COLOR->pixel on the screen and display of
3255 widget WIDGET in colormap CMAP. If an exact match cannot be
3256 allocated, try the nearest color available. Value is non-zero
3257 if successful. This is called from lwlib. */
3260 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
3265 struct frame
*f
= x_frame_of_widget (widget
);
3266 return x_alloc_nearest_color (f
, cmap
, color
);
3270 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3271 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3272 If this produces the same color as PIXEL, try a color where all RGB
3273 values have DELTA added. Return the allocated color in *PIXEL.
3274 DISPLAY is the X display, CMAP is the colormap to operate on.
3275 Value is non-zero if successful. */
3278 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
3282 unsigned long *pixel
;
3286 struct frame
*f
= x_frame_of_widget (widget
);
3287 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
3291 #endif /* USE_X_TOOLKIT */
3294 /* Value is an array of XColor structures for the contents of the
3295 color map of frame F. Set *NCELLS to the size of the array.
3296 Note that this probably shouldn't be called for large color maps,
3297 say a 24-bit TrueColor map. */
3299 static const XColor
*
3300 x_color_cells (f
, ncells
)
3304 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3306 if (dpyinfo
->color_cells
== NULL
)
3308 Display
*display
= FRAME_X_DISPLAY (f
);
3309 Screen
*screen
= FRAME_X_SCREEN (f
);
3312 dpyinfo
->ncolor_cells
3313 = XDisplayCells (display
, XScreenNumberOfScreen (screen
));
3314 dpyinfo
->color_cells
3315 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
3316 * sizeof *dpyinfo
->color_cells
);
3318 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
3319 dpyinfo
->color_cells
[i
].pixel
= i
;
3321 XQueryColors (display
, FRAME_X_COLORMAP (f
),
3322 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
3325 *ncells
= dpyinfo
->ncolor_cells
;
3326 return dpyinfo
->color_cells
;
3330 /* On frame F, translate pixel colors to RGB values for the NCOLORS
3331 colors in COLORS. Use cached information, if available. */
3334 x_query_colors (f
, colors
, ncolors
)
3339 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3341 if (dpyinfo
->color_cells
)
3344 for (i
= 0; i
< ncolors
; ++i
)
3346 unsigned long pixel
= colors
[i
].pixel
;
3347 xassert (pixel
< dpyinfo
->ncolor_cells
);
3348 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
3349 colors
[i
] = dpyinfo
->color_cells
[pixel
];
3353 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
3357 /* On frame F, translate pixel color to RGB values for the color in
3358 COLOR. Use cached information, if available. */
3361 x_query_color (f
, color
)
3365 x_query_colors (f
, color
, 1);
3369 /* Allocate the color COLOR->pixel on SCREEN of DISPLAY, colormap
3370 CMAP. If an exact match can't be allocated, try the nearest color
3371 available. Value is non-zero if successful. Set *COLOR to the
3375 x_alloc_nearest_color (f
, cmap
, color
)
3380 Display
*display
= FRAME_X_DISPLAY (f
);
3381 Screen
*screen
= FRAME_X_SCREEN (f
);
3384 gamma_correct (f
, color
);
3385 rc
= XAllocColor (display
, cmap
, color
);
3388 /* If we got to this point, the colormap is full, so we're going
3389 to try to get the next closest color. The algorithm used is
3390 a least-squares matching, which is what X uses for closest
3391 color matching with StaticColor visuals. */
3393 unsigned long nearest_delta
= ~0;
3395 const XColor
*cells
= x_color_cells (f
, &ncells
);
3397 for (nearest
= i
= 0; i
< ncells
; ++i
)
3399 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
3400 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
3401 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
3402 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
3404 if (delta
< nearest_delta
)
3407 nearest_delta
= delta
;
3411 color
->red
= cells
[nearest
].red
;
3412 color
->green
= cells
[nearest
].green
;
3413 color
->blue
= cells
[nearest
].blue
;
3414 rc
= XAllocColor (display
, cmap
, color
);
3418 /* If allocation succeeded, and the allocated pixel color is not
3419 equal to a cached pixel color recorded earlier, there was a
3420 change in the colormap, so clear the color cache. */
3421 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3422 XColor
*cached_color
;
3424 if (dpyinfo
->color_cells
3425 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
3426 (cached_color
->red
!= color
->red
3427 || cached_color
->blue
!= color
->blue
3428 || cached_color
->green
!= color
->green
)))
3430 xfree (dpyinfo
->color_cells
);
3431 dpyinfo
->color_cells
= NULL
;
3432 dpyinfo
->ncolor_cells
= 0;
3436 #ifdef DEBUG_X_COLORS
3438 register_color (color
->pixel
);
3439 #endif /* DEBUG_X_COLORS */
3445 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
3446 It's necessary to do this instead of just using PIXEL directly to
3447 get color reference counts right. */
3450 x_copy_color (f
, pixel
)
3452 unsigned long pixel
;
3456 color
.pixel
= pixel
;
3458 x_query_color (f
, &color
);
3459 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3461 #ifdef DEBUG_X_COLORS
3462 register_color (pixel
);
3468 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
3469 It's necessary to do this instead of just using PIXEL directly to
3470 get color reference counts right. */
3473 x_copy_dpy_color (dpy
, cmap
, pixel
)
3476 unsigned long pixel
;
3480 color
.pixel
= pixel
;
3482 XQueryColor (dpy
, cmap
, &color
);
3483 XAllocColor (dpy
, cmap
, &color
);
3485 #ifdef DEBUG_X_COLORS
3486 register_color (pixel
);
3492 /* Brightness beyond which a color won't have its highlight brightness
3495 Nominally, highlight colors for `3d' faces are calculated by
3496 brightening an object's color by a constant scale factor, but this
3497 doesn't yield good results for dark colors, so for colors who's
3498 brightness is less than this value (on a scale of 0-65535) have an
3499 use an additional additive factor.
3501 The value here is set so that the default menu-bar/mode-line color
3502 (grey75) will not have its highlights changed at all. */
3503 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
3506 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3507 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3508 If this produces the same color as PIXEL, try a color where all RGB
3509 values have DELTA added. Return the allocated color in *PIXEL.
3510 DISPLAY is the X display, CMAP is the colormap to operate on.
3511 Value is non-zero if successful. */
3514 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
3518 unsigned long *pixel
;
3526 /* Get RGB color values. */
3527 color
.pixel
= *pixel
;
3528 x_query_color (f
, &color
);
3530 /* Change RGB values by specified FACTOR. Avoid overflow! */
3531 xassert (factor
>= 0);
3532 new.red
= min (0xffff, factor
* color
.red
);
3533 new.green
= min (0xffff, factor
* color
.green
);
3534 new.blue
= min (0xffff, factor
* color
.blue
);
3536 /* Calculate brightness of COLOR. */
3537 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
3539 /* We only boost colors that are darker than
3540 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
3541 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
3542 /* Make an additive adjustment to NEW, because it's dark enough so
3543 that scaling by FACTOR alone isn't enough. */
3545 /* How far below the limit this color is (0 - 1, 1 being darker). */
3546 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
3547 /* The additive adjustment. */
3548 int min_delta
= delta
* dimness
* factor
/ 2;
3552 new.red
= max (0, new.red
- min_delta
);
3553 new.green
= max (0, new.green
- min_delta
);
3554 new.blue
= max (0, new.blue
- min_delta
);
3558 new.red
= min (0xffff, min_delta
+ new.red
);
3559 new.green
= min (0xffff, min_delta
+ new.green
);
3560 new.blue
= min (0xffff, min_delta
+ new.blue
);
3564 /* Try to allocate the color. */
3565 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3568 if (new.pixel
== *pixel
)
3570 /* If we end up with the same color as before, try adding
3571 delta to the RGB values. */
3572 x_free_colors (f
, &new.pixel
, 1);
3574 new.red
= min (0xffff, delta
+ color
.red
);
3575 new.green
= min (0xffff, delta
+ color
.green
);
3576 new.blue
= min (0xffff, delta
+ color
.blue
);
3577 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3588 /* Set up the foreground color for drawing relief lines of glyph
3589 string S. RELIEF is a pointer to a struct relief containing the GC
3590 with which lines will be drawn. Use a color that is FACTOR or
3591 DELTA lighter or darker than the relief's background which is found
3592 in S->f->output_data.x->relief_background. If such a color cannot
3593 be allocated, use DEFAULT_PIXEL, instead. */
3596 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3598 struct relief
*relief
;
3601 unsigned long default_pixel
;
3604 struct x_output
*di
= f
->output_data
.x
;
3605 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
3606 unsigned long pixel
;
3607 unsigned long background
= di
->relief_background
;
3608 Colormap cmap
= FRAME_X_COLORMAP (f
);
3609 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3610 Display
*dpy
= FRAME_X_DISPLAY (f
);
3612 xgcv
.graphics_exposures
= False
;
3613 xgcv
.line_width
= 1;
3615 /* Free previously allocated color. The color cell will be reused
3616 when it has been freed as many times as it was allocated, so this
3617 doesn't affect faces using the same colors. */
3619 && relief
->allocated_p
)
3621 x_free_colors (f
, &relief
->pixel
, 1);
3622 relief
->allocated_p
= 0;
3625 /* Allocate new color. */
3626 xgcv
.foreground
= default_pixel
;
3628 if (dpyinfo
->n_planes
!= 1
3629 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
3631 relief
->allocated_p
= 1;
3632 xgcv
.foreground
= relief
->pixel
= pixel
;
3635 if (relief
->gc
== 0)
3637 xgcv
.stipple
= dpyinfo
->gray
;
3639 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
3642 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
3646 /* Set up colors for the relief lines around glyph string S. */
3649 x_setup_relief_colors (s
)
3650 struct glyph_string
*s
;
3652 struct x_output
*di
= s
->f
->output_data
.x
;
3653 unsigned long color
;
3655 if (s
->face
->use_box_color_for_shadows_p
)
3656 color
= s
->face
->box_color
;
3661 /* Get the background color of the face. */
3662 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3663 color
= xgcv
.background
;
3666 if (di
->white_relief
.gc
== 0
3667 || color
!= di
->relief_background
)
3669 di
->relief_background
= color
;
3670 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3671 WHITE_PIX_DEFAULT (s
->f
));
3672 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3673 BLACK_PIX_DEFAULT (s
->f
));
3678 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3679 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3680 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3681 relief. LEFT_P non-zero means draw a relief on the left side of
3682 the rectangle. RIGHT_P non-zero means draw a relief on the right
3683 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3687 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3688 raised_p
, left_p
, right_p
, clip_rect
)
3690 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
3691 XRectangle
*clip_rect
;
3697 gc
= f
->output_data
.x
->white_relief
.gc
;
3699 gc
= f
->output_data
.x
->black_relief
.gc
;
3700 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3703 for (i
= 0; i
< width
; ++i
)
3704 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3705 left_x
+ i
* left_p
, top_y
+ i
,
3706 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3710 for (i
= 0; i
< width
; ++i
)
3711 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3712 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
);
3714 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3716 gc
= f
->output_data
.x
->black_relief
.gc
;
3718 gc
= f
->output_data
.x
->white_relief
.gc
;
3719 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3722 for (i
= 0; i
< width
; ++i
)
3723 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3724 left_x
+ i
* left_p
, bottom_y
- i
,
3725 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3729 for (i
= 0; i
< width
; ++i
)
3730 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3731 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3733 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3737 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3738 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3739 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3740 left side of the rectangle. RIGHT_P non-zero means draw a line
3741 on the right side of the rectangle. CLIP_RECT is the clipping
3742 rectangle to use when drawing. */
3745 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3746 left_p
, right_p
, clip_rect
)
3747 struct glyph_string
*s
;
3748 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
;
3749 XRectangle
*clip_rect
;
3753 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3754 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
3755 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
3758 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3759 left_x
, top_y
, right_x
- left_x
+ 1, width
);
3763 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3764 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
3767 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3768 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
3772 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3773 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
3775 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3776 XSetClipMask (s
->display
, s
->gc
, None
);
3780 /* Draw a box around glyph string S. */
3783 x_draw_glyph_string_box (s
)
3784 struct glyph_string
*s
;
3786 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3787 int left_p
, right_p
;
3788 struct glyph
*last_glyph
;
3789 XRectangle clip_rect
;
3791 last_x
= window_box_right (s
->w
, s
->area
);
3792 if (s
->row
->full_width_p
3793 && !s
->w
->pseudo_window_p
)
3795 last_x
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (s
->f
);
3796 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
3797 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
3800 /* The glyph that may have a right box line. */
3801 last_glyph
= (s
->cmp
|| s
->img
3803 : s
->first_glyph
+ s
->nchars
- 1);
3805 width
= s
->face
->box_line_width
;
3806 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
3808 right_x
= ((s
->row
->full_width_p
3810 : min (last_x
, s
->x
+ s
->background_width
) - 1));
3812 bottom_y
= top_y
+ s
->height
- 1;
3814 left_p
= (s
->first_glyph
->left_box_line_p
3815 || (s
->hl
== DRAW_MOUSE_FACE
3817 || s
->prev
->hl
!= s
->hl
)));
3818 right_p
= (last_glyph
->right_box_line_p
3819 || (s
->hl
== DRAW_MOUSE_FACE
3821 || s
->next
->hl
!= s
->hl
)));
3823 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3825 if (s
->face
->box
== FACE_SIMPLE_BOX
)
3826 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3827 left_p
, right_p
, &clip_rect
);
3830 x_setup_relief_colors (s
);
3831 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
3832 width
, raised_p
, left_p
, right_p
, &clip_rect
);
3837 /* Draw foreground of image glyph string S. */
3840 x_draw_image_foreground (s
)
3841 struct glyph_string
*s
;
3844 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3846 /* If first glyph of S has a left box line, start drawing it to the
3847 right of that line. */
3848 if (s
->face
->box
!= FACE_NO_BOX
3849 && s
->first_glyph
->left_box_line_p
)
3850 x
= s
->x
+ s
->face
->box_line_width
;
3854 /* If there is a margin around the image, adjust x- and y-position
3858 x
+= s
->img
->margin
;
3859 y
+= s
->img
->margin
;
3866 /* We can't set both a clip mask and use XSetClipRectangles
3867 because the latter also sets a clip mask. We also can't
3868 trust on the shape extension to be available
3869 (XShapeCombineRegion). So, compute the rectangle to draw
3871 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3874 XRectangle clip_rect
, image_rect
, r
;
3876 xgcv
.clip_mask
= s
->img
->mask
;
3877 xgcv
.clip_x_origin
= x
;
3878 xgcv
.clip_y_origin
= y
;
3879 xgcv
.function
= GXcopy
;
3880 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3882 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3885 image_rect
.width
= s
->img
->width
;
3886 image_rect
.height
= s
->img
->height
;
3887 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
3888 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3889 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3893 unsigned long mask
= GCClipXOrigin
| GCClipYOrigin
| GCFunction
;
3895 XRectangle clip_rect
, image_rect
, r
;
3897 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3900 image_rect
.width
= s
->img
->width
;
3901 image_rect
.height
= s
->img
->height
;
3902 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
3903 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3904 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3906 /* When the image has a mask, we can expect that at
3907 least part of a mouse highlight or a block cursor will
3908 be visible. If the image doesn't have a mask, make
3909 a block cursor visible by drawing a rectangle around
3910 the image. I believe it's looking better if we do
3911 nothing here for mouse-face. */
3912 if (s
->hl
== DRAW_CURSOR
)
3913 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3914 s
->img
->width
- 1, s
->img
->height
- 1);
3918 /* Draw a rectangle if image could not be loaded. */
3919 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3920 s
->img
->width
- 1, s
->img
->height
- 1);
3924 /* Draw a relief around the image glyph string S. */
3927 x_draw_image_relief (s
)
3928 struct glyph_string
*s
;
3930 int x0
, y0
, x1
, y1
, thick
, raised_p
;
3933 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3935 /* If first glyph of S has a left box line, start drawing it to the
3936 right of that line. */
3937 if (s
->face
->box
!= FACE_NO_BOX
3938 && s
->first_glyph
->left_box_line_p
)
3939 x
= s
->x
+ s
->face
->box_line_width
;
3943 /* If there is a margin around the image, adjust x- and y-position
3947 x
+= s
->img
->margin
;
3948 y
+= s
->img
->margin
;
3951 if (s
->hl
== DRAW_IMAGE_SUNKEN
3952 || s
->hl
== DRAW_IMAGE_RAISED
)
3954 thick
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
3955 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
3959 thick
= abs (s
->img
->relief
);
3960 raised_p
= s
->img
->relief
> 0;
3965 x1
= x
+ s
->img
->width
+ thick
- 1;
3966 y1
= y
+ s
->img
->height
+ thick
- 1;
3968 x_setup_relief_colors (s
);
3969 x_get_glyph_string_clip_rect (s
, &r
);
3970 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
3974 /* Draw the foreground of image glyph string S to PIXMAP. */
3977 x_draw_image_foreground_1 (s
, pixmap
)
3978 struct glyph_string
*s
;
3982 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
3984 /* If first glyph of S has a left box line, start drawing it to the
3985 right of that line. */
3986 if (s
->face
->box
!= FACE_NO_BOX
3987 && s
->first_glyph
->left_box_line_p
)
3988 x
= s
->face
->box_line_width
;
3992 /* If there is a margin around the image, adjust x- and y-position
3996 x
+= s
->img
->margin
;
3997 y
+= s
->img
->margin
;
4004 /* We can't set both a clip mask and use XSetClipRectangles
4005 because the latter also sets a clip mask. We also can't
4006 trust on the shape extension to be available
4007 (XShapeCombineRegion). So, compute the rectangle to draw
4009 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4013 xgcv
.clip_mask
= s
->img
->mask
;
4014 xgcv
.clip_x_origin
= x
;
4015 xgcv
.clip_y_origin
= y
;
4016 xgcv
.function
= GXcopy
;
4017 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4019 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4020 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4021 XSetClipMask (s
->display
, s
->gc
, None
);
4025 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4026 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4028 /* When the image has a mask, we can expect that at
4029 least part of a mouse highlight or a block cursor will
4030 be visible. If the image doesn't have a mask, make
4031 a block cursor visible by drawing a rectangle around
4032 the image. I believe it's looking better if we do
4033 nothing here for mouse-face. */
4034 if (s
->hl
== DRAW_CURSOR
)
4035 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
4036 s
->img
->width
- 1, s
->img
->height
- 1);
4040 /* Draw a rectangle if image could not be loaded. */
4041 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
4042 s
->img
->width
- 1, s
->img
->height
- 1);
4046 /* Draw part of the background of glyph string S. X, Y, W, and H
4047 give the rectangle to draw. */
4050 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
4051 struct glyph_string
*s
;
4056 /* Fill background with a stipple pattern. */
4057 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4058 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
4059 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4062 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
4066 /* Draw image glyph string S.
4069 s->x +-------------------------
4072 | +-------------------------
4075 | | +-------------------
4081 x_draw_image_glyph_string (s
)
4082 struct glyph_string
*s
;
4085 int box_line_width
= s
->face
->box_line_width
;
4086 int margin
= s
->img
->margin
;
4088 Pixmap pixmap
= None
;
4090 height
= s
->height
- 2 * box_line_width
;
4092 /* Fill background with face under the image. Do it only if row is
4093 taller than image or if image has a clip mask to reduce
4095 s
->stippled_p
= s
->face
->stipple
!= 0;
4096 if (height
> s
->img
->height
4099 || s
->img
->pixmap
== 0
4100 || s
->width
!= s
->background_width
)
4102 if (box_line_width
&& s
->first_glyph
->left_box_line_p
)
4103 x
= s
->x
+ box_line_width
;
4107 y
= s
->y
+ box_line_width
;
4111 /* Create a pixmap as large as the glyph string. Fill it
4112 with the background color. Copy the image to it, using
4113 its mask. Copy the temporary pixmap to the display. */
4114 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
4115 int depth
= DefaultDepthOfScreen (screen
);
4117 /* Create a pixmap as large as the glyph string. */
4118 pixmap
= XCreatePixmap (s
->display
, s
->window
,
4119 s
->background_width
,
4122 /* Don't clip in the following because we're working on the
4124 XSetClipMask (s
->display
, s
->gc
, None
);
4126 /* Fill the pixmap with the background color/stipple. */
4129 /* Fill background with a stipple pattern. */
4130 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4131 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4132 0, 0, s
->background_width
, s
->height
);
4133 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4138 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
4140 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
4141 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4142 0, 0, s
->background_width
, s
->height
);
4143 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4147 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
4149 s
->background_filled_p
= 1;
4152 /* Draw the foreground. */
4155 x_draw_image_foreground_1 (s
, pixmap
);
4156 x_set_glyph_string_clipping (s
);
4157 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
4158 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
4159 XFreePixmap (s
->display
, pixmap
);
4162 x_draw_image_foreground (s
);
4164 /* If we must draw a relief around the image, do it. */
4166 || s
->hl
== DRAW_IMAGE_RAISED
4167 || s
->hl
== DRAW_IMAGE_SUNKEN
)
4168 x_draw_image_relief (s
);
4172 /* Draw stretch glyph string S. */
4175 x_draw_stretch_glyph_string (s
)
4176 struct glyph_string
*s
;
4178 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4179 s
->stippled_p
= s
->face
->stipple
!= 0;
4181 if (s
->hl
== DRAW_CURSOR
4182 && !x_stretch_cursor_p
)
4184 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
4185 as wide as the stretch glyph. */
4186 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
4189 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
4191 /* Clear rest using the GC of the original non-cursor face. */
4192 if (width
< s
->background_width
)
4194 GC gc
= s
->face
->gc
;
4195 int x
= s
->x
+ width
, y
= s
->y
;
4196 int w
= s
->background_width
- width
, h
= s
->height
;
4199 x_get_glyph_string_clip_rect (s
, &r
);
4200 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
4202 if (s
->face
->stipple
)
4204 /* Fill background with a stipple pattern. */
4205 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
4206 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4207 XSetFillStyle (s
->display
, gc
, FillSolid
);
4212 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
4213 XSetForeground (s
->display
, gc
, xgcv
.background
);
4214 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4215 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
4220 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
4223 s
->background_filled_p
= 1;
4227 /* Draw glyph string S. */
4230 x_draw_glyph_string (s
)
4231 struct glyph_string
*s
;
4233 /* If S draws into the background of its successor, draw the
4234 background of the successor first so that S can draw into it.
4235 This makes S->next use XDrawString instead of XDrawImageString. */
4236 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4238 xassert (s
->next
->img
== NULL
);
4239 x_set_glyph_string_gc (s
->next
);
4240 x_set_glyph_string_clipping (s
->next
);
4241 x_draw_glyph_string_background (s
->next
, 1);
4244 /* Set up S->gc, set clipping and draw S. */
4245 x_set_glyph_string_gc (s
);
4246 x_set_glyph_string_clipping (s
);
4248 switch (s
->first_glyph
->type
)
4251 x_draw_image_glyph_string (s
);
4255 x_draw_stretch_glyph_string (s
);
4259 if (s
->for_overlaps_p
)
4260 s
->background_filled_p
= 1;
4262 x_draw_glyph_string_background (s
, 0);
4263 x_draw_glyph_string_foreground (s
);
4266 case COMPOSITE_GLYPH
:
4267 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4268 s
->background_filled_p
= 1;
4270 x_draw_glyph_string_background (s
, 1);
4271 x_draw_composite_glyph_string_foreground (s
);
4278 if (!s
->for_overlaps_p
)
4280 /* Draw underline. */
4281 if (s
->face
->underline_p
)
4283 unsigned long tem
, h
;
4286 /* Get the underline thickness. Default is 1 pixel. */
4287 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
4290 /* Get the underline position. This is the recommended
4291 vertical offset in pixels from the baseline to the top of
4292 the underline. This is a signed value according to the
4293 specs, and its default is
4295 ROUND ((maximum descent) / 2), with
4296 ROUND(x) = floor (x + 0.5) */
4298 if (XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &tem
))
4299 y
= s
->ybase
+ (long) tem
;
4300 else if (s
->face
->font
)
4301 y
= s
->ybase
+ (s
->face
->font
->max_bounds
.descent
+ 1) / 2;
4305 if (s
->face
->underline_defaulted_p
)
4306 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4307 s
->x
, y
, s
->width
, h
);
4311 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4312 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
4313 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4314 s
->x
, y
, s
->width
, h
);
4315 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4319 /* Draw overline. */
4320 if (s
->face
->overline_p
)
4322 unsigned long dy
= 0, h
= 1;
4324 if (s
->face
->overline_color_defaulted_p
)
4325 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4330 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4331 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
4332 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4334 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4338 /* Draw strike-through. */
4339 if (s
->face
->strike_through_p
)
4341 unsigned long h
= 1;
4342 unsigned long dy
= (s
->height
- h
) / 2;
4344 if (s
->face
->strike_through_color_defaulted_p
)
4345 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4350 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4351 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
4352 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4354 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4359 if (s
->face
->box
!= FACE_NO_BOX
)
4360 x_draw_glyph_string_box (s
);
4363 /* Reset clipping. */
4364 XSetClipMask (s
->display
, s
->gc
, None
);
4368 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4369 struct face
**, int));
4372 /* Fill glyph string S with composition components specified by S->cmp.
4374 FACES is an array of faces for all components of this composition.
4375 S->gidx is the index of the first component for S.
4376 OVERLAPS_P non-zero means S should draw the foreground only, and
4377 use its physical height for clipping.
4379 Value is the index of a component not in S. */
4382 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4383 struct glyph_string
*s
;
4384 struct face
**faces
;
4391 s
->for_overlaps_p
= overlaps_p
;
4393 s
->face
= faces
[s
->gidx
];
4394 s
->font
= s
->face
->font
;
4395 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4397 /* For all glyphs of this composition, starting at the offset
4398 S->gidx, until we reach the end of the definition or encounter a
4399 glyph that requires the different face, add it to S. */
4401 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4404 /* All glyph strings for the same composition has the same width,
4405 i.e. the width set for the first component of the composition. */
4407 s
->width
= s
->first_glyph
->pixel_width
;
4409 /* If the specified font could not be loaded, use the frame's
4410 default font, but record the fact that we couldn't load it in
4411 the glyph string so that we can draw rectangles for the
4412 characters of the glyph string. */
4413 if (s
->font
== NULL
)
4415 s
->font_not_found_p
= 1;
4416 s
->font
= FRAME_FONT (s
->f
);
4419 /* Adjust base line for subscript/superscript text. */
4420 s
->ybase
+= s
->first_glyph
->voffset
;
4422 xassert (s
->face
&& s
->face
->gc
);
4424 /* This glyph string must always be drawn with 16-bit functions. */
4427 return s
->gidx
+ s
->nchars
;
4431 /* Fill glyph string S from a sequence of character glyphs.
4433 FACE_ID is the face id of the string. START is the index of the
4434 first glyph to consider, END is the index of the last + 1.
4435 OVERLAPS_P non-zero means S should draw the foreground only, and
4436 use its physical height for clipping.
4438 Value is the index of the first glyph not in S. */
4441 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4442 struct glyph_string
*s
;
4444 int start
, end
, overlaps_p
;
4446 struct glyph
*glyph
, *last
;
4448 int glyph_not_available_p
;
4450 xassert (s
->f
== XFRAME (s
->w
->frame
));
4451 xassert (s
->nchars
== 0);
4452 xassert (start
>= 0 && end
> start
);
4454 s
->for_overlaps_p
= overlaps_p
,
4455 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4456 last
= s
->row
->glyphs
[s
->area
] + end
;
4457 voffset
= glyph
->voffset
;
4459 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4462 && glyph
->type
== CHAR_GLYPH
4463 && glyph
->voffset
== voffset
4464 /* Same face id implies same font, nowadays. */
4465 && glyph
->face_id
== face_id
4466 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4470 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4471 s
->char2b
+ s
->nchars
,
4473 s
->two_byte_p
= two_byte_p
;
4475 xassert (s
->nchars
<= end
- start
);
4476 s
->width
+= glyph
->pixel_width
;
4480 s
->font
= s
->face
->font
;
4481 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4483 /* If the specified font could not be loaded, use the frame's font,
4484 but record the fact that we couldn't load it in
4485 S->font_not_found_p so that we can draw rectangles for the
4486 characters of the glyph string. */
4487 if (s
->font
== NULL
|| glyph_not_available_p
)
4489 s
->font_not_found_p
= 1;
4490 s
->font
= FRAME_FONT (s
->f
);
4493 /* Adjust base line for subscript/superscript text. */
4494 s
->ybase
+= voffset
;
4496 xassert (s
->face
&& s
->face
->gc
);
4497 return glyph
- s
->row
->glyphs
[s
->area
];
4501 /* Fill glyph string S from image glyph S->first_glyph. */
4504 x_fill_image_glyph_string (s
)
4505 struct glyph_string
*s
;
4507 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4508 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
4510 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4511 s
->font
= s
->face
->font
;
4512 s
->width
= s
->first_glyph
->pixel_width
;
4514 /* Adjust base line for subscript/superscript text. */
4515 s
->ybase
+= s
->first_glyph
->voffset
;
4519 /* Fill glyph string S from a sequence of stretch glyphs.
4521 ROW is the glyph row in which the glyphs are found, AREA is the
4522 area within the row. START is the index of the first glyph to
4523 consider, END is the index of the last + 1.
4525 Value is the index of the first glyph not in S. */
4528 x_fill_stretch_glyph_string (s
, row
, area
, start
, end
)
4529 struct glyph_string
*s
;
4530 struct glyph_row
*row
;
4531 enum glyph_row_area area
;
4534 struct glyph
*glyph
, *last
;
4535 int voffset
, face_id
;
4537 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4539 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4540 last
= s
->row
->glyphs
[s
->area
] + end
;
4541 face_id
= glyph
->face_id
;
4542 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
4543 s
->font
= s
->face
->font
;
4544 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4545 s
->width
= glyph
->pixel_width
;
4546 voffset
= glyph
->voffset
;
4550 && glyph
->type
== STRETCH_GLYPH
4551 && glyph
->voffset
== voffset
4552 && glyph
->face_id
== face_id
);
4554 s
->width
+= glyph
->pixel_width
;
4556 /* Adjust base line for subscript/superscript text. */
4557 s
->ybase
+= voffset
;
4559 xassert (s
->face
&& s
->face
->gc
);
4560 return glyph
- s
->row
->glyphs
[s
->area
];
4564 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4565 of XChar2b structures for S; it can't be allocated in
4566 x_init_glyph_string because it must be allocated via `alloca'. W
4567 is the window on which S is drawn. ROW and AREA are the glyph row
4568 and area within the row from which S is constructed. START is the
4569 index of the first glyph structure covered by S. HL is a
4570 face-override for drawing S. */
4573 x_init_glyph_string (s
, char2b
, w
, row
, area
, start
, hl
)
4574 struct glyph_string
*s
;
4577 struct glyph_row
*row
;
4578 enum glyph_row_area area
;
4580 enum draw_glyphs_face hl
;
4582 bzero (s
, sizeof *s
);
4584 s
->f
= XFRAME (w
->frame
);
4585 s
->display
= FRAME_X_DISPLAY (s
->f
);
4586 s
->window
= FRAME_X_WINDOW (s
->f
);
4591 s
->first_glyph
= row
->glyphs
[area
] + start
;
4592 s
->height
= row
->height
;
4593 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4595 /* Display the internal border below the tool-bar window. */
4596 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4597 s
->y
-= s
->f
->output_data
.x
->internal_border_width
;
4599 s
->ybase
= s
->y
+ row
->ascent
;
4603 /* Set background width of glyph string S. START is the index of the
4604 first glyph following S. LAST_X is the right-most x-position + 1
4605 in the drawing area. */
4608 x_set_glyph_string_background_width (s
, start
, last_x
)
4609 struct glyph_string
*s
;
4613 /* If the face of this glyph string has to be drawn to the end of
4614 the drawing area, set S->extends_to_end_of_line_p. */
4615 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4617 if (start
== s
->row
->used
[s
->area
]
4618 && s
->hl
== DRAW_NORMAL_TEXT
4619 && ((s
->area
== TEXT_AREA
&& s
->row
->fill_line_p
)
4620 || s
->face
->background
!= default_face
->background
4621 || s
->face
->stipple
!= default_face
->stipple
))
4622 s
->extends_to_end_of_line_p
= 1;
4624 /* If S extends its face to the end of the line, set its
4625 background_width to the distance to the right edge of the drawing
4627 if (s
->extends_to_end_of_line_p
)
4628 s
->background_width
= last_x
- s
->x
+ 1;
4630 s
->background_width
= s
->width
;
4634 /* Add a glyph string for a stretch glyph to the list of strings
4635 between HEAD and TAIL. START is the index of the stretch glyph in
4636 row area AREA of glyph row ROW. END is the index of the last glyph
4637 in that glyph row area. X is the current output position assigned
4638 to the new glyph string constructed. HL overrides that face of the
4639 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4640 is the right-most x-position of the drawing area. */
4642 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
4643 and below -- keep them on one line. */
4644 #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4647 s = (struct glyph_string *) alloca (sizeof *s); \
4648 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4649 START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \
4650 x_append_glyph_string (&HEAD, &TAIL, s); \
4656 /* Add a glyph string for an image glyph to the list of strings
4657 between HEAD and TAIL. START is the index of the image glyph in
4658 row area AREA of glyph row ROW. END is the index of the last glyph
4659 in that glyph row area. X is the current output position assigned
4660 to the new glyph string constructed. HL overrides that face of the
4661 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4662 is the right-most x-position of the drawing area. */
4664 #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4667 s = (struct glyph_string *) alloca (sizeof *s); \
4668 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4669 x_fill_image_glyph_string (s); \
4670 x_append_glyph_string (&HEAD, &TAIL, s); \
4677 /* Add a glyph string for a sequence of character glyphs to the list
4678 of strings between HEAD and TAIL. START is the index of the first
4679 glyph in row area AREA of glyph row ROW that is part of the new
4680 glyph string. END is the index of the last glyph in that glyph row
4681 area. X is the current output position assigned to the new glyph
4682 string constructed. HL overrides that face of the glyph; e.g. it
4683 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4684 right-most x-position of the drawing area. */
4686 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4692 c = (ROW)->glyphs[AREA][START].u.ch; \
4693 face_id = (ROW)->glyphs[AREA][START].face_id; \
4695 s = (struct glyph_string *) alloca (sizeof *s); \
4696 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
4697 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4698 x_append_glyph_string (&HEAD, &TAIL, s); \
4700 START = x_fill_glyph_string (s, face_id, START, END, \
4706 /* Add a glyph string for a composite sequence to the list of strings
4707 between HEAD and TAIL. START is the index of the first glyph in
4708 row area AREA of glyph row ROW that is part of the new glyph
4709 string. END is the index of the last glyph in that glyph row area.
4710 X is the current output position assigned to the new glyph string
4711 constructed. HL overrides that face of the glyph; e.g. it is
4712 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
4713 x-position of the drawing area. */
4715 #define BUILD_COMPOSITE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4717 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
4718 int face_id = (ROW)->glyphs[AREA][START].face_id; \
4719 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
4720 struct composition *cmp = composition_table[cmp_id]; \
4721 int glyph_len = cmp->glyph_len; \
4723 struct face **faces; \
4724 struct glyph_string *first_s = NULL; \
4727 base_face = base_face->ascii_face; \
4728 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
4729 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
4730 /* At first, fill in `char2b' and `faces'. */ \
4731 for (n = 0; n < glyph_len; n++) \
4733 int c = COMPOSITION_GLYPH (cmp, n); \
4734 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
4735 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
4736 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
4737 this_face_id, char2b + n, 1); \
4740 /* Make glyph_strings for each glyph sequence that is drawable by \
4741 the same face, and append them to HEAD/TAIL. */ \
4742 for (n = 0; n < cmp->glyph_len;) \
4744 s = (struct glyph_string *) alloca (sizeof *s); \
4745 x_init_glyph_string (s, char2b + n, W, ROW, AREA, START, HL); \
4746 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4754 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
4762 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4763 of AREA of glyph row ROW on window W between indices START and END.
4764 HL overrides the face for drawing glyph strings, e.g. it is
4765 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4766 x-positions of the drawing area.
4768 This is an ugly monster macro construct because we must use alloca
4769 to allocate glyph strings (because x_draw_glyphs can be called
4772 #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4775 HEAD = TAIL = NULL; \
4776 while (START < END) \
4778 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
4779 switch (first_glyph->type) \
4782 BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \
4783 TAIL, HL, X, LAST_X, \
4787 case COMPOSITE_GLYPH: \
4788 BUILD_COMPOSITE_GLYPH_STRING (W, ROW, AREA, START, END, \
4789 HEAD, TAIL, HL, X, LAST_X,\
4793 case STRETCH_GLYPH: \
4794 BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \
4795 HEAD, TAIL, HL, X, LAST_X); \
4799 BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \
4800 TAIL, HL, X, LAST_X); \
4807 x_set_glyph_string_background_width (s, START, LAST_X); \
4814 /* Draw glyphs between START and END in AREA of ROW on window W,
4815 starting at x-position X. X is relative to AREA in W. HL is a
4816 face-override with the following meaning:
4818 DRAW_NORMAL_TEXT draw normally
4819 DRAW_CURSOR draw in cursor face
4820 DRAW_MOUSE_FACE draw in mouse face.
4821 DRAW_INVERSE_VIDEO draw in mode line face
4822 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
4823 DRAW_IMAGE_RAISED draw an image with a raised relief around it
4825 If REAL_START is non-null, return in *REAL_START the real starting
4826 position for display. This can be different from START in case
4827 overlapping glyphs must be displayed. If REAL_END is non-null,
4828 return in *REAL_END the real end position for display. This can be
4829 different from END in case overlapping glyphs must be displayed.
4831 If OVERLAPS_P is non-zero, draw only the foreground of characters
4832 and clip to the physical height of ROW.
4834 Value is the x-position reached, relative to AREA of W. */
4837 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, real_start
, real_end
,
4841 struct glyph_row
*row
;
4842 enum glyph_row_area area
;
4844 enum draw_glyphs_face hl
;
4845 int *real_start
, *real_end
;
4848 struct glyph_string
*head
, *tail
;
4849 struct glyph_string
*s
;
4850 int last_x
, area_width
;
4854 /* Let's rather be paranoid than getting a SEGV. */
4855 end
= min (end
, row
->used
[area
]);
4856 start
= max (0, start
);
4857 start
= min (end
, start
);
4859 *real_start
= start
;
4863 /* Translate X to frame coordinates. Set last_x to the right
4864 end of the drawing area. */
4865 if (row
->full_width_p
)
4867 /* X is relative to the left edge of W, without scroll bars
4869 struct frame
*f
= XFRAME (w
->frame
);
4870 /* int width = FRAME_FLAGS_AREA_WIDTH (f); */
4871 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
4874 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4875 last_x
= window_left_x
+ area_width
;
4877 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4879 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4880 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4886 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
4887 last_x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
4891 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
4892 area_width
= window_box_width (w
, area
);
4893 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
4896 /* Build a doubly-linked list of glyph_string structures between
4897 head and tail from what we have to draw. Note that the macro
4898 BUILD_GLYPH_STRINGS will modify its start parameter. That's
4899 the reason we use a separate variable `i'. */
4901 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
4904 x_reached
= tail
->x
+ tail
->background_width
;
4908 /* If there are any glyphs with lbearing < 0 or rbearing > width in
4909 the row, redraw some glyphs in front or following the glyph
4910 strings built above. */
4911 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
4914 struct glyph_string
*h
, *t
;
4916 /* Compute overhangs for all glyph strings. */
4917 for (s
= head
; s
; s
= s
->next
)
4918 x_compute_glyph_string_overhangs (s
);
4920 /* Prepend glyph strings for glyphs in front of the first glyph
4921 string that are overwritten because of the first glyph
4922 string's left overhang. The background of all strings
4923 prepended must be drawn because the first glyph string
4925 i
= x_left_overwritten (head
);
4929 BUILD_GLYPH_STRINGS (w
, row
, area
, j
, start
, h
, t
,
4930 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4934 *real_start
= start
;
4935 x_compute_overhangs_and_x (t
, head
->x
, 1);
4936 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4939 /* Prepend glyph strings for glyphs in front of the first glyph
4940 string that overwrite that glyph string because of their
4941 right overhang. For these strings, only the foreground must
4942 be drawn, because it draws over the glyph string at `head'.
4943 The background must not be drawn because this would overwrite
4944 right overhangs of preceding glyphs for which no glyph
4946 i
= x_left_overwriting (head
);
4949 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, start
, h
, t
,
4950 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4952 for (s
= h
; s
; s
= s
->next
)
4953 s
->background_filled_p
= 1;
4956 x_compute_overhangs_and_x (t
, head
->x
, 1);
4957 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4960 /* Append glyphs strings for glyphs following the last glyph
4961 string tail that are overwritten by tail. The background of
4962 these strings has to be drawn because tail's foreground draws
4964 i
= x_right_overwritten (tail
);
4967 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4968 DRAW_NORMAL_TEXT
, x
, last_x
,
4970 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4971 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
4976 /* Append glyph strings for glyphs following the last glyph
4977 string tail that overwrite tail. The foreground of such
4978 glyphs has to be drawn because it writes into the background
4979 of tail. The background must not be drawn because it could
4980 paint over the foreground of following glyphs. */
4981 i
= x_right_overwriting (tail
);
4984 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4985 DRAW_NORMAL_TEXT
, x
, last_x
,
4987 for (s
= h
; s
; s
= s
->next
)
4988 s
->background_filled_p
= 1;
4989 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4990 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
4996 /* Draw all strings. */
4997 for (s
= head
; s
; s
= s
->next
)
4998 x_draw_glyph_string (s
);
5000 /* Value is the x-position up to which drawn, relative to AREA of W.
5001 This doesn't include parts drawn because of overhangs. */
5002 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
5003 if (!row
->full_width_p
)
5005 if (area
> LEFT_MARGIN_AREA
)
5006 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
5007 if (area
> TEXT_AREA
)
5008 x_reached
-= window_box_width (w
, TEXT_AREA
);
5015 /* Fix the display of area AREA of overlapping row ROW in window W. */
5018 x_fix_overlapping_area (w
, row
, area
)
5020 struct glyph_row
*row
;
5021 enum glyph_row_area area
;
5027 if (area
== LEFT_MARGIN_AREA
)
5029 else if (area
== TEXT_AREA
)
5030 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5032 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5033 + window_box_width (w
, TEXT_AREA
));
5035 for (i
= 0; i
< row
->used
[area
];)
5037 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
5039 int start
= i
, start_x
= x
;
5043 x
+= row
->glyphs
[area
][i
].pixel_width
;
5046 while (i
< row
->used
[area
]
5047 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
5049 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
5051 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
5056 x
+= row
->glyphs
[area
][i
].pixel_width
;
5065 /* Output LEN glyphs starting at START at the nominal cursor position.
5066 Advance the nominal cursor over the text. The global variable
5067 updated_window contains the window being updated, updated_row is
5068 the glyph row being updated, and updated_area is the area of that
5069 row being updated. */
5072 x_write_glyphs (start
, len
)
5073 struct glyph
*start
;
5076 int x
, hpos
, real_start
, real_end
;
5078 xassert (updated_window
&& updated_row
);
5083 hpos
= start
- updated_row
->glyphs
[updated_area
];
5084 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
5085 updated_row
, updated_area
,
5087 (updated_row
->inverse_p
5088 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
5089 &real_start
, &real_end
, 0);
5091 /* If we drew over the cursor, note that it is not visible any more. */
5092 note_overwritten_text_cursor (updated_window
, real_start
,
5093 real_end
- real_start
);
5097 /* Advance the output cursor. */
5098 output_cursor
.hpos
+= len
;
5099 output_cursor
.x
= x
;
5103 /* Insert LEN glyphs from START at the nominal cursor position. */
5106 x_insert_glyphs (start
, len
)
5107 struct glyph
*start
;
5112 int line_height
, shift_by_width
, shifted_region_width
;
5113 struct glyph_row
*row
;
5114 struct glyph
*glyph
;
5115 int frame_x
, frame_y
, hpos
, real_start
, real_end
;
5117 xassert (updated_window
&& updated_row
);
5120 f
= XFRAME (WINDOW_FRAME (w
));
5122 /* Get the height of the line we are in. */
5124 line_height
= row
->height
;
5126 /* Get the width of the glyphs to insert. */
5128 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
5129 shift_by_width
+= glyph
->pixel_width
;
5131 /* Get the width of the region to shift right. */
5132 shifted_region_width
= (window_box_width (w
, updated_area
)
5137 frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, output_cursor
.x
);
5138 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
5139 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5140 f
->output_data
.x
->normal_gc
,
5142 shifted_region_width
, line_height
,
5143 frame_x
+ shift_by_width
, frame_y
);
5145 /* Write the glyphs. */
5146 hpos
= start
- row
->glyphs
[updated_area
];
5147 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
5148 DRAW_NORMAL_TEXT
, &real_start
, &real_end
, 0);
5149 note_overwritten_text_cursor (w
, real_start
, real_end
- real_start
);
5151 /* Advance the output cursor. */
5152 output_cursor
.hpos
+= len
;
5153 output_cursor
.x
+= shift_by_width
;
5158 /* Delete N glyphs at the nominal cursor position. Not implemented
5169 /* Erase the current text line from the nominal cursor position
5170 (inclusive) to pixel column TO_X (exclusive). The idea is that
5171 everything from TO_X onward is already erased.
5173 TO_X is a pixel position relative to updated_area of
5174 updated_window. TO_X == -1 means clear to the end of this area. */
5177 x_clear_end_of_line (to_x
)
5181 struct window
*w
= updated_window
;
5182 int max_x
, min_y
, max_y
;
5183 int from_x
, from_y
, to_y
;
5185 xassert (updated_window
&& updated_row
);
5186 f
= XFRAME (w
->frame
);
5188 if (updated_row
->full_width_p
)
5190 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5191 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5192 && !w
->pseudo_window_p
)
5193 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5196 max_x
= window_box_width (w
, updated_area
);
5197 max_y
= window_text_bottom_y (w
);
5199 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
5200 of window. For TO_X > 0, truncate to end of drawing area. */
5206 to_x
= min (to_x
, max_x
);
5208 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
5210 /* Notice if the cursor will be cleared by this operation. */
5211 if (!updated_row
->full_width_p
)
5212 note_overwritten_text_cursor (w
, output_cursor
.hpos
, -1);
5214 from_x
= output_cursor
.x
;
5216 /* Translate to frame coordinates. */
5217 if (updated_row
->full_width_p
)
5219 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
5220 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
5224 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
5225 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
5228 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
5229 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
5230 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
5232 /* Prevent inadvertently clearing to end of the X window. */
5233 if (to_x
> from_x
&& to_y
> from_y
)
5236 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5237 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
5244 /* Clear entire frame. If updating_frame is non-null, clear that
5245 frame. Otherwise clear the selected frame. */
5255 f
= SELECTED_FRAME ();
5257 /* Clearing the frame will erase any cursor, so mark them all as no
5259 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5260 output_cursor
.hpos
= output_cursor
.vpos
= 0;
5261 output_cursor
.x
= -1;
5263 /* We don't set the output cursor here because there will always
5264 follow an explicit cursor_to. */
5266 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5268 /* We have to clear the scroll bars, too. If we have changed
5269 colors or something like that, then they should be notified. */
5270 x_scroll_bar_clear (f
);
5272 XFlush (FRAME_X_DISPLAY (f
));
5278 /* Invert the middle quarter of the frame for .15 sec. */
5280 /* We use the select system call to do the waiting, so we have to make
5281 sure it's available. If it isn't, we just won't do visual bells. */
5283 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5286 /* Subtract the `struct timeval' values X and Y, storing the result in
5287 *RESULT. Return 1 if the difference is negative, otherwise 0. */
5290 timeval_subtract (result
, x
, y
)
5291 struct timeval
*result
, x
, y
;
5293 /* Perform the carry for the later subtraction by updating y. This
5294 is safer because on some systems the tv_sec member is unsigned. */
5295 if (x
.tv_usec
< y
.tv_usec
)
5297 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
5298 y
.tv_usec
-= 1000000 * nsec
;
5302 if (x
.tv_usec
- y
.tv_usec
> 1000000)
5304 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
5305 y
.tv_usec
+= 1000000 * nsec
;
5309 /* Compute the time remaining to wait. tv_usec is certainly
5311 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
5312 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
5314 /* Return indication of whether the result should be considered
5316 return x
.tv_sec
< y
.tv_sec
;
5328 /* Create a GC that will use the GXxor function to flip foreground
5329 pixels into background pixels. */
5333 values
.function
= GXxor
;
5334 values
.foreground
= (f
->output_data
.x
->foreground_pixel
5335 ^ f
->output_data
.x
->background_pixel
);
5337 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5338 GCFunction
| GCForeground
, &values
);
5342 /* Get the height not including a menu bar widget. */
5343 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
5344 /* Height of each line to flash. */
5345 int flash_height
= FRAME_LINE_HEIGHT (f
);
5346 /* These will be the left and right margins of the rectangles. */
5347 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
5348 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
5352 /* Don't flash the area between a scroll bar and the frame
5353 edge it is next to. */
5354 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
5356 case vertical_scroll_bar_left
:
5357 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5360 case vertical_scroll_bar_right
:
5361 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5368 width
= flash_right
- flash_left
;
5370 /* If window is tall, flash top and bottom line. */
5371 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5373 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5375 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5376 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5377 width
, flash_height
);
5378 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5380 (height
- flash_height
5381 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5382 width
, flash_height
);
5385 /* If it is short, flash it all. */
5386 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5387 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5388 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5393 struct timeval wakeup
;
5395 EMACS_GET_TIME (wakeup
);
5397 /* Compute time to wait until, propagating carry from usecs. */
5398 wakeup
.tv_usec
+= 150000;
5399 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
5400 wakeup
.tv_usec
%= 1000000;
5402 /* Keep waiting until past the time wakeup. */
5405 struct timeval timeout
;
5407 EMACS_GET_TIME (timeout
);
5409 /* In effect, timeout = wakeup - timeout.
5410 Break if result would be negative. */
5411 if (timeval_subtract (&timeout
, wakeup
, timeout
))
5414 /* Try to wait that long--but we might wake up sooner. */
5415 select (0, NULL
, NULL
, NULL
, &timeout
);
5419 /* If window is tall, flash top and bottom line. */
5420 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5422 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5424 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5425 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5426 width
, flash_height
);
5427 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5429 (height
- flash_height
5430 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5431 width
, flash_height
);
5434 /* If it is short, flash it all. */
5435 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5436 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5437 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5439 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
5447 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
5450 /* Make audible bell. */
5455 struct frame
*f
= SELECTED_FRAME ();
5457 if (FRAME_X_DISPLAY (f
))
5459 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5466 XBell (FRAME_X_DISPLAY (f
), 0);
5467 XFlush (FRAME_X_DISPLAY (f
));
5474 /* Specify how many text lines, from the top of the window,
5475 should be affected by insert-lines and delete-lines operations.
5476 This, and those operations, are used only within an update
5477 that is bounded by calls to x_update_begin and x_update_end. */
5480 XTset_terminal_window (n
)
5483 /* This function intentionally left blank. */
5488 /***********************************************************************
5490 ***********************************************************************/
5492 /* Perform an insert-lines or delete-lines operation, inserting N
5493 lines or deleting -N lines at vertical position VPOS. */
5496 x_ins_del_lines (vpos
, n
)
5503 /* Scroll part of the display as described by RUN. */
5506 x_scroll_run (w
, run
)
5510 struct frame
*f
= XFRAME (w
->frame
);
5511 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5513 /* Get frame-relative bounding box of the text display area of W,
5514 without mode lines. Include in this box the flags areas to the
5515 left and right of W. */
5516 window_box (w
, -1, &x
, &y
, &width
, &height
);
5517 width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
5518 x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
5520 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5521 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5522 bottom_y
= y
+ height
;
5526 /* Scrolling up. Make sure we don't copy part of the mode
5527 line at the bottom. */
5528 if (from_y
+ run
->height
> bottom_y
)
5529 height
= bottom_y
- from_y
;
5531 height
= run
->height
;
5535 /* Scolling down. Make sure we don't copy over the mode line.
5537 if (to_y
+ run
->height
> bottom_y
)
5538 height
= bottom_y
- to_y
;
5540 height
= run
->height
;
5545 /* Cursor off. Will be switched on again in x_update_window_end. */
5549 XCopyArea (FRAME_X_DISPLAY (f
),
5550 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5551 f
->output_data
.x
->normal_gc
,
5561 /***********************************************************************
5563 ***********************************************************************/
5565 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5566 corner of the exposed rectangle. W and H are width and height of
5567 the exposed area. All are pixel values. W or H zero means redraw
5568 the entire frame. */
5571 expose_frame (f
, x
, y
, w
, h
)
5577 TRACE ((stderr
, "expose_frame "));
5579 /* No need to redraw if frame will be redrawn soon. */
5580 if (FRAME_GARBAGED_P (f
))
5582 TRACE ((stderr
, " garbaged\n"));
5586 /* If basic faces haven't been realized yet, there is no point in
5587 trying to redraw anything. This can happen when we get an expose
5588 event while Emacs is starting, e.g. by moving another window. */
5589 if (FRAME_FACE_CACHE (f
) == NULL
5590 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5592 TRACE ((stderr
, " no faces\n"));
5596 if (w
== 0 || h
== 0)
5599 r
.width
= CANON_X_UNIT (f
) * f
->width
;
5600 r
.height
= CANON_Y_UNIT (f
) * f
->height
;
5610 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
5611 expose_window_tree (XWINDOW (f
->root_window
), &r
);
5613 if (WINDOWP (f
->tool_bar_window
))
5615 struct window
*w
= XWINDOW (f
->tool_bar_window
);
5616 XRectangle window_rect
;
5617 XRectangle intersection_rect
;
5618 int window_x
, window_y
, window_width
, window_height
;
5621 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5622 window_rect
.x
= window_x
;
5623 window_rect
.y
= window_y
;
5624 window_rect
.width
= window_width
;
5625 window_rect
.height
= window_height
;
5627 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5628 expose_window (w
, &intersection_rect
);
5631 #ifndef USE_X_TOOLKIT
5632 if (WINDOWP (f
->menu_bar_window
))
5634 struct window
*w
= XWINDOW (f
->menu_bar_window
);
5635 XRectangle window_rect
;
5636 XRectangle intersection_rect
;
5637 int window_x
, window_y
, window_width
, window_height
;
5640 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5641 window_rect
.x
= window_x
;
5642 window_rect
.y
= window_y
;
5643 window_rect
.width
= window_width
;
5644 window_rect
.height
= window_height
;
5646 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5647 expose_window (w
, &intersection_rect
);
5649 #endif /* not USE_X_TOOLKIT */
5653 /* Redraw (parts) of all windows in the window tree rooted at W that
5654 intersect R. R contains frame pixel coordinates. */
5657 expose_window_tree (w
, r
)
5663 if (!NILP (w
->hchild
))
5664 expose_window_tree (XWINDOW (w
->hchild
), r
);
5665 else if (!NILP (w
->vchild
))
5666 expose_window_tree (XWINDOW (w
->vchild
), r
);
5669 XRectangle window_rect
;
5670 XRectangle intersection_rect
;
5671 struct frame
*f
= XFRAME (w
->frame
);
5672 int window_x
, window_y
, window_width
, window_height
;
5674 /* Frame-relative pixel rectangle of W. */
5675 window_box (w
, -1, &window_x
, &window_y
, &window_width
,
5679 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
5680 - FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5681 window_rect
.y
= window_y
;
5684 + FRAME_X_FLAGS_AREA_WIDTH (f
)
5685 + FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5687 = window_height
+ CURRENT_MODE_LINE_HEIGHT (w
);
5689 if (x_intersect_rectangles (r
, &window_rect
, &intersection_rect
))
5690 expose_window (w
, &intersection_rect
);
5693 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5698 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5699 which intersects rectangle R. R is in window-relative coordinates. */
5702 expose_area (w
, row
, r
, area
)
5704 struct glyph_row
*row
;
5706 enum glyph_row_area area
;
5709 struct glyph
*first
= row
->glyphs
[area
];
5710 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5714 /* Set x to the window-relative start position for drawing glyphs of
5715 AREA. The first glyph of the text area can be partially visible.
5716 The first glyphs of other areas cannot. */
5717 if (area
== LEFT_MARGIN_AREA
)
5719 else if (area
== TEXT_AREA
)
5720 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5722 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5723 + window_box_width (w
, TEXT_AREA
));
5725 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5726 /* If row extends face to end of line write the whole line. */
5727 x_draw_glyphs (w
, x
, row
, area
,
5729 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5733 /* Find the first glyph that must be redrawn. */
5735 && x
+ first
->pixel_width
< r
->x
)
5737 x
+= first
->pixel_width
;
5741 /* Find the last one. */
5745 && x
< r
->x
+ r
->width
)
5747 x
+= last
->pixel_width
;
5753 x_draw_glyphs (w
, first_x
, row
, area
,
5754 first
- row
->glyphs
[area
],
5755 last
- row
->glyphs
[area
],
5756 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5762 /* Redraw the parts of the glyph row ROW on window W intersecting
5763 rectangle R. R is in window-relative coordinates. */
5766 expose_line (w
, row
, r
)
5768 struct glyph_row
*row
;
5771 xassert (row
->enabled_p
);
5773 if (row
->mode_line_p
|| w
->pseudo_window_p
)
5774 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
5775 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5779 if (row
->used
[LEFT_MARGIN_AREA
])
5780 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
5781 if (row
->used
[TEXT_AREA
])
5782 expose_area (w
, row
, r
, TEXT_AREA
);
5783 if (row
->used
[RIGHT_MARGIN_AREA
])
5784 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
5785 x_draw_row_bitmaps (w
, row
);
5790 /* Return non-zero if W's cursor intersects rectangle R. */
5793 x_phys_cursor_in_rect_p (w
, r
)
5797 XRectangle cr
, result
;
5798 struct glyph
*cursor_glyph
;
5800 cursor_glyph
= get_phys_cursor_glyph (w
);
5803 cr
.x
= w
->phys_cursor
.x
;
5804 cr
.y
= w
->phys_cursor
.y
;
5805 cr
.width
= cursor_glyph
->pixel_width
;
5806 cr
.height
= w
->phys_cursor_height
;
5807 return x_intersect_rectangles (&cr
, r
, &result
);
5814 /* Redraw a rectangle of window W. R is a rectangle in window
5815 relative coordinates. Call this function with input blocked. */
5818 expose_window (w
, r
)
5822 struct glyph_row
*row
;
5824 int yb
= window_text_bottom_y (w
);
5825 int cursor_cleared_p
;
5827 /* If window is not yet fully initialized, do nothing. This can
5828 happen when toolkit scroll bars are used and a window is split.
5829 Reconfiguring the scroll bar will generate an expose for a newly
5831 if (w
->current_matrix
== NULL
)
5834 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
5835 r
->x
, r
->y
, r
->width
, r
->height
));
5837 /* Convert to window coordinates. */
5838 r
->x
= FRAME_TO_WINDOW_PIXEL_X (w
, r
->x
);
5839 r
->y
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
->y
);
5841 /* Turn off the cursor. */
5842 if (!w
->pseudo_window_p
5843 && x_phys_cursor_in_rect_p (w
, r
))
5846 cursor_cleared_p
= 1;
5849 cursor_cleared_p
= 0;
5851 /* Find the first row intersecting the rectangle R. */
5852 row
= w
->current_matrix
->rows
;
5854 while (row
->enabled_p
5856 && y
+ row
->height
< r
->y
)
5862 /* Display the text in the rectangle, one text line at a time. */
5863 while (row
->enabled_p
5865 && y
< r
->y
+ r
->height
)
5867 expose_line (w
, row
, r
);
5872 /* Display the mode line if there is one. */
5873 if (WINDOW_WANTS_MODELINE_P (w
)
5874 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
5876 && row
->y
< r
->y
+ r
->height
)
5877 expose_line (w
, row
, r
);
5879 if (!w
->pseudo_window_p
)
5881 /* Draw border between windows. */
5882 x_draw_vertical_border (w
);
5884 /* Turn the cursor on again. */
5885 if (cursor_cleared_p
)
5886 x_update_window_cursor (w
, 1);
5891 /* Determine the intersection of two rectangles R1 and R2. Return
5892 the intersection in *RESULT. Value is non-zero if RESULT is not
5896 x_intersect_rectangles (r1
, r2
, result
)
5897 XRectangle
*r1
, *r2
, *result
;
5899 XRectangle
*left
, *right
;
5900 XRectangle
*upper
, *lower
;
5901 int intersection_p
= 0;
5903 /* Rearrange so that R1 is the left-most rectangle. */
5905 left
= r1
, right
= r2
;
5907 left
= r2
, right
= r1
;
5909 /* X0 of the intersection is right.x0, if this is inside R1,
5910 otherwise there is no intersection. */
5911 if (right
->x
<= left
->x
+ left
->width
)
5913 result
->x
= right
->x
;
5915 /* The right end of the intersection is the minimum of the
5916 the right ends of left and right. */
5917 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
5920 /* Same game for Y. */
5922 upper
= r1
, lower
= r2
;
5924 upper
= r2
, lower
= r1
;
5926 /* The upper end of the intersection is lower.y0, if this is inside
5927 of upper. Otherwise, there is no intersection. */
5928 if (lower
->y
<= upper
->y
+ upper
->height
)
5930 result
->y
= lower
->y
;
5932 /* The lower end of the intersection is the minimum of the lower
5933 ends of upper and lower. */
5934 result
->height
= (min (lower
->y
+ lower
->height
,
5935 upper
->y
+ upper
->height
)
5941 return intersection_p
;
5952 /* We used to only do this if Vx_no_window_manager was non-nil, but
5953 the ICCCM (section 4.1.6) says that the window's border pixmap
5954 and border pixel are window attributes which are "private to the
5955 client", so we can always change it to whatever we want. */
5957 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5958 f
->output_data
.x
->border_pixel
);
5960 x_update_cursor (f
, 1);
5964 frame_unhighlight (f
)
5967 /* We used to only do this if Vx_no_window_manager was non-nil, but
5968 the ICCCM (section 4.1.6) says that the window's border pixmap
5969 and border pixel are window attributes which are "private to the
5970 client", so we can always change it to whatever we want. */
5972 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5973 f
->output_data
.x
->border_tile
);
5975 x_update_cursor (f
, 1);
5978 /* The focus has changed. Update the frames as necessary to reflect
5979 the new situation. Note that we can't change the selected frame
5980 here, because the Lisp code we are interrupting might become confused.
5981 Each event gets marked with the frame in which it occurred, so the
5982 Lisp code can tell when the switch took place by examining the events. */
5985 x_new_focus_frame (dpyinfo
, frame
)
5986 struct x_display_info
*dpyinfo
;
5987 struct frame
*frame
;
5989 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
5991 if (frame
!= dpyinfo
->x_focus_frame
)
5993 /* Set this before calling other routines, so that they see
5994 the correct value of x_focus_frame. */
5995 dpyinfo
->x_focus_frame
= frame
;
5997 if (old_focus
&& old_focus
->auto_lower
)
5998 x_lower_frame (old_focus
);
6001 selected_frame
= frame
;
6002 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
6004 Fselect_window (selected_frame
->selected_window
);
6005 choose_minibuf_frame ();
6008 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
6009 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
6011 pending_autoraise_frame
= 0;
6014 x_frame_rehighlight (dpyinfo
);
6017 /* Handle an event saying the mouse has moved out of an Emacs frame. */
6020 x_mouse_leave (dpyinfo
)
6021 struct x_display_info
*dpyinfo
;
6023 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
6026 /* The focus has changed, or we have redirected a frame's focus to
6027 another frame (this happens when a frame uses a surrogate
6028 mini-buffer frame). Shift the highlight as appropriate.
6030 The FRAME argument doesn't necessarily have anything to do with which
6031 frame is being highlighted or un-highlighted; we only use it to find
6032 the appropriate X display info. */
6035 XTframe_rehighlight (frame
)
6036 struct frame
*frame
;
6038 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
6042 x_frame_rehighlight (dpyinfo
)
6043 struct x_display_info
*dpyinfo
;
6045 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
6047 if (dpyinfo
->x_focus_frame
)
6049 dpyinfo
->x_highlight_frame
6050 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
6051 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
6052 : dpyinfo
->x_focus_frame
);
6053 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
6055 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
6056 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
6060 dpyinfo
->x_highlight_frame
= 0;
6062 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
6065 frame_unhighlight (old_highlight
);
6066 if (dpyinfo
->x_highlight_frame
)
6067 frame_highlight (dpyinfo
->x_highlight_frame
);
6073 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
6075 /* Initialize mode_switch_bit and modifier_meaning. */
6077 x_find_modifier_meanings (dpyinfo
)
6078 struct x_display_info
*dpyinfo
;
6080 int min_code
, max_code
;
6083 XModifierKeymap
*mods
;
6085 dpyinfo
->meta_mod_mask
= 0;
6086 dpyinfo
->shift_lock_mask
= 0;
6087 dpyinfo
->alt_mod_mask
= 0;
6088 dpyinfo
->super_mod_mask
= 0;
6089 dpyinfo
->hyper_mod_mask
= 0;
6092 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
6094 min_code
= dpyinfo
->display
->min_keycode
;
6095 max_code
= dpyinfo
->display
->max_keycode
;
6098 syms
= XGetKeyboardMapping (dpyinfo
->display
,
6099 min_code
, max_code
- min_code
+ 1,
6101 mods
= XGetModifierMapping (dpyinfo
->display
);
6103 /* Scan the modifier table to see which modifier bits the Meta and
6104 Alt keysyms are on. */
6106 int row
, col
; /* The row and column in the modifier table. */
6108 for (row
= 3; row
< 8; row
++)
6109 for (col
= 0; col
< mods
->max_keypermod
; col
++)
6112 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
6114 /* Zeroes are used for filler. Skip them. */
6118 /* Are any of this keycode's keysyms a meta key? */
6122 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
6124 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
6130 dpyinfo
->meta_mod_mask
|= (1 << row
);
6135 dpyinfo
->alt_mod_mask
|= (1 << row
);
6140 dpyinfo
->hyper_mod_mask
|= (1 << row
);
6145 dpyinfo
->super_mod_mask
|= (1 << row
);
6149 /* Ignore this if it's not on the lock modifier. */
6150 if ((1 << row
) == LockMask
)
6151 dpyinfo
->shift_lock_mask
= LockMask
;
6159 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
6160 if (! dpyinfo
->meta_mod_mask
)
6162 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
6163 dpyinfo
->alt_mod_mask
= 0;
6166 /* If some keys are both alt and meta,
6167 make them just meta, not alt. */
6168 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
6170 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
6173 XFree ((char *) syms
);
6174 XFreeModifiermap (mods
);
6177 /* Convert between the modifier bits X uses and the modifier bits
6181 x_x_to_emacs_modifiers (dpyinfo
, state
)
6182 struct x_display_info
*dpyinfo
;
6185 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
6186 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
6187 | ((state
& dpyinfo
->meta_mod_mask
) ? meta_modifier
: 0)
6188 | ((state
& dpyinfo
->alt_mod_mask
) ? alt_modifier
: 0)
6189 | ((state
& dpyinfo
->super_mod_mask
) ? super_modifier
: 0)
6190 | ((state
& dpyinfo
->hyper_mod_mask
) ? hyper_modifier
: 0));
6194 x_emacs_to_x_modifiers (dpyinfo
, state
)
6195 struct x_display_info
*dpyinfo
;
6198 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
6199 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
6200 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
6201 | ((state
& shift_modifier
) ? ShiftMask
: 0)
6202 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
6203 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
6206 /* Convert a keysym to its name. */
6209 x_get_keysym_name (keysym
)
6215 value
= XKeysymToString (keysym
);
6223 /* Mouse clicks and mouse movement. Rah. */
6225 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
6226 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
6227 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
6228 not force the value into range. */
6231 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
6233 register int pix_x
, pix_y
;
6234 register int *x
, *y
;
6238 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
6239 even for negative values. */
6241 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
6243 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
6245 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
6246 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
6250 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
6251 bounds
->height
= f
->output_data
.x
->line_height
;
6252 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
6253 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
6260 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
6261 pix_x
= FRAME_WINDOW_WIDTH (f
);
6265 else if (pix_y
> f
->height
)
6274 /* Given HPOS/VPOS in the current matrix of W, return corresponding
6275 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
6276 can't tell the positions because W's display is not up to date,
6280 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
6283 int *frame_x
, *frame_y
;
6287 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
6288 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
6290 if (display_completed
)
6292 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6293 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
6294 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
6300 *frame_x
+= glyph
->pixel_width
;
6308 *frame_y
= *frame_x
= 0;
6312 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
6313 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6318 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6320 If the event is a button press, then note that we have grabbed
6324 construct_mouse_click (result
, event
, f
)
6325 struct input_event
*result
;
6326 XButtonEvent
*event
;
6329 /* Make the event type no_event; we'll change that when we decide
6331 result
->kind
= mouse_click
;
6332 result
->code
= event
->button
- Button1
;
6333 result
->timestamp
= event
->time
;
6334 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6336 | (event
->type
== ButtonRelease
6340 XSETINT (result
->x
, event
->x
);
6341 XSETINT (result
->y
, event
->y
);
6342 XSETFRAME (result
->frame_or_window
, f
);
6348 /* Function to report a mouse movement to the mainstream Emacs code.
6349 The input handler calls this.
6351 We have received a mouse movement event, which is given in *event.
6352 If the mouse is over a different glyph than it was last time, tell
6353 the mainstream emacs code by setting mouse_moved. If not, ask for
6354 another motion event, so we can check again the next time it moves. */
6356 static XMotionEvent last_mouse_motion_event
;
6357 static Lisp_Object last_mouse_motion_frame
;
6360 note_mouse_movement (frame
, event
)
6362 XMotionEvent
*event
;
6364 last_mouse_movement_time
= event
->time
;
6365 last_mouse_motion_event
= *event
;
6366 XSETFRAME (last_mouse_motion_frame
, frame
);
6368 if (event
->window
!= FRAME_X_WINDOW (frame
))
6370 frame
->mouse_moved
= 1;
6371 last_mouse_scroll_bar
= Qnil
;
6372 note_mouse_highlight (frame
, -1, -1);
6375 /* Has the mouse moved off the glyph it was on at the last sighting? */
6376 else if (event
->x
< last_mouse_glyph
.x
6377 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
6378 || event
->y
< last_mouse_glyph
.y
6379 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
6381 frame
->mouse_moved
= 1;
6382 last_mouse_scroll_bar
= Qnil
;
6383 note_mouse_highlight (frame
, event
->x
, event
->y
);
6387 /* This is used for debugging, to turn off note_mouse_highlight. */
6389 int disable_mouse_highlight
;
6393 /************************************************************************
6395 ************************************************************************/
6397 /* Find the glyph under window-relative coordinates X/Y in window W.
6398 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6399 strings. Return in *HPOS and *VPOS the row and column number of
6400 the glyph found. Return in *AREA the glyph area containing X.
6401 Value is a pointer to the glyph found or null if X/Y is not on
6402 text, or we can't tell because W's current matrix is not up to
6405 static struct glyph
*
6406 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
)
6409 int *hpos
, *vpos
, *area
;
6411 struct glyph
*glyph
, *end
;
6412 struct glyph_row
*row
= NULL
;
6413 int x0
, i
, left_area_width
;
6415 /* Find row containing Y. Give up if some row is not enabled. */
6416 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6418 row
= MATRIX_ROW (w
->current_matrix
, i
);
6419 if (!row
->enabled_p
)
6421 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6428 /* Give up if Y is not in the window. */
6429 if (i
== w
->current_matrix
->nrows
)
6432 /* Get the glyph area containing X. */
6433 if (w
->pseudo_window_p
)
6440 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6441 if (x
< left_area_width
)
6443 *area
= LEFT_MARGIN_AREA
;
6446 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6449 x0
= row
->x
+ left_area_width
;
6453 *area
= RIGHT_MARGIN_AREA
;
6454 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6458 /* Find glyph containing X. */
6459 glyph
= row
->glyphs
[*area
];
6460 end
= glyph
+ row
->used
[*area
];
6463 if (x
< x0
+ glyph
->pixel_width
)
6465 if (w
->pseudo_window_p
)
6467 else if (BUFFERP (glyph
->object
))
6471 x0
+= glyph
->pixel_width
;
6478 *hpos
= glyph
- row
->glyphs
[*area
];
6483 /* Convert frame-relative x/y to coordinates relative to window W.
6484 Takes pseudo-windows into account. */
6487 frame_to_window_pixel_xy (w
, x
, y
)
6491 if (w
->pseudo_window_p
)
6493 /* A pseudo-window is always full-width, and starts at the
6494 left edge of the frame, plus a frame border. */
6495 struct frame
*f
= XFRAME (w
->frame
);
6496 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6497 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6501 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6502 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6507 /* Take proper action when mouse has moved to the mode or top line of
6508 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6509 mode line. X is relative to the start of the text display area of
6510 W, so the width of bitmap areas and scroll bars must be subtracted
6511 to get a position relative to the start of the mode line. */
6514 note_mode_line_highlight (w
, x
, mode_line_p
)
6518 struct frame
*f
= XFRAME (w
->frame
);
6519 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6520 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6521 struct glyph_row
*row
;
6524 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
6526 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
6530 struct glyph
*glyph
, *end
;
6531 Lisp_Object help
, map
;
6534 /* Find the glyph under X. */
6535 glyph
= row
->glyphs
[TEXT_AREA
];
6536 end
= glyph
+ row
->used
[TEXT_AREA
];
6537 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6538 + FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
));
6540 && x
>= x0
+ glyph
->pixel_width
)
6542 x0
+= glyph
->pixel_width
;
6547 && STRINGP (glyph
->object
)
6548 && XSTRING (glyph
->object
)->intervals
6549 && glyph
->charpos
>= 0
6550 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6552 /* If we're on a string with `help-echo' text property,
6553 arrange for the help to be displayed. This is done by
6554 setting the global variable help_echo to the help string. */
6555 help
= Fget_text_property (make_number (glyph
->charpos
),
6556 Qhelp_echo
, glyph
->object
);
6560 XSETWINDOW (help_echo_window
, w
);
6561 help_echo_object
= glyph
->object
;
6562 help_echo_pos
= glyph
->charpos
;
6565 /* Change the mouse pointer according to what is under X/Y. */
6566 map
= Fget_text_property (make_number (glyph
->charpos
),
6567 Qlocal_map
, glyph
->object
);
6569 cursor
= f
->output_data
.x
->nontext_cursor
;
6572 map
= Fget_text_property (make_number (glyph
->charpos
),
6573 Qkeymap
, glyph
->object
);
6575 cursor
= f
->output_data
.x
->nontext_cursor
;
6580 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6584 /* Take proper action when the mouse has moved to position X, Y on
6585 frame F as regards highlighting characters that have mouse-face
6586 properties. Also de-highlighting chars where the mouse was before.
6587 X and Y can be negative or out of range. */
6590 note_mouse_highlight (f
, x
, y
)
6594 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6599 /* When a menu is active, don't highlight because this looks odd. */
6600 #ifdef USE_X_TOOLKIT
6601 if (popup_activated ())
6605 if (disable_mouse_highlight
6606 || !f
->glyphs_initialized_p
)
6609 dpyinfo
->mouse_face_mouse_x
= x
;
6610 dpyinfo
->mouse_face_mouse_y
= y
;
6611 dpyinfo
->mouse_face_mouse_frame
= f
;
6613 if (dpyinfo
->mouse_face_defer
)
6618 dpyinfo
->mouse_face_deferred_gc
= 1;
6622 /* Which window is that in? */
6623 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6625 /* If we were displaying active text in another window, clear that. */
6626 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6627 clear_mouse_face (dpyinfo
);
6629 /* Not on a window -> return. */
6630 if (!WINDOWP (window
))
6633 /* Convert to window-relative pixel coordinates. */
6634 w
= XWINDOW (window
);
6635 frame_to_window_pixel_xy (w
, &x
, &y
);
6637 /* Handle tool-bar window differently since it doesn't display a
6639 if (EQ (window
, f
->tool_bar_window
))
6641 note_tool_bar_highlight (f
, x
, y
);
6645 if (portion
== 1 || portion
== 3)
6647 /* Mouse is on the mode or top line. */
6648 note_mode_line_highlight (w
, x
, portion
== 1);
6652 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6653 f
->output_data
.x
->text_cursor
);
6655 /* Are we in a window whose display is up to date?
6656 And verify the buffer's text has not changed. */
6657 if (/* Within text portion of the window. */
6659 && EQ (w
->window_end_valid
, w
->buffer
)
6660 && XFASTINT (w
->last_modified
) == BUF_MODIFF (XBUFFER (w
->buffer
))
6661 && (XFASTINT (w
->last_overlay_modified
)
6662 == BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
))))
6664 int hpos
, vpos
, pos
, i
, area
;
6665 struct glyph
*glyph
;
6667 /* Find the glyph under X/Y. */
6668 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
);
6670 /* Clear mouse face if X/Y not over text. */
6672 || area
!= TEXT_AREA
6673 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6675 clear_mouse_face (dpyinfo
);
6679 pos
= glyph
->charpos
;
6680 xassert (w
->pseudo_window_p
|| BUFFERP (glyph
->object
));
6682 /* Check for mouse-face and help-echo. */
6684 Lisp_Object mouse_face
, overlay
, position
;
6685 Lisp_Object
*overlay_vec
;
6687 struct buffer
*obuf
;
6690 /* If we get an out-of-range value, return now; avoid an error. */
6691 if (pos
> BUF_Z (XBUFFER (w
->buffer
)))
6694 /* Make the window's buffer temporarily current for
6695 overlays_at and compute_char_face. */
6696 obuf
= current_buffer
;
6697 current_buffer
= XBUFFER (w
->buffer
);
6703 /* Is this char mouse-active or does it have help-echo? */
6704 XSETINT (position
, pos
);
6706 /* Put all the overlays we want in a vector in overlay_vec.
6707 Store the length in len. If there are more than 10, make
6708 enough space for all, and try again. */
6710 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6711 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
6712 if (noverlays
> len
)
6715 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6716 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
6719 /* Sort overlays into increasing priority order. */
6720 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6722 /* Check mouse-face highlighting. */
6723 if (! (EQ (window
, dpyinfo
->mouse_face_window
)
6724 && vpos
>= dpyinfo
->mouse_face_beg_row
6725 && vpos
<= dpyinfo
->mouse_face_end_row
6726 && (vpos
> dpyinfo
->mouse_face_beg_row
6727 || hpos
>= dpyinfo
->mouse_face_beg_col
)
6728 && (vpos
< dpyinfo
->mouse_face_end_row
6729 || hpos
< dpyinfo
->mouse_face_end_col
6730 || dpyinfo
->mouse_face_past_end
)))
6732 /* Clear the display of the old active region, if any. */
6733 clear_mouse_face (dpyinfo
);
6735 /* Find the highest priority overlay that has a mouse-face prop. */
6737 for (i
= noverlays
- 1; i
>= 0; --i
)
6739 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
6740 if (!NILP (mouse_face
))
6742 overlay
= overlay_vec
[i
];
6747 /* If no overlay applies, get a text property. */
6749 mouse_face
= Fget_text_property (position
, Qmouse_face
, w
->buffer
);
6751 /* Handle the overlay case. */
6752 if (! NILP (overlay
))
6754 /* Find the range of text around this char that
6755 should be active. */
6756 Lisp_Object before
, after
;
6759 before
= Foverlay_start (overlay
);
6760 after
= Foverlay_end (overlay
);
6761 /* Record this as the current active region. */
6762 fast_find_position (w
, XFASTINT (before
),
6763 &dpyinfo
->mouse_face_beg_col
,
6764 &dpyinfo
->mouse_face_beg_row
,
6765 &dpyinfo
->mouse_face_beg_x
,
6766 &dpyinfo
->mouse_face_beg_y
);
6767 dpyinfo
->mouse_face_past_end
6768 = !fast_find_position (w
, XFASTINT (after
),
6769 &dpyinfo
->mouse_face_end_col
,
6770 &dpyinfo
->mouse_face_end_row
,
6771 &dpyinfo
->mouse_face_end_x
,
6772 &dpyinfo
->mouse_face_end_y
);
6773 dpyinfo
->mouse_face_window
= window
;
6774 dpyinfo
->mouse_face_face_id
6775 = face_at_buffer_position (w
, pos
, 0, 0,
6776 &ignore
, pos
+ 1, 1);
6778 /* Display it as active. */
6779 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6781 /* Handle the text property case. */
6782 else if (! NILP (mouse_face
))
6784 /* Find the range of text around this char that
6785 should be active. */
6786 Lisp_Object before
, after
, beginning
, end
;
6789 beginning
= Fmarker_position (w
->start
);
6790 XSETINT (end
, (BUF_Z (XBUFFER (w
->buffer
))
6791 - XFASTINT (w
->window_end_pos
)));
6793 = Fprevious_single_property_change (make_number (pos
+ 1),
6795 w
->buffer
, beginning
);
6797 = Fnext_single_property_change (position
, Qmouse_face
,
6799 /* Record this as the current active region. */
6800 fast_find_position (w
, XFASTINT (before
),
6801 &dpyinfo
->mouse_face_beg_col
,
6802 &dpyinfo
->mouse_face_beg_row
,
6803 &dpyinfo
->mouse_face_beg_x
,
6804 &dpyinfo
->mouse_face_beg_y
);
6805 dpyinfo
->mouse_face_past_end
6806 = !fast_find_position (w
, XFASTINT (after
),
6807 &dpyinfo
->mouse_face_end_col
,
6808 &dpyinfo
->mouse_face_end_row
,
6809 &dpyinfo
->mouse_face_end_x
,
6810 &dpyinfo
->mouse_face_end_y
);
6811 dpyinfo
->mouse_face_window
= window
;
6812 dpyinfo
->mouse_face_face_id
6813 = face_at_buffer_position (w
, pos
, 0, 0,
6814 &ignore
, pos
+ 1, 1);
6816 /* Display it as active. */
6817 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6821 /* Look for a `help-echo' property. */
6823 Lisp_Object help
, overlay
;
6825 /* Check overlays first. */
6826 help
= overlay
= Qnil
;
6827 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
6829 overlay
= overlay_vec
[i
];
6830 help
= Foverlay_get (overlay
, Qhelp_echo
);
6836 help_echo_window
= window
;
6837 help_echo_object
= overlay
;
6838 help_echo_pos
= pos
;
6842 /* Try text properties. */
6843 if ((STRINGP (glyph
->object
)
6844 && glyph
->charpos
>= 0
6845 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6846 || (BUFFERP (glyph
->object
)
6847 && glyph
->charpos
>= BEGV
6848 && glyph
->charpos
< ZV
))
6849 help
= Fget_text_property (make_number (glyph
->charpos
),
6850 Qhelp_echo
, glyph
->object
);
6855 help_echo_window
= window
;
6856 help_echo_object
= glyph
->object
;
6857 help_echo_pos
= glyph
->charpos
;
6864 current_buffer
= obuf
;
6870 redo_mouse_highlight ()
6872 if (!NILP (last_mouse_motion_frame
)
6873 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
6874 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
6875 last_mouse_motion_event
.x
,
6876 last_mouse_motion_event
.y
);
6881 /***********************************************************************
6883 ***********************************************************************/
6885 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
6886 struct glyph
**, int *, int *, int *));
6888 /* Tool-bar item index of the item on which a mouse button was pressed
6891 static int last_tool_bar_item
;
6894 /* Get information about the tool-bar item at position X/Y on frame F.
6895 Return in *GLYPH a pointer to the glyph of the tool-bar item in
6896 the current matrix of the tool-bar window of F, or NULL if not
6897 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
6898 item in F->current_tool_bar_items. Value is
6900 -1 if X/Y is not on a tool-bar item
6901 0 if X/Y is on the same item that was highlighted before.
6905 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
6908 struct glyph
**glyph
;
6909 int *hpos
, *vpos
, *prop_idx
;
6911 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6912 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6915 /* Find the glyph under X/Y. */
6916 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
);
6920 /* Get the start of this tool-bar item's properties in
6921 f->current_tool_bar_items. */
6922 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
6925 /* Is mouse on the highlighted item? */
6926 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
6927 && *vpos
>= dpyinfo
->mouse_face_beg_row
6928 && *vpos
<= dpyinfo
->mouse_face_end_row
6929 && (*vpos
> dpyinfo
->mouse_face_beg_row
6930 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
6931 && (*vpos
< dpyinfo
->mouse_face_end_row
6932 || *hpos
< dpyinfo
->mouse_face_end_col
6933 || dpyinfo
->mouse_face_past_end
))
6940 /* Handle mouse button event on the tool-bar of frame F, at
6941 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
6945 x_handle_tool_bar_click (f
, button_event
)
6947 XButtonEvent
*button_event
;
6949 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6950 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6951 int hpos
, vpos
, prop_idx
;
6952 struct glyph
*glyph
;
6953 Lisp_Object enabled_p
;
6954 int x
= button_event
->x
;
6955 int y
= button_event
->y
;
6957 /* If not on the highlighted tool-bar item, return. */
6958 frame_to_window_pixel_xy (w
, &x
, &y
);
6959 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
6962 /* If item is disabled, do nothing. */
6963 enabled_p
= (XVECTOR (f
->current_tool_bar_items
)
6964 ->contents
[prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
]);
6965 if (NILP (enabled_p
))
6968 if (button_event
->type
== ButtonPress
)
6970 /* Show item in pressed state. */
6971 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
6972 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
6973 last_tool_bar_item
= prop_idx
;
6977 Lisp_Object key
, frame
;
6978 struct input_event event
;
6980 /* Show item in released state. */
6981 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
6982 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
6984 key
= (XVECTOR (f
->current_tool_bar_items
)
6985 ->contents
[prop_idx
+ TOOL_BAR_ITEM_KEY
]);
6987 XSETFRAME (frame
, f
);
6988 event
.kind
= TOOL_BAR_EVENT
;
6989 event
.frame_or_window
= frame
;
6991 kbd_buffer_store_event (&event
);
6993 event
.kind
= TOOL_BAR_EVENT
;
6994 event
.frame_or_window
= frame
;
6996 event
.modifiers
= x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6997 button_event
->state
);
6998 kbd_buffer_store_event (&event
);
6999 last_tool_bar_item
= -1;
7004 /* Possibly highlight a tool-bar item on frame F when mouse moves to
7005 tool-bar window-relative coordinates X/Y. Called from
7006 note_mouse_highlight. */
7009 note_tool_bar_highlight (f
, x
, y
)
7013 Lisp_Object window
= f
->tool_bar_window
;
7014 struct window
*w
= XWINDOW (window
);
7015 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7017 struct glyph
*glyph
;
7018 struct glyph_row
*row
;
7020 Lisp_Object enabled_p
;
7022 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
7023 int mouse_down_p
, rc
;
7025 /* Function note_mouse_highlight is called with negative x(y
7026 values when mouse moves outside of the frame. */
7027 if (x
<= 0 || y
<= 0)
7029 clear_mouse_face (dpyinfo
);
7033 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
7036 /* Not on tool-bar item. */
7037 clear_mouse_face (dpyinfo
);
7041 /* On same tool-bar item as before. */
7044 clear_mouse_face (dpyinfo
);
7046 /* Mouse is down, but on different tool-bar item? */
7047 mouse_down_p
= (dpyinfo
->grabbed
7048 && f
== last_mouse_frame
7049 && FRAME_LIVE_P (f
));
7051 && last_tool_bar_item
!= prop_idx
)
7054 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
7055 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
7057 /* If tool-bar item is not enabled, don't highlight it. */
7058 enabled_p
= (XVECTOR (f
->current_tool_bar_items
)
7059 ->contents
[prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
]);
7060 if (!NILP (enabled_p
))
7062 /* Compute the x-position of the glyph. In front and past the
7063 image is a space. We include this is the highlighted area. */
7064 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
7065 for (i
= x
= 0; i
< hpos
; ++i
)
7066 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
7068 /* Record this as the current active region. */
7069 dpyinfo
->mouse_face_beg_col
= hpos
;
7070 dpyinfo
->mouse_face_beg_row
= vpos
;
7071 dpyinfo
->mouse_face_beg_x
= x
;
7072 dpyinfo
->mouse_face_beg_y
= row
->y
;
7073 dpyinfo
->mouse_face_past_end
= 0;
7075 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
7076 dpyinfo
->mouse_face_end_row
= vpos
;
7077 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
7078 dpyinfo
->mouse_face_end_y
= row
->y
;
7079 dpyinfo
->mouse_face_window
= window
;
7080 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
7082 /* Display it as active. */
7083 show_mouse_face (dpyinfo
, draw
);
7084 dpyinfo
->mouse_face_image_state
= draw
;
7089 /* Set help_echo to a help string.to display for this tool-bar item.
7090 XTread_socket does the rest. */
7091 help_echo_object
= help_echo_window
= Qnil
;
7093 help_echo
= (XVECTOR (f
->current_tool_bar_items
)
7094 ->contents
[prop_idx
+ TOOL_BAR_ITEM_HELP
]);
7095 if (NILP (help_echo
))
7096 help_echo
= (XVECTOR (f
->current_tool_bar_items
)
7097 ->contents
[prop_idx
+ TOOL_BAR_ITEM_CAPTION
]);
7102 /* Find the glyph matrix position of buffer position POS in window W.
7103 *HPOS, *VPOS, *X, and *Y are set to the positions found. W's
7104 current glyphs must be up to date. If POS is above window start
7105 return (0, 0, 0, 0). If POS is after end of W, return end of
7109 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
)
7112 int *hpos
, *vpos
, *x
, *y
;
7116 int maybe_next_line_p
= 0;
7117 int line_start_position
;
7118 int yb
= window_text_bottom_y (w
);
7119 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, 0);
7120 struct glyph_row
*best_row
= row
;
7121 int row_vpos
= 0, best_row_vpos
= 0;
7126 if (row
->used
[TEXT_AREA
])
7127 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
7129 line_start_position
= 0;
7131 if (line_start_position
> pos
)
7133 /* If the position sought is the end of the buffer,
7134 don't include the blank lines at the bottom of the window. */
7135 else if (line_start_position
== pos
7136 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
7138 maybe_next_line_p
= 1;
7141 else if (line_start_position
> 0)
7144 best_row_vpos
= row_vpos
;
7147 if (row
->y
+ row
->height
>= yb
)
7154 /* Find the right column within BEST_ROW. */
7156 current_x
= best_row
->x
;
7157 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
7159 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
7162 charpos
= glyph
->charpos
;
7166 *vpos
= best_row_vpos
;
7171 else if (charpos
> pos
)
7173 else if (charpos
> 0)
7176 current_x
+= glyph
->pixel_width
;
7179 /* If we're looking for the end of the buffer,
7180 and we didn't find it in the line we scanned,
7181 use the start of the following line. */
7182 if (maybe_next_line_p
)
7187 current_x
= best_row
->x
;
7190 *vpos
= best_row_vpos
;
7191 *hpos
= lastcol
+ 1;
7198 /* Display the active region described by mouse_face_*
7199 in its mouse-face if HL > 0, in its normal face if HL = 0. */
7202 show_mouse_face (dpyinfo
, draw
)
7203 struct x_display_info
*dpyinfo
;
7204 enum draw_glyphs_face draw
;
7206 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
7207 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7209 int cursor_off_p
= 0;
7210 struct cursor_pos saved_cursor
;
7212 saved_cursor
= output_cursor
;
7214 /* If window is in the process of being destroyed, don't bother
7216 if (w
->current_matrix
== NULL
)
7219 /* Recognize when we are called to operate on rows that don't exist
7220 anymore. This can happen when a window is split. */
7221 if (dpyinfo
->mouse_face_end_row
>= w
->current_matrix
->nrows
)
7224 set_output_cursor (&w
->phys_cursor
);
7226 /* Note that mouse_face_beg_row etc. are window relative. */
7227 for (i
= dpyinfo
->mouse_face_beg_row
;
7228 i
<= dpyinfo
->mouse_face_end_row
;
7231 int start_hpos
, end_hpos
, start_x
;
7232 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, i
);
7234 /* Don't do anything if row doesn't have valid contents. */
7235 if (!row
->enabled_p
)
7238 /* For all but the first row, the highlight starts at column 0. */
7239 if (i
== dpyinfo
->mouse_face_beg_row
)
7241 start_hpos
= dpyinfo
->mouse_face_beg_col
;
7242 start_x
= dpyinfo
->mouse_face_beg_x
;
7250 if (i
== dpyinfo
->mouse_face_end_row
)
7251 end_hpos
= dpyinfo
->mouse_face_end_col
;
7253 end_hpos
= row
->used
[TEXT_AREA
];
7255 /* If the cursor's in the text we are about to rewrite, turn the
7257 if (!w
->pseudo_window_p
7258 && i
== output_cursor
.vpos
7259 && output_cursor
.hpos
>= start_hpos
- 1
7260 && output_cursor
.hpos
<= end_hpos
)
7262 x_update_window_cursor (w
, 0);
7266 if (end_hpos
> start_hpos
)
7268 row
->mouse_face_p
= draw
== DRAW_MOUSE_FACE
;
7269 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
7270 start_hpos
, end_hpos
, draw
, NULL
, NULL
, 0);
7274 /* If we turned the cursor off, turn it back on. */
7276 x_display_cursor (w
, 1,
7277 output_cursor
.hpos
, output_cursor
.vpos
,
7278 output_cursor
.x
, output_cursor
.y
);
7280 output_cursor
= saved_cursor
;
7284 /* Change the mouse cursor. */
7285 if (draw
== DRAW_NORMAL_TEXT
)
7286 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7287 f
->output_data
.x
->text_cursor
);
7288 else if (draw
== DRAW_MOUSE_FACE
)
7289 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7290 f
->output_data
.x
->cross_cursor
);
7292 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7293 f
->output_data
.x
->nontext_cursor
);
7296 /* Clear out the mouse-highlighted active region.
7297 Redraw it un-highlighted first. */
7300 clear_mouse_face (dpyinfo
)
7301 struct x_display_info
*dpyinfo
;
7306 if (! NILP (dpyinfo
->mouse_face_window
))
7307 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
7309 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7310 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7311 dpyinfo
->mouse_face_window
= Qnil
;
7315 /* Clear any mouse-face on window W. This function is part of the
7316 redisplay interface, and is called from try_window_id and similar
7317 functions to ensure the mouse-highlight is off. */
7320 x_clear_mouse_face (w
)
7323 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
7327 XSETWINDOW (window
, w
);
7328 if (EQ (window
, dpyinfo
->mouse_face_window
))
7329 clear_mouse_face (dpyinfo
);
7334 /* Just discard the mouse face information for frame F, if any.
7335 This is used when the size of F is changed. */
7338 cancel_mouse_face (f
)
7342 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7344 window
= dpyinfo
->mouse_face_window
;
7345 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
7347 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7348 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7349 dpyinfo
->mouse_face_window
= Qnil
;
7353 static struct scroll_bar
*x_window_to_scroll_bar ();
7354 static void x_scroll_bar_report_motion ();
7356 /* Return the current position of the mouse.
7357 *fp should be a frame which indicates which display to ask about.
7359 If the mouse movement started in a scroll bar, set *fp, *bar_window,
7360 and *part to the frame, window, and scroll bar part that the mouse
7361 is over. Set *x and *y to the portion and whole of the mouse's
7362 position on the scroll bar.
7364 If the mouse movement started elsewhere, set *fp to the frame the
7365 mouse is on, *bar_window to nil, and *x and *y to the character cell
7368 Set *time to the server time-stamp for the time at which the mouse
7369 was at this position.
7371 Don't store anything if we don't have a valid set of values to report.
7373 This clears the mouse_moved flag, so we can wait for the next mouse
7377 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
7380 Lisp_Object
*bar_window
;
7381 enum scroll_bar_part
*part
;
7383 unsigned long *time
;
7389 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
7390 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
7396 Window dummy_window
;
7399 Lisp_Object frame
, tail
;
7401 /* Clear the mouse-moved flag for every frame on this display. */
7402 FOR_EACH_FRAME (tail
, frame
)
7403 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
7404 XFRAME (frame
)->mouse_moved
= 0;
7406 last_mouse_scroll_bar
= Qnil
;
7408 /* Figure out which root window we're on. */
7409 XQueryPointer (FRAME_X_DISPLAY (*fp
),
7410 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
7412 /* The root window which contains the pointer. */
7415 /* Trash which we can't trust if the pointer is on
7416 a different screen. */
7419 /* The position on that root window. */
7422 /* More trash we can't trust. */
7425 /* Modifier keys and pointer buttons, about which
7427 (unsigned int *) &dummy
);
7429 /* Now we have a position on the root; find the innermost window
7430 containing the pointer. */
7434 int parent_x
= 0, parent_y
= 0;
7439 /* XTranslateCoordinates can get errors if the window
7440 structure is changing at the same time this function
7441 is running. So at least we must not crash from them. */
7443 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
7445 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
7446 && FRAME_LIVE_P (last_mouse_frame
))
7448 /* If mouse was grabbed on a frame, give coords for that frame
7449 even if the mouse is now outside it. */
7450 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7452 /* From-window, to-window. */
7453 root
, FRAME_X_WINDOW (last_mouse_frame
),
7455 /* From-position, to-position. */
7456 root_x
, root_y
, &win_x
, &win_y
,
7460 f1
= last_mouse_frame
;
7466 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7468 /* From-window, to-window. */
7471 /* From-position, to-position. */
7472 root_x
, root_y
, &win_x
, &win_y
,
7477 if (child
== None
|| child
== win
)
7485 /* Now we know that:
7486 win is the innermost window containing the pointer
7487 (XTC says it has no child containing the pointer),
7488 win_x and win_y are the pointer's position in it
7489 (XTC did this the last time through), and
7490 parent_x and parent_y are the pointer's position in win's parent.
7491 (They are what win_x and win_y were when win was child.
7492 If win is the root window, it has no parent, and
7493 parent_{x,y} are invalid, but that's okay, because we'll
7494 never use them in that case.) */
7496 /* Is win one of our frames? */
7497 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
7500 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
7503 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
7505 /* If not, is it one of our scroll bars? */
7508 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
7512 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7518 if (f1
== 0 && insist
> 0)
7519 f1
= SELECTED_FRAME ();
7523 /* Ok, we found a frame. Store all the values.
7524 last_mouse_glyph is a rectangle used to reduce the
7525 generation of mouse events. To not miss any motion
7526 events, we must divide the frame into rectangles of the
7527 size of the smallest character that could be displayed
7528 on it, i.e. into the same rectangles that matrices on
7529 the frame are divided into. */
7531 #if OLD_REDISPLAY_CODE
7532 int ignore1
, ignore2
;
7533 pixel_to_glyph_coords (f1
, win_x
, win_y
, &ignore1
, &ignore2
,
7535 FRAME_X_DISPLAY_INFO (f1
)->grabbed
7539 int width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
7540 int height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
7544 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
7545 round down even for negative values. */
7551 last_mouse_glyph
.width
= width
;
7552 last_mouse_glyph
.height
= height
;
7553 last_mouse_glyph
.x
= (x
+ width
- 1) / width
* width
;
7554 last_mouse_glyph
.y
= (y
+ height
- 1) / height
* height
;
7561 XSETINT (*x
, win_x
);
7562 XSETINT (*y
, win_y
);
7563 *time
= last_mouse_movement_time
;
7572 #ifdef USE_X_TOOLKIT
7574 /* Atimer callback function for TIMER. Called every 0.1s to process
7575 Xt timeouts, if needed. We must avoid calling XtAppPending as
7576 much as possible because that function does an implicit XFlush
7577 that slows us down. */
7580 x_process_timeouts (timer
)
7581 struct atimer
*timer
;
7583 if (toolkit_scroll_bar_interaction
|| popup_activated_flag
)
7586 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
7587 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
7592 #endif /* USE_X_TOOLKIT */
7595 /* Scroll bar support. */
7597 /* Given an X window ID, find the struct scroll_bar which manages it.
7598 This can be called in GC, so we have to make sure to strip off mark
7601 static struct scroll_bar
*
7602 x_window_to_scroll_bar (window_id
)
7607 for (tail
= Vframe_list
;
7608 XGCTYPE (tail
) == Lisp_Cons
;
7611 Lisp_Object frame
, bar
, condemned
;
7613 frame
= XCAR (tail
);
7614 /* All elements of Vframe_list should be frames. */
7615 if (! GC_FRAMEP (frame
))
7618 /* Scan this frame's scroll bar list for a scroll bar with the
7620 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
7621 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
7622 /* This trick allows us to search both the ordinary and
7623 condemned scroll bar lists with one loop. */
7624 ! GC_NILP (bar
) || (bar
= condemned
,
7627 bar
= XSCROLL_BAR (bar
)->next
)
7628 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
7629 return XSCROLL_BAR (bar
);
7637 /************************************************************************
7639 ************************************************************************/
7641 #if USE_TOOLKIT_SCROLL_BARS
7643 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
7644 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
7645 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
7646 struct scroll_bar
*));
7647 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
7651 /* Id of action hook installed for scroll bars. */
7653 static XtActionHookId action_hook_id
;
7655 /* Lisp window being scrolled. Set when starting to interact with
7656 a toolkit scroll bar, reset to nil when ending the interaction. */
7658 static Lisp_Object window_being_scrolled
;
7660 /* Last scroll bar part sent in xm_scroll_callback. */
7662 static int last_scroll_bar_part
;
7664 /* Whether this is an Xaw with arrow-scrollbars. This should imply
7665 that movements of 1/20 of the screen size are mapped to up/down. */
7667 static Boolean xaw3d_arrow_scroll
;
7669 /* Whether the drag scrolling maintains the mouse at the top of the
7670 thumb. If not, resizing the thumb needs to be done more carefully
7671 to avoid jerkyness. */
7673 static Boolean xaw3d_pick_top
;
7676 /* Action hook installed via XtAppAddActionHook when toolkit scroll
7677 bars are used.. The hook is responsible for detecting when
7678 the user ends an interaction with the scroll bar, and generates
7679 a `end-scroll' scroll_bar_click' event if so. */
7682 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
7685 XtPointer client_data
;
7689 Cardinal
*num_params
;
7695 scroll_bar_p
= XmIsScrollBar (widget
);
7696 end_action
= "Release";
7697 #else /* !USE_MOTIF i.e. use Xaw */
7698 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
7699 end_action
= "EndScroll";
7700 #endif /* USE_MOTIF */
7703 && strcmp (action_name
, end_action
) == 0
7704 && WINDOWP (window_being_scrolled
))
7708 x_send_scroll_bar_event (window_being_scrolled
,
7709 scroll_bar_end_scroll
, 0, 0);
7710 w
= XWINDOW (window_being_scrolled
);
7711 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
7712 window_being_scrolled
= Qnil
;
7713 last_scroll_bar_part
= -1;
7715 /* Xt timeouts no longer needed. */
7716 toolkit_scroll_bar_interaction
= 0;
7720 /* A vector of windows used for communication between
7721 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
7723 static struct window
**scroll_bar_windows
;
7724 static int scroll_bar_windows_size
;
7727 /* Send a client message with message type Xatom_Scrollbar for a
7728 scroll action to the frame of WINDOW. PART is a value identifying
7729 the part of the scroll bar that was clicked on. PORTION is the
7730 amount to scroll of a whole of WHOLE. */
7733 x_send_scroll_bar_event (window
, part
, portion
, whole
)
7735 int part
, portion
, whole
;
7738 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
7739 struct window
*w
= XWINDOW (window
);
7740 struct frame
*f
= XFRAME (w
->frame
);
7745 /* Construct a ClientMessage event to send to the frame. */
7746 ev
->type
= ClientMessage
;
7747 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
7748 ev
->display
= FRAME_X_DISPLAY (f
);
7749 ev
->window
= FRAME_X_WINDOW (f
);
7752 /* We can only transfer 32 bits in the XClientMessageEvent, which is
7753 not enough to store a pointer or Lisp_Object on a 64 bit system.
7754 So, store the window in scroll_bar_windows and pass the index
7755 into that array in the event. */
7756 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
7757 if (scroll_bar_windows
[i
] == NULL
)
7760 if (i
== scroll_bar_windows_size
)
7762 int new_size
= max (10, 2 * scroll_bar_windows_size
);
7763 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
7764 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
7766 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
7768 bzero (&scroll_bar_windows
[i
], nbytes
- old_nbytes
);
7769 scroll_bar_windows_size
= new_size
;
7772 scroll_bar_windows
[i
] = w
;
7773 ev
->data
.l
[0] = (long) i
;
7774 ev
->data
.l
[1] = (long) part
;
7775 ev
->data
.l
[2] = (long) 0;
7776 ev
->data
.l
[3] = (long) portion
;
7777 ev
->data
.l
[4] = (long) whole
;
7779 /* Make Xt timeouts work while the scroll bar is active. */
7780 toolkit_scroll_bar_interaction
= 1;
7782 /* Setting the event mask to zero means that the message will
7783 be sent to the client that created the window, and if that
7784 window no longer exists, no event will be sent. */
7785 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
7790 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
7794 x_scroll_bar_to_input_event (event
, ievent
)
7796 struct input_event
*ievent
;
7798 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
7803 w
= scroll_bar_windows
[ev
->data
.l
[0]];
7804 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
7806 XSETWINDOW (window
, w
);
7807 f
= XFRAME (w
->frame
);
7809 ievent
->kind
= scroll_bar_click
;
7810 ievent
->frame_or_window
= window
;
7812 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
7813 ievent
->part
= ev
->data
.l
[1];
7814 ievent
->code
= ev
->data
.l
[2];
7815 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
7816 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
7817 ievent
->modifiers
= 0;
7823 /* Minimum and maximum values used for Motif scroll bars. */
7826 #define XM_SB_MAX 10000000
7827 #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN)
7830 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
7831 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
7832 CALL_DATA is a pointer a a XmScrollBarCallbackStruct. */
7835 xm_scroll_callback (widget
, client_data
, call_data
)
7837 XtPointer client_data
, call_data
;
7839 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7840 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
7842 int part
= -1, whole
= 0, portion
= 0;
7846 case XmCR_DECREMENT
:
7847 bar
->dragging
= Qnil
;
7848 part
= scroll_bar_up_arrow
;
7851 case XmCR_INCREMENT
:
7852 bar
->dragging
= Qnil
;
7853 part
= scroll_bar_down_arrow
;
7856 case XmCR_PAGE_DECREMENT
:
7857 bar
->dragging
= Qnil
;
7858 part
= scroll_bar_above_handle
;
7861 case XmCR_PAGE_INCREMENT
:
7862 bar
->dragging
= Qnil
;
7863 part
= scroll_bar_below_handle
;
7867 bar
->dragging
= Qnil
;
7868 part
= scroll_bar_to_top
;
7871 case XmCR_TO_BOTTOM
:
7872 bar
->dragging
= Qnil
;
7873 part
= scroll_bar_to_bottom
;
7879 int dragging_down_p
= (INTEGERP (bar
->dragging
)
7880 && XINT (bar
->dragging
) <= cs
->value
);
7882 /* Get the slider size. */
7884 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
7887 /* At the max position of the scroll bar, do a line-wise
7888 movement. Without doing anything, the LessTif scroll bar
7889 calls us with the same cs->value again and again. If we
7890 want to make sure that we can reach the end of the buffer,
7891 we have to do something.
7893 Implementation note: setting bar->dragging always to
7894 cs->value gives a smoother movement at the max position.
7895 Setting it to nil when doing line-wise movement gives
7896 a better slider behavior. */
7898 if (cs
->value
+ slider_size
== XM_SB_MAX
7900 && last_scroll_bar_part
== scroll_bar_down_arrow
))
7902 part
= scroll_bar_down_arrow
;
7903 bar
->dragging
= Qnil
;
7907 whole
= XM_SB_RANGE
;
7908 portion
= min (cs
->value
- XM_SB_MIN
, XM_SB_MAX
- slider_size
);
7909 part
= scroll_bar_handle
;
7910 bar
->dragging
= make_number (cs
->value
);
7915 case XmCR_VALUE_CHANGED
:
7921 window_being_scrolled
= bar
->window
;
7922 last_scroll_bar_part
= part
;
7923 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
7928 #else /* !USE_MOTIF, i.e. Xaw. */
7931 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
7932 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
7933 scroll bar struct. CALL_DATA is a pointer to a float saying where
7937 xaw_jump_callback (widget
, client_data
, call_data
)
7939 XtPointer client_data
, call_data
;
7941 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7942 float top
= *(float *) call_data
;
7944 int whole
, portion
, height
;
7947 /* Get the size of the thumb, a value between 0 and 1. */
7949 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
7953 portion
= shown
< 1 ? top
* whole
: 0;
7955 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
7956 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
7957 the bottom, so we force the scrolling whenever we see that we're
7958 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
7959 we try to ensure that we always stay two pixels away from the
7961 part
= scroll_bar_down_arrow
;
7963 part
= scroll_bar_handle
;
7965 window_being_scrolled
= bar
->window
;
7966 bar
->dragging
= make_number (portion
);
7967 last_scroll_bar_part
= part
;
7968 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
7972 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
7973 i.e. line or page up or down. WIDGET is the Xaw scroll bar
7974 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
7975 the scroll bar. CALL_DATA is an integer specifying the action that
7976 has taken place. It's magnitude is in the range 0..height of the
7977 scroll bar. Negative values mean scroll towards buffer start.
7978 Values < height of scroll bar mean line-wise movement. */
7981 xaw_scroll_callback (widget
, client_data
, call_data
)
7983 XtPointer client_data
, call_data
;
7985 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7986 int position
= (int) call_data
;
7990 /* Get the height of the scroll bar. */
7992 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
7995 if (abs (position
) >= height
)
7996 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
7998 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
7999 it maps line-movement to call_data = max(5, height/20). */
8000 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
8001 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
8003 part
= scroll_bar_move_ratio
;
8005 window_being_scrolled
= bar
->window
;
8006 bar
->dragging
= Qnil
;
8007 last_scroll_bar_part
= part
;
8008 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
8012 #endif /* not USE_MOTIF */
8015 /* Create the widget for scroll bar BAR on frame F. Record the widget
8016 and X window of the scroll bar in BAR. */
8019 x_create_toolkit_scroll_bar (f
, bar
)
8021 struct scroll_bar
*bar
;
8027 char *scroll_bar_name
= "verticalScrollBar";
8028 unsigned long pixel
;
8033 /* LessTif 0.85, problems:
8035 1. When the mouse if over the scroll bar, the scroll bar will
8036 get keyboard events. I didn't find a way to turn this off.
8038 2. Do we have to explicitly set the cursor to get an arrow
8039 cursor (see below)? */
8041 /* Set resources. Create the widget. */
8042 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
8043 XtSetArg (av
[ac
], XmNminimum
, XM_SB_MIN
); ++ac
;
8044 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
8045 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
8046 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
8047 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
8048 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
8050 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
8053 XtSetArg (av
[ac
], XmNforeground
, pixel
);
8057 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8060 XtSetArg (av
[ac
], XmNbackground
, pixel
);
8064 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
8065 scroll_bar_name
, av
, ac
);
8067 /* Add one callback for everything that can happen. */
8068 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
8070 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
8072 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
8074 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
8076 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
8078 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
8080 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
8083 /* Realize the widget. Only after that is the X window created. */
8084 XtRealizeWidget (widget
);
8086 /* Set the cursor to an arrow. I didn't find a resource to do that.
8087 And I'm wondering why it hasn't an arrow cursor by default. */
8088 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
8089 f
->output_data
.x
->nontext_cursor
);
8091 #else /* !USE_MOTIF i.e. use Xaw */
8093 /* Set resources. Create the widget. The background of the
8094 Xaw3d scroll bar widget is a little bit light for my taste.
8095 We don't alter it here to let users change it according
8096 to their taste with `emacs*verticalScrollBar.background: xxx'. */
8097 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
8098 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
8099 /* For smoother scrolling with Xaw3d -sm */
8100 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
8101 /* XtSetArg (av[ac], XtNbeNiceToColormap, True); ++ac; */
8103 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
8106 XtSetArg (av
[ac
], XtNforeground
, pixel
);
8110 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8113 XtSetArg (av
[ac
], XtNbackground
, pixel
);
8117 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
8118 f
->output_data
.x
->edit_widget
, av
, ac
);
8122 char *val
= initial
;
8123 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
8124 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
8126 { /* ARROW_SCROLL */
8127 xaw3d_arrow_scroll
= True
;
8128 /* Isn't that just a personal preference ? -sm */
8129 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
8133 /* Define callbacks. */
8134 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
8135 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
8138 /* Realize the widget. Only after that is the X window created. */
8139 XtRealizeWidget (widget
);
8141 #endif /* !USE_MOTIF */
8143 /* Install an action hook that let's us detect when the user
8144 finishes interacting with a scroll bar. */
8145 if (action_hook_id
== 0)
8146 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
8148 /* Remember X window and widget in the scroll bar vector. */
8149 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
8150 xwindow
= XtWindow (widget
);
8151 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
8157 /* Set the thumb size and position of scroll bar BAR. We are currently
8158 displaying PORTION out of a whole WHOLE, and our position POSITION. */
8161 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
8162 struct scroll_bar
*bar
;
8163 int portion
, position
, whole
;
8165 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8166 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
8173 top
= (float) position
/ whole
;
8174 shown
= (float) portion
/ whole
;
8182 Boolean arrow1_selected
, arrow2_selected
;
8183 unsigned char flags
;
8184 XmScrollBarWidget sb
;
8186 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
8187 is the scroll bar's maximum and MIN is the scroll bar's minimum
8189 size
= shown
* XM_SB_RANGE
;
8190 size
= min (size
, XM_SB_RANGE
);
8191 size
= max (size
, 1);
8193 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
8194 value
= top
* XM_SB_RANGE
;
8195 value
= min (value
, XM_SB_MAX
- size
);
8196 value
= max (value
, XM_SB_MIN
);
8198 /* LessTif: Calling XmScrollBarSetValues after an increment or
8199 decrement turns off auto-repeat LessTif-internally. This can
8200 be seen in ScrollBar.c which resets Arrow1Selected and
8201 Arrow2Selected. It also sets internal flags so that LessTif
8202 believes the mouse is in the slider. We either have to change
8203 our code, or work around that by accessing private data. */
8205 sb
= (XmScrollBarWidget
) widget
;
8206 arrow1_selected
= sb
->scrollBar
.arrow1_selected
;
8207 arrow2_selected
= sb
->scrollBar
.arrow2_selected
;
8208 flags
= sb
->scrollBar
.flags
;
8210 if (NILP (bar
->dragging
))
8211 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
8212 else if (last_scroll_bar_part
== scroll_bar_down_arrow
)
8213 /* This has the negative side effect that the slider value is
8214 not what it would be if we scrolled here using line-wise or
8215 page-wise movement. */
8216 XmScrollBarSetValues (widget
, value
, XM_SB_RANGE
- value
, 0, 0, False
);
8219 /* If currently dragging, only update the slider size.
8220 This reduces flicker effects. */
8221 int old_value
, old_size
, increment
, page_increment
;
8223 XmScrollBarGetValues (widget
, &old_value
, &old_size
,
8224 &increment
, &page_increment
);
8225 XmScrollBarSetValues (widget
, old_value
,
8226 min (size
, XM_SB_RANGE
- old_value
),
8230 sb
->scrollBar
.arrow1_selected
= arrow1_selected
;
8231 sb
->scrollBar
.arrow2_selected
= arrow2_selected
;
8232 sb
->scrollBar
.flags
= flags
;
8234 #else /* !USE_MOTIF i.e. use Xaw */
8236 float old_top
, old_shown
;
8238 XtVaGetValues (widget
,
8239 XtNtopOfThumb
, &old_top
,
8240 XtNshown
, &old_shown
,
8244 /* Massage the top+shown values. */
8245 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
8246 top
= max (0, min (1, top
));
8249 /* Keep two pixels available for moving the thumb down. */
8250 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
8252 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
8253 check that your system's configuration file contains a define
8254 for `NARROWPROTO'. See s/freebsd.h for an example. */
8255 if (top
!= old_top
|| shown
!= old_shown
)
8257 if (NILP (bar
->dragging
))
8258 XawScrollbarSetThumb (widget
, top
, shown
);
8262 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
8263 int scroll_mode
= 0;
8265 /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR. */
8266 if (xaw3d_arrow_scroll
)
8268 /* Xaw3d stupidly ignores resize requests while dragging
8269 so we have to make it believe it's not in dragging mode. */
8270 scroll_mode
= sb
->scrollbar
.scroll_mode
;
8271 if (scroll_mode
== 2)
8272 sb
->scrollbar
.scroll_mode
= 0;
8275 /* Try to make the scrolling a tad smoother. */
8276 if (!xaw3d_pick_top
)
8277 shown
= min (shown
, old_shown
);
8279 XawScrollbarSetThumb (widget
, top
, shown
);
8282 if (xaw3d_arrow_scroll
&& scroll_mode
== 2)
8283 sb
->scrollbar
.scroll_mode
= scroll_mode
;
8288 #endif /* !USE_MOTIF */
8293 #endif /* USE_TOOLKIT_SCROLL_BARS */
8297 /************************************************************************
8298 Scroll bars, general
8299 ************************************************************************/
8301 /* Create a scroll bar and return the scroll bar vector for it. W is
8302 the Emacs window on which to create the scroll bar. TOP, LEFT,
8303 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
8306 static struct scroll_bar
*
8307 x_scroll_bar_create (w
, top
, left
, width
, height
)
8309 int top
, left
, width
, height
;
8311 struct frame
*f
= XFRAME (w
->frame
);
8312 struct scroll_bar
*bar
8313 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
8317 #if USE_TOOLKIT_SCROLL_BARS
8318 x_create_toolkit_scroll_bar (f
, bar
);
8319 #else /* not USE_TOOLKIT_SCROLL_BARS */
8321 XSetWindowAttributes a
;
8325 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8326 if (a
.background_pixel
== -1)
8327 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
8329 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
8330 | ButtonMotionMask
| PointerMotionHintMask
8332 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
8334 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
8336 /* Clear the area of W that will serve as a scroll bar. This is
8337 for the case that a window has been split horizontally. In
8338 this case, no clear_frame is generated to reduce flickering. */
8339 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8341 window_box_height (w
), False
);
8343 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8344 /* Position and size of scroll bar. */
8345 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8347 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8349 /* Border width, depth, class, and visual. */
8356 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
8358 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8360 XSETWINDOW (bar
->window
, w
);
8361 XSETINT (bar
->top
, top
);
8362 XSETINT (bar
->left
, left
);
8363 XSETINT (bar
->width
, width
);
8364 XSETINT (bar
->height
, height
);
8365 XSETINT (bar
->start
, 0);
8366 XSETINT (bar
->end
, 0);
8367 bar
->dragging
= Qnil
;
8369 /* Add bar to its frame's list of scroll bars. */
8370 bar
->next
= FRAME_SCROLL_BARS (f
);
8372 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8373 if (!NILP (bar
->next
))
8374 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8376 /* Map the window/widget. */
8377 #if USE_TOOLKIT_SCROLL_BARS
8379 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
8380 XtConfigureWidget (scroll_bar
,
8381 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8383 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8385 XtMapWidget (scroll_bar
);
8387 #else /* not USE_TOOLKIT_SCROLL_BARS */
8388 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
8389 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8396 /* Draw BAR's handle in the proper position.
8398 If the handle is already drawn from START to END, don't bother
8399 redrawing it, unless REBUILD is non-zero; in that case, always
8400 redraw it. (REBUILD is handy for drawing the handle after expose
8403 Normally, we want to constrain the start and end of the handle to
8404 fit inside its rectangle, but if the user is dragging the scroll
8405 bar handle, we want to let them drag it down all the way, so that
8406 the bar's top is as far down as it goes; otherwise, there's no way
8407 to move to the very end of the buffer. */
8409 #ifndef USE_TOOLKIT_SCROLL_BARS
8412 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
8413 struct scroll_bar
*bar
;
8417 int dragging
= ! NILP (bar
->dragging
);
8418 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8419 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8420 GC gc
= f
->output_data
.x
->normal_gc
;
8422 /* If the display is already accurate, do nothing. */
8424 && start
== XINT (bar
->start
)
8425 && end
== XINT (bar
->end
))
8431 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
8432 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8433 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8435 /* Make sure the values are reasonable, and try to preserve
8436 the distance between start and end. */
8438 int length
= end
- start
;
8442 else if (start
> top_range
)
8444 end
= start
+ length
;
8448 else if (end
> top_range
&& ! dragging
)
8452 /* Store the adjusted setting in the scroll bar. */
8453 XSETINT (bar
->start
, start
);
8454 XSETINT (bar
->end
, end
);
8456 /* Clip the end position, just for display. */
8457 if (end
> top_range
)
8460 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
8461 below top positions, to make sure the handle is always at least
8462 that many pixels tall. */
8463 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
8465 /* Draw the empty space above the handle. Note that we can't clear
8466 zero-height areas; that means "clear to end of window." */
8468 XClearArea (FRAME_X_DISPLAY (f
), w
,
8470 /* x, y, width, height, and exposures. */
8471 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8472 VERTICAL_SCROLL_BAR_TOP_BORDER
,
8473 inside_width
, start
,
8476 /* Change to proper foreground color if one is specified. */
8477 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8478 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8479 f
->output_data
.x
->scroll_bar_foreground_pixel
);
8481 /* Draw the handle itself. */
8482 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
8484 /* x, y, width, height */
8485 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8486 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
8487 inside_width
, end
- start
);
8489 /* Restore the foreground color of the GC if we changed it above. */
8490 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8491 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8492 f
->output_data
.x
->foreground_pixel
);
8494 /* Draw the empty space below the handle. Note that we can't
8495 clear zero-height areas; that means "clear to end of window." */
8496 if (end
< inside_height
)
8497 XClearArea (FRAME_X_DISPLAY (f
), w
,
8499 /* x, y, width, height, and exposures. */
8500 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8501 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
8502 inside_width
, inside_height
- end
,
8510 #endif /* !USE_TOOLKIT_SCROLL_BARS */
8512 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
8516 x_scroll_bar_remove (bar
)
8517 struct scroll_bar
*bar
;
8519 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8522 #if USE_TOOLKIT_SCROLL_BARS
8523 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
8525 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
8528 /* Disassociate this scroll bar from its window. */
8529 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
8535 /* Set the handle of the vertical scroll bar for WINDOW to indicate
8536 that we are displaying PORTION characters out of a total of WHOLE
8537 characters, starting at POSITION. If WINDOW has no scroll bar,
8541 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
8543 int portion
, whole
, position
;
8545 struct frame
*f
= XFRAME (w
->frame
);
8546 struct scroll_bar
*bar
;
8547 int top
, height
, left
, sb_left
, width
, sb_width
;
8548 int window_x
, window_y
, window_width
, window_height
;
8550 /* Get window dimensions. */
8551 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
8553 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
8554 height
= window_height
;
8556 /* Compute the left edge of the scroll bar area. */
8557 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8558 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
8560 left
= XFASTINT (w
->left
);
8561 left
*= CANON_X_UNIT (f
);
8562 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
8564 /* Compute the width of the scroll bar which might be less than
8565 the width of the area reserved for the scroll bar. */
8566 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
8567 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
8571 /* Compute the left edge of the scroll bar. */
8572 #ifdef USE_TOOLKIT_SCROLL_BARS
8573 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8574 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
8576 sb_left
= left
+ (width
- sb_width
) / 2;
8578 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8579 sb_left
= left
+ width
- sb_width
;
8584 /* Does the scroll bar exist yet? */
8585 if (NILP (w
->vertical_scroll_bar
))
8588 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8589 left
, top
, width
, height
, False
);
8591 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
8595 /* It may just need to be moved and resized. */
8596 unsigned int mask
= 0;
8598 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
8602 if (sb_left
!= XINT (bar
->left
))
8604 if (top
!= XINT (bar
->top
))
8606 if (sb_width
!= XINT (bar
->width
))
8608 if (height
!= XINT (bar
->height
))
8611 #ifdef USE_TOOLKIT_SCROLL_BARS
8613 /* Since toolkit scroll bars are smaller than the space reserved
8614 for them on the frame, we have to clear "under" them. */
8615 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8616 left
, top
, width
, height
, False
);
8618 /* Move/size the scroll bar widget. */
8620 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
8621 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8623 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8626 #else /* not USE_TOOLKIT_SCROLL_BARS */
8628 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
8630 /* Clear areas not covered by the scroll bar. This makes sure a
8631 previous mode line display is cleared after C-x 2 C-x 1, for
8632 example. Non-toolkit scroll bars are as wide as the area
8633 reserved for scroll bars - trim at both sides. */
8634 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8635 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8637 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8638 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8639 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8643 /* Move/size the scroll bar window. */
8648 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
8650 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
8652 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
8656 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8658 /* Remember new settings. */
8659 XSETINT (bar
->left
, sb_left
);
8660 XSETINT (bar
->top
, top
);
8661 XSETINT (bar
->width
, sb_width
);
8662 XSETINT (bar
->height
, height
);
8667 #if USE_TOOLKIT_SCROLL_BARS
8668 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
8669 #else /* not USE_TOOLKIT_SCROLL_BARS */
8670 /* Set the scroll bar's current state, unless we're currently being
8672 if (NILP (bar
->dragging
))
8674 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
8677 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
8680 int start
= ((double) position
* top_range
) / whole
;
8681 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
8682 x_scroll_bar_set_handle (bar
, start
, end
, 0);
8685 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8687 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
8691 /* The following three hooks are used when we're doing a thorough
8692 redisplay of the frame. We don't explicitly know which scroll bars
8693 are going to be deleted, because keeping track of when windows go
8694 away is a real pain - "Can you say set-window-configuration, boys
8695 and girls?" Instead, we just assert at the beginning of redisplay
8696 that *all* scroll bars are to be removed, and then save a scroll bar
8697 from the fiery pit when we actually redisplay its window. */
8699 /* Arrange for all scroll bars on FRAME to be removed at the next call
8700 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
8701 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
8704 XTcondemn_scroll_bars (frame
)
8707 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
8708 while (! NILP (FRAME_SCROLL_BARS (frame
)))
8711 bar
= FRAME_SCROLL_BARS (frame
);
8712 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
8713 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
8714 XSCROLL_BAR (bar
)->prev
= Qnil
;
8715 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
8716 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
8717 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
8722 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
8723 Note that WINDOW isn't necessarily condemned at all. */
8726 XTredeem_scroll_bar (window
)
8727 struct window
*window
;
8729 struct scroll_bar
*bar
;
8732 /* We can't redeem this window's scroll bar if it doesn't have one. */
8733 if (NILP (window
->vertical_scroll_bar
))
8736 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
8738 /* Unlink it from the condemned list. */
8739 f
= XFRAME (WINDOW_FRAME (window
));
8740 if (NILP (bar
->prev
))
8742 /* If the prev pointer is nil, it must be the first in one of
8744 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
8745 /* It's not condemned. Everything's fine. */
8747 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
8748 window
->vertical_scroll_bar
))
8749 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
8751 /* If its prev pointer is nil, it must be at the front of
8752 one or the other! */
8756 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
8758 if (! NILP (bar
->next
))
8759 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
8761 bar
->next
= FRAME_SCROLL_BARS (f
);
8763 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8764 if (! NILP (bar
->next
))
8765 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8768 /* Remove all scroll bars on FRAME that haven't been saved since the
8769 last call to `*condemn_scroll_bars_hook'. */
8772 XTjudge_scroll_bars (f
)
8775 Lisp_Object bar
, next
;
8777 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
8779 /* Clear out the condemned list now so we won't try to process any
8780 more events on the hapless scroll bars. */
8781 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
8783 for (; ! NILP (bar
); bar
= next
)
8785 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
8787 x_scroll_bar_remove (b
);
8790 b
->next
= b
->prev
= Qnil
;
8793 /* Now there should be no references to the condemned scroll bars,
8794 and they should get garbage-collected. */
8798 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
8799 is a no-op when using toolkit scroll bars.
8801 This may be called from a signal handler, so we have to ignore GC
8805 x_scroll_bar_expose (bar
, event
)
8806 struct scroll_bar
*bar
;
8809 #ifndef USE_TOOLKIT_SCROLL_BARS
8811 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8812 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8813 GC gc
= f
->output_data
.x
->normal_gc
;
8814 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
8818 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
8820 /* Draw a one-pixel border just inside the edges of the scroll bar. */
8821 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
8823 /* x, y, width, height */
8825 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
8826 XINT (bar
->height
) - 1);
8830 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8833 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
8834 is set to something other than no_event, it is enqueued.
8836 This may be called from a signal handler, so we have to ignore GC
8839 #ifndef USE_TOOLKIT_SCROLL_BARS
8842 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
8843 struct scroll_bar
*bar
;
8845 struct input_event
*emacs_event
;
8847 if (! GC_WINDOWP (bar
->window
))
8850 emacs_event
->kind
= scroll_bar_click
;
8851 emacs_event
->code
= event
->xbutton
.button
- Button1
;
8852 emacs_event
->modifiers
8853 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
8854 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
8855 event
->xbutton
.state
)
8856 | (event
->type
== ButtonRelease
8859 emacs_event
->frame_or_window
= bar
->window
;
8860 emacs_event
->arg
= Qnil
;
8861 emacs_event
->timestamp
= event
->xbutton
.time
;
8864 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8866 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8869 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8870 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
8873 if (y
> top_range
) y
= top_range
;
8875 if (y
< XINT (bar
->start
))
8876 emacs_event
->part
= scroll_bar_above_handle
;
8877 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
8878 emacs_event
->part
= scroll_bar_handle
;
8880 emacs_event
->part
= scroll_bar_below_handle
;
8882 /* Just because the user has clicked on the handle doesn't mean
8883 they want to drag it. Lisp code needs to be able to decide
8884 whether or not we're dragging. */
8886 /* If the user has just clicked on the handle, record where they're
8888 if (event
->type
== ButtonPress
8889 && emacs_event
->part
== scroll_bar_handle
)
8890 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
8893 /* If the user has released the handle, set it to its final position. */
8894 if (event
->type
== ButtonRelease
8895 && ! NILP (bar
->dragging
))
8897 int new_start
= y
- XINT (bar
->dragging
);
8898 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8900 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8901 bar
->dragging
= Qnil
;
8904 /* Same deal here as the other #if 0. */
8906 /* Clicks on the handle are always reported as occurring at the top of
8908 if (emacs_event
->part
== scroll_bar_handle
)
8909 emacs_event
->x
= bar
->start
;
8911 XSETINT (emacs_event
->x
, y
);
8913 XSETINT (emacs_event
->x
, y
);
8916 XSETINT (emacs_event
->y
, top_range
);
8920 /* Handle some mouse motion while someone is dragging the scroll bar.
8922 This may be called from a signal handler, so we have to ignore GC
8926 x_scroll_bar_note_movement (bar
, event
)
8927 struct scroll_bar
*bar
;
8930 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
8932 last_mouse_movement_time
= event
->xmotion
.time
;
8935 XSETVECTOR (last_mouse_scroll_bar
, bar
);
8937 /* If we're dragging the bar, display it. */
8938 if (! GC_NILP (bar
->dragging
))
8940 /* Where should the handle be now? */
8941 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
8943 if (new_start
!= XINT (bar
->start
))
8945 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8947 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8952 #endif /* !USE_TOOLKIT_SCROLL_BARS */
8954 /* Return information to the user about the current position of the mouse
8955 on the scroll bar. */
8958 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
8960 Lisp_Object
*bar_window
;
8961 enum scroll_bar_part
*part
;
8963 unsigned long *time
;
8965 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
8966 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8967 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8969 Window dummy_window
;
8971 unsigned int dummy_mask
;
8975 /* Get the mouse's position relative to the scroll bar window, and
8977 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
8979 /* Root, child, root x and root y. */
8980 &dummy_window
, &dummy_window
,
8981 &dummy_coord
, &dummy_coord
,
8983 /* Position relative to scroll bar. */
8986 /* Mouse buttons and modifier keys. */
8993 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8996 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8998 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
9000 if (! NILP (bar
->dragging
))
9001 win_y
-= XINT (bar
->dragging
);
9005 if (win_y
> top_range
)
9009 *bar_window
= bar
->window
;
9011 if (! NILP (bar
->dragging
))
9012 *part
= scroll_bar_handle
;
9013 else if (win_y
< XINT (bar
->start
))
9014 *part
= scroll_bar_above_handle
;
9015 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
9016 *part
= scroll_bar_handle
;
9018 *part
= scroll_bar_below_handle
;
9020 XSETINT (*x
, win_y
);
9021 XSETINT (*y
, top_range
);
9024 last_mouse_scroll_bar
= Qnil
;
9027 *time
= last_mouse_movement_time
;
9033 /* The screen has been cleared so we may have changed foreground or
9034 background colors, and the scroll bars may need to be redrawn.
9035 Clear out the scroll bars, and ask for expose events, so we can
9039 x_scroll_bar_clear (f
)
9042 #ifndef USE_TOOLKIT_SCROLL_BARS
9045 /* We can have scroll bars even if this is 0,
9046 if we just turned off scroll bar mode.
9047 But in that case we should not clear them. */
9048 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9049 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
9050 bar
= XSCROLL_BAR (bar
)->next
)
9051 XClearArea (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
9053 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9056 /* This processes Expose events from the menu-bar specific X event
9057 loop in xmenu.c. This allows to redisplay the frame if necessary
9058 when handling menu-bar or pop-up items. */
9061 process_expose_from_menu (event
)
9065 struct x_display_info
*dpyinfo
;
9066 int frame_exposed_p
= 0;
9070 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
9071 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
9074 if (f
->async_visible
== 0)
9076 f
->async_visible
= 1;
9077 f
->async_iconified
= 0;
9078 f
->output_data
.x
->has_been_visible
= 1;
9079 SET_FRAME_GARBAGED (f
);
9083 expose_frame (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
9084 event
.xexpose
.x
, event
.xexpose
.y
,
9085 event
.xexpose
.width
, event
.xexpose
.height
);
9086 frame_exposed_p
= 1;
9091 struct scroll_bar
*bar
9092 = x_window_to_scroll_bar (event
.xexpose
.window
);
9095 x_scroll_bar_expose (bar
, &event
);
9099 return frame_exposed_p
;
9102 /* Define a queue to save up SelectionRequest events for later handling. */
9104 struct selection_event_queue
9107 struct selection_event_queue
*next
;
9110 static struct selection_event_queue
*queue
;
9112 /* Nonzero means queue up certain events--don't process them yet. */
9114 static int x_queue_selection_requests
;
9116 /* Queue up an X event *EVENT, to be processed later. */
9119 x_queue_event (f
, event
)
9123 struct selection_event_queue
*queue_tmp
9124 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
9126 if (queue_tmp
!= NULL
)
9128 queue_tmp
->event
= *event
;
9129 queue_tmp
->next
= queue
;
9134 /* Take all the queued events and put them back
9135 so that they get processed afresh. */
9138 x_unqueue_events (display
)
9141 while (queue
!= NULL
)
9143 struct selection_event_queue
*queue_tmp
= queue
;
9144 XPutBackEvent (display
, &queue_tmp
->event
);
9145 queue
= queue_tmp
->next
;
9146 xfree ((char *)queue_tmp
);
9150 /* Start queuing SelectionRequest events. */
9153 x_start_queuing_selection_requests (display
)
9156 x_queue_selection_requests
++;
9159 /* Stop queuing SelectionRequest events. */
9162 x_stop_queuing_selection_requests (display
)
9165 x_queue_selection_requests
--;
9166 x_unqueue_events (display
);
9169 /* The main X event-reading loop - XTread_socket. */
9171 /* Time stamp of enter window event. This is only used by XTread_socket,
9172 but we have to put it out here, since static variables within functions
9173 sometimes don't work. */
9175 static Time enter_timestamp
;
9177 /* This holds the state XLookupString needs to implement dead keys
9178 and other tricks known as "compose processing". _X Window System_
9179 says that a portable program can't use this, but Stephen Gildea assures
9180 me that letting the compiler initialize it to zeros will work okay.
9182 This must be defined outside of XTread_socket, for the same reasons
9183 given for enter_time stamp, above. */
9185 static XComposeStatus compose_status
;
9187 /* Record the last 100 characters stored
9188 to help debug the loss-of-chars-during-GC problem. */
9190 static int temp_index
;
9191 static short temp_buffer
[100];
9193 /* Set this to nonzero to fake an "X I/O error"
9194 on a particular display. */
9196 struct x_display_info
*XTread_socket_fake_io_error
;
9198 /* When we find no input here, we occasionally do a no-op command
9199 to verify that the X server is still running and we can still talk with it.
9200 We try all the open displays, one by one.
9201 This variable is used for cycling thru the displays. */
9203 static struct x_display_info
*next_noop_dpyinfo
;
9205 #define SET_SAVED_MENU_EVENT(size) \
9208 if (f->output_data.x->saved_menu_event == 0) \
9209 f->output_data.x->saved_menu_event \
9210 = (XEvent *) xmalloc (sizeof (XEvent)); \
9211 bcopy (&event, f->output_data.x->saved_menu_event, size); \
9212 if (numchars >= 1) \
9214 bufp->kind = menu_bar_activate_event; \
9215 XSETFRAME (bufp->frame_or_window, f); \
9224 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
9225 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
9227 /* Read events coming from the X server.
9228 This routine is called by the SIGIO handler.
9229 We return as soon as there are no more events to be read.
9231 Events representing keys are stored in buffer BUFP,
9232 which can hold up to NUMCHARS characters.
9233 We return the number of characters stored into the buffer,
9234 thus pretending to be `read'.
9236 EXPECTED is nonzero if the caller knows input is available. */
9239 XTread_socket (sd
, bufp
, numchars
, expected
)
9241 /* register */ struct input_event
*bufp
;
9242 /* register */ int numchars
;
9249 int event_found
= 0;
9250 struct x_display_info
*dpyinfo
;
9251 struct coding_system coding
;
9253 if (interrupt_input_blocked
)
9255 interrupt_input_pending
= 1;
9259 interrupt_input_pending
= 0;
9262 /* So people can tell when we have read the available input. */
9263 input_signal_count
++;
9266 abort (); /* Don't think this happens. */
9270 /* The input should be decoded if it is from XIM. Currently the
9271 locale of XIM is the same as that of the system. So, we can use
9272 Vlocale_coding_system which is initialized properly at Emacs
9274 setup_coding_system (Vlocale_coding_system
, &coding
);
9275 coding
.src_multibyte
= 0;
9276 coding
.dst_multibyte
= 1;
9277 /* The input is converted to events, thus we can't handle
9278 composition. Anyway, there's no XIM that gives us composition
9280 coding
.composing
= COMPOSITION_DISABLED
;
9282 /* Find the display we are supposed to read input for.
9283 It's the one communicating on descriptor SD. */
9284 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
9286 #if 0 /* This ought to be unnecessary; let's verify it. */
9288 /* If available, Xlib uses FIOSNBIO to make the socket
9289 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
9290 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
9291 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
9292 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
9293 #endif /* ! defined (FIOSNBIO) */
9296 #if 0 /* This code can't be made to work, with multiple displays,
9297 and appears not to be used on any system any more.
9298 Also keyboard.c doesn't turn O_NDELAY on and off
9299 for X connections. */
9302 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
9304 extern int read_alarm_should_throw
;
9305 read_alarm_should_throw
= 1;
9306 XPeekEvent (dpyinfo
->display
, &event
);
9307 read_alarm_should_throw
= 0;
9309 #endif /* HAVE_SELECT */
9313 /* For debugging, this gives a way to fake an I/O error. */
9314 if (dpyinfo
== XTread_socket_fake_io_error
)
9316 XTread_socket_fake_io_error
= 0;
9317 x_io_error_quitter (dpyinfo
->display
);
9320 while (XPending (dpyinfo
->display
))
9322 XNextEvent (dpyinfo
->display
, &event
);
9326 /* Filter events for the current X input method.
9327 XFilterEvent returns non-zero if the input method has
9328 consumed the event. We pass the frame's X window to
9329 XFilterEvent because that's the one for which the IC
9331 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
9332 event
.xclient
.window
);
9333 if (XFilterEvent (&event
, f1
? FRAME_X_WINDOW (f1
) : None
))
9343 if (event
.xclient
.message_type
9344 == dpyinfo
->Xatom_wm_protocols
9345 && event
.xclient
.format
== 32)
9347 if (event
.xclient
.data
.l
[0]
9348 == dpyinfo
->Xatom_wm_take_focus
)
9350 /* Use x_any_window_to_frame because this
9351 could be the shell widget window
9352 if the frame has no title bar. */
9353 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9355 /* Not quite sure this is needed -pd */
9356 if (f
&& FRAME_XIC (f
))
9357 XSetICFocus (FRAME_XIC (f
));
9359 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
9360 instructs the WM to set the input focus automatically for
9361 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
9362 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
9363 it has set the focus. So, XSetInputFocus below is not
9366 The call to XSetInputFocus below has also caused trouble. In
9367 cases where the XSetInputFocus done by the WM and the one
9368 below are temporally close (on a fast machine), the call
9369 below can generate additional FocusIn events which confuse
9372 /* Since we set WM_TAKE_FOCUS, we must call
9373 XSetInputFocus explicitly. But not if f is null,
9374 since that might be an event for a deleted frame. */
9377 Display
*d
= event
.xclient
.display
;
9378 /* Catch and ignore errors, in case window has been
9379 iconified by a window manager such as GWM. */
9380 int count
= x_catch_errors (d
);
9381 XSetInputFocus (d
, event
.xclient
.window
,
9382 /* The ICCCM says this is
9383 the only valid choice. */
9385 event
.xclient
.data
.l
[1]);
9386 /* This is needed to detect the error
9387 if there is an error. */
9389 x_uncatch_errors (d
, count
);
9391 /* Not certain about handling scroll bars here */
9394 else if (event
.xclient
.data
.l
[0]
9395 == dpyinfo
->Xatom_wm_save_yourself
)
9397 /* Save state modify the WM_COMMAND property to
9398 something which can reinstate us. This notifies
9399 the session manager, who's looking for such a
9400 PropertyNotify. Can restart processing when
9401 a keyboard or mouse event arrives. */
9404 f
= x_top_window_to_frame (dpyinfo
,
9405 event
.xclient
.window
);
9407 /* This is just so we only give real data once
9408 for a single Emacs process. */
9409 if (f
== SELECTED_FRAME ())
9410 XSetCommand (FRAME_X_DISPLAY (f
),
9411 event
.xclient
.window
,
9412 initial_argv
, initial_argc
);
9414 XSetCommand (FRAME_X_DISPLAY (f
),
9415 event
.xclient
.window
,
9419 else if (event
.xclient
.data
.l
[0]
9420 == dpyinfo
->Xatom_wm_delete_window
)
9423 = x_any_window_to_frame (dpyinfo
,
9424 event
.xclient
.window
);
9431 bufp
->kind
= delete_window_event
;
9432 XSETFRAME (bufp
->frame_or_window
, f
);
9441 else if (event
.xclient
.message_type
9442 == dpyinfo
->Xatom_wm_configure_denied
)
9445 else if (event
.xclient
.message_type
9446 == dpyinfo
->Xatom_wm_window_moved
)
9450 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9452 new_x
= event
.xclient
.data
.s
[0];
9453 new_y
= event
.xclient
.data
.s
[1];
9457 f
->output_data
.x
->left_pos
= new_x
;
9458 f
->output_data
.x
->top_pos
= new_y
;
9462 else if (event
.xclient
.message_type
9463 == dpyinfo
->Xatom_editres
)
9466 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9467 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
9470 #endif /* HACK_EDITRES */
9471 else if ((event
.xclient
.message_type
9472 == dpyinfo
->Xatom_DONE
)
9473 || (event
.xclient
.message_type
9474 == dpyinfo
->Xatom_PAGE
))
9476 /* Ghostview job completed. Kill it. We could
9477 reply with "Next" if we received "Page", but we
9478 currently never do because we are interested in
9479 images, only, which should have 1 page. */
9480 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
9482 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9483 x_kill_gs_process (pixmap
, f
);
9484 expose_frame (f
, 0, 0, 0, 0);
9486 #ifdef USE_TOOLKIT_SCROLL_BARS
9487 /* Scroll bar callbacks send a ClientMessage from which
9488 we construct an input_event. */
9489 else if (event
.xclient
.message_type
9490 == dpyinfo
->Xatom_Scrollbar
)
9492 x_scroll_bar_to_input_event (&event
, bufp
);
9493 ++bufp
, ++count
, --numchars
;
9496 #endif /* USE_TOOLKIT_SCROLL_BARS */
9502 case SelectionNotify
:
9503 #ifdef USE_X_TOOLKIT
9504 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
9506 #endif /* not USE_X_TOOLKIT */
9507 x_handle_selection_notify (&event
.xselection
);
9510 case SelectionClear
: /* Someone has grabbed ownership. */
9511 #ifdef USE_X_TOOLKIT
9512 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
9514 #endif /* USE_X_TOOLKIT */
9516 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
9521 bufp
->kind
= selection_clear_event
;
9522 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
9523 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
9524 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
9525 bufp
->frame_or_window
= Qnil
;
9534 case SelectionRequest
: /* Someone wants our selection. */
9535 #ifdef USE_X_TOOLKIT
9536 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
9538 #endif /* USE_X_TOOLKIT */
9539 if (x_queue_selection_requests
)
9540 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
9544 XSelectionRequestEvent
*eventp
= (XSelectionRequestEvent
*) &event
;
9549 bufp
->kind
= selection_request_event
;
9550 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
9551 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
9552 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
9553 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
9554 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
9555 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
9556 bufp
->frame_or_window
= Qnil
;
9565 case PropertyNotify
:
9566 #ifdef USE_X_TOOLKIT
9567 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
9569 #endif /* not USE_X_TOOLKIT */
9570 x_handle_property_notify (&event
.xproperty
);
9573 case ReparentNotify
:
9574 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
9578 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
9579 x_real_positions (f
, &x
, &y
);
9580 f
->output_data
.x
->left_pos
= x
;
9581 f
->output_data
.x
->top_pos
= y
;
9586 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
9589 if (f
->async_visible
== 0)
9591 f
->async_visible
= 1;
9592 f
->async_iconified
= 0;
9593 f
->output_data
.x
->has_been_visible
= 1;
9594 SET_FRAME_GARBAGED (f
);
9597 expose_frame (x_window_to_frame (dpyinfo
,
9598 event
.xexpose
.window
),
9599 event
.xexpose
.x
, event
.xexpose
.y
,
9600 event
.xexpose
.width
, event
.xexpose
.height
);
9604 #ifdef USE_TOOLKIT_SCROLL_BARS
9605 /* Dispatch event to the widget. */
9607 #else /* not USE_TOOLKIT_SCROLL_BARS */
9608 struct scroll_bar
*bar
9609 = x_window_to_scroll_bar (event
.xexpose
.window
);
9612 x_scroll_bar_expose (bar
, &event
);
9613 #ifdef USE_X_TOOLKIT
9616 #endif /* USE_X_TOOLKIT */
9617 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9621 case GraphicsExpose
: /* This occurs when an XCopyArea's
9622 source area was obscured or not
9624 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
9628 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
9629 event
.xgraphicsexpose
.width
,
9630 event
.xgraphicsexpose
.height
);
9632 #ifdef USE_X_TOOLKIT
9635 #endif /* USE_X_TOOLKIT */
9638 case NoExpose
: /* This occurs when an XCopyArea's
9639 source area was completely
9644 /* Redo the mouse-highlight after the tooltip has gone. */
9645 if (event
.xmap
.window
== tip_window
)
9648 redo_mouse_highlight ();
9651 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
9652 if (f
) /* F may no longer exist if
9653 the frame was deleted. */
9655 /* While a frame is unmapped, display generation is
9656 disabled; you don't want to spend time updating a
9657 display that won't ever be seen. */
9658 f
->async_visible
= 0;
9659 /* We can't distinguish, from the event, whether the window
9660 has become iconified or invisible. So assume, if it
9661 was previously visible, than now it is iconified.
9662 But x_make_frame_invisible clears both
9663 the visible flag and the iconified flag;
9664 and that way, we know the window is not iconified now. */
9665 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
9667 f
->async_iconified
= 1;
9669 bufp
->kind
= iconify_event
;
9670 XSETFRAME (bufp
->frame_or_window
, f
);
9680 if (event
.xmap
.window
== tip_window
)
9681 /* The tooltip has been drawn already. Avoid
9682 the SET_FRAME_GARBAGED below. */
9685 /* We use x_top_window_to_frame because map events can
9686 come for sub-windows and they don't mean that the
9687 frame is visible. */
9688 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
9691 f
->async_visible
= 1;
9692 f
->async_iconified
= 0;
9693 f
->output_data
.x
->has_been_visible
= 1;
9695 /* wait_reading_process_input will notice this and update
9696 the frame's display structures. */
9697 SET_FRAME_GARBAGED (f
);
9701 bufp
->kind
= deiconify_event
;
9702 XSETFRAME (bufp
->frame_or_window
, f
);
9708 else if (! NILP (Vframe_list
)
9709 && ! NILP (XCDR (Vframe_list
)))
9710 /* Force a redisplay sooner or later
9711 to update the frame titles
9712 in case this is the second frame. */
9713 record_asynch_buffer_change ();
9718 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
9721 /* I couldn't find a way to prevent LessTif scroll bars
9722 from consuming key events. */
9725 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
9727 if (widget
&& XmIsScrollBar (widget
))
9729 widget
= XtParent (widget
);
9730 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
9733 #endif /* USE_MOTIF */
9737 KeySym keysym
, orig_keysym
;
9738 /* al%imercury@uunet.uu.net says that making this 81
9739 instead of 80 fixed a bug whereby meta chars made
9742 It seems that some version of XmbLookupString has
9743 a bug of not returning XBufferOverflow in
9744 status_return even if the input is too long to
9745 fit in 81 bytes. So, we must prepare sufficient
9746 bytes for copy_buffer. 513 bytes (256 chars for
9747 two-byte character set) seems to be a faily good
9748 approximation. -- 2000.8.10 handa@etl.go.jp */
9749 unsigned char copy_buffer
[513];
9750 unsigned char *copy_bufptr
= copy_buffer
;
9751 int copy_bufsiz
= sizeof (copy_buffer
);
9755 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
9756 extra_keyboard_modifiers
);
9757 modifiers
= event
.xkey
.state
;
9759 /* This will have to go some day... */
9761 /* make_lispy_event turns chars into control chars.
9762 Don't do it here because XLookupString is too eager. */
9763 event
.xkey
.state
&= ~ControlMask
;
9764 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
9765 | dpyinfo
->super_mod_mask
9766 | dpyinfo
->hyper_mod_mask
9767 | dpyinfo
->alt_mod_mask
);
9769 /* In case Meta is ComposeCharacter,
9770 clear its status. According to Markus Ehrnsperger
9771 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
9772 this enables ComposeCharacter to work whether or
9773 not it is combined with Meta. */
9774 if (modifiers
& dpyinfo
->meta_mod_mask
)
9775 bzero (&compose_status
, sizeof (compose_status
));
9780 Status status_return
;
9782 nbytes
= XmbLookupString (FRAME_XIC (f
),
9783 &event
.xkey
, copy_bufptr
,
9784 copy_bufsiz
, &keysym
,
9786 if (status_return
== XBufferOverflow
)
9788 copy_bufsiz
= nbytes
+ 1;
9789 copy_bufptr
= (char *) alloca (copy_bufsiz
);
9790 nbytes
= XmbLookupString (FRAME_XIC (f
),
9791 &event
.xkey
, copy_bufptr
,
9792 copy_bufsiz
, &keysym
,
9796 if (status_return
== XLookupNone
)
9798 else if (status_return
== XLookupChars
)
9803 else if (status_return
!= XLookupKeySym
9804 && status_return
!= XLookupBoth
)
9808 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
9809 copy_bufsiz
, &keysym
,
9812 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
9813 copy_bufsiz
, &keysym
,
9817 orig_keysym
= keysym
;
9821 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
9822 || keysym
== XK_Delete
9823 #ifdef XK_ISO_Left_Tab
9824 || (keysym
>= XK_ISO_Left_Tab
&& keysym
<= XK_ISO_Enter
)
9826 || (keysym
>= XK_Kanji
&& keysym
<= XK_Eisu_toggle
)
9827 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
9828 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
9830 /* This recognizes the "extended function keys".
9831 It seems there's no cleaner way.
9832 Test IsModifierKey to avoid handling mode_switch
9834 || ((unsigned) (keysym
) >= XK_Select
9835 && (unsigned)(keysym
) < XK_KP_Space
)
9837 #ifdef XK_dead_circumflex
9838 || orig_keysym
== XK_dead_circumflex
9840 #ifdef XK_dead_grave
9841 || orig_keysym
== XK_dead_grave
9843 #ifdef XK_dead_tilde
9844 || orig_keysym
== XK_dead_tilde
9846 #ifdef XK_dead_diaeresis
9847 || orig_keysym
== XK_dead_diaeresis
9849 #ifdef XK_dead_macron
9850 || orig_keysym
== XK_dead_macron
9852 #ifdef XK_dead_degree
9853 || orig_keysym
== XK_dead_degree
9855 #ifdef XK_dead_acute
9856 || orig_keysym
== XK_dead_acute
9858 #ifdef XK_dead_cedilla
9859 || orig_keysym
== XK_dead_cedilla
9861 #ifdef XK_dead_breve
9862 || orig_keysym
== XK_dead_breve
9864 #ifdef XK_dead_ogonek
9865 || orig_keysym
== XK_dead_ogonek
9867 #ifdef XK_dead_caron
9868 || orig_keysym
== XK_dead_caron
9870 #ifdef XK_dead_doubleacute
9871 || orig_keysym
== XK_dead_doubleacute
9873 #ifdef XK_dead_abovedot
9874 || orig_keysym
== XK_dead_abovedot
9876 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
9877 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
9878 /* Any "vendor-specific" key is ok. */
9879 || (orig_keysym
& (1 << 28)))
9880 && ! (IsModifierKey (orig_keysym
)
9882 #ifdef XK_Mode_switch
9883 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
9886 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
9888 #endif /* not HAVE_X11R5 */
9891 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
9893 temp_buffer
[temp_index
++] = keysym
;
9894 bufp
->kind
= non_ascii_keystroke
;
9895 bufp
->code
= keysym
;
9896 XSETFRAME (bufp
->frame_or_window
, f
);
9899 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
9901 bufp
->timestamp
= event
.xkey
.time
;
9906 else if (numchars
> nbytes
)
9910 unsigned char *p
, *pend
;
9913 for (i
= 0; i
< nbytes
; i
++)
9915 if (temp_index
== (sizeof temp_buffer
9918 temp_buffer
[temp_index
++] = copy_bufptr
[i
];
9921 if (/* If the event is not from XIM, */
9922 event
.xkey
.keycode
!= 0
9923 /* or the current locale doesn't request
9924 decoding of the intup data, ... */
9925 || coding
.type
== coding_type_raw_text
9926 || coding
.type
== coding_type_no_conversion
)
9928 /* ... we can use the input data as is. */
9933 /* We have to decode the input data. */
9937 require
= decoding_buffer_size (&coding
, nbytes
);
9938 p
= (unsigned char *) alloca (require
);
9939 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
9940 decode_coding (&coding
, copy_bufptr
, p
,
9942 nbytes
= coding
.produced
;
9943 nchars
= coding
.produced_char
;
9947 /* Convert the input data to a sequence of
9948 character events. */
9949 for (i
= 0; i
< nbytes
; i
+= len
)
9951 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
9953 bufp
->kind
= (SINGLE_BYTE_CHAR_P (c
)
9955 : multibyte_char_keystroke
);
9957 XSETFRAME (bufp
->frame_or_window
, f
);
9960 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
9962 bufp
->timestamp
= event
.xkey
.time
;
9969 if (keysym
== NoSymbol
)
9979 /* Don't dispatch this event since XtDispatchEvent calls
9980 XFilterEvent, and two calls in a row may freeze the
9989 /* Don't dispatch this event since XtDispatchEvent calls
9990 XFilterEvent, and two calls in a row may freeze the
9997 /* Here's a possible interpretation of the whole
9998 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If
9999 you get a FocusIn event, you have to get a FocusOut
10000 event before you relinquish the focus. If you
10001 haven't received a FocusIn event, then a mere
10002 LeaveNotify is enough to free you. */
10006 int from_menu_bar_p
= 0;
10008 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10010 #ifdef LESSTIF_VERSION
10011 /* When clicking outside of a menu bar popup to close
10012 it, we get a FocusIn/ EnterNotify sequence of
10013 events. The flag event.xcrossing.focus is not set
10014 in the EnterNotify event of that sequence because
10015 the focus is in the menu bar,
10016 event.xcrossing.window is the frame's X window.
10017 Unconditionally setting the focus frame to null in
10018 this case is not the right thing, because no event
10019 follows that could set the focus frame to the right
10022 This could be a LessTif bug, but I wasn't able to
10023 reproduce the behavior in a simple test program.
10025 (gerd, LessTif 0.88.1). */
10027 if (!event
.xcrossing
.focus
10029 && f
->output_data
.x
->menubar_widget
)
10034 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
10035 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
10036 from_menu_bar_p
= 1;
10038 #endif /* LESSTIF_VERSION */
10040 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
10042 /* Avoid nasty pop/raise loops. */
10043 if (f
&& (!(f
->auto_raise
)
10044 || !(f
->auto_lower
)
10045 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
10047 x_new_focus_frame (dpyinfo
, f
);
10048 enter_timestamp
= event
.xcrossing
.time
;
10051 else if (f
== dpyinfo
->x_focus_frame
)
10052 x_new_focus_frame (dpyinfo
, 0);
10054 /* EnterNotify counts as mouse movement,
10055 so update things that depend on mouse position. */
10056 if (f
&& !f
->output_data
.x
->busy_p
)
10057 note_mouse_movement (f
, &event
.xmotion
);
10062 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
10063 if (event
.xfocus
.detail
!= NotifyPointer
)
10064 dpyinfo
->x_focus_event_frame
= f
;
10067 x_new_focus_frame (dpyinfo
, f
);
10069 /* Don't stop displaying the initial startup message
10070 for a switch-frame event we don't need. */
10071 if (GC_NILP (Vterminal_frame
)
10072 && GC_CONSP (Vframe_list
)
10073 && !GC_NILP (XCDR (Vframe_list
)))
10075 bufp
->kind
= FOCUS_IN_EVENT
;
10076 XSETFRAME (bufp
->frame_or_window
, f
);
10078 ++bufp
, ++count
, --numchars
;
10083 if (f
&& FRAME_XIC (f
))
10084 XSetICFocus (FRAME_XIC (f
));
10090 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10094 int from_menu_bar_p
= 0;
10096 if (f
== dpyinfo
->mouse_face_mouse_frame
)
10098 /* If we move outside the frame, then we're
10099 certainly no longer on any text in the frame. */
10100 clear_mouse_face (dpyinfo
);
10101 dpyinfo
->mouse_face_mouse_frame
= 0;
10104 /* Generate a nil HELP_EVENT to cancel a help-echo.
10105 Do it only if there's something to cancel.
10106 Otherwise, the startup message is cleared when
10107 the mouse leaves the frame. */
10108 if (any_help_event_p
)
10113 XSETFRAME (frame
, f
);
10114 n
= gen_help_event (bufp
, numchars
,
10115 Qnil
, frame
, Qnil
, Qnil
, 0);
10116 bufp
+= n
, count
+= n
, numchars
-= n
;
10119 #ifdef LESSTIF_VERSION
10120 /* Please see the comment at the start of the
10121 EnterNotify case. */
10122 if (!event
.xcrossing
.focus
10123 && f
->output_data
.x
->menubar_widget
)
10127 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
10128 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
10129 from_menu_bar_p
= 1;
10131 #endif /* LESSTIF_VERSION */
10133 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
10134 x_mouse_leave (dpyinfo
);
10137 if (f
== dpyinfo
->x_focus_event_frame
)
10138 dpyinfo
->x_focus_event_frame
= 0;
10139 if (f
== dpyinfo
->x_focus_frame
)
10140 x_new_focus_frame (dpyinfo
, 0);
10146 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
10147 if (event
.xfocus
.detail
!= NotifyPointer
10148 && f
== dpyinfo
->x_focus_event_frame
)
10149 dpyinfo
->x_focus_event_frame
= 0;
10150 if (f
&& f
== dpyinfo
->x_focus_frame
)
10151 x_new_focus_frame (dpyinfo
, 0);
10154 if (f
&& FRAME_XIC (f
))
10155 XUnsetICFocus (FRAME_XIC (f
));
10162 previous_help_echo
= help_echo
;
10163 help_echo
= help_echo_object
= help_echo_window
= Qnil
;
10164 help_echo_pos
= -1;
10166 if (dpyinfo
->grabbed
&& last_mouse_frame
10167 && FRAME_LIVE_P (last_mouse_frame
))
10168 f
= last_mouse_frame
;
10170 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
10173 note_mouse_movement (f
, &event
.xmotion
);
10176 #ifndef USE_TOOLKIT_SCROLL_BARS
10177 struct scroll_bar
*bar
10178 = x_window_to_scroll_bar (event
.xmotion
.window
);
10181 x_scroll_bar_note_movement (bar
, &event
);
10182 #endif /* USE_TOOLKIT_SCROLL_BARS */
10184 /* If we move outside the frame, then we're
10185 certainly no longer on any text in the frame. */
10186 clear_mouse_face (dpyinfo
);
10189 /* If the contents of the global variable help_echo
10190 has changed, generate a HELP_EVENT. */
10191 if (!NILP (help_echo
)
10192 || !NILP (previous_help_echo
))
10198 XSETFRAME (frame
, f
);
10202 any_help_event_p
= 1;
10203 n
= gen_help_event (bufp
, numchars
, help_echo
, frame
,
10204 help_echo_window
, help_echo_object
,
10206 bufp
+= n
, count
+= n
, numchars
-= n
;
10212 case ConfigureNotify
:
10213 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
10216 #ifndef USE_X_TOOLKIT
10217 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
10218 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
10220 /* In the toolkit version, change_frame_size
10221 is called by the code that handles resizing
10222 of the EmacsFrame widget. */
10224 /* Even if the number of character rows and columns has
10225 not changed, the font size may have changed, so we need
10226 to check the pixel dimensions as well. */
10227 if (columns
!= f
->width
10228 || rows
!= f
->height
10229 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
10230 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
10232 change_frame_size (f
, rows
, columns
, 0, 1, 0);
10233 SET_FRAME_GARBAGED (f
);
10234 cancel_mouse_face (f
);
10238 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
10239 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
10241 /* What we have now is the position of Emacs's own window.
10242 Convert that to the position of the window manager window. */
10243 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
10244 &f
->output_data
.x
->top_pos
);
10247 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
10248 xic_set_statusarea (f
);
10251 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
10253 /* Since the WM decorations come below top_pos now,
10254 we must put them below top_pos in the future. */
10255 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
10256 x_wm_set_size_hint (f
, (long) 0, 0);
10259 /* Some window managers pass (0,0) as the location of
10260 the window, and the Motif event handler stores it
10261 in the emacs widget, which messes up Motif menus. */
10262 if (event
.xconfigure
.x
== 0 && event
.xconfigure
.y
== 0)
10264 event
.xconfigure
.x
= f
->output_data
.x
->widget
->core
.x
;
10265 event
.xconfigure
.y
= f
->output_data
.x
->widget
->core
.y
;
10267 #endif /* USE_MOTIF */
10272 case ButtonRelease
:
10274 /* If we decide we want to generate an event to be seen
10275 by the rest of Emacs, we put it here. */
10276 struct input_event emacs_event
;
10277 int tool_bar_p
= 0;
10279 emacs_event
.kind
= no_event
;
10280 bzero (&compose_status
, sizeof (compose_status
));
10282 if (dpyinfo
->grabbed
10283 && last_mouse_frame
10284 && FRAME_LIVE_P (last_mouse_frame
))
10285 f
= last_mouse_frame
;
10287 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
10291 /* Is this in the tool-bar? */
10292 if (WINDOWP (f
->tool_bar_window
)
10293 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
10295 Lisp_Object window
;
10298 x
= event
.xbutton
.x
;
10299 y
= event
.xbutton
.y
;
10302 window
= window_from_coordinates (f
, x
, y
, &p
, 1);
10303 if (EQ (window
, f
->tool_bar_window
))
10305 x_handle_tool_bar_click (f
, &event
.xbutton
);
10311 if (!dpyinfo
->x_focus_frame
10312 || f
== dpyinfo
->x_focus_frame
)
10313 construct_mouse_click (&emacs_event
, &event
, f
);
10317 #ifndef USE_TOOLKIT_SCROLL_BARS
10318 struct scroll_bar
*bar
10319 = x_window_to_scroll_bar (event
.xbutton
.window
);
10322 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
10323 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10326 if (event
.type
== ButtonPress
)
10328 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
10329 last_mouse_frame
= f
;
10330 /* Ignore any mouse motion that happened
10331 before this event; any subsequent mouse-movement
10332 Emacs events should reflect only motion after
10333 the ButtonPress. */
10335 f
->mouse_moved
= 0;
10338 last_tool_bar_item
= -1;
10342 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
10345 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
10347 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
10353 #ifdef USE_X_TOOLKIT
10354 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
10355 /* For a down-event in the menu bar,
10356 don't pass it to Xt right now.
10357 Instead, save it away
10358 and we will pass it to Xt from kbd_buffer_get_event.
10359 That way, we can run some Lisp code first. */
10360 if (f
&& event
.type
== ButtonPress
10361 /* Verify the event is really within the menu bar
10362 and not just sent to it due to grabbing. */
10363 && event
.xbutton
.x
>= 0
10364 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
10365 && event
.xbutton
.y
>= 0
10366 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
10367 && event
.xbutton
.same_screen
)
10369 SET_SAVED_BUTTON_EVENT
;
10370 XSETFRAME (last_mouse_press_frame
, f
);
10372 else if (event
.type
== ButtonPress
)
10374 last_mouse_press_frame
= Qnil
;
10378 #ifdef USE_MOTIF /* This should do not harm for Lucid,
10379 but I am trying to be cautious. */
10380 else if (event
.type
== ButtonRelease
)
10382 if (!NILP (last_mouse_press_frame
))
10384 f
= XFRAME (last_mouse_press_frame
);
10385 if (f
->output_data
.x
)
10386 SET_SAVED_BUTTON_EVENT
;
10391 #endif /* USE_MOTIF */
10394 #endif /* USE_X_TOOLKIT */
10398 case CirculateNotify
:
10401 case CirculateRequest
:
10404 case VisibilityNotify
:
10407 case MappingNotify
:
10408 /* Someone has changed the keyboard mapping - update the
10410 switch (event
.xmapping
.request
)
10412 case MappingModifier
:
10413 x_find_modifier_meanings (dpyinfo
);
10414 /* This is meant to fall through. */
10415 case MappingKeyboard
:
10416 XRefreshKeyboardMapping (&event
.xmapping
);
10422 #ifdef USE_X_TOOLKIT
10424 XtDispatchEvent (&event
);
10426 #endif /* USE_X_TOOLKIT */
10434 /* On some systems, an X bug causes Emacs to get no more events
10435 when the window is destroyed. Detect that. (1994.) */
10438 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
10439 One XNOOP in 100 loops will make Emacs terminate.
10440 B. Bretthauer, 1994 */
10442 if (x_noop_count
>= 100)
10446 if (next_noop_dpyinfo
== 0)
10447 next_noop_dpyinfo
= x_display_list
;
10449 XNoOp (next_noop_dpyinfo
->display
);
10451 /* Each time we get here, cycle through the displays now open. */
10452 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
10456 /* If the focus was just given to an auto-raising frame,
10458 /* ??? This ought to be able to handle more than one such frame. */
10459 if (pending_autoraise_frame
)
10461 x_raise_frame (pending_autoraise_frame
);
10462 pending_autoraise_frame
= 0;
10473 /***********************************************************************
10475 ***********************************************************************/
10477 /* Note if the text cursor of window W has been overwritten by a
10478 drawing operation that outputs N glyphs starting at HPOS in the
10479 line given by output_cursor.vpos. N < 0 means all the rest of the
10480 line after HPOS has been written. */
10483 note_overwritten_text_cursor (w
, hpos
, n
)
10487 if (updated_area
== TEXT_AREA
10488 && output_cursor
.vpos
== w
->phys_cursor
.vpos
10489 && hpos
<= w
->phys_cursor
.hpos
10491 || hpos
+ n
> w
->phys_cursor
.hpos
))
10492 w
->phys_cursor_on_p
= 0;
10496 /* Set clipping for output in glyph row ROW. W is the window in which
10497 we operate. GC is the graphics context to set clipping in.
10498 WHOLE_LINE_P non-zero means include the areas used for truncation
10499 mark display and alike in the clipping rectangle.
10501 ROW may be a text row or, e.g., a mode line. Text rows must be
10502 clipped to the interior of the window dedicated to text display,
10503 mode lines must be clipped to the whole window. */
10506 x_clip_to_row (w
, row
, gc
, whole_line_p
)
10508 struct glyph_row
*row
;
10512 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10513 XRectangle clip_rect
;
10514 int window_x
, window_y
, window_width
, window_height
;
10516 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
10518 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
10519 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
10520 clip_rect
.y
= max (clip_rect
.y
, window_y
);
10521 clip_rect
.width
= window_width
;
10522 clip_rect
.height
= row
->visible_height
;
10524 /* If clipping to the whole line, including trunc marks, extend
10525 the rectangle to the left and increase its width. */
10528 clip_rect
.x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
10529 clip_rect
.width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
10532 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
10536 /* Draw a hollow box cursor on window W in glyph row ROW. */
10539 x_draw_hollow_cursor (w
, row
)
10541 struct glyph_row
*row
;
10543 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10544 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10545 Display
*dpy
= FRAME_X_DISPLAY (f
);
10548 struct glyph
*cursor_glyph
;
10551 /* Compute frame-relative coordinates from window-relative
10553 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
10554 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
10555 + row
->ascent
- w
->phys_cursor_ascent
);
10556 h
= row
->height
- 1;
10558 /* Get the glyph the cursor is on. If we can't tell because
10559 the current matrix is invalid or such, give up. */
10560 cursor_glyph
= get_phys_cursor_glyph (w
);
10561 if (cursor_glyph
== NULL
)
10564 /* Compute the width of the rectangle to draw. If on a stretch
10565 glyph, and `x-stretch-block-cursor' is nil, don't draw a
10566 rectangle as wide as the glyph, but use a canonical character
10568 wd
= cursor_glyph
->pixel_width
- 1;
10569 if (cursor_glyph
->type
== STRETCH_GLYPH
10570 && !x_stretch_cursor_p
)
10571 wd
= min (CANON_X_UNIT (f
), wd
);
10573 /* The foreground of cursor_gc is typically the same as the normal
10574 background color, which can cause the cursor box to be invisible. */
10575 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
10576 if (dpyinfo
->scratch_cursor_gc
)
10577 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
10579 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
10580 GCForeground
, &xgcv
);
10581 gc
= dpyinfo
->scratch_cursor_gc
;
10583 /* Set clipping, draw the rectangle, and reset clipping again. */
10584 x_clip_to_row (w
, row
, gc
, 0);
10585 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
10586 XSetClipMask (dpy
, gc
, None
);
10590 /* Draw a bar cursor on window W in glyph row ROW.
10592 Implementation note: One would like to draw a bar cursor with an
10593 angle equal to the one given by the font property XA_ITALIC_ANGLE.
10594 Unfortunately, I didn't find a font yet that has this property set.
10598 x_draw_bar_cursor (w
, row
, width
)
10600 struct glyph_row
*row
;
10603 struct frame
*f
= XFRAME (w
->frame
);
10604 struct glyph
*cursor_glyph
;
10607 unsigned long mask
;
10612 /* If cursor is out of bounds, don't draw garbage. This can happen
10613 in mini-buffer windows when switching between echo area glyphs
10614 and mini-buffer. */
10615 cursor_glyph
= get_phys_cursor_glyph (w
);
10616 if (cursor_glyph
== NULL
)
10619 /* If on an image, draw like a normal cursor. That's usually better
10620 visible than drawing a bar, esp. if the image is large so that
10621 the bar might not be in the window. */
10622 if (cursor_glyph
->type
== IMAGE_GLYPH
)
10624 struct glyph_row
*row
;
10625 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
10626 x_draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
10630 xgcv
.background
= f
->output_data
.x
->cursor_pixel
;
10631 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
10632 xgcv
.graphics_exposures
= 0;
10633 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
10634 dpy
= FRAME_X_DISPLAY (f
);
10635 window
= FRAME_X_WINDOW (f
);
10636 gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
10639 XChangeGC (dpy
, gc
, mask
, &xgcv
);
10642 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
10643 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
10647 width
= f
->output_data
.x
->cursor_width
;
10649 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
10650 x_clip_to_row (w
, row
, gc
, 0);
10651 XFillRectangle (dpy
, window
, gc
,
10653 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
10654 min (cursor_glyph
->pixel_width
, width
),
10656 XSetClipMask (dpy
, gc
, None
);
10661 /* Clear the cursor of window W to background color, and mark the
10662 cursor as not shown. This is used when the text where the cursor
10663 is is about to be rewritten. */
10669 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
10670 x_update_window_cursor (w
, 0);
10674 /* Draw the cursor glyph of window W in glyph row ROW. See the
10675 comment of x_draw_glyphs for the meaning of HL. */
10678 x_draw_phys_cursor_glyph (w
, row
, hl
)
10680 struct glyph_row
*row
;
10681 enum draw_glyphs_face hl
;
10683 /* If cursor hpos is out of bounds, don't draw garbage. This can
10684 happen in mini-buffer windows when switching between echo area
10685 glyphs and mini-buffer. */
10686 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
10688 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
10689 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
10692 /* When we erase the cursor, and ROW is overlapped by other
10693 rows, make sure that these overlapping parts of other rows
10695 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
10697 if (row
> w
->current_matrix
->rows
10698 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
10699 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
10701 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
10702 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
10703 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
10709 /* Erase the image of a cursor of window W from the screen. */
10712 x_erase_phys_cursor (w
)
10715 struct frame
*f
= XFRAME (w
->frame
);
10716 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10717 int hpos
= w
->phys_cursor
.hpos
;
10718 int vpos
= w
->phys_cursor
.vpos
;
10719 int mouse_face_here_p
= 0;
10720 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
10721 struct glyph_row
*cursor_row
;
10722 struct glyph
*cursor_glyph
;
10723 enum draw_glyphs_face hl
;
10725 /* No cursor displayed or row invalidated => nothing to do on the
10727 if (w
->phys_cursor_type
== NO_CURSOR
)
10728 goto mark_cursor_off
;
10730 /* VPOS >= active_glyphs->nrows means that window has been resized.
10731 Don't bother to erase the cursor. */
10732 if (vpos
>= active_glyphs
->nrows
)
10733 goto mark_cursor_off
;
10735 /* If row containing cursor is marked invalid, there is nothing we
10737 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
10738 if (!cursor_row
->enabled_p
)
10739 goto mark_cursor_off
;
10741 /* This can happen when the new row is shorter than the old one.
10742 In this case, either x_draw_glyphs or clear_end_of_line
10743 should have cleared the cursor. Note that we wouldn't be
10744 able to erase the cursor in this case because we don't have a
10745 cursor glyph at hand. */
10746 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
10747 goto mark_cursor_off
;
10749 /* If the cursor is in the mouse face area, redisplay that when
10750 we clear the cursor. */
10751 if (! NILP (dpyinfo
->mouse_face_window
)
10752 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
10753 && (vpos
> dpyinfo
->mouse_face_beg_row
10754 || (vpos
== dpyinfo
->mouse_face_beg_row
10755 && hpos
>= dpyinfo
->mouse_face_beg_col
))
10756 && (vpos
< dpyinfo
->mouse_face_end_row
10757 || (vpos
== dpyinfo
->mouse_face_end_row
10758 && hpos
< dpyinfo
->mouse_face_end_col
))
10759 /* Don't redraw the cursor's spot in mouse face if it is at the
10760 end of a line (on a newline). The cursor appears there, but
10761 mouse highlighting does not. */
10762 && cursor_row
->used
[TEXT_AREA
] > hpos
)
10763 mouse_face_here_p
= 1;
10765 /* Maybe clear the display under the cursor. */
10766 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
10769 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10771 cursor_glyph
= get_phys_cursor_glyph (w
);
10772 if (cursor_glyph
== NULL
)
10773 goto mark_cursor_off
;
10775 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
10777 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10779 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
10781 cursor_glyph
->pixel_width
,
10782 cursor_row
->visible_height
,
10786 /* Erase the cursor by redrawing the character underneath it. */
10787 if (mouse_face_here_p
)
10788 hl
= DRAW_MOUSE_FACE
;
10789 else if (cursor_row
->inverse_p
)
10790 hl
= DRAW_INVERSE_VIDEO
;
10792 hl
= DRAW_NORMAL_TEXT
;
10793 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
10796 w
->phys_cursor_on_p
= 0;
10797 w
->phys_cursor_type
= NO_CURSOR
;
10801 /* Display or clear cursor of window W. If ON is zero, clear the
10802 cursor. If it is non-zero, display the cursor. If ON is nonzero,
10803 where to put the cursor is specified by HPOS, VPOS, X and Y. */
10806 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
10808 int on
, hpos
, vpos
, x
, y
;
10810 struct frame
*f
= XFRAME (w
->frame
);
10811 int new_cursor_type
;
10812 int new_cursor_width
;
10813 struct glyph_matrix
*current_glyphs
;
10814 struct glyph_row
*glyph_row
;
10815 struct glyph
*glyph
;
10817 /* This is pointless on invisible frames, and dangerous on garbaged
10818 windows and frames; in the latter case, the frame or window may
10819 be in the midst of changing its size, and x and y may be off the
10821 if (! FRAME_VISIBLE_P (f
)
10822 || FRAME_GARBAGED_P (f
)
10823 || vpos
>= w
->current_matrix
->nrows
10824 || hpos
>= w
->current_matrix
->matrix_w
)
10827 /* If cursor is off and we want it off, return quickly. */
10828 if (!on
&& !w
->phys_cursor_on_p
)
10831 current_glyphs
= w
->current_matrix
;
10832 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
10833 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
10835 /* If cursor row is not enabled, we don't really know where to
10836 display the cursor. */
10837 if (!glyph_row
->enabled_p
)
10839 w
->phys_cursor_on_p
= 0;
10843 xassert (interrupt_input_blocked
);
10845 /* Set new_cursor_type to the cursor we want to be displayed. In a
10846 mini-buffer window, we want the cursor only to appear if we are
10847 reading input from this window. For the selected window, we want
10848 the cursor type given by the frame parameter. If explicitly
10849 marked off, draw no cursor. In all other cases, we want a hollow
10851 new_cursor_width
= -1;
10852 if (cursor_in_echo_area
10853 && FRAME_HAS_MINIBUF_P (f
)
10854 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
10856 if (w
== XWINDOW (echo_area_window
))
10857 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
10859 new_cursor_type
= HOLLOW_BOX_CURSOR
;
10863 if (w
!= XWINDOW (selected_window
)
10864 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
10866 extern int cursor_in_non_selected_windows
;
10868 if (MINI_WINDOW_P (w
)
10869 || !cursor_in_non_selected_windows
10870 || NILP (XBUFFER (w
->buffer
)->cursor_type
))
10871 new_cursor_type
= NO_CURSOR
;
10873 new_cursor_type
= HOLLOW_BOX_CURSOR
;
10875 else if (w
->cursor_off_p
)
10876 new_cursor_type
= NO_CURSOR
;
10879 struct buffer
*b
= XBUFFER (w
->buffer
);
10881 if (EQ (b
->cursor_type
, Qt
))
10882 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
10884 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
10885 &new_cursor_width
);
10889 /* If cursor is currently being shown and we don't want it to be or
10890 it is in the wrong place, or the cursor type is not what we want,
10892 if (w
->phys_cursor_on_p
10894 || w
->phys_cursor
.x
!= x
10895 || w
->phys_cursor
.y
!= y
10896 || new_cursor_type
!= w
->phys_cursor_type
))
10897 x_erase_phys_cursor (w
);
10899 /* If the cursor is now invisible and we want it to be visible,
10901 if (on
&& !w
->phys_cursor_on_p
)
10903 w
->phys_cursor_ascent
= glyph_row
->ascent
;
10904 w
->phys_cursor_height
= glyph_row
->height
;
10906 /* Set phys_cursor_.* before x_draw_.* is called because some
10907 of them may need the information. */
10908 w
->phys_cursor
.x
= x
;
10909 w
->phys_cursor
.y
= glyph_row
->y
;
10910 w
->phys_cursor
.hpos
= hpos
;
10911 w
->phys_cursor
.vpos
= vpos
;
10912 w
->phys_cursor_type
= new_cursor_type
;
10913 w
->phys_cursor_on_p
= 1;
10915 switch (new_cursor_type
)
10917 case HOLLOW_BOX_CURSOR
:
10918 x_draw_hollow_cursor (w
, glyph_row
);
10921 case FILLED_BOX_CURSOR
:
10922 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
10926 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
);
10937 if (w
== XWINDOW (f
->selected_window
))
10938 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
10939 xic_set_preeditarea (w
, x
, y
);
10944 if (updating_frame
!= f
)
10945 XFlush (FRAME_X_DISPLAY (f
));
10950 /* Display the cursor on window W, or clear it. X and Y are window
10951 relative pixel coordinates. HPOS and VPOS are glyph matrix
10952 positions. If W is not the selected window, display a hollow
10953 cursor. ON non-zero means display the cursor at X, Y which
10954 correspond to HPOS, VPOS, otherwise it is cleared. */
10957 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
10959 int on
, hpos
, vpos
, x
, y
;
10962 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
10967 /* Display the cursor on window W, or clear it, according to ON_P.
10968 Don't change the cursor's position. */
10971 x_update_cursor (f
, on_p
)
10974 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
10978 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
10979 in the window tree rooted at W. */
10982 x_update_cursor_in_window_tree (w
, on_p
)
10988 if (!NILP (w
->hchild
))
10989 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
10990 else if (!NILP (w
->vchild
))
10991 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
10993 x_update_window_cursor (w
, on_p
);
10995 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
11000 /* Switch the display of W's cursor on or off, according to the value
11004 x_update_window_cursor (w
, on
)
11008 /* Don't update cursor in windows whose frame is in the process
11009 of being deleted. */
11010 if (w
->current_matrix
)
11013 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
11014 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
11024 /* Refresh bitmap kitchen sink icon for frame F
11025 when we get an expose event for it. */
11031 /* Normally, the window manager handles this function. */
11034 /* Make the x-window of frame F use the gnu icon bitmap. */
11037 x_bitmap_icon (f
, file
)
11043 if (FRAME_X_WINDOW (f
) == 0)
11046 /* Free up our existing icon bitmap if any. */
11047 if (f
->output_data
.x
->icon_bitmap
> 0)
11048 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
11049 f
->output_data
.x
->icon_bitmap
= 0;
11051 if (STRINGP (file
))
11052 bitmap_id
= x_create_bitmap_from_file (f
, file
);
11055 /* Create the GNU bitmap if necessary. */
11056 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
11057 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
11058 = x_create_bitmap_from_data (f
, gnu_bits
,
11059 gnu_width
, gnu_height
);
11061 /* The first time we create the GNU bitmap,
11062 this increments the ref-count one extra time.
11063 As a result, the GNU bitmap is never freed.
11064 That way, we don't have to worry about allocating it again. */
11065 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
11067 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
11070 x_wm_set_icon_pixmap (f
, bitmap_id
);
11071 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
11077 /* Make the x-window of frame F use a rectangle with text.
11078 Use ICON_NAME as the text. */
11081 x_text_icon (f
, icon_name
)
11085 if (FRAME_X_WINDOW (f
) == 0)
11090 XTextProperty text
;
11091 text
.value
= (unsigned char *) icon_name
;
11092 text
.encoding
= XA_STRING
;
11094 text
.nitems
= strlen (icon_name
);
11095 #ifdef USE_X_TOOLKIT
11096 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
11098 #else /* not USE_X_TOOLKIT */
11099 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
11100 #endif /* not USE_X_TOOLKIT */
11102 #else /* not HAVE_X11R4 */
11103 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
11104 #endif /* not HAVE_X11R4 */
11106 if (f
->output_data
.x
->icon_bitmap
> 0)
11107 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
11108 f
->output_data
.x
->icon_bitmap
= 0;
11109 x_wm_set_icon_pixmap (f
, 0);
11114 #define X_ERROR_MESSAGE_SIZE 200
11116 /* If non-nil, this should be a string.
11117 It means catch X errors and store the error message in this string. */
11119 static Lisp_Object x_error_message_string
;
11121 /* An X error handler which stores the error message in
11122 x_error_message_string. This is called from x_error_handler if
11123 x_catch_errors is in effect. */
11126 x_error_catcher (display
, error
)
11128 XErrorEvent
*error
;
11130 XGetErrorText (display
, error
->error_code
,
11131 XSTRING (x_error_message_string
)->data
,
11132 X_ERROR_MESSAGE_SIZE
);
11135 /* Begin trapping X errors for display DPY. Actually we trap X errors
11136 for all displays, but DPY should be the display you are actually
11139 After calling this function, X protocol errors no longer cause
11140 Emacs to exit; instead, they are recorded in the string
11141 stored in x_error_message_string.
11143 Calling x_check_errors signals an Emacs error if an X error has
11144 occurred since the last call to x_catch_errors or x_check_errors.
11146 Calling x_uncatch_errors resumes the normal error handling. */
11148 void x_check_errors ();
11149 static Lisp_Object
x_catch_errors_unwind ();
11152 x_catch_errors (dpy
)
11155 int count
= specpdl_ptr
- specpdl
;
11157 /* Make sure any errors from previous requests have been dealt with. */
11158 XSync (dpy
, False
);
11160 record_unwind_protect (x_catch_errors_unwind
, x_error_message_string
);
11162 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
11163 XSTRING (x_error_message_string
)->data
[0] = 0;
11168 /* Unbind the binding that we made to check for X errors. */
11171 x_catch_errors_unwind (old_val
)
11172 Lisp_Object old_val
;
11174 x_error_message_string
= old_val
;
11178 /* If any X protocol errors have arrived since the last call to
11179 x_catch_errors or x_check_errors, signal an Emacs error using
11180 sprintf (a buffer, FORMAT, the x error message text) as the text. */
11183 x_check_errors (dpy
, format
)
11187 /* Make sure to catch any errors incurred so far. */
11188 XSync (dpy
, False
);
11190 if (XSTRING (x_error_message_string
)->data
[0])
11191 error (format
, XSTRING (x_error_message_string
)->data
);
11194 /* Nonzero if we had any X protocol errors
11195 since we did x_catch_errors on DPY. */
11198 x_had_errors_p (dpy
)
11201 /* Make sure to catch any errors incurred so far. */
11202 XSync (dpy
, False
);
11204 return XSTRING (x_error_message_string
)->data
[0] != 0;
11207 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
11210 x_clear_errors (dpy
)
11213 XSTRING (x_error_message_string
)->data
[0] = 0;
11216 /* Stop catching X protocol errors and let them make Emacs die.
11217 DPY should be the display that was passed to x_catch_errors.
11218 COUNT should be the value that was returned by
11219 the corresponding call to x_catch_errors. */
11222 x_uncatch_errors (dpy
, count
)
11226 unbind_to (count
, Qnil
);
11230 static unsigned int x_wire_count
;
11233 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
11238 /* Handle SIGPIPE, which can happen when the connection to a server
11239 simply goes away. SIGPIPE is handled by x_connection_signal.
11240 Don't need to do anything, because the write which caused the
11241 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
11242 which will do the appropriate cleanup for us. */
11245 x_connection_signal (signalnum
) /* If we don't have an argument, */
11246 int signalnum
; /* some compilers complain in signal calls. */
11249 /* USG systems forget handlers when they are used;
11250 must reestablish each time */
11251 signal (signalnum
, x_connection_signal
);
11255 /* Handling X errors. */
11257 /* Handle the loss of connection to display DISPLAY. */
11260 x_connection_closed (display
, error_message
)
11262 char *error_message
;
11264 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
11265 Lisp_Object frame
, tail
;
11267 /* Indicate that this display is dead. */
11269 #if 0 /* Closing the display caused a bus error on OpenWindows. */
11270 #ifdef USE_X_TOOLKIT
11271 XtCloseDisplay (display
);
11276 dpyinfo
->display
= 0;
11278 /* First delete frames whose mini-buffers are on frames
11279 that are on the dead display. */
11280 FOR_EACH_FRAME (tail
, frame
)
11282 Lisp_Object minibuf_frame
;
11284 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
11285 if (FRAME_X_P (XFRAME (frame
))
11286 && FRAME_X_P (XFRAME (minibuf_frame
))
11287 && ! EQ (frame
, minibuf_frame
)
11288 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
11289 Fdelete_frame (frame
, Qt
);
11292 /* Now delete all remaining frames on the dead display.
11293 We are now sure none of these is used as the mini-buffer
11294 for another frame that we need to delete. */
11295 FOR_EACH_FRAME (tail
, frame
)
11296 if (FRAME_X_P (XFRAME (frame
))
11297 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
11299 /* Set this to t so that Fdelete_frame won't get confused
11300 trying to find a replacement. */
11301 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
11302 Fdelete_frame (frame
, Qt
);
11306 x_delete_display (dpyinfo
);
11308 if (x_display_list
== 0)
11310 fprintf (stderr
, "%s\n", error_message
);
11311 shut_down_emacs (0, 0, Qnil
);
11315 /* Ordinary stack unwind doesn't deal with these. */
11317 sigunblock (sigmask (SIGIO
));
11319 sigunblock (sigmask (SIGALRM
));
11320 TOTALLY_UNBLOCK_INPUT
;
11322 clear_waiting_for_input ();
11323 handling_signal
= 0;
11324 error ("%s", error_message
);
11327 /* This is the usual handler for X protocol errors.
11328 It kills all frames on the display that we got the error for.
11329 If that was the only one, it prints an error message and kills Emacs. */
11332 x_error_quitter (display
, error
)
11334 XErrorEvent
*error
;
11336 char buf
[256], buf1
[356];
11338 /* Note that there is no real way portable across R3/R4 to get the
11339 original error handler. */
11341 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
11342 sprintf (buf1
, "X protocol error: %s on protocol request %d",
11343 buf
, error
->request_code
);
11344 x_connection_closed (display
, buf1
);
11347 /* This is the first-level handler for X protocol errors.
11348 It calls x_error_quitter or x_error_catcher. */
11351 x_error_handler (display
, error
)
11353 XErrorEvent
*error
;
11355 if (! NILP (x_error_message_string
))
11356 x_error_catcher (display
, error
);
11358 x_error_quitter (display
, error
);
11362 /* This is the handler for X IO errors, always.
11363 It kills all frames on the display that we lost touch with.
11364 If that was the only one, it prints an error message and kills Emacs. */
11367 x_io_error_quitter (display
)
11372 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
11373 x_connection_closed (display
, buf
);
11377 /* Changing the font of the frame. */
11379 /* Give frame F the font named FONTNAME as its default font, and
11380 return the full name of that font. FONTNAME may be a wildcard
11381 pattern; in that case, we choose some font that fits the pattern.
11382 The return value shows which font we chose. */
11385 x_new_font (f
, fontname
)
11387 register char *fontname
;
11389 struct font_info
*fontp
11390 = FS_LOAD_FONT (f
, 0, fontname
, -1);
11395 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
11396 f
->output_data
.x
->baseline_offset
= fontp
->baseline_offset
;
11397 f
->output_data
.x
->fontset
= -1;
11399 /* Compute the scroll bar width in character columns. */
11400 if (f
->scroll_bar_pixel_width
> 0)
11402 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
11403 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
11407 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
11408 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
11411 /* Now make the frame display the given font. */
11412 if (FRAME_X_WINDOW (f
) != 0)
11414 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
11415 f
->output_data
.x
->font
->fid
);
11416 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
11417 f
->output_data
.x
->font
->fid
);
11418 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
11419 f
->output_data
.x
->font
->fid
);
11421 frame_update_line_height (f
);
11422 x_set_window_size (f
, 0, f
->width
, f
->height
);
11425 /* If we are setting a new frame's font for the first time,
11426 there are no faces yet, so this font's height is the line height. */
11427 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
11429 return build_string (fontp
->full_name
);
11432 /* Give frame F the fontset named FONTSETNAME as its default font, and
11433 return the full name of that fontset. FONTSETNAME may be a wildcard
11434 pattern; in that case, we choose some fontset that fits the pattern.
11435 The return value shows which fontset we chose. */
11438 x_new_fontset (f
, fontsetname
)
11442 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
11443 Lisp_Object result
;
11448 if (f
->output_data
.x
->fontset
== fontset
)
11449 /* This fontset is already set in frame F. There's nothing more
11451 return fontset_name (fontset
);
11453 result
= x_new_font (f
, (XSTRING (fontset_ascii (fontset
))->data
));
11455 if (!STRINGP (result
))
11456 /* Can't load ASCII font. */
11459 /* Since x_new_font doesn't update any fontset information, do it now. */
11460 f
->output_data
.x
->fontset
= fontset
;
11464 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
11465 xic_set_xfontset (f
, XSTRING (fontset_ascii (fontset
))->data
);
11468 return build_string (fontsetname
);
11472 /***********************************************************************
11474 ***********************************************************************/
11480 /* XIM destroy callback function, which is called whenever the
11481 connection to input method XIM dies. CLIENT_DATA contains a
11482 pointer to the x_display_info structure corresponding to XIM. */
11485 xim_destroy_callback (xim
, client_data
, call_data
)
11487 XPointer client_data
;
11488 XPointer call_data
;
11490 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
11491 Lisp_Object frame
, tail
;
11495 /* No need to call XDestroyIC.. */
11496 FOR_EACH_FRAME (tail
, frame
)
11498 struct frame
*f
= XFRAME (frame
);
11499 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
11501 FRAME_XIC (f
) = NULL
;
11502 if (FRAME_XIC_FONTSET (f
))
11504 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
11505 FRAME_XIC_FONTSET (f
) = NULL
;
11510 /* No need to call XCloseIM. */
11511 dpyinfo
->xim
= NULL
;
11512 XFree (dpyinfo
->xim_styles
);
11516 #endif /* HAVE_X11R6 */
11518 /* Open the connection to the XIM server on display DPYINFO.
11519 RESOURCE_NAME is the resource name Emacs uses. */
11522 xim_open_dpy (dpyinfo
, resource_name
)
11523 struct x_display_info
*dpyinfo
;
11524 char *resource_name
;
11529 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
, EMACS_CLASS
);
11530 dpyinfo
->xim
= xim
;
11535 XIMCallback destroy
;
11538 /* Get supported styles and XIM values. */
11539 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
11542 destroy
.callback
= xim_destroy_callback
;
11543 destroy
.client_data
= (XPointer
)dpyinfo
;
11544 /* This isn't prptotyped in OSF 5.0. */
11545 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
11549 #else /* not USE_XIM */
11550 dpyinfo
->xim
= NULL
;
11551 #endif /* not USE_XIM */
11555 #ifdef HAVE_X11R6_XIM
11559 struct x_display_info
*dpyinfo
;
11560 char *resource_name
;
11563 /* XIM instantiate callback function, which is called whenever an XIM
11564 server is available. DISPLAY is teh display of the XIM.
11565 CLIENT_DATA contains a pointer to an xim_inst_t structure created
11566 when the callback was registered. */
11569 xim_instantiate_callback (display
, client_data
, call_data
)
11571 XPointer client_data
;
11572 XPointer call_data
;
11574 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
11575 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
11577 /* We don't support multiple XIM connections. */
11581 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
11583 /* Create XIC for the existing frames on the same display, as long
11584 as they have no XIC. */
11585 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
11587 Lisp_Object tail
, frame
;
11590 FOR_EACH_FRAME (tail
, frame
)
11592 struct frame
*f
= XFRAME (frame
);
11594 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
11595 if (FRAME_XIC (f
) == NULL
)
11597 create_frame_xic (f
);
11598 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
11599 xic_set_statusarea (f
);
11600 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
11602 struct window
*w
= XWINDOW (f
->selected_window
);
11603 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
11612 #endif /* HAVE_X11R6_XIM */
11615 /* Open a connection to the XIM server on display DPYINFO.
11616 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
11617 connection only at the first time. On X11R6, open the connection
11618 in the XIM instantiate callback function. */
11621 xim_initialize (dpyinfo
, resource_name
)
11622 struct x_display_info
*dpyinfo
;
11623 char *resource_name
;
11626 #ifdef HAVE_X11R6_XIM
11627 struct xim_inst_t
*xim_inst
;
11630 dpyinfo
->xim
= NULL
;
11631 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
11632 xim_inst
->dpyinfo
= dpyinfo
;
11633 len
= strlen (resource_name
);
11634 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
11635 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
11636 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
11637 resource_name
, EMACS_CLASS
,
11638 xim_instantiate_callback
,
11639 /* Fixme: This is XPointer in
11640 XFree86 but (XPointer *) on
11641 Tru64, at least. */
11642 (XPointer
) xim_inst
);
11643 #else /* not HAVE_X11R6_XIM */
11644 dpyinfo
->xim
= NULL
;
11645 xim_open_dpy (dpyinfo
, resource_name
);
11646 #endif /* not HAVE_X11R6_XIM */
11648 #else /* not USE_XIM */
11649 dpyinfo
->xim
= NULL
;
11650 #endif /* not USE_XIM */
11654 /* Close the connection to the XIM server on display DPYINFO. */
11657 xim_close_dpy (dpyinfo
)
11658 struct x_display_info
*dpyinfo
;
11661 #ifdef HAVE_X11R6_XIM
11662 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
11664 xim_instantiate_callback
, NULL
);
11665 #endif /* not HAVE_X11R6_XIM */
11666 XCloseIM (dpyinfo
->xim
);
11667 dpyinfo
->xim
= NULL
;
11668 XFree (dpyinfo
->xim_styles
);
11669 #endif /* USE_XIM */
11672 #endif /* not HAVE_X11R6_XIM */
11676 /* Calculate the absolute position in frame F
11677 from its current recorded position values and gravity. */
11680 x_calc_absolute_position (f
)
11684 int win_x
= 0, win_y
= 0;
11685 int flags
= f
->output_data
.x
->size_hint_flags
;
11688 /* We have nothing to do if the current position
11689 is already for the top-left corner. */
11690 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
11693 #ifdef USE_X_TOOLKIT
11694 this_window
= XtWindow (f
->output_data
.x
->widget
);
11696 this_window
= FRAME_X_WINDOW (f
);
11699 /* Find the position of the outside upper-left corner of
11700 the inner window, with respect to the outer window.
11701 But do this only if we will need the results. */
11702 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
11707 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
11710 x_clear_errors (FRAME_X_DISPLAY (f
));
11711 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
11713 /* From-window, to-window. */
11715 f
->output_data
.x
->parent_desc
,
11717 /* From-position, to-position. */
11718 0, 0, &win_x
, &win_y
,
11720 /* Child of win. */
11722 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
11724 Window newroot
, newparent
= 0xdeadbeef;
11725 Window
*newchildren
;
11726 unsigned int nchildren
;
11728 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
11729 &newparent
, &newchildren
, &nchildren
))
11732 XFree ((char *) newchildren
);
11734 f
->output_data
.x
->parent_desc
= newparent
;
11740 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
11744 /* Treat negative positions as relative to the leftmost bottommost
11745 position that fits on the screen. */
11746 if (flags
& XNegative
)
11747 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
11748 - 2 * f
->output_data
.x
->border_width
- win_x
11750 + f
->output_data
.x
->left_pos
);
11752 if (flags
& YNegative
)
11754 int menubar_height
= 0;
11756 #ifdef USE_X_TOOLKIT
11757 if (f
->output_data
.x
->menubar_widget
)
11759 = (f
->output_data
.x
->menubar_widget
->core
.height
11760 + f
->output_data
.x
->menubar_widget
->core
.border_width
);
11763 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
11764 - 2 * f
->output_data
.x
->border_width
11768 + f
->output_data
.x
->top_pos
);
11771 /* The left_pos and top_pos
11772 are now relative to the top and left screen edges,
11773 so the flags should correspond. */
11774 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
11777 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
11778 to really change the position, and 0 when calling from
11779 x_make_frame_visible (in that case, XOFF and YOFF are the current
11780 position values). It is -1 when calling from x_set_frame_parameters,
11781 which means, do adjust for borders but don't change the gravity. */
11784 x_set_offset (f
, xoff
, yoff
, change_gravity
)
11786 register int xoff
, yoff
;
11787 int change_gravity
;
11789 int modified_top
, modified_left
;
11791 if (change_gravity
> 0)
11793 f
->output_data
.x
->top_pos
= yoff
;
11794 f
->output_data
.x
->left_pos
= xoff
;
11795 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
11797 f
->output_data
.x
->size_hint_flags
|= XNegative
;
11799 f
->output_data
.x
->size_hint_flags
|= YNegative
;
11800 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
11802 x_calc_absolute_position (f
);
11805 x_wm_set_size_hint (f
, (long) 0, 0);
11807 modified_left
= f
->output_data
.x
->left_pos
;
11808 modified_top
= f
->output_data
.x
->top_pos
;
11809 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
11810 this seems to be unnecessary and incorrect. rms, 4/17/97. */
11811 /* It is a mystery why we need to add the border_width here
11812 when the frame is already visible, but experiment says we do. */
11813 if (change_gravity
!= 0)
11815 modified_left
+= f
->output_data
.x
->border_width
;
11816 modified_top
+= f
->output_data
.x
->border_width
;
11820 #ifdef USE_X_TOOLKIT
11821 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
11822 modified_left
, modified_top
);
11823 #else /* not USE_X_TOOLKIT */
11824 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11825 modified_left
, modified_top
);
11826 #endif /* not USE_X_TOOLKIT */
11830 /* Call this to change the size of frame F's x-window.
11831 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
11832 for this size change and subsequent size changes.
11833 Otherwise we leave the window gravity unchanged. */
11836 x_set_window_size (f
, change_gravity
, cols
, rows
)
11838 int change_gravity
;
11841 #ifndef USE_X_TOOLKIT
11842 int pixelwidth
, pixelheight
;
11847 #ifdef USE_X_TOOLKIT
11849 /* The x and y position of the widget is clobbered by the
11850 call to XtSetValues within EmacsFrameSetCharSize.
11851 This is a real kludge, but I don't understand Xt so I can't
11852 figure out a correct fix. Can anyone else tell me? -- rms. */
11853 int xpos
= f
->output_data
.x
->widget
->core
.x
;
11854 int ypos
= f
->output_data
.x
->widget
->core
.y
;
11855 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
11856 f
->output_data
.x
->widget
->core
.x
= xpos
;
11857 f
->output_data
.x
->widget
->core
.y
= ypos
;
11860 #else /* not USE_X_TOOLKIT */
11862 check_frame_size (f
, &rows
, &cols
);
11863 f
->output_data
.x
->vertical_scroll_bar_extra
11864 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
11866 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
11867 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
11868 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
11869 f
->output_data
.x
->flags_areas_extra
11870 = FRAME_FLAGS_AREA_WIDTH (f
);
11871 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
11872 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
11874 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
11875 x_wm_set_size_hint (f
, (long) 0, 0);
11877 XSync (FRAME_X_DISPLAY (f
), False
);
11878 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11879 pixelwidth
, pixelheight
);
11881 /* Now, strictly speaking, we can't be sure that this is accurate,
11882 but the window manager will get around to dealing with the size
11883 change request eventually, and we'll hear how it went when the
11884 ConfigureNotify event gets here.
11886 We could just not bother storing any of this information here,
11887 and let the ConfigureNotify event set everything up, but that
11888 might be kind of confusing to the Lisp code, since size changes
11889 wouldn't be reported in the frame parameters until some random
11890 point in the future when the ConfigureNotify event arrives.
11892 We pass 1 for DELAY since we can't run Lisp code inside of
11894 change_frame_size (f
, rows
, cols
, 0, 1, 0);
11895 PIXEL_WIDTH (f
) = pixelwidth
;
11896 PIXEL_HEIGHT (f
) = pixelheight
;
11898 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
11899 receive in the ConfigureNotify event; if we get what we asked
11900 for, then the event won't cause the screen to become garbaged, so
11901 we have to make sure to do it here. */
11902 SET_FRAME_GARBAGED (f
);
11904 XFlush (FRAME_X_DISPLAY (f
));
11906 #endif /* not USE_X_TOOLKIT */
11908 /* If cursor was outside the new size, mark it as off. */
11909 mark_window_cursors_off (XWINDOW (f
->root_window
));
11911 /* Clear out any recollection of where the mouse highlighting was,
11912 since it might be in a place that's outside the new frame size.
11913 Actually checking whether it is outside is a pain in the neck,
11914 so don't try--just let the highlighting be done afresh with new size. */
11915 cancel_mouse_face (f
);
11920 /* Mouse warping. */
11923 x_set_mouse_position (f
, x
, y
)
11929 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
11930 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
11932 if (pix_x
< 0) pix_x
= 0;
11933 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
11935 if (pix_y
< 0) pix_y
= 0;
11936 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
11940 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
11941 0, 0, 0, 0, pix_x
, pix_y
);
11945 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
11948 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
11954 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
11955 0, 0, 0, 0, pix_x
, pix_y
);
11959 /* focus shifting, raising and lowering. */
11962 x_focus_on_frame (f
)
11965 #if 0 /* This proves to be unpleasant. */
11969 /* I don't think that the ICCCM allows programs to do things like this
11970 without the interaction of the window manager. Whatever you end up
11971 doing with this code, do it to x_unfocus_frame too. */
11972 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11973 RevertToPointerRoot
, CurrentTime
);
11978 x_unfocus_frame (f
)
11982 /* Look at the remarks in x_focus_on_frame. */
11983 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
11984 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
11985 RevertToPointerRoot
, CurrentTime
);
11989 /* Raise frame F. */
11995 if (f
->async_visible
)
11998 #ifdef USE_X_TOOLKIT
11999 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
12000 #else /* not USE_X_TOOLKIT */
12001 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12002 #endif /* not USE_X_TOOLKIT */
12003 XFlush (FRAME_X_DISPLAY (f
));
12008 /* Lower frame F. */
12014 if (f
->async_visible
)
12017 #ifdef USE_X_TOOLKIT
12018 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
12019 #else /* not USE_X_TOOLKIT */
12020 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12021 #endif /* not USE_X_TOOLKIT */
12022 XFlush (FRAME_X_DISPLAY (f
));
12028 XTframe_raise_lower (f
, raise_flag
)
12038 /* Change of visibility. */
12040 /* This tries to wait until the frame is really visible.
12041 However, if the window manager asks the user where to position
12042 the frame, this will return before the user finishes doing that.
12043 The frame will not actually be visible at that time,
12044 but it will become visible later when the window manager
12045 finishes with it. */
12048 x_make_frame_visible (f
)
12052 int original_top
, original_left
;
12053 int retry_count
= 2;
12059 type
= x_icon_type (f
);
12061 x_bitmap_icon (f
, type
);
12063 if (! FRAME_VISIBLE_P (f
))
12065 /* We test FRAME_GARBAGED_P here to make sure we don't
12066 call x_set_offset a second time
12067 if we get to x_make_frame_visible a second time
12068 before the window gets really visible. */
12069 if (! FRAME_ICONIFIED_P (f
)
12070 && ! f
->output_data
.x
->asked_for_visible
)
12071 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
12073 f
->output_data
.x
->asked_for_visible
= 1;
12075 if (! EQ (Vx_no_window_manager
, Qt
))
12076 x_wm_set_window_state (f
, NormalState
);
12077 #ifdef USE_X_TOOLKIT
12078 /* This was XtPopup, but that did nothing for an iconified frame. */
12079 XtMapWidget (f
->output_data
.x
->widget
);
12080 #else /* not USE_X_TOOLKIT */
12081 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12082 #endif /* not USE_X_TOOLKIT */
12083 #if 0 /* This seems to bring back scroll bars in the wrong places
12084 if the window configuration has changed. They seem
12085 to come back ok without this. */
12086 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
12087 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12091 XFlush (FRAME_X_DISPLAY (f
));
12093 /* Synchronize to ensure Emacs knows the frame is visible
12094 before we do anything else. We do this loop with input not blocked
12095 so that incoming events are handled. */
12099 /* This must be before UNBLOCK_INPUT
12100 since events that arrive in response to the actions above
12101 will set it when they are handled. */
12102 int previously_visible
= f
->output_data
.x
->has_been_visible
;
12104 original_left
= f
->output_data
.x
->left_pos
;
12105 original_top
= f
->output_data
.x
->top_pos
;
12107 /* This must come after we set COUNT. */
12110 /* We unblock here so that arriving X events are processed. */
12112 /* Now move the window back to where it was "supposed to be".
12113 But don't do it if the gravity is negative.
12114 When the gravity is negative, this uses a position
12115 that is 3 pixels too low. Perhaps that's really the border width.
12117 Don't do this if the window has never been visible before,
12118 because the window manager may choose the position
12119 and we don't want to override it. */
12121 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
12122 && f
->output_data
.x
->win_gravity
== NorthWestGravity
12123 && previously_visible
)
12127 unsigned int width
, height
, border
, depth
;
12131 /* On some window managers (such as FVWM) moving an existing
12132 window, even to the same place, causes the window manager
12133 to introduce an offset. This can cause the window to move
12134 to an unexpected location. Check the geometry (a little
12135 slow here) and then verify that the window is in the right
12136 place. If the window is not in the right place, move it
12137 there, and take the potential window manager hit. */
12138 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
12139 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
12141 if (original_left
!= x
|| original_top
!= y
)
12142 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
12143 original_left
, original_top
);
12148 XSETFRAME (frame
, f
);
12150 /* Wait until the frame is visible. Process X events until a
12151 MapNotify event has been seen, or until we think we won't get a
12152 MapNotify at all.. */
12153 for (count
= input_signal_count
+ 10;
12154 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
12156 /* Force processing of queued events. */
12159 /* Machines that do polling rather than SIGIO have been
12160 observed to go into a busy-wait here. So we'll fake an
12161 alarm signal to let the handler know that there's something
12162 to be read. We used to raise a real alarm, but it seems
12163 that the handler isn't always enabled here. This is
12165 if (input_polling_used ())
12167 /* It could be confusing if a real alarm arrives while
12168 processing the fake one. Turn it off and let the
12169 handler reset it. */
12170 extern void poll_for_input_1
P_ ((void));
12171 int old_poll_suppress_count
= poll_suppress_count
;
12172 poll_suppress_count
= 1;
12173 poll_for_input_1 ();
12174 poll_suppress_count
= old_poll_suppress_count
;
12177 /* See if a MapNotify event has been processed. */
12178 FRAME_SAMPLE_VISIBILITY (f
);
12183 (let ((f (selected-frame)))
12187 the frame is not raised with various window managers on
12188 FreeBSD, Linux and Solaris. It turns out that, for some
12189 unknown reason, the call to XtMapWidget is completely ignored.
12190 Mapping the widget a second time works. */
12192 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
12197 /* Change from mapped state to withdrawn state. */
12199 /* Make the frame visible (mapped and not iconified). */
12202 x_make_frame_invisible (f
)
12207 #ifdef USE_X_TOOLKIT
12208 /* Use the frame's outermost window, not the one we normally draw on. */
12209 window
= XtWindow (f
->output_data
.x
->widget
);
12210 #else /* not USE_X_TOOLKIT */
12211 window
= FRAME_X_WINDOW (f
);
12212 #endif /* not USE_X_TOOLKIT */
12214 /* Don't keep the highlight on an invisible frame. */
12215 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
12216 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
12218 #if 0/* This might add unreliability; I don't trust it -- rms. */
12219 if (! f
->async_visible
&& ! f
->async_iconified
)
12225 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
12226 that the current position of the window is user-specified, rather than
12227 program-specified, so that when the window is mapped again, it will be
12228 placed at the same location, without forcing the user to position it
12229 by hand again (they have already done that once for this window.) */
12230 x_wm_set_size_hint (f
, (long) 0, 1);
12234 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
12235 DefaultScreen (FRAME_X_DISPLAY (f
))))
12237 UNBLOCK_INPUT_RESIGNAL
;
12238 error ("Can't notify window manager of window withdrawal");
12240 #else /* ! defined (HAVE_X11R4) */
12242 /* Tell the window manager what we're going to do. */
12243 if (! EQ (Vx_no_window_manager
, Qt
))
12247 unmap
.xunmap
.type
= UnmapNotify
;
12248 unmap
.xunmap
.window
= window
;
12249 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
12250 unmap
.xunmap
.from_configure
= False
;
12251 if (! XSendEvent (FRAME_X_DISPLAY (f
),
12252 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
12254 SubstructureRedirectMaskSubstructureNotifyMask
,
12257 UNBLOCK_INPUT_RESIGNAL
;
12258 error ("Can't notify window manager of withdrawal");
12262 /* Unmap the window ourselves. Cheeky! */
12263 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
12264 #endif /* ! defined (HAVE_X11R4) */
12266 /* We can't distinguish this from iconification
12267 just by the event that we get from the server.
12268 So we can't win using the usual strategy of letting
12269 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
12270 and synchronize with the server to make sure we agree. */
12272 FRAME_ICONIFIED_P (f
) = 0;
12273 f
->async_visible
= 0;
12274 f
->async_iconified
= 0;
12281 /* Change window state from mapped to iconified. */
12284 x_iconify_frame (f
)
12290 /* Don't keep the highlight on an invisible frame. */
12291 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
12292 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
12294 if (f
->async_iconified
)
12299 FRAME_SAMPLE_VISIBILITY (f
);
12301 type
= x_icon_type (f
);
12303 x_bitmap_icon (f
, type
);
12305 #ifdef USE_X_TOOLKIT
12307 if (! FRAME_VISIBLE_P (f
))
12309 if (! EQ (Vx_no_window_manager
, Qt
))
12310 x_wm_set_window_state (f
, IconicState
);
12311 /* This was XtPopup, but that did nothing for an iconified frame. */
12312 XtMapWidget (f
->output_data
.x
->widget
);
12313 /* The server won't give us any event to indicate
12314 that an invisible frame was changed to an icon,
12315 so we have to record it here. */
12318 f
->async_iconified
= 1;
12319 f
->async_visible
= 0;
12324 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
12325 XtWindow (f
->output_data
.x
->widget
),
12326 DefaultScreen (FRAME_X_DISPLAY (f
)));
12330 error ("Can't notify window manager of iconification");
12332 f
->async_iconified
= 1;
12333 f
->async_visible
= 0;
12337 XFlush (FRAME_X_DISPLAY (f
));
12339 #else /* not USE_X_TOOLKIT */
12341 /* Make sure the X server knows where the window should be positioned,
12342 in case the user deiconifies with the window manager. */
12343 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
12344 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
12346 /* Since we don't know which revision of X we're running, we'll use both
12347 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
12349 /* X11R4: send a ClientMessage to the window manager using the
12350 WM_CHANGE_STATE type. */
12354 message
.xclient
.window
= FRAME_X_WINDOW (f
);
12355 message
.xclient
.type
= ClientMessage
;
12356 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
12357 message
.xclient
.format
= 32;
12358 message
.xclient
.data
.l
[0] = IconicState
;
12360 if (! XSendEvent (FRAME_X_DISPLAY (f
),
12361 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
12363 SubstructureRedirectMask
| SubstructureNotifyMask
,
12366 UNBLOCK_INPUT_RESIGNAL
;
12367 error ("Can't notify window manager of iconification");
12371 /* X11R3: set the initial_state field of the window manager hints to
12373 x_wm_set_window_state (f
, IconicState
);
12375 if (!FRAME_VISIBLE_P (f
))
12377 /* If the frame was withdrawn, before, we must map it. */
12378 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12381 f
->async_iconified
= 1;
12382 f
->async_visible
= 0;
12384 XFlush (FRAME_X_DISPLAY (f
));
12386 #endif /* not USE_X_TOOLKIT */
12389 /* Destroy the X window of frame F. */
12392 x_destroy_window (f
)
12395 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12399 /* If a display connection is dead, don't try sending more
12400 commands to the X server. */
12401 if (dpyinfo
->display
!= 0)
12403 if (f
->output_data
.x
->icon_desc
!= 0)
12404 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
12407 free_frame_xic (f
);
12409 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->window_desc
);
12410 #ifdef USE_X_TOOLKIT
12411 if (f
->output_data
.x
->widget
)
12412 XtDestroyWidget (f
->output_data
.x
->widget
);
12413 free_frame_menubar (f
);
12414 #endif /* USE_X_TOOLKIT */
12416 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
12417 unload_color (f
, f
->output_data
.x
->background_pixel
);
12418 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
12419 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
12420 unload_color (f
, f
->output_data
.x
->border_pixel
);
12421 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
12422 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
12423 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
12424 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
12425 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
12426 if (f
->output_data
.x
->white_relief
.allocated_p
)
12427 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
12428 if (f
->output_data
.x
->black_relief
.allocated_p
)
12429 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
12431 free_frame_faces (f
);
12432 XFlush (FRAME_X_DISPLAY (f
));
12435 if (f
->output_data
.x
->saved_menu_event
)
12436 xfree (f
->output_data
.x
->saved_menu_event
);
12438 xfree (f
->output_data
.x
);
12439 f
->output_data
.x
= 0;
12440 if (f
== dpyinfo
->x_focus_frame
)
12441 dpyinfo
->x_focus_frame
= 0;
12442 if (f
== dpyinfo
->x_focus_event_frame
)
12443 dpyinfo
->x_focus_event_frame
= 0;
12444 if (f
== dpyinfo
->x_highlight_frame
)
12445 dpyinfo
->x_highlight_frame
= 0;
12447 dpyinfo
->reference_count
--;
12449 if (f
== dpyinfo
->mouse_face_mouse_frame
)
12451 dpyinfo
->mouse_face_beg_row
12452 = dpyinfo
->mouse_face_beg_col
= -1;
12453 dpyinfo
->mouse_face_end_row
12454 = dpyinfo
->mouse_face_end_col
= -1;
12455 dpyinfo
->mouse_face_window
= Qnil
;
12456 dpyinfo
->mouse_face_deferred_gc
= 0;
12457 dpyinfo
->mouse_face_mouse_frame
= 0;
12463 /* Setting window manager hints. */
12465 /* Set the normal size hints for the window manager, for frame F.
12466 FLAGS is the flags word to use--or 0 meaning preserve the flags
12467 that the window now has.
12468 If USER_POSITION is nonzero, we set the USPosition
12469 flag (this is useful when FLAGS is 0). */
12472 x_wm_set_size_hint (f
, flags
, user_position
)
12477 XSizeHints size_hints
;
12479 #ifdef USE_X_TOOLKIT
12482 Dimension widget_width
, widget_height
;
12483 Window window
= XtWindow (f
->output_data
.x
->widget
);
12484 #else /* not USE_X_TOOLKIT */
12485 Window window
= FRAME_X_WINDOW (f
);
12486 #endif /* not USE_X_TOOLKIT */
12488 /* Setting PMaxSize caused various problems. */
12489 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
12491 size_hints
.x
= f
->output_data
.x
->left_pos
;
12492 size_hints
.y
= f
->output_data
.x
->top_pos
;
12494 #ifdef USE_X_TOOLKIT
12495 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
12496 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
12497 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
12498 size_hints
.height
= widget_height
;
12499 size_hints
.width
= widget_width
;
12500 #else /* not USE_X_TOOLKIT */
12501 size_hints
.height
= PIXEL_HEIGHT (f
);
12502 size_hints
.width
= PIXEL_WIDTH (f
);
12503 #endif /* not USE_X_TOOLKIT */
12505 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
12506 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
12507 size_hints
.max_width
12508 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
12509 size_hints
.max_height
12510 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
12512 /* Calculate the base and minimum sizes.
12514 (When we use the X toolkit, we don't do it here.
12515 Instead we copy the values that the widgets are using, below.) */
12516 #ifndef USE_X_TOOLKIT
12518 int base_width
, base_height
;
12519 int min_rows
= 0, min_cols
= 0;
12521 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
12522 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
12524 check_frame_size (f
, &min_rows
, &min_cols
);
12526 /* The window manager uses the base width hints to calculate the
12527 current number of rows and columns in the frame while
12528 resizing; min_width and min_height aren't useful for this
12529 purpose, since they might not give the dimensions for a
12530 zero-row, zero-column frame.
12532 We use the base_width and base_height members if we have
12533 them; otherwise, we set the min_width and min_height members
12534 to the size for a zero x zero frame. */
12537 size_hints
.flags
|= PBaseSize
;
12538 size_hints
.base_width
= base_width
;
12539 size_hints
.base_height
= base_height
;
12540 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
12541 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
12543 size_hints
.min_width
= base_width
;
12544 size_hints
.min_height
= base_height
;
12548 /* If we don't need the old flags, we don't need the old hint at all. */
12551 size_hints
.flags
|= flags
;
12554 #endif /* not USE_X_TOOLKIT */
12557 XSizeHints hints
; /* Sometimes I hate X Windows... */
12558 long supplied_return
;
12562 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
12565 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
12568 #ifdef USE_X_TOOLKIT
12569 size_hints
.base_height
= hints
.base_height
;
12570 size_hints
.base_width
= hints
.base_width
;
12571 size_hints
.min_height
= hints
.min_height
;
12572 size_hints
.min_width
= hints
.min_width
;
12576 size_hints
.flags
|= flags
;
12581 if (hints
.flags
& PSize
)
12582 size_hints
.flags
|= PSize
;
12583 if (hints
.flags
& PPosition
)
12584 size_hints
.flags
|= PPosition
;
12585 if (hints
.flags
& USPosition
)
12586 size_hints
.flags
|= USPosition
;
12587 if (hints
.flags
& USSize
)
12588 size_hints
.flags
|= USSize
;
12592 #ifndef USE_X_TOOLKIT
12597 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
12598 size_hints
.flags
|= PWinGravity
;
12602 size_hints
.flags
&= ~ PPosition
;
12603 size_hints
.flags
|= USPosition
;
12605 #endif /* PWinGravity */
12608 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
12610 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
12614 /* Used for IconicState or NormalState */
12617 x_wm_set_window_state (f
, state
)
12621 #ifdef USE_X_TOOLKIT
12624 XtSetArg (al
[0], XtNinitialState
, state
);
12625 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
12626 #else /* not USE_X_TOOLKIT */
12627 Window window
= FRAME_X_WINDOW (f
);
12629 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
12630 f
->output_data
.x
->wm_hints
.initial_state
= state
;
12632 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12633 #endif /* not USE_X_TOOLKIT */
12637 x_wm_set_icon_pixmap (f
, pixmap_id
)
12641 Pixmap icon_pixmap
;
12643 #ifndef USE_X_TOOLKIT
12644 Window window
= FRAME_X_WINDOW (f
);
12649 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
12650 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
12654 /* It seems there is no way to turn off use of an icon pixmap.
12655 The following line does it, only if no icon has yet been created,
12656 for some window managers. But with mwm it crashes.
12657 Some people say it should clear the IconPixmapHint bit in this case,
12658 but that doesn't work, and the X consortium said it isn't the
12659 right thing at all. Since there is no way to win,
12660 best to explicitly give up. */
12662 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
12668 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
12672 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
12673 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
12676 #else /* not USE_X_TOOLKIT */
12678 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
12679 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12681 #endif /* not USE_X_TOOLKIT */
12685 x_wm_set_icon_position (f
, icon_x
, icon_y
)
12687 int icon_x
, icon_y
;
12689 #ifdef USE_X_TOOLKIT
12690 Window window
= XtWindow (f
->output_data
.x
->widget
);
12692 Window window
= FRAME_X_WINDOW (f
);
12695 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
12696 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
12697 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
12699 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12703 /***********************************************************************
12705 ***********************************************************************/
12707 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
12710 x_get_font_info (f
, font_idx
)
12714 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
12718 /* Return a list of names of available fonts matching PATTERN on frame
12719 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
12720 to be listed. Frame F NULL means we have not yet created any
12721 frame on X, and consult the first display in x_display_list.
12722 MAXNAMES sets a limit on how many fonts to match. */
12725 x_list_fonts (f
, pattern
, size
, maxnames
)
12727 Lisp_Object pattern
;
12731 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
12732 Lisp_Object tem
, second_best
;
12733 Display
*dpy
= f
!= NULL
? FRAME_X_DISPLAY (f
) : x_display_list
->display
;
12734 int try_XLoadQueryFont
= 0;
12737 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
12738 if (NILP (patterns
))
12739 patterns
= Fcons (pattern
, Qnil
);
12741 if (maxnames
== 1 && !size
)
12742 /* We can return any single font matching PATTERN. */
12743 try_XLoadQueryFont
= 1;
12745 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
12748 char **names
= NULL
;
12750 pattern
= XCAR (patterns
);
12751 /* See if we cached the result for this particular query.
12752 The cache is an alist of the form:
12753 (((PATTERN . MAXNAMES) (FONTNAME . WIDTH) ...) ...)
12755 if (f
&& (tem
= XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
),
12756 key
= Fcons (pattern
, make_number (maxnames
)),
12757 !NILP (list
= Fassoc (key
, tem
))))
12759 list
= Fcdr_safe (list
);
12760 /* We have a cashed list. Don't have to get the list again. */
12764 /* At first, put PATTERN in the cache. */
12767 count
= x_catch_errors (dpy
);
12769 if (try_XLoadQueryFont
)
12772 unsigned long value
;
12774 font
= XLoadQueryFont (dpy
, XSTRING (pattern
)->data
);
12775 if (x_had_errors_p (dpy
))
12777 /* This error is perhaps due to insufficient memory on X
12778 server. Let's just ignore it. */
12780 x_clear_errors (dpy
);
12784 && XGetFontProperty (font
, XA_FONT
, &value
))
12786 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
12787 int len
= strlen (name
);
12790 /* If DXPC (a Differential X Protocol Compressor)
12791 Ver.3.7 is running, XGetAtomName will return null
12792 string. We must avoid such a name. */
12794 try_XLoadQueryFont
= 0;
12798 names
= (char **) alloca (sizeof (char *));
12799 /* Some systems only allow alloca assigned to a
12801 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
12802 bcopy (name
, names
[0], len
+ 1);
12807 try_XLoadQueryFont
= 0;
12810 XFreeFont (dpy
, font
);
12813 if (!try_XLoadQueryFont
)
12815 /* We try at least 10 fonts because XListFonts will return
12816 auto-scaled fonts at the head. */
12817 names
= XListFonts (dpy
, XSTRING (pattern
)->data
, max (maxnames
, 10),
12819 if (x_had_errors_p (dpy
))
12821 /* This error is perhaps due to insufficient memory on X
12822 server. Let's just ignore it. */
12824 x_clear_errors (dpy
);
12828 x_uncatch_errors (dpy
, count
);
12835 /* Make a list of all the fonts we got back.
12836 Store that in the font cache for the display. */
12837 for (i
= 0; i
< num_fonts
; i
++)
12840 char *p
= names
[i
];
12841 int average_width
= -1, dashes
= 0;
12843 /* Count the number of dashes in NAMES[I]. If there are
12844 14 dashes, and the field value following 12th dash
12845 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
12846 is usually too ugly to be used for editing. Let's
12852 if (dashes
== 7) /* PIXEL_SIZE field */
12854 else if (dashes
== 12) /* AVERAGE_WIDTH field */
12855 average_width
= atoi (p
);
12857 if (dashes
< 14 || average_width
!= 0)
12859 tem
= build_string (names
[i
]);
12860 if (NILP (Fassoc (tem
, list
)))
12862 if (STRINGP (Vx_pixel_size_width_font_regexp
)
12863 && ((fast_c_string_match_ignore_case
12864 (Vx_pixel_size_width_font_regexp
, names
[i
]))
12866 /* We can set the value of PIXEL_SIZE to the
12867 width of this font. */
12868 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
12870 /* For the moment, width is not known. */
12871 list
= Fcons (Fcons (tem
, Qnil
), list
);
12875 if (!try_XLoadQueryFont
)
12876 XFreeFontNames (names
);
12879 /* Now store the result in the cache. */
12881 XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)
12882 = Fcons (Fcons (key
, list
),
12883 XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
));
12886 if (NILP (list
)) continue; /* Try the remaining alternatives. */
12888 newlist
= second_best
= Qnil
;
12889 /* Make a list of the fonts that have the right width. */
12890 for (; CONSP (list
); list
= XCDR (list
))
12896 if (!CONSP (tem
) || NILP (XCAR (tem
)))
12900 newlist
= Fcons (XCAR (tem
), newlist
);
12904 if (!INTEGERP (XCDR (tem
)))
12906 /* Since we have not yet known the size of this font, we
12907 must try slow function call XLoadQueryFont. */
12908 XFontStruct
*thisinfo
;
12911 count
= x_catch_errors (dpy
);
12912 thisinfo
= XLoadQueryFont (dpy
,
12913 XSTRING (XCAR (tem
))->data
);
12914 if (x_had_errors_p (dpy
))
12916 /* This error is perhaps due to insufficient memory on X
12917 server. Let's just ignore it. */
12919 x_clear_errors (dpy
);
12921 x_uncatch_errors (dpy
, count
);
12927 = (thisinfo
->min_bounds
.width
== 0
12929 : make_number (thisinfo
->max_bounds
.width
));
12930 XFreeFont (dpy
, thisinfo
);
12933 /* For unknown reason, the previous call of XListFont had
12934 returned a font which can't be opened. Record the size
12935 as 0 not to try to open it again. */
12936 XCDR (tem
) = make_number (0);
12939 found_size
= XINT (XCDR (tem
));
12940 if (found_size
== size
)
12941 newlist
= Fcons (XCAR (tem
), newlist
);
12942 else if (found_size
> 0)
12944 if (NILP (second_best
))
12946 else if (found_size
< size
)
12948 if (XINT (XCDR (second_best
)) > size
12949 || XINT (XCDR (second_best
)) < found_size
)
12954 if (XINT (XCDR (second_best
)) > size
12955 && XINT (XCDR (second_best
)) > found_size
)
12960 if (!NILP (newlist
))
12962 else if (!NILP (second_best
))
12964 newlist
= Fcons (XCAR (second_best
), Qnil
);
12975 /* Check that FONT is valid on frame F. It is if it can be found in F's
12979 x_check_font (f
, font
)
12984 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12986 xassert (font
!= NULL
);
12988 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12989 if (dpyinfo
->font_table
[i
].name
12990 && font
== dpyinfo
->font_table
[i
].font
)
12993 xassert (i
< dpyinfo
->n_fonts
);
12996 #endif /* GLYPH_DEBUG != 0 */
12998 /* Set *W to the minimum width, *H to the minimum font height of FONT.
12999 Note: There are (broken) X fonts out there with invalid XFontStruct
13000 min_bounds contents. For example, handa@etl.go.jp reports that
13001 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
13002 have font->min_bounds.width == 0. */
13005 x_font_min_bounds (font
, w
, h
)
13009 *h
= FONT_HEIGHT (font
);
13010 *w
= font
->min_bounds
.width
;
13012 /* Try to handle the case where FONT->min_bounds has invalid
13013 contents. Since the only font known to have invalid min_bounds
13014 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
13016 *w
= font
->max_bounds
.width
;
13020 /* Compute the smallest character width and smallest font height over
13021 all fonts available on frame F. Set the members smallest_char_width
13022 and smallest_font_height in F's x_display_info structure to
13023 the values computed. Value is non-zero if smallest_font_height or
13024 smallest_char_width become smaller than they were before. */
13027 x_compute_min_glyph_bounds (f
)
13031 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13033 int old_width
= dpyinfo
->smallest_char_width
;
13034 int old_height
= dpyinfo
->smallest_font_height
;
13036 dpyinfo
->smallest_font_height
= 100000;
13037 dpyinfo
->smallest_char_width
= 100000;
13039 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
13040 if (dpyinfo
->font_table
[i
].name
)
13042 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
13045 font
= (XFontStruct
*) fontp
->font
;
13046 xassert (font
!= (XFontStruct
*) ~0);
13047 x_font_min_bounds (font
, &w
, &h
);
13049 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
13050 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
13053 xassert (dpyinfo
->smallest_char_width
> 0
13054 && dpyinfo
->smallest_font_height
> 0);
13056 return (dpyinfo
->n_fonts
== 1
13057 || dpyinfo
->smallest_char_width
< old_width
13058 || dpyinfo
->smallest_font_height
< old_height
);
13062 /* Load font named FONTNAME of the size SIZE for frame F, and return a
13063 pointer to the structure font_info while allocating it dynamically.
13064 If SIZE is 0, load any size of font.
13065 If loading is failed, return NULL. */
13068 x_load_font (f
, fontname
, size
)
13070 register char *fontname
;
13073 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13074 Lisp_Object font_names
;
13077 /* Get a list of all the fonts that match this name. Once we
13078 have a list of matching fonts, we compare them against the fonts
13079 we already have by comparing names. */
13080 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
13082 if (!NILP (font_names
))
13087 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
13088 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
13089 if (dpyinfo
->font_table
[i
].name
13090 && (!strcmp (dpyinfo
->font_table
[i
].name
,
13091 XSTRING (XCAR (tail
))->data
)
13092 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
13093 XSTRING (XCAR (tail
))->data
)))
13094 return (dpyinfo
->font_table
+ i
);
13097 /* Load the font and add it to the table. */
13101 struct font_info
*fontp
;
13102 unsigned long value
;
13105 /* If we have found fonts by x_list_font, load one of them. If
13106 not, we still try to load a font by the name given as FONTNAME
13107 because XListFonts (called in x_list_font) of some X server has
13108 a bug of not finding a font even if the font surely exists and
13109 is loadable by XLoadQueryFont. */
13110 if (size
> 0 && !NILP (font_names
))
13111 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
13114 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
13115 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
13116 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
13118 /* This error is perhaps due to insufficient memory on X
13119 server. Let's just ignore it. */
13121 x_clear_errors (FRAME_X_DISPLAY (f
));
13123 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
13128 /* Find a free slot in the font table. */
13129 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
13130 if (dpyinfo
->font_table
[i
].name
== NULL
)
13133 /* If no free slot found, maybe enlarge the font table. */
13134 if (i
== dpyinfo
->n_fonts
13135 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
13138 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
13139 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
13140 dpyinfo
->font_table
13141 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
13144 fontp
= dpyinfo
->font_table
+ i
;
13145 if (i
== dpyinfo
->n_fonts
)
13146 ++dpyinfo
->n_fonts
;
13148 /* Now fill in the slots of *FONTP. */
13150 fontp
->font
= font
;
13151 fontp
->font_idx
= i
;
13152 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
13153 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
13155 /* Try to get the full name of FONT. Put it in FULL_NAME. */
13157 if (XGetFontProperty (font
, XA_FONT
, &value
))
13159 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
13163 /* Count the number of dashes in the "full name".
13164 If it is too few, this isn't really the font's full name,
13166 In X11R4, the fonts did not come with their canonical names
13177 full_name
= (char *) xmalloc (p
- name
+ 1);
13178 bcopy (name
, full_name
, p
- name
+ 1);
13184 if (full_name
!= 0)
13185 fontp
->full_name
= full_name
;
13187 fontp
->full_name
= fontp
->name
;
13189 fontp
->size
= font
->max_bounds
.width
;
13190 fontp
->height
= FONT_HEIGHT (font
);
13192 /* For some font, ascent and descent in max_bounds field is
13193 larger than the above value. */
13194 int max_height
= font
->max_bounds
.ascent
+ font
->max_bounds
.descent
;
13195 if (max_height
> fontp
->height
)
13196 fontp
->height
= max_height
;
13199 if (NILP (font_names
))
13201 /* We come here because of a bug of XListFonts mentioned at
13202 the head of this block. Let's store this information in
13203 the cache for x_list_fonts. */
13204 Lisp_Object lispy_name
= build_string (fontname
);
13205 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
13207 XCDR (dpyinfo
->name_list_element
)
13208 = Fcons (Fcons (Fcons (lispy_name
, make_number (256)),
13209 Fcons (Fcons (lispy_full_name
,
13210 make_number (fontp
->size
)),
13212 XCDR (dpyinfo
->name_list_element
));
13214 XCDR (dpyinfo
->name_list_element
)
13215 = Fcons (Fcons (Fcons (lispy_full_name
, make_number (256)),
13216 Fcons (Fcons (lispy_full_name
,
13217 make_number (fontp
->size
)),
13219 XCDR (dpyinfo
->name_list_element
));
13222 /* The slot `encoding' specifies how to map a character
13223 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
13224 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
13225 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
13226 2:0xA020..0xFF7F). For the moment, we don't know which charset
13227 uses this font. So, we set information in fontp->encoding[1]
13228 which is never used by any charset. If mapping can't be
13229 decided, set FONT_ENCODING_NOT_DECIDED. */
13231 = (font
->max_byte1
== 0
13233 ? (font
->min_char_or_byte2
< 0x80
13234 ? (font
->max_char_or_byte2
< 0x80
13235 ? 0 /* 0x20..0x7F */
13236 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
13237 : 1) /* 0xA0..0xFF */
13239 : (font
->min_byte1
< 0x80
13240 ? (font
->max_byte1
< 0x80
13241 ? (font
->min_char_or_byte2
< 0x80
13242 ? (font
->max_char_or_byte2
< 0x80
13243 ? 0 /* 0x2020..0x7F7F */
13244 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
13245 : 3) /* 0x20A0..0x7FFF */
13246 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
13247 : (font
->min_char_or_byte2
< 0x80
13248 ? (font
->max_char_or_byte2
< 0x80
13249 ? 2 /* 0xA020..0xFF7F */
13250 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
13251 : 1))); /* 0xA0A0..0xFFFF */
13253 fontp
->baseline_offset
13254 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
13255 ? (long) value
: 0);
13256 fontp
->relative_compose
13257 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
13258 ? (long) value
: 0);
13259 fontp
->default_ascent
13260 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
13261 ? (long) value
: 0);
13263 /* Set global flag fonts_changed_p to non-zero if the font loaded
13264 has a character with a smaller width than any other character
13265 before, or if the font loaded has a smalle>r height than any
13266 other font loaded before. If this happens, it will make a
13267 glyph matrix reallocation necessary. */
13268 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
13275 /* Return a pointer to struct font_info of a font named FONTNAME for
13276 frame F. If no such font is loaded, return NULL. */
13279 x_query_font (f
, fontname
)
13281 register char *fontname
;
13283 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13286 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
13287 if (dpyinfo
->font_table
[i
].name
13288 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
13289 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
13290 return (dpyinfo
->font_table
+ i
);
13295 /* Find a CCL program for a font specified by FONTP, and set the member
13296 `encoder' of the structure. */
13299 x_find_ccl_program (fontp
)
13300 struct font_info
*fontp
;
13302 Lisp_Object list
, elt
;
13305 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
13309 && STRINGP (XCAR (elt
))
13310 && ((fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
13312 || (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->full_name
)
13319 struct ccl_program
*ccl
13320 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
13322 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
13325 fontp
->font_encoder
= ccl
;
13331 /***********************************************************************
13333 ***********************************************************************/
13335 #ifdef USE_X_TOOLKIT
13336 static XrmOptionDescRec emacs_options
[] = {
13337 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
13338 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
13340 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
13341 XrmoptionSepArg
, NULL
},
13342 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
13344 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13345 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13346 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13347 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
13348 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
13349 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
13350 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
13352 #endif /* USE_X_TOOLKIT */
13354 static int x_initialized
;
13356 #ifdef MULTI_KBOARD
13357 /* Test whether two display-name strings agree up to the dot that separates
13358 the screen number from the server number. */
13360 same_x_server (name1
, name2
)
13361 char *name1
, *name2
;
13363 int seen_colon
= 0;
13364 unsigned char *system_name
= XSTRING (Vsystem_name
)->data
;
13365 int system_name_length
= strlen (system_name
);
13366 int length_until_period
= 0;
13368 while (system_name
[length_until_period
] != 0
13369 && system_name
[length_until_period
] != '.')
13370 length_until_period
++;
13372 /* Treat `unix' like an empty host name. */
13373 if (! strncmp (name1
, "unix:", 5))
13375 if (! strncmp (name2
, "unix:", 5))
13377 /* Treat this host's name like an empty host name. */
13378 if (! strncmp (name1
, system_name
, system_name_length
)
13379 && name1
[system_name_length
] == ':')
13380 name1
+= system_name_length
;
13381 if (! strncmp (name2
, system_name
, system_name_length
)
13382 && name2
[system_name_length
] == ':')
13383 name2
+= system_name_length
;
13384 /* Treat this host's domainless name like an empty host name. */
13385 if (! strncmp (name1
, system_name
, length_until_period
)
13386 && name1
[length_until_period
] == ':')
13387 name1
+= length_until_period
;
13388 if (! strncmp (name2
, system_name
, length_until_period
)
13389 && name2
[length_until_period
] == ':')
13390 name2
+= length_until_period
;
13392 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
13396 if (seen_colon
&& *name1
== '.')
13400 && (*name1
== '.' || *name1
== '\0')
13401 && (*name2
== '.' || *name2
== '\0'));
13405 struct x_display_info
*
13406 x_term_init (display_name
, xrm_option
, resource_name
)
13407 Lisp_Object display_name
;
13409 char *resource_name
;
13413 struct x_display_info
*dpyinfo
;
13418 if (!x_initialized
)
13424 #ifdef USE_X_TOOLKIT
13425 /* weiner@footloose.sps.mot.com reports that this causes
13427 X protocol error: BadAtom (invalid Atom parameter)
13428 on protocol request 18skiloaf.
13429 So let's not use it until R6. */
13430 #ifdef HAVE_X11XTR6
13431 XtSetLanguageProc (NULL
, NULL
, NULL
);
13442 argv
[argc
++] = "-xrm";
13443 argv
[argc
++] = xrm_option
;
13445 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
13446 resource_name
, EMACS_CLASS
,
13447 emacs_options
, XtNumber (emacs_options
),
13450 #ifdef HAVE_X11XTR6
13451 /* I think this is to compensate for XtSetLanguageProc. */
13456 #else /* not USE_X_TOOLKIT */
13458 XSetLocaleModifiers ("");
13460 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
13461 #endif /* not USE_X_TOOLKIT */
13463 /* Detect failure. */
13470 /* We have definitely succeeded. Record the new connection. */
13472 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
13473 bzero (dpyinfo
, sizeof *dpyinfo
);
13475 #ifdef MULTI_KBOARD
13477 struct x_display_info
*share
;
13480 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
13481 share
= share
->next
, tail
= XCDR (tail
))
13482 if (same_x_server (XSTRING (XCAR (XCAR (tail
)))->data
,
13483 XSTRING (display_name
)->data
))
13486 dpyinfo
->kboard
= share
->kboard
;
13489 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
13490 init_kboard (dpyinfo
->kboard
);
13491 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
13493 char *vendor
= ServerVendor (dpy
);
13495 dpyinfo
->kboard
->Vsystem_key_alist
13496 = call1 (Qvendor_specific_keysyms
,
13497 build_string (vendor
? vendor
: ""));
13501 dpyinfo
->kboard
->next_kboard
= all_kboards
;
13502 all_kboards
= dpyinfo
->kboard
;
13503 /* Don't let the initial kboard remain current longer than necessary.
13504 That would cause problems if a file loaded on startup tries to
13505 prompt in the mini-buffer. */
13506 if (current_kboard
== initial_kboard
)
13507 current_kboard
= dpyinfo
->kboard
;
13509 dpyinfo
->kboard
->reference_count
++;
13513 /* Put this display on the chain. */
13514 dpyinfo
->next
= x_display_list
;
13515 x_display_list
= dpyinfo
;
13517 /* Put it on x_display_name_list as well, to keep them parallel. */
13518 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
13519 x_display_name_list
);
13520 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
13522 dpyinfo
->display
= dpy
;
13525 XSetAfterFunction (x_current_display
, x_trace_wire
);
13529 = (char *) xmalloc (STRING_BYTES (XSTRING (Vinvocation_name
))
13530 + STRING_BYTES (XSTRING (Vsystem_name
))
13532 sprintf (dpyinfo
->x_id_name
, "%s@%s",
13533 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
13535 /* Figure out which modifier bits mean what. */
13536 x_find_modifier_meanings (dpyinfo
);
13538 /* Get the scroll bar cursor. */
13539 dpyinfo
->vertical_scroll_bar_cursor
13540 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
13542 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
13543 resource_name
, EMACS_CLASS
);
13544 #ifdef HAVE_XRMSETDATABASE
13545 XrmSetDatabase (dpyinfo
->display
, xrdb
);
13547 dpyinfo
->display
->db
= xrdb
;
13549 /* Put the rdb where we can find it in a way that works on
13551 dpyinfo
->xrdb
= xrdb
;
13553 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
13554 DefaultScreen (dpyinfo
->display
));
13555 select_visual (dpyinfo
);
13556 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
13557 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
13558 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
13559 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
13560 dpyinfo
->grabbed
= 0;
13561 dpyinfo
->reference_count
= 0;
13562 dpyinfo
->icon_bitmap_id
= -1;
13563 dpyinfo
->font_table
= NULL
;
13564 dpyinfo
->n_fonts
= 0;
13565 dpyinfo
->font_table_size
= 0;
13566 dpyinfo
->bitmaps
= 0;
13567 dpyinfo
->bitmaps_size
= 0;
13568 dpyinfo
->bitmaps_last
= 0;
13569 dpyinfo
->scratch_cursor_gc
= 0;
13570 dpyinfo
->mouse_face_mouse_frame
= 0;
13571 dpyinfo
->mouse_face_deferred_gc
= 0;
13572 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
13573 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
13574 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
13575 dpyinfo
->mouse_face_window
= Qnil
;
13576 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
13577 dpyinfo
->mouse_face_defer
= 0;
13578 dpyinfo
->x_focus_frame
= 0;
13579 dpyinfo
->x_focus_event_frame
= 0;
13580 dpyinfo
->x_highlight_frame
= 0;
13581 dpyinfo
->image_cache
= make_image_cache ();
13583 /* See if a private colormap is requested. */
13584 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
13586 if (dpyinfo
->visual
->class == PseudoColor
)
13589 value
= display_x_get_resource (dpyinfo
,
13590 build_string ("privateColormap"),
13591 build_string ("PrivateColormap"),
13593 if (STRINGP (value
)
13594 && (!strcmp (XSTRING (value
)->data
, "true")
13595 || !strcmp (XSTRING (value
)->data
, "on")))
13596 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
13600 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
13601 dpyinfo
->visual
, AllocNone
);
13604 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
13605 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
13606 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
13607 dpyinfo
->resy
= pixels
* 25.4 / mm
;
13608 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
13609 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
13610 dpyinfo
->resx
= pixels
* 25.4 / mm
;
13613 dpyinfo
->Xatom_wm_protocols
13614 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
13615 dpyinfo
->Xatom_wm_take_focus
13616 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
13617 dpyinfo
->Xatom_wm_save_yourself
13618 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
13619 dpyinfo
->Xatom_wm_delete_window
13620 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
13621 dpyinfo
->Xatom_wm_change_state
13622 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
13623 dpyinfo
->Xatom_wm_configure_denied
13624 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
13625 dpyinfo
->Xatom_wm_window_moved
13626 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
13627 dpyinfo
->Xatom_editres
13628 = XInternAtom (dpyinfo
->display
, "Editres", False
);
13629 dpyinfo
->Xatom_CLIPBOARD
13630 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
13631 dpyinfo
->Xatom_TIMESTAMP
13632 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
13633 dpyinfo
->Xatom_TEXT
13634 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
13635 dpyinfo
->Xatom_COMPOUND_TEXT
13636 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
13637 dpyinfo
->Xatom_DELETE
13638 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
13639 dpyinfo
->Xatom_MULTIPLE
13640 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
13641 dpyinfo
->Xatom_INCR
13642 = XInternAtom (dpyinfo
->display
, "INCR", False
);
13643 dpyinfo
->Xatom_EMACS_TMP
13644 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
13645 dpyinfo
->Xatom_TARGETS
13646 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
13647 dpyinfo
->Xatom_NULL
13648 = XInternAtom (dpyinfo
->display
, "NULL", False
);
13649 dpyinfo
->Xatom_ATOM_PAIR
13650 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
13651 /* For properties of font. */
13652 dpyinfo
->Xatom_PIXEL_SIZE
13653 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
13654 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
13655 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
13656 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
13657 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
13658 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
13659 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
13661 /* Ghostscript support. */
13662 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
13663 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
13665 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
13668 dpyinfo
->cut_buffers_initialized
= 0;
13670 connection
= ConnectionNumber (dpyinfo
->display
);
13671 dpyinfo
->connection
= connection
;
13676 null_bits
[0] = 0x00;
13678 dpyinfo
->null_pixel
13679 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
13680 null_bits
, 1, 1, (long) 0, (long) 0,
13685 extern int gray_bitmap_width
, gray_bitmap_height
;
13686 extern unsigned char *gray_bitmap_bits
;
13688 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
13690 gray_bitmap_width
, gray_bitmap_height
,
13691 (unsigned long) 1, (unsigned long) 0, 1);
13695 xim_initialize (dpyinfo
, resource_name
);
13698 #ifdef subprocesses
13699 /* This is only needed for distinguishing keyboard and process input. */
13700 if (connection
!= 0)
13701 add_keyboard_wait_descriptor (connection
);
13704 #ifndef F_SETOWN_BUG
13706 #ifdef F_SETOWN_SOCK_NEG
13707 /* stdin is a socket here */
13708 fcntl (connection
, F_SETOWN
, -getpid ());
13709 #else /* ! defined (F_SETOWN_SOCK_NEG) */
13710 fcntl (connection
, F_SETOWN
, getpid ());
13711 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
13712 #endif /* ! defined (F_SETOWN) */
13713 #endif /* F_SETOWN_BUG */
13716 if (interrupt_input
)
13717 init_sigio (connection
);
13718 #endif /* ! defined (SIGIO) */
13721 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
13722 /* Make sure that we have a valid font for dialog boxes
13723 so that Xt does not crash. */
13725 Display
*dpy
= dpyinfo
->display
;
13726 XrmValue d
, fr
, to
;
13730 d
.addr
= (XPointer
)&dpy
;
13731 d
.size
= sizeof (Display
*);
13732 fr
.addr
= XtDefaultFont
;
13733 fr
.size
= sizeof (XtDefaultFont
);
13734 to
.size
= sizeof (Font
*);
13735 to
.addr
= (XPointer
)&font
;
13736 count
= x_catch_errors (dpy
);
13737 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
13739 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
13740 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
13741 x_uncatch_errors (dpy
, count
);
13746 /* See if we should run in synchronous mode. This is useful
13747 for debugging X code. */
13750 value
= display_x_get_resource (dpyinfo
,
13751 build_string ("synchronous"),
13752 build_string ("Synchronous"),
13754 if (STRINGP (value
)
13755 && (!strcmp (XSTRING (value
)->data
, "true")
13756 || !strcmp (XSTRING (value
)->data
, "on")))
13757 XSynchronize (dpyinfo
->display
, True
);
13765 /* Get rid of display DPYINFO, assuming all frames are already gone,
13766 and without sending any more commands to the X server. */
13769 x_delete_display (dpyinfo
)
13770 struct x_display_info
*dpyinfo
;
13772 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
13774 /* Discard this display from x_display_name_list and x_display_list.
13775 We can't use Fdelq because that can quit. */
13776 if (! NILP (x_display_name_list
)
13777 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
13778 x_display_name_list
= XCDR (x_display_name_list
);
13783 tail
= x_display_name_list
;
13784 while (CONSP (tail
) && CONSP (XCDR (tail
)))
13786 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
13788 XCDR (tail
) = XCDR (XCDR (tail
));
13791 tail
= XCDR (tail
);
13795 if (next_noop_dpyinfo
== dpyinfo
)
13796 next_noop_dpyinfo
= dpyinfo
->next
;
13798 if (x_display_list
== dpyinfo
)
13799 x_display_list
= dpyinfo
->next
;
13802 struct x_display_info
*tail
;
13804 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
13805 if (tail
->next
== dpyinfo
)
13806 tail
->next
= tail
->next
->next
;
13809 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
13810 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
13811 XrmDestroyDatabase (dpyinfo
->xrdb
);
13814 #ifdef MULTI_KBOARD
13815 if (--dpyinfo
->kboard
->reference_count
== 0)
13816 delete_kboard (dpyinfo
->kboard
);
13820 xim_close_dpy (dpyinfo
);
13823 xfree (dpyinfo
->font_table
);
13824 xfree (dpyinfo
->x_id_name
);
13825 xfree (dpyinfo
->color_cells
);
13830 /* Set up use of X before we make the first connection. */
13832 static struct redisplay_interface x_redisplay_interface
=
13837 x_clear_end_of_line
,
13839 x_after_update_window_line
,
13840 x_update_window_begin
,
13841 x_update_window_end
,
13844 x_clear_mouse_face
,
13845 x_get_glyph_overhangs
,
13846 x_fix_overlapping_area
13852 rif
= &x_redisplay_interface
;
13854 clear_frame_hook
= x_clear_frame
;
13855 ins_del_lines_hook
= x_ins_del_lines
;
13856 change_line_highlight_hook
= x_change_line_highlight
;
13857 delete_glyphs_hook
= x_delete_glyphs
;
13858 ring_bell_hook
= XTring_bell
;
13859 reset_terminal_modes_hook
= XTreset_terminal_modes
;
13860 set_terminal_modes_hook
= XTset_terminal_modes
;
13861 update_begin_hook
= x_update_begin
;
13862 update_end_hook
= x_update_end
;
13863 set_terminal_window_hook
= XTset_terminal_window
;
13864 read_socket_hook
= XTread_socket
;
13865 frame_up_to_date_hook
= XTframe_up_to_date
;
13866 reassert_line_highlight_hook
= XTreassert_line_highlight
;
13867 mouse_position_hook
= XTmouse_position
;
13868 frame_rehighlight_hook
= XTframe_rehighlight
;
13869 frame_raise_lower_hook
= XTframe_raise_lower
;
13870 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
13871 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
13872 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
13873 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
13874 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
13876 scroll_region_ok
= 1; /* we'll scroll partial frames */
13877 char_ins_del_ok
= 0; /* just as fast to write the line */
13878 line_ins_del_ok
= 1; /* we'll just blt 'em */
13879 fast_clear_end_of_line
= 1; /* X does this well */
13880 memory_below_frame
= 0; /* we don't remember what scrolls
13885 last_tool_bar_item
= -1;
13886 any_help_event_p
= 0;
13888 /* Try to use interrupt input; if we can't, then start polling. */
13889 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
13891 #ifdef USE_X_TOOLKIT
13892 XtToolkitInitialize ();
13893 Xt_app_con
= XtCreateApplicationContext ();
13894 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
13896 /* Install an asynchronous timer that processes Xt timeout events
13897 every 0.1s. This is necessary because some widget sets use
13898 timeouts internally, for example the LessTif menu bar, or the
13899 Xaw3d scroll bar. When Xt timouts aren't processed, these
13900 widgets don't behave normally. */
13902 EMACS_TIME interval
;
13903 EMACS_SET_SECS_USECS (interval
, 0, 100000);
13904 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
13908 #if USE_TOOLKIT_SCROLL_BARS
13909 xaw3d_arrow_scroll
= False
;
13910 xaw3d_pick_top
= True
;
13913 /* Note that there is no real way portable across R3/R4 to get the
13914 original error handler. */
13915 XSetErrorHandler (x_error_handler
);
13916 XSetIOErrorHandler (x_io_error_quitter
);
13918 /* Disable Window Change signals; they are handled by X events. */
13920 signal (SIGWINCH
, SIG_DFL
);
13921 #endif /* ! defined (SIGWINCH) */
13923 signal (SIGPIPE
, x_connection_signal
);
13930 staticpro (&x_error_message_string
);
13931 x_error_message_string
= Qnil
;
13933 staticpro (&x_display_name_list
);
13934 x_display_name_list
= Qnil
;
13936 staticpro (&last_mouse_scroll_bar
);
13937 last_mouse_scroll_bar
= Qnil
;
13939 staticpro (&Qvendor_specific_keysyms
);
13940 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
13942 staticpro (&last_mouse_press_frame
);
13943 last_mouse_press_frame
= Qnil
;
13946 staticpro (&help_echo
);
13947 help_echo_object
= Qnil
;
13948 staticpro (&help_echo_object
);
13949 help_echo_window
= Qnil
;
13950 staticpro (&help_echo_window
);
13951 previous_help_echo
= Qnil
;
13952 staticpro (&previous_help_echo
);
13953 help_echo_pos
= -1;
13955 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
13956 "*Non-nil means draw block cursor as wide as the glyph under it.\n\
13957 For example, if a block cursor is over a tab, it will be drawn as\n\
13958 wide as that tab on the display.");
13959 x_stretch_cursor_p
= 0;
13961 DEFVAR_BOOL ("x-toolkit-scroll-bars-p", &x_toolkit_scroll_bars_p
,
13962 "If not nil, Emacs uses toolkit scroll bars.");
13963 #if USE_TOOLKIT_SCROLL_BARS
13964 x_toolkit_scroll_bars_p
= 1;
13966 x_toolkit_scroll_bars_p
= 0;
13969 staticpro (&last_mouse_motion_frame
);
13970 last_mouse_motion_frame
= Qnil
;
13973 #endif /* not HAVE_X_WINDOWS */