1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 93, 94, 95, 96, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New display code by Gerd Moellmann <gerd@gnu.org>. */
23 /* Xt features made by Fred Pierresteguy. */
27 /* On 4.3 these lose if they come after xterm.h. */
28 /* Putting these at the beginning seems to be standard for other .c files. */
36 #include "blockinput.h"
38 /* Need syssignal.h for various externs and definitions that may be required
39 by some configurations for calls to signal later in this source file. */
40 #include "syssignal.h"
42 /* This may include sys/types.h, and that somehow loses
43 if this is not done before the other system files. */
45 #include <X11/cursorfont.h>
47 /* Load sys/types.h if not already loaded.
48 In some systems loading it twice is suicidal. */
50 #include <sys/types.h>
54 #include <sys/ioctl.h>
55 #endif /* ! defined (BSD_SYSTEM) */
60 #ifndef INCLUDED_FCNTL
67 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
68 /* #include <sys/param.h> */
74 #include "dispextern.h"
76 #include "termhooks.h"
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 #else /* !USE_MOTIF i.e. use Xaw */
123 #include <X11/Xaw3d/Simple.h>
124 #include <X11/Xaw3d/Scrollbar.h>
125 #define ARROW_SCROLLBAR
126 #include <X11/Xaw3d/ScrollbarP.h>
127 #else /* !HAVE_XAW3D */
128 #include <X11/Xaw/Simple.h>
129 #include <X11/Xaw/Scrollbar.h>
130 #endif /* !HAVE_XAW3D */
132 #define XtNpickTop "pickTop"
133 #endif /* !XtNpickTop */
134 #endif /* !USE_MOTIF */
135 #endif /* USE_TOOLKIT_SCROLL_BARS */
137 #endif /* USE_X_TOOLKIT */
139 #ifndef USE_X_TOOLKIT
140 #define x_any_window_to_frame x_window_to_frame
141 #define x_top_window_to_frame x_window_to_frame
146 #ifndef XtNinitialState
147 #define XtNinitialState "initialState"
152 #define min(a,b) ((a) < (b) ? (a) : (b))
155 #define max(a,b) ((a) > (b) ? (a) : (b))
158 #define abs(x) ((x) < 0 ? -(x) : (x))
160 #define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER))
163 /* Bitmaps for truncated lines. */
168 LEFT_TRUNCATION_BITMAP
,
169 RIGHT_TRUNCATION_BITMAP
,
170 OVERLAY_ARROW_BITMAP
,
171 CONTINUED_LINE_BITMAP
,
172 CONTINUATION_LINE_BITMAP
,
176 /* Bitmap drawn to indicate lines not displaying text if
177 `indicate-empty-lines' is non-nil. */
181 static unsigned char zv_bits
[] = {
182 0x00, 0x00, 0x1e, 0x1e, 0x1e, 0x1e, 0x00, 0x00};
184 /* An arrow like this: `<-'. */
187 #define left_height 8
188 static unsigned char left_bits
[] = {
189 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
191 /* Right truncation arrow bitmap `->'. */
193 #define right_width 8
194 #define right_height 8
195 static unsigned char right_bits
[] = {
196 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
198 /* Marker for continued lines. */
200 #define continued_width 8
201 #define continued_height 8
202 static unsigned char continued_bits
[] = {
203 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
205 /* Marker for continuation lines. */
207 #define continuation_width 8
208 #define continuation_height 8
209 static unsigned char continuation_bits
[] = {
210 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
212 /* Overlay arrow bitmap. */
218 static unsigned char ov_bits
[] = {
219 0x30, 0x08, 0x3c, 0x7e, 0x7a, 0x7a, 0x62, 0x3c};
221 /* A triangular arrow. */
224 static unsigned char ov_bits
[] = {
225 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
229 extern Lisp_Object Qhelp_echo
;
232 /* Non-nil means Emacs uses toolkit scroll bars. */
234 Lisp_Object Vx_toolkit_scroll_bars
;
236 /* If a string, XTread_socket generates an event to display that string.
237 (The display is done in read_char.) */
239 static Lisp_Object help_echo
;
240 static Lisp_Object help_echo_window
;
241 static Lisp_Object help_echo_object
;
242 static int help_echo_pos
;
244 /* Temporary variable for XTread_socket. */
246 static Lisp_Object previous_help_echo
;
248 /* Non-zero means that a HELP_EVENT has been generated since Emacs
251 static int any_help_event_p
;
253 /* Non-zero means draw block and hollow cursor as wide as the glyph
254 under it. For example, if a block cursor is over a tab, it will be
255 drawn as wide as that tab on the display. */
257 int x_stretch_cursor_p
;
259 /* This is a chain of structures for all the X displays currently in
262 struct x_display_info
*x_display_list
;
264 /* This is a list of cons cells, each of the form (NAME
265 . FONT-LIST-CACHE), one for each element of x_display_list and in
266 the same order. NAME is the name of the frame. FONT-LIST-CACHE
267 records previous values returned by x-list-fonts. */
269 Lisp_Object x_display_name_list
;
271 /* Frame being updated by update_frame. This is declared in term.c.
272 This is set by update_begin and looked at by all the XT functions.
273 It is zero while not inside an update. In that case, the XT
274 functions assume that `selected_frame' is the frame to apply to. */
276 extern struct frame
*updating_frame
;
278 extern int waiting_for_input
;
280 /* This is a frame waiting to be auto-raised, within XTread_socket. */
282 struct frame
*pending_autoraise_frame
;
285 /* The application context for Xt use. */
286 XtAppContext Xt_app_con
;
287 static String Xt_default_resources
[] = {0};
288 #endif /* USE_X_TOOLKIT */
290 /* Nominal cursor position -- where to draw output.
291 HPOS and VPOS are window relative glyph matrix coordinates.
292 X and Y are window relative pixel coordinates. */
294 struct cursor_pos output_cursor
;
296 /* Non-zero means user is interacting with a toolkit scroll bar. */
298 static int toolkit_scroll_bar_interaction
;
302 Formerly, we used PointerMotionHintMask (in standard_event_mask)
303 so that we would have to call XQueryPointer after each MotionNotify
304 event to ask for another such event. However, this made mouse tracking
305 slow, and there was a bug that made it eventually stop.
307 Simply asking for MotionNotify all the time seems to work better.
309 In order to avoid asking for motion events and then throwing most
310 of them away or busy-polling the server for mouse positions, we ask
311 the server for pointer motion hints. This means that we get only
312 one event per group of mouse movements. "Groups" are delimited by
313 other kinds of events (focus changes and button clicks, for
314 example), or by XQueryPointer calls; when one of these happens, we
315 get another MotionNotify event the next time the mouse moves. This
316 is at least as efficient as getting motion events when mouse
317 tracking is on, and I suspect only negligibly worse when tracking
320 /* Where the mouse was last time we reported a mouse event. */
322 FRAME_PTR last_mouse_frame
;
323 static XRectangle last_mouse_glyph
;
324 static Lisp_Object last_mouse_press_frame
;
326 /* The scroll bar in which the last X motion event occurred.
328 If the last X motion event occurred in a scroll bar, we set this so
329 XTmouse_position can know whether to report a scroll bar motion or
332 If the last X motion event didn't occur in a scroll bar, we set
333 this to Qnil, to tell XTmouse_position to return an ordinary motion
336 static Lisp_Object last_mouse_scroll_bar
;
338 /* This is a hack. We would really prefer that XTmouse_position would
339 return the time associated with the position it returns, but there
340 doesn't seem to be any way to wrest the time-stamp from the server
341 along with the position query. So, we just keep track of the time
342 of the last movement we received, and return that in hopes that
343 it's somewhat accurate. */
345 static Time last_mouse_movement_time
;
347 /* Incremented by XTread_socket whenever it really tries to read
351 static int volatile input_signal_count
;
353 static int input_signal_count
;
356 /* Used locally within XTread_socket. */
358 static int x_noop_count
;
360 /* Initial values of argv and argc. */
362 extern char **initial_argv
;
363 extern int initial_argc
;
365 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
367 /* Tells if a window manager is present or not. */
369 extern Lisp_Object Vx_no_window_manager
;
371 extern Lisp_Object Qface
, Qmouse_face
;
375 /* A mask of extra modifier bits to put into every keyboard char. */
377 extern int extra_keyboard_modifiers
;
379 static Lisp_Object Qvendor_specific_keysyms
;
381 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
382 extern Lisp_Object x_icon_type
P_ ((struct frame
*));
385 /* Enumeration for overriding/changing the face to use for drawing
386 glyphs in x_draw_glyphs. */
388 enum draw_glyphs_face
398 static void x_set_window_size_1
P_ ((struct frame
*, int, int, int));
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 int fast_find_string_pos
P_ ((struct window
*, int, Lisp_Object
,
408 int *, int *, int *, int *, int));
409 static void set_output_cursor
P_ ((struct cursor_pos
*));
410 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
411 int *, int *, int *, int));
412 static void note_mode_line_highlight
P_ ((struct window
*, int, int));
413 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
414 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
415 static void x_handle_tool_bar_click
P_ ((struct frame
*, XButtonEvent
*));
416 static void show_mouse_face
P_ ((struct x_display_info
*,
417 enum draw_glyphs_face
));
418 static int x_io_error_quitter
P_ ((Display
*));
419 int x_catch_errors
P_ ((Display
*));
420 void x_uncatch_errors
P_ ((Display
*, int));
421 void x_lower_frame
P_ ((struct frame
*));
422 void x_scroll_bar_clear
P_ ((struct frame
*));
423 int x_had_errors_p
P_ ((Display
*));
424 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
425 void x_raise_frame
P_ ((struct frame
*));
426 void x_set_window_size
P_ ((struct frame
*, int, int, int));
427 void x_wm_set_window_state
P_ ((struct frame
*, int));
428 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
429 void x_initialize
P_ ((void));
430 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
431 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
432 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
434 enum draw_glyphs_face
));
435 static void x_update_end
P_ ((struct frame
*));
436 static void XTframe_up_to_date
P_ ((struct frame
*));
437 static void XTreassert_line_highlight
P_ ((int, int));
438 static void x_change_line_highlight
P_ ((int, int, int, int));
439 static void XTset_terminal_modes
P_ ((void));
440 static void XTreset_terminal_modes
P_ ((void));
441 static void XTcursor_to
P_ ((int, int, int, int));
442 static void x_write_glyphs
P_ ((struct glyph
*, int));
443 static void x_clear_end_of_line
P_ ((int));
444 static void x_clear_frame
P_ ((void));
445 static void x_clear_cursor
P_ ((struct window
*));
446 static void frame_highlight
P_ ((struct frame
*));
447 static void frame_unhighlight
P_ ((struct frame
*));
448 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
449 static void XTframe_rehighlight
P_ ((struct frame
*));
450 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
451 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
452 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int));
453 static int x_intersect_rectangles
P_ ((XRectangle
*, XRectangle
*,
455 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
456 static void expose_window_tree
P_ ((struct window
*, XRectangle
*));
457 static void expose_window
P_ ((struct window
*, XRectangle
*));
458 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
459 XRectangle
*, enum glyph_row_area
));
460 static void expose_line
P_ ((struct window
*, struct glyph_row
*,
462 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
463 static void x_update_window_cursor
P_ ((struct window
*, int));
464 static void x_erase_phys_cursor
P_ ((struct window
*));
465 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
466 static void x_draw_bitmap
P_ ((struct window
*, struct glyph_row
*,
469 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
471 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, XRectangle
*));
472 static void x_draw_row_bitmaps
P_ ((struct window
*, struct glyph_row
*));
473 static void note_overwritten_text_cursor
P_ ((struct window
*, int, int));
474 static void x_flush
P_ ((struct frame
*f
));
475 static void x_update_begin
P_ ((struct frame
*));
476 static void x_update_window_begin
P_ ((struct window
*));
477 static void x_draw_vertical_border
P_ ((struct window
*));
478 static void x_after_update_window_line
P_ ((struct glyph_row
*));
479 static INLINE
void take_vertical_position_into_account
P_ ((struct it
*));
480 static void x_produce_stretch_glyph
P_ ((struct it
*));
481 static struct scroll_bar
*x_window_to_scroll_bar
P_ ((Window
));
482 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
483 enum scroll_bar_part
*,
484 Lisp_Object
*, Lisp_Object
*,
487 /* Flush display of frame F, or of all frames if F is null. */
496 Lisp_Object rest
, frame
;
497 FOR_EACH_FRAME (rest
, frame
)
498 x_flush (XFRAME (frame
));
500 else if (FRAME_X_P (f
))
501 XFlush (FRAME_X_DISPLAY (f
));
506 /* Remove calls to XFlush by defining XFlush to an empty replacement.
507 Calls to XFlush should be unnecessary because the X output buffer
508 is flushed automatically as needed by calls to XPending,
509 XNextEvent, or XWindowEvent according to the XFlush man page.
510 XTread_socket calls XPending. Removing XFlush improves
513 #define XFlush(DISPLAY) (void) 0
516 /***********************************************************************
518 ***********************************************************************/
522 /* This is a function useful for recording debugging information about
523 the sequence of occurrences in this file. */
531 struct record event_record
[100];
533 int event_record_index
;
535 record_event (locus
, type
)
539 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
540 event_record_index
= 0;
542 event_record
[event_record_index
].locus
= locus
;
543 event_record
[event_record_index
].type
= type
;
544 event_record_index
++;
551 /* Return the struct x_display_info corresponding to DPY. */
553 struct x_display_info
*
554 x_display_info_for_display (dpy
)
557 struct x_display_info
*dpyinfo
;
559 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
560 if (dpyinfo
->display
== dpy
)
568 /***********************************************************************
569 Starting and ending an update
570 ***********************************************************************/
572 /* Start an update of frame F. This function is installed as a hook
573 for update_begin, i.e. it is called when update_begin is called.
574 This function is called prior to calls to x_update_window_begin for
575 each window being updated. Currently, there is nothing to do here
576 because all interesting stuff is done on a window basis. */
586 /* Start update of window W. Set the global variable updated_window
587 to the window being updated and set output_cursor to the cursor
591 x_update_window_begin (w
)
594 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
595 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
598 set_output_cursor (&w
->cursor
);
602 if (f
== display_info
->mouse_face_mouse_frame
)
604 /* Don't do highlighting for mouse motion during the update. */
605 display_info
->mouse_face_defer
= 1;
607 /* If F needs to be redrawn, simply forget about any prior mouse
609 if (FRAME_GARBAGED_P (f
))
610 display_info
->mouse_face_window
= Qnil
;
612 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
613 their mouse_face_p flag set, which means that they are always
614 unequal to rows in a desired matrix which never have that
615 flag set. So, rows containing mouse-face glyphs are never
616 scrolled, and we don't have to switch the mouse highlight off
617 here to prevent it from being scrolled. */
619 /* Can we tell that this update does not affect the window
620 where the mouse highlight is? If so, no need to turn off.
621 Likewise, don't do anything if the frame is garbaged;
622 in that case, the frame's current matrix that we would use
623 is all wrong, and we will redisplay that line anyway. */
624 if (!NILP (display_info
->mouse_face_window
)
625 && w
== XWINDOW (display_info
->mouse_face_window
))
629 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
630 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
633 if (i
< w
->desired_matrix
->nrows
)
634 clear_mouse_face (display_info
);
643 /* Draw a vertical window border to the right of window W if W doesn't
644 have vertical scroll bars. */
647 x_draw_vertical_border (w
)
650 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
652 /* Redraw borders between horizontally adjacent windows. Don't
653 do it for frames with vertical scroll bars because either the
654 right scroll bar of a window, or the left scroll bar of its
655 neighbor will suffice as a border. */
656 if (!WINDOW_RIGHTMOST_P (w
)
657 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
661 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
662 x1
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
);
665 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
666 f
->output_data
.x
->normal_gc
, x1
, y0
, x1
, y1
);
671 /* End update of window W (which is equal to updated_window).
673 Draw vertical borders between horizontally adjacent windows, and
674 display W's cursor if CURSOR_ON_P is non-zero.
676 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
677 glyphs in mouse-face were overwritten. In that case we have to
678 make sure that the mouse-highlight is properly redrawn.
680 W may be a menu bar pseudo-window in case we don't have X toolkit
681 support. Such windows don't have a cursor, so don't display it
685 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
687 int cursor_on_p
, mouse_face_overwritten_p
;
689 if (!w
->pseudo_window_p
)
691 struct x_display_info
*dpyinfo
692 = FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
696 /* If a row with mouse-face was overwritten, arrange for
697 XTframe_up_to_date to redisplay the mouse highlight. */
698 if (mouse_face_overwritten_p
)
700 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
701 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
702 dpyinfo
->mouse_face_window
= Qnil
;
706 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
708 output_cursor
.x
, output_cursor
.y
);
710 x_draw_vertical_border (w
);
714 updated_window
= NULL
;
718 /* End update of frame F. This function is installed as a hook in
725 /* Mouse highlight may be displayed again. */
726 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
729 XFlush (FRAME_X_DISPLAY (f
));
734 /* This function is called from various places in xdisp.c whenever a
735 complete update has been performed. The global variable
736 updated_window is not available here. */
739 XTframe_up_to_date (f
)
744 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
746 if (dpyinfo
->mouse_face_deferred_gc
747 || f
== dpyinfo
->mouse_face_mouse_frame
)
750 if (dpyinfo
->mouse_face_mouse_frame
)
751 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
752 dpyinfo
->mouse_face_mouse_x
,
753 dpyinfo
->mouse_face_mouse_y
);
754 dpyinfo
->mouse_face_deferred_gc
= 0;
761 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
762 arrow bitmaps, or clear the areas where they would be displayed
763 before DESIRED_ROW is made current. The window being updated is
764 found in updated_window. This function It is called from
765 update_window_line only if it is known that there are differences
766 between bitmaps to be drawn between current row and DESIRED_ROW. */
769 x_after_update_window_line (desired_row
)
770 struct glyph_row
*desired_row
;
772 struct window
*w
= updated_window
;
776 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
782 x_draw_row_bitmaps (w
, desired_row
);
784 /* When a window has disappeared, make sure that no rest of
785 full-width rows stays visible in the internal border. */
786 if (windows_or_buffers_changed
787 && (f
= XFRAME (w
->frame
),
788 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
791 int height
= desired_row
->visible_height
;
792 int x
= (window_box_right (w
, -1)
793 + FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
));
794 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
796 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
797 x
, y
, width
, height
, False
);
805 /* Draw the bitmap WHICH in one of the areas to the left or right of
806 window W. ROW is the glyph row for which to display the bitmap; it
807 determines the vertical position at which the bitmap has to be
811 x_draw_bitmap (w
, row
, which
)
813 struct glyph_row
*row
;
814 enum bitmap_type which
;
816 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
817 Display
*display
= FRAME_X_DISPLAY (f
);
818 Window window
= FRAME_X_WINDOW (f
);
822 GC gc
= f
->output_data
.x
->normal_gc
;
824 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
826 /* Must clip because of partially visible lines. */
827 x_clip_to_row (w
, row
, gc
, 1);
831 case LEFT_TRUNCATION_BITMAP
:
835 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
837 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
840 case OVERLAY_ARROW_BITMAP
:
844 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
846 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
849 case RIGHT_TRUNCATION_BITMAP
:
853 x
= window_box_right (w
, -1);
854 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
857 case CONTINUED_LINE_BITMAP
:
860 bits
= continued_bits
;
861 x
= window_box_right (w
, -1);
862 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
865 case CONTINUATION_LINE_BITMAP
:
866 wd
= continuation_width
;
867 h
= continuation_height
;
868 bits
= continuation_bits
;
869 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
871 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
878 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
880 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
887 /* Convert to frame coordinates. Set dy to the offset in the row to
888 start drawing the bitmap. */
889 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
890 dy
= (row
->height
- h
) / 2;
892 /* Draw the bitmap. I believe these small pixmaps can be cached
894 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
895 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, wd
, h
,
897 face
->background
, depth
);
898 XCopyArea (display
, pixmap
, window
, gc
, 0, 0, wd
, h
, x
, y
+ dy
);
899 XFreePixmap (display
, pixmap
);
900 XSetClipMask (display
, gc
, None
);
904 /* Draw flags bitmaps for glyph row ROW on window W. Call this
905 function with input blocked. */
908 x_draw_row_bitmaps (w
, row
)
910 struct glyph_row
*row
;
912 struct frame
*f
= XFRAME (w
->frame
);
913 enum bitmap_type bitmap
;
915 int header_line_height
= -1;
917 xassert (interrupt_input_blocked
);
919 /* If row is completely invisible, because of vscrolling, we
920 don't have to draw anything. */
921 if (row
->visible_height
<= 0)
924 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
925 PREPARE_FACE_FOR_DISPLAY (f
, face
);
927 /* Decide which bitmap to draw at the left side. */
928 if (row
->overlay_arrow_p
)
929 bitmap
= OVERLAY_ARROW_BITMAP
;
930 else if (row
->truncated_on_left_p
)
931 bitmap
= LEFT_TRUNCATION_BITMAP
;
932 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
933 bitmap
= CONTINUATION_LINE_BITMAP
;
934 else if (row
->indicate_empty_line_p
)
935 bitmap
= ZV_LINE_BITMAP
;
939 /* Clear flags area if no bitmap to draw or if bitmap doesn't fill
941 if (bitmap
== NO_BITMAP
942 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
943 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
945 /* If W has a vertical border to its left, don't draw over it. */
946 int border
= ((XFASTINT (w
->left
) > 0
947 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
949 int left
= window_box_left (w
, -1);
951 if (header_line_height
< 0)
952 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
954 /* In case the same realized face is used for bitmap areas and
955 for something displayed in the text (e.g. face `region' on
956 mono-displays, the fill style may have been changed to
957 FillSolid in x_draw_glyph_string_background. */
959 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
961 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
963 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
966 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
968 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
970 FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - border
,
971 row
->visible_height
);
973 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
976 /* Draw the left bitmap. */
977 if (bitmap
!= NO_BITMAP
)
978 x_draw_bitmap (w
, row
, bitmap
);
980 /* Decide which bitmap to draw at the right side. */
981 if (row
->truncated_on_right_p
)
982 bitmap
= RIGHT_TRUNCATION_BITMAP
;
983 else if (row
->continued_p
)
984 bitmap
= CONTINUED_LINE_BITMAP
;
988 /* Clear flags area if no bitmap to draw of if bitmap doesn't fill
990 if (bitmap
== NO_BITMAP
991 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
)
992 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
994 int right
= window_box_right (w
, -1);
996 if (header_line_height
< 0)
997 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
999 /* In case the same realized face is used for bitmap areas and
1000 for something displayed in the text (e.g. face `region' on
1001 mono-displays, the fill style may have been changed to
1002 FillSolid in x_draw_glyph_string_background. */
1004 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
1006 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
1007 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1010 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
1012 FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
),
1013 row
->visible_height
);
1015 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
1018 /* Draw the right bitmap. */
1019 if (bitmap
!= NO_BITMAP
)
1020 x_draw_bitmap (w
, row
, bitmap
);
1024 /***********************************************************************
1026 ***********************************************************************/
1028 /* External interface to control of standout mode. Not used for X
1029 frames. Aborts when called. */
1032 XTreassert_line_highlight (new, vpos
)
1039 /* Call this when about to modify line at position VPOS and change
1040 whether it is highlighted. Not used for X frames. Aborts when
1044 x_change_line_highlight (new_highlight
, vpos
, y
, first_unused_hpos
)
1045 int new_highlight
, vpos
, y
, first_unused_hpos
;
1051 /* This is called when starting Emacs and when restarting after
1052 suspend. When starting Emacs, no X window is mapped. And nothing
1053 must be done to Emacs's own window if it is suspended (though that
1057 XTset_terminal_modes ()
1061 /* This is called when exiting or suspending Emacs. Exiting will make
1062 the X-windows go away, and suspending requires no action. */
1065 XTreset_terminal_modes ()
1071 /***********************************************************************
1073 ***********************************************************************/
1075 /* Set the global variable output_cursor to CURSOR. All cursor
1076 positions are relative to updated_window. */
1079 set_output_cursor (cursor
)
1080 struct cursor_pos
*cursor
;
1082 output_cursor
.hpos
= cursor
->hpos
;
1083 output_cursor
.vpos
= cursor
->vpos
;
1084 output_cursor
.x
= cursor
->x
;
1085 output_cursor
.y
= cursor
->y
;
1089 /* Set a nominal cursor position.
1091 HPOS and VPOS are column/row positions in a window glyph matrix. X
1092 and Y are window text area relative pixel positions.
1094 If this is done during an update, updated_window will contain the
1095 window that is being updated and the position is the future output
1096 cursor position for that window. If updated_window is null, use
1097 selected_window and display the cursor at the given position. */
1100 XTcursor_to (vpos
, hpos
, y
, x
)
1101 int vpos
, hpos
, y
, x
;
1105 /* If updated_window is not set, work on selected_window. */
1109 w
= XWINDOW (selected_window
);
1111 /* Set the output cursor. */
1112 output_cursor
.hpos
= hpos
;
1113 output_cursor
.vpos
= vpos
;
1114 output_cursor
.x
= x
;
1115 output_cursor
.y
= y
;
1117 /* If not called as part of an update, really display the cursor.
1118 This will also set the cursor position of W. */
1119 if (updated_window
== NULL
)
1122 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
1123 XFlush (FRAME_X_DISPLAY (SELECTED_FRAME ()));
1130 /***********************************************************************
1132 ***********************************************************************/
1134 /* Function prototypes of this page. */
1136 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
1140 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
1141 int, XChar2b
*, int));
1142 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
1143 static void x_encode_char
P_ ((int, XChar2b
*, struct font_info
*));
1144 static void x_append_glyph
P_ ((struct it
*));
1145 static void x_append_composite_glyph
P_ ((struct it
*));
1146 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
1148 static void x_produce_glyphs
P_ ((struct it
*));
1149 static void x_produce_image_glyph
P_ ((struct it
*it
));
1152 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
1153 is not contained in the font. */
1155 static INLINE XCharStruct
*
1156 x_per_char_metric (font
, char2b
)
1160 /* The result metric information. */
1161 XCharStruct
*pcm
= NULL
;
1163 xassert (font
&& char2b
);
1165 if (font
->per_char
!= NULL
)
1167 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
1169 /* min_char_or_byte2 specifies the linear character index
1170 corresponding to the first element of the per_char array,
1171 max_char_or_byte2 is the index of the last character. A
1172 character with non-zero CHAR2B->byte1 is not in the font.
1173 A character with byte2 less than min_char_or_byte2 or
1174 greater max_char_or_byte2 is not in the font. */
1175 if (char2b
->byte1
== 0
1176 && char2b
->byte2
>= font
->min_char_or_byte2
1177 && char2b
->byte2
<= font
->max_char_or_byte2
)
1178 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
1182 /* If either min_byte1 or max_byte1 are nonzero, both
1183 min_char_or_byte2 and max_char_or_byte2 are less than
1184 256, and the 2-byte character index values corresponding
1185 to the per_char array element N (counting from 0) are:
1187 byte1 = N/D + min_byte1
1188 byte2 = N\D + min_char_or_byte2
1192 D = max_char_or_byte2 - min_char_or_byte2 + 1
1193 / = integer division
1194 \ = integer modulus */
1195 if (char2b
->byte1
>= font
->min_byte1
1196 && char2b
->byte1
<= font
->max_byte1
1197 && char2b
->byte2
>= font
->min_char_or_byte2
1198 && char2b
->byte2
<= font
->max_char_or_byte2
)
1200 pcm
= (font
->per_char
1201 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
1202 * (char2b
->byte1
- font
->min_byte1
))
1203 + (char2b
->byte2
- font
->min_char_or_byte2
));
1209 /* If the per_char pointer is null, all glyphs between the first
1210 and last character indexes inclusive have the same
1211 information, as given by both min_bounds and max_bounds. */
1212 if (char2b
->byte2
>= font
->min_char_or_byte2
1213 && char2b
->byte2
<= font
->max_char_or_byte2
)
1214 pcm
= &font
->max_bounds
;
1217 return ((pcm
== NULL
1218 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
1223 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1224 the two-byte form of C. Encoding is returned in *CHAR2B. */
1227 x_encode_char (c
, char2b
, font_info
)
1230 struct font_info
*font_info
;
1232 int charset
= CHAR_CHARSET (c
);
1233 XFontStruct
*font
= font_info
->font
;
1235 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1236 This may be either a program in a special encoder language or a
1238 if (font_info
->font_encoder
)
1240 /* It's a program. */
1241 struct ccl_program
*ccl
= font_info
->font_encoder
;
1243 if (CHARSET_DIMENSION (charset
) == 1)
1245 ccl
->reg
[0] = charset
;
1246 ccl
->reg
[1] = char2b
->byte2
;
1250 ccl
->reg
[0] = charset
;
1251 ccl
->reg
[1] = char2b
->byte1
;
1252 ccl
->reg
[2] = char2b
->byte2
;
1255 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1257 /* We assume that MSBs are appropriately set/reset by CCL
1259 if (font
->max_byte1
== 0) /* 1-byte font */
1260 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
1262 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
1264 else if (font_info
->encoding
[charset
])
1266 /* Fixed encoding scheme. See fontset.h for the meaning of the
1267 encoding numbers. */
1268 int enc
= font_info
->encoding
[charset
];
1270 if ((enc
== 1 || enc
== 2)
1271 && CHARSET_DIMENSION (charset
) == 2)
1272 char2b
->byte1
|= 0x80;
1274 if (enc
== 1 || enc
== 3)
1275 char2b
->byte2
|= 0x80;
1280 /* Get face and two-byte form of character C in face FACE_ID on frame
1281 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1282 means we want to display multibyte text. Value is a pointer to a
1283 realized face that is ready for display. */
1285 static INLINE
struct face
*
1286 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
)
1292 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1296 /* Unibyte case. We don't have to encode, but we have to make
1297 sure to use a face suitable for unibyte. */
1300 face_id
= FACE_FOR_CHAR (f
, face
, c
);
1301 face
= FACE_FROM_ID (f
, face_id
);
1303 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1305 /* Case of ASCII in a face known to fit ASCII. */
1311 int c1
, c2
, charset
;
1313 /* Split characters into bytes. If c2 is -1 afterwards, C is
1314 really a one-byte character so that byte1 is zero. */
1315 SPLIT_CHAR (c
, charset
, c1
, c2
);
1317 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1319 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1321 /* Maybe encode the character in *CHAR2B. */
1322 if (face
->font
!= NULL
)
1324 struct font_info
*font_info
1325 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1327 x_encode_char (c
, char2b
, font_info
);
1331 /* Make sure X resources of the face are allocated. */
1332 xassert (face
!= NULL
);
1333 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1339 /* Get face and two-byte form of character glyph GLYPH on frame F.
1340 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
1341 a pointer to a realized face that is ready for display. */
1343 static INLINE
struct face
*
1344 x_get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
1346 struct glyph
*glyph
;
1352 xassert (glyph
->type
== CHAR_GLYPH
);
1353 face
= FACE_FROM_ID (f
, glyph
->face_id
);
1358 if (!glyph
->multibyte_p
)
1360 /* Unibyte case. We don't have to encode, but we have to make
1361 sure to use a face suitable for unibyte. */
1363 char2b
->byte2
= glyph
->u
.ch
;
1365 else if (glyph
->u
.ch
< 128
1366 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
1368 /* Case of ASCII in a face known to fit ASCII. */
1370 char2b
->byte2
= glyph
->u
.ch
;
1374 int c1
, c2
, charset
;
1376 /* Split characters into bytes. If c2 is -1 afterwards, C is
1377 really a one-byte character so that byte1 is zero. */
1378 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
1380 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1382 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1384 /* Maybe encode the character in *CHAR2B. */
1385 if (charset
!= CHARSET_ASCII
)
1387 struct font_info
*font_info
1388 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1391 x_encode_char (glyph
->u
.ch
, char2b
, font_info
);
1394 = ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
1399 /* Make sure X resources of the face are allocated. */
1400 xassert (face
!= NULL
);
1401 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1406 /* Store one glyph for IT->char_to_display in IT->glyph_row.
1407 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1413 struct glyph
*glyph
;
1414 enum glyph_row_area area
= it
->area
;
1416 xassert (it
->glyph_row
);
1417 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
1419 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1420 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1422 glyph
->charpos
= CHARPOS (it
->position
);
1423 glyph
->object
= it
->object
;
1424 glyph
->pixel_width
= it
->pixel_width
;
1425 glyph
->voffset
= it
->voffset
;
1426 glyph
->type
= CHAR_GLYPH
;
1427 glyph
->multibyte_p
= it
->multibyte_p
;
1428 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1429 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1430 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1431 || it
->phys_descent
> it
->descent
);
1432 glyph
->padding_p
= 0;
1433 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
1434 glyph
->face_id
= it
->face_id
;
1435 glyph
->u
.ch
= it
->char_to_display
;
1436 ++it
->glyph_row
->used
[area
];
1440 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
1441 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1444 x_append_composite_glyph (it
)
1447 struct glyph
*glyph
;
1448 enum glyph_row_area area
= it
->area
;
1450 xassert (it
->glyph_row
);
1452 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1453 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1455 glyph
->charpos
= CHARPOS (it
->position
);
1456 glyph
->object
= it
->object
;
1457 glyph
->pixel_width
= it
->pixel_width
;
1458 glyph
->voffset
= it
->voffset
;
1459 glyph
->type
= COMPOSITE_GLYPH
;
1460 glyph
->multibyte_p
= it
->multibyte_p
;
1461 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1462 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1463 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1464 || it
->phys_descent
> it
->descent
);
1465 glyph
->padding_p
= 0;
1466 glyph
->glyph_not_available_p
= 0;
1467 glyph
->face_id
= it
->face_id
;
1468 glyph
->u
.cmp_id
= it
->cmp_id
;
1469 ++it
->glyph_row
->used
[area
];
1474 /* Change IT->ascent and IT->height according to the setting of
1478 take_vertical_position_into_account (it
)
1483 if (it
->voffset
< 0)
1484 /* Increase the ascent so that we can display the text higher
1486 it
->ascent
+= abs (it
->voffset
);
1488 /* Increase the descent so that we can display the text lower
1490 it
->descent
+= it
->voffset
;
1495 /* Produce glyphs/get display metrics for the image IT is loaded with.
1496 See the description of struct display_iterator in dispextern.h for
1497 an overview of struct display_iterator. */
1500 x_produce_image_glyph (it
)
1506 xassert (it
->what
== IT_IMAGE
);
1508 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1509 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
1512 /* Make sure X resources of the face and image are loaded. */
1513 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1514 prepare_image_for_display (it
->f
, img
);
1516 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
1517 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
1518 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
1522 if (face
->box
!= FACE_NO_BOX
)
1524 if (face
->box_line_width
> 0)
1526 it
->ascent
+= face
->box_line_width
;
1527 it
->descent
+= face
->box_line_width
;
1530 if (it
->start_of_box_run_p
)
1531 it
->pixel_width
+= abs (face
->box_line_width
);
1532 if (it
->end_of_box_run_p
)
1533 it
->pixel_width
+= abs (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 if (face
->box_line_width
> 0)
1740 it
->ascent
+= face
->box_line_width
;
1741 it
->descent
+= face
->box_line_width
;
1744 if (it
->start_of_box_run_p
)
1745 it
->pixel_width
+= abs (face
->box_line_width
);
1746 if (it
->end_of_box_run_p
)
1747 it
->pixel_width
+= abs (face
->box_line_width
);
1750 take_vertical_position_into_account (it
);
1753 /* Return proper value to be used as baseline offset of font that has
1754 ASCENT and DESCENT to draw characters by the font at the vertical
1755 center of the line of frame F.
1757 Here, out task is to find the value of BOFF in the following figure;
1759 -------------------------+-----------+-
1760 -+-+---------+-+ | |
1762 | | | | F_ASCENT F_HEIGHT
1765 | | |-|-+------+-----------|------- baseline
1767 | |---------|-+-+ | |
1769 -+-+---------+-+ F_DESCENT |
1770 -------------------------+-----------+-
1772 -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
1773 BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
1774 DESCENT = FONT->descent
1775 HEIGHT = FONT_HEIGHT (FONT)
1776 F_DESCENT = (F->output_data.x->font->descent
1777 - F->output_data.x->baseline_offset)
1778 F_HEIGHT = FRAME_LINE_HEIGHT (F)
1781 #define VCENTER_BASELINE_OFFSET(FONT, F) \
1783 + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT)) \
1784 + (FRAME_LINE_HEIGHT ((F)) > FONT_HEIGHT ((FONT)))) / 2 \
1785 - ((F)->output_data.x->font->descent - (F)->output_data.x->baseline_offset))
1787 /* Produce glyphs/get display metrics for the display element IT is
1788 loaded with. See the description of struct display_iterator in
1789 dispextern.h for an overview of struct display_iterator. */
1792 x_produce_glyphs (it
)
1795 it
->glyph_not_available_p
= 0;
1797 if (it
->what
== IT_CHARACTER
)
1801 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1803 int font_not_found_p
;
1804 struct font_info
*font_info
;
1805 int boff
; /* baseline offset */
1806 /* We may change it->multibyte_p upon unibyte<->multibyte
1807 conversion. So, save the current value now and restore it
1810 Note: It seems that we don't have to record multibyte_p in
1811 struct glyph because the character code itself tells if or
1812 not the character is multibyte. Thus, in the future, we must
1813 consider eliminating the field `multibyte_p' in the struct
1816 int saved_multibyte_p
= it
->multibyte_p
;
1818 /* Maybe translate single-byte characters to multibyte, or the
1820 it
->char_to_display
= it
->c
;
1821 if (!ASCII_BYTE_P (it
->c
))
1823 if (unibyte_display_via_language_environment
1824 && SINGLE_BYTE_CHAR_P (it
->c
)
1826 || !NILP (Vnonascii_translation_table
)))
1828 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
1829 it
->multibyte_p
= 1;
1830 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1831 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1833 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
1834 && !it
->multibyte_p
)
1836 it
->char_to_display
= multibyte_char_to_unibyte (it
->c
, Qnil
);
1837 it
->multibyte_p
= 0;
1838 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1839 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1843 /* Get font to use. Encode IT->char_to_display. */
1844 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
1845 it
->face_id
, &char2b
,
1849 /* When no suitable font found, use the default font. */
1850 font_not_found_p
= font
== NULL
;
1851 if (font_not_found_p
)
1853 font
= FRAME_FONT (it
->f
);
1854 boff
= it
->f
->output_data
.x
->baseline_offset
;
1859 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
1860 boff
= font_info
->baseline_offset
;
1861 if (font_info
->vertical_centering
)
1862 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
1865 if (it
->char_to_display
>= ' '
1866 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
1868 /* Either unibyte or ASCII. */
1873 pcm
= x_per_char_metric (font
, &char2b
);
1874 it
->ascent
= font
->ascent
+ boff
;
1875 it
->descent
= font
->descent
- boff
;
1879 it
->phys_ascent
= pcm
->ascent
+ boff
;
1880 it
->phys_descent
= pcm
->descent
- boff
;
1881 it
->pixel_width
= pcm
->width
;
1885 it
->glyph_not_available_p
= 1;
1886 it
->phys_ascent
= font
->ascent
+ boff
;
1887 it
->phys_descent
= font
->descent
- boff
;
1888 it
->pixel_width
= FONT_WIDTH (font
);
1891 /* If this is a space inside a region of text with
1892 `space-width' property, change its width. */
1893 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
1895 it
->pixel_width
*= XFLOATINT (it
->space_width
);
1897 /* If face has a box, add the box thickness to the character
1898 height. If character has a box line to the left and/or
1899 right, add the box line width to the character's width. */
1900 if (face
->box
!= FACE_NO_BOX
)
1902 int thick
= face
->box_line_width
;
1906 it
->ascent
+= thick
;
1907 it
->descent
+= thick
;
1912 if (it
->start_of_box_run_p
)
1913 it
->pixel_width
+= thick
;
1914 if (it
->end_of_box_run_p
)
1915 it
->pixel_width
+= thick
;
1918 /* If face has an overline, add the height of the overline
1919 (1 pixel) and a 1 pixel margin to the character height. */
1920 if (face
->overline_p
)
1923 take_vertical_position_into_account (it
);
1925 /* If we have to actually produce glyphs, do it. */
1930 /* Translate a space with a `space-width' property
1931 into a stretch glyph. */
1932 double ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1933 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1934 it
->ascent
+ it
->descent
, ascent
);
1937 x_append_glyph (it
);
1939 /* If characters with lbearing or rbearing are displayed
1940 in this line, record that fact in a flag of the
1941 glyph row. This is used to optimize X output code. */
1942 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
1943 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1946 else if (it
->char_to_display
== '\n')
1948 /* A newline has no width but we need the height of the line. */
1949 it
->pixel_width
= 0;
1951 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1952 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1954 if (face
->box
!= FACE_NO_BOX
1955 && face
->box_line_width
> 0)
1957 it
->ascent
+= face
->box_line_width
;
1958 it
->descent
+= face
->box_line_width
;
1961 else if (it
->char_to_display
== '\t')
1963 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
1964 int x
= it
->current_x
+ it
->continuation_lines_width
;
1965 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
1967 /* If the distance from the current position to the next tab
1968 stop is less than a canonical character width, use the
1969 tab stop after that. */
1970 if (next_tab_x
- x
< CANON_X_UNIT (it
->f
))
1971 next_tab_x
+= tab_width
;
1973 it
->pixel_width
= next_tab_x
- x
;
1975 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1976 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1980 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
1981 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1982 it
->ascent
+ it
->descent
, ascent
);
1987 /* A multi-byte character. Assume that the display width of the
1988 character is the width of the character multiplied by the
1989 width of the font. */
1991 /* If we found a font, this font should give us the right
1992 metrics. If we didn't find a font, use the frame's
1993 default font and calculate the width of the character
1994 from the charset width; this is what old redisplay code
1996 pcm
= x_per_char_metric (font
, &char2b
);
1997 if (font_not_found_p
|| !pcm
)
1999 int charset
= CHAR_CHARSET (it
->char_to_display
);
2001 it
->glyph_not_available_p
= 1;
2002 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
2003 * CHARSET_WIDTH (charset
));
2004 it
->phys_ascent
= font
->ascent
+ boff
;
2005 it
->phys_descent
= font
->descent
- boff
;
2009 it
->pixel_width
= pcm
->width
;
2010 it
->phys_ascent
= pcm
->ascent
+ boff
;
2011 it
->phys_descent
= pcm
->descent
- boff
;
2013 && (pcm
->lbearing
< 0
2014 || pcm
->rbearing
> pcm
->width
))
2015 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
2018 it
->ascent
= font
->ascent
+ boff
;
2019 it
->descent
= font
->descent
- boff
;
2020 if (face
->box
!= FACE_NO_BOX
)
2022 int thick
= face
->box_line_width
;
2026 it
->ascent
+= thick
;
2027 it
->descent
+= thick
;
2032 if (it
->start_of_box_run_p
)
2033 it
->pixel_width
+= thick
;
2034 if (it
->end_of_box_run_p
)
2035 it
->pixel_width
+= thick
;
2038 /* If face has an overline, add the height of the overline
2039 (1 pixel) and a 1 pixel margin to the character height. */
2040 if (face
->overline_p
)
2043 take_vertical_position_into_account (it
);
2046 x_append_glyph (it
);
2048 it
->multibyte_p
= saved_multibyte_p
;
2050 else if (it
->what
== IT_COMPOSITION
)
2052 /* Note: A composition is represented as one glyph in the
2053 glyph matrix. There are no padding glyphs. */
2056 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2058 int font_not_found_p
;
2059 struct font_info
*font_info
;
2060 int boff
; /* baseline offset */
2061 struct composition
*cmp
= composition_table
[it
->cmp_id
];
2063 /* Maybe translate single-byte characters to multibyte. */
2064 it
->char_to_display
= it
->c
;
2065 if (unibyte_display_via_language_environment
2066 && SINGLE_BYTE_CHAR_P (it
->c
)
2069 && !NILP (Vnonascii_translation_table
))))
2071 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2074 /* Get face and font to use. Encode IT->char_to_display. */
2075 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2076 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2077 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2078 it
->face_id
, &char2b
, it
->multibyte_p
);
2081 /* When no suitable font found, use the default font. */
2082 font_not_found_p
= font
== NULL
;
2083 if (font_not_found_p
)
2085 font
= FRAME_FONT (it
->f
);
2086 boff
= it
->f
->output_data
.x
->baseline_offset
;
2091 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2092 boff
= font_info
->baseline_offset
;
2093 if (font_info
->vertical_centering
)
2094 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2097 /* There are no padding glyphs, so there is only one glyph to
2098 produce for the composition. Important is that pixel_width,
2099 ascent and descent are the values of what is drawn by
2100 draw_glyphs (i.e. the values of the overall glyphs composed). */
2103 /* If we have not yet calculated pixel size data of glyphs of
2104 the composition for the current face font, calculate them
2105 now. Theoretically, we have to check all fonts for the
2106 glyphs, but that requires much time and memory space. So,
2107 here we check only the font of the first glyph. This leads
2108 to incorrect display very rarely, and C-l (recenter) can
2109 correct the display anyway. */
2110 if (cmp
->font
!= (void *) font
)
2112 /* Ascent and descent of the font of the first character of
2113 this composition (adjusted by baseline offset). Ascent
2114 and descent of overall glyphs should not be less than
2115 them respectively. */
2116 int font_ascent
= font
->ascent
+ boff
;
2117 int font_descent
= font
->descent
- boff
;
2118 /* Bounding box of the overall glyphs. */
2119 int leftmost
, rightmost
, lowest
, highest
;
2120 int i
, width
, ascent
, descent
;
2122 cmp
->font
= (void *) font
;
2124 /* Initialize the bounding box. */
2126 && (pcm
= x_per_char_metric (font
, &char2b
)))
2129 ascent
= pcm
->ascent
;
2130 descent
= pcm
->descent
;
2134 width
= FONT_WIDTH (font
);
2135 ascent
= font
->ascent
;
2136 descent
= font
->descent
;
2140 lowest
= - descent
+ boff
;
2141 highest
= ascent
+ boff
;
2145 && font_info
->default_ascent
2146 && CHAR_TABLE_P (Vuse_default_ascent
)
2147 && !NILP (Faref (Vuse_default_ascent
,
2148 make_number (it
->char_to_display
))))
2149 highest
= font_info
->default_ascent
+ boff
;
2151 /* Draw the first glyph at the normal position. It may be
2152 shifted to right later if some other glyphs are drawn at
2154 cmp
->offsets
[0] = 0;
2155 cmp
->offsets
[1] = boff
;
2157 /* Set cmp->offsets for the remaining glyphs. */
2158 for (i
= 1; i
< cmp
->glyph_len
; i
++)
2160 int left
, right
, btm
, top
;
2161 int ch
= COMPOSITION_GLYPH (cmp
, i
);
2162 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
2164 face
= FACE_FROM_ID (it
->f
, face_id
);
2165 x_get_char_face_and_encoding (it
->f
, ch
, face
->id
, &char2b
,
2170 font
= FRAME_FONT (it
->f
);
2171 boff
= it
->f
->output_data
.x
->baseline_offset
;
2177 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2178 boff
= font_info
->baseline_offset
;
2179 if (font_info
->vertical_centering
)
2180 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2184 && (pcm
= x_per_char_metric (font
, &char2b
)))
2187 ascent
= pcm
->ascent
;
2188 descent
= pcm
->descent
;
2192 width
= FONT_WIDTH (font
);
2197 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
2199 /* Relative composition with or without
2201 left
= (leftmost
+ rightmost
- width
) / 2;
2202 btm
= - descent
+ boff
;
2203 if (font_info
&& font_info
->relative_compose
2204 && (! CHAR_TABLE_P (Vignore_relative_composition
)
2205 || NILP (Faref (Vignore_relative_composition
,
2206 make_number (ch
)))))
2209 if (- descent
>= font_info
->relative_compose
)
2210 /* One extra pixel between two glyphs. */
2212 else if (ascent
<= 0)
2213 /* One extra pixel between two glyphs. */
2214 btm
= lowest
- 1 - ascent
- descent
;
2219 /* A composition rule is specified by an integer
2220 value that encodes global and new reference
2221 points (GREF and NREF). GREF and NREF are
2222 specified by numbers as below:
2230 ---3---4---5--- baseline
2232 6---7---8 -- descent
2234 int rule
= COMPOSITION_RULE (cmp
, i
);
2235 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
2237 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
2238 grefx
= gref
% 3, nrefx
= nref
% 3;
2239 grefy
= gref
/ 3, nrefy
= nref
/ 3;
2242 + grefx
* (rightmost
- leftmost
) / 2
2243 - nrefx
* width
/ 2);
2244 btm
= ((grefy
== 0 ? highest
2246 : grefy
== 2 ? lowest
2247 : (highest
+ lowest
) / 2)
2248 - (nrefy
== 0 ? ascent
+ descent
2249 : nrefy
== 1 ? descent
- boff
2251 : (ascent
+ descent
) / 2));
2254 cmp
->offsets
[i
* 2] = left
;
2255 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
2257 /* Update the bounding box of the overall glyphs. */
2258 right
= left
+ width
;
2259 top
= btm
+ descent
+ ascent
;
2260 if (left
< leftmost
)
2262 if (right
> rightmost
)
2270 /* If there are glyphs whose x-offsets are negative,
2271 shift all glyphs to the right and make all x-offsets
2275 for (i
= 0; i
< cmp
->glyph_len
; i
++)
2276 cmp
->offsets
[i
* 2] -= leftmost
;
2277 rightmost
-= leftmost
;
2280 cmp
->pixel_width
= rightmost
;
2281 cmp
->ascent
= highest
;
2282 cmp
->descent
= - lowest
;
2283 if (cmp
->ascent
< font_ascent
)
2284 cmp
->ascent
= font_ascent
;
2285 if (cmp
->descent
< font_descent
)
2286 cmp
->descent
= font_descent
;
2289 it
->pixel_width
= cmp
->pixel_width
;
2290 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
2291 it
->descent
= it
->phys_descent
= cmp
->descent
;
2293 if (face
->box
!= FACE_NO_BOX
)
2295 int thick
= face
->box_line_width
;
2299 it
->ascent
+= thick
;
2300 it
->descent
+= thick
;
2305 if (it
->start_of_box_run_p
)
2306 it
->pixel_width
+= thick
;
2307 if (it
->end_of_box_run_p
)
2308 it
->pixel_width
+= thick
;
2311 /* If face has an overline, add the height of the overline
2312 (1 pixel) and a 1 pixel margin to the character height. */
2313 if (face
->overline_p
)
2316 take_vertical_position_into_account (it
);
2319 x_append_composite_glyph (it
);
2321 else if (it
->what
== IT_IMAGE
)
2322 x_produce_image_glyph (it
);
2323 else if (it
->what
== IT_STRETCH
)
2324 x_produce_stretch_glyph (it
);
2326 /* Accumulate dimensions. Note: can't assume that it->descent > 0
2327 because this isn't true for images with `:ascent 100'. */
2328 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
2329 if (it
->area
== TEXT_AREA
)
2330 it
->current_x
+= it
->pixel_width
;
2332 it
->descent
+= it
->extra_line_spacing
;
2334 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
2335 it
->max_descent
= max (it
->max_descent
, it
->descent
);
2336 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
2337 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
2341 /* Estimate the pixel height of the mode or top line on frame F.
2342 FACE_ID specifies what line's height to estimate. */
2345 x_estimate_mode_line_height (f
, face_id
)
2347 enum face_id face_id
;
2349 int height
= FONT_HEIGHT (FRAME_FONT (f
));
2351 /* This function is called so early when Emacs starts that the face
2352 cache and mode line face are not yet initialized. */
2353 if (FRAME_FACE_CACHE (f
))
2355 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2359 height
= FONT_HEIGHT (face
->font
);
2360 if (face
->box_line_width
> 0)
2361 height
+= 2 * face
->box_line_width
;
2369 /***********************************************************************
2371 ***********************************************************************/
2373 /* A sequence of glyphs to be drawn in the same face.
2375 This data structure is not really completely X specific, so it
2376 could possibly, at least partially, be useful for other systems. It
2377 is currently not part of the external redisplay interface because
2378 it's not clear what other systems will need. */
2382 /* X-origin of the string. */
2385 /* Y-origin and y-position of the base line of this string. */
2388 /* The width of the string, not including a face extension. */
2391 /* The width of the string, including a face extension. */
2392 int background_width
;
2394 /* The height of this string. This is the height of the line this
2395 string is drawn in, and can be different from the height of the
2396 font the string is drawn in. */
2399 /* Number of pixels this string overwrites in front of its x-origin.
2400 This number is zero if the string has an lbearing >= 0; it is
2401 -lbearing, if the string has an lbearing < 0. */
2404 /* Number of pixels this string overwrites past its right-most
2405 nominal x-position, i.e. x + width. Zero if the string's
2406 rbearing is <= its nominal width, rbearing - width otherwise. */
2409 /* The frame on which the glyph string is drawn. */
2412 /* The window on which the glyph string is drawn. */
2415 /* X display and window for convenience. */
2419 /* The glyph row for which this string was built. It determines the
2420 y-origin and height of the string. */
2421 struct glyph_row
*row
;
2423 /* The area within row. */
2424 enum glyph_row_area area
;
2426 /* Characters to be drawn, and number of characters. */
2430 /* A face-override for drawing cursors, mouse face and similar. */
2431 enum draw_glyphs_face hl
;
2433 /* Face in which this string is to be drawn. */
2436 /* Font in which this string is to be drawn. */
2439 /* Font info for this string. */
2440 struct font_info
*font_info
;
2442 /* Non-null means this string describes (part of) a composition.
2443 All characters from char2b are drawn composed. */
2444 struct composition
*cmp
;
2446 /* Index of this glyph string's first character in the glyph
2447 definition of CMP. If this is zero, this glyph string describes
2448 the first character of a composition. */
2451 /* 1 means this glyph strings face has to be drawn to the right end
2452 of the window's drawing area. */
2453 unsigned extends_to_end_of_line_p
: 1;
2455 /* 1 means the background of this string has been drawn. */
2456 unsigned background_filled_p
: 1;
2458 /* 1 means glyph string must be drawn with 16-bit functions. */
2459 unsigned two_byte_p
: 1;
2461 /* 1 means that the original font determined for drawing this glyph
2462 string could not be loaded. The member `font' has been set to
2463 the frame's default font in this case. */
2464 unsigned font_not_found_p
: 1;
2466 /* 1 means that the face in which this glyph string is drawn has a
2468 unsigned stippled_p
: 1;
2470 /* 1 means only the foreground of this glyph string must be drawn,
2471 and we should use the physical height of the line this glyph
2472 string appears in as clip rect. */
2473 unsigned for_overlaps_p
: 1;
2475 /* The GC to use for drawing this glyph string. */
2478 /* A pointer to the first glyph in the string. This glyph
2479 corresponds to char2b[0]. Needed to draw rectangles if
2480 font_not_found_p is 1. */
2481 struct glyph
*first_glyph
;
2483 /* Image, if any. */
2486 struct glyph_string
*next
, *prev
;
2493 x_dump_glyph_string (s
)
2494 struct glyph_string
*s
;
2496 fprintf (stderr
, "glyph string\n");
2497 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
2498 s
->x
, s
->y
, s
->width
, s
->height
);
2499 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
2500 fprintf (stderr
, " hl = %d\n", s
->hl
);
2501 fprintf (stderr
, " left overhang = %d, right = %d\n",
2502 s
->left_overhang
, s
->right_overhang
);
2503 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
2504 fprintf (stderr
, " extends to end of line = %d\n",
2505 s
->extends_to_end_of_line_p
);
2506 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
2507 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
2510 #endif /* GLYPH_DEBUG */
2514 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
2515 struct glyph_string
**,
2516 struct glyph_string
*,
2517 struct glyph_string
*));
2518 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
2519 struct glyph_string
**,
2520 struct glyph_string
*,
2521 struct glyph_string
*));
2522 static void x_append_glyph_string
P_ ((struct glyph_string
**,
2523 struct glyph_string
**,
2524 struct glyph_string
*));
2525 static int x_left_overwritten
P_ ((struct glyph_string
*));
2526 static int x_left_overwriting
P_ ((struct glyph_string
*));
2527 static int x_right_overwritten
P_ ((struct glyph_string
*));
2528 static int x_right_overwriting
P_ ((struct glyph_string
*));
2529 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
2531 static void x_init_glyph_string
P_ ((struct glyph_string
*,
2532 XChar2b
*, struct window
*,
2534 enum glyph_row_area
, int,
2535 enum draw_glyphs_face
));
2536 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
2537 enum glyph_row_area
, int, int,
2538 enum draw_glyphs_face
, int *, int *, int));
2539 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2540 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2541 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2543 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2544 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2545 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2546 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2547 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2548 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2549 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2550 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2551 static void x_get_glyph_overhangs
P_ ((struct glyph
*, struct frame
*,
2553 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
2554 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
2555 unsigned long *, double, int));
2556 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2557 double, int, unsigned long));
2558 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2559 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2560 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2561 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2562 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
2563 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
2564 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2566 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2567 int, int, int, int, XRectangle
*));
2568 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2569 int, int, int, XRectangle
*));
2570 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
2571 enum glyph_row_area
));
2572 static int x_fill_stretch_glyph_string
P_ ((struct glyph_string
*,
2574 enum glyph_row_area
, int, int));
2577 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
2581 /* Append the list of glyph strings with head H and tail T to the list
2582 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
2585 x_append_glyph_string_lists (head
, tail
, h
, t
)
2586 struct glyph_string
**head
, **tail
;
2587 struct glyph_string
*h
, *t
;
2601 /* Prepend the list of glyph strings with head H and tail T to the
2602 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
2606 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
2607 struct glyph_string
**head
, **tail
;
2608 struct glyph_string
*h
, *t
;
2622 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
2623 Set *HEAD and *TAIL to the resulting list. */
2626 x_append_glyph_string (head
, tail
, s
)
2627 struct glyph_string
**head
, **tail
;
2628 struct glyph_string
*s
;
2630 s
->next
= s
->prev
= NULL
;
2631 x_append_glyph_string_lists (head
, tail
, s
, s
);
2635 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2640 struct glyph_string
*s
;
2642 if (s
->font
== FRAME_FONT (s
->f
)
2643 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2644 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2646 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
2649 /* Cursor on non-default face: must merge. */
2653 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
2654 xgcv
.foreground
= s
->face
->background
;
2656 /* If the glyph would be invisible, try a different foreground. */
2657 if (xgcv
.foreground
== xgcv
.background
)
2658 xgcv
.foreground
= s
->face
->foreground
;
2659 if (xgcv
.foreground
== xgcv
.background
)
2660 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
2661 if (xgcv
.foreground
== xgcv
.background
)
2662 xgcv
.foreground
= s
->face
->foreground
;
2664 /* Make sure the cursor is distinct from text in this face. */
2665 if (xgcv
.background
== s
->face
->background
2666 && xgcv
.foreground
== s
->face
->foreground
)
2668 xgcv
.background
= s
->face
->foreground
;
2669 xgcv
.foreground
= s
->face
->background
;
2672 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2673 xgcv
.font
= s
->font
->fid
;
2674 xgcv
.graphics_exposures
= False
;
2675 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2677 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2678 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2681 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2682 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2684 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2689 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2692 x_set_mouse_face_gc (s
)
2693 struct glyph_string
*s
;
2698 /* What face has to be used last for the mouse face? */
2699 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2700 face
= FACE_FROM_ID (s
->f
, face_id
);
2702 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
2704 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2705 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2707 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2708 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2709 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2711 /* If font in this face is same as S->font, use it. */
2712 if (s
->font
== s
->face
->font
)
2713 s
->gc
= s
->face
->gc
;
2716 /* Otherwise construct scratch_cursor_gc with values from FACE
2721 xgcv
.background
= s
->face
->background
;
2722 xgcv
.foreground
= s
->face
->foreground
;
2723 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2724 xgcv
.font
= s
->font
->fid
;
2725 xgcv
.graphics_exposures
= False
;
2726 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2728 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2729 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2732 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2733 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2735 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2738 xassert (s
->gc
!= 0);
2742 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2743 Faces to use in the mode line have already been computed when the
2744 matrix was built, so there isn't much to do, here. */
2747 x_set_mode_line_face_gc (s
)
2748 struct glyph_string
*s
;
2750 s
->gc
= s
->face
->gc
;
2754 /* Set S->gc of glyph string S for drawing that glyph string. Set
2755 S->stippled_p to a non-zero value if the face of S has a stipple
2759 x_set_glyph_string_gc (s
)
2760 struct glyph_string
*s
;
2762 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2764 if (s
->hl
== DRAW_NORMAL_TEXT
)
2766 s
->gc
= s
->face
->gc
;
2767 s
->stippled_p
= s
->face
->stipple
!= 0;
2769 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2771 x_set_mode_line_face_gc (s
);
2772 s
->stippled_p
= s
->face
->stipple
!= 0;
2774 else if (s
->hl
== DRAW_CURSOR
)
2776 x_set_cursor_gc (s
);
2779 else if (s
->hl
== DRAW_MOUSE_FACE
)
2781 x_set_mouse_face_gc (s
);
2782 s
->stippled_p
= s
->face
->stipple
!= 0;
2784 else if (s
->hl
== DRAW_IMAGE_RAISED
2785 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2787 s
->gc
= s
->face
->gc
;
2788 s
->stippled_p
= s
->face
->stipple
!= 0;
2792 s
->gc
= s
->face
->gc
;
2793 s
->stippled_p
= s
->face
->stipple
!= 0;
2796 /* GC must have been set. */
2797 xassert (s
->gc
!= 0);
2801 /* Return in *R the clipping rectangle for glyph string S. */
2804 x_get_glyph_string_clip_rect (s
, r
)
2805 struct glyph_string
*s
;
2808 if (s
->row
->full_width_p
)
2810 /* Draw full-width. X coordinates are relative to S->w->left. */
2811 int canon_x
= CANON_X_UNIT (s
->f
);
2813 r
->x
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
2814 r
->width
= XFASTINT (s
->w
->width
) * canon_x
;
2816 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
2818 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
2819 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
2823 r
->x
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
2825 /* Unless displaying a mode or menu bar line, which are always
2826 fully visible, clip to the visible part of the row. */
2827 if (s
->w
->pseudo_window_p
)
2828 r
->height
= s
->row
->visible_height
;
2830 r
->height
= s
->height
;
2834 /* This is a text line that may be partially visible. */
2835 r
->x
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
2836 r
->width
= window_box_width (s
->w
, s
->area
);
2837 r
->height
= s
->row
->visible_height
;
2840 /* Don't use S->y for clipping because it doesn't take partially
2841 visible lines into account. For example, it can be negative for
2842 partially visible lines at the top of a window. */
2843 if (!s
->row
->full_width_p
2844 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2845 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2847 r
->y
= max (0, s
->row
->y
);
2849 /* If drawing a tool-bar window, draw it over the internal border
2850 at the top of the window. */
2851 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
2852 r
->y
-= s
->f
->output_data
.x
->internal_border_width
;
2854 /* If S draws overlapping rows, it's sufficient to use the top and
2855 bottom of the window for clipping because this glyph string
2856 intentionally draws over other lines. */
2857 if (s
->for_overlaps_p
)
2859 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2860 r
->height
= window_text_bottom_y (s
->w
) - r
->y
;
2863 r
->y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->y
);
2867 /* Set clipping for output of glyph string S. S may be part of a mode
2868 line or menu if we don't have X toolkit support. */
2871 x_set_glyph_string_clipping (s
)
2872 struct glyph_string
*s
;
2875 x_get_glyph_string_clip_rect (s
, &r
);
2876 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
2880 /* Compute left and right overhang of glyph string S. If S is a glyph
2881 string for a composition, assume overhangs don't exist. */
2884 x_compute_glyph_string_overhangs (s
)
2885 struct glyph_string
*s
;
2888 && s
->first_glyph
->type
== CHAR_GLYPH
)
2891 int direction
, font_ascent
, font_descent
;
2892 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
2893 &font_ascent
, &font_descent
, &cs
);
2894 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
2895 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
2900 /* Compute overhangs and x-positions for glyph string S and its
2901 predecessors, or successors. X is the starting x-position for S.
2902 BACKWARD_P non-zero means process predecessors. */
2905 x_compute_overhangs_and_x (s
, x
, backward_p
)
2906 struct glyph_string
*s
;
2914 x_compute_glyph_string_overhangs (s
);
2924 x_compute_glyph_string_overhangs (s
);
2933 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
2934 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
2935 assumed to be zero. */
2938 x_get_glyph_overhangs (glyph
, f
, left
, right
)
2939 struct glyph
*glyph
;
2945 if (glyph
->type
== CHAR_GLYPH
)
2949 struct font_info
*font_info
;
2953 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
2955 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
2957 && (pcm
= x_per_char_metric (font
, &char2b
)))
2959 if (pcm
->rbearing
> pcm
->width
)
2960 *right
= pcm
->rbearing
- pcm
->width
;
2961 if (pcm
->lbearing
< 0)
2962 *left
= -pcm
->lbearing
;
2968 /* Return the index of the first glyph preceding glyph string S that
2969 is overwritten by S because of S's left overhang. Value is -1
2970 if no glyphs are overwritten. */
2973 x_left_overwritten (s
)
2974 struct glyph_string
*s
;
2978 if (s
->left_overhang
)
2981 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2982 int first
= s
->first_glyph
- glyphs
;
2984 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
2985 x
-= glyphs
[i
].pixel_width
;
2996 /* Return the index of the first glyph preceding glyph string S that
2997 is overwriting S because of its right overhang. Value is -1 if no
2998 glyph in front of S overwrites S. */
3001 x_left_overwriting (s
)
3002 struct glyph_string
*s
;
3005 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3006 int first
= s
->first_glyph
- glyphs
;
3010 for (i
= first
- 1; i
>= 0; --i
)
3013 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3016 x
-= glyphs
[i
].pixel_width
;
3023 /* Return the index of the last glyph following glyph string S that is
3024 not overwritten by S because of S's right overhang. Value is -1 if
3025 no such glyph is found. */
3028 x_right_overwritten (s
)
3029 struct glyph_string
*s
;
3033 if (s
->right_overhang
)
3036 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3037 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3038 int end
= s
->row
->used
[s
->area
];
3040 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
3041 x
+= glyphs
[i
].pixel_width
;
3050 /* Return the index of the last glyph following glyph string S that
3051 overwrites S because of its left overhang. Value is negative
3052 if no such glyph is found. */
3055 x_right_overwriting (s
)
3056 struct glyph_string
*s
;
3059 int end
= s
->row
->used
[s
->area
];
3060 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3061 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3065 for (i
= first
; i
< end
; ++i
)
3068 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3071 x
+= glyphs
[i
].pixel_width
;
3078 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
3081 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
3082 struct glyph_string
*s
;
3086 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
3087 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3088 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3089 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3093 /* Draw the background of glyph_string S. If S->background_filled_p
3094 is non-zero don't draw it. FORCE_P non-zero means draw the
3095 background even if it wouldn't be drawn normally. This is used
3096 when a string preceding S draws into the background of S, or S
3097 contains the first component of a composition. */
3100 x_draw_glyph_string_background (s
, force_p
)
3101 struct glyph_string
*s
;
3104 /* Nothing to do if background has already been drawn or if it
3105 shouldn't be drawn in the first place. */
3106 if (!s
->background_filled_p
)
3108 int box_line_width
= max (s
->face
->box_line_width
, 0);
3112 /* Fill background with a stipple pattern. */
3113 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3114 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
3115 s
->y
+ box_line_width
,
3116 s
->background_width
,
3117 s
->height
- 2 * box_line_width
);
3118 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3119 s
->background_filled_p
= 1;
3121 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
3122 || s
->font_not_found_p
3123 || s
->extends_to_end_of_line_p
3126 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
3127 s
->background_width
,
3128 s
->height
- 2 * box_line_width
);
3129 s
->background_filled_p
= 1;
3135 /* Draw the foreground of glyph string S. */
3138 x_draw_glyph_string_foreground (s
)
3139 struct glyph_string
*s
;
3143 /* If first glyph of S has a left box line, start drawing the text
3144 of S to the right of that box line. */
3145 if (s
->face
->box
!= FACE_NO_BOX
3146 && s
->first_glyph
->left_box_line_p
)
3147 x
= s
->x
+ abs (s
->face
->box_line_width
);
3151 /* Draw characters of S as rectangles if S's font could not be
3153 if (s
->font_not_found_p
)
3155 for (i
= 0; i
< s
->nchars
; ++i
)
3157 struct glyph
*g
= s
->first_glyph
+ i
;
3158 XDrawRectangle (s
->display
, s
->window
,
3159 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
3161 x
+= g
->pixel_width
;
3166 char *char1b
= (char *) s
->char2b
;
3167 int boff
= s
->font_info
->baseline_offset
;
3169 if (s
->font_info
->vertical_centering
)
3170 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
3172 /* If we can use 8-bit functions, condense S->char2b. */
3174 for (i
= 0; i
< s
->nchars
; ++i
)
3175 char1b
[i
] = s
->char2b
[i
].byte2
;
3177 /* Draw text with XDrawString if background has already been
3178 filled. Otherwise, use XDrawImageString. (Note that
3179 XDrawImageString is usually faster than XDrawString.) Always
3180 use XDrawImageString when drawing the cursor so that there is
3181 no chance that characters under a box cursor are invisible. */
3182 if (s
->for_overlaps_p
3183 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
3185 /* Draw characters with 16-bit or 8-bit functions. */
3187 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
3188 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3190 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
3191 s
->ybase
- boff
, char1b
, s
->nchars
);
3196 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
3197 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3199 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
3200 s
->ybase
- boff
, char1b
, s
->nchars
);
3205 /* Draw the foreground of composite glyph string S. */
3208 x_draw_composite_glyph_string_foreground (s
)
3209 struct glyph_string
*s
;
3213 /* If first glyph of S has a left box line, start drawing the text
3214 of S to the right of that box line. */
3215 if (s
->face
->box
!= FACE_NO_BOX
3216 && s
->first_glyph
->left_box_line_p
)
3217 x
= s
->x
+ abs (s
->face
->box_line_width
);
3221 /* S is a glyph string for a composition. S->gidx is the index of
3222 the first character drawn for glyphs of this composition.
3223 S->gidx == 0 means we are drawing the very first character of
3224 this composition. */
3226 /* Draw a rectangle for the composition if the font for the very
3227 first character of the composition could not be loaded. */
3228 if (s
->font_not_found_p
)
3231 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
3232 s
->width
- 1, s
->height
- 1);
3236 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3237 XDrawString16 (s
->display
, s
->window
, s
->gc
,
3238 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3239 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3245 #ifdef USE_X_TOOLKIT
3247 static struct frame
*x_frame_of_widget
P_ ((Widget
));
3250 /* Return the frame on which widget WIDGET is used.. Abort if frame
3251 cannot be determined. */
3253 static struct frame
*
3254 x_frame_of_widget (widget
)
3257 struct x_display_info
*dpyinfo
;
3261 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
3263 /* Find the top-level shell of the widget. Note that this function
3264 can be called when the widget is not yet realized, so XtWindow
3265 (widget) == 0. That's the reason we can't simply use
3266 x_any_window_to_frame. */
3267 while (!XtIsTopLevelShell (widget
))
3268 widget
= XtParent (widget
);
3270 /* Look for a frame with that top-level widget. Allocate the color
3271 on that frame to get the right gamma correction value. */
3272 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
3273 if (GC_FRAMEP (XCAR (tail
))
3274 && (f
= XFRAME (XCAR (tail
)),
3275 (f
->output_data
.nothing
!= 1
3276 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
3277 && f
->output_data
.x
->widget
== widget
)
3284 /* Allocate the color COLOR->pixel on the screen and display of
3285 widget WIDGET in colormap CMAP. If an exact match cannot be
3286 allocated, try the nearest color available. Value is non-zero
3287 if successful. This is called from lwlib. */
3290 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
3295 struct frame
*f
= x_frame_of_widget (widget
);
3296 return x_alloc_nearest_color (f
, cmap
, color
);
3300 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3301 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3302 If this produces the same color as PIXEL, try a color where all RGB
3303 values have DELTA added. Return the allocated color in *PIXEL.
3304 DISPLAY is the X display, CMAP is the colormap to operate on.
3305 Value is non-zero if successful. */
3308 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
3312 unsigned long *pixel
;
3316 struct frame
*f
= x_frame_of_widget (widget
);
3317 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
3321 #endif /* USE_X_TOOLKIT */
3324 /* Value is an array of XColor structures for the contents of the
3325 color map of frame F. Set *NCELLS to the size of the array.
3326 Note that this probably shouldn't be called for large color maps,
3327 say a 24-bit TrueColor map. */
3329 static const XColor
*
3330 x_color_cells (f
, ncells
)
3334 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3336 if (dpyinfo
->color_cells
== NULL
)
3338 Display
*display
= FRAME_X_DISPLAY (f
);
3339 Screen
*screen
= FRAME_X_SCREEN (f
);
3342 dpyinfo
->ncolor_cells
3343 = XDisplayCells (display
, XScreenNumberOfScreen (screen
));
3344 dpyinfo
->color_cells
3345 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
3346 * sizeof *dpyinfo
->color_cells
);
3348 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
3349 dpyinfo
->color_cells
[i
].pixel
= i
;
3351 XQueryColors (display
, FRAME_X_COLORMAP (f
),
3352 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
3355 *ncells
= dpyinfo
->ncolor_cells
;
3356 return dpyinfo
->color_cells
;
3360 /* On frame F, translate pixel colors to RGB values for the NCOLORS
3361 colors in COLORS. Use cached information, if available. */
3364 x_query_colors (f
, colors
, ncolors
)
3369 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3371 if (dpyinfo
->color_cells
)
3374 for (i
= 0; i
< ncolors
; ++i
)
3376 unsigned long pixel
= colors
[i
].pixel
;
3377 xassert (pixel
< dpyinfo
->ncolor_cells
);
3378 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
3379 colors
[i
] = dpyinfo
->color_cells
[pixel
];
3383 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
3387 /* On frame F, translate pixel color to RGB values for the color in
3388 COLOR. Use cached information, if available. */
3391 x_query_color (f
, color
)
3395 x_query_colors (f
, color
, 1);
3399 /* Allocate the color COLOR->pixel on SCREEN of DISPLAY, colormap
3400 CMAP. If an exact match can't be allocated, try the nearest color
3401 available. Value is non-zero if successful. Set *COLOR to the
3405 x_alloc_nearest_color (f
, cmap
, color
)
3410 Display
*display
= FRAME_X_DISPLAY (f
);
3411 Screen
*screen
= FRAME_X_SCREEN (f
);
3414 gamma_correct (f
, color
);
3415 rc
= XAllocColor (display
, cmap
, color
);
3418 /* If we got to this point, the colormap is full, so we're going
3419 to try to get the next closest color. The algorithm used is
3420 a least-squares matching, which is what X uses for closest
3421 color matching with StaticColor visuals. */
3423 unsigned long nearest_delta
= ~0;
3425 const XColor
*cells
= x_color_cells (f
, &ncells
);
3427 for (nearest
= i
= 0; i
< ncells
; ++i
)
3429 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
3430 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
3431 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
3432 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
3434 if (delta
< nearest_delta
)
3437 nearest_delta
= delta
;
3441 color
->red
= cells
[nearest
].red
;
3442 color
->green
= cells
[nearest
].green
;
3443 color
->blue
= cells
[nearest
].blue
;
3444 rc
= XAllocColor (display
, cmap
, color
);
3448 /* If allocation succeeded, and the allocated pixel color is not
3449 equal to a cached pixel color recorded earlier, there was a
3450 change in the colormap, so clear the color cache. */
3451 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3452 XColor
*cached_color
;
3454 if (dpyinfo
->color_cells
3455 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
3456 (cached_color
->red
!= color
->red
3457 || cached_color
->blue
!= color
->blue
3458 || cached_color
->green
!= color
->green
)))
3460 xfree (dpyinfo
->color_cells
);
3461 dpyinfo
->color_cells
= NULL
;
3462 dpyinfo
->ncolor_cells
= 0;
3466 #ifdef DEBUG_X_COLORS
3468 register_color (color
->pixel
);
3469 #endif /* DEBUG_X_COLORS */
3475 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
3476 It's necessary to do this instead of just using PIXEL directly to
3477 get color reference counts right. */
3480 x_copy_color (f
, pixel
)
3482 unsigned long pixel
;
3486 color
.pixel
= pixel
;
3488 x_query_color (f
, &color
);
3489 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3491 #ifdef DEBUG_X_COLORS
3492 register_color (pixel
);
3498 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
3499 It's necessary to do this instead of just using PIXEL directly to
3500 get color reference counts right. */
3503 x_copy_dpy_color (dpy
, cmap
, pixel
)
3506 unsigned long pixel
;
3510 color
.pixel
= pixel
;
3512 XQueryColor (dpy
, cmap
, &color
);
3513 XAllocColor (dpy
, cmap
, &color
);
3515 #ifdef DEBUG_X_COLORS
3516 register_color (pixel
);
3522 /* Brightness beyond which a color won't have its highlight brightness
3525 Nominally, highlight colors for `3d' faces are calculated by
3526 brightening an object's color by a constant scale factor, but this
3527 doesn't yield good results for dark colors, so for colors who's
3528 brightness is less than this value (on a scale of 0-65535) have an
3529 use an additional additive factor.
3531 The value here is set so that the default menu-bar/mode-line color
3532 (grey75) will not have its highlights changed at all. */
3533 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
3536 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3537 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3538 If this produces the same color as PIXEL, try a color where all RGB
3539 values have DELTA added. Return the allocated color in *PIXEL.
3540 DISPLAY is the X display, CMAP is the colormap to operate on.
3541 Value is non-zero if successful. */
3544 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
3548 unsigned long *pixel
;
3556 /* Get RGB color values. */
3557 color
.pixel
= *pixel
;
3558 x_query_color (f
, &color
);
3560 /* Change RGB values by specified FACTOR. Avoid overflow! */
3561 xassert (factor
>= 0);
3562 new.red
= min (0xffff, factor
* color
.red
);
3563 new.green
= min (0xffff, factor
* color
.green
);
3564 new.blue
= min (0xffff, factor
* color
.blue
);
3566 /* Calculate brightness of COLOR. */
3567 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
3569 /* We only boost colors that are darker than
3570 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
3571 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
3572 /* Make an additive adjustment to NEW, because it's dark enough so
3573 that scaling by FACTOR alone isn't enough. */
3575 /* How far below the limit this color is (0 - 1, 1 being darker). */
3576 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
3577 /* The additive adjustment. */
3578 int min_delta
= delta
* dimness
* factor
/ 2;
3582 new.red
= max (0, new.red
- min_delta
);
3583 new.green
= max (0, new.green
- min_delta
);
3584 new.blue
= max (0, new.blue
- min_delta
);
3588 new.red
= min (0xffff, min_delta
+ new.red
);
3589 new.green
= min (0xffff, min_delta
+ new.green
);
3590 new.blue
= min (0xffff, min_delta
+ new.blue
);
3594 /* Try to allocate the color. */
3595 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3598 if (new.pixel
== *pixel
)
3600 /* If we end up with the same color as before, try adding
3601 delta to the RGB values. */
3602 x_free_colors (f
, &new.pixel
, 1);
3604 new.red
= min (0xffff, delta
+ color
.red
);
3605 new.green
= min (0xffff, delta
+ color
.green
);
3606 new.blue
= min (0xffff, delta
+ color
.blue
);
3607 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3618 /* Set up the foreground color for drawing relief lines of glyph
3619 string S. RELIEF is a pointer to a struct relief containing the GC
3620 with which lines will be drawn. Use a color that is FACTOR or
3621 DELTA lighter or darker than the relief's background which is found
3622 in S->f->output_data.x->relief_background. If such a color cannot
3623 be allocated, use DEFAULT_PIXEL, instead. */
3626 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3628 struct relief
*relief
;
3631 unsigned long default_pixel
;
3634 struct x_output
*di
= f
->output_data
.x
;
3635 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
3636 unsigned long pixel
;
3637 unsigned long background
= di
->relief_background
;
3638 Colormap cmap
= FRAME_X_COLORMAP (f
);
3639 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3640 Display
*dpy
= FRAME_X_DISPLAY (f
);
3642 xgcv
.graphics_exposures
= False
;
3643 xgcv
.line_width
= 1;
3645 /* Free previously allocated color. The color cell will be reused
3646 when it has been freed as many times as it was allocated, so this
3647 doesn't affect faces using the same colors. */
3649 && relief
->allocated_p
)
3651 x_free_colors (f
, &relief
->pixel
, 1);
3652 relief
->allocated_p
= 0;
3655 /* Allocate new color. */
3656 xgcv
.foreground
= default_pixel
;
3658 if (dpyinfo
->n_planes
!= 1
3659 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
3661 relief
->allocated_p
= 1;
3662 xgcv
.foreground
= relief
->pixel
= pixel
;
3665 if (relief
->gc
== 0)
3667 xgcv
.stipple
= dpyinfo
->gray
;
3669 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
3672 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
3676 /* Set up colors for the relief lines around glyph string S. */
3679 x_setup_relief_colors (s
)
3680 struct glyph_string
*s
;
3682 struct x_output
*di
= s
->f
->output_data
.x
;
3683 unsigned long color
;
3685 if (s
->face
->use_box_color_for_shadows_p
)
3686 color
= s
->face
->box_color
;
3691 /* Get the background color of the face. */
3692 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3693 color
= xgcv
.background
;
3696 if (di
->white_relief
.gc
== 0
3697 || color
!= di
->relief_background
)
3699 di
->relief_background
= color
;
3700 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3701 WHITE_PIX_DEFAULT (s
->f
));
3702 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3703 BLACK_PIX_DEFAULT (s
->f
));
3708 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3709 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3710 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3711 relief. LEFT_P non-zero means draw a relief on the left side of
3712 the rectangle. RIGHT_P non-zero means draw a relief on the right
3713 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3717 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3718 raised_p
, left_p
, right_p
, clip_rect
)
3720 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
3721 XRectangle
*clip_rect
;
3727 gc
= f
->output_data
.x
->white_relief
.gc
;
3729 gc
= f
->output_data
.x
->black_relief
.gc
;
3730 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3733 for (i
= 0; i
< width
; ++i
)
3734 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3735 left_x
+ i
* left_p
, top_y
+ i
,
3736 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3740 for (i
= 0; i
< width
; ++i
)
3741 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3742 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
);
3744 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3746 gc
= f
->output_data
.x
->black_relief
.gc
;
3748 gc
= f
->output_data
.x
->white_relief
.gc
;
3749 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3752 for (i
= 0; i
< width
; ++i
)
3753 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3754 left_x
+ i
* left_p
, bottom_y
- i
,
3755 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3759 for (i
= 0; i
< width
; ++i
)
3760 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3761 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3763 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3767 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3768 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3769 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3770 left side of the rectangle. RIGHT_P non-zero means draw a line
3771 on the right side of the rectangle. CLIP_RECT is the clipping
3772 rectangle to use when drawing. */
3775 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3776 left_p
, right_p
, clip_rect
)
3777 struct glyph_string
*s
;
3778 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
;
3779 XRectangle
*clip_rect
;
3783 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3784 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
3785 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
3788 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3789 left_x
, top_y
, right_x
- left_x
+ 1, width
);
3793 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3794 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
3797 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3798 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
3802 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3803 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
3805 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3806 XSetClipMask (s
->display
, s
->gc
, None
);
3810 /* Draw a box around glyph string S. */
3813 x_draw_glyph_string_box (s
)
3814 struct glyph_string
*s
;
3816 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3817 int left_p
, right_p
;
3818 struct glyph
*last_glyph
;
3819 XRectangle clip_rect
;
3821 last_x
= window_box_right (s
->w
, s
->area
);
3822 if (s
->row
->full_width_p
3823 && !s
->w
->pseudo_window_p
)
3825 last_x
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (s
->f
);
3826 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
3827 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
3830 /* The glyph that may have a right box line. */
3831 last_glyph
= (s
->cmp
|| s
->img
3833 : s
->first_glyph
+ s
->nchars
- 1);
3835 width
= abs (s
->face
->box_line_width
);
3836 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
3838 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
3840 : min (last_x
, s
->x
+ s
->background_width
) - 1);
3842 bottom_y
= top_y
+ s
->height
- 1;
3844 left_p
= (s
->first_glyph
->left_box_line_p
3845 || (s
->hl
== DRAW_MOUSE_FACE
3847 || s
->prev
->hl
!= s
->hl
)));
3848 right_p
= (last_glyph
->right_box_line_p
3849 || (s
->hl
== DRAW_MOUSE_FACE
3851 || s
->next
->hl
!= s
->hl
)));
3853 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3855 if (s
->face
->box
== FACE_SIMPLE_BOX
)
3856 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3857 left_p
, right_p
, &clip_rect
);
3860 x_setup_relief_colors (s
);
3861 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
3862 width
, raised_p
, left_p
, right_p
, &clip_rect
);
3867 /* Draw foreground of image glyph string S. */
3870 x_draw_image_foreground (s
)
3871 struct glyph_string
*s
;
3874 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3876 /* If first glyph of S has a left box line, start drawing it to the
3877 right of that line. */
3878 if (s
->face
->box
!= FACE_NO_BOX
3879 && s
->first_glyph
->left_box_line_p
)
3880 x
= s
->x
+ abs (s
->face
->box_line_width
);
3884 /* If there is a margin around the image, adjust x- and y-position
3886 x
+= s
->img
->hmargin
;
3887 y
+= s
->img
->vmargin
;
3893 /* We can't set both a clip mask and use XSetClipRectangles
3894 because the latter also sets a clip mask. We also can't
3895 trust on the shape extension to be available
3896 (XShapeCombineRegion). So, compute the rectangle to draw
3898 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3901 XRectangle clip_rect
, image_rect
, r
;
3903 xgcv
.clip_mask
= s
->img
->mask
;
3904 xgcv
.clip_x_origin
= x
;
3905 xgcv
.clip_y_origin
= y
;
3906 xgcv
.function
= GXcopy
;
3907 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3909 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3912 image_rect
.width
= s
->img
->width
;
3913 image_rect
.height
= s
->img
->height
;
3914 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
3915 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3916 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3920 unsigned long mask
= GCClipXOrigin
| GCClipYOrigin
| GCFunction
;
3922 XRectangle clip_rect
, image_rect
, r
;
3924 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3927 image_rect
.width
= s
->img
->width
;
3928 image_rect
.height
= s
->img
->height
;
3929 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
3930 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3931 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3933 /* When the image has a mask, we can expect that at
3934 least part of a mouse highlight or a block cursor will
3935 be visible. If the image doesn't have a mask, make
3936 a block cursor visible by drawing a rectangle around
3937 the image. I believe it's looking better if we do
3938 nothing here for mouse-face. */
3939 if (s
->hl
== DRAW_CURSOR
)
3940 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3941 s
->img
->width
- 1, s
->img
->height
- 1);
3945 /* Draw a rectangle if image could not be loaded. */
3946 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3947 s
->img
->width
- 1, s
->img
->height
- 1);
3951 /* Draw a relief around the image glyph string S. */
3954 x_draw_image_relief (s
)
3955 struct glyph_string
*s
;
3957 int x0
, y0
, x1
, y1
, thick
, raised_p
;
3960 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3962 /* If first glyph of S has a left box line, start drawing it to the
3963 right of that line. */
3964 if (s
->face
->box
!= FACE_NO_BOX
3965 && s
->first_glyph
->left_box_line_p
)
3966 x
= s
->x
+ abs (s
->face
->box_line_width
);
3970 /* If there is a margin around the image, adjust x- and y-position
3972 x
+= s
->img
->hmargin
;
3973 y
+= s
->img
->vmargin
;
3975 if (s
->hl
== DRAW_IMAGE_SUNKEN
3976 || s
->hl
== DRAW_IMAGE_RAISED
)
3978 thick
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
3979 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
3983 thick
= abs (s
->img
->relief
);
3984 raised_p
= s
->img
->relief
> 0;
3989 x1
= x
+ s
->img
->width
+ thick
- 1;
3990 y1
= y
+ s
->img
->height
+ thick
- 1;
3992 x_setup_relief_colors (s
);
3993 x_get_glyph_string_clip_rect (s
, &r
);
3994 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
3998 /* Draw the foreground of image glyph string S to PIXMAP. */
4001 x_draw_image_foreground_1 (s
, pixmap
)
4002 struct glyph_string
*s
;
4006 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
4008 /* If first glyph of S has a left box line, start drawing it to the
4009 right of that line. */
4010 if (s
->face
->box
!= FACE_NO_BOX
4011 && s
->first_glyph
->left_box_line_p
)
4012 x
= abs (s
->face
->box_line_width
);
4016 /* If there is a margin around the image, adjust x- and y-position
4018 x
+= s
->img
->hmargin
;
4019 y
+= s
->img
->vmargin
;
4025 /* We can't set both a clip mask and use XSetClipRectangles
4026 because the latter also sets a clip mask. We also can't
4027 trust on the shape extension to be available
4028 (XShapeCombineRegion). So, compute the rectangle to draw
4030 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4034 xgcv
.clip_mask
= s
->img
->mask
;
4035 xgcv
.clip_x_origin
= x
;
4036 xgcv
.clip_y_origin
= y
;
4037 xgcv
.function
= GXcopy
;
4038 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4040 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4041 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4042 XSetClipMask (s
->display
, s
->gc
, None
);
4046 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4047 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4049 /* When the image has a mask, we can expect that at
4050 least part of a mouse highlight or a block cursor will
4051 be visible. If the image doesn't have a mask, make
4052 a block cursor visible by drawing a rectangle around
4053 the image. I believe it's looking better if we do
4054 nothing here for mouse-face. */
4055 if (s
->hl
== DRAW_CURSOR
)
4056 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
4057 s
->img
->width
- 1, s
->img
->height
- 1);
4061 /* Draw a rectangle if image could not be loaded. */
4062 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
4063 s
->img
->width
- 1, s
->img
->height
- 1);
4067 /* Draw part of the background of glyph string S. X, Y, W, and H
4068 give the rectangle to draw. */
4071 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
4072 struct glyph_string
*s
;
4077 /* Fill background with a stipple pattern. */
4078 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4079 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
4080 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4083 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
4087 /* Draw image glyph string S.
4090 s->x +-------------------------
4093 | +-------------------------
4096 | | +-------------------
4102 x_draw_image_glyph_string (s
)
4103 struct glyph_string
*s
;
4106 int box_line_hwidth
= abs (s
->face
->box_line_width
);
4107 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
4109 Pixmap pixmap
= None
;
4111 height
= s
->height
- 2 * box_line_vwidth
;
4113 /* Fill background with face under the image. Do it only if row is
4114 taller than image or if image has a clip mask to reduce
4116 s
->stippled_p
= s
->face
->stipple
!= 0;
4117 if (height
> s
->img
->height
4121 || s
->img
->pixmap
== 0
4122 || s
->width
!= s
->background_width
)
4124 if (box_line_hwidth
&& s
->first_glyph
->left_box_line_p
)
4125 x
= s
->x
+ box_line_hwidth
;
4129 y
= s
->y
+ box_line_vwidth
;
4133 /* Create a pixmap as large as the glyph string. Fill it
4134 with the background color. Copy the image to it, using
4135 its mask. Copy the temporary pixmap to the display. */
4136 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
4137 int depth
= DefaultDepthOfScreen (screen
);
4139 /* Create a pixmap as large as the glyph string. */
4140 pixmap
= XCreatePixmap (s
->display
, s
->window
,
4141 s
->background_width
,
4144 /* Don't clip in the following because we're working on the
4146 XSetClipMask (s
->display
, s
->gc
, None
);
4148 /* Fill the pixmap with the background color/stipple. */
4151 /* Fill background with a stipple pattern. */
4152 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4153 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4154 0, 0, s
->background_width
, s
->height
);
4155 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4160 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
4162 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
4163 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4164 0, 0, s
->background_width
, s
->height
);
4165 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4169 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
4171 s
->background_filled_p
= 1;
4174 /* Draw the foreground. */
4177 x_draw_image_foreground_1 (s
, pixmap
);
4178 x_set_glyph_string_clipping (s
);
4179 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
4180 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
4181 XFreePixmap (s
->display
, pixmap
);
4184 x_draw_image_foreground (s
);
4186 /* If we must draw a relief around the image, do it. */
4188 || s
->hl
== DRAW_IMAGE_RAISED
4189 || s
->hl
== DRAW_IMAGE_SUNKEN
)
4190 x_draw_image_relief (s
);
4194 /* Draw stretch glyph string S. */
4197 x_draw_stretch_glyph_string (s
)
4198 struct glyph_string
*s
;
4200 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4201 s
->stippled_p
= s
->face
->stipple
!= 0;
4203 if (s
->hl
== DRAW_CURSOR
4204 && !x_stretch_cursor_p
)
4206 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
4207 as wide as the stretch glyph. */
4208 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
4211 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
4213 /* Clear rest using the GC of the original non-cursor face. */
4214 if (width
< s
->background_width
)
4216 GC gc
= s
->face
->gc
;
4217 int x
= s
->x
+ width
, y
= s
->y
;
4218 int w
= s
->background_width
- width
, h
= s
->height
;
4221 x_get_glyph_string_clip_rect (s
, &r
);
4222 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
4224 if (s
->face
->stipple
)
4226 /* Fill background with a stipple pattern. */
4227 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
4228 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4229 XSetFillStyle (s
->display
, gc
, FillSolid
);
4234 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
4235 XSetForeground (s
->display
, gc
, xgcv
.background
);
4236 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4237 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
4242 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
4245 s
->background_filled_p
= 1;
4249 /* Draw glyph string S. */
4252 x_draw_glyph_string (s
)
4253 struct glyph_string
*s
;
4255 /* If S draws into the background of its successor, draw the
4256 background of the successor first so that S can draw into it.
4257 This makes S->next use XDrawString instead of XDrawImageString. */
4258 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4260 xassert (s
->next
->img
== NULL
);
4261 x_set_glyph_string_gc (s
->next
);
4262 x_set_glyph_string_clipping (s
->next
);
4263 x_draw_glyph_string_background (s
->next
, 1);
4266 /* Set up S->gc, set clipping and draw S. */
4267 x_set_glyph_string_gc (s
);
4268 x_set_glyph_string_clipping (s
);
4270 switch (s
->first_glyph
->type
)
4273 x_draw_image_glyph_string (s
);
4277 x_draw_stretch_glyph_string (s
);
4281 if (s
->for_overlaps_p
)
4282 s
->background_filled_p
= 1;
4284 x_draw_glyph_string_background (s
, 0);
4285 x_draw_glyph_string_foreground (s
);
4288 case COMPOSITE_GLYPH
:
4289 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4290 s
->background_filled_p
= 1;
4292 x_draw_glyph_string_background (s
, 1);
4293 x_draw_composite_glyph_string_foreground (s
);
4300 if (!s
->for_overlaps_p
)
4302 /* Draw underline. */
4303 if (s
->face
->underline_p
)
4305 unsigned long tem
, h
;
4308 /* Get the underline thickness. Default is 1 pixel. */
4309 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
4312 /* Get the underline position. This is the recommended
4313 vertical offset in pixels from the baseline to the top of
4314 the underline. This is a signed value according to the
4315 specs, and its default is
4317 ROUND ((maximum descent) / 2), with
4318 ROUND(x) = floor (x + 0.5) */
4320 if (XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &tem
))
4321 y
= s
->ybase
+ (long) tem
;
4322 else if (s
->face
->font
)
4323 y
= s
->ybase
+ (s
->face
->font
->max_bounds
.descent
+ 1) / 2;
4327 if (s
->face
->underline_defaulted_p
)
4328 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4329 s
->x
, y
, s
->width
, h
);
4333 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4334 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
4335 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4336 s
->x
, y
, s
->width
, h
);
4337 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4341 /* Draw overline. */
4342 if (s
->face
->overline_p
)
4344 unsigned long dy
= 0, h
= 1;
4346 if (s
->face
->overline_color_defaulted_p
)
4347 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4352 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4353 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
4354 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4356 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4360 /* Draw strike-through. */
4361 if (s
->face
->strike_through_p
)
4363 unsigned long h
= 1;
4364 unsigned long dy
= (s
->height
- h
) / 2;
4366 if (s
->face
->strike_through_color_defaulted_p
)
4367 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4372 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4373 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
4374 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4376 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4381 if (s
->face
->box
!= FACE_NO_BOX
)
4382 x_draw_glyph_string_box (s
);
4385 /* Reset clipping. */
4386 XSetClipMask (s
->display
, s
->gc
, None
);
4390 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4391 struct face
**, int));
4394 /* Fill glyph string S with composition components specified by S->cmp.
4396 FACES is an array of faces for all components of this composition.
4397 S->gidx is the index of the first component for S.
4398 OVERLAPS_P non-zero means S should draw the foreground only, and
4399 use its physical height for clipping.
4401 Value is the index of a component not in S. */
4404 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4405 struct glyph_string
*s
;
4406 struct face
**faces
;
4413 s
->for_overlaps_p
= overlaps_p
;
4415 s
->face
= faces
[s
->gidx
];
4416 s
->font
= s
->face
->font
;
4417 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4419 /* For all glyphs of this composition, starting at the offset
4420 S->gidx, until we reach the end of the definition or encounter a
4421 glyph that requires the different face, add it to S. */
4423 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4426 /* All glyph strings for the same composition has the same width,
4427 i.e. the width set for the first component of the composition. */
4429 s
->width
= s
->first_glyph
->pixel_width
;
4431 /* If the specified font could not be loaded, use the frame's
4432 default font, but record the fact that we couldn't load it in
4433 the glyph string so that we can draw rectangles for the
4434 characters of the glyph string. */
4435 if (s
->font
== NULL
)
4437 s
->font_not_found_p
= 1;
4438 s
->font
= FRAME_FONT (s
->f
);
4441 /* Adjust base line for subscript/superscript text. */
4442 s
->ybase
+= s
->first_glyph
->voffset
;
4444 xassert (s
->face
&& s
->face
->gc
);
4446 /* This glyph string must always be drawn with 16-bit functions. */
4449 return s
->gidx
+ s
->nchars
;
4453 /* Fill glyph string S from a sequence of character glyphs.
4455 FACE_ID is the face id of the string. START is the index of the
4456 first glyph to consider, END is the index of the last + 1.
4457 OVERLAPS_P non-zero means S should draw the foreground only, and
4458 use its physical height for clipping.
4460 Value is the index of the first glyph not in S. */
4463 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4464 struct glyph_string
*s
;
4466 int start
, end
, overlaps_p
;
4468 struct glyph
*glyph
, *last
;
4470 int glyph_not_available_p
;
4472 xassert (s
->f
== XFRAME (s
->w
->frame
));
4473 xassert (s
->nchars
== 0);
4474 xassert (start
>= 0 && end
> start
);
4476 s
->for_overlaps_p
= overlaps_p
,
4477 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4478 last
= s
->row
->glyphs
[s
->area
] + end
;
4479 voffset
= glyph
->voffset
;
4481 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4484 && glyph
->type
== CHAR_GLYPH
4485 && glyph
->voffset
== voffset
4486 /* Same face id implies same font, nowadays. */
4487 && glyph
->face_id
== face_id
4488 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4492 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4493 s
->char2b
+ s
->nchars
,
4495 s
->two_byte_p
= two_byte_p
;
4497 xassert (s
->nchars
<= end
- start
);
4498 s
->width
+= glyph
->pixel_width
;
4502 s
->font
= s
->face
->font
;
4503 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4505 /* If the specified font could not be loaded, use the frame's font,
4506 but record the fact that we couldn't load it in
4507 S->font_not_found_p so that we can draw rectangles for the
4508 characters of the glyph string. */
4509 if (s
->font
== NULL
|| glyph_not_available_p
)
4511 s
->font_not_found_p
= 1;
4512 s
->font
= FRAME_FONT (s
->f
);
4515 /* Adjust base line for subscript/superscript text. */
4516 s
->ybase
+= voffset
;
4518 xassert (s
->face
&& s
->face
->gc
);
4519 return glyph
- s
->row
->glyphs
[s
->area
];
4523 /* Fill glyph string S from image glyph S->first_glyph. */
4526 x_fill_image_glyph_string (s
)
4527 struct glyph_string
*s
;
4529 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4530 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
4532 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4533 s
->font
= s
->face
->font
;
4534 s
->width
= s
->first_glyph
->pixel_width
;
4536 /* Adjust base line for subscript/superscript text. */
4537 s
->ybase
+= s
->first_glyph
->voffset
;
4541 /* Fill glyph string S from a sequence of stretch glyphs.
4543 ROW is the glyph row in which the glyphs are found, AREA is the
4544 area within the row. START is the index of the first glyph to
4545 consider, END is the index of the last + 1.
4547 Value is the index of the first glyph not in S. */
4550 x_fill_stretch_glyph_string (s
, row
, area
, start
, end
)
4551 struct glyph_string
*s
;
4552 struct glyph_row
*row
;
4553 enum glyph_row_area area
;
4556 struct glyph
*glyph
, *last
;
4557 int voffset
, face_id
;
4559 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4561 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4562 last
= s
->row
->glyphs
[s
->area
] + end
;
4563 face_id
= glyph
->face_id
;
4564 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
4565 s
->font
= s
->face
->font
;
4566 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4567 s
->width
= glyph
->pixel_width
;
4568 voffset
= glyph
->voffset
;
4572 && glyph
->type
== STRETCH_GLYPH
4573 && glyph
->voffset
== voffset
4574 && glyph
->face_id
== face_id
);
4576 s
->width
+= glyph
->pixel_width
;
4578 /* Adjust base line for subscript/superscript text. */
4579 s
->ybase
+= voffset
;
4581 xassert (s
->face
&& s
->face
->gc
);
4582 return glyph
- s
->row
->glyphs
[s
->area
];
4586 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4587 of XChar2b structures for S; it can't be allocated in
4588 x_init_glyph_string because it must be allocated via `alloca'. W
4589 is the window on which S is drawn. ROW and AREA are the glyph row
4590 and area within the row from which S is constructed. START is the
4591 index of the first glyph structure covered by S. HL is a
4592 face-override for drawing S. */
4595 x_init_glyph_string (s
, char2b
, w
, row
, area
, start
, hl
)
4596 struct glyph_string
*s
;
4599 struct glyph_row
*row
;
4600 enum glyph_row_area area
;
4602 enum draw_glyphs_face hl
;
4604 bzero (s
, sizeof *s
);
4606 s
->f
= XFRAME (w
->frame
);
4607 s
->display
= FRAME_X_DISPLAY (s
->f
);
4608 s
->window
= FRAME_X_WINDOW (s
->f
);
4613 s
->first_glyph
= row
->glyphs
[area
] + start
;
4614 s
->height
= row
->height
;
4615 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4617 /* Display the internal border below the tool-bar window. */
4618 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4619 s
->y
-= s
->f
->output_data
.x
->internal_border_width
;
4621 s
->ybase
= s
->y
+ row
->ascent
;
4625 /* Set background width of glyph string S. START is the index of the
4626 first glyph following S. LAST_X is the right-most x-position + 1
4627 in the drawing area. */
4630 x_set_glyph_string_background_width (s
, start
, last_x
)
4631 struct glyph_string
*s
;
4635 /* If the face of this glyph string has to be drawn to the end of
4636 the drawing area, set S->extends_to_end_of_line_p. */
4637 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4639 if (start
== s
->row
->used
[s
->area
]
4640 && s
->hl
== DRAW_NORMAL_TEXT
4641 && s
->area
== TEXT_AREA
4642 && (s
->row
->fill_line_p
4643 || s
->face
->background
!= default_face
->background
4644 || s
->face
->stipple
!= default_face
->stipple
))
4645 s
->extends_to_end_of_line_p
= 1;
4647 /* If S extends its face to the end of the line, set its
4648 background_width to the distance to the right edge of the drawing
4650 if (s
->extends_to_end_of_line_p
)
4651 s
->background_width
= last_x
- s
->x
+ 1;
4653 s
->background_width
= s
->width
;
4657 /* Add a glyph string for a stretch glyph to the list of strings
4658 between HEAD and TAIL. START is the index of the stretch glyph in
4659 row area AREA of glyph row ROW. END is the index of the last glyph
4660 in that glyph row area. X is the current output position assigned
4661 to the new glyph string constructed. HL overrides that face of the
4662 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4663 is the right-most x-position of the drawing area. */
4665 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
4666 and below -- keep them on one line. */
4667 #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4670 s = (struct glyph_string *) alloca (sizeof *s); \
4671 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4672 START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \
4673 x_append_glyph_string (&HEAD, &TAIL, s); \
4679 /* Add a glyph string for an image glyph to the list of strings
4680 between HEAD and TAIL. START is the index of the image glyph in
4681 row area AREA of glyph row ROW. END is the index of the last glyph
4682 in that glyph row area. X is the current output position assigned
4683 to the new glyph string constructed. HL overrides that face of the
4684 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4685 is the right-most x-position of the drawing area. */
4687 #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4690 s = (struct glyph_string *) alloca (sizeof *s); \
4691 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4692 x_fill_image_glyph_string (s); \
4693 x_append_glyph_string (&HEAD, &TAIL, s); \
4700 /* Add a glyph string for a sequence of character glyphs to the list
4701 of strings between HEAD and TAIL. START is the index of the first
4702 glyph in row area AREA of glyph row ROW that is part of the new
4703 glyph string. END is the index of the last glyph in that glyph row
4704 area. X is the current output position assigned to the new glyph
4705 string constructed. HL overrides that face of the glyph; e.g. it
4706 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4707 right-most x-position of the drawing area. */
4709 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4715 c = (ROW)->glyphs[AREA][START].u.ch; \
4716 face_id = (ROW)->glyphs[AREA][START].face_id; \
4718 s = (struct glyph_string *) alloca (sizeof *s); \
4719 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
4720 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4721 x_append_glyph_string (&HEAD, &TAIL, s); \
4723 START = x_fill_glyph_string (s, face_id, START, END, \
4729 /* Add a glyph string for a composite sequence to the list of strings
4730 between HEAD and TAIL. START is the index of the first glyph in
4731 row area AREA of glyph row ROW that is part of the new glyph
4732 string. END is the index of the last glyph in that glyph row area.
4733 X is the current output position assigned to the new glyph string
4734 constructed. HL overrides that face of the glyph; e.g. it is
4735 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
4736 x-position of the drawing area. */
4738 #define BUILD_COMPOSITE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4740 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
4741 int face_id = (ROW)->glyphs[AREA][START].face_id; \
4742 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
4743 struct composition *cmp = composition_table[cmp_id]; \
4744 int glyph_len = cmp->glyph_len; \
4746 struct face **faces; \
4747 struct glyph_string *first_s = NULL; \
4750 base_face = base_face->ascii_face; \
4751 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
4752 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
4753 /* At first, fill in `char2b' and `faces'. */ \
4754 for (n = 0; n < glyph_len; n++) \
4756 int c = COMPOSITION_GLYPH (cmp, n); \
4757 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
4758 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
4759 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
4760 this_face_id, char2b + n, 1); \
4763 /* Make glyph_strings for each glyph sequence that is drawable by \
4764 the same face, and append them to HEAD/TAIL. */ \
4765 for (n = 0; n < cmp->glyph_len;) \
4767 s = (struct glyph_string *) alloca (sizeof *s); \
4768 x_init_glyph_string (s, char2b + n, W, ROW, AREA, START, HL); \
4769 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4777 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
4785 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4786 of AREA of glyph row ROW on window W between indices START and END.
4787 HL overrides the face for drawing glyph strings, e.g. it is
4788 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4789 x-positions of the drawing area.
4791 This is an ugly monster macro construct because we must use alloca
4792 to allocate glyph strings (because x_draw_glyphs can be called
4795 #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4798 HEAD = TAIL = NULL; \
4799 while (START < END) \
4801 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
4802 switch (first_glyph->type) \
4805 BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \
4806 TAIL, HL, X, LAST_X, \
4810 case COMPOSITE_GLYPH: \
4811 BUILD_COMPOSITE_GLYPH_STRING (W, ROW, AREA, START, END, \
4812 HEAD, TAIL, HL, X, LAST_X,\
4816 case STRETCH_GLYPH: \
4817 BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \
4818 HEAD, TAIL, HL, X, LAST_X); \
4822 BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \
4823 TAIL, HL, X, LAST_X); \
4830 x_set_glyph_string_background_width (s, START, LAST_X); \
4837 /* Draw glyphs between START and END in AREA of ROW on window W,
4838 starting at x-position X. X is relative to AREA in W. HL is a
4839 face-override with the following meaning:
4841 DRAW_NORMAL_TEXT draw normally
4842 DRAW_CURSOR draw in cursor face
4843 DRAW_MOUSE_FACE draw in mouse face.
4844 DRAW_INVERSE_VIDEO draw in mode line face
4845 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
4846 DRAW_IMAGE_RAISED draw an image with a raised relief around it
4848 If REAL_START is non-null, return in *REAL_START the real starting
4849 position for display. This can be different from START in case
4850 overlapping glyphs must be displayed. If REAL_END is non-null,
4851 return in *REAL_END the real end position for display. This can be
4852 different from END in case overlapping glyphs must be displayed.
4854 If OVERLAPS_P is non-zero, draw only the foreground of characters
4855 and clip to the physical height of ROW.
4857 Value is the x-position reached, relative to AREA of W. */
4860 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, real_start
, real_end
,
4864 struct glyph_row
*row
;
4865 enum glyph_row_area area
;
4867 enum draw_glyphs_face hl
;
4868 int *real_start
, *real_end
;
4871 struct glyph_string
*head
, *tail
;
4872 struct glyph_string
*s
;
4873 int last_x
, area_width
;
4877 /* Let's rather be paranoid than getting a SEGV. */
4878 end
= min (end
, row
->used
[area
]);
4879 start
= max (0, start
);
4880 start
= min (end
, start
);
4882 *real_start
= start
;
4886 /* Translate X to frame coordinates. Set last_x to the right
4887 end of the drawing area. */
4888 if (row
->full_width_p
)
4890 /* X is relative to the left edge of W, without scroll bars
4892 struct frame
*f
= XFRAME (w
->frame
);
4893 /* int width = FRAME_FLAGS_AREA_WIDTH (f); */
4894 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
4897 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4898 last_x
= window_left_x
+ area_width
;
4900 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4902 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4903 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4909 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
4910 last_x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
4914 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
4915 area_width
= window_box_width (w
, area
);
4916 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
4919 /* Build a doubly-linked list of glyph_string structures between
4920 head and tail from what we have to draw. Note that the macro
4921 BUILD_GLYPH_STRINGS will modify its start parameter. That's
4922 the reason we use a separate variable `i'. */
4924 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
4927 x_reached
= tail
->x
+ tail
->background_width
;
4931 /* If there are any glyphs with lbearing < 0 or rbearing > width in
4932 the row, redraw some glyphs in front or following the glyph
4933 strings built above. */
4934 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
4937 struct glyph_string
*h
, *t
;
4939 /* Compute overhangs for all glyph strings. */
4940 for (s
= head
; s
; s
= s
->next
)
4941 x_compute_glyph_string_overhangs (s
);
4943 /* Prepend glyph strings for glyphs in front of the first glyph
4944 string that are overwritten because of the first glyph
4945 string's left overhang. The background of all strings
4946 prepended must be drawn because the first glyph string
4948 i
= x_left_overwritten (head
);
4952 BUILD_GLYPH_STRINGS (w
, row
, area
, j
, start
, h
, t
,
4953 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4957 *real_start
= start
;
4958 x_compute_overhangs_and_x (t
, head
->x
, 1);
4959 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4962 /* Prepend glyph strings for glyphs in front of the first glyph
4963 string that overwrite that glyph string because of their
4964 right overhang. For these strings, only the foreground must
4965 be drawn, because it draws over the glyph string at `head'.
4966 The background must not be drawn because this would overwrite
4967 right overhangs of preceding glyphs for which no glyph
4969 i
= x_left_overwriting (head
);
4972 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, start
, h
, t
,
4973 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4975 for (s
= h
; s
; s
= s
->next
)
4976 s
->background_filled_p
= 1;
4979 x_compute_overhangs_and_x (t
, head
->x
, 1);
4980 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4983 /* Append glyphs strings for glyphs following the last glyph
4984 string tail that are overwritten by tail. The background of
4985 these strings has to be drawn because tail's foreground draws
4987 i
= x_right_overwritten (tail
);
4990 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4991 DRAW_NORMAL_TEXT
, x
, last_x
,
4993 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4994 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
4999 /* Append glyph strings for glyphs following the last glyph
5000 string tail that overwrite tail. The foreground of such
5001 glyphs has to be drawn because it writes into the background
5002 of tail. The background must not be drawn because it could
5003 paint over the foreground of following glyphs. */
5004 i
= x_right_overwriting (tail
);
5007 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
5008 DRAW_NORMAL_TEXT
, x
, last_x
,
5010 for (s
= h
; s
; s
= s
->next
)
5011 s
->background_filled_p
= 1;
5012 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
5013 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
5019 /* Draw all strings. */
5020 for (s
= head
; s
; s
= s
->next
)
5021 x_draw_glyph_string (s
);
5023 /* Value is the x-position up to which drawn, relative to AREA of W.
5024 This doesn't include parts drawn because of overhangs. */
5025 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
5026 if (!row
->full_width_p
)
5028 if (area
> LEFT_MARGIN_AREA
)
5029 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
5030 if (area
> TEXT_AREA
)
5031 x_reached
-= window_box_width (w
, TEXT_AREA
);
5038 /* Fix the display of area AREA of overlapping row ROW in window W. */
5041 x_fix_overlapping_area (w
, row
, area
)
5043 struct glyph_row
*row
;
5044 enum glyph_row_area area
;
5050 if (area
== LEFT_MARGIN_AREA
)
5052 else if (area
== TEXT_AREA
)
5053 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5055 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5056 + window_box_width (w
, TEXT_AREA
));
5058 for (i
= 0; i
< row
->used
[area
];)
5060 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
5062 int start
= i
, start_x
= x
;
5066 x
+= row
->glyphs
[area
][i
].pixel_width
;
5069 while (i
< row
->used
[area
]
5070 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
5072 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
5074 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
5079 x
+= row
->glyphs
[area
][i
].pixel_width
;
5088 /* Output LEN glyphs starting at START at the nominal cursor position.
5089 Advance the nominal cursor over the text. The global variable
5090 updated_window contains the window being updated, updated_row is
5091 the glyph row being updated, and updated_area is the area of that
5092 row being updated. */
5095 x_write_glyphs (start
, len
)
5096 struct glyph
*start
;
5099 int x
, hpos
, real_start
, real_end
;
5101 xassert (updated_window
&& updated_row
);
5106 hpos
= start
- updated_row
->glyphs
[updated_area
];
5107 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
5108 updated_row
, updated_area
,
5110 (updated_row
->inverse_p
5111 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
5112 &real_start
, &real_end
, 0);
5114 /* If we drew over the cursor, note that it is not visible any more. */
5115 note_overwritten_text_cursor (updated_window
, real_start
,
5116 real_end
- real_start
);
5120 /* Advance the output cursor. */
5121 output_cursor
.hpos
+= len
;
5122 output_cursor
.x
= x
;
5126 /* Insert LEN glyphs from START at the nominal cursor position. */
5129 x_insert_glyphs (start
, len
)
5130 struct glyph
*start
;
5135 int line_height
, shift_by_width
, shifted_region_width
;
5136 struct glyph_row
*row
;
5137 struct glyph
*glyph
;
5138 int frame_x
, frame_y
, hpos
, real_start
, real_end
;
5140 xassert (updated_window
&& updated_row
);
5143 f
= XFRAME (WINDOW_FRAME (w
));
5145 /* Get the height of the line we are in. */
5147 line_height
= row
->height
;
5149 /* Get the width of the glyphs to insert. */
5151 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
5152 shift_by_width
+= glyph
->pixel_width
;
5154 /* Get the width of the region to shift right. */
5155 shifted_region_width
= (window_box_width (w
, updated_area
)
5160 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
5161 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
5162 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5163 f
->output_data
.x
->normal_gc
,
5165 shifted_region_width
, line_height
,
5166 frame_x
+ shift_by_width
, frame_y
);
5168 /* Write the glyphs. */
5169 hpos
= start
- row
->glyphs
[updated_area
];
5170 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
5171 DRAW_NORMAL_TEXT
, &real_start
, &real_end
, 0);
5172 note_overwritten_text_cursor (w
, real_start
, real_end
- real_start
);
5174 /* Advance the output cursor. */
5175 output_cursor
.hpos
+= len
;
5176 output_cursor
.x
+= shift_by_width
;
5181 /* Delete N glyphs at the nominal cursor position. Not implemented
5192 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
5193 If they are <= 0, this is probably an error. */
5196 x_clear_area (dpy
, window
, x
, y
, width
, height
, exposures
)
5203 xassert (width
> 0 && height
> 0);
5204 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
5208 /* Erase the current text line from the nominal cursor position
5209 (inclusive) to pixel column TO_X (exclusive). The idea is that
5210 everything from TO_X onward is already erased.
5212 TO_X is a pixel position relative to updated_area of
5213 updated_window. TO_X == -1 means clear to the end of this area. */
5216 x_clear_end_of_line (to_x
)
5220 struct window
*w
= updated_window
;
5221 int max_x
, min_y
, max_y
;
5222 int from_x
, from_y
, to_y
;
5224 xassert (updated_window
&& updated_row
);
5225 f
= XFRAME (w
->frame
);
5227 if (updated_row
->full_width_p
)
5229 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5230 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5231 && !w
->pseudo_window_p
)
5232 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5235 max_x
= window_box_width (w
, updated_area
);
5236 max_y
= window_text_bottom_y (w
);
5238 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
5239 of window. For TO_X > 0, truncate to end of drawing area. */
5245 to_x
= min (to_x
, max_x
);
5247 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
5249 /* Notice if the cursor will be cleared by this operation. */
5250 if (!updated_row
->full_width_p
)
5251 note_overwritten_text_cursor (w
, output_cursor
.hpos
, -1);
5253 from_x
= output_cursor
.x
;
5255 /* Translate to frame coordinates. */
5256 if (updated_row
->full_width_p
)
5258 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
5259 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
5263 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
5264 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
5267 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
5268 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
5269 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
5271 /* Prevent inadvertently clearing to end of the X window. */
5272 if (to_x
> from_x
&& to_y
> from_y
)
5275 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5276 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
5283 /* Clear entire frame. If updating_frame is non-null, clear that
5284 frame. Otherwise clear the selected frame. */
5294 f
= SELECTED_FRAME ();
5296 /* Clearing the frame will erase any cursor, so mark them all as no
5298 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5299 output_cursor
.hpos
= output_cursor
.vpos
= 0;
5300 output_cursor
.x
= -1;
5302 /* We don't set the output cursor here because there will always
5303 follow an explicit cursor_to. */
5305 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5307 /* We have to clear the scroll bars, too. If we have changed
5308 colors or something like that, then they should be notified. */
5309 x_scroll_bar_clear (f
);
5311 XFlush (FRAME_X_DISPLAY (f
));
5317 /* Invert the middle quarter of the frame for .15 sec. */
5319 /* We use the select system call to do the waiting, so we have to make
5320 sure it's available. If it isn't, we just won't do visual bells. */
5322 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5325 /* Subtract the `struct timeval' values X and Y, storing the result in
5326 *RESULT. Return 1 if the difference is negative, otherwise 0. */
5329 timeval_subtract (result
, x
, y
)
5330 struct timeval
*result
, x
, y
;
5332 /* Perform the carry for the later subtraction by updating y. This
5333 is safer because on some systems the tv_sec member is unsigned. */
5334 if (x
.tv_usec
< y
.tv_usec
)
5336 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
5337 y
.tv_usec
-= 1000000 * nsec
;
5341 if (x
.tv_usec
- y
.tv_usec
> 1000000)
5343 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
5344 y
.tv_usec
+= 1000000 * nsec
;
5348 /* Compute the time remaining to wait. tv_usec is certainly
5350 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
5351 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
5353 /* Return indication of whether the result should be considered
5355 return x
.tv_sec
< y
.tv_sec
;
5367 /* Create a GC that will use the GXxor function to flip foreground
5368 pixels into background pixels. */
5372 values
.function
= GXxor
;
5373 values
.foreground
= (f
->output_data
.x
->foreground_pixel
5374 ^ f
->output_data
.x
->background_pixel
);
5376 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5377 GCFunction
| GCForeground
, &values
);
5381 /* Get the height not including a menu bar widget. */
5382 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
5383 /* Height of each line to flash. */
5384 int flash_height
= FRAME_LINE_HEIGHT (f
);
5385 /* These will be the left and right margins of the rectangles. */
5386 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
5387 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
5391 /* Don't flash the area between a scroll bar and the frame
5392 edge it is next to. */
5393 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
5395 case vertical_scroll_bar_left
:
5396 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5399 case vertical_scroll_bar_right
:
5400 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5407 width
= flash_right
- flash_left
;
5409 /* If window is tall, flash top and bottom line. */
5410 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5412 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5414 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5415 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5416 width
, flash_height
);
5417 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5419 (height
- flash_height
5420 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5421 width
, flash_height
);
5424 /* If it is short, flash it all. */
5425 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5426 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5427 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5432 struct timeval wakeup
;
5434 EMACS_GET_TIME (wakeup
);
5436 /* Compute time to wait until, propagating carry from usecs. */
5437 wakeup
.tv_usec
+= 150000;
5438 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
5439 wakeup
.tv_usec
%= 1000000;
5441 /* Keep waiting until past the time wakeup or any input gets
5443 while (! detect_input_pending ())
5445 struct timeval current
;
5446 struct timeval timeout
;
5448 EMACS_GET_TIME (current
);
5450 /* Break if result would be negative. */
5451 if (timeval_subtract (¤t
, wakeup
, current
))
5454 /* How long `select' should wait. */
5456 timeout
.tv_usec
= 10000;
5458 /* Try to wait that long--but we might wake up sooner. */
5459 select (0, NULL
, NULL
, NULL
, &timeout
);
5463 /* If window is tall, flash top and bottom line. */
5464 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5466 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5468 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5469 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5470 width
, flash_height
);
5471 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5473 (height
- flash_height
5474 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5475 width
, flash_height
);
5478 /* If it is short, flash it all. */
5479 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5480 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5481 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5483 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
5491 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
5494 /* Make audible bell. */
5499 struct frame
*f
= SELECTED_FRAME ();
5501 if (FRAME_X_DISPLAY (f
))
5503 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5510 XBell (FRAME_X_DISPLAY (f
), 0);
5511 XFlush (FRAME_X_DISPLAY (f
));
5518 /* Specify how many text lines, from the top of the window,
5519 should be affected by insert-lines and delete-lines operations.
5520 This, and those operations, are used only within an update
5521 that is bounded by calls to x_update_begin and x_update_end. */
5524 XTset_terminal_window (n
)
5527 /* This function intentionally left blank. */
5532 /***********************************************************************
5534 ***********************************************************************/
5536 /* Perform an insert-lines or delete-lines operation, inserting N
5537 lines or deleting -N lines at vertical position VPOS. */
5540 x_ins_del_lines (vpos
, n
)
5547 /* Scroll part of the display as described by RUN. */
5550 x_scroll_run (w
, run
)
5554 struct frame
*f
= XFRAME (w
->frame
);
5555 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5557 /* Get frame-relative bounding box of the text display area of W,
5558 without mode lines. Include in this box the flags areas to the
5559 left and right of W. */
5560 window_box (w
, -1, &x
, &y
, &width
, &height
);
5561 width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
5562 x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
5564 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5565 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5566 bottom_y
= y
+ height
;
5570 /* Scrolling up. Make sure we don't copy part of the mode
5571 line at the bottom. */
5572 if (from_y
+ run
->height
> bottom_y
)
5573 height
= bottom_y
- from_y
;
5575 height
= run
->height
;
5579 /* Scolling down. Make sure we don't copy over the mode line.
5581 if (to_y
+ run
->height
> bottom_y
)
5582 height
= bottom_y
- to_y
;
5584 height
= run
->height
;
5589 /* Cursor off. Will be switched on again in x_update_window_end. */
5593 XCopyArea (FRAME_X_DISPLAY (f
),
5594 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5595 f
->output_data
.x
->normal_gc
,
5605 /***********************************************************************
5607 ***********************************************************************/
5609 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5610 corner of the exposed rectangle. W and H are width and height of
5611 the exposed area. All are pixel values. W or H zero means redraw
5612 the entire frame. */
5615 expose_frame (f
, x
, y
, w
, h
)
5621 TRACE ((stderr
, "expose_frame "));
5623 /* No need to redraw if frame will be redrawn soon. */
5624 if (FRAME_GARBAGED_P (f
))
5626 TRACE ((stderr
, " garbaged\n"));
5630 /* If basic faces haven't been realized yet, there is no point in
5631 trying to redraw anything. This can happen when we get an expose
5632 event while Emacs is starting, e.g. by moving another window. */
5633 if (FRAME_FACE_CACHE (f
) == NULL
5634 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5636 TRACE ((stderr
, " no faces\n"));
5640 if (w
== 0 || h
== 0)
5643 r
.width
= CANON_X_UNIT (f
) * f
->width
;
5644 r
.height
= CANON_Y_UNIT (f
) * f
->height
;
5654 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
5655 expose_window_tree (XWINDOW (f
->root_window
), &r
);
5657 if (WINDOWP (f
->tool_bar_window
))
5659 struct window
*w
= XWINDOW (f
->tool_bar_window
);
5660 XRectangle window_rect
;
5661 XRectangle intersection_rect
;
5662 int window_x
, window_y
, window_width
, window_height
;
5665 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5666 window_rect
.x
= window_x
;
5667 window_rect
.y
= window_y
;
5668 window_rect
.width
= window_width
;
5669 window_rect
.height
= window_height
;
5671 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5672 expose_window (w
, &intersection_rect
);
5675 #ifndef USE_X_TOOLKIT
5676 if (WINDOWP (f
->menu_bar_window
))
5678 struct window
*w
= XWINDOW (f
->menu_bar_window
);
5679 XRectangle window_rect
;
5680 XRectangle intersection_rect
;
5681 int window_x
, window_y
, window_width
, window_height
;
5684 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5685 window_rect
.x
= window_x
;
5686 window_rect
.y
= window_y
;
5687 window_rect
.width
= window_width
;
5688 window_rect
.height
= window_height
;
5690 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5691 expose_window (w
, &intersection_rect
);
5693 #endif /* not USE_X_TOOLKIT */
5697 /* Redraw (parts) of all windows in the window tree rooted at W that
5698 intersect R. R contains frame pixel coordinates. */
5701 expose_window_tree (w
, r
)
5707 if (!NILP (w
->hchild
))
5708 expose_window_tree (XWINDOW (w
->hchild
), r
);
5709 else if (!NILP (w
->vchild
))
5710 expose_window_tree (XWINDOW (w
->vchild
), r
);
5713 XRectangle window_rect
;
5714 XRectangle intersection_rect
;
5715 struct frame
*f
= XFRAME (w
->frame
);
5716 int window_x
, window_y
, window_width
, window_height
;
5718 /* Frame-relative pixel rectangle of W. */
5719 window_box (w
, -1, &window_x
, &window_y
, &window_width
,
5723 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
5724 - FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5725 window_rect
.y
= window_y
;
5728 + FRAME_X_FLAGS_AREA_WIDTH (f
)
5729 + FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5731 = window_height
+ CURRENT_MODE_LINE_HEIGHT (w
);
5733 if (x_intersect_rectangles (r
, &window_rect
, &intersection_rect
))
5734 expose_window (w
, &intersection_rect
);
5737 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5742 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5743 which intersects rectangle R. R is in window-relative coordinates. */
5746 expose_area (w
, row
, r
, area
)
5748 struct glyph_row
*row
;
5750 enum glyph_row_area area
;
5752 struct glyph
*first
= row
->glyphs
[area
];
5753 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5755 int first_x
, start_x
, x
;
5757 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5758 /* If row extends face to end of line write the whole line. */
5759 x_draw_glyphs (w
, 0, row
, area
,
5761 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5765 /* Set START_X to the window-relative start position for drawing glyphs of
5766 AREA. The first glyph of the text area can be partially visible.
5767 The first glyphs of other areas cannot. */
5768 if (area
== LEFT_MARGIN_AREA
)
5770 else if (area
== TEXT_AREA
)
5771 start_x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5773 start_x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5774 + window_box_width (w
, TEXT_AREA
));
5777 /* Find the first glyph that must be redrawn. */
5779 && x
+ first
->pixel_width
< r
->x
)
5781 x
+= first
->pixel_width
;
5785 /* Find the last one. */
5789 && x
< r
->x
+ r
->width
)
5791 x
+= last
->pixel_width
;
5797 x_draw_glyphs (w
, first_x
- start_x
, row
, area
,
5798 first
- row
->glyphs
[area
],
5799 last
- row
->glyphs
[area
],
5800 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5806 /* Redraw the parts of the glyph row ROW on window W intersecting
5807 rectangle R. R is in window-relative coordinates. */
5810 expose_line (w
, row
, r
)
5812 struct glyph_row
*row
;
5815 xassert (row
->enabled_p
);
5817 if (row
->mode_line_p
|| w
->pseudo_window_p
)
5818 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
5819 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5823 if (row
->used
[LEFT_MARGIN_AREA
])
5824 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
5825 if (row
->used
[TEXT_AREA
])
5826 expose_area (w
, row
, r
, TEXT_AREA
);
5827 if (row
->used
[RIGHT_MARGIN_AREA
])
5828 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
5829 x_draw_row_bitmaps (w
, row
);
5834 /* Return non-zero if W's cursor intersects rectangle R. */
5837 x_phys_cursor_in_rect_p (w
, r
)
5841 XRectangle cr
, result
;
5842 struct glyph
*cursor_glyph
;
5844 cursor_glyph
= get_phys_cursor_glyph (w
);
5847 cr
.x
= w
->phys_cursor
.x
;
5848 cr
.y
= w
->phys_cursor
.y
;
5849 cr
.width
= cursor_glyph
->pixel_width
;
5850 cr
.height
= w
->phys_cursor_height
;
5851 return x_intersect_rectangles (&cr
, r
, &result
);
5858 /* Redraw a rectangle of window W. R is a rectangle in window
5859 relative coordinates. Call this function with input blocked. */
5862 expose_window (w
, r
)
5866 struct glyph_row
*row
;
5868 int yb
= window_text_bottom_y (w
);
5869 int cursor_cleared_p
;
5871 /* If window is not yet fully initialized, do nothing. This can
5872 happen when toolkit scroll bars are used and a window is split.
5873 Reconfiguring the scroll bar will generate an expose for a newly
5875 if (w
->current_matrix
== NULL
|| w
== updated_window
)
5878 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
5879 r
->x
, r
->y
, r
->width
, r
->height
));
5881 /* Convert to window coordinates. */
5882 r
->x
= FRAME_TO_WINDOW_PIXEL_X (w
, r
->x
);
5883 r
->y
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
->y
);
5885 /* Turn off the cursor. */
5886 if (!w
->pseudo_window_p
5887 && x_phys_cursor_in_rect_p (w
, r
))
5890 cursor_cleared_p
= 1;
5893 cursor_cleared_p
= 0;
5895 /* Find the first row intersecting the rectangle R. */
5896 row
= w
->current_matrix
->rows
;
5898 while (row
->enabled_p
5900 && y
+ row
->height
< r
->y
)
5906 /* Display the text in the rectangle, one text line at a time. */
5907 while (row
->enabled_p
5909 && y
< r
->y
+ r
->height
)
5911 expose_line (w
, row
, r
);
5916 /* Display the mode line if there is one. */
5917 if (WINDOW_WANTS_MODELINE_P (w
)
5918 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
5920 && row
->y
< r
->y
+ r
->height
)
5921 expose_line (w
, row
, r
);
5923 if (!w
->pseudo_window_p
)
5925 /* Draw border between windows. */
5926 x_draw_vertical_border (w
);
5928 /* Turn the cursor on again. */
5929 if (cursor_cleared_p
)
5930 x_update_window_cursor (w
, 1);
5935 /* Determine the intersection of two rectangles R1 and R2. Return
5936 the intersection in *RESULT. Value is non-zero if RESULT is not
5940 x_intersect_rectangles (r1
, r2
, result
)
5941 XRectangle
*r1
, *r2
, *result
;
5943 XRectangle
*left
, *right
;
5944 XRectangle
*upper
, *lower
;
5945 int intersection_p
= 0;
5947 /* Rearrange so that R1 is the left-most rectangle. */
5949 left
= r1
, right
= r2
;
5951 left
= r2
, right
= r1
;
5953 /* X0 of the intersection is right.x0, if this is inside R1,
5954 otherwise there is no intersection. */
5955 if (right
->x
<= left
->x
+ left
->width
)
5957 result
->x
= right
->x
;
5959 /* The right end of the intersection is the minimum of the
5960 the right ends of left and right. */
5961 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
5964 /* Same game for Y. */
5966 upper
= r1
, lower
= r2
;
5968 upper
= r2
, lower
= r1
;
5970 /* The upper end of the intersection is lower.y0, if this is inside
5971 of upper. Otherwise, there is no intersection. */
5972 if (lower
->y
<= upper
->y
+ upper
->height
)
5974 result
->y
= lower
->y
;
5976 /* The lower end of the intersection is the minimum of the lower
5977 ends of upper and lower. */
5978 result
->height
= (min (lower
->y
+ lower
->height
,
5979 upper
->y
+ upper
->height
)
5985 return intersection_p
;
5996 /* We used to only do this if Vx_no_window_manager was non-nil, but
5997 the ICCCM (section 4.1.6) says that the window's border pixmap
5998 and border pixel are window attributes which are "private to the
5999 client", so we can always change it to whatever we want. */
6001 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6002 f
->output_data
.x
->border_pixel
);
6004 x_update_cursor (f
, 1);
6008 frame_unhighlight (f
)
6011 /* We used to only do this if Vx_no_window_manager was non-nil, but
6012 the ICCCM (section 4.1.6) says that the window's border pixmap
6013 and border pixel are window attributes which are "private to the
6014 client", so we can always change it to whatever we want. */
6016 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6017 f
->output_data
.x
->border_tile
);
6019 x_update_cursor (f
, 1);
6022 /* The focus has changed. Update the frames as necessary to reflect
6023 the new situation. Note that we can't change the selected frame
6024 here, because the Lisp code we are interrupting might become confused.
6025 Each event gets marked with the frame in which it occurred, so the
6026 Lisp code can tell when the switch took place by examining the events. */
6029 x_new_focus_frame (dpyinfo
, frame
)
6030 struct x_display_info
*dpyinfo
;
6031 struct frame
*frame
;
6033 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
6035 if (frame
!= dpyinfo
->x_focus_frame
)
6037 /* Set this before calling other routines, so that they see
6038 the correct value of x_focus_frame. */
6039 dpyinfo
->x_focus_frame
= frame
;
6041 if (old_focus
&& old_focus
->auto_lower
)
6042 x_lower_frame (old_focus
);
6045 selected_frame
= frame
;
6046 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
6048 Fselect_window (selected_frame
->selected_window
);
6049 choose_minibuf_frame ();
6052 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
6053 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
6055 pending_autoraise_frame
= 0;
6058 x_frame_rehighlight (dpyinfo
);
6061 /* Handle an event saying the mouse has moved out of an Emacs frame. */
6064 x_mouse_leave (dpyinfo
)
6065 struct x_display_info
*dpyinfo
;
6067 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
6070 /* The focus has changed, or we have redirected a frame's focus to
6071 another frame (this happens when a frame uses a surrogate
6072 mini-buffer frame). Shift the highlight as appropriate.
6074 The FRAME argument doesn't necessarily have anything to do with which
6075 frame is being highlighted or un-highlighted; we only use it to find
6076 the appropriate X display info. */
6079 XTframe_rehighlight (frame
)
6080 struct frame
*frame
;
6082 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
6086 x_frame_rehighlight (dpyinfo
)
6087 struct x_display_info
*dpyinfo
;
6089 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
6091 if (dpyinfo
->x_focus_frame
)
6093 dpyinfo
->x_highlight_frame
6094 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
6095 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
6096 : dpyinfo
->x_focus_frame
);
6097 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
6099 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
6100 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
6104 dpyinfo
->x_highlight_frame
= 0;
6106 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
6109 frame_unhighlight (old_highlight
);
6110 if (dpyinfo
->x_highlight_frame
)
6111 frame_highlight (dpyinfo
->x_highlight_frame
);
6117 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
6119 /* Initialize mode_switch_bit and modifier_meaning. */
6121 x_find_modifier_meanings (dpyinfo
)
6122 struct x_display_info
*dpyinfo
;
6124 int min_code
, max_code
;
6127 XModifierKeymap
*mods
;
6129 dpyinfo
->meta_mod_mask
= 0;
6130 dpyinfo
->shift_lock_mask
= 0;
6131 dpyinfo
->alt_mod_mask
= 0;
6132 dpyinfo
->super_mod_mask
= 0;
6133 dpyinfo
->hyper_mod_mask
= 0;
6136 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
6138 min_code
= dpyinfo
->display
->min_keycode
;
6139 max_code
= dpyinfo
->display
->max_keycode
;
6142 syms
= XGetKeyboardMapping (dpyinfo
->display
,
6143 min_code
, max_code
- min_code
+ 1,
6145 mods
= XGetModifierMapping (dpyinfo
->display
);
6147 /* Scan the modifier table to see which modifier bits the Meta and
6148 Alt keysyms are on. */
6150 int row
, col
; /* The row and column in the modifier table. */
6152 for (row
= 3; row
< 8; row
++)
6153 for (col
= 0; col
< mods
->max_keypermod
; col
++)
6156 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
6158 /* Zeroes are used for filler. Skip them. */
6162 /* Are any of this keycode's keysyms a meta key? */
6166 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
6168 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
6174 dpyinfo
->meta_mod_mask
|= (1 << row
);
6179 dpyinfo
->alt_mod_mask
|= (1 << row
);
6184 dpyinfo
->hyper_mod_mask
|= (1 << row
);
6189 dpyinfo
->super_mod_mask
|= (1 << row
);
6193 /* Ignore this if it's not on the lock modifier. */
6194 if ((1 << row
) == LockMask
)
6195 dpyinfo
->shift_lock_mask
= LockMask
;
6203 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
6204 if (! dpyinfo
->meta_mod_mask
)
6206 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
6207 dpyinfo
->alt_mod_mask
= 0;
6210 /* If some keys are both alt and meta,
6211 make them just meta, not alt. */
6212 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
6214 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
6217 XFree ((char *) syms
);
6218 XFreeModifiermap (mods
);
6221 /* Convert between the modifier bits X uses and the modifier bits
6225 x_x_to_emacs_modifiers (dpyinfo
, state
)
6226 struct x_display_info
*dpyinfo
;
6229 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
6230 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
6231 | ((state
& dpyinfo
->meta_mod_mask
) ? meta_modifier
: 0)
6232 | ((state
& dpyinfo
->alt_mod_mask
) ? alt_modifier
: 0)
6233 | ((state
& dpyinfo
->super_mod_mask
) ? super_modifier
: 0)
6234 | ((state
& dpyinfo
->hyper_mod_mask
) ? hyper_modifier
: 0));
6238 x_emacs_to_x_modifiers (dpyinfo
, state
)
6239 struct x_display_info
*dpyinfo
;
6242 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
6243 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
6244 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
6245 | ((state
& shift_modifier
) ? ShiftMask
: 0)
6246 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
6247 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
6250 /* Convert a keysym to its name. */
6253 x_get_keysym_name (keysym
)
6259 value
= XKeysymToString (keysym
);
6267 /* Mouse clicks and mouse movement. Rah. */
6269 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
6270 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
6271 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
6272 not force the value into range. */
6275 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
6277 register int pix_x
, pix_y
;
6278 register int *x
, *y
;
6282 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
6283 even for negative values. */
6285 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
6287 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
6289 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
6290 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
6294 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
6295 bounds
->height
= f
->output_data
.x
->line_height
;
6296 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
6297 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
6304 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
6305 pix_x
= FRAME_WINDOW_WIDTH (f
);
6309 else if (pix_y
> f
->height
)
6318 /* Given HPOS/VPOS in the current matrix of W, return corresponding
6319 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
6320 can't tell the positions because W's display is not up to date,
6324 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
6327 int *frame_x
, *frame_y
;
6331 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
6332 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
6334 if (display_completed
)
6336 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6337 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
6338 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
6344 *frame_x
+= glyph
->pixel_width
;
6352 *frame_y
= *frame_x
= 0;
6356 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
6357 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6362 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6364 If the event is a button press, then note that we have grabbed
6368 construct_mouse_click (result
, event
, f
)
6369 struct input_event
*result
;
6370 XButtonEvent
*event
;
6373 /* Make the event type no_event; we'll change that when we decide
6375 result
->kind
= mouse_click
;
6376 result
->code
= event
->button
- Button1
;
6377 result
->timestamp
= event
->time
;
6378 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6380 | (event
->type
== ButtonRelease
6384 XSETINT (result
->x
, event
->x
);
6385 XSETINT (result
->y
, event
->y
);
6386 XSETFRAME (result
->frame_or_window
, f
);
6392 /* Function to report a mouse movement to the mainstream Emacs code.
6393 The input handler calls this.
6395 We have received a mouse movement event, which is given in *event.
6396 If the mouse is over a different glyph than it was last time, tell
6397 the mainstream emacs code by setting mouse_moved. If not, ask for
6398 another motion event, so we can check again the next time it moves. */
6400 static XMotionEvent last_mouse_motion_event
;
6401 static Lisp_Object last_mouse_motion_frame
;
6404 note_mouse_movement (frame
, event
)
6406 XMotionEvent
*event
;
6408 last_mouse_movement_time
= event
->time
;
6409 last_mouse_motion_event
= *event
;
6410 XSETFRAME (last_mouse_motion_frame
, frame
);
6412 if (event
->window
!= FRAME_X_WINDOW (frame
))
6414 frame
->mouse_moved
= 1;
6415 last_mouse_scroll_bar
= Qnil
;
6416 note_mouse_highlight (frame
, -1, -1);
6419 /* Has the mouse moved off the glyph it was on at the last sighting? */
6420 else if (event
->x
< last_mouse_glyph
.x
6421 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
6422 || event
->y
< last_mouse_glyph
.y
6423 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
6425 frame
->mouse_moved
= 1;
6426 last_mouse_scroll_bar
= Qnil
;
6427 note_mouse_highlight (frame
, event
->x
, event
->y
);
6431 /* This is used for debugging, to turn off note_mouse_highlight. */
6433 int disable_mouse_highlight
;
6437 /************************************************************************
6439 ************************************************************************/
6441 /* Find the glyph under window-relative coordinates X/Y in window W.
6442 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6443 strings. Return in *HPOS and *VPOS the row and column number of
6444 the glyph found. Return in *AREA the glyph area containing X.
6445 Value is a pointer to the glyph found or null if X/Y is not on
6446 text, or we can't tell because W's current matrix is not up to
6449 static struct glyph
*
6450 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
, buffer_only_p
)
6453 int *hpos
, *vpos
, *area
;
6456 struct glyph
*glyph
, *end
;
6457 struct glyph_row
*row
= NULL
;
6458 int x0
, i
, left_area_width
;
6460 /* Find row containing Y. Give up if some row is not enabled. */
6461 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6463 row
= MATRIX_ROW (w
->current_matrix
, i
);
6464 if (!row
->enabled_p
)
6466 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6473 /* Give up if Y is not in the window. */
6474 if (i
== w
->current_matrix
->nrows
)
6477 /* Get the glyph area containing X. */
6478 if (w
->pseudo_window_p
)
6485 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6486 if (x
< left_area_width
)
6488 *area
= LEFT_MARGIN_AREA
;
6491 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6494 x0
= row
->x
+ left_area_width
;
6498 *area
= RIGHT_MARGIN_AREA
;
6499 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6503 /* Find glyph containing X. */
6504 glyph
= row
->glyphs
[*area
];
6505 end
= glyph
+ row
->used
[*area
];
6508 if (x
< x0
+ glyph
->pixel_width
)
6510 if (w
->pseudo_window_p
)
6512 else if (!buffer_only_p
|| BUFFERP (glyph
->object
))
6516 x0
+= glyph
->pixel_width
;
6523 *hpos
= glyph
- row
->glyphs
[*area
];
6528 /* Convert frame-relative x/y to coordinates relative to window W.
6529 Takes pseudo-windows into account. */
6532 frame_to_window_pixel_xy (w
, x
, y
)
6536 if (w
->pseudo_window_p
)
6538 /* A pseudo-window is always full-width, and starts at the
6539 left edge of the frame, plus a frame border. */
6540 struct frame
*f
= XFRAME (w
->frame
);
6541 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6542 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6546 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6547 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6552 /* Take proper action when mouse has moved to the mode or header line of
6553 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6554 mode line. X is relative to the start of the text display area of
6555 W, so the width of bitmap areas and scroll bars must be subtracted
6556 to get a position relative to the start of the mode line. */
6559 note_mode_line_highlight (w
, x
, mode_line_p
)
6563 struct frame
*f
= XFRAME (w
->frame
);
6564 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6565 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6566 struct glyph_row
*row
;
6569 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
6571 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
6575 struct glyph
*glyph
, *end
;
6576 Lisp_Object help
, map
;
6579 /* Find the glyph under X. */
6580 glyph
= row
->glyphs
[TEXT_AREA
];
6581 end
= glyph
+ row
->used
[TEXT_AREA
];
6582 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6583 + FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
));
6586 && x
>= x0
+ glyph
->pixel_width
)
6588 x0
+= glyph
->pixel_width
;
6593 && STRINGP (glyph
->object
)
6594 && XSTRING (glyph
->object
)->intervals
6595 && glyph
->charpos
>= 0
6596 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6598 /* If we're on a string with `help-echo' text property,
6599 arrange for the help to be displayed. This is done by
6600 setting the global variable help_echo to the help string. */
6601 help
= Fget_text_property (make_number (glyph
->charpos
),
6602 Qhelp_echo
, glyph
->object
);
6606 XSETWINDOW (help_echo_window
, w
);
6607 help_echo_object
= glyph
->object
;
6608 help_echo_pos
= glyph
->charpos
;
6611 /* Change the mouse pointer according to what is under X/Y. */
6612 map
= Fget_text_property (make_number (glyph
->charpos
),
6613 Qlocal_map
, glyph
->object
);
6615 cursor
= f
->output_data
.x
->nontext_cursor
;
6618 map
= Fget_text_property (make_number (glyph
->charpos
),
6619 Qkeymap
, glyph
->object
);
6621 cursor
= f
->output_data
.x
->nontext_cursor
;
6626 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6630 /* Take proper action when the mouse has moved to position X, Y on
6631 frame F as regards highlighting characters that have mouse-face
6632 properties. Also de-highlighting chars where the mouse was before.
6633 X and Y can be negative or out of range. */
6636 note_mouse_highlight (f
, x
, y
)
6640 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6645 /* When a menu is active, don't highlight because this looks odd. */
6646 #ifdef USE_X_TOOLKIT
6647 if (popup_activated ())
6651 if (disable_mouse_highlight
6652 || !f
->glyphs_initialized_p
)
6655 dpyinfo
->mouse_face_mouse_x
= x
;
6656 dpyinfo
->mouse_face_mouse_y
= y
;
6657 dpyinfo
->mouse_face_mouse_frame
= f
;
6659 if (dpyinfo
->mouse_face_defer
)
6664 dpyinfo
->mouse_face_deferred_gc
= 1;
6668 /* Which window is that in? */
6669 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6671 /* If we were displaying active text in another window, clear that. */
6672 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6673 clear_mouse_face (dpyinfo
);
6675 /* Not on a window -> return. */
6676 if (!WINDOWP (window
))
6679 /* Convert to window-relative pixel coordinates. */
6680 w
= XWINDOW (window
);
6681 frame_to_window_pixel_xy (w
, &x
, &y
);
6683 /* Handle tool-bar window differently since it doesn't display a
6685 if (EQ (window
, f
->tool_bar_window
))
6687 note_tool_bar_highlight (f
, x
, y
);
6691 if (portion
== 1 || portion
== 3)
6693 /* Mouse is on the mode or top line. */
6694 note_mode_line_highlight (w
, x
, portion
== 1);
6697 else if (portion
== 2)
6698 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6699 f
->output_data
.x
->horizontal_drag_cursor
);
6701 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6702 f
->output_data
.x
->text_cursor
);
6704 /* Are we in a window whose display is up to date?
6705 And verify the buffer's text has not changed. */
6706 if (/* Within text portion of the window. */
6708 && EQ (w
->window_end_valid
, w
->buffer
)
6709 && XFASTINT (w
->last_modified
) == BUF_MODIFF (XBUFFER (w
->buffer
))
6710 && (XFASTINT (w
->last_overlay_modified
)
6711 == BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
))))
6713 int hpos
, vpos
, pos
, i
, area
;
6714 struct glyph
*glyph
;
6717 /* Find the glyph under X/Y. */
6718 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
, 0);
6720 /* Clear mouse face if X/Y not over text. */
6722 || area
!= TEXT_AREA
6723 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6725 clear_mouse_face (dpyinfo
);
6729 pos
= glyph
->charpos
;
6730 object
= glyph
->object
;
6731 if (!STRINGP (object
) && !BUFFERP (object
))
6735 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
6736 Lisp_Object
*overlay_vec
= NULL
;
6738 struct buffer
*obuf
;
6741 /* If we get an out-of-range value, return now; avoid an error. */
6742 if (BUFFERP (object
) && pos
> BUF_Z (XBUFFER (w
->buffer
)))
6745 /* Make the window's buffer temporarily current for
6746 overlays_at and compute_char_face. */
6747 obuf
= current_buffer
;
6748 current_buffer
= XBUFFER (w
->buffer
);
6754 /* Is this char mouse-active or does it have help-echo? */
6755 position
= make_number (pos
);
6757 if (BUFFERP (object
))
6759 /* Put all the overlays we want in a vector in overlay_vec.
6760 Store the length in len. If there are more than 10, make
6761 enough space for all, and try again. */
6763 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6764 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
6765 if (noverlays
> len
)
6768 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6769 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
6772 /* Sort overlays into increasing priority order. */
6773 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6778 /* Check mouse-face highlighting. */
6779 if (! (EQ (window
, dpyinfo
->mouse_face_window
)
6780 && vpos
>= dpyinfo
->mouse_face_beg_row
6781 && vpos
<= dpyinfo
->mouse_face_end_row
6782 && (vpos
> dpyinfo
->mouse_face_beg_row
6783 || hpos
>= dpyinfo
->mouse_face_beg_col
)
6784 && (vpos
< dpyinfo
->mouse_face_end_row
6785 || hpos
< dpyinfo
->mouse_face_end_col
6786 || dpyinfo
->mouse_face_past_end
))
6787 /* If there exists an overlay with mouse-face overlapping
6788 the one we are currently highlighting, we have to
6789 check if we enter the overlapping overlay, and then
6790 highlight only that. */
6791 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
6792 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
6795 /* Clear the display of the old active region, if any. */
6796 clear_mouse_face (dpyinfo
);
6798 /* Find the highest priority overlay that has a mouse-face
6801 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
6803 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
6804 if (!NILP (mouse_face
))
6805 overlay
= overlay_vec
[i
];
6807 dpyinfo
->mouse_face_overlay
= overlay
;
6809 /* If no overlay applies, get a text property. */
6811 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
6813 /* Handle the overlay case. */
6814 if (!NILP (overlay
))
6816 /* Find the range of text around this char that
6817 should be active. */
6818 Lisp_Object before
, after
;
6821 before
= Foverlay_start (overlay
);
6822 after
= Foverlay_end (overlay
);
6823 /* Record this as the current active region. */
6824 fast_find_position (w
, XFASTINT (before
),
6825 &dpyinfo
->mouse_face_beg_col
,
6826 &dpyinfo
->mouse_face_beg_row
,
6827 &dpyinfo
->mouse_face_beg_x
,
6828 &dpyinfo
->mouse_face_beg_y
);
6829 dpyinfo
->mouse_face_past_end
6830 = !fast_find_position (w
, XFASTINT (after
),
6831 &dpyinfo
->mouse_face_end_col
,
6832 &dpyinfo
->mouse_face_end_row
,
6833 &dpyinfo
->mouse_face_end_x
,
6834 &dpyinfo
->mouse_face_end_y
);
6835 dpyinfo
->mouse_face_window
= window
;
6836 dpyinfo
->mouse_face_face_id
6837 = face_at_buffer_position (w
, pos
, 0, 0,
6838 &ignore
, pos
+ 1, 1);
6840 /* Display it as active. */
6841 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6843 /* Handle the text property case. */
6844 else if (!NILP (mouse_face
) && BUFFERP (object
))
6846 /* Find the range of text around this char that
6847 should be active. */
6848 Lisp_Object before
, after
, beginning
, end
;
6851 beginning
= Fmarker_position (w
->start
);
6852 end
= make_number (BUF_Z (XBUFFER (object
))
6853 - XFASTINT (w
->window_end_pos
));
6855 = Fprevious_single_property_change (make_number (pos
+ 1),
6859 = Fnext_single_property_change (position
, Qmouse_face
,
6862 /* Record this as the current active region. */
6863 fast_find_position (w
, XFASTINT (before
),
6864 &dpyinfo
->mouse_face_beg_col
,
6865 &dpyinfo
->mouse_face_beg_row
,
6866 &dpyinfo
->mouse_face_beg_x
,
6867 &dpyinfo
->mouse_face_beg_y
);
6868 dpyinfo
->mouse_face_past_end
6869 = !fast_find_position (w
, XFASTINT (after
),
6870 &dpyinfo
->mouse_face_end_col
,
6871 &dpyinfo
->mouse_face_end_row
,
6872 &dpyinfo
->mouse_face_end_x
,
6873 &dpyinfo
->mouse_face_end_y
);
6874 dpyinfo
->mouse_face_window
= window
;
6876 if (BUFFERP (object
))
6877 dpyinfo
->mouse_face_face_id
6878 = face_at_buffer_position (w
, pos
, 0, 0,
6879 &ignore
, pos
+ 1, 1);
6881 /* Display it as active. */
6882 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6884 else if (!NILP (mouse_face
) && STRINGP (object
))
6889 b
= Fprevious_single_property_change (make_number (pos
+ 1),
6892 e
= Fnext_single_property_change (position
, Qmouse_face
,
6895 b
= make_number (0);
6897 e
= make_number (XSTRING (object
)->size
) - 1;
6898 fast_find_string_pos (w
, XINT (b
), object
,
6899 &dpyinfo
->mouse_face_beg_col
,
6900 &dpyinfo
->mouse_face_beg_row
,
6901 &dpyinfo
->mouse_face_beg_x
,
6902 &dpyinfo
->mouse_face_beg_y
, 0);
6903 fast_find_string_pos (w
, XINT (e
), object
,
6904 &dpyinfo
->mouse_face_end_col
,
6905 &dpyinfo
->mouse_face_end_row
,
6906 &dpyinfo
->mouse_face_end_x
,
6907 &dpyinfo
->mouse_face_end_y
, 1);
6908 dpyinfo
->mouse_face_past_end
= 0;
6909 dpyinfo
->mouse_face_window
= window
;
6910 dpyinfo
->mouse_face_face_id
6911 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
6913 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6917 /* Look for a `help-echo' property. */
6919 Lisp_Object help
, overlay
;
6921 /* Check overlays first. */
6922 help
= overlay
= Qnil
;
6923 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
6925 overlay
= overlay_vec
[i
];
6926 help
= Foverlay_get (overlay
, Qhelp_echo
);
6932 help_echo_window
= window
;
6933 help_echo_object
= overlay
;
6934 help_echo_pos
= pos
;
6938 Lisp_Object object
= glyph
->object
;
6939 int charpos
= glyph
->charpos
;
6941 /* Try text properties. */
6942 if (STRINGP (object
)
6944 && charpos
< XSTRING (object
)->size
)
6946 help
= Fget_text_property (make_number (charpos
),
6947 Qhelp_echo
, object
);
6950 /* If the string itself doesn't specify a help-echo,
6951 see if the buffer text ``under'' it does. */
6953 = MATRIX_ROW (w
->current_matrix
, vpos
);
6954 int start
= MATRIX_ROW_START_CHARPOS (r
);
6955 int pos
= string_buffer_position (w
, object
, start
);
6958 help
= Fget_text_property (make_number (pos
),
6959 Qhelp_echo
, w
->buffer
);
6968 else if (BUFFERP (object
)
6971 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
6977 help_echo_window
= window
;
6978 help_echo_object
= object
;
6979 help_echo_pos
= charpos
;
6986 current_buffer
= obuf
;
6992 redo_mouse_highlight ()
6994 if (!NILP (last_mouse_motion_frame
)
6995 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
6996 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
6997 last_mouse_motion_event
.x
,
6998 last_mouse_motion_event
.y
);
7003 /***********************************************************************
7005 ***********************************************************************/
7007 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
7008 struct glyph
**, int *, int *, int *));
7010 /* Tool-bar item index of the item on which a mouse button was pressed
7013 static int last_tool_bar_item
;
7016 /* Get information about the tool-bar item at position X/Y on frame F.
7017 Return in *GLYPH a pointer to the glyph of the tool-bar item in
7018 the current matrix of the tool-bar window of F, or NULL if not
7019 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
7020 item in F->tool_bar_items. Value is
7022 -1 if X/Y is not on a tool-bar item
7023 0 if X/Y is on the same item that was highlighted before.
7027 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
7030 struct glyph
**glyph
;
7031 int *hpos
, *vpos
, *prop_idx
;
7033 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7034 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7037 /* Find the glyph under X/Y. */
7038 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
, 0);
7042 /* Get the start of this tool-bar item's properties in
7043 f->tool_bar_items. */
7044 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
7047 /* Is mouse on the highlighted item? */
7048 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
7049 && *vpos
>= dpyinfo
->mouse_face_beg_row
7050 && *vpos
<= dpyinfo
->mouse_face_end_row
7051 && (*vpos
> dpyinfo
->mouse_face_beg_row
7052 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
7053 && (*vpos
< dpyinfo
->mouse_face_end_row
7054 || *hpos
< dpyinfo
->mouse_face_end_col
7055 || dpyinfo
->mouse_face_past_end
))
7062 /* Handle mouse button event on the tool-bar of frame F, at
7063 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
7067 x_handle_tool_bar_click (f
, button_event
)
7069 XButtonEvent
*button_event
;
7071 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7072 struct window
*w
= XWINDOW (f
->tool_bar_window
);
7073 int hpos
, vpos
, prop_idx
;
7074 struct glyph
*glyph
;
7075 Lisp_Object enabled_p
;
7076 int x
= button_event
->x
;
7077 int y
= button_event
->y
;
7079 /* If not on the highlighted tool-bar item, return. */
7080 frame_to_window_pixel_xy (w
, &x
, &y
);
7081 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
7084 /* If item is disabled, do nothing. */
7085 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7086 if (NILP (enabled_p
))
7089 if (button_event
->type
== ButtonPress
)
7091 /* Show item in pressed state. */
7092 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
7093 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
7094 last_tool_bar_item
= prop_idx
;
7098 Lisp_Object key
, frame
;
7099 struct input_event event
;
7101 /* Show item in released state. */
7102 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
7103 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
7105 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
7107 XSETFRAME (frame
, f
);
7108 event
.kind
= TOOL_BAR_EVENT
;
7109 event
.frame_or_window
= frame
;
7111 kbd_buffer_store_event (&event
);
7113 event
.kind
= TOOL_BAR_EVENT
;
7114 event
.frame_or_window
= frame
;
7116 event
.modifiers
= x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
7117 button_event
->state
);
7118 kbd_buffer_store_event (&event
);
7119 last_tool_bar_item
= -1;
7124 /* Possibly highlight a tool-bar item on frame F when mouse moves to
7125 tool-bar window-relative coordinates X/Y. Called from
7126 note_mouse_highlight. */
7129 note_tool_bar_highlight (f
, x
, y
)
7133 Lisp_Object window
= f
->tool_bar_window
;
7134 struct window
*w
= XWINDOW (window
);
7135 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7137 struct glyph
*glyph
;
7138 struct glyph_row
*row
;
7140 Lisp_Object enabled_p
;
7142 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
7143 int mouse_down_p
, rc
;
7145 /* Function note_mouse_highlight is called with negative x(y
7146 values when mouse moves outside of the frame. */
7147 if (x
<= 0 || y
<= 0)
7149 clear_mouse_face (dpyinfo
);
7153 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
7156 /* Not on tool-bar item. */
7157 clear_mouse_face (dpyinfo
);
7161 /* On same tool-bar item as before. */
7164 clear_mouse_face (dpyinfo
);
7166 /* Mouse is down, but on different tool-bar item? */
7167 mouse_down_p
= (dpyinfo
->grabbed
7168 && f
== last_mouse_frame
7169 && FRAME_LIVE_P (f
));
7171 && last_tool_bar_item
!= prop_idx
)
7174 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
7175 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
7177 /* If tool-bar item is not enabled, don't highlight it. */
7178 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7179 if (!NILP (enabled_p
))
7181 /* Compute the x-position of the glyph. In front and past the
7182 image is a space. We include this is the highlighted area. */
7183 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
7184 for (i
= x
= 0; i
< hpos
; ++i
)
7185 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
7187 /* Record this as the current active region. */
7188 dpyinfo
->mouse_face_beg_col
= hpos
;
7189 dpyinfo
->mouse_face_beg_row
= vpos
;
7190 dpyinfo
->mouse_face_beg_x
= x
;
7191 dpyinfo
->mouse_face_beg_y
= row
->y
;
7192 dpyinfo
->mouse_face_past_end
= 0;
7194 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
7195 dpyinfo
->mouse_face_end_row
= vpos
;
7196 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
7197 dpyinfo
->mouse_face_end_y
= row
->y
;
7198 dpyinfo
->mouse_face_window
= window
;
7199 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
7201 /* Display it as active. */
7202 show_mouse_face (dpyinfo
, draw
);
7203 dpyinfo
->mouse_face_image_state
= draw
;
7208 /* Set help_echo to a help string.to display for this tool-bar item.
7209 XTread_socket does the rest. */
7210 help_echo_object
= help_echo_window
= Qnil
;
7212 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
7213 if (NILP (help_echo
))
7214 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
7219 /* Find the glyph matrix position of buffer position POS in window W.
7220 *HPOS, *VPOS, *X, and *Y are set to the positions found. W's
7221 current glyphs must be up to date. If POS is above window start
7222 return (0, 0, 0, 0). If POS is after end of W, return end of
7226 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
)
7229 int *hpos
, *vpos
, *x
, *y
;
7233 int maybe_next_line_p
= 0;
7234 int line_start_position
;
7235 int yb
= window_text_bottom_y (w
);
7236 struct glyph_row
*row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7237 struct glyph_row
*best_row
= row
;
7238 int row_vpos
= 0, best_row_vpos
= 0;
7243 if (row
->used
[TEXT_AREA
])
7244 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
7246 line_start_position
= 0;
7248 if (line_start_position
> pos
)
7250 /* If the position sought is the end of the buffer,
7251 don't include the blank lines at the bottom of the window. */
7252 else if (line_start_position
== pos
7253 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
7255 maybe_next_line_p
= 1;
7258 else if (line_start_position
> 0)
7261 best_row_vpos
= row_vpos
;
7264 if (row
->y
+ row
->height
>= yb
)
7271 /* Find the right column within BEST_ROW. */
7273 current_x
= best_row
->x
;
7274 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
7276 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
7279 charpos
= glyph
->charpos
;
7283 *vpos
= best_row_vpos
;
7288 else if (charpos
> pos
)
7290 else if (charpos
> 0)
7293 current_x
+= glyph
->pixel_width
;
7296 /* If we're looking for the end of the buffer,
7297 and we didn't find it in the line we scanned,
7298 use the start of the following line. */
7299 if (maybe_next_line_p
)
7304 current_x
= best_row
->x
;
7307 *vpos
= best_row_vpos
;
7308 *hpos
= lastcol
+ 1;
7315 /* Find the position of the the glyph for position POS in OBJECT in
7316 window W's current matrix, and return in *X/*Y the pixel
7317 coordinates, and return in *HPOS/*VPOS the column/row of the glyph.
7319 RIGHT_P non-zero means return the position of the right edge of the
7320 glyph, RIGHT_P zero means return the left edge position.
7322 If no glyph for POS exists in the matrix, return the position of
7323 the glyph with the next smaller position that is in the matrix, if
7324 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
7325 exists in the matrix, return the position of the glyph with the
7326 next larger position in OBJECT.
7328 Value is non-zero if a glyph was found. */
7331 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
7335 int *hpos
, *vpos
, *x
, *y
;
7338 int yb
= window_text_bottom_y (w
);
7339 struct glyph_row
*r
;
7340 struct glyph
*best_glyph
= NULL
;
7341 struct glyph_row
*best_row
= NULL
;
7344 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7345 r
->enabled_p
&& r
->y
< yb
;
7348 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7349 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
7352 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
7353 if (EQ (g
->object
, object
))
7355 if (g
->charpos
== pos
)
7362 else if (best_glyph
== NULL
7363 || ((abs (g
->charpos
- pos
)
7364 < abs (best_glyph
->charpos
- pos
))
7367 : g
->charpos
> pos
)))
7381 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
7385 *x
+= best_glyph
->pixel_width
;
7390 *vpos
= best_row
- w
->current_matrix
->rows
;
7393 return best_glyph
!= NULL
;
7397 /* Display the active region described by mouse_face_*
7398 in its mouse-face if HL > 0, in its normal face if HL = 0. */
7401 show_mouse_face (dpyinfo
, draw
)
7402 struct x_display_info
*dpyinfo
;
7403 enum draw_glyphs_face draw
;
7405 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
7406 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7408 int cursor_off_p
= 0;
7409 struct cursor_pos saved_cursor
;
7411 saved_cursor
= output_cursor
;
7413 /* If window is in the process of being destroyed, don't bother
7415 if (w
->current_matrix
== NULL
)
7418 /* Recognize when we are called to operate on rows that don't exist
7419 anymore. This can happen when a window is split. */
7420 if (dpyinfo
->mouse_face_end_row
>= w
->current_matrix
->nrows
)
7423 set_output_cursor (&w
->phys_cursor
);
7425 /* Note that mouse_face_beg_row etc. are window relative. */
7426 for (i
= dpyinfo
->mouse_face_beg_row
;
7427 i
<= dpyinfo
->mouse_face_end_row
;
7430 int start_hpos
, end_hpos
, start_x
;
7431 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, i
);
7433 /* Don't do anything if row doesn't have valid contents. */
7434 if (!row
->enabled_p
)
7437 /* For all but the first row, the highlight starts at column 0. */
7438 if (i
== dpyinfo
->mouse_face_beg_row
)
7440 start_hpos
= dpyinfo
->mouse_face_beg_col
;
7441 start_x
= dpyinfo
->mouse_face_beg_x
;
7449 if (i
== dpyinfo
->mouse_face_end_row
)
7450 end_hpos
= dpyinfo
->mouse_face_end_col
;
7452 end_hpos
= row
->used
[TEXT_AREA
];
7454 /* If the cursor's in the text we are about to rewrite, turn the
7456 if (!w
->pseudo_window_p
7457 && i
== output_cursor
.vpos
7458 && output_cursor
.hpos
>= start_hpos
- 1
7459 && output_cursor
.hpos
<= end_hpos
)
7461 x_update_window_cursor (w
, 0);
7465 if (end_hpos
> start_hpos
)
7467 row
->mouse_face_p
= draw
== DRAW_MOUSE_FACE
;
7468 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
7469 start_hpos
, end_hpos
, draw
, NULL
, NULL
, 0);
7473 /* If we turned the cursor off, turn it back on. */
7475 x_display_cursor (w
, 1,
7476 output_cursor
.hpos
, output_cursor
.vpos
,
7477 output_cursor
.x
, output_cursor
.y
);
7479 output_cursor
= saved_cursor
;
7483 /* Change the mouse cursor. */
7484 if (draw
== DRAW_NORMAL_TEXT
)
7485 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7486 f
->output_data
.x
->text_cursor
);
7487 else if (draw
== DRAW_MOUSE_FACE
)
7488 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7489 f
->output_data
.x
->cross_cursor
);
7491 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7492 f
->output_data
.x
->nontext_cursor
);
7495 /* Clear out the mouse-highlighted active region.
7496 Redraw it un-highlighted first. */
7499 clear_mouse_face (dpyinfo
)
7500 struct x_display_info
*dpyinfo
;
7502 #if 0 /* This prevents redrawing tool bar items when changing from one
7503 to another while a tooltip is open, so don't do it. */
7504 if (!NILP (tip_frame
))
7508 if (! NILP (dpyinfo
->mouse_face_window
))
7509 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
7511 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7512 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7513 dpyinfo
->mouse_face_window
= Qnil
;
7517 /* Clear any mouse-face on window W. This function is part of the
7518 redisplay interface, and is called from try_window_id and similar
7519 functions to ensure the mouse-highlight is off. */
7522 x_clear_mouse_face (w
)
7525 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
7529 XSETWINDOW (window
, w
);
7530 if (EQ (window
, dpyinfo
->mouse_face_window
))
7531 clear_mouse_face (dpyinfo
);
7536 /* Just discard the mouse face information for frame F, if any.
7537 This is used when the size of F is changed. */
7540 cancel_mouse_face (f
)
7544 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7546 window
= dpyinfo
->mouse_face_window
;
7547 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
7549 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7550 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7551 dpyinfo
->mouse_face_window
= Qnil
;
7556 static int glyph_rect
P_ ((struct frame
*f
, int, int, XRectangle
*));
7559 /* Try to determine frame pixel position and size of the glyph under
7560 frame pixel coordinates X/Y on frame F . Return the position and
7561 size in *RECT. Value is non-zero if we could compute these
7565 glyph_rect (f
, x
, y
, rect
)
7571 int part
, found
= 0;
7573 window
= window_from_coordinates (f
, x
, y
, &part
, 0);
7576 struct window
*w
= XWINDOW (window
);
7577 struct glyph_row
*r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
7578 struct glyph_row
*end
= r
+ w
->current_matrix
->nrows
- 1;
7581 frame_to_window_pixel_xy (w
, &x
, &y
);
7583 for (; !found
&& r
< end
&& r
->enabled_p
; ++r
)
7586 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
7587 struct glyph
*end
= g
+ r
->used
[TEXT_AREA
];
7590 for (gx
= r
->x
; !found
&& g
< end
; gx
+= g
->pixel_width
, ++g
)
7593 rect
->width
= g
->pixel_width
;
7594 rect
->height
= r
->height
;
7595 rect
->x
= WINDOW_TO_FRAME_PIXEL_X (w
, gx
);
7596 rect
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, r
->y
);
7606 /* Return the current position of the mouse.
7607 *FP should be a frame which indicates which display to ask about.
7609 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
7610 and *PART to the frame, window, and scroll bar part that the mouse
7611 is over. Set *X and *Y to the portion and whole of the mouse's
7612 position on the scroll bar.
7614 If the mouse movement started elsewhere, set *FP to the frame the
7615 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
7618 Set *TIME to the server time-stamp for the time at which the mouse
7619 was at this position.
7621 Don't store anything if we don't have a valid set of values to report.
7623 This clears the mouse_moved flag, so we can wait for the next mouse
7627 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
7630 Lisp_Object
*bar_window
;
7631 enum scroll_bar_part
*part
;
7633 unsigned long *time
;
7639 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
7640 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
7646 Window dummy_window
;
7649 Lisp_Object frame
, tail
;
7651 /* Clear the mouse-moved flag for every frame on this display. */
7652 FOR_EACH_FRAME (tail
, frame
)
7653 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
7654 XFRAME (frame
)->mouse_moved
= 0;
7656 last_mouse_scroll_bar
= Qnil
;
7658 /* Figure out which root window we're on. */
7659 XQueryPointer (FRAME_X_DISPLAY (*fp
),
7660 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
7662 /* The root window which contains the pointer. */
7665 /* Trash which we can't trust if the pointer is on
7666 a different screen. */
7669 /* The position on that root window. */
7672 /* More trash we can't trust. */
7675 /* Modifier keys and pointer buttons, about which
7677 (unsigned int *) &dummy
);
7679 /* Now we have a position on the root; find the innermost window
7680 containing the pointer. */
7684 int parent_x
= 0, parent_y
= 0;
7689 /* XTranslateCoordinates can get errors if the window
7690 structure is changing at the same time this function
7691 is running. So at least we must not crash from them. */
7693 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
7695 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
7696 && FRAME_LIVE_P (last_mouse_frame
))
7698 /* If mouse was grabbed on a frame, give coords for that frame
7699 even if the mouse is now outside it. */
7700 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7702 /* From-window, to-window. */
7703 root
, FRAME_X_WINDOW (last_mouse_frame
),
7705 /* From-position, to-position. */
7706 root_x
, root_y
, &win_x
, &win_y
,
7710 f1
= last_mouse_frame
;
7716 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7718 /* From-window, to-window. */
7721 /* From-position, to-position. */
7722 root_x
, root_y
, &win_x
, &win_y
,
7727 if (child
== None
|| child
== win
)
7735 /* Now we know that:
7736 win is the innermost window containing the pointer
7737 (XTC says it has no child containing the pointer),
7738 win_x and win_y are the pointer's position in it
7739 (XTC did this the last time through), and
7740 parent_x and parent_y are the pointer's position in win's parent.
7741 (They are what win_x and win_y were when win was child.
7742 If win is the root window, it has no parent, and
7743 parent_{x,y} are invalid, but that's okay, because we'll
7744 never use them in that case.) */
7746 /* Is win one of our frames? */
7747 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
7749 #ifdef USE_X_TOOLKIT
7750 /* If we end up with the menu bar window, say it's not
7753 && f1
->output_data
.x
->menubar_widget
7754 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
7756 #endif /* USE_X_TOOLKIT */
7759 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
7762 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
7764 /* If not, is it one of our scroll bars? */
7767 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
7771 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7777 if (f1
== 0 && insist
> 0)
7778 f1
= SELECTED_FRAME ();
7782 /* Ok, we found a frame. Store all the values.
7783 last_mouse_glyph is a rectangle used to reduce the
7784 generation of mouse events. To not miss any motion
7785 events, we must divide the frame into rectangles of the
7786 size of the smallest character that could be displayed
7787 on it, i.e. into the same rectangles that matrices on
7788 the frame are divided into. */
7790 int width
, height
, gx
, gy
;
7793 if (glyph_rect (f1
, win_x
, win_y
, &rect
))
7794 last_mouse_glyph
= rect
;
7797 width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
7798 height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
7802 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
7803 round down even for negative values. */
7808 gx
= (gx
+ width
- 1) / width
* width
;
7809 gy
= (gy
+ height
- 1) / height
* height
;
7811 last_mouse_glyph
.width
= width
;
7812 last_mouse_glyph
.height
= height
;
7813 last_mouse_glyph
.x
= gx
;
7814 last_mouse_glyph
.y
= gy
;
7820 XSETINT (*x
, win_x
);
7821 XSETINT (*y
, win_y
);
7822 *time
= last_mouse_movement_time
;
7831 #ifdef USE_X_TOOLKIT
7833 /* Atimer callback function for TIMER. Called every 0.1s to process
7834 Xt timeouts, if needed. We must avoid calling XtAppPending as
7835 much as possible because that function does an implicit XFlush
7836 that slows us down. */
7839 x_process_timeouts (timer
)
7840 struct atimer
*timer
;
7842 if (toolkit_scroll_bar_interaction
|| popup_activated_flag
)
7845 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
7846 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
7851 #endif /* USE_X_TOOLKIT */
7854 /* Scroll bar support. */
7856 /* Given an X window ID, find the struct scroll_bar which manages it.
7857 This can be called in GC, so we have to make sure to strip off mark
7860 static struct scroll_bar
*
7861 x_window_to_scroll_bar (window_id
)
7866 for (tail
= Vframe_list
;
7867 XGCTYPE (tail
) == Lisp_Cons
;
7870 Lisp_Object frame
, bar
, condemned
;
7872 frame
= XCAR (tail
);
7873 /* All elements of Vframe_list should be frames. */
7874 if (! GC_FRAMEP (frame
))
7877 /* Scan this frame's scroll bar list for a scroll bar with the
7879 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
7880 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
7881 /* This trick allows us to search both the ordinary and
7882 condemned scroll bar lists with one loop. */
7883 ! GC_NILP (bar
) || (bar
= condemned
,
7886 bar
= XSCROLL_BAR (bar
)->next
)
7887 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
7888 return XSCROLL_BAR (bar
);
7896 /************************************************************************
7898 ************************************************************************/
7900 #ifdef USE_TOOLKIT_SCROLL_BARS
7902 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
7903 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
7904 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
7905 struct scroll_bar
*));
7906 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
7910 /* Id of action hook installed for scroll bars. */
7912 static XtActionHookId action_hook_id
;
7914 /* Lisp window being scrolled. Set when starting to interact with
7915 a toolkit scroll bar, reset to nil when ending the interaction. */
7917 static Lisp_Object window_being_scrolled
;
7919 /* Last scroll bar part sent in xm_scroll_callback. */
7921 static int last_scroll_bar_part
;
7923 /* Whether this is an Xaw with arrow-scrollbars. This should imply
7924 that movements of 1/20 of the screen size are mapped to up/down. */
7926 static Boolean xaw3d_arrow_scroll
;
7928 /* Whether the drag scrolling maintains the mouse at the top of the
7929 thumb. If not, resizing the thumb needs to be done more carefully
7930 to avoid jerkyness. */
7932 static Boolean xaw3d_pick_top
;
7935 /* Action hook installed via XtAppAddActionHook when toolkit scroll
7936 bars are used.. The hook is responsible for detecting when
7937 the user ends an interaction with the scroll bar, and generates
7938 a `end-scroll' scroll_bar_click' event if so. */
7941 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
7944 XtPointer client_data
;
7948 Cardinal
*num_params
;
7954 scroll_bar_p
= XmIsScrollBar (widget
);
7955 end_action
= "Release";
7956 #else /* !USE_MOTIF i.e. use Xaw */
7957 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
7958 end_action
= "EndScroll";
7959 #endif /* USE_MOTIF */
7962 && strcmp (action_name
, end_action
) == 0
7963 && WINDOWP (window_being_scrolled
))
7967 x_send_scroll_bar_event (window_being_scrolled
,
7968 scroll_bar_end_scroll
, 0, 0);
7969 w
= XWINDOW (window_being_scrolled
);
7970 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
7971 window_being_scrolled
= Qnil
;
7972 last_scroll_bar_part
= -1;
7974 /* Xt timeouts no longer needed. */
7975 toolkit_scroll_bar_interaction
= 0;
7979 /* A vector of windows used for communication between
7980 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
7982 static struct window
**scroll_bar_windows
;
7983 static int scroll_bar_windows_size
;
7986 /* Send a client message with message type Xatom_Scrollbar for a
7987 scroll action to the frame of WINDOW. PART is a value identifying
7988 the part of the scroll bar that was clicked on. PORTION is the
7989 amount to scroll of a whole of WHOLE. */
7992 x_send_scroll_bar_event (window
, part
, portion
, whole
)
7994 int part
, portion
, whole
;
7997 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
7998 struct window
*w
= XWINDOW (window
);
7999 struct frame
*f
= XFRAME (w
->frame
);
8004 /* Construct a ClientMessage event to send to the frame. */
8005 ev
->type
= ClientMessage
;
8006 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
8007 ev
->display
= FRAME_X_DISPLAY (f
);
8008 ev
->window
= FRAME_X_WINDOW (f
);
8011 /* We can only transfer 32 bits in the XClientMessageEvent, which is
8012 not enough to store a pointer or Lisp_Object on a 64 bit system.
8013 So, store the window in scroll_bar_windows and pass the index
8014 into that array in the event. */
8015 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
8016 if (scroll_bar_windows
[i
] == NULL
)
8019 if (i
== scroll_bar_windows_size
)
8021 int new_size
= max (10, 2 * scroll_bar_windows_size
);
8022 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
8023 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
8025 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
8027 bzero (&scroll_bar_windows
[i
], nbytes
- old_nbytes
);
8028 scroll_bar_windows_size
= new_size
;
8031 scroll_bar_windows
[i
] = w
;
8032 ev
->data
.l
[0] = (long) i
;
8033 ev
->data
.l
[1] = (long) part
;
8034 ev
->data
.l
[2] = (long) 0;
8035 ev
->data
.l
[3] = (long) portion
;
8036 ev
->data
.l
[4] = (long) whole
;
8038 /* Make Xt timeouts work while the scroll bar is active. */
8039 toolkit_scroll_bar_interaction
= 1;
8041 /* Setting the event mask to zero means that the message will
8042 be sent to the client that created the window, and if that
8043 window no longer exists, no event will be sent. */
8044 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
8049 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
8053 x_scroll_bar_to_input_event (event
, ievent
)
8055 struct input_event
*ievent
;
8057 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
8062 w
= scroll_bar_windows
[ev
->data
.l
[0]];
8063 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
8065 XSETWINDOW (window
, w
);
8066 f
= XFRAME (w
->frame
);
8068 ievent
->kind
= scroll_bar_click
;
8069 ievent
->frame_or_window
= window
;
8071 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
8072 ievent
->part
= ev
->data
.l
[1];
8073 ievent
->code
= ev
->data
.l
[2];
8074 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
8075 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
8076 ievent
->modifiers
= 0;
8082 /* Minimum and maximum values used for Motif scroll bars. */
8085 #define XM_SB_MAX 10000000
8086 #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN)
8089 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
8090 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
8091 CALL_DATA is a pointer a a XmScrollBarCallbackStruct. */
8094 xm_scroll_callback (widget
, client_data
, call_data
)
8096 XtPointer client_data
, call_data
;
8098 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8099 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
8101 int part
= -1, whole
= 0, portion
= 0;
8105 case XmCR_DECREMENT
:
8106 bar
->dragging
= Qnil
;
8107 part
= scroll_bar_up_arrow
;
8110 case XmCR_INCREMENT
:
8111 bar
->dragging
= Qnil
;
8112 part
= scroll_bar_down_arrow
;
8115 case XmCR_PAGE_DECREMENT
:
8116 bar
->dragging
= Qnil
;
8117 part
= scroll_bar_above_handle
;
8120 case XmCR_PAGE_INCREMENT
:
8121 bar
->dragging
= Qnil
;
8122 part
= scroll_bar_below_handle
;
8126 bar
->dragging
= Qnil
;
8127 part
= scroll_bar_to_top
;
8130 case XmCR_TO_BOTTOM
:
8131 bar
->dragging
= Qnil
;
8132 part
= scroll_bar_to_bottom
;
8138 int dragging_down_p
= (INTEGERP (bar
->dragging
)
8139 && XINT (bar
->dragging
) <= cs
->value
);
8141 /* Get the slider size. */
8143 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
8146 /* At the max position of the scroll bar, do a line-wise
8147 movement. Without doing anything, we would be called with
8148 the same cs->value again and again. If we want to make
8149 sure that we can reach the end of the buffer, we have to do
8152 Implementation note: setting bar->dragging always to
8153 cs->value gives a smoother movement at the max position.
8154 Setting it to nil when doing line-wise movement gives
8155 a better slider behavior. */
8157 if (cs
->value
+ slider_size
== XM_SB_MAX
8159 && last_scroll_bar_part
== scroll_bar_down_arrow
))
8161 part
= scroll_bar_down_arrow
;
8162 bar
->dragging
= Qnil
;
8166 whole
= XM_SB_RANGE
;
8167 portion
= min (cs
->value
- XM_SB_MIN
, XM_SB_MAX
- slider_size
);
8168 part
= scroll_bar_handle
;
8169 bar
->dragging
= make_number (cs
->value
);
8174 case XmCR_VALUE_CHANGED
:
8180 window_being_scrolled
= bar
->window
;
8181 last_scroll_bar_part
= part
;
8182 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
8187 #else /* !USE_MOTIF, i.e. Xaw. */
8190 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
8191 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
8192 scroll bar struct. CALL_DATA is a pointer to a float saying where
8196 xaw_jump_callback (widget
, client_data
, call_data
)
8198 XtPointer client_data
, call_data
;
8200 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8201 float top
= *(float *) call_data
;
8203 int whole
, portion
, height
;
8206 /* Get the size of the thumb, a value between 0 and 1. */
8208 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
8212 portion
= shown
< 1 ? top
* whole
: 0;
8214 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
8215 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
8216 the bottom, so we force the scrolling whenever we see that we're
8217 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
8218 we try to ensure that we always stay two pixels away from the
8220 part
= scroll_bar_down_arrow
;
8222 part
= scroll_bar_handle
;
8224 window_being_scrolled
= bar
->window
;
8225 bar
->dragging
= make_number (portion
);
8226 last_scroll_bar_part
= part
;
8227 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
8231 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
8232 i.e. line or page up or down. WIDGET is the Xaw scroll bar
8233 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
8234 the scroll bar. CALL_DATA is an integer specifying the action that
8235 has taken place. It's magnitude is in the range 0..height of the
8236 scroll bar. Negative values mean scroll towards buffer start.
8237 Values < height of scroll bar mean line-wise movement. */
8240 xaw_scroll_callback (widget
, client_data
, call_data
)
8242 XtPointer client_data
, call_data
;
8244 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8245 int position
= (int) call_data
;
8249 /* Get the height of the scroll bar. */
8251 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
8254 if (abs (position
) >= height
)
8255 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
8257 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
8258 it maps line-movement to call_data = max(5, height/20). */
8259 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
8260 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
8262 part
= scroll_bar_move_ratio
;
8264 window_being_scrolled
= bar
->window
;
8265 bar
->dragging
= Qnil
;
8266 last_scroll_bar_part
= part
;
8267 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
8271 #endif /* not USE_MOTIF */
8274 /* Create the widget for scroll bar BAR on frame F. Record the widget
8275 and X window of the scroll bar in BAR. */
8278 x_create_toolkit_scroll_bar (f
, bar
)
8280 struct scroll_bar
*bar
;
8286 char *scroll_bar_name
= "verticalScrollBar";
8287 unsigned long pixel
;
8292 /* Set resources. Create the widget. */
8293 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
8294 XtSetArg (av
[ac
], XmNminimum
, XM_SB_MIN
); ++ac
;
8295 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
8296 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
8297 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
8298 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
8299 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
8301 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
8304 XtSetArg (av
[ac
], XmNforeground
, pixel
);
8308 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8311 XtSetArg (av
[ac
], XmNbackground
, pixel
);
8315 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
8316 scroll_bar_name
, av
, ac
);
8318 /* Add one callback for everything that can happen. */
8319 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
8321 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
8323 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
8325 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
8327 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
8329 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
8331 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
8334 /* Realize the widget. Only after that is the X window created. */
8335 XtRealizeWidget (widget
);
8337 /* Set the cursor to an arrow. I didn't find a resource to do that.
8338 And I'm wondering why it hasn't an arrow cursor by default. */
8339 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
8340 f
->output_data
.x
->nontext_cursor
);
8342 #else /* !USE_MOTIF i.e. use Xaw */
8344 /* Set resources. Create the widget. The background of the
8345 Xaw3d scroll bar widget is a little bit light for my taste.
8346 We don't alter it here to let users change it according
8347 to their taste with `emacs*verticalScrollBar.background: xxx'. */
8348 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
8349 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
8350 /* For smoother scrolling with Xaw3d -sm */
8351 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
8352 /* XtSetArg (av[ac], XtNbeNiceToColormap, True); ++ac; */
8354 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
8357 XtSetArg (av
[ac
], XtNforeground
, pixel
);
8361 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8364 XtSetArg (av
[ac
], XtNbackground
, pixel
);
8368 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
8369 f
->output_data
.x
->edit_widget
, av
, ac
);
8373 char *val
= initial
;
8374 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
8375 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
8377 { /* ARROW_SCROLL */
8378 xaw3d_arrow_scroll
= True
;
8379 /* Isn't that just a personal preference ? -sm */
8380 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
8384 /* Define callbacks. */
8385 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
8386 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
8389 /* Realize the widget. Only after that is the X window created. */
8390 XtRealizeWidget (widget
);
8392 #endif /* !USE_MOTIF */
8394 /* Install an action hook that let's us detect when the user
8395 finishes interacting with a scroll bar. */
8396 if (action_hook_id
== 0)
8397 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
8399 /* Remember X window and widget in the scroll bar vector. */
8400 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
8401 xwindow
= XtWindow (widget
);
8402 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
8408 /* Set the thumb size and position of scroll bar BAR. We are currently
8409 displaying PORTION out of a whole WHOLE, and our position POSITION. */
8412 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
8413 struct scroll_bar
*bar
;
8414 int portion
, position
, whole
;
8416 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8417 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
8424 top
= (float) position
/ whole
;
8425 shown
= (float) portion
/ whole
;
8433 XmScrollBarWidget sb
;
8435 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
8436 is the scroll bar's maximum and MIN is the scroll bar's minimum
8438 size
= shown
* XM_SB_RANGE
;
8439 size
= min (size
, XM_SB_RANGE
);
8440 size
= max (size
, 1);
8442 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
8443 value
= top
* XM_SB_RANGE
;
8444 value
= min (value
, XM_SB_MAX
- size
);
8445 value
= max (value
, XM_SB_MIN
);
8447 if (NILP (bar
->dragging
))
8448 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
8449 else if (last_scroll_bar_part
== scroll_bar_down_arrow
)
8450 /* This has the negative side effect that the slider value is
8451 not what it would be if we scrolled here using line-wise or
8452 page-wise movement. */
8453 XmScrollBarSetValues (widget
, value
, XM_SB_RANGE
- value
, 0, 0, False
);
8456 /* If currently dragging, only update the slider size.
8457 This reduces flicker effects. */
8458 int old_value
, old_size
, increment
, page_increment
;
8460 XmScrollBarGetValues (widget
, &old_value
, &old_size
,
8461 &increment
, &page_increment
);
8462 XmScrollBarSetValues (widget
, old_value
,
8463 min (size
, XM_SB_RANGE
- old_value
),
8467 #else /* !USE_MOTIF i.e. use Xaw */
8469 float old_top
, old_shown
;
8471 XtVaGetValues (widget
,
8472 XtNtopOfThumb
, &old_top
,
8473 XtNshown
, &old_shown
,
8477 /* Massage the top+shown values. */
8478 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
8479 top
= max (0, min (1, top
));
8482 /* Keep two pixels available for moving the thumb down. */
8483 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
8485 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
8486 check that your system's configuration file contains a define
8487 for `NARROWPROTO'. See s/freebsd.h for an example. */
8488 if (top
!= old_top
|| shown
!= old_shown
)
8490 if (NILP (bar
->dragging
))
8491 XawScrollbarSetThumb (widget
, top
, shown
);
8495 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
8496 int scroll_mode
= 0;
8498 /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR. */
8499 if (xaw3d_arrow_scroll
)
8501 /* Xaw3d stupidly ignores resize requests while dragging
8502 so we have to make it believe it's not in dragging mode. */
8503 scroll_mode
= sb
->scrollbar
.scroll_mode
;
8504 if (scroll_mode
== 2)
8505 sb
->scrollbar
.scroll_mode
= 0;
8508 /* Try to make the scrolling a tad smoother. */
8509 if (!xaw3d_pick_top
)
8510 shown
= min (shown
, old_shown
);
8512 XawScrollbarSetThumb (widget
, top
, shown
);
8515 if (xaw3d_arrow_scroll
&& scroll_mode
== 2)
8516 sb
->scrollbar
.scroll_mode
= scroll_mode
;
8521 #endif /* !USE_MOTIF */
8526 #endif /* USE_TOOLKIT_SCROLL_BARS */
8530 /************************************************************************
8531 Scroll bars, general
8532 ************************************************************************/
8534 /* Create a scroll bar and return the scroll bar vector for it. W is
8535 the Emacs window on which to create the scroll bar. TOP, LEFT,
8536 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
8539 static struct scroll_bar
*
8540 x_scroll_bar_create (w
, top
, left
, width
, height
)
8542 int top
, left
, width
, height
;
8544 struct frame
*f
= XFRAME (w
->frame
);
8545 struct scroll_bar
*bar
8546 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
8550 #ifdef USE_TOOLKIT_SCROLL_BARS
8551 x_create_toolkit_scroll_bar (f
, bar
);
8552 #else /* not USE_TOOLKIT_SCROLL_BARS */
8554 XSetWindowAttributes a
;
8558 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8559 if (a
.background_pixel
== -1)
8560 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
8562 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
8563 | ButtonMotionMask
| PointerMotionHintMask
8565 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
8567 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
8569 /* Clear the area of W that will serve as a scroll bar. This is
8570 for the case that a window has been split horizontally. In
8571 this case, no clear_frame is generated to reduce flickering. */
8572 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8574 window_box_height (w
), False
);
8576 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8577 /* Position and size of scroll bar. */
8578 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8580 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8582 /* Border width, depth, class, and visual. */
8589 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
8591 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8593 XSETWINDOW (bar
->window
, w
);
8594 XSETINT (bar
->top
, top
);
8595 XSETINT (bar
->left
, left
);
8596 XSETINT (bar
->width
, width
);
8597 XSETINT (bar
->height
, height
);
8598 XSETINT (bar
->start
, 0);
8599 XSETINT (bar
->end
, 0);
8600 bar
->dragging
= Qnil
;
8602 /* Add bar to its frame's list of scroll bars. */
8603 bar
->next
= FRAME_SCROLL_BARS (f
);
8605 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8606 if (!NILP (bar
->next
))
8607 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8609 /* Map the window/widget. */
8610 #ifdef USE_TOOLKIT_SCROLL_BARS
8612 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
8613 XtConfigureWidget (scroll_bar
,
8614 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8616 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8617 max (height
, 1), 0);
8618 XtMapWidget (scroll_bar
);
8620 #else /* not USE_TOOLKIT_SCROLL_BARS */
8621 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
8622 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8629 /* Draw BAR's handle in the proper position.
8631 If the handle is already drawn from START to END, don't bother
8632 redrawing it, unless REBUILD is non-zero; in that case, always
8633 redraw it. (REBUILD is handy for drawing the handle after expose
8636 Normally, we want to constrain the start and end of the handle to
8637 fit inside its rectangle, but if the user is dragging the scroll
8638 bar handle, we want to let them drag it down all the way, so that
8639 the bar's top is as far down as it goes; otherwise, there's no way
8640 to move to the very end of the buffer. */
8642 #ifndef USE_TOOLKIT_SCROLL_BARS
8645 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
8646 struct scroll_bar
*bar
;
8650 int dragging
= ! NILP (bar
->dragging
);
8651 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8652 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8653 GC gc
= f
->output_data
.x
->normal_gc
;
8655 /* If the display is already accurate, do nothing. */
8657 && start
== XINT (bar
->start
)
8658 && end
== XINT (bar
->end
))
8664 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
8665 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8666 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8668 /* Make sure the values are reasonable, and try to preserve
8669 the distance between start and end. */
8671 int length
= end
- start
;
8675 else if (start
> top_range
)
8677 end
= start
+ length
;
8681 else if (end
> top_range
&& ! dragging
)
8685 /* Store the adjusted setting in the scroll bar. */
8686 XSETINT (bar
->start
, start
);
8687 XSETINT (bar
->end
, end
);
8689 /* Clip the end position, just for display. */
8690 if (end
> top_range
)
8693 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
8694 below top positions, to make sure the handle is always at least
8695 that many pixels tall. */
8696 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
8698 /* Draw the empty space above the handle. Note that we can't clear
8699 zero-height areas; that means "clear to end of window." */
8701 x_clear_area (FRAME_X_DISPLAY (f
), w
,
8702 /* x, y, width, height, and exposures. */
8703 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8704 VERTICAL_SCROLL_BAR_TOP_BORDER
,
8705 inside_width
, start
,
8708 /* Change to proper foreground color if one is specified. */
8709 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8710 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8711 f
->output_data
.x
->scroll_bar_foreground_pixel
);
8713 /* Draw the handle itself. */
8714 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
8716 /* x, y, width, height */
8717 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8718 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
8719 inside_width
, end
- start
);
8721 /* Restore the foreground color of the GC if we changed it above. */
8722 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8723 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8724 f
->output_data
.x
->foreground_pixel
);
8726 /* Draw the empty space below the handle. Note that we can't
8727 clear zero-height areas; that means "clear to end of window." */
8728 if (end
< inside_height
)
8729 x_clear_area (FRAME_X_DISPLAY (f
), w
,
8730 /* x, y, width, height, and exposures. */
8731 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8732 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
8733 inside_width
, inside_height
- end
,
8741 #endif /* !USE_TOOLKIT_SCROLL_BARS */
8743 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
8747 x_scroll_bar_remove (bar
)
8748 struct scroll_bar
*bar
;
8750 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8753 #ifdef USE_TOOLKIT_SCROLL_BARS
8754 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
8756 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
8759 /* Disassociate this scroll bar from its window. */
8760 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
8766 /* Set the handle of the vertical scroll bar for WINDOW to indicate
8767 that we are displaying PORTION characters out of a total of WHOLE
8768 characters, starting at POSITION. If WINDOW has no scroll bar,
8772 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
8774 int portion
, whole
, position
;
8776 struct frame
*f
= XFRAME (w
->frame
);
8777 struct scroll_bar
*bar
;
8778 int top
, height
, left
, sb_left
, width
, sb_width
;
8779 int window_x
, window_y
, window_width
, window_height
;
8781 /* Get window dimensions. */
8782 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
8784 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
8785 height
= window_height
;
8787 /* Compute the left edge of the scroll bar area. */
8788 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8789 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
8791 left
= XFASTINT (w
->left
);
8792 left
*= CANON_X_UNIT (f
);
8793 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
8795 /* Compute the width of the scroll bar which might be less than
8796 the width of the area reserved for the scroll bar. */
8797 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
8798 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
8802 /* Compute the left edge of the scroll bar. */
8803 #ifdef USE_TOOLKIT_SCROLL_BARS
8804 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8805 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
8807 sb_left
= left
+ (width
- sb_width
) / 2;
8809 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8810 sb_left
= left
+ width
- sb_width
;
8815 /* Does the scroll bar exist yet? */
8816 if (NILP (w
->vertical_scroll_bar
))
8819 if (width
&& height
)
8820 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8821 left
, top
, width
, height
, False
);
8823 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
8827 /* It may just need to be moved and resized. */
8828 unsigned int mask
= 0;
8830 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
8834 if (sb_left
!= XINT (bar
->left
))
8836 if (top
!= XINT (bar
->top
))
8838 if (sb_width
!= XINT (bar
->width
))
8840 if (height
!= XINT (bar
->height
))
8843 #ifdef USE_TOOLKIT_SCROLL_BARS
8845 /* Since toolkit scroll bars are smaller than the space reserved
8846 for them on the frame, we have to clear "under" them. */
8847 if (width
&& height
)
8848 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8849 left
, top
, width
, height
, False
);
8851 /* Move/size the scroll bar widget. */
8853 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
8854 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8856 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8857 max (height
, 1), 0);
8859 #else /* not USE_TOOLKIT_SCROLL_BARS */
8861 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
8863 /* Clear areas not covered by the scroll bar. This makes sure a
8864 previous mode line display is cleared after C-x 2 C-x 1, for
8865 example. Non-toolkit scroll bars are as wide as the area
8866 reserved for scroll bars - trim at both sides. */
8867 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8868 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8870 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8871 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8872 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8876 /* Move/size the scroll bar window. */
8881 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
8883 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
8885 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
8889 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8891 /* Remember new settings. */
8892 XSETINT (bar
->left
, sb_left
);
8893 XSETINT (bar
->top
, top
);
8894 XSETINT (bar
->width
, sb_width
);
8895 XSETINT (bar
->height
, height
);
8900 #ifdef USE_TOOLKIT_SCROLL_BARS
8901 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
8902 #else /* not USE_TOOLKIT_SCROLL_BARS */
8903 /* Set the scroll bar's current state, unless we're currently being
8905 if (NILP (bar
->dragging
))
8907 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
8910 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
8913 int start
= ((double) position
* top_range
) / whole
;
8914 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
8915 x_scroll_bar_set_handle (bar
, start
, end
, 0);
8918 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8920 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
8924 /* The following three hooks are used when we're doing a thorough
8925 redisplay of the frame. We don't explicitly know which scroll bars
8926 are going to be deleted, because keeping track of when windows go
8927 away is a real pain - "Can you say set-window-configuration, boys
8928 and girls?" Instead, we just assert at the beginning of redisplay
8929 that *all* scroll bars are to be removed, and then save a scroll bar
8930 from the fiery pit when we actually redisplay its window. */
8932 /* Arrange for all scroll bars on FRAME to be removed at the next call
8933 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
8934 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
8937 XTcondemn_scroll_bars (frame
)
8940 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
8941 while (! NILP (FRAME_SCROLL_BARS (frame
)))
8944 bar
= FRAME_SCROLL_BARS (frame
);
8945 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
8946 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
8947 XSCROLL_BAR (bar
)->prev
= Qnil
;
8948 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
8949 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
8950 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
8955 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
8956 Note that WINDOW isn't necessarily condemned at all. */
8959 XTredeem_scroll_bar (window
)
8960 struct window
*window
;
8962 struct scroll_bar
*bar
;
8965 /* We can't redeem this window's scroll bar if it doesn't have one. */
8966 if (NILP (window
->vertical_scroll_bar
))
8969 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
8971 /* Unlink it from the condemned list. */
8972 f
= XFRAME (WINDOW_FRAME (window
));
8973 if (NILP (bar
->prev
))
8975 /* If the prev pointer is nil, it must be the first in one of
8977 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
8978 /* It's not condemned. Everything's fine. */
8980 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
8981 window
->vertical_scroll_bar
))
8982 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
8984 /* If its prev pointer is nil, it must be at the front of
8985 one or the other! */
8989 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
8991 if (! NILP (bar
->next
))
8992 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
8994 bar
->next
= FRAME_SCROLL_BARS (f
);
8996 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8997 if (! NILP (bar
->next
))
8998 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
9001 /* Remove all scroll bars on FRAME that haven't been saved since the
9002 last call to `*condemn_scroll_bars_hook'. */
9005 XTjudge_scroll_bars (f
)
9008 Lisp_Object bar
, next
;
9010 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
9012 /* Clear out the condemned list now so we won't try to process any
9013 more events on the hapless scroll bars. */
9014 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
9016 for (; ! NILP (bar
); bar
= next
)
9018 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
9020 x_scroll_bar_remove (b
);
9023 b
->next
= b
->prev
= Qnil
;
9026 /* Now there should be no references to the condemned scroll bars,
9027 and they should get garbage-collected. */
9031 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
9032 is a no-op when using toolkit scroll bars.
9034 This may be called from a signal handler, so we have to ignore GC
9038 x_scroll_bar_expose (bar
, event
)
9039 struct scroll_bar
*bar
;
9042 #ifndef USE_TOOLKIT_SCROLL_BARS
9044 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9045 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9046 GC gc
= f
->output_data
.x
->normal_gc
;
9047 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
9051 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
9053 /* Draw a one-pixel border just inside the edges of the scroll bar. */
9054 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
9056 /* x, y, width, height */
9058 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
9059 XINT (bar
->height
) - 1);
9063 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9066 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
9067 is set to something other than no_event, it is enqueued.
9069 This may be called from a signal handler, so we have to ignore GC
9072 #ifndef USE_TOOLKIT_SCROLL_BARS
9075 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
9076 struct scroll_bar
*bar
;
9078 struct input_event
*emacs_event
;
9080 if (! GC_WINDOWP (bar
->window
))
9083 emacs_event
->kind
= scroll_bar_click
;
9084 emacs_event
->code
= event
->xbutton
.button
- Button1
;
9085 emacs_event
->modifiers
9086 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
9087 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
9088 event
->xbutton
.state
)
9089 | (event
->type
== ButtonRelease
9092 emacs_event
->frame_or_window
= bar
->window
;
9093 emacs_event
->arg
= Qnil
;
9094 emacs_event
->timestamp
= event
->xbutton
.time
;
9097 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9099 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9102 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9103 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
9106 if (y
> top_range
) y
= top_range
;
9108 if (y
< XINT (bar
->start
))
9109 emacs_event
->part
= scroll_bar_above_handle
;
9110 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
9111 emacs_event
->part
= scroll_bar_handle
;
9113 emacs_event
->part
= scroll_bar_below_handle
;
9115 /* Just because the user has clicked on the handle doesn't mean
9116 they want to drag it. Lisp code needs to be able to decide
9117 whether or not we're dragging. */
9119 /* If the user has just clicked on the handle, record where they're
9121 if (event
->type
== ButtonPress
9122 && emacs_event
->part
== scroll_bar_handle
)
9123 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
9126 /* If the user has released the handle, set it to its final position. */
9127 if (event
->type
== ButtonRelease
9128 && ! NILP (bar
->dragging
))
9130 int new_start
= y
- XINT (bar
->dragging
);
9131 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
9133 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
9134 bar
->dragging
= Qnil
;
9137 /* Same deal here as the other #if 0. */
9139 /* Clicks on the handle are always reported as occurring at the top of
9141 if (emacs_event
->part
== scroll_bar_handle
)
9142 emacs_event
->x
= bar
->start
;
9144 XSETINT (emacs_event
->x
, y
);
9146 XSETINT (emacs_event
->x
, y
);
9149 XSETINT (emacs_event
->y
, top_range
);
9153 /* Handle some mouse motion while someone is dragging the scroll bar.
9155 This may be called from a signal handler, so we have to ignore GC
9159 x_scroll_bar_note_movement (bar
, event
)
9160 struct scroll_bar
*bar
;
9163 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
9165 last_mouse_movement_time
= event
->xmotion
.time
;
9168 XSETVECTOR (last_mouse_scroll_bar
, bar
);
9170 /* If we're dragging the bar, display it. */
9171 if (! GC_NILP (bar
->dragging
))
9173 /* Where should the handle be now? */
9174 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
9176 if (new_start
!= XINT (bar
->start
))
9178 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
9180 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
9185 #endif /* !USE_TOOLKIT_SCROLL_BARS */
9187 /* Return information to the user about the current position of the mouse
9188 on the scroll bar. */
9191 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
9193 Lisp_Object
*bar_window
;
9194 enum scroll_bar_part
*part
;
9196 unsigned long *time
;
9198 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
9199 Window w
= SCROLL_BAR_X_WINDOW (bar
);
9200 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
9202 Window dummy_window
;
9204 unsigned int dummy_mask
;
9208 /* Get the mouse's position relative to the scroll bar window, and
9210 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
9212 /* Root, child, root x and root y. */
9213 &dummy_window
, &dummy_window
,
9214 &dummy_coord
, &dummy_coord
,
9216 /* Position relative to scroll bar. */
9219 /* Mouse buttons and modifier keys. */
9226 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9229 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9231 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
9233 if (! NILP (bar
->dragging
))
9234 win_y
-= XINT (bar
->dragging
);
9238 if (win_y
> top_range
)
9242 *bar_window
= bar
->window
;
9244 if (! NILP (bar
->dragging
))
9245 *part
= scroll_bar_handle
;
9246 else if (win_y
< XINT (bar
->start
))
9247 *part
= scroll_bar_above_handle
;
9248 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
9249 *part
= scroll_bar_handle
;
9251 *part
= scroll_bar_below_handle
;
9253 XSETINT (*x
, win_y
);
9254 XSETINT (*y
, top_range
);
9257 last_mouse_scroll_bar
= Qnil
;
9260 *time
= last_mouse_movement_time
;
9266 /* The screen has been cleared so we may have changed foreground or
9267 background colors, and the scroll bars may need to be redrawn.
9268 Clear out the scroll bars, and ask for expose events, so we can
9272 x_scroll_bar_clear (f
)
9275 #ifndef USE_TOOLKIT_SCROLL_BARS
9278 /* We can have scroll bars even if this is 0,
9279 if we just turned off scroll bar mode.
9280 But in that case we should not clear them. */
9281 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9282 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
9283 bar
= XSCROLL_BAR (bar
)->next
)
9284 XClearArea (FRAME_X_DISPLAY (f
),
9285 SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
9287 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9290 /* This processes Expose events from the menu-bar specific X event
9291 loop in xmenu.c. This allows to redisplay the frame if necessary
9292 when handling menu-bar or pop-up items. */
9295 process_expose_from_menu (event
)
9299 struct x_display_info
*dpyinfo
;
9300 int frame_exposed_p
= 0;
9304 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
9305 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
9308 if (f
->async_visible
== 0)
9310 f
->async_visible
= 1;
9311 f
->async_iconified
= 0;
9312 f
->output_data
.x
->has_been_visible
= 1;
9313 SET_FRAME_GARBAGED (f
);
9317 expose_frame (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
9318 event
.xexpose
.x
, event
.xexpose
.y
,
9319 event
.xexpose
.width
, event
.xexpose
.height
);
9320 frame_exposed_p
= 1;
9325 struct scroll_bar
*bar
9326 = x_window_to_scroll_bar (event
.xexpose
.window
);
9329 x_scroll_bar_expose (bar
, &event
);
9333 return frame_exposed_p
;
9336 /* Define a queue to save up SelectionRequest events for later handling. */
9338 struct selection_event_queue
9341 struct selection_event_queue
*next
;
9344 static struct selection_event_queue
*queue
;
9346 /* Nonzero means queue up certain events--don't process them yet. */
9348 static int x_queue_selection_requests
;
9350 /* Queue up an X event *EVENT, to be processed later. */
9353 x_queue_event (f
, event
)
9357 struct selection_event_queue
*queue_tmp
9358 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
9360 if (queue_tmp
!= NULL
)
9362 queue_tmp
->event
= *event
;
9363 queue_tmp
->next
= queue
;
9368 /* Take all the queued events and put them back
9369 so that they get processed afresh. */
9372 x_unqueue_events (display
)
9375 while (queue
!= NULL
)
9377 struct selection_event_queue
*queue_tmp
= queue
;
9378 XPutBackEvent (display
, &queue_tmp
->event
);
9379 queue
= queue_tmp
->next
;
9380 xfree ((char *)queue_tmp
);
9384 /* Start queuing SelectionRequest events. */
9387 x_start_queuing_selection_requests (display
)
9390 x_queue_selection_requests
++;
9393 /* Stop queuing SelectionRequest events. */
9396 x_stop_queuing_selection_requests (display
)
9399 x_queue_selection_requests
--;
9400 x_unqueue_events (display
);
9403 /* The main X event-reading loop - XTread_socket. */
9405 /* Time stamp of enter window event. This is only used by XTread_socket,
9406 but we have to put it out here, since static variables within functions
9407 sometimes don't work. */
9409 static Time enter_timestamp
;
9411 /* This holds the state XLookupString needs to implement dead keys
9412 and other tricks known as "compose processing". _X Window System_
9413 says that a portable program can't use this, but Stephen Gildea assures
9414 me that letting the compiler initialize it to zeros will work okay.
9416 This must be defined outside of XTread_socket, for the same reasons
9417 given for enter_time stamp, above. */
9419 static XComposeStatus compose_status
;
9421 /* Record the last 100 characters stored
9422 to help debug the loss-of-chars-during-GC problem. */
9424 static int temp_index
;
9425 static short temp_buffer
[100];
9427 /* Set this to nonzero to fake an "X I/O error"
9428 on a particular display. */
9430 struct x_display_info
*XTread_socket_fake_io_error
;
9432 /* When we find no input here, we occasionally do a no-op command
9433 to verify that the X server is still running and we can still talk with it.
9434 We try all the open displays, one by one.
9435 This variable is used for cycling thru the displays. */
9437 static struct x_display_info
*next_noop_dpyinfo
;
9439 #define SET_SAVED_MENU_EVENT(size) \
9442 if (f->output_data.x->saved_menu_event == 0) \
9443 f->output_data.x->saved_menu_event \
9444 = (XEvent *) xmalloc (sizeof (XEvent)); \
9445 bcopy (&event, f->output_data.x->saved_menu_event, size); \
9446 if (numchars >= 1) \
9448 bufp->kind = menu_bar_activate_event; \
9449 XSETFRAME (bufp->frame_or_window, f); \
9458 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
9459 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
9461 /* Read events coming from the X server.
9462 This routine is called by the SIGIO handler.
9463 We return as soon as there are no more events to be read.
9465 Events representing keys are stored in buffer BUFP,
9466 which can hold up to NUMCHARS characters.
9467 We return the number of characters stored into the buffer,
9468 thus pretending to be `read'.
9470 EXPECTED is nonzero if the caller knows input is available. */
9473 XTread_socket (sd
, bufp
, numchars
, expected
)
9475 /* register */ struct input_event
*bufp
;
9476 /* register */ int numchars
;
9483 int event_found
= 0;
9484 struct x_display_info
*dpyinfo
;
9485 struct coding_system coding
;
9487 if (interrupt_input_blocked
)
9489 interrupt_input_pending
= 1;
9493 interrupt_input_pending
= 0;
9496 /* So people can tell when we have read the available input. */
9497 input_signal_count
++;
9500 abort (); /* Don't think this happens. */
9504 /* The input should be decoded if it is from XIM. Currently the
9505 locale of XIM is the same as that of the system. So, we can use
9506 Vlocale_coding_system which is initialized properly at Emacs
9508 setup_coding_system (Vlocale_coding_system
, &coding
);
9509 coding
.src_multibyte
= 0;
9510 coding
.dst_multibyte
= 1;
9511 /* The input is converted to events, thus we can't handle
9512 composition. Anyway, there's no XIM that gives us composition
9514 coding
.composing
= COMPOSITION_DISABLED
;
9516 /* Find the display we are supposed to read input for.
9517 It's the one communicating on descriptor SD. */
9518 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
9520 #if 0 /* This ought to be unnecessary; let's verify it. */
9522 /* If available, Xlib uses FIOSNBIO to make the socket
9523 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
9524 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
9525 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
9526 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
9527 #endif /* ! defined (FIOSNBIO) */
9530 #if 0 /* This code can't be made to work, with multiple displays,
9531 and appears not to be used on any system any more.
9532 Also keyboard.c doesn't turn O_NDELAY on and off
9533 for X connections. */
9536 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
9538 extern int read_alarm_should_throw
;
9539 read_alarm_should_throw
= 1;
9540 XPeekEvent (dpyinfo
->display
, &event
);
9541 read_alarm_should_throw
= 0;
9543 #endif /* HAVE_SELECT */
9547 /* For debugging, this gives a way to fake an I/O error. */
9548 if (dpyinfo
== XTread_socket_fake_io_error
)
9550 XTread_socket_fake_io_error
= 0;
9551 x_io_error_quitter (dpyinfo
->display
);
9554 while (XPending (dpyinfo
->display
))
9556 XNextEvent (dpyinfo
->display
, &event
);
9560 /* Filter events for the current X input method.
9561 XFilterEvent returns non-zero if the input method has
9562 consumed the event. We pass the frame's X window to
9563 XFilterEvent because that's the one for which the IC
9565 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
9566 event
.xclient
.window
);
9567 if (XFilterEvent (&event
, f1
? FRAME_X_WINDOW (f1
) : None
))
9577 if (event
.xclient
.message_type
9578 == dpyinfo
->Xatom_wm_protocols
9579 && event
.xclient
.format
== 32)
9581 if (event
.xclient
.data
.l
[0]
9582 == dpyinfo
->Xatom_wm_take_focus
)
9584 /* Use x_any_window_to_frame because this
9585 could be the shell widget window
9586 if the frame has no title bar. */
9587 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9589 /* Not quite sure this is needed -pd */
9590 if (f
&& FRAME_XIC (f
))
9591 XSetICFocus (FRAME_XIC (f
));
9593 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
9594 instructs the WM to set the input focus automatically for
9595 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
9596 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
9597 it has set the focus. So, XSetInputFocus below is not
9600 The call to XSetInputFocus below has also caused trouble. In
9601 cases where the XSetInputFocus done by the WM and the one
9602 below are temporally close (on a fast machine), the call
9603 below can generate additional FocusIn events which confuse
9606 /* Since we set WM_TAKE_FOCUS, we must call
9607 XSetInputFocus explicitly. But not if f is null,
9608 since that might be an event for a deleted frame. */
9611 Display
*d
= event
.xclient
.display
;
9612 /* Catch and ignore errors, in case window has been
9613 iconified by a window manager such as GWM. */
9614 int count
= x_catch_errors (d
);
9615 XSetInputFocus (d
, event
.xclient
.window
,
9616 /* The ICCCM says this is
9617 the only valid choice. */
9619 event
.xclient
.data
.l
[1]);
9620 /* This is needed to detect the error
9621 if there is an error. */
9623 x_uncatch_errors (d
, count
);
9625 /* Not certain about handling scroll bars here */
9628 else if (event
.xclient
.data
.l
[0]
9629 == dpyinfo
->Xatom_wm_save_yourself
)
9631 /* Save state modify the WM_COMMAND property to
9632 something which can reinstate us. This notifies
9633 the session manager, who's looking for such a
9634 PropertyNotify. Can restart processing when
9635 a keyboard or mouse event arrives. */
9638 f
= x_top_window_to_frame (dpyinfo
,
9639 event
.xclient
.window
);
9641 /* This is just so we only give real data once
9642 for a single Emacs process. */
9643 if (f
== SELECTED_FRAME ())
9644 XSetCommand (FRAME_X_DISPLAY (f
),
9645 event
.xclient
.window
,
9646 initial_argv
, initial_argc
);
9648 XSetCommand (FRAME_X_DISPLAY (f
),
9649 event
.xclient
.window
,
9653 else if (event
.xclient
.data
.l
[0]
9654 == dpyinfo
->Xatom_wm_delete_window
)
9657 = x_any_window_to_frame (dpyinfo
,
9658 event
.xclient
.window
);
9665 bufp
->kind
= delete_window_event
;
9666 XSETFRAME (bufp
->frame_or_window
, f
);
9675 else if (event
.xclient
.message_type
9676 == dpyinfo
->Xatom_wm_configure_denied
)
9679 else if (event
.xclient
.message_type
9680 == dpyinfo
->Xatom_wm_window_moved
)
9684 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9686 new_x
= event
.xclient
.data
.s
[0];
9687 new_y
= event
.xclient
.data
.s
[1];
9691 f
->output_data
.x
->left_pos
= new_x
;
9692 f
->output_data
.x
->top_pos
= new_y
;
9696 else if (event
.xclient
.message_type
9697 == dpyinfo
->Xatom_editres
)
9700 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9701 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
9704 #endif /* HACK_EDITRES */
9705 else if ((event
.xclient
.message_type
9706 == dpyinfo
->Xatom_DONE
)
9707 || (event
.xclient
.message_type
9708 == dpyinfo
->Xatom_PAGE
))
9710 /* Ghostview job completed. Kill it. We could
9711 reply with "Next" if we received "Page", but we
9712 currently never do because we are interested in
9713 images, only, which should have 1 page. */
9714 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
9716 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9717 x_kill_gs_process (pixmap
, f
);
9718 expose_frame (f
, 0, 0, 0, 0);
9720 #ifdef USE_TOOLKIT_SCROLL_BARS
9721 /* Scroll bar callbacks send a ClientMessage from which
9722 we construct an input_event. */
9723 else if (event
.xclient
.message_type
9724 == dpyinfo
->Xatom_Scrollbar
)
9726 x_scroll_bar_to_input_event (&event
, bufp
);
9727 ++bufp
, ++count
, --numchars
;
9730 #endif /* USE_TOOLKIT_SCROLL_BARS */
9736 case SelectionNotify
:
9737 #ifdef USE_X_TOOLKIT
9738 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
9740 #endif /* not USE_X_TOOLKIT */
9741 x_handle_selection_notify (&event
.xselection
);
9744 case SelectionClear
: /* Someone has grabbed ownership. */
9745 #ifdef USE_X_TOOLKIT
9746 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
9748 #endif /* USE_X_TOOLKIT */
9750 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
9755 bufp
->kind
= selection_clear_event
;
9756 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
9757 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
9758 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
9759 bufp
->frame_or_window
= Qnil
;
9768 case SelectionRequest
: /* Someone wants our selection. */
9769 #ifdef USE_X_TOOLKIT
9770 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
9772 #endif /* USE_X_TOOLKIT */
9773 if (x_queue_selection_requests
)
9774 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
9778 XSelectionRequestEvent
*eventp
= (XSelectionRequestEvent
*) &event
;
9783 bufp
->kind
= selection_request_event
;
9784 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
9785 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
9786 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
9787 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
9788 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
9789 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
9790 bufp
->frame_or_window
= Qnil
;
9799 case PropertyNotify
:
9800 #ifdef USE_X_TOOLKIT
9801 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
9803 #endif /* not USE_X_TOOLKIT */
9804 x_handle_property_notify (&event
.xproperty
);
9807 case ReparentNotify
:
9808 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
9812 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
9813 x_real_positions (f
, &x
, &y
);
9814 f
->output_data
.x
->left_pos
= x
;
9815 f
->output_data
.x
->top_pos
= y
;
9820 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
9823 if (f
->async_visible
== 0)
9825 f
->async_visible
= 1;
9826 f
->async_iconified
= 0;
9827 f
->output_data
.x
->has_been_visible
= 1;
9828 SET_FRAME_GARBAGED (f
);
9831 expose_frame (x_window_to_frame (dpyinfo
,
9832 event
.xexpose
.window
),
9833 event
.xexpose
.x
, event
.xexpose
.y
,
9834 event
.xexpose
.width
, event
.xexpose
.height
);
9838 #ifdef USE_TOOLKIT_SCROLL_BARS
9839 /* Dispatch event to the widget. */
9841 #else /* not USE_TOOLKIT_SCROLL_BARS */
9842 struct scroll_bar
*bar
9843 = x_window_to_scroll_bar (event
.xexpose
.window
);
9846 x_scroll_bar_expose (bar
, &event
);
9847 #ifdef USE_X_TOOLKIT
9850 #endif /* USE_X_TOOLKIT */
9851 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9855 case GraphicsExpose
: /* This occurs when an XCopyArea's
9856 source area was obscured or not
9858 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
9862 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
9863 event
.xgraphicsexpose
.width
,
9864 event
.xgraphicsexpose
.height
);
9866 #ifdef USE_X_TOOLKIT
9869 #endif /* USE_X_TOOLKIT */
9872 case NoExpose
: /* This occurs when an XCopyArea's
9873 source area was completely
9878 /* Redo the mouse-highlight after the tooltip has gone. */
9879 if (event
.xmap
.window
== tip_window
)
9882 redo_mouse_highlight ();
9885 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
9886 if (f
) /* F may no longer exist if
9887 the frame was deleted. */
9889 /* While a frame is unmapped, display generation is
9890 disabled; you don't want to spend time updating a
9891 display that won't ever be seen. */
9892 f
->async_visible
= 0;
9893 /* We can't distinguish, from the event, whether the window
9894 has become iconified or invisible. So assume, if it
9895 was previously visible, than now it is iconified.
9896 But x_make_frame_invisible clears both
9897 the visible flag and the iconified flag;
9898 and that way, we know the window is not iconified now. */
9899 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
9901 f
->async_iconified
= 1;
9903 bufp
->kind
= iconify_event
;
9904 XSETFRAME (bufp
->frame_or_window
, f
);
9914 if (event
.xmap
.window
== tip_window
)
9915 /* The tooltip has been drawn already. Avoid
9916 the SET_FRAME_GARBAGED below. */
9919 /* We use x_top_window_to_frame because map events can
9920 come for sub-windows and they don't mean that the
9921 frame is visible. */
9922 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
9925 f
->async_visible
= 1;
9926 f
->async_iconified
= 0;
9927 f
->output_data
.x
->has_been_visible
= 1;
9929 /* wait_reading_process_input will notice this and update
9930 the frame's display structures. */
9931 SET_FRAME_GARBAGED (f
);
9935 bufp
->kind
= deiconify_event
;
9936 XSETFRAME (bufp
->frame_or_window
, f
);
9942 else if (! NILP (Vframe_list
)
9943 && ! NILP (XCDR (Vframe_list
)))
9944 /* Force a redisplay sooner or later
9945 to update the frame titles
9946 in case this is the second frame. */
9947 record_asynch_buffer_change ();
9952 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
9954 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
9957 /* Scroll bars consume key events, but we want
9958 the keys to go to the scroll bar's frame. */
9959 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
9961 if (widget
&& XmIsScrollBar (widget
))
9963 widget
= XtParent (widget
);
9964 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
9967 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
9971 KeySym keysym
, orig_keysym
;
9972 /* al%imercury@uunet.uu.net says that making this 81
9973 instead of 80 fixed a bug whereby meta chars made
9976 It seems that some version of XmbLookupString has
9977 a bug of not returning XBufferOverflow in
9978 status_return even if the input is too long to
9979 fit in 81 bytes. So, we must prepare sufficient
9980 bytes for copy_buffer. 513 bytes (256 chars for
9981 two-byte character set) seems to be a faily good
9982 approximation. -- 2000.8.10 handa@etl.go.jp */
9983 unsigned char copy_buffer
[513];
9984 unsigned char *copy_bufptr
= copy_buffer
;
9985 int copy_bufsiz
= sizeof (copy_buffer
);
9989 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
9990 extra_keyboard_modifiers
);
9991 modifiers
= event
.xkey
.state
;
9993 /* This will have to go some day... */
9995 /* make_lispy_event turns chars into control chars.
9996 Don't do it here because XLookupString is too eager. */
9997 event
.xkey
.state
&= ~ControlMask
;
9998 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
9999 | dpyinfo
->super_mod_mask
10000 | dpyinfo
->hyper_mod_mask
10001 | dpyinfo
->alt_mod_mask
);
10003 /* In case Meta is ComposeCharacter,
10004 clear its status. According to Markus Ehrnsperger
10005 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
10006 this enables ComposeCharacter to work whether or
10007 not it is combined with Meta. */
10008 if (modifiers
& dpyinfo
->meta_mod_mask
)
10009 bzero (&compose_status
, sizeof (compose_status
));
10014 Status status_return
;
10016 nbytes
= XmbLookupString (FRAME_XIC (f
),
10017 &event
.xkey
, copy_bufptr
,
10018 copy_bufsiz
, &keysym
,
10020 if (status_return
== XBufferOverflow
)
10022 copy_bufsiz
= nbytes
+ 1;
10023 copy_bufptr
= (char *) alloca (copy_bufsiz
);
10024 nbytes
= XmbLookupString (FRAME_XIC (f
),
10025 &event
.xkey
, copy_bufptr
,
10026 copy_bufsiz
, &keysym
,
10030 if (status_return
== XLookupNone
)
10032 else if (status_return
== XLookupChars
)
10037 else if (status_return
!= XLookupKeySym
10038 && status_return
!= XLookupBoth
)
10042 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
10043 copy_bufsiz
, &keysym
,
10046 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
10047 copy_bufsiz
, &keysym
,
10051 orig_keysym
= keysym
;
10055 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
10056 || keysym
== XK_Delete
10057 #ifdef XK_ISO_Left_Tab
10058 || (keysym
>= XK_ISO_Left_Tab
&& keysym
<= XK_ISO_Enter
)
10060 || (keysym
>= XK_Kanji
&& keysym
<= XK_Eisu_toggle
)
10061 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
10062 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
10064 /* This recognizes the "extended function keys".
10065 It seems there's no cleaner way.
10066 Test IsModifierKey to avoid handling mode_switch
10068 || ((unsigned) (keysym
) >= XK_Select
10069 && (unsigned)(keysym
) < XK_KP_Space
)
10071 #ifdef XK_dead_circumflex
10072 || orig_keysym
== XK_dead_circumflex
10074 #ifdef XK_dead_grave
10075 || orig_keysym
== XK_dead_grave
10077 #ifdef XK_dead_tilde
10078 || orig_keysym
== XK_dead_tilde
10080 #ifdef XK_dead_diaeresis
10081 || orig_keysym
== XK_dead_diaeresis
10083 #ifdef XK_dead_macron
10084 || orig_keysym
== XK_dead_macron
10086 #ifdef XK_dead_degree
10087 || orig_keysym
== XK_dead_degree
10089 #ifdef XK_dead_acute
10090 || orig_keysym
== XK_dead_acute
10092 #ifdef XK_dead_cedilla
10093 || orig_keysym
== XK_dead_cedilla
10095 #ifdef XK_dead_breve
10096 || orig_keysym
== XK_dead_breve
10098 #ifdef XK_dead_ogonek
10099 || orig_keysym
== XK_dead_ogonek
10101 #ifdef XK_dead_caron
10102 || orig_keysym
== XK_dead_caron
10104 #ifdef XK_dead_doubleacute
10105 || orig_keysym
== XK_dead_doubleacute
10107 #ifdef XK_dead_abovedot
10108 || orig_keysym
== XK_dead_abovedot
10110 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
10111 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
10112 /* Any "vendor-specific" key is ok. */
10113 || (orig_keysym
& (1 << 28)))
10114 && ! (IsModifierKey (orig_keysym
)
10116 #ifdef XK_Mode_switch
10117 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
10120 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
10122 #endif /* not HAVE_X11R5 */
10125 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
10127 temp_buffer
[temp_index
++] = keysym
;
10128 bufp
->kind
= non_ascii_keystroke
;
10129 bufp
->code
= keysym
;
10130 XSETFRAME (bufp
->frame_or_window
, f
);
10133 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10135 bufp
->timestamp
= event
.xkey
.time
;
10140 else if (numchars
> nbytes
)
10146 for (i
= 0; i
< nbytes
; i
++)
10148 if (temp_index
== (sizeof temp_buffer
10151 temp_buffer
[temp_index
++] = copy_bufptr
[i
];
10154 if (/* If the event is not from XIM, */
10155 event
.xkey
.keycode
!= 0
10156 /* or the current locale doesn't request
10157 decoding of the intup data, ... */
10158 || coding
.type
== coding_type_raw_text
10159 || coding
.type
== coding_type_no_conversion
)
10161 /* ... we can use the input data as is. */
10166 /* We have to decode the input data. */
10170 require
= decoding_buffer_size (&coding
, nbytes
);
10171 p
= (unsigned char *) alloca (require
);
10172 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
10173 decode_coding (&coding
, copy_bufptr
, p
,
10175 nbytes
= coding
.produced
;
10176 nchars
= coding
.produced_char
;
10180 /* Convert the input data to a sequence of
10181 character events. */
10182 for (i
= 0; i
< nbytes
; i
+= len
)
10184 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
10186 bufp
->kind
= (SINGLE_BYTE_CHAR_P (c
)
10188 : multibyte_char_keystroke
);
10190 XSETFRAME (bufp
->frame_or_window
, f
);
10193 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
10195 bufp
->timestamp
= event
.xkey
.time
;
10200 numchars
-= nchars
;
10202 if (keysym
== NoSymbol
)
10212 /* Don't dispatch this event since XtDispatchEvent calls
10213 XFilterEvent, and two calls in a row may freeze the
10222 /* Don't dispatch this event since XtDispatchEvent calls
10223 XFilterEvent, and two calls in a row may freeze the
10230 /* Here's a possible interpretation of the whole
10231 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If
10232 you get a FocusIn event, you have to get a FocusOut
10233 event before you relinquish the focus. If you
10234 haven't received a FocusIn event, then a mere
10235 LeaveNotify is enough to free you. */
10239 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10241 if (event
.xcrossing
.focus
)
10243 /* Avoid nasty pop/raise loops. */
10244 if (f
&& (!(f
->auto_raise
)
10245 || !(f
->auto_lower
)
10246 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
10248 x_new_focus_frame (dpyinfo
, f
);
10249 enter_timestamp
= event
.xcrossing
.time
;
10252 else if (f
== dpyinfo
->x_focus_frame
)
10253 x_new_focus_frame (dpyinfo
, 0);
10255 /* EnterNotify counts as mouse movement,
10256 so update things that depend on mouse position. */
10257 if (f
&& !f
->output_data
.x
->hourglass_p
)
10258 note_mouse_movement (f
, &event
.xmotion
);
10263 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
10264 if (event
.xfocus
.detail
!= NotifyPointer
)
10265 dpyinfo
->x_focus_event_frame
= f
;
10268 x_new_focus_frame (dpyinfo
, f
);
10270 /* Don't stop displaying the initial startup message
10271 for a switch-frame event we don't need. */
10272 if (GC_NILP (Vterminal_frame
)
10273 && GC_CONSP (Vframe_list
)
10274 && !GC_NILP (XCDR (Vframe_list
)))
10276 bufp
->kind
= FOCUS_IN_EVENT
;
10277 XSETFRAME (bufp
->frame_or_window
, f
);
10279 ++bufp
, ++count
, --numchars
;
10284 if (f
&& FRAME_XIC (f
))
10285 XSetICFocus (FRAME_XIC (f
));
10291 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10294 if (f
== dpyinfo
->mouse_face_mouse_frame
)
10296 /* If we move outside the frame, then we're
10297 certainly no longer on any text in the frame. */
10298 clear_mouse_face (dpyinfo
);
10299 dpyinfo
->mouse_face_mouse_frame
= 0;
10302 /* Generate a nil HELP_EVENT to cancel a help-echo.
10303 Do it only if there's something to cancel.
10304 Otherwise, the startup message is cleared when
10305 the mouse leaves the frame. */
10306 if (any_help_event_p
)
10311 XSETFRAME (frame
, f
);
10313 n
= gen_help_event (bufp
, numchars
,
10314 Qnil
, frame
, Qnil
, Qnil
, 0);
10315 bufp
+= n
, count
+= n
, numchars
-= n
;
10318 if (event
.xcrossing
.focus
)
10319 x_mouse_leave (dpyinfo
);
10322 if (f
== dpyinfo
->x_focus_event_frame
)
10323 dpyinfo
->x_focus_event_frame
= 0;
10324 if (f
== dpyinfo
->x_focus_frame
)
10325 x_new_focus_frame (dpyinfo
, 0);
10331 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
10332 if (event
.xfocus
.detail
!= NotifyPointer
10333 && f
== dpyinfo
->x_focus_event_frame
)
10334 dpyinfo
->x_focus_event_frame
= 0;
10335 if (f
&& f
== dpyinfo
->x_focus_frame
)
10336 x_new_focus_frame (dpyinfo
, 0);
10339 if (f
&& FRAME_XIC (f
))
10340 XUnsetICFocus (FRAME_XIC (f
));
10347 previous_help_echo
= help_echo
;
10348 help_echo
= help_echo_object
= help_echo_window
= Qnil
;
10349 help_echo_pos
= -1;
10351 if (dpyinfo
->grabbed
&& last_mouse_frame
10352 && FRAME_LIVE_P (last_mouse_frame
))
10353 f
= last_mouse_frame
;
10355 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
10358 note_mouse_movement (f
, &event
.xmotion
);
10361 #ifndef USE_TOOLKIT_SCROLL_BARS
10362 struct scroll_bar
*bar
10363 = x_window_to_scroll_bar (event
.xmotion
.window
);
10366 x_scroll_bar_note_movement (bar
, &event
);
10367 #endif /* USE_TOOLKIT_SCROLL_BARS */
10369 /* If we move outside the frame, then we're
10370 certainly no longer on any text in the frame. */
10371 clear_mouse_face (dpyinfo
);
10374 /* If the contents of the global variable help_echo
10375 has changed, generate a HELP_EVENT. */
10376 if (!NILP (help_echo
)
10377 || !NILP (previous_help_echo
))
10383 XSETFRAME (frame
, f
);
10387 any_help_event_p
= 1;
10388 n
= gen_help_event (bufp
, numchars
, help_echo
, frame
,
10389 help_echo_window
, help_echo_object
,
10391 bufp
+= n
, count
+= n
, numchars
-= n
;
10397 case ConfigureNotify
:
10398 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
10401 #ifndef USE_X_TOOLKIT
10402 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
10403 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
10405 /* In the toolkit version, change_frame_size
10406 is called by the code that handles resizing
10407 of the EmacsFrame widget. */
10409 /* Even if the number of character rows and columns has
10410 not changed, the font size may have changed, so we need
10411 to check the pixel dimensions as well. */
10412 if (columns
!= f
->width
10413 || rows
!= f
->height
10414 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
10415 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
10417 change_frame_size (f
, rows
, columns
, 0, 1, 0);
10418 SET_FRAME_GARBAGED (f
);
10419 cancel_mouse_face (f
);
10423 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
10424 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
10426 /* What we have now is the position of Emacs's own window.
10427 Convert that to the position of the window manager window. */
10428 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
10429 &f
->output_data
.x
->top_pos
);
10432 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
10433 xic_set_statusarea (f
);
10436 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
10438 /* Since the WM decorations come below top_pos now,
10439 we must put them below top_pos in the future. */
10440 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
10441 x_wm_set_size_hint (f
, (long) 0, 0);
10444 /* Some window managers pass (0,0) as the location of
10445 the window, and the Motif event handler stores it
10446 in the emacs widget, which messes up Motif menus. */
10447 if (event
.xconfigure
.x
== 0 && event
.xconfigure
.y
== 0)
10449 event
.xconfigure
.x
= f
->output_data
.x
->widget
->core
.x
;
10450 event
.xconfigure
.y
= f
->output_data
.x
->widget
->core
.y
;
10452 #endif /* USE_MOTIF */
10457 case ButtonRelease
:
10459 /* If we decide we want to generate an event to be seen
10460 by the rest of Emacs, we put it here. */
10461 struct input_event emacs_event
;
10462 int tool_bar_p
= 0;
10464 emacs_event
.kind
= no_event
;
10465 bzero (&compose_status
, sizeof (compose_status
));
10467 if (dpyinfo
->grabbed
10468 && last_mouse_frame
10469 && FRAME_LIVE_P (last_mouse_frame
))
10470 f
= last_mouse_frame
;
10472 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
10476 /* Is this in the tool-bar? */
10477 if (WINDOWP (f
->tool_bar_window
)
10478 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
10480 Lisp_Object window
;
10483 x
= event
.xbutton
.x
;
10484 y
= event
.xbutton
.y
;
10487 window
= window_from_coordinates (f
, x
, y
, &p
, 1);
10488 if (EQ (window
, f
->tool_bar_window
))
10490 x_handle_tool_bar_click (f
, &event
.xbutton
);
10496 if (!dpyinfo
->x_focus_frame
10497 || f
== dpyinfo
->x_focus_frame
)
10498 construct_mouse_click (&emacs_event
, &event
, f
);
10502 #ifndef USE_TOOLKIT_SCROLL_BARS
10503 struct scroll_bar
*bar
10504 = x_window_to_scroll_bar (event
.xbutton
.window
);
10507 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
10508 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10511 if (event
.type
== ButtonPress
)
10513 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
10514 last_mouse_frame
= f
;
10515 /* Ignore any mouse motion that happened
10516 before this event; any subsequent mouse-movement
10517 Emacs events should reflect only motion after
10518 the ButtonPress. */
10520 f
->mouse_moved
= 0;
10523 last_tool_bar_item
= -1;
10527 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
10530 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
10532 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
10538 #ifdef USE_X_TOOLKIT
10539 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
10540 /* For a down-event in the menu bar,
10541 don't pass it to Xt right now.
10542 Instead, save it away
10543 and we will pass it to Xt from kbd_buffer_get_event.
10544 That way, we can run some Lisp code first. */
10545 if (f
&& event
.type
== ButtonPress
10546 /* Verify the event is really within the menu bar
10547 and not just sent to it due to grabbing. */
10548 && event
.xbutton
.x
>= 0
10549 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
10550 && event
.xbutton
.y
>= 0
10551 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
10552 && event
.xbutton
.same_screen
)
10554 SET_SAVED_BUTTON_EVENT
;
10555 XSETFRAME (last_mouse_press_frame
, f
);
10557 else if (event
.type
== ButtonPress
)
10559 last_mouse_press_frame
= Qnil
;
10563 #ifdef USE_MOTIF /* This should do not harm for Lucid,
10564 but I am trying to be cautious. */
10565 else if (event
.type
== ButtonRelease
)
10567 if (!NILP (last_mouse_press_frame
))
10569 f
= XFRAME (last_mouse_press_frame
);
10570 if (f
->output_data
.x
)
10571 SET_SAVED_BUTTON_EVENT
;
10576 #endif /* USE_MOTIF */
10579 #endif /* USE_X_TOOLKIT */
10583 case CirculateNotify
:
10586 case CirculateRequest
:
10589 case VisibilityNotify
:
10592 case MappingNotify
:
10593 /* Someone has changed the keyboard mapping - update the
10595 switch (event
.xmapping
.request
)
10597 case MappingModifier
:
10598 x_find_modifier_meanings (dpyinfo
);
10599 /* This is meant to fall through. */
10600 case MappingKeyboard
:
10601 XRefreshKeyboardMapping (&event
.xmapping
);
10607 #ifdef USE_X_TOOLKIT
10609 XtDispatchEvent (&event
);
10611 #endif /* USE_X_TOOLKIT */
10619 /* On some systems, an X bug causes Emacs to get no more events
10620 when the window is destroyed. Detect that. (1994.) */
10623 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
10624 One XNOOP in 100 loops will make Emacs terminate.
10625 B. Bretthauer, 1994 */
10627 if (x_noop_count
>= 100)
10631 if (next_noop_dpyinfo
== 0)
10632 next_noop_dpyinfo
= x_display_list
;
10634 XNoOp (next_noop_dpyinfo
->display
);
10636 /* Each time we get here, cycle through the displays now open. */
10637 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
10641 /* If the focus was just given to an auto-raising frame,
10643 /* ??? This ought to be able to handle more than one such frame. */
10644 if (pending_autoraise_frame
)
10646 x_raise_frame (pending_autoraise_frame
);
10647 pending_autoraise_frame
= 0;
10658 /***********************************************************************
10660 ***********************************************************************/
10662 /* Note if the text cursor of window W has been overwritten by a
10663 drawing operation that outputs N glyphs starting at HPOS in the
10664 line given by output_cursor.vpos. N < 0 means all the rest of the
10665 line after HPOS has been written. */
10668 note_overwritten_text_cursor (w
, hpos
, n
)
10672 if (updated_area
== TEXT_AREA
10673 && output_cursor
.vpos
== w
->phys_cursor
.vpos
10674 && hpos
<= w
->phys_cursor
.hpos
10676 || hpos
+ n
> w
->phys_cursor
.hpos
))
10677 w
->phys_cursor_on_p
= 0;
10681 /* Set clipping for output in glyph row ROW. W is the window in which
10682 we operate. GC is the graphics context to set clipping in.
10683 WHOLE_LINE_P non-zero means include the areas used for truncation
10684 mark display and alike in the clipping rectangle.
10686 ROW may be a text row or, e.g., a mode line. Text rows must be
10687 clipped to the interior of the window dedicated to text display,
10688 mode lines must be clipped to the whole window. */
10691 x_clip_to_row (w
, row
, gc
, whole_line_p
)
10693 struct glyph_row
*row
;
10697 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10698 XRectangle clip_rect
;
10699 int window_x
, window_y
, window_width
, window_height
;
10701 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
10703 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
10704 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
10705 clip_rect
.y
= max (clip_rect
.y
, window_y
);
10706 clip_rect
.width
= window_width
;
10707 clip_rect
.height
= row
->visible_height
;
10709 /* If clipping to the whole line, including trunc marks, extend
10710 the rectangle to the left and increase its width. */
10713 clip_rect
.x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
10714 clip_rect
.width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
10717 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
10721 /* Draw a hollow box cursor on window W in glyph row ROW. */
10724 x_draw_hollow_cursor (w
, row
)
10726 struct glyph_row
*row
;
10728 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10729 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10730 Display
*dpy
= FRAME_X_DISPLAY (f
);
10733 struct glyph
*cursor_glyph
;
10736 /* Compute frame-relative coordinates from window-relative
10738 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
10739 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
10740 + row
->ascent
- w
->phys_cursor_ascent
);
10741 h
= row
->height
- 1;
10743 /* Get the glyph the cursor is on. If we can't tell because
10744 the current matrix is invalid or such, give up. */
10745 cursor_glyph
= get_phys_cursor_glyph (w
);
10746 if (cursor_glyph
== NULL
)
10749 /* Compute the width of the rectangle to draw. If on a stretch
10750 glyph, and `x-stretch-block-cursor' is nil, don't draw a
10751 rectangle as wide as the glyph, but use a canonical character
10753 wd
= cursor_glyph
->pixel_width
- 1;
10754 if (cursor_glyph
->type
== STRETCH_GLYPH
10755 && !x_stretch_cursor_p
)
10756 wd
= min (CANON_X_UNIT (f
), wd
);
10758 /* The foreground of cursor_gc is typically the same as the normal
10759 background color, which can cause the cursor box to be invisible. */
10760 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
10761 if (dpyinfo
->scratch_cursor_gc
)
10762 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
10764 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
10765 GCForeground
, &xgcv
);
10766 gc
= dpyinfo
->scratch_cursor_gc
;
10768 /* Set clipping, draw the rectangle, and reset clipping again. */
10769 x_clip_to_row (w
, row
, gc
, 0);
10770 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
10771 XSetClipMask (dpy
, gc
, None
);
10775 /* Draw a bar cursor on window W in glyph row ROW.
10777 Implementation note: One would like to draw a bar cursor with an
10778 angle equal to the one given by the font property XA_ITALIC_ANGLE.
10779 Unfortunately, I didn't find a font yet that has this property set.
10783 x_draw_bar_cursor (w
, row
, width
)
10785 struct glyph_row
*row
;
10788 struct frame
*f
= XFRAME (w
->frame
);
10789 struct glyph
*cursor_glyph
;
10792 unsigned long mask
;
10797 /* If cursor is out of bounds, don't draw garbage. This can happen
10798 in mini-buffer windows when switching between echo area glyphs
10799 and mini-buffer. */
10800 cursor_glyph
= get_phys_cursor_glyph (w
);
10801 if (cursor_glyph
== NULL
)
10804 /* If on an image, draw like a normal cursor. That's usually better
10805 visible than drawing a bar, esp. if the image is large so that
10806 the bar might not be in the window. */
10807 if (cursor_glyph
->type
== IMAGE_GLYPH
)
10809 struct glyph_row
*row
;
10810 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
10811 x_draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
10815 xgcv
.background
= f
->output_data
.x
->cursor_pixel
;
10816 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
10817 xgcv
.graphics_exposures
= 0;
10818 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
10819 dpy
= FRAME_X_DISPLAY (f
);
10820 window
= FRAME_X_WINDOW (f
);
10821 gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
10824 XChangeGC (dpy
, gc
, mask
, &xgcv
);
10827 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
10828 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
10832 width
= f
->output_data
.x
->cursor_width
;
10834 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
10835 x_clip_to_row (w
, row
, gc
, 0);
10836 XFillRectangle (dpy
, window
, gc
,
10838 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
10839 min (cursor_glyph
->pixel_width
, width
),
10841 XSetClipMask (dpy
, gc
, None
);
10846 /* Clear the cursor of window W to background color, and mark the
10847 cursor as not shown. This is used when the text where the cursor
10848 is is about to be rewritten. */
10854 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
10855 x_update_window_cursor (w
, 0);
10859 /* Draw the cursor glyph of window W in glyph row ROW. See the
10860 comment of x_draw_glyphs for the meaning of HL. */
10863 x_draw_phys_cursor_glyph (w
, row
, hl
)
10865 struct glyph_row
*row
;
10866 enum draw_glyphs_face hl
;
10868 /* If cursor hpos is out of bounds, don't draw garbage. This can
10869 happen in mini-buffer windows when switching between echo area
10870 glyphs and mini-buffer. */
10871 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
10873 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
10874 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
10877 /* When we erase the cursor, and ROW is overlapped by other
10878 rows, make sure that these overlapping parts of other rows
10880 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
10882 if (row
> w
->current_matrix
->rows
10883 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
10884 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
10886 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
10887 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
10888 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
10894 /* Erase the image of a cursor of window W from the screen. */
10897 x_erase_phys_cursor (w
)
10900 struct frame
*f
= XFRAME (w
->frame
);
10901 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10902 int hpos
= w
->phys_cursor
.hpos
;
10903 int vpos
= w
->phys_cursor
.vpos
;
10904 int mouse_face_here_p
= 0;
10905 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
10906 struct glyph_row
*cursor_row
;
10907 struct glyph
*cursor_glyph
;
10908 enum draw_glyphs_face hl
;
10910 /* No cursor displayed or row invalidated => nothing to do on the
10912 if (w
->phys_cursor_type
== NO_CURSOR
)
10913 goto mark_cursor_off
;
10915 /* VPOS >= active_glyphs->nrows means that window has been resized.
10916 Don't bother to erase the cursor. */
10917 if (vpos
>= active_glyphs
->nrows
)
10918 goto mark_cursor_off
;
10920 /* If row containing cursor is marked invalid, there is nothing we
10922 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
10923 if (!cursor_row
->enabled_p
)
10924 goto mark_cursor_off
;
10926 /* This can happen when the new row is shorter than the old one.
10927 In this case, either x_draw_glyphs or clear_end_of_line
10928 should have cleared the cursor. Note that we wouldn't be
10929 able to erase the cursor in this case because we don't have a
10930 cursor glyph at hand. */
10931 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
10932 goto mark_cursor_off
;
10934 /* If the cursor is in the mouse face area, redisplay that when
10935 we clear the cursor. */
10936 if (! NILP (dpyinfo
->mouse_face_window
)
10937 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
10938 && (vpos
> dpyinfo
->mouse_face_beg_row
10939 || (vpos
== dpyinfo
->mouse_face_beg_row
10940 && hpos
>= dpyinfo
->mouse_face_beg_col
))
10941 && (vpos
< dpyinfo
->mouse_face_end_row
10942 || (vpos
== dpyinfo
->mouse_face_end_row
10943 && hpos
< dpyinfo
->mouse_face_end_col
))
10944 /* Don't redraw the cursor's spot in mouse face if it is at the
10945 end of a line (on a newline). The cursor appears there, but
10946 mouse highlighting does not. */
10947 && cursor_row
->used
[TEXT_AREA
] > hpos
)
10948 mouse_face_here_p
= 1;
10950 /* Maybe clear the display under the cursor. */
10951 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
10954 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10956 cursor_glyph
= get_phys_cursor_glyph (w
);
10957 if (cursor_glyph
== NULL
)
10958 goto mark_cursor_off
;
10960 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
10962 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10964 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
10966 cursor_glyph
->pixel_width
,
10967 cursor_row
->visible_height
,
10971 /* Erase the cursor by redrawing the character underneath it. */
10972 if (mouse_face_here_p
)
10973 hl
= DRAW_MOUSE_FACE
;
10974 else if (cursor_row
->inverse_p
)
10975 hl
= DRAW_INVERSE_VIDEO
;
10977 hl
= DRAW_NORMAL_TEXT
;
10978 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
10981 w
->phys_cursor_on_p
= 0;
10982 w
->phys_cursor_type
= NO_CURSOR
;
10986 /* Display or clear cursor of window W. If ON is zero, clear the
10987 cursor. If it is non-zero, display the cursor. If ON is nonzero,
10988 where to put the cursor is specified by HPOS, VPOS, X and Y. */
10991 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
10993 int on
, hpos
, vpos
, x
, y
;
10995 struct frame
*f
= XFRAME (w
->frame
);
10996 int new_cursor_type
;
10997 int new_cursor_width
;
10998 struct glyph_matrix
*current_glyphs
;
10999 struct glyph_row
*glyph_row
;
11000 struct glyph
*glyph
;
11002 /* This is pointless on invisible frames, and dangerous on garbaged
11003 windows and frames; in the latter case, the frame or window may
11004 be in the midst of changing its size, and x and y may be off the
11006 if (! FRAME_VISIBLE_P (f
)
11007 || FRAME_GARBAGED_P (f
)
11008 || vpos
>= w
->current_matrix
->nrows
11009 || hpos
>= w
->current_matrix
->matrix_w
)
11012 /* If cursor is off and we want it off, return quickly. */
11013 if (!on
&& !w
->phys_cursor_on_p
)
11016 current_glyphs
= w
->current_matrix
;
11017 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
11018 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
11020 /* If cursor row is not enabled, we don't really know where to
11021 display the cursor. */
11022 if (!glyph_row
->enabled_p
)
11024 w
->phys_cursor_on_p
= 0;
11028 xassert (interrupt_input_blocked
);
11030 /* Set new_cursor_type to the cursor we want to be displayed. In a
11031 mini-buffer window, we want the cursor only to appear if we are
11032 reading input from this window. For the selected window, we want
11033 the cursor type given by the frame parameter. If explicitly
11034 marked off, draw no cursor. In all other cases, we want a hollow
11036 new_cursor_width
= -1;
11037 if (cursor_in_echo_area
11038 && FRAME_HAS_MINIBUF_P (f
)
11039 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
11041 if (w
== XWINDOW (echo_area_window
))
11042 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
11044 new_cursor_type
= HOLLOW_BOX_CURSOR
;
11048 if (f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
11049 || w
!= XWINDOW (f
->selected_window
))
11051 extern int cursor_in_non_selected_windows
;
11053 if (MINI_WINDOW_P (w
)
11054 || !cursor_in_non_selected_windows
11055 || NILP (XBUFFER (w
->buffer
)->cursor_type
))
11056 new_cursor_type
= NO_CURSOR
;
11058 new_cursor_type
= HOLLOW_BOX_CURSOR
;
11060 else if (w
->cursor_off_p
)
11061 new_cursor_type
= NO_CURSOR
;
11064 struct buffer
*b
= XBUFFER (w
->buffer
);
11066 if (EQ (b
->cursor_type
, Qt
))
11067 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
11069 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
11070 &new_cursor_width
);
11074 /* If cursor is currently being shown and we don't want it to be or
11075 it is in the wrong place, or the cursor type is not what we want,
11077 if (w
->phys_cursor_on_p
11079 || w
->phys_cursor
.x
!= x
11080 || w
->phys_cursor
.y
!= y
11081 || new_cursor_type
!= w
->phys_cursor_type
))
11082 x_erase_phys_cursor (w
);
11084 /* If the cursor is now invisible and we want it to be visible,
11086 if (on
&& !w
->phys_cursor_on_p
)
11088 w
->phys_cursor_ascent
= glyph_row
->ascent
;
11089 w
->phys_cursor_height
= glyph_row
->height
;
11091 /* Set phys_cursor_.* before x_draw_.* is called because some
11092 of them may need the information. */
11093 w
->phys_cursor
.x
= x
;
11094 w
->phys_cursor
.y
= glyph_row
->y
;
11095 w
->phys_cursor
.hpos
= hpos
;
11096 w
->phys_cursor
.vpos
= vpos
;
11097 w
->phys_cursor_type
= new_cursor_type
;
11098 w
->phys_cursor_on_p
= 1;
11100 switch (new_cursor_type
)
11102 case HOLLOW_BOX_CURSOR
:
11103 x_draw_hollow_cursor (w
, glyph_row
);
11106 case FILLED_BOX_CURSOR
:
11107 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
11111 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
);
11122 if (w
== XWINDOW (f
->selected_window
))
11123 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
11124 xic_set_preeditarea (w
, x
, y
);
11129 if (updating_frame
!= f
)
11130 XFlush (FRAME_X_DISPLAY (f
));
11135 /* Display the cursor on window W, or clear it. X and Y are window
11136 relative pixel coordinates. HPOS and VPOS are glyph matrix
11137 positions. If W is not the selected window, display a hollow
11138 cursor. ON non-zero means display the cursor at X, Y which
11139 correspond to HPOS, VPOS, otherwise it is cleared. */
11142 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
11144 int on
, hpos
, vpos
, x
, y
;
11147 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
11152 /* Display the cursor on window W, or clear it, according to ON_P.
11153 Don't change the cursor's position. */
11156 x_update_cursor (f
, on_p
)
11159 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
11163 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
11164 in the window tree rooted at W. */
11167 x_update_cursor_in_window_tree (w
, on_p
)
11173 if (!NILP (w
->hchild
))
11174 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
11175 else if (!NILP (w
->vchild
))
11176 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
11178 x_update_window_cursor (w
, on_p
);
11180 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
11185 /* Switch the display of W's cursor on or off, according to the value
11189 x_update_window_cursor (w
, on
)
11193 /* Don't update cursor in windows whose frame is in the process
11194 of being deleted. */
11195 if (w
->current_matrix
)
11198 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
11199 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
11209 /* Refresh bitmap kitchen sink icon for frame F
11210 when we get an expose event for it. */
11216 /* Normally, the window manager handles this function. */
11219 /* Make the x-window of frame F use the gnu icon bitmap. */
11222 x_bitmap_icon (f
, file
)
11228 if (FRAME_X_WINDOW (f
) == 0)
11231 /* Free up our existing icon bitmap if any. */
11232 if (f
->output_data
.x
->icon_bitmap
> 0)
11233 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
11234 f
->output_data
.x
->icon_bitmap
= 0;
11236 if (STRINGP (file
))
11237 bitmap_id
= x_create_bitmap_from_file (f
, file
);
11240 /* Create the GNU bitmap if necessary. */
11241 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
11242 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
11243 = x_create_bitmap_from_data (f
, gnu_bits
,
11244 gnu_width
, gnu_height
);
11246 /* The first time we create the GNU bitmap,
11247 this increments the ref-count one extra time.
11248 As a result, the GNU bitmap is never freed.
11249 That way, we don't have to worry about allocating it again. */
11250 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
11252 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
11255 x_wm_set_icon_pixmap (f
, bitmap_id
);
11256 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
11262 /* Make the x-window of frame F use a rectangle with text.
11263 Use ICON_NAME as the text. */
11266 x_text_icon (f
, icon_name
)
11270 if (FRAME_X_WINDOW (f
) == 0)
11275 XTextProperty text
;
11276 text
.value
= (unsigned char *) icon_name
;
11277 text
.encoding
= XA_STRING
;
11279 text
.nitems
= strlen (icon_name
);
11280 #ifdef USE_X_TOOLKIT
11281 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
11283 #else /* not USE_X_TOOLKIT */
11284 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
11285 #endif /* not USE_X_TOOLKIT */
11287 #else /* not HAVE_X11R4 */
11288 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
11289 #endif /* not HAVE_X11R4 */
11291 if (f
->output_data
.x
->icon_bitmap
> 0)
11292 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
11293 f
->output_data
.x
->icon_bitmap
= 0;
11294 x_wm_set_icon_pixmap (f
, 0);
11299 #define X_ERROR_MESSAGE_SIZE 200
11301 /* If non-nil, this should be a string.
11302 It means catch X errors and store the error message in this string. */
11304 static Lisp_Object x_error_message_string
;
11306 /* An X error handler which stores the error message in
11307 x_error_message_string. This is called from x_error_handler if
11308 x_catch_errors is in effect. */
11311 x_error_catcher (display
, error
)
11313 XErrorEvent
*error
;
11315 XGetErrorText (display
, error
->error_code
,
11316 XSTRING (x_error_message_string
)->data
,
11317 X_ERROR_MESSAGE_SIZE
);
11320 /* Begin trapping X errors for display DPY. Actually we trap X errors
11321 for all displays, but DPY should be the display you are actually
11324 After calling this function, X protocol errors no longer cause
11325 Emacs to exit; instead, they are recorded in the string
11326 stored in x_error_message_string.
11328 Calling x_check_errors signals an Emacs error if an X error has
11329 occurred since the last call to x_catch_errors or x_check_errors.
11331 Calling x_uncatch_errors resumes the normal error handling. */
11333 void x_check_errors ();
11334 static Lisp_Object
x_catch_errors_unwind ();
11337 x_catch_errors (dpy
)
11340 int count
= specpdl_ptr
- specpdl
;
11342 /* Make sure any errors from previous requests have been dealt with. */
11343 XSync (dpy
, False
);
11345 record_unwind_protect (x_catch_errors_unwind
, x_error_message_string
);
11347 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
11348 XSTRING (x_error_message_string
)->data
[0] = 0;
11353 /* Unbind the binding that we made to check for X errors. */
11356 x_catch_errors_unwind (old_val
)
11357 Lisp_Object old_val
;
11359 x_error_message_string
= old_val
;
11363 /* If any X protocol errors have arrived since the last call to
11364 x_catch_errors or x_check_errors, signal an Emacs error using
11365 sprintf (a buffer, FORMAT, the x error message text) as the text. */
11368 x_check_errors (dpy
, format
)
11372 /* Make sure to catch any errors incurred so far. */
11373 XSync (dpy
, False
);
11375 if (XSTRING (x_error_message_string
)->data
[0])
11376 error (format
, XSTRING (x_error_message_string
)->data
);
11379 /* Nonzero if we had any X protocol errors
11380 since we did x_catch_errors on DPY. */
11383 x_had_errors_p (dpy
)
11386 /* Make sure to catch any errors incurred so far. */
11387 XSync (dpy
, False
);
11389 return XSTRING (x_error_message_string
)->data
[0] != 0;
11392 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
11395 x_clear_errors (dpy
)
11398 XSTRING (x_error_message_string
)->data
[0] = 0;
11401 /* Stop catching X protocol errors and let them make Emacs die.
11402 DPY should be the display that was passed to x_catch_errors.
11403 COUNT should be the value that was returned by
11404 the corresponding call to x_catch_errors. */
11407 x_uncatch_errors (dpy
, count
)
11411 unbind_to (count
, Qnil
);
11415 static unsigned int x_wire_count
;
11418 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
11423 /* Handle SIGPIPE, which can happen when the connection to a server
11424 simply goes away. SIGPIPE is handled by x_connection_signal.
11425 Don't need to do anything, because the write which caused the
11426 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
11427 which will do the appropriate cleanup for us. */
11430 x_connection_signal (signalnum
) /* If we don't have an argument, */
11431 int signalnum
; /* some compilers complain in signal calls. */
11434 /* USG systems forget handlers when they are used;
11435 must reestablish each time */
11436 signal (signalnum
, x_connection_signal
);
11441 /************************************************************************
11443 ************************************************************************/
11445 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
11446 the text of an error message that lead to the connection loss. */
11449 x_connection_closed (dpy
, error_message
)
11451 char *error_message
;
11453 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
11454 Lisp_Object frame
, tail
;
11458 msg
= (char *) alloca (strlen (error_message
) + 1);
11459 strcpy (msg
, error_message
);
11460 handling_signal
= 0;
11462 /* Prevent being called recursively because of an error condition
11463 below. Otherwise, we might end up with printing ``can't find per
11464 display information'' in the recursive call instead of printing
11465 the original message here. */
11466 count
= x_catch_errors (dpy
);
11468 /* We have to close the display to inform Xt that it doesn't
11469 exist anymore. If we don't, Xt will continue to wait for
11470 events from the display. As a consequence, a sequence of
11472 M-x make-frame-on-display RET :1 RET
11473 ...kill the new frame, so that we get an IO error...
11474 M-x make-frame-on-display RET :1 RET
11476 will indefinitely wait in Xt for events for display `:1', opened
11477 in the first class to make-frame-on-display.
11479 Closing the display is reported to lead to a bus error on
11480 OpenWindows in certain situations. I suspect that is a bug
11481 in OpenWindows. I don't know how to cicumvent it here. */
11483 #ifdef USE_X_TOOLKIT
11484 /* If DPYINFO is null, this means we didn't open the display
11485 in the first place, so don't try to close it. */
11487 XtCloseDisplay (dpy
);
11490 /* Indicate that this display is dead. */
11492 dpyinfo
->display
= 0;
11494 /* First delete frames whose mini-buffers are on frames
11495 that are on the dead display. */
11496 FOR_EACH_FRAME (tail
, frame
)
11498 Lisp_Object minibuf_frame
;
11500 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
11501 if (FRAME_X_P (XFRAME (frame
))
11502 && FRAME_X_P (XFRAME (minibuf_frame
))
11503 && ! EQ (frame
, minibuf_frame
)
11504 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
11505 Fdelete_frame (frame
, Qt
);
11508 /* Now delete all remaining frames on the dead display.
11509 We are now sure none of these is used as the mini-buffer
11510 for another frame that we need to delete. */
11511 FOR_EACH_FRAME (tail
, frame
)
11512 if (FRAME_X_P (XFRAME (frame
))
11513 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
11515 /* Set this to t so that Fdelete_frame won't get confused
11516 trying to find a replacement. */
11517 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
11518 Fdelete_frame (frame
, Qt
);
11522 x_delete_display (dpyinfo
);
11524 x_uncatch_errors (dpy
, count
);
11526 if (x_display_list
== 0)
11528 fprintf (stderr
, "%s\n", msg
);
11529 shut_down_emacs (0, 0, Qnil
);
11533 /* Ordinary stack unwind doesn't deal with these. */
11535 sigunblock (sigmask (SIGIO
));
11537 sigunblock (sigmask (SIGALRM
));
11538 TOTALLY_UNBLOCK_INPUT
;
11540 clear_waiting_for_input ();
11545 /* This is the usual handler for X protocol errors.
11546 It kills all frames on the display that we got the error for.
11547 If that was the only one, it prints an error message and kills Emacs. */
11550 x_error_quitter (display
, error
)
11552 XErrorEvent
*error
;
11554 char buf
[256], buf1
[356];
11556 /* Note that there is no real way portable across R3/R4 to get the
11557 original error handler. */
11559 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
11560 sprintf (buf1
, "X protocol error: %s on protocol request %d",
11561 buf
, error
->request_code
);
11562 x_connection_closed (display
, buf1
);
11566 /* This is the first-level handler for X protocol errors.
11567 It calls x_error_quitter or x_error_catcher. */
11570 x_error_handler (display
, error
)
11572 XErrorEvent
*error
;
11574 if (! NILP (x_error_message_string
))
11575 x_error_catcher (display
, error
);
11577 x_error_quitter (display
, error
);
11581 /* This is the handler for X IO errors, always.
11582 It kills all frames on the display that we lost touch with.
11583 If that was the only one, it prints an error message and kills Emacs. */
11586 x_io_error_quitter (display
)
11591 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
11592 x_connection_closed (display
, buf
);
11596 /* Changing the font of the frame. */
11598 /* Give frame F the font named FONTNAME as its default font, and
11599 return the full name of that font. FONTNAME may be a wildcard
11600 pattern; in that case, we choose some font that fits the pattern.
11601 The return value shows which font we chose. */
11604 x_new_font (f
, fontname
)
11606 register char *fontname
;
11608 struct font_info
*fontp
11609 = FS_LOAD_FONT (f
, 0, fontname
, -1);
11614 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
11615 f
->output_data
.x
->baseline_offset
= fontp
->baseline_offset
;
11616 f
->output_data
.x
->fontset
= -1;
11618 /* Compute the scroll bar width in character columns. */
11619 if (f
->scroll_bar_pixel_width
> 0)
11621 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
11622 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
11626 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
11627 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
11630 /* Now make the frame display the given font. */
11631 if (FRAME_X_WINDOW (f
) != 0)
11633 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
11634 f
->output_data
.x
->font
->fid
);
11635 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
11636 f
->output_data
.x
->font
->fid
);
11637 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
11638 f
->output_data
.x
->font
->fid
);
11640 frame_update_line_height (f
);
11642 /* Don't change the size of a tip frame; there's no point in
11643 doing it because it's done in Fx_show_tip, and it leads to
11644 problems because the tip frame has no widget. */
11645 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
11646 x_set_window_size (f
, 0, f
->width
, f
->height
);
11649 /* If we are setting a new frame's font for the first time,
11650 there are no faces yet, so this font's height is the line height. */
11651 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
11653 return build_string (fontp
->full_name
);
11656 /* Give frame F the fontset named FONTSETNAME as its default font, and
11657 return the full name of that fontset. FONTSETNAME may be a wildcard
11658 pattern; in that case, we choose some fontset that fits the pattern.
11659 The return value shows which fontset we chose. */
11662 x_new_fontset (f
, fontsetname
)
11666 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
11667 Lisp_Object result
;
11672 if (f
->output_data
.x
->fontset
== fontset
)
11673 /* This fontset is already set in frame F. There's nothing more
11675 return fontset_name (fontset
);
11677 result
= x_new_font (f
, (XSTRING (fontset_ascii (fontset
))->data
));
11679 if (!STRINGP (result
))
11680 /* Can't load ASCII font. */
11683 /* Since x_new_font doesn't update any fontset information, do it now. */
11684 f
->output_data
.x
->fontset
= fontset
;
11688 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
11689 xic_set_xfontset (f
, XSTRING (fontset_ascii (fontset
))->data
);
11692 return build_string (fontsetname
);
11696 /***********************************************************************
11698 ***********************************************************************/
11704 /* XIM destroy callback function, which is called whenever the
11705 connection to input method XIM dies. CLIENT_DATA contains a
11706 pointer to the x_display_info structure corresponding to XIM. */
11709 xim_destroy_callback (xim
, client_data
, call_data
)
11711 XPointer client_data
;
11712 XPointer call_data
;
11714 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
11715 Lisp_Object frame
, tail
;
11719 /* No need to call XDestroyIC.. */
11720 FOR_EACH_FRAME (tail
, frame
)
11722 struct frame
*f
= XFRAME (frame
);
11723 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
11725 FRAME_XIC (f
) = NULL
;
11726 if (FRAME_XIC_FONTSET (f
))
11728 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
11729 FRAME_XIC_FONTSET (f
) = NULL
;
11734 /* No need to call XCloseIM. */
11735 dpyinfo
->xim
= NULL
;
11736 XFree (dpyinfo
->xim_styles
);
11740 #endif /* HAVE_X11R6 */
11742 /* Open the connection to the XIM server on display DPYINFO.
11743 RESOURCE_NAME is the resource name Emacs uses. */
11746 xim_open_dpy (dpyinfo
, resource_name
)
11747 struct x_display_info
*dpyinfo
;
11748 char *resource_name
;
11753 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
, EMACS_CLASS
);
11754 dpyinfo
->xim
= xim
;
11759 XIMCallback destroy
;
11762 /* Get supported styles and XIM values. */
11763 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
11766 destroy
.callback
= xim_destroy_callback
;
11767 destroy
.client_data
= (XPointer
)dpyinfo
;
11768 /* This isn't prptotyped in OSF 5.0. */
11769 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
11773 #else /* not USE_XIM */
11774 dpyinfo
->xim
= NULL
;
11775 #endif /* not USE_XIM */
11779 #ifdef HAVE_X11R6_XIM
11783 struct x_display_info
*dpyinfo
;
11784 char *resource_name
;
11787 /* XIM instantiate callback function, which is called whenever an XIM
11788 server is available. DISPLAY is teh display of the XIM.
11789 CLIENT_DATA contains a pointer to an xim_inst_t structure created
11790 when the callback was registered. */
11793 xim_instantiate_callback (display
, client_data
, call_data
)
11795 XPointer client_data
;
11796 XPointer call_data
;
11798 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
11799 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
11801 /* We don't support multiple XIM connections. */
11805 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
11807 /* Create XIC for the existing frames on the same display, as long
11808 as they have no XIC. */
11809 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
11811 Lisp_Object tail
, frame
;
11814 FOR_EACH_FRAME (tail
, frame
)
11816 struct frame
*f
= XFRAME (frame
);
11818 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
11819 if (FRAME_XIC (f
) == NULL
)
11821 create_frame_xic (f
);
11822 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
11823 xic_set_statusarea (f
);
11824 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
11826 struct window
*w
= XWINDOW (f
->selected_window
);
11827 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
11836 #endif /* HAVE_X11R6_XIM */
11839 /* Open a connection to the XIM server on display DPYINFO.
11840 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
11841 connection only at the first time. On X11R6, open the connection
11842 in the XIM instantiate callback function. */
11845 xim_initialize (dpyinfo
, resource_name
)
11846 struct x_display_info
*dpyinfo
;
11847 char *resource_name
;
11850 #ifdef HAVE_X11R6_XIM
11851 struct xim_inst_t
*xim_inst
;
11854 dpyinfo
->xim
= NULL
;
11855 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
11856 xim_inst
->dpyinfo
= dpyinfo
;
11857 len
= strlen (resource_name
);
11858 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
11859 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
11860 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
11861 resource_name
, EMACS_CLASS
,
11862 xim_instantiate_callback
,
11863 /* Fixme: This is XPointer in
11864 XFree86 but (XPointer *) on
11865 Tru64, at least. */
11866 (XPointer
) xim_inst
);
11867 #else /* not HAVE_X11R6_XIM */
11868 dpyinfo
->xim
= NULL
;
11869 xim_open_dpy (dpyinfo
, resource_name
);
11870 #endif /* not HAVE_X11R6_XIM */
11872 #else /* not USE_XIM */
11873 dpyinfo
->xim
= NULL
;
11874 #endif /* not USE_XIM */
11878 /* Close the connection to the XIM server on display DPYINFO. */
11881 xim_close_dpy (dpyinfo
)
11882 struct x_display_info
*dpyinfo
;
11885 #ifdef HAVE_X11R6_XIM
11886 if (dpyinfo
->display
)
11887 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
11889 xim_instantiate_callback
, NULL
);
11890 #endif /* not HAVE_X11R6_XIM */
11891 if (dpyinfo
->display
)
11892 XCloseIM (dpyinfo
->xim
);
11893 dpyinfo
->xim
= NULL
;
11894 XFree (dpyinfo
->xim_styles
);
11895 #endif /* USE_XIM */
11898 #endif /* not HAVE_X11R6_XIM */
11902 /* Calculate the absolute position in frame F
11903 from its current recorded position values and gravity. */
11906 x_calc_absolute_position (f
)
11910 int win_x
= 0, win_y
= 0;
11911 int flags
= f
->output_data
.x
->size_hint_flags
;
11914 /* We have nothing to do if the current position
11915 is already for the top-left corner. */
11916 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
11919 #ifdef USE_X_TOOLKIT
11920 this_window
= XtWindow (f
->output_data
.x
->widget
);
11922 this_window
= FRAME_X_WINDOW (f
);
11925 /* Find the position of the outside upper-left corner of
11926 the inner window, with respect to the outer window.
11927 But do this only if we will need the results. */
11928 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
11933 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
11936 x_clear_errors (FRAME_X_DISPLAY (f
));
11937 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
11939 /* From-window, to-window. */
11941 f
->output_data
.x
->parent_desc
,
11943 /* From-position, to-position. */
11944 0, 0, &win_x
, &win_y
,
11946 /* Child of win. */
11948 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
11950 Window newroot
, newparent
= 0xdeadbeef;
11951 Window
*newchildren
;
11952 unsigned int nchildren
;
11954 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
11955 &newparent
, &newchildren
, &nchildren
))
11958 XFree ((char *) newchildren
);
11960 f
->output_data
.x
->parent_desc
= newparent
;
11966 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
11970 /* Treat negative positions as relative to the leftmost bottommost
11971 position that fits on the screen. */
11972 if (flags
& XNegative
)
11973 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
11974 - 2 * f
->output_data
.x
->border_width
- win_x
11976 + f
->output_data
.x
->left_pos
);
11979 int height
= PIXEL_HEIGHT (f
);
11981 #if defined USE_X_TOOLKIT && defined USE_MOTIF
11982 /* Something is fishy here. When using Motif, starting Emacs with
11983 `-g -0-0', the frame appears too low by a few pixels.
11985 This seems to be so because initially, while Emacs is starting,
11986 the column widget's height and the frame's pixel height are
11987 different. The column widget's height is the right one. In
11988 later invocations, when Emacs is up, the frame's pixel height
11991 It's not obvious where the initial small difference comes from.
11992 2000-12-01, gerd. */
11994 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
11997 if (flags
& YNegative
)
11998 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
11999 - 2 * f
->output_data
.x
->border_width
12002 + f
->output_data
.x
->top_pos
);
12005 /* The left_pos and top_pos
12006 are now relative to the top and left screen edges,
12007 so the flags should correspond. */
12008 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
12011 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
12012 to really change the position, and 0 when calling from
12013 x_make_frame_visible (in that case, XOFF and YOFF are the current
12014 position values). It is -1 when calling from x_set_frame_parameters,
12015 which means, do adjust for borders but don't change the gravity. */
12018 x_set_offset (f
, xoff
, yoff
, change_gravity
)
12020 register int xoff
, yoff
;
12021 int change_gravity
;
12023 int modified_top
, modified_left
;
12025 if (change_gravity
> 0)
12027 f
->output_data
.x
->top_pos
= yoff
;
12028 f
->output_data
.x
->left_pos
= xoff
;
12029 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
12031 f
->output_data
.x
->size_hint_flags
|= XNegative
;
12033 f
->output_data
.x
->size_hint_flags
|= YNegative
;
12034 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
12036 x_calc_absolute_position (f
);
12039 x_wm_set_size_hint (f
, (long) 0, 0);
12041 modified_left
= f
->output_data
.x
->left_pos
;
12042 modified_top
= f
->output_data
.x
->top_pos
;
12043 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
12044 this seems to be unnecessary and incorrect. rms, 4/17/97. */
12045 /* It is a mystery why we need to add the border_width here
12046 when the frame is already visible, but experiment says we do. */
12047 if (change_gravity
!= 0)
12049 modified_left
+= f
->output_data
.x
->border_width
;
12050 modified_top
+= f
->output_data
.x
->border_width
;
12054 #ifdef USE_X_TOOLKIT
12055 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
12056 modified_left
, modified_top
);
12057 #else /* not USE_X_TOOLKIT */
12058 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12059 modified_left
, modified_top
);
12060 #endif /* not USE_X_TOOLKIT */
12065 /* Change the size of frame F's X window to COLS/ROWS in the case F
12066 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
12067 top-left-corner window gravity for this size change and subsequent
12068 size changes. Otherwise we leave the window gravity unchanged. */
12071 x_set_window_size_1 (f
, change_gravity
, cols
, rows
)
12073 int change_gravity
;
12076 int pixelwidth
, pixelheight
;
12078 check_frame_size (f
, &rows
, &cols
);
12079 f
->output_data
.x
->vertical_scroll_bar_extra
12080 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
12082 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
12083 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
12084 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
12085 f
->output_data
.x
->flags_areas_extra
12086 = FRAME_FLAGS_AREA_WIDTH (f
);
12087 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
12088 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
12090 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
12091 x_wm_set_size_hint (f
, (long) 0, 0);
12093 XSync (FRAME_X_DISPLAY (f
), False
);
12094 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12095 pixelwidth
, pixelheight
);
12097 /* Now, strictly speaking, we can't be sure that this is accurate,
12098 but the window manager will get around to dealing with the size
12099 change request eventually, and we'll hear how it went when the
12100 ConfigureNotify event gets here.
12102 We could just not bother storing any of this information here,
12103 and let the ConfigureNotify event set everything up, but that
12104 might be kind of confusing to the Lisp code, since size changes
12105 wouldn't be reported in the frame parameters until some random
12106 point in the future when the ConfigureNotify event arrives.
12108 We pass 1 for DELAY since we can't run Lisp code inside of
12110 change_frame_size (f
, rows
, cols
, 0, 1, 0);
12111 PIXEL_WIDTH (f
) = pixelwidth
;
12112 PIXEL_HEIGHT (f
) = pixelheight
;
12114 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
12115 receive in the ConfigureNotify event; if we get what we asked
12116 for, then the event won't cause the screen to become garbaged, so
12117 we have to make sure to do it here. */
12118 SET_FRAME_GARBAGED (f
);
12120 XFlush (FRAME_X_DISPLAY (f
));
12124 /* Call this to change the size of frame F's x-window.
12125 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
12126 for this size change and subsequent size changes.
12127 Otherwise we leave the window gravity unchanged. */
12130 x_set_window_size (f
, change_gravity
, cols
, rows
)
12132 int change_gravity
;
12137 #ifdef USE_X_TOOLKIT
12139 if (f
->output_data
.x
->widget
!= NULL
)
12141 /* The x and y position of the widget is clobbered by the
12142 call to XtSetValues within EmacsFrameSetCharSize.
12143 This is a real kludge, but I don't understand Xt so I can't
12144 figure out a correct fix. Can anyone else tell me? -- rms. */
12145 int xpos
= f
->output_data
.x
->widget
->core
.x
;
12146 int ypos
= f
->output_data
.x
->widget
->core
.y
;
12147 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
12148 f
->output_data
.x
->widget
->core
.x
= xpos
;
12149 f
->output_data
.x
->widget
->core
.y
= ypos
;
12152 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
12154 #else /* not USE_X_TOOLKIT */
12156 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
12158 #endif /* not USE_X_TOOLKIT */
12160 /* If cursor was outside the new size, mark it as off. */
12161 mark_window_cursors_off (XWINDOW (f
->root_window
));
12163 /* Clear out any recollection of where the mouse highlighting was,
12164 since it might be in a place that's outside the new frame size.
12165 Actually checking whether it is outside is a pain in the neck,
12166 so don't try--just let the highlighting be done afresh with new size. */
12167 cancel_mouse_face (f
);
12172 /* Mouse warping. */
12175 x_set_mouse_position (f
, x
, y
)
12181 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
12182 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
12184 if (pix_x
< 0) pix_x
= 0;
12185 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
12187 if (pix_y
< 0) pix_y
= 0;
12188 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
12192 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
12193 0, 0, 0, 0, pix_x
, pix_y
);
12197 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
12200 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
12206 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
12207 0, 0, 0, 0, pix_x
, pix_y
);
12211 /* focus shifting, raising and lowering. */
12214 x_focus_on_frame (f
)
12217 #if 0 /* This proves to be unpleasant. */
12221 /* I don't think that the ICCCM allows programs to do things like this
12222 without the interaction of the window manager. Whatever you end up
12223 doing with this code, do it to x_unfocus_frame too. */
12224 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12225 RevertToPointerRoot
, CurrentTime
);
12230 x_unfocus_frame (f
)
12234 /* Look at the remarks in x_focus_on_frame. */
12235 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
12236 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
12237 RevertToPointerRoot
, CurrentTime
);
12241 /* Raise frame F. */
12247 if (f
->async_visible
)
12250 #ifdef USE_X_TOOLKIT
12251 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
12252 #else /* not USE_X_TOOLKIT */
12253 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12254 #endif /* not USE_X_TOOLKIT */
12255 XFlush (FRAME_X_DISPLAY (f
));
12260 /* Lower frame F. */
12266 if (f
->async_visible
)
12269 #ifdef USE_X_TOOLKIT
12270 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
12271 #else /* not USE_X_TOOLKIT */
12272 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12273 #endif /* not USE_X_TOOLKIT */
12274 XFlush (FRAME_X_DISPLAY (f
));
12280 XTframe_raise_lower (f
, raise_flag
)
12290 /* Change of visibility. */
12292 /* This tries to wait until the frame is really visible.
12293 However, if the window manager asks the user where to position
12294 the frame, this will return before the user finishes doing that.
12295 The frame will not actually be visible at that time,
12296 but it will become visible later when the window manager
12297 finishes with it. */
12300 x_make_frame_visible (f
)
12304 int original_top
, original_left
;
12305 int retry_count
= 2;
12311 type
= x_icon_type (f
);
12313 x_bitmap_icon (f
, type
);
12315 if (! FRAME_VISIBLE_P (f
))
12317 /* We test FRAME_GARBAGED_P here to make sure we don't
12318 call x_set_offset a second time
12319 if we get to x_make_frame_visible a second time
12320 before the window gets really visible. */
12321 if (! FRAME_ICONIFIED_P (f
)
12322 && ! f
->output_data
.x
->asked_for_visible
)
12323 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
12325 f
->output_data
.x
->asked_for_visible
= 1;
12327 if (! EQ (Vx_no_window_manager
, Qt
))
12328 x_wm_set_window_state (f
, NormalState
);
12329 #ifdef USE_X_TOOLKIT
12330 /* This was XtPopup, but that did nothing for an iconified frame. */
12331 XtMapWidget (f
->output_data
.x
->widget
);
12332 #else /* not USE_X_TOOLKIT */
12333 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12334 #endif /* not USE_X_TOOLKIT */
12335 #if 0 /* This seems to bring back scroll bars in the wrong places
12336 if the window configuration has changed. They seem
12337 to come back ok without this. */
12338 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
12339 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12343 XFlush (FRAME_X_DISPLAY (f
));
12345 /* Synchronize to ensure Emacs knows the frame is visible
12346 before we do anything else. We do this loop with input not blocked
12347 so that incoming events are handled. */
12351 /* This must be before UNBLOCK_INPUT
12352 since events that arrive in response to the actions above
12353 will set it when they are handled. */
12354 int previously_visible
= f
->output_data
.x
->has_been_visible
;
12356 original_left
= f
->output_data
.x
->left_pos
;
12357 original_top
= f
->output_data
.x
->top_pos
;
12359 /* This must come after we set COUNT. */
12362 /* We unblock here so that arriving X events are processed. */
12364 /* Now move the window back to where it was "supposed to be".
12365 But don't do it if the gravity is negative.
12366 When the gravity is negative, this uses a position
12367 that is 3 pixels too low. Perhaps that's really the border width.
12369 Don't do this if the window has never been visible before,
12370 because the window manager may choose the position
12371 and we don't want to override it. */
12373 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
12374 && f
->output_data
.x
->win_gravity
== NorthWestGravity
12375 && previously_visible
)
12379 unsigned int width
, height
, border
, depth
;
12383 /* On some window managers (such as FVWM) moving an existing
12384 window, even to the same place, causes the window manager
12385 to introduce an offset. This can cause the window to move
12386 to an unexpected location. Check the geometry (a little
12387 slow here) and then verify that the window is in the right
12388 place. If the window is not in the right place, move it
12389 there, and take the potential window manager hit. */
12390 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
12391 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
12393 if (original_left
!= x
|| original_top
!= y
)
12394 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
12395 original_left
, original_top
);
12400 XSETFRAME (frame
, f
);
12402 /* Wait until the frame is visible. Process X events until a
12403 MapNotify event has been seen, or until we think we won't get a
12404 MapNotify at all.. */
12405 for (count
= input_signal_count
+ 10;
12406 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
12408 /* Force processing of queued events. */
12411 /* Machines that do polling rather than SIGIO have been
12412 observed to go into a busy-wait here. So we'll fake an
12413 alarm signal to let the handler know that there's something
12414 to be read. We used to raise a real alarm, but it seems
12415 that the handler isn't always enabled here. This is
12417 if (input_polling_used ())
12419 /* It could be confusing if a real alarm arrives while
12420 processing the fake one. Turn it off and let the
12421 handler reset it. */
12422 extern void poll_for_input_1
P_ ((void));
12423 int old_poll_suppress_count
= poll_suppress_count
;
12424 poll_suppress_count
= 1;
12425 poll_for_input_1 ();
12426 poll_suppress_count
= old_poll_suppress_count
;
12429 /* See if a MapNotify event has been processed. */
12430 FRAME_SAMPLE_VISIBILITY (f
);
12435 (let ((f (selected-frame)))
12439 the frame is not raised with various window managers on
12440 FreeBSD, Linux and Solaris. It turns out that, for some
12441 unknown reason, the call to XtMapWidget is completely ignored.
12442 Mapping the widget a second time works. */
12444 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
12449 /* Change from mapped state to withdrawn state. */
12451 /* Make the frame visible (mapped and not iconified). */
12454 x_make_frame_invisible (f
)
12459 #ifdef USE_X_TOOLKIT
12460 /* Use the frame's outermost window, not the one we normally draw on. */
12461 window
= XtWindow (f
->output_data
.x
->widget
);
12462 #else /* not USE_X_TOOLKIT */
12463 window
= FRAME_X_WINDOW (f
);
12464 #endif /* not USE_X_TOOLKIT */
12466 /* Don't keep the highlight on an invisible frame. */
12467 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
12468 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
12470 #if 0/* This might add unreliability; I don't trust it -- rms. */
12471 if (! f
->async_visible
&& ! f
->async_iconified
)
12477 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
12478 that the current position of the window is user-specified, rather than
12479 program-specified, so that when the window is mapped again, it will be
12480 placed at the same location, without forcing the user to position it
12481 by hand again (they have already done that once for this window.) */
12482 x_wm_set_size_hint (f
, (long) 0, 1);
12486 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
12487 DefaultScreen (FRAME_X_DISPLAY (f
))))
12489 UNBLOCK_INPUT_RESIGNAL
;
12490 error ("Can't notify window manager of window withdrawal");
12492 #else /* ! defined (HAVE_X11R4) */
12494 /* Tell the window manager what we're going to do. */
12495 if (! EQ (Vx_no_window_manager
, Qt
))
12499 unmap
.xunmap
.type
= UnmapNotify
;
12500 unmap
.xunmap
.window
= window
;
12501 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
12502 unmap
.xunmap
.from_configure
= False
;
12503 if (! XSendEvent (FRAME_X_DISPLAY (f
),
12504 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
12506 SubstructureRedirectMaskSubstructureNotifyMask
,
12509 UNBLOCK_INPUT_RESIGNAL
;
12510 error ("Can't notify window manager of withdrawal");
12514 /* Unmap the window ourselves. Cheeky! */
12515 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
12516 #endif /* ! defined (HAVE_X11R4) */
12518 /* We can't distinguish this from iconification
12519 just by the event that we get from the server.
12520 So we can't win using the usual strategy of letting
12521 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
12522 and synchronize with the server to make sure we agree. */
12524 FRAME_ICONIFIED_P (f
) = 0;
12525 f
->async_visible
= 0;
12526 f
->async_iconified
= 0;
12533 /* Change window state from mapped to iconified. */
12536 x_iconify_frame (f
)
12542 /* Don't keep the highlight on an invisible frame. */
12543 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
12544 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
12546 if (f
->async_iconified
)
12551 FRAME_SAMPLE_VISIBILITY (f
);
12553 type
= x_icon_type (f
);
12555 x_bitmap_icon (f
, type
);
12557 #ifdef USE_X_TOOLKIT
12559 if (! FRAME_VISIBLE_P (f
))
12561 if (! EQ (Vx_no_window_manager
, Qt
))
12562 x_wm_set_window_state (f
, IconicState
);
12563 /* This was XtPopup, but that did nothing for an iconified frame. */
12564 XtMapWidget (f
->output_data
.x
->widget
);
12565 /* The server won't give us any event to indicate
12566 that an invisible frame was changed to an icon,
12567 so we have to record it here. */
12570 f
->async_iconified
= 1;
12571 f
->async_visible
= 0;
12576 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
12577 XtWindow (f
->output_data
.x
->widget
),
12578 DefaultScreen (FRAME_X_DISPLAY (f
)));
12582 error ("Can't notify window manager of iconification");
12584 f
->async_iconified
= 1;
12585 f
->async_visible
= 0;
12589 XFlush (FRAME_X_DISPLAY (f
));
12591 #else /* not USE_X_TOOLKIT */
12593 /* Make sure the X server knows where the window should be positioned,
12594 in case the user deiconifies with the window manager. */
12595 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
12596 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
12598 /* Since we don't know which revision of X we're running, we'll use both
12599 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
12601 /* X11R4: send a ClientMessage to the window manager using the
12602 WM_CHANGE_STATE type. */
12606 message
.xclient
.window
= FRAME_X_WINDOW (f
);
12607 message
.xclient
.type
= ClientMessage
;
12608 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
12609 message
.xclient
.format
= 32;
12610 message
.xclient
.data
.l
[0] = IconicState
;
12612 if (! XSendEvent (FRAME_X_DISPLAY (f
),
12613 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
12615 SubstructureRedirectMask
| SubstructureNotifyMask
,
12618 UNBLOCK_INPUT_RESIGNAL
;
12619 error ("Can't notify window manager of iconification");
12623 /* X11R3: set the initial_state field of the window manager hints to
12625 x_wm_set_window_state (f
, IconicState
);
12627 if (!FRAME_VISIBLE_P (f
))
12629 /* If the frame was withdrawn, before, we must map it. */
12630 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12633 f
->async_iconified
= 1;
12634 f
->async_visible
= 0;
12636 XFlush (FRAME_X_DISPLAY (f
));
12638 #endif /* not USE_X_TOOLKIT */
12642 /* Free X resources of frame F. */
12645 x_free_frame_resources (f
)
12648 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12652 /* If a display connection is dead, don't try sending more
12653 commands to the X server. */
12654 if (dpyinfo
->display
)
12656 if (f
->output_data
.x
->icon_desc
)
12657 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
12661 free_frame_xic (f
);
12664 if (FRAME_X_WINDOW (f
))
12665 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12667 #ifdef USE_X_TOOLKIT
12668 if (f
->output_data
.x
->widget
)
12669 XtDestroyWidget (f
->output_data
.x
->widget
);
12670 free_frame_menubar (f
);
12671 #endif /* USE_X_TOOLKIT */
12673 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
12674 unload_color (f
, f
->output_data
.x
->background_pixel
);
12675 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
12676 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
12677 unload_color (f
, f
->output_data
.x
->border_pixel
);
12678 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
12680 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
12681 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
12682 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
12683 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
12684 if (f
->output_data
.x
->white_relief
.allocated_p
)
12685 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
12686 if (f
->output_data
.x
->black_relief
.allocated_p
)
12687 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
12689 if (FRAME_FACE_CACHE (f
))
12690 free_frame_faces (f
);
12693 XFlush (FRAME_X_DISPLAY (f
));
12696 if (f
->output_data
.x
->saved_menu_event
)
12697 xfree (f
->output_data
.x
->saved_menu_event
);
12699 xfree (f
->output_data
.x
);
12700 f
->output_data
.x
= NULL
;
12702 if (f
== dpyinfo
->x_focus_frame
)
12703 dpyinfo
->x_focus_frame
= 0;
12704 if (f
== dpyinfo
->x_focus_event_frame
)
12705 dpyinfo
->x_focus_event_frame
= 0;
12706 if (f
== dpyinfo
->x_highlight_frame
)
12707 dpyinfo
->x_highlight_frame
= 0;
12709 if (f
== dpyinfo
->mouse_face_mouse_frame
)
12711 dpyinfo
->mouse_face_beg_row
12712 = dpyinfo
->mouse_face_beg_col
= -1;
12713 dpyinfo
->mouse_face_end_row
12714 = dpyinfo
->mouse_face_end_col
= -1;
12715 dpyinfo
->mouse_face_window
= Qnil
;
12716 dpyinfo
->mouse_face_deferred_gc
= 0;
12717 dpyinfo
->mouse_face_mouse_frame
= 0;
12724 /* Destroy the X window of frame F. */
12727 x_destroy_window (f
)
12730 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12732 /* If a display connection is dead, don't try sending more
12733 commands to the X server. */
12734 if (dpyinfo
->display
!= 0)
12735 x_free_frame_resources (f
);
12737 dpyinfo
->reference_count
--;
12741 /* Setting window manager hints. */
12743 /* Set the normal size hints for the window manager, for frame F.
12744 FLAGS is the flags word to use--or 0 meaning preserve the flags
12745 that the window now has.
12746 If USER_POSITION is nonzero, we set the USPosition
12747 flag (this is useful when FLAGS is 0). */
12750 x_wm_set_size_hint (f
, flags
, user_position
)
12755 XSizeHints size_hints
;
12757 #ifdef USE_X_TOOLKIT
12760 Dimension widget_width
, widget_height
;
12761 Window window
= XtWindow (f
->output_data
.x
->widget
);
12762 #else /* not USE_X_TOOLKIT */
12763 Window window
= FRAME_X_WINDOW (f
);
12764 #endif /* not USE_X_TOOLKIT */
12766 /* Setting PMaxSize caused various problems. */
12767 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
12769 size_hints
.x
= f
->output_data
.x
->left_pos
;
12770 size_hints
.y
= f
->output_data
.x
->top_pos
;
12772 #ifdef USE_X_TOOLKIT
12773 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
12774 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
12775 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
12776 size_hints
.height
= widget_height
;
12777 size_hints
.width
= widget_width
;
12778 #else /* not USE_X_TOOLKIT */
12779 size_hints
.height
= PIXEL_HEIGHT (f
);
12780 size_hints
.width
= PIXEL_WIDTH (f
);
12781 #endif /* not USE_X_TOOLKIT */
12783 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
12784 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
12785 size_hints
.max_width
12786 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
12787 size_hints
.max_height
12788 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
12790 /* Calculate the base and minimum sizes.
12792 (When we use the X toolkit, we don't do it here.
12793 Instead we copy the values that the widgets are using, below.) */
12794 #ifndef USE_X_TOOLKIT
12796 int base_width
, base_height
;
12797 int min_rows
= 0, min_cols
= 0;
12799 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
12800 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
12802 check_frame_size (f
, &min_rows
, &min_cols
);
12804 /* The window manager uses the base width hints to calculate the
12805 current number of rows and columns in the frame while
12806 resizing; min_width and min_height aren't useful for this
12807 purpose, since they might not give the dimensions for a
12808 zero-row, zero-column frame.
12810 We use the base_width and base_height members if we have
12811 them; otherwise, we set the min_width and min_height members
12812 to the size for a zero x zero frame. */
12815 size_hints
.flags
|= PBaseSize
;
12816 size_hints
.base_width
= base_width
;
12817 size_hints
.base_height
= base_height
;
12818 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
12819 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
12821 size_hints
.min_width
= base_width
;
12822 size_hints
.min_height
= base_height
;
12826 /* If we don't need the old flags, we don't need the old hint at all. */
12829 size_hints
.flags
|= flags
;
12832 #endif /* not USE_X_TOOLKIT */
12835 XSizeHints hints
; /* Sometimes I hate X Windows... */
12836 long supplied_return
;
12840 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
12843 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
12846 #ifdef USE_X_TOOLKIT
12847 size_hints
.base_height
= hints
.base_height
;
12848 size_hints
.base_width
= hints
.base_width
;
12849 size_hints
.min_height
= hints
.min_height
;
12850 size_hints
.min_width
= hints
.min_width
;
12854 size_hints
.flags
|= flags
;
12859 if (hints
.flags
& PSize
)
12860 size_hints
.flags
|= PSize
;
12861 if (hints
.flags
& PPosition
)
12862 size_hints
.flags
|= PPosition
;
12863 if (hints
.flags
& USPosition
)
12864 size_hints
.flags
|= USPosition
;
12865 if (hints
.flags
& USSize
)
12866 size_hints
.flags
|= USSize
;
12870 #ifndef USE_X_TOOLKIT
12875 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
12876 size_hints
.flags
|= PWinGravity
;
12880 size_hints
.flags
&= ~ PPosition
;
12881 size_hints
.flags
|= USPosition
;
12883 #endif /* PWinGravity */
12886 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
12888 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
12892 /* Used for IconicState or NormalState */
12895 x_wm_set_window_state (f
, state
)
12899 #ifdef USE_X_TOOLKIT
12902 XtSetArg (al
[0], XtNinitialState
, state
);
12903 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
12904 #else /* not USE_X_TOOLKIT */
12905 Window window
= FRAME_X_WINDOW (f
);
12907 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
12908 f
->output_data
.x
->wm_hints
.initial_state
= state
;
12910 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12911 #endif /* not USE_X_TOOLKIT */
12915 x_wm_set_icon_pixmap (f
, pixmap_id
)
12919 Pixmap icon_pixmap
;
12921 #ifndef USE_X_TOOLKIT
12922 Window window
= FRAME_X_WINDOW (f
);
12927 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
12928 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
12932 /* It seems there is no way to turn off use of an icon pixmap.
12933 The following line does it, only if no icon has yet been created,
12934 for some window managers. But with mwm it crashes.
12935 Some people say it should clear the IconPixmapHint bit in this case,
12936 but that doesn't work, and the X consortium said it isn't the
12937 right thing at all. Since there is no way to win,
12938 best to explicitly give up. */
12940 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
12946 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
12950 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
12951 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
12954 #else /* not USE_X_TOOLKIT */
12956 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
12957 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12959 #endif /* not USE_X_TOOLKIT */
12963 x_wm_set_icon_position (f
, icon_x
, icon_y
)
12965 int icon_x
, icon_y
;
12967 #ifdef USE_X_TOOLKIT
12968 Window window
= XtWindow (f
->output_data
.x
->widget
);
12970 Window window
= FRAME_X_WINDOW (f
);
12973 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
12974 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
12975 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
12977 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12981 /***********************************************************************
12983 ***********************************************************************/
12985 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
12988 x_get_font_info (f
, font_idx
)
12992 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
12996 /* Return a list of names of available fonts matching PATTERN on frame F.
12998 If SIZE is > 0, it is the size (maximum bounds width) of fonts
13001 SIZE < 0 means include scalable fonts.
13003 Frame F null means we have not yet created any frame on X, and
13004 consult the first display in x_display_list. MAXNAMES sets a limit
13005 on how many fonts to match. */
13008 x_list_fonts (f
, pattern
, size
, maxnames
)
13010 Lisp_Object pattern
;
13014 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
13015 Lisp_Object tem
, second_best
;
13016 struct x_display_info
*dpyinfo
13017 = f
? FRAME_X_DISPLAY_INFO (f
) : x_display_list
;
13018 Display
*dpy
= dpyinfo
->display
;
13019 int try_XLoadQueryFont
= 0;
13021 int allow_scalable_fonts_p
= 0;
13025 allow_scalable_fonts_p
= 1;
13029 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
13030 if (NILP (patterns
))
13031 patterns
= Fcons (pattern
, Qnil
);
13033 if (maxnames
== 1 && !size
)
13034 /* We can return any single font matching PATTERN. */
13035 try_XLoadQueryFont
= 1;
13037 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
13040 char **names
= NULL
;
13042 pattern
= XCAR (patterns
);
13043 /* See if we cached the result for this particular query.
13044 The cache is an alist of the form:
13045 ((((PATTERN . MAXNAMES) . SCALABLE) (FONTNAME . WIDTH) ...) ...) */
13046 tem
= XCDR (dpyinfo
->name_list_element
);
13047 key
= Fcons (Fcons (pattern
, make_number (maxnames
)),
13048 allow_scalable_fonts_p
? Qt
: Qnil
);
13049 list
= Fassoc (key
, tem
);
13052 list
= Fcdr_safe (list
);
13053 /* We have a cashed list. Don't have to get the list again. */
13057 /* At first, put PATTERN in the cache. */
13060 count
= x_catch_errors (dpy
);
13062 if (try_XLoadQueryFont
)
13065 unsigned long value
;
13067 font
= XLoadQueryFont (dpy
, XSTRING (pattern
)->data
);
13068 if (x_had_errors_p (dpy
))
13070 /* This error is perhaps due to insufficient memory on X
13071 server. Let's just ignore it. */
13073 x_clear_errors (dpy
);
13077 && XGetFontProperty (font
, XA_FONT
, &value
))
13079 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
13080 int len
= strlen (name
);
13083 /* If DXPC (a Differential X Protocol Compressor)
13084 Ver.3.7 is running, XGetAtomName will return null
13085 string. We must avoid such a name. */
13087 try_XLoadQueryFont
= 0;
13091 names
= (char **) alloca (sizeof (char *));
13092 /* Some systems only allow alloca assigned to a
13094 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
13095 bcopy (name
, names
[0], len
+ 1);
13100 try_XLoadQueryFont
= 0;
13103 XFreeFont (dpy
, font
);
13106 if (!try_XLoadQueryFont
)
13108 /* We try at least 10 fonts because XListFonts will return
13109 auto-scaled fonts at the head. */
13110 names
= XListFonts (dpy
, XSTRING (pattern
)->data
, max (maxnames
, 10),
13112 if (x_had_errors_p (dpy
))
13114 /* This error is perhaps due to insufficient memory on X
13115 server. Let's just ignore it. */
13117 x_clear_errors (dpy
);
13121 x_uncatch_errors (dpy
, count
);
13128 /* Make a list of all the fonts we got back.
13129 Store that in the font cache for the display. */
13130 for (i
= 0; i
< num_fonts
; i
++)
13133 char *p
= names
[i
];
13134 int average_width
= -1, dashes
= 0;
13136 /* Count the number of dashes in NAMES[I]. If there are
13137 14 dashes, and the field value following 12th dash
13138 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
13139 is usually too ugly to be used for editing. Let's
13145 if (dashes
== 7) /* PIXEL_SIZE field */
13147 else if (dashes
== 12) /* AVERAGE_WIDTH field */
13148 average_width
= atoi (p
);
13151 if (allow_scalable_fonts_p
13152 || dashes
< 14 || average_width
!= 0)
13154 tem
= build_string (names
[i
]);
13155 if (NILP (Fassoc (tem
, list
)))
13157 if (STRINGP (Vx_pixel_size_width_font_regexp
)
13158 && ((fast_c_string_match_ignore_case
13159 (Vx_pixel_size_width_font_regexp
, names
[i
]))
13161 /* We can set the value of PIXEL_SIZE to the
13162 width of this font. */
13163 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
13165 /* For the moment, width is not known. */
13166 list
= Fcons (Fcons (tem
, Qnil
), list
);
13170 if (!try_XLoadQueryFont
)
13171 XFreeFontNames (names
);
13174 /* Now store the result in the cache. */
13175 XCDR (dpyinfo
->name_list_element
)
13176 = Fcons (Fcons (key
, list
), XCDR (dpyinfo
->name_list_element
));
13179 if (NILP (list
)) continue; /* Try the remaining alternatives. */
13181 newlist
= second_best
= Qnil
;
13182 /* Make a list of the fonts that have the right width. */
13183 for (; CONSP (list
); list
= XCDR (list
))
13189 if (!CONSP (tem
) || NILP (XCAR (tem
)))
13193 newlist
= Fcons (XCAR (tem
), newlist
);
13197 if (!INTEGERP (XCDR (tem
)))
13199 /* Since we have not yet known the size of this font, we
13200 must try slow function call XLoadQueryFont. */
13201 XFontStruct
*thisinfo
;
13204 count
= x_catch_errors (dpy
);
13205 thisinfo
= XLoadQueryFont (dpy
,
13206 XSTRING (XCAR (tem
))->data
);
13207 if (x_had_errors_p (dpy
))
13209 /* This error is perhaps due to insufficient memory on X
13210 server. Let's just ignore it. */
13212 x_clear_errors (dpy
);
13214 x_uncatch_errors (dpy
, count
);
13220 = (thisinfo
->min_bounds
.width
== 0
13222 : make_number (thisinfo
->max_bounds
.width
));
13223 XFreeFont (dpy
, thisinfo
);
13226 /* For unknown reason, the previous call of XListFont had
13227 returned a font which can't be opened. Record the size
13228 as 0 not to try to open it again. */
13229 XCDR (tem
) = make_number (0);
13232 found_size
= XINT (XCDR (tem
));
13233 if (found_size
== size
)
13234 newlist
= Fcons (XCAR (tem
), newlist
);
13235 else if (found_size
> 0)
13237 if (NILP (second_best
))
13239 else if (found_size
< size
)
13241 if (XINT (XCDR (second_best
)) > size
13242 || XINT (XCDR (second_best
)) < found_size
)
13247 if (XINT (XCDR (second_best
)) > size
13248 && XINT (XCDR (second_best
)) > found_size
)
13253 if (!NILP (newlist
))
13255 else if (!NILP (second_best
))
13257 newlist
= Fcons (XCAR (second_best
), Qnil
);
13268 /* Check that FONT is valid on frame F. It is if it can be found in F's
13272 x_check_font (f
, font
)
13277 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13279 xassert (font
!= NULL
);
13281 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
13282 if (dpyinfo
->font_table
[i
].name
13283 && font
== dpyinfo
->font_table
[i
].font
)
13286 xassert (i
< dpyinfo
->n_fonts
);
13289 #endif /* GLYPH_DEBUG != 0 */
13291 /* Set *W to the minimum width, *H to the minimum font height of FONT.
13292 Note: There are (broken) X fonts out there with invalid XFontStruct
13293 min_bounds contents. For example, handa@etl.go.jp reports that
13294 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
13295 have font->min_bounds.width == 0. */
13298 x_font_min_bounds (font
, w
, h
)
13302 *h
= FONT_HEIGHT (font
);
13303 *w
= font
->min_bounds
.width
;
13305 /* Try to handle the case where FONT->min_bounds has invalid
13306 contents. Since the only font known to have invalid min_bounds
13307 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
13309 *w
= font
->max_bounds
.width
;
13313 /* Compute the smallest character width and smallest font height over
13314 all fonts available on frame F. Set the members smallest_char_width
13315 and smallest_font_height in F's x_display_info structure to
13316 the values computed. Value is non-zero if smallest_font_height or
13317 smallest_char_width become smaller than they were before. */
13320 x_compute_min_glyph_bounds (f
)
13324 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13326 int old_width
= dpyinfo
->smallest_char_width
;
13327 int old_height
= dpyinfo
->smallest_font_height
;
13329 dpyinfo
->smallest_font_height
= 100000;
13330 dpyinfo
->smallest_char_width
= 100000;
13332 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
13333 if (dpyinfo
->font_table
[i
].name
)
13335 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
13338 font
= (XFontStruct
*) fontp
->font
;
13339 xassert (font
!= (XFontStruct
*) ~0);
13340 x_font_min_bounds (font
, &w
, &h
);
13342 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
13343 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
13346 xassert (dpyinfo
->smallest_char_width
> 0
13347 && dpyinfo
->smallest_font_height
> 0);
13349 return (dpyinfo
->n_fonts
== 1
13350 || dpyinfo
->smallest_char_width
< old_width
13351 || dpyinfo
->smallest_font_height
< old_height
);
13355 /* Load font named FONTNAME of the size SIZE for frame F, and return a
13356 pointer to the structure font_info while allocating it dynamically.
13357 If SIZE is 0, load any size of font.
13358 If loading is failed, return NULL. */
13361 x_load_font (f
, fontname
, size
)
13363 register char *fontname
;
13366 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13367 Lisp_Object font_names
;
13370 /* Get a list of all the fonts that match this name. Once we
13371 have a list of matching fonts, we compare them against the fonts
13372 we already have by comparing names. */
13373 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
13375 if (!NILP (font_names
))
13380 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
13381 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
13382 if (dpyinfo
->font_table
[i
].name
13383 && (!strcmp (dpyinfo
->font_table
[i
].name
,
13384 XSTRING (XCAR (tail
))->data
)
13385 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
13386 XSTRING (XCAR (tail
))->data
)))
13387 return (dpyinfo
->font_table
+ i
);
13390 /* Load the font and add it to the table. */
13394 struct font_info
*fontp
;
13395 unsigned long value
;
13398 /* If we have found fonts by x_list_font, load one of them. If
13399 not, we still try to load a font by the name given as FONTNAME
13400 because XListFonts (called in x_list_font) of some X server has
13401 a bug of not finding a font even if the font surely exists and
13402 is loadable by XLoadQueryFont. */
13403 if (size
> 0 && !NILP (font_names
))
13404 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
13407 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
13408 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
13409 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
13411 /* This error is perhaps due to insufficient memory on X
13412 server. Let's just ignore it. */
13414 x_clear_errors (FRAME_X_DISPLAY (f
));
13416 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
13421 /* Find a free slot in the font table. */
13422 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
13423 if (dpyinfo
->font_table
[i
].name
== NULL
)
13426 /* If no free slot found, maybe enlarge the font table. */
13427 if (i
== dpyinfo
->n_fonts
13428 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
13431 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
13432 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
13433 dpyinfo
->font_table
13434 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
13437 fontp
= dpyinfo
->font_table
+ i
;
13438 if (i
== dpyinfo
->n_fonts
)
13439 ++dpyinfo
->n_fonts
;
13441 /* Now fill in the slots of *FONTP. */
13443 fontp
->font
= font
;
13444 fontp
->font_idx
= i
;
13445 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
13446 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
13448 /* Try to get the full name of FONT. Put it in FULL_NAME. */
13450 if (XGetFontProperty (font
, XA_FONT
, &value
))
13452 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
13456 /* Count the number of dashes in the "full name".
13457 If it is too few, this isn't really the font's full name,
13459 In X11R4, the fonts did not come with their canonical names
13470 full_name
= (char *) xmalloc (p
- name
+ 1);
13471 bcopy (name
, full_name
, p
- name
+ 1);
13477 if (full_name
!= 0)
13478 fontp
->full_name
= full_name
;
13480 fontp
->full_name
= fontp
->name
;
13482 fontp
->size
= font
->max_bounds
.width
;
13483 fontp
->height
= FONT_HEIGHT (font
);
13485 if (NILP (font_names
))
13487 /* We come here because of a bug of XListFonts mentioned at
13488 the head of this block. Let's store this information in
13489 the cache for x_list_fonts. */
13490 Lisp_Object lispy_name
= build_string (fontname
);
13491 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
13492 Lisp_Object key
= Fcons (Fcons (lispy_name
, make_number (256)),
13495 XCDR (dpyinfo
->name_list_element
)
13496 = Fcons (Fcons (key
,
13497 Fcons (Fcons (lispy_full_name
,
13498 make_number (fontp
->size
)),
13500 XCDR (dpyinfo
->name_list_element
));
13503 key
= Fcons (Fcons (lispy_full_name
, make_number (256)),
13505 XCDR (dpyinfo
->name_list_element
)
13506 = Fcons (Fcons (key
,
13507 Fcons (Fcons (lispy_full_name
,
13508 make_number (fontp
->size
)),
13510 XCDR (dpyinfo
->name_list_element
));
13514 /* The slot `encoding' specifies how to map a character
13515 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
13516 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
13517 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
13518 2:0xA020..0xFF7F). For the moment, we don't know which charset
13519 uses this font. So, we set information in fontp->encoding[1]
13520 which is never used by any charset. If mapping can't be
13521 decided, set FONT_ENCODING_NOT_DECIDED. */
13523 = (font
->max_byte1
== 0
13525 ? (font
->min_char_or_byte2
< 0x80
13526 ? (font
->max_char_or_byte2
< 0x80
13527 ? 0 /* 0x20..0x7F */
13528 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
13529 : 1) /* 0xA0..0xFF */
13531 : (font
->min_byte1
< 0x80
13532 ? (font
->max_byte1
< 0x80
13533 ? (font
->min_char_or_byte2
< 0x80
13534 ? (font
->max_char_or_byte2
< 0x80
13535 ? 0 /* 0x2020..0x7F7F */
13536 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
13537 : 3) /* 0x20A0..0x7FFF */
13538 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
13539 : (font
->min_char_or_byte2
< 0x80
13540 ? (font
->max_char_or_byte2
< 0x80
13541 ? 2 /* 0xA020..0xFF7F */
13542 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
13543 : 1))); /* 0xA0A0..0xFFFF */
13545 fontp
->baseline_offset
13546 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
13547 ? (long) value
: 0);
13548 fontp
->relative_compose
13549 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
13550 ? (long) value
: 0);
13551 fontp
->default_ascent
13552 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
13553 ? (long) value
: 0);
13555 /* Set global flag fonts_changed_p to non-zero if the font loaded
13556 has a character with a smaller width than any other character
13557 before, or if the font loaded has a smalle>r height than any
13558 other font loaded before. If this happens, it will make a
13559 glyph matrix reallocation necessary. */
13560 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
13567 /* Return a pointer to struct font_info of a font named FONTNAME for
13568 frame F. If no such font is loaded, return NULL. */
13571 x_query_font (f
, fontname
)
13573 register char *fontname
;
13575 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13578 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
13579 if (dpyinfo
->font_table
[i
].name
13580 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
13581 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
13582 return (dpyinfo
->font_table
+ i
);
13587 /* Find a CCL program for a font specified by FONTP, and set the member
13588 `encoder' of the structure. */
13591 x_find_ccl_program (fontp
)
13592 struct font_info
*fontp
;
13594 Lisp_Object list
, elt
;
13597 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
13601 && STRINGP (XCAR (elt
))
13602 && ((fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
13604 || (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->full_name
)
13611 struct ccl_program
*ccl
13612 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
13614 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
13617 fontp
->font_encoder
= ccl
;
13623 /***********************************************************************
13625 ***********************************************************************/
13627 #ifdef USE_X_TOOLKIT
13628 static XrmOptionDescRec emacs_options
[] = {
13629 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
13630 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
13632 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
13633 XrmoptionSepArg
, NULL
},
13634 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
13636 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13637 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13638 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13639 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
13640 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
13641 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
13642 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
13644 #endif /* USE_X_TOOLKIT */
13646 static int x_initialized
;
13648 #ifdef MULTI_KBOARD
13649 /* Test whether two display-name strings agree up to the dot that separates
13650 the screen number from the server number. */
13652 same_x_server (name1
, name2
)
13653 char *name1
, *name2
;
13655 int seen_colon
= 0;
13656 unsigned char *system_name
= XSTRING (Vsystem_name
)->data
;
13657 int system_name_length
= strlen (system_name
);
13658 int length_until_period
= 0;
13660 while (system_name
[length_until_period
] != 0
13661 && system_name
[length_until_period
] != '.')
13662 length_until_period
++;
13664 /* Treat `unix' like an empty host name. */
13665 if (! strncmp (name1
, "unix:", 5))
13667 if (! strncmp (name2
, "unix:", 5))
13669 /* Treat this host's name like an empty host name. */
13670 if (! strncmp (name1
, system_name
, system_name_length
)
13671 && name1
[system_name_length
] == ':')
13672 name1
+= system_name_length
;
13673 if (! strncmp (name2
, system_name
, system_name_length
)
13674 && name2
[system_name_length
] == ':')
13675 name2
+= system_name_length
;
13676 /* Treat this host's domainless name like an empty host name. */
13677 if (! strncmp (name1
, system_name
, length_until_period
)
13678 && name1
[length_until_period
] == ':')
13679 name1
+= length_until_period
;
13680 if (! strncmp (name2
, system_name
, length_until_period
)
13681 && name2
[length_until_period
] == ':')
13682 name2
+= length_until_period
;
13684 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
13688 if (seen_colon
&& *name1
== '.')
13692 && (*name1
== '.' || *name1
== '\0')
13693 && (*name2
== '.' || *name2
== '\0'));
13697 struct x_display_info
*
13698 x_term_init (display_name
, xrm_option
, resource_name
)
13699 Lisp_Object display_name
;
13701 char *resource_name
;
13705 struct x_display_info
*dpyinfo
;
13710 if (!x_initialized
)
13716 #ifdef USE_X_TOOLKIT
13717 /* weiner@footloose.sps.mot.com reports that this causes
13719 X protocol error: BadAtom (invalid Atom parameter)
13720 on protocol request 18skiloaf.
13721 So let's not use it until R6. */
13722 #ifdef HAVE_X11XTR6
13723 XtSetLanguageProc (NULL
, NULL
, NULL
);
13734 argv
[argc
++] = "-xrm";
13735 argv
[argc
++] = xrm_option
;
13737 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
13738 resource_name
, EMACS_CLASS
,
13739 emacs_options
, XtNumber (emacs_options
),
13742 #ifdef HAVE_X11XTR6
13743 /* I think this is to compensate for XtSetLanguageProc. */
13748 #else /* not USE_X_TOOLKIT */
13750 XSetLocaleModifiers ("");
13752 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
13753 #endif /* not USE_X_TOOLKIT */
13755 /* Detect failure. */
13762 /* We have definitely succeeded. Record the new connection. */
13764 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
13765 bzero (dpyinfo
, sizeof *dpyinfo
);
13767 #ifdef MULTI_KBOARD
13769 struct x_display_info
*share
;
13772 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
13773 share
= share
->next
, tail
= XCDR (tail
))
13774 if (same_x_server (XSTRING (XCAR (XCAR (tail
)))->data
,
13775 XSTRING (display_name
)->data
))
13778 dpyinfo
->kboard
= share
->kboard
;
13781 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
13782 init_kboard (dpyinfo
->kboard
);
13783 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
13785 char *vendor
= ServerVendor (dpy
);
13787 dpyinfo
->kboard
->Vsystem_key_alist
13788 = call1 (Qvendor_specific_keysyms
,
13789 build_string (vendor
? vendor
: ""));
13793 dpyinfo
->kboard
->next_kboard
= all_kboards
;
13794 all_kboards
= dpyinfo
->kboard
;
13795 /* Don't let the initial kboard remain current longer than necessary.
13796 That would cause problems if a file loaded on startup tries to
13797 prompt in the mini-buffer. */
13798 if (current_kboard
== initial_kboard
)
13799 current_kboard
= dpyinfo
->kboard
;
13801 dpyinfo
->kboard
->reference_count
++;
13805 /* Put this display on the chain. */
13806 dpyinfo
->next
= x_display_list
;
13807 x_display_list
= dpyinfo
;
13809 /* Put it on x_display_name_list as well, to keep them parallel. */
13810 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
13811 x_display_name_list
);
13812 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
13814 dpyinfo
->display
= dpy
;
13817 XSetAfterFunction (x_current_display
, x_trace_wire
);
13821 = (char *) xmalloc (STRING_BYTES (XSTRING (Vinvocation_name
))
13822 + STRING_BYTES (XSTRING (Vsystem_name
))
13824 sprintf (dpyinfo
->x_id_name
, "%s@%s",
13825 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
13827 /* Figure out which modifier bits mean what. */
13828 x_find_modifier_meanings (dpyinfo
);
13830 /* Get the scroll bar cursor. */
13831 dpyinfo
->vertical_scroll_bar_cursor
13832 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
13834 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
13835 resource_name
, EMACS_CLASS
);
13836 #ifdef HAVE_XRMSETDATABASE
13837 XrmSetDatabase (dpyinfo
->display
, xrdb
);
13839 dpyinfo
->display
->db
= xrdb
;
13841 /* Put the rdb where we can find it in a way that works on
13843 dpyinfo
->xrdb
= xrdb
;
13845 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
13846 DefaultScreen (dpyinfo
->display
));
13847 select_visual (dpyinfo
);
13848 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
13849 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
13850 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
13851 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
13852 dpyinfo
->grabbed
= 0;
13853 dpyinfo
->reference_count
= 0;
13854 dpyinfo
->icon_bitmap_id
= -1;
13855 dpyinfo
->font_table
= NULL
;
13856 dpyinfo
->n_fonts
= 0;
13857 dpyinfo
->font_table_size
= 0;
13858 dpyinfo
->bitmaps
= 0;
13859 dpyinfo
->bitmaps_size
= 0;
13860 dpyinfo
->bitmaps_last
= 0;
13861 dpyinfo
->scratch_cursor_gc
= 0;
13862 dpyinfo
->mouse_face_mouse_frame
= 0;
13863 dpyinfo
->mouse_face_deferred_gc
= 0;
13864 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
13865 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
13866 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
13867 dpyinfo
->mouse_face_window
= Qnil
;
13868 dpyinfo
->mouse_face_overlay
= Qnil
;
13869 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
13870 dpyinfo
->mouse_face_defer
= 0;
13871 dpyinfo
->x_focus_frame
= 0;
13872 dpyinfo
->x_focus_event_frame
= 0;
13873 dpyinfo
->x_highlight_frame
= 0;
13874 dpyinfo
->image_cache
= make_image_cache ();
13876 /* See if a private colormap is requested. */
13877 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
13879 if (dpyinfo
->visual
->class == PseudoColor
)
13882 value
= display_x_get_resource (dpyinfo
,
13883 build_string ("privateColormap"),
13884 build_string ("PrivateColormap"),
13886 if (STRINGP (value
)
13887 && (!strcmp (XSTRING (value
)->data
, "true")
13888 || !strcmp (XSTRING (value
)->data
, "on")))
13889 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
13893 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
13894 dpyinfo
->visual
, AllocNone
);
13897 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
13898 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
13899 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
13900 dpyinfo
->resy
= pixels
* 25.4 / mm
;
13901 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
13902 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
13903 dpyinfo
->resx
= pixels
* 25.4 / mm
;
13906 dpyinfo
->Xatom_wm_protocols
13907 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
13908 dpyinfo
->Xatom_wm_take_focus
13909 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
13910 dpyinfo
->Xatom_wm_save_yourself
13911 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
13912 dpyinfo
->Xatom_wm_delete_window
13913 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
13914 dpyinfo
->Xatom_wm_change_state
13915 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
13916 dpyinfo
->Xatom_wm_configure_denied
13917 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
13918 dpyinfo
->Xatom_wm_window_moved
13919 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
13920 dpyinfo
->Xatom_editres
13921 = XInternAtom (dpyinfo
->display
, "Editres", False
);
13922 dpyinfo
->Xatom_CLIPBOARD
13923 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
13924 dpyinfo
->Xatom_TIMESTAMP
13925 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
13926 dpyinfo
->Xatom_TEXT
13927 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
13928 dpyinfo
->Xatom_COMPOUND_TEXT
13929 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
13930 dpyinfo
->Xatom_DELETE
13931 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
13932 dpyinfo
->Xatom_MULTIPLE
13933 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
13934 dpyinfo
->Xatom_INCR
13935 = XInternAtom (dpyinfo
->display
, "INCR", False
);
13936 dpyinfo
->Xatom_EMACS_TMP
13937 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
13938 dpyinfo
->Xatom_TARGETS
13939 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
13940 dpyinfo
->Xatom_NULL
13941 = XInternAtom (dpyinfo
->display
, "NULL", False
);
13942 dpyinfo
->Xatom_ATOM_PAIR
13943 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
13944 /* For properties of font. */
13945 dpyinfo
->Xatom_PIXEL_SIZE
13946 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
13947 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
13948 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
13949 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
13950 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
13951 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
13952 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
13954 /* Ghostscript support. */
13955 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
13956 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
13958 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
13961 dpyinfo
->cut_buffers_initialized
= 0;
13963 connection
= ConnectionNumber (dpyinfo
->display
);
13964 dpyinfo
->connection
= connection
;
13969 null_bits
[0] = 0x00;
13971 dpyinfo
->null_pixel
13972 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
13973 null_bits
, 1, 1, (long) 0, (long) 0,
13978 extern int gray_bitmap_width
, gray_bitmap_height
;
13979 extern char *gray_bitmap_bits
;
13981 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
13983 gray_bitmap_width
, gray_bitmap_height
,
13984 (unsigned long) 1, (unsigned long) 0, 1);
13988 xim_initialize (dpyinfo
, resource_name
);
13991 #ifdef subprocesses
13992 /* This is only needed for distinguishing keyboard and process input. */
13993 if (connection
!= 0)
13994 add_keyboard_wait_descriptor (connection
);
13997 #ifndef F_SETOWN_BUG
13999 #ifdef F_SETOWN_SOCK_NEG
14000 /* stdin is a socket here */
14001 fcntl (connection
, F_SETOWN
, -getpid ());
14002 #else /* ! defined (F_SETOWN_SOCK_NEG) */
14003 fcntl (connection
, F_SETOWN
, getpid ());
14004 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
14005 #endif /* ! defined (F_SETOWN) */
14006 #endif /* F_SETOWN_BUG */
14009 if (interrupt_input
)
14010 init_sigio (connection
);
14011 #endif /* ! defined (SIGIO) */
14014 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
14015 /* Make sure that we have a valid font for dialog boxes
14016 so that Xt does not crash. */
14018 Display
*dpy
= dpyinfo
->display
;
14019 XrmValue d
, fr
, to
;
14023 d
.addr
= (XPointer
)&dpy
;
14024 d
.size
= sizeof (Display
*);
14025 fr
.addr
= XtDefaultFont
;
14026 fr
.size
= sizeof (XtDefaultFont
);
14027 to
.size
= sizeof (Font
*);
14028 to
.addr
= (XPointer
)&font
;
14029 count
= x_catch_errors (dpy
);
14030 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
14032 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
14033 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
14034 x_uncatch_errors (dpy
, count
);
14039 /* See if we should run in synchronous mode. This is useful
14040 for debugging X code. */
14043 value
= display_x_get_resource (dpyinfo
,
14044 build_string ("synchronous"),
14045 build_string ("Synchronous"),
14047 if (STRINGP (value
)
14048 && (!strcmp (XSTRING (value
)->data
, "true")
14049 || !strcmp (XSTRING (value
)->data
, "on")))
14050 XSynchronize (dpyinfo
->display
, True
);
14058 /* Get rid of display DPYINFO, assuming all frames are already gone,
14059 and without sending any more commands to the X server. */
14062 x_delete_display (dpyinfo
)
14063 struct x_display_info
*dpyinfo
;
14065 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
14067 /* Discard this display from x_display_name_list and x_display_list.
14068 We can't use Fdelq because that can quit. */
14069 if (! NILP (x_display_name_list
)
14070 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
14071 x_display_name_list
= XCDR (x_display_name_list
);
14076 tail
= x_display_name_list
;
14077 while (CONSP (tail
) && CONSP (XCDR (tail
)))
14079 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
14081 XCDR (tail
) = XCDR (XCDR (tail
));
14084 tail
= XCDR (tail
);
14088 if (next_noop_dpyinfo
== dpyinfo
)
14089 next_noop_dpyinfo
= dpyinfo
->next
;
14091 if (x_display_list
== dpyinfo
)
14092 x_display_list
= dpyinfo
->next
;
14095 struct x_display_info
*tail
;
14097 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
14098 if (tail
->next
== dpyinfo
)
14099 tail
->next
= tail
->next
->next
;
14102 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
14103 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
14104 XrmDestroyDatabase (dpyinfo
->xrdb
);
14107 #ifdef MULTI_KBOARD
14108 if (--dpyinfo
->kboard
->reference_count
== 0)
14109 delete_kboard (dpyinfo
->kboard
);
14113 xim_close_dpy (dpyinfo
);
14116 xfree (dpyinfo
->font_table
);
14117 xfree (dpyinfo
->x_id_name
);
14118 xfree (dpyinfo
->color_cells
);
14123 /* Set up use of X before we make the first connection. */
14125 static struct redisplay_interface x_redisplay_interface
=
14130 x_clear_end_of_line
,
14132 x_after_update_window_line
,
14133 x_update_window_begin
,
14134 x_update_window_end
,
14137 x_clear_mouse_face
,
14138 x_get_glyph_overhangs
,
14139 x_fix_overlapping_area
14145 rif
= &x_redisplay_interface
;
14147 clear_frame_hook
= x_clear_frame
;
14148 ins_del_lines_hook
= x_ins_del_lines
;
14149 change_line_highlight_hook
= x_change_line_highlight
;
14150 delete_glyphs_hook
= x_delete_glyphs
;
14151 ring_bell_hook
= XTring_bell
;
14152 reset_terminal_modes_hook
= XTreset_terminal_modes
;
14153 set_terminal_modes_hook
= XTset_terminal_modes
;
14154 update_begin_hook
= x_update_begin
;
14155 update_end_hook
= x_update_end
;
14156 set_terminal_window_hook
= XTset_terminal_window
;
14157 read_socket_hook
= XTread_socket
;
14158 frame_up_to_date_hook
= XTframe_up_to_date
;
14159 reassert_line_highlight_hook
= XTreassert_line_highlight
;
14160 mouse_position_hook
= XTmouse_position
;
14161 frame_rehighlight_hook
= XTframe_rehighlight
;
14162 frame_raise_lower_hook
= XTframe_raise_lower
;
14163 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
14164 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
14165 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
14166 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
14167 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
14169 scroll_region_ok
= 1; /* we'll scroll partial frames */
14170 char_ins_del_ok
= 1;
14171 line_ins_del_ok
= 1; /* we'll just blt 'em */
14172 fast_clear_end_of_line
= 1; /* X does this well */
14173 memory_below_frame
= 0; /* we don't remember what scrolls
14178 last_tool_bar_item
= -1;
14179 any_help_event_p
= 0;
14181 /* Try to use interrupt input; if we can't, then start polling. */
14182 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
14184 #ifdef USE_X_TOOLKIT
14185 XtToolkitInitialize ();
14186 Xt_app_con
= XtCreateApplicationContext ();
14187 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
14189 /* Install an asynchronous timer that processes Xt timeout events
14190 every 0.1s. This is necessary because some widget sets use
14191 timeouts internally, for example the LessTif menu bar, or the
14192 Xaw3d scroll bar. When Xt timouts aren't processed, these
14193 widgets don't behave normally. */
14195 EMACS_TIME interval
;
14196 EMACS_SET_SECS_USECS (interval
, 0, 100000);
14197 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
14201 #ifdef USE_TOOLKIT_SCROLL_BARS
14202 xaw3d_arrow_scroll
= False
;
14203 xaw3d_pick_top
= True
;
14206 /* Note that there is no real way portable across R3/R4 to get the
14207 original error handler. */
14208 XSetErrorHandler (x_error_handler
);
14209 XSetIOErrorHandler (x_io_error_quitter
);
14211 /* Disable Window Change signals; they are handled by X events. */
14213 signal (SIGWINCH
, SIG_DFL
);
14214 #endif /* ! defined (SIGWINCH) */
14216 signal (SIGPIPE
, x_connection_signal
);
14223 staticpro (&x_error_message_string
);
14224 x_error_message_string
= Qnil
;
14226 staticpro (&x_display_name_list
);
14227 x_display_name_list
= Qnil
;
14229 staticpro (&last_mouse_scroll_bar
);
14230 last_mouse_scroll_bar
= Qnil
;
14232 staticpro (&Qvendor_specific_keysyms
);
14233 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
14235 staticpro (&last_mouse_press_frame
);
14236 last_mouse_press_frame
= Qnil
;
14239 staticpro (&help_echo
);
14240 help_echo_object
= Qnil
;
14241 staticpro (&help_echo_object
);
14242 help_echo_window
= Qnil
;
14243 staticpro (&help_echo_window
);
14244 previous_help_echo
= Qnil
;
14245 staticpro (&previous_help_echo
);
14246 help_echo_pos
= -1;
14248 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
14249 "*Non-nil means draw block cursor as wide as the glyph under it.\n\
14250 For example, if a block cursor is over a tab, it will be drawn as\n\
14251 wide as that tab on the display.");
14252 x_stretch_cursor_p
= 0;
14254 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
14255 "What X toolkit scroll bars Emacs uses.\n\
14256 A value of nil means Emacs doesn't use X toolkit scroll bars.\n\
14257 Otherwise, value is a symbol describing the X toolkit.");
14258 #ifdef USE_TOOLKIT_SCROLL_BARS
14260 Vx_toolkit_scroll_bars
= intern ("motif");
14261 #elif defined HAVE_XAW3D
14262 Vx_toolkit_scroll_bars
= intern ("xaw3d");
14264 Vx_toolkit_scroll_bars
= intern ("xaw");
14267 Vx_toolkit_scroll_bars
= Qnil
;
14270 staticpro (&last_mouse_motion_frame
);
14271 last_mouse_motion_frame
= Qnil
;
14274 #endif /* not HAVE_X_WINDOWS */