1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 93, 94, 95, 96, 1997, 1998, 1999, 2000
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New display code by Gerd Moellmann <gerd@gnu.org>. */
23 /* Xt features made by Fred Pierresteguy. */
27 /* On 4.3 these lose if they come after xterm.h. */
28 /* Putting these at the beginning seems to be standard for other .c files. */
36 #include "blockinput.h"
38 /* Need syssignal.h for various externs and definitions that may be required
39 by some configurations for calls to signal later in this source file. */
40 #include "syssignal.h"
42 /* This may include sys/types.h, and that somehow loses
43 if this is not done before the other system files. */
45 #include <X11/cursorfont.h>
47 /* Load sys/types.h if not already loaded.
48 In some systems loading it twice is suicidal. */
50 #include <sys/types.h>
54 #include <sys/ioctl.h>
55 #endif /* ! defined (BSD_SYSTEM) */
60 #ifndef INCLUDED_FCNTL
67 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
68 /* #include <sys/param.h> */
74 #include "dispextern.h"
76 #include "termhooks.h"
88 #include "intervals.h"
93 #include <X11/Shell.h>
96 #ifdef HAVE_SYS_TIME_H
105 extern void free_frame_menubar
P_ ((struct frame
*));
106 extern struct frame
*x_menubar_window_to_frame
P_ ((struct x_display_info
*,
109 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
111 extern void _XEditResCheckMessages ();
112 #endif /* not NO_EDITRES */
114 /* Include toolkit specific headers for the scroll bar widget. */
116 #ifdef USE_TOOLKIT_SCROLL_BARS
117 #if defined USE_MOTIF
118 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
119 #include <Xm/ScrollBar.h>
120 #include <Xm/ScrollBarP.h>
121 #else /* !USE_MOTIF i.e. use Xaw */
124 #include <X11/Xaw3d/Simple.h>
125 #include <X11/Xaw3d/Scrollbar.h>
126 #define ARROW_SCROLLBAR
127 #include <X11/Xaw3d/ScrollbarP.h>
128 #else /* !HAVE_XAW3D */
129 #include <X11/Xaw/Simple.h>
130 #include <X11/Xaw/Scrollbar.h>
131 #endif /* !HAVE_XAW3D */
133 #define XtNpickTop "pickTop"
134 #endif /* !XtNpickTop */
135 #endif /* !USE_MOTIF */
136 #endif /* USE_TOOLKIT_SCROLL_BARS */
138 #endif /* USE_X_TOOLKIT */
140 #ifndef USE_X_TOOLKIT
141 #define x_any_window_to_frame x_window_to_frame
142 #define x_top_window_to_frame x_window_to_frame
147 #ifndef XtNinitialState
148 #define XtNinitialState "initialState"
153 #define min(a,b) ((a) < (b) ? (a) : (b))
156 #define max(a,b) ((a) > (b) ? (a) : (b))
159 #define abs(x) ((x) < 0 ? -(x) : (x))
161 #define BETWEEN(X, LOWER, UPPER) ((X) >= (LOWER) && (X) < (UPPER))
164 /* Bitmaps for truncated lines. */
169 LEFT_TRUNCATION_BITMAP
,
170 RIGHT_TRUNCATION_BITMAP
,
171 OVERLAY_ARROW_BITMAP
,
172 CONTINUED_LINE_BITMAP
,
173 CONTINUATION_LINE_BITMAP
,
177 /* Bitmap drawn to indicate lines not displaying text if
178 `indicate-empty-lines' is non-nil. */
182 static unsigned char zv_bits
[] = {
183 0x00, 0x00, 0x1e, 0x1e, 0x1e, 0x1e, 0x00, 0x00};
185 /* An arrow like this: `<-'. */
188 #define left_height 8
189 static unsigned char left_bits
[] = {
190 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
192 /* Right truncation arrow bitmap `->'. */
194 #define right_width 8
195 #define right_height 8
196 static unsigned char right_bits
[] = {
197 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
199 /* Marker for continued lines. */
201 #define continued_width 8
202 #define continued_height 8
203 static unsigned char continued_bits
[] = {
204 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
206 /* Marker for continuation lines. */
208 #define continuation_width 8
209 #define continuation_height 8
210 static unsigned char continuation_bits
[] = {
211 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
213 /* Overlay arrow bitmap. */
219 static unsigned char ov_bits
[] = {
220 0x30, 0x08, 0x3c, 0x7e, 0x7a, 0x7a, 0x62, 0x3c};
222 /* A triangular arrow. */
225 static unsigned char ov_bits
[] = {
226 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
230 extern Lisp_Object Qhelp_echo
;
233 /* Non-zero means Emacs uses toolkit scroll bars. */
235 int x_toolkit_scroll_bars_p
;
237 /* If a string, XTread_socket generates an event to display that string.
238 (The display is done in read_char.) */
240 static Lisp_Object help_echo
;
241 static Lisp_Object help_echo_window
;
242 static Lisp_Object help_echo_object
;
243 static int help_echo_pos
;
245 /* Temporary variable for XTread_socket. */
247 static Lisp_Object previous_help_echo
;
249 /* Non-zero means that a HELP_EVENT has been generated since Emacs
252 static int any_help_event_p
;
254 /* Non-zero means draw block and hollow cursor as wide as the glyph
255 under it. For example, if a block cursor is over a tab, it will be
256 drawn as wide as that tab on the display. */
258 int x_stretch_cursor_p
;
260 /* This is a chain of structures for all the X displays currently in
263 struct x_display_info
*x_display_list
;
265 /* This is a list of cons cells, each of the form (NAME
266 . FONT-LIST-CACHE), one for each element of x_display_list and in
267 the same order. NAME is the name of the frame. FONT-LIST-CACHE
268 records previous values returned by x-list-fonts. */
270 Lisp_Object x_display_name_list
;
272 /* Frame being updated by update_frame. This is declared in term.c.
273 This is set by update_begin and looked at by all the XT functions.
274 It is zero while not inside an update. In that case, the XT
275 functions assume that `selected_frame' is the frame to apply to. */
277 extern struct frame
*updating_frame
;
279 extern int waiting_for_input
;
281 /* This is a frame waiting to be auto-raised, within XTread_socket. */
283 struct frame
*pending_autoraise_frame
;
286 /* The application context for Xt use. */
287 XtAppContext Xt_app_con
;
288 static String Xt_default_resources
[] = {0};
289 #endif /* USE_X_TOOLKIT */
291 /* Nominal cursor position -- where to draw output.
292 HPOS and VPOS are window relative glyph matrix coordinates.
293 X and Y are window relative pixel coordinates. */
295 struct cursor_pos output_cursor
;
297 /* Non-zero means user is interacting with a toolkit scroll bar. */
299 static int toolkit_scroll_bar_interaction
;
303 Formerly, we used PointerMotionHintMask (in standard_event_mask)
304 so that we would have to call XQueryPointer after each MotionNotify
305 event to ask for another such event. However, this made mouse tracking
306 slow, and there was a bug that made it eventually stop.
308 Simply asking for MotionNotify all the time seems to work better.
310 In order to avoid asking for motion events and then throwing most
311 of them away or busy-polling the server for mouse positions, we ask
312 the server for pointer motion hints. This means that we get only
313 one event per group of mouse movements. "Groups" are delimited by
314 other kinds of events (focus changes and button clicks, for
315 example), or by XQueryPointer calls; when one of these happens, we
316 get another MotionNotify event the next time the mouse moves. This
317 is at least as efficient as getting motion events when mouse
318 tracking is on, and I suspect only negligibly worse when tracking
321 /* Where the mouse was last time we reported a mouse event. */
323 FRAME_PTR last_mouse_frame
;
324 static XRectangle last_mouse_glyph
;
325 static Lisp_Object last_mouse_press_frame
;
327 /* The scroll bar in which the last X motion event occurred.
329 If the last X motion event occurred in a scroll bar, we set this so
330 XTmouse_position can know whether to report a scroll bar motion or
333 If the last X motion event didn't occur in a scroll bar, we set
334 this to Qnil, to tell XTmouse_position to return an ordinary motion
337 static Lisp_Object last_mouse_scroll_bar
;
339 /* This is a hack. We would really prefer that XTmouse_position would
340 return the time associated with the position it returns, but there
341 doesn't seem to be any way to wrest the time-stamp from the server
342 along with the position query. So, we just keep track of the time
343 of the last movement we received, and return that in hopes that
344 it's somewhat accurate. */
346 static Time last_mouse_movement_time
;
348 /* Incremented by XTread_socket whenever it really tries to read
352 static int volatile input_signal_count
;
354 static int input_signal_count
;
357 /* Used locally within XTread_socket. */
359 static int x_noop_count
;
361 /* Initial values of argv and argc. */
363 extern char **initial_argv
;
364 extern int initial_argc
;
366 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
368 /* Tells if a window manager is present or not. */
370 extern Lisp_Object Vx_no_window_manager
;
372 extern Lisp_Object Qface
, Qmouse_face
;
376 /* A mask of extra modifier bits to put into every keyboard char. */
378 extern int extra_keyboard_modifiers
;
380 static Lisp_Object Qvendor_specific_keysyms
;
382 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
383 extern Lisp_Object x_icon_type
P_ ((struct frame
*));
386 /* Enumeration for overriding/changing the face to use for drawing
387 glyphs in x_draw_glyphs. */
389 enum draw_glyphs_face
399 static void x_update_window_end
P_ ((struct window
*, int, int));
400 static void frame_to_window_pixel_xy
P_ ((struct window
*, int *, int *));
401 void x_delete_display
P_ ((struct x_display_info
*));
402 static unsigned int x_x_to_emacs_modifiers
P_ ((struct x_display_info
*,
404 static int fast_find_position
P_ ((struct window
*, int, int *, int *,
406 static void set_output_cursor
P_ ((struct cursor_pos
*));
407 static struct glyph
*x_y_to_hpos_vpos
P_ ((struct window
*, int, int,
408 int *, int *, int *));
409 static void note_mode_line_highlight
P_ ((struct window
*, int, int));
410 static void note_mouse_highlight
P_ ((struct frame
*, int, int));
411 static void note_tool_bar_highlight
P_ ((struct frame
*f
, int, int));
412 static void x_handle_tool_bar_click
P_ ((struct frame
*, XButtonEvent
*));
413 static void show_mouse_face
P_ ((struct x_display_info
*,
414 enum draw_glyphs_face
));
415 static int x_io_error_quitter
P_ ((Display
*));
416 int x_catch_errors
P_ ((Display
*));
417 void x_uncatch_errors
P_ ((Display
*, int));
418 void x_lower_frame
P_ ((struct frame
*));
419 void x_scroll_bar_clear
P_ ((struct frame
*));
420 int x_had_errors_p
P_ ((Display
*));
421 void x_wm_set_size_hint
P_ ((struct frame
*, long, int));
422 void x_raise_frame
P_ ((struct frame
*));
423 void x_set_window_size
P_ ((struct frame
*, int, int, int));
424 void x_wm_set_window_state
P_ ((struct frame
*, int));
425 void x_wm_set_icon_pixmap
P_ ((struct frame
*, int));
426 void x_initialize
P_ ((void));
427 static void x_font_min_bounds
P_ ((XFontStruct
*, int *, int *));
428 static int x_compute_min_glyph_bounds
P_ ((struct frame
*));
429 static void x_draw_phys_cursor_glyph
P_ ((struct window
*,
431 enum draw_glyphs_face
));
432 static void x_update_end
P_ ((struct frame
*));
433 static void XTframe_up_to_date
P_ ((struct frame
*));
434 static void XTreassert_line_highlight
P_ ((int, int));
435 static void x_change_line_highlight
P_ ((int, int, int, int));
436 static void XTset_terminal_modes
P_ ((void));
437 static void XTreset_terminal_modes
P_ ((void));
438 static void XTcursor_to
P_ ((int, int, int, int));
439 static void x_write_glyphs
P_ ((struct glyph
*, int));
440 static void x_clear_end_of_line
P_ ((int));
441 static void x_clear_frame
P_ ((void));
442 static void x_clear_cursor
P_ ((struct window
*));
443 static void frame_highlight
P_ ((struct frame
*));
444 static void frame_unhighlight
P_ ((struct frame
*));
445 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
446 static void XTframe_rehighlight
P_ ((struct frame
*));
447 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
448 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
449 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int));
450 static int x_intersect_rectangles
P_ ((XRectangle
*, XRectangle
*,
452 static void expose_frame
P_ ((struct frame
*, int, int, int, int));
453 static void expose_window_tree
P_ ((struct window
*, XRectangle
*));
454 static void expose_window
P_ ((struct window
*, XRectangle
*));
455 static void expose_area
P_ ((struct window
*, struct glyph_row
*,
456 XRectangle
*, enum glyph_row_area
));
457 static void expose_line
P_ ((struct window
*, struct glyph_row
*,
459 static void x_update_cursor_in_window_tree
P_ ((struct window
*, int));
460 static void x_update_window_cursor
P_ ((struct window
*, int));
461 static void x_erase_phys_cursor
P_ ((struct window
*));
462 void x_display_and_set_cursor
P_ ((struct window
*, int, int, int, int, int));
463 static void x_draw_bitmap
P_ ((struct window
*, struct glyph_row
*,
466 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*,
468 static int x_phys_cursor_in_rect_p
P_ ((struct window
*, XRectangle
*));
469 static void x_draw_row_bitmaps
P_ ((struct window
*, struct glyph_row
*));
470 static void note_overwritten_text_cursor
P_ ((struct window
*, int, int));
471 static void x_flush
P_ ((struct frame
*f
));
472 static void x_update_begin
P_ ((struct frame
*));
473 static void x_update_window_begin
P_ ((struct window
*));
474 static void x_draw_vertical_border
P_ ((struct window
*));
475 static void x_after_update_window_line
P_ ((struct glyph_row
*));
476 static INLINE
void take_vertical_position_into_account
P_ ((struct it
*));
477 static void x_produce_stretch_glyph
P_ ((struct it
*));
480 /* Flush display of frame F, or of all frames if F is null. */
489 Lisp_Object rest
, frame
;
490 FOR_EACH_FRAME (rest
, frame
)
491 x_flush (XFRAME (frame
));
493 else if (FRAME_X_P (f
))
494 XFlush (FRAME_X_DISPLAY (f
));
499 /* Remove calls to XFlush by defining XFlush to an empty replacement.
500 Calls to XFlush should be unnecessary because the X output buffer
501 is flushed automatically as needed by calls to XPending,
502 XNextEvent, or XWindowEvent according to the XFlush man page.
503 XTread_socket calls XPending. Removing XFlush improves
506 #define XFlush(DISPLAY) (void) 0
509 /***********************************************************************
511 ***********************************************************************/
515 /* This is a function useful for recording debugging information about
516 the sequence of occurrences in this file. */
524 struct record event_record
[100];
526 int event_record_index
;
528 record_event (locus
, type
)
532 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
533 event_record_index
= 0;
535 event_record
[event_record_index
].locus
= locus
;
536 event_record
[event_record_index
].type
= type
;
537 event_record_index
++;
544 /* Return the struct x_display_info corresponding to DPY. */
546 struct x_display_info
*
547 x_display_info_for_display (dpy
)
550 struct x_display_info
*dpyinfo
;
552 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
553 if (dpyinfo
->display
== dpy
)
561 /***********************************************************************
562 Starting and ending an update
563 ***********************************************************************/
565 /* Start an update of frame F. This function is installed as a hook
566 for update_begin, i.e. it is called when update_begin is called.
567 This function is called prior to calls to x_update_window_begin for
568 each window being updated. Currently, there is nothing to do here
569 because all interesting stuff is done on a window basis. */
579 /* Start update of window W. Set the global variable updated_window
580 to the window being updated and set output_cursor to the cursor
584 x_update_window_begin (w
)
587 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
588 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
591 set_output_cursor (&w
->cursor
);
595 if (f
== display_info
->mouse_face_mouse_frame
)
597 /* Don't do highlighting for mouse motion during the update. */
598 display_info
->mouse_face_defer
= 1;
600 /* If F needs to be redrawn, simply forget about any prior mouse
602 if (FRAME_GARBAGED_P (f
))
603 display_info
->mouse_face_window
= Qnil
;
605 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
606 their mouse_face_p flag set, which means that they are always
607 unequal to rows in a desired matrix which never have that
608 flag set. So, rows containing mouse-face glyphs are never
609 scrolled, and we don't have to switch the mouse highlight off
610 here to prevent it from being scrolled. */
612 /* Can we tell that this update does not affect the window
613 where the mouse highlight is? If so, no need to turn off.
614 Likewise, don't do anything if the frame is garbaged;
615 in that case, the frame's current matrix that we would use
616 is all wrong, and we will redisplay that line anyway. */
617 if (!NILP (display_info
->mouse_face_window
)
618 && w
== XWINDOW (display_info
->mouse_face_window
))
622 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
623 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
626 if (i
< w
->desired_matrix
->nrows
)
627 clear_mouse_face (display_info
);
636 /* Draw a vertical window border to the right of window W if W doesn't
637 have vertical scroll bars. */
640 x_draw_vertical_border (w
)
643 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
645 /* Redraw borders between horizontally adjacent windows. Don't
646 do it for frames with vertical scroll bars because either the
647 right scroll bar of a window, or the left scroll bar of its
648 neighbor will suffice as a border. */
649 if (!WINDOW_RIGHTMOST_P (w
)
650 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
654 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
655 x1
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
);
658 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
659 f
->output_data
.x
->normal_gc
, x1
, y0
, x1
, y1
);
664 /* End update of window W (which is equal to updated_window).
666 Draw vertical borders between horizontally adjacent windows, and
667 display W's cursor if CURSOR_ON_P is non-zero.
669 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
670 glyphs in mouse-face were overwritten. In that case we have to
671 make sure that the mouse-highlight is properly redrawn.
673 W may be a menu bar pseudo-window in case we don't have X toolkit
674 support. Such windows don't have a cursor, so don't display it
678 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
680 int cursor_on_p
, mouse_face_overwritten_p
;
682 if (!w
->pseudo_window_p
)
684 struct x_display_info
*dpyinfo
685 = FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
689 /* If a row with mouse-face was overwritten, arrange for
690 XTframe_up_to_date to redisplay the mouse highlight. */
691 if (mouse_face_overwritten_p
)
693 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
694 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
695 dpyinfo
->mouse_face_window
= Qnil
;
699 x_display_and_set_cursor (w
, 1, output_cursor
.hpos
,
701 output_cursor
.x
, output_cursor
.y
);
703 x_draw_vertical_border (w
);
707 updated_window
= NULL
;
711 /* End update of frame F. This function is installed as a hook in
718 /* Mouse highlight may be displayed again. */
719 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
722 XFlush (FRAME_X_DISPLAY (f
));
727 /* This function is called from various places in xdisp.c whenever a
728 complete update has been performed. The global variable
729 updated_window is not available here. */
732 XTframe_up_to_date (f
)
737 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
739 if (dpyinfo
->mouse_face_deferred_gc
740 || f
== dpyinfo
->mouse_face_mouse_frame
)
743 if (dpyinfo
->mouse_face_mouse_frame
)
744 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
745 dpyinfo
->mouse_face_mouse_x
,
746 dpyinfo
->mouse_face_mouse_y
);
747 dpyinfo
->mouse_face_deferred_gc
= 0;
754 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
755 arrow bitmaps, or clear the areas where they would be displayed
756 before DESIRED_ROW is made current. The window being updated is
757 found in updated_window. This function It is called from
758 update_window_line only if it is known that there are differences
759 between bitmaps to be drawn between current row and DESIRED_ROW. */
762 x_after_update_window_line (desired_row
)
763 struct glyph_row
*desired_row
;
765 struct window
*w
= updated_window
;
769 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
772 x_draw_row_bitmaps (w
, desired_row
);
774 /* When a window has disappeared, make sure that no rest of
775 full-width rows stays visible in the internal border. */
776 if (windows_or_buffers_changed
)
778 struct frame
*f
= XFRAME (w
->frame
);
779 int width
= FRAME_INTERNAL_BORDER_WIDTH (f
);
780 int height
= desired_row
->visible_height
;
781 int x
= (window_box_right (w
, -1)
782 + FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
));
783 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
785 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
786 x
, y
, width
, height
, False
);
794 /* Draw the bitmap WHICH in one of the areas to the left or right of
795 window W. ROW is the glyph row for which to display the bitmap; it
796 determines the vertical position at which the bitmap has to be
800 x_draw_bitmap (w
, row
, which
)
802 struct glyph_row
*row
;
803 enum bitmap_type which
;
805 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
806 Display
*display
= FRAME_X_DISPLAY (f
);
807 Window window
= FRAME_X_WINDOW (f
);
811 GC gc
= f
->output_data
.x
->normal_gc
;
813 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
815 /* Must clip because of partially visible lines. */
816 x_clip_to_row (w
, row
, gc
, 1);
820 case LEFT_TRUNCATION_BITMAP
:
824 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
826 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
829 case OVERLAY_ARROW_BITMAP
:
833 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
835 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
838 case RIGHT_TRUNCATION_BITMAP
:
842 x
= window_box_right (w
, -1);
843 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
846 case CONTINUED_LINE_BITMAP
:
849 bits
= continued_bits
;
850 x
= window_box_right (w
, -1);
851 x
+= (FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
) - wd
) / 2;
854 case CONTINUATION_LINE_BITMAP
:
855 wd
= continuation_width
;
856 h
= continuation_height
;
857 bits
= continuation_bits
;
858 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
860 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
867 x
= (WINDOW_TO_FRAME_PIXEL_X (w
, 0)
869 - (FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - wd
) / 2);
876 /* Convert to frame coordinates. Set dy to the offset in the row to
877 start drawing the bitmap. */
878 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
879 dy
= (row
->height
- h
) / 2;
881 /* Draw the bitmap. I believe these small pixmaps can be cached
883 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
884 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, wd
, h
,
886 face
->background
, depth
);
887 XCopyArea (display
, pixmap
, window
, gc
, 0, 0, wd
, h
, x
, y
+ dy
);
888 XFreePixmap (display
, pixmap
);
889 XSetClipMask (display
, gc
, None
);
893 /* Draw flags bitmaps for glyph row ROW on window W. Call this
894 function with input blocked. */
897 x_draw_row_bitmaps (w
, row
)
899 struct glyph_row
*row
;
901 struct frame
*f
= XFRAME (w
->frame
);
902 enum bitmap_type bitmap
;
904 int header_line_height
= -1;
906 xassert (interrupt_input_blocked
);
908 /* If row is completely invisible, because of vscrolling, we
909 don't have to draw anything. */
910 if (row
->visible_height
<= 0)
913 face
= FACE_FROM_ID (f
, BITMAP_AREA_FACE_ID
);
914 PREPARE_FACE_FOR_DISPLAY (f
, face
);
916 /* Decide which bitmap to draw at the left side. */
917 if (row
->overlay_arrow_p
)
918 bitmap
= OVERLAY_ARROW_BITMAP
;
919 else if (row
->truncated_on_left_p
)
920 bitmap
= LEFT_TRUNCATION_BITMAP
;
921 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
922 bitmap
= CONTINUATION_LINE_BITMAP
;
923 else if (row
->indicate_empty_line_p
)
924 bitmap
= ZV_LINE_BITMAP
;
928 /* Clear flags area if no bitmap to draw or if bitmap doesn't fill
930 if (bitmap
== NO_BITMAP
931 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
932 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
934 /* If W has a vertical border to its left, don't draw over it. */
935 int border
= ((XFASTINT (w
->left
) > 0
936 && !FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
938 int left
= window_box_left (w
, -1);
940 if (header_line_height
< 0)
941 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
943 /* In case the same realized face is used for bitmap areas and
944 for something displayed in the text (e.g. face `region' on
945 mono-displays, the fill style may have been changed to
946 FillSolid in x_draw_glyph_string_background. */
948 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
950 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
952 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
955 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
957 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
959 FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
) - border
,
960 row
->visible_height
);
962 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
965 /* Draw the left bitmap. */
966 if (bitmap
!= NO_BITMAP
)
967 x_draw_bitmap (w
, row
, bitmap
);
969 /* Decide which bitmap to draw at the right side. */
970 if (row
->truncated_on_right_p
)
971 bitmap
= RIGHT_TRUNCATION_BITMAP
;
972 else if (row
->continued_p
)
973 bitmap
= CONTINUED_LINE_BITMAP
;
977 /* Clear flags area if no bitmap to draw of if bitmap doesn't fill
979 if (bitmap
== NO_BITMAP
980 || FRAME_FLAGS_BITMAP_WIDTH (f
) < FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
)
981 || row
->height
> FRAME_FLAGS_BITMAP_HEIGHT (f
))
983 int right
= window_box_right (w
, -1);
985 if (header_line_height
< 0)
986 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
988 /* In case the same realized face is used for bitmap areas and
989 for something displayed in the text (e.g. face `region' on
990 mono-displays, the fill style may have been changed to
991 FillSolid in x_draw_glyph_string_background. */
993 XSetFillStyle (FRAME_X_DISPLAY (f
), face
->gc
, FillOpaqueStippled
);
995 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->background
);
996 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
999 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
1001 FRAME_X_RIGHT_FLAGS_AREA_WIDTH (f
),
1002 row
->visible_height
);
1004 XSetForeground (FRAME_X_DISPLAY (f
), face
->gc
, face
->foreground
);
1007 /* Draw the right bitmap. */
1008 if (bitmap
!= NO_BITMAP
)
1009 x_draw_bitmap (w
, row
, bitmap
);
1013 /***********************************************************************
1015 ***********************************************************************/
1017 /* External interface to control of standout mode. Not used for X
1018 frames. Aborts when called. */
1021 XTreassert_line_highlight (new, vpos
)
1028 /* Call this when about to modify line at position VPOS and change
1029 whether it is highlighted. Not used for X frames. Aborts when
1033 x_change_line_highlight (new_highlight
, vpos
, y
, first_unused_hpos
)
1034 int new_highlight
, vpos
, y
, first_unused_hpos
;
1040 /* This is called when starting Emacs and when restarting after
1041 suspend. When starting Emacs, no X window is mapped. And nothing
1042 must be done to Emacs's own window if it is suspended (though that
1046 XTset_terminal_modes ()
1050 /* This is called when exiting or suspending Emacs. Exiting will make
1051 the X-windows go away, and suspending requires no action. */
1054 XTreset_terminal_modes ()
1060 /***********************************************************************
1062 ***********************************************************************/
1064 /* Set the global variable output_cursor to CURSOR. All cursor
1065 positions are relative to updated_window. */
1068 set_output_cursor (cursor
)
1069 struct cursor_pos
*cursor
;
1071 output_cursor
.hpos
= cursor
->hpos
;
1072 output_cursor
.vpos
= cursor
->vpos
;
1073 output_cursor
.x
= cursor
->x
;
1074 output_cursor
.y
= cursor
->y
;
1078 /* Set a nominal cursor position.
1080 HPOS and VPOS are column/row positions in a window glyph matrix. X
1081 and Y are window text area relative pixel positions.
1083 If this is done during an update, updated_window will contain the
1084 window that is being updated and the position is the future output
1085 cursor position for that window. If updated_window is null, use
1086 selected_window and display the cursor at the given position. */
1089 XTcursor_to (vpos
, hpos
, y
, x
)
1090 int vpos
, hpos
, y
, x
;
1094 /* If updated_window is not set, work on selected_window. */
1098 w
= XWINDOW (selected_window
);
1100 /* Set the output cursor. */
1101 output_cursor
.hpos
= hpos
;
1102 output_cursor
.vpos
= vpos
;
1103 output_cursor
.x
= x
;
1104 output_cursor
.y
= y
;
1106 /* If not called as part of an update, really display the cursor.
1107 This will also set the cursor position of W. */
1108 if (updated_window
== NULL
)
1111 x_display_cursor (w
, 1, hpos
, vpos
, x
, y
);
1112 XFlush (FRAME_X_DISPLAY (SELECTED_FRAME ()));
1119 /***********************************************************************
1121 ***********************************************************************/
1123 /* Function prototypes of this page. */
1125 static struct face
*x_get_glyph_face_and_encoding
P_ ((struct frame
*,
1129 static struct face
*x_get_char_face_and_encoding
P_ ((struct frame
*, int,
1130 int, XChar2b
*, int));
1131 static XCharStruct
*x_per_char_metric
P_ ((XFontStruct
*, XChar2b
*));
1132 static void x_encode_char
P_ ((int, XChar2b
*, struct font_info
*));
1133 static void x_append_glyph
P_ ((struct it
*));
1134 static void x_append_composite_glyph
P_ ((struct it
*));
1135 static void x_append_stretch_glyph
P_ ((struct it
*it
, Lisp_Object
,
1137 static void x_produce_glyphs
P_ ((struct it
*));
1138 static void x_produce_image_glyph
P_ ((struct it
*it
));
1141 /* Return a pointer to per-char metric information in FONT of a
1142 character pointed by B which is a pointer to an XChar2b. */
1144 #define PER_CHAR_METRIC(font, b) \
1146 ? ((font)->per_char + (b)->byte2 - (font)->min_char_or_byte2 \
1147 + (((font)->min_byte1 || (font)->max_byte1) \
1148 ? (((b)->byte1 - (font)->min_byte1) \
1149 * ((font)->max_char_or_byte2 - (font)->min_char_or_byte2 + 1)) \
1151 : &((font)->max_bounds))
1154 /* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
1155 is not contained in the font. */
1157 static INLINE XCharStruct
*
1158 x_per_char_metric (font
, char2b
)
1162 /* The result metric information. */
1163 XCharStruct
*pcm
= NULL
;
1165 xassert (font
&& char2b
);
1167 if (font
->per_char
!= NULL
)
1169 if (font
->min_byte1
== 0 && font
->max_byte1
== 0)
1171 /* min_char_or_byte2 specifies the linear character index
1172 corresponding to the first element of the per_char array,
1173 max_char_or_byte2 is the index of the last character. A
1174 character with non-zero CHAR2B->byte1 is not in the font.
1175 A character with byte2 less than min_char_or_byte2 or
1176 greater max_char_or_byte2 is not in the font. */
1177 if (char2b
->byte1
== 0
1178 && char2b
->byte2
>= font
->min_char_or_byte2
1179 && char2b
->byte2
<= font
->max_char_or_byte2
)
1180 pcm
= font
->per_char
+ char2b
->byte2
- font
->min_char_or_byte2
;
1184 /* If either min_byte1 or max_byte1 are nonzero, both
1185 min_char_or_byte2 and max_char_or_byte2 are less than
1186 256, and the 2-byte character index values corresponding
1187 to the per_char array element N (counting from 0) are:
1189 byte1 = N/D + min_byte1
1190 byte2 = N\D + min_char_or_byte2
1194 D = max_char_or_byte2 - min_char_or_byte2 + 1
1195 / = integer division
1196 \ = integer modulus */
1197 if (char2b
->byte1
>= font
->min_byte1
1198 && char2b
->byte1
<= font
->max_byte1
1199 && char2b
->byte2
>= font
->min_char_or_byte2
1200 && char2b
->byte2
<= font
->max_char_or_byte2
)
1202 pcm
= (font
->per_char
1203 + ((font
->max_char_or_byte2
- font
->min_char_or_byte2
+ 1)
1204 * (char2b
->byte1
- font
->min_byte1
))
1205 + (char2b
->byte2
- font
->min_char_or_byte2
));
1211 /* If the per_char pointer is null, all glyphs between the first
1212 and last character indexes inclusive have the same
1213 information, as given by both min_bounds and max_bounds. */
1214 if (char2b
->byte2
>= font
->min_char_or_byte2
1215 && char2b
->byte2
<= font
->max_char_or_byte2
)
1216 pcm
= &font
->max_bounds
;
1219 return ((pcm
== NULL
1220 || (pcm
->width
== 0 && (pcm
->rbearing
- pcm
->lbearing
) == 0))
1225 /* Encode CHAR2B using encoding information from FONT_INFO. CHAR2B is
1226 the two-byte form of C. Encoding is returned in *CHAR2B. */
1229 x_encode_char (c
, char2b
, font_info
)
1232 struct font_info
*font_info
;
1234 int charset
= CHAR_CHARSET (c
);
1235 XFontStruct
*font
= font_info
->font
;
1237 /* FONT_INFO may define a scheme by which to encode byte1 and byte2.
1238 This may be either a program in a special encoder language or a
1240 if (font_info
->font_encoder
)
1242 /* It's a program. */
1243 struct ccl_program
*ccl
= font_info
->font_encoder
;
1245 if (CHARSET_DIMENSION (charset
) == 1)
1247 ccl
->reg
[0] = charset
;
1248 ccl
->reg
[1] = char2b
->byte2
;
1252 ccl
->reg
[0] = charset
;
1253 ccl
->reg
[1] = char2b
->byte1
;
1254 ccl
->reg
[2] = char2b
->byte2
;
1257 ccl_driver (ccl
, NULL
, NULL
, 0, 0, NULL
);
1259 /* We assume that MSBs are appropriately set/reset by CCL
1261 if (font
->max_byte1
== 0) /* 1-byte font */
1262 char2b
->byte1
= 0, char2b
->byte2
= ccl
->reg
[1];
1264 char2b
->byte1
= ccl
->reg
[1], char2b
->byte2
= ccl
->reg
[2];
1266 else if (font_info
->encoding
[charset
])
1268 /* Fixed encoding scheme. See fontset.h for the meaning of the
1269 encoding numbers. */
1270 int enc
= font_info
->encoding
[charset
];
1272 if ((enc
== 1 || enc
== 2)
1273 && CHARSET_DIMENSION (charset
) == 2)
1274 char2b
->byte1
|= 0x80;
1276 if (enc
== 1 || enc
== 3)
1277 char2b
->byte2
|= 0x80;
1282 /* Get face and two-byte form of character C in face FACE_ID on frame
1283 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
1284 means we want to display multibyte text. Value is a pointer to a
1285 realized face that is ready for display. */
1287 static INLINE
struct face
*
1288 x_get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
)
1294 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1298 /* Unibyte case. We don't have to encode, but we have to make
1299 sure to use a face suitable for unibyte. */
1302 face_id
= FACE_FOR_CHAR (f
, face
, c
);
1303 face
= FACE_FROM_ID (f
, face_id
);
1305 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
1307 /* Case of ASCII in a face known to fit ASCII. */
1313 int c1
, c2
, charset
;
1315 /* Split characters into bytes. If c2 is -1 afterwards, C is
1316 really a one-byte character so that byte1 is zero. */
1317 SPLIT_CHAR (c
, charset
, c1
, c2
);
1319 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1321 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1323 /* Maybe encode the character in *CHAR2B. */
1324 if (face
->font
!= NULL
)
1326 struct font_info
*font_info
1327 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1329 x_encode_char (c
, char2b
, font_info
);
1333 /* Make sure X resources of the face are allocated. */
1334 xassert (face
!= NULL
);
1335 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1341 /* Get face and two-byte form of character glyph GLYPH on frame F.
1342 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
1343 a pointer to a realized face that is ready for display. */
1345 static INLINE
struct face
*
1346 x_get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
1348 struct glyph
*glyph
;
1354 xassert (glyph
->type
== CHAR_GLYPH
);
1355 face
= FACE_FROM_ID (f
, glyph
->face_id
);
1360 if (!glyph
->multibyte_p
)
1362 /* Unibyte case. We don't have to encode, but we have to make
1363 sure to use a face suitable for unibyte. */
1365 char2b
->byte2
= glyph
->u
.ch
;
1367 else if (glyph
->u
.ch
< 128
1368 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
1370 /* Case of ASCII in a face known to fit ASCII. */
1372 char2b
->byte2
= glyph
->u
.ch
;
1376 int c1
, c2
, charset
;
1378 /* Split characters into bytes. If c2 is -1 afterwards, C is
1379 really a one-byte character so that byte1 is zero. */
1380 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
1382 char2b
->byte1
= c1
, char2b
->byte2
= c2
;
1384 char2b
->byte1
= 0, char2b
->byte2
= c1
;
1386 /* Maybe encode the character in *CHAR2B. */
1387 if (charset
!= CHARSET_ASCII
)
1389 struct font_info
*font_info
1390 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
1393 x_encode_char (glyph
->u
.ch
, char2b
, font_info
);
1396 = ((XFontStruct
*) (font_info
->font
))->max_byte1
> 0;
1401 /* Make sure X resources of the face are allocated. */
1402 xassert (face
!= NULL
);
1403 PREPARE_FACE_FOR_DISPLAY (f
, face
);
1408 /* Store one glyph for IT->char_to_display in IT->glyph_row.
1409 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1415 struct glyph
*glyph
;
1416 enum glyph_row_area area
= it
->area
;
1418 xassert (it
->glyph_row
);
1419 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
1421 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1422 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1424 glyph
->charpos
= CHARPOS (it
->position
);
1425 glyph
->object
= it
->object
;
1426 glyph
->pixel_width
= it
->pixel_width
;
1427 glyph
->voffset
= it
->voffset
;
1428 glyph
->type
= CHAR_GLYPH
;
1429 glyph
->multibyte_p
= it
->multibyte_p
;
1430 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1431 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1432 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1433 || it
->phys_descent
> it
->descent
);
1434 glyph
->padding_p
= 0;
1435 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
1436 glyph
->face_id
= it
->face_id
;
1437 glyph
->u
.ch
= it
->char_to_display
;
1438 ++it
->glyph_row
->used
[area
];
1442 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
1443 Called from x_produce_glyphs when IT->glyph_row is non-null. */
1446 x_append_composite_glyph (it
)
1449 struct glyph
*glyph
;
1450 enum glyph_row_area area
= it
->area
;
1452 xassert (it
->glyph_row
);
1454 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1455 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1457 glyph
->charpos
= CHARPOS (it
->position
);
1458 glyph
->object
= it
->object
;
1459 glyph
->pixel_width
= it
->pixel_width
;
1460 glyph
->voffset
= it
->voffset
;
1461 glyph
->type
= COMPOSITE_GLYPH
;
1462 glyph
->multibyte_p
= it
->multibyte_p
;
1463 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1464 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1465 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
1466 || it
->phys_descent
> it
->descent
);
1467 glyph
->padding_p
= 0;
1468 glyph
->glyph_not_available_p
= 0;
1469 glyph
->face_id
= it
->face_id
;
1470 glyph
->u
.cmp_id
= it
->cmp_id
;
1471 ++it
->glyph_row
->used
[area
];
1476 /* Change IT->ascent and IT->height according to the setting of
1480 take_vertical_position_into_account (it
)
1485 if (it
->voffset
< 0)
1486 /* Increase the ascent so that we can display the text higher
1488 it
->ascent
+= abs (it
->voffset
);
1490 /* Increase the descent so that we can display the text lower
1492 it
->descent
+= it
->voffset
;
1497 /* Produce glyphs/get display metrics for the image IT is loaded with.
1498 See the description of struct display_iterator in dispextern.h for
1499 an overview of struct display_iterator. */
1502 x_produce_image_glyph (it
)
1508 xassert (it
->what
== IT_IMAGE
);
1510 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1511 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
1514 /* Make sure X resources of the face and image are loaded. */
1515 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1516 prepare_image_for_display (it
->f
, img
);
1518 it
->ascent
= it
->phys_ascent
= image_ascent (img
, face
);
1519 it
->descent
= it
->phys_descent
= img
->height
+ 2 * img
->margin
- it
->ascent
;
1520 it
->pixel_width
= img
->width
+ 2 * img
->margin
;
1524 if (face
->box
!= FACE_NO_BOX
)
1526 it
->ascent
+= face
->box_line_width
;
1527 it
->descent
+= face
->box_line_width
;
1529 if (it
->start_of_box_run_p
)
1530 it
->pixel_width
+= face
->box_line_width
;
1531 if (it
->end_of_box_run_p
)
1532 it
->pixel_width
+= face
->box_line_width
;
1535 take_vertical_position_into_account (it
);
1539 struct glyph
*glyph
;
1540 enum glyph_row_area area
= it
->area
;
1542 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1543 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1545 glyph
->charpos
= CHARPOS (it
->position
);
1546 glyph
->object
= it
->object
;
1547 glyph
->pixel_width
= it
->pixel_width
;
1548 glyph
->voffset
= it
->voffset
;
1549 glyph
->type
= IMAGE_GLYPH
;
1550 glyph
->multibyte_p
= it
->multibyte_p
;
1551 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1552 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1553 glyph
->overlaps_vertically_p
= 0;
1554 glyph
->padding_p
= 0;
1555 glyph
->glyph_not_available_p
= 0;
1556 glyph
->face_id
= it
->face_id
;
1557 glyph
->u
.img_id
= img
->id
;
1558 ++it
->glyph_row
->used
[area
];
1564 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
1565 of the glyph, WIDTH and HEIGHT are the width and height of the
1566 stretch. ASCENT is the percentage/100 of HEIGHT to use for the
1567 ascent of the glyph (0 <= ASCENT <= 1). */
1570 x_append_stretch_glyph (it
, object
, width
, height
, ascent
)
1576 struct glyph
*glyph
;
1577 enum glyph_row_area area
= it
->area
;
1579 xassert (ascent
>= 0 && ascent
<= 1);
1581 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
1582 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
1584 glyph
->charpos
= CHARPOS (it
->position
);
1585 glyph
->object
= object
;
1586 glyph
->pixel_width
= width
;
1587 glyph
->voffset
= it
->voffset
;
1588 glyph
->type
= STRETCH_GLYPH
;
1589 glyph
->multibyte_p
= it
->multibyte_p
;
1590 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
1591 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
1592 glyph
->overlaps_vertically_p
= 0;
1593 glyph
->padding_p
= 0;
1594 glyph
->glyph_not_available_p
= 0;
1595 glyph
->face_id
= it
->face_id
;
1596 glyph
->u
.stretch
.ascent
= height
* ascent
;
1597 glyph
->u
.stretch
.height
= height
;
1598 ++it
->glyph_row
->used
[area
];
1603 /* Produce a stretch glyph for iterator IT. IT->object is the value
1604 of the glyph property displayed. The value must be a list
1605 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1608 1. `:width WIDTH' specifies that the space should be WIDTH *
1609 canonical char width wide. WIDTH may be an integer or floating
1612 2. `:relative-width FACTOR' specifies that the width of the stretch
1613 should be computed from the width of the first character having the
1614 `glyph' property, and should be FACTOR times that width.
1616 3. `:align-to HPOS' specifies that the space should be wide enough
1617 to reach HPOS, a value in canonical character units.
1619 Exactly one of the above pairs must be present.
1621 4. `:height HEIGHT' specifies that the height of the stretch produced
1622 should be HEIGHT, measured in canonical character units.
1624 5. `:relative-height FACTOR' specifies that the height of the the
1625 stretch should be FACTOR times the height of the characters having
1628 Either none or exactly one of 4 or 5 must be present.
1630 6. `:ascent ASCENT' specifies that ASCENT percent of the height
1631 of the stretch should be used for the ascent of the stretch.
1632 ASCENT must be in the range 0 <= ASCENT <= 100. */
1635 ((INTEGERP (X) || FLOATP (X)) \
1641 x_produce_stretch_glyph (it
)
1644 /* (space :width WIDTH :height HEIGHT. */
1646 extern Lisp_Object Qspace
;
1648 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
1649 extern Lisp_Object QCrelative_width
, QCrelative_height
;
1650 extern Lisp_Object QCalign_to
;
1651 Lisp_Object prop
, plist
;
1652 double width
= 0, height
= 0, ascent
= 0;
1653 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1654 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
1656 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
1658 /* List should start with `space'. */
1659 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1660 plist
= XCDR (it
->object
);
1662 /* Compute the width of the stretch. */
1663 if (prop
= Fplist_get (plist
, QCwidth
),
1665 /* Absolute width `:width WIDTH' specified and valid. */
1666 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
);
1667 else if (prop
= Fplist_get (plist
, QCrelative_width
),
1670 /* Relative width `:relative-width FACTOR' specified and valid.
1671 Compute the width of the characters having the `glyph'
1674 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
1677 if (it
->multibyte_p
)
1679 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
1680 - IT_BYTEPOS (*it
));
1681 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
1684 it2
.c
= *p
, it2
.len
= 1;
1686 it2
.glyph_row
= NULL
;
1687 it2
.what
= IT_CHARACTER
;
1688 x_produce_glyphs (&it2
);
1689 width
= NUMVAL (prop
) * it2
.pixel_width
;
1691 else if (prop
= Fplist_get (plist
, QCalign_to
),
1693 width
= NUMVAL (prop
) * CANON_X_UNIT (it
->f
) - it
->current_x
;
1695 /* Nothing specified -> width defaults to canonical char width. */
1696 width
= CANON_X_UNIT (it
->f
);
1698 /* Compute height. */
1699 if (prop
= Fplist_get (plist
, QCheight
),
1701 height
= NUMVAL (prop
) * CANON_Y_UNIT (it
->f
);
1702 else if (prop
= Fplist_get (plist
, QCrelative_height
),
1704 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
1706 height
= FONT_HEIGHT (font
);
1708 /* Compute percentage of height used for ascent. If
1709 `:ascent ASCENT' is present and valid, use that. Otherwise,
1710 derive the ascent from the font in use. */
1711 if (prop
= Fplist_get (plist
, QCascent
),
1712 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
1713 ascent
= NUMVAL (prop
) / 100.0;
1715 ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1724 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1725 if (!STRINGP (object
))
1726 object
= it
->w
->buffer
;
1727 x_append_stretch_glyph (it
, object
, width
, height
, ascent
);
1730 it
->pixel_width
= width
;
1731 it
->ascent
= it
->phys_ascent
= height
* ascent
;
1732 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
1735 if (face
->box
!= FACE_NO_BOX
)
1737 it
->ascent
+= face
->box_line_width
;
1738 it
->descent
+= face
->box_line_width
;
1740 if (it
->start_of_box_run_p
)
1741 it
->pixel_width
+= face
->box_line_width
;
1742 if (it
->end_of_box_run_p
)
1743 it
->pixel_width
+= face
->box_line_width
;
1746 take_vertical_position_into_account (it
);
1749 /* Return proper value to be used as baseline offset of font that has
1750 ASCENT and DESCENT to draw characters by the font at the vertical
1751 center of the line of frame F.
1753 Here, out task is to find the value of BOFF in the following figure;
1755 -------------------------+-----------+-
1756 -+-+---------+-+ | |
1758 | | | | F_ASCENT F_HEIGHT
1761 | | |-|-+------+-----------|------- baseline
1763 | |---------|-+-+ | |
1765 -+-+---------+-+ F_DESCENT |
1766 -------------------------+-----------+-
1768 -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
1769 BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
1770 DESCENT = FONT->descent
1771 HEIGHT = FONT_HEIGHT (FONT)
1772 F_DESCENT = (F->output_data.x->font->descent
1773 - F->output_data.x->baseline_offset)
1774 F_HEIGHT = FRAME_LINE_HEIGHT (F)
1777 #define VCENTER_BASELINE_OFFSET(FONT, F) \
1779 + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT))) / 2 \
1780 - ((F)->output_data.x->font->descent - (F)->output_data.x->baseline_offset))
1782 /* Produce glyphs/get display metrics for the display element IT is
1783 loaded with. See the description of struct display_iterator in
1784 dispextern.h for an overview of struct display_iterator. */
1787 x_produce_glyphs (it
)
1790 it
->glyph_not_available_p
= 0;
1792 if (it
->what
== IT_CHARACTER
)
1796 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1798 int font_not_found_p
;
1799 struct font_info
*font_info
;
1800 int boff
; /* baseline offset */
1802 /* Maybe translate single-byte characters to multibyte, or the
1804 it
->char_to_display
= it
->c
;
1805 if (!ASCII_BYTE_P (it
->c
))
1807 if (unibyte_display_via_language_environment
1808 && SINGLE_BYTE_CHAR_P (it
->c
)
1810 || !NILP (Vnonascii_translation_table
)))
1812 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
1813 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1814 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1816 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
1817 && !it
->multibyte_p
)
1819 it
->char_to_display
= multibyte_char_to_unibyte (it
->c
, Qnil
);
1820 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
1821 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1825 /* Get font to use. Encode IT->char_to_display. */
1826 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
1827 it
->face_id
, &char2b
,
1831 /* When no suitable font found, use the default font. */
1832 font_not_found_p
= font
== NULL
;
1833 if (font_not_found_p
)
1835 font
= FRAME_FONT (it
->f
);
1836 boff
= it
->f
->output_data
.x
->baseline_offset
;
1841 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
1842 boff
= font_info
->baseline_offset
;
1843 if (font_info
->vertical_centering
)
1844 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
1847 if (it
->char_to_display
>= ' '
1848 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
1850 /* Either unibyte or ASCII. */
1855 pcm
= x_per_char_metric (font
, &char2b
);
1856 it
->ascent
= font
->ascent
+ boff
;
1857 it
->descent
= font
->descent
- boff
;
1861 it
->phys_ascent
= pcm
->ascent
+ boff
;
1862 it
->phys_descent
= pcm
->descent
- boff
;
1863 it
->pixel_width
= pcm
->width
;
1867 it
->glyph_not_available_p
= 1;
1868 it
->phys_ascent
= font
->ascent
+ boff
;
1869 it
->phys_descent
= font
->descent
- boff
;
1870 it
->pixel_width
= FONT_WIDTH (font
);
1873 /* If this is a space inside a region of text with
1874 `space-width' property, change its width. */
1875 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
1877 it
->pixel_width
*= XFLOATINT (it
->space_width
);
1879 /* If face has a box, add the box thickness to the character
1880 height. If character has a box line to the left and/or
1881 right, add the box line width to the character's width. */
1882 if (face
->box
!= FACE_NO_BOX
)
1884 int thick
= face
->box_line_width
;
1886 it
->ascent
+= thick
;
1887 it
->descent
+= thick
;
1889 if (it
->start_of_box_run_p
)
1890 it
->pixel_width
+= thick
;
1891 if (it
->end_of_box_run_p
)
1892 it
->pixel_width
+= thick
;
1895 /* If face has an overline, add the height of the overline
1896 (1 pixel) and a 1 pixel margin to the character height. */
1897 if (face
->overline_p
)
1900 take_vertical_position_into_account (it
);
1902 /* If we have to actually produce glyphs, do it. */
1907 /* Translate a space with a `space-width' property
1908 into a stretch glyph. */
1909 double ascent
= (double) font
->ascent
/ FONT_HEIGHT (font
);
1910 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1911 it
->ascent
+ it
->descent
, ascent
);
1914 x_append_glyph (it
);
1916 /* If characters with lbearing or rbearing are displayed
1917 in this line, record that fact in a flag of the
1918 glyph row. This is used to optimize X output code. */
1919 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
1920 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1923 else if (it
->char_to_display
== '\n')
1925 /* A newline has no width but we need the height of the line. */
1926 it
->pixel_width
= 0;
1928 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1929 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1931 if (face
->box
!= FACE_NO_BOX
)
1933 int thick
= face
->box_line_width
;
1934 it
->ascent
+= thick
;
1935 it
->descent
+= thick
;
1938 else if (it
->char_to_display
== '\t')
1940 int tab_width
= it
->tab_width
* CANON_X_UNIT (it
->f
);
1941 int x
= it
->current_x
+ it
->continuation_lines_width
;
1942 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
1944 /* If the distance from the current position to the next tab
1945 stop is less than a canonical character width, use the
1946 tab stop after that. */
1947 if (next_tab_x
- x
< CANON_X_UNIT (it
->f
))
1948 next_tab_x
+= tab_width
;
1950 it
->pixel_width
= next_tab_x
- x
;
1952 it
->ascent
= it
->phys_ascent
= font
->ascent
+ boff
;
1953 it
->descent
= it
->phys_descent
= font
->descent
- boff
;
1957 double ascent
= (double) it
->ascent
/ (it
->ascent
+ it
->descent
);
1958 x_append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
1959 it
->ascent
+ it
->descent
, ascent
);
1964 /* A multi-byte character. Assume that the display width of the
1965 character is the width of the character multiplied by the
1966 width of the font. */
1968 /* If we found a font, this font should give us the right
1969 metrics. If we didn't find a font, use the frame's
1970 default font and calculate the width of the character
1971 from the charset width; this is what old redisplay code
1973 pcm
= x_per_char_metric (font
, &char2b
);
1974 if (font_not_found_p
|| !pcm
)
1976 int charset
= CHAR_CHARSET (it
->char_to_display
);
1978 it
->glyph_not_available_p
= 1;
1979 it
->pixel_width
= (FONT_WIDTH (FRAME_FONT (it
->f
))
1980 * CHARSET_WIDTH (charset
));
1981 it
->phys_ascent
= font
->ascent
+ boff
;
1982 it
->phys_descent
= font
->descent
- boff
;
1986 it
->pixel_width
= pcm
->width
;
1987 it
->phys_ascent
= pcm
->ascent
+ boff
;
1988 it
->phys_descent
= pcm
->descent
- boff
;
1990 && (pcm
->lbearing
< 0
1991 || pcm
->rbearing
> pcm
->width
))
1992 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
1995 it
->ascent
= font
->ascent
+ boff
;
1996 it
->descent
= font
->descent
- boff
;
1997 if (face
->box
!= FACE_NO_BOX
)
1999 int thick
= face
->box_line_width
;
2000 it
->ascent
+= thick
;
2001 it
->descent
+= thick
;
2003 if (it
->start_of_box_run_p
)
2004 it
->pixel_width
+= thick
;
2005 if (it
->end_of_box_run_p
)
2006 it
->pixel_width
+= thick
;
2009 /* If face has an overline, add the height of the overline
2010 (1 pixel) and a 1 pixel margin to the character height. */
2011 if (face
->overline_p
)
2014 take_vertical_position_into_account (it
);
2017 x_append_glyph (it
);
2020 else if (it
->what
== IT_COMPOSITION
)
2022 /* Note: A composition is represented as one glyph in the
2023 glyph matrix. There are no padding glyphs. */
2026 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2028 int font_not_found_p
;
2029 struct font_info
*font_info
;
2030 int boff
; /* baseline offset */
2031 struct composition
*cmp
= composition_table
[it
->cmp_id
];
2033 /* Maybe translate single-byte characters to multibyte. */
2034 it
->char_to_display
= it
->c
;
2035 if (unibyte_display_via_language_environment
2036 && SINGLE_BYTE_CHAR_P (it
->c
)
2039 && !NILP (Vnonascii_translation_table
))))
2041 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
2044 /* Get face and font to use. Encode IT->char_to_display. */
2045 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
2046 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2047 x_get_char_face_and_encoding (it
->f
, it
->char_to_display
,
2048 it
->face_id
, &char2b
, it
->multibyte_p
);
2051 /* When no suitable font found, use the default font. */
2052 font_not_found_p
= font
== NULL
;
2053 if (font_not_found_p
)
2055 font
= FRAME_FONT (it
->f
);
2056 boff
= it
->f
->output_data
.x
->baseline_offset
;
2061 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2062 boff
= font_info
->baseline_offset
;
2063 if (font_info
->vertical_centering
)
2064 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2067 /* There are no padding glyphs, so there is only one glyph to
2068 produce for the composition. Important is that pixel_width,
2069 ascent and descent are the values of what is drawn by
2070 draw_glyphs (i.e. the values of the overall glyphs composed). */
2073 /* If we have not yet calculated pixel size data of glyphs of
2074 the composition for the current face font, calculate them
2075 now. Theoretically, we have to check all fonts for the
2076 glyphs, but that requires much time and memory space. So,
2077 here we check only the font of the first glyph. This leads
2078 to incorrect display very rarely, and C-l (recenter) can
2079 correct the display anyway. */
2080 if (cmp
->font
!= (void *) font
)
2082 /* Ascent and descent of the font of the first character of
2083 this composition (adjusted by baseline offset). Ascent
2084 and descent of overall glyphs should not be less than
2085 them respectively. */
2086 int font_ascent
= font
->ascent
+ boff
;
2087 int font_descent
= font
->descent
- boff
;
2088 /* Bounding box of the overall glyphs. */
2089 int leftmost
, rightmost
, lowest
, highest
;
2090 int i
, width
, ascent
, descent
;
2092 cmp
->font
= (void *) font
;
2094 /* Initialize the bounding box. */
2095 pcm
= x_per_char_metric (font
, &char2b
);
2099 ascent
= pcm
->ascent
;
2100 descent
= pcm
->descent
;
2104 width
= FONT_WIDTH (font
);
2105 ascent
= font
->ascent
;
2106 descent
= font
->descent
;
2110 lowest
= - descent
+ boff
;
2111 highest
= ascent
+ boff
;
2115 && font_info
->default_ascent
2116 && CHAR_TABLE_P (Vuse_default_ascent
)
2117 && !NILP (Faref (Vuse_default_ascent
,
2118 make_number (it
->char_to_display
))))
2119 highest
= font_info
->default_ascent
+ boff
;
2121 /* Draw the first glyph at the normal position. It may be
2122 shifted to right later if some other glyphs are drawn at
2124 cmp
->offsets
[0] = 0;
2125 cmp
->offsets
[1] = boff
;
2127 /* Set cmp->offsets for the remaining glyphs. */
2128 for (i
= 1; i
< cmp
->glyph_len
; i
++)
2130 int left
, right
, btm
, top
;
2131 int ch
= COMPOSITION_GLYPH (cmp
, i
);
2132 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
2134 face
= FACE_FROM_ID (it
->f
, face_id
);
2135 x_get_char_face_and_encoding (it
->f
, ch
, face
->id
, &char2b
,
2140 font
= FRAME_FONT (it
->f
);
2141 boff
= it
->f
->output_data
.x
->baseline_offset
;
2147 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
2148 boff
= font_info
->baseline_offset
;
2149 if (font_info
->vertical_centering
)
2150 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
2153 pcm
= x_per_char_metric (font
, &char2b
);
2157 ascent
= pcm
->ascent
;
2158 descent
= pcm
->descent
;
2162 width
= FONT_WIDTH (font
);
2163 ascent
= font
->ascent
;
2164 descent
= font
->descent
;
2167 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
2169 /* Relative composition with or without
2171 left
= (leftmost
+ rightmost
- width
) / 2;
2172 btm
= - descent
+ boff
;
2173 if (font_info
&& font_info
->relative_compose
2174 && (! CHAR_TABLE_P (Vignore_relative_composition
)
2175 || NILP (Faref (Vignore_relative_composition
,
2176 make_number (ch
)))))
2179 if (- descent
>= font_info
->relative_compose
)
2180 /* One extra pixel between two glyphs. */
2182 else if (ascent
<= 0)
2183 /* One extra pixel between two glyphs. */
2184 btm
= lowest
- 1 - ascent
- descent
;
2189 /* A composition rule is specified by an integer
2190 value that encodes global and new reference
2191 points (GREF and NREF). GREF and NREF are
2192 specified by numbers as below:
2200 ---3---4---5--- baseline
2202 6---7---8 -- descent
2204 int rule
= COMPOSITION_RULE (cmp
, i
);
2205 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
2207 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
2208 grefx
= gref
% 3, nrefx
= nref
% 3;
2209 grefy
= gref
/ 3, nrefy
= nref
/ 3;
2212 + grefx
* (rightmost
- leftmost
) / 2
2213 - nrefx
* width
/ 2);
2214 btm
= ((grefy
== 0 ? highest
2216 : grefy
== 2 ? lowest
2217 : (highest
+ lowest
) / 2)
2218 - (nrefy
== 0 ? ascent
+ descent
2219 : nrefy
== 1 ? descent
- boff
2221 : (ascent
+ descent
) / 2));
2224 cmp
->offsets
[i
* 2] = left
;
2225 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
2227 /* Update the bounding box of the overall glyphs. */
2228 right
= left
+ width
;
2229 top
= btm
+ descent
+ ascent
;
2230 if (left
< leftmost
)
2232 if (right
> rightmost
)
2240 /* If there are glyphs whose x-offsets are negative,
2241 shift all glyphs to the right and make all x-offsets
2245 for (i
= 0; i
< cmp
->glyph_len
; i
++)
2246 cmp
->offsets
[i
* 2] -= leftmost
;
2247 rightmost
-= leftmost
;
2250 cmp
->pixel_width
= rightmost
;
2251 cmp
->ascent
= highest
;
2252 cmp
->descent
= - lowest
;
2253 if (cmp
->ascent
< font_ascent
)
2254 cmp
->ascent
= font_ascent
;
2255 if (cmp
->descent
< font_descent
)
2256 cmp
->descent
= font_descent
;
2259 it
->pixel_width
= cmp
->pixel_width
;
2260 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
2261 it
->descent
= it
->phys_descent
= cmp
->descent
;
2263 if (face
->box
!= FACE_NO_BOX
)
2265 int thick
= face
->box_line_width
;
2266 it
->ascent
+= thick
;
2267 it
->descent
+= thick
;
2269 if (it
->start_of_box_run_p
)
2270 it
->pixel_width
+= thick
;
2271 if (it
->end_of_box_run_p
)
2272 it
->pixel_width
+= thick
;
2275 /* If face has an overline, add the height of the overline
2276 (1 pixel) and a 1 pixel margin to the character height. */
2277 if (face
->overline_p
)
2280 take_vertical_position_into_account (it
);
2283 x_append_composite_glyph (it
);
2285 else if (it
->what
== IT_IMAGE
)
2286 x_produce_image_glyph (it
);
2287 else if (it
->what
== IT_STRETCH
)
2288 x_produce_stretch_glyph (it
);
2290 /* Accumulate dimensions. Note: can't assume that it->descent > 0
2291 because this isn't true for images with `:ascent 100'. */
2292 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
2293 if (it
->area
== TEXT_AREA
)
2294 it
->current_x
+= it
->pixel_width
;
2296 it
->descent
+= it
->extra_line_spacing
;
2298 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
2299 it
->max_descent
= max (it
->max_descent
, it
->descent
);
2300 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
2301 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
2305 /* Estimate the pixel height of the mode or top line on frame F.
2306 FACE_ID specifies what line's height to estimate. */
2309 x_estimate_mode_line_height (f
, face_id
)
2311 enum face_id face_id
;
2315 /* This function is called so early when Emacs starts that the face
2316 cache and mode line face are not yet initialized. */
2317 if (FRAME_FACE_CACHE (f
))
2319 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2321 height
= FONT_HEIGHT (face
->font
) + 2 * face
->box_line_width
;
2328 /***********************************************************************
2330 ***********************************************************************/
2332 /* A sequence of glyphs to be drawn in the same face.
2334 This data structure is not really completely X specific, so it
2335 could possibly, at least partially, be useful for other systems. It
2336 is currently not part of the external redisplay interface because
2337 it's not clear what other systems will need. */
2341 /* X-origin of the string. */
2344 /* Y-origin and y-position of the base line of this string. */
2347 /* The width of the string, not including a face extension. */
2350 /* The width of the string, including a face extension. */
2351 int background_width
;
2353 /* The height of this string. This is the height of the line this
2354 string is drawn in, and can be different from the height of the
2355 font the string is drawn in. */
2358 /* Number of pixels this string overwrites in front of its x-origin.
2359 This number is zero if the string has an lbearing >= 0; it is
2360 -lbearing, if the string has an lbearing < 0. */
2363 /* Number of pixels this string overwrites past its right-most
2364 nominal x-position, i.e. x + width. Zero if the string's
2365 rbearing is <= its nominal width, rbearing - width otherwise. */
2368 /* The frame on which the glyph string is drawn. */
2371 /* The window on which the glyph string is drawn. */
2374 /* X display and window for convenience. */
2378 /* The glyph row for which this string was built. It determines the
2379 y-origin and height of the string. */
2380 struct glyph_row
*row
;
2382 /* The area within row. */
2383 enum glyph_row_area area
;
2385 /* Characters to be drawn, and number of characters. */
2389 /* A face-override for drawing cursors, mouse face and similar. */
2390 enum draw_glyphs_face hl
;
2392 /* Face in which this string is to be drawn. */
2395 /* Font in which this string is to be drawn. */
2398 /* Font info for this string. */
2399 struct font_info
*font_info
;
2401 /* Non-null means this string describes (part of) a composition.
2402 All characters from char2b are drawn composed. */
2403 struct composition
*cmp
;
2405 /* Index of this glyph string's first character in the glyph
2406 definition of CMP. If this is zero, this glyph string describes
2407 the first character of a composition. */
2410 /* 1 means this glyph strings face has to be drawn to the right end
2411 of the window's drawing area. */
2412 unsigned extends_to_end_of_line_p
: 1;
2414 /* 1 means the background of this string has been drawn. */
2415 unsigned background_filled_p
: 1;
2417 /* 1 means glyph string must be drawn with 16-bit functions. */
2418 unsigned two_byte_p
: 1;
2420 /* 1 means that the original font determined for drawing this glyph
2421 string could not be loaded. The member `font' has been set to
2422 the frame's default font in this case. */
2423 unsigned font_not_found_p
: 1;
2425 /* 1 means that the face in which this glyph string is drawn has a
2427 unsigned stippled_p
: 1;
2429 /* 1 means only the foreground of this glyph string must be drawn,
2430 and we should use the physical height of the line this glyph
2431 string appears in as clip rect. */
2432 unsigned for_overlaps_p
: 1;
2434 /* The GC to use for drawing this glyph string. */
2437 /* A pointer to the first glyph in the string. This glyph
2438 corresponds to char2b[0]. Needed to draw rectangles if
2439 font_not_found_p is 1. */
2440 struct glyph
*first_glyph
;
2442 /* Image, if any. */
2445 struct glyph_string
*next
, *prev
;
2452 x_dump_glyph_string (s
)
2453 struct glyph_string
*s
;
2455 fprintf (stderr
, "glyph string\n");
2456 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
2457 s
->x
, s
->y
, s
->width
, s
->height
);
2458 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
2459 fprintf (stderr
, " hl = %d\n", s
->hl
);
2460 fprintf (stderr
, " left overhang = %d, right = %d\n",
2461 s
->left_overhang
, s
->right_overhang
);
2462 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
2463 fprintf (stderr
, " extends to end of line = %d\n",
2464 s
->extends_to_end_of_line_p
);
2465 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
2466 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
2469 #endif /* GLYPH_DEBUG */
2473 static void x_append_glyph_string_lists
P_ ((struct glyph_string
**,
2474 struct glyph_string
**,
2475 struct glyph_string
*,
2476 struct glyph_string
*));
2477 static void x_prepend_glyph_string_lists
P_ ((struct glyph_string
**,
2478 struct glyph_string
**,
2479 struct glyph_string
*,
2480 struct glyph_string
*));
2481 static void x_append_glyph_string
P_ ((struct glyph_string
**,
2482 struct glyph_string
**,
2483 struct glyph_string
*));
2484 static int x_left_overwritten
P_ ((struct glyph_string
*));
2485 static int x_left_overwriting
P_ ((struct glyph_string
*));
2486 static int x_right_overwritten
P_ ((struct glyph_string
*));
2487 static int x_right_overwriting
P_ ((struct glyph_string
*));
2488 static int x_fill_glyph_string
P_ ((struct glyph_string
*, int, int, int,
2490 static void x_init_glyph_string
P_ ((struct glyph_string
*,
2491 XChar2b
*, struct window
*,
2493 enum glyph_row_area
, int,
2494 enum draw_glyphs_face
));
2495 static int x_draw_glyphs
P_ ((struct window
*, int , struct glyph_row
*,
2496 enum glyph_row_area
, int, int,
2497 enum draw_glyphs_face
, int *, int *, int));
2498 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
2499 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
2500 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
2502 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
2503 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
2504 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
2505 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
2506 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
2507 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
2508 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
2509 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
2510 static void x_get_glyph_overhangs
P_ ((struct glyph
*, struct frame
*,
2512 static void x_compute_overhangs_and_x
P_ ((struct glyph_string
*, int, int));
2513 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
2514 unsigned long *, double, int));
2515 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
2516 double, int, unsigned long));
2517 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
2518 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
2519 static void x_draw_image_relief
P_ ((struct glyph_string
*));
2520 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
2521 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
2522 static void x_fill_image_glyph_string
P_ ((struct glyph_string
*));
2523 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
2525 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
2526 int, int, int, int, XRectangle
*));
2527 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
2528 int, int, int, XRectangle
*));
2529 static void x_fix_overlapping_area
P_ ((struct window
*, struct glyph_row
*,
2530 enum glyph_row_area
));
2531 static int x_fill_stretch_glyph_string
P_ ((struct glyph_string
*,
2533 enum glyph_row_area
, int, int));
2536 static void x_check_font
P_ ((struct frame
*, XFontStruct
*));
2540 /* Append the list of glyph strings with head H and tail T to the list
2541 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
2544 x_append_glyph_string_lists (head
, tail
, h
, t
)
2545 struct glyph_string
**head
, **tail
;
2546 struct glyph_string
*h
, *t
;
2560 /* Prepend the list of glyph strings with head H and tail T to the
2561 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
2565 x_prepend_glyph_string_lists (head
, tail
, h
, t
)
2566 struct glyph_string
**head
, **tail
;
2567 struct glyph_string
*h
, *t
;
2581 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
2582 Set *HEAD and *TAIL to the resulting list. */
2585 x_append_glyph_string (head
, tail
, s
)
2586 struct glyph_string
**head
, **tail
;
2587 struct glyph_string
*s
;
2589 s
->next
= s
->prev
= NULL
;
2590 x_append_glyph_string_lists (head
, tail
, s
, s
);
2594 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
2599 struct glyph_string
*s
;
2601 if (s
->font
== FRAME_FONT (s
->f
)
2602 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
2603 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
2605 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
2608 /* Cursor on non-default face: must merge. */
2612 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
2613 xgcv
.foreground
= s
->face
->background
;
2615 /* If the glyph would be invisible, try a different foreground. */
2616 if (xgcv
.foreground
== xgcv
.background
)
2617 xgcv
.foreground
= s
->face
->foreground
;
2618 if (xgcv
.foreground
== xgcv
.background
)
2619 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
2620 if (xgcv
.foreground
== xgcv
.background
)
2621 xgcv
.foreground
= s
->face
->foreground
;
2623 /* Make sure the cursor is distinct from text in this face. */
2624 if (xgcv
.background
== s
->face
->background
2625 && xgcv
.foreground
== s
->face
->foreground
)
2627 xgcv
.background
= s
->face
->foreground
;
2628 xgcv
.foreground
= s
->face
->background
;
2631 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2632 xgcv
.font
= s
->font
->fid
;
2633 xgcv
.graphics_exposures
= False
;
2634 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2636 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2637 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2640 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2641 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2643 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2648 /* Set up S->gc of glyph string S for drawing text in mouse face. */
2651 x_set_mouse_face_gc (s
)
2652 struct glyph_string
*s
;
2657 /* What face has to be used for the mouse face? */
2658 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
2659 face
= FACE_FROM_ID (s
->f
, face_id
);
2660 if (s
->first_glyph
->type
== CHAR_GLYPH
)
2661 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
);
2663 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0);
2664 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
2665 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2667 /* If font in this face is same as S->font, use it. */
2668 if (s
->font
== s
->face
->font
)
2669 s
->gc
= s
->face
->gc
;
2672 /* Otherwise construct scratch_cursor_gc with values from FACE
2677 xgcv
.background
= s
->face
->background
;
2678 xgcv
.foreground
= s
->face
->foreground
;
2679 IF_DEBUG (x_check_font (s
->f
, s
->font
));
2680 xgcv
.font
= s
->font
->fid
;
2681 xgcv
.graphics_exposures
= False
;
2682 mask
= GCForeground
| GCBackground
| GCFont
| GCGraphicsExposures
;
2684 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
2685 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
2688 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
2689 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
2691 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
2694 xassert (s
->gc
!= 0);
2698 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
2699 Faces to use in the mode line have already been computed when the
2700 matrix was built, so there isn't much to do, here. */
2703 x_set_mode_line_face_gc (s
)
2704 struct glyph_string
*s
;
2706 s
->gc
= s
->face
->gc
;
2710 /* Set S->gc of glyph string S for drawing that glyph string. Set
2711 S->stippled_p to a non-zero value if the face of S has a stipple
2715 x_set_glyph_string_gc (s
)
2716 struct glyph_string
*s
;
2718 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
2720 if (s
->hl
== DRAW_NORMAL_TEXT
)
2722 s
->gc
= s
->face
->gc
;
2723 s
->stippled_p
= s
->face
->stipple
!= 0;
2725 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
2727 x_set_mode_line_face_gc (s
);
2728 s
->stippled_p
= s
->face
->stipple
!= 0;
2730 else if (s
->hl
== DRAW_CURSOR
)
2732 x_set_cursor_gc (s
);
2735 else if (s
->hl
== DRAW_MOUSE_FACE
)
2737 x_set_mouse_face_gc (s
);
2738 s
->stippled_p
= s
->face
->stipple
!= 0;
2740 else if (s
->hl
== DRAW_IMAGE_RAISED
2741 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2743 s
->gc
= s
->face
->gc
;
2744 s
->stippled_p
= s
->face
->stipple
!= 0;
2748 s
->gc
= s
->face
->gc
;
2749 s
->stippled_p
= s
->face
->stipple
!= 0;
2752 /* GC must have been set. */
2753 xassert (s
->gc
!= 0);
2757 /* Return in *R the clipping rectangle for glyph string S. */
2760 x_get_glyph_string_clip_rect (s
, r
)
2761 struct glyph_string
*s
;
2764 if (s
->row
->full_width_p
)
2766 /* Draw full-width. X coordinates are relative to S->w->left. */
2767 int canon_x
= CANON_X_UNIT (s
->f
);
2769 r
->x
= WINDOW_LEFT_MARGIN (s
->w
) * canon_x
;
2770 r
->width
= XFASTINT (s
->w
->width
) * canon_x
;
2772 if (FRAME_HAS_VERTICAL_SCROLL_BARS (s
->f
))
2774 int width
= FRAME_SCROLL_BAR_WIDTH (s
->f
) * canon_x
;
2775 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (s
->f
))
2779 r
->x
+= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
2781 /* Unless displaying a mode or menu bar line, which are always
2782 fully visible, clip to the visible part of the row. */
2783 if (s
->w
->pseudo_window_p
)
2784 r
->height
= s
->row
->visible_height
;
2786 r
->height
= s
->height
;
2790 /* This is a text line that may be partially visible. */
2791 r
->x
= WINDOW_AREA_TO_FRAME_PIXEL_X (s
->w
, s
->area
, 0);
2792 r
->width
= window_box_width (s
->w
, s
->area
);
2793 r
->height
= s
->row
->visible_height
;
2796 /* Don't use S->y for clipping because it doesn't take partially
2797 visible lines into account. For example, it can be negative for
2798 partially visible lines at the top of a window. */
2799 if (!s
->row
->full_width_p
2800 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2801 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2803 r
->y
= max (0, s
->row
->y
);
2805 /* If drawing a tool-bar window, draw it over the internal border
2806 at the top of the window. */
2807 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
2808 r
->y
-= s
->f
->output_data
.x
->internal_border_width
;
2810 /* If S draws overlapping rows, it's sufficient to use the top and
2811 bottom of the window for clipping because this glyph string
2812 intentionally draws over other lines. */
2813 if (s
->for_overlaps_p
)
2815 r
->y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (s
->w
);
2816 r
->height
= window_text_bottom_y (s
->w
) - r
->y
;
2819 r
->y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
->y
);
2823 /* Set clipping for output of glyph string S. S may be part of a mode
2824 line or menu if we don't have X toolkit support. */
2827 x_set_glyph_string_clipping (s
)
2828 struct glyph_string
*s
;
2831 x_get_glyph_string_clip_rect (s
, &r
);
2832 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &r
, 1, Unsorted
);
2836 /* Compute left and right overhang of glyph string S. If S is a glyph
2837 string for a composition, assume overhangs don't exist. */
2840 x_compute_glyph_string_overhangs (s
)
2841 struct glyph_string
*s
;
2844 && s
->first_glyph
->type
== CHAR_GLYPH
)
2847 int direction
, font_ascent
, font_descent
;
2848 XTextExtents16 (s
->font
, s
->char2b
, s
->nchars
, &direction
,
2849 &font_ascent
, &font_descent
, &cs
);
2850 s
->right_overhang
= cs
.rbearing
> cs
.width
? cs
.rbearing
- cs
.width
: 0;
2851 s
->left_overhang
= cs
.lbearing
< 0 ? -cs
.lbearing
: 0;
2856 /* Compute overhangs and x-positions for glyph string S and its
2857 predecessors, or successors. X is the starting x-position for S.
2858 BACKWARD_P non-zero means process predecessors. */
2861 x_compute_overhangs_and_x (s
, x
, backward_p
)
2862 struct glyph_string
*s
;
2870 x_compute_glyph_string_overhangs (s
);
2880 x_compute_glyph_string_overhangs (s
);
2889 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
2890 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
2891 assumed to be zero. */
2894 x_get_glyph_overhangs (glyph
, f
, left
, right
)
2895 struct glyph
*glyph
;
2901 if (glyph
->type
== CHAR_GLYPH
)
2905 struct font_info
*font_info
;
2909 face
= x_get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
2911 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
2913 && (pcm
= x_per_char_metric (font
, &char2b
)))
2915 if (pcm
->rbearing
> pcm
->width
)
2916 *right
= pcm
->rbearing
- pcm
->width
;
2917 if (pcm
->lbearing
< 0)
2918 *left
= -pcm
->lbearing
;
2924 /* Return the index of the first glyph preceding glyph string S that
2925 is overwritten by S because of S's left overhang. Value is -1
2926 if no glyphs are overwritten. */
2929 x_left_overwritten (s
)
2930 struct glyph_string
*s
;
2934 if (s
->left_overhang
)
2937 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2938 int first
= s
->first_glyph
- glyphs
;
2940 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
2941 x
-= glyphs
[i
].pixel_width
;
2952 /* Return the index of the first glyph preceding glyph string S that
2953 is overwriting S because of its right overhang. Value is -1 if no
2954 glyph in front of S overwrites S. */
2957 x_left_overwriting (s
)
2958 struct glyph_string
*s
;
2961 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2962 int first
= s
->first_glyph
- glyphs
;
2966 for (i
= first
- 1; i
>= 0; --i
)
2969 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
2972 x
-= glyphs
[i
].pixel_width
;
2979 /* Return the index of the last glyph following glyph string S that is
2980 not overwritten by S because of S's right overhang. Value is -1 if
2981 no such glyph is found. */
2984 x_right_overwritten (s
)
2985 struct glyph_string
*s
;
2989 if (s
->right_overhang
)
2992 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
2993 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
2994 int end
= s
->row
->used
[s
->area
];
2996 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
2997 x
+= glyphs
[i
].pixel_width
;
3006 /* Return the index of the last glyph following glyph string S that
3007 overwrites S because of its left overhang. Value is negative
3008 if no such glyph is found. */
3011 x_right_overwriting (s
)
3012 struct glyph_string
*s
;
3015 int end
= s
->row
->used
[s
->area
];
3016 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
3017 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
3021 for (i
= first
; i
< end
; ++i
)
3024 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
3027 x
+= glyphs
[i
].pixel_width
;
3034 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
3037 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
3038 struct glyph_string
*s
;
3042 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
3043 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3044 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3045 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3049 /* Draw the background of glyph_string S. If S->background_filled_p
3050 is non-zero don't draw it. FORCE_P non-zero means draw the
3051 background even if it wouldn't be drawn normally. This is used
3052 when a string preceding S draws into the background of S, or S
3053 contains the first component of a composition. */
3056 x_draw_glyph_string_background (s
, force_p
)
3057 struct glyph_string
*s
;
3060 /* Nothing to do if background has already been drawn or if it
3061 shouldn't be drawn in the first place. */
3062 if (!s
->background_filled_p
)
3066 /* Fill background with a stipple pattern. */
3067 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3068 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
3069 s
->y
+ s
->face
->box_line_width
,
3070 s
->background_width
,
3071 s
->height
- 2 * s
->face
->box_line_width
);
3072 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3073 s
->background_filled_p
= 1;
3075 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * s
->face
->box_line_width
3076 || s
->font_not_found_p
3077 || s
->extends_to_end_of_line_p
3080 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ s
->face
->box_line_width
,
3081 s
->background_width
,
3082 s
->height
- 2 * s
->face
->box_line_width
);
3083 s
->background_filled_p
= 1;
3089 /* Draw the foreground of glyph string S. */
3092 x_draw_glyph_string_foreground (s
)
3093 struct glyph_string
*s
;
3097 /* If first glyph of S has a left box line, start drawing the text
3098 of S to the right of that box line. */
3099 if (s
->face
->box
!= FACE_NO_BOX
3100 && s
->first_glyph
->left_box_line_p
)
3101 x
= s
->x
+ s
->face
->box_line_width
;
3105 /* Draw characters of S as rectangles if S's font could not be
3107 if (s
->font_not_found_p
)
3109 for (i
= 0; i
< s
->nchars
; ++i
)
3111 struct glyph
*g
= s
->first_glyph
+ i
;
3112 XDrawRectangle (s
->display
, s
->window
,
3113 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
3115 x
+= g
->pixel_width
;
3120 char *char1b
= (char *) s
->char2b
;
3121 int boff
= s
->font_info
->baseline_offset
;
3123 if (s
->font_info
->vertical_centering
)
3124 boff
= VCENTER_BASELINE_OFFSET (s
->font
, s
->f
) - boff
;
3126 /* If we can use 8-bit functions, condense S->char2b. */
3128 for (i
= 0; i
< s
->nchars
; ++i
)
3129 char1b
[i
] = s
->char2b
[i
].byte2
;
3131 /* Draw text with XDrawString if background has already been
3132 filled. Otherwise, use XDrawImageString. (Note that
3133 XDrawImageString is usually faster than XDrawString.) Always
3134 use XDrawImageString when drawing the cursor so that there is
3135 no chance that characters under a box cursor are invisible. */
3136 if (s
->for_overlaps_p
3137 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
3139 /* Draw characters with 16-bit or 8-bit functions. */
3141 XDrawString16 (s
->display
, s
->window
, s
->gc
, x
,
3142 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3144 XDrawString (s
->display
, s
->window
, s
->gc
, x
,
3145 s
->ybase
- boff
, char1b
, s
->nchars
);
3150 XDrawImageString16 (s
->display
, s
->window
, s
->gc
, x
,
3151 s
->ybase
- boff
, s
->char2b
, s
->nchars
);
3153 XDrawImageString (s
->display
, s
->window
, s
->gc
, x
,
3154 s
->ybase
- boff
, char1b
, s
->nchars
);
3159 /* Draw the foreground of composite glyph string S. */
3162 x_draw_composite_glyph_string_foreground (s
)
3163 struct glyph_string
*s
;
3167 /* If first glyph of S has a left box line, start drawing the text
3168 of S to the right of that box line. */
3169 if (s
->face
->box
!= FACE_NO_BOX
3170 && s
->first_glyph
->left_box_line_p
)
3171 x
= s
->x
+ s
->face
->box_line_width
;
3175 /* S is a glyph string for a composition. S->gidx is the index of
3176 the first character drawn for glyphs of this composition.
3177 S->gidx == 0 means we are drawing the very first character of
3178 this composition. */
3180 /* Draw a rectangle for the composition if the font for the very
3181 first character of the composition could not be loaded. */
3182 if (s
->font_not_found_p
)
3185 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
3186 s
->width
- 1, s
->height
- 1);
3190 for (i
= 0; i
< s
->nchars
; i
++, ++s
->gidx
)
3191 XDrawString16 (s
->display
, s
->window
, s
->gc
,
3192 x
+ s
->cmp
->offsets
[s
->gidx
* 2],
3193 s
->ybase
- s
->cmp
->offsets
[s
->gidx
* 2 + 1],
3199 #ifdef USE_X_TOOLKIT
3201 static struct frame
*x_frame_of_widget
P_ ((Widget
));
3204 /* Return the frame on which widget WIDGET is used.. Abort if frame
3205 cannot be determined. */
3207 static struct frame
*
3208 x_frame_of_widget (widget
)
3211 struct x_display_info
*dpyinfo
;
3215 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
3217 /* Find the top-level shell of the widget. Note that this function
3218 can be called when the widget is not yet realized, so XtWindow
3219 (widget) == 0. That's the reason we can't simply use
3220 x_any_window_to_frame. */
3221 while (!XtIsTopLevelShell (widget
))
3222 widget
= XtParent (widget
);
3224 /* Look for a frame with that top-level widget. Allocate the color
3225 on that frame to get the right gamma correction value. */
3226 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
3227 if (GC_FRAMEP (XCAR (tail
))
3228 && (f
= XFRAME (XCAR (tail
)),
3229 (f
->output_data
.nothing
!= 1
3230 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
3231 && f
->output_data
.x
->widget
== widget
)
3238 /* Allocate the color COLOR->pixel on the screen and display of
3239 widget WIDGET in colormap CMAP. If an exact match cannot be
3240 allocated, try the nearest color available. Value is non-zero
3241 if successful. This is called from lwlib. */
3244 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
3249 struct frame
*f
= x_frame_of_widget (widget
);
3250 return x_alloc_nearest_color (f
, cmap
, color
);
3254 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3255 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3256 If this produces the same color as PIXEL, try a color where all RGB
3257 values have DELTA added. Return the allocated color in *PIXEL.
3258 DISPLAY is the X display, CMAP is the colormap to operate on.
3259 Value is non-zero if successful. */
3262 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
3266 unsigned long *pixel
;
3270 struct frame
*f
= x_frame_of_widget (widget
);
3271 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
3275 #endif /* USE_X_TOOLKIT */
3278 /* Allocate the color COLOR->pixel on SCREEN of DISPLAY, colormap
3279 CMAP. If an exact match can't be allocated, try the nearest color
3280 available. Value is non-zero if successful. Set *COLOR to the
3284 x_alloc_nearest_color (f
, cmap
, color
)
3289 Display
*display
= FRAME_X_DISPLAY (f
);
3290 Screen
*screen
= FRAME_X_SCREEN (f
);
3293 gamma_correct (f
, color
);
3294 rc
= XAllocColor (display
, cmap
, color
);
3297 /* If we got to this point, the colormap is full, so we're going
3298 to try to get the next closest color. The algorithm used is
3299 a least-squares matching, which is what X uses for closest
3300 color matching with StaticColor visuals. */
3302 unsigned long nearest_delta
= ~0;
3303 int ncells
= XDisplayCells (display
, XScreenNumberOfScreen (screen
));
3304 XColor
*cells
= (XColor
*) alloca (ncells
* sizeof *cells
);
3306 for (i
= 0; i
< ncells
; ++i
)
3308 XQueryColors (display
, cmap
, cells
, ncells
);
3310 for (nearest
= i
= 0; i
< ncells
; ++i
)
3312 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
3313 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
3314 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
3315 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
3317 if (delta
< nearest_delta
)
3320 nearest_delta
= delta
;
3324 color
->red
= cells
[nearest
].red
;
3325 color
->green
= cells
[nearest
].green
;
3326 color
->blue
= cells
[nearest
].blue
;
3327 rc
= XAllocColor (display
, cmap
, color
);
3330 #ifdef DEBUG_X_COLORS
3332 register_color (color
->pixel
);
3333 #endif /* DEBUG_X_COLORS */
3339 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
3340 It's necessary to do this instead of just using PIXEL directly to
3341 get color reference counts right. */
3344 x_copy_color (f
, pixel
)
3346 unsigned long pixel
;
3350 color
.pixel
= pixel
;
3352 XQueryColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3353 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
3355 #ifdef DEBUG_X_COLORS
3356 register_color (pixel
);
3362 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
3363 It's necessary to do this instead of just using PIXEL directly to
3364 get color reference counts right. */
3367 x_copy_dpy_color (dpy
, cmap
, pixel
)
3370 unsigned long pixel
;
3374 color
.pixel
= pixel
;
3376 XQueryColor (dpy
, cmap
, &color
);
3377 XAllocColor (dpy
, cmap
, &color
);
3379 #ifdef DEBUG_X_COLORS
3380 register_color (pixel
);
3386 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
3387 or DELTA. Try a color with RGB values multiplied by FACTOR first.
3388 If this produces the same color as PIXEL, try a color where all RGB
3389 values have DELTA added. Return the allocated color in *PIXEL.
3390 DISPLAY is the X display, CMAP is the colormap to operate on.
3391 Value is non-zero if successful. */
3394 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
3398 unsigned long *pixel
;
3405 /* Get RGB color values. */
3406 color
.pixel
= *pixel
;
3407 XQueryColor (display
, cmap
, &color
);
3409 /* Change RGB values by specified FACTOR. Avoid overflow! */
3410 xassert (factor
>= 0);
3411 new.red
= min (0xffff, factor
* color
.red
);
3412 new.green
= min (0xffff, factor
* color
.green
);
3413 new.blue
= min (0xffff, factor
* color
.blue
);
3415 /* Try to allocate the color. */
3416 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3419 if (new.pixel
== *pixel
)
3421 /* If we end up with the same color as before, try adding
3422 delta to the RGB values. */
3423 x_free_colors (f
, &new.pixel
, 1);
3425 new.red
= min (0xffff, delta
+ color
.red
);
3426 new.green
= min (0xffff, delta
+ color
.green
);
3427 new.blue
= min (0xffff, delta
+ color
.blue
);
3428 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
3439 /* Set up the foreground color for drawing relief lines of glyph
3440 string S. RELIEF is a pointer to a struct relief containing the GC
3441 with which lines will be drawn. Use a color that is FACTOR or
3442 DELTA lighter or darker than the relief's background which is found
3443 in S->f->output_data.x->relief_background. If such a color cannot
3444 be allocated, use DEFAULT_PIXEL, instead. */
3447 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
3449 struct relief
*relief
;
3452 unsigned long default_pixel
;
3455 struct x_output
*di
= f
->output_data
.x
;
3456 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
3457 unsigned long pixel
;
3458 unsigned long background
= di
->relief_background
;
3459 Colormap cmap
= FRAME_X_COLORMAP (f
);
3460 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
3461 Display
*dpy
= FRAME_X_DISPLAY (f
);
3463 xgcv
.graphics_exposures
= False
;
3464 xgcv
.line_width
= 1;
3466 /* Free previously allocated color. The color cell will be reused
3467 when it has been freed as many times as it was allocated, so this
3468 doesn't affect faces using the same colors. */
3470 && relief
->allocated_p
)
3472 x_free_colors (f
, &relief
->pixel
, 1);
3473 relief
->allocated_p
= 0;
3476 /* Allocate new color. */
3477 xgcv
.foreground
= default_pixel
;
3479 if (dpyinfo
->n_planes
!= 1
3480 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
3482 relief
->allocated_p
= 1;
3483 xgcv
.foreground
= relief
->pixel
= pixel
;
3486 if (relief
->gc
== 0)
3488 xgcv
.stipple
= dpyinfo
->gray
;
3490 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
3493 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
3497 /* Set up colors for the relief lines around glyph string S. */
3500 x_setup_relief_colors (s
)
3501 struct glyph_string
*s
;
3503 struct x_output
*di
= s
->f
->output_data
.x
;
3504 unsigned long color
;
3506 if (s
->face
->use_box_color_for_shadows_p
)
3507 color
= s
->face
->box_color
;
3512 /* Get the background color of the face. */
3513 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
3514 color
= xgcv
.background
;
3517 if (di
->white_relief
.gc
== 0
3518 || color
!= di
->relief_background
)
3520 di
->relief_background
= color
;
3521 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
3522 WHITE_PIX_DEFAULT (s
->f
));
3523 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
3524 BLACK_PIX_DEFAULT (s
->f
));
3529 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
3530 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
3531 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
3532 relief. LEFT_P non-zero means draw a relief on the left side of
3533 the rectangle. RIGHT_P non-zero means draw a relief on the right
3534 side of the rectangle. CLIP_RECT is the clipping rectangle to use
3538 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
3539 raised_p
, left_p
, right_p
, clip_rect
)
3541 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
, raised_p
;
3542 XRectangle
*clip_rect
;
3548 gc
= f
->output_data
.x
->white_relief
.gc
;
3550 gc
= f
->output_data
.x
->black_relief
.gc
;
3551 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3554 for (i
= 0; i
< width
; ++i
)
3555 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3556 left_x
+ i
* left_p
, top_y
+ i
,
3557 right_x
+ 1 - i
* right_p
, top_y
+ i
);
3561 for (i
= 0; i
< width
; ++i
)
3562 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3563 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
);
3565 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3567 gc
= f
->output_data
.x
->black_relief
.gc
;
3569 gc
= f
->output_data
.x
->white_relief
.gc
;
3570 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, clip_rect
, 1, Unsorted
);
3573 for (i
= 0; i
< width
; ++i
)
3574 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3575 left_x
+ i
* left_p
, bottom_y
- i
,
3576 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
3580 for (i
= 0; i
< width
; ++i
)
3581 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3582 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
3584 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
3588 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
3589 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
3590 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
3591 left side of the rectangle. RIGHT_P non-zero means draw a line
3592 on the right side of the rectangle. CLIP_RECT is the clipping
3593 rectangle to use when drawing. */
3596 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3597 left_p
, right_p
, clip_rect
)
3598 struct glyph_string
*s
;
3599 int left_x
, top_y
, right_x
, bottom_y
, left_p
, right_p
;
3600 XRectangle
*clip_rect
;
3604 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3605 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
3606 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
3609 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3610 left_x
, top_y
, right_x
- left_x
, width
);
3614 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3615 left_x
, top_y
, width
, bottom_y
- top_y
);
3618 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3619 left_x
, bottom_y
- width
, right_x
- left_x
, width
);
3623 XFillRectangle (s
->display
, s
->window
, s
->gc
,
3624 right_x
- width
, top_y
, width
, bottom_y
- top_y
);
3626 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3627 XSetClipMask (s
->display
, s
->gc
, None
);
3631 /* Draw a box around glyph string S. */
3634 x_draw_glyph_string_box (s
)
3635 struct glyph_string
*s
;
3637 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
3638 int left_p
, right_p
;
3639 struct glyph
*last_glyph
;
3640 XRectangle clip_rect
;
3642 last_x
= window_box_right (s
->w
, s
->area
);
3643 if (s
->row
->full_width_p
3644 && !s
->w
->pseudo_window_p
)
3646 last_x
+= FRAME_X_RIGHT_FLAGS_AREA_WIDTH (s
->f
);
3647 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (s
->f
))
3648 last_x
+= FRAME_SCROLL_BAR_WIDTH (s
->f
) * CANON_X_UNIT (s
->f
);
3651 /* The glyph that may have a right box line. */
3652 last_glyph
= (s
->cmp
|| s
->img
3654 : s
->first_glyph
+ s
->nchars
- 1);
3656 width
= s
->face
->box_line_width
;
3657 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
3659 right_x
= ((s
->row
->full_width_p
3661 : min (last_x
, s
->x
+ s
->background_width
) - 1));
3663 bottom_y
= top_y
+ s
->height
- 1;
3665 left_p
= (s
->first_glyph
->left_box_line_p
3666 || (s
->hl
== DRAW_MOUSE_FACE
3668 || s
->prev
->hl
!= s
->hl
)));
3669 right_p
= (last_glyph
->right_box_line_p
3670 || (s
->hl
== DRAW_MOUSE_FACE
3672 || s
->next
->hl
!= s
->hl
)));
3674 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3676 if (s
->face
->box
== FACE_SIMPLE_BOX
)
3677 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
3678 left_p
, right_p
, &clip_rect
);
3681 x_setup_relief_colors (s
);
3682 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
3683 width
, raised_p
, left_p
, right_p
, &clip_rect
);
3688 /* Draw foreground of image glyph string S. */
3691 x_draw_image_foreground (s
)
3692 struct glyph_string
*s
;
3695 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3697 /* If first glyph of S has a left box line, start drawing it to the
3698 right of that line. */
3699 if (s
->face
->box
!= FACE_NO_BOX
3700 && s
->first_glyph
->left_box_line_p
)
3701 x
= s
->x
+ s
->face
->box_line_width
;
3705 /* If there is a margin around the image, adjust x- and y-position
3709 x
+= s
->img
->margin
;
3710 y
+= s
->img
->margin
;
3717 /* We can't set both a clip mask and use XSetClipRectangles
3718 because the latter also sets a clip mask. We also can't
3719 trust on the shape extension to be available
3720 (XShapeCombineRegion). So, compute the rectangle to draw
3722 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3725 XRectangle clip_rect
, image_rect
, r
;
3727 xgcv
.clip_mask
= s
->img
->mask
;
3728 xgcv
.clip_x_origin
= x
;
3729 xgcv
.clip_y_origin
= y
;
3730 xgcv
.function
= GXcopy
;
3731 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3733 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3736 image_rect
.width
= s
->img
->width
;
3737 image_rect
.height
= s
->img
->height
;
3738 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
3739 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3740 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3744 unsigned long mask
= GCClipXOrigin
| GCClipYOrigin
| GCFunction
;
3746 XRectangle clip_rect
, image_rect
, r
;
3748 x_get_glyph_string_clip_rect (s
, &clip_rect
);
3751 image_rect
.width
= s
->img
->width
;
3752 image_rect
.height
= s
->img
->height
;
3753 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
3754 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
3755 r
.x
- x
, r
.y
- y
, r
.width
, r
.height
, r
.x
, r
.y
);
3757 /* When the image has a mask, we can expect that at
3758 least part of a mouse highlight or a block cursor will
3759 be visible. If the image doesn't have a mask, make
3760 a block cursor visible by drawing a rectangle around
3761 the image. I believe it's looking better if we do
3762 nothing here for mouse-face. */
3763 if (s
->hl
== DRAW_CURSOR
)
3764 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3765 s
->img
->width
- 1, s
->img
->height
- 1);
3769 /* Draw a rectangle if image could not be loaded. */
3770 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
3771 s
->img
->width
- 1, s
->img
->height
- 1);
3775 /* Draw a relief around the image glyph string S. */
3778 x_draw_image_relief (s
)
3779 struct glyph_string
*s
;
3781 int x0
, y0
, x1
, y1
, thick
, raised_p
;
3784 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
);
3786 /* If first glyph of S has a left box line, start drawing it to the
3787 right of that line. */
3788 if (s
->face
->box
!= FACE_NO_BOX
3789 && s
->first_glyph
->left_box_line_p
)
3790 x
= s
->x
+ s
->face
->box_line_width
;
3794 /* If there is a margin around the image, adjust x- and y-position
3798 x
+= s
->img
->margin
;
3799 y
+= s
->img
->margin
;
3802 if (s
->hl
== DRAW_IMAGE_SUNKEN
3803 || s
->hl
== DRAW_IMAGE_RAISED
)
3805 thick
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
3806 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
3810 thick
= abs (s
->img
->relief
);
3811 raised_p
= s
->img
->relief
> 0;
3816 x1
= x
+ s
->img
->width
+ thick
- 1;
3817 y1
= y
+ s
->img
->height
+ thick
- 1;
3819 x_setup_relief_colors (s
);
3820 x_get_glyph_string_clip_rect (s
, &r
);
3821 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
, 1, 1, &r
);
3825 /* Draw the foreground of image glyph string S to PIXMAP. */
3828 x_draw_image_foreground_1 (s
, pixmap
)
3829 struct glyph_string
*s
;
3833 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
);
3835 /* If first glyph of S has a left box line, start drawing it to the
3836 right of that line. */
3837 if (s
->face
->box
!= FACE_NO_BOX
3838 && s
->first_glyph
->left_box_line_p
)
3839 x
= s
->face
->box_line_width
;
3843 /* If there is a margin around the image, adjust x- and y-position
3847 x
+= s
->img
->margin
;
3848 y
+= s
->img
->margin
;
3855 /* We can't set both a clip mask and use XSetClipRectangles
3856 because the latter also sets a clip mask. We also can't
3857 trust on the shape extension to be available
3858 (XShapeCombineRegion). So, compute the rectangle to draw
3860 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3864 xgcv
.clip_mask
= s
->img
->mask
;
3865 xgcv
.clip_x_origin
= x
;
3866 xgcv
.clip_y_origin
= y
;
3867 xgcv
.function
= GXcopy
;
3868 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3870 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
3871 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3872 XSetClipMask (s
->display
, s
->gc
, None
);
3876 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
3877 0, 0, s
->img
->width
, s
->img
->height
, x
, y
);
3879 /* When the image has a mask, we can expect that at
3880 least part of a mouse highlight or a block cursor will
3881 be visible. If the image doesn't have a mask, make
3882 a block cursor visible by drawing a rectangle around
3883 the image. I believe it's looking better if we do
3884 nothing here for mouse-face. */
3885 if (s
->hl
== DRAW_CURSOR
)
3886 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
3887 s
->img
->width
- 1, s
->img
->height
- 1);
3891 /* Draw a rectangle if image could not be loaded. */
3892 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
3893 s
->img
->width
- 1, s
->img
->height
- 1);
3897 /* Draw part of the background of glyph string S. X, Y, W, and H
3898 give the rectangle to draw. */
3901 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
3902 struct glyph_string
*s
;
3907 /* Fill background with a stipple pattern. */
3908 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3909 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
3910 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3913 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
3917 /* Draw image glyph string S.
3920 s->x +-------------------------
3923 | +-------------------------
3926 | | +-------------------
3932 x_draw_image_glyph_string (s
)
3933 struct glyph_string
*s
;
3936 int box_line_width
= s
->face
->box_line_width
;
3937 int margin
= s
->img
->margin
;
3939 Pixmap pixmap
= None
;
3941 height
= s
->height
- 2 * box_line_width
;
3943 /* Fill background with face under the image. Do it only if row is
3944 taller than image or if image has a clip mask to reduce
3946 s
->stippled_p
= s
->face
->stipple
!= 0;
3947 if (height
> s
->img
->height
3950 || s
->img
->pixmap
== 0
3951 || s
->width
!= s
->background_width
)
3953 if (box_line_width
&& s
->first_glyph
->left_box_line_p
)
3954 x
= s
->x
+ box_line_width
;
3958 y
= s
->y
+ box_line_width
;
3962 /* Create a pixmap as large as the glyph string. Fill it
3963 with the background color. Copy the image to it, using
3964 its mask. Copy the temporary pixmap to the display. */
3965 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
3966 int depth
= DefaultDepthOfScreen (screen
);
3968 /* Create a pixmap as large as the glyph string. */
3969 pixmap
= XCreatePixmap (s
->display
, s
->window
,
3970 s
->background_width
,
3973 /* Don't clip in the following because we're working on the
3975 XSetClipMask (s
->display
, s
->gc
, None
);
3977 /* Fill the pixmap with the background color/stipple. */
3980 /* Fill background with a stipple pattern. */
3981 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3982 XFillRectangle (s
->display
, pixmap
, s
->gc
,
3983 0, 0, s
->background_width
, s
->height
);
3984 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3989 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
3991 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3992 XFillRectangle (s
->display
, pixmap
, s
->gc
,
3993 0, 0, s
->background_width
, s
->height
);
3994 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3998 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
4000 s
->background_filled_p
= 1;
4003 /* Draw the foreground. */
4006 x_draw_image_foreground_1 (s
, pixmap
);
4007 x_set_glyph_string_clipping (s
);
4008 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
4009 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
4010 XFreePixmap (s
->display
, pixmap
);
4013 x_draw_image_foreground (s
);
4015 /* If we must draw a relief around the image, do it. */
4017 || s
->hl
== DRAW_IMAGE_RAISED
4018 || s
->hl
== DRAW_IMAGE_SUNKEN
)
4019 x_draw_image_relief (s
);
4023 /* Draw stretch glyph string S. */
4026 x_draw_stretch_glyph_string (s
)
4027 struct glyph_string
*s
;
4029 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4030 s
->stippled_p
= s
->face
->stipple
!= 0;
4032 if (s
->hl
== DRAW_CURSOR
4033 && !x_stretch_cursor_p
)
4035 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
4036 as wide as the stretch glyph. */
4037 int width
= min (CANON_X_UNIT (s
->f
), s
->background_width
);
4040 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, width
, s
->height
);
4042 /* Clear rest using the GC of the original non-cursor face. */
4043 if (width
< s
->background_width
)
4045 GC gc
= s
->face
->gc
;
4046 int x
= s
->x
+ width
, y
= s
->y
;
4047 int w
= s
->background_width
- width
, h
= s
->height
;
4050 x_get_glyph_string_clip_rect (s
, &r
);
4051 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
4053 if (s
->face
->stipple
)
4055 /* Fill background with a stipple pattern. */
4056 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
4057 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4058 XSetFillStyle (s
->display
, gc
, FillSolid
);
4063 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
4064 XSetForeground (s
->display
, gc
, xgcv
.background
);
4065 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
4066 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
4071 x_draw_glyph_string_bg_rect (s
, s
->x
, s
->y
, s
->background_width
,
4074 s
->background_filled_p
= 1;
4078 /* Draw glyph string S. */
4081 x_draw_glyph_string (s
)
4082 struct glyph_string
*s
;
4084 /* If S draws into the background of its successor, draw the
4085 background of the successor first so that S can draw into it.
4086 This makes S->next use XDrawString instead of XDrawImageString. */
4087 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps_p
)
4089 xassert (s
->next
->img
== NULL
);
4090 x_set_glyph_string_gc (s
->next
);
4091 x_set_glyph_string_clipping (s
->next
);
4092 x_draw_glyph_string_background (s
->next
, 1);
4095 /* Set up S->gc, set clipping and draw S. */
4096 x_set_glyph_string_gc (s
);
4097 x_set_glyph_string_clipping (s
);
4099 switch (s
->first_glyph
->type
)
4102 x_draw_image_glyph_string (s
);
4106 x_draw_stretch_glyph_string (s
);
4110 if (s
->for_overlaps_p
)
4111 s
->background_filled_p
= 1;
4113 x_draw_glyph_string_background (s
, 0);
4114 x_draw_glyph_string_foreground (s
);
4117 case COMPOSITE_GLYPH
:
4118 if (s
->for_overlaps_p
|| s
->gidx
> 0)
4119 s
->background_filled_p
= 1;
4121 x_draw_glyph_string_background (s
, 1);
4122 x_draw_composite_glyph_string_foreground (s
);
4129 if (!s
->for_overlaps_p
)
4131 /* Draw underline. */
4132 if (s
->face
->underline_p
)
4134 unsigned long dy
, h
;
4136 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_THICKNESS
, &h
))
4138 if (!XGetFontProperty (s
->font
, XA_UNDERLINE_POSITION
, &dy
))
4141 if (s
->face
->underline_defaulted_p
)
4142 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4147 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4148 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
4149 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4151 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4155 /* Draw overline. */
4156 if (s
->face
->overline_p
)
4158 unsigned long dy
= 0, h
= 1;
4160 if (s
->face
->overline_color_defaulted_p
)
4161 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4166 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4167 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
4168 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4170 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4174 /* Draw strike-through. */
4175 if (s
->face
->strike_through_p
)
4177 unsigned long h
= 1;
4178 unsigned long dy
= (s
->height
- h
) / 2;
4180 if (s
->face
->strike_through_color_defaulted_p
)
4181 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4186 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
4187 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
4188 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
4190 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
4195 if (s
->face
->box
!= FACE_NO_BOX
)
4196 x_draw_glyph_string_box (s
);
4199 /* Reset clipping. */
4200 XSetClipMask (s
->display
, s
->gc
, None
);
4204 static int x_fill_composite_glyph_string
P_ ((struct glyph_string
*,
4205 struct face
**, int));
4208 /* Fill glyph string S with composition components specified by S->cmp.
4210 FACES is an array of faces for all components of this composition.
4211 S->gidx is the index of the first component for S.
4212 OVERLAPS_P non-zero means S should draw the foreground only, and
4213 use its physical height for clipping.
4215 Value is the index of a component not in S. */
4218 x_fill_composite_glyph_string (s
, faces
, overlaps_p
)
4219 struct glyph_string
*s
;
4220 struct face
**faces
;
4227 s
->for_overlaps_p
= overlaps_p
;
4229 s
->face
= faces
[s
->gidx
];
4230 s
->font
= s
->face
->font
;
4231 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4233 /* For all glyphs of this composition, starting at the offset
4234 S->gidx, until we reach the end of the definition or encounter a
4235 glyph that requires the different face, add it to S. */
4237 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
4240 /* All glyph strings for the same composition has the same width,
4241 i.e. the width set for the first component of the composition. */
4243 s
->width
= s
->first_glyph
->pixel_width
;
4245 /* If the specified font could not be loaded, use the frame's
4246 default font, but record the fact that we couldn't load it in
4247 the glyph string so that we can draw rectangles for the
4248 characters of the glyph string. */
4249 if (s
->font
== NULL
)
4251 s
->font_not_found_p
= 1;
4252 s
->font
= FRAME_FONT (s
->f
);
4255 /* Adjust base line for subscript/superscript text. */
4256 s
->ybase
+= s
->first_glyph
->voffset
;
4258 xassert (s
->face
&& s
->face
->gc
);
4260 /* This glyph string must always be drawn with 16-bit functions. */
4263 return s
->gidx
+ s
->nchars
;
4267 /* Fill glyph string S from a sequence of character glyphs.
4269 FACE_ID is the face id of the string. START is the index of the
4270 first glyph to consider, END is the index of the last + 1.
4271 OVERLAPS_P non-zero means S should draw the foreground only, and
4272 use its physical height for clipping.
4274 Value is the index of the first glyph not in S. */
4277 x_fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
4278 struct glyph_string
*s
;
4280 int start
, end
, overlaps_p
;
4282 struct glyph
*glyph
, *last
;
4284 int glyph_not_available_p
;
4286 xassert (s
->f
== XFRAME (s
->w
->frame
));
4287 xassert (s
->nchars
== 0);
4288 xassert (start
>= 0 && end
> start
);
4290 s
->for_overlaps_p
= overlaps_p
,
4291 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4292 last
= s
->row
->glyphs
[s
->area
] + end
;
4293 voffset
= glyph
->voffset
;
4295 glyph_not_available_p
= glyph
->glyph_not_available_p
;
4298 && glyph
->type
== CHAR_GLYPH
4299 && glyph
->voffset
== voffset
4300 /* Same face id implies same font, nowadays. */
4301 && glyph
->face_id
== face_id
4302 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
4306 s
->face
= x_get_glyph_face_and_encoding (s
->f
, glyph
,
4307 s
->char2b
+ s
->nchars
,
4309 s
->two_byte_p
= two_byte_p
;
4311 xassert (s
->nchars
<= end
- start
);
4312 s
->width
+= glyph
->pixel_width
;
4316 s
->font
= s
->face
->font
;
4317 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4319 /* If the specified font could not be loaded, use the frame's font,
4320 but record the fact that we couldn't load it in
4321 S->font_not_found_p so that we can draw rectangles for the
4322 characters of the glyph string. */
4323 if (s
->font
== NULL
|| glyph_not_available_p
)
4325 s
->font_not_found_p
= 1;
4326 s
->font
= FRAME_FONT (s
->f
);
4329 /* Adjust base line for subscript/superscript text. */
4330 s
->ybase
+= voffset
;
4332 xassert (s
->face
&& s
->face
->gc
);
4333 return glyph
- s
->row
->glyphs
[s
->area
];
4337 /* Fill glyph string S from image glyph S->first_glyph. */
4340 x_fill_image_glyph_string (s
)
4341 struct glyph_string
*s
;
4343 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
4344 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
4346 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
4347 s
->font
= s
->face
->font
;
4348 s
->width
= s
->first_glyph
->pixel_width
;
4350 /* Adjust base line for subscript/superscript text. */
4351 s
->ybase
+= s
->first_glyph
->voffset
;
4355 /* Fill glyph string S from a sequence of stretch glyphs.
4357 ROW is the glyph row in which the glyphs are found, AREA is the
4358 area within the row. START is the index of the first glyph to
4359 consider, END is the index of the last + 1.
4361 Value is the index of the first glyph not in S. */
4364 x_fill_stretch_glyph_string (s
, row
, area
, start
, end
)
4365 struct glyph_string
*s
;
4366 struct glyph_row
*row
;
4367 enum glyph_row_area area
;
4370 struct glyph
*glyph
, *last
;
4371 int voffset
, face_id
;
4373 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
4375 glyph
= s
->row
->glyphs
[s
->area
] + start
;
4376 last
= s
->row
->glyphs
[s
->area
] + end
;
4377 face_id
= glyph
->face_id
;
4378 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
4379 s
->font
= s
->face
->font
;
4380 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
4381 s
->width
= glyph
->pixel_width
;
4382 voffset
= glyph
->voffset
;
4386 && glyph
->type
== STRETCH_GLYPH
4387 && glyph
->voffset
== voffset
4388 && glyph
->face_id
== face_id
);
4390 s
->width
+= glyph
->pixel_width
;
4392 /* Adjust base line for subscript/superscript text. */
4393 s
->ybase
+= voffset
;
4395 xassert (s
->face
&& s
->face
->gc
);
4396 return glyph
- s
->row
->glyphs
[s
->area
];
4400 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
4401 of XChar2b structures for S; it can't be allocated in
4402 x_init_glyph_string because it must be allocated via `alloca'. W
4403 is the window on which S is drawn. ROW and AREA are the glyph row
4404 and area within the row from which S is constructed. START is the
4405 index of the first glyph structure covered by S. HL is a
4406 face-override for drawing S. */
4409 x_init_glyph_string (s
, char2b
, w
, row
, area
, start
, hl
)
4410 struct glyph_string
*s
;
4413 struct glyph_row
*row
;
4414 enum glyph_row_area area
;
4416 enum draw_glyphs_face hl
;
4418 bzero (s
, sizeof *s
);
4420 s
->f
= XFRAME (w
->frame
);
4421 s
->display
= FRAME_X_DISPLAY (s
->f
);
4422 s
->window
= FRAME_X_WINDOW (s
->f
);
4427 s
->first_glyph
= row
->glyphs
[area
] + start
;
4428 s
->height
= row
->height
;
4429 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
4431 /* Display the internal border below the tool-bar window. */
4432 if (s
->w
== XWINDOW (s
->f
->tool_bar_window
))
4433 s
->y
-= s
->f
->output_data
.x
->internal_border_width
;
4435 s
->ybase
= s
->y
+ row
->ascent
;
4439 /* Set background width of glyph string S. START is the index of the
4440 first glyph following S. LAST_X is the right-most x-position + 1
4441 in the drawing area. */
4444 x_set_glyph_string_background_width (s
, start
, last_x
)
4445 struct glyph_string
*s
;
4449 /* If the face of this glyph string has to be drawn to the end of
4450 the drawing area, set S->extends_to_end_of_line_p. */
4451 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
4453 if (start
== s
->row
->used
[s
->area
]
4454 && s
->hl
== DRAW_NORMAL_TEXT
4455 && ((s
->area
== TEXT_AREA
&& s
->row
->fill_line_p
)
4456 || s
->face
->background
!= default_face
->background
4457 || s
->face
->stipple
!= default_face
->stipple
))
4458 s
->extends_to_end_of_line_p
= 1;
4460 /* If S extends its face to the end of the line, set its
4461 background_width to the distance to the right edge of the drawing
4463 if (s
->extends_to_end_of_line_p
)
4464 s
->background_width
= last_x
- s
->x
+ 1;
4466 s
->background_width
= s
->width
;
4470 /* Add a glyph string for a stretch glyph to the list of strings
4471 between HEAD and TAIL. START is the index of the stretch glyph in
4472 row area AREA of glyph row ROW. END is the index of the last glyph
4473 in that glyph row area. X is the current output position assigned
4474 to the new glyph string constructed. HL overrides that face of the
4475 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4476 is the right-most x-position of the drawing area. */
4478 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
4479 and below -- keep them on one line. */
4480 #define BUILD_STRETCH_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4483 s = (struct glyph_string *) alloca (sizeof *s); \
4484 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4485 START = x_fill_stretch_glyph_string (s, ROW, AREA, START, END); \
4486 x_append_glyph_string (&HEAD, &TAIL, s); \
4492 /* Add a glyph string for an image glyph to the list of strings
4493 between HEAD and TAIL. START is the index of the image glyph in
4494 row area AREA of glyph row ROW. END is the index of the last glyph
4495 in that glyph row area. X is the current output position assigned
4496 to the new glyph string constructed. HL overrides that face of the
4497 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
4498 is the right-most x-position of the drawing area. */
4500 #define BUILD_IMAGE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X) \
4503 s = (struct glyph_string *) alloca (sizeof *s); \
4504 x_init_glyph_string (s, NULL, W, ROW, AREA, START, HL); \
4505 x_fill_image_glyph_string (s); \
4506 x_append_glyph_string (&HEAD, &TAIL, s); \
4513 /* Add a glyph string for a sequence of character glyphs to the list
4514 of strings between HEAD and TAIL. START is the index of the first
4515 glyph in row area AREA of glyph row ROW that is part of the new
4516 glyph string. END is the index of the last glyph in that glyph row
4517 area. X is the current output position assigned to the new glyph
4518 string constructed. HL overrides that face of the glyph; e.g. it
4519 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
4520 right-most x-position of the drawing area. */
4522 #define BUILD_CHAR_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4528 c = (ROW)->glyphs[AREA][START].u.ch; \
4529 face_id = (ROW)->glyphs[AREA][START].face_id; \
4531 s = (struct glyph_string *) alloca (sizeof *s); \
4532 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
4533 x_init_glyph_string (s, char2b, W, ROW, AREA, START, HL); \
4534 x_append_glyph_string (&HEAD, &TAIL, s); \
4536 START = x_fill_glyph_string (s, face_id, START, END, \
4542 /* Add a glyph string for a composite sequence to the list of strings
4543 between HEAD and TAIL. START is the index of the first glyph in
4544 row area AREA of glyph row ROW that is part of the new glyph
4545 string. END is the index of the last glyph in that glyph row area.
4546 X is the current output position assigned to the new glyph string
4547 constructed. HL overrides that face of the glyph; e.g. it is
4548 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
4549 x-position of the drawing area. */
4551 #define BUILD_COMPOSITE_GLYPH_STRING(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4553 int cmp_id = (ROW)->glyphs[AREA][START].u.cmp_id; \
4554 int face_id = (ROW)->glyphs[AREA][START].face_id; \
4555 struct face *base_face = FACE_FROM_ID (XFRAME (w->frame), face_id); \
4556 struct composition *cmp = composition_table[cmp_id]; \
4557 int glyph_len = cmp->glyph_len; \
4559 struct face **faces; \
4560 struct glyph_string *first_s = NULL; \
4563 base_face = base_face->ascii_face; \
4564 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
4565 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
4566 /* At first, fill in `char2b' and `faces'. */ \
4567 for (n = 0; n < glyph_len; n++) \
4569 int c = COMPOSITION_GLYPH (cmp, n); \
4570 int this_face_id = FACE_FOR_CHAR (XFRAME (w->frame), base_face, c); \
4571 faces[n] = FACE_FROM_ID (XFRAME (w->frame), this_face_id); \
4572 x_get_char_face_and_encoding (XFRAME (w->frame), c, \
4573 this_face_id, char2b + n, 1); \
4576 /* Make glyph_strings for each glyph sequence that is drawable by \
4577 the same face, and append them to HEAD/TAIL. */ \
4578 for (n = 0; n < cmp->glyph_len;) \
4580 s = (struct glyph_string *) alloca (sizeof *s); \
4581 x_init_glyph_string (s, char2b + n, W, ROW, AREA, START, HL); \
4582 x_append_glyph_string (&(HEAD), &(TAIL), s); \
4590 n = x_fill_composite_glyph_string (s, faces, OVERLAPS_P); \
4598 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
4599 of AREA of glyph row ROW on window W between indices START and END.
4600 HL overrides the face for drawing glyph strings, e.g. it is
4601 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
4602 x-positions of the drawing area.
4604 This is an ugly monster macro construct because we must use alloca
4605 to allocate glyph strings (because x_draw_glyphs can be called
4608 #define BUILD_GLYPH_STRINGS(W, ROW, AREA, START, END, HEAD, TAIL, HL, X, LAST_X, OVERLAPS_P) \
4611 HEAD = TAIL = NULL; \
4612 while (START < END) \
4614 struct glyph *first_glyph = (ROW)->glyphs[AREA] + START; \
4615 switch (first_glyph->type) \
4618 BUILD_CHAR_GLYPH_STRINGS (W, ROW, AREA, START, END, HEAD, \
4619 TAIL, HL, X, LAST_X, \
4623 case COMPOSITE_GLYPH: \
4624 BUILD_COMPOSITE_GLYPH_STRING (W, ROW, AREA, START, END, \
4625 HEAD, TAIL, HL, X, LAST_X,\
4629 case STRETCH_GLYPH: \
4630 BUILD_STRETCH_GLYPH_STRING (W, ROW, AREA, START, END, \
4631 HEAD, TAIL, HL, X, LAST_X); \
4635 BUILD_IMAGE_GLYPH_STRING (W, ROW, AREA, START, END, HEAD, \
4636 TAIL, HL, X, LAST_X); \
4643 x_set_glyph_string_background_width (s, START, LAST_X); \
4650 /* Draw glyphs between START and END in AREA of ROW on window W,
4651 starting at x-position X. X is relative to AREA in W. HL is a
4652 face-override with the following meaning:
4654 DRAW_NORMAL_TEXT draw normally
4655 DRAW_CURSOR draw in cursor face
4656 DRAW_MOUSE_FACE draw in mouse face.
4657 DRAW_INVERSE_VIDEO draw in mode line face
4658 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
4659 DRAW_IMAGE_RAISED draw an image with a raised relief around it
4661 If REAL_START is non-null, return in *REAL_START the real starting
4662 position for display. This can be different from START in case
4663 overlapping glyphs must be displayed. If REAL_END is non-null,
4664 return in *REAL_END the real end position for display. This can be
4665 different from END in case overlapping glyphs must be displayed.
4667 If OVERLAPS_P is non-zero, draw only the foreground of characters
4668 and clip to the physical height of ROW.
4670 Value is the x-position reached, relative to AREA of W. */
4673 x_draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, real_start
, real_end
,
4677 struct glyph_row
*row
;
4678 enum glyph_row_area area
;
4680 enum draw_glyphs_face hl
;
4681 int *real_start
, *real_end
;
4684 struct glyph_string
*head
, *tail
;
4685 struct glyph_string
*s
;
4686 int last_x
, area_width
;
4690 /* Let's rather be paranoid than getting a SEGV. */
4691 end
= min (end
, row
->used
[area
]);
4692 start
= max (0, start
);
4693 start
= min (end
, start
);
4695 *real_start
= start
;
4699 /* Translate X to frame coordinates. Set last_x to the right
4700 end of the drawing area. */
4701 if (row
->full_width_p
)
4703 /* X is relative to the left edge of W, without scroll bars
4705 struct frame
*f
= XFRAME (w
->frame
);
4706 /* int width = FRAME_FLAGS_AREA_WIDTH (f); */
4707 int window_left_x
= WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
);
4710 area_width
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
4711 last_x
= window_left_x
+ area_width
;
4713 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
4715 int width
= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
4716 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
4722 x
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
4723 last_x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
4727 x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, x
);
4728 area_width
= window_box_width (w
, area
);
4729 last_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, area
, area_width
);
4732 /* Build a doubly-linked list of glyph_string structures between
4733 head and tail from what we have to draw. Note that the macro
4734 BUILD_GLYPH_STRINGS will modify its start parameter. That's
4735 the reason we use a separate variable `i'. */
4737 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, end
, head
, tail
, hl
, x
, last_x
,
4740 x_reached
= tail
->x
+ tail
->background_width
;
4744 /* If there are any glyphs with lbearing < 0 or rbearing > width in
4745 the row, redraw some glyphs in front or following the glyph
4746 strings built above. */
4747 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
4750 struct glyph_string
*h
, *t
;
4752 /* Compute overhangs for all glyph strings. */
4753 for (s
= head
; s
; s
= s
->next
)
4754 x_compute_glyph_string_overhangs (s
);
4756 /* Prepend glyph strings for glyphs in front of the first glyph
4757 string that are overwritten because of the first glyph
4758 string's left overhang. The background of all strings
4759 prepended must be drawn because the first glyph string
4761 i
= x_left_overwritten (head
);
4765 BUILD_GLYPH_STRINGS (w
, row
, area
, j
, start
, h
, t
,
4766 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4770 *real_start
= start
;
4771 x_compute_overhangs_and_x (t
, head
->x
, 1);
4772 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4775 /* Prepend glyph strings for glyphs in front of the first glyph
4776 string that overwrite that glyph string because of their
4777 right overhang. For these strings, only the foreground must
4778 be drawn, because it draws over the glyph string at `head'.
4779 The background must not be drawn because this would overwrite
4780 right overhangs of preceding glyphs for which no glyph
4782 i
= x_left_overwriting (head
);
4785 BUILD_GLYPH_STRINGS (w
, row
, area
, i
, start
, h
, t
,
4786 DRAW_NORMAL_TEXT
, dummy_x
, last_x
,
4788 for (s
= h
; s
; s
= s
->next
)
4789 s
->background_filled_p
= 1;
4792 x_compute_overhangs_and_x (t
, head
->x
, 1);
4793 x_prepend_glyph_string_lists (&head
, &tail
, h
, t
);
4796 /* Append glyphs strings for glyphs following the last glyph
4797 string tail that are overwritten by tail. The background of
4798 these strings has to be drawn because tail's foreground draws
4800 i
= x_right_overwritten (tail
);
4803 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4804 DRAW_NORMAL_TEXT
, x
, last_x
,
4806 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4807 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
4812 /* Append glyph strings for glyphs following the last glyph
4813 string tail that overwrite tail. The foreground of such
4814 glyphs has to be drawn because it writes into the background
4815 of tail. The background must not be drawn because it could
4816 paint over the foreground of following glyphs. */
4817 i
= x_right_overwriting (tail
);
4820 BUILD_GLYPH_STRINGS (w
, row
, area
, end
, i
, h
, t
,
4821 DRAW_NORMAL_TEXT
, x
, last_x
,
4823 for (s
= h
; s
; s
= s
->next
)
4824 s
->background_filled_p
= 1;
4825 x_compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
4826 x_append_glyph_string_lists (&head
, &tail
, h
, t
);
4832 /* Draw all strings. */
4833 for (s
= head
; s
; s
= s
->next
)
4834 x_draw_glyph_string (s
);
4836 /* Value is the x-position up to which drawn, relative to AREA of W.
4837 This doesn't include parts drawn because of overhangs. */
4838 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
4839 if (!row
->full_width_p
)
4841 if (area
> LEFT_MARGIN_AREA
)
4842 x_reached
-= window_box_width (w
, LEFT_MARGIN_AREA
);
4843 if (area
> TEXT_AREA
)
4844 x_reached
-= window_box_width (w
, TEXT_AREA
);
4851 /* Fix the display of area AREA of overlapping row ROW in window W. */
4854 x_fix_overlapping_area (w
, row
, area
)
4856 struct glyph_row
*row
;
4857 enum glyph_row_area area
;
4863 if (area
== LEFT_MARGIN_AREA
)
4865 else if (area
== TEXT_AREA
)
4866 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
4868 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
4869 + window_box_width (w
, TEXT_AREA
));
4871 for (i
= 0; i
< row
->used
[area
];)
4873 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
4875 int start
= i
, start_x
= x
;
4879 x
+= row
->glyphs
[area
][i
].pixel_width
;
4882 while (i
< row
->used
[area
]
4883 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
4885 x_draw_glyphs (w
, start_x
, row
, area
, start
, i
,
4887 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
4892 x
+= row
->glyphs
[area
][i
].pixel_width
;
4901 /* Output LEN glyphs starting at START at the nominal cursor position.
4902 Advance the nominal cursor over the text. The global variable
4903 updated_window contains the window being updated, updated_row is
4904 the glyph row being updated, and updated_area is the area of that
4905 row being updated. */
4908 x_write_glyphs (start
, len
)
4909 struct glyph
*start
;
4912 int x
, hpos
, real_start
, real_end
;
4914 xassert (updated_window
&& updated_row
);
4919 hpos
= start
- updated_row
->glyphs
[updated_area
];
4920 x
= x_draw_glyphs (updated_window
, output_cursor
.x
,
4921 updated_row
, updated_area
,
4923 (updated_row
->inverse_p
4924 ? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
),
4925 &real_start
, &real_end
, 0);
4927 /* If we drew over the cursor, note that it is not visible any more. */
4928 note_overwritten_text_cursor (updated_window
, real_start
,
4929 real_end
- real_start
);
4933 /* Advance the output cursor. */
4934 output_cursor
.hpos
+= len
;
4935 output_cursor
.x
= x
;
4939 /* Insert LEN glyphs from START at the nominal cursor position. */
4942 x_insert_glyphs (start
, len
)
4943 struct glyph
*start
;
4948 int line_height
, shift_by_width
, shifted_region_width
;
4949 struct glyph_row
*row
;
4950 struct glyph
*glyph
;
4951 int frame_x
, frame_y
, hpos
, real_start
, real_end
;
4953 xassert (updated_window
&& updated_row
);
4956 f
= XFRAME (WINDOW_FRAME (w
));
4958 /* Get the height of the line we are in. */
4960 line_height
= row
->height
;
4962 /* Get the width of the glyphs to insert. */
4964 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
4965 shift_by_width
+= glyph
->pixel_width
;
4967 /* Get the width of the region to shift right. */
4968 shifted_region_width
= (window_box_width (w
, updated_area
)
4973 frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, output_cursor
.x
);
4974 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
4975 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
4976 f
->output_data
.x
->normal_gc
,
4978 shifted_region_width
, line_height
,
4979 frame_x
+ shift_by_width
, frame_y
);
4981 /* Write the glyphs. */
4982 hpos
= start
- row
->glyphs
[updated_area
];
4983 x_draw_glyphs (w
, output_cursor
.x
, row
, updated_area
, hpos
, hpos
+ len
,
4984 DRAW_NORMAL_TEXT
, &real_start
, &real_end
, 0);
4985 note_overwritten_text_cursor (w
, real_start
, real_end
- real_start
);
4987 /* Advance the output cursor. */
4988 output_cursor
.hpos
+= len
;
4989 output_cursor
.x
+= shift_by_width
;
4994 /* Delete N glyphs at the nominal cursor position. Not implemented
5005 /* Erase the current text line from the nominal cursor position
5006 (inclusive) to pixel column TO_X (exclusive). The idea is that
5007 everything from TO_X onward is already erased.
5009 TO_X is a pixel position relative to updated_area of
5010 updated_window. TO_X == -1 means clear to the end of this area. */
5013 x_clear_end_of_line (to_x
)
5017 struct window
*w
= updated_window
;
5018 int max_x
, min_y
, max_y
;
5019 int from_x
, from_y
, to_y
;
5021 xassert (updated_window
&& updated_row
);
5022 f
= XFRAME (w
->frame
);
5024 if (updated_row
->full_width_p
)
5026 max_x
= XFASTINT (w
->width
) * CANON_X_UNIT (f
);
5027 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
5028 && !w
->pseudo_window_p
)
5029 max_x
+= FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
);
5032 max_x
= window_box_width (w
, updated_area
);
5033 max_y
= window_text_bottom_y (w
);
5035 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
5036 of window. For TO_X > 0, truncate to end of drawing area. */
5042 to_x
= min (to_x
, max_x
);
5044 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
5046 /* Notice if the cursor will be cleared by this operation. */
5047 if (!updated_row
->full_width_p
)
5048 note_overwritten_text_cursor (w
, output_cursor
.hpos
, -1);
5050 from_x
= output_cursor
.x
;
5052 /* Translate to frame coordinates. */
5053 if (updated_row
->full_width_p
)
5055 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
5056 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
5060 from_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, from_x
);
5061 to_x
= WINDOW_AREA_TO_FRAME_PIXEL_X (w
, updated_area
, to_x
);
5064 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
5065 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
5066 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
5068 /* Prevent inadvertently clearing to end of the X window. */
5069 if (to_x
> from_x
&& to_y
> from_y
)
5072 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5073 from_x
, from_y
, to_x
- from_x
, to_y
- from_y
,
5080 /* Clear entire frame. If updating_frame is non-null, clear that
5081 frame. Otherwise clear the selected frame. */
5091 f
= SELECTED_FRAME ();
5093 /* Clearing the frame will erase any cursor, so mark them all as no
5095 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5096 output_cursor
.hpos
= output_cursor
.vpos
= 0;
5097 output_cursor
.x
= -1;
5099 /* We don't set the output cursor here because there will always
5100 follow an explicit cursor_to. */
5102 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5104 /* We have to clear the scroll bars, too. If we have changed
5105 colors or something like that, then they should be notified. */
5106 x_scroll_bar_clear (f
);
5108 XFlush (FRAME_X_DISPLAY (f
));
5114 /* Invert the middle quarter of the frame for .15 sec. */
5116 /* We use the select system call to do the waiting, so we have to make
5117 sure it's available. If it isn't, we just won't do visual bells. */
5119 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5122 /* Subtract the `struct timeval' values X and Y, storing the result in
5123 *RESULT. Return 1 if the difference is negative, otherwise 0. */
5126 timeval_subtract (result
, x
, y
)
5127 struct timeval
*result
, x
, y
;
5129 /* Perform the carry for the later subtraction by updating y. This
5130 is safer because on some systems the tv_sec member is unsigned. */
5131 if (x
.tv_usec
< y
.tv_usec
)
5133 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
5134 y
.tv_usec
-= 1000000 * nsec
;
5138 if (x
.tv_usec
- y
.tv_usec
> 1000000)
5140 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
5141 y
.tv_usec
+= 1000000 * nsec
;
5145 /* Compute the time remaining to wait. tv_usec is certainly
5147 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
5148 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
5150 /* Return indication of whether the result should be considered
5152 return x
.tv_sec
< y
.tv_sec
;
5164 /* Create a GC that will use the GXxor function to flip foreground
5165 pixels into background pixels. */
5169 values
.function
= GXxor
;
5170 values
.foreground
= (f
->output_data
.x
->foreground_pixel
5171 ^ f
->output_data
.x
->background_pixel
);
5173 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5174 GCFunction
| GCForeground
, &values
);
5178 /* Get the height not including a menu bar widget. */
5179 int height
= CHAR_TO_PIXEL_HEIGHT (f
, FRAME_HEIGHT (f
));
5180 /* Height of each line to flash. */
5181 int flash_height
= FRAME_LINE_HEIGHT (f
);
5182 /* These will be the left and right margins of the rectangles. */
5183 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
5184 int flash_right
= PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
5188 /* Don't flash the area between a scroll bar and the frame
5189 edge it is next to. */
5190 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
5192 case vertical_scroll_bar_left
:
5193 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5196 case vertical_scroll_bar_right
:
5197 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5204 width
= flash_right
- flash_left
;
5206 /* If window is tall, flash top and bottom line. */
5207 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5209 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5211 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5212 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5213 width
, flash_height
);
5214 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5216 (height
- flash_height
5217 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5218 width
, flash_height
);
5221 /* If it is short, flash it all. */
5222 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5223 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5224 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5229 struct timeval wakeup
;
5231 EMACS_GET_TIME (wakeup
);
5233 /* Compute time to wait until, propagating carry from usecs. */
5234 wakeup
.tv_usec
+= 150000;
5235 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
5236 wakeup
.tv_usec
%= 1000000;
5238 /* Keep waiting until past the time wakeup. */
5241 struct timeval timeout
;
5243 EMACS_GET_TIME (timeout
);
5245 /* In effect, timeout = wakeup - timeout.
5246 Break if result would be negative. */
5247 if (timeval_subtract (&timeout
, wakeup
, timeout
))
5250 /* Try to wait that long--but we might wake up sooner. */
5251 select (0, NULL
, NULL
, NULL
, &timeout
);
5255 /* If window is tall, flash top and bottom line. */
5256 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
5258 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5260 (FRAME_INTERNAL_BORDER_WIDTH (f
)
5261 + FRAME_TOOL_BAR_LINES (f
) * CANON_Y_UNIT (f
)),
5262 width
, flash_height
);
5263 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5265 (height
- flash_height
5266 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
5267 width
, flash_height
);
5270 /* If it is short, flash it all. */
5271 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
5272 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
5273 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
5275 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
5283 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
5286 /* Make audible bell. */
5291 struct frame
*f
= SELECTED_FRAME ();
5293 if (FRAME_X_DISPLAY (f
))
5295 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
5302 XBell (FRAME_X_DISPLAY (f
), 0);
5303 XFlush (FRAME_X_DISPLAY (f
));
5310 /* Specify how many text lines, from the top of the window,
5311 should be affected by insert-lines and delete-lines operations.
5312 This, and those operations, are used only within an update
5313 that is bounded by calls to x_update_begin and x_update_end. */
5316 XTset_terminal_window (n
)
5319 /* This function intentionally left blank. */
5324 /***********************************************************************
5326 ***********************************************************************/
5328 /* Perform an insert-lines or delete-lines operation, inserting N
5329 lines or deleting -N lines at vertical position VPOS. */
5332 x_ins_del_lines (vpos
, n
)
5339 /* Scroll part of the display as described by RUN. */
5342 x_scroll_run (w
, run
)
5346 struct frame
*f
= XFRAME (w
->frame
);
5347 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
5349 /* Get frame-relative bounding box of the text display area of W,
5350 without mode lines. Include in this box the flags areas to the
5351 left and right of W. */
5352 window_box (w
, -1, &x
, &y
, &width
, &height
);
5353 width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
5354 x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
5356 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
5357 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
5358 bottom_y
= y
+ height
;
5362 /* Scrolling up. Make sure we don't copy part of the mode
5363 line at the bottom. */
5364 if (from_y
+ run
->height
> bottom_y
)
5365 height
= bottom_y
- from_y
;
5367 height
= run
->height
;
5371 /* Scolling down. Make sure we don't copy over the mode line.
5373 if (to_y
+ run
->height
> bottom_y
)
5374 height
= bottom_y
- to_y
;
5376 height
= run
->height
;
5381 /* Cursor off. Will be switched on again in x_update_window_end. */
5385 XCopyArea (FRAME_X_DISPLAY (f
),
5386 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
5387 f
->output_data
.x
->normal_gc
,
5397 /***********************************************************************
5399 ***********************************************************************/
5401 /* Redisplay an exposed area of frame F. X and Y are the upper-left
5402 corner of the exposed rectangle. W and H are width and height of
5403 the exposed area. All are pixel values. W or H zero means redraw
5404 the entire frame. */
5407 expose_frame (f
, x
, y
, w
, h
)
5413 TRACE ((stderr
, "expose_frame "));
5415 /* No need to redraw if frame will be redrawn soon. */
5416 if (FRAME_GARBAGED_P (f
))
5418 TRACE ((stderr
, " garbaged\n"));
5422 /* If basic faces haven't been realized yet, there is no point in
5423 trying to redraw anything. This can happen when we get an expose
5424 event while Emacs is starting, e.g. by moving another window. */
5425 if (FRAME_FACE_CACHE (f
) == NULL
5426 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
5428 TRACE ((stderr
, " no faces\n"));
5432 if (w
== 0 || h
== 0)
5435 r
.width
= CANON_X_UNIT (f
) * f
->width
;
5436 r
.height
= CANON_Y_UNIT (f
) * f
->height
;
5446 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
5447 expose_window_tree (XWINDOW (f
->root_window
), &r
);
5449 if (WINDOWP (f
->tool_bar_window
))
5451 struct window
*w
= XWINDOW (f
->tool_bar_window
);
5452 XRectangle window_rect
;
5453 XRectangle intersection_rect
;
5454 int window_x
, window_y
, window_width
, window_height
;
5457 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5458 window_rect
.x
= window_x
;
5459 window_rect
.y
= window_y
;
5460 window_rect
.width
= window_width
;
5461 window_rect
.height
= window_height
;
5463 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5464 expose_window (w
, &intersection_rect
);
5467 #ifndef USE_X_TOOLKIT
5468 if (WINDOWP (f
->menu_bar_window
))
5470 struct window
*w
= XWINDOW (f
->menu_bar_window
);
5471 XRectangle window_rect
;
5472 XRectangle intersection_rect
;
5473 int window_x
, window_y
, window_width
, window_height
;
5476 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
5477 window_rect
.x
= window_x
;
5478 window_rect
.y
= window_y
;
5479 window_rect
.width
= window_width
;
5480 window_rect
.height
= window_height
;
5482 if (x_intersect_rectangles (&r
, &window_rect
, &intersection_rect
))
5483 expose_window (w
, &intersection_rect
);
5485 #endif /* not USE_X_TOOLKIT */
5489 /* Redraw (parts) of all windows in the window tree rooted at W that
5490 intersect R. R contains frame pixel coordinates. */
5493 expose_window_tree (w
, r
)
5499 if (!NILP (w
->hchild
))
5500 expose_window_tree (XWINDOW (w
->hchild
), r
);
5501 else if (!NILP (w
->vchild
))
5502 expose_window_tree (XWINDOW (w
->vchild
), r
);
5505 XRectangle window_rect
;
5506 XRectangle intersection_rect
;
5507 struct frame
*f
= XFRAME (w
->frame
);
5508 int window_x
, window_y
, window_width
, window_height
;
5510 /* Frame-relative pixel rectangle of W. */
5511 window_box (w
, -1, &window_x
, &window_y
, &window_width
,
5515 - FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
)
5516 - FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5517 window_rect
.y
= window_y
;
5520 + FRAME_X_FLAGS_AREA_WIDTH (f
)
5521 + FRAME_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
));
5523 = window_height
+ CURRENT_MODE_LINE_HEIGHT (w
);
5525 if (x_intersect_rectangles (r
, &window_rect
, &intersection_rect
))
5526 expose_window (w
, &intersection_rect
);
5529 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5534 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
5535 which intersects rectangle R. R is in window-relative coordinates. */
5538 expose_area (w
, row
, r
, area
)
5540 struct glyph_row
*row
;
5542 enum glyph_row_area area
;
5545 struct glyph
*first
= row
->glyphs
[area
];
5546 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
5550 /* Set x to the window-relative start position for drawing glyphs of
5551 AREA. The first glyph of the text area can be partially visible.
5552 The first glyphs of other areas cannot. */
5553 if (area
== LEFT_MARGIN_AREA
)
5555 else if (area
== TEXT_AREA
)
5556 x
= row
->x
+ window_box_width (w
, LEFT_MARGIN_AREA
);
5558 x
= (window_box_width (w
, LEFT_MARGIN_AREA
)
5559 + window_box_width (w
, TEXT_AREA
));
5561 if (area
== TEXT_AREA
&& row
->fill_line_p
)
5562 /* If row extends face to end of line write the whole line. */
5563 x_draw_glyphs (w
, x
, row
, area
,
5565 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5569 /* Find the first glyph that must be redrawn. */
5571 && x
+ first
->pixel_width
< r
->x
)
5573 x
+= first
->pixel_width
;
5577 /* Find the last one. */
5581 && x
< r
->x
+ r
->width
)
5583 x
+= last
->pixel_width
;
5589 x_draw_glyphs (w
, first_x
, row
, area
,
5590 first
- row
->glyphs
[area
],
5591 last
- row
->glyphs
[area
],
5592 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5598 /* Redraw the parts of the glyph row ROW on window W intersecting
5599 rectangle R. R is in window-relative coordinates. */
5602 expose_line (w
, row
, r
)
5604 struct glyph_row
*row
;
5607 xassert (row
->enabled_p
);
5609 if (row
->mode_line_p
|| w
->pseudo_window_p
)
5610 x_draw_glyphs (w
, 0, row
, TEXT_AREA
, 0, row
->used
[TEXT_AREA
],
5611 row
->inverse_p
? DRAW_INVERSE_VIDEO
: DRAW_NORMAL_TEXT
,
5615 if (row
->used
[LEFT_MARGIN_AREA
])
5616 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
5617 if (row
->used
[TEXT_AREA
])
5618 expose_area (w
, row
, r
, TEXT_AREA
);
5619 if (row
->used
[RIGHT_MARGIN_AREA
])
5620 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
5621 x_draw_row_bitmaps (w
, row
);
5626 /* Return non-zero if W's cursor intersects rectangle R. */
5629 x_phys_cursor_in_rect_p (w
, r
)
5633 XRectangle cr
, result
;
5634 struct glyph
*cursor_glyph
;
5636 cursor_glyph
= get_phys_cursor_glyph (w
);
5639 cr
.x
= w
->phys_cursor
.x
;
5640 cr
.y
= w
->phys_cursor
.y
;
5641 cr
.width
= cursor_glyph
->pixel_width
;
5642 cr
.height
= w
->phys_cursor_height
;
5643 return x_intersect_rectangles (&cr
, r
, &result
);
5650 /* Redraw a rectangle of window W. R is a rectangle in window
5651 relative coordinates. Call this function with input blocked. */
5654 expose_window (w
, r
)
5658 struct glyph_row
*row
;
5660 int yb
= window_text_bottom_y (w
);
5661 int cursor_cleared_p
;
5663 /* If window is not yet fully initialized, do nothing. This can
5664 happen when toolkit scroll bars are used and a window is split.
5665 Reconfiguring the scroll bar will generate an expose for a newly
5667 if (w
->current_matrix
== NULL
)
5670 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
5671 r
->x
, r
->y
, r
->width
, r
->height
));
5673 /* Convert to window coordinates. */
5674 r
->x
= FRAME_TO_WINDOW_PIXEL_X (w
, r
->x
);
5675 r
->y
= FRAME_TO_WINDOW_PIXEL_Y (w
, r
->y
);
5677 /* Turn off the cursor. */
5678 if (!w
->pseudo_window_p
5679 && x_phys_cursor_in_rect_p (w
, r
))
5682 cursor_cleared_p
= 1;
5685 cursor_cleared_p
= 0;
5687 /* Find the first row intersecting the rectangle R. */
5688 row
= w
->current_matrix
->rows
;
5690 while (row
->enabled_p
5692 && y
+ row
->height
< r
->y
)
5698 /* Display the text in the rectangle, one text line at a time. */
5699 while (row
->enabled_p
5701 && y
< r
->y
+ r
->height
)
5703 expose_line (w
, row
, r
);
5708 /* Display the mode line if there is one. */
5709 if (WINDOW_WANTS_MODELINE_P (w
)
5710 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
5712 && row
->y
< r
->y
+ r
->height
)
5713 expose_line (w
, row
, r
);
5715 if (!w
->pseudo_window_p
)
5717 /* Draw border between windows. */
5718 x_draw_vertical_border (w
);
5720 /* Turn the cursor on again. */
5721 if (cursor_cleared_p
)
5722 x_update_window_cursor (w
, 1);
5727 /* Determine the intersection of two rectangles R1 and R2. Return
5728 the intersection in *RESULT. Value is non-zero if RESULT is not
5732 x_intersect_rectangles (r1
, r2
, result
)
5733 XRectangle
*r1
, *r2
, *result
;
5735 XRectangle
*left
, *right
;
5736 XRectangle
*upper
, *lower
;
5737 int intersection_p
= 0;
5739 /* Rearrange so that R1 is the left-most rectangle. */
5741 left
= r1
, right
= r2
;
5743 left
= r2
, right
= r1
;
5745 /* X0 of the intersection is right.x0, if this is inside R1,
5746 otherwise there is no intersection. */
5747 if (right
->x
<= left
->x
+ left
->width
)
5749 result
->x
= right
->x
;
5751 /* The right end of the intersection is the minimum of the
5752 the right ends of left and right. */
5753 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
5756 /* Same game for Y. */
5758 upper
= r1
, lower
= r2
;
5760 upper
= r2
, lower
= r1
;
5762 /* The upper end of the intersection is lower.y0, if this is inside
5763 of upper. Otherwise, there is no intersection. */
5764 if (lower
->y
<= upper
->y
+ upper
->height
)
5766 result
->y
= lower
->y
;
5768 /* The lower end of the intersection is the minimum of the lower
5769 ends of upper and lower. */
5770 result
->height
= (min (lower
->y
+ lower
->height
,
5771 upper
->y
+ upper
->height
)
5777 return intersection_p
;
5788 /* We used to only do this if Vx_no_window_manager was non-nil, but
5789 the ICCCM (section 4.1.6) says that the window's border pixmap
5790 and border pixel are window attributes which are "private to the
5791 client", so we can always change it to whatever we want. */
5793 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5794 f
->output_data
.x
->border_pixel
);
5796 x_update_cursor (f
, 1);
5800 frame_unhighlight (f
)
5803 /* We used to only do this if Vx_no_window_manager was non-nil, but
5804 the ICCCM (section 4.1.6) says that the window's border pixmap
5805 and border pixel are window attributes which are "private to the
5806 client", so we can always change it to whatever we want. */
5808 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5809 f
->output_data
.x
->border_tile
);
5811 x_update_cursor (f
, 1);
5814 /* The focus has changed. Update the frames as necessary to reflect
5815 the new situation. Note that we can't change the selected frame
5816 here, because the Lisp code we are interrupting might become confused.
5817 Each event gets marked with the frame in which it occurred, so the
5818 Lisp code can tell when the switch took place by examining the events. */
5821 x_new_focus_frame (dpyinfo
, frame
)
5822 struct x_display_info
*dpyinfo
;
5823 struct frame
*frame
;
5825 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
5827 if (frame
!= dpyinfo
->x_focus_frame
)
5829 /* Set this before calling other routines, so that they see
5830 the correct value of x_focus_frame. */
5831 dpyinfo
->x_focus_frame
= frame
;
5833 if (old_focus
&& old_focus
->auto_lower
)
5834 x_lower_frame (old_focus
);
5837 selected_frame
= frame
;
5838 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
5840 Fselect_window (selected_frame
->selected_window
);
5841 choose_minibuf_frame ();
5844 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
5845 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
5847 pending_autoraise_frame
= 0;
5850 x_frame_rehighlight (dpyinfo
);
5853 /* Handle an event saying the mouse has moved out of an Emacs frame. */
5856 x_mouse_leave (dpyinfo
)
5857 struct x_display_info
*dpyinfo
;
5859 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
5862 /* The focus has changed, or we have redirected a frame's focus to
5863 another frame (this happens when a frame uses a surrogate
5864 mini-buffer frame). Shift the highlight as appropriate.
5866 The FRAME argument doesn't necessarily have anything to do with which
5867 frame is being highlighted or un-highlighted; we only use it to find
5868 the appropriate X display info. */
5871 XTframe_rehighlight (frame
)
5872 struct frame
*frame
;
5874 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
5878 x_frame_rehighlight (dpyinfo
)
5879 struct x_display_info
*dpyinfo
;
5881 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
5883 if (dpyinfo
->x_focus_frame
)
5885 dpyinfo
->x_highlight_frame
5886 = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
5887 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
5888 : dpyinfo
->x_focus_frame
);
5889 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
5891 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
5892 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
5896 dpyinfo
->x_highlight_frame
= 0;
5898 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
5901 frame_unhighlight (old_highlight
);
5902 if (dpyinfo
->x_highlight_frame
)
5903 frame_highlight (dpyinfo
->x_highlight_frame
);
5909 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
5911 /* Initialize mode_switch_bit and modifier_meaning. */
5913 x_find_modifier_meanings (dpyinfo
)
5914 struct x_display_info
*dpyinfo
;
5916 int min_code
, max_code
;
5919 XModifierKeymap
*mods
;
5921 dpyinfo
->meta_mod_mask
= 0;
5922 dpyinfo
->shift_lock_mask
= 0;
5923 dpyinfo
->alt_mod_mask
= 0;
5924 dpyinfo
->super_mod_mask
= 0;
5925 dpyinfo
->hyper_mod_mask
= 0;
5928 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
5930 min_code
= dpyinfo
->display
->min_keycode
;
5931 max_code
= dpyinfo
->display
->max_keycode
;
5934 syms
= XGetKeyboardMapping (dpyinfo
->display
,
5935 min_code
, max_code
- min_code
+ 1,
5937 mods
= XGetModifierMapping (dpyinfo
->display
);
5939 /* Scan the modifier table to see which modifier bits the Meta and
5940 Alt keysyms are on. */
5942 int row
, col
; /* The row and column in the modifier table. */
5944 for (row
= 3; row
< 8; row
++)
5945 for (col
= 0; col
< mods
->max_keypermod
; col
++)
5948 = mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
5950 /* Zeroes are used for filler. Skip them. */
5954 /* Are any of this keycode's keysyms a meta key? */
5958 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
5960 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
5966 dpyinfo
->meta_mod_mask
|= (1 << row
);
5971 dpyinfo
->alt_mod_mask
|= (1 << row
);
5976 dpyinfo
->hyper_mod_mask
|= (1 << row
);
5981 dpyinfo
->super_mod_mask
|= (1 << row
);
5985 /* Ignore this if it's not on the lock modifier. */
5986 if ((1 << row
) == LockMask
)
5987 dpyinfo
->shift_lock_mask
= LockMask
;
5995 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
5996 if (! dpyinfo
->meta_mod_mask
)
5998 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
5999 dpyinfo
->alt_mod_mask
= 0;
6002 /* If some keys are both alt and meta,
6003 make them just meta, not alt. */
6004 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
6006 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
6009 XFree ((char *) syms
);
6010 XFreeModifiermap (mods
);
6013 /* Convert between the modifier bits X uses and the modifier bits
6017 x_x_to_emacs_modifiers (dpyinfo
, state
)
6018 struct x_display_info
*dpyinfo
;
6021 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
6022 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
6023 | ((state
& dpyinfo
->meta_mod_mask
) ? meta_modifier
: 0)
6024 | ((state
& dpyinfo
->alt_mod_mask
) ? alt_modifier
: 0)
6025 | ((state
& dpyinfo
->super_mod_mask
) ? super_modifier
: 0)
6026 | ((state
& dpyinfo
->hyper_mod_mask
) ? hyper_modifier
: 0));
6030 x_emacs_to_x_modifiers (dpyinfo
, state
)
6031 struct x_display_info
*dpyinfo
;
6034 return ( ((state
& alt_modifier
) ? dpyinfo
->alt_mod_mask
: 0)
6035 | ((state
& super_modifier
) ? dpyinfo
->super_mod_mask
: 0)
6036 | ((state
& hyper_modifier
) ? dpyinfo
->hyper_mod_mask
: 0)
6037 | ((state
& shift_modifier
) ? ShiftMask
: 0)
6038 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
6039 | ((state
& meta_modifier
) ? dpyinfo
->meta_mod_mask
: 0));
6042 /* Convert a keysym to its name. */
6045 x_get_keysym_name (keysym
)
6051 value
= XKeysymToString (keysym
);
6059 /* Mouse clicks and mouse movement. Rah. */
6061 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
6062 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
6063 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
6064 not force the value into range. */
6067 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
6069 register int pix_x
, pix_y
;
6070 register int *x
, *y
;
6074 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
6075 even for negative values. */
6077 pix_x
-= FONT_WIDTH ((f
)->output_data
.x
->font
) - 1;
6079 pix_y
-= (f
)->output_data
.x
->line_height
- 1;
6081 pix_x
= PIXEL_TO_CHAR_COL (f
, pix_x
);
6082 pix_y
= PIXEL_TO_CHAR_ROW (f
, pix_y
);
6086 bounds
->width
= FONT_WIDTH (f
->output_data
.x
->font
);
6087 bounds
->height
= f
->output_data
.x
->line_height
;
6088 bounds
->x
= CHAR_TO_PIXEL_COL (f
, pix_x
);
6089 bounds
->y
= CHAR_TO_PIXEL_ROW (f
, pix_y
);
6096 else if (pix_x
> FRAME_WINDOW_WIDTH (f
))
6097 pix_x
= FRAME_WINDOW_WIDTH (f
);
6101 else if (pix_y
> f
->height
)
6110 /* Given HPOS/VPOS in the current matrix of W, return corresponding
6111 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
6112 can't tell the positions because W's display is not up to date,
6116 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
6119 int *frame_x
, *frame_y
;
6123 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
6124 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
6126 if (display_completed
)
6128 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6129 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
6130 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
6136 *frame_x
+= glyph
->pixel_width
;
6144 *frame_y
= *frame_x
= 0;
6148 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, *frame_y
);
6149 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, *frame_x
);
6154 /* Prepare a mouse-event in *RESULT for placement in the input queue.
6156 If the event is a button press, then note that we have grabbed
6160 construct_mouse_click (result
, event
, f
)
6161 struct input_event
*result
;
6162 XButtonEvent
*event
;
6165 /* Make the event type no_event; we'll change that when we decide
6167 result
->kind
= mouse_click
;
6168 result
->code
= event
->button
- Button1
;
6169 result
->timestamp
= event
->time
;
6170 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6172 | (event
->type
== ButtonRelease
6176 XSETINT (result
->x
, event
->x
);
6177 XSETINT (result
->y
, event
->y
);
6178 XSETFRAME (result
->frame_or_window
, f
);
6184 /* Function to report a mouse movement to the mainstream Emacs code.
6185 The input handler calls this.
6187 We have received a mouse movement event, which is given in *event.
6188 If the mouse is over a different glyph than it was last time, tell
6189 the mainstream emacs code by setting mouse_moved. If not, ask for
6190 another motion event, so we can check again the next time it moves. */
6192 static XMotionEvent last_mouse_motion_event
;
6193 static Lisp_Object last_mouse_motion_frame
;
6196 note_mouse_movement (frame
, event
)
6198 XMotionEvent
*event
;
6200 last_mouse_movement_time
= event
->time
;
6201 last_mouse_motion_event
= *event
;
6202 XSETFRAME (last_mouse_motion_frame
, frame
);
6204 if (event
->window
!= FRAME_X_WINDOW (frame
))
6206 frame
->mouse_moved
= 1;
6207 last_mouse_scroll_bar
= Qnil
;
6208 note_mouse_highlight (frame
, -1, -1);
6211 /* Has the mouse moved off the glyph it was on at the last sighting? */
6212 else if (event
->x
< last_mouse_glyph
.x
6213 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
6214 || event
->y
< last_mouse_glyph
.y
6215 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
6217 frame
->mouse_moved
= 1;
6218 last_mouse_scroll_bar
= Qnil
;
6219 note_mouse_highlight (frame
, event
->x
, event
->y
);
6223 /* This is used for debugging, to turn off note_mouse_highlight. */
6225 int disable_mouse_highlight
;
6229 /************************************************************************
6231 ************************************************************************/
6233 /* Find the glyph under window-relative coordinates X/Y in window W.
6234 Consider only glyphs from buffer text, i.e. no glyphs from overlay
6235 strings. Return in *HPOS and *VPOS the row and column number of
6236 the glyph found. Return in *AREA the glyph area containing X.
6237 Value is a pointer to the glyph found or null if X/Y is not on
6238 text, or we can't tell because W's current matrix is not up to
6241 static struct glyph
*
6242 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, area
)
6245 int *hpos
, *vpos
, *area
;
6247 struct glyph
*glyph
, *end
;
6248 struct glyph_row
*row
= NULL
;
6249 int x0
, i
, left_area_width
;
6251 /* Find row containing Y. Give up if some row is not enabled. */
6252 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
6254 row
= MATRIX_ROW (w
->current_matrix
, i
);
6255 if (!row
->enabled_p
)
6257 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
6264 /* Give up if Y is not in the window. */
6265 if (i
== w
->current_matrix
->nrows
)
6268 /* Get the glyph area containing X. */
6269 if (w
->pseudo_window_p
)
6276 left_area_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
6277 if (x
< left_area_width
)
6279 *area
= LEFT_MARGIN_AREA
;
6282 else if (x
< left_area_width
+ window_box_width (w
, TEXT_AREA
))
6285 x0
= row
->x
+ left_area_width
;
6289 *area
= RIGHT_MARGIN_AREA
;
6290 x0
= left_area_width
+ window_box_width (w
, TEXT_AREA
);
6294 /* Find glyph containing X. */
6295 glyph
= row
->glyphs
[*area
];
6296 end
= glyph
+ row
->used
[*area
];
6299 if (x
< x0
+ glyph
->pixel_width
)
6301 if (w
->pseudo_window_p
)
6303 else if (BUFFERP (glyph
->object
))
6307 x0
+= glyph
->pixel_width
;
6314 *hpos
= glyph
- row
->glyphs
[*area
];
6319 /* Convert frame-relative x/y to coordinates relative to window W.
6320 Takes pseudo-windows into account. */
6323 frame_to_window_pixel_xy (w
, x
, y
)
6327 if (w
->pseudo_window_p
)
6329 /* A pseudo-window is always full-width, and starts at the
6330 left edge of the frame, plus a frame border. */
6331 struct frame
*f
= XFRAME (w
->frame
);
6332 *x
-= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
6333 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6337 *x
= FRAME_TO_WINDOW_PIXEL_X (w
, *x
);
6338 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
6343 /* Take proper action when mouse has moved to the mode or top line of
6344 window W, x-position X. MODE_LINE_P non-zero means mouse is on the
6345 mode line. X is relative to the start of the text display area of
6346 W, so the width of bitmap areas and scroll bars must be subtracted
6347 to get a position relative to the start of the mode line. */
6350 note_mode_line_highlight (w
, x
, mode_line_p
)
6354 struct frame
*f
= XFRAME (w
->frame
);
6355 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6356 Cursor cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
6357 struct glyph_row
*row
;
6360 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
6362 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
6366 struct glyph
*glyph
, *end
;
6367 Lisp_Object help
, map
;
6370 /* Find the glyph under X. */
6371 glyph
= row
->glyphs
[TEXT_AREA
];
6372 end
= glyph
+ row
->used
[TEXT_AREA
];
6373 x0
= - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
) * CANON_X_UNIT (f
)
6374 + FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
));
6376 && x
>= x0
+ glyph
->pixel_width
)
6378 x0
+= glyph
->pixel_width
;
6383 && STRINGP (glyph
->object
)
6384 && XSTRING (glyph
->object
)->intervals
6385 && glyph
->charpos
>= 0
6386 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6388 /* If we're on a string with `help-echo' text property,
6389 arrange for the help to be displayed. This is done by
6390 setting the global variable help_echo to the help string. */
6391 help
= Fget_text_property (make_number (glyph
->charpos
),
6392 Qhelp_echo
, glyph
->object
);
6396 XSETWINDOW (help_echo_window
, w
);
6397 help_echo_object
= glyph
->object
;
6398 help_echo_pos
= glyph
->charpos
;
6401 /* Change the mouse pointer according to what is under X/Y. */
6402 map
= Fget_text_property (make_number (glyph
->charpos
),
6403 Qlocal_map
, glyph
->object
);
6404 if (!NILP (Fkeymapp (map
)))
6405 cursor
= f
->output_data
.x
->nontext_cursor
;
6408 map
= Fget_text_property (make_number (glyph
->charpos
),
6409 Qkeymap
, glyph
->object
);
6410 if (!NILP (Fkeymapp (map
)))
6411 cursor
= f
->output_data
.x
->nontext_cursor
;
6416 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
6420 /* Take proper action when the mouse has moved to position X, Y on
6421 frame F as regards highlighting characters that have mouse-face
6422 properties. Also de-highlighting chars where the mouse was before.
6423 X and Y can be negative or out of range. */
6426 note_mouse_highlight (f
, x
, y
)
6430 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6435 /* When a menu is active, don't highlight because this looks odd. */
6436 #ifdef USE_X_TOOLKIT
6437 if (popup_activated ())
6441 if (disable_mouse_highlight
6442 || !f
->glyphs_initialized_p
)
6445 dpyinfo
->mouse_face_mouse_x
= x
;
6446 dpyinfo
->mouse_face_mouse_y
= y
;
6447 dpyinfo
->mouse_face_mouse_frame
= f
;
6449 if (dpyinfo
->mouse_face_defer
)
6454 dpyinfo
->mouse_face_deferred_gc
= 1;
6458 /* Which window is that in? */
6459 window
= window_from_coordinates (f
, x
, y
, &portion
, 1);
6461 /* If we were displaying active text in another window, clear that. */
6462 if (! EQ (window
, dpyinfo
->mouse_face_window
))
6463 clear_mouse_face (dpyinfo
);
6465 /* Not on a window -> return. */
6466 if (!WINDOWP (window
))
6469 /* Convert to window-relative pixel coordinates. */
6470 w
= XWINDOW (window
);
6471 frame_to_window_pixel_xy (w
, &x
, &y
);
6473 /* Handle tool-bar window differently since it doesn't display a
6475 if (EQ (window
, f
->tool_bar_window
))
6477 note_tool_bar_highlight (f
, x
, y
);
6481 if (portion
== 1 || portion
== 3)
6483 /* Mouse is on the mode or top line. */
6484 note_mode_line_highlight (w
, x
, portion
== 1);
6488 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6489 f
->output_data
.x
->text_cursor
);
6491 /* Are we in a window whose display is up to date?
6492 And verify the buffer's text has not changed. */
6493 if (/* Within text portion of the window. */
6495 && EQ (w
->window_end_valid
, w
->buffer
)
6496 && XFASTINT (w
->last_modified
) == BUF_MODIFF (XBUFFER (w
->buffer
))
6497 && (XFASTINT (w
->last_overlay_modified
)
6498 == BUF_OVERLAY_MODIFF (XBUFFER (w
->buffer
))))
6500 int hpos
, vpos
, pos
, i
, area
;
6501 struct glyph
*glyph
;
6503 /* Find the glyph under X/Y. */
6504 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &area
);
6506 /* Clear mouse face if X/Y not over text. */
6508 || area
!= TEXT_AREA
6509 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
6511 clear_mouse_face (dpyinfo
);
6515 pos
= glyph
->charpos
;
6516 xassert (w
->pseudo_window_p
|| BUFFERP (glyph
->object
));
6518 /* Check for mouse-face and help-echo. */
6520 Lisp_Object mouse_face
, overlay
, position
;
6521 Lisp_Object
*overlay_vec
;
6523 struct buffer
*obuf
;
6526 /* If we get an out-of-range value, return now; avoid an error. */
6527 if (pos
> BUF_Z (XBUFFER (w
->buffer
)))
6530 /* Make the window's buffer temporarily current for
6531 overlays_at and compute_char_face. */
6532 obuf
= current_buffer
;
6533 current_buffer
= XBUFFER (w
->buffer
);
6539 /* Is this char mouse-active or does it have help-echo? */
6540 XSETINT (position
, pos
);
6542 /* Put all the overlays we want in a vector in overlay_vec.
6543 Store the length in len. If there are more than 10, make
6544 enough space for all, and try again. */
6546 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6547 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
, 0);
6548 if (noverlays
> len
)
6551 overlay_vec
= (Lisp_Object
*) alloca (len
* sizeof (Lisp_Object
));
6552 noverlays
= overlays_at (pos
, 0, &overlay_vec
, &len
, NULL
, NULL
,0);
6555 /* Sort overlays into increasing priority order. */
6556 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
6558 /* Check mouse-face highlighting. */
6559 if (! (EQ (window
, dpyinfo
->mouse_face_window
)
6560 && vpos
>= dpyinfo
->mouse_face_beg_row
6561 && vpos
<= dpyinfo
->mouse_face_end_row
6562 && (vpos
> dpyinfo
->mouse_face_beg_row
6563 || hpos
>= dpyinfo
->mouse_face_beg_col
)
6564 && (vpos
< dpyinfo
->mouse_face_end_row
6565 || hpos
< dpyinfo
->mouse_face_end_col
6566 || dpyinfo
->mouse_face_past_end
)))
6568 /* Clear the display of the old active region, if any. */
6569 clear_mouse_face (dpyinfo
);
6571 /* Find the highest priority overlay that has a mouse-face prop. */
6573 for (i
= noverlays
- 1; i
>= 0; --i
)
6575 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
6576 if (!NILP (mouse_face
))
6578 overlay
= overlay_vec
[i
];
6583 /* If no overlay applies, get a text property. */
6585 mouse_face
= Fget_text_property (position
, Qmouse_face
, w
->buffer
);
6587 /* Handle the overlay case. */
6588 if (! NILP (overlay
))
6590 /* Find the range of text around this char that
6591 should be active. */
6592 Lisp_Object before
, after
;
6595 before
= Foverlay_start (overlay
);
6596 after
= Foverlay_end (overlay
);
6597 /* Record this as the current active region. */
6598 fast_find_position (w
, XFASTINT (before
),
6599 &dpyinfo
->mouse_face_beg_col
,
6600 &dpyinfo
->mouse_face_beg_row
,
6601 &dpyinfo
->mouse_face_beg_x
,
6602 &dpyinfo
->mouse_face_beg_y
);
6603 dpyinfo
->mouse_face_past_end
6604 = !fast_find_position (w
, XFASTINT (after
),
6605 &dpyinfo
->mouse_face_end_col
,
6606 &dpyinfo
->mouse_face_end_row
,
6607 &dpyinfo
->mouse_face_end_x
,
6608 &dpyinfo
->mouse_face_end_y
);
6609 dpyinfo
->mouse_face_window
= window
;
6610 dpyinfo
->mouse_face_face_id
6611 = face_at_buffer_position (w
, pos
, 0, 0,
6612 &ignore
, pos
+ 1, 1);
6614 /* Display it as active. */
6615 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6617 /* Handle the text property case. */
6618 else if (! NILP (mouse_face
))
6620 /* Find the range of text around this char that
6621 should be active. */
6622 Lisp_Object before
, after
, beginning
, end
;
6625 beginning
= Fmarker_position (w
->start
);
6626 XSETINT (end
, (BUF_Z (XBUFFER (w
->buffer
))
6627 - XFASTINT (w
->window_end_pos
)));
6629 = Fprevious_single_property_change (make_number (pos
+ 1),
6631 w
->buffer
, beginning
);
6633 = Fnext_single_property_change (position
, Qmouse_face
,
6635 /* Record this as the current active region. */
6636 fast_find_position (w
, XFASTINT (before
),
6637 &dpyinfo
->mouse_face_beg_col
,
6638 &dpyinfo
->mouse_face_beg_row
,
6639 &dpyinfo
->mouse_face_beg_x
,
6640 &dpyinfo
->mouse_face_beg_y
);
6641 dpyinfo
->mouse_face_past_end
6642 = !fast_find_position (w
, XFASTINT (after
),
6643 &dpyinfo
->mouse_face_end_col
,
6644 &dpyinfo
->mouse_face_end_row
,
6645 &dpyinfo
->mouse_face_end_x
,
6646 &dpyinfo
->mouse_face_end_y
);
6647 dpyinfo
->mouse_face_window
= window
;
6648 dpyinfo
->mouse_face_face_id
6649 = face_at_buffer_position (w
, pos
, 0, 0,
6650 &ignore
, pos
+ 1, 1);
6652 /* Display it as active. */
6653 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
6657 /* Look for a `help-echo' property. */
6659 Lisp_Object help
, overlay
;
6661 /* Check overlays first. */
6662 help
= overlay
= Qnil
;
6663 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
6665 overlay
= overlay_vec
[i
];
6666 help
= Foverlay_get (overlay
, Qhelp_echo
);
6672 help_echo_window
= window
;
6673 help_echo_object
= overlay
;
6674 help_echo_pos
= pos
;
6678 /* Try text properties. */
6679 if ((STRINGP (glyph
->object
)
6680 && glyph
->charpos
>= 0
6681 && glyph
->charpos
< XSTRING (glyph
->object
)->size
)
6682 || (BUFFERP (glyph
->object
)
6683 && glyph
->charpos
>= BEGV
6684 && glyph
->charpos
< ZV
))
6685 help
= Fget_text_property (make_number (glyph
->charpos
),
6686 Qhelp_echo
, glyph
->object
);
6691 help_echo_window
= window
;
6692 help_echo_object
= glyph
->object
;
6693 help_echo_pos
= glyph
->charpos
;
6700 current_buffer
= obuf
;
6706 redo_mouse_highlight ()
6708 if (!NILP (last_mouse_motion_frame
)
6709 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
6710 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
6711 last_mouse_motion_event
.x
,
6712 last_mouse_motion_event
.y
);
6717 /***********************************************************************
6719 ***********************************************************************/
6721 static int x_tool_bar_item
P_ ((struct frame
*, int, int,
6722 struct glyph
**, int *, int *, int *));
6724 /* Tool-bar item index of the item on which a mouse button was pressed
6727 static int last_tool_bar_item
;
6730 /* Get information about the tool-bar item at position X/Y on frame F.
6731 Return in *GLYPH a pointer to the glyph of the tool-bar item in
6732 the current matrix of the tool-bar window of F, or NULL if not
6733 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
6734 item in F->current_tool_bar_items. Value is
6736 -1 if X/Y is not on a tool-bar item
6737 0 if X/Y is on the same item that was highlighted before.
6741 x_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
6744 struct glyph
**glyph
;
6745 int *hpos
, *vpos
, *prop_idx
;
6747 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6748 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6751 /* Find the glyph under X/Y. */
6752 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, &area
);
6756 /* Get the start of this tool-bar item's properties in
6757 f->current_tool_bar_items. */
6758 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
6761 /* Is mouse on the highlighted item? */
6762 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
6763 && *vpos
>= dpyinfo
->mouse_face_beg_row
6764 && *vpos
<= dpyinfo
->mouse_face_end_row
6765 && (*vpos
> dpyinfo
->mouse_face_beg_row
6766 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
6767 && (*vpos
< dpyinfo
->mouse_face_end_row
6768 || *hpos
< dpyinfo
->mouse_face_end_col
6769 || dpyinfo
->mouse_face_past_end
))
6776 /* Handle mouse button event on the tool-bar of frame F, at
6777 frame-relative coordinates X/Y. EVENT_TYPE is either ButtionPress
6781 x_handle_tool_bar_click (f
, button_event
)
6783 XButtonEvent
*button_event
;
6785 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6786 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6787 int hpos
, vpos
, prop_idx
;
6788 struct glyph
*glyph
;
6789 Lisp_Object enabled_p
;
6790 int x
= button_event
->x
;
6791 int y
= button_event
->y
;
6793 /* If not on the highlighted tool-bar item, return. */
6794 frame_to_window_pixel_xy (w
, &x
, &y
);
6795 if (x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
6798 /* If item is disabled, do nothing. */
6799 enabled_p
= (XVECTOR (f
->current_tool_bar_items
)
6800 ->contents
[prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
]);
6801 if (NILP (enabled_p
))
6804 if (button_event
->type
== ButtonPress
)
6806 /* Show item in pressed state. */
6807 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
6808 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
6809 last_tool_bar_item
= prop_idx
;
6813 Lisp_Object key
, frame
;
6814 struct input_event event
;
6816 /* Show item in released state. */
6817 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
6818 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
6820 key
= (XVECTOR (f
->current_tool_bar_items
)
6821 ->contents
[prop_idx
+ TOOL_BAR_ITEM_KEY
]);
6823 XSETFRAME (frame
, f
);
6824 event
.kind
= TOOL_BAR_EVENT
;
6825 event
.frame_or_window
= frame
;
6827 kbd_buffer_store_event (&event
);
6829 event
.kind
= TOOL_BAR_EVENT
;
6830 event
.frame_or_window
= frame
;
6832 event
.modifiers
= x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
6833 button_event
->state
);
6834 kbd_buffer_store_event (&event
);
6835 last_tool_bar_item
= -1;
6840 /* Possibly highlight a tool-bar item on frame F when mouse moves to
6841 tool-bar window-relative coordinates X/Y. Called from
6842 note_mouse_highlight. */
6845 note_tool_bar_highlight (f
, x
, y
)
6849 Lisp_Object window
= f
->tool_bar_window
;
6850 struct window
*w
= XWINDOW (window
);
6851 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
6853 struct glyph
*glyph
;
6854 struct glyph_row
*row
;
6856 Lisp_Object enabled_p
;
6858 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
6859 int mouse_down_p
, rc
;
6861 /* Function note_mouse_highlight is called with negative x(y
6862 values when mouse moves outside of the frame. */
6863 if (x
<= 0 || y
<= 0)
6865 clear_mouse_face (dpyinfo
);
6869 rc
= x_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
6872 /* Not on tool-bar item. */
6873 clear_mouse_face (dpyinfo
);
6877 /* On same tool-bar item as before. */
6880 clear_mouse_face (dpyinfo
);
6882 /* Mouse is down, but on different tool-bar item? */
6883 mouse_down_p
= (dpyinfo
->grabbed
6884 && f
== last_mouse_frame
6885 && FRAME_LIVE_P (f
));
6887 && last_tool_bar_item
!= prop_idx
)
6890 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
6891 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
6893 /* If tool-bar item is not enabled, don't highlight it. */
6894 enabled_p
= (XVECTOR (f
->current_tool_bar_items
)
6895 ->contents
[prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
]);
6896 if (!NILP (enabled_p
))
6898 /* Compute the x-position of the glyph. In front and past the
6899 image is a space. We include this is the highlighted area. */
6900 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
6901 for (i
= x
= 0; i
< hpos
; ++i
)
6902 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
6904 /* Record this as the current active region. */
6905 dpyinfo
->mouse_face_beg_col
= hpos
;
6906 dpyinfo
->mouse_face_beg_row
= vpos
;
6907 dpyinfo
->mouse_face_beg_x
= x
;
6908 dpyinfo
->mouse_face_beg_y
= row
->y
;
6909 dpyinfo
->mouse_face_past_end
= 0;
6911 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
6912 dpyinfo
->mouse_face_end_row
= vpos
;
6913 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
6914 dpyinfo
->mouse_face_end_y
= row
->y
;
6915 dpyinfo
->mouse_face_window
= window
;
6916 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
6918 /* Display it as active. */
6919 show_mouse_face (dpyinfo
, draw
);
6920 dpyinfo
->mouse_face_image_state
= draw
;
6925 /* Set help_echo to a help string.to display for this tool-bar item.
6926 XTread_socket does the rest. */
6927 help_echo_object
= help_echo_window
= Qnil
;
6929 help_echo
= (XVECTOR (f
->current_tool_bar_items
)
6930 ->contents
[prop_idx
+ TOOL_BAR_ITEM_HELP
]);
6931 if (NILP (help_echo
))
6932 help_echo
= (XVECTOR (f
->current_tool_bar_items
)
6933 ->contents
[prop_idx
+ TOOL_BAR_ITEM_CAPTION
]);
6938 /* Find the glyph matrix position of buffer position POS in window W.
6939 *HPOS, *VPOS, *X, and *Y are set to the positions found. W's
6940 current glyphs must be up to date. If POS is above window start
6941 return (0, 0, 0, 0). If POS is after end of W, return end of
6945 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
)
6948 int *hpos
, *vpos
, *x
, *y
;
6952 int maybe_next_line_p
= 0;
6953 int line_start_position
;
6954 int yb
= window_text_bottom_y (w
);
6955 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, 0);
6956 struct glyph_row
*best_row
= row
;
6957 int row_vpos
= 0, best_row_vpos
= 0;
6962 if (row
->used
[TEXT_AREA
])
6963 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
6965 line_start_position
= 0;
6967 if (line_start_position
> pos
)
6969 /* If the position sought is the end of the buffer,
6970 don't include the blank lines at the bottom of the window. */
6971 else if (line_start_position
== pos
6972 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
6974 maybe_next_line_p
= 1;
6977 else if (line_start_position
> 0)
6980 best_row_vpos
= row_vpos
;
6983 if (row
->y
+ row
->height
>= yb
)
6990 /* Find the right column within BEST_ROW. */
6992 current_x
= best_row
->x
;
6993 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
6995 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
6998 charpos
= glyph
->charpos
;
7002 *vpos
= best_row_vpos
;
7007 else if (charpos
> pos
)
7009 else if (charpos
> 0)
7012 current_x
+= glyph
->pixel_width
;
7015 /* If we're looking for the end of the buffer,
7016 and we didn't find it in the line we scanned,
7017 use the start of the following line. */
7018 if (maybe_next_line_p
)
7023 current_x
= best_row
->x
;
7026 *vpos
= best_row_vpos
;
7027 *hpos
= lastcol
+ 1;
7034 /* Display the active region described by mouse_face_*
7035 in its mouse-face if HL > 0, in its normal face if HL = 0. */
7038 show_mouse_face (dpyinfo
, draw
)
7039 struct x_display_info
*dpyinfo
;
7040 enum draw_glyphs_face draw
;
7042 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
7043 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7045 int cursor_off_p
= 0;
7046 struct cursor_pos saved_cursor
;
7048 saved_cursor
= output_cursor
;
7050 /* If window is in the process of being destroyed, don't bother
7052 if (w
->current_matrix
== NULL
)
7055 /* Recognize when we are called to operate on rows that don't exist
7056 anymore. This can happen when a window is split. */
7057 if (dpyinfo
->mouse_face_end_row
>= w
->current_matrix
->nrows
)
7060 set_output_cursor (&w
->phys_cursor
);
7062 /* Note that mouse_face_beg_row etc. are window relative. */
7063 for (i
= dpyinfo
->mouse_face_beg_row
;
7064 i
<= dpyinfo
->mouse_face_end_row
;
7067 int start_hpos
, end_hpos
, start_x
;
7068 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, i
);
7070 /* Don't do anything if row doesn't have valid contents. */
7071 if (!row
->enabled_p
)
7074 /* For all but the first row, the highlight starts at column 0. */
7075 if (i
== dpyinfo
->mouse_face_beg_row
)
7077 start_hpos
= dpyinfo
->mouse_face_beg_col
;
7078 start_x
= dpyinfo
->mouse_face_beg_x
;
7086 if (i
== dpyinfo
->mouse_face_end_row
)
7087 end_hpos
= dpyinfo
->mouse_face_end_col
;
7089 end_hpos
= row
->used
[TEXT_AREA
];
7091 /* If the cursor's in the text we are about to rewrite, turn the
7093 if (!w
->pseudo_window_p
7094 && i
== output_cursor
.vpos
7095 && output_cursor
.hpos
>= start_hpos
- 1
7096 && output_cursor
.hpos
<= end_hpos
)
7098 x_update_window_cursor (w
, 0);
7102 if (end_hpos
> start_hpos
)
7104 row
->mouse_face_p
= draw
== DRAW_MOUSE_FACE
;
7105 x_draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
7106 start_hpos
, end_hpos
, draw
, NULL
, NULL
, 0);
7110 /* If we turned the cursor off, turn it back on. */
7112 x_display_cursor (w
, 1,
7113 output_cursor
.hpos
, output_cursor
.vpos
,
7114 output_cursor
.x
, output_cursor
.y
);
7116 output_cursor
= saved_cursor
;
7120 /* Change the mouse cursor. */
7121 if (draw
== DRAW_NORMAL_TEXT
)
7122 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7123 f
->output_data
.x
->text_cursor
);
7124 else if (draw
== DRAW_MOUSE_FACE
)
7125 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7126 f
->output_data
.x
->cross_cursor
);
7128 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7129 f
->output_data
.x
->nontext_cursor
);
7132 /* Clear out the mouse-highlighted active region.
7133 Redraw it un-highlighted first. */
7136 clear_mouse_face (dpyinfo
)
7137 struct x_display_info
*dpyinfo
;
7142 if (! NILP (dpyinfo
->mouse_face_window
))
7143 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
7145 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7146 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7147 dpyinfo
->mouse_face_window
= Qnil
;
7151 /* Clear any mouse-face on window W. This function is part of the
7152 redisplay interface, and is called from try_window_id and similar
7153 functions to ensure the mouse-highlight is off. */
7156 x_clear_mouse_face (w
)
7159 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
7163 XSETWINDOW (window
, w
);
7164 if (EQ (window
, dpyinfo
->mouse_face_window
))
7165 clear_mouse_face (dpyinfo
);
7170 /* Just discard the mouse face information for frame F, if any.
7171 This is used when the size of F is changed. */
7174 cancel_mouse_face (f
)
7178 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7180 window
= dpyinfo
->mouse_face_window
;
7181 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
7183 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
7184 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
7185 dpyinfo
->mouse_face_window
= Qnil
;
7189 static struct scroll_bar
*x_window_to_scroll_bar ();
7190 static void x_scroll_bar_report_motion ();
7192 /* Return the current position of the mouse.
7193 *fp should be a frame which indicates which display to ask about.
7195 If the mouse movement started in a scroll bar, set *fp, *bar_window,
7196 and *part to the frame, window, and scroll bar part that the mouse
7197 is over. Set *x and *y to the portion and whole of the mouse's
7198 position on the scroll bar.
7200 If the mouse movement started elsewhere, set *fp to the frame the
7201 mouse is on, *bar_window to nil, and *x and *y to the character cell
7204 Set *time to the server time-stamp for the time at which the mouse
7205 was at this position.
7207 Don't store anything if we don't have a valid set of values to report.
7209 This clears the mouse_moved flag, so we can wait for the next mouse
7213 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
7216 Lisp_Object
*bar_window
;
7217 enum scroll_bar_part
*part
;
7219 unsigned long *time
;
7225 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
7226 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
7232 Window dummy_window
;
7235 Lisp_Object frame
, tail
;
7237 /* Clear the mouse-moved flag for every frame on this display. */
7238 FOR_EACH_FRAME (tail
, frame
)
7239 if (FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
7240 XFRAME (frame
)->mouse_moved
= 0;
7242 last_mouse_scroll_bar
= Qnil
;
7244 /* Figure out which root window we're on. */
7245 XQueryPointer (FRAME_X_DISPLAY (*fp
),
7246 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
7248 /* The root window which contains the pointer. */
7251 /* Trash which we can't trust if the pointer is on
7252 a different screen. */
7255 /* The position on that root window. */
7258 /* More trash we can't trust. */
7261 /* Modifier keys and pointer buttons, about which
7263 (unsigned int *) &dummy
);
7265 /* Now we have a position on the root; find the innermost window
7266 containing the pointer. */
7270 int parent_x
= 0, parent_y
= 0;
7275 /* XTranslateCoordinates can get errors if the window
7276 structure is changing at the same time this function
7277 is running. So at least we must not crash from them. */
7279 count
= x_catch_errors (FRAME_X_DISPLAY (*fp
));
7281 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
7282 && FRAME_LIVE_P (last_mouse_frame
))
7284 /* If mouse was grabbed on a frame, give coords for that frame
7285 even if the mouse is now outside it. */
7286 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7288 /* From-window, to-window. */
7289 root
, FRAME_X_WINDOW (last_mouse_frame
),
7291 /* From-position, to-position. */
7292 root_x
, root_y
, &win_x
, &win_y
,
7296 f1
= last_mouse_frame
;
7302 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
7304 /* From-window, to-window. */
7307 /* From-position, to-position. */
7308 root_x
, root_y
, &win_x
, &win_y
,
7313 if (child
== None
|| child
== win
)
7321 /* Now we know that:
7322 win is the innermost window containing the pointer
7323 (XTC says it has no child containing the pointer),
7324 win_x and win_y are the pointer's position in it
7325 (XTC did this the last time through), and
7326 parent_x and parent_y are the pointer's position in win's parent.
7327 (They are what win_x and win_y were when win was child.
7328 If win is the root window, it has no parent, and
7329 parent_{x,y} are invalid, but that's okay, because we'll
7330 never use them in that case.) */
7332 /* Is win one of our frames? */
7333 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
7336 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
7339 x_uncatch_errors (FRAME_X_DISPLAY (*fp
), count
);
7341 /* If not, is it one of our scroll bars? */
7344 struct scroll_bar
*bar
= x_window_to_scroll_bar (win
);
7348 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7354 if (f1
== 0 && insist
> 0)
7355 f1
= SELECTED_FRAME ();
7359 /* Ok, we found a frame. Store all the values.
7360 last_mouse_glyph is a rectangle used to reduce the
7361 generation of mouse events. To not miss any motion
7362 events, we must divide the frame into rectangles of the
7363 size of the smallest character that could be displayed
7364 on it, i.e. into the same rectangles that matrices on
7365 the frame are divided into. */
7367 #if OLD_REDISPLAY_CODE
7368 int ignore1
, ignore2
;
7369 pixel_to_glyph_coords (f1
, win_x
, win_y
, &ignore1
, &ignore2
,
7371 FRAME_X_DISPLAY_INFO (f1
)->grabbed
7375 int width
= FRAME_SMALLEST_CHAR_WIDTH (f1
);
7376 int height
= FRAME_SMALLEST_FONT_HEIGHT (f1
);
7380 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to
7381 round down even for negative values. */
7387 last_mouse_glyph
.width
= width
;
7388 last_mouse_glyph
.height
= height
;
7389 last_mouse_glyph
.x
= (x
+ width
- 1) / width
* width
;
7390 last_mouse_glyph
.y
= (y
+ height
- 1) / height
* height
;
7397 XSETINT (*x
, win_x
);
7398 XSETINT (*y
, win_y
);
7399 *time
= last_mouse_movement_time
;
7408 #ifdef USE_X_TOOLKIT
7410 /* Atimer callback function for TIMER. Called every 0.1s to process
7411 Xt timeouts, if needed. We must avoid calling XtAppPending as
7412 much as possible because that function does an implicit XFlush
7413 that slows us down. */
7416 x_process_timeouts (timer
)
7417 struct atimer
*timer
;
7419 if (toolkit_scroll_bar_interaction
|| popup_activated_flag
)
7422 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
7423 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
7428 #endif /* USE_X_TOOLKIT */
7431 /* Scroll bar support. */
7433 /* Given an X window ID, find the struct scroll_bar which manages it.
7434 This can be called in GC, so we have to make sure to strip off mark
7437 static struct scroll_bar
*
7438 x_window_to_scroll_bar (window_id
)
7443 for (tail
= Vframe_list
;
7444 XGCTYPE (tail
) == Lisp_Cons
;
7447 Lisp_Object frame
, bar
, condemned
;
7449 frame
= XCAR (tail
);
7450 /* All elements of Vframe_list should be frames. */
7451 if (! GC_FRAMEP (frame
))
7454 /* Scan this frame's scroll bar list for a scroll bar with the
7456 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
7457 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
7458 /* This trick allows us to search both the ordinary and
7459 condemned scroll bar lists with one loop. */
7460 ! GC_NILP (bar
) || (bar
= condemned
,
7463 bar
= XSCROLL_BAR (bar
)->next
)
7464 if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)) == window_id
)
7465 return XSCROLL_BAR (bar
);
7473 /************************************************************************
7475 ************************************************************************/
7477 #if USE_TOOLKIT_SCROLL_BARS
7479 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
7480 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
7481 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
7482 struct scroll_bar
*));
7483 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
7487 /* Id of action hook installed for scroll bars. */
7489 static XtActionHookId action_hook_id
;
7491 /* Lisp window being scrolled. Set when starting to interact with
7492 a toolkit scroll bar, reset to nil when ending the interaction. */
7494 static Lisp_Object window_being_scrolled
;
7496 /* Last scroll bar part sent in xm_scroll_callback. */
7498 static int last_scroll_bar_part
;
7500 /* Whether this is an Xaw with arrow-scrollbars. This should imply
7501 that movements of 1/20 of the screen size are mapped to up/down. */
7503 static Boolean xaw3d_arrow_scroll
;
7505 /* Whether the drag scrolling maintains the mouse at the top of the
7506 thumb. If not, resizing the thumb needs to be done more carefully
7507 to avoid jerkyness. */
7509 static Boolean xaw3d_pick_top
;
7512 /* Action hook installed via XtAppAddActionHook when toolkit scroll
7513 bars are used.. The hook is responsible for detecting when
7514 the user ends an interaction with the scroll bar, and generates
7515 a `end-scroll' scroll_bar_click' event if so. */
7518 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
7521 XtPointer client_data
;
7525 Cardinal
*num_params
;
7531 scroll_bar_p
= XmIsScrollBar (widget
);
7532 end_action
= "Release";
7533 #else /* !USE_MOTIF i.e. use Xaw */
7534 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
7535 end_action
= "EndScroll";
7536 #endif /* USE_MOTIF */
7539 && strcmp (action_name
, end_action
) == 0
7540 && WINDOWP (window_being_scrolled
))
7544 x_send_scroll_bar_event (window_being_scrolled
,
7545 scroll_bar_end_scroll
, 0, 0);
7546 w
= XWINDOW (window_being_scrolled
);
7547 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
7548 window_being_scrolled
= Qnil
;
7549 last_scroll_bar_part
= -1;
7551 /* Xt timeouts no longer needed. */
7552 toolkit_scroll_bar_interaction
= 0;
7557 /* Send a client message with message type Xatom_Scrollbar for a
7558 scroll action to the frame of WINDOW. PART is a value identifying
7559 the part of the scroll bar that was clicked on. PORTION is the
7560 amount to scroll of a whole of WHOLE. */
7563 x_send_scroll_bar_event (window
, part
, portion
, whole
)
7565 int part
, portion
, whole
;
7568 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
7569 struct frame
*f
= XFRAME (XWINDOW (window
)->frame
);
7571 /* Construct a ClientMessage event to send to the frame. */
7572 ev
->type
= ClientMessage
;
7573 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
7574 ev
->display
= FRAME_X_DISPLAY (f
);
7575 ev
->window
= FRAME_X_WINDOW (f
);
7577 ev
->data
.l
[0] = (long) XFASTINT (window
);
7578 ev
->data
.l
[1] = (long) part
;
7579 ev
->data
.l
[2] = (long) 0;
7580 ev
->data
.l
[3] = (long) portion
;
7581 ev
->data
.l
[4] = (long) whole
;
7583 /* Make Xt timeouts work while the scroll bar is active. */
7584 toolkit_scroll_bar_interaction
= 1;
7586 /* Setting the event mask to zero means that the message will
7587 be sent to the client that created the window, and if that
7588 window no longer exists, no event will be sent. */
7590 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
7595 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
7599 x_scroll_bar_to_input_event (event
, ievent
)
7601 struct input_event
*ievent
;
7603 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
7607 XSETFASTINT (window
, ev
->data
.l
[0]);
7608 f
= XFRAME (XWINDOW (window
)->frame
);
7610 ievent
->kind
= scroll_bar_click
;
7611 ievent
->frame_or_window
= window
;
7613 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
7614 ievent
->part
= ev
->data
.l
[1];
7615 ievent
->code
= ev
->data
.l
[2];
7616 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
7617 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
7618 ievent
->modifiers
= 0;
7624 /* Minimum and maximum values used for Motif scroll bars. */
7627 #define XM_SB_MAX 10000000
7628 #define XM_SB_RANGE (XM_SB_MAX - XM_SB_MIN)
7631 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
7632 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
7633 CALL_DATA is a pointer a a XmScrollBarCallbackStruct. */
7636 xm_scroll_callback (widget
, client_data
, call_data
)
7638 XtPointer client_data
, call_data
;
7640 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7641 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
7643 int part
= -1, whole
= 0, portion
= 0;
7647 case XmCR_DECREMENT
:
7648 bar
->dragging
= Qnil
;
7649 part
= scroll_bar_up_arrow
;
7652 case XmCR_INCREMENT
:
7653 bar
->dragging
= Qnil
;
7654 part
= scroll_bar_down_arrow
;
7657 case XmCR_PAGE_DECREMENT
:
7658 bar
->dragging
= Qnil
;
7659 part
= scroll_bar_above_handle
;
7662 case XmCR_PAGE_INCREMENT
:
7663 bar
->dragging
= Qnil
;
7664 part
= scroll_bar_below_handle
;
7668 bar
->dragging
= Qnil
;
7669 part
= scroll_bar_to_top
;
7672 case XmCR_TO_BOTTOM
:
7673 bar
->dragging
= Qnil
;
7674 part
= scroll_bar_to_bottom
;
7680 int dragging_down_p
= (INTEGERP (bar
->dragging
)
7681 && XINT (bar
->dragging
) <= cs
->value
);
7683 /* Get the slider size. */
7685 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
7688 /* At the max position of the scroll bar, do a line-wise
7689 movement. Without doing anything, the LessTif scroll bar
7690 calls us with the same cs->value again and again. If we
7691 want to make sure that we can reach the end of the buffer,
7692 we have to do something.
7694 Implementation note: setting bar->dragging always to
7695 cs->value gives a smoother movement at the max position.
7696 Setting it to nil when doing line-wise movement gives
7697 a better slider behavior. */
7699 if (cs
->value
+ slider_size
== XM_SB_MAX
7701 && last_scroll_bar_part
== scroll_bar_down_arrow
))
7703 part
= scroll_bar_down_arrow
;
7704 bar
->dragging
= Qnil
;
7708 whole
= XM_SB_RANGE
;
7709 portion
= min (cs
->value
- XM_SB_MIN
, XM_SB_MAX
- slider_size
);
7710 part
= scroll_bar_handle
;
7711 bar
->dragging
= make_number (cs
->value
);
7716 case XmCR_VALUE_CHANGED
:
7722 window_being_scrolled
= bar
->window
;
7723 last_scroll_bar_part
= part
;
7724 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
7729 #else /* !USE_MOTIF, i.e. Xaw. */
7732 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
7733 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
7734 scroll bar struct. CALL_DATA is a pointer to a float saying where
7738 xaw_jump_callback (widget
, client_data
, call_data
)
7740 XtPointer client_data
, call_data
;
7742 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7743 float top
= *(float *) call_data
;
7745 int whole
, portion
, height
;
7748 /* Get the size of the thumb, a value between 0 and 1. */
7750 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
7754 portion
= shown
< 1 ? top
* whole
: 0;
7756 if (shown
< 1 && (abs (top
+ shown
- 1) < 1.0/height
))
7757 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
7758 the bottom, so we force the scrolling whenever we see that we're
7759 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
7760 we try to ensure that we always stay two pixels away from the
7762 part
= scroll_bar_down_arrow
;
7764 part
= scroll_bar_handle
;
7766 window_being_scrolled
= bar
->window
;
7767 bar
->dragging
= make_number (portion
);
7768 last_scroll_bar_part
= part
;
7769 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
7773 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
7774 i.e. line or page up or down. WIDGET is the Xaw scroll bar
7775 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
7776 the scroll bar. CALL_DATA is an integer specifying the action that
7777 has taken place. It's magnitude is in the range 0..height of the
7778 scroll bar. Negative values mean scroll towards buffer start.
7779 Values < height of scroll bar mean line-wise movement. */
7782 xaw_scroll_callback (widget
, client_data
, call_data
)
7784 XtPointer client_data
, call_data
;
7786 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
7787 int position
= (int) call_data
;
7791 /* Get the height of the scroll bar. */
7793 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
7796 if (abs (position
) >= height
)
7797 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
7799 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
7800 it maps line-movement to call_data = max(5, height/20). */
7801 else if (xaw3d_arrow_scroll
&& abs (position
) <= max (5, height
/ 20))
7802 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
7804 part
= scroll_bar_move_ratio
;
7806 window_being_scrolled
= bar
->window
;
7807 bar
->dragging
= Qnil
;
7808 last_scroll_bar_part
= part
;
7809 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
7813 #endif /* not USE_MOTIF */
7816 /* Create the widget for scroll bar BAR on frame F. Record the widget
7817 and X window of the scroll bar in BAR. */
7820 x_create_toolkit_scroll_bar (f
, bar
)
7822 struct scroll_bar
*bar
;
7828 char *scroll_bar_name
= "verticalScrollBar";
7829 unsigned long pixel
;
7834 /* LessTif 0.85, problems:
7836 1. When the mouse if over the scroll bar, the scroll bar will
7837 get keyboard events. I didn't find a way to turn this off.
7839 2. Do we have to explicitly set the cursor to get an arrow
7840 cursor (see below)? */
7842 /* Set resources. Create the widget. */
7843 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
7844 XtSetArg (av
[ac
], XmNminimum
, XM_SB_MIN
); ++ac
;
7845 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
7846 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
7847 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
7848 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
7849 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
7851 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
7854 XtSetArg (av
[ac
], XmNforeground
, pixel
);
7858 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
7861 XtSetArg (av
[ac
], XmNbackground
, pixel
);
7865 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
7866 scroll_bar_name
, av
, ac
);
7868 /* Add one callback for everything that can happen. */
7869 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
7871 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
7873 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
7875 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
7877 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
7879 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
7881 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
7884 /* Realize the widget. Only after that is the X window created. */
7885 XtRealizeWidget (widget
);
7887 /* Set the cursor to an arrow. I didn't find a resource to do that.
7888 And I'm wondering why it hasn't an arrow cursor by default. */
7889 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
7890 f
->output_data
.x
->nontext_cursor
);
7892 #else /* !USE_MOTIF i.e. use Xaw */
7894 /* Set resources. Create the widget. The background of the
7895 Xaw3d scroll bar widget is a little bit light for my taste.
7896 We don't alter it here to let users change it according
7897 to their taste with `emacs*verticalScrollBar.background: xxx'. */
7898 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
7899 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
7900 /* For smoother scrolling with Xaw3d -sm */
7901 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
7902 /* XtSetArg (av[ac], XtNbeNiceToColormap, True); ++ac; */
7904 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
7907 XtSetArg (av
[ac
], XtNforeground
, pixel
);
7911 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
7914 XtSetArg (av
[ac
], XtNbackground
, pixel
);
7918 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
7919 f
->output_data
.x
->edit_widget
, av
, ac
);
7923 char *val
= initial
;
7924 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
7925 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
7927 { /* ARROW_SCROLL */
7928 xaw3d_arrow_scroll
= True
;
7929 /* Isn't that just a personal preference ? -sm */
7930 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
7934 /* Define callbacks. */
7935 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
7936 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
7939 /* Realize the widget. Only after that is the X window created. */
7940 XtRealizeWidget (widget
);
7942 #endif /* !USE_MOTIF */
7944 /* Install an action hook that let's us detect when the user
7945 finishes interacting with a scroll bar. */
7946 if (action_hook_id
== 0)
7947 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
7949 /* Remember X window and widget in the scroll bar vector. */
7950 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
7951 xwindow
= XtWindow (widget
);
7952 SET_SCROLL_BAR_X_WINDOW (bar
, xwindow
);
7958 /* Set the thumb size and position of scroll bar BAR. We are currently
7959 displaying PORTION out of a whole WHOLE, and our position POSITION. */
7962 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
7963 struct scroll_bar
*bar
;
7964 int portion
, position
, whole
;
7967 Widget widget
= SCROLL_BAR_X_WIDGET (bar
);
7973 top
= (float) position
/ whole
;
7974 shown
= (float) portion
/ whole
;
7982 Boolean arrow1_selected
, arrow2_selected
;
7983 unsigned char flags
;
7984 XmScrollBarWidget sb
;
7986 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
7987 is the scroll bar's maximum and MIN is the scroll bar's minimum
7989 size
= shown
* XM_SB_RANGE
;
7990 size
= min (size
, XM_SB_RANGE
);
7991 size
= max (size
, 1);
7993 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
7994 value
= top
* XM_SB_RANGE
;
7995 value
= min (value
, XM_SB_MAX
- size
);
7996 value
= max (value
, XM_SB_MIN
);
7998 /* LessTif: Calling XmScrollBarSetValues after an increment or
7999 decrement turns off auto-repeat LessTif-internally. This can
8000 be seen in ScrollBar.c which resets Arrow1Selected and
8001 Arrow2Selected. It also sets internal flags so that LessTif
8002 believes the mouse is in the slider. We either have to change
8003 our code, or work around that by accessing private data. */
8005 sb
= (XmScrollBarWidget
) widget
;
8006 arrow1_selected
= sb
->scrollBar
.arrow1_selected
;
8007 arrow2_selected
= sb
->scrollBar
.arrow2_selected
;
8008 flags
= sb
->scrollBar
.flags
;
8010 if (NILP (bar
->dragging
))
8011 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
8012 else if (last_scroll_bar_part
== scroll_bar_down_arrow
)
8013 /* This has the negative side effect that the slider value is
8014 not what it would be if we scrolled here using line-wise or
8015 page-wise movement. */
8016 XmScrollBarSetValues (widget
, value
, XM_SB_RANGE
- value
, 0, 0, False
);
8019 /* If currently dragging, only update the slider size.
8020 This reduces flicker effects. */
8021 int old_value
, old_size
, increment
, page_increment
;
8023 XmScrollBarGetValues (widget
, &old_value
, &old_size
,
8024 &increment
, &page_increment
);
8025 XmScrollBarSetValues (widget
, old_value
,
8026 min (size
, XM_SB_RANGE
- old_value
),
8030 sb
->scrollBar
.arrow1_selected
= arrow1_selected
;
8031 sb
->scrollBar
.arrow2_selected
= arrow2_selected
;
8032 sb
->scrollBar
.flags
= flags
;
8034 #else /* !USE_MOTIF i.e. use Xaw */
8036 float old_top
, old_shown
;
8038 XtVaGetValues (widget
,
8039 XtNtopOfThumb
, &old_top
,
8040 XtNshown
, &old_shown
,
8044 /* Massage the top+shown values. */
8045 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
8046 top
= max (0, min (1, top
));
8049 /* Keep two pixels available for moving the thumb down. */
8050 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
8052 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
8053 check that your system's configuration file contains a define
8054 for `NARROWPROTO'. See s/freebsd.h for an example. */
8055 if (top
!= old_top
|| shown
!= old_shown
)
8057 if (NILP (bar
->dragging
))
8058 XawScrollbarSetThumb (widget
, top
, shown
);
8062 ScrollbarWidget sb
= (ScrollbarWidget
) widget
;
8063 int scroll_mode
= 0;
8065 /* `scroll_mode' only exists with Xaw3d + ARROW_SCROLLBAR. */
8066 if (xaw3d_arrow_scroll
)
8068 /* Xaw3d stupidly ignores resize requests while dragging
8069 so we have to make it believe it's not in dragging mode. */
8070 scroll_mode
= sb
->scrollbar
.scroll_mode
;
8071 if (scroll_mode
== 2)
8072 sb
->scrollbar
.scroll_mode
= 0;
8075 /* Try to make the scrolling a tad smoother. */
8076 if (!xaw3d_pick_top
)
8077 shown
= min (shown
, old_shown
);
8079 XawScrollbarSetThumb (widget
, top
, shown
);
8082 if (xaw3d_arrow_scroll
&& scroll_mode
== 2)
8083 sb
->scrollbar
.scroll_mode
= scroll_mode
;
8088 #endif /* !USE_MOTIF */
8093 #endif /* USE_TOOLKIT_SCROLL_BARS */
8097 /************************************************************************
8098 Scroll bars, general
8099 ************************************************************************/
8101 /* Create a scroll bar and return the scroll bar vector for it. W is
8102 the Emacs window on which to create the scroll bar. TOP, LEFT,
8103 WIDTH and HEIGHT are.the pixel coordinates and dimensions of the
8106 static struct scroll_bar
*
8107 x_scroll_bar_create (w
, top
, left
, width
, height
)
8109 int top
, left
, width
, height
;
8111 struct frame
*f
= XFRAME (w
->frame
);
8112 struct scroll_bar
*bar
8113 = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE
), Qnil
));
8117 #if USE_TOOLKIT_SCROLL_BARS
8118 x_create_toolkit_scroll_bar (f
, bar
);
8119 #else /* not USE_TOOLKIT_SCROLL_BARS */
8121 XSetWindowAttributes a
;
8125 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
8126 if (a
.background_pixel
== -1)
8127 a
.background_pixel
= f
->output_data
.x
->background_pixel
;
8129 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
8130 | ButtonMotionMask
| PointerMotionHintMask
8132 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
8134 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
8136 /* Clear the area of W that will serve as a scroll bar. This is
8137 for the case that a window has been split horizontally. In
8138 this case, no clear_frame is generated to reduce flickering. */
8139 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8141 window_box_height (w
), False
);
8143 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8144 /* Position and size of scroll bar. */
8145 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8147 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8149 /* Border width, depth, class, and visual. */
8156 SET_SCROLL_BAR_X_WINDOW (bar
, window
);
8158 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8160 XSETWINDOW (bar
->window
, w
);
8161 XSETINT (bar
->top
, top
);
8162 XSETINT (bar
->left
, left
);
8163 XSETINT (bar
->width
, width
);
8164 XSETINT (bar
->height
, height
);
8165 XSETINT (bar
->start
, 0);
8166 XSETINT (bar
->end
, 0);
8167 bar
->dragging
= Qnil
;
8169 /* Add bar to its frame's list of scroll bars. */
8170 bar
->next
= FRAME_SCROLL_BARS (f
);
8172 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8173 if (!NILP (bar
->next
))
8174 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8176 /* Map the window/widget. */
8177 #if USE_TOOLKIT_SCROLL_BARS
8178 XtMapWidget (SCROLL_BAR_X_WIDGET (bar
));
8179 XtConfigureWidget (SCROLL_BAR_X_WIDGET (bar
),
8180 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8182 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8184 #else /* not USE_TOOLKIT_SCROLL_BARS */
8185 XMapRaised (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
8186 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8193 /* Draw BAR's handle in the proper position.
8195 If the handle is already drawn from START to END, don't bother
8196 redrawing it, unless REBUILD is non-zero; in that case, always
8197 redraw it. (REBUILD is handy for drawing the handle after expose
8200 Normally, we want to constrain the start and end of the handle to
8201 fit inside its rectangle, but if the user is dragging the scroll
8202 bar handle, we want to let them drag it down all the way, so that
8203 the bar's top is as far down as it goes; otherwise, there's no way
8204 to move to the very end of the buffer. */
8206 #ifndef USE_TOOLKIT_SCROLL_BARS
8209 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
8210 struct scroll_bar
*bar
;
8214 int dragging
= ! NILP (bar
->dragging
);
8215 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8216 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8217 GC gc
= f
->output_data
.x
->normal_gc
;
8219 /* If the display is already accurate, do nothing. */
8221 && start
== XINT (bar
->start
)
8222 && end
== XINT (bar
->end
))
8228 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, XINT (bar
->width
));
8229 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8230 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8232 /* Make sure the values are reasonable, and try to preserve
8233 the distance between start and end. */
8235 int length
= end
- start
;
8239 else if (start
> top_range
)
8241 end
= start
+ length
;
8245 else if (end
> top_range
&& ! dragging
)
8249 /* Store the adjusted setting in the scroll bar. */
8250 XSETINT (bar
->start
, start
);
8251 XSETINT (bar
->end
, end
);
8253 /* Clip the end position, just for display. */
8254 if (end
> top_range
)
8257 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
8258 below top positions, to make sure the handle is always at least
8259 that many pixels tall. */
8260 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
8262 /* Draw the empty space above the handle. Note that we can't clear
8263 zero-height areas; that means "clear to end of window." */
8265 XClearArea (FRAME_X_DISPLAY (f
), w
,
8267 /* x, y, width, height, and exposures. */
8268 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8269 VERTICAL_SCROLL_BAR_TOP_BORDER
,
8270 inside_width
, start
,
8273 /* Change to proper foreground color if one is specified. */
8274 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8275 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8276 f
->output_data
.x
->scroll_bar_foreground_pixel
);
8278 /* Draw the handle itself. */
8279 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
8281 /* x, y, width, height */
8282 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8283 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
8284 inside_width
, end
- start
);
8286 /* Restore the foreground color of the GC if we changed it above. */
8287 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
8288 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
8289 f
->output_data
.x
->foreground_pixel
);
8291 /* Draw the empty space below the handle. Note that we can't
8292 clear zero-height areas; that means "clear to end of window." */
8293 if (end
< inside_height
)
8294 XClearArea (FRAME_X_DISPLAY (f
), w
,
8296 /* x, y, width, height, and exposures. */
8297 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
8298 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
8299 inside_width
, inside_height
- end
,
8307 #endif /* !USE_TOOLKIT_SCROLL_BARS */
8309 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
8313 x_scroll_bar_remove (bar
)
8314 struct scroll_bar
*bar
;
8318 #if USE_TOOLKIT_SCROLL_BARS
8319 XtDestroyWidget (SCROLL_BAR_X_WIDGET (bar
));
8320 #else /* not USE_TOOLKIT_SCROLL_BARS */
8322 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8323 XDestroyWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
));
8325 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8327 /* Disassociate this scroll bar from its window. */
8328 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
8334 /* Set the handle of the vertical scroll bar for WINDOW to indicate
8335 that we are displaying PORTION characters out of a total of WHOLE
8336 characters, starting at POSITION. If WINDOW has no scroll bar,
8340 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
8342 int portion
, whole
, position
;
8344 struct frame
*f
= XFRAME (w
->frame
);
8345 struct scroll_bar
*bar
;
8346 int top
, height
, left
, sb_left
, width
, sb_width
;
8347 int window_x
, window_y
, window_width
, window_height
;
8349 /* Get window dimensions. */
8350 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
8352 width
= FRAME_SCROLL_BAR_COLS (f
) * CANON_X_UNIT (f
);
8353 height
= window_height
;
8355 /* Compute the left edge of the scroll bar area. */
8356 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8357 left
= XINT (w
->left
) + XINT (w
->width
) - FRAME_SCROLL_BAR_COLS (f
);
8359 left
= XFASTINT (w
->left
);
8360 left
*= CANON_X_UNIT (f
);
8361 left
+= FRAME_INTERNAL_BORDER_WIDTH (f
);
8363 /* Compute the width of the scroll bar which might be less than
8364 the width of the area reserved for the scroll bar. */
8365 if (FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0)
8366 sb_width
= FRAME_SCROLL_BAR_PIXEL_WIDTH (f
);
8370 /* Compute the left edge of the scroll bar. */
8371 #ifdef USE_TOOLKIT_SCROLL_BARS
8372 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8373 sb_left
= left
+ width
- sb_width
- (width
- sb_width
) / 2;
8375 sb_left
= left
+ (width
- sb_width
) / 2;
8377 if (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f
))
8378 sb_left
= left
+ width
- sb_width
;
8383 /* Does the scroll bar exist yet? */
8384 if (NILP (w
->vertical_scroll_bar
))
8387 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8388 left
, top
, width
, height
, False
);
8390 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
8394 /* It may just need to be moved and resized. */
8395 unsigned int mask
= 0;
8397 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
8401 if (sb_left
!= XINT (bar
->left
))
8403 if (top
!= XINT (bar
->top
))
8405 if (sb_width
!= XINT (bar
->width
))
8407 if (height
!= XINT (bar
->height
))
8410 #ifdef USE_TOOLKIT_SCROLL_BARS
8412 /* Since toolkit scroll bars are smaller than the space reserved
8413 for them on the frame, we have to clear "under" them. */
8414 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8415 left
, top
, width
, height
, False
);
8417 /* Move/size the scroll bar widget. */
8419 XtConfigureWidget (SCROLL_BAR_X_WIDGET (bar
),
8420 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8422 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
8425 #else /* not USE_TOOLKIT_SCROLL_BARS */
8427 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
8429 /* Clear areas not covered by the scroll bar. This makes sure a
8430 previous mode line display is cleared after C-x 2 C-x 1, for
8431 example. Non-toolkit scroll bars are as wide as the area
8432 reserved for scroll bars - trim at both sides. */
8433 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8434 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8436 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8437 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8438 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
8442 /* Move/size the scroll bar window. */
8447 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
8449 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
8451 XConfigureWindow (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (bar
),
8455 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8457 /* Remember new settings. */
8458 XSETINT (bar
->left
, sb_left
);
8459 XSETINT (bar
->top
, top
);
8460 XSETINT (bar
->width
, sb_width
);
8461 XSETINT (bar
->height
, height
);
8466 #if USE_TOOLKIT_SCROLL_BARS
8467 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
8468 #else /* not USE_TOOLKIT_SCROLL_BARS */
8469 /* Set the scroll bar's current state, unless we're currently being
8471 if (NILP (bar
->dragging
))
8473 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
8476 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
8479 int start
= ((double) position
* top_range
) / whole
;
8480 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
8481 x_scroll_bar_set_handle (bar
, start
, end
, 0);
8484 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8486 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
8490 /* The following three hooks are used when we're doing a thorough
8491 redisplay of the frame. We don't explicitly know which scroll bars
8492 are going to be deleted, because keeping track of when windows go
8493 away is a real pain - "Can you say set-window-configuration, boys
8494 and girls?" Instead, we just assert at the beginning of redisplay
8495 that *all* scroll bars are to be removed, and then save a scroll bar
8496 from the fiery pit when we actually redisplay its window. */
8498 /* Arrange for all scroll bars on FRAME to be removed at the next call
8499 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
8500 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
8503 XTcondemn_scroll_bars (frame
)
8506 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
8507 while (! NILP (FRAME_SCROLL_BARS (frame
)))
8510 bar
= FRAME_SCROLL_BARS (frame
);
8511 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
8512 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
8513 XSCROLL_BAR (bar
)->prev
= Qnil
;
8514 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
8515 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
8516 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
8520 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
8521 Note that WINDOW isn't necessarily condemned at all. */
8523 XTredeem_scroll_bar (window
)
8524 struct window
*window
;
8526 struct scroll_bar
*bar
;
8528 /* We can't redeem this window's scroll bar if it doesn't have one. */
8529 if (NILP (window
->vertical_scroll_bar
))
8532 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
8534 /* Unlink it from the condemned list. */
8536 FRAME_PTR f
= XFRAME (WINDOW_FRAME (window
));
8538 if (NILP (bar
->prev
))
8540 /* If the prev pointer is nil, it must be the first in one of
8542 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
8543 /* It's not condemned. Everything's fine. */
8545 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
8546 window
->vertical_scroll_bar
))
8547 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
8549 /* If its prev pointer is nil, it must be at the front of
8550 one or the other! */
8554 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
8556 if (! NILP (bar
->next
))
8557 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
8559 bar
->next
= FRAME_SCROLL_BARS (f
);
8561 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
8562 if (! NILP (bar
->next
))
8563 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
8567 /* Remove all scroll bars on FRAME that haven't been saved since the
8568 last call to `*condemn_scroll_bars_hook'. */
8571 XTjudge_scroll_bars (f
)
8574 Lisp_Object bar
, next
;
8576 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
8578 /* Clear out the condemned list now so we won't try to process any
8579 more events on the hapless scroll bars. */
8580 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
8582 for (; ! NILP (bar
); bar
= next
)
8584 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
8586 x_scroll_bar_remove (b
);
8589 b
->next
= b
->prev
= Qnil
;
8592 /* Now there should be no references to the condemned scroll bars,
8593 and they should get garbage-collected. */
8597 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
8598 is a no-op when using toolkit scroll bars.
8600 This may be called from a signal handler, so we have to ignore GC
8604 x_scroll_bar_expose (bar
, event
)
8605 struct scroll_bar
*bar
;
8608 #ifndef USE_TOOLKIT_SCROLL_BARS
8610 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8611 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8612 GC gc
= f
->output_data
.x
->normal_gc
;
8613 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
8617 x_scroll_bar_set_handle (bar
, XINT (bar
->start
), XINT (bar
->end
), 1);
8619 /* Draw a one-pixel border just inside the edges of the scroll bar. */
8620 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
8622 /* x, y, width, height */
8624 XINT (bar
->width
) - 1 - width_trim
- width_trim
,
8625 XINT (bar
->height
) - 1);
8629 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8632 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
8633 is set to something other than no_event, it is enqueued.
8635 This may be called from a signal handler, so we have to ignore GC
8638 #ifndef USE_TOOLKIT_SCROLL_BARS
8641 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
8642 struct scroll_bar
*bar
;
8644 struct input_event
*emacs_event
;
8646 if (! GC_WINDOWP (bar
->window
))
8649 emacs_event
->kind
= scroll_bar_click
;
8650 emacs_event
->code
= event
->xbutton
.button
- Button1
;
8651 emacs_event
->modifiers
8652 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
8653 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
8654 event
->xbutton
.state
)
8655 | (event
->type
== ButtonRelease
8658 emacs_event
->frame_or_window
= bar
->window
;
8659 emacs_event
->arg
= Qnil
;
8660 emacs_event
->timestamp
= event
->xbutton
.time
;
8663 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8665 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8668 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8669 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
8672 if (y
> top_range
) y
= top_range
;
8674 if (y
< XINT (bar
->start
))
8675 emacs_event
->part
= scroll_bar_above_handle
;
8676 else if (y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
8677 emacs_event
->part
= scroll_bar_handle
;
8679 emacs_event
->part
= scroll_bar_below_handle
;
8681 /* Just because the user has clicked on the handle doesn't mean
8682 they want to drag it. Lisp code needs to be able to decide
8683 whether or not we're dragging. */
8685 /* If the user has just clicked on the handle, record where they're
8687 if (event
->type
== ButtonPress
8688 && emacs_event
->part
== scroll_bar_handle
)
8689 XSETINT (bar
->dragging
, y
- XINT (bar
->start
));
8692 /* If the user has released the handle, set it to its final position. */
8693 if (event
->type
== ButtonRelease
8694 && ! NILP (bar
->dragging
))
8696 int new_start
= y
- XINT (bar
->dragging
);
8697 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8699 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8700 bar
->dragging
= Qnil
;
8703 /* Same deal here as the other #if 0. */
8705 /* Clicks on the handle are always reported as occurring at the top of
8707 if (emacs_event
->part
== scroll_bar_handle
)
8708 emacs_event
->x
= bar
->start
;
8710 XSETINT (emacs_event
->x
, y
);
8712 XSETINT (emacs_event
->x
, y
);
8715 XSETINT (emacs_event
->y
, top_range
);
8719 /* Handle some mouse motion while someone is dragging the scroll bar.
8721 This may be called from a signal handler, so we have to ignore GC
8725 x_scroll_bar_note_movement (bar
, event
)
8726 struct scroll_bar
*bar
;
8729 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
8731 last_mouse_movement_time
= event
->xmotion
.time
;
8734 XSETVECTOR (last_mouse_scroll_bar
, bar
);
8736 /* If we're dragging the bar, display it. */
8737 if (! GC_NILP (bar
->dragging
))
8739 /* Where should the handle be now? */
8740 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
8742 if (new_start
!= XINT (bar
->start
))
8744 int new_end
= new_start
+ (XINT (bar
->end
) - XINT (bar
->start
));
8746 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
8751 #endif /* !USE_TOOLKIT_SCROLL_BARS */
8753 /* Return information to the user about the current position of the mouse
8754 on the scroll bar. */
8757 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
8759 Lisp_Object
*bar_window
;
8760 enum scroll_bar_part
*part
;
8762 unsigned long *time
;
8764 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
8765 Window w
= SCROLL_BAR_X_WINDOW (bar
);
8766 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
8768 Window dummy_window
;
8770 unsigned int dummy_mask
;
8774 /* Get the mouse's position relative to the scroll bar window, and
8776 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
8778 /* Root, child, root x and root y. */
8779 &dummy_window
, &dummy_window
,
8780 &dummy_coord
, &dummy_coord
,
8782 /* Position relative to scroll bar. */
8785 /* Mouse buttons and modifier keys. */
8792 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, XINT (bar
->height
));
8795 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, XINT (bar
->height
));
8797 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
8799 if (! NILP (bar
->dragging
))
8800 win_y
-= XINT (bar
->dragging
);
8804 if (win_y
> top_range
)
8808 *bar_window
= bar
->window
;
8810 if (! NILP (bar
->dragging
))
8811 *part
= scroll_bar_handle
;
8812 else if (win_y
< XINT (bar
->start
))
8813 *part
= scroll_bar_above_handle
;
8814 else if (win_y
< XINT (bar
->end
) + VERTICAL_SCROLL_BAR_MIN_HANDLE
)
8815 *part
= scroll_bar_handle
;
8817 *part
= scroll_bar_below_handle
;
8819 XSETINT (*x
, win_y
);
8820 XSETINT (*y
, top_range
);
8823 last_mouse_scroll_bar
= Qnil
;
8826 *time
= last_mouse_movement_time
;
8832 /* The screen has been cleared so we may have changed foreground or
8833 background colors, and the scroll bars may need to be redrawn.
8834 Clear out the scroll bars, and ask for expose events, so we can
8838 x_scroll_bar_clear (f
)
8841 #ifndef USE_TOOLKIT_SCROLL_BARS
8844 /* We can have scroll bars even if this is 0,
8845 if we just turned off scroll bar mode.
8846 But in that case we should not clear them. */
8847 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
8848 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
8849 bar
= XSCROLL_BAR (bar
)->next
)
8850 XClearArea (FRAME_X_DISPLAY (f
), SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
)),
8852 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8855 /* This processes Expose events from the menu-bar specific X event
8856 loop in xmenu.c. This allows to redisplay the frame if necessary
8857 when handling menu-bar or pop-up items. */
8860 process_expose_from_menu (event
)
8864 struct x_display_info
*dpyinfo
;
8865 int frame_exposed_p
= 0;
8869 dpyinfo
= x_display_info_for_display (event
.xexpose
.display
);
8870 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
8873 if (f
->async_visible
== 0)
8875 f
->async_visible
= 1;
8876 f
->async_iconified
= 0;
8877 f
->output_data
.x
->has_been_visible
= 1;
8878 SET_FRAME_GARBAGED (f
);
8882 expose_frame (x_window_to_frame (dpyinfo
, event
.xexpose
.window
),
8883 event
.xexpose
.x
, event
.xexpose
.y
,
8884 event
.xexpose
.width
, event
.xexpose
.height
);
8885 frame_exposed_p
= 1;
8890 struct scroll_bar
*bar
8891 = x_window_to_scroll_bar (event
.xexpose
.window
);
8894 x_scroll_bar_expose (bar
, &event
);
8898 return frame_exposed_p
;
8901 /* Define a queue to save up SelectionRequest events for later handling. */
8903 struct selection_event_queue
8906 struct selection_event_queue
*next
;
8909 static struct selection_event_queue
*queue
;
8911 /* Nonzero means queue up certain events--don't process them yet. */
8913 static int x_queue_selection_requests
;
8915 /* Queue up an X event *EVENT, to be processed later. */
8918 x_queue_event (f
, event
)
8922 struct selection_event_queue
*queue_tmp
8923 = (struct selection_event_queue
*) xmalloc (sizeof (struct selection_event_queue
));
8925 if (queue_tmp
!= NULL
)
8927 queue_tmp
->event
= *event
;
8928 queue_tmp
->next
= queue
;
8933 /* Take all the queued events and put them back
8934 so that they get processed afresh. */
8937 x_unqueue_events (display
)
8940 while (queue
!= NULL
)
8942 struct selection_event_queue
*queue_tmp
= queue
;
8943 XPutBackEvent (display
, &queue_tmp
->event
);
8944 queue
= queue_tmp
->next
;
8945 xfree ((char *)queue_tmp
);
8949 /* Start queuing SelectionRequest events. */
8952 x_start_queuing_selection_requests (display
)
8955 x_queue_selection_requests
++;
8958 /* Stop queuing SelectionRequest events. */
8961 x_stop_queuing_selection_requests (display
)
8964 x_queue_selection_requests
--;
8965 x_unqueue_events (display
);
8968 /* The main X event-reading loop - XTread_socket. */
8970 /* Time stamp of enter window event. This is only used by XTread_socket,
8971 but we have to put it out here, since static variables within functions
8972 sometimes don't work. */
8974 static Time enter_timestamp
;
8976 /* This holds the state XLookupString needs to implement dead keys
8977 and other tricks known as "compose processing". _X Window System_
8978 says that a portable program can't use this, but Stephen Gildea assures
8979 me that letting the compiler initialize it to zeros will work okay.
8981 This must be defined outside of XTread_socket, for the same reasons
8982 given for enter_time stamp, above. */
8984 static XComposeStatus compose_status
;
8986 /* Record the last 100 characters stored
8987 to help debug the loss-of-chars-during-GC problem. */
8989 static int temp_index
;
8990 static short temp_buffer
[100];
8992 /* Set this to nonzero to fake an "X I/O error"
8993 on a particular display. */
8995 struct x_display_info
*XTread_socket_fake_io_error
;
8997 /* When we find no input here, we occasionally do a no-op command
8998 to verify that the X server is still running and we can still talk with it.
8999 We try all the open displays, one by one.
9000 This variable is used for cycling thru the displays. */
9002 static struct x_display_info
*next_noop_dpyinfo
;
9004 #define SET_SAVED_MENU_EVENT(size) \
9007 if (f->output_data.x->saved_menu_event == 0) \
9008 f->output_data.x->saved_menu_event \
9009 = (XEvent *) xmalloc (sizeof (XEvent)); \
9010 bcopy (&event, f->output_data.x->saved_menu_event, size); \
9011 if (numchars >= 1) \
9013 bufp->kind = menu_bar_activate_event; \
9014 XSETFRAME (bufp->frame_or_window, f); \
9023 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
9024 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
9026 /* Read events coming from the X server.
9027 This routine is called by the SIGIO handler.
9028 We return as soon as there are no more events to be read.
9030 Events representing keys are stored in buffer BUFP,
9031 which can hold up to NUMCHARS characters.
9032 We return the number of characters stored into the buffer,
9033 thus pretending to be `read'.
9035 EXPECTED is nonzero if the caller knows input is available. */
9038 XTread_socket (sd
, bufp
, numchars
, expected
)
9040 /* register */ struct input_event
*bufp
;
9041 /* register */ int numchars
;
9048 int event_found
= 0;
9049 struct x_display_info
*dpyinfo
;
9050 struct coding_system coding
;
9052 if (interrupt_input_blocked
)
9054 interrupt_input_pending
= 1;
9058 interrupt_input_pending
= 0;
9061 /* So people can tell when we have read the available input. */
9062 input_signal_count
++;
9065 abort (); /* Don't think this happens. */
9069 /* The input should be decoded if it is from XIM. Currently the
9070 locale of XIM is the same as that of the system. So, we can use
9071 Vlocale_coding_system which is initialized properly at Emacs
9073 setup_coding_system (Vlocale_coding_system
, &coding
);
9074 coding
.src_multibyte
= 0;
9075 coding
.dst_multibyte
= 1;
9076 /* The input is converted to events, thus we can't handle
9077 composition. Anyway, there's no XIM that gives us composition
9079 coding
.composing
= COMPOSITION_DISABLED
;
9081 /* Find the display we are supposed to read input for.
9082 It's the one communicating on descriptor SD. */
9083 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
9085 #if 0 /* This ought to be unnecessary; let's verify it. */
9087 /* If available, Xlib uses FIOSNBIO to make the socket
9088 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
9089 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
9090 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
9091 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
9092 #endif /* ! defined (FIOSNBIO) */
9095 #if 0 /* This code can't be made to work, with multiple displays,
9096 and appears not to be used on any system any more.
9097 Also keyboard.c doesn't turn O_NDELAY on and off
9098 for X connections. */
9101 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
9103 extern int read_alarm_should_throw
;
9104 read_alarm_should_throw
= 1;
9105 XPeekEvent (dpyinfo
->display
, &event
);
9106 read_alarm_should_throw
= 0;
9108 #endif /* HAVE_SELECT */
9112 /* For debugging, this gives a way to fake an I/O error. */
9113 if (dpyinfo
== XTread_socket_fake_io_error
)
9115 XTread_socket_fake_io_error
= 0;
9116 x_io_error_quitter (dpyinfo
->display
);
9119 while (XPending (dpyinfo
->display
))
9121 XNextEvent (dpyinfo
->display
, &event
);
9125 /* Filter events for the current X input method.
9126 XFilterEvent returns non-zero if the input method has
9127 consumed the event. We pass the frame's X window to
9128 XFilterEvent because that's the one for which the IC
9130 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
9131 event
.xclient
.window
);
9132 if (XFilterEvent (&event
, f1
? FRAME_X_WINDOW (f1
) : None
))
9142 if (event
.xclient
.message_type
9143 == dpyinfo
->Xatom_wm_protocols
9144 && event
.xclient
.format
== 32)
9146 if (event
.xclient
.data
.l
[0]
9147 == dpyinfo
->Xatom_wm_take_focus
)
9149 /* Use x_any_window_to_frame because this
9150 could be the shell widget window
9151 if the frame has no title bar. */
9152 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9154 /* Not quite sure this is needed -pd */
9155 if (f
&& FRAME_XIC (f
))
9156 XSetICFocus (FRAME_XIC (f
));
9158 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
9159 instructs the WM to set the input focus automatically for
9160 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
9161 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
9162 it has set the focus. So, XSetInputFocus below is not
9165 The call to XSetInputFocus below has also caused trouble. In
9166 cases where the XSetInputFocus done by the WM and the one
9167 below are temporally close (on a fast machine), the call
9168 below can generate additional FocusIn events which confuse
9171 /* Since we set WM_TAKE_FOCUS, we must call
9172 XSetInputFocus explicitly. But not if f is null,
9173 since that might be an event for a deleted frame. */
9176 Display
*d
= event
.xclient
.display
;
9177 /* Catch and ignore errors, in case window has been
9178 iconified by a window manager such as GWM. */
9179 int count
= x_catch_errors (d
);
9180 XSetInputFocus (d
, event
.xclient
.window
,
9181 /* The ICCCM says this is
9182 the only valid choice. */
9184 event
.xclient
.data
.l
[1]);
9185 /* This is needed to detect the error
9186 if there is an error. */
9188 x_uncatch_errors (d
, count
);
9190 /* Not certain about handling scroll bars here */
9193 else if (event
.xclient
.data
.l
[0]
9194 == dpyinfo
->Xatom_wm_save_yourself
)
9196 /* Save state modify the WM_COMMAND property to
9197 something which can reinstate us. This notifies
9198 the session manager, who's looking for such a
9199 PropertyNotify. Can restart processing when
9200 a keyboard or mouse event arrives. */
9203 f
= x_top_window_to_frame (dpyinfo
,
9204 event
.xclient
.window
);
9206 /* This is just so we only give real data once
9207 for a single Emacs process. */
9208 if (f
== SELECTED_FRAME ())
9209 XSetCommand (FRAME_X_DISPLAY (f
),
9210 event
.xclient
.window
,
9211 initial_argv
, initial_argc
);
9213 XSetCommand (FRAME_X_DISPLAY (f
),
9214 event
.xclient
.window
,
9218 else if (event
.xclient
.data
.l
[0]
9219 == dpyinfo
->Xatom_wm_delete_window
)
9222 = x_any_window_to_frame (dpyinfo
,
9223 event
.xclient
.window
);
9230 bufp
->kind
= delete_window_event
;
9231 XSETFRAME (bufp
->frame_or_window
, f
);
9240 else if (event
.xclient
.message_type
9241 == dpyinfo
->Xatom_wm_configure_denied
)
9244 else if (event
.xclient
.message_type
9245 == dpyinfo
->Xatom_wm_window_moved
)
9249 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9251 new_x
= event
.xclient
.data
.s
[0];
9252 new_y
= event
.xclient
.data
.s
[1];
9256 f
->output_data
.x
->left_pos
= new_x
;
9257 f
->output_data
.x
->top_pos
= new_y
;
9261 else if (event
.xclient
.message_type
9262 == dpyinfo
->Xatom_editres
)
9265 = x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
9266 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
9269 #endif /* HACK_EDITRES */
9270 else if ((event
.xclient
.message_type
9271 == dpyinfo
->Xatom_DONE
)
9272 || (event
.xclient
.message_type
9273 == dpyinfo
->Xatom_PAGE
))
9275 /* Ghostview job completed. Kill it. We could
9276 reply with "Next" if we received "Page", but we
9277 currently never do because we are interested in
9278 images, only, which should have 1 page. */
9279 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
9281 = x_window_to_frame (dpyinfo
, event
.xclient
.window
);
9282 x_kill_gs_process (pixmap
, f
);
9283 expose_frame (f
, 0, 0, 0, 0);
9285 #ifdef USE_TOOLKIT_SCROLL_BARS
9286 /* Scroll bar callbacks send a ClientMessage from which
9287 we construct an input_event. */
9288 else if (event
.xclient
.message_type
9289 == dpyinfo
->Xatom_Scrollbar
)
9291 x_scroll_bar_to_input_event (&event
, bufp
);
9292 ++bufp
, ++count
, --numchars
;
9295 #endif /* USE_TOOLKIT_SCROLL_BARS */
9301 case SelectionNotify
:
9302 #ifdef USE_X_TOOLKIT
9303 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
9305 #endif /* not USE_X_TOOLKIT */
9306 x_handle_selection_notify (&event
.xselection
);
9309 case SelectionClear
: /* Someone has grabbed ownership. */
9310 #ifdef USE_X_TOOLKIT
9311 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
9313 #endif /* USE_X_TOOLKIT */
9315 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
9320 bufp
->kind
= selection_clear_event
;
9321 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
9322 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
9323 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
9324 bufp
->frame_or_window
= Qnil
;
9333 case SelectionRequest
: /* Someone wants our selection. */
9334 #ifdef USE_X_TOOLKIT
9335 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
9337 #endif /* USE_X_TOOLKIT */
9338 if (x_queue_selection_requests
)
9339 x_queue_event (x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
),
9343 XSelectionRequestEvent
*eventp
= (XSelectionRequestEvent
*) &event
;
9348 bufp
->kind
= selection_request_event
;
9349 SELECTION_EVENT_DISPLAY (bufp
) = eventp
->display
;
9350 SELECTION_EVENT_REQUESTOR (bufp
) = eventp
->requestor
;
9351 SELECTION_EVENT_SELECTION (bufp
) = eventp
->selection
;
9352 SELECTION_EVENT_TARGET (bufp
) = eventp
->target
;
9353 SELECTION_EVENT_PROPERTY (bufp
) = eventp
->property
;
9354 SELECTION_EVENT_TIME (bufp
) = eventp
->time
;
9355 bufp
->frame_or_window
= Qnil
;
9364 case PropertyNotify
:
9365 #ifdef USE_X_TOOLKIT
9366 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
9368 #endif /* not USE_X_TOOLKIT */
9369 x_handle_property_notify (&event
.xproperty
);
9372 case ReparentNotify
:
9373 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
9377 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
9378 x_real_positions (f
, &x
, &y
);
9379 f
->output_data
.x
->left_pos
= x
;
9380 f
->output_data
.x
->top_pos
= y
;
9385 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
9388 if (f
->async_visible
== 0)
9390 f
->async_visible
= 1;
9391 f
->async_iconified
= 0;
9392 f
->output_data
.x
->has_been_visible
= 1;
9393 SET_FRAME_GARBAGED (f
);
9396 expose_frame (x_window_to_frame (dpyinfo
,
9397 event
.xexpose
.window
),
9398 event
.xexpose
.x
, event
.xexpose
.y
,
9399 event
.xexpose
.width
, event
.xexpose
.height
);
9403 #ifdef USE_TOOLKIT_SCROLL_BARS
9404 /* Dispatch event to the widget. */
9406 #else /* not USE_TOOLKIT_SCROLL_BARS */
9407 struct scroll_bar
*bar
9408 = x_window_to_scroll_bar (event
.xexpose
.window
);
9411 x_scroll_bar_expose (bar
, &event
);
9412 #ifdef USE_X_TOOLKIT
9415 #endif /* USE_X_TOOLKIT */
9416 #endif /* not USE_TOOLKIT_SCROLL_BARS */
9420 case GraphicsExpose
: /* This occurs when an XCopyArea's
9421 source area was obscured or not
9423 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
9427 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
9428 event
.xgraphicsexpose
.width
,
9429 event
.xgraphicsexpose
.height
);
9431 #ifdef USE_X_TOOLKIT
9434 #endif /* USE_X_TOOLKIT */
9437 case NoExpose
: /* This occurs when an XCopyArea's
9438 source area was completely
9443 /* Redo the mouse-highlight after the tooltip has gone. */
9444 if (event
.xmap
.window
== tip_window
)
9447 redo_mouse_highlight ();
9450 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
9451 if (f
) /* F may no longer exist if
9452 the frame was deleted. */
9454 /* While a frame is unmapped, display generation is
9455 disabled; you don't want to spend time updating a
9456 display that won't ever be seen. */
9457 f
->async_visible
= 0;
9458 /* We can't distinguish, from the event, whether the window
9459 has become iconified or invisible. So assume, if it
9460 was previously visible, than now it is iconified.
9461 But x_make_frame_invisible clears both
9462 the visible flag and the iconified flag;
9463 and that way, we know the window is not iconified now. */
9464 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
9466 f
->async_iconified
= 1;
9468 bufp
->kind
= iconify_event
;
9469 XSETFRAME (bufp
->frame_or_window
, f
);
9479 if (event
.xmap
.window
== tip_window
)
9480 /* The tooltip has been drawn already. Avoid
9481 the SET_FRAME_GARBAGED below. */
9484 /* We use x_top_window_to_frame because map events can
9485 come for sub-windows and they don't mean that the
9486 frame is visible. */
9487 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
9490 f
->async_visible
= 1;
9491 f
->async_iconified
= 0;
9492 f
->output_data
.x
->has_been_visible
= 1;
9494 /* wait_reading_process_input will notice this and update
9495 the frame's display structures. */
9496 SET_FRAME_GARBAGED (f
);
9500 bufp
->kind
= deiconify_event
;
9501 XSETFRAME (bufp
->frame_or_window
, f
);
9507 else if (! NILP (Vframe_list
)
9508 && ! NILP (XCDR (Vframe_list
)))
9509 /* Force a redisplay sooner or later
9510 to update the frame titles
9511 in case this is the second frame. */
9512 record_asynch_buffer_change ();
9517 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
9520 /* I couldn't find a way to prevent LessTif scroll bars
9521 from consuming key events. */
9524 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
9526 if (widget
&& XmIsScrollBar (widget
))
9528 widget
= XtParent (widget
);
9529 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
9532 #endif /* USE_MOTIF */
9536 KeySym keysym
, orig_keysym
;
9537 /* al%imercury@uunet.uu.net says that making this 81
9538 instead of 80 fixed a bug whereby meta chars made
9541 It seems that some version of XmbLookupString has
9542 a bug of not returning XBufferOverflow in
9543 status_return even if the input is too long to
9544 fit in 81 bytes. So, we must prepare sufficient
9545 bytes for copy_buffer. 513 bytes (256 chars for
9546 two-byte character set) seems to be a faily good
9547 approximation. -- 2000.8.10 handa@etl.go.jp */
9548 unsigned char copy_buffer
[513];
9549 unsigned char *copy_bufptr
= copy_buffer
;
9550 int copy_bufsiz
= sizeof (copy_buffer
);
9554 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
9555 extra_keyboard_modifiers
);
9556 modifiers
= event
.xkey
.state
;
9558 /* This will have to go some day... */
9560 /* make_lispy_event turns chars into control chars.
9561 Don't do it here because XLookupString is too eager. */
9562 event
.xkey
.state
&= ~ControlMask
;
9563 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
9564 | dpyinfo
->super_mod_mask
9565 | dpyinfo
->hyper_mod_mask
9566 | dpyinfo
->alt_mod_mask
);
9568 /* In case Meta is ComposeCharacter,
9569 clear its status. According to Markus Ehrnsperger
9570 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
9571 this enables ComposeCharacter to work whether or
9572 not it is combined with Meta. */
9573 if (modifiers
& dpyinfo
->meta_mod_mask
)
9574 bzero (&compose_status
, sizeof (compose_status
));
9579 Status status_return
;
9581 nbytes
= XmbLookupString (FRAME_XIC (f
),
9582 &event
.xkey
, copy_bufptr
,
9583 copy_bufsiz
, &keysym
,
9585 if (status_return
== XBufferOverflow
)
9587 copy_bufsiz
= nbytes
+ 1;
9588 copy_bufptr
= (char *) alloca (copy_bufsiz
);
9589 nbytes
= XmbLookupString (FRAME_XIC (f
),
9590 &event
.xkey
, copy_bufptr
,
9591 copy_bufsiz
, &keysym
,
9595 if (status_return
== XLookupNone
)
9597 else if (status_return
== XLookupChars
)
9602 else if (status_return
!= XLookupKeySym
9603 && status_return
!= XLookupBoth
)
9607 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
9608 copy_bufsiz
, &keysym
,
9611 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
9612 copy_bufsiz
, &keysym
,
9616 orig_keysym
= keysym
;
9620 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
9621 || keysym
== XK_Delete
9622 #ifdef XK_ISO_Left_Tab
9623 || (keysym
>= XK_ISO_Left_Tab
&& keysym
<= XK_ISO_Enter
)
9625 || (keysym
>= XK_Kanji
&& keysym
<= XK_Eisu_toggle
)
9626 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
9627 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
9629 /* This recognizes the "extended function keys".
9630 It seems there's no cleaner way.
9631 Test IsModifierKey to avoid handling mode_switch
9633 || ((unsigned) (keysym
) >= XK_Select
9634 && (unsigned)(keysym
) < XK_KP_Space
)
9636 #ifdef XK_dead_circumflex
9637 || orig_keysym
== XK_dead_circumflex
9639 #ifdef XK_dead_grave
9640 || orig_keysym
== XK_dead_grave
9642 #ifdef XK_dead_tilde
9643 || orig_keysym
== XK_dead_tilde
9645 #ifdef XK_dead_diaeresis
9646 || orig_keysym
== XK_dead_diaeresis
9648 #ifdef XK_dead_macron
9649 || orig_keysym
== XK_dead_macron
9651 #ifdef XK_dead_degree
9652 || orig_keysym
== XK_dead_degree
9654 #ifdef XK_dead_acute
9655 || orig_keysym
== XK_dead_acute
9657 #ifdef XK_dead_cedilla
9658 || orig_keysym
== XK_dead_cedilla
9660 #ifdef XK_dead_breve
9661 || orig_keysym
== XK_dead_breve
9663 #ifdef XK_dead_ogonek
9664 || orig_keysym
== XK_dead_ogonek
9666 #ifdef XK_dead_caron
9667 || orig_keysym
== XK_dead_caron
9669 #ifdef XK_dead_doubleacute
9670 || orig_keysym
== XK_dead_doubleacute
9672 #ifdef XK_dead_abovedot
9673 || orig_keysym
== XK_dead_abovedot
9675 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
9676 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
9677 /* Any "vendor-specific" key is ok. */
9678 || (orig_keysym
& (1 << 28)))
9679 && ! (IsModifierKey (orig_keysym
)
9681 #ifdef XK_Mode_switch
9682 || ((unsigned)(orig_keysym
) == XK_Mode_switch
)
9685 || ((unsigned)(orig_keysym
) == XK_Num_Lock
)
9687 #endif /* not HAVE_X11R5 */
9690 if (temp_index
== sizeof temp_buffer
/ sizeof (short))
9692 temp_buffer
[temp_index
++] = keysym
;
9693 bufp
->kind
= non_ascii_keystroke
;
9694 bufp
->code
= keysym
;
9695 XSETFRAME (bufp
->frame_or_window
, f
);
9698 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
9700 bufp
->timestamp
= event
.xkey
.time
;
9705 else if (numchars
> nbytes
)
9709 unsigned char *p
, *pend
;
9712 for (i
= 0; i
< nbytes
; i
++)
9714 if (temp_index
== (sizeof temp_buffer
9717 temp_buffer
[temp_index
++] = copy_bufptr
[i
];
9720 if (/* If the event is not from XIM, */
9721 event
.xkey
.keycode
!= 0
9722 /* or the current locale doesn't request
9723 decoding of the intup data, ... */
9724 || coding
.type
== coding_type_raw_text
9725 || coding
.type
== coding_type_no_conversion
)
9727 /* ... we can use the input data as is. */
9732 /* We have to decode the input data. */
9736 require
= decoding_buffer_size (&coding
, nbytes
);
9737 p
= (unsigned char *) alloca (require
);
9738 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
9739 decode_coding (&coding
, copy_bufptr
, p
,
9741 nbytes
= coding
.produced
;
9742 nchars
= coding
.produced_char
;
9746 /* Convert the input data to a sequence of
9747 character events. */
9748 for (i
= 0; i
< nbytes
; i
+= len
)
9750 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
9752 bufp
->kind
= (SINGLE_BYTE_CHAR_P (c
)
9754 : multibyte_char_keystroke
);
9756 XSETFRAME (bufp
->frame_or_window
, f
);
9759 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
9761 bufp
->timestamp
= event
.xkey
.time
;
9768 if (keysym
== NoSymbol
)
9778 /* Don't dispatch this event since XtDispatchEvent calls
9779 XFilterEvent, and two calls in a row may freeze the
9788 /* Don't dispatch this event since XtDispatchEvent calls
9789 XFilterEvent, and two calls in a row may freeze the
9796 /* Here's a possible interpretation of the whole
9797 FocusIn-EnterNotify FocusOut-LeaveNotify mess. If
9798 you get a FocusIn event, you have to get a FocusOut
9799 event before you relinquish the focus. If you
9800 haven't received a FocusIn event, then a mere
9801 LeaveNotify is enough to free you. */
9805 int from_menu_bar_p
= 0;
9807 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
9809 #ifdef LESSTIF_VERSION
9810 /* When clicking outside of a menu bar popup to close
9811 it, we get a FocusIn/ EnterNotify sequence of
9812 events. The flag event.xcrossing.focus is not set
9813 in the EnterNotify event of that sequence because
9814 the focus is in the menu bar,
9815 event.xcrossing.window is the frame's X window.
9816 Unconditionally setting the focus frame to null in
9817 this case is not the right thing, because no event
9818 follows that could set the focus frame to the right
9821 This could be a LessTif bug, but I wasn't able to
9822 reproduce the behavior in a simple test program.
9824 (gerd, LessTif 0.88.1). */
9826 if (!event
.xcrossing
.focus
9828 && f
->output_data
.x
->menubar_widget
)
9833 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
9834 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
9835 from_menu_bar_p
= 1;
9837 #endif /* LESSTIF_VERSION */
9839 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
9841 /* Avoid nasty pop/raise loops. */
9842 if (f
&& (!(f
->auto_raise
)
9844 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
9846 x_new_focus_frame (dpyinfo
, f
);
9847 enter_timestamp
= event
.xcrossing
.time
;
9850 else if (f
== dpyinfo
->x_focus_frame
)
9851 x_new_focus_frame (dpyinfo
, 0);
9853 /* EnterNotify counts as mouse movement,
9854 so update things that depend on mouse position. */
9855 if (f
&& !f
->output_data
.x
->busy_p
)
9856 note_mouse_movement (f
, &event
.xmotion
);
9861 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
9862 if (event
.xfocus
.detail
!= NotifyPointer
)
9863 dpyinfo
->x_focus_event_frame
= f
;
9866 x_new_focus_frame (dpyinfo
, f
);
9868 /* Don't stop displaying the initial startup message
9869 for a switch-frame event we don't need. */
9870 if (GC_NILP (Vterminal_frame
)
9871 && GC_CONSP (Vframe_list
)
9872 && !GC_NILP (XCDR (Vframe_list
)))
9874 bufp
->kind
= FOCUS_IN_EVENT
;
9875 XSETFRAME (bufp
->frame_or_window
, f
);
9877 ++bufp
, ++count
, --numchars
;
9882 if (f
&& FRAME_XIC (f
))
9883 XSetICFocus (FRAME_XIC (f
));
9889 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
9893 int from_menu_bar_p
= 0;
9895 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9897 /* If we move outside the frame, then we're
9898 certainly no longer on any text in the frame. */
9899 clear_mouse_face (dpyinfo
);
9900 dpyinfo
->mouse_face_mouse_frame
= 0;
9903 /* Generate a nil HELP_EVENT to cancel a help-echo.
9904 Do it only if there's something to cancel.
9905 Otherwise, the startup message is cleared when
9906 the mouse leaves the frame. */
9907 if (any_help_event_p
)
9912 XSETFRAME (frame
, f
);
9913 n
= gen_help_event (bufp
, numchars
,
9914 Qnil
, frame
, Qnil
, Qnil
, 0);
9915 bufp
+= n
, count
+= n
, numchars
-= n
;
9918 #ifdef LESSTIF_VERSION
9919 /* Please see the comment at the start of the
9920 EnterNotify case. */
9921 if (!event
.xcrossing
.focus
9922 && f
->output_data
.x
->menubar_widget
)
9926 XGetInputFocus (FRAME_X_DISPLAY (f
), &focus
, &revert
);
9927 if (focus
== XtWindow (f
->output_data
.x
->menubar_widget
))
9928 from_menu_bar_p
= 1;
9930 #endif /* LESSTIF_VERSION */
9932 if (event
.xcrossing
.focus
|| from_menu_bar_p
)
9933 x_mouse_leave (dpyinfo
);
9936 if (f
== dpyinfo
->x_focus_event_frame
)
9937 dpyinfo
->x_focus_event_frame
= 0;
9938 if (f
== dpyinfo
->x_focus_frame
)
9939 x_new_focus_frame (dpyinfo
, 0);
9945 f
= x_any_window_to_frame (dpyinfo
, event
.xfocus
.window
);
9946 if (event
.xfocus
.detail
!= NotifyPointer
9947 && f
== dpyinfo
->x_focus_event_frame
)
9948 dpyinfo
->x_focus_event_frame
= 0;
9949 if (f
&& f
== dpyinfo
->x_focus_frame
)
9950 x_new_focus_frame (dpyinfo
, 0);
9953 if (f
&& FRAME_XIC (f
))
9954 XUnsetICFocus (FRAME_XIC (f
));
9961 previous_help_echo
= help_echo
;
9962 help_echo
= help_echo_object
= help_echo_window
= Qnil
;
9965 if (dpyinfo
->grabbed
&& last_mouse_frame
9966 && FRAME_LIVE_P (last_mouse_frame
))
9967 f
= last_mouse_frame
;
9969 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
9972 note_mouse_movement (f
, &event
.xmotion
);
9975 #ifndef USE_TOOLKIT_SCROLL_BARS
9976 struct scroll_bar
*bar
9977 = x_window_to_scroll_bar (event
.xmotion
.window
);
9980 x_scroll_bar_note_movement (bar
, &event
);
9981 #endif /* USE_TOOLKIT_SCROLL_BARS */
9983 /* If we move outside the frame, then we're
9984 certainly no longer on any text in the frame. */
9985 clear_mouse_face (dpyinfo
);
9988 /* If the contents of the global variable help_echo
9989 has changed, generate a HELP_EVENT. */
9990 if (!NILP (help_echo
)
9991 || !NILP (previous_help_echo
))
9997 XSETFRAME (frame
, f
);
10001 any_help_event_p
= 1;
10002 n
= gen_help_event (bufp
, numchars
, help_echo
, frame
,
10003 help_echo_window
, help_echo_object
,
10005 bufp
+= n
, count
+= n
, numchars
-= n
;
10011 case ConfigureNotify
:
10012 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
10015 #ifndef USE_X_TOOLKIT
10016 int rows
= PIXEL_TO_CHAR_HEIGHT (f
, event
.xconfigure
.height
);
10017 int columns
= PIXEL_TO_CHAR_WIDTH (f
, event
.xconfigure
.width
);
10019 /* In the toolkit version, change_frame_size
10020 is called by the code that handles resizing
10021 of the EmacsFrame widget. */
10023 /* Even if the number of character rows and columns has
10024 not changed, the font size may have changed, so we need
10025 to check the pixel dimensions as well. */
10026 if (columns
!= f
->width
10027 || rows
!= f
->height
10028 || event
.xconfigure
.width
!= f
->output_data
.x
->pixel_width
10029 || event
.xconfigure
.height
!= f
->output_data
.x
->pixel_height
)
10031 change_frame_size (f
, rows
, columns
, 0, 1, 0);
10032 SET_FRAME_GARBAGED (f
);
10033 cancel_mouse_face (f
);
10037 f
->output_data
.x
->pixel_width
= event
.xconfigure
.width
;
10038 f
->output_data
.x
->pixel_height
= event
.xconfigure
.height
;
10040 /* What we have now is the position of Emacs's own window.
10041 Convert that to the position of the window manager window. */
10042 x_real_positions (f
, &f
->output_data
.x
->left_pos
,
10043 &f
->output_data
.x
->top_pos
);
10046 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
10047 xic_set_statusarea (f
);
10050 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
10052 /* Since the WM decorations come below top_pos now,
10053 we must put them below top_pos in the future. */
10054 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
10055 x_wm_set_size_hint (f
, (long) 0, 0);
10058 /* Some window managers pass (0,0) as the location of
10059 the window, and the Motif event handler stores it
10060 in the emacs widget, which messes up Motif menus. */
10061 if (event
.xconfigure
.x
== 0 && event
.xconfigure
.y
== 0)
10063 event
.xconfigure
.x
= f
->output_data
.x
->widget
->core
.x
;
10064 event
.xconfigure
.y
= f
->output_data
.x
->widget
->core
.y
;
10066 #endif /* USE_MOTIF */
10071 case ButtonRelease
:
10073 /* If we decide we want to generate an event to be seen
10074 by the rest of Emacs, we put it here. */
10075 struct input_event emacs_event
;
10076 int tool_bar_p
= 0;
10078 emacs_event
.kind
= no_event
;
10079 bzero (&compose_status
, sizeof (compose_status
));
10081 if (dpyinfo
->grabbed
10082 && last_mouse_frame
10083 && FRAME_LIVE_P (last_mouse_frame
))
10084 f
= last_mouse_frame
;
10086 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
10090 /* Is this in the tool-bar? */
10091 if (WINDOWP (f
->tool_bar_window
)
10092 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
))
10094 Lisp_Object window
;
10097 x
= event
.xbutton
.x
;
10098 y
= event
.xbutton
.y
;
10101 window
= window_from_coordinates (f
, x
, y
, &p
, 1);
10102 if (EQ (window
, f
->tool_bar_window
))
10104 x_handle_tool_bar_click (f
, &event
.xbutton
);
10110 if (!dpyinfo
->x_focus_frame
10111 || f
== dpyinfo
->x_focus_frame
)
10112 construct_mouse_click (&emacs_event
, &event
, f
);
10116 #ifndef USE_TOOLKIT_SCROLL_BARS
10117 struct scroll_bar
*bar
10118 = x_window_to_scroll_bar (event
.xbutton
.window
);
10121 x_scroll_bar_handle_click (bar
, &event
, &emacs_event
);
10122 #endif /* not USE_TOOLKIT_SCROLL_BARS */
10125 if (event
.type
== ButtonPress
)
10127 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
10128 last_mouse_frame
= f
;
10129 /* Ignore any mouse motion that happened
10130 before this event; any subsequent mouse-movement
10131 Emacs events should reflect only motion after
10132 the ButtonPress. */
10134 f
->mouse_moved
= 0;
10137 last_tool_bar_item
= -1;
10141 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
10144 if (numchars
>= 1 && emacs_event
.kind
!= no_event
)
10146 bcopy (&emacs_event
, bufp
, sizeof (struct input_event
));
10152 #ifdef USE_X_TOOLKIT
10153 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
10154 /* For a down-event in the menu bar,
10155 don't pass it to Xt right now.
10156 Instead, save it away
10157 and we will pass it to Xt from kbd_buffer_get_event.
10158 That way, we can run some Lisp code first. */
10159 if (f
&& event
.type
== ButtonPress
10160 /* Verify the event is really within the menu bar
10161 and not just sent to it due to grabbing. */
10162 && event
.xbutton
.x
>= 0
10163 && event
.xbutton
.x
< f
->output_data
.x
->pixel_width
10164 && event
.xbutton
.y
>= 0
10165 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
10166 && event
.xbutton
.same_screen
)
10168 SET_SAVED_BUTTON_EVENT
;
10169 XSETFRAME (last_mouse_press_frame
, f
);
10171 else if (event
.type
== ButtonPress
)
10173 last_mouse_press_frame
= Qnil
;
10177 #ifdef USE_MOTIF /* This should do not harm for Lucid,
10178 but I am trying to be cautious. */
10179 else if (event
.type
== ButtonRelease
)
10181 if (!NILP (last_mouse_press_frame
))
10183 f
= XFRAME (last_mouse_press_frame
);
10184 if (f
->output_data
.x
)
10185 SET_SAVED_BUTTON_EVENT
;
10190 #endif /* USE_MOTIF */
10193 #endif /* USE_X_TOOLKIT */
10197 case CirculateNotify
:
10200 case CirculateRequest
:
10203 case VisibilityNotify
:
10206 case MappingNotify
:
10207 /* Someone has changed the keyboard mapping - update the
10209 switch (event
.xmapping
.request
)
10211 case MappingModifier
:
10212 x_find_modifier_meanings (dpyinfo
);
10213 /* This is meant to fall through. */
10214 case MappingKeyboard
:
10215 XRefreshKeyboardMapping (&event
.xmapping
);
10221 #ifdef USE_X_TOOLKIT
10223 XtDispatchEvent (&event
);
10225 #endif /* USE_X_TOOLKIT */
10233 /* On some systems, an X bug causes Emacs to get no more events
10234 when the window is destroyed. Detect that. (1994.) */
10237 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
10238 One XNOOP in 100 loops will make Emacs terminate.
10239 B. Bretthauer, 1994 */
10241 if (x_noop_count
>= 100)
10245 if (next_noop_dpyinfo
== 0)
10246 next_noop_dpyinfo
= x_display_list
;
10248 XNoOp (next_noop_dpyinfo
->display
);
10250 /* Each time we get here, cycle through the displays now open. */
10251 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
10255 /* If the focus was just given to an auto-raising frame,
10257 /* ??? This ought to be able to handle more than one such frame. */
10258 if (pending_autoraise_frame
)
10260 x_raise_frame (pending_autoraise_frame
);
10261 pending_autoraise_frame
= 0;
10272 /***********************************************************************
10274 ***********************************************************************/
10276 /* Note if the text cursor of window W has been overwritten by a
10277 drawing operation that outputs N glyphs starting at HPOS in the
10278 line given by output_cursor.vpos. N < 0 means all the rest of the
10279 line after HPOS has been written. */
10282 note_overwritten_text_cursor (w
, hpos
, n
)
10286 if (updated_area
== TEXT_AREA
10287 && output_cursor
.vpos
== w
->phys_cursor
.vpos
10288 && hpos
<= w
->phys_cursor
.hpos
10290 || hpos
+ n
> w
->phys_cursor
.hpos
))
10291 w
->phys_cursor_on_p
= 0;
10295 /* Set clipping for output in glyph row ROW. W is the window in which
10296 we operate. GC is the graphics context to set clipping in.
10297 WHOLE_LINE_P non-zero means include the areas used for truncation
10298 mark display and alike in the clipping rectangle.
10300 ROW may be a text row or, e.g., a mode line. Text rows must be
10301 clipped to the interior of the window dedicated to text display,
10302 mode lines must be clipped to the whole window. */
10305 x_clip_to_row (w
, row
, gc
, whole_line_p
)
10307 struct glyph_row
*row
;
10311 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10312 XRectangle clip_rect
;
10313 int window_x
, window_y
, window_width
, window_height
;
10315 window_box (w
, -1, &window_x
, &window_y
, &window_width
, &window_height
);
10317 clip_rect
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, 0);
10318 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
10319 clip_rect
.y
= max (clip_rect
.y
, window_y
);
10320 clip_rect
.width
= window_width
;
10321 clip_rect
.height
= row
->visible_height
;
10323 /* If clipping to the whole line, including trunc marks, extend
10324 the rectangle to the left and increase its width. */
10327 clip_rect
.x
-= FRAME_X_LEFT_FLAGS_AREA_WIDTH (f
);
10328 clip_rect
.width
+= FRAME_X_FLAGS_AREA_WIDTH (f
);
10331 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
10335 /* Draw a hollow box cursor on window W in glyph row ROW. */
10338 x_draw_hollow_cursor (w
, row
)
10340 struct glyph_row
*row
;
10342 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10343 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10344 Display
*dpy
= FRAME_X_DISPLAY (f
);
10347 struct glyph
*cursor_glyph
;
10350 /* Compute frame-relative coordinates from window-relative
10352 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
10353 y
= (WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
)
10354 + row
->ascent
- w
->phys_cursor_ascent
);
10355 h
= row
->height
- 1;
10357 /* Get the glyph the cursor is on. If we can't tell because
10358 the current matrix is invalid or such, give up. */
10359 cursor_glyph
= get_phys_cursor_glyph (w
);
10360 if (cursor_glyph
== NULL
)
10363 /* Compute the width of the rectangle to draw. If on a stretch
10364 glyph, and `x-stretch-block-cursor' is nil, don't draw a
10365 rectangle as wide as the glyph, but use a canonical character
10367 wd
= cursor_glyph
->pixel_width
- 1;
10368 if (cursor_glyph
->type
== STRETCH_GLYPH
10369 && !x_stretch_cursor_p
)
10370 wd
= min (CANON_X_UNIT (f
), wd
);
10372 /* The foreground of cursor_gc is typically the same as the normal
10373 background color, which can cause the cursor box to be invisible. */
10374 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
10375 if (dpyinfo
->scratch_cursor_gc
)
10376 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
10378 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
10379 GCForeground
, &xgcv
);
10380 gc
= dpyinfo
->scratch_cursor_gc
;
10382 /* Set clipping, draw the rectangle, and reset clipping again. */
10383 x_clip_to_row (w
, row
, gc
, 0);
10384 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
);
10385 XSetClipMask (dpy
, gc
, None
);
10389 /* Draw a bar cursor on window W in glyph row ROW.
10391 Implementation note: One would like to draw a bar cursor with an
10392 angle equal to the one given by the font property XA_ITALIC_ANGLE.
10393 Unfortunately, I didn't find a font yet that has this property set.
10397 x_draw_bar_cursor (w
, row
, width
)
10399 struct glyph_row
*row
;
10402 struct frame
*f
= XFRAME (w
->frame
);
10403 struct glyph
*cursor_glyph
;
10406 unsigned long mask
;
10411 /* If cursor is out of bounds, don't draw garbage. This can happen
10412 in mini-buffer windows when switching between echo area glyphs
10413 and mini-buffer. */
10414 cursor_glyph
= get_phys_cursor_glyph (w
);
10415 if (cursor_glyph
== NULL
)
10418 /* If on an image, draw like a normal cursor. That's usually better
10419 visible than drawing a bar, esp. if the image is large so that
10420 the bar might not be in the window. */
10421 if (cursor_glyph
->type
== IMAGE_GLYPH
)
10423 struct glyph_row
*row
;
10424 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
10425 x_draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
10429 xgcv
.background
= f
->output_data
.x
->cursor_pixel
;
10430 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
10431 xgcv
.graphics_exposures
= 0;
10432 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
10433 dpy
= FRAME_X_DISPLAY (f
);
10434 window
= FRAME_X_WINDOW (f
);
10435 gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
10438 XChangeGC (dpy
, gc
, mask
, &xgcv
);
10441 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
10442 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
10446 width
= f
->output_data
.x
->cursor_width
;
10448 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
10449 x_clip_to_row (w
, row
, gc
, 0);
10450 XFillRectangle (dpy
, window
, gc
,
10452 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
10453 min (cursor_glyph
->pixel_width
, width
),
10455 XSetClipMask (dpy
, gc
, None
);
10460 /* Clear the cursor of window W to background color, and mark the
10461 cursor as not shown. This is used when the text where the cursor
10462 is is about to be rewritten. */
10468 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
10469 x_update_window_cursor (w
, 0);
10473 /* Draw the cursor glyph of window W in glyph row ROW. See the
10474 comment of x_draw_glyphs for the meaning of HL. */
10477 x_draw_phys_cursor_glyph (w
, row
, hl
)
10479 struct glyph_row
*row
;
10480 enum draw_glyphs_face hl
;
10482 /* If cursor hpos is out of bounds, don't draw garbage. This can
10483 happen in mini-buffer windows when switching between echo area
10484 glyphs and mini-buffer. */
10485 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
10487 x_draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
10488 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
10491 /* When we erase the cursor, and ROW is overlapped by other
10492 rows, make sure that these overlapping parts of other rows
10494 if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
10496 if (row
> w
->current_matrix
->rows
10497 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
10498 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
10500 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
10501 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
10502 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
10508 /* Erase the image of a cursor of window W from the screen. */
10511 x_erase_phys_cursor (w
)
10514 struct frame
*f
= XFRAME (w
->frame
);
10515 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10516 int hpos
= w
->phys_cursor
.hpos
;
10517 int vpos
= w
->phys_cursor
.vpos
;
10518 int mouse_face_here_p
= 0;
10519 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
10520 struct glyph_row
*cursor_row
;
10521 struct glyph
*cursor_glyph
;
10522 enum draw_glyphs_face hl
;
10524 /* No cursor displayed or row invalidated => nothing to do on the
10526 if (w
->phys_cursor_type
== NO_CURSOR
)
10527 goto mark_cursor_off
;
10529 /* VPOS >= active_glyphs->nrows means that window has been resized.
10530 Don't bother to erase the cursor. */
10531 if (vpos
>= active_glyphs
->nrows
)
10532 goto mark_cursor_off
;
10534 /* If row containing cursor is marked invalid, there is nothing we
10536 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
10537 if (!cursor_row
->enabled_p
)
10538 goto mark_cursor_off
;
10540 /* This can happen when the new row is shorter than the old one.
10541 In this case, either x_draw_glyphs or clear_end_of_line
10542 should have cleared the cursor. Note that we wouldn't be
10543 able to erase the cursor in this case because we don't have a
10544 cursor glyph at hand. */
10545 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
10546 goto mark_cursor_off
;
10548 /* If the cursor is in the mouse face area, redisplay that when
10549 we clear the cursor. */
10550 if (! NILP (dpyinfo
->mouse_face_window
)
10551 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
10552 && (vpos
> dpyinfo
->mouse_face_beg_row
10553 || (vpos
== dpyinfo
->mouse_face_beg_row
10554 && hpos
>= dpyinfo
->mouse_face_beg_col
))
10555 && (vpos
< dpyinfo
->mouse_face_end_row
10556 || (vpos
== dpyinfo
->mouse_face_end_row
10557 && hpos
< dpyinfo
->mouse_face_end_col
))
10558 /* Don't redraw the cursor's spot in mouse face if it is at the
10559 end of a line (on a newline). The cursor appears there, but
10560 mouse highlighting does not. */
10561 && cursor_row
->used
[TEXT_AREA
] > hpos
)
10562 mouse_face_here_p
= 1;
10564 /* Maybe clear the display under the cursor. */
10565 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
10568 int header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
10570 cursor_glyph
= get_phys_cursor_glyph (w
);
10571 if (cursor_glyph
== NULL
)
10572 goto mark_cursor_off
;
10574 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
10576 XClearArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10578 WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
10580 cursor_glyph
->pixel_width
,
10581 cursor_row
->visible_height
,
10585 /* Erase the cursor by redrawing the character underneath it. */
10586 if (mouse_face_here_p
)
10587 hl
= DRAW_MOUSE_FACE
;
10588 else if (cursor_row
->inverse_p
)
10589 hl
= DRAW_INVERSE_VIDEO
;
10591 hl
= DRAW_NORMAL_TEXT
;
10592 x_draw_phys_cursor_glyph (w
, cursor_row
, hl
);
10595 w
->phys_cursor_on_p
= 0;
10596 w
->phys_cursor_type
= NO_CURSOR
;
10600 /* Display or clear cursor of window W. If ON is zero, clear the
10601 cursor. If it is non-zero, display the cursor. If ON is nonzero,
10602 where to put the cursor is specified by HPOS, VPOS, X and Y. */
10605 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
10607 int on
, hpos
, vpos
, x
, y
;
10609 struct frame
*f
= XFRAME (w
->frame
);
10610 int new_cursor_type
;
10611 int new_cursor_width
;
10612 struct glyph_matrix
*current_glyphs
;
10613 struct glyph_row
*glyph_row
;
10614 struct glyph
*glyph
;
10616 /* This is pointless on invisible frames, and dangerous on garbaged
10617 windows and frames; in the latter case, the frame or window may
10618 be in the midst of changing its size, and x and y may be off the
10620 if (! FRAME_VISIBLE_P (f
)
10621 || FRAME_GARBAGED_P (f
)
10622 || vpos
>= w
->current_matrix
->nrows
10623 || hpos
>= w
->current_matrix
->matrix_w
)
10626 /* If cursor is off and we want it off, return quickly. */
10627 if (!on
&& !w
->phys_cursor_on_p
)
10630 current_glyphs
= w
->current_matrix
;
10631 glyph_row
= MATRIX_ROW (current_glyphs
, vpos
);
10632 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
10634 /* If cursor row is not enabled, we don't really know where to
10635 display the cursor. */
10636 if (!glyph_row
->enabled_p
)
10638 w
->phys_cursor_on_p
= 0;
10642 xassert (interrupt_input_blocked
);
10644 /* Set new_cursor_type to the cursor we want to be displayed. In a
10645 mini-buffer window, we want the cursor only to appear if we are
10646 reading input from this window. For the selected window, we want
10647 the cursor type given by the frame parameter. If explicitly
10648 marked off, draw no cursor. In all other cases, we want a hollow
10650 new_cursor_width
= -1;
10651 if (cursor_in_echo_area
10652 && FRAME_HAS_MINIBUF_P (f
)
10653 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
10655 if (w
== XWINDOW (echo_area_window
))
10656 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
10658 new_cursor_type
= HOLLOW_BOX_CURSOR
;
10662 if (w
!= XWINDOW (selected_window
)
10663 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
10665 extern int cursor_in_non_selected_windows
;
10667 if (MINI_WINDOW_P (w
)
10668 || !cursor_in_non_selected_windows
10669 || NILP (XBUFFER (w
->buffer
)->cursor_type
))
10670 new_cursor_type
= NO_CURSOR
;
10672 new_cursor_type
= HOLLOW_BOX_CURSOR
;
10674 else if (w
->cursor_off_p
)
10675 new_cursor_type
= NO_CURSOR
;
10678 struct buffer
*b
= XBUFFER (w
->buffer
);
10680 if (EQ (b
->cursor_type
, Qt
))
10681 new_cursor_type
= FRAME_DESIRED_CURSOR (f
);
10683 new_cursor_type
= x_specified_cursor_type (b
->cursor_type
,
10684 &new_cursor_width
);
10688 /* If cursor is currently being shown and we don't want it to be or
10689 it is in the wrong place, or the cursor type is not what we want,
10691 if (w
->phys_cursor_on_p
10693 || w
->phys_cursor
.x
!= x
10694 || w
->phys_cursor
.y
!= y
10695 || new_cursor_type
!= w
->phys_cursor_type
))
10696 x_erase_phys_cursor (w
);
10698 /* If the cursor is now invisible and we want it to be visible,
10700 if (on
&& !w
->phys_cursor_on_p
)
10702 w
->phys_cursor_ascent
= glyph_row
->ascent
;
10703 w
->phys_cursor_height
= glyph_row
->height
;
10705 /* Set phys_cursor_.* before x_draw_.* is called because some
10706 of them may need the information. */
10707 w
->phys_cursor
.x
= x
;
10708 w
->phys_cursor
.y
= glyph_row
->y
;
10709 w
->phys_cursor
.hpos
= hpos
;
10710 w
->phys_cursor
.vpos
= vpos
;
10711 w
->phys_cursor_type
= new_cursor_type
;
10712 w
->phys_cursor_on_p
= 1;
10714 switch (new_cursor_type
)
10716 case HOLLOW_BOX_CURSOR
:
10717 x_draw_hollow_cursor (w
, glyph_row
);
10720 case FILLED_BOX_CURSOR
:
10721 x_draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
10725 x_draw_bar_cursor (w
, glyph_row
, new_cursor_width
);
10736 if (w
== XWINDOW (f
->selected_window
))
10737 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
10738 xic_set_preeditarea (w
, x
, y
);
10743 if (updating_frame
!= f
)
10744 XFlush (FRAME_X_DISPLAY (f
));
10749 /* Display the cursor on window W, or clear it. X and Y are window
10750 relative pixel coordinates. HPOS and VPOS are glyph matrix
10751 positions. If W is not the selected window, display a hollow
10752 cursor. ON non-zero means display the cursor at X, Y which
10753 correspond to HPOS, VPOS, otherwise it is cleared. */
10756 x_display_cursor (w
, on
, hpos
, vpos
, x
, y
)
10758 int on
, hpos
, vpos
, x
, y
;
10761 x_display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
);
10766 /* Display the cursor on window W, or clear it, according to ON_P.
10767 Don't change the cursor's position. */
10770 x_update_cursor (f
, on_p
)
10773 x_update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
10777 /* Call x_update_window_cursor with parameter ON_P on all leaf windows
10778 in the window tree rooted at W. */
10781 x_update_cursor_in_window_tree (w
, on_p
)
10787 if (!NILP (w
->hchild
))
10788 x_update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
10789 else if (!NILP (w
->vchild
))
10790 x_update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
10792 x_update_window_cursor (w
, on_p
);
10794 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
10799 /* Switch the display of W's cursor on or off, according to the value
10803 x_update_window_cursor (w
, on
)
10807 /* Don't update cursor in windows whose frame is in the process
10808 of being deleted. */
10809 if (w
->current_matrix
)
10812 x_display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
10813 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
10823 /* Refresh bitmap kitchen sink icon for frame F
10824 when we get an expose event for it. */
10830 /* Normally, the window manager handles this function. */
10833 /* Make the x-window of frame F use the gnu icon bitmap. */
10836 x_bitmap_icon (f
, file
)
10842 if (FRAME_X_WINDOW (f
) == 0)
10845 /* Free up our existing icon bitmap if any. */
10846 if (f
->output_data
.x
->icon_bitmap
> 0)
10847 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
10848 f
->output_data
.x
->icon_bitmap
= 0;
10850 if (STRINGP (file
))
10851 bitmap_id
= x_create_bitmap_from_file (f
, file
);
10854 /* Create the GNU bitmap if necessary. */
10855 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
10856 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
10857 = x_create_bitmap_from_data (f
, gnu_bits
,
10858 gnu_width
, gnu_height
);
10860 /* The first time we create the GNU bitmap,
10861 this increments the ref-count one extra time.
10862 As a result, the GNU bitmap is never freed.
10863 That way, we don't have to worry about allocating it again. */
10864 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
10866 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
10869 x_wm_set_icon_pixmap (f
, bitmap_id
);
10870 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
10876 /* Make the x-window of frame F use a rectangle with text.
10877 Use ICON_NAME as the text. */
10880 x_text_icon (f
, icon_name
)
10884 if (FRAME_X_WINDOW (f
) == 0)
10889 XTextProperty text
;
10890 text
.value
= (unsigned char *) icon_name
;
10891 text
.encoding
= XA_STRING
;
10893 text
.nitems
= strlen (icon_name
);
10894 #ifdef USE_X_TOOLKIT
10895 XSetWMIconName (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
10897 #else /* not USE_X_TOOLKIT */
10898 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &text
);
10899 #endif /* not USE_X_TOOLKIT */
10901 #else /* not HAVE_X11R4 */
10902 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), icon_name
);
10903 #endif /* not HAVE_X11R4 */
10905 if (f
->output_data
.x
->icon_bitmap
> 0)
10906 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
10907 f
->output_data
.x
->icon_bitmap
= 0;
10908 x_wm_set_icon_pixmap (f
, 0);
10913 #define X_ERROR_MESSAGE_SIZE 200
10915 /* If non-nil, this should be a string.
10916 It means catch X errors and store the error message in this string. */
10918 static Lisp_Object x_error_message_string
;
10920 /* An X error handler which stores the error message in
10921 x_error_message_string. This is called from x_error_handler if
10922 x_catch_errors is in effect. */
10925 x_error_catcher (display
, error
)
10927 XErrorEvent
*error
;
10929 XGetErrorText (display
, error
->error_code
,
10930 XSTRING (x_error_message_string
)->data
,
10931 X_ERROR_MESSAGE_SIZE
);
10934 /* Begin trapping X errors for display DPY. Actually we trap X errors
10935 for all displays, but DPY should be the display you are actually
10938 After calling this function, X protocol errors no longer cause
10939 Emacs to exit; instead, they are recorded in the string
10940 stored in x_error_message_string.
10942 Calling x_check_errors signals an Emacs error if an X error has
10943 occurred since the last call to x_catch_errors or x_check_errors.
10945 Calling x_uncatch_errors resumes the normal error handling. */
10947 void x_check_errors ();
10948 static Lisp_Object
x_catch_errors_unwind ();
10951 x_catch_errors (dpy
)
10954 int count
= specpdl_ptr
- specpdl
;
10956 /* Make sure any errors from previous requests have been dealt with. */
10957 XSync (dpy
, False
);
10959 record_unwind_protect (x_catch_errors_unwind
, x_error_message_string
);
10961 x_error_message_string
= make_uninit_string (X_ERROR_MESSAGE_SIZE
);
10962 XSTRING (x_error_message_string
)->data
[0] = 0;
10967 /* Unbind the binding that we made to check for X errors. */
10970 x_catch_errors_unwind (old_val
)
10971 Lisp_Object old_val
;
10973 x_error_message_string
= old_val
;
10977 /* If any X protocol errors have arrived since the last call to
10978 x_catch_errors or x_check_errors, signal an Emacs error using
10979 sprintf (a buffer, FORMAT, the x error message text) as the text. */
10982 x_check_errors (dpy
, format
)
10986 /* Make sure to catch any errors incurred so far. */
10987 XSync (dpy
, False
);
10989 if (XSTRING (x_error_message_string
)->data
[0])
10990 error (format
, XSTRING (x_error_message_string
)->data
);
10993 /* Nonzero if we had any X protocol errors
10994 since we did x_catch_errors on DPY. */
10997 x_had_errors_p (dpy
)
11000 /* Make sure to catch any errors incurred so far. */
11001 XSync (dpy
, False
);
11003 return XSTRING (x_error_message_string
)->data
[0] != 0;
11006 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
11009 x_clear_errors (dpy
)
11012 XSTRING (x_error_message_string
)->data
[0] = 0;
11015 /* Stop catching X protocol errors and let them make Emacs die.
11016 DPY should be the display that was passed to x_catch_errors.
11017 COUNT should be the value that was returned by
11018 the corresponding call to x_catch_errors. */
11021 x_uncatch_errors (dpy
, count
)
11025 unbind_to (count
, Qnil
);
11029 static unsigned int x_wire_count
;
11032 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
11037 /* Handle SIGPIPE, which can happen when the connection to a server
11038 simply goes away. SIGPIPE is handled by x_connection_signal.
11039 Don't need to do anything, because the write which caused the
11040 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
11041 which will do the appropriate cleanup for us. */
11044 x_connection_signal (signalnum
) /* If we don't have an argument, */
11045 int signalnum
; /* some compilers complain in signal calls. */
11048 /* USG systems forget handlers when they are used;
11049 must reestablish each time */
11050 signal (signalnum
, x_connection_signal
);
11054 /* Handling X errors. */
11056 /* Handle the loss of connection to display DISPLAY. */
11059 x_connection_closed (display
, error_message
)
11061 char *error_message
;
11063 struct x_display_info
*dpyinfo
= x_display_info_for_display (display
);
11064 Lisp_Object frame
, tail
;
11066 /* Indicate that this display is dead. */
11068 #if 0 /* Closing the display caused a bus error on OpenWindows. */
11069 #ifdef USE_X_TOOLKIT
11070 XtCloseDisplay (display
);
11075 dpyinfo
->display
= 0;
11077 /* First delete frames whose mini-buffers are on frames
11078 that are on the dead display. */
11079 FOR_EACH_FRAME (tail
, frame
)
11081 Lisp_Object minibuf_frame
;
11083 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
11084 if (FRAME_X_P (XFRAME (frame
))
11085 && FRAME_X_P (XFRAME (minibuf_frame
))
11086 && ! EQ (frame
, minibuf_frame
)
11087 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
11088 Fdelete_frame (frame
, Qt
);
11091 /* Now delete all remaining frames on the dead display.
11092 We are now sure none of these is used as the mini-buffer
11093 for another frame that we need to delete. */
11094 FOR_EACH_FRAME (tail
, frame
)
11095 if (FRAME_X_P (XFRAME (frame
))
11096 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
11098 /* Set this to t so that Fdelete_frame won't get confused
11099 trying to find a replacement. */
11100 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
11101 Fdelete_frame (frame
, Qt
);
11105 x_delete_display (dpyinfo
);
11107 if (x_display_list
== 0)
11109 fprintf (stderr
, "%s\n", error_message
);
11110 shut_down_emacs (0, 0, Qnil
);
11114 /* Ordinary stack unwind doesn't deal with these. */
11116 sigunblock (sigmask (SIGIO
));
11118 sigunblock (sigmask (SIGALRM
));
11119 TOTALLY_UNBLOCK_INPUT
;
11121 clear_waiting_for_input ();
11122 error ("%s", error_message
);
11125 /* This is the usual handler for X protocol errors.
11126 It kills all frames on the display that we got the error for.
11127 If that was the only one, it prints an error message and kills Emacs. */
11130 x_error_quitter (display
, error
)
11132 XErrorEvent
*error
;
11134 char buf
[256], buf1
[356];
11136 /* Note that there is no real way portable across R3/R4 to get the
11137 original error handler. */
11139 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
11140 sprintf (buf1
, "X protocol error: %s on protocol request %d",
11141 buf
, error
->request_code
);
11142 x_connection_closed (display
, buf1
);
11145 /* This is the first-level handler for X protocol errors.
11146 It calls x_error_quitter or x_error_catcher. */
11149 x_error_handler (display
, error
)
11151 XErrorEvent
*error
;
11153 if (! NILP (x_error_message_string
))
11154 x_error_catcher (display
, error
);
11156 x_error_quitter (display
, error
);
11160 /* This is the handler for X IO errors, always.
11161 It kills all frames on the display that we lost touch with.
11162 If that was the only one, it prints an error message and kills Emacs. */
11165 x_io_error_quitter (display
)
11170 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
11171 x_connection_closed (display
, buf
);
11175 /* Changing the font of the frame. */
11177 /* Give frame F the font named FONTNAME as its default font, and
11178 return the full name of that font. FONTNAME may be a wildcard
11179 pattern; in that case, we choose some font that fits the pattern.
11180 The return value shows which font we chose. */
11183 x_new_font (f
, fontname
)
11185 register char *fontname
;
11187 struct font_info
*fontp
11188 = FS_LOAD_FONT (f
, 0, fontname
, -1);
11193 f
->output_data
.x
->font
= (XFontStruct
*) (fontp
->font
);
11194 f
->output_data
.x
->baseline_offset
= fontp
->baseline_offset
;
11195 f
->output_data
.x
->fontset
= -1;
11197 /* Compute the scroll bar width in character columns. */
11198 if (f
->scroll_bar_pixel_width
> 0)
11200 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
11201 f
->scroll_bar_cols
= (f
->scroll_bar_pixel_width
+ wid
-1) / wid
;
11205 int wid
= FONT_WIDTH (f
->output_data
.x
->font
);
11206 f
->scroll_bar_cols
= (14 + wid
- 1) / wid
;
11209 /* Now make the frame display the given font. */
11210 if (FRAME_X_WINDOW (f
) != 0)
11212 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
11213 f
->output_data
.x
->font
->fid
);
11214 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->reverse_gc
,
11215 f
->output_data
.x
->font
->fid
);
11216 XSetFont (FRAME_X_DISPLAY (f
), f
->output_data
.x
->cursor_gc
,
11217 f
->output_data
.x
->font
->fid
);
11219 frame_update_line_height (f
);
11220 x_set_window_size (f
, 0, f
->width
, f
->height
);
11223 /* If we are setting a new frame's font for the first time,
11224 there are no faces yet, so this font's height is the line height. */
11225 f
->output_data
.x
->line_height
= FONT_HEIGHT (f
->output_data
.x
->font
);
11227 return build_string (fontp
->full_name
);
11230 /* Give frame F the fontset named FONTSETNAME as its default font, and
11231 return the full name of that fontset. FONTSETNAME may be a wildcard
11232 pattern; in that case, we choose some fontset that fits the pattern.
11233 The return value shows which fontset we chose. */
11236 x_new_fontset (f
, fontsetname
)
11240 int fontset
= fs_query_fontset (build_string (fontsetname
), 0);
11241 Lisp_Object result
;
11246 if (f
->output_data
.x
->fontset
== fontset
)
11247 /* This fontset is already set in frame F. There's nothing more
11249 return fontset_name (fontset
);
11251 result
= x_new_font (f
, (XSTRING (fontset_ascii (fontset
))->data
));
11253 if (!STRINGP (result
))
11254 /* Can't load ASCII font. */
11257 /* Since x_new_font doesn't update any fontset information, do it now. */
11258 f
->output_data
.x
->fontset
= fontset
;
11262 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
11263 xic_set_xfontset (f
, XSTRING (fontset_ascii (fontset
))->data
);
11266 return build_string (fontsetname
);
11270 /***********************************************************************
11272 ***********************************************************************/
11278 /* XIM destroy callback function, which is called whenever the
11279 connection to input method XIM dies. CLIENT_DATA contains a
11280 pointer to the x_display_info structure corresponding to XIM. */
11283 xim_destroy_callback (xim
, client_data
, call_data
)
11285 XPointer client_data
;
11286 XPointer call_data
;
11288 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
11289 Lisp_Object frame
, tail
;
11293 /* No need to call XDestroyIC.. */
11294 FOR_EACH_FRAME (tail
, frame
)
11296 struct frame
*f
= XFRAME (frame
);
11297 if (FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
11299 FRAME_XIC (f
) = NULL
;
11300 if (FRAME_XIC_FONTSET (f
))
11302 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
11303 FRAME_XIC_FONTSET (f
) = NULL
;
11308 /* No need to call XCloseIM. */
11309 dpyinfo
->xim
= NULL
;
11310 XFree (dpyinfo
->xim_styles
);
11314 #endif /* HAVE_X11R6 */
11316 /* Open the connection to the XIM server on display DPYINFO.
11317 RESOURCE_NAME is the resource name Emacs uses. */
11320 xim_open_dpy (dpyinfo
, resource_name
)
11321 struct x_display_info
*dpyinfo
;
11322 char *resource_name
;
11327 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
, EMACS_CLASS
);
11328 dpyinfo
->xim
= xim
;
11333 XIMCallback destroy
;
11336 /* Get supported styles and XIM values. */
11337 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
11340 destroy
.callback
= xim_destroy_callback
;
11341 destroy
.client_data
= (XPointer
)dpyinfo
;
11342 /* This isn't prptotyped in OSF 5.0. */
11343 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
11347 #else /* not USE_XIM */
11348 dpyinfo
->xim
= NULL
;
11349 #endif /* not USE_XIM */
11353 #ifdef HAVE_X11R6_XIM
11357 struct x_display_info
*dpyinfo
;
11358 char *resource_name
;
11361 /* XIM instantiate callback function, which is called whenever an XIM
11362 server is available. DISPLAY is teh display of the XIM.
11363 CLIENT_DATA contains a pointer to an xim_inst_t structure created
11364 when the callback was registered. */
11367 xim_instantiate_callback (display
, client_data
, call_data
)
11369 XPointer client_data
;
11370 XPointer call_data
;
11372 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
11373 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
11375 /* We don't support multiple XIM connections. */
11379 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
11381 /* Create XIC for the existing frames on the same display, as long
11382 as they have no XIC. */
11383 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
11385 Lisp_Object tail
, frame
;
11388 FOR_EACH_FRAME (tail
, frame
)
11390 struct frame
*f
= XFRAME (frame
);
11392 if (FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
11393 if (FRAME_XIC (f
) == NULL
)
11395 create_frame_xic (f
);
11396 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
11397 xic_set_statusarea (f
);
11398 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
11400 struct window
*w
= XWINDOW (f
->selected_window
);
11401 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
11410 #endif /* HAVE_X11R6_XIM */
11413 /* Open a connection to the XIM server on display DPYINFO.
11414 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
11415 connection only at the first time. On X11R6, open the connection
11416 in the XIM instantiate callback function. */
11419 xim_initialize (dpyinfo
, resource_name
)
11420 struct x_display_info
*dpyinfo
;
11421 char *resource_name
;
11424 #ifdef HAVE_X11R6_XIM
11425 struct xim_inst_t
*xim_inst
;
11428 dpyinfo
->xim
= NULL
;
11429 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
11430 xim_inst
->dpyinfo
= dpyinfo
;
11431 len
= strlen (resource_name
);
11432 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
11433 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
11434 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
11435 resource_name
, EMACS_CLASS
,
11436 xim_instantiate_callback
,
11437 /* Fixme: This is XPointer in
11438 XFree86 but (XPointer *) on
11439 Tru64, at least. */
11440 (XPointer
) xim_inst
);
11441 #else /* not HAVE_X11R6_XIM */
11442 dpyinfo
->xim
= NULL
;
11443 xim_open_dpy (dpyinfo
, resource_name
);
11444 #endif /* not HAVE_X11R6_XIM */
11446 #else /* not USE_XIM */
11447 dpyinfo
->xim
= NULL
;
11448 #endif /* not USE_XIM */
11452 /* Close the connection to the XIM server on display DPYINFO. */
11455 xim_close_dpy (dpyinfo
)
11456 struct x_display_info
*dpyinfo
;
11459 #ifdef HAVE_X11R6_XIM
11460 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
11462 xim_instantiate_callback
, NULL
);
11463 #endif /* not HAVE_X11R6_XIM */
11464 XCloseIM (dpyinfo
->xim
);
11465 dpyinfo
->xim
= NULL
;
11466 XFree (dpyinfo
->xim_styles
);
11467 #endif /* USE_XIM */
11470 #endif /* not HAVE_X11R6_XIM */
11474 /* Calculate the absolute position in frame F
11475 from its current recorded position values and gravity. */
11478 x_calc_absolute_position (f
)
11482 int win_x
= 0, win_y
= 0;
11483 int flags
= f
->output_data
.x
->size_hint_flags
;
11486 /* We have nothing to do if the current position
11487 is already for the top-left corner. */
11488 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
11491 #ifdef USE_X_TOOLKIT
11492 this_window
= XtWindow (f
->output_data
.x
->widget
);
11494 this_window
= FRAME_X_WINDOW (f
);
11497 /* Find the position of the outside upper-left corner of
11498 the inner window, with respect to the outer window.
11499 But do this only if we will need the results. */
11500 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
11505 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
11508 x_clear_errors (FRAME_X_DISPLAY (f
));
11509 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
11511 /* From-window, to-window. */
11513 f
->output_data
.x
->parent_desc
,
11515 /* From-position, to-position. */
11516 0, 0, &win_x
, &win_y
,
11518 /* Child of win. */
11520 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
11522 Window newroot
, newparent
= 0xdeadbeef;
11523 Window
*newchildren
;
11524 unsigned int nchildren
;
11526 if (! XQueryTree (FRAME_X_DISPLAY (f
), this_window
, &newroot
,
11527 &newparent
, &newchildren
, &nchildren
))
11530 XFree ((char *) newchildren
);
11532 f
->output_data
.x
->parent_desc
= newparent
;
11538 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
11542 /* Treat negative positions as relative to the leftmost bottommost
11543 position that fits on the screen. */
11544 if (flags
& XNegative
)
11545 f
->output_data
.x
->left_pos
= (FRAME_X_DISPLAY_INFO (f
)->width
11546 - 2 * f
->output_data
.x
->border_width
- win_x
11548 + f
->output_data
.x
->left_pos
);
11550 if (flags
& YNegative
)
11552 int menubar_height
= 0;
11554 #ifdef USE_X_TOOLKIT
11555 if (f
->output_data
.x
->menubar_widget
)
11557 = (f
->output_data
.x
->menubar_widget
->core
.height
11558 + f
->output_data
.x
->menubar_widget
->core
.border_width
);
11561 f
->output_data
.x
->top_pos
= (FRAME_X_DISPLAY_INFO (f
)->height
11562 - 2 * f
->output_data
.x
->border_width
11566 + f
->output_data
.x
->top_pos
);
11569 /* The left_pos and top_pos
11570 are now relative to the top and left screen edges,
11571 so the flags should correspond. */
11572 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
11575 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
11576 to really change the position, and 0 when calling from
11577 x_make_frame_visible (in that case, XOFF and YOFF are the current
11578 position values). It is -1 when calling from x_set_frame_parameters,
11579 which means, do adjust for borders but don't change the gravity. */
11582 x_set_offset (f
, xoff
, yoff
, change_gravity
)
11584 register int xoff
, yoff
;
11585 int change_gravity
;
11587 int modified_top
, modified_left
;
11589 if (change_gravity
> 0)
11591 f
->output_data
.x
->top_pos
= yoff
;
11592 f
->output_data
.x
->left_pos
= xoff
;
11593 f
->output_data
.x
->size_hint_flags
&= ~ (XNegative
| YNegative
);
11595 f
->output_data
.x
->size_hint_flags
|= XNegative
;
11597 f
->output_data
.x
->size_hint_flags
|= YNegative
;
11598 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
11600 x_calc_absolute_position (f
);
11603 x_wm_set_size_hint (f
, (long) 0, 0);
11605 modified_left
= f
->output_data
.x
->left_pos
;
11606 modified_top
= f
->output_data
.x
->top_pos
;
11607 #if 0 /* Running on psilocin (Debian), and displaying on the NCD X-terminal,
11608 this seems to be unnecessary and incorrect. rms, 4/17/97. */
11609 /* It is a mystery why we need to add the border_width here
11610 when the frame is already visible, but experiment says we do. */
11611 if (change_gravity
!= 0)
11613 modified_left
+= f
->output_data
.x
->border_width
;
11614 modified_top
+= f
->output_data
.x
->border_width
;
11618 #ifdef USE_X_TOOLKIT
11619 XMoveWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
),
11620 modified_left
, modified_top
);
11621 #else /* not USE_X_TOOLKIT */
11622 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11623 modified_left
, modified_top
);
11624 #endif /* not USE_X_TOOLKIT */
11628 /* Call this to change the size of frame F's x-window.
11629 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
11630 for this size change and subsequent size changes.
11631 Otherwise we leave the window gravity unchanged. */
11634 x_set_window_size (f
, change_gravity
, cols
, rows
)
11636 int change_gravity
;
11639 #ifndef USE_X_TOOLKIT
11640 int pixelwidth
, pixelheight
;
11645 #ifdef USE_X_TOOLKIT
11647 /* The x and y position of the widget is clobbered by the
11648 call to XtSetValues within EmacsFrameSetCharSize.
11649 This is a real kludge, but I don't understand Xt so I can't
11650 figure out a correct fix. Can anyone else tell me? -- rms. */
11651 int xpos
= f
->output_data
.x
->widget
->core
.x
;
11652 int ypos
= f
->output_data
.x
->widget
->core
.y
;
11653 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
11654 f
->output_data
.x
->widget
->core
.x
= xpos
;
11655 f
->output_data
.x
->widget
->core
.y
= ypos
;
11658 #else /* not USE_X_TOOLKIT */
11660 check_frame_size (f
, &rows
, &cols
);
11661 f
->output_data
.x
->vertical_scroll_bar_extra
11662 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
11664 : FRAME_SCROLL_BAR_PIXEL_WIDTH (f
) > 0
11665 ? FRAME_SCROLL_BAR_PIXEL_WIDTH (f
)
11666 : (FRAME_SCROLL_BAR_COLS (f
) * FONT_WIDTH (f
->output_data
.x
->font
)));
11667 f
->output_data
.x
->flags_areas_extra
11668 = FRAME_FLAGS_AREA_WIDTH (f
);
11669 pixelwidth
= CHAR_TO_PIXEL_WIDTH (f
, cols
);
11670 pixelheight
= CHAR_TO_PIXEL_HEIGHT (f
, rows
);
11672 f
->output_data
.x
->win_gravity
= NorthWestGravity
;
11673 x_wm_set_size_hint (f
, (long) 0, 0);
11675 XSync (FRAME_X_DISPLAY (f
), False
);
11676 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11677 pixelwidth
, pixelheight
);
11679 /* Now, strictly speaking, we can't be sure that this is accurate,
11680 but the window manager will get around to dealing with the size
11681 change request eventually, and we'll hear how it went when the
11682 ConfigureNotify event gets here.
11684 We could just not bother storing any of this information here,
11685 and let the ConfigureNotify event set everything up, but that
11686 might be kind of confusing to the Lisp code, since size changes
11687 wouldn't be reported in the frame parameters until some random
11688 point in the future when the ConfigureNotify event arrives.
11690 We pass 1 for DELAY since we can't run Lisp code inside of
11692 change_frame_size (f
, rows
, cols
, 0, 1, 0);
11693 PIXEL_WIDTH (f
) = pixelwidth
;
11694 PIXEL_HEIGHT (f
) = pixelheight
;
11696 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
11697 receive in the ConfigureNotify event; if we get what we asked
11698 for, then the event won't cause the screen to become garbaged, so
11699 we have to make sure to do it here. */
11700 SET_FRAME_GARBAGED (f
);
11702 XFlush (FRAME_X_DISPLAY (f
));
11704 #endif /* not USE_X_TOOLKIT */
11706 /* If cursor was outside the new size, mark it as off. */
11707 mark_window_cursors_off (XWINDOW (f
->root_window
));
11709 /* Clear out any recollection of where the mouse highlighting was,
11710 since it might be in a place that's outside the new frame size.
11711 Actually checking whether it is outside is a pain in the neck,
11712 so don't try--just let the highlighting be done afresh with new size. */
11713 cancel_mouse_face (f
);
11718 /* Mouse warping. */
11721 x_set_mouse_position (f
, x
, y
)
11727 pix_x
= CHAR_TO_PIXEL_COL (f
, x
) + FONT_WIDTH (f
->output_data
.x
->font
) / 2;
11728 pix_y
= CHAR_TO_PIXEL_ROW (f
, y
) + f
->output_data
.x
->line_height
/ 2;
11730 if (pix_x
< 0) pix_x
= 0;
11731 if (pix_x
> PIXEL_WIDTH (f
)) pix_x
= PIXEL_WIDTH (f
);
11733 if (pix_y
< 0) pix_y
= 0;
11734 if (pix_y
> PIXEL_HEIGHT (f
)) pix_y
= PIXEL_HEIGHT (f
);
11738 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
11739 0, 0, 0, 0, pix_x
, pix_y
);
11743 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
11746 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
11752 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
11753 0, 0, 0, 0, pix_x
, pix_y
);
11757 /* focus shifting, raising and lowering. */
11760 x_focus_on_frame (f
)
11763 #if 0 /* This proves to be unpleasant. */
11767 /* I don't think that the ICCCM allows programs to do things like this
11768 without the interaction of the window manager. Whatever you end up
11769 doing with this code, do it to x_unfocus_frame too. */
11770 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11771 RevertToPointerRoot
, CurrentTime
);
11776 x_unfocus_frame (f
)
11780 /* Look at the remarks in x_focus_on_frame. */
11781 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
11782 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
11783 RevertToPointerRoot
, CurrentTime
);
11787 /* Raise frame F. */
11793 if (f
->async_visible
)
11796 #ifdef USE_X_TOOLKIT
11797 XRaiseWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
11798 #else /* not USE_X_TOOLKIT */
11799 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11800 #endif /* not USE_X_TOOLKIT */
11801 XFlush (FRAME_X_DISPLAY (f
));
11806 /* Lower frame F. */
11812 if (f
->async_visible
)
11815 #ifdef USE_X_TOOLKIT
11816 XLowerWindow (FRAME_X_DISPLAY (f
), XtWindow (f
->output_data
.x
->widget
));
11817 #else /* not USE_X_TOOLKIT */
11818 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11819 #endif /* not USE_X_TOOLKIT */
11820 XFlush (FRAME_X_DISPLAY (f
));
11826 XTframe_raise_lower (f
, raise_flag
)
11836 /* Change of visibility. */
11838 /* This tries to wait until the frame is really visible.
11839 However, if the window manager asks the user where to position
11840 the frame, this will return before the user finishes doing that.
11841 The frame will not actually be visible at that time,
11842 but it will become visible later when the window manager
11843 finishes with it. */
11846 x_make_frame_visible (f
)
11850 int original_top
, original_left
;
11851 int retry_count
= 2;
11857 type
= x_icon_type (f
);
11859 x_bitmap_icon (f
, type
);
11861 if (! FRAME_VISIBLE_P (f
))
11863 /* We test FRAME_GARBAGED_P here to make sure we don't
11864 call x_set_offset a second time
11865 if we get to x_make_frame_visible a second time
11866 before the window gets really visible. */
11867 if (! FRAME_ICONIFIED_P (f
)
11868 && ! f
->output_data
.x
->asked_for_visible
)
11869 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
11871 f
->output_data
.x
->asked_for_visible
= 1;
11873 if (! EQ (Vx_no_window_manager
, Qt
))
11874 x_wm_set_window_state (f
, NormalState
);
11875 #ifdef USE_X_TOOLKIT
11876 /* This was XtPopup, but that did nothing for an iconified frame. */
11877 XtMapWidget (f
->output_data
.x
->widget
);
11878 #else /* not USE_X_TOOLKIT */
11879 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11880 #endif /* not USE_X_TOOLKIT */
11881 #if 0 /* This seems to bring back scroll bars in the wrong places
11882 if the window configuration has changed. They seem
11883 to come back ok without this. */
11884 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
11885 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11889 XFlush (FRAME_X_DISPLAY (f
));
11891 /* Synchronize to ensure Emacs knows the frame is visible
11892 before we do anything else. We do this loop with input not blocked
11893 so that incoming events are handled. */
11897 /* This must be before UNBLOCK_INPUT
11898 since events that arrive in response to the actions above
11899 will set it when they are handled. */
11900 int previously_visible
= f
->output_data
.x
->has_been_visible
;
11902 original_left
= f
->output_data
.x
->left_pos
;
11903 original_top
= f
->output_data
.x
->top_pos
;
11905 /* This must come after we set COUNT. */
11908 /* We unblock here so that arriving X events are processed. */
11910 /* Now move the window back to where it was "supposed to be".
11911 But don't do it if the gravity is negative.
11912 When the gravity is negative, this uses a position
11913 that is 3 pixels too low. Perhaps that's really the border width.
11915 Don't do this if the window has never been visible before,
11916 because the window manager may choose the position
11917 and we don't want to override it. */
11919 if (! FRAME_VISIBLE_P (f
) && ! FRAME_ICONIFIED_P (f
)
11920 && f
->output_data
.x
->win_gravity
== NorthWestGravity
11921 && previously_visible
)
11925 unsigned int width
, height
, border
, depth
;
11929 /* On some window managers (such as FVWM) moving an existing
11930 window, even to the same place, causes the window manager
11931 to introduce an offset. This can cause the window to move
11932 to an unexpected location. Check the geometry (a little
11933 slow here) and then verify that the window is in the right
11934 place. If the window is not in the right place, move it
11935 there, and take the potential window manager hit. */
11936 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
11937 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
11939 if (original_left
!= x
|| original_top
!= y
)
11940 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
11941 original_left
, original_top
);
11946 XSETFRAME (frame
, f
);
11948 /* Wait until the frame is visible. Process X events until a
11949 MapNotify event has been seen, or until we think we won't get a
11950 MapNotify at all.. */
11951 for (count
= input_signal_count
+ 10;
11952 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
11954 /* Force processing of queued events. */
11957 /* Machines that do polling rather than SIGIO have been
11958 observed to go into a busy-wait here. So we'll fake an
11959 alarm signal to let the handler know that there's something
11960 to be read. We used to raise a real alarm, but it seems
11961 that the handler isn't always enabled here. This is
11963 if (input_polling_used ())
11965 /* It could be confusing if a real alarm arrives while
11966 processing the fake one. Turn it off and let the
11967 handler reset it. */
11968 extern void poll_for_input_1
P_ ((void));
11969 int old_poll_suppress_count
= poll_suppress_count
;
11970 poll_suppress_count
= 1;
11971 poll_for_input_1 ();
11972 poll_suppress_count
= old_poll_suppress_count
;
11975 /* See if a MapNotify event has been processed. */
11976 FRAME_SAMPLE_VISIBILITY (f
);
11981 (let ((f (selected-frame)))
11985 the frame is not raised with various window managers on
11986 FreeBSD, Linux and Solaris. It turns out that, for some
11987 unknown reason, the call to XtMapWidget is completely ignored.
11988 Mapping the widget a second time works. */
11990 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
11995 /* Change from mapped state to withdrawn state. */
11997 /* Make the frame visible (mapped and not iconified). */
12000 x_make_frame_invisible (f
)
12005 #ifdef USE_X_TOOLKIT
12006 /* Use the frame's outermost window, not the one we normally draw on. */
12007 window
= XtWindow (f
->output_data
.x
->widget
);
12008 #else /* not USE_X_TOOLKIT */
12009 window
= FRAME_X_WINDOW (f
);
12010 #endif /* not USE_X_TOOLKIT */
12012 /* Don't keep the highlight on an invisible frame. */
12013 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
12014 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
12016 #if 0/* This might add unreliability; I don't trust it -- rms. */
12017 if (! f
->async_visible
&& ! f
->async_iconified
)
12023 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
12024 that the current position of the window is user-specified, rather than
12025 program-specified, so that when the window is mapped again, it will be
12026 placed at the same location, without forcing the user to position it
12027 by hand again (they have already done that once for this window.) */
12028 x_wm_set_size_hint (f
, (long) 0, 1);
12032 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
12033 DefaultScreen (FRAME_X_DISPLAY (f
))))
12035 UNBLOCK_INPUT_RESIGNAL
;
12036 error ("Can't notify window manager of window withdrawal");
12038 #else /* ! defined (HAVE_X11R4) */
12040 /* Tell the window manager what we're going to do. */
12041 if (! EQ (Vx_no_window_manager
, Qt
))
12045 unmap
.xunmap
.type
= UnmapNotify
;
12046 unmap
.xunmap
.window
= window
;
12047 unmap
.xunmap
.event
= DefaultRootWindow (FRAME_X_DISPLAY (f
));
12048 unmap
.xunmap
.from_configure
= False
;
12049 if (! XSendEvent (FRAME_X_DISPLAY (f
),
12050 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
12052 SubstructureRedirectMaskSubstructureNotifyMask
,
12055 UNBLOCK_INPUT_RESIGNAL
;
12056 error ("Can't notify window manager of withdrawal");
12060 /* Unmap the window ourselves. Cheeky! */
12061 XUnmapWindow (FRAME_X_DISPLAY (f
), window
);
12062 #endif /* ! defined (HAVE_X11R4) */
12064 /* We can't distinguish this from iconification
12065 just by the event that we get from the server.
12066 So we can't win using the usual strategy of letting
12067 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
12068 and synchronize with the server to make sure we agree. */
12070 FRAME_ICONIFIED_P (f
) = 0;
12071 f
->async_visible
= 0;
12072 f
->async_iconified
= 0;
12079 /* Change window state from mapped to iconified. */
12082 x_iconify_frame (f
)
12088 /* Don't keep the highlight on an invisible frame. */
12089 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
12090 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
12092 if (f
->async_iconified
)
12097 FRAME_SAMPLE_VISIBILITY (f
);
12099 type
= x_icon_type (f
);
12101 x_bitmap_icon (f
, type
);
12103 #ifdef USE_X_TOOLKIT
12105 if (! FRAME_VISIBLE_P (f
))
12107 if (! EQ (Vx_no_window_manager
, Qt
))
12108 x_wm_set_window_state (f
, IconicState
);
12109 /* This was XtPopup, but that did nothing for an iconified frame. */
12110 XtMapWidget (f
->output_data
.x
->widget
);
12111 /* The server won't give us any event to indicate
12112 that an invisible frame was changed to an icon,
12113 so we have to record it here. */
12116 f
->async_iconified
= 1;
12117 f
->async_visible
= 0;
12122 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
12123 XtWindow (f
->output_data
.x
->widget
),
12124 DefaultScreen (FRAME_X_DISPLAY (f
)));
12128 error ("Can't notify window manager of iconification");
12130 f
->async_iconified
= 1;
12131 f
->async_visible
= 0;
12135 XFlush (FRAME_X_DISPLAY (f
));
12137 #else /* not USE_X_TOOLKIT */
12139 /* Make sure the X server knows where the window should be positioned,
12140 in case the user deiconifies with the window manager. */
12141 if (! FRAME_VISIBLE_P (f
) && !FRAME_ICONIFIED_P (f
))
12142 x_set_offset (f
, f
->output_data
.x
->left_pos
, f
->output_data
.x
->top_pos
, 0);
12144 /* Since we don't know which revision of X we're running, we'll use both
12145 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
12147 /* X11R4: send a ClientMessage to the window manager using the
12148 WM_CHANGE_STATE type. */
12152 message
.xclient
.window
= FRAME_X_WINDOW (f
);
12153 message
.xclient
.type
= ClientMessage
;
12154 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
12155 message
.xclient
.format
= 32;
12156 message
.xclient
.data
.l
[0] = IconicState
;
12158 if (! XSendEvent (FRAME_X_DISPLAY (f
),
12159 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
12161 SubstructureRedirectMask
| SubstructureNotifyMask
,
12164 UNBLOCK_INPUT_RESIGNAL
;
12165 error ("Can't notify window manager of iconification");
12169 /* X11R3: set the initial_state field of the window manager hints to
12171 x_wm_set_window_state (f
, IconicState
);
12173 if (!FRAME_VISIBLE_P (f
))
12175 /* If the frame was withdrawn, before, we must map it. */
12176 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
12179 f
->async_iconified
= 1;
12180 f
->async_visible
= 0;
12182 XFlush (FRAME_X_DISPLAY (f
));
12184 #endif /* not USE_X_TOOLKIT */
12187 /* Destroy the X window of frame F. */
12190 x_destroy_window (f
)
12193 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12197 /* If a display connection is dead, don't try sending more
12198 commands to the X server. */
12199 if (dpyinfo
->display
!= 0)
12201 if (f
->output_data
.x
->icon_desc
!= 0)
12202 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
12205 free_frame_xic (f
);
12207 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->window_desc
);
12208 #ifdef USE_X_TOOLKIT
12209 if (f
->output_data
.x
->widget
)
12210 XtDestroyWidget (f
->output_data
.x
->widget
);
12211 free_frame_menubar (f
);
12212 #endif /* USE_X_TOOLKIT */
12214 unload_color (f
, f
->output_data
.x
->foreground_pixel
);
12215 unload_color (f
, f
->output_data
.x
->background_pixel
);
12216 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
12217 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
12218 unload_color (f
, f
->output_data
.x
->border_pixel
);
12219 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
12220 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
12221 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
12222 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
12223 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
12224 if (f
->output_data
.x
->white_relief
.allocated_p
)
12225 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
12226 if (f
->output_data
.x
->black_relief
.allocated_p
)
12227 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
12229 free_frame_faces (f
);
12230 XFlush (FRAME_X_DISPLAY (f
));
12233 if (f
->output_data
.x
->saved_menu_event
)
12234 xfree (f
->output_data
.x
->saved_menu_event
);
12236 xfree (f
->output_data
.x
);
12237 f
->output_data
.x
= 0;
12238 if (f
== dpyinfo
->x_focus_frame
)
12239 dpyinfo
->x_focus_frame
= 0;
12240 if (f
== dpyinfo
->x_focus_event_frame
)
12241 dpyinfo
->x_focus_event_frame
= 0;
12242 if (f
== dpyinfo
->x_highlight_frame
)
12243 dpyinfo
->x_highlight_frame
= 0;
12245 dpyinfo
->reference_count
--;
12247 if (f
== dpyinfo
->mouse_face_mouse_frame
)
12249 dpyinfo
->mouse_face_beg_row
12250 = dpyinfo
->mouse_face_beg_col
= -1;
12251 dpyinfo
->mouse_face_end_row
12252 = dpyinfo
->mouse_face_end_col
= -1;
12253 dpyinfo
->mouse_face_window
= Qnil
;
12254 dpyinfo
->mouse_face_deferred_gc
= 0;
12255 dpyinfo
->mouse_face_mouse_frame
= 0;
12261 /* Setting window manager hints. */
12263 /* Set the normal size hints for the window manager, for frame F.
12264 FLAGS is the flags word to use--or 0 meaning preserve the flags
12265 that the window now has.
12266 If USER_POSITION is nonzero, we set the USPosition
12267 flag (this is useful when FLAGS is 0). */
12270 x_wm_set_size_hint (f
, flags
, user_position
)
12275 XSizeHints size_hints
;
12277 #ifdef USE_X_TOOLKIT
12280 Dimension widget_width
, widget_height
;
12281 Window window
= XtWindow (f
->output_data
.x
->widget
);
12282 #else /* not USE_X_TOOLKIT */
12283 Window window
= FRAME_X_WINDOW (f
);
12284 #endif /* not USE_X_TOOLKIT */
12286 /* Setting PMaxSize caused various problems. */
12287 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
12289 size_hints
.x
= f
->output_data
.x
->left_pos
;
12290 size_hints
.y
= f
->output_data
.x
->top_pos
;
12292 #ifdef USE_X_TOOLKIT
12293 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
12294 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
12295 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
12296 size_hints
.height
= widget_height
;
12297 size_hints
.width
= widget_width
;
12298 #else /* not USE_X_TOOLKIT */
12299 size_hints
.height
= PIXEL_HEIGHT (f
);
12300 size_hints
.width
= PIXEL_WIDTH (f
);
12301 #endif /* not USE_X_TOOLKIT */
12303 size_hints
.width_inc
= FONT_WIDTH (f
->output_data
.x
->font
);
12304 size_hints
.height_inc
= f
->output_data
.x
->line_height
;
12305 size_hints
.max_width
12306 = FRAME_X_DISPLAY_INFO (f
)->width
- CHAR_TO_PIXEL_WIDTH (f
, 0);
12307 size_hints
.max_height
12308 = FRAME_X_DISPLAY_INFO (f
)->height
- CHAR_TO_PIXEL_HEIGHT (f
, 0);
12310 /* Calculate the base and minimum sizes.
12312 (When we use the X toolkit, we don't do it here.
12313 Instead we copy the values that the widgets are using, below.) */
12314 #ifndef USE_X_TOOLKIT
12316 int base_width
, base_height
;
12317 int min_rows
= 0, min_cols
= 0;
12319 base_width
= CHAR_TO_PIXEL_WIDTH (f
, 0);
12320 base_height
= CHAR_TO_PIXEL_HEIGHT (f
, 0);
12322 check_frame_size (f
, &min_rows
, &min_cols
);
12324 /* The window manager uses the base width hints to calculate the
12325 current number of rows and columns in the frame while
12326 resizing; min_width and min_height aren't useful for this
12327 purpose, since they might not give the dimensions for a
12328 zero-row, zero-column frame.
12330 We use the base_width and base_height members if we have
12331 them; otherwise, we set the min_width and min_height members
12332 to the size for a zero x zero frame. */
12335 size_hints
.flags
|= PBaseSize
;
12336 size_hints
.base_width
= base_width
;
12337 size_hints
.base_height
= base_height
;
12338 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
12339 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
12341 size_hints
.min_width
= base_width
;
12342 size_hints
.min_height
= base_height
;
12346 /* If we don't need the old flags, we don't need the old hint at all. */
12349 size_hints
.flags
|= flags
;
12352 #endif /* not USE_X_TOOLKIT */
12355 XSizeHints hints
; /* Sometimes I hate X Windows... */
12356 long supplied_return
;
12360 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
12363 value
= XGetNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
);
12366 #ifdef USE_X_TOOLKIT
12367 size_hints
.base_height
= hints
.base_height
;
12368 size_hints
.base_width
= hints
.base_width
;
12369 size_hints
.min_height
= hints
.min_height
;
12370 size_hints
.min_width
= hints
.min_width
;
12374 size_hints
.flags
|= flags
;
12379 if (hints
.flags
& PSize
)
12380 size_hints
.flags
|= PSize
;
12381 if (hints
.flags
& PPosition
)
12382 size_hints
.flags
|= PPosition
;
12383 if (hints
.flags
& USPosition
)
12384 size_hints
.flags
|= USPosition
;
12385 if (hints
.flags
& USSize
)
12386 size_hints
.flags
|= USSize
;
12390 #ifndef USE_X_TOOLKIT
12395 size_hints
.win_gravity
= f
->output_data
.x
->win_gravity
;
12396 size_hints
.flags
|= PWinGravity
;
12400 size_hints
.flags
&= ~ PPosition
;
12401 size_hints
.flags
|= USPosition
;
12403 #endif /* PWinGravity */
12406 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
12408 XSetNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
12412 /* Used for IconicState or NormalState */
12415 x_wm_set_window_state (f
, state
)
12419 #ifdef USE_X_TOOLKIT
12422 XtSetArg (al
[0], XtNinitialState
, state
);
12423 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
12424 #else /* not USE_X_TOOLKIT */
12425 Window window
= FRAME_X_WINDOW (f
);
12427 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
12428 f
->output_data
.x
->wm_hints
.initial_state
= state
;
12430 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12431 #endif /* not USE_X_TOOLKIT */
12435 x_wm_set_icon_pixmap (f
, pixmap_id
)
12439 Pixmap icon_pixmap
;
12441 #ifndef USE_X_TOOLKIT
12442 Window window
= FRAME_X_WINDOW (f
);
12447 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
12448 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
12452 /* It seems there is no way to turn off use of an icon pixmap.
12453 The following line does it, only if no icon has yet been created,
12454 for some window managers. But with mwm it crashes.
12455 Some people say it should clear the IconPixmapHint bit in this case,
12456 but that doesn't work, and the X consortium said it isn't the
12457 right thing at all. Since there is no way to win,
12458 best to explicitly give up. */
12460 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
12466 #ifdef USE_X_TOOLKIT /* same as in x_wm_set_window_state. */
12470 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
12471 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
12474 #else /* not USE_X_TOOLKIT */
12476 f
->output_data
.x
->wm_hints
.flags
|= IconPixmapHint
;
12477 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12479 #endif /* not USE_X_TOOLKIT */
12483 x_wm_set_icon_position (f
, icon_x
, icon_y
)
12485 int icon_x
, icon_y
;
12487 #ifdef USE_X_TOOLKIT
12488 Window window
= XtWindow (f
->output_data
.x
->widget
);
12490 Window window
= FRAME_X_WINDOW (f
);
12493 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
12494 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
12495 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
12497 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
12501 /***********************************************************************
12503 ***********************************************************************/
12505 /* Return a pointer to struct font_info of font FONT_IDX of frame F. */
12508 x_get_font_info (f
, font_idx
)
12512 return (FRAME_X_FONT_TABLE (f
) + font_idx
);
12516 /* Return a list of names of available fonts matching PATTERN on frame
12517 F. If SIZE is not 0, it is the size (maximum bound width) of fonts
12518 to be listed. Frame F NULL means we have not yet created any
12519 frame on X, and consult the first display in x_display_list.
12520 MAXNAMES sets a limit on how many fonts to match. */
12523 x_list_fonts (f
, pattern
, size
, maxnames
)
12525 Lisp_Object pattern
;
12529 Lisp_Object list
= Qnil
, patterns
, newlist
= Qnil
, key
= Qnil
;
12530 Lisp_Object tem
, second_best
;
12531 Display
*dpy
= f
!= NULL
? FRAME_X_DISPLAY (f
) : x_display_list
->display
;
12532 int try_XLoadQueryFont
= 0;
12535 patterns
= Fassoc (pattern
, Valternate_fontname_alist
);
12536 if (NILP (patterns
))
12537 patterns
= Fcons (pattern
, Qnil
);
12539 if (maxnames
== 1 && !size
)
12540 /* We can return any single font matching PATTERN. */
12541 try_XLoadQueryFont
= 1;
12543 for (; CONSP (patterns
); patterns
= XCDR (patterns
))
12546 char **names
= NULL
;
12548 pattern
= XCAR (patterns
);
12549 /* See if we cached the result for this particular query.
12550 The cache is an alist of the form:
12551 (((PATTERN . MAXNAMES) (FONTNAME . WIDTH) ...) ...)
12553 if (f
&& (tem
= XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
),
12554 key
= Fcons (pattern
, make_number (maxnames
)),
12555 !NILP (list
= Fassoc (key
, tem
))))
12557 list
= Fcdr_safe (list
);
12558 /* We have a cashed list. Don't have to get the list again. */
12562 /* At first, put PATTERN in the cache. */
12565 count
= x_catch_errors (dpy
);
12567 if (try_XLoadQueryFont
)
12570 unsigned long value
;
12572 font
= XLoadQueryFont (dpy
, XSTRING (pattern
)->data
);
12573 if (x_had_errors_p (dpy
))
12575 /* This error is perhaps due to insufficient memory on X
12576 server. Let's just ignore it. */
12578 x_clear_errors (dpy
);
12582 && XGetFontProperty (font
, XA_FONT
, &value
))
12584 char *name
= (char *) XGetAtomName (dpy
, (Atom
) value
);
12585 int len
= strlen (name
);
12588 /* If DXPC (a Differential X Protocol Compressor)
12589 Ver.3.7 is running, XGetAtomName will return null
12590 string. We must avoid such a name. */
12592 try_XLoadQueryFont
= 0;
12596 names
= (char **) alloca (sizeof (char *));
12597 /* Some systems only allow alloca assigned to a
12599 tmp
= (char *) alloca (len
+ 1); names
[0] = tmp
;
12600 bcopy (name
, names
[0], len
+ 1);
12605 try_XLoadQueryFont
= 0;
12608 XFreeFont (dpy
, font
);
12611 if (!try_XLoadQueryFont
)
12613 /* We try at least 10 fonts because XListFonts will return
12614 auto-scaled fonts at the head. */
12615 names
= XListFonts (dpy
, XSTRING (pattern
)->data
, max (maxnames
, 10),
12617 if (x_had_errors_p (dpy
))
12619 /* This error is perhaps due to insufficient memory on X
12620 server. Let's just ignore it. */
12622 x_clear_errors (dpy
);
12626 x_uncatch_errors (dpy
, count
);
12633 /* Make a list of all the fonts we got back.
12634 Store that in the font cache for the display. */
12635 for (i
= 0; i
< num_fonts
; i
++)
12638 char *p
= names
[i
];
12639 int average_width
= -1, dashes
= 0;
12641 /* Count the number of dashes in NAMES[I]. If there are
12642 14 dashes, and the field value following 12th dash
12643 (AVERAGE_WIDTH) is 0, this is a auto-scaled font which
12644 is usually too ugly to be used for editing. Let's
12650 if (dashes
== 7) /* PIXEL_SIZE field */
12652 else if (dashes
== 12) /* AVERAGE_WIDTH field */
12653 average_width
= atoi (p
);
12655 if (dashes
< 14 || average_width
!= 0)
12657 tem
= build_string (names
[i
]);
12658 if (NILP (Fassoc (tem
, list
)))
12660 if (STRINGP (Vx_pixel_size_width_font_regexp
)
12661 && ((fast_c_string_match_ignore_case
12662 (Vx_pixel_size_width_font_regexp
, names
[i
]))
12664 /* We can set the value of PIXEL_SIZE to the
12665 width of this font. */
12666 list
= Fcons (Fcons (tem
, make_number (width
)), list
);
12668 /* For the moment, width is not known. */
12669 list
= Fcons (Fcons (tem
, Qnil
), list
);
12673 if (!try_XLoadQueryFont
)
12674 XFreeFontNames (names
);
12677 /* Now store the result in the cache. */
12679 XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
)
12680 = Fcons (Fcons (key
, list
),
12681 XCDR (FRAME_X_DISPLAY_INFO (f
)->name_list_element
));
12684 if (NILP (list
)) continue; /* Try the remaining alternatives. */
12686 newlist
= second_best
= Qnil
;
12687 /* Make a list of the fonts that have the right width. */
12688 for (; CONSP (list
); list
= XCDR (list
))
12694 if (!CONSP (tem
) || NILP (XCAR (tem
)))
12698 newlist
= Fcons (XCAR (tem
), newlist
);
12702 if (!INTEGERP (XCDR (tem
)))
12704 /* Since we have not yet known the size of this font, we
12705 must try slow function call XLoadQueryFont. */
12706 XFontStruct
*thisinfo
;
12709 count
= x_catch_errors (dpy
);
12710 thisinfo
= XLoadQueryFont (dpy
,
12711 XSTRING (XCAR (tem
))->data
);
12712 if (x_had_errors_p (dpy
))
12714 /* This error is perhaps due to insufficient memory on X
12715 server. Let's just ignore it. */
12717 x_clear_errors (dpy
);
12719 x_uncatch_errors (dpy
, count
);
12725 = (thisinfo
->min_bounds
.width
== 0
12727 : make_number (thisinfo
->max_bounds
.width
));
12728 XFreeFont (dpy
, thisinfo
);
12731 /* For unknown reason, the previous call of XListFont had
12732 returned a font which can't be opened. Record the size
12733 as 0 not to try to open it again. */
12734 XCDR (tem
) = make_number (0);
12737 found_size
= XINT (XCDR (tem
));
12738 if (found_size
== size
)
12739 newlist
= Fcons (XCAR (tem
), newlist
);
12740 else if (found_size
> 0)
12742 if (NILP (second_best
))
12744 else if (found_size
< size
)
12746 if (XINT (XCDR (second_best
)) > size
12747 || XINT (XCDR (second_best
)) < found_size
)
12752 if (XINT (XCDR (second_best
)) > size
12753 && XINT (XCDR (second_best
)) > found_size
)
12758 if (!NILP (newlist
))
12760 else if (!NILP (second_best
))
12762 newlist
= Fcons (XCAR (second_best
), Qnil
);
12773 /* Check that FONT is valid on frame F. It is if it can be found in F's
12777 x_check_font (f
, font
)
12782 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12784 xassert (font
!= NULL
);
12786 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12787 if (dpyinfo
->font_table
[i
].name
12788 && font
== dpyinfo
->font_table
[i
].font
)
12791 xassert (i
< dpyinfo
->n_fonts
);
12794 #endif /* GLYPH_DEBUG != 0 */
12796 /* Set *W to the minimum width, *H to the minimum font height of FONT.
12797 Note: There are (broken) X fonts out there with invalid XFontStruct
12798 min_bounds contents. For example, handa@etl.go.jp reports that
12799 "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1" fonts
12800 have font->min_bounds.width == 0. */
12803 x_font_min_bounds (font
, w
, h
)
12807 *h
= FONT_HEIGHT (font
);
12808 *w
= font
->min_bounds
.width
;
12810 /* Try to handle the case where FONT->min_bounds has invalid
12811 contents. Since the only font known to have invalid min_bounds
12812 is fixed-width, use max_bounds if min_bounds seems to be invalid. */
12814 *w
= font
->max_bounds
.width
;
12818 /* Compute the smallest character width and smallest font height over
12819 all fonts available on frame F. Set the members smallest_char_width
12820 and smallest_font_height in F's x_display_info structure to
12821 the values computed. Value is non-zero if smallest_font_height or
12822 smallest_char_width become smaller than they were before. */
12825 x_compute_min_glyph_bounds (f
)
12829 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12831 int old_width
= dpyinfo
->smallest_char_width
;
12832 int old_height
= dpyinfo
->smallest_font_height
;
12834 dpyinfo
->smallest_font_height
= 100000;
12835 dpyinfo
->smallest_char_width
= 100000;
12837 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
12838 if (dpyinfo
->font_table
[i
].name
)
12840 struct font_info
*fontp
= dpyinfo
->font_table
+ i
;
12843 font
= (XFontStruct
*) fontp
->font
;
12844 xassert (font
!= (XFontStruct
*) ~0);
12845 x_font_min_bounds (font
, &w
, &h
);
12847 dpyinfo
->smallest_font_height
= min (dpyinfo
->smallest_font_height
, h
);
12848 dpyinfo
->smallest_char_width
= min (dpyinfo
->smallest_char_width
, w
);
12851 xassert (dpyinfo
->smallest_char_width
> 0
12852 && dpyinfo
->smallest_font_height
> 0);
12854 return (dpyinfo
->n_fonts
== 1
12855 || dpyinfo
->smallest_char_width
< old_width
12856 || dpyinfo
->smallest_font_height
< old_height
);
12860 /* Load font named FONTNAME of the size SIZE for frame F, and return a
12861 pointer to the structure font_info while allocating it dynamically.
12862 If SIZE is 0, load any size of font.
12863 If loading is failed, return NULL. */
12866 x_load_font (f
, fontname
, size
)
12868 register char *fontname
;
12871 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12872 Lisp_Object font_names
;
12875 /* Get a list of all the fonts that match this name. Once we
12876 have a list of matching fonts, we compare them against the fonts
12877 we already have by comparing names. */
12878 font_names
= x_list_fonts (f
, build_string (fontname
), size
, 1);
12880 if (!NILP (font_names
))
12885 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
12886 for (tail
= font_names
; CONSP (tail
); tail
= XCDR (tail
))
12887 if (dpyinfo
->font_table
[i
].name
12888 && (!strcmp (dpyinfo
->font_table
[i
].name
,
12889 XSTRING (XCAR (tail
))->data
)
12890 || !strcmp (dpyinfo
->font_table
[i
].full_name
,
12891 XSTRING (XCAR (tail
))->data
)))
12892 return (dpyinfo
->font_table
+ i
);
12895 /* Load the font and add it to the table. */
12899 struct font_info
*fontp
;
12900 unsigned long value
;
12903 /* If we have found fonts by x_list_font, load one of them. If
12904 not, we still try to load a font by the name given as FONTNAME
12905 because XListFonts (called in x_list_font) of some X server has
12906 a bug of not finding a font even if the font surely exists and
12907 is loadable by XLoadQueryFont. */
12908 if (size
> 0 && !NILP (font_names
))
12909 fontname
= (char *) XSTRING (XCAR (font_names
))->data
;
12912 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
12913 font
= (XFontStruct
*) XLoadQueryFont (FRAME_X_DISPLAY (f
), fontname
);
12914 if (x_had_errors_p (FRAME_X_DISPLAY (f
)))
12916 /* This error is perhaps due to insufficient memory on X
12917 server. Let's just ignore it. */
12919 x_clear_errors (FRAME_X_DISPLAY (f
));
12921 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
12926 /* Find a free slot in the font table. */
12927 for (i
= 0; i
< dpyinfo
->n_fonts
; ++i
)
12928 if (dpyinfo
->font_table
[i
].name
== NULL
)
12931 /* If no free slot found, maybe enlarge the font table. */
12932 if (i
== dpyinfo
->n_fonts
12933 && dpyinfo
->n_fonts
== dpyinfo
->font_table_size
)
12936 dpyinfo
->font_table_size
= max (16, 2 * dpyinfo
->font_table_size
);
12937 sz
= dpyinfo
->font_table_size
* sizeof *dpyinfo
->font_table
;
12938 dpyinfo
->font_table
12939 = (struct font_info
*) xrealloc (dpyinfo
->font_table
, sz
);
12942 fontp
= dpyinfo
->font_table
+ i
;
12943 if (i
== dpyinfo
->n_fonts
)
12944 ++dpyinfo
->n_fonts
;
12946 /* Now fill in the slots of *FONTP. */
12948 fontp
->font
= font
;
12949 fontp
->font_idx
= i
;
12950 fontp
->name
= (char *) xmalloc (strlen (fontname
) + 1);
12951 bcopy (fontname
, fontp
->name
, strlen (fontname
) + 1);
12953 /* Try to get the full name of FONT. Put it in FULL_NAME. */
12955 if (XGetFontProperty (font
, XA_FONT
, &value
))
12957 char *name
= (char *) XGetAtomName (FRAME_X_DISPLAY (f
), (Atom
) value
);
12961 /* Count the number of dashes in the "full name".
12962 If it is too few, this isn't really the font's full name,
12964 In X11R4, the fonts did not come with their canonical names
12975 full_name
= (char *) xmalloc (p
- name
+ 1);
12976 bcopy (name
, full_name
, p
- name
+ 1);
12982 if (full_name
!= 0)
12983 fontp
->full_name
= full_name
;
12985 fontp
->full_name
= fontp
->name
;
12987 fontp
->size
= font
->max_bounds
.width
;
12988 fontp
->height
= FONT_HEIGHT (font
);
12990 /* For some font, ascent and descent in max_bounds field is
12991 larger than the above value. */
12992 int max_height
= font
->max_bounds
.ascent
+ font
->max_bounds
.descent
;
12993 if (max_height
> fontp
->height
)
12994 fontp
->height
= max_height
;
12997 if (NILP (font_names
))
12999 /* We come here because of a bug of XListFonts mentioned at
13000 the head of this block. Let's store this information in
13001 the cache for x_list_fonts. */
13002 Lisp_Object lispy_name
= build_string (fontname
);
13003 Lisp_Object lispy_full_name
= build_string (fontp
->full_name
);
13005 XCDR (dpyinfo
->name_list_element
)
13006 = Fcons (Fcons (Fcons (lispy_name
, make_number (256)),
13007 Fcons (Fcons (lispy_full_name
,
13008 make_number (fontp
->size
)),
13010 XCDR (dpyinfo
->name_list_element
));
13012 XCDR (dpyinfo
->name_list_element
)
13013 = Fcons (Fcons (Fcons (lispy_full_name
, make_number (256)),
13014 Fcons (Fcons (lispy_full_name
,
13015 make_number (fontp
->size
)),
13017 XCDR (dpyinfo
->name_list_element
));
13020 /* The slot `encoding' specifies how to map a character
13021 code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
13022 the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
13023 (0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
13024 2:0xA020..0xFF7F). For the moment, we don't know which charset
13025 uses this font. So, we set information in fontp->encoding[1]
13026 which is never used by any charset. If mapping can't be
13027 decided, set FONT_ENCODING_NOT_DECIDED. */
13029 = (font
->max_byte1
== 0
13031 ? (font
->min_char_or_byte2
< 0x80
13032 ? (font
->max_char_or_byte2
< 0x80
13033 ? 0 /* 0x20..0x7F */
13034 : FONT_ENCODING_NOT_DECIDED
) /* 0x20..0xFF */
13035 : 1) /* 0xA0..0xFF */
13037 : (font
->min_byte1
< 0x80
13038 ? (font
->max_byte1
< 0x80
13039 ? (font
->min_char_or_byte2
< 0x80
13040 ? (font
->max_char_or_byte2
< 0x80
13041 ? 0 /* 0x2020..0x7F7F */
13042 : FONT_ENCODING_NOT_DECIDED
) /* 0x2020..0x7FFF */
13043 : 3) /* 0x20A0..0x7FFF */
13044 : FONT_ENCODING_NOT_DECIDED
) /* 0x20??..0xA0?? */
13045 : (font
->min_char_or_byte2
< 0x80
13046 ? (font
->max_char_or_byte2
< 0x80
13047 ? 2 /* 0xA020..0xFF7F */
13048 : FONT_ENCODING_NOT_DECIDED
) /* 0xA020..0xFFFF */
13049 : 1))); /* 0xA0A0..0xFFFF */
13051 fontp
->baseline_offset
13052 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_BASELINE_OFFSET
, &value
)
13053 ? (long) value
: 0);
13054 fontp
->relative_compose
13055 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
, &value
)
13056 ? (long) value
: 0);
13057 fontp
->default_ascent
13058 = (XGetFontProperty (font
, dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
, &value
)
13059 ? (long) value
: 0);
13061 /* Set global flag fonts_changed_p to non-zero if the font loaded
13062 has a character with a smaller width than any other character
13063 before, or if the font loaded has a smalle>r height than any
13064 other font loaded before. If this happens, it will make a
13065 glyph matrix reallocation necessary. */
13066 fonts_changed_p
= x_compute_min_glyph_bounds (f
);
13073 /* Return a pointer to struct font_info of a font named FONTNAME for
13074 frame F. If no such font is loaded, return NULL. */
13077 x_query_font (f
, fontname
)
13079 register char *fontname
;
13081 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
13084 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
13085 if (dpyinfo
->font_table
[i
].name
13086 && (!strcmp (dpyinfo
->font_table
[i
].name
, fontname
)
13087 || !strcmp (dpyinfo
->font_table
[i
].full_name
, fontname
)))
13088 return (dpyinfo
->font_table
+ i
);
13093 /* Find a CCL program for a font specified by FONTP, and set the member
13094 `encoder' of the structure. */
13097 x_find_ccl_program (fontp
)
13098 struct font_info
*fontp
;
13100 Lisp_Object list
, elt
;
13103 for (list
= Vfont_ccl_encoder_alist
; CONSP (list
); list
= XCDR (list
))
13107 && STRINGP (XCAR (elt
))
13108 && (fast_c_string_match_ignore_case (XCAR (elt
), fontp
->name
)
13115 struct ccl_program
*ccl
13116 = (struct ccl_program
*) xmalloc (sizeof (struct ccl_program
));
13118 if (setup_ccl_program (ccl
, XCDR (elt
)) < 0)
13121 fontp
->font_encoder
= ccl
;
13127 /***********************************************************************
13129 ***********************************************************************/
13131 #ifdef USE_X_TOOLKIT
13132 static XrmOptionDescRec emacs_options
[] = {
13133 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
13134 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
13136 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
13137 XrmoptionSepArg
, NULL
},
13138 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
13140 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13141 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13142 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
13143 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
13144 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
13145 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
13146 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
13148 #endif /* USE_X_TOOLKIT */
13150 static int x_initialized
;
13152 #ifdef MULTI_KBOARD
13153 /* Test whether two display-name strings agree up to the dot that separates
13154 the screen number from the server number. */
13156 same_x_server (name1
, name2
)
13157 char *name1
, *name2
;
13159 int seen_colon
= 0;
13160 unsigned char *system_name
= XSTRING (Vsystem_name
)->data
;
13161 int system_name_length
= strlen (system_name
);
13162 int length_until_period
= 0;
13164 while (system_name
[length_until_period
] != 0
13165 && system_name
[length_until_period
] != '.')
13166 length_until_period
++;
13168 /* Treat `unix' like an empty host name. */
13169 if (! strncmp (name1
, "unix:", 5))
13171 if (! strncmp (name2
, "unix:", 5))
13173 /* Treat this host's name like an empty host name. */
13174 if (! strncmp (name1
, system_name
, system_name_length
)
13175 && name1
[system_name_length
] == ':')
13176 name1
+= system_name_length
;
13177 if (! strncmp (name2
, system_name
, system_name_length
)
13178 && name2
[system_name_length
] == ':')
13179 name2
+= system_name_length
;
13180 /* Treat this host's domainless name like an empty host name. */
13181 if (! strncmp (name1
, system_name
, length_until_period
)
13182 && name1
[length_until_period
] == ':')
13183 name1
+= length_until_period
;
13184 if (! strncmp (name2
, system_name
, length_until_period
)
13185 && name2
[length_until_period
] == ':')
13186 name2
+= length_until_period
;
13188 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
13192 if (seen_colon
&& *name1
== '.')
13196 && (*name1
== '.' || *name1
== '\0')
13197 && (*name2
== '.' || *name2
== '\0'));
13201 struct x_display_info
*
13202 x_term_init (display_name
, xrm_option
, resource_name
)
13203 Lisp_Object display_name
;
13205 char *resource_name
;
13209 struct x_display_info
*dpyinfo
;
13214 if (!x_initialized
)
13220 #ifdef USE_X_TOOLKIT
13221 /* weiner@footloose.sps.mot.com reports that this causes
13223 X protocol error: BadAtom (invalid Atom parameter)
13224 on protocol request 18skiloaf.
13225 So let's not use it until R6. */
13226 #ifdef HAVE_X11XTR6
13227 XtSetLanguageProc (NULL
, NULL
, NULL
);
13238 argv
[argc
++] = "-xrm";
13239 argv
[argc
++] = xrm_option
;
13241 dpy
= XtOpenDisplay (Xt_app_con
, XSTRING (display_name
)->data
,
13242 resource_name
, EMACS_CLASS
,
13243 emacs_options
, XtNumber (emacs_options
),
13246 #ifdef HAVE_X11XTR6
13247 /* I think this is to compensate for XtSetLanguageProc. */
13252 #else /* not USE_X_TOOLKIT */
13254 XSetLocaleModifiers ("");
13256 dpy
= XOpenDisplay (XSTRING (display_name
)->data
);
13257 #endif /* not USE_X_TOOLKIT */
13259 /* Detect failure. */
13266 /* We have definitely succeeded. Record the new connection. */
13268 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
13270 #ifdef MULTI_KBOARD
13272 struct x_display_info
*share
;
13275 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
13276 share
= share
->next
, tail
= XCDR (tail
))
13277 if (same_x_server (XSTRING (XCAR (XCAR (tail
)))->data
,
13278 XSTRING (display_name
)->data
))
13281 dpyinfo
->kboard
= share
->kboard
;
13284 dpyinfo
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
13285 init_kboard (dpyinfo
->kboard
);
13286 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
13288 char *vendor
= ServerVendor (dpy
);
13290 dpyinfo
->kboard
->Vsystem_key_alist
13291 = call1 (Qvendor_specific_keysyms
,
13292 build_string (vendor
? vendor
: ""));
13296 dpyinfo
->kboard
->next_kboard
= all_kboards
;
13297 all_kboards
= dpyinfo
->kboard
;
13298 /* Don't let the initial kboard remain current longer than necessary.
13299 That would cause problems if a file loaded on startup tries to
13300 prompt in the mini-buffer. */
13301 if (current_kboard
== initial_kboard
)
13302 current_kboard
= dpyinfo
->kboard
;
13304 dpyinfo
->kboard
->reference_count
++;
13308 /* Put this display on the chain. */
13309 dpyinfo
->next
= x_display_list
;
13310 x_display_list
= dpyinfo
;
13312 /* Put it on x_display_name_list as well, to keep them parallel. */
13313 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
13314 x_display_name_list
);
13315 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
13317 dpyinfo
->display
= dpy
;
13320 XSetAfterFunction (x_current_display
, x_trace_wire
);
13324 = (char *) xmalloc (STRING_BYTES (XSTRING (Vinvocation_name
))
13325 + STRING_BYTES (XSTRING (Vsystem_name
))
13327 sprintf (dpyinfo
->x_id_name
, "%s@%s",
13328 XSTRING (Vinvocation_name
)->data
, XSTRING (Vsystem_name
)->data
);
13330 /* Figure out which modifier bits mean what. */
13331 x_find_modifier_meanings (dpyinfo
);
13333 /* Get the scroll bar cursor. */
13334 dpyinfo
->vertical_scroll_bar_cursor
13335 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
13337 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
13338 resource_name
, EMACS_CLASS
);
13339 #ifdef HAVE_XRMSETDATABASE
13340 XrmSetDatabase (dpyinfo
->display
, xrdb
);
13342 dpyinfo
->display
->db
= xrdb
;
13344 /* Put the rdb where we can find it in a way that works on
13346 dpyinfo
->xrdb
= xrdb
;
13348 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
13349 DefaultScreen (dpyinfo
->display
));
13350 select_visual (dpyinfo
);
13351 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
13352 dpyinfo
->height
= HeightOfScreen (dpyinfo
->screen
);
13353 dpyinfo
->width
= WidthOfScreen (dpyinfo
->screen
);
13354 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
13355 dpyinfo
->grabbed
= 0;
13356 dpyinfo
->reference_count
= 0;
13357 dpyinfo
->icon_bitmap_id
= -1;
13358 dpyinfo
->font_table
= NULL
;
13359 dpyinfo
->n_fonts
= 0;
13360 dpyinfo
->font_table_size
= 0;
13361 dpyinfo
->bitmaps
= 0;
13362 dpyinfo
->bitmaps_size
= 0;
13363 dpyinfo
->bitmaps_last
= 0;
13364 dpyinfo
->scratch_cursor_gc
= 0;
13365 dpyinfo
->mouse_face_mouse_frame
= 0;
13366 dpyinfo
->mouse_face_deferred_gc
= 0;
13367 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
13368 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
13369 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
13370 dpyinfo
->mouse_face_window
= Qnil
;
13371 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
13372 dpyinfo
->mouse_face_defer
= 0;
13373 dpyinfo
->x_focus_frame
= 0;
13374 dpyinfo
->x_focus_event_frame
= 0;
13375 dpyinfo
->x_highlight_frame
= 0;
13376 dpyinfo
->image_cache
= make_image_cache ();
13378 /* See if a private colormap is requested. */
13379 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
13381 if (dpyinfo
->visual
->class == PseudoColor
)
13384 value
= display_x_get_resource (dpyinfo
,
13385 build_string ("privateColormap"),
13386 build_string ("PrivateColormap"),
13388 if (STRINGP (value
)
13389 && (!strcmp (XSTRING (value
)->data
, "true")
13390 || !strcmp (XSTRING (value
)->data
, "on")))
13391 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
13395 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
13396 dpyinfo
->visual
, AllocNone
);
13399 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
13400 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
13401 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
13402 dpyinfo
->resy
= pixels
* 25.4 / mm
;
13403 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
13404 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
13405 dpyinfo
->resx
= pixels
* 25.4 / mm
;
13408 dpyinfo
->Xatom_wm_protocols
13409 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
13410 dpyinfo
->Xatom_wm_take_focus
13411 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
13412 dpyinfo
->Xatom_wm_save_yourself
13413 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
13414 dpyinfo
->Xatom_wm_delete_window
13415 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
13416 dpyinfo
->Xatom_wm_change_state
13417 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
13418 dpyinfo
->Xatom_wm_configure_denied
13419 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
13420 dpyinfo
->Xatom_wm_window_moved
13421 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
13422 dpyinfo
->Xatom_editres
13423 = XInternAtom (dpyinfo
->display
, "Editres", False
);
13424 dpyinfo
->Xatom_CLIPBOARD
13425 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
13426 dpyinfo
->Xatom_TIMESTAMP
13427 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
13428 dpyinfo
->Xatom_TEXT
13429 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
13430 dpyinfo
->Xatom_COMPOUND_TEXT
13431 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
13432 dpyinfo
->Xatom_DELETE
13433 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
13434 dpyinfo
->Xatom_MULTIPLE
13435 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
13436 dpyinfo
->Xatom_INCR
13437 = XInternAtom (dpyinfo
->display
, "INCR", False
);
13438 dpyinfo
->Xatom_EMACS_TMP
13439 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
13440 dpyinfo
->Xatom_TARGETS
13441 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
13442 dpyinfo
->Xatom_NULL
13443 = XInternAtom (dpyinfo
->display
, "NULL", False
);
13444 dpyinfo
->Xatom_ATOM_PAIR
13445 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
13446 /* For properties of font. */
13447 dpyinfo
->Xatom_PIXEL_SIZE
13448 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
13449 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
13450 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
13451 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
13452 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
13453 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
13454 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
13456 /* Ghostscript support. */
13457 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
13458 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
13460 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
13463 dpyinfo
->cut_buffers_initialized
= 0;
13465 connection
= ConnectionNumber (dpyinfo
->display
);
13466 dpyinfo
->connection
= connection
;
13471 null_bits
[0] = 0x00;
13473 dpyinfo
->null_pixel
13474 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
13475 null_bits
, 1, 1, (long) 0, (long) 0,
13480 extern int gray_bitmap_width
, gray_bitmap_height
;
13481 extern unsigned char *gray_bitmap_bits
;
13483 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
13485 gray_bitmap_width
, gray_bitmap_height
,
13486 (unsigned long) 1, (unsigned long) 0, 1);
13490 xim_initialize (dpyinfo
, resource_name
);
13493 #ifdef subprocesses
13494 /* This is only needed for distinguishing keyboard and process input. */
13495 if (connection
!= 0)
13496 add_keyboard_wait_descriptor (connection
);
13499 #ifndef F_SETOWN_BUG
13501 #ifdef F_SETOWN_SOCK_NEG
13502 /* stdin is a socket here */
13503 fcntl (connection
, F_SETOWN
, -getpid ());
13504 #else /* ! defined (F_SETOWN_SOCK_NEG) */
13505 fcntl (connection
, F_SETOWN
, getpid ());
13506 #endif /* ! defined (F_SETOWN_SOCK_NEG) */
13507 #endif /* ! defined (F_SETOWN) */
13508 #endif /* F_SETOWN_BUG */
13511 if (interrupt_input
)
13512 init_sigio (connection
);
13513 #endif /* ! defined (SIGIO) */
13516 #ifdef HAVE_X11R5 /* It seems X11R4 lacks XtCvtStringToFont, and XPointer. */
13517 /* Make sure that we have a valid font for dialog boxes
13518 so that Xt does not crash. */
13520 Display
*dpy
= dpyinfo
->display
;
13521 XrmValue d
, fr
, to
;
13525 d
.addr
= (XPointer
)&dpy
;
13526 d
.size
= sizeof (Display
*);
13527 fr
.addr
= XtDefaultFont
;
13528 fr
.size
= sizeof (XtDefaultFont
);
13529 to
.size
= sizeof (Font
*);
13530 to
.addr
= (XPointer
)&font
;
13531 count
= x_catch_errors (dpy
);
13532 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
13534 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
13535 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
13536 x_uncatch_errors (dpy
, count
);
13541 /* See if we should run in synchronous mode. This is useful
13542 for debugging X code. */
13545 value
= display_x_get_resource (dpyinfo
,
13546 build_string ("synchronous"),
13547 build_string ("Synchronous"),
13549 if (STRINGP (value
)
13550 && (!strcmp (XSTRING (value
)->data
, "true")
13551 || !strcmp (XSTRING (value
)->data
, "on")))
13552 XSynchronize (dpyinfo
->display
, True
);
13560 /* Get rid of display DPYINFO, assuming all frames are already gone,
13561 and without sending any more commands to the X server. */
13564 x_delete_display (dpyinfo
)
13565 struct x_display_info
*dpyinfo
;
13567 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
13569 /* Discard this display from x_display_name_list and x_display_list.
13570 We can't use Fdelq because that can quit. */
13571 if (! NILP (x_display_name_list
)
13572 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
13573 x_display_name_list
= XCDR (x_display_name_list
);
13578 tail
= x_display_name_list
;
13579 while (CONSP (tail
) && CONSP (XCDR (tail
)))
13581 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
13583 XCDR (tail
) = XCDR (XCDR (tail
));
13586 tail
= XCDR (tail
);
13590 if (next_noop_dpyinfo
== dpyinfo
)
13591 next_noop_dpyinfo
= dpyinfo
->next
;
13593 if (x_display_list
== dpyinfo
)
13594 x_display_list
= dpyinfo
->next
;
13597 struct x_display_info
*tail
;
13599 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
13600 if (tail
->next
== dpyinfo
)
13601 tail
->next
= tail
->next
->next
;
13604 #ifndef USE_X_TOOLKIT /* I'm told Xt does this itself. */
13605 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
13606 XrmDestroyDatabase (dpyinfo
->xrdb
);
13609 #ifdef MULTI_KBOARD
13610 if (--dpyinfo
->kboard
->reference_count
== 0)
13611 delete_kboard (dpyinfo
->kboard
);
13615 xim_close_dpy (dpyinfo
);
13618 xfree (dpyinfo
->font_table
);
13619 xfree (dpyinfo
->x_id_name
);
13623 /* Set up use of X before we make the first connection. */
13625 static struct redisplay_interface x_redisplay_interface
=
13630 x_clear_end_of_line
,
13632 x_after_update_window_line
,
13633 x_update_window_begin
,
13634 x_update_window_end
,
13637 x_clear_mouse_face
,
13638 x_get_glyph_overhangs
,
13639 x_fix_overlapping_area
13645 rif
= &x_redisplay_interface
;
13647 clear_frame_hook
= x_clear_frame
;
13648 ins_del_lines_hook
= x_ins_del_lines
;
13649 change_line_highlight_hook
= x_change_line_highlight
;
13650 delete_glyphs_hook
= x_delete_glyphs
;
13651 ring_bell_hook
= XTring_bell
;
13652 reset_terminal_modes_hook
= XTreset_terminal_modes
;
13653 set_terminal_modes_hook
= XTset_terminal_modes
;
13654 update_begin_hook
= x_update_begin
;
13655 update_end_hook
= x_update_end
;
13656 set_terminal_window_hook
= XTset_terminal_window
;
13657 read_socket_hook
= XTread_socket
;
13658 frame_up_to_date_hook
= XTframe_up_to_date
;
13659 reassert_line_highlight_hook
= XTreassert_line_highlight
;
13660 mouse_position_hook
= XTmouse_position
;
13661 frame_rehighlight_hook
= XTframe_rehighlight
;
13662 frame_raise_lower_hook
= XTframe_raise_lower
;
13663 set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
13664 condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
13665 redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
13666 judge_scroll_bars_hook
= XTjudge_scroll_bars
;
13667 estimate_mode_line_height_hook
= x_estimate_mode_line_height
;
13669 scroll_region_ok
= 1; /* we'll scroll partial frames */
13670 char_ins_del_ok
= 0; /* just as fast to write the line */
13671 line_ins_del_ok
= 1; /* we'll just blt 'em */
13672 fast_clear_end_of_line
= 1; /* X does this well */
13673 memory_below_frame
= 0; /* we don't remember what scrolls
13678 last_tool_bar_item
= -1;
13679 any_help_event_p
= 0;
13681 /* Try to use interrupt input; if we can't, then start polling. */
13682 Fset_input_mode (Qt
, Qnil
, Qt
, Qnil
);
13684 #ifdef USE_X_TOOLKIT
13685 XtToolkitInitialize ();
13686 Xt_app_con
= XtCreateApplicationContext ();
13687 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
13689 /* Install an asynchronous timer that processes Xt timeout events
13690 every 0.1s. This is necessary because some widget sets use
13691 timeouts internally, for example the LessTif menu bar, or the
13692 Xaw3d scroll bar. When Xt timouts aren't processed, these
13693 widgets don't behave normally. */
13695 EMACS_TIME interval
;
13696 EMACS_SET_SECS_USECS (interval
, 0, 100000);
13697 start_atimer (ATIMER_CONTINUOUS
, interval
, x_process_timeouts
, 0);
13701 #if USE_TOOLKIT_SCROLL_BARS
13702 xaw3d_arrow_scroll
= False
;
13703 xaw3d_pick_top
= True
;
13706 /* Note that there is no real way portable across R3/R4 to get the
13707 original error handler. */
13708 XSetErrorHandler (x_error_handler
);
13709 XSetIOErrorHandler (x_io_error_quitter
);
13711 /* Disable Window Change signals; they are handled by X events. */
13713 signal (SIGWINCH
, SIG_DFL
);
13714 #endif /* ! defined (SIGWINCH) */
13716 signal (SIGPIPE
, x_connection_signal
);
13723 staticpro (&x_error_message_string
);
13724 x_error_message_string
= Qnil
;
13726 staticpro (&x_display_name_list
);
13727 x_display_name_list
= Qnil
;
13729 staticpro (&last_mouse_scroll_bar
);
13730 last_mouse_scroll_bar
= Qnil
;
13732 staticpro (&Qvendor_specific_keysyms
);
13733 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
13735 staticpro (&last_mouse_press_frame
);
13736 last_mouse_press_frame
= Qnil
;
13739 staticpro (&help_echo
);
13740 help_echo_object
= Qnil
;
13741 staticpro (&help_echo_object
);
13742 help_echo_window
= Qnil
;
13743 staticpro (&help_echo_window
);
13744 previous_help_echo
= Qnil
;
13745 staticpro (&previous_help_echo
);
13746 help_echo_pos
= -1;
13748 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
13749 "*Non-nil means draw block cursor as wide as the glyph under it.\n\
13750 For example, if a block cursor is over a tab, it will be drawn as\n\
13751 wide as that tab on the display.");
13752 x_stretch_cursor_p
= 0;
13754 DEFVAR_BOOL ("x-toolkit-scroll-bars-p", &x_toolkit_scroll_bars_p
,
13755 "If not nil, Emacs uses toolkit scroll bars.");
13756 #if USE_TOOLKIT_SCROLL_BARS
13757 x_toolkit_scroll_bars_p
= 1;
13759 x_toolkit_scroll_bars_p
= 0;
13762 staticpro (&last_mouse_motion_frame
);
13763 last_mouse_motion_frame
= Qnil
;
13766 #endif /* not HAVE_X_WINDOWS */