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 #include <Xm/ScrollBarP.h>
121 #else /* !USE_MOTIF i.e. use Xaw */
124 #include <X11/Xaw3d/Simple.h>
125 #include <X11/Xaw3d/Scrollbar.h>
126 #define ARROW_SCROLLBAR
127 #include <X11/Xaw3d/ScrollbarP.h>
128 #else /* !HAVE_XAW3D */
129 #include <X11/Xaw/Simple.h>
130 #include <X11/Xaw/Scrollbar.h>
131 #endif /* !HAVE_XAW3D */
133 #define XtNpickTop "pickTop"
134 #endif /* !XtNpickTop */
135 #endif /* !USE_MOTIF */
136 #endif /* USE_TOOLKIT_SCROLL_BARS */
138 #endif /* USE_X_TOOLKIT */
140 #ifndef USE_X_TOOLKIT
141 #define x_any_window_to_frame x_window_to_frame
142 #define x_top_window_to_frame x_window_to_frame
147 #ifndef XtNinitialState
148 #define XtNinitialState "initialState"
153 #define min(a,b) ((a) < (b) ? (a) : (b))
156 #define max(a,b) ((a) > (b) ? (a) : (b))
159 #define abs(x) ((x) < 0 ? -(x) : (x))
161 #define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER))
164 /* Bitmaps for truncated lines. */
169 LEFT_TRUNCATION_BITMAP
,
170 RIGHT_TRUNCATION_BITMAP
,
171 OVERLAY_ARROW_BITMAP
,
172 CONTINUED_LINE_BITMAP
,
173 CONTINUATION_LINE_BITMAP
,
177 /* Bitmap drawn to indicate lines not displaying text if
178 `indicate-empty-lines' is non-nil. */
182 static unsigned char zv_bits
[] = {
183 0x00, 0x00, 0x1e, 0x1e, 0x1e, 0x1e, 0x00, 0x00};
185 /* An arrow like this: `<-'. */
188 #define left_height 8
189 static unsigned char left_bits
[] = {
190 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
192 /* Right truncation arrow bitmap `->'. */
194 #define right_width 8
195 #define right_height 8
196 static unsigned char right_bits
[] = {
197 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
199 /* Marker for continued lines. */
201 #define continued_width 8
202 #define continued_height 8
203 static unsigned char continued_bits
[] = {
204 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
206 /* Marker for continuation lines. */
208 #define continuation_width 8
209 #define continuation_height 8
210 static unsigned char continuation_bits
[] = {
211 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
213 /* Overlay arrow bitmap. */
219 static unsigned char ov_bits
[] = {
220 0x30, 0x08, 0x3c, 0x7e, 0x7a, 0x7a, 0x62, 0x3c};
222 /* A triangular arrow. */
225 static unsigned char ov_bits
[] = {
226 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
230 extern Lisp_Object Qhelp_echo
;
233 /* Non-nil means Emacs uses toolkit scroll bars. */
235 Lisp_Object Vx_toolkit_scroll_bars
;
237 /* If a string, XTread_socket generates an event to display that string.
238 (The display is done in read_char.) */
240 static Lisp_Object help_echo
;
241 static Lisp_Object help_echo_window
;
242 static Lisp_Object help_echo_object
;
243 static int help_echo_pos
;
245 /* Temporary variable for XTread_socket. */
247 static Lisp_Object previous_help_echo
;
249 /* Non-zero means that a HELP_EVENT has been generated since Emacs
252 static int any_help_event_p
;
254 /* Non-zero means draw block and hollow cursor as wide as the glyph
255 under it. For example, if a block cursor is over a tab, it will be
256 drawn as wide as that tab on the display. */
258 int x_stretch_cursor_p
;
260 /* This is a chain of structures for all the X displays currently in
263 struct x_display_info
*x_display_list
;
265 /* This is a list of cons cells, each of the form (NAME
266 . FONT-LIST-CACHE), one for each element of x_display_list and in
267 the same order. NAME is the name of the frame. FONT-LIST-CACHE
268 records previous values returned by x-list-fonts. */
270 Lisp_Object x_display_name_list
;
272 /* Frame being updated by update_frame. This is declared in term.c.
273 This is set by update_begin and looked at by all the XT functions.
274 It is zero while not inside an update. In that case, the XT
275 functions assume that `selected_frame' is the frame to apply to. */
277 extern struct frame
*updating_frame
;
279 extern int waiting_for_input
;
281 /* This is a frame waiting to be auto-raised, within XTread_socket. */
283 struct frame
*pending_autoraise_frame
;
286 /* The application context for Xt use. */
287 XtAppContext Xt_app_con
;
288 static String Xt_default_resources
[] = {0};
289 #endif /* USE_X_TOOLKIT */
291 /* Nominal cursor position -- where to draw output.
292 HPOS and VPOS are window relative glyph matrix coordinates.
293 X and Y are window relative pixel coordinates. */
295 struct cursor_pos output_cursor
;
297 /* Non-zero means user is interacting with a toolkit scroll bar. */
299 static int toolkit_scroll_bar_interaction
;
303 Formerly, we used PointerMotionHintMask (in standard_event_mask)
304 so that we would have to call XQueryPointer after each MotionNotify
305 event to ask for another such event. However, this made mouse tracking
306 slow, and there was a bug that made it eventually stop.
308 Simply asking for MotionNotify all the time seems to work better.
310 In order to avoid asking for motion events and then throwing most
311 of them away or busy-polling the server for mouse positions, we ask
312 the server for pointer motion hints. This means that we get only
313 one event per group of mouse movements. "Groups" are delimited by
314 other kinds of events (focus changes and button clicks, for
315 example), or by XQueryPointer calls; when one of these happens, we
316 get another MotionNotify event the next time the mouse moves. This
317 is at least as efficient as getting motion events when mouse
318 tracking is on, and I suspect only negligibly worse when tracking
321 /* Where the mouse was last time we reported a mouse event. */
323 FRAME_PTR last_mouse_frame
;
324 static XRectangle last_mouse_glyph
;
325 static Lisp_Object last_mouse_press_frame
;
327 /* The scroll bar in which the last X motion event occurred.
329 If the last X motion event occurred in a scroll bar, we set this so
330 XTmouse_position can know whether to report a scroll bar motion or
333 If the last X motion event didn't occur in a scroll bar, we set
334 this to Qnil, to tell XTmouse_position to return an ordinary motion
337 static Lisp_Object last_mouse_scroll_bar
;
339 /* This is a hack. We would really prefer that XTmouse_position would
340 return the time associated with the position it returns, but there
341 doesn't seem to be any way to wrest the time-stamp from the server
342 along with the position query. So, we just keep track of the time
343 of the last movement we received, and return that in hopes that
344 it's somewhat accurate. */
346 static Time last_mouse_movement_time
;
348 /* Incremented by XTread_socket whenever it really tries to read
352 static int volatile input_signal_count
;
354 static int input_signal_count
;
357 /* Used locally within XTread_socket. */
359 static int x_noop_count
;
361 /* Initial values of argv and argc. */
363 extern char **initial_argv
;
364 extern int initial_argc
;
366 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
368 /* Tells if a window manager is present or not. */
370 extern Lisp_Object Vx_no_window_manager
;
372 extern Lisp_Object Qface
, Qmouse_face
;
376 /* A mask of extra modifier bits to put into every keyboard char. */
378 extern int extra_keyboard_modifiers
;
380 static Lisp_Object Qvendor_specific_keysyms
;
382 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
383 extern Lisp_Object x_icon_type
P_ ((struct frame
*));
386 /* Enumeration for overriding/changing the face to use for drawing
387 glyphs in x_draw_glyphs. */
389 enum draw_glyphs_face
399 static void x_set_window_size_1
P_ ((struct frame
*, int, int, int));
400 static const XColor
*x_color_cells
P_ ((struct frame
*, int *));
401 static void x_update_window_end
P_ ((struct window
*, int, int));
402 static void frame_to_window_pixel_xy
P_ ((struct window
*, int *, int *));
403 void x_delete_display
P_ ((struct x_display_info
*));
404 static unsigned int x_x_to_emacs_modifiers
P_ ((struct x_display_info
*,
406 static int fast_find_position
P_ ((struct window
*, int, int *, int *,
408 static void set_output_cursor
P_ ((struct cursor_pos
*));
409 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
410 int *, int *, int *));
411 static void note_mode_line_highlight
P_ ((struct window
*, int, int));
412 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
413 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
414 static void x_handle_tool_bar_click
P_ ((struct frame
*, XButtonEvent
*));
415 static void show_mouse_face
P_ ((struct x_display_info
*,
416 enum draw_glyphs_face
));
417 static int x_io_error_quitter
P_ ((Display
*));
418 int x_catch_errors
P_ ((Display
*));
419 void x_uncatch_errors
P_ ((Display
*, int));
420 void x_lower_frame
P_ ((struct frame
*));
421 void x_scroll_bar_clear
P_ ((struct frame
*));
422 int x_had_errors_p
P_ ((Display
*));
423 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
424 void x_raise_frame
P_ ((struct frame
*));
425 void x_set_window_size
P_ ((struct frame
*, int, int, int));
426 void x_wm_set_window_state
P_ ((struct frame
*, int));
427 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
428 void x_initialize
P_ ((void));
429 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
430 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
431 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
433 enum draw_glyphs_face
));
434 static void x_update_end
P_ ((struct frame
*));
435 static void XTframe_up_to_date
P_ ((struct frame
*));
436 static void XTreassert_line_highlight
P_ ((int, int));
437 static void x_change_line_highlight
P_ ((int, int, int, int));
438 static void XTset_terminal_modes
P_ ((void));
439 static void XTreset_terminal_modes
P_ ((void));
440 static void XTcursor_to
P_ ((int, int, int, int));
441 static void x_write_glyphs
P_ ((struct glyph
*, int));
442 static void x_clear_end_of_line
P_ ((int));
443 static void x_clear_frame
P_ ((void));
444 static void x_clear_cursor
P_ ((struct window
*));
445 static void frame_highlight
P_ ((struct frame
*));
446 static void frame_unhighlight
P_ ((struct frame
*));
447 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
448 static void XTframe_rehighlight
P_ ((struct frame
*));
449 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
450 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
451 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int));
452 static int x_intersect_rectangles
P_ ((XRectangle
*, XRectangle
*,
454 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
455 static void expose_window_tree
P_ ((struct window
*, XRectangle
*));
456 static void expose_window
P_ ((struct window
*, XRectangle
*));
457 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
458 XRectangle
*, enum glyph_row_area
));
459 static void expose_line
P_ ((struct window
*, struct glyph_row
*,
461 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
462 static void x_update_window_cursor
P_ ((struct window
*, int));
463 static void x_erase_phys_cursor
P_ ((struct window
*));
464 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
465 static void x_draw_bitmap
P_ ((struct window
*, struct glyph_row
*,
468 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
470 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, XRectangle
*));
471 static void x_draw_row_bitmaps
P_ ((struct window
*, struct glyph_row
*));
472 static void note_overwritten_text_cursor
P_ ((struct window
*, int, int));
473 static void x_flush
P_ ((struct frame
*f
));
474 static void x_update_begin
P_ ((struct frame
*));
475 static void x_update_window_begin
P_ ((struct window
*));
476 static void x_draw_vertical_border
P_ ((struct window
*));
477 static void x_after_update_window_line
P_ ((struct glyph_row
*));
478 static INLINE
void take_vertical_position_into_account
P_ ((struct it
*));
479 static void x_produce_stretch_glyph
P_ ((struct it
*));
482 /* Flush display of frame F, or of all frames if F is null. */
491 Lisp_Object rest
, frame
;
492 FOR_EACH_FRAME (rest
, frame
)
493 x_flush (XFRAME (frame
));
495 else if (FRAME_X_P (f
))
496 XFlush (FRAME_X_DISPLAY (f
));
501 /* Remove calls to XFlush by defining XFlush to an empty replacement.
502 Calls to XFlush should be unnecessary because the X output buffer
503 is flushed automatically as needed by calls to XPending,
504 XNextEvent, or XWindowEvent according to the XFlush man page.
505 XTread_socket calls XPending. Removing XFlush improves
508 #define XFlush(DISPLAY) (void) 0
511 /***********************************************************************
513 ***********************************************************************/
517 /* This is a function useful for recording debugging information about
518 the sequence of occurrences in this file. */
526 struct record event_record
[100];
528 int event_record_index
;
530 record_event (locus
, type
)
534 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
535 event_record_index
= 0;
537 event_record
[event_record_index
].locus
= locus
;
538 event_record
[event_record_index
].type
= type
;
539 event_record_index
++;
546 /* Return the struct x_display_info corresponding to DPY. */
548 struct x_display_info
*
549 x_display_info_for_display (dpy
)
552 struct x_display_info
*dpyinfo
;
554 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
555 if (dpyinfo
->display
== dpy
)
563 /***********************************************************************
564 Starting and ending an update
565 ***********************************************************************/
567 /* Start an update of frame F. This function is installed as a hook
568 for update_begin, i.e. it is called when update_begin is called.
569 This function is called prior to calls to x_update_window_begin for
570 each window being updated. Currently, there is nothing to do here
571 because all interesting stuff is done on a window basis. */
581 /* Start update of window W. Set the global variable updated_window
582 to the window being updated and set output_cursor to the cursor
586 x_update_window_begin (w
)
589 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
590 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
593 set_output_cursor (&w
->cursor
);
597 if (f
== display_info
->mouse_face_mouse_frame
)
599 /* Don't do highlighting for mouse motion during the update. */
600 display_info
->mouse_face_defer
= 1;
602 /* If F needs to be redrawn, simply forget about any prior mouse
604 if (FRAME_GARBAGED_P (f
))
605 display_info
->mouse_face_window
= Qnil
;
607 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
608 their mouse_face_p flag set, which means that they are always
609 unequal to rows in a desired matrix which never have that
610 flag set. So, rows containing mouse-face glyphs are never
611 scrolled, and we don't have to switch the mouse highlight off
612 here to prevent it from being scrolled. */
614 /* Can we tell that this update does not affect the window
615 where the mouse highlight is? If so, no need to turn off.
616 Likewise, don't do anything if the frame is garbaged;
617 in that case, the frame's current matrix that we would use
618 is all wrong, and we will redisplay that line anyway. */
619 if (!NILP (display_info
->mouse_face_window
)
620 && w
== XWINDOW (display_info
->mouse_face_window
))
624 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
625 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
628 if (i
< w
->desired_matrix
->nrows
)
629 clear_mouse_face (display_info
);
638 /* Draw a vertical window border to the right of window W if W doesn't
639 have vertical scroll bars. */
642 x_draw_vertical_border (w
)
645 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
647 /* Redraw borders between horizontally adjacent windows. Don't
648 do it for frames with vertical scroll bars because either the
649 right scroll bar of a window, or the left scroll bar of its
650 neighbor will suffice as a border. */
651 if (!WINDOW_RIGHTMOST_P (w
)
652 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
656 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
657 x1
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
);
660 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
661 f
->output_data
.x
->normal_gc
, x1
, y0
, x1
, y1
);
666 /* End update of window W (which is equal to updated_window).
668 Draw vertical borders between horizontally adjacent windows, and
669 display W's cursor if CURSOR_ON_P is non-zero.
671 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
672 glyphs in mouse-face were overwritten. In that case we have to
673 make sure that the mouse-highlight is properly redrawn.
675 W may be a menu bar pseudo-window in case we don't have X toolkit
676 support. Such windows don't have a cursor, so don't display it
680 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
682 int cursor_on_p
, mouse_face_overwritten_p
;
684 if (!w
->pseudo_window_p
)
686 struct x_display_info
*dpyinfo
687 = FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
691 /* If a row with mouse-face was overwritten, arrange for
692 XTframe_up_to_date to redisplay the mouse highlight. */
693 if (mouse_face_overwritten_p
)
695 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
696 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
697 dpyinfo
->mouse_face_window
= Qnil
;
701 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
703 output_cursor
.x
, output_cursor
.y
);
705 x_draw_vertical_border (w
);
709 updated_window
= NULL
;
713 /* End update of frame F. This function is installed as a hook in
720 /* Mouse highlight may be displayed again. */
721 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
724 XFlush (FRAME_X_DISPLAY (f
));
729 /* This function is called from various places in xdisp.c whenever a
730 complete update has been performed. The global variable
731 updated_window is not available here. */
734 XTframe_up_to_date (f
)
739 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
741 if (dpyinfo
->mouse_face_deferred_gc
742 || f
== dpyinfo
->mouse_face_mouse_frame
)
745 if (dpyinfo
->mouse_face_mouse_frame
)
746 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
747 dpyinfo
->mouse_face_mouse_x
,
748 dpyinfo
->mouse_face_mouse_y
);
749 dpyinfo
->mouse_face_deferred_gc
= 0;
756 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
757 arrow bitmaps, or clear the areas where they would be displayed
758 before DESIRED_ROW is made current. The window being updated is
759 found in updated_window. This function It is called from
760 update_window_line only if it is known that there are differences
761 between bitmaps to be drawn between current row and DESIRED_ROW. */
764 x_after_update_window_line (desired_row
)
765 struct glyph_row
*desired_row
;
767 struct window
*w
= updated_window
;
771 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
777 x_draw_row_bitmaps (w
, desired_row
);
779 /* When a window has disappeared, make sure that no rest of
780 full-width rows stays visible in the internal border. */
781 if (windows_or_buffers_changed
782 && (f
= XFRAME (w
->frame
),
783 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
786 int height
= desired_row
->visible_height
;
787 int x
= (window_box_right (w
, -1)
788 + FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
));
789 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
791 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
792 x
, y
, width
, height
, False
);
800 /* Draw the bitmap WHICH in one of the areas to the left or right of
801 window W. ROW is the glyph row for which to display the bitmap; it
802 determines the vertical position at which the bitmap has to be
806 x_draw_bitmap (w
, row
, which
)
808 struct glyph_row
*row
;
809 enum bitmap_type which
;
811 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
812 Display
*display
= FRAME_X_DISPLAY (f
);
813 Window window
= FRAME_X_WINDOW (f
);
817 GC gc
= f
->output_data
.x
->normal_gc
;
819 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
821 /* Must clip because of partially visible lines. */
822 x_clip_to_row (w
, row
, gc
, 1);
826 case LEFT_TRUNCATION_BITMAP
:
830 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
832 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
835 case OVERLAY_ARROW_BITMAP
:
839 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
841 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
844 case RIGHT_TRUNCATION_BITMAP
:
848 x
= window_box_right (w
, -1);
849 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
852 case CONTINUED_LINE_BITMAP
:
855 bits
= continued_bits
;
856 x
= window_box_right (w
, -1);
857 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
860 case CONTINUATION_LINE_BITMAP
:
861 wd
= continuation_width
;
862 h
= continuation_height
;
863 bits
= continuation_bits
;
864 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
866 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
873 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
875 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
882 /* Convert to frame coordinates. Set dy to the offset in the row to
883 start drawing the bitmap. */
884 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
885 dy
= (row
->height
- h
) / 2;
887 /* Draw the bitmap. I believe these small pixmaps can be cached
889 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
890 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, wd
, h
,
892 face
->background
, depth
);
893 XCopyArea (display
, pixmap
, window
, gc
, 0, 0, wd
, h
, x
, y
+ dy
);
894 XFreePixmap (display
, pixmap
);
895 XSetClipMask (display
, gc
, None
);
899 /* Draw flags bitmaps for glyph row ROW on window W. Call this
900 function with input blocked. */
903 x_draw_row_bitmaps (w
, row
)
905 struct glyph_row
*row
;
907 struct frame
*f
= XFRAME (w
->frame
);
908 enum bitmap_type bitmap
;
910 int header_line_height
= -1;
912 xassert (interrupt_input_blocked
);
914 /* If row is completely invisible, because of vscrolling, we
915 don't have to draw anything. */
916 if (row
->visible_height
<= 0)
919 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
920 PREPARE_FACE_FOR_DISPLAY (f
, face
);
922 /* Decide which bitmap to draw at the left side. */
923 if (row
->overlay_arrow_p
)
924 bitmap
= OVERLAY_ARROW_BITMAP
;
925 else if (row
->truncated_on_left_p
)
926 bitmap
= LEFT_TRUNCATION_BITMAP
;
927 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
928 bitmap
= CONTINUATION_LINE_BITMAP
;
929 else if (row
->indicate_empty_line_p
)
930 bitmap
= ZV_LINE_BITMAP
;
934 /* Clear flags area if no bitmap to draw or if bitmap doesn't fill
936 if (bitmap
== NO_BITMAP
937 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
938 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
940 /* If W has a vertical border to its left, don't draw over it. */
941 int border
= ((XFASTINT (w
->left
) > 0
942 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
944 int left
= window_box_left (w
, -1);
946 if (header_line_height
< 0)
947 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
949 /* In case the same realized face is used for bitmap areas and
950 for something displayed in the text (e.g. face `region' on
951 mono-displays, the fill style may have been changed to
952 FillSolid in x_draw_glyph_string_background. */
954 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
956 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
958 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
961 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
963 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
965 FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - border
,
966 row
->visible_height
);
968 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
971 /* Draw the left bitmap. */
972 if (bitmap
!= NO_BITMAP
)
973 x_draw_bitmap (w
, row
, bitmap
);
975 /* Decide which bitmap to draw at the right side. */
976 if (row
->truncated_on_right_p
)
977 bitmap
= RIGHT_TRUNCATION_BITMAP
;
978 else if (row
->continued_p
)
979 bitmap
= CONTINUED_LINE_BITMAP
;
983 /* Clear flags area if no bitmap to draw of if bitmap doesn't fill
985 if (bitmap
== NO_BITMAP
986 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
)
987 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
989 int right
= window_box_right (w
, -1);
991 if (header_line_height
< 0)
992 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
994 /* In case the same realized face is used for bitmap areas and
995 for something displayed in the text (e.g. face `region' on
996 mono-displays, the fill style may have been changed to
997 FillSolid in x_draw_glyph_string_background. */
999 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
1001 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
1002 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1005 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
1007 FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
),
1008 row
->visible_height
);
1010 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
1013 /* Draw the right bitmap. */
1014 if (bitmap
!= NO_BITMAP
)
1015 x_draw_bitmap (w
, row
, bitmap
);
1019 /***********************************************************************
1021 ***********************************************************************/
1023 /* External interface to control of standout mode. Not used for X
1024 frames. Aborts when called. */
1027 XTreassert_line_highlight (new, vpos
)
1034 /* Call this when about to modify line at position VPOS and change
1035 whether it is highlighted. Not used for X frames. Aborts when
1039 x_change_line_highlight (new_highlight
, vpos
, y
, first_unused_hpos
)
1040 int new_highlight
, vpos
, y
, first_unused_hpos
;
1046 /* This is called when starting Emacs and when restarting after
1047 suspend. When starting Emacs, no X window is mapped. And nothing
1048 must be done to Emacs's own window if it is suspended (though that
1052 XTset_terminal_modes ()
1056 /* This is called when exiting or suspending Emacs. Exiting will make
1057 the X-windows go away, and suspending requires no action. */
1060 XTreset_terminal_modes ()
1066 /***********************************************************************
1068 ***********************************************************************/
1070 /* Set the global variable output_cursor to CURSOR. All cursor
1071 positions are relative to updated_window. */
1074 set_output_cursor (cursor
)
1075 struct cursor_pos
*cursor
;
1077 output_cursor
.hpos
= cursor
->hpos
;
1078 output_cursor
.vpos
= cursor
->vpos
;
1079 output_cursor
.x
= cursor
->x
;
1080 output_cursor
.y
= cursor
->y
;
1084 /* Set a nominal cursor position.
1086 HPOS and VPOS are column/row positions in a window glyph matrix. X
1087 and Y are window text area relative pixel positions.
1089 If this is done during an update, updated_window will contain the
1090 window that is being updated and the position is the future output
1091 cursor position for that window. If updated_window is null, use
1092 selected_window and display the cursor at the given position. */
1095 XTcursor_to (vpos
, hpos
, y
, x
)
1096 int vpos
, hpos
, y
, x
;
1100 /* If updated_window is not set, work on selected_window. */
1104 w
= XWINDOW (selected_window
);
1106 /* Set the output cursor. */
1107 output_cursor
.hpos
= hpos
;
1108 output_cursor
.vpos
= vpos
;
1109 output_cursor
.x
= x
;
1110 output_cursor
.y
= y
;
1112 /* If not called as part of an update, really display the cursor.
1113 This will also set the cursor position of W. */
1114 if (updated_window
== NULL
)
1117 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
1118 XFlush (FRAME_X_DISPLAY (SELECTED_FRAME ()));
1125 /***********************************************************************
1127 ***********************************************************************/
1129 /* Function prototypes of this page. */
1131 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
1135 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
1136 int, XChar2b
*, int));
1137 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
1138 static void x_encode_char
P_ ((int, XChar2b
*, struct font_info
*));
1139 static void x_append_glyph
P_ ((struct it
*));
1140 static void x_append_composite_glyph
P_ ((struct it
*));
1141 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
1143 static void x_produce_glyphs
P_ ((struct it
*));
1144 static void x_produce_image_glyph
P_ ((struct it
*it
));
1147 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
1148 is not contained in the font. */
1150 static INLINE XCharStruct
*
1151 x_per_char_metric (font
, char2b
)
1155 /* The result metric information. */
1156 XCharStruct
*pcm
= NULL
;
1158 xassert (font
&& char2b
);
1160 if (font
->per_char
!= NULL
)
1162 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
1164 /* min_char_or_byte2 specifies the linear character index
1165 corresponding to the first element of the per_char array,
1166 max_char_or_byte2 is the index of the last character. A
1167 character with non-zero CHAR2B->byte1 is not in the font.
1168 A character with byte2 less than min_char_or_byte2 or
1169 greater max_char_or_byte2 is not in the font. */
1170 if (char2b
->byte1
== 0
1171 && char2b
->byte2
>= font
->min_char_or_byte2
1172 && char2b
->byte2
<= font
->max_char_or_byte2
)
1173 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
1177 /* If either min_byte1 or max_byte1 are nonzero, both
1178 min_char_or_byte2 and max_char_or_byte2 are less than
1179 256, and the 2-byte character index values corresponding
1180 to the per_char array element N (counting from 0) are:
1182 byte1 = N/D + min_byte1
1183 byte2 = N\D + min_char_or_byte2
1187 D = max_char_or_byte2 - min_char_or_byte2 + 1
1188 / = integer division
1189 \ = integer modulus */
1190 if (char2b
->byte1
>= font
->min_byte1
1191 && char2b
->byte1
<= font
->max_byte1
1192 && char2b
->byte2
>= font
->min_char_or_byte2
1193 && char2b
->byte2
<= font
->max_char_or_byte2
)
1195 pcm
= (font
->per_char
1196 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
1197 * (char2b
->byte1
- font
->min_byte1
))
1198 + (char2b
->byte2
- font
->min_char_or_byte2
));
1204 /* If the per_char pointer is null, all glyphs between the first
1205 and last character indexes inclusive have the same
1206 information, as given by both min_bounds and max_bounds. */
1207 if (char2b
->byte2
>= font
->min_char_or_byte2
1208 && char2b
->byte2
<= font
->max_char_or_byte2
)
1209 pcm
= &font
->max_bounds
;
1212 return ((pcm
== NULL
1213 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
1218 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1219 the two-byte form of C. Encoding is returned in *CHAR2B. */
1222 x_encode_char (c
, char2b
, font_info
)
1225 struct font_info
*font_info
;
1227 int charset
= CHAR_CHARSET (c
);
1228 XFontStruct
*font
= font_info
->font
;
1230 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1231 This may be either a program in a special encoder language or a
1233 if (font_info
->font_encoder
)
1235 /* It's a program. */
1236 struct ccl_program
*ccl
= font_info
->font_encoder
;
1238 if (CHARSET_DIMENSION (charset
) == 1)
1240 ccl
->reg
[0] = charset
;
1241 ccl
->reg
[1] = char2b
->byte2
;
1245 ccl
->reg
[0] = charset
;
1246 ccl
->reg
[1] = char2b
->byte1
;
1247 ccl
->reg
[2] = char2b
->byte2
;
1250 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1252 /* We assume that MSBs are appropriately set/reset by CCL
1254 if (font
->max_byte1
== 0) /* 1-byte font */
1255 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
1257 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
1259 else if (font_info
->encoding
[charset
])
1261 /* Fixed encoding scheme. See fontset.h for the meaning of the
1262 encoding numbers. */
1263 int enc
= font_info
->encoding
[charset
];
1265 if ((enc
== 1 || enc
== 2)
1266 && CHARSET_DIMENSION (charset
) == 2)
1267 char2b
->byte1
|= 0x80;
1269 if (enc
== 1 || enc
== 3)
1270 char2b
->byte2
|= 0x80;
1275 /* Get face and two-byte form of character C in face FACE_ID on frame
1276 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1277 means we want to display multibyte text. Value is a pointer to a
1278 realized face that is ready for display. */
1280 static INLINE
struct face
*
1281 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
)
1287 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1291 /* Unibyte case. We don't have to encode, but we have to make
1292 sure to use a face suitable for unibyte. */
1295 face_id
= FACE_FOR_CHAR (f
, face
, c
);
1296 face
= FACE_FROM_ID (f
, face_id
);
1298 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1300 /* Case of ASCII in a face known to fit ASCII. */
1306 int c1
, c2
, charset
;
1308 /* Split characters into bytes. If c2 is -1 afterwards, C is
1309 really a one-byte character so that byte1 is zero. */
1310 SPLIT_CHAR (c
, charset
, c1
, c2
);
1312 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1314 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1316 /* Maybe encode the character in *CHAR2B. */
1317 if (face
->font
!= NULL
)
1319 struct font_info
*font_info
1320 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1322 x_encode_char (c
, char2b
, font_info
);
1326 /* Make sure X resources of the face are allocated. */
1327 xassert (face
!= NULL
);
1328 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1334 /* Get face and two-byte form of character glyph GLYPH on frame F.
1335 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
1336 a pointer to a realized face that is ready for display. */
1338 static INLINE
struct face
*
1339 x_get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
1341 struct glyph
*glyph
;
1347 xassert (glyph
->type
== CHAR_GLYPH
);
1348 face
= FACE_FROM_ID (f
, glyph
->face_id
);
1353 if (!glyph
->multibyte_p
)
1355 /* Unibyte case. We don't have to encode, but we have to make
1356 sure to use a face suitable for unibyte. */
1358 char2b
->byte2
= glyph
->u
.ch
;
1360 else if (glyph
->u
.ch
< 128
1361 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
1363 /* Case of ASCII in a face known to fit ASCII. */
1365 char2b
->byte2
= glyph
->u
.ch
;
1369 int c1
, c2
, charset
;
1371 /* Split characters into bytes. If c2 is -1 afterwards, C is
1372 really a one-byte character so that byte1 is zero. */
1373 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
1375 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1377 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1379 /* Maybe encode the character in *CHAR2B. */
1380 if (charset
!= CHARSET_ASCII
)
1382 struct font_info
*font_info
1383 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1386 x_encode_char (glyph
->u
.ch
, char2b
, font_info
);
1389 = ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
1394 /* Make sure X resources of the face are allocated. */
1395 xassert (face
!= NULL
);
1396 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1401 /* Store one glyph for IT->char_to_display in IT->glyph_row.
1402 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1408 struct glyph
*glyph
;
1409 enum glyph_row_area area
= it
->area
;
1411 xassert (it
->glyph_row
);
1412 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
1414 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1415 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1417 glyph
->charpos
= CHARPOS (it
->position
);
1418 glyph
->object
= it
->object
;
1419 glyph
->pixel_width
= it
->pixel_width
;
1420 glyph
->voffset
= it
->voffset
;
1421 glyph
->type
= CHAR_GLYPH
;
1422 glyph
->multibyte_p
= it
->multibyte_p
;
1423 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1424 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1425 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1426 || it
->phys_descent
> it
->descent
);
1427 glyph
->padding_p
= 0;
1428 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
1429 glyph
->face_id
= it
->face_id
;
1430 glyph
->u
.ch
= it
->char_to_display
;
1431 ++it
->glyph_row
->used
[area
];
1435 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
1436 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1439 x_append_composite_glyph (it
)
1442 struct glyph
*glyph
;
1443 enum glyph_row_area area
= it
->area
;
1445 xassert (it
->glyph_row
);
1447 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1448 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1450 glyph
->charpos
= CHARPOS (it
->position
);
1451 glyph
->object
= it
->object
;
1452 glyph
->pixel_width
= it
->pixel_width
;
1453 glyph
->voffset
= it
->voffset
;
1454 glyph
->type
= COMPOSITE_GLYPH
;
1455 glyph
->multibyte_p
= it
->multibyte_p
;
1456 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1457 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1458 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1459 || it
->phys_descent
> it
->descent
);
1460 glyph
->padding_p
= 0;
1461 glyph
->glyph_not_available_p
= 0;
1462 glyph
->face_id
= it
->face_id
;
1463 glyph
->u
.cmp_id
= it
->cmp_id
;
1464 ++it
->glyph_row
->used
[area
];
1469 /* Change IT->ascent and IT->height according to the setting of
1473 take_vertical_position_into_account (it
)
1478 if (it
->voffset
< 0)
1479 /* Increase the ascent so that we can display the text higher
1481 it
->ascent
+= abs (it
->voffset
);
1483 /* Increase the descent so that we can display the text lower
1485 it
->descent
+= it
->voffset
;
1490 /* Produce glyphs/get display metrics for the image IT is loaded with.
1491 See the description of struct display_iterator in dispextern.h for
1492 an overview of struct display_iterator. */
1495 x_produce_image_glyph (it
)
1501 xassert (it
->what
== IT_IMAGE
);
1503 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1504 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
1507 /* Make sure X resources of the face and image are loaded. */
1508 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1509 prepare_image_for_display (it
->f
, img
);
1511 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
1512 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->vmargin
- it
->ascent
;
1513 it
->pixel_width
= img
->width
+ 2 * img
->hmargin
;
1517 if (face
->box
!= FACE_NO_BOX
)
1519 it
->ascent
+= face
->box_line_width
;
1520 it
->descent
+= face
->box_line_width
;
1522 if (it
->start_of_box_run_p
)
1523 it
->pixel_width
+= face
->box_line_width
;
1524 if (it
->end_of_box_run_p
)
1525 it
->pixel_width
+= face
->box_line_width
;
1528 take_vertical_position_into_account (it
);
1532 struct glyph
*glyph
;
1533 enum glyph_row_area area
= it
->area
;
1535 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1536 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1538 glyph
->charpos
= CHARPOS (it
->position
);
1539 glyph
->object
= it
->object
;
1540 glyph
->pixel_width
= it
->pixel_width
;
1541 glyph
->voffset
= it
->voffset
;
1542 glyph
->type
= IMAGE_GLYPH
;
1543 glyph
->multibyte_p
= it
->multibyte_p
;
1544 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1545 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1546 glyph
->overlaps_vertically_p
= 0;
1547 glyph
->padding_p
= 0;
1548 glyph
->glyph_not_available_p
= 0;
1549 glyph
->face_id
= it
->face_id
;
1550 glyph
->u
.img_id
= img
->id
;
1551 ++it
->glyph_row
->used
[area
];
1557 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
1558 of the glyph, WIDTH and HEIGHT are the width and height of the
1559 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
1560 ascent of the glyph (0 <= ASCENT <= 1). */
1563 x_append_stretch_glyph (it
, object
, width
, height
, ascent
)
1569 struct glyph
*glyph
;
1570 enum glyph_row_area area
= it
->area
;
1572 xassert (ascent
>= 0 && ascent
<= 1);
1574 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1575 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1577 glyph
->charpos
= CHARPOS (it
->position
);
1578 glyph
->object
= object
;
1579 glyph
->pixel_width
= width
;
1580 glyph
->voffset
= it
->voffset
;
1581 glyph
->type
= STRETCH_GLYPH
;
1582 glyph
->multibyte_p
= it
->multibyte_p
;
1583 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1584 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1585 glyph
->overlaps_vertically_p
= 0;
1586 glyph
->padding_p
= 0;
1587 glyph
->glyph_not_available_p
= 0;
1588 glyph
->face_id
= it
->face_id
;
1589 glyph
->u
.stretch
.ascent
= height
* ascent
;
1590 glyph
->u
.stretch
.height
= height
;
1591 ++it
->glyph_row
->used
[area
];
1596 /* Produce a stretch glyph for iterator IT. IT->object is the value
1597 of the glyph property displayed. The value must be a list
1598 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1601 1. `:width WIDTH' specifies that the space should be WIDTH *
1602 canonical char width wide. WIDTH may be an integer or floating
1605 2. `:relative-width FACTOR' specifies that the width of the stretch
1606 should be computed from the width of the first character having the
1607 `glyph' property, and should be FACTOR times that width.
1609 3. `:align-to HPOS' specifies that the space should be wide enough
1610 to reach HPOS, a value in canonical character units.
1612 Exactly one of the above pairs must be present.
1614 4. `:height HEIGHT' specifies that the height of the stretch produced
1615 should be HEIGHT, measured in canonical character units.
1617 5. `:relative-height FACTOR' specifies that the height of the the
1618 stretch should be FACTOR times the height of the characters having
1621 Either none or exactly one of 4 or 5 must be present.
1623 6. `:ascent ASCENT' specifies that ASCENT percent of the height
1624 of the stretch should be used for the ascent of the stretch.
1625 ASCENT must be in the range 0 <= ASCENT <= 100. */
1628 ((INTEGERP (X) || FLOATP (X)) \
1634 x_produce_stretch_glyph (it
)
1637 /* (space :width WIDTH :height HEIGHT. */
1639 extern Lisp_Object Qspace
;
1641 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
1642 extern Lisp_Object QCrelative_width
, QCrelative_height
;
1643 extern Lisp_Object QCalign_to
;
1644 Lisp_Object prop
, plist
;
1645 double width
= 0, height
= 0, ascent
= 0;
1646 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1647 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
1649 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1651 /* List should start with `space'. */
1652 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1653 plist
= XCDR (it
->object
);
1655 /* Compute the width of the stretch. */
1656 if (prop
= Fplist_get (plist
, QCwidth
),
1658 /* Absolute width `:width WIDTH' specified and valid. */
1659 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
1660 else if (prop
= Fplist_get (plist
, QCrelative_width
),
1663 /* Relative width `:relative-width FACTOR' specified and valid.
1664 Compute the width of the characters having the `glyph'
1667 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
1670 if (it
->multibyte_p
)
1672 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
1673 - IT_BYTEPOS (*it
));
1674 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
1677 it2
.c
= *p
, it2
.len
= 1;
1679 it2
.glyph_row
= NULL
;
1680 it2
.what
= IT_CHARACTER
;
1681 x_produce_glyphs (&it2
);
1682 width
= NUMVAL (prop
) * it2
.pixel_width
;
1684 else if (prop
= Fplist_get (plist
, QCalign_to
),
1686 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
1688 /* Nothing specified -> width defaults to canonical char width. */
1689 width
= CANON_X_UNIT (it
->f
);
1691 /* Compute height. */
1692 if (prop
= Fplist_get (plist
, QCheight
),
1694 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
1695 else if (prop
= Fplist_get (plist
, QCrelative_height
),
1697 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
1699 height
= FONT_HEIGHT (font
);
1701 /* Compute percentage of height used for ascent. If
1702 `:ascent ASCENT' is present and valid, use that. Otherwise,
1703 derive the ascent from the font in use. */
1704 if (prop
= Fplist_get (plist
, QCascent
),
1705 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
1706 ascent
= NUMVAL (prop
) / 100.0;
1708 ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1717 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1718 if (!STRINGP (object
))
1719 object
= it
->w
->buffer
;
1720 x_append_stretch_glyph (it
, object
, width
, height
, ascent
);
1723 it
->pixel_width
= width
;
1724 it
->ascent
= it
->phys_ascent
= height
* ascent
;
1725 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
1728 if (face
->box
!= FACE_NO_BOX
)
1730 it
->ascent
+= face
->box_line_width
;
1731 it
->descent
+= face
->box_line_width
;
1733 if (it
->start_of_box_run_p
)
1734 it
->pixel_width
+= face
->box_line_width
;
1735 if (it
->end_of_box_run_p
)
1736 it
->pixel_width
+= face
->box_line_width
;
1739 take_vertical_position_into_account (it
);
1742 /* Return proper value to be used as baseline offset of font that has
1743 ASCENT and DESCENT to draw characters by the font at the vertical
1744 center of the line of frame F.
1746 Here, out task is to find the value of BOFF in the following figure;
1748 -------------------------+-----------+-
1749 -+-+---------+-+ | |
1751 | | | | F_ASCENT F_HEIGHT
1754 | | |-|-+------+-----------|------- baseline
1756 | |---------|-+-+ | |
1758 -+-+---------+-+ F_DESCENT |
1759 -------------------------+-----------+-
1761 -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
1762 BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
1763 DESCENT = FONT->descent
1764 HEIGHT = FONT_HEIGHT (FONT)
1765 F_DESCENT = (F->output_data.x->font->descent
1766 - F->output_data.x->baseline_offset)
1767 F_HEIGHT = FRAME_LINE_HEIGHT (F)
1770 #define VCENTER_BASELINE_OFFSET(FONT, F) \
1772 + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT)) \
1773 + (FRAME_LINE_HEIGHT ((F)) > FONT_HEIGHT ((FONT)))) / 2 \
1774 - ((F)->output_data.x->font->descent - (F)->output_data.x->baseline_offset))
1776 /* Produce glyphs/get display metrics for the display element IT is
1777 loaded with. See the description of struct display_iterator in
1778 dispextern.h for an overview of struct display_iterator. */
1781 x_produce_glyphs (it
)
1784 it
->glyph_not_available_p
= 0;
1786 if (it
->what
== IT_CHARACTER
)
1790 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1792 int font_not_found_p
;
1793 struct font_info
*font_info
;
1794 int boff
; /* baseline offset */
1795 /* We may change it->multibyte_p upon unibyte<->multibyte
1796 conversion. So, save the current value now and restore it
1799 Note: It seems that we don't have to record multibyte_p in
1800 struct glyph because the character code itself tells if or
1801 not the character is multibyte. Thus, in the future, we must
1802 consider eliminating the field `multibyte_p' in the struct
1805 int saved_multibyte_p
= it
->multibyte_p
;
1807 /* Maybe translate single-byte characters to multibyte, or the
1809 it
->char_to_display
= it
->c
;
1810 if (!ASCII_BYTE_P (it
->c
))
1812 if (unibyte_display_via_language_environment
1813 && SINGLE_BYTE_CHAR_P (it
->c
)
1815 || !NILP (Vnonascii_translation_table
)))
1817 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
1818 it
->multibyte_p
= 1;
1819 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1820 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1822 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
1823 && !it
->multibyte_p
)
1825 it
->char_to_display
= multibyte_char_to_unibyte (it
->c
, Qnil
);
1826 it
->multibyte_p
= 0;
1827 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1828 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1832 /* Get font to use. Encode IT->char_to_display. */
1833 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
1834 it
->face_id
, &char2b
,
1838 /* When no suitable font found, use the default font. */
1839 font_not_found_p
= font
== NULL
;
1840 if (font_not_found_p
)
1842 font
= FRAME_FONT (it
->f
);
1843 boff
= it
->f
->output_data
.x
->baseline_offset
;
1848 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
1849 boff
= font_info
->baseline_offset
;
1850 if (font_info
->vertical_centering
)
1851 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
1854 if (it
->char_to_display
>= ' '
1855 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
1857 /* Either unibyte or ASCII. */
1862 pcm
= x_per_char_metric (font
, &char2b
);
1863 it
->ascent
= font
->ascent
+ boff
;
1864 it
->descent
= font
->descent
- boff
;
1868 it
->phys_ascent
= pcm
->ascent
+ boff
;
1869 it
->phys_descent
= pcm
->descent
- boff
;
1870 it
->pixel_width
= pcm
->width
;
1874 it
->glyph_not_available_p
= 1;
1875 it
->phys_ascent
= font
->ascent
+ boff
;
1876 it
->phys_descent
= font
->descent
- boff
;
1877 it
->pixel_width
= FONT_WIDTH (font
);
1880 /* If this is a space inside a region of text with
1881 `space-width' property, change its width. */
1882 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
1884 it
->pixel_width
*= XFLOATINT (it
->space_width
);
1886 /* If face has a box, add the box thickness to the character
1887 height. If character has a box line to the left and/or
1888 right, add the box line width to the character's width. */
1889 if (face
->box
!= FACE_NO_BOX
)
1891 int thick
= face
->box_line_width
;
1893 it
->ascent
+= thick
;
1894 it
->descent
+= thick
;
1896 if (it
->start_of_box_run_p
)
1897 it
->pixel_width
+= thick
;
1898 if (it
->end_of_box_run_p
)
1899 it
->pixel_width
+= thick
;
1902 /* If face has an overline, add the height of the overline
1903 (1 pixel) and a 1 pixel margin to the character height. */
1904 if (face
->overline_p
)
1907 take_vertical_position_into_account (it
);
1909 /* If we have to actually produce glyphs, do it. */
1914 /* Translate a space with a `space-width' property
1915 into a stretch glyph. */
1916 double ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1917 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1918 it
->ascent
+ it
->descent
, ascent
);
1921 x_append_glyph (it
);
1923 /* If characters with lbearing or rbearing are displayed
1924 in this line, record that fact in a flag of the
1925 glyph row. This is used to optimize X output code. */
1926 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
1927 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1930 else if (it
->char_to_display
== '\n')
1932 /* A newline has no width but we need the height of the line. */
1933 it
->pixel_width
= 0;
1935 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1936 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1938 if (face
->box
!= FACE_NO_BOX
)
1940 int thick
= face
->box_line_width
;
1941 it
->ascent
+= thick
;
1942 it
->descent
+= thick
;
1945 else if (it
->char_to_display
== '\t')
1947 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
1948 int x
= it
->current_x
+ it
->continuation_lines_width
;
1949 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
1951 /* If the distance from the current position to the next tab
1952 stop is less than a canonical character width, use the
1953 tab stop after that. */
1954 if (next_tab_x
- x
< CANON_X_UNIT (it
->f
))
1955 next_tab_x
+= tab_width
;
1957 it
->pixel_width
= next_tab_x
- x
;
1959 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1960 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1964 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
1965 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1966 it
->ascent
+ it
->descent
, ascent
);
1971 /* A multi-byte character. Assume that the display width of the
1972 character is the width of the character multiplied by the
1973 width of the font. */
1975 /* If we found a font, this font should give us the right
1976 metrics. If we didn't find a font, use the frame's
1977 default font and calculate the width of the character
1978 from the charset width; this is what old redisplay code
1980 pcm
= x_per_char_metric (font
, &char2b
);
1981 if (font_not_found_p
|| !pcm
)
1983 int charset
= CHAR_CHARSET (it
->char_to_display
);
1985 it
->glyph_not_available_p
= 1;
1986 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
1987 * CHARSET_WIDTH (charset
));
1988 it
->phys_ascent
= font
->ascent
+ boff
;
1989 it
->phys_descent
= font
->descent
- boff
;
1993 it
->pixel_width
= pcm
->width
;
1994 it
->phys_ascent
= pcm
->ascent
+ boff
;
1995 it
->phys_descent
= pcm
->descent
- boff
;
1997 && (pcm
->lbearing
< 0
1998 || pcm
->rbearing
> pcm
->width
))
1999 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
2002 it
->ascent
= font
->ascent
+ boff
;
2003 it
->descent
= font
->descent
- boff
;
2004 if (face
->box
!= FACE_NO_BOX
)
2006 int thick
= face
->box_line_width
;
2007 it
->ascent
+= thick
;
2008 it
->descent
+= thick
;
2010 if (it
->start_of_box_run_p
)
2011 it
->pixel_width
+= thick
;
2012 if (it
->end_of_box_run_p
)
2013 it
->pixel_width
+= thick
;
2016 /* If face has an overline, add the height of the overline
2017 (1 pixel) and a 1 pixel margin to the character height. */
2018 if (face
->overline_p
)
2021 take_vertical_position_into_account (it
);
2024 x_append_glyph (it
);
2026 it
->multibyte_p
= saved_multibyte_p
;
2028 else if (it
->what
== IT_COMPOSITION
)
2030 /* Note: A composition is represented as one glyph in the
2031 glyph matrix. There are no padding glyphs. */
2034 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2036 int font_not_found_p
;
2037 struct font_info
*font_info
;
2038 int boff
; /* baseline offset */
2039 struct composition
*cmp
= composition_table
[it
->cmp_id
];
2041 /* Maybe translate single-byte characters to multibyte. */
2042 it
->char_to_display
= it
->c
;
2043 if (unibyte_display_via_language_environment
2044 && SINGLE_BYTE_CHAR_P (it
->c
)
2047 && !NILP (Vnonascii_translation_table
))))
2049 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2052 /* Get face and font to use. Encode IT->char_to_display. */
2053 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2054 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2055 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2056 it
->face_id
, &char2b
, it
->multibyte_p
);
2059 /* When no suitable font found, use the default font. */
2060 font_not_found_p
= font
== NULL
;
2061 if (font_not_found_p
)
2063 font
= FRAME_FONT (it
->f
);
2064 boff
= it
->f
->output_data
.x
->baseline_offset
;
2069 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2070 boff
= font_info
->baseline_offset
;
2071 if (font_info
->vertical_centering
)
2072 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2075 /* There are no padding glyphs, so there is only one glyph to
2076 produce for the composition. Important is that pixel_width,
2077 ascent and descent are the values of what is drawn by
2078 draw_glyphs (i.e. the values of the overall glyphs composed). */
2081 /* If we have not yet calculated pixel size data of glyphs of
2082 the composition for the current face font, calculate them
2083 now. Theoretically, we have to check all fonts for the
2084 glyphs, but that requires much time and memory space. So,
2085 here we check only the font of the first glyph. This leads
2086 to incorrect display very rarely, and C-l (recenter) can
2087 correct the display anyway. */
2088 if (cmp
->font
!= (void *) font
)
2090 /* Ascent and descent of the font of the first character of
2091 this composition (adjusted by baseline offset). Ascent
2092 and descent of overall glyphs should not be less than
2093 them respectively. */
2094 int font_ascent
= font
->ascent
+ boff
;
2095 int font_descent
= font
->descent
- boff
;
2096 /* Bounding box of the overall glyphs. */
2097 int leftmost
, rightmost
, lowest
, highest
;
2098 int i
, width
, ascent
, descent
;
2100 cmp
->font
= (void *) font
;
2102 /* Initialize the bounding box. */
2104 && (pcm
= x_per_char_metric (font
, &char2b
)))
2107 ascent
= pcm
->ascent
;
2108 descent
= pcm
->descent
;
2112 width
= FONT_WIDTH (font
);
2113 ascent
= font
->ascent
;
2114 descent
= font
->descent
;
2118 lowest
= - descent
+ boff
;
2119 highest
= ascent
+ boff
;
2123 && font_info
->default_ascent
2124 && CHAR_TABLE_P (Vuse_default_ascent
)
2125 && !NILP (Faref (Vuse_default_ascent
,
2126 make_number (it
->char_to_display
))))
2127 highest
= font_info
->default_ascent
+ boff
;
2129 /* Draw the first glyph at the normal position. It may be
2130 shifted to right later if some other glyphs are drawn at
2132 cmp
->offsets
[0] = 0;
2133 cmp
->offsets
[1] = boff
;
2135 /* Set cmp->offsets for the remaining glyphs. */
2136 for (i
= 1; i
< cmp
->glyph_len
; i
++)
2138 int left
, right
, btm
, top
;
2139 int ch
= COMPOSITION_GLYPH (cmp
, i
);
2140 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
2142 face
= FACE_FROM_ID (it
->f
, face_id
);
2143 x_get_char_face_and_encoding (it
->f
, ch
, face
->id
, &char2b
,
2148 font
= FRAME_FONT (it
->f
);
2149 boff
= it
->f
->output_data
.x
->baseline_offset
;
2155 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2156 boff
= font_info
->baseline_offset
;
2157 if (font_info
->vertical_centering
)
2158 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2162 && (pcm
= x_per_char_metric (font
, &char2b
)))
2165 ascent
= pcm
->ascent
;
2166 descent
= pcm
->descent
;
2170 width
= FONT_WIDTH (font
);
2175 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
2177 /* Relative composition with or without
2179 left
= (leftmost
+ rightmost
- width
) / 2;
2180 btm
= - descent
+ boff
;
2181 if (font_info
&& font_info
->relative_compose
2182 && (! CHAR_TABLE_P (Vignore_relative_composition
)
2183 || NILP (Faref (Vignore_relative_composition
,
2184 make_number (ch
)))))
2187 if (- descent
>= font_info
->relative_compose
)
2188 /* One extra pixel between two glyphs. */
2190 else if (ascent
<= 0)
2191 /* One extra pixel between two glyphs. */
2192 btm
= lowest
- 1 - ascent
- descent
;
2197 /* A composition rule is specified by an integer
2198 value that encodes global and new reference
2199 points (GREF and NREF). GREF and NREF are
2200 specified by numbers as below:
2208 ---3---4---5--- baseline
2210 6---7---8 -- descent
2212 int rule
= COMPOSITION_RULE (cmp
, i
);
2213 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
2215 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
2216 grefx
= gref
% 3, nrefx
= nref
% 3;
2217 grefy
= gref
/ 3, nrefy
= nref
/ 3;
2220 + grefx
* (rightmost
- leftmost
) / 2
2221 - nrefx
* width
/ 2);
2222 btm
= ((grefy
== 0 ? highest
2224 : grefy
== 2 ? lowest
2225 : (highest
+ lowest
) / 2)
2226 - (nrefy
== 0 ? ascent
+ descent
2227 : nrefy
== 1 ? descent
- boff
2229 : (ascent
+ descent
) / 2));
2232 cmp
->offsets
[i
* 2] = left
;
2233 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
2235 /* Update the bounding box of the overall glyphs. */
2236 right
= left
+ width
;
2237 top
= btm
+ descent
+ ascent
;
2238 if (left
< leftmost
)
2240 if (right
> rightmost
)
2248 /* If there are glyphs whose x-offsets are negative,
2249 shift all glyphs to the right and make all x-offsets
2253 for (i
= 0; i
< cmp
->glyph_len
; i
++)
2254 cmp
->offsets
[i
* 2] -= leftmost
;
2255 rightmost
-= leftmost
;
2258 cmp
->pixel_width
= rightmost
;
2259 cmp
->ascent
= highest
;
2260 cmp
->descent
= - lowest
;
2261 if (cmp
->ascent
< font_ascent
)
2262 cmp
->ascent
= font_ascent
;
2263 if (cmp
->descent
< font_descent
)
2264 cmp
->descent
= font_descent
;
2267 it
->pixel_width
= cmp
->pixel_width
;
2268 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
2269 it
->descent
= it
->phys_descent
= cmp
->descent
;
2271 if (face
->box
!= FACE_NO_BOX
)
2273 int thick
= face
->box_line_width
;
2274 it
->ascent
+= thick
;
2275 it
->descent
+= thick
;
2277 if (it
->start_of_box_run_p
)
2278 it
->pixel_width
+= thick
;
2279 if (it
->end_of_box_run_p
)
2280 it
->pixel_width
+= thick
;
2283 /* If face has an overline, add the height of the overline
2284 (1 pixel) and a 1 pixel margin to the character height. */
2285 if (face
->overline_p
)
2288 take_vertical_position_into_account (it
);
2291 x_append_composite_glyph (it
);
2293 else if (it
->what
== IT_IMAGE
)
2294 x_produce_image_glyph (it
);
2295 else if (it
->what
== IT_STRETCH
)
2296 x_produce_stretch_glyph (it
);
2298 /* Accumulate dimensions. Note: can't assume that it->descent > 0
2299 because this isn't true for images with `:ascent 100'. */
2300 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
2301 if (it
->area
== TEXT_AREA
)
2302 it
->current_x
+= it
->pixel_width
;
2304 it
->descent
+= it
->extra_line_spacing
;
2306 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
2307 it
->max_descent
= max (it
->max_descent
, it
->descent
);
2308 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
2309 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
2313 /* Estimate the pixel height of the mode or top line on frame F.
2314 FACE_ID specifies what line's height to estimate. */
2317 x_estimate_mode_line_height (f
, face_id
)
2319 enum face_id face_id
;
2321 int height
= FONT_HEIGHT (FRAME_FONT (f
));
2323 /* This function is called so early when Emacs starts that the face
2324 cache and mode line face are not yet initialized. */
2325 if (FRAME_FACE_CACHE (f
))
2327 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2331 height
= FONT_HEIGHT (face
->font
);
2332 height
+= 2 * face
->box_line_width
;
2340 /***********************************************************************
2342 ***********************************************************************/
2344 /* A sequence of glyphs to be drawn in the same face.
2346 This data structure is not really completely X specific, so it
2347 could possibly, at least partially, be useful for other systems. It
2348 is currently not part of the external redisplay interface because
2349 it's not clear what other systems will need. */
2353 /* X-origin of the string. */
2356 /* Y-origin and y-position of the base line of this string. */
2359 /* The width of the string, not including a face extension. */
2362 /* The width of the string, including a face extension. */
2363 int background_width
;
2365 /* The height of this string. This is the height of the line this
2366 string is drawn in, and can be different from the height of the
2367 font the string is drawn in. */
2370 /* Number of pixels this string overwrites in front of its x-origin.
2371 This number is zero if the string has an lbearing >= 0; it is
2372 -lbearing, if the string has an lbearing < 0. */
2375 /* Number of pixels this string overwrites past its right-most
2376 nominal x-position, i.e. x + width. Zero if the string's
2377 rbearing is <= its nominal width, rbearing - width otherwise. */
2380 /* The frame on which the glyph string is drawn. */
2383 /* The window on which the glyph string is drawn. */
2386 /* X display and window for convenience. */
2390 /* The glyph row for which this string was built. It determines the
2391 y-origin and height of the string. */
2392 struct glyph_row
*row
;
2394 /* The area within row. */
2395 enum glyph_row_area area
;
2397 /* Characters to be drawn, and number of characters. */
2401 /* A face-override for drawing cursors, mouse face and similar. */
2402 enum draw_glyphs_face hl
;
2404 /* Face in which this string is to be drawn. */
2407 /* Font in which this string is to be drawn. */
2410 /* Font info for this string. */
2411 struct font_info
*font_info
;
2413 /* Non-null means this string describes (part of) a composition.
2414 All characters from char2b are drawn composed. */
2415 struct composition
*cmp
;
2417 /* Index of this glyph string's first character in the glyph
2418 definition of CMP. If this is zero, this glyph string describes
2419 the first character of a composition. */
2422 /* 1 means this glyph strings face has to be drawn to the right end
2423 of the window's drawing area. */
2424 unsigned extends_to_end_of_line_p
: 1;
2426 /* 1 means the background of this string has been drawn. */
2427 unsigned background_filled_p
: 1;
2429 /* 1 means glyph string must be drawn with 16-bit functions. */
2430 unsigned two_byte_p
: 1;
2432 /* 1 means that the original font determined for drawing this glyph
2433 string could not be loaded. The member `font' has been set to
2434 the frame's default font in this case. */
2435 unsigned font_not_found_p
: 1;
2437 /* 1 means that the face in which this glyph string is drawn has a
2439 unsigned stippled_p
: 1;
2441 /* 1 means only the foreground of this glyph string must be drawn,
2442 and we should use the physical height of the line this glyph
2443 string appears in as clip rect. */
2444 unsigned for_overlaps_p
: 1;
2446 /* The GC to use for drawing this glyph string. */
2449 /* A pointer to the first glyph in the string. This glyph
2450 corresponds to char2b[0]. Needed to draw rectangles if
2451 font_not_found_p is 1. */
2452 struct glyph
*first_glyph
;
2454 /* Image, if any. */
2457 struct glyph_string
*next
, *prev
;
2464 x_dump_glyph_string (s
)
2465 struct glyph_string
*s
;
2467 fprintf (stderr
, "glyph string\n");
2468 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
2469 s
->x
, s
->y
, s
->width
, s
->height
);
2470 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
2471 fprintf (stderr
, " hl = %d\n", s
->hl
);
2472 fprintf (stderr
, " left overhang = %d, right = %d\n",
2473 s
->left_overhang
, s
->right_overhang
);
2474 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
2475 fprintf (stderr
, " extends to end of line = %d\n",
2476 s
->extends_to_end_of_line_p
);
2477 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
2478 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
2481 #endif /* GLYPH_DEBUG */
2485 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
2486 struct glyph_string
**,
2487 struct glyph_string
*,
2488 struct glyph_string
*));
2489 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
2490 struct glyph_string
**,
2491 struct glyph_string
*,
2492 struct glyph_string
*));
2493 static void x_append_glyph_string
P_ ((struct glyph_string
**,
2494 struct glyph_string
**,
2495 struct glyph_string
*));
2496 static int x_left_overwritten
P_ ((struct glyph_string
*));
2497 static int x_left_overwriting
P_ ((struct glyph_string
*));
2498 static int x_right_overwritten
P_ ((struct glyph_string
*));
2499 static int x_right_overwriting
P_ ((struct glyph_string
*));
2500 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
2502 static void x_init_glyph_string
P_ ((struct glyph_string
*,
2503 XChar2b
*, struct window
*,
2505 enum glyph_row_area
, int,
2506 enum draw_glyphs_face
));
2507 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
2508 enum glyph_row_area
, int, int,
2509 enum draw_glyphs_face
, int *, int *, int));
2510 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2511 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2512 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2514 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2515 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2516 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2517 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2518 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2519 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2520 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2521 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2522 static void x_get_glyph_overhangs
P_ ((struct glyph
*, struct frame
*,
2524 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
2525 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
2526 unsigned long *, double, int));
2527 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2528 double, int, unsigned long));
2529 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2530 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2531 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2532 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2533 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
2534 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
2535 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2537 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2538 int, int, int, int, XRectangle
*));
2539 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2540 int, int, int, XRectangle
*));
2541 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
2542 enum glyph_row_area
));
2543 static int x_fill_stretch_glyph_string
P_ ((struct glyph_string
*,
2545 enum glyph_row_area
, int, int));
2548 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
2552 /* Append the list of glyph strings with head H and tail T to the list
2553 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
2556 x_append_glyph_string_lists (head
, tail
, h
, t
)
2557 struct glyph_string
**head
, **tail
;
2558 struct glyph_string
*h
, *t
;
2572 /* Prepend the list of glyph strings with head H and tail T to the
2573 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
2577 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
2578 struct glyph_string
**head
, **tail
;
2579 struct glyph_string
*h
, *t
;
2593 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
2594 Set *HEAD and *TAIL to the resulting list. */
2597 x_append_glyph_string (head
, tail
, s
)
2598 struct glyph_string
**head
, **tail
;
2599 struct glyph_string
*s
;
2601 s
->next
= s
->prev
= NULL
;
2602 x_append_glyph_string_lists (head
, tail
, s
, s
);
2606 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2611 struct glyph_string
*s
;
2613 if (s
->font
== FRAME_FONT (s
->f
)
2614 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2615 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2617 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
2620 /* Cursor on non-default face: must merge. */
2624 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
2625 xgcv
.foreground
= s
->face
->background
;
2627 /* If the glyph would be invisible, try a different foreground. */
2628 if (xgcv
.foreground
== xgcv
.background
)
2629 xgcv
.foreground
= s
->face
->foreground
;
2630 if (xgcv
.foreground
== xgcv
.background
)
2631 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
2632 if (xgcv
.foreground
== xgcv
.background
)
2633 xgcv
.foreground
= s
->face
->foreground
;
2635 /* Make sure the cursor is distinct from text in this face. */
2636 if (xgcv
.background
== s
->face
->background
2637 && xgcv
.foreground
== s
->face
->foreground
)
2639 xgcv
.background
= s
->face
->foreground
;
2640 xgcv
.foreground
= s
->face
->background
;
2643 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2644 xgcv
.font
= s
->font
->fid
;
2645 xgcv
.graphics_exposures
= False
;
2646 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2648 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2649 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2652 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2653 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2655 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2660 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2663 x_set_mouse_face_gc (s
)
2664 struct glyph_string
*s
;
2669 /* What face has to be used last for the mouse face? */
2670 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2671 face
= FACE_FROM_ID (s
->f
, face_id
);
2673 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
2675 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2676 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2678 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2679 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2680 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2682 /* If font in this face is same as S->font, use it. */
2683 if (s
->font
== s
->face
->font
)
2684 s
->gc
= s
->face
->gc
;
2687 /* Otherwise construct scratch_cursor_gc with values from FACE
2692 xgcv
.background
= s
->face
->background
;
2693 xgcv
.foreground
= s
->face
->foreground
;
2694 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2695 xgcv
.font
= s
->font
->fid
;
2696 xgcv
.graphics_exposures
= False
;
2697 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2699 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2700 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2703 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2704 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2706 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2709 xassert (s
->gc
!= 0);
2713 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2714 Faces to use in the mode line have already been computed when the
2715 matrix was built, so there isn't much to do, here. */
2718 x_set_mode_line_face_gc (s
)
2719 struct glyph_string
*s
;
2721 s
->gc
= s
->face
->gc
;
2725 /* Set S->gc of glyph string S for drawing that glyph string. Set
2726 S->stippled_p to a non-zero value if the face of S has a stipple
2730 x_set_glyph_string_gc (s
)
2731 struct glyph_string
*s
;
2733 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2735 if (s
->hl
== DRAW_NORMAL_TEXT
)
2737 s
->gc
= s
->face
->gc
;
2738 s
->stippled_p
= s
->face
->stipple
!= 0;
2740 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2742 x_set_mode_line_face_gc (s
);
2743 s
->stippled_p
= s
->face
->stipple
!= 0;
2745 else if (s
->hl
== DRAW_CURSOR
)
2747 x_set_cursor_gc (s
);
2750 else if (s
->hl
== DRAW_MOUSE_FACE
)
2752 x_set_mouse_face_gc (s
);
2753 s
->stippled_p
= s
->face
->stipple
!= 0;
2755 else if (s
->hl
== DRAW_IMAGE_RAISED
2756 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2758 s
->gc
= s
->face
->gc
;
2759 s
->stippled_p
= s
->face
->stipple
!= 0;
2763 s
->gc
= s
->face
->gc
;
2764 s
->stippled_p
= s
->face
->stipple
!= 0;
2767 /* GC must have been set. */
2768 xassert (s
->gc
!= 0);
2772 /* Return in *R the clipping rectangle for glyph string S. */
2775 x_get_glyph_string_clip_rect (s
, r
)
2776 struct glyph_string
*s
;
2779 if (s
->row
->full_width_p
)
2781 /* Draw full-width. X coordinates are relative to S->w->left. */
2782 int canon_x
= CANON_X_UNIT (s
->f
);
2784 r
->x
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
2785 r
->width
= XFASTINT (s
->w
->width
) * canon_x
;
2787 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
2789 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
2790 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
2794 r
->x
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
2796 /* Unless displaying a mode or menu bar line, which are always
2797 fully visible, clip to the visible part of the row. */
2798 if (s
->w
->pseudo_window_p
)
2799 r
->height
= s
->row
->visible_height
;
2801 r
->height
= s
->height
;
2805 /* This is a text line that may be partially visible. */
2806 r
->x
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
2807 r
->width
= window_box_width (s
->w
, s
->area
);
2808 r
->height
= s
->row
->visible_height
;
2811 /* Don't use S->y for clipping because it doesn't take partially
2812 visible lines into account. For example, it can be negative for
2813 partially visible lines at the top of a window. */
2814 if (!s
->row
->full_width_p
2815 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2816 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2818 r
->y
= max (0, s
->row
->y
);
2820 /* If drawing a tool-bar window, draw it over the internal border
2821 at the top of the window. */
2822 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
2823 r
->y
-= s
->f
->output_data
.x
->internal_border_width
;
2825 /* If S draws overlapping rows, it's sufficient to use the top and
2826 bottom of the window for clipping because this glyph string
2827 intentionally draws over other lines. */
2828 if (s
->for_overlaps_p
)
2830 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2831 r
->height
= window_text_bottom_y (s
->w
) - r
->y
;
2834 r
->y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->y
);
2838 /* Set clipping for output of glyph string S. S may be part of a mode
2839 line or menu if we don't have X toolkit support. */
2842 x_set_glyph_string_clipping (s
)
2843 struct glyph_string
*s
;
2846 x_get_glyph_string_clip_rect (s
, &r
);
2847 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
2851 /* Compute left and right overhang of glyph string S. If S is a glyph
2852 string for a composition, assume overhangs don't exist. */
2855 x_compute_glyph_string_overhangs (s
)
2856 struct glyph_string
*s
;
2859 && s
->first_glyph
->type
== CHAR_GLYPH
)
2862 int direction
, font_ascent
, font_descent
;
2863 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
2864 &font_ascent
, &font_descent
, &cs
);
2865 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
2866 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
2871 /* Compute overhangs and x-positions for glyph string S and its
2872 predecessors, or successors. X is the starting x-position for S.
2873 BACKWARD_P non-zero means process predecessors. */
2876 x_compute_overhangs_and_x (s
, x
, backward_p
)
2877 struct glyph_string
*s
;
2885 x_compute_glyph_string_overhangs (s
);
2895 x_compute_glyph_string_overhangs (s
);
2904 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
2905 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
2906 assumed to be zero. */
2909 x_get_glyph_overhangs (glyph
, f
, left
, right
)
2910 struct glyph
*glyph
;
2916 if (glyph
->type
== CHAR_GLYPH
)
2920 struct font_info
*font_info
;
2924 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
2926 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
2928 && (pcm
= x_per_char_metric (font
, &char2b
)))
2930 if (pcm
->rbearing
> pcm
->width
)
2931 *right
= pcm
->rbearing
- pcm
->width
;
2932 if (pcm
->lbearing
< 0)
2933 *left
= -pcm
->lbearing
;
2939 /* Return the index of the first glyph preceding glyph string S that
2940 is overwritten by S because of S's left overhang. Value is -1
2941 if no glyphs are overwritten. */
2944 x_left_overwritten (s
)
2945 struct glyph_string
*s
;
2949 if (s
->left_overhang
)
2952 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2953 int first
= s
->first_glyph
- glyphs
;
2955 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
2956 x
-= glyphs
[i
].pixel_width
;
2967 /* Return the index of the first glyph preceding glyph string S that
2968 is overwriting S because of its right overhang. Value is -1 if no
2969 glyph in front of S overwrites S. */
2972 x_left_overwriting (s
)
2973 struct glyph_string
*s
;
2976 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2977 int first
= s
->first_glyph
- glyphs
;
2981 for (i
= first
- 1; i
>= 0; --i
)
2984 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
2987 x
-= glyphs
[i
].pixel_width
;
2994 /* Return the index of the last glyph following glyph string S that is
2995 not overwritten by S because of S's right overhang. Value is -1 if
2996 no such glyph is found. */
2999 x_right_overwritten (s
)
3000 struct glyph_string
*s
;
3004 if (s
->right_overhang
)
3007 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3008 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3009 int end
= s
->row
->used
[s
->area
];
3011 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
3012 x
+= glyphs
[i
].pixel_width
;
3021 /* Return the index of the last glyph following glyph string S that
3022 overwrites S because of its left overhang. Value is negative
3023 if no such glyph is found. */
3026 x_right_overwriting (s
)
3027 struct glyph_string
*s
;
3030 int end
= s
->row
->used
[s
->area
];
3031 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3032 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3036 for (i
= first
; i
< end
; ++i
)
3039 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3042 x
+= glyphs
[i
].pixel_width
;
3049 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
3052 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
3053 struct glyph_string
*s
;
3057 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
3058 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3059 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3060 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3064 /* Draw the background of glyph_string S. If S->background_filled_p
3065 is non-zero don't draw it. FORCE_P non-zero means draw the
3066 background even if it wouldn't be drawn normally. This is used
3067 when a string preceding S draws into the background of S, or S
3068 contains the first component of a composition. */
3071 x_draw_glyph_string_background (s
, force_p
)
3072 struct glyph_string
*s
;
3075 /* Nothing to do if background has already been drawn or if it
3076 shouldn't be drawn in the first place. */
3077 if (!s
->background_filled_p
)
3081 /* Fill background with a stipple pattern. */
3082 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3083 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
3084 s
->y
+ s
->face
->box_line_width
,
3085 s
->background_width
,
3086 s
->height
- 2 * s
->face
->box_line_width
);
3087 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3088 s
->background_filled_p
= 1;
3090 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * s
->face
->box_line_width
3091 || s
->font_not_found_p
3092 || s
->extends_to_end_of_line_p
3095 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ s
->face
->box_line_width
,
3096 s
->background_width
,
3097 s
->height
- 2 * s
->face
->box_line_width
);
3098 s
->background_filled_p
= 1;
3104 /* Draw the foreground of glyph string S. */
3107 x_draw_glyph_string_foreground (s
)
3108 struct glyph_string
*s
;
3112 /* If first glyph of S has a left box line, start drawing the text
3113 of S to the right of that box line. */
3114 if (s
->face
->box
!= FACE_NO_BOX
3115 && s
->first_glyph
->left_box_line_p
)
3116 x
= s
->x
+ s
->face
->box_line_width
;
3120 /* Draw characters of S as rectangles if S's font could not be
3122 if (s
->font_not_found_p
)
3124 for (i
= 0; i
< s
->nchars
; ++i
)
3126 struct glyph
*g
= s
->first_glyph
+ i
;
3127 XDrawRectangle (s
->display
, s
->window
,
3128 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
3130 x
+= g
->pixel_width
;
3135 char *char1b
= (char *) s
->char2b
;
3136 int boff
= s
->font_info
->baseline_offset
;
3138 if (s
->font_info
->vertical_centering
)
3139 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
3141 /* If we can use 8-bit functions, condense S->char2b. */
3143 for (i
= 0; i
< s
->nchars
; ++i
)
3144 char1b
[i
] = s
->char2b
[i
].byte2
;
3146 /* Draw text with XDrawString if background has already been
3147 filled. Otherwise, use XDrawImageString. (Note that
3148 XDrawImageString is usually faster than XDrawString.) Always
3149 use XDrawImageString when drawing the cursor so that there is
3150 no chance that characters under a box cursor are invisible. */
3151 if (s
->for_overlaps_p
3152 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
3154 /* Draw characters with 16-bit or 8-bit functions. */
3156 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
3157 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3159 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
3160 s
->ybase
- boff
, char1b
, s
->nchars
);
3165 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
3166 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3168 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
3169 s
->ybase
- boff
, char1b
, s
->nchars
);
3174 /* Draw the foreground of composite glyph string S. */
3177 x_draw_composite_glyph_string_foreground (s
)
3178 struct glyph_string
*s
;
3182 /* If first glyph of S has a left box line, start drawing the text
3183 of S to the right of that box line. */
3184 if (s
->face
->box
!= FACE_NO_BOX
3185 && s
->first_glyph
->left_box_line_p
)
3186 x
= s
->x
+ s
->face
->box_line_width
;
3190 /* S is a glyph string for a composition. S->gidx is the index of
3191 the first character drawn for glyphs of this composition.
3192 S->gidx == 0 means we are drawing the very first character of
3193 this composition. */
3195 /* Draw a rectangle for the composition if the font for the very
3196 first character of the composition could not be loaded. */
3197 if (s
->font_not_found_p
)
3200 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
3201 s
->width
- 1, s
->height
- 1);
3205 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3206 XDrawString16 (s
->display
, s
->window
, s
->gc
,
3207 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3208 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3214 #ifdef USE_X_TOOLKIT
3216 static struct frame
*x_frame_of_widget
P_ ((Widget
));
3219 /* Return the frame on which widget WIDGET is used.. Abort if frame
3220 cannot be determined. */
3222 static struct frame
*
3223 x_frame_of_widget (widget
)
3226 struct x_display_info
*dpyinfo
;
3230 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
3232 /* Find the top-level shell of the widget. Note that this function
3233 can be called when the widget is not yet realized, so XtWindow
3234 (widget) == 0. That's the reason we can't simply use
3235 x_any_window_to_frame. */
3236 while (!XtIsTopLevelShell (widget
))
3237 widget
= XtParent (widget
);
3239 /* Look for a frame with that top-level widget. Allocate the color
3240 on that frame to get the right gamma correction value. */
3241 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
3242 if (GC_FRAMEP (XCAR (tail
))
3243 && (f
= XFRAME (XCAR (tail
)),
3244 (f
->output_data
.nothing
!= 1
3245 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
3246 && f
->output_data
.x
->widget
== widget
)
3253 /* Allocate the color COLOR->pixel on the screen and display of
3254 widget WIDGET in colormap CMAP. If an exact match cannot be
3255 allocated, try the nearest color available. Value is non-zero
3256 if successful. This is called from lwlib. */
3259 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
3264 struct frame
*f
= x_frame_of_widget (widget
);
3265 return x_alloc_nearest_color (f
, cmap
, color
);
3269 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3270 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3271 If this produces the same color as PIXEL, try a color where all RGB
3272 values have DELTA added. Return the allocated color in *PIXEL.
3273 DISPLAY is the X display, CMAP is the colormap to operate on.
3274 Value is non-zero if successful. */
3277 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
3281 unsigned long *pixel
;
3285 struct frame
*f
= x_frame_of_widget (widget
);
3286 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
3290 #endif /* USE_X_TOOLKIT */
3293 /* Value is an array of XColor structures for the contents of the
3294 color map of frame F. Set *NCELLS to the size of the array.
3295 Note that this probably shouldn't be called for large color maps,
3296 say a 24-bit TrueColor map. */
3298 static const XColor
*
3299 x_color_cells (f
, ncells
)
3303 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3305 if (dpyinfo
->color_cells
== NULL
)
3307 Display
*display
= FRAME_X_DISPLAY (f
);
3308 Screen
*screen
= FRAME_X_SCREEN (f
);
3311 dpyinfo
->ncolor_cells
3312 = XDisplayCells (display
, XScreenNumberOfScreen (screen
));
3313 dpyinfo
->color_cells
3314 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
3315 * sizeof *dpyinfo
->color_cells
);
3317 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
3318 dpyinfo
->color_cells
[i
].pixel
= i
;
3320 XQueryColors (display
, FRAME_X_COLORMAP (f
),
3321 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
3324 *ncells
= dpyinfo
->ncolor_cells
;
3325 return dpyinfo
->color_cells
;
3329 /* On frame F, translate pixel colors to RGB values for the NCOLORS
3330 colors in COLORS. Use cached information, if available. */
3333 x_query_colors (f
, colors
, ncolors
)
3338 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3340 if (dpyinfo
->color_cells
)
3343 for (i
= 0; i
< ncolors
; ++i
)
3345 unsigned long pixel
= colors
[i
].pixel
;
3346 xassert (pixel
< dpyinfo
->ncolor_cells
);
3347 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
3348 colors
[i
] = dpyinfo
->color_cells
[pixel
];
3352 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
3356 /* On frame F, translate pixel color to RGB values for the color in
3357 COLOR. Use cached information, if available. */
3360 x_query_color (f
, color
)
3364 x_query_colors (f
, color
, 1);
3368 /* Allocate the color COLOR->pixel on SCREEN of DISPLAY, colormap
3369 CMAP. If an exact match can't be allocated, try the nearest color
3370 available. Value is non-zero if successful. Set *COLOR to the
3374 x_alloc_nearest_color (f
, cmap
, color
)
3379 Display
*display
= FRAME_X_DISPLAY (f
);
3380 Screen
*screen
= FRAME_X_SCREEN (f
);
3383 gamma_correct (f
, color
);
3384 rc
= XAllocColor (display
, cmap
, color
);
3387 /* If we got to this point, the colormap is full, so we're going
3388 to try to get the next closest color. The algorithm used is
3389 a least-squares matching, which is what X uses for closest
3390 color matching with StaticColor visuals. */
3392 unsigned long nearest_delta
= ~0;
3394 const XColor
*cells
= x_color_cells (f
, &ncells
);
3396 for (nearest
= i
= 0; i
< ncells
; ++i
)
3398 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
3399 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
3400 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
3401 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
3403 if (delta
< nearest_delta
)
3406 nearest_delta
= delta
;
3410 color
->red
= cells
[nearest
].red
;
3411 color
->green
= cells
[nearest
].green
;
3412 color
->blue
= cells
[nearest
].blue
;
3413 rc
= XAllocColor (display
, cmap
, color
);
3417 /* If allocation succeeded, and the allocated pixel color is not
3418 equal to a cached pixel color recorded earlier, there was a
3419 change in the colormap, so clear the color cache. */
3420 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3421 XColor
*cached_color
;
3423 if (dpyinfo
->color_cells
3424 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
3425 (cached_color
->red
!= color
->red
3426 || cached_color
->blue
!= color
->blue
3427 || cached_color
->green
!= color
->green
)))
3429 xfree (dpyinfo
->color_cells
);
3430 dpyinfo
->color_cells
= NULL
;
3431 dpyinfo
->ncolor_cells
= 0;
3435 #ifdef DEBUG_X_COLORS
3437 register_color (color
->pixel
);
3438 #endif /* DEBUG_X_COLORS */
3444 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
3445 It's necessary to do this instead of just using PIXEL directly to
3446 get color reference counts right. */
3449 x_copy_color (f
, pixel
)
3451 unsigned long pixel
;
3455 color
.pixel
= pixel
;
3457 x_query_color (f
, &color
);
3458 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3460 #ifdef DEBUG_X_COLORS
3461 register_color (pixel
);
3467 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
3468 It's necessary to do this instead of just using PIXEL directly to
3469 get color reference counts right. */
3472 x_copy_dpy_color (dpy
, cmap
, pixel
)
3475 unsigned long pixel
;
3479 color
.pixel
= pixel
;
3481 XQueryColor (dpy
, cmap
, &color
);
3482 XAllocColor (dpy
, cmap
, &color
);
3484 #ifdef DEBUG_X_COLORS
3485 register_color (pixel
);
3491 /* Brightness beyond which a color won't have its highlight brightness
3494 Nominally, highlight colors for `3d' faces are calculated by
3495 brightening an object's color by a constant scale factor, but this
3496 doesn't yield good results for dark colors, so for colors who's
3497 brightness is less than this value (on a scale of 0-65535) have an
3498 use an additional additive factor.
3500 The value here is set so that the default menu-bar/mode-line color
3501 (grey75) will not have its highlights changed at all. */
3502 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
3505 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3506 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3507 If this produces the same color as PIXEL, try a color where all RGB
3508 values have DELTA added. Return the allocated color in *PIXEL.
3509 DISPLAY is the X display, CMAP is the colormap to operate on.
3510 Value is non-zero if successful. */
3513 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
3517 unsigned long *pixel
;
3525 /* Get RGB color values. */
3526 color
.pixel
= *pixel
;
3527 x_query_color (f
, &color
);
3529 /* Change RGB values by specified FACTOR. Avoid overflow! */
3530 xassert (factor
>= 0);
3531 new.red
= min (0xffff, factor
* color
.red
);
3532 new.green
= min (0xffff, factor
* color
.green
);
3533 new.blue
= min (0xffff, factor
* color
.blue
);
3535 /* Calculate brightness of COLOR. */
3536 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
3538 /* We only boost colors that are darker than
3539 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
3540 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
3541 /* Make an additive adjustment to NEW, because it's dark enough so
3542 that scaling by FACTOR alone isn't enough. */
3544 /* How far below the limit this color is (0 - 1, 1 being darker). */
3545 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
3546 /* The additive adjustment. */
3547 int min_delta
= delta
* dimness
* factor
/ 2;
3551 new.red
= max (0, new.red
- min_delta
);
3552 new.green
= max (0, new.green
- min_delta
);
3553 new.blue
= max (0, new.blue
- min_delta
);
3557 new.red
= min (0xffff, min_delta
+ new.red
);
3558 new.green
= min (0xffff, min_delta
+ new.green
);
3559 new.blue
= min (0xffff, min_delta
+ new.blue
);
3563 /* Try to allocate the color. */
3564 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3567 if (new.pixel
== *pixel
)
3569 /* If we end up with the same color as before, try adding
3570 delta to the RGB values. */
3571 x_free_colors (f
, &new.pixel
, 1);
3573 new.red
= min (0xffff, delta
+ color
.red
);
3574 new.green
= min (0xffff, delta
+ color
.green
);
3575 new.blue
= min (0xffff, delta
+ color
.blue
);
3576 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3587 /* Set up the foreground color for drawing relief lines of glyph
3588 string S. RELIEF is a pointer to a struct relief containing the GC
3589 with which lines will be drawn. Use a color that is FACTOR or
3590 DELTA lighter or darker than the relief's background which is found
3591 in S->f->output_data.x->relief_background. If such a color cannot
3592 be allocated, use DEFAULT_PIXEL, instead. */
3595 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3597 struct relief
*relief
;
3600 unsigned long default_pixel
;
3603 struct x_output
*di
= f
->output_data
.x
;
3604 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
3605 unsigned long pixel
;
3606 unsigned long background
= di
->relief_background
;
3607 Colormap cmap
= FRAME_X_COLORMAP (f
);
3608 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3609 Display
*dpy
= FRAME_X_DISPLAY (f
);
3611 xgcv
.graphics_exposures
= False
;
3612 xgcv
.line_width
= 1;
3614 /* Free previously allocated color. The color cell will be reused
3615 when it has been freed as many times as it was allocated, so this
3616 doesn't affect faces using the same colors. */
3618 && relief
->allocated_p
)
3620 x_free_colors (f
, &relief
->pixel
, 1);
3621 relief
->allocated_p
= 0;
3624 /* Allocate new color. */
3625 xgcv
.foreground
= default_pixel
;
3627 if (dpyinfo
->n_planes
!= 1
3628 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
3630 relief
->allocated_p
= 1;
3631 xgcv
.foreground
= relief
->pixel
= pixel
;
3634 if (relief
->gc
== 0)
3636 xgcv
.stipple
= dpyinfo
->gray
;
3638 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
3641 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
3645 /* Set up colors for the relief lines around glyph string S. */
3648 x_setup_relief_colors (s
)
3649 struct glyph_string
*s
;
3651 struct x_output
*di
= s
->f
->output_data
.x
;
3652 unsigned long color
;
3654 if (s
->face
->use_box_color_for_shadows_p
)
3655 color
= s
->face
->box_color
;
3660 /* Get the background color of the face. */
3661 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3662 color
= xgcv
.background
;
3665 if (di
->white_relief
.gc
== 0
3666 || color
!= di
->relief_background
)
3668 di
->relief_background
= color
;
3669 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3670 WHITE_PIX_DEFAULT (s
->f
));
3671 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3672 BLACK_PIX_DEFAULT (s
->f
));
3677 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3678 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3679 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3680 relief. LEFT_P non-zero means draw a relief on the left side of
3681 the rectangle. RIGHT_P non-zero means draw a relief on the right
3682 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3686 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3687 raised_p
, left_p
, right_p
, clip_rect
)
3689 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
3690 XRectangle
*clip_rect
;
3696 gc
= f
->output_data
.x
->white_relief
.gc
;
3698 gc
= f
->output_data
.x
->black_relief
.gc
;
3699 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3702 for (i
= 0; i
< width
; ++i
)
3703 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3704 left_x
+ i
* left_p
, top_y
+ i
,
3705 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3709 for (i
= 0; i
< width
; ++i
)
3710 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3711 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
);
3713 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3715 gc
= f
->output_data
.x
->black_relief
.gc
;
3717 gc
= f
->output_data
.x
->white_relief
.gc
;
3718 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3721 for (i
= 0; i
< width
; ++i
)
3722 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3723 left_x
+ i
* left_p
, bottom_y
- i
,
3724 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3728 for (i
= 0; i
< width
; ++i
)
3729 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3730 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3732 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3736 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3737 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3738 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3739 left side of the rectangle. RIGHT_P non-zero means draw a line
3740 on the right side of the rectangle. CLIP_RECT is the clipping
3741 rectangle to use when drawing. */
3744 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3745 left_p
, right_p
, clip_rect
)
3746 struct glyph_string
*s
;
3747 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
;
3748 XRectangle
*clip_rect
;
3752 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3753 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
3754 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
3757 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3758 left_x
, top_y
, right_x
- left_x
+ 1, width
);
3762 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3763 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
3766 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3767 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
3771 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3772 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
3774 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3775 XSetClipMask (s
->display
, s
->gc
, None
);
3779 /* Draw a box around glyph string S. */
3782 x_draw_glyph_string_box (s
)
3783 struct glyph_string
*s
;
3785 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3786 int left_p
, right_p
;
3787 struct glyph
*last_glyph
;
3788 XRectangle clip_rect
;
3790 last_x
= window_box_right (s
->w
, s
->area
);
3791 if (s
->row
->full_width_p
3792 && !s
->w
->pseudo_window_p
)
3794 last_x
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (s
->f
);
3795 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
3796 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
3799 /* The glyph that may have a right box line. */
3800 last_glyph
= (s
->cmp
|| s
->img
3802 : s
->first_glyph
+ s
->nchars
- 1);
3804 width
= s
->face
->box_line_width
;
3805 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
3807 right_x
= ((s
->row
->full_width_p
3809 : min (last_x
, s
->x
+ s
->background_width
) - 1));
3811 bottom_y
= top_y
+ s
->height
- 1;
3813 left_p
= (s
->first_glyph
->left_box_line_p
3814 || (s
->hl
== DRAW_MOUSE_FACE
3816 || s
->prev
->hl
!= s
->hl
)));
3817 right_p
= (last_glyph
->right_box_line_p
3818 || (s
->hl
== DRAW_MOUSE_FACE
3820 || s
->next
->hl
!= s
->hl
)));
3822 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3824 if (s
->face
->box
== FACE_SIMPLE_BOX
)
3825 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3826 left_p
, right_p
, &clip_rect
);
3829 x_setup_relief_colors (s
);
3830 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
3831 width
, raised_p
, left_p
, right_p
, &clip_rect
);
3836 /* Draw foreground of image glyph string S. */
3839 x_draw_image_foreground (s
)
3840 struct glyph_string
*s
;
3843 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3845 /* If first glyph of S has a left box line, start drawing it to the
3846 right of that line. */
3847 if (s
->face
->box
!= FACE_NO_BOX
3848 && s
->first_glyph
->left_box_line_p
)
3849 x
= s
->x
+ s
->face
->box_line_width
;
3853 /* If there is a margin around the image, adjust x- and y-position
3855 x
+= s
->img
->hmargin
;
3856 y
+= s
->img
->vmargin
;
3862 /* We can't set both a clip mask and use XSetClipRectangles
3863 because the latter also sets a clip mask. We also can't
3864 trust on the shape extension to be available
3865 (XShapeCombineRegion). So, compute the rectangle to draw
3867 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3870 XRectangle clip_rect
, image_rect
, r
;
3872 xgcv
.clip_mask
= s
->img
->mask
;
3873 xgcv
.clip_x_origin
= x
;
3874 xgcv
.clip_y_origin
= y
;
3875 xgcv
.function
= GXcopy
;
3876 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3878 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3881 image_rect
.width
= s
->img
->width
;
3882 image_rect
.height
= s
->img
->height
;
3883 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
3884 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3885 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3889 unsigned long mask
= GCClipXOrigin
| GCClipYOrigin
| GCFunction
;
3891 XRectangle clip_rect
, image_rect
, r
;
3893 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3896 image_rect
.width
= s
->img
->width
;
3897 image_rect
.height
= s
->img
->height
;
3898 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
3899 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3900 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3902 /* When the image has a mask, we can expect that at
3903 least part of a mouse highlight or a block cursor will
3904 be visible. If the image doesn't have a mask, make
3905 a block cursor visible by drawing a rectangle around
3906 the image. I believe it's looking better if we do
3907 nothing here for mouse-face. */
3908 if (s
->hl
== DRAW_CURSOR
)
3909 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3910 s
->img
->width
- 1, s
->img
->height
- 1);
3914 /* Draw a rectangle if image could not be loaded. */
3915 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3916 s
->img
->width
- 1, s
->img
->height
- 1);
3920 /* Draw a relief around the image glyph string S. */
3923 x_draw_image_relief (s
)
3924 struct glyph_string
*s
;
3926 int x0
, y0
, x1
, y1
, thick
, raised_p
;
3929 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3931 /* If first glyph of S has a left box line, start drawing it to the
3932 right of that line. */
3933 if (s
->face
->box
!= FACE_NO_BOX
3934 && s
->first_glyph
->left_box_line_p
)
3935 x
= s
->x
+ s
->face
->box_line_width
;
3939 /* If there is a margin around the image, adjust x- and y-position
3941 x
+= s
->img
->hmargin
;
3942 y
+= s
->img
->vmargin
;
3944 if (s
->hl
== DRAW_IMAGE_SUNKEN
3945 || s
->hl
== DRAW_IMAGE_RAISED
)
3947 thick
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
3948 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
3952 thick
= abs (s
->img
->relief
);
3953 raised_p
= s
->img
->relief
> 0;
3958 x1
= x
+ s
->img
->width
+ thick
- 1;
3959 y1
= y
+ s
->img
->height
+ thick
- 1;
3961 x_setup_relief_colors (s
);
3962 x_get_glyph_string_clip_rect (s
, &r
);
3963 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
3967 /* Draw the foreground of image glyph string S to PIXMAP. */
3970 x_draw_image_foreground_1 (s
, pixmap
)
3971 struct glyph_string
*s
;
3975 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
3977 /* If first glyph of S has a left box line, start drawing it to the
3978 right of that line. */
3979 if (s
->face
->box
!= FACE_NO_BOX
3980 && s
->first_glyph
->left_box_line_p
)
3981 x
= s
->face
->box_line_width
;
3985 /* If there is a margin around the image, adjust x- and y-position
3987 x
+= s
->img
->hmargin
;
3988 y
+= s
->img
->vmargin
;
3994 /* We can't set both a clip mask and use XSetClipRectangles
3995 because the latter also sets a clip mask. We also can't
3996 trust on the shape extension to be available
3997 (XShapeCombineRegion). So, compute the rectangle to draw
3999 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
4003 xgcv
.clip_mask
= s
->img
->mask
;
4004 xgcv
.clip_x_origin
= x
;
4005 xgcv
.clip_y_origin
= y
;
4006 xgcv
.function
= GXcopy
;
4007 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
4009 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4010 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4011 XSetClipMask (s
->display
, s
->gc
, None
);
4015 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
4016 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
4018 /* When the image has a mask, we can expect that at
4019 least part of a mouse highlight or a block cursor will
4020 be visible. If the image doesn't have a mask, make
4021 a block cursor visible by drawing a rectangle around
4022 the image. I believe it's looking better if we do
4023 nothing here for mouse-face. */
4024 if (s
->hl
== DRAW_CURSOR
)
4025 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
4026 s
->img
->width
- 1, s
->img
->height
- 1);
4030 /* Draw a rectangle if image could not be loaded. */
4031 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
4032 s
->img
->width
- 1, s
->img
->height
- 1);
4036 /* Draw part of the background of glyph string S. X, Y, W, and H
4037 give the rectangle to draw. */
4040 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
4041 struct glyph_string
*s
;
4046 /* Fill background with a stipple pattern. */
4047 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4048 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
4049 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4052 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
4056 /* Draw image glyph string S.
4059 s->x +-------------------------
4062 | +-------------------------
4065 | | +-------------------
4071 x_draw_image_glyph_string (s
)
4072 struct glyph_string
*s
;
4075 int box_line_width
= s
->face
->box_line_width
;
4077 Pixmap pixmap
= None
;
4079 height
= s
->height
- 2 * box_line_width
;
4081 /* Fill background with face under the image. Do it only if row is
4082 taller than image or if image has a clip mask to reduce
4084 s
->stippled_p
= s
->face
->stipple
!= 0;
4085 if (height
> s
->img
->height
4089 || s
->img
->pixmap
== 0
4090 || s
->width
!= s
->background_width
)
4092 if (box_line_width
&& s
->first_glyph
->left_box_line_p
)
4093 x
= s
->x
+ box_line_width
;
4097 y
= s
->y
+ box_line_width
;
4101 /* Create a pixmap as large as the glyph string. Fill it
4102 with the background color. Copy the image to it, using
4103 its mask. Copy the temporary pixmap to the display. */
4104 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
4105 int depth
= DefaultDepthOfScreen (screen
);
4107 /* Create a pixmap as large as the glyph string. */
4108 pixmap
= XCreatePixmap (s
->display
, s
->window
,
4109 s
->background_width
,
4112 /* Don't clip in the following because we're working on the
4114 XSetClipMask (s
->display
, s
->gc
, None
);
4116 /* Fill the pixmap with the background color/stipple. */
4119 /* Fill background with a stipple pattern. */
4120 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
4121 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4122 0, 0, s
->background_width
, s
->height
);
4123 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
4128 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
4130 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
4131 XFillRectangle (s
->display
, pixmap
, s
->gc
,
4132 0, 0, s
->background_width
, s
->height
);
4133 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4137 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
4139 s
->background_filled_p
= 1;
4142 /* Draw the foreground. */
4145 x_draw_image_foreground_1 (s
, pixmap
);
4146 x_set_glyph_string_clipping (s
);
4147 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
4148 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
4149 XFreePixmap (s
->display
, pixmap
);
4152 x_draw_image_foreground (s
);
4154 /* If we must draw a relief around the image, do it. */
4156 || s
->hl
== DRAW_IMAGE_RAISED
4157 || s
->hl
== DRAW_IMAGE_SUNKEN
)
4158 x_draw_image_relief (s
);
4162 /* Draw stretch glyph string S. */
4165 x_draw_stretch_glyph_string (s
)
4166 struct glyph_string
*s
;
4168 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4169 s
->stippled_p
= s
->face
->stipple
!= 0;
4171 if (s
->hl
== DRAW_CURSOR
4172 && !x_stretch_cursor_p
)
4174 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
4175 as wide as the stretch glyph. */
4176 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
4179 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
4181 /* Clear rest using the GC of the original non-cursor face. */
4182 if (width
< s
->background_width
)
4184 GC gc
= s
->face
->gc
;
4185 int x
= s
->x
+ width
, y
= s
->y
;
4186 int w
= s
->background_width
- width
, h
= s
->height
;
4189 x_get_glyph_string_clip_rect (s
, &r
);
4190 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
4192 if (s
->face
->stipple
)
4194 /* Fill background with a stipple pattern. */
4195 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
4196 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4197 XSetFillStyle (s
->display
, gc
, FillSolid
);
4202 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
4203 XSetForeground (s
->display
, gc
, xgcv
.background
);
4204 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4205 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
4210 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
4213 s
->background_filled_p
= 1;
4217 /* Draw glyph string S. */
4220 x_draw_glyph_string (s
)
4221 struct glyph_string
*s
;
4223 /* If S draws into the background of its successor, draw the
4224 background of the successor first so that S can draw into it.
4225 This makes S->next use XDrawString instead of XDrawImageString. */
4226 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4228 xassert (s
->next
->img
== NULL
);
4229 x_set_glyph_string_gc (s
->next
);
4230 x_set_glyph_string_clipping (s
->next
);
4231 x_draw_glyph_string_background (s
->next
, 1);
4234 /* Set up S->gc, set clipping and draw S. */
4235 x_set_glyph_string_gc (s
);
4236 x_set_glyph_string_clipping (s
);
4238 switch (s
->first_glyph
->type
)
4241 x_draw_image_glyph_string (s
);
4245 x_draw_stretch_glyph_string (s
);
4249 if (s
->for_overlaps_p
)
4250 s
->background_filled_p
= 1;
4252 x_draw_glyph_string_background (s
, 0);
4253 x_draw_glyph_string_foreground (s
);
4256 case COMPOSITE_GLYPH
:
4257 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4258 s
->background_filled_p
= 1;
4260 x_draw_glyph_string_background (s
, 1);
4261 x_draw_composite_glyph_string_foreground (s
);
4268 if (!s
->for_overlaps_p
)
4270 /* Draw underline. */
4271 if (s
->face
->underline_p
)
4273 unsigned long tem
, h
;
4276 /* Get the underline thickness. Default is 1 pixel. */
4277 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
4280 /* Get the underline position. This is the recommended
4281 vertical offset in pixels from the baseline to the top of
4282 the underline. This is a signed value according to the
4283 specs, and its default is
4285 ROUND ((maximum descent) / 2), with
4286 ROUND(x) = floor (x + 0.5) */
4288 if (XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &tem
))
4289 y
= s
->ybase
+ (long) tem
;
4290 else if (s
->face
->font
)
4291 y
= s
->ybase
+ (s
->face
->font
->max_bounds
.descent
+ 1) / 2;
4295 if (s
->face
->underline_defaulted_p
)
4296 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4297 s
->x
, y
, s
->width
, h
);
4301 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4302 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
4303 XFillRectangle (s
->display
, s
->window
, s
->gc
,
4304 s
->x
, y
, s
->width
, h
);
4305 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4309 /* Draw overline. */
4310 if (s
->face
->overline_p
)
4312 unsigned long dy
= 0, h
= 1;
4314 if (s
->face
->overline_color_defaulted_p
)
4315 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4320 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4321 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
4322 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4324 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4328 /* Draw strike-through. */
4329 if (s
->face
->strike_through_p
)
4331 unsigned long h
= 1;
4332 unsigned long dy
= (s
->height
- h
) / 2;
4334 if (s
->face
->strike_through_color_defaulted_p
)
4335 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4340 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4341 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
4342 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4344 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4349 if (s
->face
->box
!= FACE_NO_BOX
)
4350 x_draw_glyph_string_box (s
);
4353 /* Reset clipping. */
4354 XSetClipMask (s
->display
, s
->gc
, None
);
4358 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4359 struct face
**, int));
4362 /* Fill glyph string S with composition components specified by S->cmp.
4364 FACES is an array of faces for all components of this composition.
4365 S->gidx is the index of the first component for S.
4366 OVERLAPS_P non-zero means S should draw the foreground only, and
4367 use its physical height for clipping.
4369 Value is the index of a component not in S. */
4372 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4373 struct glyph_string
*s
;
4374 struct face
**faces
;
4381 s
->for_overlaps_p
= overlaps_p
;
4383 s
->face
= faces
[s
->gidx
];
4384 s
->font
= s
->face
->font
;
4385 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4387 /* For all glyphs of this composition, starting at the offset
4388 S->gidx, until we reach the end of the definition or encounter a
4389 glyph that requires the different face, add it to S. */
4391 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4394 /* All glyph strings for the same composition has the same width,
4395 i.e. the width set for the first component of the composition. */
4397 s
->width
= s
->first_glyph
->pixel_width
;
4399 /* If the specified font could not be loaded, use the frame's
4400 default font, but record the fact that we couldn't load it in
4401 the glyph string so that we can draw rectangles for the
4402 characters of the glyph string. */
4403 if (s
->font
== NULL
)
4405 s
->font_not_found_p
= 1;
4406 s
->font
= FRAME_FONT (s
->f
);
4409 /* Adjust base line for subscript/superscript text. */
4410 s
->ybase
+= s
->first_glyph
->voffset
;
4412 xassert (s
->face
&& s
->face
->gc
);
4414 /* This glyph string must always be drawn with 16-bit functions. */
4417 return s
->gidx
+ s
->nchars
;
4421 /* Fill glyph string S from a sequence of character glyphs.
4423 FACE_ID is the face id of the string. START is the index of the
4424 first glyph to consider, END is the index of the last + 1.
4425 OVERLAPS_P non-zero means S should draw the foreground only, and
4426 use its physical height for clipping.
4428 Value is the index of the first glyph not in S. */
4431 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4432 struct glyph_string
*s
;
4434 int start
, end
, overlaps_p
;
4436 struct glyph
*glyph
, *last
;
4438 int glyph_not_available_p
;
4440 xassert (s
->f
== XFRAME (s
->w
->frame
));
4441 xassert (s
->nchars
== 0);
4442 xassert (start
>= 0 && end
> start
);
4444 s
->for_overlaps_p
= overlaps_p
,
4445 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4446 last
= s
->row
->glyphs
[s
->area
] + end
;
4447 voffset
= glyph
->voffset
;
4449 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4452 && glyph
->type
== CHAR_GLYPH
4453 && glyph
->voffset
== voffset
4454 /* Same face id implies same font, nowadays. */
4455 && glyph
->face_id
== face_id
4456 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4460 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4461 s
->char2b
+ s
->nchars
,
4463 s
->two_byte_p
= two_byte_p
;
4465 xassert (s
->nchars
<= end
- start
);
4466 s
->width
+= glyph
->pixel_width
;
4470 s
->font
= s
->face
->font
;
4471 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4473 /* If the specified font could not be loaded, use the frame's font,
4474 but record the fact that we couldn't load it in
4475 S->font_not_found_p so that we can draw rectangles for the
4476 characters of the glyph string. */
4477 if (s
->font
== NULL
|| glyph_not_available_p
)
4479 s
->font_not_found_p
= 1;
4480 s
->font
= FRAME_FONT (s
->f
);
4483 /* Adjust base line for subscript/superscript text. */
4484 s
->ybase
+= voffset
;
4486 xassert (s
->face
&& s
->face
->gc
);
4487 return glyph
- s
->row
->glyphs
[s
->area
];
4491 /* Fill glyph string S from image glyph S->first_glyph. */
4494 x_fill_image_glyph_string (s
)
4495 struct glyph_string
*s
;
4497 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4498 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
4500 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4501 s
->font
= s
->face
->font
;
4502 s
->width
= s
->first_glyph
->pixel_width
;
4504 /* Adjust base line for subscript/superscript text. */
4505 s
->ybase
+= s
->first_glyph
->voffset
;
4509 /* Fill glyph string S from a sequence of stretch glyphs.
4511 ROW is the glyph row in which the glyphs are found, AREA is the
4512 area within the row. START is the index of the first glyph to
4513 consider, END is the index of the last + 1.
4515 Value is the index of the first glyph not in S. */
4518 x_fill_stretch_glyph_string (s
, row
, area
, start
, end
)
4519 struct glyph_string
*s
;
4520 struct glyph_row
*row
;
4521 enum glyph_row_area area
;
4524 struct glyph
*glyph
, *last
;
4525 int voffset
, face_id
;
4527 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4529 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4530 last
= s
->row
->glyphs
[s
->area
] + end
;
4531 face_id
= glyph
->face_id
;
4532 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
4533 s
->font
= s
->face
->font
;
4534 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4535 s
->width
= glyph
->pixel_width
;
4536 voffset
= glyph
->voffset
;
4540 && glyph
->type
== STRETCH_GLYPH
4541 && glyph
->voffset
== voffset
4542 && glyph
->face_id
== face_id
);
4544 s
->width
+= glyph
->pixel_width
;
4546 /* Adjust base line for subscript/superscript text. */
4547 s
->ybase
+= voffset
;
4549 xassert (s
->face
&& s
->face
->gc
);
4550 return glyph
- s
->row
->glyphs
[s
->area
];
4554 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4555 of XChar2b structures for S; it can't be allocated in
4556 x_init_glyph_string because it must be allocated via `alloca'. W
4557 is the window on which S is drawn. ROW and AREA are the glyph row
4558 and area within the row from which S is constructed. START is the
4559 index of the first glyph structure covered by S. HL is a
4560 face-override for drawing S. */
4563 x_init_glyph_string (s
, char2b
, w
, row
, area
, start
, hl
)
4564 struct glyph_string
*s
;
4567 struct glyph_row
*row
;
4568 enum glyph_row_area area
;
4570 enum draw_glyphs_face hl
;
4572 bzero (s
, sizeof *s
);
4574 s
->f
= XFRAME (w
->frame
);
4575 s
->display
= FRAME_X_DISPLAY (s
->f
);
4576 s
->window
= FRAME_X_WINDOW (s
->f
);
4581 s
->first_glyph
= row
->glyphs
[area
] + start
;
4582 s
->height
= row
->height
;
4583 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4585 /* Display the internal border below the tool-bar window. */
4586 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4587 s
->y
-= s
->f
->output_data
.x
->internal_border_width
;
4589 s
->ybase
= s
->y
+ row
->ascent
;
4593 /* Set background width of glyph string S. START is the index of the
4594 first glyph following S. LAST_X is the right-most x-position + 1
4595 in the drawing area. */
4598 x_set_glyph_string_background_width (s
, start
, last_x
)
4599 struct glyph_string
*s
;
4603 /* If the face of this glyph string has to be drawn to the end of
4604 the drawing area, set S->extends_to_end_of_line_p. */
4605 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4607 if (start
== s
->row
->used
[s
->area
]
4608 && s
->hl
== DRAW_NORMAL_TEXT
4609 && ((s
->area
== TEXT_AREA
&& s
->row
->fill_line_p
)
4610 || s
->face
->background
!= default_face
->background
4611 || s
->face
->stipple
!= default_face
->stipple
))
4612 s
->extends_to_end_of_line_p
= 1;
4614 /* If S extends its face to the end of the line, set its
4615 background_width to the distance to the right edge of the drawing
4617 if (s
->extends_to_end_of_line_p
)
4618 s
->background_width
= last_x
- s
->x
+ 1;
4620 s
->background_width
= s
->width
;
4624 /* Add a glyph string for a stretch glyph to the list of strings
4625 between HEAD and TAIL. START is the index of the stretch glyph in
4626 row area AREA of glyph row ROW. END is the index of the last glyph
4627 in that glyph row area. X is the current output position assigned
4628 to the new glyph string constructed. HL overrides that face of the
4629 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4630 is the right-most x-position of the drawing area. */
4632 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
4633 and below -- keep them on one line. */
4634 #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4637 s = (struct glyph_string *) alloca (sizeof *s); \
4638 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4639 START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \
4640 x_append_glyph_string (&HEAD, &TAIL, s); \
4646 /* Add a glyph string for an image glyph to the list of strings
4647 between HEAD and TAIL. START is the index of the image glyph in
4648 row area AREA of glyph row ROW. END is the index of the last glyph
4649 in that glyph row area. X is the current output position assigned
4650 to the new glyph string constructed. HL overrides that face of the
4651 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4652 is the right-most x-position of the drawing area. */
4654 #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4657 s = (struct glyph_string *) alloca (sizeof *s); \
4658 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4659 x_fill_image_glyph_string (s); \
4660 x_append_glyph_string (&HEAD, &TAIL, s); \
4667 /* Add a glyph string for a sequence of character glyphs to the list
4668 of strings between HEAD and TAIL. START is the index of the first
4669 glyph in row area AREA of glyph row ROW that is part of the new
4670 glyph string. END is the index of the last glyph in that glyph row
4671 area. X is the current output position assigned to the new glyph
4672 string constructed. HL overrides that face of the glyph; e.g. it
4673 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4674 right-most x-position of the drawing area. */
4676 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4682 c = (ROW)->glyphs[AREA][START].u.ch; \
4683 face_id = (ROW)->glyphs[AREA][START].face_id; \
4685 s = (struct glyph_string *) alloca (sizeof *s); \
4686 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
4687 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4688 x_append_glyph_string (&HEAD, &TAIL, s); \
4690 START = x_fill_glyph_string (s, face_id, START, END, \
4696 /* Add a glyph string for a composite sequence to the list of strings
4697 between HEAD and TAIL. START is the index of the first glyph in
4698 row area AREA of glyph row ROW that is part of the new glyph
4699 string. END is the index of the last glyph in that glyph row area.
4700 X is the current output position assigned to the new glyph string
4701 constructed. HL overrides that face of the glyph; e.g. it is
4702 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
4703 x-position of the drawing area. */
4705 #define BUILD_COMPOSITE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4707 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
4708 int face_id = (ROW)->glyphs[AREA][START].face_id; \
4709 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
4710 struct composition *cmp = composition_table[cmp_id]; \
4711 int glyph_len = cmp->glyph_len; \
4713 struct face **faces; \
4714 struct glyph_string *first_s = NULL; \
4717 base_face = base_face->ascii_face; \
4718 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
4719 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
4720 /* At first, fill in `char2b' and `faces'. */ \
4721 for (n = 0; n < glyph_len; n++) \
4723 int c = COMPOSITION_GLYPH (cmp, n); \
4724 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
4725 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
4726 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
4727 this_face_id, char2b + n, 1); \
4730 /* Make glyph_strings for each glyph sequence that is drawable by \
4731 the same face, and append them to HEAD/TAIL. */ \
4732 for (n = 0; n < cmp->glyph_len;) \
4734 s = (struct glyph_string *) alloca (sizeof *s); \
4735 x_init_glyph_string (s, char2b + n, W, ROW, AREA, START, HL); \
4736 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4744 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
4752 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4753 of AREA of glyph row ROW on window W between indices START and END.
4754 HL overrides the face for drawing glyph strings, e.g. it is
4755 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4756 x-positions of the drawing area.
4758 This is an ugly monster macro construct because we must use alloca
4759 to allocate glyph strings (because x_draw_glyphs can be called
4762 #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4765 HEAD = TAIL = NULL; \
4766 while (START < END) \
4768 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
4769 switch (first_glyph->type) \
4772 BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \
4773 TAIL, HL, X, LAST_X, \
4777 case COMPOSITE_GLYPH: \
4778 BUILD_COMPOSITE_GLYPH_STRING (W, ROW, AREA, START, END, \
4779 HEAD, TAIL, HL, X, LAST_X,\
4783 case STRETCH_GLYPH: \
4784 BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \
4785 HEAD, TAIL, HL, X, LAST_X); \
4789 BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \
4790 TAIL, HL, X, LAST_X); \
4797 x_set_glyph_string_background_width (s, START, LAST_X); \
4804 /* Draw glyphs between START and END in AREA of ROW on window W,
4805 starting at x-position X. X is relative to AREA in W. HL is a
4806 face-override with the following meaning:
4808 DRAW_NORMAL_TEXT draw normally
4809 DRAW_CURSOR draw in cursor face
4810 DRAW_MOUSE_FACE draw in mouse face.
4811 DRAW_INVERSE_VIDEO draw in mode line face
4812 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
4813 DRAW_IMAGE_RAISED draw an image with a raised relief around it
4815 If REAL_START is non-null, return in *REAL_START the real starting
4816 position for display. This can be different from START in case
4817 overlapping glyphs must be displayed. If REAL_END is non-null,
4818 return in *REAL_END the real end position for display. This can be
4819 different from END in case overlapping glyphs must be displayed.
4821 If OVERLAPS_P is non-zero, draw only the foreground of characters
4822 and clip to the physical height of ROW.
4824 Value is the x-position reached, relative to AREA of W. */
4827 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, real_start
, real_end
,
4831 struct glyph_row
*row
;
4832 enum glyph_row_area area
;
4834 enum draw_glyphs_face hl
;
4835 int *real_start
, *real_end
;
4838 struct glyph_string
*head
, *tail
;
4839 struct glyph_string
*s
;
4840 int last_x
, area_width
;
4844 /* Let's rather be paranoid than getting a SEGV. */
4845 end
= min (end
, row
->used
[area
]);
4846 start
= max (0, start
);
4847 start
= min (end
, start
);
4849 *real_start
= start
;
4853 /* Translate X to frame coordinates. Set last_x to the right
4854 end of the drawing area. */
4855 if (row
->full_width_p
)
4857 /* X is relative to the left edge of W, without scroll bars
4859 struct frame
*f
= XFRAME (w
->frame
);
4860 /* int width = FRAME_FLAGS_AREA_WIDTH (f); */
4861 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
4864 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4865 last_x
= window_left_x
+ area_width
;
4867 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4869 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4870 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4876 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
4877 last_x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
4881 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
4882 area_width
= window_box_width (w
, area
);
4883 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
4886 /* Build a doubly-linked list of glyph_string structures between
4887 head and tail from what we have to draw. Note that the macro
4888 BUILD_GLYPH_STRINGS will modify its start parameter. That's
4889 the reason we use a separate variable `i'. */
4891 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
4894 x_reached
= tail
->x
+ tail
->background_width
;
4898 /* If there are any glyphs with lbearing < 0 or rbearing > width in
4899 the row, redraw some glyphs in front or following the glyph
4900 strings built above. */
4901 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
4904 struct glyph_string
*h
, *t
;
4906 /* Compute overhangs for all glyph strings. */
4907 for (s
= head
; s
; s
= s
->next
)
4908 x_compute_glyph_string_overhangs (s
);
4910 /* Prepend glyph strings for glyphs in front of the first glyph
4911 string that are overwritten because of the first glyph
4912 string's left overhang. The background of all strings
4913 prepended must be drawn because the first glyph string
4915 i
= x_left_overwritten (head
);
4919 BUILD_GLYPH_STRINGS (w
, row
, area
, j
, start
, h
, t
,
4920 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4924 *real_start
= start
;
4925 x_compute_overhangs_and_x (t
, head
->x
, 1);
4926 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4929 /* Prepend glyph strings for glyphs in front of the first glyph
4930 string that overwrite that glyph string because of their
4931 right overhang. For these strings, only the foreground must
4932 be drawn, because it draws over the glyph string at `head'.
4933 The background must not be drawn because this would overwrite
4934 right overhangs of preceding glyphs for which no glyph
4936 i
= x_left_overwriting (head
);
4939 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, start
, h
, t
,
4940 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4942 for (s
= h
; s
; s
= s
->next
)
4943 s
->background_filled_p
= 1;
4946 x_compute_overhangs_and_x (t
, head
->x
, 1);
4947 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4950 /* Append glyphs strings for glyphs following the last glyph
4951 string tail that are overwritten by tail. The background of
4952 these strings has to be drawn because tail's foreground draws
4954 i
= x_right_overwritten (tail
);
4957 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4958 DRAW_NORMAL_TEXT
, x
, last_x
,
4960 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4961 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
4966 /* Append glyph strings for glyphs following the last glyph
4967 string tail that overwrite tail. The foreground of such
4968 glyphs has to be drawn because it writes into the background
4969 of tail. The background must not be drawn because it could
4970 paint over the foreground of following glyphs. */
4971 i
= x_right_overwriting (tail
);
4974 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4975 DRAW_NORMAL_TEXT
, x
, last_x
,
4977 for (s
= h
; s
; s
= s
->next
)
4978 s
->background_filled_p
= 1;
4979 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4980 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
4986 /* Draw all strings. */
4987 for (s
= head
; s
; s
= s
->next
)
4988 x_draw_glyph_string (s
);
4990 /* Value is the x-position up to which drawn, relative to AREA of W.
4991 This doesn't include parts drawn because of overhangs. */
4992 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
4993 if (!row
->full_width_p
)
4995 if (area
> LEFT_MARGIN_AREA
)
4996 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
4997 if (area
> TEXT_AREA
)
4998 x_reached
-= window_box_width (w
, TEXT_AREA
);
5005 /* Fix the display of area AREA of overlapping row ROW in window W. */
5008 x_fix_overlapping_area (w
, row
, area
)
5010 struct glyph_row
*row
;
5011 enum glyph_row_area area
;
5017 if (area
== LEFT_MARGIN_AREA
)
5019 else if (area
== TEXT_AREA
)
5020 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5022 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5023 + window_box_width (w
, TEXT_AREA
));
5025 for (i
= 0; i
< row
->used
[area
];)
5027 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
5029 int start
= i
, start_x
= x
;
5033 x
+= row
->glyphs
[area
][i
].pixel_width
;
5036 while (i
< row
->used
[area
]
5037 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
5039 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
5041 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
5046 x
+= row
->glyphs
[area
][i
].pixel_width
;
5055 /* Output LEN glyphs starting at START at the nominal cursor position.
5056 Advance the nominal cursor over the text. The global variable
5057 updated_window contains the window being updated, updated_row is
5058 the glyph row being updated, and updated_area is the area of that
5059 row being updated. */
5062 x_write_glyphs (start
, len
)
5063 struct glyph
*start
;
5066 int x
, hpos
, real_start
, real_end
;
5068 xassert (updated_window
&& updated_row
);
5073 hpos
= start
- updated_row
->glyphs
[updated_area
];
5074 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
5075 updated_row
, updated_area
,
5077 (updated_row
->inverse_p
5078 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
5079 &real_start
, &real_end
, 0);
5081 /* If we drew over the cursor, note that it is not visible any more. */
5082 note_overwritten_text_cursor (updated_window
, real_start
,
5083 real_end
- real_start
);
5087 /* Advance the output cursor. */
5088 output_cursor
.hpos
+= len
;
5089 output_cursor
.x
= x
;
5093 /* Insert LEN glyphs from START at the nominal cursor position. */
5096 x_insert_glyphs (start
, len
)
5097 struct glyph
*start
;
5102 int line_height
, shift_by_width
, shifted_region_width
;
5103 struct glyph_row
*row
;
5104 struct glyph
*glyph
;
5105 int frame_x
, frame_y
, hpos
, real_start
, real_end
;
5107 xassert (updated_window
&& updated_row
);
5110 f
= XFRAME (WINDOW_FRAME (w
));
5112 /* Get the height of the line we are in. */
5114 line_height
= row
->height
;
5116 /* Get the width of the glyphs to insert. */
5118 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
5119 shift_by_width
+= glyph
->pixel_width
;
5121 /* Get the width of the region to shift right. */
5122 shifted_region_width
= (window_box_width (w
, updated_area
)
5127 frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, output_cursor
.x
);
5128 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
5129 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5130 f
->output_data
.x
->normal_gc
,
5132 shifted_region_width
, line_height
,
5133 frame_x
+ shift_by_width
, frame_y
);
5135 /* Write the glyphs. */
5136 hpos
= start
- row
->glyphs
[updated_area
];
5137 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
5138 DRAW_NORMAL_TEXT
, &real_start
, &real_end
, 0);
5139 note_overwritten_text_cursor (w
, real_start
, real_end
- real_start
);
5141 /* Advance the output cursor. */
5142 output_cursor
.hpos
+= len
;
5143 output_cursor
.x
+= shift_by_width
;
5148 /* Delete N glyphs at the nominal cursor position. Not implemented
5159 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
5160 If they are <= 0, this is probably an error. */
5163 x_clear_area (dpy
, window
, x
, y
, width
, height
, exposures
)
5170 xassert (width
> 0 && height
> 0);
5171 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
5175 /* Erase the current text line from the nominal cursor position
5176 (inclusive) to pixel column TO_X (exclusive). The idea is that
5177 everything from TO_X onward is already erased.
5179 TO_X is a pixel position relative to updated_area of
5180 updated_window. TO_X == -1 means clear to the end of this area. */
5183 x_clear_end_of_line (to_x
)
5187 struct window
*w
= updated_window
;
5188 int max_x
, min_y
, max_y
;
5189 int from_x
, from_y
, to_y
;
5191 xassert (updated_window
&& updated_row
);
5192 f
= XFRAME (w
->frame
);
5194 if (updated_row
->full_width_p
)
5196 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5197 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5198 && !w
->pseudo_window_p
)
5199 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5202 max_x
= window_box_width (w
, updated_area
);
5203 max_y
= window_text_bottom_y (w
);
5205 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
5206 of window. For TO_X > 0, truncate to end of drawing area. */
5212 to_x
= min (to_x
, max_x
);
5214 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
5216 /* Notice if the cursor will be cleared by this operation. */
5217 if (!updated_row
->full_width_p
)
5218 note_overwritten_text_cursor (w
, output_cursor
.hpos
, -1);
5220 from_x
= output_cursor
.x
;
5222 /* Translate to frame coordinates. */
5223 if (updated_row
->full_width_p
)
5225 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
5226 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
5230 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
5231 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
5234 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
5235 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
5236 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
5238 /* Prevent inadvertently clearing to end of the X window. */
5239 if (to_x
> from_x
&& to_y
> from_y
)
5242 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5243 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
5250 /* Clear entire frame. If updating_frame is non-null, clear that
5251 frame. Otherwise clear the selected frame. */
5261 f
= SELECTED_FRAME ();
5263 /* Clearing the frame will erase any cursor, so mark them all as no
5265 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5266 output_cursor
.hpos
= output_cursor
.vpos
= 0;
5267 output_cursor
.x
= -1;
5269 /* We don't set the output cursor here because there will always
5270 follow an explicit cursor_to. */
5272 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5274 /* We have to clear the scroll bars, too. If we have changed
5275 colors or something like that, then they should be notified. */
5276 x_scroll_bar_clear (f
);
5278 XFlush (FRAME_X_DISPLAY (f
));
5284 /* Invert the middle quarter of the frame for .15 sec. */
5286 /* We use the select system call to do the waiting, so we have to make
5287 sure it's available. If it isn't, we just won't do visual bells. */
5289 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5292 /* Subtract the `struct timeval' values X and Y, storing the result in
5293 *RESULT. Return 1 if the difference is negative, otherwise 0. */
5296 timeval_subtract (result
, x
, y
)
5297 struct timeval
*result
, x
, y
;
5299 /* Perform the carry for the later subtraction by updating y. This
5300 is safer because on some systems the tv_sec member is unsigned. */
5301 if (x
.tv_usec
< y
.tv_usec
)
5303 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
5304 y
.tv_usec
-= 1000000 * nsec
;
5308 if (x
.tv_usec
- y
.tv_usec
> 1000000)
5310 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
5311 y
.tv_usec
+= 1000000 * nsec
;
5315 /* Compute the time remaining to wait. tv_usec is certainly
5317 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
5318 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
5320 /* Return indication of whether the result should be considered
5322 return x
.tv_sec
< y
.tv_sec
;
5334 /* Create a GC that will use the GXxor function to flip foreground
5335 pixels into background pixels. */
5339 values
.function
= GXxor
;
5340 values
.foreground
= (f
->output_data
.x
->foreground_pixel
5341 ^ f
->output_data
.x
->background_pixel
);
5343 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5344 GCFunction
| GCForeground
, &values
);
5348 /* Get the height not including a menu bar widget. */
5349 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
5350 /* Height of each line to flash. */
5351 int flash_height
= FRAME_LINE_HEIGHT (f
);
5352 /* These will be the left and right margins of the rectangles. */
5353 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
5354 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
5358 /* Don't flash the area between a scroll bar and the frame
5359 edge it is next to. */
5360 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
5362 case vertical_scroll_bar_left
:
5363 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5366 case vertical_scroll_bar_right
:
5367 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5374 width
= flash_right
- flash_left
;
5376 /* If window is tall, flash top and bottom line. */
5377 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5379 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5381 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5382 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5383 width
, flash_height
);
5384 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5386 (height
- flash_height
5387 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5388 width
, flash_height
);
5391 /* If it is short, flash it all. */
5392 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5393 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5394 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5399 struct timeval wakeup
;
5401 EMACS_GET_TIME (wakeup
);
5403 /* Compute time to wait until, propagating carry from usecs. */
5404 wakeup
.tv_usec
+= 150000;
5405 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
5406 wakeup
.tv_usec
%= 1000000;
5408 /* Keep waiting until past the time wakeup. */
5411 struct timeval timeout
;
5413 EMACS_GET_TIME (timeout
);
5415 /* In effect, timeout = wakeup - timeout.
5416 Break if result would be negative. */
5417 if (timeval_subtract (&timeout
, wakeup
, timeout
))
5420 /* Try to wait that long--but we might wake up sooner. */
5421 select (0, NULL
, NULL
, NULL
, &timeout
);
5425 /* If window is tall, flash top and bottom line. */
5426 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5428 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5430 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5431 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5432 width
, flash_height
);
5433 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5435 (height
- flash_height
5436 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5437 width
, flash_height
);
5440 /* If it is short, flash it all. */
5441 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5442 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5443 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5445 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
5453 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
5456 /* Make audible bell. */
5461 struct frame
*f
= SELECTED_FRAME ();
5463 if (FRAME_X_DISPLAY (f
))
5465 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5472 XBell (FRAME_X_DISPLAY (f
), 0);
5473 XFlush (FRAME_X_DISPLAY (f
));
5480 /* Specify how many text lines, from the top of the window,
5481 should be affected by insert-lines and delete-lines operations.
5482 This, and those operations, are used only within an update
5483 that is bounded by calls to x_update_begin and x_update_end. */
5486 XTset_terminal_window (n
)
5489 /* This function intentionally left blank. */
5494 /***********************************************************************
5496 ***********************************************************************/
5498 /* Perform an insert-lines or delete-lines operation, inserting N
5499 lines or deleting -N lines at vertical position VPOS. */
5502 x_ins_del_lines (vpos
, n
)
5509 /* Scroll part of the display as described by RUN. */
5512 x_scroll_run (w
, run
)
5516 struct frame
*f
= XFRAME (w
->frame
);
5517 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5519 /* Get frame-relative bounding box of the text display area of W,
5520 without mode lines. Include in this box the flags areas to the
5521 left and right of W. */
5522 window_box (w
, -1, &x
, &y
, &width
, &height
);
5523 width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
5524 x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
5526 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5527 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5528 bottom_y
= y
+ height
;
5532 /* Scrolling up. Make sure we don't copy part of the mode
5533 line at the bottom. */
5534 if (from_y
+ run
->height
> bottom_y
)
5535 height
= bottom_y
- from_y
;
5537 height
= run
->height
;
5541 /* Scolling down. Make sure we don't copy over the mode line.
5543 if (to_y
+ run
->height
> bottom_y
)
5544 height
= bottom_y
- to_y
;
5546 height
= run
->height
;
5551 /* Cursor off. Will be switched on again in x_update_window_end. */
5555 XCopyArea (FRAME_X_DISPLAY (f
),
5556 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5557 f
->output_data
.x
->normal_gc
,
5567 /***********************************************************************
5569 ***********************************************************************/
5571 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5572 corner of the exposed rectangle. W and H are width and height of
5573 the exposed area. All are pixel values. W or H zero means redraw
5574 the entire frame. */
5577 expose_frame (f
, x
, y
, w
, h
)
5583 TRACE ((stderr
, "expose_frame "));
5585 /* No need to redraw if frame will be redrawn soon. */
5586 if (FRAME_GARBAGED_P (f
))
5588 TRACE ((stderr
, " garbaged\n"));
5592 /* If basic faces haven't been realized yet, there is no point in
5593 trying to redraw anything. This can happen when we get an expose
5594 event while Emacs is starting, e.g. by moving another window. */
5595 if (FRAME_FACE_CACHE (f
) == NULL
5596 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5598 TRACE ((stderr
, " no faces\n"));
5602 if (w
== 0 || h
== 0)
5605 r
.width
= CANON_X_UNIT (f
) * f
->width
;
5606 r
.height
= CANON_Y_UNIT (f
) * f
->height
;
5616 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
5617 expose_window_tree (XWINDOW (f
->root_window
), &r
);
5619 if (WINDOWP (f
->tool_bar_window
))
5621 struct window
*w
= XWINDOW (f
->tool_bar_window
);
5622 XRectangle window_rect
;
5623 XRectangle intersection_rect
;
5624 int window_x
, window_y
, window_width
, window_height
;
5627 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5628 window_rect
.x
= window_x
;
5629 window_rect
.y
= window_y
;
5630 window_rect
.width
= window_width
;
5631 window_rect
.height
= window_height
;
5633 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5634 expose_window (w
, &intersection_rect
);
5637 #ifndef USE_X_TOOLKIT
5638 if (WINDOWP (f
->menu_bar_window
))
5640 struct window
*w
= XWINDOW (f
->menu_bar_window
);
5641 XRectangle window_rect
;
5642 XRectangle intersection_rect
;
5643 int window_x
, window_y
, window_width
, window_height
;
5646 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5647 window_rect
.x
= window_x
;
5648 window_rect
.y
= window_y
;
5649 window_rect
.width
= window_width
;
5650 window_rect
.height
= window_height
;
5652 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5653 expose_window (w
, &intersection_rect
);
5655 #endif /* not USE_X_TOOLKIT */
5659 /* Redraw (parts) of all windows in the window tree rooted at W that
5660 intersect R. R contains frame pixel coordinates. */
5663 expose_window_tree (w
, r
)
5669 if (!NILP (w
->hchild
))
5670 expose_window_tree (XWINDOW (w
->hchild
), r
);
5671 else if (!NILP (w
->vchild
))
5672 expose_window_tree (XWINDOW (w
->vchild
), r
);
5675 XRectangle window_rect
;
5676 XRectangle intersection_rect
;
5677 struct frame
*f
= XFRAME (w
->frame
);
5678 int window_x
, window_y
, window_width
, window_height
;
5680 /* Frame-relative pixel rectangle of W. */
5681 window_box (w
, -1, &window_x
, &window_y
, &window_width
,
5685 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
5686 - FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5687 window_rect
.y
= window_y
;
5690 + FRAME_X_FLAGS_AREA_WIDTH (f
)
5691 + FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5693 = window_height
+ CURRENT_MODE_LINE_HEIGHT (w
);
5695 if (x_intersect_rectangles (r
, &window_rect
, &intersection_rect
))
5696 expose_window (w
, &intersection_rect
);
5699 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5704 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5705 which intersects rectangle R. R is in window-relative coordinates. */
5708 expose_area (w
, row
, r
, area
)
5710 struct glyph_row
*row
;
5712 enum glyph_row_area area
;
5714 struct glyph
*first
= row
->glyphs
[area
];
5715 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5717 int first_x
, start_x
, x
;
5719 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5720 /* If row extends face to end of line write the whole line. */
5721 x_draw_glyphs (w
, 0, row
, area
,
5723 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5727 /* Set START_X to the window-relative start position for drawing glyphs of
5728 AREA. The first glyph of the text area can be partially visible.
5729 The first glyphs of other areas cannot. */
5730 if (area
== LEFT_MARGIN_AREA
)
5732 else if (area
== TEXT_AREA
)
5733 start_x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5735 start_x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5736 + window_box_width (w
, TEXT_AREA
));
5739 /* Find the first glyph that must be redrawn. */
5741 && x
+ first
->pixel_width
< r
->x
)
5743 x
+= first
->pixel_width
;
5747 /* Find the last one. */
5751 && x
< r
->x
+ r
->width
)
5753 x
+= last
->pixel_width
;
5759 x_draw_glyphs (w
, first_x
- start_x
, row
, area
,
5760 first
- row
->glyphs
[area
],
5761 last
- row
->glyphs
[area
],
5762 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5768 /* Redraw the parts of the glyph row ROW on window W intersecting
5769 rectangle R. R is in window-relative coordinates. */
5772 expose_line (w
, row
, r
)
5774 struct glyph_row
*row
;
5777 xassert (row
->enabled_p
);
5779 if (row
->mode_line_p
|| w
->pseudo_window_p
)
5780 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
5781 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5785 if (row
->used
[LEFT_MARGIN_AREA
])
5786 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
5787 if (row
->used
[TEXT_AREA
])
5788 expose_area (w
, row
, r
, TEXT_AREA
);
5789 if (row
->used
[RIGHT_MARGIN_AREA
])
5790 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
5791 x_draw_row_bitmaps (w
, row
);
5796 /* Return non-zero if W's cursor intersects rectangle R. */
5799 x_phys_cursor_in_rect_p (w
, r
)
5803 XRectangle cr
, result
;
5804 struct glyph
*cursor_glyph
;
5806 cursor_glyph
= get_phys_cursor_glyph (w
);
5809 cr
.x
= w
->phys_cursor
.x
;
5810 cr
.y
= w
->phys_cursor
.y
;
5811 cr
.width
= cursor_glyph
->pixel_width
;
5812 cr
.height
= w
->phys_cursor_height
;
5813 return x_intersect_rectangles (&cr
, r
, &result
);
5820 /* Redraw a rectangle of window W. R is a rectangle in window
5821 relative coordinates. Call this function with input blocked. */
5824 expose_window (w
, r
)
5828 struct glyph_row
*row
;
5830 int yb
= window_text_bottom_y (w
);
5831 int cursor_cleared_p
;
5833 /* If window is not yet fully initialized, do nothing. This can
5834 happen when toolkit scroll bars are used and a window is split.
5835 Reconfiguring the scroll bar will generate an expose for a newly
5837 if (w
->current_matrix
== NULL
|| w
== updated_window
)
5840 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
5841 r
->x
, r
->y
, r
->width
, r
->height
));
5843 /* Convert to window coordinates. */
5844 r
->x
= FRAME_TO_WINDOW_PIXEL_X (w
, r
->x
);
5845 r
->y
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
->y
);
5847 /* Turn off the cursor. */
5848 if (!w
->pseudo_window_p
5849 && x_phys_cursor_in_rect_p (w
, r
))
5852 cursor_cleared_p
= 1;
5855 cursor_cleared_p
= 0;
5857 /* Find the first row intersecting the rectangle R. */
5858 row
= w
->current_matrix
->rows
;
5860 while (row
->enabled_p
5862 && y
+ row
->height
< r
->y
)
5868 /* Display the text in the rectangle, one text line at a time. */
5869 while (row
->enabled_p
5871 && y
< r
->y
+ r
->height
)
5873 expose_line (w
, row
, r
);
5878 /* Display the mode line if there is one. */
5879 if (WINDOW_WANTS_MODELINE_P (w
)
5880 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
5882 && row
->y
< r
->y
+ r
->height
)
5883 expose_line (w
, row
, r
);
5885 if (!w
->pseudo_window_p
)
5887 /* Draw border between windows. */
5888 x_draw_vertical_border (w
);
5890 /* Turn the cursor on again. */
5891 if (cursor_cleared_p
)
5892 x_update_window_cursor (w
, 1);
5897 /* Determine the intersection of two rectangles R1 and R2. Return
5898 the intersection in *RESULT. Value is non-zero if RESULT is not
5902 x_intersect_rectangles (r1
, r2
, result
)
5903 XRectangle
*r1
, *r2
, *result
;
5905 XRectangle
*left
, *right
;
5906 XRectangle
*upper
, *lower
;
5907 int intersection_p
= 0;
5909 /* Rearrange so that R1 is the left-most rectangle. */
5911 left
= r1
, right
= r2
;
5913 left
= r2
, right
= r1
;
5915 /* X0 of the intersection is right.x0, if this is inside R1,
5916 otherwise there is no intersection. */
5917 if (right
->x
<= left
->x
+ left
->width
)
5919 result
->x
= right
->x
;
5921 /* The right end of the intersection is the minimum of the
5922 the right ends of left and right. */
5923 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
5926 /* Same game for Y. */
5928 upper
= r1
, lower
= r2
;
5930 upper
= r2
, lower
= r1
;
5932 /* The upper end of the intersection is lower.y0, if this is inside
5933 of upper. Otherwise, there is no intersection. */
5934 if (lower
->y
<= upper
->y
+ upper
->height
)
5936 result
->y
= lower
->y
;
5938 /* The lower end of the intersection is the minimum of the lower
5939 ends of upper and lower. */
5940 result
->height
= (min (lower
->y
+ lower
->height
,
5941 upper
->y
+ upper
->height
)
5947 return intersection_p
;
5958 /* We used to only do this if Vx_no_window_manager was non-nil, but
5959 the ICCCM (section 4.1.6) says that the window's border pixmap
5960 and border pixel are window attributes which are "private to the
5961 client", so we can always change it to whatever we want. */
5963 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5964 f
->output_data
.x
->border_pixel
);
5966 x_update_cursor (f
, 1);
5970 frame_unhighlight (f
)
5973 /* We used to only do this if Vx_no_window_manager was non-nil, but
5974 the ICCCM (section 4.1.6) says that the window's border pixmap
5975 and border pixel are window attributes which are "private to the
5976 client", so we can always change it to whatever we want. */
5978 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5979 f
->output_data
.x
->border_tile
);
5981 x_update_cursor (f
, 1);
5984 /* The focus has changed. Update the frames as necessary to reflect
5985 the new situation. Note that we can't change the selected frame
5986 here, because the Lisp code we are interrupting might become confused.
5987 Each event gets marked with the frame in which it occurred, so the
5988 Lisp code can tell when the switch took place by examining the events. */
5991 x_new_focus_frame (dpyinfo
, frame
)
5992 struct x_display_info
*dpyinfo
;
5993 struct frame
*frame
;
5995 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
5997 if (frame
!= dpyinfo
->x_focus_frame
)
5999 /* Set this before calling other routines, so that they see
6000 the correct value of x_focus_frame. */
6001 dpyinfo
->x_focus_frame
= frame
;
6003 if (old_focus
&& old_focus
->auto_lower
)
6004 x_lower_frame (old_focus
);
6007 selected_frame
= frame
;
6008 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
6010 Fselect_window (selected_frame
->selected_window
);
6011 choose_minibuf_frame ();
6014 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
6015 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
6017 pending_autoraise_frame
= 0;
6020 x_frame_rehighlight (dpyinfo
);
6023 /* Handle an event saying the mouse has moved out of an Emacs frame. */
6026 x_mouse_leave (dpyinfo
)
6027 struct x_display_info
*dpyinfo
;
6029 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
6032 /* The focus has changed, or we have redirected a frame's focus to
6033 another frame (this happens when a frame uses a surrogate
6034 mini-buffer frame). Shift the highlight as appropriate.
6036 The FRAME argument doesn't necessarily have anything to do with which
6037 frame is being highlighted or un-highlighted; we only use it to find
6038 the appropriate X display info. */
6041 XTframe_rehighlight (frame
)
6042 struct frame
*frame
;
6044 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
6048 x_frame_rehighlight (dpyinfo
)
6049 struct x_display_info
*dpyinfo
;
6051 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
6053 if (dpyinfo
->x_focus_frame
)
6055 dpyinfo
->x_highlight_frame
6056 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
6057 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
6058 : dpyinfo
->x_focus_frame
);
6059 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
6061 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
6062 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
6066 dpyinfo
->x_highlight_frame
= 0;
6068 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
6071 frame_unhighlight (old_highlight
);
6072 if (dpyinfo
->x_highlight_frame
)
6073 frame_highlight (dpyinfo
->x_highlight_frame
);
6079 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
6081 /* Initialize mode_switch_bit and modifier_meaning. */
6083 x_find_modifier_meanings (dpyinfo
)
6084 struct x_display_info
*dpyinfo
;
6086 int min_code
, max_code
;
6089 XModifierKeymap
*mods
;
6091 dpyinfo
->meta_mod_mask
= 0;
6092 dpyinfo
->shift_lock_mask
= 0;
6093 dpyinfo
->alt_mod_mask
= 0;
6094 dpyinfo
->super_mod_mask
= 0;
6095 dpyinfo
->hyper_mod_mask
= 0;
6098 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
6100 min_code
= dpyinfo
->display
->min_keycode
;
6101 max_code
= dpyinfo
->display
->max_keycode
;
6104 syms
= XGetKeyboardMapping (dpyinfo
->display
,
6105 min_code
, max_code
- min_code
+ 1,
6107 mods
= XGetModifierMapping (dpyinfo
->display
);
6109 /* Scan the modifier table to see which modifier bits the Meta and
6110 Alt keysyms are on. */
6112 int row
, col
; /* The row and column in the modifier table. */
6114 for (row
= 3; row
< 8; row
++)
6115 for (col
= 0; col
< mods
->max_keypermod
; col
++)
6118 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
6120 /* Zeroes are used for filler. Skip them. */
6124 /* Are any of this keycode's keysyms a meta key? */
6128 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
6130 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
6136 dpyinfo
->meta_mod_mask
|= (1 << row
);
6141 dpyinfo
->alt_mod_mask
|= (1 << row
);
6146 dpyinfo
->hyper_mod_mask
|= (1 << row
);
6151 dpyinfo
->super_mod_mask
|= (1 << row
);
6155 /* Ignore this if it's not on the lock modifier. */
6156 if ((1 << row
) == LockMask
)
6157 dpyinfo
->shift_lock_mask
= LockMask
;
6165 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
6166 if (! dpyinfo
->meta_mod_mask
)
6168 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
6169 dpyinfo
->alt_mod_mask
= 0;
6172 /* If some keys are both alt and meta,
6173 make them just meta, not alt. */
6174 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
6176 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
6179 XFree ((char *) syms
);
6180 XFreeModifiermap (mods
);
6183 /* Convert between the modifier bits X uses and the modifier bits
6187 x_x_to_emacs_modifiers (dpyinfo
, state
)
6188 struct x_display_info
*dpyinfo
;
6191 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
6192 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
6193 | ((state
& dpyinfo
->meta_mod_mask
) ? meta_modifier
: 0)
6194 | ((state
& dpyinfo
->alt_mod_mask
) ? alt_modifier
: 0)
6195 | ((state
& dpyinfo
->super_mod_mask
) ? super_modifier
: 0)
6196 | ((state
& dpyinfo
->hyper_mod_mask
) ? hyper_modifier
: 0));
6200 x_emacs_to_x_modifiers (dpyinfo
, state
)
6201 struct x_display_info
*dpyinfo
;
6204 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
6205 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
6206 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
6207 | ((state
& shift_modifier
) ? ShiftMask
: 0)
6208 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
6209 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
6212 /* Convert a keysym to its name. */
6215 x_get_keysym_name (keysym
)
6221 value
= XKeysymToString (keysym
);
6229 /* Mouse clicks and mouse movement. Rah. */
6231 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
6232 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
6233 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
6234 not force the value into range. */
6237 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
6239 register int pix_x
, pix_y
;
6240 register int *x
, *y
;
6244 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
6245 even for negative values. */
6247 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
6249 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
6251 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
6252 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
6256 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
6257 bounds
->height
= f
->output_data
.x
->line_height
;
6258 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
6259 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
6266 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
6267 pix_x
= FRAME_WINDOW_WIDTH (f
);
6271 else if (pix_y
> f
->height
)
6280 /* Given HPOS/VPOS in the current matrix of W, return corresponding
6281 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
6282 can't tell the positions because W's display is not up to date,
6286 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
6289 int *frame_x
, *frame_y
;
6293 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
6294 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
6296 if (display_completed
)
6298 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6299 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
6300 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
6306 *frame_x
+= glyph
->pixel_width
;
6314 *frame_y
= *frame_x
= 0;
6318 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
6319 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6324 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6326 If the event is a button press, then note that we have grabbed
6330 construct_mouse_click (result
, event
, f
)
6331 struct input_event
*result
;
6332 XButtonEvent
*event
;
6335 /* Make the event type no_event; we'll change that when we decide
6337 result
->kind
= mouse_click
;
6338 result
->code
= event
->button
- Button1
;
6339 result
->timestamp
= event
->time
;
6340 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6342 | (event
->type
== ButtonRelease
6346 XSETINT (result
->x
, event
->x
);
6347 XSETINT (result
->y
, event
->y
);
6348 XSETFRAME (result
->frame_or_window
, f
);
6354 /* Function to report a mouse movement to the mainstream Emacs code.
6355 The input handler calls this.
6357 We have received a mouse movement event, which is given in *event.
6358 If the mouse is over a different glyph than it was last time, tell
6359 the mainstream emacs code by setting mouse_moved. If not, ask for
6360 another motion event, so we can check again the next time it moves. */
6362 static XMotionEvent last_mouse_motion_event
;
6363 static Lisp_Object last_mouse_motion_frame
;
6366 note_mouse_movement (frame
, event
)
6368 XMotionEvent
*event
;
6370 last_mouse_movement_time
= event
->time
;
6371 last_mouse_motion_event
= *event
;
6372 XSETFRAME (last_mouse_motion_frame
, frame
);
6374 if (event
->window
!= FRAME_X_WINDOW (frame
))
6376 frame
->mouse_moved
= 1;
6377 last_mouse_scroll_bar
= Qnil
;
6378 note_mouse_highlight (frame
, -1, -1);
6381 /* Has the mouse moved off the glyph it was on at the last sighting? */
6382 else if (event
->x
< last_mouse_glyph
.x
6383 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
6384 || event
->y
< last_mouse_glyph
.y
6385 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
6387 frame
->mouse_moved
= 1;
6388 last_mouse_scroll_bar
= Qnil
;
6389 note_mouse_highlight (frame
, event
->x
, event
->y
);
6393 /* This is used for debugging, to turn off note_mouse_highlight. */
6395 int disable_mouse_highlight
;
6399 /************************************************************************
6401 ************************************************************************/
6403 /* Find the glyph under window-relative coordinates X/Y in window W.
6404 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6405 strings. Return in *HPOS and *VPOS the row and column number of
6406 the glyph found. Return in *AREA the glyph area containing X.
6407 Value is a pointer to the glyph found or null if X/Y is not on
6408 text, or we can't tell because W's current matrix is not up to
6411 static struct glyph
*
6412 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
)
6415 int *hpos
, *vpos
, *area
;
6417 struct glyph
*glyph
, *end
;
6418 struct glyph_row
*row
= NULL
;
6419 int x0
, i
, left_area_width
;
6421 /* Find row containing Y. Give up if some row is not enabled. */
6422 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6424 row
= MATRIX_ROW (w
->current_matrix
, i
);
6425 if (!row
->enabled_p
)
6427 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6434 /* Give up if Y is not in the window. */
6435 if (i
== w
->current_matrix
->nrows
)
6438 /* Get the glyph area containing X. */
6439 if (w
->pseudo_window_p
)
6446 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6447 if (x
< left_area_width
)
6449 *area
= LEFT_MARGIN_AREA
;
6452 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6455 x0
= row
->x
+ left_area_width
;
6459 *area
= RIGHT_MARGIN_AREA
;
6460 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6464 /* Find glyph containing X. */
6465 glyph
= row
->glyphs
[*area
];
6466 end
= glyph
+ row
->used
[*area
];
6469 if (x
< x0
+ glyph
->pixel_width
)
6471 if (w
->pseudo_window_p
)
6473 else if (BUFFERP (glyph
->object
))
6477 x0
+= glyph
->pixel_width
;
6484 *hpos
= glyph
- row
->glyphs
[*area
];
6489 /* Convert frame-relative x/y to coordinates relative to window W.
6490 Takes pseudo-windows into account. */
6493 frame_to_window_pixel_xy (w
, x
, y
)
6497 if (w
->pseudo_window_p
)
6499 /* A pseudo-window is always full-width, and starts at the
6500 left edge of the frame, plus a frame border. */
6501 struct frame
*f
= XFRAME (w
->frame
);
6502 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6503 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6507 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6508 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6513 /* Take proper action when mouse has moved to the mode or header line of
6514 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6515 mode line. X is relative to the start of the text display area of
6516 W, so the width of bitmap areas and scroll bars must be subtracted
6517 to get a position relative to the start of the mode line. */
6520 note_mode_line_highlight (w
, x
, mode_line_p
)
6524 struct frame
*f
= XFRAME (w
->frame
);
6525 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6526 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6527 struct glyph_row
*row
;
6530 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
6532 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
6536 struct glyph
*glyph
, *end
;
6537 Lisp_Object help
, map
;
6540 /* Find the glyph under X. */
6541 glyph
= row
->glyphs
[TEXT_AREA
];
6542 end
= glyph
+ row
->used
[TEXT_AREA
];
6543 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6544 + FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
));
6547 && x
>= x0
+ glyph
->pixel_width
)
6549 x0
+= glyph
->pixel_width
;
6554 && STRINGP (glyph
->object
)
6555 && XSTRING (glyph
->object
)->intervals
6556 && glyph
->charpos
>= 0
6557 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6559 /* If we're on a string with `help-echo' text property,
6560 arrange for the help to be displayed. This is done by
6561 setting the global variable help_echo to the help string. */
6562 help
= Fget_text_property (make_number (glyph
->charpos
),
6563 Qhelp_echo
, glyph
->object
);
6567 XSETWINDOW (help_echo_window
, w
);
6568 help_echo_object
= glyph
->object
;
6569 help_echo_pos
= glyph
->charpos
;
6572 /* Change the mouse pointer according to what is under X/Y. */
6573 map
= Fget_text_property (make_number (glyph
->charpos
),
6574 Qlocal_map
, glyph
->object
);
6576 cursor
= f
->output_data
.x
->nontext_cursor
;
6579 map
= Fget_text_property (make_number (glyph
->charpos
),
6580 Qkeymap
, glyph
->object
);
6582 cursor
= f
->output_data
.x
->nontext_cursor
;
6587 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6591 /* Take proper action when the mouse has moved to position X, Y on
6592 frame F as regards highlighting characters that have mouse-face
6593 properties. Also de-highlighting chars where the mouse was before.
6594 X and Y can be negative or out of range. */
6597 note_mouse_highlight (f
, x
, y
)
6601 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6606 /* When a menu is active, don't highlight because this looks odd. */
6607 #ifdef USE_X_TOOLKIT
6608 if (popup_activated ())
6612 if (disable_mouse_highlight
6613 || !f
->glyphs_initialized_p
)
6616 dpyinfo
->mouse_face_mouse_x
= x
;
6617 dpyinfo
->mouse_face_mouse_y
= y
;
6618 dpyinfo
->mouse_face_mouse_frame
= f
;
6620 if (dpyinfo
->mouse_face_defer
)
6625 dpyinfo
->mouse_face_deferred_gc
= 1;
6629 /* Which window is that in? */
6630 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6632 /* If we were displaying active text in another window, clear that. */
6633 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6634 clear_mouse_face (dpyinfo
);
6636 /* Not on a window -> return. */
6637 if (!WINDOWP (window
))
6640 /* Convert to window-relative pixel coordinates. */
6641 w
= XWINDOW (window
);
6642 frame_to_window_pixel_xy (w
, &x
, &y
);
6644 /* Handle tool-bar window differently since it doesn't display a
6646 if (EQ (window
, f
->tool_bar_window
))
6648 note_tool_bar_highlight (f
, x
, y
);
6652 if (portion
== 1 || portion
== 3)
6654 /* Mouse is on the mode or top line. */
6655 note_mode_line_highlight (w
, x
, portion
== 1);
6658 else if (portion
== 2)
6659 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6660 f
->output_data
.x
->horizontal_drag_cursor
);
6662 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6663 f
->output_data
.x
->text_cursor
);
6665 /* Are we in a window whose display is up to date?
6666 And verify the buffer's text has not changed. */
6667 if (/* Within text portion of the window. */
6669 && EQ (w
->window_end_valid
, w
->buffer
)
6670 && XFASTINT (w
->last_modified
) == BUF_MODIFF (XBUFFER (w
->buffer
))
6671 && (XFASTINT (w
->last_overlay_modified
)
6672 == BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
))))
6674 int hpos
, vpos
, pos
, i
, area
;
6675 struct glyph
*glyph
;
6677 /* Find the glyph under X/Y. */
6678 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
);
6680 /* Clear mouse face if X/Y not over text. */
6682 || area
!= TEXT_AREA
6683 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6685 clear_mouse_face (dpyinfo
);
6689 pos
= glyph
->charpos
;
6690 xassert (w
->pseudo_window_p
|| BUFFERP (glyph
->object
));
6692 /* Check for mouse-face and help-echo. */
6694 Lisp_Object mouse_face
, overlay
, position
;
6695 Lisp_Object
*overlay_vec
;
6697 struct buffer
*obuf
;
6700 /* If we get an out-of-range value, return now; avoid an error. */
6701 if (pos
> BUF_Z (XBUFFER (w
->buffer
)))
6704 /* Make the window's buffer temporarily current for
6705 overlays_at and compute_char_face. */
6706 obuf
= current_buffer
;
6707 current_buffer
= XBUFFER (w
->buffer
);
6713 /* Is this char mouse-active or does it have help-echo? */
6714 XSETINT (position
, pos
);
6716 /* Put all the overlays we want in a vector in overlay_vec.
6717 Store the length in len. If there are more than 10, make
6718 enough space for all, and try again. */
6720 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6721 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
6722 if (noverlays
> len
)
6725 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6726 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
6729 /* Sort overlays into increasing priority order. */
6730 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6732 /* Check mouse-face highlighting. */
6733 if (! (EQ (window
, dpyinfo
->mouse_face_window
)
6734 && vpos
>= dpyinfo
->mouse_face_beg_row
6735 && vpos
<= dpyinfo
->mouse_face_end_row
6736 && (vpos
> dpyinfo
->mouse_face_beg_row
6737 || hpos
>= dpyinfo
->mouse_face_beg_col
)
6738 && (vpos
< dpyinfo
->mouse_face_end_row
6739 || hpos
< dpyinfo
->mouse_face_end_col
6740 || dpyinfo
->mouse_face_past_end
)))
6742 /* Clear the display of the old active region, if any. */
6743 clear_mouse_face (dpyinfo
);
6745 /* Find the highest priority overlay that has a mouse-face prop. */
6747 for (i
= noverlays
- 1; i
>= 0; --i
)
6749 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
6750 if (!NILP (mouse_face
))
6752 overlay
= overlay_vec
[i
];
6757 /* If no overlay applies, get a text property. */
6759 mouse_face
= Fget_text_property (position
, Qmouse_face
, w
->buffer
);
6761 /* Handle the overlay case. */
6762 if (! NILP (overlay
))
6764 /* Find the range of text around this char that
6765 should be active. */
6766 Lisp_Object before
, after
;
6769 before
= Foverlay_start (overlay
);
6770 after
= Foverlay_end (overlay
);
6771 /* Record this as the current active region. */
6772 fast_find_position (w
, XFASTINT (before
),
6773 &dpyinfo
->mouse_face_beg_col
,
6774 &dpyinfo
->mouse_face_beg_row
,
6775 &dpyinfo
->mouse_face_beg_x
,
6776 &dpyinfo
->mouse_face_beg_y
);
6777 dpyinfo
->mouse_face_past_end
6778 = !fast_find_position (w
, XFASTINT (after
),
6779 &dpyinfo
->mouse_face_end_col
,
6780 &dpyinfo
->mouse_face_end_row
,
6781 &dpyinfo
->mouse_face_end_x
,
6782 &dpyinfo
->mouse_face_end_y
);
6783 dpyinfo
->mouse_face_window
= window
;
6784 dpyinfo
->mouse_face_face_id
6785 = face_at_buffer_position (w
, pos
, 0, 0,
6786 &ignore
, pos
+ 1, 1);
6788 /* Display it as active. */
6789 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6791 /* Handle the text property case. */
6792 else if (! NILP (mouse_face
))
6794 /* Find the range of text around this char that
6795 should be active. */
6796 Lisp_Object before
, after
, beginning
, end
;
6799 beginning
= Fmarker_position (w
->start
);
6800 XSETINT (end
, (BUF_Z (XBUFFER (w
->buffer
))
6801 - XFASTINT (w
->window_end_pos
)));
6803 = Fprevious_single_property_change (make_number (pos
+ 1),
6805 w
->buffer
, beginning
);
6807 = Fnext_single_property_change (position
, Qmouse_face
,
6809 /* Record this as the current active region. */
6810 fast_find_position (w
, XFASTINT (before
),
6811 &dpyinfo
->mouse_face_beg_col
,
6812 &dpyinfo
->mouse_face_beg_row
,
6813 &dpyinfo
->mouse_face_beg_x
,
6814 &dpyinfo
->mouse_face_beg_y
);
6815 dpyinfo
->mouse_face_past_end
6816 = !fast_find_position (w
, XFASTINT (after
),
6817 &dpyinfo
->mouse_face_end_col
,
6818 &dpyinfo
->mouse_face_end_row
,
6819 &dpyinfo
->mouse_face_end_x
,
6820 &dpyinfo
->mouse_face_end_y
);
6821 dpyinfo
->mouse_face_window
= window
;
6822 dpyinfo
->mouse_face_face_id
6823 = face_at_buffer_position (w
, pos
, 0, 0,
6824 &ignore
, pos
+ 1, 1);
6826 /* Display it as active. */
6827 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6831 /* Look for a `help-echo' property. */
6833 Lisp_Object help
, overlay
;
6835 /* Check overlays first. */
6836 help
= overlay
= Qnil
;
6837 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
6839 overlay
= overlay_vec
[i
];
6840 help
= Foverlay_get (overlay
, Qhelp_echo
);
6846 help_echo_window
= window
;
6847 help_echo_object
= overlay
;
6848 help_echo_pos
= pos
;
6852 /* Try text properties. */
6853 if ((STRINGP (glyph
->object
)
6854 && glyph
->charpos
>= 0
6855 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6856 || (BUFFERP (glyph
->object
)
6857 && glyph
->charpos
>= BEGV
6858 && glyph
->charpos
< ZV
))
6859 help
= Fget_text_property (make_number (glyph
->charpos
),
6860 Qhelp_echo
, glyph
->object
);
6865 help_echo_window
= window
;
6866 help_echo_object
= glyph
->object
;
6867 help_echo_pos
= glyph
->charpos
;
6874 current_buffer
= obuf
;
6880 redo_mouse_highlight ()
6882 if (!NILP (last_mouse_motion_frame
)
6883 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
6884 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
6885 last_mouse_motion_event
.x
,
6886 last_mouse_motion_event
.y
);
6891 /***********************************************************************
6893 ***********************************************************************/
6895 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
6896 struct glyph
**, int *, int *, int *));
6898 /* Tool-bar item index of the item on which a mouse button was pressed
6901 static int last_tool_bar_item
;
6904 /* Get information about the tool-bar item at position X/Y on frame F.
6905 Return in *GLYPH a pointer to the glyph of the tool-bar item in
6906 the current matrix of the tool-bar window of F, or NULL if not
6907 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
6908 item in F->tool_bar_items. Value is
6910 -1 if X/Y is not on a tool-bar item
6911 0 if X/Y is on the same item that was highlighted before.
6915 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
6918 struct glyph
**glyph
;
6919 int *hpos
, *vpos
, *prop_idx
;
6921 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6922 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6925 /* Find the glyph under X/Y. */
6926 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
);
6930 /* Get the start of this tool-bar item's properties in
6931 f->tool_bar_items. */
6932 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
6935 /* Is mouse on the highlighted item? */
6936 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
6937 && *vpos
>= dpyinfo
->mouse_face_beg_row
6938 && *vpos
<= dpyinfo
->mouse_face_end_row
6939 && (*vpos
> dpyinfo
->mouse_face_beg_row
6940 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
6941 && (*vpos
< dpyinfo
->mouse_face_end_row
6942 || *hpos
< dpyinfo
->mouse_face_end_col
6943 || dpyinfo
->mouse_face_past_end
))
6950 /* Handle mouse button event on the tool-bar of frame F, at
6951 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
6955 x_handle_tool_bar_click (f
, button_event
)
6957 XButtonEvent
*button_event
;
6959 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6960 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6961 int hpos
, vpos
, prop_idx
;
6962 struct glyph
*glyph
;
6963 Lisp_Object enabled_p
;
6964 int x
= button_event
->x
;
6965 int y
= button_event
->y
;
6967 /* If not on the highlighted tool-bar item, return. */
6968 frame_to_window_pixel_xy (w
, &x
, &y
);
6969 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
6972 /* If item is disabled, do nothing. */
6973 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
6974 if (NILP (enabled_p
))
6977 if (button_event
->type
== ButtonPress
)
6979 /* Show item in pressed state. */
6980 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
6981 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
6982 last_tool_bar_item
= prop_idx
;
6986 Lisp_Object key
, frame
;
6987 struct input_event event
;
6989 /* Show item in released state. */
6990 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
6991 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
6993 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
6995 XSETFRAME (frame
, f
);
6996 event
.kind
= TOOL_BAR_EVENT
;
6997 event
.frame_or_window
= frame
;
6999 kbd_buffer_store_event (&event
);
7001 event
.kind
= TOOL_BAR_EVENT
;
7002 event
.frame_or_window
= frame
;
7004 event
.modifiers
= x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
7005 button_event
->state
);
7006 kbd_buffer_store_event (&event
);
7007 last_tool_bar_item
= -1;
7012 /* Possibly highlight a tool-bar item on frame F when mouse moves to
7013 tool-bar window-relative coordinates X/Y. Called from
7014 note_mouse_highlight. */
7017 note_tool_bar_highlight (f
, x
, y
)
7021 Lisp_Object window
= f
->tool_bar_window
;
7022 struct window
*w
= XWINDOW (window
);
7023 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7025 struct glyph
*glyph
;
7026 struct glyph_row
*row
;
7028 Lisp_Object enabled_p
;
7030 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
7031 int mouse_down_p
, rc
;
7033 /* Function note_mouse_highlight is called with negative x(y
7034 values when mouse moves outside of the frame. */
7035 if (x
<= 0 || y
<= 0)
7037 clear_mouse_face (dpyinfo
);
7041 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
7044 /* Not on tool-bar item. */
7045 clear_mouse_face (dpyinfo
);
7049 /* On same tool-bar item as before. */
7052 clear_mouse_face (dpyinfo
);
7054 /* Mouse is down, but on different tool-bar item? */
7055 mouse_down_p
= (dpyinfo
->grabbed
7056 && f
== last_mouse_frame
7057 && FRAME_LIVE_P (f
));
7059 && last_tool_bar_item
!= prop_idx
)
7062 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
7063 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
7065 /* If tool-bar item is not enabled, don't highlight it. */
7066 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
7067 if (!NILP (enabled_p
))
7069 /* Compute the x-position of the glyph. In front and past the
7070 image is a space. We include this is the highlighted area. */
7071 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
7072 for (i
= x
= 0; i
< hpos
; ++i
)
7073 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
7075 /* Record this as the current active region. */
7076 dpyinfo
->mouse_face_beg_col
= hpos
;
7077 dpyinfo
->mouse_face_beg_row
= vpos
;
7078 dpyinfo
->mouse_face_beg_x
= x
;
7079 dpyinfo
->mouse_face_beg_y
= row
->y
;
7080 dpyinfo
->mouse_face_past_end
= 0;
7082 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
7083 dpyinfo
->mouse_face_end_row
= vpos
;
7084 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
7085 dpyinfo
->mouse_face_end_y
= row
->y
;
7086 dpyinfo
->mouse_face_window
= window
;
7087 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
7089 /* Display it as active. */
7090 show_mouse_face (dpyinfo
, draw
);
7091 dpyinfo
->mouse_face_image_state
= draw
;
7096 /* Set help_echo to a help string.to display for this tool-bar item.
7097 XTread_socket does the rest. */
7098 help_echo_object
= help_echo_window
= Qnil
;
7100 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
7101 if (NILP (help_echo
))
7102 help_echo
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
7107 /* Find the glyph matrix position of buffer position POS in window W.
7108 *HPOS, *VPOS, *X, and *Y are set to the positions found. W's
7109 current glyphs must be up to date. If POS is above window start
7110 return (0, 0, 0, 0). If POS is after end of W, return end of
7114 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
)
7117 int *hpos
, *vpos
, *x
, *y
;
7121 int maybe_next_line_p
= 0;
7122 int line_start_position
;
7123 int yb
= window_text_bottom_y (w
);
7124 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, 0);
7125 struct glyph_row
*best_row
= row
;
7126 int row_vpos
= 0, best_row_vpos
= 0;
7131 if (row
->used
[TEXT_AREA
])
7132 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
7134 line_start_position
= 0;
7136 if (line_start_position
> pos
)
7138 /* If the position sought is the end of the buffer,
7139 don't include the blank lines at the bottom of the window. */
7140 else if (line_start_position
== pos
7141 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
7143 maybe_next_line_p
= 1;
7146 else if (line_start_position
> 0)
7149 best_row_vpos
= row_vpos
;
7152 if (row
->y
+ row
->height
>= yb
)
7159 /* Find the right column within BEST_ROW. */
7161 current_x
= best_row
->x
;
7162 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
7164 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
7167 charpos
= glyph
->charpos
;
7171 *vpos
= best_row_vpos
;
7176 else if (charpos
> pos
)
7178 else if (charpos
> 0)
7181 current_x
+= glyph
->pixel_width
;
7184 /* If we're looking for the end of the buffer,
7185 and we didn't find it in the line we scanned,
7186 use the start of the following line. */
7187 if (maybe_next_line_p
)
7192 current_x
= best_row
->x
;
7195 *vpos
= best_row_vpos
;
7196 *hpos
= lastcol
+ 1;
7203 /* Display the active region described by mouse_face_*
7204 in its mouse-face if HL > 0, in its normal face if HL = 0. */
7207 show_mouse_face (dpyinfo
, draw
)
7208 struct x_display_info
*dpyinfo
;
7209 enum draw_glyphs_face draw
;
7211 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
7212 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7214 int cursor_off_p
= 0;
7215 struct cursor_pos saved_cursor
;
7217 saved_cursor
= output_cursor
;
7219 /* If window is in the process of being destroyed, don't bother
7221 if (w
->current_matrix
== NULL
)
7224 /* Recognize when we are called to operate on rows that don't exist
7225 anymore. This can happen when a window is split. */
7226 if (dpyinfo
->mouse_face_end_row
>= w
->current_matrix
->nrows
)
7229 set_output_cursor (&w
->phys_cursor
);
7231 /* Note that mouse_face_beg_row etc. are window relative. */
7232 for (i
= dpyinfo
->mouse_face_beg_row
;
7233 i
<= dpyinfo
->mouse_face_end_row
;
7236 int start_hpos
, end_hpos
, start_x
;
7237 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, i
);
7239 /* Don't do anything if row doesn't have valid contents. */
7240 if (!row
->enabled_p
)
7243 /* For all but the first row, the highlight starts at column 0. */
7244 if (i
== dpyinfo
->mouse_face_beg_row
)
7246 start_hpos
= dpyinfo
->mouse_face_beg_col
;
7247 start_x
= dpyinfo
->mouse_face_beg_x
;
7255 if (i
== dpyinfo
->mouse_face_end_row
)
7256 end_hpos
= dpyinfo
->mouse_face_end_col
;
7258 end_hpos
= row
->used
[TEXT_AREA
];
7260 /* If the cursor's in the text we are about to rewrite, turn the
7262 if (!w
->pseudo_window_p
7263 && i
== output_cursor
.vpos
7264 && output_cursor
.hpos
>= start_hpos
- 1
7265 && output_cursor
.hpos
<= end_hpos
)
7267 x_update_window_cursor (w
, 0);
7271 if (end_hpos
> start_hpos
)
7273 row
->mouse_face_p
= draw
== DRAW_MOUSE_FACE
;
7274 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
7275 start_hpos
, end_hpos
, draw
, NULL
, NULL
, 0);
7279 /* If we turned the cursor off, turn it back on. */
7281 x_display_cursor (w
, 1,
7282 output_cursor
.hpos
, output_cursor
.vpos
,
7283 output_cursor
.x
, output_cursor
.y
);
7285 output_cursor
= saved_cursor
;
7289 /* Change the mouse cursor. */
7290 if (draw
== DRAW_NORMAL_TEXT
)
7291 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7292 f
->output_data
.x
->text_cursor
);
7293 else if (draw
== DRAW_MOUSE_FACE
)
7294 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7295 f
->output_data
.x
->cross_cursor
);
7297 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7298 f
->output_data
.x
->nontext_cursor
);
7301 /* Clear out the mouse-highlighted active region.
7302 Redraw it un-highlighted first. */
7305 clear_mouse_face (dpyinfo
)
7306 struct x_display_info
*dpyinfo
;
7308 #if 0 /* This prevents redrawing tool bar items when changing from one
7309 to another while a tooltip is open, so don't do it. */
7310 if (!NILP (tip_frame
))
7314 if (! NILP (dpyinfo
->mouse_face_window
))
7315 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
7317 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7318 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7319 dpyinfo
->mouse_face_window
= Qnil
;
7323 /* Clear any mouse-face on window W. This function is part of the
7324 redisplay interface, and is called from try_window_id and similar
7325 functions to ensure the mouse-highlight is off. */
7328 x_clear_mouse_face (w
)
7331 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
7335 XSETWINDOW (window
, w
);
7336 if (EQ (window
, dpyinfo
->mouse_face_window
))
7337 clear_mouse_face (dpyinfo
);
7342 /* Just discard the mouse face information for frame F, if any.
7343 This is used when the size of F is changed. */
7346 cancel_mouse_face (f
)
7350 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7352 window
= dpyinfo
->mouse_face_window
;
7353 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
7355 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7356 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7357 dpyinfo
->mouse_face_window
= Qnil
;
7361 static struct scroll_bar
*x_window_to_scroll_bar ();
7362 static void x_scroll_bar_report_motion ();
7364 /* Return the current position of the mouse.
7365 *fp should be a frame which indicates which display to ask about.
7367 If the mouse movement started in a scroll bar, set *fp, *bar_window,
7368 and *part to the frame, window, and scroll bar part that the mouse
7369 is over. Set *x and *y to the portion and whole of the mouse's
7370 position on the scroll bar.
7372 If the mouse movement started elsewhere, set *fp to the frame the
7373 mouse is on, *bar_window to nil, and *x and *y to the character cell
7376 Set *time to the server time-stamp for the time at which the mouse
7377 was at this position.
7379 Don't store anything if we don't have a valid set of values to report.
7381 This clears the mouse_moved flag, so we can wait for the next mouse
7385 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
7388 Lisp_Object
*bar_window
;
7389 enum scroll_bar_part
*part
;
7391 unsigned long *time
;
7397 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
7398 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
7404 Window dummy_window
;
7407 Lisp_Object frame
, tail
;
7409 /* Clear the mouse-moved flag for every frame on this display. */
7410 FOR_EACH_FRAME (tail
, frame
)
7411 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
7412 XFRAME (frame
)->mouse_moved
= 0;
7414 last_mouse_scroll_bar
= Qnil
;
7416 /* Figure out which root window we're on. */
7417 XQueryPointer (FRAME_X_DISPLAY (*fp
),
7418 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
7420 /* The root window which contains the pointer. */
7423 /* Trash which we can't trust if the pointer is on
7424 a different screen. */
7427 /* The position on that root window. */
7430 /* More trash we can't trust. */
7433 /* Modifier keys and pointer buttons, about which
7435 (unsigned int *) &dummy
);
7437 /* Now we have a position on the root; find the innermost window
7438 containing the pointer. */
7442 int parent_x
= 0, parent_y
= 0;
7447 /* XTranslateCoordinates can get errors if the window
7448 structure is changing at the same time this function
7449 is running. So at least we must not crash from them. */
7451 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
7453 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
7454 && FRAME_LIVE_P (last_mouse_frame
))
7456 /* If mouse was grabbed on a frame, give coords for that frame
7457 even if the mouse is now outside it. */
7458 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7460 /* From-window, to-window. */
7461 root
, FRAME_X_WINDOW (last_mouse_frame
),
7463 /* From-position, to-position. */
7464 root_x
, root_y
, &win_x
, &win_y
,
7468 f1
= last_mouse_frame
;
7474 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7476 /* From-window, to-window. */
7479 /* From-position, to-position. */
7480 root_x
, root_y
, &win_x
, &win_y
,
7485 if (child
== None
|| child
== win
)
7493 /* Now we know that:
7494 win is the innermost window containing the pointer
7495 (XTC says it has no child containing the pointer),
7496 win_x and win_y are the pointer's position in it
7497 (XTC did this the last time through), and
7498 parent_x and parent_y are the pointer's position in win's parent.
7499 (They are what win_x and win_y were when win was child.
7500 If win is the root window, it has no parent, and
7501 parent_{x,y} are invalid, but that's okay, because we'll
7502 never use them in that case.) */
7504 /* Is win one of our frames? */
7505 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
7507 #ifdef USE_X_TOOLKIT
7508 /* If we end up with the menu bar window, say it's not
7511 && f1
->output_data
.x
->menubar_widget
7512 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
7514 #endif /* USE_X_TOOLKIT */
7517 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
7520 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
7522 /* If not, is it one of our scroll bars? */
7525 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
7529 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7535 if (f1
== 0 && insist
> 0)
7536 f1
= SELECTED_FRAME ();
7540 /* Ok, we found a frame. Store all the values.
7541 last_mouse_glyph is a rectangle used to reduce the
7542 generation of mouse events. To not miss any motion
7543 events, we must divide the frame into rectangles of the
7544 size of the smallest character that could be displayed
7545 on it, i.e. into the same rectangles that matrices on
7546 the frame are divided into. */
7548 #if OLD_REDISPLAY_CODE
7549 int ignore1
, ignore2
;
7550 pixel_to_glyph_coords (f1
, win_x
, win_y
, &ignore1
, &ignore2
,
7552 FRAME_X_DISPLAY_INFO (f1
)->grabbed
7556 int width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
7557 int height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
7561 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
7562 round down even for negative values. */
7568 last_mouse_glyph
.width
= width
;
7569 last_mouse_glyph
.height
= height
;
7570 last_mouse_glyph
.x
= (x
+ width
- 1) / width
* width
;
7571 last_mouse_glyph
.y
= (y
+ height
- 1) / height
* height
;
7578 XSETINT (*x
, win_x
);
7579 XSETINT (*y
, win_y
);
7580 *time
= last_mouse_movement_time
;
7589 #ifdef USE_X_TOOLKIT
7591 /* Atimer callback function for TIMER. Called every 0.1s to process
7592 Xt timeouts, if needed. We must avoid calling XtAppPending as
7593 much as possible because that function does an implicit XFlush
7594 that slows us down. */
7597 x_process_timeouts (timer
)
7598 struct atimer
*timer
;
7600 if (toolkit_scroll_bar_interaction
|| popup_activated_flag
)
7603 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
7604 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
7609 #endif /* USE_X_TOOLKIT */
7612 /* Scroll bar support. */
7614 /* Given an X window ID, find the struct scroll_bar which manages it.
7615 This can be called in GC, so we have to make sure to strip off mark
7618 static struct scroll_bar
*
7619 x_window_to_scroll_bar (window_id
)
7624 for (tail
= Vframe_list
;
7625 XGCTYPE (tail
) == Lisp_Cons
;
7628 Lisp_Object frame
, bar
, condemned
;
7630 frame
= XCAR (tail
);
7631 /* All elements of Vframe_list should be frames. */
7632 if (! GC_FRAMEP (frame
))
7635 /* Scan this frame's scroll bar list for a scroll bar with the
7637 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
7638 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
7639 /* This trick allows us to search both the ordinary and
7640 condemned scroll bar lists with one loop. */
7641 ! GC_NILP (bar
) || (bar
= condemned
,
7644 bar
= XSCROLL_BAR (bar
)->next
)
7645 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
7646 return XSCROLL_BAR (bar
);
7654 /************************************************************************
7656 ************************************************************************/
7658 #ifdef USE_TOOLKIT_SCROLL_BARS
7660 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
7661 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
7662 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
7663 struct scroll_bar
*));
7664 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
7668 /* Id of action hook installed for scroll bars. */
7670 static XtActionHookId action_hook_id
;
7672 /* Lisp window being scrolled. Set when starting to interact with
7673 a toolkit scroll bar, reset to nil when ending the interaction. */
7675 static Lisp_Object window_being_scrolled
;
7677 /* Last scroll bar part sent in xm_scroll_callback. */
7679 static int last_scroll_bar_part
;
7681 /* Whether this is an Xaw with arrow-scrollbars. This should imply
7682 that movements of 1/20 of the screen size are mapped to up/down. */
7684 static Boolean xaw3d_arrow_scroll
;
7686 /* Whether the drag scrolling maintains the mouse at the top of the
7687 thumb. If not, resizing the thumb needs to be done more carefully
7688 to avoid jerkyness. */
7690 static Boolean xaw3d_pick_top
;
7693 /* Action hook installed via XtAppAddActionHook when toolkit scroll
7694 bars are used.. The hook is responsible for detecting when
7695 the user ends an interaction with the scroll bar, and generates
7696 a `end-scroll' scroll_bar_click' event if so. */
7699 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
7702 XtPointer client_data
;
7706 Cardinal
*num_params
;
7712 scroll_bar_p
= XmIsScrollBar (widget
);
7713 end_action
= "Release";
7714 #else /* !USE_MOTIF i.e. use Xaw */
7715 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
7716 end_action
= "EndScroll";
7717 #endif /* USE_MOTIF */
7720 && strcmp (action_name
, end_action
) == 0
7721 && WINDOWP (window_being_scrolled
))
7725 x_send_scroll_bar_event (window_being_scrolled
,
7726 scroll_bar_end_scroll
, 0, 0);
7727 w
= XWINDOW (window_being_scrolled
);
7728 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
7729 window_being_scrolled
= Qnil
;
7730 last_scroll_bar_part
= -1;
7732 /* Xt timeouts no longer needed. */
7733 toolkit_scroll_bar_interaction
= 0;
7737 /* A vector of windows used for communication between
7738 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
7740 static struct window
**scroll_bar_windows
;
7741 static int scroll_bar_windows_size
;
7744 /* Send a client message with message type Xatom_Scrollbar for a
7745 scroll action to the frame of WINDOW. PART is a value identifying
7746 the part of the scroll bar that was clicked on. PORTION is the
7747 amount to scroll of a whole of WHOLE. */
7750 x_send_scroll_bar_event (window
, part
, portion
, whole
)
7752 int part
, portion
, whole
;
7755 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
7756 struct window
*w
= XWINDOW (window
);
7757 struct frame
*f
= XFRAME (w
->frame
);
7762 /* Construct a ClientMessage event to send to the frame. */
7763 ev
->type
= ClientMessage
;
7764 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
7765 ev
->display
= FRAME_X_DISPLAY (f
);
7766 ev
->window
= FRAME_X_WINDOW (f
);
7769 /* We can only transfer 32 bits in the XClientMessageEvent, which is
7770 not enough to store a pointer or Lisp_Object on a 64 bit system.
7771 So, store the window in scroll_bar_windows and pass the index
7772 into that array in the event. */
7773 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
7774 if (scroll_bar_windows
[i
] == NULL
)
7777 if (i
== scroll_bar_windows_size
)
7779 int new_size
= max (10, 2 * scroll_bar_windows_size
);
7780 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
7781 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
7783 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
7785 bzero (&scroll_bar_windows
[i
], nbytes
- old_nbytes
);
7786 scroll_bar_windows_size
= new_size
;
7789 scroll_bar_windows
[i
] = w
;
7790 ev
->data
.l
[0] = (long) i
;
7791 ev
->data
.l
[1] = (long) part
;
7792 ev
->data
.l
[2] = (long) 0;
7793 ev
->data
.l
[3] = (long) portion
;
7794 ev
->data
.l
[4] = (long) whole
;
7796 /* Make Xt timeouts work while the scroll bar is active. */
7797 toolkit_scroll_bar_interaction
= 1;
7799 /* Setting the event mask to zero means that the message will
7800 be sent to the client that created the window, and if that
7801 window no longer exists, no event will be sent. */
7802 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
7807 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
7811 x_scroll_bar_to_input_event (event
, ievent
)
7813 struct input_event
*ievent
;
7815 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
7820 w
= scroll_bar_windows
[ev
->data
.l
[0]];
7821 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
7823 XSETWINDOW (window
, w
);
7824 f
= XFRAME (w
->frame
);
7826 ievent
->kind
= scroll_bar_click
;
7827 ievent
->frame_or_window
= window
;
7829 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
7830 ievent
->part
= ev
->data
.l
[1];
7831 ievent
->code
= ev
->data
.l
[2];
7832 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
7833 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
7834 ievent
->modifiers
= 0;
7840 /* Minimum and maximum values used for Motif scroll bars. */
7843 #define XM_SB_MAX 10000000
7844 #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN)
7847 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
7848 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
7849 CALL_DATA is a pointer a a XmScrollBarCallbackStruct. */
7852 xm_scroll_callback (widget
, client_data
, call_data
)
7854 XtPointer client_data
, call_data
;
7856 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7857 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
7859 int part
= -1, whole
= 0, portion
= 0;
7863 case XmCR_DECREMENT
:
7864 bar
->dragging
= Qnil
;
7865 part
= scroll_bar_up_arrow
;
7868 case XmCR_INCREMENT
:
7869 bar
->dragging
= Qnil
;
7870 part
= scroll_bar_down_arrow
;
7873 case XmCR_PAGE_DECREMENT
:
7874 bar
->dragging
= Qnil
;
7875 part
= scroll_bar_above_handle
;
7878 case XmCR_PAGE_INCREMENT
:
7879 bar
->dragging
= Qnil
;
7880 part
= scroll_bar_below_handle
;
7884 bar
->dragging
= Qnil
;
7885 part
= scroll_bar_to_top
;
7888 case XmCR_TO_BOTTOM
:
7889 bar
->dragging
= Qnil
;
7890 part
= scroll_bar_to_bottom
;
7896 int dragging_down_p
= (INTEGERP (bar
->dragging
)
7897 && XINT (bar
->dragging
) <= cs
->value
);
7899 /* Get the slider size. */
7901 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
7904 /* At the max position of the scroll bar, do a line-wise
7905 movement. Without doing anything, the LessTif scroll bar
7906 calls us with the same cs->value again and again. If we
7907 want to make sure that we can reach the end of the buffer,
7908 we have to do something.
7910 Implementation note: setting bar->dragging always to
7911 cs->value gives a smoother movement at the max position.
7912 Setting it to nil when doing line-wise movement gives
7913 a better slider behavior. */
7915 if (cs
->value
+ slider_size
== XM_SB_MAX
7917 && last_scroll_bar_part
== scroll_bar_down_arrow
))
7919 part
= scroll_bar_down_arrow
;
7920 bar
->dragging
= Qnil
;
7924 whole
= XM_SB_RANGE
;
7925 portion
= min (cs
->value
- XM_SB_MIN
, XM_SB_MAX
- slider_size
);
7926 part
= scroll_bar_handle
;
7927 bar
->dragging
= make_number (cs
->value
);
7932 case XmCR_VALUE_CHANGED
:
7938 window_being_scrolled
= bar
->window
;
7939 last_scroll_bar_part
= part
;
7940 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
7945 #else /* !USE_MOTIF, i.e. Xaw. */
7948 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
7949 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
7950 scroll bar struct. CALL_DATA is a pointer to a float saying where
7954 xaw_jump_callback (widget
, client_data
, call_data
)
7956 XtPointer client_data
, call_data
;
7958 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7959 float top
= *(float *) call_data
;
7961 int whole
, portion
, height
;
7964 /* Get the size of the thumb, a value between 0 and 1. */
7966 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
7970 portion
= shown
< 1 ? top
* whole
: 0;
7972 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
7973 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
7974 the bottom, so we force the scrolling whenever we see that we're
7975 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
7976 we try to ensure that we always stay two pixels away from the
7978 part
= scroll_bar_down_arrow
;
7980 part
= scroll_bar_handle
;
7982 window_being_scrolled
= bar
->window
;
7983 bar
->dragging
= make_number (portion
);
7984 last_scroll_bar_part
= part
;
7985 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
7989 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
7990 i.e. line or page up or down. WIDGET is the Xaw scroll bar
7991 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
7992 the scroll bar. CALL_DATA is an integer specifying the action that
7993 has taken place. It's magnitude is in the range 0..height of the
7994 scroll bar. Negative values mean scroll towards buffer start.
7995 Values < height of scroll bar mean line-wise movement. */
7998 xaw_scroll_callback (widget
, client_data
, call_data
)
8000 XtPointer client_data
, call_data
;
8002 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
8003 int position
= (int) call_data
;
8007 /* Get the height of the scroll bar. */
8009 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
8012 if (abs (position
) >= height
)
8013 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
8015 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
8016 it maps line-movement to call_data = max(5, height/20). */
8017 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
8018 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
8020 part
= scroll_bar_move_ratio
;
8022 window_being_scrolled
= bar
->window
;
8023 bar
->dragging
= Qnil
;
8024 last_scroll_bar_part
= part
;
8025 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
8029 #endif /* not USE_MOTIF */
8032 /* Create the widget for scroll bar BAR on frame F. Record the widget
8033 and X window of the scroll bar in BAR. */
8036 x_create_toolkit_scroll_bar (f
, bar
)
8038 struct scroll_bar
*bar
;
8044 char *scroll_bar_name
= "verticalScrollBar";
8045 unsigned long pixel
;
8050 /* LessTif 0.85, problems:
8052 1. When the mouse if over the scroll bar, the scroll bar will
8053 get keyboard events. I didn't find a way to turn this off.
8055 2. Do we have to explicitly set the cursor to get an arrow
8056 cursor (see below)? */
8058 /* Set resources. Create the widget. */
8059 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
8060 XtSetArg (av
[ac
], XmNminimum
, XM_SB_MIN
); ++ac
;
8061 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
8062 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
8063 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
8064 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
8065 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
8067 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
8070 XtSetArg (av
[ac
], XmNforeground
, pixel
);
8074 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8077 XtSetArg (av
[ac
], XmNbackground
, pixel
);
8081 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
8082 scroll_bar_name
, av
, ac
);
8084 /* Add one callback for everything that can happen. */
8085 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
8087 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
8089 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
8091 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
8093 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
8095 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
8097 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
8100 /* Realize the widget. Only after that is the X window created. */
8101 XtRealizeWidget (widget
);
8103 /* Set the cursor to an arrow. I didn't find a resource to do that.
8104 And I'm wondering why it hasn't an arrow cursor by default. */
8105 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
8106 f
->output_data
.x
->nontext_cursor
);
8108 #else /* !USE_MOTIF i.e. use Xaw */
8110 /* Set resources. Create the widget. The background of the
8111 Xaw3d scroll bar widget is a little bit light for my taste.
8112 We don't alter it here to let users change it according
8113 to their taste with `emacs*verticalScrollBar.background: xxx'. */
8114 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
8115 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
8116 /* For smoother scrolling with Xaw3d -sm */
8117 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
8118 /* XtSetArg (av[ac], XtNbeNiceToColormap, True); ++ac; */
8120 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
8123 XtSetArg (av
[ac
], XtNforeground
, pixel
);
8127 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8130 XtSetArg (av
[ac
], XtNbackground
, pixel
);
8134 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
8135 f
->output_data
.x
->edit_widget
, av
, ac
);
8139 char *val
= initial
;
8140 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
8141 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
8143 { /* ARROW_SCROLL */
8144 xaw3d_arrow_scroll
= True
;
8145 /* Isn't that just a personal preference ? -sm */
8146 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
8150 /* Define callbacks. */
8151 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
8152 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
8155 /* Realize the widget. Only after that is the X window created. */
8156 XtRealizeWidget (widget
);
8158 #endif /* !USE_MOTIF */
8160 /* Install an action hook that let's us detect when the user
8161 finishes interacting with a scroll bar. */
8162 if (action_hook_id
== 0)
8163 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
8165 /* Remember X window and widget in the scroll bar vector. */
8166 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
8167 xwindow
= XtWindow (widget
);
8168 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
8174 /* Set the thumb size and position of scroll bar BAR. We are currently
8175 displaying PORTION out of a whole WHOLE, and our position POSITION. */
8178 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
8179 struct scroll_bar
*bar
;
8180 int portion
, position
, whole
;
8182 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8183 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
8190 top
= (float) position
/ whole
;
8191 shown
= (float) portion
/ whole
;
8199 Boolean arrow1_selected
, arrow2_selected
;
8200 unsigned char flags
;
8201 XmScrollBarWidget sb
;
8203 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
8204 is the scroll bar's maximum and MIN is the scroll bar's minimum
8206 size
= shown
* XM_SB_RANGE
;
8207 size
= min (size
, XM_SB_RANGE
);
8208 size
= max (size
, 1);
8210 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
8211 value
= top
* XM_SB_RANGE
;
8212 value
= min (value
, XM_SB_MAX
- size
);
8213 value
= max (value
, XM_SB_MIN
);
8215 /* LessTif: Calling XmScrollBarSetValues after an increment or
8216 decrement turns off auto-repeat LessTif-internally. This can
8217 be seen in ScrollBar.c which resets Arrow1Selected and
8218 Arrow2Selected. It also sets internal flags so that LessTif
8219 believes the mouse is in the slider. We either have to change
8220 our code, or work around that by accessing private data. */
8222 sb
= (XmScrollBarWidget
) widget
;
8223 arrow1_selected
= sb
->scrollBar
.arrow1_selected
;
8224 arrow2_selected
= sb
->scrollBar
.arrow2_selected
;
8225 flags
= sb
->scrollBar
.flags
;
8227 if (NILP (bar
->dragging
))
8228 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
8229 else if (last_scroll_bar_part
== scroll_bar_down_arrow
)
8230 /* This has the negative side effect that the slider value is
8231 not what it would be if we scrolled here using line-wise or
8232 page-wise movement. */
8233 XmScrollBarSetValues (widget
, value
, XM_SB_RANGE
- value
, 0, 0, False
);
8236 /* If currently dragging, only update the slider size.
8237 This reduces flicker effects. */
8238 int old_value
, old_size
, increment
, page_increment
;
8240 XmScrollBarGetValues (widget
, &old_value
, &old_size
,
8241 &increment
, &page_increment
);
8242 XmScrollBarSetValues (widget
, old_value
,
8243 min (size
, XM_SB_RANGE
- old_value
),
8247 sb
->scrollBar
.arrow1_selected
= arrow1_selected
;
8248 sb
->scrollBar
.arrow2_selected
= arrow2_selected
;
8249 sb
->scrollBar
.flags
= flags
;
8251 #else /* !USE_MOTIF i.e. use Xaw */
8253 float old_top
, old_shown
;
8255 XtVaGetValues (widget
,
8256 XtNtopOfThumb
, &old_top
,
8257 XtNshown
, &old_shown
,
8261 /* Massage the top+shown values. */
8262 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
8263 top
= max (0, min (1, top
));
8266 /* Keep two pixels available for moving the thumb down. */
8267 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
8269 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
8270 check that your system's configuration file contains a define
8271 for `NARROWPROTO'. See s/freebsd.h for an example. */
8272 if (top
!= old_top
|| shown
!= old_shown
)
8274 if (NILP (bar
->dragging
))
8275 XawScrollbarSetThumb (widget
, top
, shown
);
8279 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
8280 int scroll_mode
= 0;
8282 /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR. */
8283 if (xaw3d_arrow_scroll
)
8285 /* Xaw3d stupidly ignores resize requests while dragging
8286 so we have to make it believe it's not in dragging mode. */
8287 scroll_mode
= sb
->scrollbar
.scroll_mode
;
8288 if (scroll_mode
== 2)
8289 sb
->scrollbar
.scroll_mode
= 0;
8292 /* Try to make the scrolling a tad smoother. */
8293 if (!xaw3d_pick_top
)
8294 shown
= min (shown
, old_shown
);
8296 XawScrollbarSetThumb (widget
, top
, shown
);
8299 if (xaw3d_arrow_scroll
&& scroll_mode
== 2)
8300 sb
->scrollbar
.scroll_mode
= scroll_mode
;
8305 #endif /* !USE_MOTIF */
8310 #endif /* USE_TOOLKIT_SCROLL_BARS */
8314 /************************************************************************
8315 Scroll bars, general
8316 ************************************************************************/
8318 /* Create a scroll bar and return the scroll bar vector for it. W is
8319 the Emacs window on which to create the scroll bar. TOP, LEFT,
8320 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
8323 static struct scroll_bar
*
8324 x_scroll_bar_create (w
, top
, left
, width
, height
)
8326 int top
, left
, width
, height
;
8328 struct frame
*f
= XFRAME (w
->frame
);
8329 struct scroll_bar
*bar
8330 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
8334 #ifdef USE_TOOLKIT_SCROLL_BARS
8335 x_create_toolkit_scroll_bar (f
, bar
);
8336 #else /* not USE_TOOLKIT_SCROLL_BARS */
8338 XSetWindowAttributes a
;
8342 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8343 if (a
.background_pixel
== -1)
8344 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
8346 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
8347 | ButtonMotionMask
| PointerMotionHintMask
8349 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
8351 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
8353 /* Clear the area of W that will serve as a scroll bar. This is
8354 for the case that a window has been split horizontally. In
8355 this case, no clear_frame is generated to reduce flickering. */
8356 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8358 window_box_height (w
), False
);
8360 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8361 /* Position and size of scroll bar. */
8362 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8364 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8366 /* Border width, depth, class, and visual. */
8373 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
8375 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8377 XSETWINDOW (bar
->window
, w
);
8378 XSETINT (bar
->top
, top
);
8379 XSETINT (bar
->left
, left
);
8380 XSETINT (bar
->width
, width
);
8381 XSETINT (bar
->height
, height
);
8382 XSETINT (bar
->start
, 0);
8383 XSETINT (bar
->end
, 0);
8384 bar
->dragging
= Qnil
;
8386 /* Add bar to its frame's list of scroll bars. */
8387 bar
->next
= FRAME_SCROLL_BARS (f
);
8389 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8390 if (!NILP (bar
->next
))
8391 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8393 /* Map the window/widget. */
8394 #ifdef USE_TOOLKIT_SCROLL_BARS
8396 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
8397 XtConfigureWidget (scroll_bar
,
8398 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8400 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8402 XtMapWidget (scroll_bar
);
8404 #else /* not USE_TOOLKIT_SCROLL_BARS */
8405 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
8406 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8413 /* Draw BAR's handle in the proper position.
8415 If the handle is already drawn from START to END, don't bother
8416 redrawing it, unless REBUILD is non-zero; in that case, always
8417 redraw it. (REBUILD is handy for drawing the handle after expose
8420 Normally, we want to constrain the start and end of the handle to
8421 fit inside its rectangle, but if the user is dragging the scroll
8422 bar handle, we want to let them drag it down all the way, so that
8423 the bar's top is as far down as it goes; otherwise, there's no way
8424 to move to the very end of the buffer. */
8426 #ifndef USE_TOOLKIT_SCROLL_BARS
8429 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
8430 struct scroll_bar
*bar
;
8434 int dragging
= ! NILP (bar
->dragging
);
8435 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8436 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8437 GC gc
= f
->output_data
.x
->normal_gc
;
8439 /* If the display is already accurate, do nothing. */
8441 && start
== XINT (bar
->start
)
8442 && end
== XINT (bar
->end
))
8448 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
8449 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8450 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8452 /* Make sure the values are reasonable, and try to preserve
8453 the distance between start and end. */
8455 int length
= end
- start
;
8459 else if (start
> top_range
)
8461 end
= start
+ length
;
8465 else if (end
> top_range
&& ! dragging
)
8469 /* Store the adjusted setting in the scroll bar. */
8470 XSETINT (bar
->start
, start
);
8471 XSETINT (bar
->end
, end
);
8473 /* Clip the end position, just for display. */
8474 if (end
> top_range
)
8477 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
8478 below top positions, to make sure the handle is always at least
8479 that many pixels tall. */
8480 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
8482 /* Draw the empty space above the handle. Note that we can't clear
8483 zero-height areas; that means "clear to end of window." */
8485 x_clear_area (FRAME_X_DISPLAY (f
), w
,
8486 /* x, y, width, height, and exposures. */
8487 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8488 VERTICAL_SCROLL_BAR_TOP_BORDER
,
8489 inside_width
, start
,
8492 /* Change to proper foreground color if one is specified. */
8493 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8494 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8495 f
->output_data
.x
->scroll_bar_foreground_pixel
);
8497 /* Draw the handle itself. */
8498 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
8500 /* x, y, width, height */
8501 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8502 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
8503 inside_width
, end
- start
);
8505 /* Restore the foreground color of the GC if we changed it above. */
8506 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8507 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8508 f
->output_data
.x
->foreground_pixel
);
8510 /* Draw the empty space below the handle. Note that we can't
8511 clear zero-height areas; that means "clear to end of window." */
8512 if (end
< inside_height
)
8513 x_clear_area (FRAME_X_DISPLAY (f
), w
,
8514 /* x, y, width, height, and exposures. */
8515 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8516 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
8517 inside_width
, inside_height
- end
,
8525 #endif /* !USE_TOOLKIT_SCROLL_BARS */
8527 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
8531 x_scroll_bar_remove (bar
)
8532 struct scroll_bar
*bar
;
8534 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8537 #ifdef USE_TOOLKIT_SCROLL_BARS
8538 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
8540 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
8543 /* Disassociate this scroll bar from its window. */
8544 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
8550 /* Set the handle of the vertical scroll bar for WINDOW to indicate
8551 that we are displaying PORTION characters out of a total of WHOLE
8552 characters, starting at POSITION. If WINDOW has no scroll bar,
8556 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
8558 int portion
, whole
, position
;
8560 struct frame
*f
= XFRAME (w
->frame
);
8561 struct scroll_bar
*bar
;
8562 int top
, height
, left
, sb_left
, width
, sb_width
;
8563 int window_x
, window_y
, window_width
, window_height
;
8565 /* Get window dimensions. */
8566 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
8568 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
8569 height
= window_height
;
8571 /* Compute the left edge of the scroll bar area. */
8572 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8573 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
8575 left
= XFASTINT (w
->left
);
8576 left
*= CANON_X_UNIT (f
);
8577 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
8579 /* Compute the width of the scroll bar which might be less than
8580 the width of the area reserved for the scroll bar. */
8581 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
8582 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
8586 /* Compute the left edge of the scroll bar. */
8587 #ifdef USE_TOOLKIT_SCROLL_BARS
8588 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8589 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
8591 sb_left
= left
+ (width
- sb_width
) / 2;
8593 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8594 sb_left
= left
+ width
- sb_width
;
8599 /* Does the scroll bar exist yet? */
8600 if (NILP (w
->vertical_scroll_bar
))
8603 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8604 left
, top
, width
, height
, False
);
8606 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
8610 /* It may just need to be moved and resized. */
8611 unsigned int mask
= 0;
8613 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
8617 if (sb_left
!= XINT (bar
->left
))
8619 if (top
!= XINT (bar
->top
))
8621 if (sb_width
!= XINT (bar
->width
))
8623 if (height
!= XINT (bar
->height
))
8626 #ifdef USE_TOOLKIT_SCROLL_BARS
8628 /* Since toolkit scroll bars are smaller than the space reserved
8629 for them on the frame, we have to clear "under" them. */
8630 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8631 left
, top
, width
, height
, False
);
8633 /* Move/size the scroll bar widget. */
8635 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
8636 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8638 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8641 #else /* not USE_TOOLKIT_SCROLL_BARS */
8643 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
8645 /* Clear areas not covered by the scroll bar. This makes sure a
8646 previous mode line display is cleared after C-x 2 C-x 1, for
8647 example. Non-toolkit scroll bars are as wide as the area
8648 reserved for scroll bars - trim at both sides. */
8649 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8650 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8652 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8653 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8654 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8658 /* Move/size the scroll bar window. */
8663 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
8665 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
8667 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
8671 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8673 /* Remember new settings. */
8674 XSETINT (bar
->left
, sb_left
);
8675 XSETINT (bar
->top
, top
);
8676 XSETINT (bar
->width
, sb_width
);
8677 XSETINT (bar
->height
, height
);
8682 #ifdef USE_TOOLKIT_SCROLL_BARS
8683 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
8684 #else /* not USE_TOOLKIT_SCROLL_BARS */
8685 /* Set the scroll bar's current state, unless we're currently being
8687 if (NILP (bar
->dragging
))
8689 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
8692 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
8695 int start
= ((double) position
* top_range
) / whole
;
8696 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
8697 x_scroll_bar_set_handle (bar
, start
, end
, 0);
8700 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8702 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
8706 /* The following three hooks are used when we're doing a thorough
8707 redisplay of the frame. We don't explicitly know which scroll bars
8708 are going to be deleted, because keeping track of when windows go
8709 away is a real pain - "Can you say set-window-configuration, boys
8710 and girls?" Instead, we just assert at the beginning of redisplay
8711 that *all* scroll bars are to be removed, and then save a scroll bar
8712 from the fiery pit when we actually redisplay its window. */
8714 /* Arrange for all scroll bars on FRAME to be removed at the next call
8715 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
8716 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
8719 XTcondemn_scroll_bars (frame
)
8722 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
8723 while (! NILP (FRAME_SCROLL_BARS (frame
)))
8726 bar
= FRAME_SCROLL_BARS (frame
);
8727 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
8728 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
8729 XSCROLL_BAR (bar
)->prev
= Qnil
;
8730 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
8731 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
8732 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
8737 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
8738 Note that WINDOW isn't necessarily condemned at all. */
8741 XTredeem_scroll_bar (window
)
8742 struct window
*window
;
8744 struct scroll_bar
*bar
;
8747 /* We can't redeem this window's scroll bar if it doesn't have one. */
8748 if (NILP (window
->vertical_scroll_bar
))
8751 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
8753 /* Unlink it from the condemned list. */
8754 f
= XFRAME (WINDOW_FRAME (window
));
8755 if (NILP (bar
->prev
))
8757 /* If the prev pointer is nil, it must be the first in one of
8759 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
8760 /* It's not condemned. Everything's fine. */
8762 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
8763 window
->vertical_scroll_bar
))
8764 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
8766 /* If its prev pointer is nil, it must be at the front of
8767 one or the other! */
8771 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
8773 if (! NILP (bar
->next
))
8774 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
8776 bar
->next
= FRAME_SCROLL_BARS (f
);
8778 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8779 if (! NILP (bar
->next
))
8780 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8783 /* Remove all scroll bars on FRAME that haven't been saved since the
8784 last call to `*condemn_scroll_bars_hook'. */
8787 XTjudge_scroll_bars (f
)
8790 Lisp_Object bar
, next
;
8792 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
8794 /* Clear out the condemned list now so we won't try to process any
8795 more events on the hapless scroll bars. */
8796 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
8798 for (; ! NILP (bar
); bar
= next
)
8800 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
8802 x_scroll_bar_remove (b
);
8805 b
->next
= b
->prev
= Qnil
;
8808 /* Now there should be no references to the condemned scroll bars,
8809 and they should get garbage-collected. */
8813 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
8814 is a no-op when using toolkit scroll bars.
8816 This may be called from a signal handler, so we have to ignore GC
8820 x_scroll_bar_expose (bar
, event
)
8821 struct scroll_bar
*bar
;
8824 #ifndef USE_TOOLKIT_SCROLL_BARS
8826 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8827 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8828 GC gc
= f
->output_data
.x
->normal_gc
;
8829 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
8833 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
8835 /* Draw a one-pixel border just inside the edges of the scroll bar. */
8836 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
8838 /* x, y, width, height */
8840 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
8841 XINT (bar
->height
) - 1);
8845 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8848 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
8849 is set to something other than no_event, it is enqueued.
8851 This may be called from a signal handler, so we have to ignore GC
8854 #ifndef USE_TOOLKIT_SCROLL_BARS
8857 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
8858 struct scroll_bar
*bar
;
8860 struct input_event
*emacs_event
;
8862 if (! GC_WINDOWP (bar
->window
))
8865 emacs_event
->kind
= scroll_bar_click
;
8866 emacs_event
->code
= event
->xbutton
.button
- Button1
;
8867 emacs_event
->modifiers
8868 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
8869 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
8870 event
->xbutton
.state
)
8871 | (event
->type
== ButtonRelease
8874 emacs_event
->frame_or_window
= bar
->window
;
8875 emacs_event
->arg
= Qnil
;
8876 emacs_event
->timestamp
= event
->xbutton
.time
;
8879 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8881 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8884 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8885 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
8888 if (y
> top_range
) y
= top_range
;
8890 if (y
< XINT (bar
->start
))
8891 emacs_event
->part
= scroll_bar_above_handle
;
8892 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
8893 emacs_event
->part
= scroll_bar_handle
;
8895 emacs_event
->part
= scroll_bar_below_handle
;
8897 /* Just because the user has clicked on the handle doesn't mean
8898 they want to drag it. Lisp code needs to be able to decide
8899 whether or not we're dragging. */
8901 /* If the user has just clicked on the handle, record where they're
8903 if (event
->type
== ButtonPress
8904 && emacs_event
->part
== scroll_bar_handle
)
8905 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
8908 /* If the user has released the handle, set it to its final position. */
8909 if (event
->type
== ButtonRelease
8910 && ! NILP (bar
->dragging
))
8912 int new_start
= y
- XINT (bar
->dragging
);
8913 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8915 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8916 bar
->dragging
= Qnil
;
8919 /* Same deal here as the other #if 0. */
8921 /* Clicks on the handle are always reported as occurring at the top of
8923 if (emacs_event
->part
== scroll_bar_handle
)
8924 emacs_event
->x
= bar
->start
;
8926 XSETINT (emacs_event
->x
, y
);
8928 XSETINT (emacs_event
->x
, y
);
8931 XSETINT (emacs_event
->y
, top_range
);
8935 /* Handle some mouse motion while someone is dragging the scroll bar.
8937 This may be called from a signal handler, so we have to ignore GC
8941 x_scroll_bar_note_movement (bar
, event
)
8942 struct scroll_bar
*bar
;
8945 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
8947 last_mouse_movement_time
= event
->xmotion
.time
;
8950 XSETVECTOR (last_mouse_scroll_bar
, bar
);
8952 /* If we're dragging the bar, display it. */
8953 if (! GC_NILP (bar
->dragging
))
8955 /* Where should the handle be now? */
8956 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
8958 if (new_start
!= XINT (bar
->start
))
8960 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8962 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8967 #endif /* !USE_TOOLKIT_SCROLL_BARS */
8969 /* Return information to the user about the current position of the mouse
8970 on the scroll bar. */
8973 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
8975 Lisp_Object
*bar_window
;
8976 enum scroll_bar_part
*part
;
8978 unsigned long *time
;
8980 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
8981 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8982 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8984 Window dummy_window
;
8986 unsigned int dummy_mask
;
8990 /* Get the mouse's position relative to the scroll bar window, and
8992 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
8994 /* Root, child, root x and root y. */
8995 &dummy_window
, &dummy_window
,
8996 &dummy_coord
, &dummy_coord
,
8998 /* Position relative to scroll bar. */
9001 /* Mouse buttons and modifier keys. */
9008 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
9011 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
9013 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
9015 if (! NILP (bar
->dragging
))
9016 win_y
-= XINT (bar
->dragging
);
9020 if (win_y
> top_range
)
9024 *bar_window
= bar
->window
;
9026 if (! NILP (bar
->dragging
))
9027 *part
= scroll_bar_handle
;
9028 else if (win_y
< XINT (bar
->start
))
9029 *part
= scroll_bar_above_handle
;
9030 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
9031 *part
= scroll_bar_handle
;
9033 *part
= scroll_bar_below_handle
;
9035 XSETINT (*x
, win_y
);
9036 XSETINT (*y
, top_range
);
9039 last_mouse_scroll_bar
= Qnil
;
9042 *time
= last_mouse_movement_time
;
9048 /* The screen has been cleared so we may have changed foreground or
9049 background colors, and the scroll bars may need to be redrawn.
9050 Clear out the scroll bars, and ask for expose events, so we can
9054 x_scroll_bar_clear (f
)
9057 #ifndef USE_TOOLKIT_SCROLL_BARS
9060 /* We can have scroll bars even if this is 0,
9061 if we just turned off scroll bar mode.
9062 But in that case we should not clear them. */
9063 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9064 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
9065 bar
= XSCROLL_BAR (bar
)->next
)
9066 XClearArea (FRAME_X_DISPLAY (f
),
9067 SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
9069 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9072 /* This processes Expose events from the menu-bar specific X event
9073 loop in xmenu.c. This allows to redisplay the frame if necessary
9074 when handling menu-bar or pop-up items. */
9077 process_expose_from_menu (event
)
9081 struct x_display_info
*dpyinfo
;
9082 int frame_exposed_p
= 0;
9086 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
9087 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
9090 if (f
->async_visible
== 0)
9092 f
->async_visible
= 1;
9093 f
->async_iconified
= 0;
9094 f
->output_data
.x
->has_been_visible
= 1;
9095 SET_FRAME_GARBAGED (f
);
9099 expose_frame (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
9100 event
.xexpose
.x
, event
.xexpose
.y
,
9101 event
.xexpose
.width
, event
.xexpose
.height
);
9102 frame_exposed_p
= 1;
9107 struct scroll_bar
*bar
9108 = x_window_to_scroll_bar (event
.xexpose
.window
);
9111 x_scroll_bar_expose (bar
, &event
);
9115 return frame_exposed_p
;
9118 /* Define a queue to save up SelectionRequest events for later handling. */
9120 struct selection_event_queue
9123 struct selection_event_queue
*next
;
9126 static struct selection_event_queue
*queue
;
9128 /* Nonzero means queue up certain events--don't process them yet. */
9130 static int x_queue_selection_requests
;
9132 /* Queue up an X event *EVENT, to be processed later. */
9135 x_queue_event (f
, event
)
9139 struct selection_event_queue
*queue_tmp
9140 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
9142 if (queue_tmp
!= NULL
)
9144 queue_tmp
->event
= *event
;
9145 queue_tmp
->next
= queue
;
9150 /* Take all the queued events and put them back
9151 so that they get processed afresh. */
9154 x_unqueue_events (display
)
9157 while (queue
!= NULL
)
9159 struct selection_event_queue
*queue_tmp
= queue
;
9160 XPutBackEvent (display
, &queue_tmp
->event
);
9161 queue
= queue_tmp
->next
;
9162 xfree ((char *)queue_tmp
);
9166 /* Start queuing SelectionRequest events. */
9169 x_start_queuing_selection_requests (display
)
9172 x_queue_selection_requests
++;
9175 /* Stop queuing SelectionRequest events. */
9178 x_stop_queuing_selection_requests (display
)
9181 x_queue_selection_requests
--;
9182 x_unqueue_events (display
);
9185 /* The main X event-reading loop - XTread_socket. */
9187 /* Time stamp of enter window event. This is only used by XTread_socket,
9188 but we have to put it out here, since static variables within functions
9189 sometimes don't work. */
9191 static Time enter_timestamp
;
9193 /* This holds the state XLookupString needs to implement dead keys
9194 and other tricks known as "compose processing". _X Window System_
9195 says that a portable program can't use this, but Stephen Gildea assures
9196 me that letting the compiler initialize it to zeros will work okay.
9198 This must be defined outside of XTread_socket, for the same reasons
9199 given for enter_time stamp, above. */
9201 static XComposeStatus compose_status
;
9203 /* Record the last 100 characters stored
9204 to help debug the loss-of-chars-during-GC problem. */
9206 static int temp_index
;
9207 static short temp_buffer
[100];
9209 /* Set this to nonzero to fake an "X I/O error"
9210 on a particular display. */
9212 struct x_display_info
*XTread_socket_fake_io_error
;
9214 /* When we find no input here, we occasionally do a no-op command
9215 to verify that the X server is still running and we can still talk with it.
9216 We try all the open displays, one by one.
9217 This variable is used for cycling thru the displays. */
9219 static struct x_display_info
*next_noop_dpyinfo
;
9221 #define SET_SAVED_MENU_EVENT(size) \
9224 if (f->output_data.x->saved_menu_event == 0) \
9225 f->output_data.x->saved_menu_event \
9226 = (XEvent *) xmalloc (sizeof (XEvent)); \
9227 bcopy (&event, f->output_data.x->saved_menu_event, size); \
9228 if (numchars >= 1) \
9230 bufp->kind = menu_bar_activate_event; \
9231 XSETFRAME (bufp->frame_or_window, f); \
9240 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
9241 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
9243 /* Read events coming from the X server.
9244 This routine is called by the SIGIO handler.
9245 We return as soon as there are no more events to be read.
9247 Events representing keys are stored in buffer BUFP,
9248 which can hold up to NUMCHARS characters.
9249 We return the number of characters stored into the buffer,
9250 thus pretending to be `read'.
9252 EXPECTED is nonzero if the caller knows input is available. */
9255 XTread_socket (sd
, bufp
, numchars
, expected
)
9257 /* register */ struct input_event
*bufp
;
9258 /* register */ int numchars
;
9265 int event_found
= 0;
9266 struct x_display_info
*dpyinfo
;
9267 struct coding_system coding
;
9269 if (interrupt_input_blocked
)
9271 interrupt_input_pending
= 1;
9275 interrupt_input_pending
= 0;
9278 /* So people can tell when we have read the available input. */
9279 input_signal_count
++;
9282 abort (); /* Don't think this happens. */
9286 /* The input should be decoded if it is from XIM. Currently the
9287 locale of XIM is the same as that of the system. So, we can use
9288 Vlocale_coding_system which is initialized properly at Emacs
9290 setup_coding_system (Vlocale_coding_system
, &coding
);
9291 coding
.src_multibyte
= 0;
9292 coding
.dst_multibyte
= 1;
9293 /* The input is converted to events, thus we can't handle
9294 composition. Anyway, there's no XIM that gives us composition
9296 coding
.composing
= COMPOSITION_DISABLED
;
9298 /* Find the display we are supposed to read input for.
9299 It's the one communicating on descriptor SD. */
9300 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
9302 #if 0 /* This ought to be unnecessary; let's verify it. */
9304 /* If available, Xlib uses FIOSNBIO to make the socket
9305 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
9306 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
9307 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
9308 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
9309 #endif /* ! defined (FIOSNBIO) */
9312 #if 0 /* This code can't be made to work, with multiple displays,
9313 and appears not to be used on any system any more.
9314 Also keyboard.c doesn't turn O_NDELAY on and off
9315 for X connections. */
9318 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
9320 extern int read_alarm_should_throw
;
9321 read_alarm_should_throw
= 1;
9322 XPeekEvent (dpyinfo
->display
, &event
);
9323 read_alarm_should_throw
= 0;
9325 #endif /* HAVE_SELECT */
9329 /* For debugging, this gives a way to fake an I/O error. */
9330 if (dpyinfo
== XTread_socket_fake_io_error
)
9332 XTread_socket_fake_io_error
= 0;
9333 x_io_error_quitter (dpyinfo
->display
);
9336 while (XPending (dpyinfo
->display
))
9338 XNextEvent (dpyinfo
->display
, &event
);
9342 /* Filter events for the current X input method.
9343 XFilterEvent returns non-zero if the input method has
9344 consumed the event. We pass the frame's X window to
9345 XFilterEvent because that's the one for which the IC
9347 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
9348 event
.xclient
.window
);
9349 if (XFilterEvent (&event
, f1
? FRAME_X_WINDOW (f1
) : None
))
9359 if (event
.xclient
.message_type
9360 == dpyinfo
->Xatom_wm_protocols
9361 && event
.xclient
.format
== 32)
9363 if (event
.xclient
.data
.l
[0]
9364 == dpyinfo
->Xatom_wm_take_focus
)
9366 /* Use x_any_window_to_frame because this
9367 could be the shell widget window
9368 if the frame has no title bar. */
9369 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9371 /* Not quite sure this is needed -pd */
9372 if (f
&& FRAME_XIC (f
))
9373 XSetICFocus (FRAME_XIC (f
));
9375 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
9376 instructs the WM to set the input focus automatically for
9377 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
9378 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
9379 it has set the focus. So, XSetInputFocus below is not
9382 The call to XSetInputFocus below has also caused trouble. In
9383 cases where the XSetInputFocus done by the WM and the one
9384 below are temporally close (on a fast machine), the call
9385 below can generate additional FocusIn events which confuse
9388 /* Since we set WM_TAKE_FOCUS, we must call
9389 XSetInputFocus explicitly. But not if f is null,
9390 since that might be an event for a deleted frame. */
9393 Display
*d
= event
.xclient
.display
;
9394 /* Catch and ignore errors, in case window has been
9395 iconified by a window manager such as GWM. */
9396 int count
= x_catch_errors (d
);
9397 XSetInputFocus (d
, event
.xclient
.window
,
9398 /* The ICCCM says this is
9399 the only valid choice. */
9401 event
.xclient
.data
.l
[1]);
9402 /* This is needed to detect the error
9403 if there is an error. */
9405 x_uncatch_errors (d
, count
);
9407 /* Not certain about handling scroll bars here */
9410 else if (event
.xclient
.data
.l
[0]
9411 == dpyinfo
->Xatom_wm_save_yourself
)
9413 /* Save state modify the WM_COMMAND property to
9414 something which can reinstate us. This notifies
9415 the session manager, who's looking for such a
9416 PropertyNotify. Can restart processing when
9417 a keyboard or mouse event arrives. */
9420 f
= x_top_window_to_frame (dpyinfo
,
9421 event
.xclient
.window
);
9423 /* This is just so we only give real data once
9424 for a single Emacs process. */
9425 if (f
== SELECTED_FRAME ())
9426 XSetCommand (FRAME_X_DISPLAY (f
),
9427 event
.xclient
.window
,
9428 initial_argv
, initial_argc
);
9430 XSetCommand (FRAME_X_DISPLAY (f
),
9431 event
.xclient
.window
,
9435 else if (event
.xclient
.data
.l
[0]
9436 == dpyinfo
->Xatom_wm_delete_window
)
9439 = x_any_window_to_frame (dpyinfo
,
9440 event
.xclient
.window
);
9447 bufp
->kind
= delete_window_event
;
9448 XSETFRAME (bufp
->frame_or_window
, f
);
9457 else if (event
.xclient
.message_type
9458 == dpyinfo
->Xatom_wm_configure_denied
)
9461 else if (event
.xclient
.message_type
9462 == dpyinfo
->Xatom_wm_window_moved
)
9466 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9468 new_x
= event
.xclient
.data
.s
[0];
9469 new_y
= event
.xclient
.data
.s
[1];
9473 f
->output_data
.x
->left_pos
= new_x
;
9474 f
->output_data
.x
->top_pos
= new_y
;
9478 else if (event
.xclient
.message_type
9479 == dpyinfo
->Xatom_editres
)
9482 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9483 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
9486 #endif /* HACK_EDITRES */
9487 else if ((event
.xclient
.message_type
9488 == dpyinfo
->Xatom_DONE
)
9489 || (event
.xclient
.message_type
9490 == dpyinfo
->Xatom_PAGE
))
9492 /* Ghostview job completed. Kill it. We could
9493 reply with "Next" if we received "Page", but we
9494 currently never do because we are interested in
9495 images, only, which should have 1 page. */
9496 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
9498 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9499 x_kill_gs_process (pixmap
, f
);
9500 expose_frame (f
, 0, 0, 0, 0);
9502 #ifdef USE_TOOLKIT_SCROLL_BARS
9503 /* Scroll bar callbacks send a ClientMessage from which
9504 we construct an input_event. */
9505 else if (event
.xclient
.message_type
9506 == dpyinfo
->Xatom_Scrollbar
)
9508 x_scroll_bar_to_input_event (&event
, bufp
);
9509 ++bufp
, ++count
, --numchars
;
9512 #endif /* USE_TOOLKIT_SCROLL_BARS */
9518 case SelectionNotify
:
9519 #ifdef USE_X_TOOLKIT
9520 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
9522 #endif /* not USE_X_TOOLKIT */
9523 x_handle_selection_notify (&event
.xselection
);
9526 case SelectionClear
: /* Someone has grabbed ownership. */
9527 #ifdef USE_X_TOOLKIT
9528 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
9530 #endif /* USE_X_TOOLKIT */
9532 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
9537 bufp
->kind
= selection_clear_event
;
9538 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
9539 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
9540 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
9541 bufp
->frame_or_window
= Qnil
;
9550 case SelectionRequest
: /* Someone wants our selection. */
9551 #ifdef USE_X_TOOLKIT
9552 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
9554 #endif /* USE_X_TOOLKIT */
9555 if (x_queue_selection_requests
)
9556 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
9560 XSelectionRequestEvent
*eventp
= (XSelectionRequestEvent
*) &event
;
9565 bufp
->kind
= selection_request_event
;
9566 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
9567 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
9568 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
9569 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
9570 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
9571 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
9572 bufp
->frame_or_window
= Qnil
;
9581 case PropertyNotify
:
9582 #ifdef USE_X_TOOLKIT
9583 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
9585 #endif /* not USE_X_TOOLKIT */
9586 x_handle_property_notify (&event
.xproperty
);
9589 case ReparentNotify
:
9590 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
9594 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
9595 x_real_positions (f
, &x
, &y
);
9596 f
->output_data
.x
->left_pos
= x
;
9597 f
->output_data
.x
->top_pos
= y
;
9602 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
9605 if (f
->async_visible
== 0)
9607 f
->async_visible
= 1;
9608 f
->async_iconified
= 0;
9609 f
->output_data
.x
->has_been_visible
= 1;
9610 SET_FRAME_GARBAGED (f
);
9613 expose_frame (x_window_to_frame (dpyinfo
,
9614 event
.xexpose
.window
),
9615 event
.xexpose
.x
, event
.xexpose
.y
,
9616 event
.xexpose
.width
, event
.xexpose
.height
);
9620 #ifdef USE_TOOLKIT_SCROLL_BARS
9621 /* Dispatch event to the widget. */
9623 #else /* not USE_TOOLKIT_SCROLL_BARS */
9624 struct scroll_bar
*bar
9625 = x_window_to_scroll_bar (event
.xexpose
.window
);
9628 x_scroll_bar_expose (bar
, &event
);
9629 #ifdef USE_X_TOOLKIT
9632 #endif /* USE_X_TOOLKIT */
9633 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9637 case GraphicsExpose
: /* This occurs when an XCopyArea's
9638 source area was obscured or not
9640 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
9644 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
9645 event
.xgraphicsexpose
.width
,
9646 event
.xgraphicsexpose
.height
);
9648 #ifdef USE_X_TOOLKIT
9651 #endif /* USE_X_TOOLKIT */
9654 case NoExpose
: /* This occurs when an XCopyArea's
9655 source area was completely
9660 /* Redo the mouse-highlight after the tooltip has gone. */
9661 if (event
.xmap
.window
== tip_window
)
9664 redo_mouse_highlight ();
9667 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
9668 if (f
) /* F may no longer exist if
9669 the frame was deleted. */
9671 /* While a frame is unmapped, display generation is
9672 disabled; you don't want to spend time updating a
9673 display that won't ever be seen. */
9674 f
->async_visible
= 0;
9675 /* We can't distinguish, from the event, whether the window
9676 has become iconified or invisible. So assume, if it
9677 was previously visible, than now it is iconified.
9678 But x_make_frame_invisible clears both
9679 the visible flag and the iconified flag;
9680 and that way, we know the window is not iconified now. */
9681 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
9683 f
->async_iconified
= 1;
9685 bufp
->kind
= iconify_event
;
9686 XSETFRAME (bufp
->frame_or_window
, f
);
9696 if (event
.xmap
.window
== tip_window
)
9697 /* The tooltip has been drawn already. Avoid
9698 the SET_FRAME_GARBAGED below. */
9701 /* We use x_top_window_to_frame because map events can
9702 come for sub-windows and they don't mean that the
9703 frame is visible. */
9704 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
9707 f
->async_visible
= 1;
9708 f
->async_iconified
= 0;
9709 f
->output_data
.x
->has_been_visible
= 1;
9711 /* wait_reading_process_input will notice this and update
9712 the frame's display structures. */
9713 SET_FRAME_GARBAGED (f
);
9717 bufp
->kind
= deiconify_event
;
9718 XSETFRAME (bufp
->frame_or_window
, f
);
9724 else if (! NILP (Vframe_list
)
9725 && ! NILP (XCDR (Vframe_list
)))
9726 /* Force a redisplay sooner or later
9727 to update the frame titles
9728 in case this is the second frame. */
9729 record_asynch_buffer_change ();
9734 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
9736 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
9737 /* I couldn't find a way to prevent LessTif scroll bars
9738 from consuming key events. */
9741 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
9743 if (widget
&& XmIsScrollBar (widget
))
9745 widget
= XtParent (widget
);
9746 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
9749 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
9753 KeySym keysym
, orig_keysym
;
9754 /* al%imercury@uunet.uu.net says that making this 81
9755 instead of 80 fixed a bug whereby meta chars made
9758 It seems that some version of XmbLookupString has
9759 a bug of not returning XBufferOverflow in
9760 status_return even if the input is too long to
9761 fit in 81 bytes. So, we must prepare sufficient
9762 bytes for copy_buffer. 513 bytes (256 chars for
9763 two-byte character set) seems to be a faily good
9764 approximation. -- 2000.8.10 handa@etl.go.jp */
9765 unsigned char copy_buffer
[513];
9766 unsigned char *copy_bufptr
= copy_buffer
;
9767 int copy_bufsiz
= sizeof (copy_buffer
);
9771 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
9772 extra_keyboard_modifiers
);
9773 modifiers
= event
.xkey
.state
;
9775 /* This will have to go some day... */
9777 /* make_lispy_event turns chars into control chars.
9778 Don't do it here because XLookupString is too eager. */
9779 event
.xkey
.state
&= ~ControlMask
;
9780 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
9781 | dpyinfo
->super_mod_mask
9782 | dpyinfo
->hyper_mod_mask
9783 | dpyinfo
->alt_mod_mask
);
9785 /* In case Meta is ComposeCharacter,
9786 clear its status. According to Markus Ehrnsperger
9787 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
9788 this enables ComposeCharacter to work whether or
9789 not it is combined with Meta. */
9790 if (modifiers
& dpyinfo
->meta_mod_mask
)
9791 bzero (&compose_status
, sizeof (compose_status
));
9796 Status status_return
;
9798 nbytes
= XmbLookupString (FRAME_XIC (f
),
9799 &event
.xkey
, copy_bufptr
,
9800 copy_bufsiz
, &keysym
,
9802 if (status_return
== XBufferOverflow
)
9804 copy_bufsiz
= nbytes
+ 1;
9805 copy_bufptr
= (char *) alloca (copy_bufsiz
);
9806 nbytes
= XmbLookupString (FRAME_XIC (f
),
9807 &event
.xkey
, copy_bufptr
,
9808 copy_bufsiz
, &keysym
,
9812 if (status_return
== XLookupNone
)
9814 else if (status_return
== XLookupChars
)
9819 else if (status_return
!= XLookupKeySym
9820 && status_return
!= XLookupBoth
)
9824 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
9825 copy_bufsiz
, &keysym
,
9828 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
9829 copy_bufsiz
, &keysym
,
9833 orig_keysym
= keysym
;
9837 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
9838 || keysym
== XK_Delete
9839 #ifdef XK_ISO_Left_Tab
9840 || (keysym
>= XK_ISO_Left_Tab
&& keysym
<= XK_ISO_Enter
)
9842 || (keysym
>= XK_Kanji
&& keysym
<= XK_Eisu_toggle
)
9843 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
9844 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
9846 /* This recognizes the "extended function keys".
9847 It seems there's no cleaner way.
9848 Test IsModifierKey to avoid handling mode_switch
9850 || ((unsigned) (keysym
) >= XK_Select
9851 && (unsigned)(keysym
) < XK_KP_Space
)
9853 #ifdef XK_dead_circumflex
9854 || orig_keysym
== XK_dead_circumflex
9856 #ifdef XK_dead_grave
9857 || orig_keysym
== XK_dead_grave
9859 #ifdef XK_dead_tilde
9860 || orig_keysym
== XK_dead_tilde
9862 #ifdef XK_dead_diaeresis
9863 || orig_keysym
== XK_dead_diaeresis
9865 #ifdef XK_dead_macron
9866 || orig_keysym
== XK_dead_macron
9868 #ifdef XK_dead_degree
9869 || orig_keysym
== XK_dead_degree
9871 #ifdef XK_dead_acute
9872 || orig_keysym
== XK_dead_acute
9874 #ifdef XK_dead_cedilla
9875 || orig_keysym
== XK_dead_cedilla
9877 #ifdef XK_dead_breve
9878 || orig_keysym
== XK_dead_breve
9880 #ifdef XK_dead_ogonek
9881 || orig_keysym
== XK_dead_ogonek
9883 #ifdef XK_dead_caron
9884 || orig_keysym
== XK_dead_caron
9886 #ifdef XK_dead_doubleacute
9887 || orig_keysym
== XK_dead_doubleacute
9889 #ifdef XK_dead_abovedot
9890 || orig_keysym
== XK_dead_abovedot
9892 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
9893 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
9894 /* Any "vendor-specific" key is ok. */
9895 || (orig_keysym
& (1 << 28)))
9896 && ! (IsModifierKey (orig_keysym
)
9898 #ifdef XK_Mode_switch
9899 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
9902 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
9904 #endif /* not HAVE_X11R5 */
9907 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
9909 temp_buffer
[temp_index
++] = keysym
;
9910 bufp
->kind
= non_ascii_keystroke
;
9911 bufp
->code
= keysym
;
9912 XSETFRAME (bufp
->frame_or_window
, f
);
9915 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
9917 bufp
->timestamp
= event
.xkey
.time
;
9922 else if (numchars
> nbytes
)
9928 for (i
= 0; i
< nbytes
; i
++)
9930 if (temp_index
== (sizeof temp_buffer
9933 temp_buffer
[temp_index
++] = copy_bufptr
[i
];
9936 if (/* If the event is not from XIM, */
9937 event
.xkey
.keycode
!= 0
9938 /* or the current locale doesn't request
9939 decoding of the intup data, ... */
9940 || coding
.type
== coding_type_raw_text
9941 || coding
.type
== coding_type_no_conversion
)
9943 /* ... we can use the input data as is. */
9948 /* We have to decode the input data. */
9952 require
= decoding_buffer_size (&coding
, nbytes
);
9953 p
= (unsigned char *) alloca (require
);
9954 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
9955 decode_coding (&coding
, copy_bufptr
, p
,
9957 nbytes
= coding
.produced
;
9958 nchars
= coding
.produced_char
;
9962 /* Convert the input data to a sequence of
9963 character events. */
9964 for (i
= 0; i
< nbytes
; i
+= len
)
9966 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
9968 bufp
->kind
= (SINGLE_BYTE_CHAR_P (c
)
9970 : multibyte_char_keystroke
);
9972 XSETFRAME (bufp
->frame_or_window
, f
);
9975 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
9977 bufp
->timestamp
= event
.xkey
.time
;
9984 if (keysym
== NoSymbol
)
9994 /* Don't dispatch this event since XtDispatchEvent calls
9995 XFilterEvent, and two calls in a row may freeze the
10004 /* Don't dispatch this event since XtDispatchEvent calls
10005 XFilterEvent, and two calls in a row may freeze the
10012 /* Here's a possible interpretation of the whole
10013 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If
10014 you get a FocusIn event, you have to get a FocusOut
10015 event before you relinquish the focus. If you
10016 haven't received a FocusIn event, then a mere
10017 LeaveNotify is enough to free you. */
10021 int from_menu_bar_p
= 0;
10023 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10025 #ifdef LESSTIF_VERSION
10026 /* When clicking outside of a menu bar popup to close
10027 it, we get a FocusIn/ EnterNotify sequence of
10028 events. The flag event.xcrossing.focus is not set
10029 in the EnterNotify event of that sequence because
10030 the focus is in the menu bar,
10031 event.xcrossing.window is the frame's X window.
10032 Unconditionally setting the focus frame to null in
10033 this case is not the right thing, because no event
10034 follows that could set the focus frame to the right
10037 This could be a LessTif bug, but I wasn't able to
10038 reproduce the behavior in a simple test program.
10039 On the other hand, Motif seems to not have this
10042 (gerd, LessTif 0.92). */
10044 if (!event
.xcrossing
.focus
10046 && f
->output_data
.x
->menubar_widget
)
10051 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
10052 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
10053 from_menu_bar_p
= 1;
10055 #endif /* LESSTIF_VERSION */
10057 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
10059 /* Avoid nasty pop/raise loops. */
10060 if (f
&& (!(f
->auto_raise
)
10061 || !(f
->auto_lower
)
10062 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
10064 x_new_focus_frame (dpyinfo
, f
);
10065 enter_timestamp
= event
.xcrossing
.time
;
10068 else if (f
== dpyinfo
->x_focus_frame
)
10069 x_new_focus_frame (dpyinfo
, 0);
10071 /* EnterNotify counts as mouse movement,
10072 so update things that depend on mouse position. */
10073 if (f
&& !f
->output_data
.x
->busy_p
)
10074 note_mouse_movement (f
, &event
.xmotion
);
10079 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
10080 if (event
.xfocus
.detail
!= NotifyPointer
)
10081 dpyinfo
->x_focus_event_frame
= f
;
10084 x_new_focus_frame (dpyinfo
, f
);
10086 /* Don't stop displaying the initial startup message
10087 for a switch-frame event we don't need. */
10088 if (GC_NILP (Vterminal_frame
)
10089 && GC_CONSP (Vframe_list
)
10090 && !GC_NILP (XCDR (Vframe_list
)))
10092 bufp
->kind
= FOCUS_IN_EVENT
;
10093 XSETFRAME (bufp
->frame_or_window
, f
);
10095 ++bufp
, ++count
, --numchars
;
10100 if (f
&& FRAME_XIC (f
))
10101 XSetICFocus (FRAME_XIC (f
));
10107 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
10110 int from_menu_bar_p
= 0;
10112 if (f
== dpyinfo
->mouse_face_mouse_frame
)
10114 /* If we move outside the frame, then we're
10115 certainly no longer on any text in the frame. */
10116 clear_mouse_face (dpyinfo
);
10117 dpyinfo
->mouse_face_mouse_frame
= 0;
10120 /* Generate a nil HELP_EVENT to cancel a help-echo.
10121 Do it only if there's something to cancel.
10122 Otherwise, the startup message is cleared when
10123 the mouse leaves the frame. */
10124 if (any_help_event_p
)
10129 XSETFRAME (frame
, f
);
10131 n
= gen_help_event (bufp
, numchars
,
10132 Qnil
, frame
, Qnil
, Qnil
, 0);
10133 bufp
+= n
, count
+= n
, numchars
-= n
;
10136 #ifdef LESSTIF_VERSION
10137 /* Please see the comment at the start of the
10138 EnterNotify case. */
10139 if (!event
.xcrossing
.focus
10140 && f
->output_data
.x
->menubar_widget
)
10144 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
10145 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
10146 from_menu_bar_p
= 1;
10148 #endif /* LESSTIF_VERSION */
10150 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
10151 x_mouse_leave (dpyinfo
);
10154 if (f
== dpyinfo
->x_focus_event_frame
)
10155 dpyinfo
->x_focus_event_frame
= 0;
10156 if (f
== dpyinfo
->x_focus_frame
)
10157 x_new_focus_frame (dpyinfo
, 0);
10163 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
10164 if (event
.xfocus
.detail
!= NotifyPointer
10165 && f
== dpyinfo
->x_focus_event_frame
)
10166 dpyinfo
->x_focus_event_frame
= 0;
10167 if (f
&& f
== dpyinfo
->x_focus_frame
)
10168 x_new_focus_frame (dpyinfo
, 0);
10171 if (f
&& FRAME_XIC (f
))
10172 XUnsetICFocus (FRAME_XIC (f
));
10179 previous_help_echo
= help_echo
;
10180 help_echo
= help_echo_object
= help_echo_window
= Qnil
;
10181 help_echo_pos
= -1;
10183 if (dpyinfo
->grabbed
&& last_mouse_frame
10184 && FRAME_LIVE_P (last_mouse_frame
))
10185 f
= last_mouse_frame
;
10187 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
10190 note_mouse_movement (f
, &event
.xmotion
);
10193 #ifndef USE_TOOLKIT_SCROLL_BARS
10194 struct scroll_bar
*bar
10195 = x_window_to_scroll_bar (event
.xmotion
.window
);
10198 x_scroll_bar_note_movement (bar
, &event
);
10199 #endif /* USE_TOOLKIT_SCROLL_BARS */
10201 /* If we move outside the frame, then we're
10202 certainly no longer on any text in the frame. */
10203 clear_mouse_face (dpyinfo
);
10206 /* If the contents of the global variable help_echo
10207 has changed, generate a HELP_EVENT. */
10208 if (!NILP (help_echo
)
10209 || !NILP (previous_help_echo
))
10215 XSETFRAME (frame
, f
);
10219 any_help_event_p
= 1;
10220 n
= gen_help_event (bufp
, numchars
, help_echo
, frame
,
10221 help_echo_window
, help_echo_object
,
10223 bufp
+= n
, count
+= n
, numchars
-= n
;
10229 case ConfigureNotify
:
10230 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
10233 #ifndef USE_X_TOOLKIT
10234 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
10235 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
10237 /* In the toolkit version, change_frame_size
10238 is called by the code that handles resizing
10239 of the EmacsFrame widget. */
10241 /* Even if the number of character rows and columns has
10242 not changed, the font size may have changed, so we need
10243 to check the pixel dimensions as well. */
10244 if (columns
!= f
->width
10245 || rows
!= f
->height
10246 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
10247 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
10249 change_frame_size (f
, rows
, columns
, 0, 1, 0);
10250 SET_FRAME_GARBAGED (f
);
10251 cancel_mouse_face (f
);
10255 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
10256 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
10258 /* What we have now is the position of Emacs's own window.
10259 Convert that to the position of the window manager window. */
10260 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
10261 &f
->output_data
.x
->top_pos
);
10264 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
10265 xic_set_statusarea (f
);
10268 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
10270 /* Since the WM decorations come below top_pos now,
10271 we must put them below top_pos in the future. */
10272 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
10273 x_wm_set_size_hint (f
, (long) 0, 0);
10276 /* Some window managers pass (0,0) as the location of
10277 the window, and the Motif event handler stores it
10278 in the emacs widget, which messes up Motif menus. */
10279 if (event
.xconfigure
.x
== 0 && event
.xconfigure
.y
== 0)
10281 event
.xconfigure
.x
= f
->output_data
.x
->widget
->core
.x
;
10282 event
.xconfigure
.y
= f
->output_data
.x
->widget
->core
.y
;
10284 #endif /* USE_MOTIF */
10289 case ButtonRelease
:
10291 /* If we decide we want to generate an event to be seen
10292 by the rest of Emacs, we put it here. */
10293 struct input_event emacs_event
;
10294 int tool_bar_p
= 0;
10296 emacs_event
.kind
= no_event
;
10297 bzero (&compose_status
, sizeof (compose_status
));
10299 if (dpyinfo
->grabbed
10300 && last_mouse_frame
10301 && FRAME_LIVE_P (last_mouse_frame
))
10302 f
= last_mouse_frame
;
10304 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
10308 /* Is this in the tool-bar? */
10309 if (WINDOWP (f
->tool_bar_window
)
10310 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
10312 Lisp_Object window
;
10315 x
= event
.xbutton
.x
;
10316 y
= event
.xbutton
.y
;
10319 window
= window_from_coordinates (f
, x
, y
, &p
, 1);
10320 if (EQ (window
, f
->tool_bar_window
))
10322 x_handle_tool_bar_click (f
, &event
.xbutton
);
10328 if (!dpyinfo
->x_focus_frame
10329 || f
== dpyinfo
->x_focus_frame
)
10330 construct_mouse_click (&emacs_event
, &event
, f
);
10334 #ifndef USE_TOOLKIT_SCROLL_BARS
10335 struct scroll_bar
*bar
10336 = x_window_to_scroll_bar (event
.xbutton
.window
);
10339 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
10340 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10343 if (event
.type
== ButtonPress
)
10345 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
10346 last_mouse_frame
= f
;
10347 /* Ignore any mouse motion that happened
10348 before this event; any subsequent mouse-movement
10349 Emacs events should reflect only motion after
10350 the ButtonPress. */
10352 f
->mouse_moved
= 0;
10355 last_tool_bar_item
= -1;
10359 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
10362 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
10364 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
10370 #ifdef USE_X_TOOLKIT
10371 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
10372 /* For a down-event in the menu bar,
10373 don't pass it to Xt right now.
10374 Instead, save it away
10375 and we will pass it to Xt from kbd_buffer_get_event.
10376 That way, we can run some Lisp code first. */
10377 if (f
&& event
.type
== ButtonPress
10378 /* Verify the event is really within the menu bar
10379 and not just sent to it due to grabbing. */
10380 && event
.xbutton
.x
>= 0
10381 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
10382 && event
.xbutton
.y
>= 0
10383 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
10384 && event
.xbutton
.same_screen
)
10386 SET_SAVED_BUTTON_EVENT
;
10387 XSETFRAME (last_mouse_press_frame
, f
);
10389 else if (event
.type
== ButtonPress
)
10391 last_mouse_press_frame
= Qnil
;
10395 #ifdef USE_MOTIF /* This should do not harm for Lucid,
10396 but I am trying to be cautious. */
10397 else if (event
.type
== ButtonRelease
)
10399 if (!NILP (last_mouse_press_frame
))
10401 f
= XFRAME (last_mouse_press_frame
);
10402 if (f
->output_data
.x
)
10403 SET_SAVED_BUTTON_EVENT
;
10408 #endif /* USE_MOTIF */
10411 #endif /* USE_X_TOOLKIT */
10415 case CirculateNotify
:
10418 case CirculateRequest
:
10421 case VisibilityNotify
:
10424 case MappingNotify
:
10425 /* Someone has changed the keyboard mapping - update the
10427 switch (event
.xmapping
.request
)
10429 case MappingModifier
:
10430 x_find_modifier_meanings (dpyinfo
);
10431 /* This is meant to fall through. */
10432 case MappingKeyboard
:
10433 XRefreshKeyboardMapping (&event
.xmapping
);
10439 #ifdef USE_X_TOOLKIT
10441 XtDispatchEvent (&event
);
10443 #endif /* USE_X_TOOLKIT */
10451 /* On some systems, an X bug causes Emacs to get no more events
10452 when the window is destroyed. Detect that. (1994.) */
10455 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
10456 One XNOOP in 100 loops will make Emacs terminate.
10457 B. Bretthauer, 1994 */
10459 if (x_noop_count
>= 100)
10463 if (next_noop_dpyinfo
== 0)
10464 next_noop_dpyinfo
= x_display_list
;
10466 XNoOp (next_noop_dpyinfo
->display
);
10468 /* Each time we get here, cycle through the displays now open. */
10469 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
10473 /* If the focus was just given to an auto-raising frame,
10475 /* ??? This ought to be able to handle more than one such frame. */
10476 if (pending_autoraise_frame
)
10478 x_raise_frame (pending_autoraise_frame
);
10479 pending_autoraise_frame
= 0;
10490 /***********************************************************************
10492 ***********************************************************************/
10494 /* Note if the text cursor of window W has been overwritten by a
10495 drawing operation that outputs N glyphs starting at HPOS in the
10496 line given by output_cursor.vpos. N < 0 means all the rest of the
10497 line after HPOS has been written. */
10500 note_overwritten_text_cursor (w
, hpos
, n
)
10504 if (updated_area
== TEXT_AREA
10505 && output_cursor
.vpos
== w
->phys_cursor
.vpos
10506 && hpos
<= w
->phys_cursor
.hpos
10508 || hpos
+ n
> w
->phys_cursor
.hpos
))
10509 w
->phys_cursor_on_p
= 0;
10513 /* Set clipping for output in glyph row ROW. W is the window in which
10514 we operate. GC is the graphics context to set clipping in.
10515 WHOLE_LINE_P non-zero means include the areas used for truncation
10516 mark display and alike in the clipping rectangle.
10518 ROW may be a text row or, e.g., a mode line. Text rows must be
10519 clipped to the interior of the window dedicated to text display,
10520 mode lines must be clipped to the whole window. */
10523 x_clip_to_row (w
, row
, gc
, whole_line_p
)
10525 struct glyph_row
*row
;
10529 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10530 XRectangle clip_rect
;
10531 int window_x
, window_y
, window_width
, window_height
;
10533 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
10535 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
10536 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
10537 clip_rect
.y
= max (clip_rect
.y
, window_y
);
10538 clip_rect
.width
= window_width
;
10539 clip_rect
.height
= row
->visible_height
;
10541 /* If clipping to the whole line, including trunc marks, extend
10542 the rectangle to the left and increase its width. */
10545 clip_rect
.x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
10546 clip_rect
.width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
10549 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
10553 /* Draw a hollow box cursor on window W in glyph row ROW. */
10556 x_draw_hollow_cursor (w
, row
)
10558 struct glyph_row
*row
;
10560 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10561 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10562 Display
*dpy
= FRAME_X_DISPLAY (f
);
10565 struct glyph
*cursor_glyph
;
10568 /* Compute frame-relative coordinates from window-relative
10570 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
10571 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
10572 + row
->ascent
- w
->phys_cursor_ascent
);
10573 h
= row
->height
- 1;
10575 /* Get the glyph the cursor is on. If we can't tell because
10576 the current matrix is invalid or such, give up. */
10577 cursor_glyph
= get_phys_cursor_glyph (w
);
10578 if (cursor_glyph
== NULL
)
10581 /* Compute the width of the rectangle to draw. If on a stretch
10582 glyph, and `x-stretch-block-cursor' is nil, don't draw a
10583 rectangle as wide as the glyph, but use a canonical character
10585 wd
= cursor_glyph
->pixel_width
- 1;
10586 if (cursor_glyph
->type
== STRETCH_GLYPH
10587 && !x_stretch_cursor_p
)
10588 wd
= min (CANON_X_UNIT (f
), wd
);
10590 /* The foreground of cursor_gc is typically the same as the normal
10591 background color, which can cause the cursor box to be invisible. */
10592 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
10593 if (dpyinfo
->scratch_cursor_gc
)
10594 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
10596 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
10597 GCForeground
, &xgcv
);
10598 gc
= dpyinfo
->scratch_cursor_gc
;
10600 /* Set clipping, draw the rectangle, and reset clipping again. */
10601 x_clip_to_row (w
, row
, gc
, 0);
10602 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
10603 XSetClipMask (dpy
, gc
, None
);
10607 /* Draw a bar cursor on window W in glyph row ROW.
10609 Implementation note: One would like to draw a bar cursor with an
10610 angle equal to the one given by the font property XA_ITALIC_ANGLE.
10611 Unfortunately, I didn't find a font yet that has this property set.
10615 x_draw_bar_cursor (w
, row
, width
)
10617 struct glyph_row
*row
;
10620 struct frame
*f
= XFRAME (w
->frame
);
10621 struct glyph
*cursor_glyph
;
10624 unsigned long mask
;
10629 /* If cursor is out of bounds, don't draw garbage. This can happen
10630 in mini-buffer windows when switching between echo area glyphs
10631 and mini-buffer. */
10632 cursor_glyph
= get_phys_cursor_glyph (w
);
10633 if (cursor_glyph
== NULL
)
10636 /* If on an image, draw like a normal cursor. That's usually better
10637 visible than drawing a bar, esp. if the image is large so that
10638 the bar might not be in the window. */
10639 if (cursor_glyph
->type
== IMAGE_GLYPH
)
10641 struct glyph_row
*row
;
10642 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
10643 x_draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
10647 xgcv
.background
= f
->output_data
.x
->cursor_pixel
;
10648 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
10649 xgcv
.graphics_exposures
= 0;
10650 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
10651 dpy
= FRAME_X_DISPLAY (f
);
10652 window
= FRAME_X_WINDOW (f
);
10653 gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
10656 XChangeGC (dpy
, gc
, mask
, &xgcv
);
10659 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
10660 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
10664 width
= f
->output_data
.x
->cursor_width
;
10666 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
10667 x_clip_to_row (w
, row
, gc
, 0);
10668 XFillRectangle (dpy
, window
, gc
,
10670 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
10671 min (cursor_glyph
->pixel_width
, width
),
10673 XSetClipMask (dpy
, gc
, None
);
10678 /* Clear the cursor of window W to background color, and mark the
10679 cursor as not shown. This is used when the text where the cursor
10680 is is about to be rewritten. */
10686 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
10687 x_update_window_cursor (w
, 0);
10691 /* Draw the cursor glyph of window W in glyph row ROW. See the
10692 comment of x_draw_glyphs for the meaning of HL. */
10695 x_draw_phys_cursor_glyph (w
, row
, hl
)
10697 struct glyph_row
*row
;
10698 enum draw_glyphs_face hl
;
10700 /* If cursor hpos is out of bounds, don't draw garbage. This can
10701 happen in mini-buffer windows when switching between echo area
10702 glyphs and mini-buffer. */
10703 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
10705 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
10706 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
10709 /* When we erase the cursor, and ROW is overlapped by other
10710 rows, make sure that these overlapping parts of other rows
10712 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
10714 if (row
> w
->current_matrix
->rows
10715 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
10716 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
10718 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
10719 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
10720 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
10726 /* Erase the image of a cursor of window W from the screen. */
10729 x_erase_phys_cursor (w
)
10732 struct frame
*f
= XFRAME (w
->frame
);
10733 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10734 int hpos
= w
->phys_cursor
.hpos
;
10735 int vpos
= w
->phys_cursor
.vpos
;
10736 int mouse_face_here_p
= 0;
10737 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
10738 struct glyph_row
*cursor_row
;
10739 struct glyph
*cursor_glyph
;
10740 enum draw_glyphs_face hl
;
10742 /* No cursor displayed or row invalidated => nothing to do on the
10744 if (w
->phys_cursor_type
== NO_CURSOR
)
10745 goto mark_cursor_off
;
10747 /* VPOS >= active_glyphs->nrows means that window has been resized.
10748 Don't bother to erase the cursor. */
10749 if (vpos
>= active_glyphs
->nrows
)
10750 goto mark_cursor_off
;
10752 /* If row containing cursor is marked invalid, there is nothing we
10754 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
10755 if (!cursor_row
->enabled_p
)
10756 goto mark_cursor_off
;
10758 /* This can happen when the new row is shorter than the old one.
10759 In this case, either x_draw_glyphs or clear_end_of_line
10760 should have cleared the cursor. Note that we wouldn't be
10761 able to erase the cursor in this case because we don't have a
10762 cursor glyph at hand. */
10763 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
10764 goto mark_cursor_off
;
10766 /* If the cursor is in the mouse face area, redisplay that when
10767 we clear the cursor. */
10768 if (! NILP (dpyinfo
->mouse_face_window
)
10769 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
10770 && (vpos
> dpyinfo
->mouse_face_beg_row
10771 || (vpos
== dpyinfo
->mouse_face_beg_row
10772 && hpos
>= dpyinfo
->mouse_face_beg_col
))
10773 && (vpos
< dpyinfo
->mouse_face_end_row
10774 || (vpos
== dpyinfo
->mouse_face_end_row
10775 && hpos
< dpyinfo
->mouse_face_end_col
))
10776 /* Don't redraw the cursor's spot in mouse face if it is at the
10777 end of a line (on a newline). The cursor appears there, but
10778 mouse highlighting does not. */
10779 && cursor_row
->used
[TEXT_AREA
] > hpos
)
10780 mouse_face_here_p
= 1;
10782 /* Maybe clear the display under the cursor. */
10783 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
10786 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10788 cursor_glyph
= get_phys_cursor_glyph (w
);
10789 if (cursor_glyph
== NULL
)
10790 goto mark_cursor_off
;
10792 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
10794 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10796 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
10798 cursor_glyph
->pixel_width
,
10799 cursor_row
->visible_height
,
10803 /* Erase the cursor by redrawing the character underneath it. */
10804 if (mouse_face_here_p
)
10805 hl
= DRAW_MOUSE_FACE
;
10806 else if (cursor_row
->inverse_p
)
10807 hl
= DRAW_INVERSE_VIDEO
;
10809 hl
= DRAW_NORMAL_TEXT
;
10810 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
10813 w
->phys_cursor_on_p
= 0;
10814 w
->phys_cursor_type
= NO_CURSOR
;
10818 /* Display or clear cursor of window W. If ON is zero, clear the
10819 cursor. If it is non-zero, display the cursor. If ON is nonzero,
10820 where to put the cursor is specified by HPOS, VPOS, X and Y. */
10823 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
10825 int on
, hpos
, vpos
, x
, y
;
10827 struct frame
*f
= XFRAME (w
->frame
);
10828 int new_cursor_type
;
10829 int new_cursor_width
;
10830 struct glyph_matrix
*current_glyphs
;
10831 struct glyph_row
*glyph_row
;
10832 struct glyph
*glyph
;
10834 /* This is pointless on invisible frames, and dangerous on garbaged
10835 windows and frames; in the latter case, the frame or window may
10836 be in the midst of changing its size, and x and y may be off the
10838 if (! FRAME_VISIBLE_P (f
)
10839 || FRAME_GARBAGED_P (f
)
10840 || vpos
>= w
->current_matrix
->nrows
10841 || hpos
>= w
->current_matrix
->matrix_w
)
10844 /* If cursor is off and we want it off, return quickly. */
10845 if (!on
&& !w
->phys_cursor_on_p
)
10848 current_glyphs
= w
->current_matrix
;
10849 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
10850 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
10852 /* If cursor row is not enabled, we don't really know where to
10853 display the cursor. */
10854 if (!glyph_row
->enabled_p
)
10856 w
->phys_cursor_on_p
= 0;
10860 xassert (interrupt_input_blocked
);
10862 /* Set new_cursor_type to the cursor we want to be displayed. In a
10863 mini-buffer window, we want the cursor only to appear if we are
10864 reading input from this window. For the selected window, we want
10865 the cursor type given by the frame parameter. If explicitly
10866 marked off, draw no cursor. In all other cases, we want a hollow
10868 new_cursor_width
= -1;
10869 if (cursor_in_echo_area
10870 && FRAME_HAS_MINIBUF_P (f
)
10871 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
10873 if (w
== XWINDOW (echo_area_window
))
10874 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
10876 new_cursor_type
= HOLLOW_BOX_CURSOR
;
10880 if (w
!= XWINDOW (selected_window
)
10881 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
10883 extern int cursor_in_non_selected_windows
;
10885 if (MINI_WINDOW_P (w
)
10886 || !cursor_in_non_selected_windows
10887 || NILP (XBUFFER (w
->buffer
)->cursor_type
))
10888 new_cursor_type
= NO_CURSOR
;
10890 new_cursor_type
= HOLLOW_BOX_CURSOR
;
10892 else if (w
->cursor_off_p
)
10893 new_cursor_type
= NO_CURSOR
;
10896 struct buffer
*b
= XBUFFER (w
->buffer
);
10898 if (EQ (b
->cursor_type
, Qt
))
10899 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
10901 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
10902 &new_cursor_width
);
10906 /* If cursor is currently being shown and we don't want it to be or
10907 it is in the wrong place, or the cursor type is not what we want,
10909 if (w
->phys_cursor_on_p
10911 || w
->phys_cursor
.x
!= x
10912 || w
->phys_cursor
.y
!= y
10913 || new_cursor_type
!= w
->phys_cursor_type
))
10914 x_erase_phys_cursor (w
);
10916 /* If the cursor is now invisible and we want it to be visible,
10918 if (on
&& !w
->phys_cursor_on_p
)
10920 w
->phys_cursor_ascent
= glyph_row
->ascent
;
10921 w
->phys_cursor_height
= glyph_row
->height
;
10923 /* Set phys_cursor_.* before x_draw_.* is called because some
10924 of them may need the information. */
10925 w
->phys_cursor
.x
= x
;
10926 w
->phys_cursor
.y
= glyph_row
->y
;
10927 w
->phys_cursor
.hpos
= hpos
;
10928 w
->phys_cursor
.vpos
= vpos
;
10929 w
->phys_cursor_type
= new_cursor_type
;
10930 w
->phys_cursor_on_p
= 1;
10932 switch (new_cursor_type
)
10934 case HOLLOW_BOX_CURSOR
:
10935 x_draw_hollow_cursor (w
, glyph_row
);
10938 case FILLED_BOX_CURSOR
:
10939 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
10943 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
);
10954 if (w
== XWINDOW (f
->selected_window
))
10955 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
10956 xic_set_preeditarea (w
, x
, y
);
10961 if (updating_frame
!= f
)
10962 XFlush (FRAME_X_DISPLAY (f
));
10967 /* Display the cursor on window W, or clear it. X and Y are window
10968 relative pixel coordinates. HPOS and VPOS are glyph matrix
10969 positions. If W is not the selected window, display a hollow
10970 cursor. ON non-zero means display the cursor at X, Y which
10971 correspond to HPOS, VPOS, otherwise it is cleared. */
10974 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
10976 int on
, hpos
, vpos
, x
, y
;
10979 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
10984 /* Display the cursor on window W, or clear it, according to ON_P.
10985 Don't change the cursor's position. */
10988 x_update_cursor (f
, on_p
)
10991 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
10995 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
10996 in the window tree rooted at W. */
10999 x_update_cursor_in_window_tree (w
, on_p
)
11005 if (!NILP (w
->hchild
))
11006 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
11007 else if (!NILP (w
->vchild
))
11008 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
11010 x_update_window_cursor (w
, on_p
);
11012 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
11017 /* Switch the display of W's cursor on or off, according to the value
11021 x_update_window_cursor (w
, on
)
11025 /* Don't update cursor in windows whose frame is in the process
11026 of being deleted. */
11027 if (w
->current_matrix
)
11030 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
11031 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
11041 /* Refresh bitmap kitchen sink icon for frame F
11042 when we get an expose event for it. */
11048 /* Normally, the window manager handles this function. */
11051 /* Make the x-window of frame F use the gnu icon bitmap. */
11054 x_bitmap_icon (f
, file
)
11060 if (FRAME_X_WINDOW (f
) == 0)
11063 /* Free up our existing icon bitmap if any. */
11064 if (f
->output_data
.x
->icon_bitmap
> 0)
11065 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
11066 f
->output_data
.x
->icon_bitmap
= 0;
11068 if (STRINGP (file
))
11069 bitmap_id
= x_create_bitmap_from_file (f
, file
);
11072 /* Create the GNU bitmap if necessary. */
11073 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
11074 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
11075 = x_create_bitmap_from_data (f
, gnu_bits
,
11076 gnu_width
, gnu_height
);
11078 /* The first time we create the GNU bitmap,
11079 this increments the ref-count one extra time.
11080 As a result, the GNU bitmap is never freed.
11081 That way, we don't have to worry about allocating it again. */
11082 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
11084 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
11087 x_wm_set_icon_pixmap (f
, bitmap_id
);
11088 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
11094 /* Make the x-window of frame F use a rectangle with text.
11095 Use ICON_NAME as the text. */
11098 x_text_icon (f
, icon_name
)
11102 if (FRAME_X_WINDOW (f
) == 0)
11107 XTextProperty text
;
11108 text
.value
= (unsigned char *) icon_name
;
11109 text
.encoding
= XA_STRING
;
11111 text
.nitems
= strlen (icon_name
);
11112 #ifdef USE_X_TOOLKIT
11113 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
11115 #else /* not USE_X_TOOLKIT */
11116 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
11117 #endif /* not USE_X_TOOLKIT */
11119 #else /* not HAVE_X11R4 */
11120 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
11121 #endif /* not HAVE_X11R4 */
11123 if (f
->output_data
.x
->icon_bitmap
> 0)
11124 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
11125 f
->output_data
.x
->icon_bitmap
= 0;
11126 x_wm_set_icon_pixmap (f
, 0);
11131 #define X_ERROR_MESSAGE_SIZE 200
11133 /* If non-nil, this should be a string.
11134 It means catch X errors and store the error message in this string. */
11136 static Lisp_Object x_error_message_string
;
11138 /* An X error handler which stores the error message in
11139 x_error_message_string. This is called from x_error_handler if
11140 x_catch_errors is in effect. */
11143 x_error_catcher (display
, error
)
11145 XErrorEvent
*error
;
11147 XGetErrorText (display
, error
->error_code
,
11148 XSTRING (x_error_message_string
)->data
,
11149 X_ERROR_MESSAGE_SIZE
);
11152 /* Begin trapping X errors for display DPY. Actually we trap X errors
11153 for all displays, but DPY should be the display you are actually
11156 After calling this function, X protocol errors no longer cause
11157 Emacs to exit; instead, they are recorded in the string
11158 stored in x_error_message_string.
11160 Calling x_check_errors signals an Emacs error if an X error has
11161 occurred since the last call to x_catch_errors or x_check_errors.
11163 Calling x_uncatch_errors resumes the normal error handling. */
11165 void x_check_errors ();
11166 static Lisp_Object
x_catch_errors_unwind ();
11169 x_catch_errors (dpy
)
11172 int count
= specpdl_ptr
- specpdl
;
11174 /* Make sure any errors from previous requests have been dealt with. */
11175 XSync (dpy
, False
);
11177 record_unwind_protect (x_catch_errors_unwind
, x_error_message_string
);
11179 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
11180 XSTRING (x_error_message_string
)->data
[0] = 0;
11185 /* Unbind the binding that we made to check for X errors. */
11188 x_catch_errors_unwind (old_val
)
11189 Lisp_Object old_val
;
11191 x_error_message_string
= old_val
;
11195 /* If any X protocol errors have arrived since the last call to
11196 x_catch_errors or x_check_errors, signal an Emacs error using
11197 sprintf (a buffer, FORMAT, the x error message text) as the text. */
11200 x_check_errors (dpy
, format
)
11204 /* Make sure to catch any errors incurred so far. */
11205 XSync (dpy
, False
);
11207 if (XSTRING (x_error_message_string
)->data
[0])
11208 error (format
, XSTRING (x_error_message_string
)->data
);
11211 /* Nonzero if we had any X protocol errors
11212 since we did x_catch_errors on DPY. */
11215 x_had_errors_p (dpy
)
11218 /* Make sure to catch any errors incurred so far. */
11219 XSync (dpy
, False
);
11221 return XSTRING (x_error_message_string
)->data
[0] != 0;
11224 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
11227 x_clear_errors (dpy
)
11230 XSTRING (x_error_message_string
)->data
[0] = 0;
11233 /* Stop catching X protocol errors and let them make Emacs die.
11234 DPY should be the display that was passed to x_catch_errors.
11235 COUNT should be the value that was returned by
11236 the corresponding call to x_catch_errors. */
11239 x_uncatch_errors (dpy
, count
)
11243 unbind_to (count
, Qnil
);
11247 static unsigned int x_wire_count
;
11250 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
11255 /* Handle SIGPIPE, which can happen when the connection to a server
11256 simply goes away. SIGPIPE is handled by x_connection_signal.
11257 Don't need to do anything, because the write which caused the
11258 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
11259 which will do the appropriate cleanup for us. */
11262 x_connection_signal (signalnum
) /* If we don't have an argument, */
11263 int signalnum
; /* some compilers complain in signal calls. */
11266 /* USG systems forget handlers when they are used;
11267 must reestablish each time */
11268 signal (signalnum
, x_connection_signal
);
11273 /************************************************************************
11275 ************************************************************************/
11277 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
11278 the text of an error message that lead to the connection loss. */
11281 x_connection_closed (dpy
, error_message
)
11283 char *error_message
;
11285 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
11286 Lisp_Object frame
, tail
;
11290 msg
= (char *) alloca (strlen (error_message
) + 1);
11291 strcpy (msg
, error_message
);
11292 handling_signal
= 0;
11294 /* Prevent being called recursively because of an error condition
11295 below. Otherwise, we might end up with printing ``can't find per
11296 display information'' in the recursive call instead of printing
11297 the original message here. */
11298 count
= x_catch_errors (dpy
);
11300 /* We have to close the display to inform Xt that it doesn't
11301 exist anymore. If we don't, Xt will continue to wait for
11302 events from the display. As a consequence, a sequence of
11304 M-x make-frame-on-display RET :1 RET
11305 ...kill the new frame, so that we get an IO error...
11306 M-x make-frame-on-display RET :1 RET
11308 will indefinitely wait in Xt for events for display `:1', opened
11309 in the first class to make-frame-on-display.
11311 Closing the display is reported to lead to a bus error on
11312 OpenWindows in certain situations. I suspect that is a bug
11313 in OpenWindows. I don't know how to cicumvent it here. */
11315 #ifdef USE_X_TOOLKIT
11316 /* If DPYINFO is null, this means we didn't open the display
11317 in the first place, so don't try to close it. */
11319 XtCloseDisplay (dpy
);
11322 /* Indicate that this display is dead. */
11324 dpyinfo
->display
= 0;
11326 /* First delete frames whose mini-buffers are on frames
11327 that are on the dead display. */
11328 FOR_EACH_FRAME (tail
, frame
)
11330 Lisp_Object minibuf_frame
;
11332 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
11333 if (FRAME_X_P (XFRAME (frame
))
11334 && FRAME_X_P (XFRAME (minibuf_frame
))
11335 && ! EQ (frame
, minibuf_frame
)
11336 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
11337 Fdelete_frame (frame
, Qt
);
11340 /* Now delete all remaining frames on the dead display.
11341 We are now sure none of these is used as the mini-buffer
11342 for another frame that we need to delete. */
11343 FOR_EACH_FRAME (tail
, frame
)
11344 if (FRAME_X_P (XFRAME (frame
))
11345 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
11347 /* Set this to t so that Fdelete_frame won't get confused
11348 trying to find a replacement. */
11349 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
11350 Fdelete_frame (frame
, Qt
);
11354 x_delete_display (dpyinfo
);
11356 x_uncatch_errors (dpy
, count
);
11358 if (x_display_list
== 0)
11360 fprintf (stderr
, "%s\n", msg
);
11361 shut_down_emacs (0, 0, Qnil
);
11365 /* Ordinary stack unwind doesn't deal with these. */
11367 sigunblock (sigmask (SIGIO
));
11369 sigunblock (sigmask (SIGALRM
));
11370 TOTALLY_UNBLOCK_INPUT
;
11372 clear_waiting_for_input ();
11377 /* This is the usual handler for X protocol errors.
11378 It kills all frames on the display that we got the error for.
11379 If that was the only one, it prints an error message and kills Emacs. */
11382 x_error_quitter (display
, error
)
11384 XErrorEvent
*error
;
11386 char buf
[256], buf1
[356];
11388 /* Note that there is no real way portable across R3/R4 to get the
11389 original error handler. */
11391 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
11392 sprintf (buf1
, "X protocol error: %s on protocol request %d",
11393 buf
, error
->request_code
);
11394 x_connection_closed (display
, buf1
);
11398 /* This is the first-level handler for X protocol errors.
11399 It calls x_error_quitter or x_error_catcher. */
11402 x_error_handler (display
, error
)
11404 XErrorEvent
*error
;
11406 if (! NILP (x_error_message_string
))
11407 x_error_catcher (display
, error
);
11409 x_error_quitter (display
, error
);
11413 /* This is the handler for X IO errors, always.
11414 It kills all frames on the display that we lost touch with.
11415 If that was the only one, it prints an error message and kills Emacs. */
11418 x_io_error_quitter (display
)
11423 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
11424 x_connection_closed (display
, buf
);
11428 /* Changing the font of the frame. */
11430 /* Give frame F the font named FONTNAME as its default font, and
11431 return the full name of that font. FONTNAME may be a wildcard
11432 pattern; in that case, we choose some font that fits the pattern.
11433 The return value shows which font we chose. */
11436 x_new_font (f
, fontname
)
11438 register char *fontname
;
11440 struct font_info
*fontp
11441 = FS_LOAD_FONT (f
, 0, fontname
, -1);
11446 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
11447 f
->output_data
.x
->baseline_offset
= fontp
->baseline_offset
;
11448 f
->output_data
.x
->fontset
= -1;
11450 /* Compute the scroll bar width in character columns. */
11451 if (f
->scroll_bar_pixel_width
> 0)
11453 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
11454 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
11458 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
11459 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
11462 /* Now make the frame display the given font. */
11463 if (FRAME_X_WINDOW (f
) != 0)
11465 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
11466 f
->output_data
.x
->font
->fid
);
11467 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
11468 f
->output_data
.x
->font
->fid
);
11469 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
11470 f
->output_data
.x
->font
->fid
);
11472 frame_update_line_height (f
);
11474 /* Don't change the size of a tip frame; there's no point in
11475 doing it because it's done in Fx_show_tip, and it leads to
11476 problems because the tip frame has no widget. */
11477 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
11478 x_set_window_size (f
, 0, f
->width
, f
->height
);
11481 /* If we are setting a new frame's font for the first time,
11482 there are no faces yet, so this font's height is the line height. */
11483 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
11485 return build_string (fontp
->full_name
);
11488 /* Give frame F the fontset named FONTSETNAME as its default font, and
11489 return the full name of that fontset. FONTSETNAME may be a wildcard
11490 pattern; in that case, we choose some fontset that fits the pattern.
11491 The return value shows which fontset we chose. */
11494 x_new_fontset (f
, fontsetname
)
11498 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
11499 Lisp_Object result
;
11504 if (f
->output_data
.x
->fontset
== fontset
)
11505 /* This fontset is already set in frame F. There's nothing more
11507 return fontset_name (fontset
);
11509 result
= x_new_font (f
, (XSTRING (fontset_ascii (fontset
))->data
));
11511 if (!STRINGP (result
))
11512 /* Can't load ASCII font. */
11515 /* Since x_new_font doesn't update any fontset information, do it now. */
11516 f
->output_data
.x
->fontset
= fontset
;
11520 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
11521 xic_set_xfontset (f
, XSTRING (fontset_ascii (fontset
))->data
);
11524 return build_string (fontsetname
);
11528 /***********************************************************************
11530 ***********************************************************************/
11536 /* XIM destroy callback function, which is called whenever the
11537 connection to input method XIM dies. CLIENT_DATA contains a
11538 pointer to the x_display_info structure corresponding to XIM. */
11541 xim_destroy_callback (xim
, client_data
, call_data
)
11543 XPointer client_data
;
11544 XPointer call_data
;
11546 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
11547 Lisp_Object frame
, tail
;
11551 /* No need to call XDestroyIC.. */
11552 FOR_EACH_FRAME (tail
, frame
)
11554 struct frame
*f
= XFRAME (frame
);
11555 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
11557 FRAME_XIC (f
) = NULL
;
11558 if (FRAME_XIC_FONTSET (f
))
11560 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
11561 FRAME_XIC_FONTSET (f
) = NULL
;
11566 /* No need to call XCloseIM. */
11567 dpyinfo
->xim
= NULL
;
11568 XFree (dpyinfo
->xim_styles
);
11572 #endif /* HAVE_X11R6 */
11574 /* Open the connection to the XIM server on display DPYINFO.
11575 RESOURCE_NAME is the resource name Emacs uses. */
11578 xim_open_dpy (dpyinfo
, resource_name
)
11579 struct x_display_info
*dpyinfo
;
11580 char *resource_name
;
11585 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
, EMACS_CLASS
);
11586 dpyinfo
->xim
= xim
;
11591 XIMCallback destroy
;
11594 /* Get supported styles and XIM values. */
11595 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
11598 destroy
.callback
= xim_destroy_callback
;
11599 destroy
.client_data
= (XPointer
)dpyinfo
;
11600 /* This isn't prptotyped in OSF 5.0. */
11601 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
11605 #else /* not USE_XIM */
11606 dpyinfo
->xim
= NULL
;
11607 #endif /* not USE_XIM */
11611 #ifdef HAVE_X11R6_XIM
11615 struct x_display_info
*dpyinfo
;
11616 char *resource_name
;
11619 /* XIM instantiate callback function, which is called whenever an XIM
11620 server is available. DISPLAY is teh display of the XIM.
11621 CLIENT_DATA contains a pointer to an xim_inst_t structure created
11622 when the callback was registered. */
11625 xim_instantiate_callback (display
, client_data
, call_data
)
11627 XPointer client_data
;
11628 XPointer call_data
;
11630 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
11631 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
11633 /* We don't support multiple XIM connections. */
11637 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
11639 /* Create XIC for the existing frames on the same display, as long
11640 as they have no XIC. */
11641 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
11643 Lisp_Object tail
, frame
;
11646 FOR_EACH_FRAME (tail
, frame
)
11648 struct frame
*f
= XFRAME (frame
);
11650 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
11651 if (FRAME_XIC (f
) == NULL
)
11653 create_frame_xic (f
);
11654 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
11655 xic_set_statusarea (f
);
11656 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
11658 struct window
*w
= XWINDOW (f
->selected_window
);
11659 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
11668 #endif /* HAVE_X11R6_XIM */
11671 /* Open a connection to the XIM server on display DPYINFO.
11672 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
11673 connection only at the first time. On X11R6, open the connection
11674 in the XIM instantiate callback function. */
11677 xim_initialize (dpyinfo
, resource_name
)
11678 struct x_display_info
*dpyinfo
;
11679 char *resource_name
;
11682 #ifdef HAVE_X11R6_XIM
11683 struct xim_inst_t
*xim_inst
;
11686 dpyinfo
->xim
= NULL
;
11687 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
11688 xim_inst
->dpyinfo
= dpyinfo
;
11689 len
= strlen (resource_name
);
11690 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
11691 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
11692 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
11693 resource_name
, EMACS_CLASS
,
11694 xim_instantiate_callback
,
11695 /* Fixme: This is XPointer in
11696 XFree86 but (XPointer *) on
11697 Tru64, at least. */
11698 (XPointer
) xim_inst
);
11699 #else /* not HAVE_X11R6_XIM */
11700 dpyinfo
->xim
= NULL
;
11701 xim_open_dpy (dpyinfo
, resource_name
);
11702 #endif /* not HAVE_X11R6_XIM */
11704 #else /* not USE_XIM */
11705 dpyinfo
->xim
= NULL
;
11706 #endif /* not USE_XIM */
11710 /* Close the connection to the XIM server on display DPYINFO. */
11713 xim_close_dpy (dpyinfo
)
11714 struct x_display_info
*dpyinfo
;
11717 #ifdef HAVE_X11R6_XIM
11718 if (dpyinfo
->display
)
11719 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
11721 xim_instantiate_callback
, NULL
);
11722 #endif /* not HAVE_X11R6_XIM */
11723 if (dpyinfo
->display
)
11724 XCloseIM (dpyinfo
->xim
);
11725 dpyinfo
->xim
= NULL
;
11726 XFree (dpyinfo
->xim_styles
);
11727 #endif /* USE_XIM */
11730 #endif /* not HAVE_X11R6_XIM */
11734 /* Calculate the absolute position in frame F
11735 from its current recorded position values and gravity. */
11738 x_calc_absolute_position (f
)
11742 int win_x
= 0, win_y
= 0;
11743 int flags
= f
->output_data
.x
->size_hint_flags
;
11746 /* We have nothing to do if the current position
11747 is already for the top-left corner. */
11748 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
11751 #ifdef USE_X_TOOLKIT
11752 this_window
= XtWindow (f
->output_data
.x
->widget
);
11754 this_window
= FRAME_X_WINDOW (f
);
11757 /* Find the position of the outside upper-left corner of
11758 the inner window, with respect to the outer window.
11759 But do this only if we will need the results. */
11760 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
11765 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
11768 x_clear_errors (FRAME_X_DISPLAY (f
));
11769 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
11771 /* From-window, to-window. */
11773 f
->output_data
.x
->parent_desc
,
11775 /* From-position, to-position. */
11776 0, 0, &win_x
, &win_y
,
11778 /* Child of win. */
11780 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
11782 Window newroot
, newparent
= 0xdeadbeef;
11783 Window
*newchildren
;
11784 unsigned int nchildren
;
11786 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
11787 &newparent
, &newchildren
, &nchildren
))
11790 XFree ((char *) newchildren
);
11792 f
->output_data
.x
->parent_desc
= newparent
;
11798 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
11802 /* Treat negative positions as relative to the leftmost bottommost
11803 position that fits on the screen. */
11804 if (flags
& XNegative
)
11805 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
11806 - 2 * f
->output_data
.x
->border_width
- win_x
11808 + f
->output_data
.x
->left_pos
);
11811 int height
= PIXEL_HEIGHT (f
);
11813 #if defined USE_X_TOOLKIT && defined USE_MOTIF
11814 /* Something is fishy here. When using Motif, starting Emacs with
11815 `-g -0-0', the frame appears too low by a few pixels.
11817 This seems to be so because initially, while Emacs is starting,
11818 the column widget's height and the frame's pixel height are
11819 different. The column widget's height is the right one. In
11820 later invocations, when Emacs is up, the frame's pixel height
11823 It's not obvious where the initial small difference comes from.
11824 2000-12-01, gerd. */
11826 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
11829 if (flags
& YNegative
)
11830 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
11831 - 2 * f
->output_data
.x
->border_width
11834 + f
->output_data
.x
->top_pos
);
11837 /* The left_pos and top_pos
11838 are now relative to the top and left screen edges,
11839 so the flags should correspond. */
11840 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
11843 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
11844 to really change the position, and 0 when calling from
11845 x_make_frame_visible (in that case, XOFF and YOFF are the current
11846 position values). It is -1 when calling from x_set_frame_parameters,
11847 which means, do adjust for borders but don't change the gravity. */
11850 x_set_offset (f
, xoff
, yoff
, change_gravity
)
11852 register int xoff
, yoff
;
11853 int change_gravity
;
11855 int modified_top
, modified_left
;
11857 if (change_gravity
> 0)
11859 f
->output_data
.x
->top_pos
= yoff
;
11860 f
->output_data
.x
->left_pos
= xoff
;
11861 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
11863 f
->output_data
.x
->size_hint_flags
|= XNegative
;
11865 f
->output_data
.x
->size_hint_flags
|= YNegative
;
11866 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
11868 x_calc_absolute_position (f
);
11871 x_wm_set_size_hint (f
, (long) 0, 0);
11873 modified_left
= f
->output_data
.x
->left_pos
;
11874 modified_top
= f
->output_data
.x
->top_pos
;
11875 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
11876 this seems to be unnecessary and incorrect. rms, 4/17/97. */
11877 /* It is a mystery why we need to add the border_width here
11878 when the frame is already visible, but experiment says we do. */
11879 if (change_gravity
!= 0)
11881 modified_left
+= f
->output_data
.x
->border_width
;
11882 modified_top
+= f
->output_data
.x
->border_width
;
11886 #ifdef USE_X_TOOLKIT
11887 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
11888 modified_left
, modified_top
);
11889 #else /* not USE_X_TOOLKIT */
11890 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11891 modified_left
, modified_top
);
11892 #endif /* not USE_X_TOOLKIT */
11897 /* Change the size of frame F's X window to COLS/ROWS in the case F
11898 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
11899 top-left-corner window gravity for this size change and subsequent
11900 size changes. Otherwise we leave the window gravity unchanged. */
11903 x_set_window_size_1 (f
, change_gravity
, cols
, rows
)
11905 int change_gravity
;
11908 int pixelwidth
, pixelheight
;
11910 check_frame_size (f
, &rows
, &cols
);
11911 f
->output_data
.x
->vertical_scroll_bar_extra
11912 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
11914 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
11915 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
11916 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
11917 f
->output_data
.x
->flags_areas_extra
11918 = FRAME_FLAGS_AREA_WIDTH (f
);
11919 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
11920 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
11922 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
11923 x_wm_set_size_hint (f
, (long) 0, 0);
11925 XSync (FRAME_X_DISPLAY (f
), False
);
11926 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11927 pixelwidth
, pixelheight
);
11929 /* Now, strictly speaking, we can't be sure that this is accurate,
11930 but the window manager will get around to dealing with the size
11931 change request eventually, and we'll hear how it went when the
11932 ConfigureNotify event gets here.
11934 We could just not bother storing any of this information here,
11935 and let the ConfigureNotify event set everything up, but that
11936 might be kind of confusing to the Lisp code, since size changes
11937 wouldn't be reported in the frame parameters until some random
11938 point in the future when the ConfigureNotify event arrives.
11940 We pass 1 for DELAY since we can't run Lisp code inside of
11942 change_frame_size (f
, rows
, cols
, 0, 1, 0);
11943 PIXEL_WIDTH (f
) = pixelwidth
;
11944 PIXEL_HEIGHT (f
) = pixelheight
;
11946 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
11947 receive in the ConfigureNotify event; if we get what we asked
11948 for, then the event won't cause the screen to become garbaged, so
11949 we have to make sure to do it here. */
11950 SET_FRAME_GARBAGED (f
);
11952 XFlush (FRAME_X_DISPLAY (f
));
11956 /* Call this to change the size of frame F's x-window.
11957 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
11958 for this size change and subsequent size changes.
11959 Otherwise we leave the window gravity unchanged. */
11962 x_set_window_size (f
, change_gravity
, cols
, rows
)
11964 int change_gravity
;
11969 #ifdef USE_X_TOOLKIT
11971 if (f
->output_data
.x
->widget
!= None
)
11973 /* The x and y position of the widget is clobbered by the
11974 call to XtSetValues within EmacsFrameSetCharSize.
11975 This is a real kludge, but I don't understand Xt so I can't
11976 figure out a correct fix. Can anyone else tell me? -- rms. */
11977 int xpos
= f
->output_data
.x
->widget
->core
.x
;
11978 int ypos
= f
->output_data
.x
->widget
->core
.y
;
11979 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
11980 f
->output_data
.x
->widget
->core
.x
= xpos
;
11981 f
->output_data
.x
->widget
->core
.y
= ypos
;
11984 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
11986 #else /* not USE_X_TOOLKIT */
11988 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
11990 #endif /* not USE_X_TOOLKIT */
11992 /* If cursor was outside the new size, mark it as off. */
11993 mark_window_cursors_off (XWINDOW (f
->root_window
));
11995 /* Clear out any recollection of where the mouse highlighting was,
11996 since it might be in a place that's outside the new frame size.
11997 Actually checking whether it is outside is a pain in the neck,
11998 so don't try--just let the highlighting be done afresh with new size. */
11999 cancel_mouse_face (f
);
12004 /* Mouse warping. */
12007 x_set_mouse_position (f
, x
, y
)
12013 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
12014 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
12016 if (pix_x
< 0) pix_x
= 0;
12017 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
12019 if (pix_y
< 0) pix_y
= 0;
12020 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
12024 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
12025 0, 0, 0, 0, pix_x
, pix_y
);
12029 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
12032 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
12038 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
12039 0, 0, 0, 0, pix_x
, pix_y
);
12043 /* focus shifting, raising and lowering. */
12046 x_focus_on_frame (f
)
12049 #if 0 /* This proves to be unpleasant. */
12053 /* I don't think that the ICCCM allows programs to do things like this
12054 without the interaction of the window manager. Whatever you end up
12055 doing with this code, do it to x_unfocus_frame too. */
12056 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
12057 RevertToPointerRoot
, CurrentTime
);
12062 x_unfocus_frame (f
)
12066 /* Look at the remarks in x_focus_on_frame. */
12067 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
12068 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
12069 RevertToPointerRoot
, CurrentTime
);
12073 /* Raise frame F. */
12079 if (f
->async_visible
)
12082 #ifdef USE_X_TOOLKIT
12083 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
12084 #else /* not USE_X_TOOLKIT */
12085 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12086 #endif /* not USE_X_TOOLKIT */
12087 XFlush (FRAME_X_DISPLAY (f
));
12092 /* Lower frame F. */
12098 if (f
->async_visible
)
12101 #ifdef USE_X_TOOLKIT
12102 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
12103 #else /* not USE_X_TOOLKIT */
12104 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12105 #endif /* not USE_X_TOOLKIT */
12106 XFlush (FRAME_X_DISPLAY (f
));
12112 XTframe_raise_lower (f
, raise_flag
)
12122 /* Change of visibility. */
12124 /* This tries to wait until the frame is really visible.
12125 However, if the window manager asks the user where to position
12126 the frame, this will return before the user finishes doing that.
12127 The frame will not actually be visible at that time,
12128 but it will become visible later when the window manager
12129 finishes with it. */
12132 x_make_frame_visible (f
)
12136 int original_top
, original_left
;
12137 int retry_count
= 2;
12143 type
= x_icon_type (f
);
12145 x_bitmap_icon (f
, type
);
12147 if (! FRAME_VISIBLE_P (f
))
12149 /* We test FRAME_GARBAGED_P here to make sure we don't
12150 call x_set_offset a second time
12151 if we get to x_make_frame_visible a second time
12152 before the window gets really visible. */
12153 if (! FRAME_ICONIFIED_P (f
)
12154 && ! f
->output_data
.x
->asked_for_visible
)
12155 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
12157 f
->output_data
.x
->asked_for_visible
= 1;
12159 if (! EQ (Vx_no_window_manager
, Qt
))
12160 x_wm_set_window_state (f
, NormalState
);
12161 #ifdef USE_X_TOOLKIT
12162 /* This was XtPopup, but that did nothing for an iconified frame. */
12163 XtMapWidget (f
->output_data
.x
->widget
);
12164 #else /* not USE_X_TOOLKIT */
12165 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12166 #endif /* not USE_X_TOOLKIT */
12167 #if 0 /* This seems to bring back scroll bars in the wrong places
12168 if the window configuration has changed. They seem
12169 to come back ok without this. */
12170 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
12171 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12175 XFlush (FRAME_X_DISPLAY (f
));
12177 /* Synchronize to ensure Emacs knows the frame is visible
12178 before we do anything else. We do this loop with input not blocked
12179 so that incoming events are handled. */
12183 /* This must be before UNBLOCK_INPUT
12184 since events that arrive in response to the actions above
12185 will set it when they are handled. */
12186 int previously_visible
= f
->output_data
.x
->has_been_visible
;
12188 original_left
= f
->output_data
.x
->left_pos
;
12189 original_top
= f
->output_data
.x
->top_pos
;
12191 /* This must come after we set COUNT. */
12194 /* We unblock here so that arriving X events are processed. */
12196 /* Now move the window back to where it was "supposed to be".
12197 But don't do it if the gravity is negative.
12198 When the gravity is negative, this uses a position
12199 that is 3 pixels too low. Perhaps that's really the border width.
12201 Don't do this if the window has never been visible before,
12202 because the window manager may choose the position
12203 and we don't want to override it. */
12205 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
12206 && f
->output_data
.x
->win_gravity
== NorthWestGravity
12207 && previously_visible
)
12211 unsigned int width
, height
, border
, depth
;
12215 /* On some window managers (such as FVWM) moving an existing
12216 window, even to the same place, causes the window manager
12217 to introduce an offset. This can cause the window to move
12218 to an unexpected location. Check the geometry (a little
12219 slow here) and then verify that the window is in the right
12220 place. If the window is not in the right place, move it
12221 there, and take the potential window manager hit. */
12222 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
12223 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
12225 if (original_left
!= x
|| original_top
!= y
)
12226 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
12227 original_left
, original_top
);
12232 XSETFRAME (frame
, f
);
12234 /* Wait until the frame is visible. Process X events until a
12235 MapNotify event has been seen, or until we think we won't get a
12236 MapNotify at all.. */
12237 for (count
= input_signal_count
+ 10;
12238 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
12240 /* Force processing of queued events. */
12243 /* Machines that do polling rather than SIGIO have been
12244 observed to go into a busy-wait here. So we'll fake an
12245 alarm signal to let the handler know that there's something
12246 to be read. We used to raise a real alarm, but it seems
12247 that the handler isn't always enabled here. This is
12249 if (input_polling_used ())
12251 /* It could be confusing if a real alarm arrives while
12252 processing the fake one. Turn it off and let the
12253 handler reset it. */
12254 extern void poll_for_input_1
P_ ((void));
12255 int old_poll_suppress_count
= poll_suppress_count
;
12256 poll_suppress_count
= 1;
12257 poll_for_input_1 ();
12258 poll_suppress_count
= old_poll_suppress_count
;
12261 /* See if a MapNotify event has been processed. */
12262 FRAME_SAMPLE_VISIBILITY (f
);
12267 (let ((f (selected-frame)))
12271 the frame is not raised with various window managers on
12272 FreeBSD, Linux and Solaris. It turns out that, for some
12273 unknown reason, the call to XtMapWidget is completely ignored.
12274 Mapping the widget a second time works. */
12276 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
12281 /* Change from mapped state to withdrawn state. */
12283 /* Make the frame visible (mapped and not iconified). */
12286 x_make_frame_invisible (f
)
12291 #ifdef USE_X_TOOLKIT
12292 /* Use the frame's outermost window, not the one we normally draw on. */
12293 window
= XtWindow (f
->output_data
.x
->widget
);
12294 #else /* not USE_X_TOOLKIT */
12295 window
= FRAME_X_WINDOW (f
);
12296 #endif /* not USE_X_TOOLKIT */
12298 /* Don't keep the highlight on an invisible frame. */
12299 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
12300 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
12302 #if 0/* This might add unreliability; I don't trust it -- rms. */
12303 if (! f
->async_visible
&& ! f
->async_iconified
)
12309 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
12310 that the current position of the window is user-specified, rather than
12311 program-specified, so that when the window is mapped again, it will be
12312 placed at the same location, without forcing the user to position it
12313 by hand again (they have already done that once for this window.) */
12314 x_wm_set_size_hint (f
, (long) 0, 1);
12318 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
12319 DefaultScreen (FRAME_X_DISPLAY (f
))))
12321 UNBLOCK_INPUT_RESIGNAL
;
12322 error ("Can't notify window manager of window withdrawal");
12324 #else /* ! defined (HAVE_X11R4) */
12326 /* Tell the window manager what we're going to do. */
12327 if (! EQ (Vx_no_window_manager
, Qt
))
12331 unmap
.xunmap
.type
= UnmapNotify
;
12332 unmap
.xunmap
.window
= window
;
12333 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
12334 unmap
.xunmap
.from_configure
= False
;
12335 if (! XSendEvent (FRAME_X_DISPLAY (f
),
12336 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
12338 SubstructureRedirectMaskSubstructureNotifyMask
,
12341 UNBLOCK_INPUT_RESIGNAL
;
12342 error ("Can't notify window manager of withdrawal");
12346 /* Unmap the window ourselves. Cheeky! */
12347 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
12348 #endif /* ! defined (HAVE_X11R4) */
12350 /* We can't distinguish this from iconification
12351 just by the event that we get from the server.
12352 So we can't win using the usual strategy of letting
12353 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
12354 and synchronize with the server to make sure we agree. */
12356 FRAME_ICONIFIED_P (f
) = 0;
12357 f
->async_visible
= 0;
12358 f
->async_iconified
= 0;
12365 /* Change window state from mapped to iconified. */
12368 x_iconify_frame (f
)
12374 /* Don't keep the highlight on an invisible frame. */
12375 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
12376 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
12378 if (f
->async_iconified
)
12383 FRAME_SAMPLE_VISIBILITY (f
);
12385 type
= x_icon_type (f
);
12387 x_bitmap_icon (f
, type
);
12389 #ifdef USE_X_TOOLKIT
12391 if (! FRAME_VISIBLE_P (f
))
12393 if (! EQ (Vx_no_window_manager
, Qt
))
12394 x_wm_set_window_state (f
, IconicState
);
12395 /* This was XtPopup, but that did nothing for an iconified frame. */
12396 XtMapWidget (f
->output_data
.x
->widget
);
12397 /* The server won't give us any event to indicate
12398 that an invisible frame was changed to an icon,
12399 so we have to record it here. */
12402 f
->async_iconified
= 1;
12403 f
->async_visible
= 0;
12408 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
12409 XtWindow (f
->output_data
.x
->widget
),
12410 DefaultScreen (FRAME_X_DISPLAY (f
)));
12414 error ("Can't notify window manager of iconification");
12416 f
->async_iconified
= 1;
12417 f
->async_visible
= 0;
12421 XFlush (FRAME_X_DISPLAY (f
));
12423 #else /* not USE_X_TOOLKIT */
12425 /* Make sure the X server knows where the window should be positioned,
12426 in case the user deiconifies with the window manager. */
12427 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
12428 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
12430 /* Since we don't know which revision of X we're running, we'll use both
12431 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
12433 /* X11R4: send a ClientMessage to the window manager using the
12434 WM_CHANGE_STATE type. */
12438 message
.xclient
.window
= FRAME_X_WINDOW (f
);
12439 message
.xclient
.type
= ClientMessage
;
12440 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
12441 message
.xclient
.format
= 32;
12442 message
.xclient
.data
.l
[0] = IconicState
;
12444 if (! XSendEvent (FRAME_X_DISPLAY (f
),
12445 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
12447 SubstructureRedirectMask
| SubstructureNotifyMask
,
12450 UNBLOCK_INPUT_RESIGNAL
;
12451 error ("Can't notify window manager of iconification");
12455 /* X11R3: set the initial_state field of the window manager hints to
12457 x_wm_set_window_state (f
, IconicState
);
12459 if (!FRAME_VISIBLE_P (f
))
12461 /* If the frame was withdrawn, before, we must map it. */
12462 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12465 f
->async_iconified
= 1;
12466 f
->async_visible
= 0;
12468 XFlush (FRAME_X_DISPLAY (f
));
12470 #endif /* not USE_X_TOOLKIT */
12474 /* Free X resources of frame F. */
12477 x_free_frame_resources (f
)
12480 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12484 /* If a display connection is dead, don't try sending more
12485 commands to the X server. */
12486 if (dpyinfo
->display
)
12488 if (f
->output_data
.x
->icon_desc
)
12489 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
12493 free_frame_xic (f
);
12496 if (FRAME_X_WINDOW (f
))
12497 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12499 #ifdef USE_X_TOOLKIT
12500 if (f
->output_data
.x
->widget
)
12501 XtDestroyWidget (f
->output_data
.x
->widget
);
12502 free_frame_menubar (f
);
12503 #endif /* USE_X_TOOLKIT */
12505 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
12506 unload_color (f
, f
->output_data
.x
->background_pixel
);
12507 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
12508 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
12509 unload_color (f
, f
->output_data
.x
->border_pixel
);
12510 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
12512 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
12513 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
12514 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
12515 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
12516 if (f
->output_data
.x
->white_relief
.allocated_p
)
12517 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
12518 if (f
->output_data
.x
->black_relief
.allocated_p
)
12519 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
12521 if (FRAME_FACE_CACHE (f
))
12522 free_frame_faces (f
);
12525 XFlush (FRAME_X_DISPLAY (f
));
12528 if (f
->output_data
.x
->saved_menu_event
)
12529 xfree (f
->output_data
.x
->saved_menu_event
);
12531 xfree (f
->output_data
.x
);
12532 f
->output_data
.x
= NULL
;
12534 if (f
== dpyinfo
->x_focus_frame
)
12535 dpyinfo
->x_focus_frame
= 0;
12536 if (f
== dpyinfo
->x_focus_event_frame
)
12537 dpyinfo
->x_focus_event_frame
= 0;
12538 if (f
== dpyinfo
->x_highlight_frame
)
12539 dpyinfo
->x_highlight_frame
= 0;
12541 if (f
== dpyinfo
->mouse_face_mouse_frame
)
12543 dpyinfo
->mouse_face_beg_row
12544 = dpyinfo
->mouse_face_beg_col
= -1;
12545 dpyinfo
->mouse_face_end_row
12546 = dpyinfo
->mouse_face_end_col
= -1;
12547 dpyinfo
->mouse_face_window
= Qnil
;
12548 dpyinfo
->mouse_face_deferred_gc
= 0;
12549 dpyinfo
->mouse_face_mouse_frame
= 0;
12556 /* Destroy the X window of frame F. */
12559 x_destroy_window (f
)
12562 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12564 /* If a display connection is dead, don't try sending more
12565 commands to the X server. */
12566 if (dpyinfo
->display
!= 0)
12567 x_free_frame_resources (f
);
12569 dpyinfo
->reference_count
--;
12573 /* Setting window manager hints. */
12575 /* Set the normal size hints for the window manager, for frame F.
12576 FLAGS is the flags word to use--or 0 meaning preserve the flags
12577 that the window now has.
12578 If USER_POSITION is nonzero, we set the USPosition
12579 flag (this is useful when FLAGS is 0). */
12582 x_wm_set_size_hint (f
, flags
, user_position
)
12587 XSizeHints size_hints
;
12589 #ifdef USE_X_TOOLKIT
12592 Dimension widget_width
, widget_height
;
12593 Window window
= XtWindow (f
->output_data
.x
->widget
);
12594 #else /* not USE_X_TOOLKIT */
12595 Window window
= FRAME_X_WINDOW (f
);
12596 #endif /* not USE_X_TOOLKIT */
12598 /* Setting PMaxSize caused various problems. */
12599 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
12601 size_hints
.x
= f
->output_data
.x
->left_pos
;
12602 size_hints
.y
= f
->output_data
.x
->top_pos
;
12604 #ifdef USE_X_TOOLKIT
12605 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
12606 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
12607 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
12608 size_hints
.height
= widget_height
;
12609 size_hints
.width
= widget_width
;
12610 #else /* not USE_X_TOOLKIT */
12611 size_hints
.height
= PIXEL_HEIGHT (f
);
12612 size_hints
.width
= PIXEL_WIDTH (f
);
12613 #endif /* not USE_X_TOOLKIT */
12615 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
12616 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
12617 size_hints
.max_width
12618 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
12619 size_hints
.max_height
12620 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
12622 /* Calculate the base and minimum sizes.
12624 (When we use the X toolkit, we don't do it here.
12625 Instead we copy the values that the widgets are using, below.) */
12626 #ifndef USE_X_TOOLKIT
12628 int base_width
, base_height
;
12629 int min_rows
= 0, min_cols
= 0;
12631 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
12632 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
12634 check_frame_size (f
, &min_rows
, &min_cols
);
12636 /* The window manager uses the base width hints to calculate the
12637 current number of rows and columns in the frame while
12638 resizing; min_width and min_height aren't useful for this
12639 purpose, since they might not give the dimensions for a
12640 zero-row, zero-column frame.
12642 We use the base_width and base_height members if we have
12643 them; otherwise, we set the min_width and min_height members
12644 to the size for a zero x zero frame. */
12647 size_hints
.flags
|= PBaseSize
;
12648 size_hints
.base_width
= base_width
;
12649 size_hints
.base_height
= base_height
;
12650 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
12651 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
12653 size_hints
.min_width
= base_width
;
12654 size_hints
.min_height
= base_height
;
12658 /* If we don't need the old flags, we don't need the old hint at all. */
12661 size_hints
.flags
|= flags
;
12664 #endif /* not USE_X_TOOLKIT */
12667 XSizeHints hints
; /* Sometimes I hate X Windows... */
12668 long supplied_return
;
12672 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
12675 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
12678 #ifdef USE_X_TOOLKIT
12679 size_hints
.base_height
= hints
.base_height
;
12680 size_hints
.base_width
= hints
.base_width
;
12681 size_hints
.min_height
= hints
.min_height
;
12682 size_hints
.min_width
= hints
.min_width
;
12686 size_hints
.flags
|= flags
;
12691 if (hints
.flags
& PSize
)
12692 size_hints
.flags
|= PSize
;
12693 if (hints
.flags
& PPosition
)
12694 size_hints
.flags
|= PPosition
;
12695 if (hints
.flags
& USPosition
)
12696 size_hints
.flags
|= USPosition
;
12697 if (hints
.flags
& USSize
)
12698 size_hints
.flags
|= USSize
;
12702 #ifndef USE_X_TOOLKIT
12707 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
12708 size_hints
.flags
|= PWinGravity
;
12712 size_hints
.flags
&= ~ PPosition
;
12713 size_hints
.flags
|= USPosition
;
12715 #endif /* PWinGravity */
12718 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
12720 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
12724 /* Used for IconicState or NormalState */
12727 x_wm_set_window_state (f
, state
)
12731 #ifdef USE_X_TOOLKIT
12734 XtSetArg (al
[0], XtNinitialState
, state
);
12735 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
12736 #else /* not USE_X_TOOLKIT */
12737 Window window
= FRAME_X_WINDOW (f
);
12739 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
12740 f
->output_data
.x
->wm_hints
.initial_state
= state
;
12742 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12743 #endif /* not USE_X_TOOLKIT */
12747 x_wm_set_icon_pixmap (f
, pixmap_id
)
12751 Pixmap icon_pixmap
;
12753 #ifndef USE_X_TOOLKIT
12754 Window window
= FRAME_X_WINDOW (f
);
12759 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
12760 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
12764 /* It seems there is no way to turn off use of an icon pixmap.
12765 The following line does it, only if no icon has yet been created,
12766 for some window managers. But with mwm it crashes.
12767 Some people say it should clear the IconPixmapHint bit in this case,
12768 but that doesn't work, and the X consortium said it isn't the
12769 right thing at all. Since there is no way to win,
12770 best to explicitly give up. */
12772 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
12778 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
12782 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
12783 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
12786 #else /* not USE_X_TOOLKIT */
12788 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
12789 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12791 #endif /* not USE_X_TOOLKIT */
12795 x_wm_set_icon_position (f
, icon_x
, icon_y
)
12797 int icon_x
, icon_y
;
12799 #ifdef USE_X_TOOLKIT
12800 Window window
= XtWindow (f
->output_data
.x
->widget
);
12802 Window window
= FRAME_X_WINDOW (f
);
12805 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
12806 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
12807 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
12809 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12813 /***********************************************************************
12815 ***********************************************************************/
12817 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
12820 x_get_font_info (f
, font_idx
)
12824 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
12828 /* Return a list of names of available fonts matching PATTERN on frame F.
12830 If SIZE is > 0, it is the size (maximum bounds width) of fonts
12833 SIZE < 0 means include scalable fonts.
12835 Frame F null means we have not yet created any frame on X, and
12836 consult the first display in x_display_list. MAXNAMES sets a limit
12837 on how many fonts to match. */
12840 x_list_fonts (f
, pattern
, size
, maxnames
)
12842 Lisp_Object pattern
;
12846 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
12847 Lisp_Object tem
, second_best
;
12848 struct x_display_info
*dpyinfo
12849 = f
? FRAME_X_DISPLAY_INFO (f
) : x_display_list
;
12850 Display
*dpy
= dpyinfo
->display
;
12851 int try_XLoadQueryFont
= 0;
12853 int allow_scalable_fonts_p
= 0;
12857 allow_scalable_fonts_p
= 1;
12861 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
12862 if (NILP (patterns
))
12863 patterns
= Fcons (pattern
, Qnil
);
12865 if (maxnames
== 1 && !size
)
12866 /* We can return any single font matching PATTERN. */
12867 try_XLoadQueryFont
= 1;
12869 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
12872 char **names
= NULL
;
12874 pattern
= XCAR (patterns
);
12875 /* See if we cached the result for this particular query.
12876 The cache is an alist of the form:
12877 ((((PATTERN . MAXNAMES) . SCALABLE) (FONTNAME . WIDTH) ...) ...) */
12878 tem
= XCDR (dpyinfo
->name_list_element
);
12879 key
= Fcons (Fcons (pattern
, make_number (maxnames
)),
12880 allow_scalable_fonts_p
? Qt
: Qnil
);
12881 list
= Fassoc (key
, tem
);
12884 list
= Fcdr_safe (list
);
12885 /* We have a cashed list. Don't have to get the list again. */
12889 /* At first, put PATTERN in the cache. */
12892 count
= x_catch_errors (dpy
);
12894 if (try_XLoadQueryFont
)
12897 unsigned long value
;
12899 font
= XLoadQueryFont (dpy
, XSTRING (pattern
)->data
);
12900 if (x_had_errors_p (dpy
))
12902 /* This error is perhaps due to insufficient memory on X
12903 server. Let's just ignore it. */
12905 x_clear_errors (dpy
);
12909 && XGetFontProperty (font
, XA_FONT
, &value
))
12911 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
12912 int len
= strlen (name
);
12915 /* If DXPC (a Differential X Protocol Compressor)
12916 Ver.3.7 is running, XGetAtomName will return null
12917 string. We must avoid such a name. */
12919 try_XLoadQueryFont
= 0;
12923 names
= (char **) alloca (sizeof (char *));
12924 /* Some systems only allow alloca assigned to a
12926 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
12927 bcopy (name
, names
[0], len
+ 1);
12932 try_XLoadQueryFont
= 0;
12935 XFreeFont (dpy
, font
);
12938 if (!try_XLoadQueryFont
)
12940 /* We try at least 10 fonts because XListFonts will return
12941 auto-scaled fonts at the head. */
12942 names
= XListFonts (dpy
, XSTRING (pattern
)->data
, max (maxnames
, 10),
12944 if (x_had_errors_p (dpy
))
12946 /* This error is perhaps due to insufficient memory on X
12947 server. Let's just ignore it. */
12949 x_clear_errors (dpy
);
12953 x_uncatch_errors (dpy
, count
);
12960 /* Make a list of all the fonts we got back.
12961 Store that in the font cache for the display. */
12962 for (i
= 0; i
< num_fonts
; i
++)
12965 char *p
= names
[i
];
12966 int average_width
= -1, dashes
= 0;
12968 /* Count the number of dashes in NAMES[I]. If there are
12969 14 dashes, and the field value following 12th dash
12970 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
12971 is usually too ugly to be used for editing. Let's
12977 if (dashes
== 7) /* PIXEL_SIZE field */
12979 else if (dashes
== 12) /* AVERAGE_WIDTH field */
12980 average_width
= atoi (p
);
12983 if (allow_scalable_fonts_p
12984 || dashes
< 14 || average_width
!= 0)
12986 tem
= build_string (names
[i
]);
12987 if (NILP (Fassoc (tem
, list
)))
12989 if (STRINGP (Vx_pixel_size_width_font_regexp
)
12990 && ((fast_c_string_match_ignore_case
12991 (Vx_pixel_size_width_font_regexp
, names
[i
]))
12993 /* We can set the value of PIXEL_SIZE to the
12994 width of this font. */
12995 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
12997 /* For the moment, width is not known. */
12998 list
= Fcons (Fcons (tem
, Qnil
), list
);
13002 if (!try_XLoadQueryFont
)
13003 XFreeFontNames (names
);
13006 /* Now store the result in the cache. */
13007 XCDR (dpyinfo
->name_list_element
)
13008 = Fcons (Fcons (key
, list
), XCDR (dpyinfo
->name_list_element
));
13011 if (NILP (list
)) continue; /* Try the remaining alternatives. */
13013 newlist
= second_best
= Qnil
;
13014 /* Make a list of the fonts that have the right width. */
13015 for (; CONSP (list
); list
= XCDR (list
))
13021 if (!CONSP (tem
) || NILP (XCAR (tem
)))
13025 newlist
= Fcons (XCAR (tem
), newlist
);
13029 if (!INTEGERP (XCDR (tem
)))
13031 /* Since we have not yet known the size of this font, we
13032 must try slow function call XLoadQueryFont. */
13033 XFontStruct
*thisinfo
;
13036 count
= x_catch_errors (dpy
);
13037 thisinfo
= XLoadQueryFont (dpy
,
13038 XSTRING (XCAR (tem
))->data
);
13039 if (x_had_errors_p (dpy
))
13041 /* This error is perhaps due to insufficient memory on X
13042 server. Let's just ignore it. */
13044 x_clear_errors (dpy
);
13046 x_uncatch_errors (dpy
, count
);
13052 = (thisinfo
->min_bounds
.width
== 0
13054 : make_number (thisinfo
->max_bounds
.width
));
13055 XFreeFont (dpy
, thisinfo
);
13058 /* For unknown reason, the previous call of XListFont had
13059 returned a font which can't be opened. Record the size
13060 as 0 not to try to open it again. */
13061 XCDR (tem
) = make_number (0);
13064 found_size
= XINT (XCDR (tem
));
13065 if (found_size
== size
)
13066 newlist
= Fcons (XCAR (tem
), newlist
);
13067 else if (found_size
> 0)
13069 if (NILP (second_best
))
13071 else if (found_size
< size
)
13073 if (XINT (XCDR (second_best
)) > size
13074 || XINT (XCDR (second_best
)) < found_size
)
13079 if (XINT (XCDR (second_best
)) > size
13080 && XINT (XCDR (second_best
)) > found_size
)
13085 if (!NILP (newlist
))
13087 else if (!NILP (second_best
))
13089 newlist
= Fcons (XCAR (second_best
), Qnil
);
13100 /* Check that FONT is valid on frame F. It is if it can be found in F's
13104 x_check_font (f
, font
)
13109 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13111 xassert (font
!= NULL
);
13113 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
13114 if (dpyinfo
->font_table
[i
].name
13115 && font
== dpyinfo
->font_table
[i
].font
)
13118 xassert (i
< dpyinfo
->n_fonts
);
13121 #endif /* GLYPH_DEBUG != 0 */
13123 /* Set *W to the minimum width, *H to the minimum font height of FONT.
13124 Note: There are (broken) X fonts out there with invalid XFontStruct
13125 min_bounds contents. For example, handa@etl.go.jp reports that
13126 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
13127 have font->min_bounds.width == 0. */
13130 x_font_min_bounds (font
, w
, h
)
13134 *h
= FONT_HEIGHT (font
);
13135 *w
= font
->min_bounds
.width
;
13137 /* Try to handle the case where FONT->min_bounds has invalid
13138 contents. Since the only font known to have invalid min_bounds
13139 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
13141 *w
= font
->max_bounds
.width
;
13145 /* Compute the smallest character width and smallest font height over
13146 all fonts available on frame F. Set the members smallest_char_width
13147 and smallest_font_height in F's x_display_info structure to
13148 the values computed. Value is non-zero if smallest_font_height or
13149 smallest_char_width become smaller than they were before. */
13152 x_compute_min_glyph_bounds (f
)
13156 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13158 int old_width
= dpyinfo
->smallest_char_width
;
13159 int old_height
= dpyinfo
->smallest_font_height
;
13161 dpyinfo
->smallest_font_height
= 100000;
13162 dpyinfo
->smallest_char_width
= 100000;
13164 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
13165 if (dpyinfo
->font_table
[i
].name
)
13167 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
13170 font
= (XFontStruct
*) fontp
->font
;
13171 xassert (font
!= (XFontStruct
*) ~0);
13172 x_font_min_bounds (font
, &w
, &h
);
13174 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
13175 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
13178 xassert (dpyinfo
->smallest_char_width
> 0
13179 && dpyinfo
->smallest_font_height
> 0);
13181 return (dpyinfo
->n_fonts
== 1
13182 || dpyinfo
->smallest_char_width
< old_width
13183 || dpyinfo
->smallest_font_height
< old_height
);
13187 /* Load font named FONTNAME of the size SIZE for frame F, and return a
13188 pointer to the structure font_info while allocating it dynamically.
13189 If SIZE is 0, load any size of font.
13190 If loading is failed, return NULL. */
13193 x_load_font (f
, fontname
, size
)
13195 register char *fontname
;
13198 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13199 Lisp_Object font_names
;
13202 /* Get a list of all the fonts that match this name. Once we
13203 have a list of matching fonts, we compare them against the fonts
13204 we already have by comparing names. */
13205 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
13207 if (!NILP (font_names
))
13212 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
13213 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
13214 if (dpyinfo
->font_table
[i
].name
13215 && (!strcmp (dpyinfo
->font_table
[i
].name
,
13216 XSTRING (XCAR (tail
))->data
)
13217 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
13218 XSTRING (XCAR (tail
))->data
)))
13219 return (dpyinfo
->font_table
+ i
);
13222 /* Load the font and add it to the table. */
13226 struct font_info
*fontp
;
13227 unsigned long value
;
13230 /* If we have found fonts by x_list_font, load one of them. If
13231 not, we still try to load a font by the name given as FONTNAME
13232 because XListFonts (called in x_list_font) of some X server has
13233 a bug of not finding a font even if the font surely exists and
13234 is loadable by XLoadQueryFont. */
13235 if (size
> 0 && !NILP (font_names
))
13236 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
13239 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
13240 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
13241 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
13243 /* This error is perhaps due to insufficient memory on X
13244 server. Let's just ignore it. */
13246 x_clear_errors (FRAME_X_DISPLAY (f
));
13248 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
13253 /* Find a free slot in the font table. */
13254 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
13255 if (dpyinfo
->font_table
[i
].name
== NULL
)
13258 /* If no free slot found, maybe enlarge the font table. */
13259 if (i
== dpyinfo
->n_fonts
13260 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
13263 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
13264 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
13265 dpyinfo
->font_table
13266 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
13269 fontp
= dpyinfo
->font_table
+ i
;
13270 if (i
== dpyinfo
->n_fonts
)
13271 ++dpyinfo
->n_fonts
;
13273 /* Now fill in the slots of *FONTP. */
13275 fontp
->font
= font
;
13276 fontp
->font_idx
= i
;
13277 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
13278 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
13280 /* Try to get the full name of FONT. Put it in FULL_NAME. */
13282 if (XGetFontProperty (font
, XA_FONT
, &value
))
13284 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
13288 /* Count the number of dashes in the "full name".
13289 If it is too few, this isn't really the font's full name,
13291 In X11R4, the fonts did not come with their canonical names
13302 full_name
= (char *) xmalloc (p
- name
+ 1);
13303 bcopy (name
, full_name
, p
- name
+ 1);
13309 if (full_name
!= 0)
13310 fontp
->full_name
= full_name
;
13312 fontp
->full_name
= fontp
->name
;
13314 fontp
->size
= font
->max_bounds
.width
;
13315 fontp
->height
= FONT_HEIGHT (font
);
13317 if (NILP (font_names
))
13319 /* We come here because of a bug of XListFonts mentioned at
13320 the head of this block. Let's store this information in
13321 the cache for x_list_fonts. */
13322 Lisp_Object lispy_name
= build_string (fontname
);
13323 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
13324 Lisp_Object key
= Fcons (Fcons (lispy_name
, make_number (256)),
13327 XCDR (dpyinfo
->name_list_element
)
13328 = Fcons (Fcons (key
,
13329 Fcons (Fcons (lispy_full_name
,
13330 make_number (fontp
->size
)),
13332 XCDR (dpyinfo
->name_list_element
));
13335 key
= Fcons (Fcons (lispy_full_name
, make_number (256)),
13337 XCDR (dpyinfo
->name_list_element
)
13338 = Fcons (Fcons (key
,
13339 Fcons (Fcons (lispy_full_name
,
13340 make_number (fontp
->size
)),
13342 XCDR (dpyinfo
->name_list_element
));
13346 /* The slot `encoding' specifies how to map a character
13347 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
13348 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
13349 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
13350 2:0xA020..0xFF7F). For the moment, we don't know which charset
13351 uses this font. So, we set information in fontp->encoding[1]
13352 which is never used by any charset. If mapping can't be
13353 decided, set FONT_ENCODING_NOT_DECIDED. */
13355 = (font
->max_byte1
== 0
13357 ? (font
->min_char_or_byte2
< 0x80
13358 ? (font
->max_char_or_byte2
< 0x80
13359 ? 0 /* 0x20..0x7F */
13360 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
13361 : 1) /* 0xA0..0xFF */
13363 : (font
->min_byte1
< 0x80
13364 ? (font
->max_byte1
< 0x80
13365 ? (font
->min_char_or_byte2
< 0x80
13366 ? (font
->max_char_or_byte2
< 0x80
13367 ? 0 /* 0x2020..0x7F7F */
13368 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
13369 : 3) /* 0x20A0..0x7FFF */
13370 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
13371 : (font
->min_char_or_byte2
< 0x80
13372 ? (font
->max_char_or_byte2
< 0x80
13373 ? 2 /* 0xA020..0xFF7F */
13374 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
13375 : 1))); /* 0xA0A0..0xFFFF */
13377 fontp
->baseline_offset
13378 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
13379 ? (long) value
: 0);
13380 fontp
->relative_compose
13381 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
13382 ? (long) value
: 0);
13383 fontp
->default_ascent
13384 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
13385 ? (long) value
: 0);
13387 /* Set global flag fonts_changed_p to non-zero if the font loaded
13388 has a character with a smaller width than any other character
13389 before, or if the font loaded has a smalle>r height than any
13390 other font loaded before. If this happens, it will make a
13391 glyph matrix reallocation necessary. */
13392 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
13399 /* Return a pointer to struct font_info of a font named FONTNAME for
13400 frame F. If no such font is loaded, return NULL. */
13403 x_query_font (f
, fontname
)
13405 register char *fontname
;
13407 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13410 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
13411 if (dpyinfo
->font_table
[i
].name
13412 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
13413 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
13414 return (dpyinfo
->font_table
+ i
);
13419 /* Find a CCL program for a font specified by FONTP, and set the member
13420 `encoder' of the structure. */
13423 x_find_ccl_program (fontp
)
13424 struct font_info
*fontp
;
13426 Lisp_Object list
, elt
;
13429 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
13433 && STRINGP (XCAR (elt
))
13434 && ((fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
13436 || (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->full_name
)
13443 struct ccl_program
*ccl
13444 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
13446 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
13449 fontp
->font_encoder
= ccl
;
13455 /***********************************************************************
13457 ***********************************************************************/
13459 #ifdef USE_X_TOOLKIT
13460 static XrmOptionDescRec emacs_options
[] = {
13461 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
13462 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
13464 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
13465 XrmoptionSepArg
, NULL
},
13466 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
13468 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13469 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13470 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13471 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
13472 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
13473 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
13474 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
13476 #endif /* USE_X_TOOLKIT */
13478 static int x_initialized
;
13480 #ifdef MULTI_KBOARD
13481 /* Test whether two display-name strings agree up to the dot that separates
13482 the screen number from the server number. */
13484 same_x_server (name1
, name2
)
13485 char *name1
, *name2
;
13487 int seen_colon
= 0;
13488 unsigned char *system_name
= XSTRING (Vsystem_name
)->data
;
13489 int system_name_length
= strlen (system_name
);
13490 int length_until_period
= 0;
13492 while (system_name
[length_until_period
] != 0
13493 && system_name
[length_until_period
] != '.')
13494 length_until_period
++;
13496 /* Treat `unix' like an empty host name. */
13497 if (! strncmp (name1
, "unix:", 5))
13499 if (! strncmp (name2
, "unix:", 5))
13501 /* Treat this host's name like an empty host name. */
13502 if (! strncmp (name1
, system_name
, system_name_length
)
13503 && name1
[system_name_length
] == ':')
13504 name1
+= system_name_length
;
13505 if (! strncmp (name2
, system_name
, system_name_length
)
13506 && name2
[system_name_length
] == ':')
13507 name2
+= system_name_length
;
13508 /* Treat this host's domainless name like an empty host name. */
13509 if (! strncmp (name1
, system_name
, length_until_period
)
13510 && name1
[length_until_period
] == ':')
13511 name1
+= length_until_period
;
13512 if (! strncmp (name2
, system_name
, length_until_period
)
13513 && name2
[length_until_period
] == ':')
13514 name2
+= length_until_period
;
13516 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
13520 if (seen_colon
&& *name1
== '.')
13524 && (*name1
== '.' || *name1
== '\0')
13525 && (*name2
== '.' || *name2
== '\0'));
13529 struct x_display_info
*
13530 x_term_init (display_name
, xrm_option
, resource_name
)
13531 Lisp_Object display_name
;
13533 char *resource_name
;
13537 struct x_display_info
*dpyinfo
;
13542 if (!x_initialized
)
13548 #ifdef USE_X_TOOLKIT
13549 /* weiner@footloose.sps.mot.com reports that this causes
13551 X protocol error: BadAtom (invalid Atom parameter)
13552 on protocol request 18skiloaf.
13553 So let's not use it until R6. */
13554 #ifdef HAVE_X11XTR6
13555 XtSetLanguageProc (NULL
, NULL
, NULL
);
13566 argv
[argc
++] = "-xrm";
13567 argv
[argc
++] = xrm_option
;
13569 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
13570 resource_name
, EMACS_CLASS
,
13571 emacs_options
, XtNumber (emacs_options
),
13574 #ifdef HAVE_X11XTR6
13575 /* I think this is to compensate for XtSetLanguageProc. */
13580 #else /* not USE_X_TOOLKIT */
13582 XSetLocaleModifiers ("");
13584 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
13585 #endif /* not USE_X_TOOLKIT */
13587 /* Detect failure. */
13594 /* We have definitely succeeded. Record the new connection. */
13596 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
13597 bzero (dpyinfo
, sizeof *dpyinfo
);
13599 #ifdef MULTI_KBOARD
13601 struct x_display_info
*share
;
13604 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
13605 share
= share
->next
, tail
= XCDR (tail
))
13606 if (same_x_server (XSTRING (XCAR (XCAR (tail
)))->data
,
13607 XSTRING (display_name
)->data
))
13610 dpyinfo
->kboard
= share
->kboard
;
13613 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
13614 init_kboard (dpyinfo
->kboard
);
13615 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
13617 char *vendor
= ServerVendor (dpy
);
13619 dpyinfo
->kboard
->Vsystem_key_alist
13620 = call1 (Qvendor_specific_keysyms
,
13621 build_string (vendor
? vendor
: ""));
13625 dpyinfo
->kboard
->next_kboard
= all_kboards
;
13626 all_kboards
= dpyinfo
->kboard
;
13627 /* Don't let the initial kboard remain current longer than necessary.
13628 That would cause problems if a file loaded on startup tries to
13629 prompt in the mini-buffer. */
13630 if (current_kboard
== initial_kboard
)
13631 current_kboard
= dpyinfo
->kboard
;
13633 dpyinfo
->kboard
->reference_count
++;
13637 /* Put this display on the chain. */
13638 dpyinfo
->next
= x_display_list
;
13639 x_display_list
= dpyinfo
;
13641 /* Put it on x_display_name_list as well, to keep them parallel. */
13642 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
13643 x_display_name_list
);
13644 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
13646 dpyinfo
->display
= dpy
;
13649 XSetAfterFunction (x_current_display
, x_trace_wire
);
13653 = (char *) xmalloc (STRING_BYTES (XSTRING (Vinvocation_name
))
13654 + STRING_BYTES (XSTRING (Vsystem_name
))
13656 sprintf (dpyinfo
->x_id_name
, "%s@%s",
13657 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
13659 /* Figure out which modifier bits mean what. */
13660 x_find_modifier_meanings (dpyinfo
);
13662 /* Get the scroll bar cursor. */
13663 dpyinfo
->vertical_scroll_bar_cursor
13664 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
13666 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
13667 resource_name
, EMACS_CLASS
);
13668 #ifdef HAVE_XRMSETDATABASE
13669 XrmSetDatabase (dpyinfo
->display
, xrdb
);
13671 dpyinfo
->display
->db
= xrdb
;
13673 /* Put the rdb where we can find it in a way that works on
13675 dpyinfo
->xrdb
= xrdb
;
13677 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
13678 DefaultScreen (dpyinfo
->display
));
13679 select_visual (dpyinfo
);
13680 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
13681 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
13682 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
13683 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
13684 dpyinfo
->grabbed
= 0;
13685 dpyinfo
->reference_count
= 0;
13686 dpyinfo
->icon_bitmap_id
= -1;
13687 dpyinfo
->font_table
= NULL
;
13688 dpyinfo
->n_fonts
= 0;
13689 dpyinfo
->font_table_size
= 0;
13690 dpyinfo
->bitmaps
= 0;
13691 dpyinfo
->bitmaps_size
= 0;
13692 dpyinfo
->bitmaps_last
= 0;
13693 dpyinfo
->scratch_cursor_gc
= 0;
13694 dpyinfo
->mouse_face_mouse_frame
= 0;
13695 dpyinfo
->mouse_face_deferred_gc
= 0;
13696 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
13697 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
13698 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
13699 dpyinfo
->mouse_face_window
= Qnil
;
13700 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
13701 dpyinfo
->mouse_face_defer
= 0;
13702 dpyinfo
->x_focus_frame
= 0;
13703 dpyinfo
->x_focus_event_frame
= 0;
13704 dpyinfo
->x_highlight_frame
= 0;
13705 dpyinfo
->image_cache
= make_image_cache ();
13707 /* See if a private colormap is requested. */
13708 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
13710 if (dpyinfo
->visual
->class == PseudoColor
)
13713 value
= display_x_get_resource (dpyinfo
,
13714 build_string ("privateColormap"),
13715 build_string ("PrivateColormap"),
13717 if (STRINGP (value
)
13718 && (!strcmp (XSTRING (value
)->data
, "true")
13719 || !strcmp (XSTRING (value
)->data
, "on")))
13720 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
13724 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
13725 dpyinfo
->visual
, AllocNone
);
13728 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
13729 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
13730 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
13731 dpyinfo
->resy
= pixels
* 25.4 / mm
;
13732 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
13733 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
13734 dpyinfo
->resx
= pixels
* 25.4 / mm
;
13737 dpyinfo
->Xatom_wm_protocols
13738 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
13739 dpyinfo
->Xatom_wm_take_focus
13740 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
13741 dpyinfo
->Xatom_wm_save_yourself
13742 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
13743 dpyinfo
->Xatom_wm_delete_window
13744 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
13745 dpyinfo
->Xatom_wm_change_state
13746 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
13747 dpyinfo
->Xatom_wm_configure_denied
13748 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
13749 dpyinfo
->Xatom_wm_window_moved
13750 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
13751 dpyinfo
->Xatom_editres
13752 = XInternAtom (dpyinfo
->display
, "Editres", False
);
13753 dpyinfo
->Xatom_CLIPBOARD
13754 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
13755 dpyinfo
->Xatom_TIMESTAMP
13756 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
13757 dpyinfo
->Xatom_TEXT
13758 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
13759 dpyinfo
->Xatom_COMPOUND_TEXT
13760 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
13761 dpyinfo
->Xatom_DELETE
13762 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
13763 dpyinfo
->Xatom_MULTIPLE
13764 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
13765 dpyinfo
->Xatom_INCR
13766 = XInternAtom (dpyinfo
->display
, "INCR", False
);
13767 dpyinfo
->Xatom_EMACS_TMP
13768 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
13769 dpyinfo
->Xatom_TARGETS
13770 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
13771 dpyinfo
->Xatom_NULL
13772 = XInternAtom (dpyinfo
->display
, "NULL", False
);
13773 dpyinfo
->Xatom_ATOM_PAIR
13774 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
13775 /* For properties of font. */
13776 dpyinfo
->Xatom_PIXEL_SIZE
13777 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
13778 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
13779 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
13780 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
13781 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
13782 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
13783 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
13785 /* Ghostscript support. */
13786 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
13787 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
13789 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
13792 dpyinfo
->cut_buffers_initialized
= 0;
13794 connection
= ConnectionNumber (dpyinfo
->display
);
13795 dpyinfo
->connection
= connection
;
13800 null_bits
[0] = 0x00;
13802 dpyinfo
->null_pixel
13803 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
13804 null_bits
, 1, 1, (long) 0, (long) 0,
13809 extern int gray_bitmap_width
, gray_bitmap_height
;
13810 extern char *gray_bitmap_bits
;
13812 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
13814 gray_bitmap_width
, gray_bitmap_height
,
13815 (unsigned long) 1, (unsigned long) 0, 1);
13819 xim_initialize (dpyinfo
, resource_name
);
13822 #ifdef subprocesses
13823 /* This is only needed for distinguishing keyboard and process input. */
13824 if (connection
!= 0)
13825 add_keyboard_wait_descriptor (connection
);
13828 #ifndef F_SETOWN_BUG
13830 #ifdef F_SETOWN_SOCK_NEG
13831 /* stdin is a socket here */
13832 fcntl (connection
, F_SETOWN
, -getpid ());
13833 #else /* ! defined (F_SETOWN_SOCK_NEG) */
13834 fcntl (connection
, F_SETOWN
, getpid ());
13835 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
13836 #endif /* ! defined (F_SETOWN) */
13837 #endif /* F_SETOWN_BUG */
13840 if (interrupt_input
)
13841 init_sigio (connection
);
13842 #endif /* ! defined (SIGIO) */
13845 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
13846 /* Make sure that we have a valid font for dialog boxes
13847 so that Xt does not crash. */
13849 Display
*dpy
= dpyinfo
->display
;
13850 XrmValue d
, fr
, to
;
13854 d
.addr
= (XPointer
)&dpy
;
13855 d
.size
= sizeof (Display
*);
13856 fr
.addr
= XtDefaultFont
;
13857 fr
.size
= sizeof (XtDefaultFont
);
13858 to
.size
= sizeof (Font
*);
13859 to
.addr
= (XPointer
)&font
;
13860 count
= x_catch_errors (dpy
);
13861 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
13863 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
13864 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
13865 x_uncatch_errors (dpy
, count
);
13870 /* See if we should run in synchronous mode. This is useful
13871 for debugging X code. */
13874 value
= display_x_get_resource (dpyinfo
,
13875 build_string ("synchronous"),
13876 build_string ("Synchronous"),
13878 if (STRINGP (value
)
13879 && (!strcmp (XSTRING (value
)->data
, "true")
13880 || !strcmp (XSTRING (value
)->data
, "on")))
13881 XSynchronize (dpyinfo
->display
, True
);
13889 /* Get rid of display DPYINFO, assuming all frames are already gone,
13890 and without sending any more commands to the X server. */
13893 x_delete_display (dpyinfo
)
13894 struct x_display_info
*dpyinfo
;
13896 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
13898 /* Discard this display from x_display_name_list and x_display_list.
13899 We can't use Fdelq because that can quit. */
13900 if (! NILP (x_display_name_list
)
13901 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
13902 x_display_name_list
= XCDR (x_display_name_list
);
13907 tail
= x_display_name_list
;
13908 while (CONSP (tail
) && CONSP (XCDR (tail
)))
13910 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
13912 XCDR (tail
) = XCDR (XCDR (tail
));
13915 tail
= XCDR (tail
);
13919 if (next_noop_dpyinfo
== dpyinfo
)
13920 next_noop_dpyinfo
= dpyinfo
->next
;
13922 if (x_display_list
== dpyinfo
)
13923 x_display_list
= dpyinfo
->next
;
13926 struct x_display_info
*tail
;
13928 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
13929 if (tail
->next
== dpyinfo
)
13930 tail
->next
= tail
->next
->next
;
13933 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
13934 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
13935 XrmDestroyDatabase (dpyinfo
->xrdb
);
13938 #ifdef MULTI_KBOARD
13939 if (--dpyinfo
->kboard
->reference_count
== 0)
13940 delete_kboard (dpyinfo
->kboard
);
13944 xim_close_dpy (dpyinfo
);
13947 xfree (dpyinfo
->font_table
);
13948 xfree (dpyinfo
->x_id_name
);
13949 xfree (dpyinfo
->color_cells
);
13954 /* Set up use of X before we make the first connection. */
13956 static struct redisplay_interface x_redisplay_interface
=
13961 x_clear_end_of_line
,
13963 x_after_update_window_line
,
13964 x_update_window_begin
,
13965 x_update_window_end
,
13968 x_clear_mouse_face
,
13969 x_get_glyph_overhangs
,
13970 x_fix_overlapping_area
13976 rif
= &x_redisplay_interface
;
13978 clear_frame_hook
= x_clear_frame
;
13979 ins_del_lines_hook
= x_ins_del_lines
;
13980 change_line_highlight_hook
= x_change_line_highlight
;
13981 delete_glyphs_hook
= x_delete_glyphs
;
13982 ring_bell_hook
= XTring_bell
;
13983 reset_terminal_modes_hook
= XTreset_terminal_modes
;
13984 set_terminal_modes_hook
= XTset_terminal_modes
;
13985 update_begin_hook
= x_update_begin
;
13986 update_end_hook
= x_update_end
;
13987 set_terminal_window_hook
= XTset_terminal_window
;
13988 read_socket_hook
= XTread_socket
;
13989 frame_up_to_date_hook
= XTframe_up_to_date
;
13990 reassert_line_highlight_hook
= XTreassert_line_highlight
;
13991 mouse_position_hook
= XTmouse_position
;
13992 frame_rehighlight_hook
= XTframe_rehighlight
;
13993 frame_raise_lower_hook
= XTframe_raise_lower
;
13994 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
13995 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
13996 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
13997 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
13998 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
14000 scroll_region_ok
= 1; /* we'll scroll partial frames */
14001 char_ins_del_ok
= 1;
14002 line_ins_del_ok
= 1; /* we'll just blt 'em */
14003 fast_clear_end_of_line
= 1; /* X does this well */
14004 memory_below_frame
= 0; /* we don't remember what scrolls
14009 last_tool_bar_item
= -1;
14010 any_help_event_p
= 0;
14012 /* Try to use interrupt input; if we can't, then start polling. */
14013 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
14015 #ifdef USE_X_TOOLKIT
14016 XtToolkitInitialize ();
14017 Xt_app_con
= XtCreateApplicationContext ();
14018 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
14020 /* Install an asynchronous timer that processes Xt timeout events
14021 every 0.1s. This is necessary because some widget sets use
14022 timeouts internally, for example the LessTif menu bar, or the
14023 Xaw3d scroll bar. When Xt timouts aren't processed, these
14024 widgets don't behave normally. */
14026 EMACS_TIME interval
;
14027 EMACS_SET_SECS_USECS (interval
, 0, 100000);
14028 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
14032 #ifdef USE_TOOLKIT_SCROLL_BARS
14033 xaw3d_arrow_scroll
= False
;
14034 xaw3d_pick_top
= True
;
14037 /* Note that there is no real way portable across R3/R4 to get the
14038 original error handler. */
14039 XSetErrorHandler (x_error_handler
);
14040 XSetIOErrorHandler (x_io_error_quitter
);
14042 /* Disable Window Change signals; they are handled by X events. */
14044 signal (SIGWINCH
, SIG_DFL
);
14045 #endif /* ! defined (SIGWINCH) */
14047 signal (SIGPIPE
, x_connection_signal
);
14054 staticpro (&x_error_message_string
);
14055 x_error_message_string
= Qnil
;
14057 staticpro (&x_display_name_list
);
14058 x_display_name_list
= Qnil
;
14060 staticpro (&last_mouse_scroll_bar
);
14061 last_mouse_scroll_bar
= Qnil
;
14063 staticpro (&Qvendor_specific_keysyms
);
14064 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
14066 staticpro (&last_mouse_press_frame
);
14067 last_mouse_press_frame
= Qnil
;
14070 staticpro (&help_echo
);
14071 help_echo_object
= Qnil
;
14072 staticpro (&help_echo_object
);
14073 help_echo_window
= Qnil
;
14074 staticpro (&help_echo_window
);
14075 previous_help_echo
= Qnil
;
14076 staticpro (&previous_help_echo
);
14077 help_echo_pos
= -1;
14079 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
14080 "*Non-nil means draw block cursor as wide as the glyph under it.\n\
14081 For example, if a block cursor is over a tab, it will be drawn as\n\
14082 wide as that tab on the display.");
14083 x_stretch_cursor_p
= 0;
14085 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
14086 "What X toolkit scroll bars Emacs uses.\n\
14087 A value of nil means Emacs doesn't use X toolkit scroll bars.\n\
14088 Otherwise, value is a symbol describing the X toolkit.");
14089 #ifdef USE_TOOLKIT_SCROLL_BARS
14091 Vx_toolkit_scroll_bars
= intern ("motif");
14092 #elif defined HAVE_XAW3D
14093 Vx_toolkit_scroll_bars
= intern ("xaw3d");
14095 Vx_toolkit_scroll_bars
= intern ("xaw");
14098 Vx_toolkit_scroll_bars
= Qnil
;
14101 staticpro (&last_mouse_motion_frame
);
14102 last_mouse_motion_frame
= Qnil
;
14105 #endif /* not HAVE_X_WINDOWS */